repoburg 1.3.304 → 1.3.305
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/agent-pane/backend/dist/index.js +1646 -649
- package/agent-pane/backend/dist/server.js +1648 -651
- package/agent-pane/frontend/dist/assets/{TerminalView-BN_4GKd9.js → TerminalView-CWb7lwEQ.js} +1 -1
- package/agent-pane/frontend/dist/assets/index-B5j2jGP4.css +1 -0
- package/agent-pane/frontend/dist/assets/index-BhyGOapD.js +836 -0
- package/agent-pane/frontend/dist/index.html +2 -2
- package/package.json +1 -1
- package/tabtape/extension/dist/build-info.json +3 -3
- package/tabtape/extension/dist/manifest.json +1 -1
- package/tabtape/ui/dist/build-info.json +3 -3
- package/agent-pane/frontend/dist/assets/index-CaUGqLNi.js +0 -836
- package/agent-pane/frontend/dist/assets/index-CuJZVIUh.css +0 -1
|
@@ -2680,7 +2680,7 @@ var require_server = __commonJS({
|
|
|
2680
2680
|
var https = __require("node:https");
|
|
2681
2681
|
var http22 = __require("node:http2");
|
|
2682
2682
|
var dns = __require("node:dns");
|
|
2683
|
-
var
|
|
2683
|
+
var os6 = __require("node:os");
|
|
2684
2684
|
var { kState, kOptions, kServerBindings, kHttp2ServerSessions } = require_symbols2();
|
|
2685
2685
|
var { FSTWRN003 } = require_warnings();
|
|
2686
2686
|
var { onListenHookRunner } = require_hooks();
|
|
@@ -2942,7 +2942,7 @@ var require_server = __commonJS({
|
|
|
2942
2942
|
}
|
|
2943
2943
|
function getAddresses(address) {
|
|
2944
2944
|
if (address.address === "0.0.0.0") {
|
|
2945
|
-
return Object.values(
|
|
2945
|
+
return Object.values(os6.networkInterfaces()).flatMap((iface) => {
|
|
2946
2946
|
return iface.filter((iface2) => iface2.family === "IPv4");
|
|
2947
2947
|
}).sort((iface) => {
|
|
2948
2948
|
return iface.internal ? -1 : 1;
|
|
@@ -6128,8 +6128,8 @@ var require_req = __commonJS({
|
|
|
6128
6128
|
if (req.originalUrl) {
|
|
6129
6129
|
_req.url = req.originalUrl;
|
|
6130
6130
|
} else {
|
|
6131
|
-
const
|
|
6132
|
-
_req.url = typeof
|
|
6131
|
+
const path19 = req.path;
|
|
6132
|
+
_req.url = typeof path19 === "string" ? path19 : req.url ? req.url.path || req.url : void 0;
|
|
6133
6133
|
}
|
|
6134
6134
|
if (req.query) {
|
|
6135
6135
|
_req.query = req.query;
|
|
@@ -6294,14 +6294,14 @@ var require_redact = __commonJS({
|
|
|
6294
6294
|
}
|
|
6295
6295
|
return obj2;
|
|
6296
6296
|
}
|
|
6297
|
-
function parsePath(
|
|
6297
|
+
function parsePath(path19) {
|
|
6298
6298
|
const parts = [];
|
|
6299
6299
|
let current = "";
|
|
6300
6300
|
let inBrackets = false;
|
|
6301
6301
|
let inQuotes = false;
|
|
6302
6302
|
let quoteChar = "";
|
|
6303
|
-
for (let i = 0; i <
|
|
6304
|
-
const char =
|
|
6303
|
+
for (let i = 0; i < path19.length; i++) {
|
|
6304
|
+
const char = path19[i];
|
|
6305
6305
|
if (!inBrackets && char === ".") {
|
|
6306
6306
|
if (current) {
|
|
6307
6307
|
parts.push(current);
|
|
@@ -6432,10 +6432,10 @@ var require_redact = __commonJS({
|
|
|
6432
6432
|
return current;
|
|
6433
6433
|
}
|
|
6434
6434
|
function redactPaths(obj2, paths, censor, remove = false) {
|
|
6435
|
-
for (const
|
|
6436
|
-
const parts = parsePath(
|
|
6435
|
+
for (const path19 of paths) {
|
|
6436
|
+
const parts = parsePath(path19);
|
|
6437
6437
|
if (parts.includes("*")) {
|
|
6438
|
-
redactWildcardPath(obj2, parts, censor,
|
|
6438
|
+
redactWildcardPath(obj2, parts, censor, path19, remove);
|
|
6439
6439
|
} else {
|
|
6440
6440
|
if (remove) {
|
|
6441
6441
|
removeKey(obj2, parts);
|
|
@@ -6520,8 +6520,8 @@ var require_redact = __commonJS({
|
|
|
6520
6520
|
}
|
|
6521
6521
|
} else {
|
|
6522
6522
|
if (afterWildcard.includes("*")) {
|
|
6523
|
-
const wrappedCensor = typeof censor === "function" ? (value,
|
|
6524
|
-
const fullPath = [...pathArray.slice(0, pathLength), ...
|
|
6523
|
+
const wrappedCensor = typeof censor === "function" ? (value, path19) => {
|
|
6524
|
+
const fullPath = [...pathArray.slice(0, pathLength), ...path19];
|
|
6525
6525
|
return censor(value, fullPath);
|
|
6526
6526
|
} : censor;
|
|
6527
6527
|
redactWildcardPath(current, afterWildcard, wrappedCensor, originalPath, remove);
|
|
@@ -6556,8 +6556,8 @@ var require_redact = __commonJS({
|
|
|
6556
6556
|
return null;
|
|
6557
6557
|
}
|
|
6558
6558
|
const pathStructure = /* @__PURE__ */ new Map();
|
|
6559
|
-
for (const
|
|
6560
|
-
const parts = parsePath(
|
|
6559
|
+
for (const path19 of pathsToClone) {
|
|
6560
|
+
const parts = parsePath(path19);
|
|
6561
6561
|
let current = pathStructure;
|
|
6562
6562
|
for (let i = 0; i < parts.length; i++) {
|
|
6563
6563
|
const part = parts[i];
|
|
@@ -6609,24 +6609,24 @@ var require_redact = __commonJS({
|
|
|
6609
6609
|
}
|
|
6610
6610
|
return cloneSelectively(obj2, pathStructure);
|
|
6611
6611
|
}
|
|
6612
|
-
function validatePath(
|
|
6613
|
-
if (typeof
|
|
6612
|
+
function validatePath(path19) {
|
|
6613
|
+
if (typeof path19 !== "string") {
|
|
6614
6614
|
throw new Error("Paths must be (non-empty) strings");
|
|
6615
6615
|
}
|
|
6616
|
-
if (
|
|
6616
|
+
if (path19 === "") {
|
|
6617
6617
|
throw new Error("Invalid redaction path ()");
|
|
6618
6618
|
}
|
|
6619
|
-
if (
|
|
6620
|
-
throw new Error(`Invalid redaction path (${
|
|
6619
|
+
if (path19.includes("..")) {
|
|
6620
|
+
throw new Error(`Invalid redaction path (${path19})`);
|
|
6621
6621
|
}
|
|
6622
|
-
if (
|
|
6623
|
-
throw new Error(`Invalid redaction path (${
|
|
6622
|
+
if (path19.includes(",")) {
|
|
6623
|
+
throw new Error(`Invalid redaction path (${path19})`);
|
|
6624
6624
|
}
|
|
6625
6625
|
let bracketCount = 0;
|
|
6626
6626
|
let inQuotes = false;
|
|
6627
6627
|
let quoteChar = "";
|
|
6628
|
-
for (let i = 0; i <
|
|
6629
|
-
const char =
|
|
6628
|
+
for (let i = 0; i < path19.length; i++) {
|
|
6629
|
+
const char = path19[i];
|
|
6630
6630
|
if ((char === '"' || char === "'") && bracketCount > 0) {
|
|
6631
6631
|
if (!inQuotes) {
|
|
6632
6632
|
inQuotes = true;
|
|
@@ -6640,20 +6640,20 @@ var require_redact = __commonJS({
|
|
|
6640
6640
|
} else if (char === "]" && !inQuotes) {
|
|
6641
6641
|
bracketCount--;
|
|
6642
6642
|
if (bracketCount < 0) {
|
|
6643
|
-
throw new Error(`Invalid redaction path (${
|
|
6643
|
+
throw new Error(`Invalid redaction path (${path19})`);
|
|
6644
6644
|
}
|
|
6645
6645
|
}
|
|
6646
6646
|
}
|
|
6647
6647
|
if (bracketCount !== 0) {
|
|
6648
|
-
throw new Error(`Invalid redaction path (${
|
|
6648
|
+
throw new Error(`Invalid redaction path (${path19})`);
|
|
6649
6649
|
}
|
|
6650
6650
|
}
|
|
6651
6651
|
function validatePaths(paths) {
|
|
6652
6652
|
if (!Array.isArray(paths)) {
|
|
6653
6653
|
throw new TypeError("paths must be an array");
|
|
6654
6654
|
}
|
|
6655
|
-
for (const
|
|
6656
|
-
validatePath(
|
|
6655
|
+
for (const path19 of paths) {
|
|
6656
|
+
validatePath(path19);
|
|
6657
6657
|
}
|
|
6658
6658
|
}
|
|
6659
6659
|
function slowRedact(options = {}) {
|
|
@@ -6821,8 +6821,8 @@ var require_redaction = __commonJS({
|
|
|
6821
6821
|
if (shape[k] === null) {
|
|
6822
6822
|
o[k] = (value) => topCensor(value, [k]);
|
|
6823
6823
|
} else {
|
|
6824
|
-
const wrappedCensor = typeof censor === "function" ? (value,
|
|
6825
|
-
return censor(value, [k, ...
|
|
6824
|
+
const wrappedCensor = typeof censor === "function" ? (value, path19) => {
|
|
6825
|
+
return censor(value, [k, ...path19]);
|
|
6826
6826
|
} : censor;
|
|
6827
6827
|
o[k] = Redact({
|
|
6828
6828
|
paths: shape[k],
|
|
@@ -7043,7 +7043,7 @@ var require_sonic_boom = __commonJS({
|
|
|
7043
7043
|
var fs11 = __require("fs");
|
|
7044
7044
|
var EventEmitter5 = __require("events");
|
|
7045
7045
|
var inherits = __require("util").inherits;
|
|
7046
|
-
var
|
|
7046
|
+
var path19 = __require("path");
|
|
7047
7047
|
var sleep2 = require_atomic_sleep();
|
|
7048
7048
|
var assert2 = __require("assert");
|
|
7049
7049
|
var BUSY_WRITE_TIMEOUT = 100;
|
|
@@ -7097,7 +7097,7 @@ var require_sonic_boom = __commonJS({
|
|
|
7097
7097
|
const mode = sonic.mode;
|
|
7098
7098
|
if (sonic.sync) {
|
|
7099
7099
|
try {
|
|
7100
|
-
if (sonic.mkdir) fs11.mkdirSync(
|
|
7100
|
+
if (sonic.mkdir) fs11.mkdirSync(path19.dirname(file2), { recursive: true });
|
|
7101
7101
|
const fd = fs11.openSync(file2, flags, mode);
|
|
7102
7102
|
fileOpened(null, fd);
|
|
7103
7103
|
} catch (err) {
|
|
@@ -7105,7 +7105,7 @@ var require_sonic_boom = __commonJS({
|
|
|
7105
7105
|
throw err;
|
|
7106
7106
|
}
|
|
7107
7107
|
} else if (sonic.mkdir) {
|
|
7108
|
-
fs11.mkdir(
|
|
7108
|
+
fs11.mkdir(path19.dirname(file2), { recursive: true }, (err) => {
|
|
7109
7109
|
if (err) return fileOpened(err);
|
|
7110
7110
|
fs11.open(file2, flags, mode, fileOpened);
|
|
7111
7111
|
});
|
|
@@ -8437,15 +8437,15 @@ var require_transport = __commonJS({
|
|
|
8437
8437
|
if (!unquoted) {
|
|
8438
8438
|
return false;
|
|
8439
8439
|
}
|
|
8440
|
-
let
|
|
8441
|
-
if (
|
|
8440
|
+
let path19 = unquoted;
|
|
8441
|
+
if (path19.startsWith("file://")) {
|
|
8442
8442
|
try {
|
|
8443
|
-
|
|
8443
|
+
path19 = fileURLToPath5(path19);
|
|
8444
8444
|
} catch {
|
|
8445
8445
|
return false;
|
|
8446
8446
|
}
|
|
8447
8447
|
}
|
|
8448
|
-
return isAbsolute(
|
|
8448
|
+
return isAbsolute(path19) && !existsSync3(path19);
|
|
8449
8449
|
}
|
|
8450
8450
|
function stripQuotes(value) {
|
|
8451
8451
|
const first = value[0];
|
|
@@ -10139,7 +10139,7 @@ var require_multistream = __commonJS({
|
|
|
10139
10139
|
var require_pino = __commonJS({
|
|
10140
10140
|
"node_modules/pino/pino.js"(exports, module) {
|
|
10141
10141
|
"use strict";
|
|
10142
|
-
var
|
|
10142
|
+
var os6 = __require("node:os");
|
|
10143
10143
|
var stdSerializers = require_pino_std_serializers();
|
|
10144
10144
|
var caller = require_caller();
|
|
10145
10145
|
var redaction = require_redaction();
|
|
@@ -10186,7 +10186,7 @@ var require_pino = __commonJS({
|
|
|
10186
10186
|
} = symbols;
|
|
10187
10187
|
var { epochTime, nullTime } = time3;
|
|
10188
10188
|
var { pid } = process;
|
|
10189
|
-
var hostname4 =
|
|
10189
|
+
var hostname4 = os6.hostname();
|
|
10190
10190
|
var defaultErrorSerializer = stdSerializers.err;
|
|
10191
10191
|
var defaultOptions = {
|
|
10192
10192
|
level: "info",
|
|
@@ -11884,7 +11884,7 @@ var require_reply = __commonJS({
|
|
|
11884
11884
|
const trailerHeaders = Object.keys(reply[kReplyTrailers]);
|
|
11885
11885
|
const trailers = {};
|
|
11886
11886
|
let handled = 0;
|
|
11887
|
-
let
|
|
11887
|
+
let skipped2 = true;
|
|
11888
11888
|
let sent = false;
|
|
11889
11889
|
function send2() {
|
|
11890
11890
|
if (handled === 0 && !sent) {
|
|
@@ -11903,7 +11903,7 @@ var require_reply = __commonJS({
|
|
|
11903
11903
|
process.nextTick(send2);
|
|
11904
11904
|
};
|
|
11905
11905
|
if (typeof reply[kReplyTrailers][trailerName] !== "function") continue;
|
|
11906
|
-
|
|
11906
|
+
skipped2 = false;
|
|
11907
11907
|
handled--;
|
|
11908
11908
|
let cbAlreadyCalled = false;
|
|
11909
11909
|
const result = reply[kReplyTrailers][trailerName](reply, payload, cb);
|
|
@@ -11911,7 +11911,7 @@ var require_reply = __commonJS({
|
|
|
11911
11911
|
result.then((v) => cb(null, v), cb);
|
|
11912
11912
|
}
|
|
11913
11913
|
}
|
|
11914
|
-
if (
|
|
11914
|
+
if (skipped2) res.end(null, null, null);
|
|
11915
11915
|
}
|
|
11916
11916
|
function sendStreamTrailer(payload, res, reply) {
|
|
11917
11917
|
if (reply[kReplyTrailers] === null) return;
|
|
@@ -17121,8 +17121,8 @@ var require_utils = __commonJS({
|
|
|
17121
17121
|
}
|
|
17122
17122
|
return ind;
|
|
17123
17123
|
}
|
|
17124
|
-
function removeDotSegments(
|
|
17125
|
-
let input =
|
|
17124
|
+
function removeDotSegments(path19) {
|
|
17125
|
+
let input = path19;
|
|
17126
17126
|
const output = [];
|
|
17127
17127
|
let nextSlash = -1;
|
|
17128
17128
|
let len = 0;
|
|
@@ -17374,8 +17374,8 @@ var require_schemes = __commonJS({
|
|
|
17374
17374
|
wsComponent.secure = void 0;
|
|
17375
17375
|
}
|
|
17376
17376
|
if (wsComponent.resourceName) {
|
|
17377
|
-
const [
|
|
17378
|
-
wsComponent.path =
|
|
17377
|
+
const [path19, query2] = wsComponent.resourceName.split("?");
|
|
17378
|
+
wsComponent.path = path19 && path19 !== "/" ? path19 : void 0;
|
|
17379
17379
|
wsComponent.query = query2;
|
|
17380
17380
|
wsComponent.resourceName = void 0;
|
|
17381
17381
|
}
|
|
@@ -22312,8 +22312,8 @@ var require_utils2 = __commonJS({
|
|
|
22312
22312
|
}
|
|
22313
22313
|
return ind;
|
|
22314
22314
|
}
|
|
22315
|
-
function removeDotSegments(
|
|
22316
|
-
let input =
|
|
22315
|
+
function removeDotSegments(path19) {
|
|
22316
|
+
let input = path19;
|
|
22317
22317
|
const output = [];
|
|
22318
22318
|
let nextSlash = -1;
|
|
22319
22319
|
let len = 0;
|
|
@@ -22658,8 +22658,8 @@ var require_schemes2 = __commonJS({
|
|
|
22658
22658
|
wsComponent.secure = void 0;
|
|
22659
22659
|
}
|
|
22660
22660
|
if (wsComponent.resourceName) {
|
|
22661
|
-
const [
|
|
22662
|
-
wsComponent.path =
|
|
22661
|
+
const [path19, query2] = wsComponent.resourceName.split("?");
|
|
22662
|
+
wsComponent.path = path19 && path19 !== "/" ? path19 : void 0;
|
|
22663
22663
|
wsComponent.query = query2;
|
|
22664
22664
|
wsComponent.resourceName = void 0;
|
|
22665
22665
|
}
|
|
@@ -24143,8 +24143,8 @@ var require_utils3 = __commonJS({
|
|
|
24143
24143
|
}
|
|
24144
24144
|
return ind;
|
|
24145
24145
|
}
|
|
24146
|
-
function removeDotSegments(
|
|
24147
|
-
let input =
|
|
24146
|
+
function removeDotSegments(path19) {
|
|
24147
|
+
let input = path19;
|
|
24148
24148
|
const output = [];
|
|
24149
24149
|
let nextSlash = -1;
|
|
24150
24150
|
let len = 0;
|
|
@@ -24489,8 +24489,8 @@ var require_schemes3 = __commonJS({
|
|
|
24489
24489
|
wsComponent.secure = void 0;
|
|
24490
24490
|
}
|
|
24491
24491
|
if (wsComponent.resourceName) {
|
|
24492
|
-
const [
|
|
24493
|
-
wsComponent.path =
|
|
24492
|
+
const [path19, query2] = wsComponent.resourceName.split("?");
|
|
24493
|
+
wsComponent.path = path19 && path19 !== "/" ? path19 : void 0;
|
|
24494
24494
|
wsComponent.query = query2;
|
|
24495
24495
|
wsComponent.resourceName = void 0;
|
|
24496
24496
|
}
|
|
@@ -32007,13 +32007,13 @@ var require_node = __commonJS({
|
|
|
32007
32007
|
this.staticChildrenNodes[index] = node;
|
|
32008
32008
|
}
|
|
32009
32009
|
}
|
|
32010
|
-
findStaticMatchingChild(
|
|
32011
|
-
const charCode =
|
|
32010
|
+
findStaticMatchingChild(path19, pathIndex) {
|
|
32011
|
+
const charCode = path19.charCodeAt(pathIndex);
|
|
32012
32012
|
const charCodes = this.staticChildrenCharCodes;
|
|
32013
32013
|
for (let i = 0; i < charCodes.length; i++) {
|
|
32014
32014
|
if (charCodes[i] === charCode) {
|
|
32015
32015
|
const staticChild = this.staticChildrenNodes[i];
|
|
32016
|
-
if (staticChild.matchPrefix(
|
|
32016
|
+
if (staticChild.matchPrefix(path19, pathIndex)) {
|
|
32017
32017
|
return staticChild;
|
|
32018
32018
|
}
|
|
32019
32019
|
return null;
|
|
@@ -32021,34 +32021,34 @@ var require_node = __commonJS({
|
|
|
32021
32021
|
}
|
|
32022
32022
|
return null;
|
|
32023
32023
|
}
|
|
32024
|
-
getStaticChild(
|
|
32025
|
-
if (
|
|
32024
|
+
getStaticChild(path19, pathIndex = 0) {
|
|
32025
|
+
if (path19.length === pathIndex) {
|
|
32026
32026
|
return this;
|
|
32027
32027
|
}
|
|
32028
|
-
const staticChild = this.findStaticMatchingChild(
|
|
32028
|
+
const staticChild = this.findStaticMatchingChild(path19, pathIndex);
|
|
32029
32029
|
if (staticChild) {
|
|
32030
|
-
return staticChild.getStaticChild(
|
|
32030
|
+
return staticChild.getStaticChild(path19, pathIndex + staticChild.prefix.length);
|
|
32031
32031
|
}
|
|
32032
32032
|
return null;
|
|
32033
32033
|
}
|
|
32034
|
-
createStaticChild(
|
|
32035
|
-
if (
|
|
32034
|
+
createStaticChild(path19) {
|
|
32035
|
+
if (path19.length === 0) {
|
|
32036
32036
|
return this;
|
|
32037
32037
|
}
|
|
32038
|
-
const childIndex = this.staticChildrenCharCodes.indexOf(
|
|
32038
|
+
const childIndex = this.staticChildrenCharCodes.indexOf(path19.charCodeAt(0));
|
|
32039
32039
|
let staticChild = childIndex === -1 ? void 0 : this.staticChildrenNodes[childIndex];
|
|
32040
32040
|
if (staticChild) {
|
|
32041
32041
|
let i = 1;
|
|
32042
32042
|
for (; i < staticChild.prefix.length; i++) {
|
|
32043
|
-
if (
|
|
32043
|
+
if (path19.charCodeAt(i) !== staticChild.prefix.charCodeAt(i)) {
|
|
32044
32044
|
staticChild = staticChild.split(this, i);
|
|
32045
32045
|
break;
|
|
32046
32046
|
}
|
|
32047
32047
|
}
|
|
32048
|
-
return staticChild.createStaticChild(
|
|
32048
|
+
return staticChild.createStaticChild(path19.slice(i));
|
|
32049
32049
|
}
|
|
32050
|
-
const node = new StaticNode(
|
|
32051
|
-
this.setStaticChild(
|
|
32050
|
+
const node = new StaticNode(path19);
|
|
32051
|
+
this.setStaticChild(path19.charAt(0), node);
|
|
32052
32052
|
return node;
|
|
32053
32053
|
}
|
|
32054
32054
|
};
|
|
@@ -32108,8 +32108,8 @@ var require_node = __commonJS({
|
|
|
32108
32108
|
parentNode.setStaticChild(parentPrefix.charAt(0), staticNode);
|
|
32109
32109
|
return staticNode;
|
|
32110
32110
|
}
|
|
32111
|
-
getNextNode(
|
|
32112
|
-
let node = this.findStaticMatchingChild(
|
|
32111
|
+
getNextNode(path19, pathIndex, nodeStack, paramsCount) {
|
|
32112
|
+
let node = this.findStaticMatchingChild(path19, pathIndex);
|
|
32113
32113
|
let parametricBrotherNodeIndex = 0;
|
|
32114
32114
|
if (node === null) {
|
|
32115
32115
|
if (this.parametricChildren.length === 0) {
|
|
@@ -32156,8 +32156,8 @@ var require_node = __commonJS({
|
|
|
32156
32156
|
this.kind = NODE_TYPES.PARAMETRIC;
|
|
32157
32157
|
this.nodePaths = /* @__PURE__ */ new Set([nodePath2]);
|
|
32158
32158
|
}
|
|
32159
|
-
getNextNode(
|
|
32160
|
-
return this.findStaticMatchingChild(
|
|
32159
|
+
getNextNode(path19, pathIndex) {
|
|
32160
|
+
return this.findStaticMatchingChild(path19, pathIndex);
|
|
32161
32161
|
}
|
|
32162
32162
|
};
|
|
32163
32163
|
var WildcardNode = class extends Node {
|
|
@@ -32513,81 +32513,81 @@ var require_url_sanitizer = __commonJS({
|
|
|
32513
32513
|
return String.fromCharCode(charCode);
|
|
32514
32514
|
}
|
|
32515
32515
|
var MIN_NATIVE_SCAN_LENGTH = 12;
|
|
32516
|
-
function safeDecodeURI(
|
|
32517
|
-
if (
|
|
32518
|
-
return safeDecodeURINativeScan(
|
|
32516
|
+
function safeDecodeURI(path19, useSemicolonDelimiter) {
|
|
32517
|
+
if (path19.length >= MIN_NATIVE_SCAN_LENGTH) {
|
|
32518
|
+
return safeDecodeURINativeScan(path19, useSemicolonDelimiter);
|
|
32519
32519
|
}
|
|
32520
|
-
return safeDecodeURICharScan(
|
|
32520
|
+
return safeDecodeURICharScan(path19, useSemicolonDelimiter, 1);
|
|
32521
32521
|
}
|
|
32522
|
-
function safeDecodeURINativeScan(
|
|
32523
|
-
const percentIndex =
|
|
32524
|
-
let delimIndex =
|
|
32525
|
-
const hashIndex =
|
|
32522
|
+
function safeDecodeURINativeScan(path19, useSemicolonDelimiter) {
|
|
32523
|
+
const percentIndex = path19.indexOf("%", 1);
|
|
32524
|
+
let delimIndex = path19.indexOf("?", 1);
|
|
32525
|
+
const hashIndex = path19.indexOf("#", 1);
|
|
32526
32526
|
if (hashIndex !== -1 && (delimIndex === -1 || hashIndex < delimIndex)) {
|
|
32527
32527
|
delimIndex = hashIndex;
|
|
32528
32528
|
}
|
|
32529
32529
|
if (useSemicolonDelimiter) {
|
|
32530
|
-
const semicolonIndex =
|
|
32530
|
+
const semicolonIndex = path19.indexOf(";", 1);
|
|
32531
32531
|
if (semicolonIndex !== -1 && (delimIndex === -1 || semicolonIndex < delimIndex)) {
|
|
32532
32532
|
delimIndex = semicolonIndex;
|
|
32533
32533
|
}
|
|
32534
32534
|
}
|
|
32535
32535
|
if (percentIndex === -1 || delimIndex !== -1 && percentIndex > delimIndex) {
|
|
32536
32536
|
if (delimIndex === -1) {
|
|
32537
|
-
return { path:
|
|
32537
|
+
return { path: path19, querystring: "", shouldDecodeParam: false };
|
|
32538
32538
|
}
|
|
32539
32539
|
return {
|
|
32540
|
-
path:
|
|
32541
|
-
querystring:
|
|
32540
|
+
path: path19.slice(0, delimIndex),
|
|
32541
|
+
querystring: path19.slice(delimIndex + 1),
|
|
32542
32542
|
shouldDecodeParam: false
|
|
32543
32543
|
};
|
|
32544
32544
|
}
|
|
32545
|
-
return safeDecodeURIPercentScan(
|
|
32545
|
+
return safeDecodeURIPercentScan(path19, useSemicolonDelimiter, percentIndex);
|
|
32546
32546
|
}
|
|
32547
|
-
function safeDecodeURICharScan(
|
|
32548
|
-
for (let i = startIndex; i <
|
|
32549
|
-
const charCode =
|
|
32547
|
+
function safeDecodeURICharScan(path19, useSemicolonDelimiter, startIndex) {
|
|
32548
|
+
for (let i = startIndex; i < path19.length; i++) {
|
|
32549
|
+
const charCode = path19.charCodeAt(i);
|
|
32550
32550
|
if (charCode === 37) {
|
|
32551
|
-
return safeDecodeURIPercentScan(
|
|
32551
|
+
return safeDecodeURIPercentScan(path19, useSemicolonDelimiter, i);
|
|
32552
32552
|
} else if (charCode === 63 || charCode === 35 || charCode === 59 && useSemicolonDelimiter) {
|
|
32553
32553
|
return {
|
|
32554
|
-
path:
|
|
32555
|
-
querystring:
|
|
32554
|
+
path: path19.slice(0, i),
|
|
32555
|
+
querystring: path19.slice(i + 1),
|
|
32556
32556
|
shouldDecodeParam: false
|
|
32557
32557
|
};
|
|
32558
32558
|
}
|
|
32559
32559
|
}
|
|
32560
|
-
return { path:
|
|
32560
|
+
return { path: path19, querystring: "", shouldDecodeParam: false };
|
|
32561
32561
|
}
|
|
32562
|
-
function reencodePercentChar(
|
|
32563
|
-
return
|
|
32562
|
+
function reencodePercentChar(path19, index) {
|
|
32563
|
+
return path19.slice(0, index + 1) + "25" + path19.slice(index + 1);
|
|
32564
32564
|
}
|
|
32565
|
-
function safeDecodeURIPercentScan(
|
|
32565
|
+
function safeDecodeURIPercentScan(path19, useSemicolonDelimiter, startIndex) {
|
|
32566
32566
|
let shouldDecode = false;
|
|
32567
32567
|
let shouldDecodeParam = false;
|
|
32568
32568
|
let querystring = "";
|
|
32569
|
-
for (let i = startIndex; i <
|
|
32570
|
-
const charCode =
|
|
32569
|
+
for (let i = startIndex; i < path19.length; i++) {
|
|
32570
|
+
const charCode = path19.charCodeAt(i);
|
|
32571
32571
|
if (charCode === 37) {
|
|
32572
|
-
const componentCharCode = decodeComponentCharCode(
|
|
32572
|
+
const componentCharCode = decodeComponentCharCode(path19.charCodeAt(i + 1), path19.charCodeAt(i + 2));
|
|
32573
32573
|
if (componentCharCode === 0) {
|
|
32574
32574
|
shouldDecode = true;
|
|
32575
32575
|
} else {
|
|
32576
32576
|
shouldDecodeParam = true;
|
|
32577
32577
|
if (componentCharCode === 37) {
|
|
32578
32578
|
shouldDecode = true;
|
|
32579
|
-
|
|
32579
|
+
path19 = reencodePercentChar(path19, i);
|
|
32580
32580
|
i += 2;
|
|
32581
32581
|
}
|
|
32582
32582
|
i += 2;
|
|
32583
32583
|
}
|
|
32584
32584
|
} else if (charCode === 63 || charCode === 35 || charCode === 59 && useSemicolonDelimiter) {
|
|
32585
|
-
querystring =
|
|
32586
|
-
|
|
32585
|
+
querystring = path19.slice(i + 1);
|
|
32586
|
+
path19 = path19.slice(0, i);
|
|
32587
32587
|
break;
|
|
32588
32588
|
}
|
|
32589
32589
|
}
|
|
32590
|
-
const decodedPath = shouldDecode ? decodeURI(
|
|
32590
|
+
const decodedPath = shouldDecode ? decodeURI(path19) : path19;
|
|
32591
32591
|
return { path: decodedPath, querystring, shouldDecodeParam };
|
|
32592
32592
|
}
|
|
32593
32593
|
function safeDecodeURIComponent(uriComponent) {
|
|
@@ -32682,7 +32682,7 @@ var require_find_my_way = __commonJS({
|
|
|
32682
32682
|
this.trees = /* @__PURE__ */ Object.create(null);
|
|
32683
32683
|
this._treeGET = null;
|
|
32684
32684
|
}
|
|
32685
|
-
Router.prototype.on = function on(method,
|
|
32685
|
+
Router.prototype.on = function on(method, path19, opts, handler, store) {
|
|
32686
32686
|
if (typeof opts === "function") {
|
|
32687
32687
|
if (handler !== void 0) {
|
|
32688
32688
|
store = handler;
|
|
@@ -32690,34 +32690,34 @@ var require_find_my_way = __commonJS({
|
|
|
32690
32690
|
handler = opts;
|
|
32691
32691
|
opts = {};
|
|
32692
32692
|
}
|
|
32693
|
-
assert2(typeof
|
|
32694
|
-
assert2(
|
|
32695
|
-
assert2(
|
|
32693
|
+
assert2(typeof path19 === "string", "Path should be a string");
|
|
32694
|
+
assert2(path19.length > 0, "The path could not be empty");
|
|
32695
|
+
assert2(path19[0] === "/" || path19[0] === "*", "The first character of a path should be `/` or `*`");
|
|
32696
32696
|
assert2(typeof handler === "function", "Handler should be a function");
|
|
32697
|
-
const optionalParamMatch =
|
|
32697
|
+
const optionalParamMatch = path19.match(OPTIONAL_PARAM_REGEXP);
|
|
32698
32698
|
if (optionalParamMatch) {
|
|
32699
|
-
assert2(
|
|
32700
|
-
const pathFull =
|
|
32701
|
-
const pathOptional =
|
|
32699
|
+
assert2(path19.length === optionalParamMatch.index + optionalParamMatch[0].length, "Optional Parameter needs to be the last parameter of the path");
|
|
32700
|
+
const pathFull = path19.replace(OPTIONAL_PARAM_REGEXP, "$1$2");
|
|
32701
|
+
const pathOptional = path19.replace(OPTIONAL_PARAM_REGEXP, "$2") || "/";
|
|
32702
32702
|
this.on(method, pathFull, opts, handler, store);
|
|
32703
32703
|
this.on(method, pathOptional, opts, handler, store);
|
|
32704
32704
|
return;
|
|
32705
32705
|
}
|
|
32706
|
-
const route =
|
|
32706
|
+
const route = path19;
|
|
32707
32707
|
if (this.ignoreDuplicateSlashes) {
|
|
32708
|
-
|
|
32708
|
+
path19 = removeDuplicateSlashes(path19);
|
|
32709
32709
|
}
|
|
32710
32710
|
if (this.ignoreTrailingSlash) {
|
|
32711
|
-
|
|
32711
|
+
path19 = trimLastSlash(path19);
|
|
32712
32712
|
}
|
|
32713
32713
|
const methods = Array.isArray(method) ? method : [method];
|
|
32714
32714
|
for (const method2 of methods) {
|
|
32715
32715
|
assert2(typeof method2 === "string", "Method should be a string");
|
|
32716
32716
|
assert2(httpMethods.includes(method2), `Method '${method2}' is not an http method.`);
|
|
32717
|
-
this._on(method2,
|
|
32717
|
+
this._on(method2, path19, opts, handler, store, route);
|
|
32718
32718
|
}
|
|
32719
32719
|
};
|
|
32720
|
-
Router.prototype._on = function _on(method,
|
|
32720
|
+
Router.prototype._on = function _on(method, path19, opts, handler, store) {
|
|
32721
32721
|
let constraints = {};
|
|
32722
32722
|
if (opts.constraints !== void 0) {
|
|
32723
32723
|
assert2(typeof opts.constraints === "object" && opts.constraints !== null, "Constraints should be an object");
|
|
@@ -32730,7 +32730,7 @@ var require_find_my_way = __commonJS({
|
|
|
32730
32730
|
if (this.trees[method] === void 0) {
|
|
32731
32731
|
this.trees[method] = new StaticNode("/");
|
|
32732
32732
|
}
|
|
32733
|
-
let pattern =
|
|
32733
|
+
let pattern = path19;
|
|
32734
32734
|
if (pattern === "*" && this.trees[method].prefix.length !== 0) {
|
|
32735
32735
|
const currentRoot = this.trees[method];
|
|
32736
32736
|
this.trees[method] = new StaticNode("");
|
|
@@ -32838,19 +32838,19 @@ var require_find_my_way = __commonJS({
|
|
|
32838
32838
|
throw new Error(`Method '${method}' already declared for route '${pattern}' with constraints '${JSON.stringify(constraints)}'`);
|
|
32839
32839
|
}
|
|
32840
32840
|
}
|
|
32841
|
-
const route = { method, path:
|
|
32841
|
+
const route = { method, path: path19, pattern, params, opts, handler, store };
|
|
32842
32842
|
this.routes.push(route);
|
|
32843
32843
|
currentNode.addRoute(route, this.constrainer);
|
|
32844
32844
|
};
|
|
32845
|
-
Router.prototype.hasRoute = function hasRoute(method,
|
|
32846
|
-
const route = this.findRoute(method,
|
|
32845
|
+
Router.prototype.hasRoute = function hasRoute(method, path19, constraints) {
|
|
32846
|
+
const route = this.findRoute(method, path19, constraints);
|
|
32847
32847
|
return route !== null;
|
|
32848
32848
|
};
|
|
32849
|
-
Router.prototype.findRoute = function findNode(method,
|
|
32849
|
+
Router.prototype.findRoute = function findNode(method, path19, constraints = {}) {
|
|
32850
32850
|
if (this.trees[method] === void 0) {
|
|
32851
32851
|
return null;
|
|
32852
32852
|
}
|
|
32853
|
-
let pattern =
|
|
32853
|
+
let pattern = path19;
|
|
32854
32854
|
let currentNode = this.trees[method];
|
|
32855
32855
|
let parentNodePathIndex = currentNode.prefix.length;
|
|
32856
32856
|
const params = [];
|
|
@@ -32971,39 +32971,39 @@ var require_find_my_way = __commonJS({
|
|
|
32971
32971
|
this._treeGET = null;
|
|
32972
32972
|
this.routes = [];
|
|
32973
32973
|
};
|
|
32974
|
-
Router.prototype.off = function off(method,
|
|
32975
|
-
assert2(typeof
|
|
32976
|
-
assert2(
|
|
32977
|
-
assert2(
|
|
32974
|
+
Router.prototype.off = function off(method, path19, constraints) {
|
|
32975
|
+
assert2(typeof path19 === "string", "Path should be a string");
|
|
32976
|
+
assert2(path19.length > 0, "The path could not be empty");
|
|
32977
|
+
assert2(path19[0] === "/" || path19[0] === "*", "The first character of a path should be `/` or `*`");
|
|
32978
32978
|
assert2(
|
|
32979
32979
|
typeof constraints === "undefined" || typeof constraints === "object" && !Array.isArray(constraints) && constraints !== null,
|
|
32980
32980
|
"Constraints should be an object or undefined."
|
|
32981
32981
|
);
|
|
32982
|
-
const optionalParamMatch =
|
|
32982
|
+
const optionalParamMatch = path19.match(OPTIONAL_PARAM_REGEXP);
|
|
32983
32983
|
if (optionalParamMatch) {
|
|
32984
|
-
assert2(
|
|
32985
|
-
const pathFull =
|
|
32986
|
-
const pathOptional =
|
|
32984
|
+
assert2(path19.length === optionalParamMatch.index + optionalParamMatch[0].length, "Optional Parameter needs to be the last parameter of the path");
|
|
32985
|
+
const pathFull = path19.replace(OPTIONAL_PARAM_REGEXP, "$1$2");
|
|
32986
|
+
const pathOptional = path19.replace(OPTIONAL_PARAM_REGEXP, "$2") || "/";
|
|
32987
32987
|
this.off(method, pathFull, constraints);
|
|
32988
32988
|
this.off(method, pathOptional, constraints);
|
|
32989
32989
|
return;
|
|
32990
32990
|
}
|
|
32991
32991
|
if (this.ignoreDuplicateSlashes) {
|
|
32992
|
-
|
|
32992
|
+
path19 = removeDuplicateSlashes(path19);
|
|
32993
32993
|
}
|
|
32994
32994
|
if (this.ignoreTrailingSlash) {
|
|
32995
|
-
|
|
32995
|
+
path19 = trimLastSlash(path19);
|
|
32996
32996
|
}
|
|
32997
32997
|
const methods = Array.isArray(method) ? method : [method];
|
|
32998
32998
|
for (const method2 of methods) {
|
|
32999
|
-
this._off(method2,
|
|
32999
|
+
this._off(method2, path19, constraints);
|
|
33000
33000
|
}
|
|
33001
33001
|
};
|
|
33002
|
-
Router.prototype._off = function _off(method,
|
|
33002
|
+
Router.prototype._off = function _off(method, path19, constraints) {
|
|
33003
33003
|
assert2(typeof method === "string", "Method should be a string");
|
|
33004
33004
|
assert2(httpMethods.includes(method), `Method '${method}' is not an http method.`);
|
|
33005
33005
|
function matcherWithoutConstraints(route) {
|
|
33006
|
-
return method !== route.method ||
|
|
33006
|
+
return method !== route.method || path19 !== route.path;
|
|
33007
33007
|
}
|
|
33008
33008
|
function matcherWithConstraints(route) {
|
|
33009
33009
|
return matcherWithoutConstraints(route) || !deepEqual(constraints, route.opts.constraints || {});
|
|
@@ -33040,37 +33040,37 @@ var require_find_my_way = __commonJS({
|
|
|
33040
33040
|
if (handle === null) return this._defaultRoute(req, res, ctx);
|
|
33041
33041
|
return ctx === void 0 ? handle.handler(req, res, handle.params, handle.store, handle.searchParams) : handle.handler.call(ctx, req, res, handle.params, handle.store, handle.searchParams);
|
|
33042
33042
|
};
|
|
33043
|
-
Router.prototype.find = function find(method,
|
|
33043
|
+
Router.prototype.find = function find(method, path19, derivedConstraints) {
|
|
33044
33044
|
let currentNode = method === "GET" ? this._treeGET : this.trees[method];
|
|
33045
33045
|
if (currentNode == null) return null;
|
|
33046
|
-
if (
|
|
33047
|
-
|
|
33046
|
+
if (path19.charCodeAt(0) !== 47) {
|
|
33047
|
+
path19 = path19.replace(FULL_PATH_REGEXP, "/");
|
|
33048
33048
|
}
|
|
33049
33049
|
if (this.ignoreDuplicateSlashes) {
|
|
33050
|
-
|
|
33050
|
+
path19 = removeDuplicateSlashes(path19);
|
|
33051
33051
|
}
|
|
33052
33052
|
let sanitizedUrl;
|
|
33053
33053
|
let querystring2;
|
|
33054
33054
|
let shouldDecodeParam;
|
|
33055
33055
|
try {
|
|
33056
|
-
sanitizedUrl =
|
|
33057
|
-
|
|
33056
|
+
sanitizedUrl = path19.length >= MIN_NATIVE_SCAN_LENGTH ? safeDecodeURINativeScan(path19, this.useSemicolonDelimiter) : safeDecodeURICharScan(path19, this.useSemicolonDelimiter, 1);
|
|
33057
|
+
path19 = sanitizedUrl.path;
|
|
33058
33058
|
querystring2 = sanitizedUrl.querystring;
|
|
33059
33059
|
shouldDecodeParam = sanitizedUrl.shouldDecodeParam;
|
|
33060
33060
|
} catch (error51) {
|
|
33061
|
-
return this._onBadUrl(
|
|
33061
|
+
return this._onBadUrl(path19);
|
|
33062
33062
|
}
|
|
33063
33063
|
if (this.ignoreTrailingSlash) {
|
|
33064
|
-
|
|
33064
|
+
path19 = trimLastSlash(path19);
|
|
33065
33065
|
}
|
|
33066
|
-
const originPath =
|
|
33066
|
+
const originPath = path19;
|
|
33067
33067
|
if (this.caseSensitive === false) {
|
|
33068
|
-
|
|
33068
|
+
path19 = path19.toLowerCase();
|
|
33069
33069
|
}
|
|
33070
33070
|
const maxParamLength = this.maxParamLength;
|
|
33071
33071
|
let pathIndex = currentNode.prefix.length;
|
|
33072
33072
|
const params = [];
|
|
33073
|
-
const pathLen =
|
|
33073
|
+
const pathLen = path19.length;
|
|
33074
33074
|
const brothersNodesStack = [];
|
|
33075
33075
|
let maxParamLengthExceeded = false;
|
|
33076
33076
|
while (true) {
|
|
@@ -33085,7 +33085,7 @@ var require_find_my_way = __commonJS({
|
|
|
33085
33085
|
};
|
|
33086
33086
|
}
|
|
33087
33087
|
}
|
|
33088
|
-
let node = currentNode.getNextNode(
|
|
33088
|
+
let node = currentNode.getNextNode(path19, pathIndex, brothersNodesStack, params.length);
|
|
33089
33089
|
if (node === null) {
|
|
33090
33090
|
if (brothersNodesStack.length === 0) {
|
|
33091
33091
|
if (maxParamLengthExceeded && this.onMaxParamLength) {
|
|
@@ -33186,8 +33186,8 @@ var require_find_my_way = __commonJS({
|
|
|
33186
33186
|
Router.prototype._rebuild = function(routes) {
|
|
33187
33187
|
this.reset();
|
|
33188
33188
|
for (const route of routes) {
|
|
33189
|
-
const { method, path:
|
|
33190
|
-
this._on(method,
|
|
33189
|
+
const { method, path: path19, opts, handler, store } = route;
|
|
33190
|
+
this._on(method, path19, opts, handler, store);
|
|
33191
33191
|
}
|
|
33192
33192
|
};
|
|
33193
33193
|
Router.prototype._defaultRoute = function(req, res, ctx) {
|
|
@@ -33198,24 +33198,24 @@ var require_find_my_way = __commonJS({
|
|
|
33198
33198
|
res.end();
|
|
33199
33199
|
}
|
|
33200
33200
|
};
|
|
33201
|
-
Router.prototype._onBadUrl = function(
|
|
33201
|
+
Router.prototype._onBadUrl = function(path19) {
|
|
33202
33202
|
if (this.onBadUrl === null) {
|
|
33203
33203
|
return null;
|
|
33204
33204
|
}
|
|
33205
33205
|
const onBadUrl = this.onBadUrl;
|
|
33206
33206
|
return {
|
|
33207
|
-
handler: (req, res, ctx) => onBadUrl(
|
|
33207
|
+
handler: (req, res, ctx) => onBadUrl(path19, req, res),
|
|
33208
33208
|
params: {},
|
|
33209
33209
|
store: null
|
|
33210
33210
|
};
|
|
33211
33211
|
};
|
|
33212
|
-
Router.prototype._onMaxParamLength = function(
|
|
33212
|
+
Router.prototype._onMaxParamLength = function(path19) {
|
|
33213
33213
|
if (this.onMaxParamLength === null) {
|
|
33214
33214
|
return null;
|
|
33215
33215
|
}
|
|
33216
33216
|
const onMaxParamLength = this.onMaxParamLength;
|
|
33217
33217
|
return {
|
|
33218
|
-
handler: (req, res, ctx) => onMaxParamLength(
|
|
33218
|
+
handler: (req, res, ctx) => onMaxParamLength(path19, req, res),
|
|
33219
33219
|
params: {},
|
|
33220
33220
|
store: null
|
|
33221
33221
|
};
|
|
@@ -33247,12 +33247,12 @@ var require_find_my_way = __commonJS({
|
|
|
33247
33247
|
if (!httpMethods.hasOwnProperty(i)) continue;
|
|
33248
33248
|
const m = httpMethods[i];
|
|
33249
33249
|
const methodName = m.toLowerCase();
|
|
33250
|
-
Router.prototype[methodName] = function(
|
|
33251
|
-
return this.on(m,
|
|
33250
|
+
Router.prototype[methodName] = function(path19, handler, store) {
|
|
33251
|
+
return this.on(m, path19, handler, store);
|
|
33252
33252
|
};
|
|
33253
33253
|
}
|
|
33254
|
-
Router.prototype.all = function(
|
|
33255
|
-
this.on(httpMethods,
|
|
33254
|
+
Router.prototype.all = function(path19, handler, store) {
|
|
33255
|
+
this.on(httpMethods, path19, handler, store);
|
|
33256
33256
|
};
|
|
33257
33257
|
Router.sanitizeUrlPath = function sanitizeUrlPath(url2, useSemicolonDelimiter) {
|
|
33258
33258
|
const decoded = safeDecodeURI(url2, useSemicolonDelimiter);
|
|
@@ -33267,14 +33267,14 @@ var require_find_my_way = __commonJS({
|
|
|
33267
33267
|
function escapeRegExp(string4) {
|
|
33268
33268
|
return string4.replace(ESCAPE_REGEXP, "\\$&");
|
|
33269
33269
|
}
|
|
33270
|
-
function removeDuplicateSlashes(
|
|
33271
|
-
return
|
|
33270
|
+
function removeDuplicateSlashes(path19) {
|
|
33271
|
+
return path19.indexOf("//") !== -1 ? path19.replace(REMOVE_DUPLICATE_SLASHES_REGEXP, "/") : path19;
|
|
33272
33272
|
}
|
|
33273
|
-
function trimLastSlash(
|
|
33274
|
-
if (
|
|
33275
|
-
return
|
|
33273
|
+
function trimLastSlash(path19) {
|
|
33274
|
+
if (path19.length > 1 && path19.charCodeAt(path19.length - 1) === 47) {
|
|
33275
|
+
return path19.slice(0, -1);
|
|
33276
33276
|
}
|
|
33277
|
-
return
|
|
33277
|
+
return path19;
|
|
33278
33278
|
}
|
|
33279
33279
|
function trimRegExpStartAndEnd(regexString) {
|
|
33280
33280
|
if (regexString.charCodeAt(1) === 94) {
|
|
@@ -33285,22 +33285,22 @@ var require_find_my_way = __commonJS({
|
|
|
33285
33285
|
}
|
|
33286
33286
|
return regexString;
|
|
33287
33287
|
}
|
|
33288
|
-
function getClosingParenthensePosition(
|
|
33288
|
+
function getClosingParenthensePosition(path19, idx) {
|
|
33289
33289
|
let parentheses = 1;
|
|
33290
|
-
while (idx <
|
|
33290
|
+
while (idx < path19.length) {
|
|
33291
33291
|
idx++;
|
|
33292
|
-
if (
|
|
33292
|
+
if (path19.charCodeAt(idx) === 92) {
|
|
33293
33293
|
idx++;
|
|
33294
33294
|
continue;
|
|
33295
33295
|
}
|
|
33296
|
-
if (
|
|
33296
|
+
if (path19.charCodeAt(idx) === 41) {
|
|
33297
33297
|
parentheses--;
|
|
33298
|
-
} else if (
|
|
33298
|
+
} else if (path19.charCodeAt(idx) === 40) {
|
|
33299
33299
|
parentheses++;
|
|
33300
33300
|
}
|
|
33301
33301
|
if (!parentheses) return idx;
|
|
33302
33302
|
}
|
|
33303
|
-
throw new TypeError('Invalid regexp expression in "' +
|
|
33303
|
+
throw new TypeError('Invalid regexp expression in "' + path19 + '"');
|
|
33304
33304
|
}
|
|
33305
33305
|
function defaultBuildPrettyMeta(route) {
|
|
33306
33306
|
if (!route) return {};
|
|
@@ -33533,12 +33533,12 @@ var require_route = __commonJS({
|
|
|
33533
33533
|
function route({ options: options2, isFastify }) {
|
|
33534
33534
|
throwIfAlreadyStarted("Cannot add route!");
|
|
33535
33535
|
const opts = { ...options2 };
|
|
33536
|
-
const
|
|
33536
|
+
const path19 = opts.url || opts.path || "";
|
|
33537
33537
|
if (!opts.handler) {
|
|
33538
|
-
throw new FST_ERR_ROUTE_MISSING_HANDLER(opts.method,
|
|
33538
|
+
throw new FST_ERR_ROUTE_MISSING_HANDLER(opts.method, path19);
|
|
33539
33539
|
}
|
|
33540
33540
|
if (opts.errorHandler !== void 0 && typeof opts.errorHandler !== "function") {
|
|
33541
|
-
throw new FST_ERR_ROUTE_HANDLER_NOT_FN(opts.method,
|
|
33541
|
+
throw new FST_ERR_ROUTE_HANDLER_NOT_FN(opts.method, path19);
|
|
33542
33542
|
}
|
|
33543
33543
|
validateBodyLimitOption(opts.bodyLimit);
|
|
33544
33544
|
validateHandlerTimeoutOption(opts.handlerTimeout);
|
|
@@ -33548,22 +33548,22 @@ var require_route = __commonJS({
|
|
|
33548
33548
|
if (Array.isArray(opts.method)) {
|
|
33549
33549
|
for (let i = 0; i < opts.method.length; ++i) {
|
|
33550
33550
|
opts.method[i] = normalizeAndValidateMethod.call(this, opts.method[i]);
|
|
33551
|
-
validateSchemaBodyOption.call(this, opts.method[i],
|
|
33551
|
+
validateSchemaBodyOption.call(this, opts.method[i], path19, opts.schema);
|
|
33552
33552
|
isGetRoute = opts.method.includes("GET");
|
|
33553
33553
|
isHeadRoute = opts.method.includes("HEAD");
|
|
33554
33554
|
}
|
|
33555
33555
|
} else {
|
|
33556
33556
|
opts.method = normalizeAndValidateMethod.call(this, opts.method);
|
|
33557
|
-
validateSchemaBodyOption.call(this, opts.method,
|
|
33557
|
+
validateSchemaBodyOption.call(this, opts.method, path19, opts.schema);
|
|
33558
33558
|
isGetRoute = opts.method === "GET";
|
|
33559
33559
|
isHeadRoute = opts.method === "HEAD";
|
|
33560
33560
|
}
|
|
33561
33561
|
const headOpts = shouldExposeHead && isGetRoute ? { ...options2 } : null;
|
|
33562
33562
|
const prefix = this[kRoutePrefix];
|
|
33563
|
-
if (
|
|
33563
|
+
if (path19 === "/" && prefix.length > 0 && opts.method !== "HEAD") {
|
|
33564
33564
|
switch (opts.prefixTrailingSlash) {
|
|
33565
33565
|
case "slash":
|
|
33566
|
-
addNewRoute.call(this, { path:
|
|
33566
|
+
addNewRoute.call(this, { path: path19, isFastify });
|
|
33567
33567
|
break;
|
|
33568
33568
|
case "no-slash":
|
|
33569
33569
|
addNewRoute.call(this, { path: "", isFastify });
|
|
@@ -33572,20 +33572,20 @@ var require_route = __commonJS({
|
|
|
33572
33572
|
default:
|
|
33573
33573
|
addNewRoute.call(this, { path: "", isFastify });
|
|
33574
33574
|
if (ignoreTrailingSlash !== true && (ignoreDuplicateSlashes !== true || !prefix.endsWith("/"))) {
|
|
33575
|
-
addNewRoute.call(this, { path:
|
|
33575
|
+
addNewRoute.call(this, { path: path19, prefixing: true, isFastify });
|
|
33576
33576
|
}
|
|
33577
33577
|
}
|
|
33578
|
-
} else if (
|
|
33579
|
-
addNewRoute.call(this, { path:
|
|
33578
|
+
} else if (path19[0] === "/" && prefix.endsWith("/")) {
|
|
33579
|
+
addNewRoute.call(this, { path: path19.slice(1), isFastify });
|
|
33580
33580
|
} else {
|
|
33581
|
-
addNewRoute.call(this, { path:
|
|
33581
|
+
addNewRoute.call(this, { path: path19, isFastify });
|
|
33582
33582
|
}
|
|
33583
33583
|
return this;
|
|
33584
|
-
function addNewRoute({ path:
|
|
33585
|
-
const url2 = prefix +
|
|
33584
|
+
function addNewRoute({ path: path20, prefixing = false, isFastify: isFastify2 = false }) {
|
|
33585
|
+
const url2 = prefix + path20;
|
|
33586
33586
|
opts.url = url2;
|
|
33587
33587
|
opts.path = url2;
|
|
33588
|
-
opts.routePath =
|
|
33588
|
+
opts.routePath = path20;
|
|
33589
33589
|
opts.prefix = prefix;
|
|
33590
33590
|
opts.logLevel = opts.logLevel || this[kLogLevel];
|
|
33591
33591
|
validateLogLevelOption(opts.logLevel, opts.method, opts.url, logger);
|
|
@@ -33717,7 +33717,7 @@ var require_route = __commonJS({
|
|
|
33717
33717
|
});
|
|
33718
33718
|
if (shouldExposeHead && isGetRoute && !isHeadRoute && !hasHEADHandler) {
|
|
33719
33719
|
const onSendHandlers = parseHeadOnSendHandlers(headOpts.onSend);
|
|
33720
|
-
prepareRoute.call(this, { method: "HEAD", url:
|
|
33720
|
+
prepareRoute.call(this, { method: "HEAD", url: path20, options: { ...headOpts, onSend: onSendHandlers }, isFastify: true });
|
|
33721
33721
|
}
|
|
33722
33722
|
}
|
|
33723
33723
|
}
|
|
@@ -33841,9 +33841,9 @@ var require_route = __commonJS({
|
|
|
33841
33841
|
}
|
|
33842
33842
|
return method;
|
|
33843
33843
|
}
|
|
33844
|
-
function validateSchemaBodyOption(method,
|
|
33844
|
+
function validateSchemaBodyOption(method, path19, schema) {
|
|
33845
33845
|
if (this[kSupportedHTTPMethods].bodyless.has(method) && schema?.body) {
|
|
33846
|
-
throw new FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED(method,
|
|
33846
|
+
throw new FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED(method, path19);
|
|
33847
33847
|
}
|
|
33848
33848
|
}
|
|
33849
33849
|
function validateBodyLimitOption(bodyLimit) {
|
|
@@ -33858,11 +33858,11 @@ var require_route = __commonJS({
|
|
|
33858
33858
|
throw new FST_ERR_ROUTE_HANDLER_TIMEOUT_OPTION_NOT_INT(handlerTimeout);
|
|
33859
33859
|
}
|
|
33860
33860
|
}
|
|
33861
|
-
function validateLogLevelOption(logLevel, method,
|
|
33861
|
+
function validateLogLevelOption(logLevel, method, path19, logger) {
|
|
33862
33862
|
if (logLevel == null || logLevel === "") return;
|
|
33863
33863
|
if (logger?.levels?.values == null) return;
|
|
33864
33864
|
if (typeof logLevel !== "string" || logger.levels.values[logLevel] === void 0) {
|
|
33865
|
-
throw new FST_ERR_ROUTE_LOG_LEVEL_INVALID(method,
|
|
33865
|
+
throw new FST_ERR_ROUTE_LOG_LEVEL_INVALID(method, path19, logLevel);
|
|
33866
33866
|
}
|
|
33867
33867
|
}
|
|
33868
33868
|
function runPreParsing(err, request, reply) {
|
|
@@ -33951,7 +33951,7 @@ var require_four_oh_four = __commonJS({
|
|
|
33951
33951
|
});
|
|
33952
33952
|
}
|
|
33953
33953
|
function createRouteEventHandler() {
|
|
33954
|
-
return function onRouteEvent(
|
|
33954
|
+
return function onRouteEvent(path19, req, res) {
|
|
33955
33955
|
const fourOhFourContext = this[kFourOhFourLevelInstance][kFourOhFourContext];
|
|
33956
33956
|
const id = getGenReqId(fourOhFourContext.server, req);
|
|
33957
33957
|
const childLogger = createChildLogger(fourOhFourContext, logger, req, id);
|
|
@@ -36622,19 +36622,19 @@ var require_fastify = __commonJS({
|
|
|
36622
36622
|
}
|
|
36623
36623
|
fourOhFour.router.lookup(req, res);
|
|
36624
36624
|
}
|
|
36625
|
-
function onBadUrl(
|
|
36625
|
+
function onBadUrl(path19, req, res) {
|
|
36626
36626
|
if (options.frameworkErrors) {
|
|
36627
36627
|
const id = getGenReqId(routeEventContext.server, req);
|
|
36628
36628
|
const childLogger = createChildLogger(routeEventContext, options.logger, req, id);
|
|
36629
36629
|
const request = new Request(id, null, req, null, childLogger, routeEventContext);
|
|
36630
36630
|
const reply = new Reply(res, request, childLogger);
|
|
36631
36631
|
routeEventContext.server[kLogController].incomingRequest(request, reply);
|
|
36632
|
-
return options.frameworkErrors(new FST_ERR_BAD_URL(
|
|
36632
|
+
return options.frameworkErrors(new FST_ERR_BAD_URL(path19), request, reply);
|
|
36633
36633
|
}
|
|
36634
36634
|
const body = JSON.stringify({
|
|
36635
36635
|
error: "Bad Request",
|
|
36636
36636
|
code: "FST_ERR_BAD_URL",
|
|
36637
|
-
message: `'${
|
|
36637
|
+
message: `'${path19}' is not a valid url component`,
|
|
36638
36638
|
statusCode: 400
|
|
36639
36639
|
});
|
|
36640
36640
|
res.writeHead(400, {
|
|
@@ -36643,19 +36643,19 @@ var require_fastify = __commonJS({
|
|
|
36643
36643
|
});
|
|
36644
36644
|
res.end(body);
|
|
36645
36645
|
}
|
|
36646
|
-
function onMaxParamLength(
|
|
36646
|
+
function onMaxParamLength(path19, req, res) {
|
|
36647
36647
|
if (options.frameworkErrors) {
|
|
36648
36648
|
const id = getGenReqId(routeEventContext.server, req);
|
|
36649
36649
|
const childLogger = createChildLogger(routeEventContext, options.logger, req, id);
|
|
36650
36650
|
const request = new Request(id, null, req, null, childLogger, routeEventContext);
|
|
36651
36651
|
const reply = new Reply(res, request, childLogger);
|
|
36652
36652
|
routeEventContext.server[kLogController].incomingRequest(request, reply);
|
|
36653
|
-
return options.frameworkErrors(new FST_ERR_MAX_PARAM_LENGTH(
|
|
36653
|
+
return options.frameworkErrors(new FST_ERR_MAX_PARAM_LENGTH(path19), request, reply);
|
|
36654
36654
|
}
|
|
36655
36655
|
const body = JSON.stringify({
|
|
36656
36656
|
error: "Bad Request",
|
|
36657
36657
|
code: "FST_ERR_MAX_PARAM_LENGTH",
|
|
36658
|
-
message: `'${
|
|
36658
|
+
message: `'${path19}' is exceeding the max param length`,
|
|
36659
36659
|
statusCode: 414
|
|
36660
36660
|
});
|
|
36661
36661
|
res.writeHead(414, {
|
|
@@ -41001,13 +41001,13 @@ var require_websocket_server = __commonJS({
|
|
|
41001
41001
|
// src/server.ts
|
|
41002
41002
|
var import_fastify = __toESM(require_fastify(), 1);
|
|
41003
41003
|
var import_cors = __toESM(require_cors(), 1);
|
|
41004
|
-
import
|
|
41004
|
+
import path18 from "node:path";
|
|
41005
41005
|
|
|
41006
41006
|
// src/db/index.ts
|
|
41007
41007
|
import Database from "better-sqlite3";
|
|
41008
41008
|
var db;
|
|
41009
|
-
function initDb(
|
|
41010
|
-
db = new Database(
|
|
41009
|
+
function initDb(path19 = "data.db") {
|
|
41010
|
+
db = new Database(path19);
|
|
41011
41011
|
db.pragma("journal_mode = WAL");
|
|
41012
41012
|
db.pragma("foreign_keys = ON");
|
|
41013
41013
|
createTables(db);
|
|
@@ -41139,6 +41139,15 @@ function createTables(database) {
|
|
|
41139
41139
|
updated_at TEXT NOT NULL
|
|
41140
41140
|
);
|
|
41141
41141
|
|
|
41142
|
+
-- Codex threads the pane started or forked (main threads, rewind and
|
|
41143
|
+
-- branch forks, discussion threads), kept after the session or thread that
|
|
41144
|
+
-- used them is gone: the Codex import never lists them as outside work.
|
|
41145
|
+
CREATE TABLE IF NOT EXISTS codex_threads (
|
|
41146
|
+
thread_id TEXT PRIMARY KEY,
|
|
41147
|
+
session_id TEXT,
|
|
41148
|
+
created_at TEXT NOT NULL
|
|
41149
|
+
);
|
|
41150
|
+
|
|
41142
41151
|
CREATE INDEX IF NOT EXISTS idx_turns_session_id ON turns(session_id);
|
|
41143
41152
|
CREATE INDEX IF NOT EXISTS idx_items_turn_id ON items(turn_id);
|
|
41144
41153
|
CREATE INDEX IF NOT EXISTS idx_workspaces_path ON workspaces(path);
|
|
@@ -41673,7 +41682,7 @@ function handleTerminalUpgrade(request, socket, head) {
|
|
|
41673
41682
|
}
|
|
41674
41683
|
|
|
41675
41684
|
// src/routes/sessions.ts
|
|
41676
|
-
import
|
|
41685
|
+
import path3 from "node:path";
|
|
41677
41686
|
|
|
41678
41687
|
// node_modules/uuid/dist/esm/stringify.js
|
|
41679
41688
|
var byteToHex = [];
|
|
@@ -41965,6 +41974,45 @@ function startTurn(db2, session, { prompt, attachments, originAppId }) {
|
|
|
41965
41974
|
return parsedTurn;
|
|
41966
41975
|
}
|
|
41967
41976
|
|
|
41977
|
+
// src/providers/attachment-files.ts
|
|
41978
|
+
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
41979
|
+
import os2 from "node:os";
|
|
41980
|
+
import path2 from "node:path";
|
|
41981
|
+
function sessionDir(sessionId) {
|
|
41982
|
+
let base = path2.join(os2.tmpdir(), "agentpane");
|
|
41983
|
+
try {
|
|
41984
|
+
const file2 = getDb().name;
|
|
41985
|
+
if (file2 && file2 !== ":memory:") base = path2.dirname(path2.resolve(file2));
|
|
41986
|
+
} catch {
|
|
41987
|
+
}
|
|
41988
|
+
return path2.join(base, "attachments", sessionId.replace(/[^\w.-]/g, "_"));
|
|
41989
|
+
}
|
|
41990
|
+
function safeName(name) {
|
|
41991
|
+
const base = path2.basename(name || "attachment").replace(/[^\w.\- ()]/g, "_").trim();
|
|
41992
|
+
return base && base !== "." && base !== ".." ? base : "attachment";
|
|
41993
|
+
}
|
|
41994
|
+
function freeName(name, taken) {
|
|
41995
|
+
const ext = path2.extname(name);
|
|
41996
|
+
let free = name;
|
|
41997
|
+
for (let n = 2; taken.has(free.toLowerCase()); n++) free = `${name.slice(0, name.length - ext.length)}-${n}${ext}`;
|
|
41998
|
+
taken.add(free.toLowerCase());
|
|
41999
|
+
return free;
|
|
42000
|
+
}
|
|
42001
|
+
function saveAttachmentFile(sessionId, turnId, name, base643, taken = /* @__PURE__ */ new Set()) {
|
|
42002
|
+
const dir = path2.join(sessionDir(sessionId), turnId.replace(/[^\w.-]/g, "_"));
|
|
42003
|
+
mkdirSync(dir, { recursive: true });
|
|
42004
|
+
const file2 = path2.join(dir, freeName(safeName(name), taken));
|
|
42005
|
+
writeFileSync(file2, Buffer.from(base643, "base64"));
|
|
42006
|
+
return file2;
|
|
42007
|
+
}
|
|
42008
|
+
function removeAttachmentFiles(sessionId) {
|
|
42009
|
+
try {
|
|
42010
|
+
rmSync(sessionDir(sessionId), { recursive: true, force: true });
|
|
42011
|
+
} catch (err) {
|
|
42012
|
+
console.warn(`[attachments] could not remove the files of session ${sessionId}: ${err.message}`);
|
|
42013
|
+
}
|
|
42014
|
+
}
|
|
42015
|
+
|
|
41968
42016
|
// src/routes/sessions.ts
|
|
41969
42017
|
async function registerSessionRoutes(fastify) {
|
|
41970
42018
|
fastify.get("/api/sessions", async () => {
|
|
@@ -42061,6 +42109,7 @@ async function registerSessionRoutes(fastify) {
|
|
|
42061
42109
|
db2.prepare("DELETE FROM items WHERE turn_id IN (SELECT id FROM turns WHERE session_id = ?)").run(id);
|
|
42062
42110
|
db2.prepare("DELETE FROM turns WHERE session_id = ?").run(id);
|
|
42063
42111
|
db2.prepare("DELETE FROM sessions WHERE id = ?").run(id);
|
|
42112
|
+
removeAttachmentFiles(id);
|
|
42064
42113
|
return { success: true };
|
|
42065
42114
|
});
|
|
42066
42115
|
fastify.patch("/api/sessions/:id", {
|
|
@@ -42126,8 +42175,8 @@ async function registerSessionRoutes(fastify) {
|
|
|
42126
42175
|
}
|
|
42127
42176
|
let workspaceChanged = false;
|
|
42128
42177
|
if (cwd !== void 0) {
|
|
42129
|
-
const oldAbs = existing.cwd ?
|
|
42130
|
-
const newAbs = cwd ?
|
|
42178
|
+
const oldAbs = existing.cwd ? path3.resolve(existing.cwd) : null;
|
|
42179
|
+
const newAbs = cwd ? path3.resolve(cwd) : null;
|
|
42131
42180
|
workspaceChanged = oldAbs !== newAbs;
|
|
42132
42181
|
if (workspaceChanged && existing.is_running) {
|
|
42133
42182
|
return reply.code(409).send({ error: "Cannot change workspace while a turn is running" });
|
|
@@ -42575,7 +42624,7 @@ function recoverInterruptedTurns(db2, opts) {
|
|
|
42575
42624
|
WHERE i.status = 'in_progress'`
|
|
42576
42625
|
).all();
|
|
42577
42626
|
const orphaned = open.filter((i) => !skip.entries.has(runtimeEntryKey(i.session_id, i.thread_id)));
|
|
42578
|
-
const
|
|
42627
|
+
const stopTask3 = db2.prepare(
|
|
42579
42628
|
`UPDATE items SET data = json_set(COALESCE(data, '{}'), '$.status', 'stopped')
|
|
42580
42629
|
WHERE id = ? AND json_valid(COALESCE(data, '{}'))`
|
|
42581
42630
|
);
|
|
@@ -42583,7 +42632,7 @@ function recoverInterruptedTurns(db2, opts) {
|
|
|
42583
42632
|
const items = { changes: 0 };
|
|
42584
42633
|
db2.transaction(() => {
|
|
42585
42634
|
for (const item of orphaned) {
|
|
42586
|
-
if (item.type === "background_task")
|
|
42635
|
+
if (item.type === "background_task") stopTask3.run(item.id);
|
|
42587
42636
|
items.changes += failItem.run(now, item.id).changes;
|
|
42588
42637
|
}
|
|
42589
42638
|
})();
|
|
@@ -42953,6 +43002,28 @@ async function registerTurnRoutes(fastify) {
|
|
|
42953
43002
|
markSessionTouched(db2, id);
|
|
42954
43003
|
return { success: true };
|
|
42955
43004
|
});
|
|
43005
|
+
fastify.post(
|
|
43006
|
+
"/api/sessions/:id/tasks/:taskId/stop",
|
|
43007
|
+
async (request, reply) => {
|
|
43008
|
+
const { id, taskId } = request.params;
|
|
43009
|
+
const db2 = getDb();
|
|
43010
|
+
const session = db2.prepare("SELECT runtime_type FROM sessions WHERE id = ?").get(id);
|
|
43011
|
+
if (!session) {
|
|
43012
|
+
return reply.code(404).send({ error: "Session not found" });
|
|
43013
|
+
}
|
|
43014
|
+
const provider = getProvider(session.runtime_type);
|
|
43015
|
+
if (!provider.stopTask) {
|
|
43016
|
+
return reply.code(501).send({ error: `${session.runtime_type} sessions cannot stop background tasks` });
|
|
43017
|
+
}
|
|
43018
|
+
try {
|
|
43019
|
+
await provider.stopTask(id, taskId);
|
|
43020
|
+
} catch (err) {
|
|
43021
|
+
return reply.code(409).send({ error: err.message });
|
|
43022
|
+
}
|
|
43023
|
+
markSessionTouched(db2, id);
|
|
43024
|
+
return { success: true };
|
|
43025
|
+
}
|
|
43026
|
+
);
|
|
42956
43027
|
fastify.post(
|
|
42957
43028
|
"/api/sessions/:id/turns/:turnId/resume",
|
|
42958
43029
|
async (request, reply) => {
|
|
@@ -43370,9 +43441,9 @@ async function browseFolder(input, opts = {}) {
|
|
|
43370
43441
|
const atHome = dir === nodePath.resolve(home);
|
|
43371
43442
|
const folders = await Promise.all(
|
|
43372
43443
|
names.slice(0, limit).map(async (name) => {
|
|
43373
|
-
const
|
|
43444
|
+
const path19 = nodePath.join(dir, name);
|
|
43374
43445
|
const skipProbe = atHome && HOME_STANDARD_FOLDERS.has(name) || dir === "/Volumes";
|
|
43375
|
-
return { name, path:
|
|
43446
|
+
return { name, path: path19, git: !skipProbe && await exists(nodePath.join(path19, ".git")) };
|
|
43376
43447
|
})
|
|
43377
43448
|
);
|
|
43378
43449
|
const parent = nodePath.dirname(dir);
|
|
@@ -43410,11 +43481,11 @@ async function registerWorkspaceRoutes(fastify) {
|
|
|
43410
43481
|
}
|
|
43411
43482
|
}
|
|
43412
43483
|
}, async (request, reply) => {
|
|
43413
|
-
const { path:
|
|
43414
|
-
if (!
|
|
43484
|
+
const { path: path19, label = null } = request.body || {};
|
|
43485
|
+
if (!path19 || !path19.trim()) {
|
|
43415
43486
|
return reply.code(400).send({ error: "Path is required" });
|
|
43416
43487
|
}
|
|
43417
|
-
const resolved = await resolveWorkspacePath(
|
|
43488
|
+
const resolved = await resolveWorkspacePath(path19);
|
|
43418
43489
|
if ("error" in resolved) {
|
|
43419
43490
|
return reply.code(400).send({ error: resolved.error });
|
|
43420
43491
|
}
|
|
@@ -43456,8 +43527,8 @@ async function registerWorkspaceRoutes(fastify) {
|
|
|
43456
43527
|
"-e",
|
|
43457
43528
|
'POSIX path of (choose folder with prompt "Select a workspace directory")'
|
|
43458
43529
|
]);
|
|
43459
|
-
const
|
|
43460
|
-
return { path:
|
|
43530
|
+
const path19 = stdout.trim().replace(/\/$/, "");
|
|
43531
|
+
return { path: path19 };
|
|
43461
43532
|
} catch {
|
|
43462
43533
|
return reply.code(204).send({ cancelled: true });
|
|
43463
43534
|
}
|
|
@@ -43473,11 +43544,11 @@ async function registerWorkspaceRoutes(fastify) {
|
|
|
43473
43544
|
}
|
|
43474
43545
|
}
|
|
43475
43546
|
}, async (request, reply) => {
|
|
43476
|
-
const { path:
|
|
43477
|
-
if (!
|
|
43547
|
+
const { path: path19 } = request.body || {};
|
|
43548
|
+
if (!path19 || !path19.trim()) {
|
|
43478
43549
|
return reply.code(400).send({ error: "Path is required" });
|
|
43479
43550
|
}
|
|
43480
|
-
const trimmedPath =
|
|
43551
|
+
const trimmedPath = path19.trim();
|
|
43481
43552
|
const db2 = getDb();
|
|
43482
43553
|
const existing = db2.prepare("SELECT * FROM workspaces WHERE path = ?").get(trimmedPath);
|
|
43483
43554
|
if (existing) {
|
|
@@ -44168,7 +44239,7 @@ async function registerFileRoutes(fastify) {
|
|
|
44168
44239
|
}
|
|
44169
44240
|
|
|
44170
44241
|
// src/routes/perf-log.ts
|
|
44171
|
-
import { appendFileSync, mkdirSync, renameSync, statSync } from "node:fs";
|
|
44242
|
+
import { appendFileSync, mkdirSync as mkdirSync2, renameSync, statSync } from "node:fs";
|
|
44172
44243
|
import { homedir as homedir2 } from "node:os";
|
|
44173
44244
|
import { dirname, join } from "node:path";
|
|
44174
44245
|
var MAX_BYTES = 5 * 1024 * 1024;
|
|
@@ -44211,17 +44282,17 @@ async function registerPerfLogRoutes(fastify) {
|
|
|
44211
44282
|
if (entries.length === 0) {
|
|
44212
44283
|
return reply.send({ written: 0 });
|
|
44213
44284
|
}
|
|
44214
|
-
const
|
|
44285
|
+
const path19 = perfLogPath();
|
|
44215
44286
|
try {
|
|
44216
|
-
|
|
44287
|
+
mkdirSync2(dirname(path19), { recursive: true });
|
|
44217
44288
|
try {
|
|
44218
|
-
if (statSync(
|
|
44219
|
-
renameSync(
|
|
44289
|
+
if (statSync(path19).size > MAX_BYTES) {
|
|
44290
|
+
renameSync(path19, `${path19}.1`);
|
|
44220
44291
|
}
|
|
44221
44292
|
} catch {
|
|
44222
44293
|
}
|
|
44223
44294
|
const lines = entries.map((e) => `${new Date(e.t).toISOString()} [${oneLine(e.cat)}] ${oneLine(e.msg)}`).join("\n");
|
|
44224
|
-
appendFileSync(
|
|
44295
|
+
appendFileSync(path19, `${lines}
|
|
44225
44296
|
`, "utf-8");
|
|
44226
44297
|
return reply.send({ written: entries.length });
|
|
44227
44298
|
} catch (err) {
|
|
@@ -44297,24 +44368,24 @@ import { existsSync } from "node:fs";
|
|
|
44297
44368
|
import http from "node:http";
|
|
44298
44369
|
import net from "node:net";
|
|
44299
44370
|
import crypto from "node:crypto";
|
|
44300
|
-
import
|
|
44301
|
-
import
|
|
44371
|
+
import os3 from "node:os";
|
|
44372
|
+
import path4 from "node:path";
|
|
44302
44373
|
import { mkdir, readdir as readdir2, symlink, lstat, access, readFile, writeFile, unlink } from "node:fs/promises";
|
|
44303
|
-
var VSCODE_WEB_DATA_DIR =
|
|
44374
|
+
var VSCODE_WEB_DATA_DIR = path4.join(os3.homedir(), ".repoburg", "vscode-web");
|
|
44304
44375
|
function resolveDesktopUserDir() {
|
|
44305
44376
|
if (process.platform === "darwin") {
|
|
44306
|
-
return
|
|
44377
|
+
return path4.join(os3.homedir(), "Library", "Application Support", "Code", "User");
|
|
44307
44378
|
}
|
|
44308
44379
|
if (process.platform === "win32" && process.env.APPDATA) {
|
|
44309
|
-
return
|
|
44380
|
+
return path4.join(process.env.APPDATA, "Code", "User");
|
|
44310
44381
|
}
|
|
44311
44382
|
if (process.platform === "linux") {
|
|
44312
|
-
return
|
|
44383
|
+
return path4.join(os3.homedir(), ".config", "Code", "User");
|
|
44313
44384
|
}
|
|
44314
44385
|
return null;
|
|
44315
44386
|
}
|
|
44316
44387
|
async function linkUnlessExists(src, dst) {
|
|
44317
|
-
await mkdir(
|
|
44388
|
+
await mkdir(path4.dirname(dst), { recursive: true });
|
|
44318
44389
|
try {
|
|
44319
44390
|
await lstat(dst);
|
|
44320
44391
|
return false;
|
|
@@ -44329,19 +44400,19 @@ function fileRegistryUri(dir) {
|
|
|
44329
44400
|
}
|
|
44330
44401
|
async function syncProfile(dataDir = VSCODE_WEB_DATA_DIR) {
|
|
44331
44402
|
try {
|
|
44332
|
-
const desktopExt =
|
|
44403
|
+
const desktopExt = path4.join(os3.homedir(), ".vscode", "extensions");
|
|
44333
44404
|
let entries;
|
|
44334
44405
|
try {
|
|
44335
44406
|
entries = await readdir2(desktopExt, { withFileTypes: true });
|
|
44336
44407
|
} catch {
|
|
44337
44408
|
return;
|
|
44338
44409
|
}
|
|
44339
|
-
const serverExt =
|
|
44410
|
+
const serverExt = path4.join(dataDir, "extensions");
|
|
44340
44411
|
const linkedFolders = [];
|
|
44341
44412
|
for (const entry of entries) {
|
|
44342
44413
|
if (!entry.isDirectory()) continue;
|
|
44343
|
-
const target =
|
|
44344
|
-
await linkUnlessExists(
|
|
44414
|
+
const target = path4.join(serverExt, entry.name);
|
|
44415
|
+
await linkUnlessExists(path4.join(desktopExt, entry.name), target);
|
|
44345
44416
|
const st = await lstat(target).catch(() => null);
|
|
44346
44417
|
if (st?.isSymbolicLink()) linkedFolders.push(entry.name);
|
|
44347
44418
|
}
|
|
@@ -44349,15 +44420,15 @@ async function syncProfile(dataDir = VSCODE_WEB_DATA_DIR) {
|
|
|
44349
44420
|
await pruneObsolete(serverExt, linkedFolders);
|
|
44350
44421
|
const desktopUser = resolveDesktopUserDir();
|
|
44351
44422
|
if (!desktopUser) return;
|
|
44352
|
-
const serverUser =
|
|
44423
|
+
const serverUser = path4.join(dataDir, "data", "User");
|
|
44353
44424
|
for (const item of ["settings.json", "keybindings.json", "snippets"]) {
|
|
44354
|
-
const src =
|
|
44425
|
+
const src = path4.join(desktopUser, item);
|
|
44355
44426
|
try {
|
|
44356
44427
|
await access(src);
|
|
44357
44428
|
} catch {
|
|
44358
44429
|
continue;
|
|
44359
44430
|
}
|
|
44360
|
-
await linkUnlessExists(src,
|
|
44431
|
+
await linkUnlessExists(src, path4.join(serverUser, item));
|
|
44361
44432
|
}
|
|
44362
44433
|
} catch {
|
|
44363
44434
|
}
|
|
@@ -44365,13 +44436,13 @@ async function syncProfile(dataDir = VSCODE_WEB_DATA_DIR) {
|
|
|
44365
44436
|
async function mergeExtensionRegistry(desktopExt, serverExt, linkedFolders) {
|
|
44366
44437
|
let desktopEntries = [];
|
|
44367
44438
|
try {
|
|
44368
|
-
desktopEntries = JSON.parse(await readFile(
|
|
44439
|
+
desktopEntries = JSON.parse(await readFile(path4.join(desktopExt, "extensions.json"), "utf8"));
|
|
44369
44440
|
} catch {
|
|
44370
44441
|
return;
|
|
44371
44442
|
}
|
|
44372
44443
|
const linked = new Set(linkedFolders);
|
|
44373
44444
|
const toAdd = desktopEntries.filter((e) => e.identifier?.id && linked.has(e.relativeLocation));
|
|
44374
|
-
const serverRegistryPath =
|
|
44445
|
+
const serverRegistryPath = path4.join(serverExt, "extensions.json");
|
|
44375
44446
|
let serverEntries = [];
|
|
44376
44447
|
try {
|
|
44377
44448
|
serverEntries = JSON.parse(await readFile(serverRegistryPath, "utf8"));
|
|
@@ -44381,13 +44452,13 @@ async function mergeExtensionRegistry(desktopExt, serverExt, linkedFolders) {
|
|
|
44381
44452
|
const additions = toAdd.filter((e) => !known.has(`${e.identifier.id.toLowerCase()}@${e.version}`));
|
|
44382
44453
|
if (additions.length === 0) return;
|
|
44383
44454
|
for (const entry of additions) {
|
|
44384
|
-
const dir =
|
|
44455
|
+
const dir = path4.join(serverExt, entry.relativeLocation);
|
|
44385
44456
|
serverEntries.push({ ...entry, location: fileRegistryUri(dir) });
|
|
44386
44457
|
}
|
|
44387
44458
|
await writeFile(serverRegistryPath, JSON.stringify(serverEntries));
|
|
44388
44459
|
}
|
|
44389
44460
|
async function pruneObsolete(serverExt, linkedFolders) {
|
|
44390
|
-
const obsoletePath =
|
|
44461
|
+
const obsoletePath = path4.join(serverExt, ".obsolete");
|
|
44391
44462
|
let obsolete;
|
|
44392
44463
|
try {
|
|
44393
44464
|
obsolete = JSON.parse(await readFile(obsoletePath, "utf8"));
|
|
@@ -44846,16 +44917,16 @@ function proxyHandler(request, reply) {
|
|
|
44846
44917
|
|
|
44847
44918
|
// src/routes/apps.ts
|
|
44848
44919
|
import fs6 from "node:fs";
|
|
44849
|
-
import
|
|
44920
|
+
import path10 from "node:path";
|
|
44850
44921
|
|
|
44851
44922
|
// src/apps/instances.ts
|
|
44852
44923
|
import fs3 from "node:fs";
|
|
44853
|
-
import
|
|
44924
|
+
import path6 from "node:path";
|
|
44854
44925
|
|
|
44855
44926
|
// src/apps/apps-registry.ts
|
|
44856
44927
|
import fs2 from "node:fs";
|
|
44857
|
-
import
|
|
44858
|
-
import
|
|
44928
|
+
import path5 from "node:path";
|
|
44929
|
+
import os4 from "node:os";
|
|
44859
44930
|
import { fileURLToPath } from "node:url";
|
|
44860
44931
|
|
|
44861
44932
|
// node_modules/lucide-static/icon-nodes.json
|
|
@@ -99079,10 +99150,10 @@ function setAppsRootOverride(root) {
|
|
|
99079
99150
|
rootOverride = root;
|
|
99080
99151
|
}
|
|
99081
99152
|
function appsRoot() {
|
|
99082
|
-
return rootOverride ?? process.env.AGENT_PANE_APPS_DIR ??
|
|
99153
|
+
return rootOverride ?? process.env.AGENT_PANE_APPS_DIR ?? path5.join(os4.homedir(), ".repoburg", "agent-pane", "apps");
|
|
99083
99154
|
}
|
|
99084
99155
|
function appDir(id) {
|
|
99085
|
-
return
|
|
99156
|
+
return path5.join(appsRoot(), id);
|
|
99086
99157
|
}
|
|
99087
99158
|
var examplesRootOverride = null;
|
|
99088
99159
|
function setExamplesRootOverride(root) {
|
|
@@ -99091,16 +99162,16 @@ function setExamplesRootOverride(root) {
|
|
|
99091
99162
|
function examplesRoot() {
|
|
99092
99163
|
if (examplesRootOverride) return examplesRootOverride;
|
|
99093
99164
|
if (process.env.AGENT_PANE_EXAMPLES_DIR) return process.env.AGENT_PANE_EXAMPLES_DIR;
|
|
99094
|
-
const here =
|
|
99095
|
-
for (const candidate of [
|
|
99165
|
+
const here = path5.dirname(fileURLToPath(import.meta.url));
|
|
99166
|
+
for (const candidate of [path5.resolve(here, "../../examples"), path5.resolve(here, "../../../examples")]) {
|
|
99096
99167
|
if (fs2.existsSync(candidate)) return candidate;
|
|
99097
99168
|
}
|
|
99098
99169
|
return null;
|
|
99099
99170
|
}
|
|
99100
99171
|
function isInAppFolder(cwd) {
|
|
99101
99172
|
if (!cwd) return false;
|
|
99102
|
-
const rel =
|
|
99103
|
-
return rel !== "" && !
|
|
99173
|
+
const rel = path5.relative(path5.resolve(appsRoot()), path5.resolve(cwd));
|
|
99174
|
+
return rel !== "" && !path5.isAbsolute(rel) && rel.split(path5.sep)[0] !== "..";
|
|
99104
99175
|
}
|
|
99105
99176
|
function appsConventions() {
|
|
99106
99177
|
return APPS_MD_SKELETON;
|
|
@@ -99109,7 +99180,7 @@ function ensureAppsRoot() {
|
|
|
99109
99180
|
const root = appsRoot();
|
|
99110
99181
|
fs2.mkdirSync(root, { recursive: true });
|
|
99111
99182
|
for (const name of ["CLAUDE.md", "AGENTS.md"]) {
|
|
99112
|
-
const file2 =
|
|
99183
|
+
const file2 = path5.join(root, name);
|
|
99113
99184
|
try {
|
|
99114
99185
|
if (fs2.existsSync(file2) && fs2.readFileSync(file2, "utf-8") === APPS_MD_FILE) continue;
|
|
99115
99186
|
fs2.writeFileSync(file2, APPS_MD_FILE);
|
|
@@ -99333,7 +99404,7 @@ folder's own CLAUDE.md / AGENTS.md. -->
|
|
|
99333
99404
|
${APPS_MD_SKELETON}`;
|
|
99334
99405
|
function readManifestIn(dir) {
|
|
99335
99406
|
try {
|
|
99336
|
-
const raw = fs2.readFileSync(
|
|
99407
|
+
const raw = fs2.readFileSync(path5.join(dir, "manifest.json"), "utf-8");
|
|
99337
99408
|
const parsed = JSON.parse(raw);
|
|
99338
99409
|
if (!parsed || typeof parsed.title !== "string") return null;
|
|
99339
99410
|
return {
|
|
@@ -99352,7 +99423,7 @@ function readManifest(id) {
|
|
|
99352
99423
|
}
|
|
99353
99424
|
function readAppFile(id, name) {
|
|
99354
99425
|
try {
|
|
99355
|
-
return fs2.readFileSync(
|
|
99426
|
+
return fs2.readFileSync(path5.join(appDir(id), name), "utf-8");
|
|
99356
99427
|
} catch {
|
|
99357
99428
|
return "";
|
|
99358
99429
|
}
|
|
@@ -99385,11 +99456,11 @@ function startAppsWatch(onAppChange) {
|
|
|
99385
99456
|
try {
|
|
99386
99457
|
watcher = fs2.watch(root, { recursive: true }, (_event, filename) => {
|
|
99387
99458
|
const rel = String(filename ?? "");
|
|
99388
|
-
const segs = rel.split(
|
|
99459
|
+
const segs = rel.split(path5.sep);
|
|
99389
99460
|
const appId = segs[0];
|
|
99390
99461
|
const file2 = segs[segs.length - 1];
|
|
99391
|
-
if (!appId || appId ===
|
|
99392
|
-
if (segs.length === 1 && isRegularFile(
|
|
99462
|
+
if (!appId || appId === path5.basename(root) || !APP_ID_RE.test(appId) || file2 === "state.json") return;
|
|
99463
|
+
if (segs.length === 1 && isRegularFile(path5.join(root, appId))) return;
|
|
99393
99464
|
const timer2 = pendingChanges.get(appId);
|
|
99394
99465
|
if (timer2) clearTimeout(timer2);
|
|
99395
99466
|
pendingChanges.set(
|
|
@@ -99460,7 +99531,7 @@ function getInstanceState(appId, workspace = "") {
|
|
|
99460
99531
|
const stored = readRow(appId, workspace);
|
|
99461
99532
|
if (stored) return stored;
|
|
99462
99533
|
if (workspace === "") {
|
|
99463
|
-
const legacyFile =
|
|
99534
|
+
const legacyFile = path6.join(appDir(appId), "state.json");
|
|
99464
99535
|
if (fs3.existsSync(legacyFile)) {
|
|
99465
99536
|
const legacy = readState(appId);
|
|
99466
99537
|
const imported = { pinned: legacy.pinned, data: legacy.data, version: 1 };
|
|
@@ -99493,9 +99564,9 @@ function resolveToolWorkspace(workspace) {
|
|
|
99493
99564
|
const rows = getDb().prepare("SELECT path, deleted FROM workspaces").all();
|
|
99494
99565
|
const active = rows.filter((w) => !w.deleted).map((w) => w.path);
|
|
99495
99566
|
if (active.includes(workspace)) return workspace;
|
|
99496
|
-
const cwd =
|
|
99567
|
+
const cwd = path6.isAbsolute(workspace) ? path6.resolve(workspace) : "";
|
|
99497
99568
|
if (isInAppFolder(cwd)) return "";
|
|
99498
|
-
const covering = rows.filter((w) => cwd === w.path || cwd.startsWith(w.path +
|
|
99569
|
+
const covering = rows.filter((w) => cwd === w.path || cwd.startsWith(w.path + path6.sep)).sort((a, b) => b.path.length - a.path.length)[0];
|
|
99499
99570
|
if (covering && !covering.deleted) return covering.path;
|
|
99500
99571
|
throw new Error(`Unknown workspace: ${workspace}. Known workspaces: ${active.join(", ") || "none"}`);
|
|
99501
99572
|
}
|
|
@@ -99507,7 +99578,7 @@ function deleteAppInstances(appId) {
|
|
|
99507
99578
|
import fs5 from "node:fs";
|
|
99508
99579
|
|
|
99509
99580
|
// src/apps/app-sessions.ts
|
|
99510
|
-
import
|
|
99581
|
+
import path8 from "node:path";
|
|
99511
99582
|
|
|
99512
99583
|
// src/sidecar/transcript-locator.ts
|
|
99513
99584
|
import { existsSync as existsSync2, readdirSync } from "node:fs";
|
|
@@ -99592,8 +99663,8 @@ function locateTranscriptCached(session) {
|
|
|
99592
99663
|
// src/apps/app-files.ts
|
|
99593
99664
|
import crypto2 from "node:crypto";
|
|
99594
99665
|
import fs4 from "node:fs";
|
|
99595
|
-
import
|
|
99596
|
-
import
|
|
99666
|
+
import os5 from "node:os";
|
|
99667
|
+
import path7 from "node:path";
|
|
99597
99668
|
var APP_FILE_MAX_BYTES = 5 * 1024 * 1024;
|
|
99598
99669
|
var APP_FILE_TYPES = {
|
|
99599
99670
|
"image/png": "png",
|
|
@@ -99618,11 +99689,11 @@ function setAppFilesRootOverride(root) {
|
|
|
99618
99689
|
rootOverride2 = root;
|
|
99619
99690
|
}
|
|
99620
99691
|
function appFilesRoot() {
|
|
99621
|
-
return rootOverride2 ?? process.env.AGENT_PANE_APP_FILES_DIR ??
|
|
99692
|
+
return rootOverride2 ?? process.env.AGENT_PANE_APP_FILES_DIR ?? path7.join(os5.homedir(), ".repoburg", "agent-pane", "app-files");
|
|
99622
99693
|
}
|
|
99623
99694
|
function appFilesDir(appId) {
|
|
99624
99695
|
if (!APP_ID_RE.test(appId)) throw new AppFileError("Invalid app id", 400);
|
|
99625
|
-
return
|
|
99696
|
+
return path7.join(appFilesRoot(), appId);
|
|
99626
99697
|
}
|
|
99627
99698
|
function appFileUrl(appId, fileId) {
|
|
99628
99699
|
return `/api/apps/${appId}/files/${fileId}`;
|
|
@@ -99683,7 +99754,7 @@ function saveAppFile(appId, upload) {
|
|
|
99683
99754
|
const type = sniffImageType(bytes);
|
|
99684
99755
|
if (!type) throw new AppFileError(`The file is not a ${ACCEPTED} image`, 400);
|
|
99685
99756
|
const fileId = `${crypto2.createHash("sha256").update(bytes).digest("hex")}.${APP_FILE_TYPES[type]}`;
|
|
99686
|
-
const file2 =
|
|
99757
|
+
const file2 = path7.join(dir, fileId);
|
|
99687
99758
|
if (!fs4.existsSync(file2)) {
|
|
99688
99759
|
fs4.mkdirSync(dir, { recursive: true });
|
|
99689
99760
|
const tmp = `${file2}.${process.pid}.${crypto2.randomBytes(4).toString("hex")}.tmp`;
|
|
@@ -99715,7 +99786,7 @@ function getAppFile(appId, ref) {
|
|
|
99715
99786
|
if (!APP_ID_RE.test(appId)) return null;
|
|
99716
99787
|
const fileId = appFileRefId(appId, ref);
|
|
99717
99788
|
if (!fileId) return null;
|
|
99718
|
-
const file2 =
|
|
99789
|
+
const file2 = path7.join(appFilesDir(appId), fileId);
|
|
99719
99790
|
try {
|
|
99720
99791
|
const stat2 = fs4.statSync(file2);
|
|
99721
99792
|
if (!stat2.isFile()) return null;
|
|
@@ -99727,7 +99798,7 @@ function getAppFile(appId, ref) {
|
|
|
99727
99798
|
function readAppFileData(appId, fileId) {
|
|
99728
99799
|
if (!APP_ID_RE.test(appId) || !APP_FILE_ID_RE.test(fileId)) return null;
|
|
99729
99800
|
try {
|
|
99730
|
-
return { bytes: fs4.readFileSync(
|
|
99801
|
+
return { bytes: fs4.readFileSync(path7.join(appFilesDir(appId), fileId)), type: fileType(fileId) };
|
|
99731
99802
|
} catch {
|
|
99732
99803
|
return null;
|
|
99733
99804
|
}
|
|
@@ -99837,7 +99908,7 @@ function appSessionInfo(appId, sessionId) {
|
|
|
99837
99908
|
function sessionVisibleTo(session, appId, workspace) {
|
|
99838
99909
|
if (!workspace) return true;
|
|
99839
99910
|
const cwd = session.cwd;
|
|
99840
|
-
if (cwd && (cwd === workspace || cwd.startsWith(workspace.endsWith(
|
|
99911
|
+
if (cwd && (cwd === workspace || cwd.startsWith(workspace.endsWith(path8.sep) ? workspace : workspace + path8.sep))) {
|
|
99841
99912
|
return true;
|
|
99842
99913
|
}
|
|
99843
99914
|
return session.origin_app_workspace === workspace && openedByApp(session, appId);
|
|
@@ -99932,7 +100003,7 @@ import vm2 from "node:vm";
|
|
|
99932
100003
|
|
|
99933
100004
|
// src/apps/app-compile.ts
|
|
99934
100005
|
import vm from "node:vm";
|
|
99935
|
-
import
|
|
100006
|
+
import path9 from "node:path";
|
|
99936
100007
|
import ts from "typescript";
|
|
99937
100008
|
|
|
99938
100009
|
// src/apps/app-lint.ts
|
|
@@ -100329,15 +100400,15 @@ function typeCheckModules(appId, modules) {
|
|
|
100329
100400
|
};
|
|
100330
100401
|
const host = ts.createCompilerHost(options);
|
|
100331
100402
|
const origReadFile = host.readFile.bind(host);
|
|
100332
|
-
host.readFile = (fname) =>
|
|
100403
|
+
host.readFile = (fname) => path9.basename(fname) === BRIDGE_DTS_FILE ? BRIDGE_DTS : origReadFile(fname);
|
|
100333
100404
|
host.writeFile = () => {
|
|
100334
100405
|
};
|
|
100335
|
-
const bridgePath =
|
|
100336
|
-
const rootNames = [...modules.map((m) =>
|
|
100406
|
+
const bridgePath = path9.join(dir, BRIDGE_DTS_FILE);
|
|
100407
|
+
const rootNames = [...modules.map((m) => path9.join(dir, m.file)), bridgePath];
|
|
100337
100408
|
const program = ts.createProgram(rootNames, options, host);
|
|
100338
100409
|
const out = [];
|
|
100339
100410
|
for (const mod of modules) {
|
|
100340
|
-
const sf = program.getSourceFile(
|
|
100411
|
+
const sf = program.getSourceFile(path9.join(dir, mod.file));
|
|
100341
100412
|
if (!sf) continue;
|
|
100342
100413
|
out.push(
|
|
100343
100414
|
...[...program.getSyntacticDiagnostics(sf), ...program.getSemanticDiagnostics(sf)].map((d) => tsDiagnosticToFile(mod.file, d)).filter((d) => d !== null)
|
|
@@ -100697,6 +100768,63 @@ function invalidateHeadlessRuntime(appId) {
|
|
|
100697
100768
|
}
|
|
100698
100769
|
}
|
|
100699
100770
|
|
|
100771
|
+
// src/providers/widget-spec.ts
|
|
100772
|
+
var WIDGET_TOOL_BASE_NAME = "show_widget";
|
|
100773
|
+
var WIDGET_CDN_ORIGINS = [
|
|
100774
|
+
"https://cdnjs.cloudflare.com",
|
|
100775
|
+
"https://cdn.jsdelivr.net",
|
|
100776
|
+
"https://unpkg.com",
|
|
100777
|
+
"https://esm.sh"
|
|
100778
|
+
];
|
|
100779
|
+
var WIDGET_INSTRUCTIONS = "AgentPane shows the result of show_widget inline in the chat, as a live visual. Use it when the user asks for a chart, diagram or other visual, and on your own when a visual explains something clearly better than text: numbers to compare, an architecture or flow to follow, a concept to explore. Keep routine progress updates and plain answers as text.";
|
|
100780
|
+
var WIDGET_TOOL_DESCRIPTION = [
|
|
100781
|
+
"Show a visual inline in the chat: a chart, diagram, flow, timeline, comparison, interactive explainer or small UI mockup, drawn from the HTML/SVG you pass. The user sees it right away, so do not repeat its content in your reply.",
|
|
100782
|
+
"",
|
|
100783
|
+
"widget_code is an HTML fragment, not a document: no <!DOCTYPE>, <html>, <head> or <body>. Order it <style> first, then the markup, then <script> last. The markup renders while you write it; scripts run once, after the whole fragment has arrived, and DOMContentLoaded and load fire again for them.",
|
|
100784
|
+
"",
|
|
100785
|
+
`Where it renders: a sandboxed iframe as wide as the chat column (up to 720px, narrower on small screens, so lay out fluidly; give SVG a viewBox and width 100%). The frame grows to fit the content, so never size anything from the frame: no 100vh, and give canvas charts a fixed-height wrapper (Chart.js: <div style="position:relative;height:320px"><canvas></canvas></div>). The background is transparent over the chat. The widget is offline except for these CDNs, which may serve scripts, stylesheets, fonts and data files: ${WIDGET_CDN_ORIGINS.join(", ")} (e.g. Chart.js, D3, Mermaid). Embed your data; storage, cookies and form submission do not work. Links open in a new browser tab.`,
|
|
100786
|
+
"",
|
|
100787
|
+
"Style with the chat's CSS variables, not hard-coded colors, so the widget matches it: --color-text-primary, --color-text-secondary, --color-text-muted, --color-background-primary (cards), --color-background-secondary (subtle fills), --color-border, --color-accent, --font-sans, --font-mono, --radius. Text defaults to 14px var(--font-sans) in --color-text-primary. Keep it calm: no gradients or heavy shadows, font weights 400-600, sentence case.",
|
|
100788
|
+
"",
|
|
100789
|
+
'Charts: color series with --color-series-1 to --color-series-8 (SVG: fill="var(--color-series-1)"), in that order (never skip or cycle; past 8 series, group the rest as "Other"). One y-axis per chart. A legend for 2+ series. Text, values and labels in text colors, never in series colors. Hover tooltips with exact values. --color-good, --color-warning, --color-serious and --color-critical are for states only, never for series. Read CSS variables in scripts with getComputedStyle(document.documentElement).getPropertyValue(name).',
|
|
100790
|
+
"",
|
|
100791
|
+
"Buttons, sliders, toggles and hover effects work inside the widget. Each call shows a new widget; to change one, call again with the complete new code."
|
|
100792
|
+
].join("\n");
|
|
100793
|
+
var WIDGET_SHOWN_RESULT = "The widget is now shown to the user inline in the chat.";
|
|
100794
|
+
var WIDGET_EMPTY_RESULT = "widget_code is empty, so nothing was shown.";
|
|
100795
|
+
var WIDGET_TITLE_DESCRIPTION = 'Short human-readable title shown above the widget, e.g. "Monthly revenue by region".';
|
|
100796
|
+
var WIDGET_CODE_DESCRIPTION = "The HTML fragment to render: <style>, then markup (HTML or inline SVG), then <script>.";
|
|
100797
|
+
|
|
100798
|
+
// src/codex/codex-widget.ts
|
|
100799
|
+
var CODEX_WIDGET_TOOL = {
|
|
100800
|
+
name: WIDGET_TOOL_BASE_NAME,
|
|
100801
|
+
description: `${WIDGET_INSTRUCTIONS}
|
|
100802
|
+
|
|
100803
|
+
${WIDGET_TOOL_DESCRIPTION}`,
|
|
100804
|
+
inputSchema: {
|
|
100805
|
+
type: "object",
|
|
100806
|
+
properties: {
|
|
100807
|
+
title: { type: "string", description: WIDGET_TITLE_DESCRIPTION },
|
|
100808
|
+
widget_code: { type: "string", description: WIDGET_CODE_DESCRIPTION }
|
|
100809
|
+
},
|
|
100810
|
+
required: ["title", "widget_code"]
|
|
100811
|
+
}
|
|
100812
|
+
};
|
|
100813
|
+
function servesCodexSession(sessionId) {
|
|
100814
|
+
if (!sessionId) return false;
|
|
100815
|
+
try {
|
|
100816
|
+
const row = getDb().prepare("SELECT runtime_type FROM sessions WHERE id = ?").get(sessionId);
|
|
100817
|
+
return row?.runtime_type === "codex";
|
|
100818
|
+
} catch {
|
|
100819
|
+
return false;
|
|
100820
|
+
}
|
|
100821
|
+
}
|
|
100822
|
+
function answerWidgetCall(args) {
|
|
100823
|
+
const code = args.widget_code;
|
|
100824
|
+
if (typeof code !== "string" || !code.trim()) return { ok: false, error: WIDGET_EMPTY_RESULT };
|
|
100825
|
+
return { ok: true, text: WIDGET_SHOWN_RESULT };
|
|
100826
|
+
}
|
|
100827
|
+
|
|
100700
100828
|
// src/apps/mcp-tools.ts
|
|
100701
100829
|
var TOOL_CALL_TIMEOUT_MS = Number(process.env.AGENT_PANE_TOOL_TIMEOUT_MS ?? 3e4);
|
|
100702
100830
|
var TOOL_NS = "__";
|
|
@@ -100719,6 +100847,14 @@ function listAppTools() {
|
|
|
100719
100847
|
}
|
|
100720
100848
|
return tools;
|
|
100721
100849
|
}
|
|
100850
|
+
function listGatewayTools(callerSessionId) {
|
|
100851
|
+
const tools = listAppTools();
|
|
100852
|
+
return servesCodexSession(callerSessionId) ? [CODEX_WIDGET_TOOL, ...tools] : tools;
|
|
100853
|
+
}
|
|
100854
|
+
function callPaneTool(toolName, args, callerSessionId) {
|
|
100855
|
+
if (toolName !== CODEX_WIDGET_TOOL.name || !servesCodexSession(callerSessionId)) return null;
|
|
100856
|
+
return answerWidgetCall(args);
|
|
100857
|
+
}
|
|
100722
100858
|
function splitToolName(name) {
|
|
100723
100859
|
const idx = name.indexOf(TOOL_NS);
|
|
100724
100860
|
if (idx <= 0 || idx === name.length - TOOL_NS.length) return null;
|
|
@@ -100849,7 +100985,10 @@ async function registerAppRoutes(fastify, opts) {
|
|
|
100849
100985
|
}
|
|
100850
100986
|
});
|
|
100851
100987
|
fastify.get("/api/apps/root", async () => ({ root: appsRoot() }));
|
|
100852
|
-
fastify.get(
|
|
100988
|
+
fastify.get(
|
|
100989
|
+
"/api/apps/mcp/tools",
|
|
100990
|
+
async (request) => listGatewayTools(request.query.session)
|
|
100991
|
+
);
|
|
100853
100992
|
fastify.get("/api/apps/examples", async () => {
|
|
100854
100993
|
const exRoot = examplesRoot();
|
|
100855
100994
|
if (!exRoot) return [];
|
|
@@ -100857,7 +100996,7 @@ async function registerAppRoutes(fastify, opts) {
|
|
|
100857
100996
|
try {
|
|
100858
100997
|
for (const entry of fs6.readdirSync(exRoot, { withFileTypes: true })) {
|
|
100859
100998
|
if (!entry.isDirectory() || !APP_ID_RE.test(entry.name)) continue;
|
|
100860
|
-
const manifest = readManifestIn(
|
|
100999
|
+
const manifest = readManifestIn(path10.join(exRoot, entry.name));
|
|
100861
101000
|
if (!manifest) continue;
|
|
100862
101001
|
out.push({
|
|
100863
101002
|
id: entry.name,
|
|
@@ -100878,7 +101017,7 @@ async function registerAppRoutes(fastify, opts) {
|
|
|
100878
101017
|
if (!APP_ID_RE.test(id)) return reply.code(400).send({ error: "Invalid app id" });
|
|
100879
101018
|
const exRoot = examplesRoot();
|
|
100880
101019
|
if (!exRoot) return reply.code(404).send({ error: "Examples catalog not available" });
|
|
100881
|
-
const src =
|
|
101020
|
+
const src = path10.join(exRoot, id);
|
|
100882
101021
|
if (!readManifestIn(src)) return reply.code(404).send({ error: "Example not found" });
|
|
100883
101022
|
if (readManifest(id)) return reply.code(409).send({ error: "App already installed" });
|
|
100884
101023
|
ensureAppsRoot();
|
|
@@ -100917,7 +101056,7 @@ async function registerAppRoutes(fastify, opts) {
|
|
|
100917
101056
|
fs6.mkdirSync(dir, { recursive: true });
|
|
100918
101057
|
const cleanTitle2 = title.trim();
|
|
100919
101058
|
fs6.writeFileSync(
|
|
100920
|
-
|
|
101059
|
+
path10.join(dir, "manifest.json"),
|
|
100921
101060
|
JSON.stringify(
|
|
100922
101061
|
{
|
|
100923
101062
|
title: cleanTitle2,
|
|
@@ -100928,8 +101067,8 @@ async function registerAppRoutes(fastify, opts) {
|
|
|
100928
101067
|
2
|
|
100929
101068
|
)
|
|
100930
101069
|
);
|
|
100931
|
-
fs6.writeFileSync(
|
|
100932
|
-
fs6.writeFileSync(
|
|
101070
|
+
fs6.writeFileSync(path10.join(dir, "index.html"), SKELETON_HTML.replaceAll("__TITLE__", cleanTitle2));
|
|
101071
|
+
fs6.writeFileSync(path10.join(dir, "app.ts"), SKELETON_TS);
|
|
100933
101072
|
return { ok: true, id };
|
|
100934
101073
|
}
|
|
100935
101074
|
);
|
|
@@ -100966,9 +101105,9 @@ async function registerAppRoutes(fastify, opts) {
|
|
|
100966
101105
|
const dir = appDir(id);
|
|
100967
101106
|
fs6.mkdirSync(dir, { recursive: true });
|
|
100968
101107
|
if (!Object.hasOwn(files ?? {}, "manifest.json")) {
|
|
100969
|
-
fs6.writeFileSync(
|
|
101108
|
+
fs6.writeFileSync(path10.join(dir, "manifest.json"), JSON.stringify({ title: id }, null, 2));
|
|
100970
101109
|
}
|
|
100971
|
-
for (const [name, content] of entries) fs6.writeFileSync(
|
|
101110
|
+
for (const [name, content] of entries) fs6.writeFileSync(path10.join(dir, name), content);
|
|
100972
101111
|
return { ok: true, id };
|
|
100973
101112
|
}
|
|
100974
101113
|
);
|
|
@@ -100990,6 +101129,8 @@ async function registerAppRoutes(fastify, opts) {
|
|
|
100990
101129
|
},
|
|
100991
101130
|
async (request, reply) => {
|
|
100992
101131
|
const { tool: tool2, args, workspace, caller } = request.body || {};
|
|
101132
|
+
const own = callPaneTool(tool2, args ?? {}, caller?.sessionId);
|
|
101133
|
+
if (own) return own;
|
|
100993
101134
|
try {
|
|
100994
101135
|
const result = await callAppTool(tool2, args ?? {}, resolveToolWorkspace(workspace), caller?.sessionId);
|
|
100995
101136
|
return { ok: true, result };
|
|
@@ -101283,7 +101424,7 @@ function buildSidecarPrompt(externalSessionId, transcriptPath, question) {
|
|
|
101283
101424
|
}
|
|
101284
101425
|
|
|
101285
101426
|
// src/routes/sidecar.ts
|
|
101286
|
-
var SIDECAR_RUNTIMES = /* @__PURE__ */ new Set(["claude"]);
|
|
101427
|
+
var SIDECAR_RUNTIMES = /* @__PURE__ */ new Set(["claude", "codex"]);
|
|
101287
101428
|
async function registerSidecarRoutes(fastify) {
|
|
101288
101429
|
fastify.post(
|
|
101289
101430
|
"/api/sessions/:sessionId/sidecar",
|
|
@@ -101898,7 +102039,7 @@ async function registerUsageRoutes(fastify) {
|
|
|
101898
102039
|
|
|
101899
102040
|
// src/claude/session-import.ts
|
|
101900
102041
|
import { readFile as readFile2, realpath } from "node:fs/promises";
|
|
101901
|
-
import
|
|
102042
|
+
import path11 from "node:path";
|
|
101902
102043
|
import { getSessionInfo, listSessions } from "@anthropic-ai/claude-agent-sdk";
|
|
101903
102044
|
|
|
101904
102045
|
// src/claude/widget-tool.ts
|
|
@@ -102670,10 +102811,10 @@ function mergeDefs(...defs) {
|
|
|
102670
102811
|
function cloneDef(schema) {
|
|
102671
102812
|
return mergeDefs(schema._zod.def);
|
|
102672
102813
|
}
|
|
102673
|
-
function getElementAtPath(obj2,
|
|
102674
|
-
if (!
|
|
102814
|
+
function getElementAtPath(obj2, path19) {
|
|
102815
|
+
if (!path19)
|
|
102675
102816
|
return obj2;
|
|
102676
|
-
return
|
|
102817
|
+
return path19.reduce((acc, key) => acc?.[key], obj2);
|
|
102677
102818
|
}
|
|
102678
102819
|
function promiseAllObject(promisesObj) {
|
|
102679
102820
|
const keys = Object.keys(promisesObj);
|
|
@@ -103082,11 +103223,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
103082
103223
|
}
|
|
103083
103224
|
return false;
|
|
103084
103225
|
}
|
|
103085
|
-
function prefixIssues(
|
|
103226
|
+
function prefixIssues(path19, issues) {
|
|
103086
103227
|
return issues.map((iss) => {
|
|
103087
103228
|
var _a3;
|
|
103088
103229
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
103089
|
-
iss.path.unshift(
|
|
103230
|
+
iss.path.unshift(path19);
|
|
103090
103231
|
return iss;
|
|
103091
103232
|
});
|
|
103092
103233
|
}
|
|
@@ -103233,16 +103374,16 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
|
|
|
103233
103374
|
}
|
|
103234
103375
|
function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
103235
103376
|
const fieldErrors = { _errors: [] };
|
|
103236
|
-
const processError = (error52,
|
|
103377
|
+
const processError = (error52, path19 = []) => {
|
|
103237
103378
|
for (const issue2 of error52.issues) {
|
|
103238
103379
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
103239
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
103380
|
+
issue2.errors.map((issues) => processError({ issues }, [...path19, ...issue2.path]));
|
|
103240
103381
|
} else if (issue2.code === "invalid_key") {
|
|
103241
|
-
processError({ issues: issue2.issues }, [...
|
|
103382
|
+
processError({ issues: issue2.issues }, [...path19, ...issue2.path]);
|
|
103242
103383
|
} else if (issue2.code === "invalid_element") {
|
|
103243
|
-
processError({ issues: issue2.issues }, [...
|
|
103384
|
+
processError({ issues: issue2.issues }, [...path19, ...issue2.path]);
|
|
103244
103385
|
} else {
|
|
103245
|
-
const fullpath = [...
|
|
103386
|
+
const fullpath = [...path19, ...issue2.path];
|
|
103246
103387
|
if (fullpath.length === 0) {
|
|
103247
103388
|
fieldErrors._errors.push(mapper(issue2));
|
|
103248
103389
|
} else {
|
|
@@ -103269,17 +103410,17 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
|
103269
103410
|
}
|
|
103270
103411
|
function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
103271
103412
|
const result = { errors: [] };
|
|
103272
|
-
const processError = (error52,
|
|
103413
|
+
const processError = (error52, path19 = []) => {
|
|
103273
103414
|
var _a3, _b;
|
|
103274
103415
|
for (const issue2 of error52.issues) {
|
|
103275
103416
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
103276
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
103417
|
+
issue2.errors.map((issues) => processError({ issues }, [...path19, ...issue2.path]));
|
|
103277
103418
|
} else if (issue2.code === "invalid_key") {
|
|
103278
|
-
processError({ issues: issue2.issues }, [...
|
|
103419
|
+
processError({ issues: issue2.issues }, [...path19, ...issue2.path]);
|
|
103279
103420
|
} else if (issue2.code === "invalid_element") {
|
|
103280
|
-
processError({ issues: issue2.issues }, [...
|
|
103421
|
+
processError({ issues: issue2.issues }, [...path19, ...issue2.path]);
|
|
103281
103422
|
} else {
|
|
103282
|
-
const fullpath = [...
|
|
103423
|
+
const fullpath = [...path19, ...issue2.path];
|
|
103283
103424
|
if (fullpath.length === 0) {
|
|
103284
103425
|
result.errors.push(mapper(issue2));
|
|
103285
103426
|
continue;
|
|
@@ -103311,8 +103452,8 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
|
103311
103452
|
}
|
|
103312
103453
|
function toDotPath(_path) {
|
|
103313
103454
|
const segs = [];
|
|
103314
|
-
const
|
|
103315
|
-
for (const seg of
|
|
103455
|
+
const path19 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
103456
|
+
for (const seg of path19) {
|
|
103316
103457
|
if (typeof seg === "number")
|
|
103317
103458
|
segs.push(`[${seg}]`);
|
|
103318
103459
|
else if (typeof seg === "symbol")
|
|
@@ -116004,13 +116145,13 @@ function resolveRef(ref, ctx) {
|
|
|
116004
116145
|
if (!ref.startsWith("#")) {
|
|
116005
116146
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
116006
116147
|
}
|
|
116007
|
-
const
|
|
116008
|
-
if (
|
|
116148
|
+
const path19 = ref.slice(1).split("/").filter(Boolean);
|
|
116149
|
+
if (path19.length === 0) {
|
|
116009
116150
|
return ctx.rootSchema;
|
|
116010
116151
|
}
|
|
116011
116152
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
116012
|
-
if (
|
|
116013
|
-
const key =
|
|
116153
|
+
if (path19[0] === defsKey) {
|
|
116154
|
+
const key = path19[1];
|
|
116014
116155
|
if (!key || !ctx.defs[key]) {
|
|
116015
116156
|
throw new Error(`Reference not found: ${ref}`);
|
|
116016
116157
|
}
|
|
@@ -116420,28 +116561,7 @@ config2(en_default());
|
|
|
116420
116561
|
|
|
116421
116562
|
// src/claude/widget-tool.ts
|
|
116422
116563
|
var WIDGET_SERVER_NAME = "agentpane";
|
|
116423
|
-
var WIDGET_TOOL_NAME = `mcp__${WIDGET_SERVER_NAME}
|
|
116424
|
-
var WIDGET_CDN_ORIGINS = [
|
|
116425
|
-
"https://cdnjs.cloudflare.com",
|
|
116426
|
-
"https://cdn.jsdelivr.net",
|
|
116427
|
-
"https://unpkg.com",
|
|
116428
|
-
"https://esm.sh"
|
|
116429
|
-
];
|
|
116430
|
-
var WIDGET_INSTRUCTIONS = "AgentPane shows the result of show_widget inline in the chat, as a live visual. Use it when the user asks for a chart, diagram or other visual, and on your own when a visual explains something clearly better than text: numbers to compare, an architecture or flow to follow, a concept to explore. Keep routine progress updates and plain answers as text.";
|
|
116431
|
-
var WIDGET_TOOL_DESCRIPTION = [
|
|
116432
|
-
"Show a visual inline in the chat: a chart, diagram, flow, timeline, comparison, interactive explainer or small UI mockup, drawn from the HTML/SVG you pass. The user sees it right away, so do not repeat its content in your reply.",
|
|
116433
|
-
"",
|
|
116434
|
-
"widget_code is an HTML fragment, not a document: no <!DOCTYPE>, <html>, <head> or <body>. Order it <style> first, then the markup, then <script> last. The markup renders while you write it; scripts run once, after the whole fragment has arrived, and DOMContentLoaded and load fire again for them.",
|
|
116435
|
-
"",
|
|
116436
|
-
`Where it renders: a sandboxed iframe as wide as the chat column (up to 720px, narrower on small screens, so lay out fluidly; give SVG a viewBox and width 100%). The frame grows to fit the content, so never size anything from the frame: no 100vh, and give canvas charts a fixed-height wrapper (Chart.js: <div style="position:relative;height:320px"><canvas></canvas></div>). The background is transparent over the chat. The widget is offline except for these CDNs, which may serve scripts, stylesheets, fonts and data files: ${WIDGET_CDN_ORIGINS.join(", ")} (e.g. Chart.js, D3, Mermaid). Embed your data; storage, cookies and form submission do not work. Links open in a new browser tab.`,
|
|
116437
|
-
"",
|
|
116438
|
-
"Style with the chat's CSS variables, not hard-coded colors, so the widget matches it: --color-text-primary, --color-text-secondary, --color-text-muted, --color-background-primary (cards), --color-background-secondary (subtle fills), --color-border, --color-accent, --font-sans, --font-mono, --radius. Text defaults to 14px var(--font-sans) in --color-text-primary. Keep it calm: no gradients or heavy shadows, font weights 400-600, sentence case.",
|
|
116439
|
-
"",
|
|
116440
|
-
'Charts: color series with --color-series-1 to --color-series-8 (SVG: fill="var(--color-series-1)"), in that order (never skip or cycle; past 8 series, group the rest as "Other"). One y-axis per chart. A legend for 2+ series. Text, values and labels in text colors, never in series colors. Hover tooltips with exact values. --color-good, --color-warning, --color-serious and --color-critical are for states only, never for series. Read CSS variables in scripts with getComputedStyle(document.documentElement).getPropertyValue(name).',
|
|
116441
|
-
"",
|
|
116442
|
-
"Buttons, sliders, toggles and hover effects work inside the widget. Each call shows a new widget; to change one, call again with the complete new code."
|
|
116443
|
-
].join("\n");
|
|
116444
|
-
var SHOWN_RESULT = "The widget is now shown to the user inline in the chat.";
|
|
116564
|
+
var WIDGET_TOOL_NAME = `mcp__${WIDGET_SERVER_NAME}__${WIDGET_TOOL_BASE_NAME}`;
|
|
116445
116565
|
function createWidgetMcpServer() {
|
|
116446
116566
|
return createSdkMcpServer({
|
|
116447
116567
|
name: WIDGET_SERVER_NAME,
|
|
@@ -116450,17 +116570,17 @@ function createWidgetMcpServer() {
|
|
|
116450
116570
|
alwaysLoad: true,
|
|
116451
116571
|
tools: [
|
|
116452
116572
|
tool(
|
|
116453
|
-
|
|
116573
|
+
WIDGET_TOOL_BASE_NAME,
|
|
116454
116574
|
WIDGET_TOOL_DESCRIPTION,
|
|
116455
116575
|
{
|
|
116456
|
-
title: external_exports.string().describe(
|
|
116457
|
-
widget_code: external_exports.string().describe(
|
|
116576
|
+
title: external_exports.string().describe(WIDGET_TITLE_DESCRIPTION),
|
|
116577
|
+
widget_code: external_exports.string().describe(WIDGET_CODE_DESCRIPTION)
|
|
116458
116578
|
},
|
|
116459
116579
|
async ({ widget_code }) => {
|
|
116460
116580
|
if (!widget_code.trim()) {
|
|
116461
|
-
return { content: [{ type: "text", text:
|
|
116581
|
+
return { content: [{ type: "text", text: WIDGET_EMPTY_RESULT }], isError: true };
|
|
116462
116582
|
}
|
|
116463
|
-
return { content: [{ type: "text", text:
|
|
116583
|
+
return { content: [{ type: "text", text: WIDGET_SHOWN_RESULT }] };
|
|
116464
116584
|
}
|
|
116465
116585
|
)
|
|
116466
116586
|
]
|
|
@@ -116556,9 +116676,9 @@ function mapToolUse(block) {
|
|
|
116556
116676
|
};
|
|
116557
116677
|
}
|
|
116558
116678
|
function deriveFileChangeData(input, toolName) {
|
|
116559
|
-
const
|
|
116679
|
+
const path19 = input.file_path ?? input.notebook_path ?? "";
|
|
116560
116680
|
const kind = toolName === "Write" ? "add" : "modify";
|
|
116561
|
-
return { changes: [{ path:
|
|
116681
|
+
return { changes: [{ path: path19, kind }], status: "in_progress" };
|
|
116562
116682
|
}
|
|
116563
116683
|
function extractToolResultText(content) {
|
|
116564
116684
|
if (!content) return "";
|
|
@@ -116923,7 +117043,7 @@ async function realDir(dir) {
|
|
|
116923
117043
|
}
|
|
116924
117044
|
}
|
|
116925
117045
|
async function sameDir(a, realB) {
|
|
116926
|
-
const realA = await realDir(a) ??
|
|
117046
|
+
const realA = await realDir(a) ?? path11.resolve(a);
|
|
116927
117047
|
return realA === realB;
|
|
116928
117048
|
}
|
|
116929
117049
|
function knownClaudeSessionIds(db2) {
|
|
@@ -117089,9 +117209,523 @@ async function registerClaudeSessionRoutes(fastify) {
|
|
|
117089
117209
|
);
|
|
117090
117210
|
}
|
|
117091
117211
|
|
|
117092
|
-
// src/session-
|
|
117212
|
+
// src/codex/session-import.ts
|
|
117213
|
+
import { realpath as realpath2 } from "node:fs/promises";
|
|
117214
|
+
import path13 from "node:path";
|
|
117215
|
+
|
|
117216
|
+
// src/apps/register-mcp.ts
|
|
117093
117217
|
import fs7 from "node:fs";
|
|
117094
|
-
import
|
|
117218
|
+
import path12 from "node:path";
|
|
117219
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
117220
|
+
var MCP_SERVER_NAME = "agentpane-miniapps";
|
|
117221
|
+
function panePublicUrl() {
|
|
117222
|
+
return (process.env.AGENT_PANE_PUBLIC_URL || process.env.REPOBURG_DAEMON_URL || "http://localhost:9998").replace(/\/+$/, "");
|
|
117223
|
+
}
|
|
117224
|
+
function stdioScriptPath() {
|
|
117225
|
+
const here = path12.dirname(fileURLToPath2(import.meta.url));
|
|
117226
|
+
const candidates = [
|
|
117227
|
+
path12.resolve(here, "../../scripts/miniapp-mcp-stdio.mjs"),
|
|
117228
|
+
// src/apps/ → backend/scripts
|
|
117229
|
+
path12.resolve(here, "../scripts/miniapp-mcp-stdio.mjs")
|
|
117230
|
+
// dist bundle → backend/scripts
|
|
117231
|
+
];
|
|
117232
|
+
for (const candidate of candidates) {
|
|
117233
|
+
if (fs7.existsSync(candidate)) return candidate;
|
|
117234
|
+
}
|
|
117235
|
+
return null;
|
|
117236
|
+
}
|
|
117237
|
+
var registered = /* @__PURE__ */ new Set();
|
|
117238
|
+
async function registerMiniAppMcp(baseUrl, workspace = "") {
|
|
117239
|
+
const key = `${baseUrl}|${workspace}`;
|
|
117240
|
+
if (registered.has(key)) return true;
|
|
117241
|
+
const script = stdioScriptPath();
|
|
117242
|
+
if (!script) {
|
|
117243
|
+
console.warn("[miniapp-mcp] stdio proxy script not found \u2014 registration skipped");
|
|
117244
|
+
return false;
|
|
117245
|
+
}
|
|
117246
|
+
if (!anyAppHasTools()) {
|
|
117247
|
+
return false;
|
|
117248
|
+
}
|
|
117249
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
117250
|
+
try {
|
|
117251
|
+
try {
|
|
117252
|
+
const res2 = await fetch(`${base}/mcp/servers`, { signal: AbortSignal.timeout(5e3) });
|
|
117253
|
+
if (res2.ok) {
|
|
117254
|
+
const servers = await res2.json();
|
|
117255
|
+
const names = servers.map((s) => s.server_name ?? s.name);
|
|
117256
|
+
if (names.includes(MCP_SERVER_NAME)) {
|
|
117257
|
+
await fetch(`${base}/mcp/configs/${MCP_SERVER_NAME}`, {
|
|
117258
|
+
method: "DELETE",
|
|
117259
|
+
signal: AbortSignal.timeout(5e3)
|
|
117260
|
+
}).catch(() => {
|
|
117261
|
+
});
|
|
117262
|
+
}
|
|
117263
|
+
}
|
|
117264
|
+
} catch {
|
|
117265
|
+
}
|
|
117266
|
+
const body = {
|
|
117267
|
+
configJson: JSON.stringify({
|
|
117268
|
+
[MCP_SERVER_NAME]: {
|
|
117269
|
+
command: process.execPath,
|
|
117270
|
+
args: [script, panePublicUrl(), workspace],
|
|
117271
|
+
env: { AGENT_PANE_SESSION_ID: "" }
|
|
117272
|
+
}
|
|
117273
|
+
})
|
|
117274
|
+
};
|
|
117275
|
+
const res = await fetch(`${base}/mcp/configs`, {
|
|
117276
|
+
method: "POST",
|
|
117277
|
+
headers: { "Content-Type": "application/json" },
|
|
117278
|
+
body: JSON.stringify(body),
|
|
117279
|
+
signal: AbortSignal.timeout(1e4)
|
|
117280
|
+
});
|
|
117281
|
+
if (res.status === 201) {
|
|
117282
|
+
console.log(`[miniapp-mcp] gateway registered in workspace backend ${base} (workspace: ${workspace || "global"})`);
|
|
117283
|
+
registered.add(key);
|
|
117284
|
+
return true;
|
|
117285
|
+
}
|
|
117286
|
+
const text2 = await res.text();
|
|
117287
|
+
if (res.status === 400 && /already exists/i.test(text2)) {
|
|
117288
|
+
registered.add(key);
|
|
117289
|
+
return true;
|
|
117290
|
+
}
|
|
117291
|
+
console.warn(`[miniapp-mcp] registration failed (${res.status}): ${text2.slice(0, 200)}`);
|
|
117292
|
+
return false;
|
|
117293
|
+
} catch (err) {
|
|
117294
|
+
console.warn(`[miniapp-mcp] registration error: ${err.message}`);
|
|
117295
|
+
return false;
|
|
117296
|
+
}
|
|
117297
|
+
}
|
|
117298
|
+
function codexMiniAppLaunchArgs(workspace = "", sessionId = "") {
|
|
117299
|
+
const script = stdioScriptPath();
|
|
117300
|
+
if (!script) return null;
|
|
117301
|
+
return [
|
|
117302
|
+
// MCP tool calls must not ask for elicitation approval — nobody is
|
|
117303
|
+
// watching an agent-driven session to approve (feature is stable/on).
|
|
117304
|
+
"-c",
|
|
117305
|
+
"features.tool_call_mcp_elicitation=false",
|
|
117306
|
+
"-c",
|
|
117307
|
+
`mcp_servers.${MCP_SERVER_NAME}.command=${JSON.stringify(process.execPath)}`,
|
|
117308
|
+
"-c",
|
|
117309
|
+
`mcp_servers.${MCP_SERVER_NAME}.args=${JSON.stringify([script, panePublicUrl(), workspace, ...sessionId ? [sessionId] : []])}`
|
|
117310
|
+
];
|
|
117311
|
+
}
|
|
117312
|
+
|
|
117313
|
+
// src/codex/item-mapper.ts
|
|
117314
|
+
function paneStatus(status) {
|
|
117315
|
+
switch (status) {
|
|
117316
|
+
case "inProgress":
|
|
117317
|
+
case "in_progress":
|
|
117318
|
+
return "in_progress";
|
|
117319
|
+
case "completed":
|
|
117320
|
+
return "completed";
|
|
117321
|
+
case "failed":
|
|
117322
|
+
case "declined":
|
|
117323
|
+
return "failed";
|
|
117324
|
+
default:
|
|
117325
|
+
return void 0;
|
|
117326
|
+
}
|
|
117327
|
+
}
|
|
117328
|
+
function errorText(error51) {
|
|
117329
|
+
if (!error51) return null;
|
|
117330
|
+
if (typeof error51 === "string") return error51;
|
|
117331
|
+
const message = error51.message;
|
|
117332
|
+
return typeof message === "string" ? message : JSON.stringify(error51);
|
|
117333
|
+
}
|
|
117334
|
+
function resultText(result) {
|
|
117335
|
+
const content = result?.content;
|
|
117336
|
+
if (!Array.isArray(content)) return "";
|
|
117337
|
+
return content.map((part) => typeof part.text === "string" ? part.text : "").filter(Boolean).join("\n");
|
|
117338
|
+
}
|
|
117339
|
+
function isWidgetCall(item) {
|
|
117340
|
+
return item.type === "mcpToolCall" && item.server === MCP_SERVER_NAME && item.tool === WIDGET_TOOL_BASE_NAME;
|
|
117341
|
+
}
|
|
117342
|
+
var ITEM_TYPES = {
|
|
117343
|
+
agentMessage: "agent_message",
|
|
117344
|
+
userMessage: "user_message",
|
|
117345
|
+
agentReasoning: "reasoning",
|
|
117346
|
+
commandExecution: "command_execution",
|
|
117347
|
+
fileChange: "file_change",
|
|
117348
|
+
mcpToolCall: "mcp_tool_call",
|
|
117349
|
+
webSearch: "web_search",
|
|
117350
|
+
todoList: "todo_list",
|
|
117351
|
+
contextCompaction: "context_compaction",
|
|
117352
|
+
error: "error"
|
|
117353
|
+
};
|
|
117354
|
+
function mapItemType(item) {
|
|
117355
|
+
if (isWidgetCall(item)) return "widget";
|
|
117356
|
+
return ITEM_TYPES[item.type] ?? item.type;
|
|
117357
|
+
}
|
|
117358
|
+
function mapItemData(item) {
|
|
117359
|
+
switch (item.type) {
|
|
117360
|
+
case "agentMessage":
|
|
117361
|
+
case "agent_message":
|
|
117362
|
+
return { text: item.text };
|
|
117363
|
+
case "reasoning":
|
|
117364
|
+
case "agentReasoning": {
|
|
117365
|
+
const summary = Array.isArray(item.summary) ? item.summary.join("\n") : "";
|
|
117366
|
+
return { text: summary || item.text || "" };
|
|
117367
|
+
}
|
|
117368
|
+
case "commandExecution":
|
|
117369
|
+
case "command_execution":
|
|
117370
|
+
return {
|
|
117371
|
+
command: item.command,
|
|
117372
|
+
aggregated_output: item.aggregatedOutput ?? item.aggregated_output,
|
|
117373
|
+
exit_code: item.exitCode ?? item.exit_code ?? null,
|
|
117374
|
+
status: paneStatus(item.status)
|
|
117375
|
+
};
|
|
117376
|
+
case "fileChange":
|
|
117377
|
+
case "file_change":
|
|
117378
|
+
return {
|
|
117379
|
+
changes: item.changes,
|
|
117380
|
+
status: paneStatus(item.status)
|
|
117381
|
+
};
|
|
117382
|
+
case "mcpToolCall":
|
|
117383
|
+
case "mcp_tool_call":
|
|
117384
|
+
if (isWidgetCall(item)) {
|
|
117385
|
+
const args = item.arguments ?? {};
|
|
117386
|
+
const failed = paneStatus(item.status) === "failed";
|
|
117387
|
+
return {
|
|
117388
|
+
title: typeof args.title === "string" ? args.title : "",
|
|
117389
|
+
html: typeof args.widget_code === "string" ? args.widget_code : "",
|
|
117390
|
+
error: failed ? errorText(item.error) || resultText(item.result) || "Tool error" : null
|
|
117391
|
+
};
|
|
117392
|
+
}
|
|
117393
|
+
return {
|
|
117394
|
+
server: item.server,
|
|
117395
|
+
tool: item.tool,
|
|
117396
|
+
arguments: item.arguments,
|
|
117397
|
+
result: item.result ?? null,
|
|
117398
|
+
error: errorText(item.error),
|
|
117399
|
+
status: paneStatus(item.status)
|
|
117400
|
+
};
|
|
117401
|
+
case "webSearch":
|
|
117402
|
+
case "web_search":
|
|
117403
|
+
return { query: item.query };
|
|
117404
|
+
case "todoList":
|
|
117405
|
+
case "todo_list":
|
|
117406
|
+
return { items: item.items };
|
|
117407
|
+
case "contextCompaction":
|
|
117408
|
+
return { trigger: "auto", pre_tokens: null, post_tokens: null };
|
|
117409
|
+
case "error":
|
|
117410
|
+
return { message: item.message };
|
|
117411
|
+
default:
|
|
117412
|
+
return {};
|
|
117413
|
+
}
|
|
117414
|
+
}
|
|
117415
|
+
function getItemStatus(item) {
|
|
117416
|
+
if (item.type === "commandExecution" || item.type === "command_execution" || item.type === "fileChange" || item.type === "file_change" || item.type === "mcpToolCall" || item.type === "mcp_tool_call") {
|
|
117417
|
+
return paneStatus(item.status) ?? "completed";
|
|
117418
|
+
}
|
|
117419
|
+
if (item.type === "error") {
|
|
117420
|
+
return "failed";
|
|
117421
|
+
}
|
|
117422
|
+
return "completed";
|
|
117423
|
+
}
|
|
117424
|
+
|
|
117425
|
+
// src/codex/known-threads.ts
|
|
117426
|
+
var PANE_THREAD_SOURCE = "agentpane";
|
|
117427
|
+
function recordCodexThread(threadId, sessionId) {
|
|
117428
|
+
try {
|
|
117429
|
+
getDb().prepare("INSERT OR IGNORE INTO codex_threads (thread_id, session_id, created_at) VALUES (?, ?, ?)").run(threadId, sessionId, (/* @__PURE__ */ new Date()).toISOString());
|
|
117430
|
+
} catch {
|
|
117431
|
+
}
|
|
117432
|
+
}
|
|
117433
|
+
function knownCodexThreadIds(db2) {
|
|
117434
|
+
const rows = db2.prepare(
|
|
117435
|
+
`SELECT external_thread_id AS id FROM sessions WHERE external_thread_id IS NOT NULL
|
|
117436
|
+
UNION SELECT pre_rewind_thread_id FROM sessions WHERE pre_rewind_thread_id IS NOT NULL
|
|
117437
|
+
UNION SELECT import_source_id FROM sessions WHERE import_source_id IS NOT NULL
|
|
117438
|
+
UNION SELECT external_thread_id FROM discussion_threads WHERE external_thread_id IS NOT NULL
|
|
117439
|
+
UNION SELECT thread_id FROM codex_threads`
|
|
117440
|
+
).all();
|
|
117441
|
+
return new Set(rows.map((row) => row.id));
|
|
117442
|
+
}
|
|
117443
|
+
|
|
117444
|
+
// src/codex/review-turns.ts
|
|
117445
|
+
function isReview(turn) {
|
|
117446
|
+
return (turn.items ?? []).some((item) => item.type === "enteredReviewMode");
|
|
117447
|
+
}
|
|
117448
|
+
function isInsideReview(review, turn) {
|
|
117449
|
+
return isReview(review) && review.completedAt != null && turn.startedAt != null && turn.startedAt < review.completedAt;
|
|
117450
|
+
}
|
|
117451
|
+
function forkThroughReview(turns, turnId) {
|
|
117452
|
+
const index = turns.findIndex((turn) => turn.id === turnId);
|
|
117453
|
+
if (index < 0 || !isReview(turns[index])) return void 0;
|
|
117454
|
+
let next = index + 1;
|
|
117455
|
+
while (next < turns.length && isInsideReview(turns[index], turns[next])) next++;
|
|
117456
|
+
if (next < turns.length - 1 && isInsideReview(turns[next], turns[next + 1])) next++;
|
|
117457
|
+
return next < turns.length ? { beforeTurnId: turns[next].id } : {};
|
|
117458
|
+
}
|
|
117459
|
+
|
|
117460
|
+
// src/codex/session-import.ts
|
|
117461
|
+
var CodexImportError = class extends Error {
|
|
117462
|
+
status;
|
|
117463
|
+
paneSessionId;
|
|
117464
|
+
constructor(status, message, paneSessionId = null) {
|
|
117465
|
+
super(message);
|
|
117466
|
+
this.name = "CodexImportError";
|
|
117467
|
+
this.status = status;
|
|
117468
|
+
this.paneSessionId = paneSessionId;
|
|
117469
|
+
}
|
|
117470
|
+
};
|
|
117471
|
+
var RECENT_MS2 = 10 * 6e4;
|
|
117472
|
+
var THREAD_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
117473
|
+
var TITLE_MAX2 = 100;
|
|
117474
|
+
var LIST_PAGE = 100;
|
|
117475
|
+
var LIST_MAX = 1e3;
|
|
117476
|
+
var USER_SOURCES = ["cli", "vscode", "exec", "appServer", "unknown"];
|
|
117477
|
+
var THROWAWAY_PROMPTS = ["Generate a concise 3-5 word title", "You are summarizing a side discussion thread"];
|
|
117478
|
+
async function realDir2(dir) {
|
|
117479
|
+
try {
|
|
117480
|
+
return await realpath2(dir);
|
|
117481
|
+
} catch {
|
|
117482
|
+
return null;
|
|
117483
|
+
}
|
|
117484
|
+
}
|
|
117485
|
+
async function workspaceDirs(workspacePath) {
|
|
117486
|
+
const real = await realDir2(workspacePath);
|
|
117487
|
+
if (!real) return null;
|
|
117488
|
+
const given = path13.resolve(workspacePath);
|
|
117489
|
+
return given === real ? [real] : [given, real];
|
|
117490
|
+
}
|
|
117491
|
+
function titleOf2(thread) {
|
|
117492
|
+
const raw = (thread.name || thread.preview || "").trim();
|
|
117493
|
+
const firstLine = raw.split("\n")[0].trim();
|
|
117494
|
+
return firstLine.length > TITLE_MAX2 ? `${firstLine.slice(0, TITLE_MAX2 - 1)}\u2026` : firstLine;
|
|
117495
|
+
}
|
|
117496
|
+
function isThrowaway(thread) {
|
|
117497
|
+
const preview = (thread.preview ?? "").trimStart();
|
|
117498
|
+
return THROWAWAY_PROMPTS.some((prompt) => preview.startsWith(prompt));
|
|
117499
|
+
}
|
|
117500
|
+
function paneSessionHolding2(db2, threadId) {
|
|
117501
|
+
const row = db2.prepare(
|
|
117502
|
+
`SELECT id FROM sessions WHERE import_source_id = ? OR external_thread_id = ? OR pre_rewind_thread_id = ?
|
|
117503
|
+
UNION ALL SELECT session_id FROM discussion_threads WHERE external_thread_id = ?
|
|
117504
|
+
UNION ALL SELECT session_id FROM codex_threads WHERE thread_id = ?
|
|
117505
|
+
LIMIT 1`
|
|
117506
|
+
).get(threadId, threadId, threadId, threadId, threadId);
|
|
117507
|
+
return row ? { sessionId: row.id } : null;
|
|
117508
|
+
}
|
|
117509
|
+
async function listImportableCodexSessions(db2, workspacePath, now = Date.now()) {
|
|
117510
|
+
const dirs = await workspaceDirs(workspacePath);
|
|
117511
|
+
if (!dirs) return [];
|
|
117512
|
+
const known = knownCodexThreadIds(db2);
|
|
117513
|
+
const client = getSharedAppServer();
|
|
117514
|
+
const sessions = [];
|
|
117515
|
+
let cursor = null;
|
|
117516
|
+
let seen = 0;
|
|
117517
|
+
do {
|
|
117518
|
+
const page = await client.request("thread/list", {
|
|
117519
|
+
cwd: dirs,
|
|
117520
|
+
limit: LIST_PAGE,
|
|
117521
|
+
cursor,
|
|
117522
|
+
sortKey: "updated_at",
|
|
117523
|
+
sourceKinds: USER_SOURCES
|
|
117524
|
+
});
|
|
117525
|
+
for (const thread of page.data ?? []) {
|
|
117526
|
+
seen += 1;
|
|
117527
|
+
if (known.has(thread.id) || thread.parentThreadId || thread.ephemeral || isThrowaway(thread)) continue;
|
|
117528
|
+
const title = titleOf2(thread);
|
|
117529
|
+
if (!title) continue;
|
|
117530
|
+
const updatedMs = thread.updatedAt * 1e3;
|
|
117531
|
+
sessions.push({
|
|
117532
|
+
session_id: thread.id,
|
|
117533
|
+
title,
|
|
117534
|
+
cwd: thread.cwd,
|
|
117535
|
+
git_branch: thread.gitInfo?.branch ?? null,
|
|
117536
|
+
created_at: new Date(thread.createdAt * 1e3).toISOString(),
|
|
117537
|
+
last_modified: new Date(updatedMs).toISOString(),
|
|
117538
|
+
recently_active: now - updatedMs < RECENT_MS2
|
|
117539
|
+
});
|
|
117540
|
+
}
|
|
117541
|
+
cursor = page.nextCursor;
|
|
117542
|
+
} while (cursor && seen < LIST_MAX);
|
|
117543
|
+
return sessions.sort((a, b) => a.last_modified < b.last_modified ? 1 : -1);
|
|
117544
|
+
}
|
|
117545
|
+
var TURN_STATUS = {
|
|
117546
|
+
completed: "completed",
|
|
117547
|
+
failed: "failed",
|
|
117548
|
+
interrupted: "aborted",
|
|
117549
|
+
inProgress: "aborted"
|
|
117550
|
+
};
|
|
117551
|
+
function userText(item) {
|
|
117552
|
+
const content = Array.isArray(item.content) ? item.content : [];
|
|
117553
|
+
return content.map((part) => {
|
|
117554
|
+
if (part.type === "text" && typeof part.text === "string") return part.text;
|
|
117555
|
+
if (part.type === "image") return "[image]";
|
|
117556
|
+
if (part.type === "localImage" && typeof part.path === "string") return `[image: ${part.path}]`;
|
|
117557
|
+
return "";
|
|
117558
|
+
}).filter(Boolean).join("\n");
|
|
117559
|
+
}
|
|
117560
|
+
function skipped(item, data) {
|
|
117561
|
+
if (item.type === "userMessage" || item.type === "enteredReviewMode" || item.type === "exitedReviewMode") return true;
|
|
117562
|
+
return (item.type === "reasoning" || item.type === "agentReasoning") && !data.text;
|
|
117563
|
+
}
|
|
117564
|
+
function threadToTurns(thread) {
|
|
117565
|
+
const turns = [];
|
|
117566
|
+
const stored = thread.turns ?? [];
|
|
117567
|
+
let last = thread.createdAt * 1e3 - 1;
|
|
117568
|
+
for (const [position, turn] of stored.entries()) {
|
|
117569
|
+
if (position > 0 && isInsideReview(stored[position - 1], turn)) continue;
|
|
117570
|
+
const items = turn.items ?? [];
|
|
117571
|
+
const prompt = items.filter((item) => item.type === "userMessage").map(userText).filter(Boolean).join("\n\n");
|
|
117572
|
+
const command = items.some((item) => item.type === "enteredReviewMode") ? "/review" : items.some((item) => item.type === "contextCompaction") ? "/compact" : "";
|
|
117573
|
+
const output = [];
|
|
117574
|
+
let agentResponse = null;
|
|
117575
|
+
let review = null;
|
|
117576
|
+
let thoughts = null;
|
|
117577
|
+
const started = Math.max(last + 1, (turn.startedAt ?? 0) * 1e3);
|
|
117578
|
+
for (const [index, item] of items.entries()) {
|
|
117579
|
+
if (item.type === "exitedReviewMode" && typeof item.review === "string" && item.review.trim())
|
|
117580
|
+
review = item.review;
|
|
117581
|
+
const data = mapItemData(item);
|
|
117582
|
+
if (skipped(item, data)) continue;
|
|
117583
|
+
if (item.type === "agentMessage" || item.type === "agent_message") agentResponse = item.text ?? agentResponse;
|
|
117584
|
+
if ((item.type === "reasoning" || item.type === "agentReasoning") && typeof data.text === "string") {
|
|
117585
|
+
thoughts = data.text;
|
|
117586
|
+
}
|
|
117587
|
+
const status = getItemStatus(item);
|
|
117588
|
+
output.push({
|
|
117589
|
+
externalId: item.id,
|
|
117590
|
+
type: mapItemType(item),
|
|
117591
|
+
data,
|
|
117592
|
+
// Left open when its turn ended: it never finished.
|
|
117593
|
+
status: status === "in_progress" ? "failed" : status,
|
|
117594
|
+
createdAt: new Date(started + index).toISOString()
|
|
117595
|
+
});
|
|
117596
|
+
}
|
|
117597
|
+
const userPrompt = prompt || command;
|
|
117598
|
+
if (!userPrompt && output.length === 0) continue;
|
|
117599
|
+
const ended = Math.max(started, (turn.completedAt ?? 0) * 1e3);
|
|
117600
|
+
turns.push({
|
|
117601
|
+
userPrompt,
|
|
117602
|
+
agentResponse: agentResponse ?? review,
|
|
117603
|
+
thoughts,
|
|
117604
|
+
externalTurnId: turn.id,
|
|
117605
|
+
status: TURN_STATUS[turn.status] ?? "completed",
|
|
117606
|
+
error: turn.status === "failed" ? turn.error?.message ?? "Codex turn failed" : null,
|
|
117607
|
+
createdAt: new Date(started).toISOString(),
|
|
117608
|
+
updatedAt: new Date(ended).toISOString(),
|
|
117609
|
+
items: output
|
|
117610
|
+
});
|
|
117611
|
+
last = started;
|
|
117612
|
+
}
|
|
117613
|
+
return turns;
|
|
117614
|
+
}
|
|
117615
|
+
async function importCodexSession(db2, threadId, workspacePath) {
|
|
117616
|
+
if (!THREAD_ID.test(threadId)) throw new CodexImportError(400, "Not a Codex thread id");
|
|
117617
|
+
const holder = paneSessionHolding2(db2, threadId);
|
|
117618
|
+
if (holder) throw new CodexImportError(409, "This thread is already in the pane", holder.sessionId);
|
|
117619
|
+
let thread;
|
|
117620
|
+
try {
|
|
117621
|
+
({ thread } = await getSharedAppServer().request("thread/read", {
|
|
117622
|
+
threadId,
|
|
117623
|
+
includeTurns: true
|
|
117624
|
+
}));
|
|
117625
|
+
} catch (err) {
|
|
117626
|
+
throw new CodexImportError(404, `Codex thread not found: ${err.message}`);
|
|
117627
|
+
}
|
|
117628
|
+
const turns = threadToTurns(thread);
|
|
117629
|
+
if (turns.length === 0) throw new CodexImportError(422, "This thread has no conversation to import");
|
|
117630
|
+
const dirs = workspacePath ? await workspaceDirs(workspacePath) : null;
|
|
117631
|
+
const cwd = workspacePath && dirs?.includes(thread.cwd) ? workspacePath : thread.cwd;
|
|
117632
|
+
const sessionId = v4_default();
|
|
117633
|
+
const insertSession = db2.prepare(
|
|
117634
|
+
`INSERT INTO sessions (id, title, runtime_type, model, model_reasoning_effort, cwd, external_thread_id, status,
|
|
117635
|
+
is_running, lifecycle, sort_order, user_touched, import_source_id, created_at, updated_at)
|
|
117636
|
+
VALUES (?, ?, 'codex', NULL, NULL, ?, ?, 'active', 0, 'working', ?, 1, ?, ?, ?)`
|
|
117637
|
+
);
|
|
117638
|
+
const insertTurn = db2.prepare(
|
|
117639
|
+
`INSERT INTO turns (id, session_id, user_prompt, agent_response, thoughts, token_usage, external_turn_id, status,
|
|
117640
|
+
error, created_at, updated_at)
|
|
117641
|
+
VALUES (?, ?, ?, ?, ?, NULL, ?, ?, ?, ?, ?)`
|
|
117642
|
+
);
|
|
117643
|
+
const insertItem2 = db2.prepare(
|
|
117644
|
+
`INSERT INTO items (id, turn_id, external_item_id, type, data, status, created_at, updated_at)
|
|
117645
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`
|
|
117646
|
+
);
|
|
117647
|
+
db2.transaction(() => {
|
|
117648
|
+
const raced = paneSessionHolding2(db2, threadId);
|
|
117649
|
+
if (raced) throw new CodexImportError(409, "This thread is already in the pane", raced.sessionId);
|
|
117650
|
+
const { m } = db2.prepare("SELECT COALESCE(MAX(sort_order), 0) AS m FROM sessions WHERE cwd = ?").get(cwd);
|
|
117651
|
+
insertSession.run(
|
|
117652
|
+
sessionId,
|
|
117653
|
+
titleOf2(thread) || null,
|
|
117654
|
+
cwd,
|
|
117655
|
+
threadId,
|
|
117656
|
+
m + 1,
|
|
117657
|
+
threadId,
|
|
117658
|
+
turns[0].createdAt,
|
|
117659
|
+
turns[turns.length - 1].updatedAt
|
|
117660
|
+
);
|
|
117661
|
+
for (const turn of turns) {
|
|
117662
|
+
const turnId = v4_default();
|
|
117663
|
+
insertTurn.run(
|
|
117664
|
+
turnId,
|
|
117665
|
+
sessionId,
|
|
117666
|
+
turn.userPrompt,
|
|
117667
|
+
turn.agentResponse,
|
|
117668
|
+
turn.thoughts,
|
|
117669
|
+
turn.externalTurnId,
|
|
117670
|
+
turn.status,
|
|
117671
|
+
turn.error,
|
|
117672
|
+
turn.createdAt,
|
|
117673
|
+
turn.updatedAt
|
|
117674
|
+
);
|
|
117675
|
+
for (const item of turn.items) {
|
|
117676
|
+
insertItem2.run(
|
|
117677
|
+
v4_default(),
|
|
117678
|
+
turnId,
|
|
117679
|
+
item.externalId,
|
|
117680
|
+
item.type,
|
|
117681
|
+
JSON.stringify(trimItemData(item.data)),
|
|
117682
|
+
item.status,
|
|
117683
|
+
item.createdAt,
|
|
117684
|
+
item.createdAt
|
|
117685
|
+
);
|
|
117686
|
+
}
|
|
117687
|
+
}
|
|
117688
|
+
})();
|
|
117689
|
+
return db2.prepare("SELECT * FROM sessions WHERE id = ?").get(sessionId);
|
|
117690
|
+
}
|
|
117691
|
+
|
|
117692
|
+
// src/routes/codex-sessions.ts
|
|
117693
|
+
async function registerCodexSessionRoutes(fastify) {
|
|
117694
|
+
fastify.get("/api/codex-sessions", async (request, reply) => {
|
|
117695
|
+
const workspace = request.query.workspace?.trim();
|
|
117696
|
+
if (!workspace) return reply.code(400).send({ error: "workspace is required" });
|
|
117697
|
+
try {
|
|
117698
|
+
return { sessions: await listImportableCodexSessions(getDb(), workspace) };
|
|
117699
|
+
} catch (err) {
|
|
117700
|
+
return reply.code(500).send({ error: `Could not list Codex sessions: ${err.message}` });
|
|
117701
|
+
}
|
|
117702
|
+
});
|
|
117703
|
+
fastify.post(
|
|
117704
|
+
"/api/codex-sessions/:id/import",
|
|
117705
|
+
{
|
|
117706
|
+
schema: {
|
|
117707
|
+
body: {
|
|
117708
|
+
type: ["object", "null"],
|
|
117709
|
+
properties: { workspace: { type: ["string", "null"] } }
|
|
117710
|
+
}
|
|
117711
|
+
}
|
|
117712
|
+
},
|
|
117713
|
+
async (request, reply) => {
|
|
117714
|
+
try {
|
|
117715
|
+
return await importCodexSession(getDb(), request.params.id, request.body?.workspace?.trim() || null);
|
|
117716
|
+
} catch (err) {
|
|
117717
|
+
if (err instanceof CodexImportError) {
|
|
117718
|
+
return reply.code(err.status).send({ error: err.message, session_id: err.paneSessionId });
|
|
117719
|
+
}
|
|
117720
|
+
return reply.code(500).send({ error: `Import failed: ${err.message}` });
|
|
117721
|
+
}
|
|
117722
|
+
}
|
|
117723
|
+
);
|
|
117724
|
+
}
|
|
117725
|
+
|
|
117726
|
+
// src/session-host/flags.ts
|
|
117727
|
+
import fs8 from "node:fs";
|
|
117728
|
+
import path14 from "node:path";
|
|
117095
117729
|
var DEFAULT_FLAGS = {
|
|
117096
117730
|
claude: true,
|
|
117097
117731
|
codex: true,
|
|
@@ -117110,18 +117744,18 @@ function setPaneDataDir(dir) {
|
|
|
117110
117744
|
}
|
|
117111
117745
|
function sessionHostsRoot() {
|
|
117112
117746
|
const override = process.env.AGENT_PANE_SESSION_HOSTS_DIR;
|
|
117113
|
-
if (override) return
|
|
117114
|
-
return paneDataDir ?
|
|
117747
|
+
if (override) return path14.resolve(override);
|
|
117748
|
+
return paneDataDir ? path14.join(paneDataDir, "session-hosts") : null;
|
|
117115
117749
|
}
|
|
117116
117750
|
function flagsFilePath() {
|
|
117117
117751
|
const root = sessionHostsRoot();
|
|
117118
|
-
if (process.env.AGENT_PANE_SESSION_HOSTS_DIR) return
|
|
117119
|
-
return paneDataDir ?
|
|
117752
|
+
if (process.env.AGENT_PANE_SESSION_HOSTS_DIR) return path14.join(path14.dirname(root), "session-hosts.json");
|
|
117753
|
+
return paneDataDir ? path14.join(paneDataDir, "session-hosts.json") : null;
|
|
117120
117754
|
}
|
|
117121
117755
|
function readFlagFile(file2) {
|
|
117122
117756
|
if (!file2) return {};
|
|
117123
117757
|
try {
|
|
117124
|
-
const parsed = JSON.parse(
|
|
117758
|
+
const parsed = JSON.parse(fs8.readFileSync(file2, "utf8"));
|
|
117125
117759
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) return parsed;
|
|
117126
117760
|
console.warn(`[session-host] ${file2} is not a JSON object; using the defaults`);
|
|
117127
117761
|
} catch (err) {
|
|
@@ -117187,17 +117821,17 @@ var LOG_HEADER_LEN = LOG_HEADER_PREFIX.length + LOG_HEADER_DIGITS + 1;
|
|
|
117187
117821
|
|
|
117188
117822
|
// src/session-host/registry.ts
|
|
117189
117823
|
import { randomBytes, randomUUID as randomUUID2 } from "node:crypto";
|
|
117190
|
-
import
|
|
117191
|
-
import
|
|
117192
|
-
import { fileURLToPath as
|
|
117824
|
+
import fs10 from "node:fs";
|
|
117825
|
+
import path16 from "node:path";
|
|
117826
|
+
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
117193
117827
|
|
|
117194
117828
|
// src/session-host/client.ts
|
|
117195
117829
|
import { execFile as execFile3, spawn as spawn4 } from "node:child_process";
|
|
117196
117830
|
import { EventEmitter as EventEmitter2 } from "node:events";
|
|
117197
|
-
import
|
|
117831
|
+
import fs9 from "node:fs";
|
|
117198
117832
|
import net2 from "node:net";
|
|
117199
|
-
import
|
|
117200
|
-
import { fileURLToPath as
|
|
117833
|
+
import path15 from "node:path";
|
|
117834
|
+
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
117201
117835
|
var HostRequestError = class extends Error {
|
|
117202
117836
|
reply;
|
|
117203
117837
|
constructor(reply) {
|
|
@@ -117208,36 +117842,36 @@ var HostRequestError = class extends Error {
|
|
|
117208
117842
|
function hostScriptPath() {
|
|
117209
117843
|
const override = process.env.AGENT_PANE_SESSION_HOST_SCRIPT;
|
|
117210
117844
|
if (override) return override;
|
|
117211
|
-
const here =
|
|
117845
|
+
const here = path15.dirname(fileURLToPath3(import.meta.url));
|
|
117212
117846
|
const candidates = [
|
|
117213
|
-
|
|
117847
|
+
path15.resolve(here, "../../scripts/session-host.mjs"),
|
|
117214
117848
|
// src/session-host/ → backend/scripts
|
|
117215
|
-
|
|
117849
|
+
path15.resolve(here, "../scripts/session-host.mjs")
|
|
117216
117850
|
// dist bundle → backend/scripts
|
|
117217
117851
|
];
|
|
117218
117852
|
for (const candidate of candidates) {
|
|
117219
|
-
if (
|
|
117853
|
+
if (fs9.existsSync(candidate)) return candidate;
|
|
117220
117854
|
}
|
|
117221
117855
|
return null;
|
|
117222
117856
|
}
|
|
117223
117857
|
function hostSocketPath(dir) {
|
|
117224
|
-
const direct =
|
|
117858
|
+
const direct = path15.join(dir, "sock");
|
|
117225
117859
|
if (Buffer.byteLength(direct) < 100) return direct;
|
|
117226
117860
|
const uid = typeof process.getuid === "function" ? process.getuid() : 0;
|
|
117227
|
-
return
|
|
117861
|
+
return path15.join("/tmp", `rbsh-${uid}`, path15.basename(dir), "sock");
|
|
117228
117862
|
}
|
|
117229
117863
|
function readJson(file2) {
|
|
117230
117864
|
try {
|
|
117231
|
-
return JSON.parse(
|
|
117865
|
+
return JSON.parse(fs9.readFileSync(file2, "utf8"));
|
|
117232
117866
|
} catch {
|
|
117233
117867
|
return null;
|
|
117234
117868
|
}
|
|
117235
117869
|
}
|
|
117236
117870
|
function readHostExit(dir) {
|
|
117237
|
-
return readJson(
|
|
117871
|
+
return readJson(path15.join(dir, "exit.json"));
|
|
117238
117872
|
}
|
|
117239
117873
|
function readHostChild(dir) {
|
|
117240
|
-
return readJson(
|
|
117874
|
+
return readJson(path15.join(dir, "child.json"));
|
|
117241
117875
|
}
|
|
117242
117876
|
function isPidAlive(pid) {
|
|
117243
117877
|
if (!pid || pid <= 0) return false;
|
|
@@ -117392,8 +118026,8 @@ function attachHost(dir, after, timeoutMs = 5e3) {
|
|
|
117392
118026
|
function startHost(opts) {
|
|
117393
118027
|
const script = hostScriptPath();
|
|
117394
118028
|
if (!script) throw new Error("session host script not found");
|
|
117395
|
-
|
|
117396
|
-
|
|
118029
|
+
fs9.mkdirSync(opts.dir, { recursive: true, mode: 448 });
|
|
118030
|
+
fs9.chmodSync(opts.dir, 448);
|
|
117397
118031
|
const env = {};
|
|
117398
118032
|
for (const [k, v] of Object.entries(opts.env)) if (v !== void 0) env[k] = v;
|
|
117399
118033
|
const child = spawn4(opts.nodePath ?? process.execPath, [script, opts.dir, JSON.stringify(opts.config), opts.command, ...opts.args], {
|
|
@@ -117427,9 +118061,9 @@ async function waitForHost(dir, timeoutMs = 1e4) {
|
|
|
117427
118061
|
function readLogOldest(dir) {
|
|
117428
118062
|
let fd = null;
|
|
117429
118063
|
try {
|
|
117430
|
-
fd =
|
|
118064
|
+
fd = fs9.openSync(path15.join(dir, "out.log"), "r");
|
|
117431
118065
|
const buf = Buffer.alloc(LOG_HEADER_LEN);
|
|
117432
|
-
const n =
|
|
118066
|
+
const n = fs9.readSync(fd, buf, 0, LOG_HEADER_LEN, 0);
|
|
117433
118067
|
const text2 = buf.subarray(0, n).toString("utf8");
|
|
117434
118068
|
if (n < LOG_HEADER_LEN || !text2.startsWith(LOG_HEADER_PREFIX) || text2[LOG_HEADER_LEN - 1] !== "\n") return null;
|
|
117435
118069
|
const digits = text2.slice(LOG_HEADER_PREFIX.length, LOG_HEADER_PREFIX.length + LOG_HEADER_DIGITS);
|
|
@@ -117437,14 +118071,14 @@ function readLogOldest(dir) {
|
|
|
117437
118071
|
} catch {
|
|
117438
118072
|
return null;
|
|
117439
118073
|
} finally {
|
|
117440
|
-
if (fd !== null)
|
|
118074
|
+
if (fd !== null) fs9.closeSync(fd);
|
|
117441
118075
|
}
|
|
117442
118076
|
}
|
|
117443
118077
|
function readHostLog(dir, after) {
|
|
117444
118078
|
const oldest = readLogOldest(dir);
|
|
117445
118079
|
if (oldest === null || after < oldest) return null;
|
|
117446
118080
|
try {
|
|
117447
|
-
const all =
|
|
118081
|
+
const all = fs9.readFileSync(path15.join(dir, "out.log"));
|
|
117448
118082
|
const start = LOG_HEADER_LEN + (after - oldest);
|
|
117449
118083
|
if (start > all.length) return null;
|
|
117450
118084
|
return all.subarray(start);
|
|
@@ -117454,14 +118088,14 @@ function readHostLog(dir, after) {
|
|
|
117454
118088
|
}
|
|
117455
118089
|
function removeHostDir(dir) {
|
|
117456
118090
|
try {
|
|
117457
|
-
|
|
118091
|
+
fs9.rmSync(dir, { recursive: true, force: true });
|
|
117458
118092
|
} catch (err) {
|
|
117459
118093
|
console.error(`[session-host] could not remove ${dir}:`, err.message);
|
|
117460
118094
|
}
|
|
117461
|
-
const alias =
|
|
118095
|
+
const alias = path15.dirname(hostSocketPath(dir));
|
|
117462
118096
|
if (alias !== dir) {
|
|
117463
118097
|
try {
|
|
117464
|
-
|
|
118098
|
+
fs9.unlinkSync(alias);
|
|
117465
118099
|
} catch {
|
|
117466
118100
|
}
|
|
117467
118101
|
}
|
|
@@ -117518,16 +118152,16 @@ function newHostDir() {
|
|
|
117518
118152
|
const root = sessionHostsRoot();
|
|
117519
118153
|
if (!root) throw new Error("session hosts have no directory");
|
|
117520
118154
|
const id = randomBytes(8).toString("hex");
|
|
117521
|
-
return { id, dir:
|
|
118155
|
+
return { id, dir: path16.join(root, id) };
|
|
117522
118156
|
}
|
|
117523
118157
|
var cachedVersion;
|
|
117524
118158
|
function runtimeVersion() {
|
|
117525
118159
|
if (cachedVersion !== void 0) return cachedVersion;
|
|
117526
118160
|
cachedVersion = null;
|
|
117527
|
-
const here =
|
|
118161
|
+
const here = path16.dirname(fileURLToPath4(import.meta.url));
|
|
117528
118162
|
for (const rel of ["../../../../package.json", "../../../package.json"]) {
|
|
117529
118163
|
try {
|
|
117530
|
-
const pkg = JSON.parse(
|
|
118164
|
+
const pkg = JSON.parse(fs10.readFileSync(path16.resolve(here, rel), "utf8"));
|
|
117531
118165
|
if (pkg.name === "repoburg" && pkg.version) {
|
|
117532
118166
|
cachedVersion = pkg.version;
|
|
117533
118167
|
break;
|
|
@@ -117538,15 +118172,15 @@ function runtimeVersion() {
|
|
|
117538
118172
|
return cachedVersion;
|
|
117539
118173
|
}
|
|
117540
118174
|
function writeHostMeta(dir, meta3) {
|
|
117541
|
-
|
|
117542
|
-
|
|
117543
|
-
const tmp =
|
|
117544
|
-
|
|
117545
|
-
|
|
118175
|
+
fs10.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
118176
|
+
fs10.chmodSync(dir, 448);
|
|
118177
|
+
const tmp = path16.join(dir, "meta.json.tmp");
|
|
118178
|
+
fs10.writeFileSync(tmp, JSON.stringify(meta3, null, 2) + "\n", { mode: 384 });
|
|
118179
|
+
fs10.renameSync(tmp, path16.join(dir, "meta.json"));
|
|
117546
118180
|
}
|
|
117547
118181
|
function readHostMeta(dir) {
|
|
117548
118182
|
try {
|
|
117549
|
-
return JSON.parse(
|
|
118183
|
+
return JSON.parse(fs10.readFileSync(path16.join(dir, "meta.json"), "utf8"));
|
|
117550
118184
|
} catch {
|
|
117551
118185
|
return null;
|
|
117552
118186
|
}
|
|
@@ -117684,16 +118318,16 @@ async function runAdoption() {
|
|
|
117684
118318
|
async function adoptHosts(db2, root, adoption, result) {
|
|
117685
118319
|
let entries = [];
|
|
117686
118320
|
try {
|
|
117687
|
-
entries =
|
|
118321
|
+
entries = fs10.readdirSync(root);
|
|
117688
118322
|
} catch (err) {
|
|
117689
118323
|
if (err.code !== "ENOENT") console.error("[session-host] cannot read", root, err.message);
|
|
117690
118324
|
}
|
|
117691
118325
|
const seen = /* @__PURE__ */ new Set();
|
|
117692
118326
|
const queue = [];
|
|
117693
118327
|
for (const id of entries) {
|
|
117694
|
-
const dir =
|
|
118328
|
+
const dir = path16.join(root, id);
|
|
117695
118329
|
try {
|
|
117696
|
-
if (!
|
|
118330
|
+
if (!fs10.statSync(dir).isDirectory()) continue;
|
|
117697
118331
|
} catch {
|
|
117698
118332
|
continue;
|
|
117699
118333
|
}
|
|
@@ -117805,7 +118439,7 @@ async function shutDownAllHosts() {
|
|
|
117805
118439
|
if (!root) return 0;
|
|
117806
118440
|
let entries = [];
|
|
117807
118441
|
try {
|
|
117808
|
-
entries =
|
|
118442
|
+
entries = fs10.readdirSync(root);
|
|
117809
118443
|
} catch {
|
|
117810
118444
|
return 0;
|
|
117811
118445
|
}
|
|
@@ -117818,7 +118452,7 @@ async function shutDownAllHosts() {
|
|
|
117818
118452
|
}
|
|
117819
118453
|
await Promise.all(
|
|
117820
118454
|
entries.map(async (id) => {
|
|
117821
|
-
const dir =
|
|
118455
|
+
const dir = path16.join(root, id);
|
|
117822
118456
|
const row = db2 ? getHostRow(db2, id) : void 0;
|
|
117823
118457
|
try {
|
|
117824
118458
|
await shutDownHost(dir, { eof: row?.runtime === "codex" });
|
|
@@ -117859,63 +118493,6 @@ async function registerSessionHostRoutes(fastify) {
|
|
|
117859
118493
|
});
|
|
117860
118494
|
}
|
|
117861
118495
|
|
|
117862
|
-
// src/codex/item-mapper.ts
|
|
117863
|
-
function mapItemData(item) {
|
|
117864
|
-
switch (item.type) {
|
|
117865
|
-
case "agentMessage":
|
|
117866
|
-
case "agent_message":
|
|
117867
|
-
return { text: item.text };
|
|
117868
|
-
case "reasoning":
|
|
117869
|
-
case "agentReasoning": {
|
|
117870
|
-
const summary = Array.isArray(item.summary) ? item.summary.join("\n") : "";
|
|
117871
|
-
return { text: summary || item.text || "" };
|
|
117872
|
-
}
|
|
117873
|
-
case "commandExecution":
|
|
117874
|
-
case "command_execution":
|
|
117875
|
-
return {
|
|
117876
|
-
command: item.command,
|
|
117877
|
-
aggregated_output: item.aggregated_output,
|
|
117878
|
-
exit_code: item.exit_code ?? null,
|
|
117879
|
-
status: item.status
|
|
117880
|
-
};
|
|
117881
|
-
case "fileChange":
|
|
117882
|
-
case "file_change":
|
|
117883
|
-
return {
|
|
117884
|
-
changes: item.changes,
|
|
117885
|
-
status: item.status
|
|
117886
|
-
};
|
|
117887
|
-
case "mcpToolCall":
|
|
117888
|
-
case "mcp_tool_call":
|
|
117889
|
-
return {
|
|
117890
|
-
server: item.server,
|
|
117891
|
-
tool: item.tool,
|
|
117892
|
-
arguments: item.arguments,
|
|
117893
|
-
result: item.result ?? null,
|
|
117894
|
-
error: item.error ?? null,
|
|
117895
|
-
status: item.status
|
|
117896
|
-
};
|
|
117897
|
-
case "webSearch":
|
|
117898
|
-
case "web_search":
|
|
117899
|
-
return { query: item.query };
|
|
117900
|
-
case "todoList":
|
|
117901
|
-
case "todo_list":
|
|
117902
|
-
return { items: item.items };
|
|
117903
|
-
case "error":
|
|
117904
|
-
return { message: item.message };
|
|
117905
|
-
default:
|
|
117906
|
-
return {};
|
|
117907
|
-
}
|
|
117908
|
-
}
|
|
117909
|
-
function getItemStatus(item) {
|
|
117910
|
-
if (item.type === "commandExecution" || item.type === "command_execution" || item.type === "fileChange" || item.type === "file_change" || item.type === "mcpToolCall" || item.type === "mcp_tool_call") {
|
|
117911
|
-
return item.status ?? "completed";
|
|
117912
|
-
}
|
|
117913
|
-
if (item.type === "error") {
|
|
117914
|
-
return "failed";
|
|
117915
|
-
}
|
|
117916
|
-
return "completed";
|
|
117917
|
-
}
|
|
117918
|
-
|
|
117919
118496
|
// src/codex/codex-host.ts
|
|
117920
118497
|
import { EventEmitter as EventEmitter4 } from "node:events";
|
|
117921
118498
|
import { PassThrough as PassThrough2, Writable as Writable2 } from "node:stream";
|
|
@@ -118342,103 +118919,6 @@ function mapTokenUsage(data) {
|
|
|
118342
118919
|
};
|
|
118343
118920
|
}
|
|
118344
118921
|
|
|
118345
|
-
// src/apps/register-mcp.ts
|
|
118346
|
-
import fs10 from "node:fs";
|
|
118347
|
-
import path14 from "node:path";
|
|
118348
|
-
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
118349
|
-
var MCP_SERVER_NAME = "agentpane-miniapps";
|
|
118350
|
-
function panePublicUrl() {
|
|
118351
|
-
return (process.env.AGENT_PANE_PUBLIC_URL || process.env.REPOBURG_DAEMON_URL || "http://localhost:9998").replace(/\/+$/, "");
|
|
118352
|
-
}
|
|
118353
|
-
function stdioScriptPath() {
|
|
118354
|
-
const here = path14.dirname(fileURLToPath4(import.meta.url));
|
|
118355
|
-
const candidates = [
|
|
118356
|
-
path14.resolve(here, "../../scripts/miniapp-mcp-stdio.mjs"),
|
|
118357
|
-
// src/apps/ → backend/scripts
|
|
118358
|
-
path14.resolve(here, "../scripts/miniapp-mcp-stdio.mjs")
|
|
118359
|
-
// dist bundle → backend/scripts
|
|
118360
|
-
];
|
|
118361
|
-
for (const candidate of candidates) {
|
|
118362
|
-
if (fs10.existsSync(candidate)) return candidate;
|
|
118363
|
-
}
|
|
118364
|
-
return null;
|
|
118365
|
-
}
|
|
118366
|
-
var registered = /* @__PURE__ */ new Set();
|
|
118367
|
-
async function registerMiniAppMcp(baseUrl, workspace = "") {
|
|
118368
|
-
const key = `${baseUrl}|${workspace}`;
|
|
118369
|
-
if (registered.has(key)) return true;
|
|
118370
|
-
const script = stdioScriptPath();
|
|
118371
|
-
if (!script) {
|
|
118372
|
-
console.warn("[miniapp-mcp] stdio proxy script not found \u2014 registration skipped");
|
|
118373
|
-
return false;
|
|
118374
|
-
}
|
|
118375
|
-
if (!anyAppHasTools()) {
|
|
118376
|
-
return false;
|
|
118377
|
-
}
|
|
118378
|
-
const base = baseUrl.replace(/\/+$/, "");
|
|
118379
|
-
try {
|
|
118380
|
-
try {
|
|
118381
|
-
const res2 = await fetch(`${base}/mcp/servers`, { signal: AbortSignal.timeout(5e3) });
|
|
118382
|
-
if (res2.ok) {
|
|
118383
|
-
const servers = await res2.json();
|
|
118384
|
-
const names = servers.map((s) => s.server_name ?? s.name);
|
|
118385
|
-
if (names.includes(MCP_SERVER_NAME)) {
|
|
118386
|
-
await fetch(`${base}/mcp/configs/${MCP_SERVER_NAME}`, {
|
|
118387
|
-
method: "DELETE",
|
|
118388
|
-
signal: AbortSignal.timeout(5e3)
|
|
118389
|
-
}).catch(() => {
|
|
118390
|
-
});
|
|
118391
|
-
}
|
|
118392
|
-
}
|
|
118393
|
-
} catch {
|
|
118394
|
-
}
|
|
118395
|
-
const body = {
|
|
118396
|
-
configJson: JSON.stringify({
|
|
118397
|
-
[MCP_SERVER_NAME]: {
|
|
118398
|
-
command: process.execPath,
|
|
118399
|
-
args: [script, panePublicUrl(), workspace],
|
|
118400
|
-
env: { AGENT_PANE_SESSION_ID: "" }
|
|
118401
|
-
}
|
|
118402
|
-
})
|
|
118403
|
-
};
|
|
118404
|
-
const res = await fetch(`${base}/mcp/configs`, {
|
|
118405
|
-
method: "POST",
|
|
118406
|
-
headers: { "Content-Type": "application/json" },
|
|
118407
|
-
body: JSON.stringify(body),
|
|
118408
|
-
signal: AbortSignal.timeout(1e4)
|
|
118409
|
-
});
|
|
118410
|
-
if (res.status === 201) {
|
|
118411
|
-
console.log(`[miniapp-mcp] gateway registered in workspace backend ${base} (workspace: ${workspace || "global"})`);
|
|
118412
|
-
registered.add(key);
|
|
118413
|
-
return true;
|
|
118414
|
-
}
|
|
118415
|
-
const text2 = await res.text();
|
|
118416
|
-
if (res.status === 400 && /already exists/i.test(text2)) {
|
|
118417
|
-
registered.add(key);
|
|
118418
|
-
return true;
|
|
118419
|
-
}
|
|
118420
|
-
console.warn(`[miniapp-mcp] registration failed (${res.status}): ${text2.slice(0, 200)}`);
|
|
118421
|
-
return false;
|
|
118422
|
-
} catch (err) {
|
|
118423
|
-
console.warn(`[miniapp-mcp] registration error: ${err.message}`);
|
|
118424
|
-
return false;
|
|
118425
|
-
}
|
|
118426
|
-
}
|
|
118427
|
-
function codexMiniAppLaunchArgs(workspace = "", sessionId = "") {
|
|
118428
|
-
const script = stdioScriptPath();
|
|
118429
|
-
if (!script || !anyAppHasTools()) return null;
|
|
118430
|
-
return [
|
|
118431
|
-
// MCP tool calls must not ask for elicitation approval — nobody is
|
|
118432
|
-
// watching an agent-driven session to approve (feature is stable/on).
|
|
118433
|
-
"-c",
|
|
118434
|
-
"features.tool_call_mcp_elicitation=false",
|
|
118435
|
-
"-c",
|
|
118436
|
-
`mcp_servers.${MCP_SERVER_NAME}.command=${JSON.stringify(process.execPath)}`,
|
|
118437
|
-
"-c",
|
|
118438
|
-
`mcp_servers.${MCP_SERVER_NAME}.args=${JSON.stringify([script, panePublicUrl(), workspace, ...sessionId ? [sessionId] : []])}`
|
|
118439
|
-
];
|
|
118440
|
-
}
|
|
118441
|
-
|
|
118442
118922
|
// src/claude/cli-orphans.ts
|
|
118443
118923
|
import { execFile as execFile4 } from "node:child_process";
|
|
118444
118924
|
var TERM_GRACE_MS = 2e3;
|
|
@@ -118536,6 +119016,11 @@ function reapOrphanCliProcesses(db2, deps = defaultDeps) {
|
|
|
118536
119016
|
}
|
|
118537
119017
|
|
|
118538
119018
|
// src/codex/codex-provider.ts
|
|
119019
|
+
var TERMINAL_TASK_TYPE = "background_terminal";
|
|
119020
|
+
function taskPollMs() {
|
|
119021
|
+
const ms = Number(process.env.AGENT_PANE_CODEX_TASK_POLL_MS);
|
|
119022
|
+
return Number.isFinite(ms) && ms > 0 ? ms : 5e3;
|
|
119023
|
+
}
|
|
118539
119024
|
var sessionMap = /* @__PURE__ */ new Map();
|
|
118540
119025
|
var startingThreads = /* @__PURE__ */ new Map();
|
|
118541
119026
|
var ENDED_TURNS_KEPT = 20;
|
|
@@ -118579,22 +119064,34 @@ function sandboxType(config3) {
|
|
|
118579
119064
|
return "workspace-write";
|
|
118580
119065
|
}
|
|
118581
119066
|
}
|
|
118582
|
-
function
|
|
118583
|
-
|
|
118584
|
-
|
|
118585
|
-
|
|
118586
|
-
|
|
118587
|
-
|
|
118588
|
-
|
|
118589
|
-
|
|
118590
|
-
|
|
118591
|
-
|
|
118592
|
-
|
|
119067
|
+
function sandboxPolicy(config3) {
|
|
119068
|
+
if (!config3 || !config3.sandboxMode && config3.networkAccessEnabled === void 0) return null;
|
|
119069
|
+
const networkAccess = config3.networkAccessEnabled === true;
|
|
119070
|
+
switch (sandboxType(config3)) {
|
|
119071
|
+
case "read-only":
|
|
119072
|
+
return { type: "readOnly", networkAccess };
|
|
119073
|
+
case "danger-full-access":
|
|
119074
|
+
return { type: "dangerFullAccess" };
|
|
119075
|
+
default:
|
|
119076
|
+
return { type: "workspaceWrite", networkAccess };
|
|
119077
|
+
}
|
|
119078
|
+
}
|
|
119079
|
+
function threadConfig(config3) {
|
|
119080
|
+
return config3?.webSearchMode ? { web_search: config3.webSearchMode } : void 0;
|
|
119081
|
+
}
|
|
119082
|
+
function threadParams(session, cwd) {
|
|
119083
|
+
const config3 = parseRuntimeConfig(session);
|
|
119084
|
+
return {
|
|
119085
|
+
cwd,
|
|
119086
|
+
approvalPolicy: "never",
|
|
119087
|
+
sandbox: sandboxType(config3),
|
|
119088
|
+
model: session.model ?? void 0,
|
|
119089
|
+
config: threadConfig(config3),
|
|
119090
|
+
...threadInstructionParams(cwd)
|
|
118593
119091
|
};
|
|
118594
|
-
return map2[type] ?? type;
|
|
118595
119092
|
}
|
|
118596
119093
|
function shouldSkipItem(type) {
|
|
118597
|
-
return type === "userMessage" || type === "user_message";
|
|
119094
|
+
return type === "userMessage" || type === "user_message" || type === "enteredReviewMode" || type === "exitedReviewMode";
|
|
118598
119095
|
}
|
|
118599
119096
|
function isEmptyReasoning(item) {
|
|
118600
119097
|
const summary = Array.isArray(item.summary) ? item.summary : [];
|
|
@@ -118636,9 +119133,32 @@ function untrackProcess(pid) {
|
|
|
118636
119133
|
} catch {
|
|
118637
119134
|
}
|
|
118638
119135
|
}
|
|
119136
|
+
function emptyThreadState() {
|
|
119137
|
+
return {
|
|
119138
|
+
threadId: "",
|
|
119139
|
+
sideThreads: /* @__PURE__ */ new Map(),
|
|
119140
|
+
loadingSide: /* @__PURE__ */ new Map(),
|
|
119141
|
+
codexThreads: /* @__PURE__ */ new Set(),
|
|
119142
|
+
webSearch: void 0,
|
|
119143
|
+
contextTokens: /* @__PURE__ */ new Map(),
|
|
119144
|
+
compactions: /* @__PURE__ */ new Map(),
|
|
119145
|
+
publishedContext: null,
|
|
119146
|
+
tasks: /* @__PURE__ */ new Map(),
|
|
119147
|
+
publishedTasks: "[]",
|
|
119148
|
+
taskTimer: null,
|
|
119149
|
+
refreshing: null,
|
|
119150
|
+
refreshAgain: false
|
|
119151
|
+
};
|
|
119152
|
+
}
|
|
118639
119153
|
function getOrCreateThread(session) {
|
|
118640
119154
|
const existing = sessionMap.get(session.id);
|
|
118641
|
-
if (existing && !existing.client.isClosed())
|
|
119155
|
+
if (existing && !existing.client.isClosed()) {
|
|
119156
|
+
const webSearch = threadConfig(parseRuntimeConfig(session))?.web_search;
|
|
119157
|
+
if (webSearch === existing.webSearch || existing.turns.length > 0 || existing.tasks.size > 0) {
|
|
119158
|
+
return Promise.resolve(existing);
|
|
119159
|
+
}
|
|
119160
|
+
void retireEntry(existing, "keep");
|
|
119161
|
+
}
|
|
118642
119162
|
const pending = startingThreads.get(session.id);
|
|
118643
119163
|
if (pending) return pending;
|
|
118644
119164
|
const started = startThread(session).finally(() => startingThreads.delete(session.id));
|
|
@@ -118665,7 +119185,7 @@ async function startThread(session) {
|
|
|
118665
119185
|
client,
|
|
118666
119186
|
// A hosted app-server has no cli_processes row: its host supervises it.
|
|
118667
119187
|
pid: host ? void 0 : client.pid,
|
|
118668
|
-
|
|
119188
|
+
...emptyThreadState(),
|
|
118669
119189
|
turns: [],
|
|
118670
119190
|
ended: /* @__PURE__ */ new Map(),
|
|
118671
119191
|
resumedTurnIds: null,
|
|
@@ -118678,33 +119198,25 @@ async function startThread(session) {
|
|
|
118678
119198
|
listen(entry);
|
|
118679
119199
|
try {
|
|
118680
119200
|
await client.initialize();
|
|
118681
|
-
|
|
118682
|
-
|
|
118683
|
-
|
|
118684
|
-
const config3 = parseRuntimeConfig(session);
|
|
118685
|
-
const sandbox = sandboxType(config3);
|
|
118686
|
-
const instructions = threadInstructionParams(cwd);
|
|
119201
|
+
autoApproveToolUserInput(client);
|
|
119202
|
+
const base = threadParams(session, cwd);
|
|
119203
|
+
entry.webSearch = base.config?.web_search;
|
|
118687
119204
|
if (session.external_thread_id) {
|
|
119205
|
+
entry.threadId = session.external_thread_id;
|
|
119206
|
+
entry.codexThreads.add(entry.threadId);
|
|
118688
119207
|
const result = await client.request("thread/resume", {
|
|
118689
119208
|
threadId: session.external_thread_id,
|
|
118690
|
-
|
|
118691
|
-
approvalPolicy: "never",
|
|
118692
|
-
sandbox,
|
|
118693
|
-
model: session.model ?? void 0,
|
|
118694
|
-
...instructions
|
|
119209
|
+
...base
|
|
118695
119210
|
});
|
|
118696
119211
|
entry.threadId = result.thread.id;
|
|
118697
119212
|
entry.resumedTurnIds = new Set((result.thread.turns ?? []).map((t) => t.id));
|
|
118698
|
-
noteHostThread(entry);
|
|
118699
119213
|
} else {
|
|
118700
119214
|
const result = await client.request("thread/start", {
|
|
118701
|
-
|
|
118702
|
-
|
|
118703
|
-
sandbox,
|
|
118704
|
-
model: session.model ?? void 0,
|
|
118705
|
-
...instructions
|
|
119215
|
+
...base,
|
|
119216
|
+
threadSource: PANE_THREAD_SOURCE
|
|
118706
119217
|
});
|
|
118707
119218
|
entry.threadId = result.thread.id;
|
|
119219
|
+
recordCodexThread(entry.threadId, session.id);
|
|
118708
119220
|
const db2 = getDb();
|
|
118709
119221
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
118710
119222
|
db2.prepare("UPDATE sessions SET external_thread_id = ?, updated_at = ? WHERE id = ?").run(
|
|
@@ -118712,8 +119224,9 @@ async function startThread(session) {
|
|
|
118712
119224
|
now,
|
|
118713
119225
|
session.id
|
|
118714
119226
|
);
|
|
118715
|
-
noteHostThread(entry);
|
|
118716
119227
|
}
|
|
119228
|
+
entry.codexThreads.add(entry.threadId);
|
|
119229
|
+
noteHostThread(entry);
|
|
118717
119230
|
} catch (err) {
|
|
118718
119231
|
void retireEntry(entry, "keep");
|
|
118719
119232
|
throw err;
|
|
@@ -118736,6 +119249,7 @@ function retireEntry(entry, left, error51 = "App-server closed") {
|
|
|
118736
119249
|
}
|
|
118737
119250
|
}
|
|
118738
119251
|
}
|
|
119252
|
+
dropTasks(entry);
|
|
118739
119253
|
entry.closing = entry.client.close().catch(() => {
|
|
118740
119254
|
}).finally(async () => {
|
|
118741
119255
|
untrackProcess(entry.pid);
|
|
@@ -118746,6 +119260,7 @@ function retireEntry(entry, left, error51 = "App-server closed") {
|
|
|
118746
119260
|
function onClientClosed(entry, reason) {
|
|
118747
119261
|
if (sessionMap.get(entry.sessionId) === entry) sessionMap.delete(entry.sessionId);
|
|
118748
119262
|
untrackProcess(entry.pid);
|
|
119263
|
+
if (!entry.closing) dropTasks(entry);
|
|
118749
119264
|
if (entry.host && !entry.closing) void releaseCodexHost(entry.host);
|
|
118750
119265
|
if (entry.closing || entry.turns.length === 0) return;
|
|
118751
119266
|
let db2;
|
|
@@ -118778,22 +119293,45 @@ function endTurn(entry, active) {
|
|
|
118778
119293
|
}
|
|
118779
119294
|
function rememberEnded(entry, active) {
|
|
118780
119295
|
if (!active.codexId) return;
|
|
118781
|
-
entry
|
|
119296
|
+
rememberTurnId(entry, active.codexId, active.id);
|
|
119297
|
+
}
|
|
119298
|
+
function rememberTurnId(entry, codexId, paneTurnId) {
|
|
119299
|
+
entry.ended.set(codexId, paneTurnId);
|
|
118782
119300
|
if (entry.ended.size > ENDED_TURNS_KEPT) entry.ended.delete(entry.ended.keys().next().value);
|
|
118783
119301
|
}
|
|
118784
|
-
function
|
|
118785
|
-
|
|
118786
|
-
|
|
118787
|
-
|
|
118788
|
-
|
|
118789
|
-
|
|
118790
|
-
waiting.codexId = codexId;
|
|
119302
|
+
function runsOn(active, threadId) {
|
|
119303
|
+
return active.codexThreadId === null || active.codexThreadId === threadId;
|
|
119304
|
+
}
|
|
119305
|
+
function bindCodexId(active, codexId) {
|
|
119306
|
+
active.codexId = codexId;
|
|
119307
|
+
active.resolveStarted(codexId);
|
|
118791
119308
|
try {
|
|
118792
|
-
getDb().prepare("UPDATE turns SET external_turn_id = ?, updated_at = ? WHERE id = ? AND external_turn_id IS NULL").run(codexId, (/* @__PURE__ */ new Date()).toISOString(),
|
|
119309
|
+
getDb().prepare("UPDATE turns SET external_turn_id = ?, updated_at = ? WHERE id = ? AND external_turn_id IS NULL").run(codexId, (/* @__PURE__ */ new Date()).toISOString(), active.id);
|
|
118793
119310
|
} catch {
|
|
118794
119311
|
}
|
|
119312
|
+
}
|
|
119313
|
+
function liveTurnsOf(entry, threadId, codexId) {
|
|
119314
|
+
if (!codexId) return entry.turns.filter((t) => runsOn(t, threadId)).slice(-1);
|
|
119315
|
+
const known = entry.turns.filter((t) => t.codexId === codexId);
|
|
119316
|
+
if (known.length > 0 || entry.ended.has(codexId)) return known;
|
|
119317
|
+
const waiting = entry.turns.find((t) => t.codexId === null && t.kind !== "review" && runsOn(t, threadId));
|
|
119318
|
+
if (!waiting) return [];
|
|
119319
|
+
bindCodexId(waiting, codexId);
|
|
118795
119320
|
return [waiting];
|
|
118796
119321
|
}
|
|
119322
|
+
function deferToReview(entry, threadId, codexId, replay) {
|
|
119323
|
+
if (!codexId) return false;
|
|
119324
|
+
const review = entry.turns.find((t) => t.kind === "review" && t.codexId === null && t.codexThreadId === threadId);
|
|
119325
|
+
if (!review) return false;
|
|
119326
|
+
review.early.push({ codexId, replay });
|
|
119327
|
+
return true;
|
|
119328
|
+
}
|
|
119329
|
+
function releaseEarly(entry, active) {
|
|
119330
|
+
for (const event of active.early.splice(0)) {
|
|
119331
|
+
if (event.codexId === active.codexId) event.replay();
|
|
119332
|
+
else rememberTurnId(entry, event.codexId, active.id);
|
|
119333
|
+
}
|
|
119334
|
+
}
|
|
118797
119335
|
function noteContinued(active) {
|
|
118798
119336
|
if (!active.resuming) return;
|
|
118799
119337
|
active.resuming = false;
|
|
@@ -118870,10 +119408,11 @@ function listen(entry) {
|
|
|
118870
119408
|
const on = (method, handle) => {
|
|
118871
119409
|
entry.client.onNotification(method, (params) => {
|
|
118872
119410
|
const p = params;
|
|
118873
|
-
if (!p || p.threadId
|
|
119411
|
+
if (!p || !entry.codexThreads.has(p.threadId)) return;
|
|
118874
119412
|
handle(p);
|
|
118875
119413
|
});
|
|
118876
119414
|
};
|
|
119415
|
+
on("turn/started", (p) => onTurnStarted(entry, p));
|
|
118877
119416
|
on("item/started", (p) => onItem(entry, p, "in_progress", "item:started"));
|
|
118878
119417
|
on("item/updated", (p) => onItem(entry, p, "in_progress", "item:updated"));
|
|
118879
119418
|
on("item/completed", (p) => onItem(entry, p, getItemStatus(p.item), "item:completed"));
|
|
@@ -118883,19 +119422,57 @@ function listen(entry) {
|
|
|
118883
119422
|
on("thread/tokenUsage/updated", (p) => onTokenUsage(entry, p));
|
|
118884
119423
|
entry.client.events.once("closed", (reason) => onClientClosed(entry, reason));
|
|
118885
119424
|
}
|
|
119425
|
+
function onTurnStarted(entry, p) {
|
|
119426
|
+
const codexId = p.turn?.id;
|
|
119427
|
+
if (!codexId || entry.ended.has(codexId) || entry.turns.some((t) => t.codexId === codexId)) return;
|
|
119428
|
+
const onThread = entry.turns.filter((t) => t.codexThreadId === p.threadId);
|
|
119429
|
+
const compaction = onThread.find((t) => t.kind === "compact" && t.codexId === null);
|
|
119430
|
+
if (compaction) {
|
|
119431
|
+
bindCodexId(compaction, codexId);
|
|
119432
|
+
return;
|
|
119433
|
+
}
|
|
119434
|
+
const review = onThread.find((t) => t.kind === "review");
|
|
119435
|
+
if (review?.codexId) rememberTurnId(entry, codexId, review.id);
|
|
119436
|
+
else if (review) review.early.push({ codexId, replay: () => {
|
|
119437
|
+
} });
|
|
119438
|
+
}
|
|
118886
119439
|
function onItem(entry, p, status, event) {
|
|
118887
|
-
const [live] = liveTurnsOf(entry, p.turnId);
|
|
119440
|
+
const [live] = liveTurnsOf(entry, p.threadId, p.turnId);
|
|
118888
119441
|
if (live) {
|
|
118889
119442
|
if (!shouldSkipItem(p.item.type)) noteContinued(live);
|
|
118890
|
-
handleItemEvent(p, entry.sessionId, live.id, status, event);
|
|
119443
|
+
handleItemEvent(p, entry.sessionId, live.id, status, event, compactionData(entry, live, p, event));
|
|
118891
119444
|
return;
|
|
118892
119445
|
}
|
|
118893
119446
|
const ended = p.turnId ? entry.ended.get(p.turnId) : void 0;
|
|
118894
|
-
if (ended)
|
|
119447
|
+
if (ended) {
|
|
119448
|
+
handleItemEvent(p, entry.sessionId, ended, status, event, compactionData(entry, null, p, event));
|
|
119449
|
+
if (event === "item:completed" && [...entry.tasks.values()].some((t) => t.commandItemId === p.item.id)) {
|
|
119450
|
+
refreshBackgroundTasks(entry);
|
|
119451
|
+
}
|
|
119452
|
+
return;
|
|
119453
|
+
}
|
|
119454
|
+
deferToReview(entry, p.threadId, p.turnId, () => onItem(entry, p, status, event));
|
|
119455
|
+
}
|
|
119456
|
+
function compactionData(entry, live, p, event) {
|
|
119457
|
+
if (p.item.type !== "contextCompaction") return void 0;
|
|
119458
|
+
let compaction = entry.compactions.get(p.item.id);
|
|
119459
|
+
if (!compaction) {
|
|
119460
|
+
compaction = { threadId: p.threadId, pre: entry.contextTokens.get(p.threadId) ?? null, post: null, done: false };
|
|
119461
|
+
entry.compactions.set(p.item.id, compaction);
|
|
119462
|
+
if (entry.compactions.size > ENDED_TURNS_KEPT) {
|
|
119463
|
+
entry.compactions.delete(entry.compactions.keys().next().value);
|
|
119464
|
+
}
|
|
119465
|
+
}
|
|
119466
|
+
if (event === "item:completed") compaction.done = true;
|
|
119467
|
+
const post = compaction.done ? compaction.post : null;
|
|
119468
|
+
return { trigger: live?.kind === "compact" ? "manual" : "auto", pre_tokens: compaction.pre, post_tokens: post };
|
|
118895
119469
|
}
|
|
118896
119470
|
function onAgentMessageDelta(entry, p) {
|
|
118897
|
-
const [live] = liveTurnsOf(entry, p.turnId);
|
|
118898
|
-
if (!live)
|
|
119471
|
+
const [live] = liveTurnsOf(entry, p.threadId, p.turnId);
|
|
119472
|
+
if (!live) {
|
|
119473
|
+
deferToReview(entry, p.threadId, p.turnId, () => onAgentMessageDelta(entry, p));
|
|
119474
|
+
return;
|
|
119475
|
+
}
|
|
118899
119476
|
noteContinued(live);
|
|
118900
119477
|
const payload = { sessionId: entry.sessionId, turnId: live.id, itemId: p.itemId, delta: p.delta };
|
|
118901
119478
|
if (entry.replaying) noteDelta(payload);
|
|
@@ -118903,7 +119480,10 @@ function onAgentMessageDelta(entry, p) {
|
|
|
118903
119480
|
}
|
|
118904
119481
|
function onTurnCompleted(entry, p) {
|
|
118905
119482
|
const db2 = getDb();
|
|
118906
|
-
|
|
119483
|
+
const codexId = p.turn?.id ?? p.turnId;
|
|
119484
|
+
const lives = liveTurnsOf(entry, p.threadId, codexId);
|
|
119485
|
+
if (lives.length === 0 && deferToReview(entry, p.threadId, codexId, () => onTurnCompleted(entry, p))) return;
|
|
119486
|
+
for (const live of lives) {
|
|
118907
119487
|
if (p.turn?.status === "interrupted") {
|
|
118908
119488
|
cancelTurn(entry, live);
|
|
118909
119489
|
} else if (p.turn?.status === "failed") {
|
|
@@ -118914,16 +119494,21 @@ function onTurnCompleted(entry, p) {
|
|
|
118914
119494
|
completeTurn(db2, entry.sessionId, live.id, p.usage);
|
|
118915
119495
|
}
|
|
118916
119496
|
}
|
|
119497
|
+
refreshBackgroundTasks(entry);
|
|
118917
119498
|
}
|
|
118918
119499
|
function onTurnFailed(entry, p) {
|
|
118919
119500
|
const db2 = getDb();
|
|
118920
|
-
|
|
119501
|
+
const lives = liveTurnsOf(entry, p.threadId, p.turnId);
|
|
119502
|
+
if (lives.length === 0 && deferToReview(entry, p.threadId, p.turnId, () => onTurnFailed(entry, p))) return;
|
|
119503
|
+
for (const live of lives) {
|
|
118921
119504
|
endTurn(entry, live);
|
|
118922
119505
|
failTurn(db2, entry.sessionId, live.id, p.error.message);
|
|
118923
119506
|
}
|
|
119507
|
+
refreshBackgroundTasks(entry);
|
|
118924
119508
|
}
|
|
118925
119509
|
function onTokenUsage(entry, p) {
|
|
118926
|
-
|
|
119510
|
+
noteContext(entry, p);
|
|
119511
|
+
const turnId = liveTurnsOf(entry, p.threadId, p.turnId)[0]?.id ?? (p.turnId ? entry.ended.get(p.turnId) : void 0);
|
|
118927
119512
|
if (!turnId) return;
|
|
118928
119513
|
const usage = mapTokenUsage(p.tokenUsage.total);
|
|
118929
119514
|
const db2 = getDb();
|
|
@@ -118931,6 +119516,30 @@ function onTokenUsage(entry, p) {
|
|
|
118931
119516
|
db2.prepare("UPDATE turns SET token_usage = ?, updated_at = ? WHERE id = ?").run(JSON.stringify(usage), now, turnId);
|
|
118932
119517
|
broadcast("turn:tokenUsage", { sessionId: entry.sessionId, turnId, usage });
|
|
118933
119518
|
}
|
|
119519
|
+
function noteContext(entry, p) {
|
|
119520
|
+
const last = p.tokenUsage?.last;
|
|
119521
|
+
if (!last) return;
|
|
119522
|
+
const tokens2 = Math.max(0, (last.totalTokens ?? 0) - (last.reasoningOutputTokens ?? 0));
|
|
119523
|
+
entry.contextTokens.set(p.threadId, tokens2);
|
|
119524
|
+
for (const compaction of entry.compactions.values()) {
|
|
119525
|
+
if (compaction.threadId === p.threadId && !compaction.done) compaction.post = tokens2;
|
|
119526
|
+
}
|
|
119527
|
+
const window = p.tokenUsage.modelContextWindow;
|
|
119528
|
+
if (p.threadId !== entry.threadId || !window || window <= 0) return;
|
|
119529
|
+
const usage = {
|
|
119530
|
+
totalTokens: tokens2,
|
|
119531
|
+
contextWindow: window,
|
|
119532
|
+
percentage: Math.min(100, Math.round(tokens2 / window * 100))
|
|
119533
|
+
};
|
|
119534
|
+
const json2 = JSON.stringify(usage);
|
|
119535
|
+
if (json2 === entry.publishedContext) return;
|
|
119536
|
+
entry.publishedContext = json2;
|
|
119537
|
+
broadcast("turn:contextUsage", { sessionId: entry.sessionId, ...usage });
|
|
119538
|
+
try {
|
|
119539
|
+
getDb().prepare("UPDATE sessions SET context_usage = ? WHERE id = ?").run(json2, entry.sessionId);
|
|
119540
|
+
} catch {
|
|
119541
|
+
}
|
|
119542
|
+
}
|
|
118934
119543
|
function turnAttachments2(turn) {
|
|
118935
119544
|
const raw = turn.attachments;
|
|
118936
119545
|
if (!raw) return [];
|
|
@@ -118944,16 +119553,14 @@ function turnAttachments2(turn) {
|
|
|
118944
119553
|
}
|
|
118945
119554
|
function buildCodexInput(turn) {
|
|
118946
119555
|
const input = [{ type: "text", text: turn.user_prompt }];
|
|
119556
|
+
const saved = /* @__PURE__ */ new Set();
|
|
118947
119557
|
for (const att of turnAttachments2(turn)) {
|
|
118948
119558
|
if (!att || typeof att.data !== "string" || !att.data) continue;
|
|
118949
119559
|
const type = String(att.media_type ?? "").toLowerCase();
|
|
118950
119560
|
if (type.startsWith("image/")) {
|
|
118951
119561
|
input.push({ type: "image", url: `data:${type};base64,${att.data}` });
|
|
118952
119562
|
} else if (type === "application/pdf") {
|
|
118953
|
-
input.push({
|
|
118954
|
-
type: "text",
|
|
118955
|
-
text: `[Attachment ${att.name} (PDF) was not sent: Codex does not accept PDF files.]`
|
|
118956
|
-
});
|
|
119563
|
+
input.push({ type: "text", text: pdfNote(turn, att, saved) });
|
|
118957
119564
|
} else {
|
|
118958
119565
|
const decoded = Buffer.from(att.data, "base64").toString("utf-8");
|
|
118959
119566
|
input.push({ type: "text", text: `
|
|
@@ -118964,17 +119571,76 @@ ${decoded}
|
|
|
118964
119571
|
}
|
|
118965
119572
|
return input;
|
|
118966
119573
|
}
|
|
118967
|
-
|
|
119574
|
+
function pdfNote(turn, att, saved) {
|
|
119575
|
+
try {
|
|
119576
|
+
const file2 = saveAttachmentFile(turn.session_id, turn.id, att.name || "attachment.pdf", att.data, saved);
|
|
119577
|
+
return `[The user attached the PDF "${att.name}". Codex cannot take PDF input, so it is saved at ${file2}; read it from there.]`;
|
|
119578
|
+
} catch (err) {
|
|
119579
|
+
return `[Attachment ${att.name} (PDF) was not sent: it could not be saved for Codex (${err.message}).]`;
|
|
119580
|
+
}
|
|
119581
|
+
}
|
|
119582
|
+
var CODEX_COMMANDS = [
|
|
119583
|
+
{ name: "compact", description: "Summarize the conversation to free up the model's context" },
|
|
119584
|
+
{
|
|
119585
|
+
name: "review",
|
|
119586
|
+
description: "Review the uncommitted changes, the changes against a base branch, a commit, or by your instructions",
|
|
119587
|
+
argumentHint: "[base <branch> | commit <sha> | <instructions>]"
|
|
119588
|
+
}
|
|
119589
|
+
];
|
|
119590
|
+
function parseCodexCommand(prompt) {
|
|
119591
|
+
const match = /^\/(compact|review)(?:\s+([\s\S]*))?$/.exec(prompt.trim());
|
|
119592
|
+
if (!match) return null;
|
|
119593
|
+
const args = (match[2] ?? "").trim();
|
|
119594
|
+
if (match[1] === "compact") return args ? null : { kind: "compact" };
|
|
119595
|
+
if (!args) return { kind: "review", target: { type: "uncommittedChanges" } };
|
|
119596
|
+
const base = /^base\s+(\S+)$/i.exec(args);
|
|
119597
|
+
if (base) return { kind: "review", target: { type: "baseBranch", branch: base[1] } };
|
|
119598
|
+
const commit = /^commit\s+([0-9a-f]{4,40})$/i.exec(args);
|
|
119599
|
+
if (commit) return { kind: "review", target: { type: "commit", sha: commit[1] } };
|
|
119600
|
+
return { kind: "review", target: { type: "custom", instructions: args } };
|
|
119601
|
+
}
|
|
119602
|
+
function turnRequest(turn) {
|
|
119603
|
+
return parseCodexCommand(turn.user_prompt) ?? { kind: "prompt", input: buildCodexInput(turn) };
|
|
119604
|
+
}
|
|
119605
|
+
async function sendTurnRequest(session, entry, threadId, request) {
|
|
119606
|
+
if (request.kind === "compact") {
|
|
119607
|
+
await entry.client.request("thread/compact/start", { threadId });
|
|
119608
|
+
return null;
|
|
119609
|
+
}
|
|
119610
|
+
if (request.kind === "review") {
|
|
119611
|
+
const result2 = await entry.client.request("review/start", {
|
|
119612
|
+
threadId,
|
|
119613
|
+
target: request.target,
|
|
119614
|
+
delivery: "inline"
|
|
119615
|
+
});
|
|
119616
|
+
return result2.turn.id;
|
|
119617
|
+
}
|
|
119618
|
+
const policy = sandboxPolicy(parseRuntimeConfig(session));
|
|
119619
|
+
const result = await entry.client.request("turn/start", {
|
|
119620
|
+
threadId,
|
|
119621
|
+
input: request.input,
|
|
119622
|
+
approvalPolicy: "never",
|
|
119623
|
+
...policy ? { sandboxPolicy: policy } : {},
|
|
119624
|
+
model: session.model ?? void 0,
|
|
119625
|
+
effort: session.model_reasoning_effort ?? void 0
|
|
119626
|
+
});
|
|
119627
|
+
return result.turn.id;
|
|
119628
|
+
}
|
|
119629
|
+
async function runTurn(session, turn, entry, codexThreadId, request, resume) {
|
|
118968
119630
|
const db2 = getDb();
|
|
118969
|
-
const sandbox = sandboxType(parseRuntimeConfig(session));
|
|
118970
119631
|
let resolveStarted;
|
|
119632
|
+
const started = new Promise((resolve) => {
|
|
119633
|
+
resolveStarted = resolve;
|
|
119634
|
+
});
|
|
118971
119635
|
const active = {
|
|
118972
119636
|
id: turn.id,
|
|
118973
119637
|
discussionThreadId: turn.thread_id ?? null,
|
|
119638
|
+
codexThreadId,
|
|
119639
|
+
kind: request.kind,
|
|
118974
119640
|
codexId: null,
|
|
118975
|
-
started
|
|
118976
|
-
|
|
118977
|
-
|
|
119641
|
+
started,
|
|
119642
|
+
resolveStarted,
|
|
119643
|
+
early: [],
|
|
118978
119644
|
done: false,
|
|
118979
119645
|
resuming: resume,
|
|
118980
119646
|
hostOffset: null
|
|
@@ -118982,22 +119648,18 @@ async function runTurn(session, turn, entry, input, resume) {
|
|
|
118982
119648
|
entry.turns.push(active);
|
|
118983
119649
|
bindHostTurn(entry, active);
|
|
118984
119650
|
try {
|
|
118985
|
-
const
|
|
118986
|
-
|
|
118987
|
-
|
|
118988
|
-
|
|
118989
|
-
|
|
118990
|
-
|
|
118991
|
-
|
|
118992
|
-
|
|
118993
|
-
|
|
118994
|
-
|
|
118995
|
-
|
|
118996
|
-
|
|
118997
|
-
(/* @__PURE__ */ new Date()).toISOString(),
|
|
118998
|
-
turn.id
|
|
118999
|
-
);
|
|
119000
|
-
resolveStarted(result.turn.id);
|
|
119651
|
+
const codexId = await sendTurnRequest(session, entry, codexThreadId, request);
|
|
119652
|
+
if (codexId) {
|
|
119653
|
+
active.codexId = codexId;
|
|
119654
|
+
if (active.done) rememberEnded(entry, active);
|
|
119655
|
+
db2.prepare("UPDATE turns SET external_turn_id = ?, updated_at = ? WHERE id = ?").run(
|
|
119656
|
+
codexId,
|
|
119657
|
+
(/* @__PURE__ */ new Date()).toISOString(),
|
|
119658
|
+
turn.id
|
|
119659
|
+
);
|
|
119660
|
+
resolveStarted(codexId);
|
|
119661
|
+
releaseEarly(entry, active);
|
|
119662
|
+
}
|
|
119001
119663
|
} catch (err) {
|
|
119002
119664
|
const message = err.message;
|
|
119003
119665
|
const settled = active.done;
|
|
@@ -119011,8 +119673,10 @@ async function runTurn(session, turn, entry, input, resume) {
|
|
|
119011
119673
|
async function startTurn2(session, turn) {
|
|
119012
119674
|
const db2 = getDb();
|
|
119013
119675
|
let entry;
|
|
119676
|
+
let codexThreadId;
|
|
119014
119677
|
try {
|
|
119015
119678
|
entry = await getOrCreateThread(session);
|
|
119679
|
+
codexThreadId = turn.thread_id ? await sideThreadFor(entry, session, turn.thread_id) : entry.threadId;
|
|
119016
119680
|
} catch (err) {
|
|
119017
119681
|
failTurn(db2, session.id, turn.id, `Failed to create app-server thread: ${err.message}`);
|
|
119018
119682
|
return;
|
|
@@ -119022,16 +119686,60 @@ async function startTurn2(session, turn) {
|
|
|
119022
119686
|
db2.prepare("UPDATE turns SET status = ?, updated_at = ? WHERE id = ?").run("running", now, turn.id);
|
|
119023
119687
|
setSessionStatus(db2, session.id, 1, "running", now);
|
|
119024
119688
|
broadcast("turn:started", { sessionId: session.id, turnId: turn.id });
|
|
119025
|
-
await runTurn(session, turn, entry,
|
|
119689
|
+
await runTurn(session, turn, entry, codexThreadId, turnRequest(turn), false);
|
|
119690
|
+
}
|
|
119691
|
+
function sideThreadFor(entry, session, discussionThreadId) {
|
|
119692
|
+
const loaded = entry.sideThreads.get(discussionThreadId);
|
|
119693
|
+
if (loaded) return Promise.resolve(loaded);
|
|
119694
|
+
const pending = entry.loadingSide.get(discussionThreadId);
|
|
119695
|
+
if (pending) return pending;
|
|
119696
|
+
const loading = loadSideThread(entry, session, discussionThreadId).finally(
|
|
119697
|
+
() => entry.loadingSide.delete(discussionThreadId)
|
|
119698
|
+
);
|
|
119699
|
+
entry.loadingSide.set(discussionThreadId, loading);
|
|
119700
|
+
return loading;
|
|
119701
|
+
}
|
|
119702
|
+
async function loadSideThread(entry, session, discussionThreadId) {
|
|
119703
|
+
const db2 = getDb();
|
|
119704
|
+
const row = db2.prepare("SELECT external_thread_id FROM discussion_threads WHERE id = ?").get(discussionThreadId);
|
|
119705
|
+
const base = threadParams(session, session.cwd ?? process.cwd());
|
|
119706
|
+
let codexThreadId;
|
|
119707
|
+
if (row?.external_thread_id) {
|
|
119708
|
+
entry.codexThreads.add(row.external_thread_id);
|
|
119709
|
+
const result = await entry.client.request("thread/resume", {
|
|
119710
|
+
threadId: row.external_thread_id,
|
|
119711
|
+
...base
|
|
119712
|
+
});
|
|
119713
|
+
codexThreadId = result.thread.id;
|
|
119714
|
+
} else {
|
|
119715
|
+
const result = await entry.client.request("thread/start", {
|
|
119716
|
+
...base,
|
|
119717
|
+
threadSource: PANE_THREAD_SOURCE
|
|
119718
|
+
});
|
|
119719
|
+
codexThreadId = result.thread.id;
|
|
119720
|
+
recordCodexThread(codexThreadId, session.id);
|
|
119721
|
+
db2.prepare("UPDATE discussion_threads SET external_thread_id = ? WHERE id = ?").run(
|
|
119722
|
+
codexThreadId,
|
|
119723
|
+
discussionThreadId
|
|
119724
|
+
);
|
|
119725
|
+
}
|
|
119726
|
+
entry.sideThreads.set(discussionThreadId, codexThreadId);
|
|
119727
|
+
entry.codexThreads.add(codexThreadId);
|
|
119728
|
+
return codexThreadId;
|
|
119026
119729
|
}
|
|
119027
|
-
function handleItemEvent(params, sessionId, turnId, status, broadcastEvent) {
|
|
119730
|
+
function handleItemEvent(params, sessionId, turnId, status, broadcastEvent, extraData) {
|
|
119028
119731
|
const db2 = getDb();
|
|
119029
119732
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
119030
119733
|
const item = params.item;
|
|
119734
|
+
if (item.type === "exitedReviewMode" && typeof item.review === "string" && item.review.trim()) {
|
|
119735
|
+
db2.prepare(
|
|
119736
|
+
"UPDATE turns SET agent_response = ?, updated_at = ? WHERE id = ? AND (agent_response IS NULL OR agent_response = '')"
|
|
119737
|
+
).run(item.review, now, turnId);
|
|
119738
|
+
}
|
|
119031
119739
|
if (shouldSkipItem(item.type)) return;
|
|
119032
119740
|
if ((item.type === "reasoning" || item.type === "agentReasoning") && isEmptyReasoning(item)) return;
|
|
119033
|
-
const data = mapItemData(item);
|
|
119034
|
-
const normalizedType =
|
|
119741
|
+
const data = { ...mapItemData(item), ...extraData };
|
|
119742
|
+
const normalizedType = mapItemType(item);
|
|
119035
119743
|
const result = db2.prepare("UPDATE items SET data = ?, status = ?, updated_at = ? WHERE external_item_id = ? AND turn_id = ?").run(JSON.stringify(data), status, now, item.id, turnId);
|
|
119036
119744
|
let itemId;
|
|
119037
119745
|
let createdAt;
|
|
@@ -119102,7 +119810,9 @@ function abortOrphanTurn(sessionId, threadId) {
|
|
|
119102
119810
|
}
|
|
119103
119811
|
}
|
|
119104
119812
|
var END_COMMANDS_WAIT_MS = 5e3;
|
|
119105
|
-
async function endTurnCommands(entry,
|
|
119813
|
+
async function endTurnCommands(entry, active) {
|
|
119814
|
+
const turnId = active.id;
|
|
119815
|
+
const threadId = active.codexThreadId ?? entry.threadId;
|
|
119106
119816
|
try {
|
|
119107
119817
|
const rows = getDb().prepare(
|
|
119108
119818
|
"SELECT external_item_id AS id FROM items WHERE turn_id = ? AND type = 'command_execution' AND external_item_id IS NOT NULL"
|
|
@@ -119112,13 +119822,13 @@ async function endTurnCommands(entry, turnId) {
|
|
|
119112
119822
|
let cursor = null;
|
|
119113
119823
|
do {
|
|
119114
119824
|
const page = await entry.client.request("thread/backgroundTerminals/list", {
|
|
119115
|
-
threadId
|
|
119825
|
+
threadId,
|
|
119116
119826
|
cursor
|
|
119117
119827
|
});
|
|
119118
119828
|
for (const terminal of page.data) {
|
|
119119
119829
|
if (!started.has(terminal.itemId)) continue;
|
|
119120
119830
|
await entry.client.request("thread/backgroundTerminals/terminate", {
|
|
119121
|
-
threadId
|
|
119831
|
+
threadId,
|
|
119122
119832
|
processId: terminal.processId
|
|
119123
119833
|
});
|
|
119124
119834
|
}
|
|
@@ -119137,7 +119847,7 @@ async function interruptTurn(sessionId, threadId) {
|
|
|
119137
119847
|
if (codexId && !target.done) {
|
|
119138
119848
|
try {
|
|
119139
119849
|
await entry.client.request("turn/interrupt", {
|
|
119140
|
-
threadId: entry.threadId,
|
|
119850
|
+
threadId: target.codexThreadId ?? entry.threadId,
|
|
119141
119851
|
turnId: codexId
|
|
119142
119852
|
});
|
|
119143
119853
|
stopped = true;
|
|
@@ -119150,7 +119860,10 @@ async function interruptTurn(sessionId, threadId) {
|
|
|
119150
119860
|
cancelTurn(entry, target);
|
|
119151
119861
|
if (!stopped) void retireEntry(entry, "fail");
|
|
119152
119862
|
}
|
|
119153
|
-
if (stopped)
|
|
119863
|
+
if (stopped) {
|
|
119864
|
+
await within(endTurnCommands(entry, target), END_COMMANDS_WAIT_MS);
|
|
119865
|
+
refreshBackgroundTasks(entry);
|
|
119866
|
+
}
|
|
119154
119867
|
if (live || stopped) return true;
|
|
119155
119868
|
}
|
|
119156
119869
|
return abortOrphanTurn(sessionId, threadId);
|
|
@@ -119159,8 +119872,31 @@ function clearThread(sessionId) {
|
|
|
119159
119872
|
const entry = sessionMap.get(sessionId);
|
|
119160
119873
|
if (entry) void retireEntry(entry, "cancel");
|
|
119161
119874
|
}
|
|
119875
|
+
function clearThreadBranch(sessionId, threadId) {
|
|
119876
|
+
const entry = sessionMap.get(sessionId);
|
|
119877
|
+
if (!entry) return;
|
|
119878
|
+
for (const active of entry.turns.filter((t) => t.discussionThreadId === threadId)) {
|
|
119879
|
+
if (active.codexId) {
|
|
119880
|
+
void entry.client.request("turn/interrupt", {
|
|
119881
|
+
threadId: active.codexThreadId ?? entry.threadId,
|
|
119882
|
+
turnId: active.codexId
|
|
119883
|
+
}).catch(() => {
|
|
119884
|
+
});
|
|
119885
|
+
}
|
|
119886
|
+
endTurn(entry, active);
|
|
119887
|
+
}
|
|
119888
|
+
const codexThreadId = entry.sideThreads.get(threadId);
|
|
119889
|
+
entry.sideThreads.delete(threadId);
|
|
119890
|
+
if (!codexThreadId || codexThreadId === entry.threadId) return;
|
|
119891
|
+
entry.codexThreads.delete(codexThreadId);
|
|
119892
|
+
void entry.client.request("thread/unsubscribe", { threadId: codexThreadId }).catch(() => {
|
|
119893
|
+
}).finally(() => refreshBackgroundTasks(entry));
|
|
119894
|
+
}
|
|
119162
119895
|
function clearAllThreads() {
|
|
119163
|
-
for (const entry of [...sessionMap.values()])
|
|
119896
|
+
for (const entry of [...sessionMap.values()]) {
|
|
119897
|
+
stopTaskPolling(entry);
|
|
119898
|
+
void retireEntry(entry, "keep");
|
|
119899
|
+
}
|
|
119164
119900
|
sessionMap.clear();
|
|
119165
119901
|
startingThreads.clear();
|
|
119166
119902
|
titleGenerating.clear();
|
|
@@ -119186,7 +119922,8 @@ async function generateTitleAsync(sessionId, userPrompt, agentResponse) {
|
|
|
119186
119922
|
const initResult = await client.request("thread/start", {
|
|
119187
119923
|
cwd: process.cwd(),
|
|
119188
119924
|
approvalPolicy: "never",
|
|
119189
|
-
sandbox: "read-only"
|
|
119925
|
+
sandbox: "read-only",
|
|
119926
|
+
ephemeral: true
|
|
119190
119927
|
});
|
|
119191
119928
|
const threadId = initResult.thread.id;
|
|
119192
119929
|
const truncatedPrompt = userPrompt.slice(0, 500);
|
|
@@ -119227,7 +119964,7 @@ Agent responded: "${truncatedResponse}"`;
|
|
|
119227
119964
|
threadId,
|
|
119228
119965
|
input: [{ type: "text", text: titlePrompt }],
|
|
119229
119966
|
approvalPolicy: "never",
|
|
119230
|
-
|
|
119967
|
+
sandboxPolicy: { type: "readOnly" }
|
|
119231
119968
|
});
|
|
119232
119969
|
const title = await titlePromise;
|
|
119233
119970
|
clearTimeout(timeout);
|
|
@@ -119254,7 +119991,8 @@ async function summarizeCodexThread(session, _thread, transcript, directives) {
|
|
|
119254
119991
|
const initResult = await client.request("thread/start", {
|
|
119255
119992
|
cwd: session.cwd ?? process.cwd(),
|
|
119256
119993
|
approvalPolicy: "never",
|
|
119257
|
-
sandbox: "read-only"
|
|
119994
|
+
sandbox: "read-only",
|
|
119995
|
+
ephemeral: true
|
|
119258
119996
|
});
|
|
119259
119997
|
const threadId = initResult.thread.id;
|
|
119260
119998
|
const directiveLine = directives.trim() ? `
|
|
@@ -119299,7 +120037,7 @@ Produce a concise summary of the discussion that preserves: concrete findings, f
|
|
|
119299
120037
|
threadId,
|
|
119300
120038
|
input: [{ type: "text", text: summaryPrompt }],
|
|
119301
120039
|
approvalPolicy: "never",
|
|
119302
|
-
|
|
120040
|
+
sandboxPolicy: { type: "readOnly" }
|
|
119303
120041
|
});
|
|
119304
120042
|
const summary = await summaryPromise;
|
|
119305
120043
|
clearTimeout(timeout);
|
|
@@ -119341,6 +120079,230 @@ async function getModels() {
|
|
|
119341
120079
|
return [];
|
|
119342
120080
|
}
|
|
119343
120081
|
}
|
|
120082
|
+
async function getCommands() {
|
|
120083
|
+
return CODEX_COMMANDS;
|
|
120084
|
+
}
|
|
120085
|
+
function forkPoint(db2, sessionId, target) {
|
|
120086
|
+
const row = db2.prepare(
|
|
120087
|
+
`SELECT external_turn_id FROM turns
|
|
120088
|
+
WHERE session_id = ? AND thread_id IS NULL AND external_turn_id IS NOT NULL
|
|
120089
|
+
AND status NOT IN ('pending', 'running') AND (id = ? OR created_at < ?)
|
|
120090
|
+
ORDER BY created_at DESC, rowid DESC LIMIT 1`
|
|
120091
|
+
).get(sessionId, target.id, target.created_at);
|
|
120092
|
+
return row?.external_turn_id ?? null;
|
|
120093
|
+
}
|
|
120094
|
+
async function forkSession(session, targetTurn) {
|
|
120095
|
+
const threadId = session.external_thread_id;
|
|
120096
|
+
if (!threadId) return null;
|
|
120097
|
+
const lastTurnId = forkPoint(getDb(), session.id, targetTurn);
|
|
120098
|
+
if (!lastTurnId) return null;
|
|
120099
|
+
const cwd = session.cwd ?? process.cwd();
|
|
120100
|
+
const client = new AppServerClient({ cwd });
|
|
120101
|
+
try {
|
|
120102
|
+
await client.initialize();
|
|
120103
|
+
const fork = (range) => client.request("thread/fork", {
|
|
120104
|
+
threadId,
|
|
120105
|
+
...range,
|
|
120106
|
+
cwd,
|
|
120107
|
+
excludeTurns: true,
|
|
120108
|
+
threadSource: PANE_THREAD_SOURCE
|
|
120109
|
+
});
|
|
120110
|
+
let result;
|
|
120111
|
+
try {
|
|
120112
|
+
result = await fork({ lastTurnId });
|
|
120113
|
+
} catch (err) {
|
|
120114
|
+
const range = await client.request("thread/read", { threadId, includeTurns: true }).then(({ thread }) => forkThroughReview(thread.turns ?? [], lastTurnId), () => void 0);
|
|
120115
|
+
if (!range) throw err;
|
|
120116
|
+
result = await fork(range);
|
|
120117
|
+
}
|
|
120118
|
+
recordCodexThread(result.thread.id, session.id);
|
|
120119
|
+
return result.thread.id;
|
|
120120
|
+
} finally {
|
|
120121
|
+
await client.close();
|
|
120122
|
+
}
|
|
120123
|
+
}
|
|
120124
|
+
function refreshBackgroundTasks(entry) {
|
|
120125
|
+
if (entry.refreshing) {
|
|
120126
|
+
entry.refreshAgain = true;
|
|
120127
|
+
return;
|
|
120128
|
+
}
|
|
120129
|
+
entry.refreshing = (async () => {
|
|
120130
|
+
do {
|
|
120131
|
+
entry.refreshAgain = false;
|
|
120132
|
+
await refreshTasksOnce(entry);
|
|
120133
|
+
} while (entry.refreshAgain && isCurrent(entry));
|
|
120134
|
+
})().catch(
|
|
120135
|
+
(err) => console.warn(`[codex] could not list the background commands of ${entry.sessionId}: ${err.message}`)
|
|
120136
|
+
).finally(() => {
|
|
120137
|
+
entry.refreshing = null;
|
|
120138
|
+
});
|
|
120139
|
+
}
|
|
120140
|
+
async function refreshTasksOnce(entry) {
|
|
120141
|
+
if (!isCurrent(entry) || entry.replaying) return;
|
|
120142
|
+
const live = /* @__PURE__ */ new Map();
|
|
120143
|
+
const unknown2 = /* @__PURE__ */ new Set();
|
|
120144
|
+
for (const codexThreadId of entry.codexThreads) {
|
|
120145
|
+
let cursor = null;
|
|
120146
|
+
try {
|
|
120147
|
+
do {
|
|
120148
|
+
const page = await entry.client.request("thread/backgroundTerminals/list", {
|
|
120149
|
+
threadId: codexThreadId,
|
|
120150
|
+
cursor
|
|
120151
|
+
});
|
|
120152
|
+
for (const terminal of page.data) {
|
|
120153
|
+
live.set(terminal.processId, { codexThreadId, itemId: terminal.itemId, command: terminal.command });
|
|
120154
|
+
}
|
|
120155
|
+
cursor = page.nextCursor;
|
|
120156
|
+
} while (cursor);
|
|
120157
|
+
} catch {
|
|
120158
|
+
unknown2.add(codexThreadId);
|
|
120159
|
+
}
|
|
120160
|
+
}
|
|
120161
|
+
if (!isCurrent(entry)) return;
|
|
120162
|
+
for (const [taskId, task] of entry.tasks) {
|
|
120163
|
+
if (live.has(taskId) || unknown2.has(task.codexThreadId)) continue;
|
|
120164
|
+
entry.tasks.delete(taskId);
|
|
120165
|
+
closeTaskItem(entry.sessionId, task, task.stopped ? "stopped" : "completed");
|
|
120166
|
+
}
|
|
120167
|
+
for (const [processId, terminal] of live) {
|
|
120168
|
+
if (entry.tasks.has(processId)) continue;
|
|
120169
|
+
const turnId = commandTurnOf(entry.sessionId, terminal.itemId);
|
|
120170
|
+
if (turnId && entry.turns.some((t) => t.id === turnId)) continue;
|
|
120171
|
+
const task = {
|
|
120172
|
+
info: { task_id: processId, task_type: TERMINAL_TASK_TYPE, description: terminal.command },
|
|
120173
|
+
codexThreadId: terminal.codexThreadId,
|
|
120174
|
+
processId,
|
|
120175
|
+
commandItemId: terminal.itemId,
|
|
120176
|
+
item: null,
|
|
120177
|
+
stopped: false
|
|
120178
|
+
};
|
|
120179
|
+
if (turnId) openTaskItem(entry.sessionId, turnId, task);
|
|
120180
|
+
entry.tasks.set(processId, task);
|
|
120181
|
+
}
|
|
120182
|
+
publishTasks(entry);
|
|
120183
|
+
}
|
|
120184
|
+
function publishTasks(entry) {
|
|
120185
|
+
const tasks = [...entry.tasks.values()].map((task) => task.info);
|
|
120186
|
+
const json2 = JSON.stringify(tasks);
|
|
120187
|
+
if (json2 !== entry.publishedTasks) {
|
|
120188
|
+
entry.publishedTasks = json2;
|
|
120189
|
+
broadcast("background_tasks", { sessionId: entry.sessionId, tasks });
|
|
120190
|
+
}
|
|
120191
|
+
if (tasks.length > 0 && !entry.taskTimer && isCurrent(entry)) {
|
|
120192
|
+
entry.taskTimer = setInterval(() => refreshBackgroundTasks(entry), taskPollMs());
|
|
120193
|
+
entry.taskTimer.unref?.();
|
|
120194
|
+
} else if (tasks.length === 0) {
|
|
120195
|
+
stopTaskPolling(entry);
|
|
120196
|
+
}
|
|
120197
|
+
}
|
|
120198
|
+
function stopTaskPolling(entry) {
|
|
120199
|
+
if (!entry.taskTimer) return;
|
|
120200
|
+
clearInterval(entry.taskTimer);
|
|
120201
|
+
entry.taskTimer = null;
|
|
120202
|
+
}
|
|
120203
|
+
function dropTasks(entry) {
|
|
120204
|
+
stopTaskPolling(entry);
|
|
120205
|
+
for (const task of entry.tasks.values()) closeTaskItem(entry.sessionId, task, "stopped");
|
|
120206
|
+
entry.tasks.clear();
|
|
120207
|
+
publishTasks(entry);
|
|
120208
|
+
}
|
|
120209
|
+
function commandTurnOf(sessionId, itemId) {
|
|
120210
|
+
try {
|
|
120211
|
+
const row = getDb().prepare(
|
|
120212
|
+
`SELECT i.turn_id FROM items i JOIN turns t ON t.id = i.turn_id
|
|
120213
|
+
WHERE t.session_id = ? AND i.external_item_id = ? ORDER BY i.created_at DESC LIMIT 1`
|
|
120214
|
+
).get(sessionId, itemId);
|
|
120215
|
+
return row?.turn_id ?? null;
|
|
120216
|
+
} catch {
|
|
120217
|
+
return null;
|
|
120218
|
+
}
|
|
120219
|
+
}
|
|
120220
|
+
function openTaskItem(sessionId, turnId, task) {
|
|
120221
|
+
try {
|
|
120222
|
+
const db2 = getDb();
|
|
120223
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
120224
|
+
const item = {
|
|
120225
|
+
id: v4_default(),
|
|
120226
|
+
turn_id: turnId,
|
|
120227
|
+
external_item_id: `terminal-${task.processId}-${task.commandItemId}`,
|
|
120228
|
+
type: "background_task",
|
|
120229
|
+
data: {
|
|
120230
|
+
task_id: task.processId,
|
|
120231
|
+
description: task.info.description,
|
|
120232
|
+
task_type: TERMINAL_TASK_TYPE,
|
|
120233
|
+
status: "running",
|
|
120234
|
+
output: ""
|
|
120235
|
+
},
|
|
120236
|
+
status: "in_progress",
|
|
120237
|
+
created_at: now,
|
|
120238
|
+
updated_at: now
|
|
120239
|
+
};
|
|
120240
|
+
db2.prepare(
|
|
120241
|
+
"INSERT INTO items (id, turn_id, external_item_id, type, data, status, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
|
|
120242
|
+
).run(item.id, item.turn_id, item.external_item_id, item.type, JSON.stringify(item.data), item.status, now, now);
|
|
120243
|
+
task.item = { id: item.id, turnId, createdAt: now };
|
|
120244
|
+
broadcast("item:started", { sessionId, turnId, item });
|
|
120245
|
+
} catch (err) {
|
|
120246
|
+
console.warn(`[codex] could not record background command ${task.processId}: ${err.message}`);
|
|
120247
|
+
}
|
|
120248
|
+
}
|
|
120249
|
+
var TASK_OUTPUT_MAX = 2e4;
|
|
120250
|
+
function closeTaskItem(sessionId, task, status) {
|
|
120251
|
+
const ref = task.item;
|
|
120252
|
+
if (!ref) return;
|
|
120253
|
+
try {
|
|
120254
|
+
const db2 = getDb();
|
|
120255
|
+
const command = db2.prepare("SELECT data FROM items WHERE turn_id = ? AND external_item_id = ?").get(ref.turnId, task.commandItemId);
|
|
120256
|
+
let output = "";
|
|
120257
|
+
try {
|
|
120258
|
+
output = String(JSON.parse(command?.data ?? "{}").aggregated_output ?? "");
|
|
120259
|
+
} catch {
|
|
120260
|
+
}
|
|
120261
|
+
const data = {
|
|
120262
|
+
task_id: task.processId,
|
|
120263
|
+
description: task.info.description,
|
|
120264
|
+
task_type: TERMINAL_TASK_TYPE,
|
|
120265
|
+
status,
|
|
120266
|
+
output: output.length > TASK_OUTPUT_MAX ? output.slice(-TASK_OUTPUT_MAX) : output
|
|
120267
|
+
};
|
|
120268
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
120269
|
+
db2.prepare("UPDATE items SET data = ?, status = 'completed', updated_at = ? WHERE id = ?").run(
|
|
120270
|
+
JSON.stringify(data),
|
|
120271
|
+
now,
|
|
120272
|
+
ref.id
|
|
120273
|
+
);
|
|
120274
|
+
const item = {
|
|
120275
|
+
id: ref.id,
|
|
120276
|
+
turn_id: ref.turnId,
|
|
120277
|
+
external_item_id: `terminal-${task.processId}-${task.commandItemId}`,
|
|
120278
|
+
type: "background_task",
|
|
120279
|
+
data,
|
|
120280
|
+
status: "completed",
|
|
120281
|
+
created_at: ref.createdAt,
|
|
120282
|
+
updated_at: now
|
|
120283
|
+
};
|
|
120284
|
+
broadcast("item:completed", { sessionId, turnId: ref.turnId, item });
|
|
120285
|
+
} catch {
|
|
120286
|
+
}
|
|
120287
|
+
}
|
|
120288
|
+
async function stopTask(sessionId, taskId) {
|
|
120289
|
+
const entry = sessionMap.get(sessionId);
|
|
120290
|
+
const task = entry?.tasks.get(taskId);
|
|
120291
|
+
if (!entry || !task) throw new Error(`No running background command ${taskId} in this session`);
|
|
120292
|
+
task.stopped = true;
|
|
120293
|
+
await entry.client.request("thread/backgroundTerminals/terminate", {
|
|
120294
|
+
threadId: task.codexThreadId,
|
|
120295
|
+
processId: task.processId
|
|
120296
|
+
});
|
|
120297
|
+
refreshBackgroundTasks(entry);
|
|
120298
|
+
}
|
|
120299
|
+
function listBackgroundTasks() {
|
|
120300
|
+
const bySession = {};
|
|
120301
|
+
for (const entry of sessionMap.values()) {
|
|
120302
|
+
if (entry.tasks.size > 0) bySession[entry.sessionId] = [...entry.tasks.values()].map((task) => task.info);
|
|
120303
|
+
}
|
|
120304
|
+
return bySession;
|
|
120305
|
+
}
|
|
119344
120306
|
async function shutdown() {
|
|
119345
120307
|
let db2 = null;
|
|
119346
120308
|
try {
|
|
@@ -119376,12 +120338,13 @@ async function reapOrphans() {
|
|
|
119376
120338
|
async function resumeInterruptedTurn(session, turn, _opts) {
|
|
119377
120339
|
if (turn.thread_id) throw new Error("Discussion-thread turns cannot be resumed");
|
|
119378
120340
|
const entry = await getOrCreateThread(session);
|
|
119379
|
-
if (entry.turns.
|
|
120341
|
+
if (entry.turns.some((t) => !t.discussionThreadId)) throw new Error("Another turn is running in this session");
|
|
119380
120342
|
if (!isTurnLive(getDb(), turn.id)) return;
|
|
120343
|
+
const command = parseCodexCommand(turn.user_prompt);
|
|
119381
120344
|
const codexId = turn.external_turn_id;
|
|
119382
120345
|
const inThread = !!codexId && (!!entry.resumedTurnIds?.has(codexId) || entry.ended.has(codexId));
|
|
119383
|
-
const
|
|
119384
|
-
await runTurn(session, turn, entry,
|
|
120346
|
+
const request = command ?? (inThread ? { kind: "prompt", input: [{ type: "text", text: CODEX_CONTINUE_PROMPT }] } : { kind: "prompt", input: buildCodexInput(turn) });
|
|
120347
|
+
await runTurn(session, turn, entry, entry.threadId, request, true);
|
|
119385
120348
|
}
|
|
119386
120349
|
function hostFor(sessionId, cwd, options, onDirect) {
|
|
119387
120350
|
if (!hostsEnabledFor("codex")) return null;
|
|
@@ -119448,38 +120411,65 @@ function maybeRetire(entry) {
|
|
|
119448
120411
|
}
|
|
119449
120412
|
function detachEntry(entry) {
|
|
119450
120413
|
if (sessionMap.get(entry.sessionId) === entry) sessionMap.delete(entry.sessionId);
|
|
120414
|
+
stopTaskPolling(entry);
|
|
119451
120415
|
entry.closing = Promise.resolve();
|
|
119452
120416
|
entry.client.detach();
|
|
119453
120417
|
entry.host?.proc.detach();
|
|
119454
120418
|
}
|
|
119455
120419
|
function runningTurns(db2, sessionId) {
|
|
119456
120420
|
return db2.prepare(
|
|
119457
|
-
"SELECT id, thread_id, external_turn_id, resume_state FROM turns WHERE session_id = ? AND status = 'running' ORDER BY created_at, rowid"
|
|
120421
|
+
"SELECT id, thread_id, external_turn_id, resume_state, user_prompt FROM turns WHERE session_id = ? AND status = 'running' ORDER BY created_at, rowid"
|
|
119458
120422
|
).all(sessionId);
|
|
119459
120423
|
}
|
|
120424
|
+
function storedContextTokens(db2, sessionId) {
|
|
120425
|
+
const row = db2.prepare("SELECT context_usage FROM sessions WHERE id = ?").get(sessionId);
|
|
120426
|
+
try {
|
|
120427
|
+
const tokens2 = row?.context_usage ? JSON.parse(row.context_usage).totalTokens : null;
|
|
120428
|
+
return typeof tokens2 === "number" ? tokens2 : null;
|
|
120429
|
+
} catch {
|
|
120430
|
+
return null;
|
|
120431
|
+
}
|
|
120432
|
+
}
|
|
119460
120433
|
function adoptedEntry(db2, session, threadId, client, host) {
|
|
119461
|
-
const
|
|
119462
|
-
|
|
120434
|
+
const sideRows = db2.prepare(
|
|
120435
|
+
"SELECT id, external_thread_id FROM discussion_threads WHERE session_id = ? AND external_thread_id IS NOT NULL"
|
|
120436
|
+
).all(session.id);
|
|
120437
|
+
const sideOf = new Map(sideRows.map((row) => [row.id, row.external_thread_id]));
|
|
120438
|
+
const turns = runningTurns(db2, session.id).map((row) => {
|
|
120439
|
+
const kind = parseCodexCommand(row.user_prompt)?.kind ?? "prompt";
|
|
120440
|
+
return {
|
|
119463
120441
|
id: row.id,
|
|
119464
120442
|
discussionThreadId: row.thread_id,
|
|
120443
|
+
codexThreadId: row.thread_id ? sideOf.get(row.thread_id) ?? null : threadId,
|
|
120444
|
+
// A review whose answer went to the previous daemon takes the first id it sees.
|
|
120445
|
+
kind: kind === "review" && !row.external_turn_id ? "prompt" : kind,
|
|
119465
120446
|
codexId: row.external_turn_id,
|
|
119466
120447
|
started: Promise.resolve(row.external_turn_id),
|
|
120448
|
+
resolveStarted: () => {
|
|
120449
|
+
},
|
|
120450
|
+
early: [],
|
|
119467
120451
|
done: false,
|
|
119468
120452
|
resuming: row.resume_state === "resuming",
|
|
119469
120453
|
hostOffset: null
|
|
119470
|
-
}
|
|
119471
|
-
);
|
|
120454
|
+
};
|
|
120455
|
+
});
|
|
119472
120456
|
const ended = /* @__PURE__ */ new Map();
|
|
119473
120457
|
const endedRows = db2.prepare(
|
|
119474
120458
|
"SELECT id, external_turn_id FROM turns WHERE session_id = ? AND external_turn_id IS NOT NULL AND status != 'running' ORDER BY created_at DESC, rowid DESC LIMIT ?"
|
|
119475
120459
|
).all(session.id, ENDED_TURNS_KEPT);
|
|
119476
120460
|
for (const row of endedRows.reverse()) ended.set(row.external_turn_id, row.id);
|
|
119477
120461
|
const known = db2.prepare("SELECT external_turn_id FROM turns WHERE session_id = ? AND external_turn_id IS NOT NULL").all(session.id);
|
|
120462
|
+
const state = emptyThreadState();
|
|
120463
|
+
const fill = storedContextTokens(db2, session.id);
|
|
119478
120464
|
return {
|
|
119479
120465
|
sessionId: session.id,
|
|
119480
120466
|
client,
|
|
119481
120467
|
pid: void 0,
|
|
120468
|
+
...state,
|
|
119482
120469
|
threadId,
|
|
120470
|
+
codexThreads: /* @__PURE__ */ new Set([threadId, ...sideOf.values()]),
|
|
120471
|
+
contextTokens: new Map(fill === null ? [] : [[threadId, fill]]),
|
|
120472
|
+
webSearch: threadConfig(parseRuntimeConfig(session))?.web_search,
|
|
119483
120473
|
turns,
|
|
119484
120474
|
ended,
|
|
119485
120475
|
// A turn resumed on this app-server later continues with the continue
|
|
@@ -119552,7 +120542,7 @@ var codexHostAdopter = {
|
|
|
119552
120542
|
entry.retireWhenIdle = !sessionHostFlags().codex ? "session hosts are off for Codex" : row.runtime_version !== version2 ? `started by runtime ${row.runtime_version ?? "unknown"}, this is ${version2 ?? "unknown"}` : null;
|
|
119553
120543
|
sessionMap.set(session.id, entry);
|
|
119554
120544
|
listen(entry);
|
|
119555
|
-
|
|
120545
|
+
autoApproveToolUserInput(client);
|
|
119556
120546
|
await replayDone(client, `session ${session.id}`);
|
|
119557
120547
|
entry.replaying = false;
|
|
119558
120548
|
if (!isCurrent(entry)) {
|
|
@@ -119563,6 +120553,7 @@ var codexHostAdopter = {
|
|
|
119563
120553
|
recomputeSessionRunning(db2, session.id);
|
|
119564
120554
|
broadcast("session:resync", { sessionId: session.id });
|
|
119565
120555
|
resendStreams(session.id);
|
|
120556
|
+
refreshBackgroundTasks(entry);
|
|
119566
120557
|
const running = entry.turns.map((t) => ({ id: t.id, threadId: t.discussionThreadId }));
|
|
119567
120558
|
console.log(
|
|
119568
120559
|
`[codex] adopted the app-server of session ${session.id} (pid ${proc.pid ?? "?"})${running.length ? `, ${running.length} turn(s) go on` : ""}${entry.retireWhenIdle ? `; it closes once idle: ${entry.retireWhenIdle}` : ""}`
|
|
@@ -119603,8 +120594,13 @@ var codexProvider = {
|
|
|
119603
120594
|
startTurn: startTurn2,
|
|
119604
120595
|
interruptTurn,
|
|
119605
120596
|
clearThread,
|
|
120597
|
+
clearThreadBranch,
|
|
119606
120598
|
clearAllThreads,
|
|
119607
120599
|
getModels,
|
|
120600
|
+
getCommands,
|
|
120601
|
+
forkSession,
|
|
120602
|
+
stopTask,
|
|
120603
|
+
listBackgroundTasks,
|
|
119608
120604
|
summarizeThread: summarizeCodexThread,
|
|
119609
120605
|
resumeInterruptedTurn,
|
|
119610
120606
|
reapOrphans,
|
|
@@ -120155,7 +121151,7 @@ function dropBackgroundTasks(sessionId, entry) {
|
|
|
120155
121151
|
entry.backgroundTasks = [];
|
|
120156
121152
|
publishBackgroundTasks(sessionId);
|
|
120157
121153
|
}
|
|
120158
|
-
function
|
|
121154
|
+
function listBackgroundTasks2() {
|
|
120159
121155
|
const bySession = {};
|
|
120160
121156
|
for (const [key, entry] of sessionMap2) {
|
|
120161
121157
|
if (!entry.backgroundTasks?.length) continue;
|
|
@@ -121186,7 +122182,7 @@ function clearThread2(sessionId) {
|
|
|
121186
122182
|
}
|
|
121187
122183
|
publishBackgroundTasks(sessionId);
|
|
121188
122184
|
}
|
|
121189
|
-
function
|
|
122185
|
+
function clearThreadBranch2(sessionId, threadId) {
|
|
121190
122186
|
const key = `${sessionId}:thread:${threadId}`;
|
|
121191
122187
|
const entry = sessionMap2.get(key);
|
|
121192
122188
|
if (entry) closeEntry(key, entry);
|
|
@@ -121266,7 +122262,7 @@ async function setModel(sessionId, model) {
|
|
|
121266
122262
|
await entry.query.setModel(model);
|
|
121267
122263
|
void refreshContext(entry, sessionId, getDb());
|
|
121268
122264
|
}
|
|
121269
|
-
async function
|
|
122265
|
+
async function stopTask2(sessionId, taskId) {
|
|
121270
122266
|
const entry = sessionMap2.get(sessionId);
|
|
121271
122267
|
if (!entry) return;
|
|
121272
122268
|
await entry.query.stopTask(taskId);
|
|
@@ -121301,7 +122297,7 @@ async function getModels2() {
|
|
|
121301
122297
|
return [];
|
|
121302
122298
|
}
|
|
121303
122299
|
}
|
|
121304
|
-
async function
|
|
122300
|
+
async function getCommands2() {
|
|
121305
122301
|
if (cachedCommands) return cachedCommands;
|
|
121306
122302
|
await getModels2();
|
|
121307
122303
|
return cachedCommands ?? [];
|
|
@@ -121714,15 +122710,15 @@ var claudeProvider = {
|
|
|
121714
122710
|
startTurn: startTurn3,
|
|
121715
122711
|
interruptTurn: interruptTurn2,
|
|
121716
122712
|
clearThread: clearThread2,
|
|
121717
|
-
clearThreadBranch,
|
|
122713
|
+
clearThreadBranch: clearThreadBranch2,
|
|
121718
122714
|
clearAllThreads: clearAllThreads2,
|
|
121719
122715
|
getModels: getModels2,
|
|
121720
|
-
getCommands,
|
|
122716
|
+
getCommands: getCommands2,
|
|
121721
122717
|
forkSession: forkClaudeSession,
|
|
121722
122718
|
summarizeThread: summarizeClaudeThread,
|
|
121723
122719
|
setModel,
|
|
121724
|
-
stopTask,
|
|
121725
|
-
listBackgroundTasks,
|
|
122720
|
+
stopTask: stopTask2,
|
|
122721
|
+
listBackgroundTasks: listBackgroundTasks2,
|
|
121726
122722
|
resumeInterruptedTurn: resumeInterruptedTurn2,
|
|
121727
122723
|
reapOrphans: reapOrphans2,
|
|
121728
122724
|
shutdown: shutdown2
|
|
@@ -121743,8 +122739,8 @@ var RepoburgHttpClient = class {
|
|
|
121743
122739
|
this.baseUrl = baseUrl.replace(/\/+$/, "");
|
|
121744
122740
|
}
|
|
121745
122741
|
/** Perform a JSON request. Throws a concise error on non-OK/non-JSON responses. */
|
|
121746
|
-
async request(method,
|
|
121747
|
-
const response = await fetch(`${this.baseUrl}${
|
|
122742
|
+
async request(method, path19, body) {
|
|
122743
|
+
const response = await fetch(`${this.baseUrl}${path19}`, {
|
|
121748
122744
|
method,
|
|
121749
122745
|
headers: { "Content-Type": "application/json" },
|
|
121750
122746
|
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
@@ -121753,17 +122749,17 @@ var RepoburgHttpClient = class {
|
|
|
121753
122749
|
if (!response.ok) {
|
|
121754
122750
|
if (isHtml(text2)) {
|
|
121755
122751
|
throw new Error(
|
|
121756
|
-
`${method} ${
|
|
122752
|
+
`${method} ${path19} failed: ${response.status} HTML response from ${this.baseUrl} \u2014 the URL points to the wrong server`
|
|
121757
122753
|
);
|
|
121758
122754
|
}
|
|
121759
|
-
throw new Error(`${method} ${
|
|
122755
|
+
throw new Error(`${method} ${path19} failed: ${response.status} ${text2}`);
|
|
121760
122756
|
}
|
|
121761
122757
|
if (text2.length === 0) return void 0;
|
|
121762
122758
|
try {
|
|
121763
122759
|
return JSON.parse(text2);
|
|
121764
122760
|
} catch {
|
|
121765
122761
|
throw new Error(
|
|
121766
|
-
`${method} ${
|
|
122762
|
+
`${method} ${path19} failed: non-JSON response from ${this.baseUrl} \u2014 the URL points to the wrong server`
|
|
121767
122763
|
);
|
|
121768
122764
|
}
|
|
121769
122765
|
}
|
|
@@ -121818,7 +122814,7 @@ var RepoburgHttpClient = class {
|
|
|
121818
122814
|
};
|
|
121819
122815
|
|
|
121820
122816
|
// src/repoburg/backend-resolver.ts
|
|
121821
|
-
import
|
|
122817
|
+
import path17 from "node:path";
|
|
121822
122818
|
var HEALTH_POLL_INTERVAL_MS = 1e3;
|
|
121823
122819
|
var HEALTH_TIMEOUT_MS = 3e4;
|
|
121824
122820
|
function daemonBaseUrl() {
|
|
@@ -121873,7 +122869,7 @@ async function backendHealthy(baseUrl, expectedPath) {
|
|
|
121873
122869
|
const health = await fetchJson(`${baseUrl}/health`, void 0, 2e3);
|
|
121874
122870
|
if (health.status !== "ok") return false;
|
|
121875
122871
|
if (expectedPath && health.projectPath) {
|
|
121876
|
-
return
|
|
122872
|
+
return path17.resolve(health.projectPath) === path17.resolve(expectedPath);
|
|
121877
122873
|
}
|
|
121878
122874
|
return true;
|
|
121879
122875
|
} catch {
|
|
@@ -121894,7 +122890,7 @@ function serviceBaseUrl(service) {
|
|
|
121894
122890
|
return `http://localhost:${service.port}`;
|
|
121895
122891
|
}
|
|
121896
122892
|
function coveringService(services, absPath) {
|
|
121897
|
-
return services.filter((s) => absPath === s.path || absPath.startsWith(s.path +
|
|
122893
|
+
return services.filter((s) => absPath === s.path || absPath.startsWith(s.path + path17.sep)).sort((a, b) => b.path.length - a.path.length)[0];
|
|
121898
122894
|
}
|
|
121899
122895
|
async function restartService(daemon, name) {
|
|
121900
122896
|
try {
|
|
@@ -121930,7 +122926,7 @@ async function resolveBackendUrl(projectPath, opts = {}) {
|
|
|
121930
122926
|
if (envUrl) {
|
|
121931
122927
|
return { baseUrl: envUrl.replace(/\/+$/, ""), port: 0, name: "REPOBURG_BACKEND_URL" };
|
|
121932
122928
|
}
|
|
121933
|
-
const absPath =
|
|
122929
|
+
const absPath = path17.resolve(projectPath);
|
|
121934
122930
|
const daemon = daemonBaseUrl();
|
|
121935
122931
|
const cached3 = resolvedCache.get(absPath);
|
|
121936
122932
|
if (cached3 && await backendHealthy(cached3.baseUrl, cached3.servesPath ?? absPath)) {
|
|
@@ -123483,7 +124479,7 @@ function clearThread3(sessionId) {
|
|
|
123483
124479
|
sessionMap3.delete(key);
|
|
123484
124480
|
}
|
|
123485
124481
|
}
|
|
123486
|
-
function
|
|
124482
|
+
function clearThreadBranch3(sessionId, threadId) {
|
|
123487
124483
|
const key = `${sessionId}:thread:${threadId}`;
|
|
123488
124484
|
const entry = sessionMap3.get(key);
|
|
123489
124485
|
if (entry) {
|
|
@@ -123532,7 +124528,7 @@ async function resolveClient(session) {
|
|
|
123532
124528
|
if (!resolved) throw new Error("No repoburg backend resolved.");
|
|
123533
124529
|
return new RepoburgHttpClient(resolved.baseUrl);
|
|
123534
124530
|
}
|
|
123535
|
-
async function
|
|
124531
|
+
async function forkSession2(session, targetTurn) {
|
|
123536
124532
|
if (!session.external_thread_id) return null;
|
|
123537
124533
|
const anchor = parseRuntimeInputIds(targetTurn).pop();
|
|
123538
124534
|
if (!anchor) {
|
|
@@ -123572,7 +124568,7 @@ async function getModels3(cwd) {
|
|
|
123572
124568
|
return [];
|
|
123573
124569
|
}
|
|
123574
124570
|
}
|
|
123575
|
-
async function
|
|
124571
|
+
async function getCommands3(cwd) {
|
|
123576
124572
|
try {
|
|
123577
124573
|
const resolved = await resolveBackendUrl(cwd ?? process.cwd(), { autoStart: false });
|
|
123578
124574
|
if (!resolved) return [];
|
|
@@ -123593,12 +124589,12 @@ var repoburgProvider = {
|
|
|
123593
124589
|
startTurn: startTurn4,
|
|
123594
124590
|
interruptTurn: interruptTurn3,
|
|
123595
124591
|
clearThread: clearThread3,
|
|
123596
|
-
clearThreadBranch:
|
|
124592
|
+
clearThreadBranch: clearThreadBranch3,
|
|
123597
124593
|
clearAllThreads: clearAllThreads3,
|
|
123598
124594
|
getModels: getModels3,
|
|
123599
|
-
getCommands:
|
|
124595
|
+
getCommands: getCommands3,
|
|
123600
124596
|
rewindRuntime,
|
|
123601
|
-
forkSession,
|
|
124597
|
+
forkSession: forkSession2,
|
|
123602
124598
|
shutdown: shutdown3
|
|
123603
124599
|
};
|
|
123604
124600
|
|
|
@@ -123611,7 +124607,7 @@ registerProvider("repoburg", repoburgProvider);
|
|
|
123611
124607
|
async function createAgentPaneApp(dbPath, opts = {}) {
|
|
123612
124608
|
const allowRequest = opts.allowRequest ?? isLocalRequest;
|
|
123613
124609
|
initDb(dbPath);
|
|
123614
|
-
setPaneDataDir(dbPath === ":memory:" ? null :
|
|
124610
|
+
setPaneDataDir(dbPath === ":memory:" ? null : path18.dirname(path18.resolve(dbPath)));
|
|
123615
124611
|
const fastify = (0, import_fastify.default)({ logger: true, bodyLimit: 50 * 1024 * 1024 });
|
|
123616
124612
|
fastify.addHook("onRequest", async (request, reply) => {
|
|
123617
124613
|
if (!allowRequest(request.headers.origin, request.headers.host)) {
|
|
@@ -123637,6 +124633,7 @@ async function createAgentPaneApp(dbPath, opts = {}) {
|
|
|
123637
124633
|
await registerSidecarRoutes(fastify);
|
|
123638
124634
|
await registerUsageRoutes(fastify);
|
|
123639
124635
|
await registerClaudeSessionRoutes(fastify);
|
|
124636
|
+
await registerCodexSessionRoutes(fastify);
|
|
123640
124637
|
await registerSessionHostRoutes(fastify);
|
|
123641
124638
|
const wss3 = initWs(allowRequest);
|
|
123642
124639
|
initTerminalWs(allowRequest);
|