@vibedeckx/linux-x64 0.3.23 → 0.3.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.js +371 -269
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -4594,7 +4594,7 @@ var require_W3CTraceContextPropagator = __commonJS({
|
|
|
4594
4594
|
var TraceState_1 = require_TraceState();
|
|
4595
4595
|
exports.TRACE_PARENT_HEADER = "traceparent";
|
|
4596
4596
|
exports.TRACE_STATE_HEADER = "tracestate";
|
|
4597
|
-
var
|
|
4597
|
+
var VERSION9 = "00";
|
|
4598
4598
|
var VERSION_PART = "(?!ff)[\\da-f]{2}";
|
|
4599
4599
|
var TRACE_ID_PART = "(?![0]{32})[\\da-f]{32}";
|
|
4600
4600
|
var PARENT_ID_PART = "(?![0]{16})[\\da-f]{16}";
|
|
@@ -4618,7 +4618,7 @@ var require_W3CTraceContextPropagator = __commonJS({
|
|
|
4618
4618
|
const spanContext = api_1.trace.getSpanContext(context2);
|
|
4619
4619
|
if (!spanContext || (0, suppress_tracing_1.isTracingSuppressed)(context2) || !(0, api_1.isSpanContextValid)(spanContext))
|
|
4620
4620
|
return;
|
|
4621
|
-
const traceParent = `${
|
|
4621
|
+
const traceParent = `${VERSION9}-${spanContext.traceId}-${spanContext.spanId}-0${Number(spanContext.traceFlags || api_1.TraceFlags.NONE).toString(16)}`;
|
|
4622
4622
|
setter.set(carrier, exports.TRACE_PARENT_HEADER, traceParent);
|
|
4623
4623
|
if (spanContext.traceState) {
|
|
4624
4624
|
setter.set(carrier, exports.TRACE_STATE_HEADER, spanContext.traceState.serialize());
|
|
@@ -9571,32 +9571,32 @@ var require_Meter = __commonJS({
|
|
|
9571
9571
|
*/
|
|
9572
9572
|
createGauge(name25, options) {
|
|
9573
9573
|
const descriptor = (0, InstrumentDescriptor_1.createInstrumentDescriptor)(name25, MetricData_1.InstrumentType.GAUGE, options);
|
|
9574
|
-
const
|
|
9575
|
-
return new Instruments_1.GaugeInstrument(
|
|
9574
|
+
const storage2 = this._meterSharedState.registerMetricStorage(descriptor);
|
|
9575
|
+
return new Instruments_1.GaugeInstrument(storage2, descriptor);
|
|
9576
9576
|
}
|
|
9577
9577
|
/**
|
|
9578
9578
|
* Create a {@link Histogram} instrument.
|
|
9579
9579
|
*/
|
|
9580
9580
|
createHistogram(name25, options) {
|
|
9581
9581
|
const descriptor = (0, InstrumentDescriptor_1.createInstrumentDescriptor)(name25, MetricData_1.InstrumentType.HISTOGRAM, options);
|
|
9582
|
-
const
|
|
9583
|
-
return new Instruments_1.HistogramInstrument(
|
|
9582
|
+
const storage2 = this._meterSharedState.registerMetricStorage(descriptor);
|
|
9583
|
+
return new Instruments_1.HistogramInstrument(storage2, descriptor);
|
|
9584
9584
|
}
|
|
9585
9585
|
/**
|
|
9586
9586
|
* Create a {@link Counter} instrument.
|
|
9587
9587
|
*/
|
|
9588
9588
|
createCounter(name25, options) {
|
|
9589
9589
|
const descriptor = (0, InstrumentDescriptor_1.createInstrumentDescriptor)(name25, MetricData_1.InstrumentType.COUNTER, options);
|
|
9590
|
-
const
|
|
9591
|
-
return new Instruments_1.CounterInstrument(
|
|
9590
|
+
const storage2 = this._meterSharedState.registerMetricStorage(descriptor);
|
|
9591
|
+
return new Instruments_1.CounterInstrument(storage2, descriptor);
|
|
9592
9592
|
}
|
|
9593
9593
|
/**
|
|
9594
9594
|
* Create a {@link UpDownCounter} instrument.
|
|
9595
9595
|
*/
|
|
9596
9596
|
createUpDownCounter(name25, options) {
|
|
9597
9597
|
const descriptor = (0, InstrumentDescriptor_1.createInstrumentDescriptor)(name25, MetricData_1.InstrumentType.UP_DOWN_COUNTER, options);
|
|
9598
|
-
const
|
|
9599
|
-
return new Instruments_1.UpDownCounterInstrument(
|
|
9598
|
+
const storage2 = this._meterSharedState.registerMetricStorage(descriptor);
|
|
9599
|
+
return new Instruments_1.UpDownCounterInstrument(storage2, descriptor);
|
|
9600
9600
|
}
|
|
9601
9601
|
/**
|
|
9602
9602
|
* Create a {@link ObservableGauge} instrument.
|
|
@@ -10084,16 +10084,16 @@ var require_MetricStorageRegistry = __commonJS({
|
|
|
10084
10084
|
}
|
|
10085
10085
|
return storages;
|
|
10086
10086
|
}
|
|
10087
|
-
register(
|
|
10088
|
-
this._registerStorage(
|
|
10087
|
+
register(storage2) {
|
|
10088
|
+
this._registerStorage(storage2, this._sharedRegistry);
|
|
10089
10089
|
}
|
|
10090
|
-
registerForCollector(collector,
|
|
10090
|
+
registerForCollector(collector, storage2) {
|
|
10091
10091
|
let storageMap = this._perCollectorRegistry.get(collector);
|
|
10092
10092
|
if (storageMap == null) {
|
|
10093
10093
|
storageMap = /* @__PURE__ */ new Map();
|
|
10094
10094
|
this._perCollectorRegistry.set(collector, storageMap);
|
|
10095
10095
|
}
|
|
10096
|
-
this._registerStorage(
|
|
10096
|
+
this._registerStorage(storage2, storageMap);
|
|
10097
10097
|
}
|
|
10098
10098
|
findOrUpdateCompatibleStorage(expectedDescriptor) {
|
|
10099
10099
|
const storages = this._sharedRegistry.get(expectedDescriptor.name);
|
|
@@ -10113,14 +10113,14 @@ var require_MetricStorageRegistry = __commonJS({
|
|
|
10113
10113
|
}
|
|
10114
10114
|
return this._findOrUpdateCompatibleStorage(expectedDescriptor, storages);
|
|
10115
10115
|
}
|
|
10116
|
-
_registerStorage(
|
|
10117
|
-
const descriptor =
|
|
10116
|
+
_registerStorage(storage2, storageMap) {
|
|
10117
|
+
const descriptor = storage2.getInstrumentDescriptor();
|
|
10118
10118
|
const storages = storageMap.get(descriptor.name);
|
|
10119
10119
|
if (storages === void 0) {
|
|
10120
|
-
storageMap.set(descriptor.name, [
|
|
10120
|
+
storageMap.set(descriptor.name, [storage2]);
|
|
10121
10121
|
return;
|
|
10122
10122
|
}
|
|
10123
|
-
storages.push(
|
|
10123
|
+
storages.push(storage2);
|
|
10124
10124
|
}
|
|
10125
10125
|
_findOrUpdateCompatibleStorage(expectedDescriptor, existingStorages) {
|
|
10126
10126
|
let compatibleStorage = null;
|
|
@@ -10550,9 +10550,9 @@ var require_MeterSharedState = __commonJS({
|
|
|
10550
10550
|
}
|
|
10551
10551
|
const aggregator = aggregation.createAggregator(descriptor);
|
|
10552
10552
|
const cardinalityLimit = collector.selectCardinalityLimit(descriptor.type);
|
|
10553
|
-
const
|
|
10554
|
-
this.metricStorageRegistry.registerForCollector(collector,
|
|
10555
|
-
return
|
|
10553
|
+
const storage2 = new MetricStorageType(descriptor, aggregator, (0, AttributesProcessor_1.createNoopAttributesProcessor)(), [collector], cardinalityLimit);
|
|
10554
|
+
this.metricStorageRegistry.registerForCollector(collector, storage2);
|
|
10555
|
+
return storage2;
|
|
10556
10556
|
});
|
|
10557
10557
|
storages = storages.concat(collectorStorages);
|
|
10558
10558
|
}
|
|
@@ -95415,7 +95415,7 @@ var require_light_my_request = __commonJS({
|
|
|
95415
95415
|
var require_fastify = __commonJS({
|
|
95416
95416
|
"../../node_modules/.pnpm/fastify@5.7.2/node_modules/fastify/fastify.js"(exports, module) {
|
|
95417
95417
|
"use strict";
|
|
95418
|
-
var
|
|
95418
|
+
var VERSION9 = "5.7.2";
|
|
95419
95419
|
var Avvio = require_boot();
|
|
95420
95420
|
var http = __require("node:http");
|
|
95421
95421
|
var diagnostics = __require("node:diagnostics_channel");
|
|
@@ -95716,7 +95716,7 @@ var require_fastify = __commonJS({
|
|
|
95716
95716
|
version: {
|
|
95717
95717
|
configurable: true,
|
|
95718
95718
|
get() {
|
|
95719
|
-
return
|
|
95719
|
+
return VERSION9;
|
|
95720
95720
|
}
|
|
95721
95721
|
},
|
|
95722
95722
|
errorHandler: {
|
|
@@ -107959,7 +107959,7 @@ var require_websocket = __commonJS({
|
|
|
107959
107959
|
var http = __require("http");
|
|
107960
107960
|
var net2 = __require("net");
|
|
107961
107961
|
var tls = __require("tls");
|
|
107962
|
-
var { randomBytes:
|
|
107962
|
+
var { randomBytes: randomBytes5, createHash: createHash9 } = __require("crypto");
|
|
107963
107963
|
var { Duplex, Readable: Readable4 } = __require("stream");
|
|
107964
107964
|
var { URL: URL2 } = __require("url");
|
|
107965
107965
|
var PerMessageDeflate = require_permessage_deflate();
|
|
@@ -108489,7 +108489,7 @@ var require_websocket = __commonJS({
|
|
|
108489
108489
|
}
|
|
108490
108490
|
}
|
|
108491
108491
|
const defaultPort = isSecure ? 443 : 80;
|
|
108492
|
-
const key2 =
|
|
108492
|
+
const key2 = randomBytes5(16).toString("base64");
|
|
108493
108493
|
const request = isSecure ? https.request : http.request;
|
|
108494
108494
|
const protocolSet = /* @__PURE__ */ new Set();
|
|
108495
108495
|
let perMessageDeflate;
|
|
@@ -112389,7 +112389,7 @@ var require_websocket2 = __commonJS({
|
|
|
112389
112389
|
"use strict";
|
|
112390
112390
|
var { ServerResponse } = __require("node:http");
|
|
112391
112391
|
var { PassThrough } = __require("node:stream");
|
|
112392
|
-
var { randomBytes:
|
|
112392
|
+
var { randomBytes: randomBytes5 } = __require("node:crypto");
|
|
112393
112393
|
var fp36 = require_plugin2();
|
|
112394
112394
|
var WebSocket2 = require_ws();
|
|
112395
112395
|
var Duplexify = require_duplexify();
|
|
@@ -112460,7 +112460,7 @@ var require_websocket2 = __commonJS({
|
|
|
112460
112460
|
connection: "upgrade",
|
|
112461
112461
|
upgrade: "websocket",
|
|
112462
112462
|
"sec-websocket-version": 13,
|
|
112463
|
-
"sec-websocket-key":
|
|
112463
|
+
"sec-websocket-key": randomBytes5(16).toString("base64")
|
|
112464
112464
|
},
|
|
112465
112465
|
httpVersion: "1.1",
|
|
112466
112466
|
url: path23,
|
|
@@ -132602,7 +132602,7 @@ var require_sqlite_cache_store = __commonJS({
|
|
|
132602
132602
|
var { Writable: Writable2 } = __require("node:stream");
|
|
132603
132603
|
var { assertCacheKey, assertCacheValue } = require_cache();
|
|
132604
132604
|
var DatabaseSync;
|
|
132605
|
-
var
|
|
132605
|
+
var VERSION9 = 3;
|
|
132606
132606
|
var MAX_ENTRY_SIZE = 2 * 1e3 * 1e3 * 1e3;
|
|
132607
132607
|
module.exports = class SqliteCacheStore {
|
|
132608
132608
|
#maxEntrySize = MAX_ENTRY_SIZE;
|
|
@@ -132673,7 +132673,7 @@ var require_sqlite_cache_store = __commonJS({
|
|
|
132673
132673
|
PRAGMA temp_store = memory;
|
|
132674
132674
|
PRAGMA optimize;
|
|
132675
132675
|
|
|
132676
|
-
CREATE TABLE IF NOT EXISTS cacheInterceptorV${
|
|
132676
|
+
CREATE TABLE IF NOT EXISTS cacheInterceptorV${VERSION9} (
|
|
132677
132677
|
-- Data specific to us
|
|
132678
132678
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
132679
132679
|
url TEXT NOT NULL,
|
|
@@ -132692,8 +132692,8 @@ var require_sqlite_cache_store = __commonJS({
|
|
|
132692
132692
|
staleAt INTEGER NOT NULL
|
|
132693
132693
|
);
|
|
132694
132694
|
|
|
132695
|
-
CREATE INDEX IF NOT EXISTS idx_cacheInterceptorV${
|
|
132696
|
-
CREATE INDEX IF NOT EXISTS idx_cacheInterceptorV${
|
|
132695
|
+
CREATE INDEX IF NOT EXISTS idx_cacheInterceptorV${VERSION9}_getValuesQuery ON cacheInterceptorV${VERSION9}(url, method, deleteAt);
|
|
132696
|
+
CREATE INDEX IF NOT EXISTS idx_cacheInterceptorV${VERSION9}_deleteByUrlQuery ON cacheInterceptorV${VERSION9}(deleteAt);
|
|
132697
132697
|
`);
|
|
132698
132698
|
this.#getValuesQuery = this.#db.prepare(`
|
|
132699
132699
|
SELECT
|
|
@@ -132708,7 +132708,7 @@ var require_sqlite_cache_store = __commonJS({
|
|
|
132708
132708
|
vary,
|
|
132709
132709
|
cachedAt,
|
|
132710
132710
|
staleAt
|
|
132711
|
-
FROM cacheInterceptorV${
|
|
132711
|
+
FROM cacheInterceptorV${VERSION9}
|
|
132712
132712
|
WHERE
|
|
132713
132713
|
url = ?
|
|
132714
132714
|
AND method = ?
|
|
@@ -132716,7 +132716,7 @@ var require_sqlite_cache_store = __commonJS({
|
|
|
132716
132716
|
deleteAt ASC
|
|
132717
132717
|
`);
|
|
132718
132718
|
this.#updateValueQuery = this.#db.prepare(`
|
|
132719
|
-
UPDATE cacheInterceptorV${
|
|
132719
|
+
UPDATE cacheInterceptorV${VERSION9} SET
|
|
132720
132720
|
body = ?,
|
|
132721
132721
|
deleteAt = ?,
|
|
132722
132722
|
statusCode = ?,
|
|
@@ -132730,7 +132730,7 @@ var require_sqlite_cache_store = __commonJS({
|
|
|
132730
132730
|
id = ?
|
|
132731
132731
|
`);
|
|
132732
132732
|
this.#insertValueQuery = this.#db.prepare(`
|
|
132733
|
-
INSERT INTO cacheInterceptorV${
|
|
132733
|
+
INSERT INTO cacheInterceptorV${VERSION9} (
|
|
132734
132734
|
url,
|
|
132735
132735
|
method,
|
|
132736
132736
|
body,
|
|
@@ -132746,20 +132746,20 @@ var require_sqlite_cache_store = __commonJS({
|
|
|
132746
132746
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
132747
132747
|
`);
|
|
132748
132748
|
this.#deleteByUrlQuery = this.#db.prepare(
|
|
132749
|
-
`DELETE FROM cacheInterceptorV${
|
|
132749
|
+
`DELETE FROM cacheInterceptorV${VERSION9} WHERE url = ?`
|
|
132750
132750
|
);
|
|
132751
132751
|
this.#countEntriesQuery = this.#db.prepare(
|
|
132752
|
-
`SELECT COUNT(*) AS total FROM cacheInterceptorV${
|
|
132752
|
+
`SELECT COUNT(*) AS total FROM cacheInterceptorV${VERSION9}`
|
|
132753
132753
|
);
|
|
132754
132754
|
this.#deleteExpiredValuesQuery = this.#db.prepare(
|
|
132755
|
-
`DELETE FROM cacheInterceptorV${
|
|
132755
|
+
`DELETE FROM cacheInterceptorV${VERSION9} WHERE deleteAt <= ?`
|
|
132756
132756
|
);
|
|
132757
132757
|
this.#deleteOldValuesQuery = this.#maxCount === Infinity ? null : this.#db.prepare(`
|
|
132758
|
-
DELETE FROM cacheInterceptorV${
|
|
132758
|
+
DELETE FROM cacheInterceptorV${VERSION9}
|
|
132759
132759
|
WHERE id IN (
|
|
132760
132760
|
SELECT
|
|
132761
132761
|
id
|
|
132762
|
-
FROM cacheInterceptorV${
|
|
132762
|
+
FROM cacheInterceptorV${VERSION9}
|
|
132763
132763
|
ORDER BY cachedAt DESC
|
|
132764
132764
|
LIMIT ?
|
|
132765
132765
|
)
|
|
@@ -136302,8 +136302,8 @@ var require_cache3 = __commonJS({
|
|
|
136302
136302
|
*/
|
|
136303
136303
|
#queryCache(requestQuery, options, targetStorage) {
|
|
136304
136304
|
const resultList = [];
|
|
136305
|
-
const
|
|
136306
|
-
for (const requestResponse of
|
|
136305
|
+
const storage2 = targetStorage ?? this.#relevantRequestResponseList;
|
|
136306
|
+
for (const requestResponse of storage2) {
|
|
136307
136307
|
const [cachedRequest, cachedResponse] = requestResponse;
|
|
136308
136308
|
if (this.#requestMatchesCachedItem(requestQuery, cachedRequest, cachedResponse, options)) {
|
|
136309
136309
|
resultList.push(requestResponse);
|
|
@@ -205475,8 +205475,8 @@ function verifySessionToolsToken(secret, token, nowMs) {
|
|
|
205475
205475
|
if (typeof wire.exp !== "number" || nowMs >= wire.exp) return null;
|
|
205476
205476
|
return { sessionId: wire.s };
|
|
205477
205477
|
}
|
|
205478
|
-
async function getSessionToolsSecret(
|
|
205479
|
-
return
|
|
205478
|
+
async function getSessionToolsSecret(storage2) {
|
|
205479
|
+
return storage2.settings.getOrCreate(
|
|
205480
205480
|
SESSION_TOOLS_SECRET_SETTING,
|
|
205481
205481
|
() => randomBytes(32).toString("hex")
|
|
205482
205482
|
);
|
|
@@ -205940,8 +205940,8 @@ var ProcessManager = class _ProcessManager {
|
|
|
205940
205940
|
storage;
|
|
205941
205941
|
eventBus = null;
|
|
205942
205942
|
terminalCounter = 0;
|
|
205943
|
-
constructor(
|
|
205944
|
-
this.storage =
|
|
205943
|
+
constructor(storage2) {
|
|
205944
|
+
this.storage = storage2;
|
|
205945
205945
|
}
|
|
205946
205946
|
/** Payload size of one entry; `finished` carries an uncapped finalResult. */
|
|
205947
205947
|
static logMessageBytes(msg) {
|
|
@@ -207966,22 +207966,22 @@ function reconcileWorktreeBranches(projectPath, entries, sessionBranches = [], r
|
|
|
207966
207966
|
}
|
|
207967
207967
|
return worktrees;
|
|
207968
207968
|
}
|
|
207969
|
-
async function getRegisteredWorktreeBranches(
|
|
207969
|
+
async function getRegisteredWorktreeBranches(storage2, projectId, projectPath) {
|
|
207970
207970
|
const entries = readWorktreeListTolerant(projectPath);
|
|
207971
|
-
const sessions = await
|
|
207971
|
+
const sessions = await storage2.agentSessions.getProjectedByProjectId(projectId, "runtime");
|
|
207972
207972
|
const sessionBranches = sessions.map((session) => session.branch);
|
|
207973
207973
|
const sessionBranchByPath = /* @__PURE__ */ new Map();
|
|
207974
207974
|
for (const branch of sessionBranches) {
|
|
207975
207975
|
if (branch) sessionBranchByPath.set(path7.resolve(conventionalWorktreePath(projectPath, branch)), branch);
|
|
207976
207976
|
}
|
|
207977
|
-
let registered = await
|
|
207977
|
+
let registered = await storage2.workspaceRegistry.listByProject(projectId, "local");
|
|
207978
207978
|
const livePaths = new Set(entries.map((entry) => path7.resolve(entry.path)));
|
|
207979
207979
|
for (const row of registered) {
|
|
207980
207980
|
if (livePaths.has(path7.resolve(row.checkout.worktree_path))) continue;
|
|
207981
207981
|
if (row.checkout.status === "deleting") {
|
|
207982
|
-
await
|
|
207982
|
+
await storage2.workspaceRegistry.markCheckoutDeleted(row.checkout.id);
|
|
207983
207983
|
} else if (row.checkout.status !== "error" || row.checkout.error !== "Worktree is missing") {
|
|
207984
|
-
await
|
|
207984
|
+
await storage2.workspaceRegistry.setCheckoutStatusIfCurrent(
|
|
207985
207985
|
row.checkout.id,
|
|
207986
207986
|
{ status: row.checkout.status, updatedAt: row.checkout.updated_at },
|
|
207987
207987
|
"error",
|
|
@@ -207989,7 +207989,7 @@ async function getRegisteredWorktreeBranches(storage, projectId, projectPath) {
|
|
|
207989
207989
|
);
|
|
207990
207990
|
}
|
|
207991
207991
|
}
|
|
207992
|
-
registered = await
|
|
207992
|
+
registered = await storage2.workspaceRegistry.listByProject(projectId, "local");
|
|
207993
207993
|
const registeredPaths = new Set(registered.map((row) => path7.resolve(row.checkout.worktree_path)));
|
|
207994
207994
|
for (let index = 0; index < entries.length; index++) {
|
|
207995
207995
|
const entry = entries[index];
|
|
@@ -207997,10 +207997,10 @@ async function getRegisteredWorktreeBranches(storage, projectId, projectPath) {
|
|
|
207997
207997
|
const existing = registered.find((row) => path7.resolve(row.checkout.worktree_path) === resolvedPath);
|
|
207998
207998
|
if (existing) {
|
|
207999
207999
|
if (existing.checkout.status === "creating" || existing.checkout.status === "error") {
|
|
208000
|
-
await
|
|
208000
|
+
await storage2.workspaceRegistry.setCheckoutStatus(existing.checkout.id, "ready");
|
|
208001
208001
|
}
|
|
208002
208002
|
if (index === 0 && existing.checkout.expected_branch === "" && entry.branch) {
|
|
208003
|
-
await
|
|
208003
|
+
await storage2.workspaceRegistry.registerReadyCheckout({
|
|
208004
208004
|
projectId,
|
|
208005
208005
|
branch: existing.workspace.branch,
|
|
208006
208006
|
targetId: "local",
|
|
@@ -208012,7 +208012,7 @@ async function getRegisteredWorktreeBranches(storage, projectId, projectPath) {
|
|
|
208012
208012
|
}
|
|
208013
208013
|
if (registeredPaths.has(resolvedPath) || entry.branch === null && index > 0) continue;
|
|
208014
208014
|
const stableBranch = index === 0 ? "" : sessionBranchByPath.get(resolvedPath) ?? entry.branch;
|
|
208015
|
-
await
|
|
208015
|
+
await storage2.workspaceRegistry.registerReadyCheckout({
|
|
208016
208016
|
projectId,
|
|
208017
208017
|
branch: stableBranch,
|
|
208018
208018
|
targetId: "local",
|
|
@@ -208021,7 +208021,7 @@ async function getRegisteredWorktreeBranches(storage, projectId, projectPath) {
|
|
|
208021
208021
|
});
|
|
208022
208022
|
registeredPaths.add(resolvedPath);
|
|
208023
208023
|
}
|
|
208024
|
-
registered = await
|
|
208024
|
+
registered = await storage2.workspaceRegistry.listByProject(projectId, "local");
|
|
208025
208025
|
const anchors = registered.map((row) => ({
|
|
208026
208026
|
branch: row.workspace.branch,
|
|
208027
208027
|
worktreePath: row.checkout.worktree_path,
|
|
@@ -208029,13 +208029,13 @@ async function getRegisteredWorktreeBranches(storage, projectId, projectPath) {
|
|
|
208029
208029
|
}));
|
|
208030
208030
|
return reconcileWorktreeBranches(projectPath, entries, sessionBranches, anchors);
|
|
208031
208031
|
}
|
|
208032
|
-
async function anchorRootWorkspaceBranch(
|
|
208032
|
+
async function anchorRootWorkspaceBranch(storage2, projectId, projectPath, observedBranch) {
|
|
208033
208033
|
invalidateWorktreeListCache(projectPath);
|
|
208034
208034
|
const rootEntry = readWorktreeListTolerant(projectPath)[0];
|
|
208035
208035
|
if (!rootEntry || rootEntry.branch !== observedBranch) {
|
|
208036
208036
|
return { anchored: false, currentBranch: rootEntry?.branch ?? null };
|
|
208037
208037
|
}
|
|
208038
|
-
await
|
|
208038
|
+
await storage2.workspaceRegistry.registerReadyCheckout({
|
|
208039
208039
|
projectId,
|
|
208040
208040
|
branch: "",
|
|
208041
208041
|
// The main-workspace identity sentinel; never the branch name.
|
|
@@ -208057,20 +208057,20 @@ function localBranchExists(projectPath, branch) {
|
|
|
208057
208057
|
return false;
|
|
208058
208058
|
}
|
|
208059
208059
|
}
|
|
208060
|
-
async function setRootWorkspaceAnchor(
|
|
208060
|
+
async function setRootWorkspaceAnchor(storage2, projectId, projectPath, branch) {
|
|
208061
208061
|
invalidateWorktreeListCache(projectPath);
|
|
208062
208062
|
const entries = readWorktreeListTolerant(projectPath);
|
|
208063
208063
|
const rootEntry = entries[0];
|
|
208064
208064
|
if (!rootEntry || !localBranchExists(projectPath, branch)) {
|
|
208065
208065
|
return { anchored: false, reason: rootEntry ? "unknown-branch" : "not-a-repository" };
|
|
208066
208066
|
}
|
|
208067
|
-
const registered = await
|
|
208067
|
+
const registered = await storage2.workspaceRegistry.listByProject(projectId, "local");
|
|
208068
208068
|
const takenByWorkspace = registered.some((row) => row.workspace.branch !== "" && row.workspace.branch === branch);
|
|
208069
208069
|
const takenByWorktree = entries.slice(1).some((entry) => entry.branch === branch);
|
|
208070
208070
|
if (takenByWorkspace || takenByWorktree) {
|
|
208071
208071
|
return { anchored: false, reason: "branch-is-another-workspace" };
|
|
208072
208072
|
}
|
|
208073
|
-
await
|
|
208073
|
+
await storage2.workspaceRegistry.registerReadyCheckout({
|
|
208074
208074
|
projectId,
|
|
208075
208075
|
branch: "",
|
|
208076
208076
|
// The main-workspace identity sentinel; never the branch name.
|
|
@@ -228912,8 +228912,8 @@ function parseChatProviderConfig(raw) {
|
|
|
228912
228912
|
return defaultConfig();
|
|
228913
228913
|
}
|
|
228914
228914
|
}
|
|
228915
|
-
async function getChatProviderConfig(
|
|
228916
|
-
const raw = await
|
|
228915
|
+
async function getChatProviderConfig(storage2, userId) {
|
|
228916
|
+
const raw = await storage2.userSettings.get(userId, "chat_provider");
|
|
228917
228917
|
return parseChatProviderConfig(raw);
|
|
228918
228918
|
}
|
|
228919
228919
|
function resolveModel(choice2, apiKeys) {
|
|
@@ -228925,12 +228925,12 @@ function isModelConfigured(config2, choice2) {
|
|
|
228925
228925
|
const def = PROVIDERS[choice2.provider];
|
|
228926
228926
|
return Boolean(config2.apiKeys[choice2.provider] || process.env[def.envKey]);
|
|
228927
228927
|
}
|
|
228928
|
-
async function resolveChatModel(
|
|
228929
|
-
const config2 = await getChatProviderConfig(
|
|
228928
|
+
async function resolveChatModel(storage2, userId) {
|
|
228929
|
+
const config2 = await getChatProviderConfig(storage2, userId);
|
|
228930
228930
|
return resolveModel(config2.main, config2.apiKeys);
|
|
228931
228931
|
}
|
|
228932
|
-
async function resolveFastChatModel(
|
|
228933
|
-
const config2 = await getChatProviderConfig(
|
|
228932
|
+
async function resolveFastChatModel(storage2, userId) {
|
|
228933
|
+
const config2 = await getChatProviderConfig(storage2, userId);
|
|
228934
228934
|
return resolveModel(config2.fast, config2.apiKeys);
|
|
228935
228935
|
}
|
|
228936
228936
|
|
|
@@ -228946,8 +228946,8 @@ function buildPrompt(userMessage) {
|
|
|
228946
228946
|
|
|
228947
228947
|
${input}`;
|
|
228948
228948
|
}
|
|
228949
|
-
async function isChatModelConfigured(
|
|
228950
|
-
const config2 = await getChatProviderConfig(
|
|
228949
|
+
async function isChatModelConfigured(storage2, userId) {
|
|
228950
|
+
const config2 = await getChatProviderConfig(storage2, userId);
|
|
228951
228951
|
return isModelConfigured(config2, config2.fast);
|
|
228952
228952
|
}
|
|
228953
228953
|
function extractUserText(content) {
|
|
@@ -228996,9 +228996,9 @@ async function generateSessionTitleWithModel(model, userMessage, options = {}) {
|
|
|
228996
228996
|
return null;
|
|
228997
228997
|
}
|
|
228998
228998
|
}
|
|
228999
|
-
async function generateSessionTitle(
|
|
229000
|
-
if (!await isChatModelConfigured(
|
|
229001
|
-
return generateSessionTitleWithModel(await resolveFastChatModel(
|
|
228999
|
+
async function generateSessionTitle(storage2, userMessage, userId) {
|
|
229000
|
+
if (!await isChatModelConfigured(storage2, userId)) return null;
|
|
229001
|
+
return generateSessionTitleWithModel(await resolveFastChatModel(storage2, userId), userMessage, { userId });
|
|
229002
229002
|
}
|
|
229003
229003
|
|
|
229004
229004
|
// src/utils/review-snapshot.ts
|
|
@@ -229149,11 +229149,11 @@ function computeScope(start, end, worktreePath) {
|
|
|
229149
229149
|
changed.sort();
|
|
229150
229150
|
return { changedFiles: changed, startHead: start.head };
|
|
229151
229151
|
}
|
|
229152
|
-
async function recordTurnSnapshot(
|
|
229152
|
+
async function recordTurnSnapshot(storage2, sessionId, turnEndIndex, worktreePath, captured) {
|
|
229153
229153
|
try {
|
|
229154
229154
|
const snap = captured ?? captureSnapshot(worktreePath);
|
|
229155
229155
|
if (!snap) return;
|
|
229156
|
-
await
|
|
229156
|
+
await storage2.turnSnapshots.create({
|
|
229157
229157
|
session_id: sessionId,
|
|
229158
229158
|
turn_end_index: turnEndIndex,
|
|
229159
229159
|
head: snap.head,
|
|
@@ -229163,8 +229163,8 @@ async function recordTurnSnapshot(storage, sessionId, turnEndIndex, worktreePath
|
|
|
229163
229163
|
console.warn(`[ReviewSnapshot] failed to record snapshot for ${sessionId}@${turnEndIndex}:`, err.message);
|
|
229164
229164
|
}
|
|
229165
229165
|
}
|
|
229166
|
-
async function resolveStartSnapshot(
|
|
229167
|
-
return span === "session_start" ?
|
|
229166
|
+
async function resolveStartSnapshot(storage2, sessionId, span, turnEndIndex) {
|
|
229167
|
+
return span === "session_start" ? storage2.turnSnapshots.getSessionStart(sessionId) : storage2.turnSnapshots.getStartBoundary(sessionId, turnEndIndex);
|
|
229168
229168
|
}
|
|
229169
229169
|
|
|
229170
229170
|
// src/branch-activity.ts
|
|
@@ -229516,8 +229516,8 @@ var AgentSessionManager = class {
|
|
|
229516
229516
|
/** Grace window before committing a held completion (injectable for tests). */
|
|
229517
229517
|
completionGraceMs;
|
|
229518
229518
|
workflowSuppressionCheck = null;
|
|
229519
|
-
constructor(
|
|
229520
|
-
this.storage =
|
|
229519
|
+
constructor(storage2, opts) {
|
|
229520
|
+
this.storage = storage2;
|
|
229521
229521
|
this.completionGraceMs = opts?.completionGraceMs ?? COMPLETION_GRACE_MS;
|
|
229522
229522
|
}
|
|
229523
229523
|
async resolveSessionWorktreePath(session, legacyProjectPath) {
|
|
@@ -231892,6 +231892,68 @@ var AgentSessionManager = class {
|
|
|
231892
231892
|
// src/chat-session-manager.ts
|
|
231893
231893
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
231894
231894
|
|
|
231895
|
+
// src/trace-context.ts
|
|
231896
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
231897
|
+
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
231898
|
+
var VERSION8 = "00";
|
|
231899
|
+
var INVALID_VERSION = "ff";
|
|
231900
|
+
var ZERO_TRACE_ID = "0".repeat(32);
|
|
231901
|
+
var ZERO_SPAN_ID = "0".repeat(16);
|
|
231902
|
+
var HEX_2 = /^[0-9a-f]{2}$/;
|
|
231903
|
+
var HEX_16 = /^[0-9a-f]{16}$/;
|
|
231904
|
+
var HEX_32 = /^[0-9a-f]{32}$/;
|
|
231905
|
+
function parseTraceparent(value) {
|
|
231906
|
+
const raw = Array.isArray(value) ? value[0] : value;
|
|
231907
|
+
if (typeof raw !== "string") return null;
|
|
231908
|
+
const parts = raw.split("-");
|
|
231909
|
+
if (parts.length < 4) return null;
|
|
231910
|
+
const [version2, traceId, spanId, flags] = parts;
|
|
231911
|
+
if (!HEX_2.test(version2) || version2 === INVALID_VERSION) return null;
|
|
231912
|
+
if (version2 === VERSION8 && parts.length !== 4) return null;
|
|
231913
|
+
if (!HEX_32.test(traceId) || traceId === ZERO_TRACE_ID) return null;
|
|
231914
|
+
if (!HEX_16.test(spanId) || spanId === ZERO_SPAN_ID) return null;
|
|
231915
|
+
if (!HEX_2.test(flags)) return null;
|
|
231916
|
+
return { traceId, spanId, flags };
|
|
231917
|
+
}
|
|
231918
|
+
function formatTraceparent(ctx) {
|
|
231919
|
+
return `${VERSION8}-${ctx.traceId}-${ctx.spanId}-${ctx.sampled ? "01" : "00"}`;
|
|
231920
|
+
}
|
|
231921
|
+
function newTraceId() {
|
|
231922
|
+
return randomBytes2(16).toString("hex");
|
|
231923
|
+
}
|
|
231924
|
+
function newSpanId() {
|
|
231925
|
+
return randomBytes2(8).toString("hex");
|
|
231926
|
+
}
|
|
231927
|
+
function newTraceContext(incoming) {
|
|
231928
|
+
const parsed = parseTraceparent(incoming);
|
|
231929
|
+
if (parsed) {
|
|
231930
|
+
return {
|
|
231931
|
+
traceId: parsed.traceId,
|
|
231932
|
+
spanId: newSpanId(),
|
|
231933
|
+
parentSpanId: parsed.spanId,
|
|
231934
|
+
sampled: (parseInt(parsed.flags, 16) & 1) === 1,
|
|
231935
|
+
continued: true
|
|
231936
|
+
};
|
|
231937
|
+
}
|
|
231938
|
+
return {
|
|
231939
|
+
traceId: newTraceId(),
|
|
231940
|
+
spanId: newSpanId(),
|
|
231941
|
+
sampled: true,
|
|
231942
|
+
continued: false
|
|
231943
|
+
};
|
|
231944
|
+
}
|
|
231945
|
+
var storage = new AsyncLocalStorage();
|
|
231946
|
+
function runWithTraceContext(ctx, fn) {
|
|
231947
|
+
return storage.run(ctx, fn);
|
|
231948
|
+
}
|
|
231949
|
+
function getTraceContext() {
|
|
231950
|
+
return storage.getStore();
|
|
231951
|
+
}
|
|
231952
|
+
function outboundTraceparent() {
|
|
231953
|
+
const ctx = storage.getStore();
|
|
231954
|
+
return ctx ? formatTraceparent(ctx) : void 0;
|
|
231955
|
+
}
|
|
231956
|
+
|
|
231895
231957
|
// src/utils/remote-proxy.ts
|
|
231896
231958
|
function proxyStatus(result, fallback = 502) {
|
|
231897
231959
|
return result.status > 0 ? result.status : fallback;
|
|
@@ -231899,7 +231961,12 @@ function proxyStatus(result, fallback = 502) {
|
|
|
231899
231961
|
async function proxyToRemoteAuto(remoteServerId, method, apiPath, body, options) {
|
|
231900
231962
|
const rcm = options?.reverseConnectManager;
|
|
231901
231963
|
if (rcm && rcm.isConnected(remoteServerId)) {
|
|
231902
|
-
|
|
231964
|
+
const traceparent = outboundTraceparent();
|
|
231965
|
+
const headers = {
|
|
231966
|
+
...traceparent ? { traceparent } : {},
|
|
231967
|
+
...options?.headers
|
|
231968
|
+
};
|
|
231969
|
+
return rcm.sendHttpRequest(remoteServerId, method, apiPath, body, options?.timeoutMs, headers);
|
|
231903
231970
|
}
|
|
231904
231971
|
return {
|
|
231905
231972
|
ok: false,
|
|
@@ -232040,7 +232107,7 @@ function runUpdatedFrameForSubscribers(evt) {
|
|
|
232040
232107
|
}
|
|
232041
232108
|
|
|
232042
232109
|
// src/utils/cross-remote-token.ts
|
|
232043
|
-
import { createHmac as createHmac2, randomBytes as
|
|
232110
|
+
import { createHmac as createHmac2, randomBytes as randomBytes3, timingSafeEqual as timingSafeEqual2 } from "crypto";
|
|
232044
232111
|
var CROSS_REMOTE_SECRET_SETTING = "cross_remote_token_secret";
|
|
232045
232112
|
var CROSS_REMOTE_TOKEN_TTL_MS = 864e5;
|
|
232046
232113
|
var sign2 = (secret, body) => createHmac2("sha256", secret).update(body).digest("base64url");
|
|
@@ -232076,10 +232143,10 @@ function verifyCrossRemoteToken(secret, token, nowMs) {
|
|
|
232076
232143
|
if (nowMs >= wire.exp) return null;
|
|
232077
232144
|
return { userId: wire.u, sessionId: wire.s, sourceRemoteServerId: wire.src };
|
|
232078
232145
|
}
|
|
232079
|
-
async function getCrossRemoteSecret(
|
|
232080
|
-
return
|
|
232146
|
+
async function getCrossRemoteSecret(storage2) {
|
|
232147
|
+
return storage2.settings.getOrCreate(
|
|
232081
232148
|
CROSS_REMOTE_SECRET_SETTING,
|
|
232082
|
-
() =>
|
|
232149
|
+
() => randomBytes3(32).toString("hex")
|
|
232083
232150
|
);
|
|
232084
232151
|
}
|
|
232085
232152
|
|
|
@@ -232633,8 +232700,8 @@ function groupByServer(mappings) {
|
|
|
232633
232700
|
}
|
|
232634
232701
|
|
|
232635
232702
|
// src/remote-agent-sessions.ts
|
|
232636
|
-
async function bindRemoteSessionMapping(
|
|
232637
|
-
const mappingRepo = opts.mappingRepo ??
|
|
232703
|
+
async function bindRemoteSessionMapping(storage2, opts) {
|
|
232704
|
+
const mappingRepo = opts.mappingRepo ?? storage2.remoteSessionMappings;
|
|
232638
232705
|
const existingMapping = await mappingRepo.getByLocal(opts.localSessionId);
|
|
232639
232706
|
if (existingMapping?.workspace_checkout_id) {
|
|
232640
232707
|
if (existingMapping.project_id !== opts.projectId || existingMapping.remote_server_id !== opts.remoteServerId || existingMapping.remote_session_id !== opts.remoteSessionId || (existingMapping.branch ?? "") !== (opts.branch ?? "")) {
|
|
@@ -232644,13 +232711,13 @@ async function bindRemoteSessionMapping(storage, opts) {
|
|
|
232644
232711
|
}
|
|
232645
232712
|
const branchKey = opts.branch ?? "";
|
|
232646
232713
|
const fallbackPath = opts.branch ? conventionalWorktreePath(opts.remotePath, opts.branch) : opts.remotePath;
|
|
232647
|
-
let registered = await
|
|
232714
|
+
let registered = await storage2.workspaceRegistry.getByProjectBranch(
|
|
232648
232715
|
opts.projectId,
|
|
232649
232716
|
branchKey,
|
|
232650
232717
|
opts.remoteServerId
|
|
232651
232718
|
);
|
|
232652
232719
|
if (!registered || opts.reportedWorktreePath && (registered.checkout.path_source !== "reported" || registered.checkout.worktree_path !== opts.reportedWorktreePath)) {
|
|
232653
|
-
registered = await
|
|
232720
|
+
registered = await storage2.workspaceRegistry.registerReadyCheckout({
|
|
232654
232721
|
projectId: opts.projectId,
|
|
232655
232722
|
branch: branchKey,
|
|
232656
232723
|
targetId: opts.remoteServerId,
|
|
@@ -233182,11 +233249,11 @@ function isSequencePrefix(cached2, replay) {
|
|
|
233182
233249
|
}
|
|
233183
233250
|
return true;
|
|
233184
233251
|
}
|
|
233185
|
-
async function persistRemoteSessionActivityFrame(
|
|
233252
|
+
async function persistRemoteSessionActivityFrame(storage2, sessionId, remoteInfo, parsed, activityAt = Date.now()) {
|
|
233186
233253
|
const projectId = projectIdFromRemoteSessionId(sessionId, remoteInfo);
|
|
233187
233254
|
const statusEvent = statusEventFromRemotePatch(parsed, sessionId, remoteInfo);
|
|
233188
233255
|
if (statusEvent) {
|
|
233189
|
-
return
|
|
233256
|
+
return storage2.searchCache.updateRemoteSessionActivity({
|
|
233190
233257
|
localSessionId: sessionId,
|
|
233191
233258
|
projectId,
|
|
233192
233259
|
targetId: remoteInfo.remoteServerId,
|
|
@@ -233197,7 +233264,7 @@ async function persistRemoteSessionActivityFrame(storage, sessionId, remoteInfo,
|
|
|
233197
233264
|
});
|
|
233198
233265
|
}
|
|
233199
233266
|
if ("taskCompleted" in parsed) {
|
|
233200
|
-
return
|
|
233267
|
+
return storage2.searchCache.updateRemoteSessionActivity({
|
|
233201
233268
|
localSessionId: sessionId,
|
|
233202
233269
|
projectId,
|
|
233203
233270
|
targetId: remoteInfo.remoteServerId,
|
|
@@ -233208,7 +233275,7 @@ async function persistRemoteSessionActivityFrame(storage, sessionId, remoteInfo,
|
|
|
233208
233275
|
});
|
|
233209
233276
|
}
|
|
233210
233277
|
if ("error" in parsed) {
|
|
233211
|
-
return
|
|
233278
|
+
return storage2.searchCache.updateRemoteSessionActivity({
|
|
233212
233279
|
localSessionId: sessionId,
|
|
233213
233280
|
projectId,
|
|
233214
233281
|
targetId: remoteInfo.remoteServerId,
|
|
@@ -233219,7 +233286,7 @@ async function persistRemoteSessionActivityFrame(storage, sessionId, remoteInfo,
|
|
|
233219
233286
|
}
|
|
233220
233287
|
return false;
|
|
233221
233288
|
}
|
|
233222
|
-
function connectPersistentRemoteWs(sessionId, remoteInfo, cache2, reverseConnectManager, eventBus, agentSessionManager,
|
|
233289
|
+
function connectPersistentRemoteWs(sessionId, remoteInfo, cache2, reverseConnectManager, eventBus, agentSessionManager, storage2, requestedHistory) {
|
|
233223
233290
|
const hasCachedData = cache2.hasData(sessionId);
|
|
233224
233291
|
console.log(`[AgentWS] Opening persistent remote WS for ${sessionId} (cached=${hasCachedData})`);
|
|
233225
233292
|
if (!reverseConnectManager || !reverseConnectManager.isConnected(remoteInfo.remoteServerId)) {
|
|
@@ -233274,8 +233341,8 @@ function connectPersistentRemoteWs(sessionId, remoteInfo, cache2, reverseConnect
|
|
|
233274
233341
|
if (statusEvent) {
|
|
233275
233342
|
cache2.setSessionStatus(sessionId, statusEvent.status);
|
|
233276
233343
|
let activityReady = true;
|
|
233277
|
-
if (
|
|
233278
|
-
activityReady = await persistRemoteSessionActivityFrame(
|
|
233344
|
+
if (storage2) {
|
|
233345
|
+
activityReady = await persistRemoteSessionActivityFrame(storage2, sessionId, remoteInfo, parsed).catch((error48) => {
|
|
233279
233346
|
console.error(`[AgentWS] activity write-through failed for ${sessionId}:`, error48);
|
|
233280
233347
|
return false;
|
|
233281
233348
|
});
|
|
@@ -233297,8 +233364,8 @@ function connectPersistentRemoteWs(sessionId, remoteInfo, cache2, reverseConnect
|
|
|
233297
233364
|
cache2.appendMessage(sessionId, raw, false);
|
|
233298
233365
|
cache2.broadcast(sessionId, raw);
|
|
233299
233366
|
let activityReady = true;
|
|
233300
|
-
if (
|
|
233301
|
-
activityReady = await persistRemoteSessionActivityFrame(
|
|
233367
|
+
if (storage2) {
|
|
233368
|
+
activityReady = await persistRemoteSessionActivityFrame(storage2, sessionId, remoteInfo, parsed).catch((error48) => {
|
|
233302
233369
|
console.error(`[AgentWS] completion write-through failed for ${sessionId}:`, error48);
|
|
233303
233370
|
return false;
|
|
233304
233371
|
});
|
|
@@ -233353,8 +233420,8 @@ function connectPersistentRemoteWs(sessionId, remoteInfo, cache2, reverseConnect
|
|
|
233353
233420
|
cache2.appendMessage(sessionId, raw, false);
|
|
233354
233421
|
cache2.broadcast(sessionId, raw);
|
|
233355
233422
|
let activityReady = true;
|
|
233356
|
-
if (
|
|
233357
|
-
activityReady = await persistRemoteSessionActivityFrame(
|
|
233423
|
+
if (storage2) {
|
|
233424
|
+
activityReady = await persistRemoteSessionActivityFrame(storage2, sessionId, remoteInfo, parsed).catch((error48) => {
|
|
233358
233425
|
console.error(`[AgentWS] error write-through failed for ${sessionId}:`, error48);
|
|
233359
233426
|
return false;
|
|
233360
233427
|
});
|
|
@@ -233472,10 +233539,10 @@ function connectPersistentRemoteWs(sessionId, remoteInfo, cache2, reverseConnect
|
|
|
233472
233539
|
cache2.setRemoteWs(sessionId, null);
|
|
233473
233540
|
const entry = cache2.get(sessionId);
|
|
233474
233541
|
if (!entry || entry.finished) return;
|
|
233475
|
-
scheduleRemoteReconnect(sessionId, remoteInfo, cache2, reverseConnectManager, eventBus, agentSessionManager,
|
|
233542
|
+
scheduleRemoteReconnect(sessionId, remoteInfo, cache2, reverseConnectManager, eventBus, agentSessionManager, storage2);
|
|
233476
233543
|
});
|
|
233477
233544
|
}
|
|
233478
|
-
function scheduleRemoteReconnect(sessionId, remoteInfo, cache2, reverseConnectManager, eventBus, agentSessionManager,
|
|
233545
|
+
function scheduleRemoteReconnect(sessionId, remoteInfo, cache2, reverseConnectManager, eventBus, agentSessionManager, storage2) {
|
|
233479
233546
|
const entry = cache2.get(sessionId);
|
|
233480
233547
|
if (!entry || entry.finished) return;
|
|
233481
233548
|
const attempt = cache2.getReconnectAttempt(sessionId);
|
|
@@ -233497,7 +233564,7 @@ function scheduleRemoteReconnect(sessionId, remoteInfo, cache2, reverseConnectMa
|
|
|
233497
233564
|
cache2.setReconnecting(sessionId, false);
|
|
233498
233565
|
return;
|
|
233499
233566
|
}
|
|
233500
|
-
connectPersistentRemoteWs(sessionId, remoteInfo, cache2, reverseConnectManager, eventBus, agentSessionManager,
|
|
233567
|
+
connectPersistentRemoteWs(sessionId, remoteInfo, cache2, reverseConnectManager, eventBus, agentSessionManager, storage2);
|
|
233501
233568
|
}, totalDelay);
|
|
233502
233569
|
cache2.setReconnectTimer(sessionId, timer);
|
|
233503
233570
|
}
|
|
@@ -233642,8 +233709,8 @@ var ChatSessionManager = class {
|
|
|
233642
233709
|
workflowEngine = null;
|
|
233643
233710
|
/** Pending browser commands waiting for iframe response: commandId → resolve */
|
|
233644
233711
|
pendingBrowserCommands = /* @__PURE__ */ new Map();
|
|
233645
|
-
constructor(
|
|
233646
|
-
this.storage =
|
|
233712
|
+
constructor(storage2, processManager, agentSessionManager, remoteSessionMap, remoteExecutorMap, remotePatchCache, reverseConnectManager, browserManager) {
|
|
233713
|
+
this.storage = storage2;
|
|
233647
233714
|
this.processManager = processManager;
|
|
233648
233715
|
this.agentSessionManager = agentSessionManager;
|
|
233649
233716
|
this.remoteSessionMap = remoteSessionMap;
|
|
@@ -234558,7 +234625,7 @@ var ChatSessionManager = class {
|
|
|
234558
234625
|
return sections.join("\n");
|
|
234559
234626
|
}
|
|
234560
234627
|
createTools(projectId, branch, sessionId) {
|
|
234561
|
-
const
|
|
234628
|
+
const storage2 = this.storage;
|
|
234562
234629
|
const processManager = this.processManager;
|
|
234563
234630
|
const turnStartedAt = (sessionId ? this.sessions.get(sessionId)?.turnStartedAt : null) ?? null;
|
|
234564
234631
|
const wokenByEvent = (sessionId ? this.sessions.get(sessionId)?.wokenByEvent : false) ?? false;
|
|
@@ -234703,7 +234770,7 @@ var ChatSessionManager = class {
|
|
|
234703
234770
|
if (!sessionId) {
|
|
234704
234771
|
return { success: false, message: "No session context available." };
|
|
234705
234772
|
}
|
|
234706
|
-
const project = await
|
|
234773
|
+
const project = await storage2.projects.getById(projectId);
|
|
234707
234774
|
const agentMode = project?.agent_mode;
|
|
234708
234775
|
if (project && agentMode && agentMode !== "local") {
|
|
234709
234776
|
return await this.spawnRemoteAgentSession({ projectId, branch, agentMode, prompt, agentType, chatSessionId: sessionId });
|
|
@@ -234756,12 +234823,12 @@ var ChatSessionManager = class {
|
|
|
234756
234823
|
if (!sessionId) {
|
|
234757
234824
|
return { success: false, message: "No session context available." };
|
|
234758
234825
|
}
|
|
234759
|
-
const sendProject = await
|
|
234826
|
+
const sendProject = await storage2.projects.getById(projectId);
|
|
234760
234827
|
const sendAgentMode = sendProject?.agent_mode;
|
|
234761
234828
|
if (sendProject && sendAgentMode && sendAgentMode !== "local") {
|
|
234762
234829
|
return await this.sendToRemoteAgentSession({ projectId, branch, message, chatSessionId: sessionId });
|
|
234763
234830
|
}
|
|
234764
|
-
const project = await
|
|
234831
|
+
const project = await storage2.projects.getById(projectId);
|
|
234765
234832
|
const target = agentSessionManager.getSessionByBranch(projectId, branch);
|
|
234766
234833
|
if (!target) {
|
|
234767
234834
|
return {
|
|
@@ -234794,14 +234861,14 @@ var ChatSessionManager = class {
|
|
|
234794
234861
|
tailLines: external_exports.number().min(1).max(100).default(20).describe("Number of recent output lines to include per executor")
|
|
234795
234862
|
}),
|
|
234796
234863
|
execute: async ({ tailLines }) => {
|
|
234797
|
-
const workspace = await
|
|
234864
|
+
const workspace = await storage2.workspaceRegistry.getWorkspaceByProjectBranch(projectId, branch ?? "");
|
|
234798
234865
|
if (!workspace) {
|
|
234799
234866
|
return { executors: [], message: "No workspace found for this branch." };
|
|
234800
234867
|
}
|
|
234801
|
-
const executors = await
|
|
234868
|
+
const executors = await storage2.executors.getByWorkspaceId(workspace.id);
|
|
234802
234869
|
const now3 = Date.now();
|
|
234803
234870
|
const results = await Promise.all(executors.map(async (executor) => {
|
|
234804
|
-
const lastRow = await
|
|
234871
|
+
const lastRow = await storage2.executorProcesses.getLastByExecutorId(executor.id);
|
|
234805
234872
|
const liveProcesses = processManager.getProcessesByExecutorId(executor.id);
|
|
234806
234873
|
const latestLive = liveProcesses[liveProcesses.length - 1];
|
|
234807
234874
|
if (!lastRow) {
|
|
@@ -234840,11 +234907,11 @@ var ChatSessionManager = class {
|
|
|
234840
234907
|
remote: external_exports.string().optional().describe("Remote server name or ID to run the executor on. If omitted, uses project executor_mode or runs locally.")
|
|
234841
234908
|
}),
|
|
234842
234909
|
execute: async ({ executorName, remote }) => {
|
|
234843
|
-
const workspace = await
|
|
234910
|
+
const workspace = await storage2.workspaceRegistry.getWorkspaceByProjectBranch(projectId, branch ?? "");
|
|
234844
234911
|
if (!workspace) {
|
|
234845
234912
|
return { success: false, message: "No workspace found for this branch." };
|
|
234846
234913
|
}
|
|
234847
|
-
const executors = await
|
|
234914
|
+
const executors = await storage2.executors.getByWorkspaceId(workspace.id);
|
|
234848
234915
|
const executor = executors.find(
|
|
234849
234916
|
(e) => e.name.toLowerCase() === executorName.toLowerCase()
|
|
234850
234917
|
);
|
|
@@ -234857,26 +234924,26 @@ var ChatSessionManager = class {
|
|
|
234857
234924
|
}
|
|
234858
234925
|
let remoteServerId = remote;
|
|
234859
234926
|
if (remote) {
|
|
234860
|
-
const byId = await
|
|
234927
|
+
const byId = await storage2.remoteServers.getById(remote);
|
|
234861
234928
|
if (!byId) {
|
|
234862
|
-
const allServers = await
|
|
234929
|
+
const allServers = await storage2.remoteServers.getAll();
|
|
234863
234930
|
const byName = allServers.find((s3) => s3.name.toLowerCase() === remote.toLowerCase());
|
|
234864
234931
|
if (byName) {
|
|
234865
234932
|
remoteServerId = byName.id;
|
|
234866
234933
|
}
|
|
234867
234934
|
}
|
|
234868
234935
|
}
|
|
234869
|
-
const project = await
|
|
234936
|
+
const project = await storage2.projects.getById(projectId);
|
|
234870
234937
|
let executorMode = remoteServerId || project?.executor_mode;
|
|
234871
234938
|
let resolvedRemote = executorMode && executorMode !== "local" ? executorMode : void 0;
|
|
234872
234939
|
if (!resolvedRemote && !project?.path) {
|
|
234873
|
-
const remotes = await
|
|
234940
|
+
const remotes = await storage2.projectRemotes.getByProject(projectId);
|
|
234874
234941
|
if (remotes.length > 0) {
|
|
234875
234942
|
resolvedRemote = remotes[0].remote_server_id;
|
|
234876
234943
|
}
|
|
234877
234944
|
}
|
|
234878
234945
|
if (resolvedRemote) {
|
|
234879
|
-
const remoteConfig = await
|
|
234946
|
+
const remoteConfig = await storage2.projectRemotes.getByProjectAndServer(projectId, resolvedRemote);
|
|
234880
234947
|
if (!remoteConfig) {
|
|
234881
234948
|
return { success: false, message: `Remote server "${resolvedRemote}" not configured for this project.` };
|
|
234882
234949
|
}
|
|
@@ -234980,11 +235047,11 @@ var ChatSessionManager = class {
|
|
|
234980
235047
|
remote: external_exports.string().optional().describe("Remote server name or ID where the executor is running. If omitted, auto-detects.")
|
|
234981
235048
|
}),
|
|
234982
235049
|
execute: async ({ executorName, remote }) => {
|
|
234983
|
-
const workspace = await
|
|
235050
|
+
const workspace = await storage2.workspaceRegistry.getWorkspaceByProjectBranch(projectId, branch ?? "");
|
|
234984
235051
|
if (!workspace) {
|
|
234985
235052
|
return { success: false, message: "No workspace found for this branch." };
|
|
234986
235053
|
}
|
|
234987
|
-
const executors = await
|
|
235054
|
+
const executors = await storage2.executors.getByWorkspaceId(workspace.id);
|
|
234988
235055
|
const executor = executors.find(
|
|
234989
235056
|
(e) => e.name.toLowerCase() === executorName.toLowerCase()
|
|
234990
235057
|
);
|
|
@@ -234997,9 +235064,9 @@ var ChatSessionManager = class {
|
|
|
234997
235064
|
}
|
|
234998
235065
|
let remoteServerId = remote;
|
|
234999
235066
|
if (remote) {
|
|
235000
|
-
const byId = await
|
|
235067
|
+
const byId = await storage2.remoteServers.getById(remote);
|
|
235001
235068
|
if (!byId) {
|
|
235002
|
-
const allServers = await
|
|
235069
|
+
const allServers = await storage2.remoteServers.getAll();
|
|
235003
235070
|
const byName = allServers.find((s3) => s3.name.toLowerCase() === remote.toLowerCase());
|
|
235004
235071
|
if (byName) {
|
|
235005
235072
|
remoteServerId = byName.id;
|
|
@@ -235018,7 +235085,7 @@ var ChatSessionManager = class {
|
|
|
235018
235085
|
resolvedRemote = runningRemotes[0];
|
|
235019
235086
|
} else if (runningRemotes.length > 1) {
|
|
235020
235087
|
const remoteNames = await Promise.all(runningRemotes.map(async (id) => {
|
|
235021
|
-
const server = await
|
|
235088
|
+
const server = await storage2.remoteServers.getById(id);
|
|
235022
235089
|
return server?.name ?? id;
|
|
235023
235090
|
}));
|
|
235024
235091
|
return {
|
|
@@ -235801,14 +235868,14 @@ import { createHash as createHash2, randomUUID as randomUUID5 } from "crypto";
|
|
|
235801
235868
|
|
|
235802
235869
|
// src/project-chat-context.ts
|
|
235803
235870
|
var PROJECT_CHAT_CONTEXT_REF_LIMIT = 100;
|
|
235804
|
-
async function listProjectChatPublicContextRefs(
|
|
235805
|
-
const refs = await
|
|
235871
|
+
async function listProjectChatPublicContextRefs(storage2, thread) {
|
|
235872
|
+
const refs = await storage2.projectChatContextRefs.listByThread(
|
|
235806
235873
|
thread.id,
|
|
235807
235874
|
thread.project_id,
|
|
235808
235875
|
thread.user_id,
|
|
235809
235876
|
PROJECT_CHAT_CONTEXT_REF_LIMIT
|
|
235810
235877
|
);
|
|
235811
|
-
const existing = new Map((await
|
|
235878
|
+
const existing = new Map((await storage2.projectChatContextRefs.resolveExisting(
|
|
235812
235879
|
thread.project_id,
|
|
235813
235880
|
refs.map(({ entity_type, entity_id }) => ({ entity_type, entity_id }))
|
|
235814
235881
|
)).map((resolved) => [`${resolved.entity_type}\0${resolved.entity_id}`, resolved.navigation]));
|
|
@@ -236178,19 +236245,19 @@ async function createProjectChatTools(options) {
|
|
|
236178
236245
|
projectId,
|
|
236179
236246
|
threadId,
|
|
236180
236247
|
userId,
|
|
236181
|
-
storage,
|
|
236248
|
+
storage: storage2,
|
|
236182
236249
|
agentSessionManager,
|
|
236183
236250
|
remoteSessions,
|
|
236184
236251
|
mutationServices,
|
|
236185
236252
|
onOperationMessage
|
|
236186
236253
|
} = options;
|
|
236187
|
-
const project = await
|
|
236254
|
+
const project = await storage2.projects.getById(projectId, userId);
|
|
236188
236255
|
if (!project) throw new Error("Project not found");
|
|
236189
|
-
const thread = await
|
|
236256
|
+
const thread = await storage2.projectChatThreads.getById(threadId, projectId, userId);
|
|
236190
236257
|
if (!thread) throw new Error("Project Chat thread not found");
|
|
236191
236258
|
const touchAll = async (entityType, ids) => {
|
|
236192
236259
|
if (ids.length === 0) return;
|
|
236193
|
-
const tracked = await
|
|
236260
|
+
const tracked = await storage2.projectChatContextRefs.touchMany(
|
|
236194
236261
|
threadId,
|
|
236195
236262
|
projectId,
|
|
236196
236263
|
userId,
|
|
@@ -236205,8 +236272,8 @@ async function createProjectChatTools(options) {
|
|
|
236205
236272
|
};
|
|
236206
236273
|
const revalidateScope = async () => {
|
|
236207
236274
|
const [ownedProject, ownedThread] = await Promise.all([
|
|
236208
|
-
|
|
236209
|
-
|
|
236275
|
+
storage2.projects.getById(projectId, userId),
|
|
236276
|
+
storage2.projectChatThreads.getById(threadId, projectId, userId)
|
|
236210
236277
|
]);
|
|
236211
236278
|
if (!ownedProject || !ownedThread) throw new Error("Project Chat scope is no longer authorized");
|
|
236212
236279
|
};
|
|
@@ -236221,7 +236288,7 @@ async function createProjectChatTools(options) {
|
|
|
236221
236288
|
const beginOperation = async (kind, entityType, entityId, details, ids = {}) => {
|
|
236222
236289
|
const operationId = ids.operationId ?? randomUUID4();
|
|
236223
236290
|
const idempotencyKey = ids.idempotencyKey ?? operationId;
|
|
236224
|
-
const row = await
|
|
236291
|
+
const row = await storage2.projectChatOperations.create({
|
|
236225
236292
|
id: operationId,
|
|
236226
236293
|
thread_id: threadId,
|
|
236227
236294
|
project_id: projectId,
|
|
@@ -236238,7 +236305,7 @@ async function createProjectChatTools(options) {
|
|
|
236238
236305
|
return row;
|
|
236239
236306
|
};
|
|
236240
236307
|
const finishOperation = async (operation, status, details, error48 = null) => {
|
|
236241
|
-
const current = await
|
|
236308
|
+
const current = await storage2.projectChatOperations.getById(
|
|
236242
236309
|
operation.id,
|
|
236243
236310
|
threadId,
|
|
236244
236311
|
projectId,
|
|
@@ -236248,7 +236315,7 @@ async function createProjectChatTools(options) {
|
|
|
236248
236315
|
const publicError = error48 === null ? null : sanitizeProjectChatPublicError(error48, "Operation failed");
|
|
236249
236316
|
const payload = { ...current.payload, status, ...details };
|
|
236250
236317
|
const content = projectChatPublicOperationContent(payload, publicError);
|
|
236251
|
-
const result = await
|
|
236318
|
+
const result = await storage2.projectChatOperations.transition({
|
|
236252
236319
|
id: operation.id,
|
|
236253
236320
|
thread_id: threadId,
|
|
236254
236321
|
project_id: projectId,
|
|
@@ -236268,7 +236335,7 @@ async function createProjectChatTools(options) {
|
|
|
236268
236335
|
return result.operation;
|
|
236269
236336
|
};
|
|
236270
236337
|
const markOperationRunning = async (operation, details) => {
|
|
236271
|
-
const current = await
|
|
236338
|
+
const current = await storage2.projectChatOperations.getById(
|
|
236272
236339
|
operation.id,
|
|
236273
236340
|
threadId,
|
|
236274
236341
|
projectId,
|
|
@@ -236281,9 +236348,9 @@ async function createProjectChatTools(options) {
|
|
|
236281
236348
|
return finishOperation(current, "running", details);
|
|
236282
236349
|
};
|
|
236283
236350
|
const workspaceCandidates = async () => {
|
|
236284
|
-
const project2 = await
|
|
236351
|
+
const project2 = await storage2.projects.getById(projectId, userId);
|
|
236285
236352
|
if (!project2) throw new Error("Project is no longer authorized");
|
|
236286
|
-
const rows = await
|
|
236353
|
+
const rows = await storage2.searchCache.listWorkspacesByProject(projectId, LIST_LIMIT + 1);
|
|
236287
236354
|
const candidates = rows.flatMap((row) => {
|
|
236288
236355
|
if (typeof row.targetId !== "string" || !isNullableString(row.branch)) return [];
|
|
236289
236356
|
if (row.targetId.length > TARGET_CHAR_LIMIT || (row.branch?.length ?? 0) > BRANCH_CHAR_LIMIT) return [];
|
|
@@ -236291,7 +236358,7 @@ async function createProjectChatTools(options) {
|
|
|
236291
236358
|
if (!isToolSelectorId(id)) return [];
|
|
236292
236359
|
return [{ id, target: row.targetId, branch: row.branch }];
|
|
236293
236360
|
});
|
|
236294
|
-
const authorized = await Promise.all(candidates.map(async (candidate) => candidate.target === "local" ? candidate : await
|
|
236361
|
+
const authorized = await Promise.all(candidates.map(async (candidate) => candidate.target === "local" ? candidate : await storage2.projectRemotes.getByProjectAndServer(projectId, candidate.target) ? candidate : void 0));
|
|
236295
236362
|
const available = authorized.filter((candidate) => Boolean(candidate));
|
|
236296
236363
|
return { items: available.slice(0, LIST_LIMIT), truncated: available.length > LIST_LIMIT };
|
|
236297
236364
|
};
|
|
@@ -236305,24 +236372,24 @@ async function createProjectChatTools(options) {
|
|
|
236305
236372
|
const candidate = (await workspaceCandidates()).items.find(({ id }) => id === workspaceId);
|
|
236306
236373
|
if (!candidate) throw new Error("Workspace is no longer available in this project");
|
|
236307
236374
|
if (candidate.target !== "local") {
|
|
236308
|
-
const association = await
|
|
236375
|
+
const association = await storage2.projectRemotes.getByProjectAndServer(projectId, candidate.target);
|
|
236309
236376
|
if (!association) throw new Error("Workspace is no longer available in this project");
|
|
236310
236377
|
}
|
|
236311
236378
|
return candidate;
|
|
236312
236379
|
};
|
|
236313
236380
|
const sessionExistsInScope = async (sessionId) => {
|
|
236314
|
-
const local = await
|
|
236315
|
-
if (local) return (await
|
|
236381
|
+
const local = await storage2.agentSessions.getById(sessionId);
|
|
236382
|
+
if (local) return (await storage2.agentSessions.getActivityById(sessionId, "project-chat"))?.projectId === projectId;
|
|
236316
236383
|
const mapping = await remoteSessions?.getMapping(sessionId);
|
|
236317
236384
|
if (!mapping || mapping.projectId !== projectId) return false;
|
|
236318
|
-
return Boolean(await
|
|
236385
|
+
return Boolean(await storage2.projectRemotes.getByProjectAndServer(
|
|
236319
236386
|
projectId,
|
|
236320
236387
|
mapping.remoteServerId
|
|
236321
236388
|
));
|
|
236322
236389
|
};
|
|
236323
236390
|
const rereadConfirmedSession = async (operation, sessionId) => {
|
|
236324
|
-
const local = await
|
|
236325
|
-
const localProjection = local ? await
|
|
236391
|
+
const local = await storage2.agentSessions.getById(sessionId);
|
|
236392
|
+
const localProjection = local ? await storage2.agentSessions.getActivityById(sessionId, "project-chat") : void 0;
|
|
236326
236393
|
if (local && localProjection?.projectId === projectId && local.status !== "running") {
|
|
236327
236394
|
const status = local.status === "stopped" && local.last_completed_at ? "completed" : "failed";
|
|
236328
236395
|
return finishOperation(operation, status, { sessionId }, status === "failed" ? "Agent session failed" : null);
|
|
@@ -236362,7 +236429,7 @@ async function createProjectChatTools(options) {
|
|
|
236362
236429
|
try {
|
|
236363
236430
|
await revalidateScope();
|
|
236364
236431
|
await validateAssignedBranch(assignedBranch);
|
|
236365
|
-
const task = await
|
|
236432
|
+
const task = await storage2.tasks.create({
|
|
236366
236433
|
id: taskId,
|
|
236367
236434
|
project_id: projectId,
|
|
236368
236435
|
title,
|
|
@@ -236376,7 +236443,7 @@ async function createProjectChatTools(options) {
|
|
|
236376
236443
|
return { ok: true, operationId: operation.id, taskId: task.id, status: "completed" };
|
|
236377
236444
|
} catch (error48) {
|
|
236378
236445
|
const message = boundedError(error48);
|
|
236379
|
-
const applied = await
|
|
236446
|
+
const applied = await storage2.tasks.getById(taskId);
|
|
236380
236447
|
if (applied?.project_id === projectId) {
|
|
236381
236448
|
return {
|
|
236382
236449
|
ok: false,
|
|
@@ -236398,7 +236465,7 @@ async function createProjectChatTools(options) {
|
|
|
236398
236465
|
execute: async ({ taskId, assignedBranch, ...patch }) => {
|
|
236399
236466
|
mutationService();
|
|
236400
236467
|
await revalidateScope();
|
|
236401
|
-
const target = await
|
|
236468
|
+
const target = await storage2.tasks.getById(taskId);
|
|
236402
236469
|
if (!target) throw new Error("Task not found");
|
|
236403
236470
|
if (target.project_id !== projectId) throw new Error("Object is not part of this project");
|
|
236404
236471
|
await validateAssignedBranch(assignedBranch);
|
|
@@ -236419,10 +236486,10 @@ async function createProjectChatTools(options) {
|
|
|
236419
236486
|
});
|
|
236420
236487
|
try {
|
|
236421
236488
|
await revalidateScope();
|
|
236422
|
-
const current = await
|
|
236489
|
+
const current = await storage2.tasks.getById(taskId);
|
|
236423
236490
|
if (!current || current.project_id !== projectId) throw new Error("Task is no longer authorized");
|
|
236424
236491
|
await validateAssignedBranch(assignedBranch);
|
|
236425
|
-
const updated = await
|
|
236492
|
+
const updated = await storage2.tasks.update(taskId, {
|
|
236426
236493
|
...patch,
|
|
236427
236494
|
...assignedBranch !== void 0 ? { assigned_branch: assignedBranch } : {}
|
|
236428
236495
|
});
|
|
@@ -236432,7 +236499,7 @@ async function createProjectChatTools(options) {
|
|
|
236432
236499
|
return { ok: true, operationId: operation.id, taskId, status: "completed" };
|
|
236433
236500
|
} catch (error48) {
|
|
236434
236501
|
const message = boundedError(error48);
|
|
236435
|
-
const applied = await
|
|
236502
|
+
const applied = await storage2.tasks.getById(taskId);
|
|
236436
236503
|
const current = applied && {
|
|
236437
236504
|
title: applied.title,
|
|
236438
236505
|
description: applied.description,
|
|
@@ -236483,7 +236550,7 @@ async function createProjectChatTools(options) {
|
|
|
236483
236550
|
"pending",
|
|
236484
236551
|
{ requestId: operation2.id, candidates: candidates.map(({ id, target, branch }) => ({ id, target, branch })) }
|
|
236485
236552
|
));
|
|
236486
|
-
const announced = await
|
|
236553
|
+
const announced = await storage2.projectChatOperations.announce({
|
|
236487
236554
|
id: operation2.id,
|
|
236488
236555
|
thread_id: threadId,
|
|
236489
236556
|
project_id: projectId,
|
|
@@ -236567,7 +236634,7 @@ async function createProjectChatTools(options) {
|
|
|
236567
236634
|
execute: async ({ requestId, workspaceId }) => {
|
|
236568
236635
|
const service = mutationService();
|
|
236569
236636
|
await revalidateScope();
|
|
236570
|
-
const operation = await
|
|
236637
|
+
const operation = await storage2.projectChatOperations.getById(
|
|
236571
236638
|
requestId,
|
|
236572
236639
|
threadId,
|
|
236573
236640
|
projectId,
|
|
@@ -236596,7 +236663,7 @@ async function createProjectChatTools(options) {
|
|
|
236596
236663
|
let current = operation;
|
|
236597
236664
|
for (let attempt = 0; attempt < 100 && current.status === "resolving"; attempt++) {
|
|
236598
236665
|
await new Promise((resolve3) => setTimeout(resolve3, 5));
|
|
236599
|
-
current = await
|
|
236666
|
+
current = await storage2.projectChatOperations.getById(
|
|
236600
236667
|
requestId,
|
|
236601
236668
|
threadId,
|
|
236602
236669
|
projectId,
|
|
@@ -236646,7 +236713,7 @@ async function createProjectChatTools(options) {
|
|
|
236646
236713
|
branch: workspace.branch,
|
|
236647
236714
|
initialInstructionDelivery: "pending"
|
|
236648
236715
|
};
|
|
236649
|
-
const claim = await
|
|
236716
|
+
const claim = await storage2.projectChatOperations.claimWorkspaceSelection({
|
|
236650
236717
|
id: operation.id,
|
|
236651
236718
|
thread_id: threadId,
|
|
236652
236719
|
project_id: projectId,
|
|
@@ -236674,7 +236741,7 @@ async function createProjectChatTools(options) {
|
|
|
236674
236741
|
}
|
|
236675
236742
|
for (let attempt = 0; attempt < 100 && correlated.status === "resolving"; attempt++) {
|
|
236676
236743
|
await new Promise((resolve3) => setTimeout(resolve3, 5));
|
|
236677
|
-
correlated = await
|
|
236744
|
+
correlated = await storage2.projectChatOperations.getById(
|
|
236678
236745
|
requestId,
|
|
236679
236746
|
threadId,
|
|
236680
236747
|
projectId,
|
|
@@ -236750,10 +236817,10 @@ async function createProjectChatTools(options) {
|
|
|
236750
236817
|
execute: async ({ sessionId, instruction }) => {
|
|
236751
236818
|
const service = mutationService();
|
|
236752
236819
|
await revalidateScope();
|
|
236753
|
-
const local = await
|
|
236820
|
+
const local = await storage2.agentSessions.getById(sessionId);
|
|
236754
236821
|
let target;
|
|
236755
236822
|
if (local) {
|
|
236756
|
-
const localProjectId = local.workspace_checkout_id ? (await
|
|
236823
|
+
const localProjectId = local.workspace_checkout_id ? (await storage2.agentSessions.getActivityById(sessionId, "project-chat"))?.projectId : local.project_id;
|
|
236757
236824
|
if (localProjectId !== projectId) {
|
|
236758
236825
|
throw new Error("Object is not part of this project");
|
|
236759
236826
|
}
|
|
@@ -236762,7 +236829,7 @@ async function createProjectChatTools(options) {
|
|
|
236762
236829
|
const mapping = await remoteSessions?.getMapping(sessionId);
|
|
236763
236830
|
if (!mapping) throw new Error("Agent session not found");
|
|
236764
236831
|
if (mapping.projectId !== projectId) throw new Error("Object is not part of this project");
|
|
236765
|
-
const association = await
|
|
236832
|
+
const association = await storage2.projectRemotes.getByProjectAndServer(projectId, mapping.remoteServerId);
|
|
236766
236833
|
if (!association) throw new Error("Agent session not found");
|
|
236767
236834
|
target = { remoteServerId: mapping.remoteServerId, remoteSessionId: mapping.remoteSessionId };
|
|
236768
236835
|
}
|
|
@@ -236776,8 +236843,8 @@ async function createProjectChatTools(options) {
|
|
|
236776
236843
|
try {
|
|
236777
236844
|
await revalidateScope();
|
|
236778
236845
|
if (target === "local") {
|
|
236779
|
-
const current = await
|
|
236780
|
-
const currentProjection = current && current.workspace_checkout_id ? await
|
|
236846
|
+
const current = await storage2.agentSessions.getById(sessionId);
|
|
236847
|
+
const currentProjection = current && current.workspace_checkout_id ? await storage2.agentSessions.getActivityById(sessionId, "project-chat") : void 0;
|
|
236781
236848
|
const currentProjectId = current?.workspace_checkout_id ? currentProjection?.projectId : current?.project_id;
|
|
236782
236849
|
if (!current || currentProjectId !== projectId) {
|
|
236783
236850
|
throw new Error("Agent session is no longer authorized");
|
|
@@ -236787,7 +236854,7 @@ async function createProjectChatTools(options) {
|
|
|
236787
236854
|
if (!current || current.projectId !== projectId || current.remoteServerId !== target.remoteServerId || current.remoteSessionId !== target.remoteSessionId) {
|
|
236788
236855
|
throw new Error("Agent session is no longer authorized");
|
|
236789
236856
|
}
|
|
236790
|
-
const association = await
|
|
236857
|
+
const association = await storage2.projectRemotes.getByProjectAndServer(
|
|
236791
236858
|
projectId,
|
|
236792
236859
|
current.remoteServerId
|
|
236793
236860
|
);
|
|
@@ -236823,7 +236890,7 @@ async function createProjectChatTools(options) {
|
|
|
236823
236890
|
execute: async ({ scheduleId }) => {
|
|
236824
236891
|
const service = mutationService();
|
|
236825
236892
|
await revalidateScope();
|
|
236826
|
-
const schedule = await
|
|
236893
|
+
const schedule = await storage2.scheduledTasks.getById(scheduleId);
|
|
236827
236894
|
if (!schedule) throw new Error("Schedule not found");
|
|
236828
236895
|
if (schedule.project_id !== projectId) throw new Error("Object is not part of this project");
|
|
236829
236896
|
const runId = randomUUID4();
|
|
@@ -236834,12 +236901,12 @@ async function createProjectChatTools(options) {
|
|
|
236834
236901
|
});
|
|
236835
236902
|
try {
|
|
236836
236903
|
await revalidateScope();
|
|
236837
|
-
const current = await
|
|
236904
|
+
const current = await storage2.scheduledTasks.getById(scheduleId);
|
|
236838
236905
|
if (!current || current.project_id !== projectId) throw new Error("Schedule is no longer authorized");
|
|
236839
236906
|
const result = await service.runScheduleNow(scheduleId, runId);
|
|
236840
236907
|
const [persisted, authorizedSchedule] = await Promise.all([
|
|
236841
|
-
|
|
236842
|
-
|
|
236908
|
+
storage2.scheduledTaskRuns.getById(runId),
|
|
236909
|
+
storage2.scheduledTasks.getById(scheduleId)
|
|
236843
236910
|
]);
|
|
236844
236911
|
if (!authorizedSchedule || authorizedSchedule.project_id !== projectId) {
|
|
236845
236912
|
throw new Error("Schedule is no longer authorized");
|
|
@@ -236851,7 +236918,7 @@ async function createProjectChatTools(options) {
|
|
|
236851
236918
|
throw new Error("error" in result ? result.error : "Schedule run identity mismatch");
|
|
236852
236919
|
}
|
|
236853
236920
|
const skipped = "error" in result ? persisted.status === "skipped" : result.skipped;
|
|
236854
|
-
const tracked = await
|
|
236921
|
+
const tracked = await storage2.projectChatContextRefs.touchMany(
|
|
236855
236922
|
threadId,
|
|
236856
236923
|
projectId,
|
|
236857
236924
|
userId,
|
|
@@ -236870,7 +236937,7 @@ async function createProjectChatTools(options) {
|
|
|
236870
236937
|
);
|
|
236871
236938
|
let final = transitioned;
|
|
236872
236939
|
if (status === "running") {
|
|
236873
|
-
const latest = await
|
|
236940
|
+
const latest = await storage2.scheduledTaskRuns.getById(runId);
|
|
236874
236941
|
if (latest?.project_id === projectId && latest.schedule_id === scheduleId && latest.status !== "starting" && latest.status !== "running") {
|
|
236875
236942
|
const latestStatus = latest.status === "completed" || latest.status === "skipped" ? "completed" : "failed";
|
|
236876
236943
|
final = await finishOperation(
|
|
@@ -236883,7 +236950,7 @@ async function createProjectChatTools(options) {
|
|
|
236883
236950
|
}
|
|
236884
236951
|
return { ok: final.status !== "failed", operationId: operation.id, scheduleId, runId, status: final.status, skipped };
|
|
236885
236952
|
} catch (error48) {
|
|
236886
|
-
const persisted = await
|
|
236953
|
+
const persisted = await storage2.scheduledTaskRuns.getById(runId);
|
|
236887
236954
|
if (persisted?.project_id === projectId && persisted.schedule_id === scheduleId) {
|
|
236888
236955
|
return {
|
|
236889
236956
|
ok: false,
|
|
@@ -236916,7 +236983,7 @@ async function createProjectChatTools(options) {
|
|
|
236916
236983
|
status: external_exports.enum(["todo", "in_progress", "done", "cancelled"]).optional()
|
|
236917
236984
|
}).strict(),
|
|
236918
236985
|
execute: readInScope(async ({ query, status }) => {
|
|
236919
|
-
const rows = await
|
|
236986
|
+
const rows = await storage2.tasks.queryByProject(projectId, { query, status, limit: LIST_LIMIT });
|
|
236920
236987
|
const validRows = rows.filter((row) => isToolSelectorId(row.id));
|
|
236921
236988
|
await touchAll("task", validRows.map((row) => row.id));
|
|
236922
236989
|
return {
|
|
@@ -236936,7 +237003,7 @@ async function createProjectChatTools(options) {
|
|
|
236936
237003
|
description: "Inspect one task by id, only if it belongs to this project.",
|
|
236937
237004
|
inputSchema: external_exports.object({ taskId: external_exports.string().min(1).max(MAX_TOOL_SELECTOR_ID) }).strict(),
|
|
236938
237005
|
execute: readInScope(async ({ taskId }) => {
|
|
236939
|
-
const row = await
|
|
237006
|
+
const row = await storage2.tasks.getById(taskId);
|
|
236940
237007
|
if (!row) throw new Error("Task not found");
|
|
236941
237008
|
if (row.project_id !== projectId) throw new Error("Object is not part of this project");
|
|
236942
237009
|
if (!isToolSelectorId(row.id)) throw new Error("Task not found");
|
|
@@ -236977,7 +237044,7 @@ async function createProjectChatTools(options) {
|
|
|
236977
237044
|
inputSchema: emptySchema,
|
|
236978
237045
|
execute: readInScope(async () => {
|
|
236979
237046
|
const [localRows, untrustedRemoteRows] = await Promise.all([
|
|
236980
|
-
|
|
237047
|
+
storage2.agentSessions.listRecentActivityByProject(projectId, LIST_LIMIT / 2, "project-chat"),
|
|
236981
237048
|
remoteSessions?.listByProject(projectId, LIST_LIMIT / 2) ?? Promise.resolve([])
|
|
236982
237049
|
]);
|
|
236983
237050
|
const remoteRows = safeArrayPrefix(untrustedRemoteRows, LIST_LIMIT / 2);
|
|
@@ -237043,9 +237110,9 @@ async function createProjectChatTools(options) {
|
|
|
237043
237110
|
description: "Return status and a server-bounded recent transcript for one project agent session.",
|
|
237044
237111
|
inputSchema: external_exports.object({ sessionId: external_exports.string().min(1).max(MAX_TOOL_SELECTOR_ID) }).strict(),
|
|
237045
237112
|
execute: readInScope(async ({ sessionId }) => {
|
|
237046
|
-
const local = await
|
|
237113
|
+
const local = await storage2.agentSessions.getById(sessionId);
|
|
237047
237114
|
if (local) {
|
|
237048
|
-
const projection = await
|
|
237115
|
+
const projection = await storage2.agentSessions.getActivityById(sessionId, "project-chat");
|
|
237049
237116
|
if (projection?.projectId !== projectId) throw new Error("Object is not part of this project");
|
|
237050
237117
|
if (!isToolSelectorId(local.id)) throw new Error("Agent session not found");
|
|
237051
237118
|
const detail2 = {
|
|
@@ -237118,7 +237185,7 @@ async function createProjectChatTools(options) {
|
|
|
237118
237185
|
description: "List schedules configured for this project without commands, prompts, or raw configuration.",
|
|
237119
237186
|
inputSchema: emptySchema,
|
|
237120
237187
|
execute: readInScope(async () => {
|
|
237121
|
-
const rows = await
|
|
237188
|
+
const rows = await storage2.scheduledTasks.listByProject(projectId, LIST_LIMIT);
|
|
237122
237189
|
const validRows = rows.filter((row) => isToolSelectorId(row.id));
|
|
237123
237190
|
await touchAll("schedule", validRows.map((row) => row.id));
|
|
237124
237191
|
return {
|
|
@@ -237140,7 +237207,7 @@ async function createProjectChatTools(options) {
|
|
|
237140
237207
|
description: "List recent runs across this project's schedules without raw output or reports.",
|
|
237141
237208
|
inputSchema: emptySchema,
|
|
237142
237209
|
execute: readInScope(async () => {
|
|
237143
|
-
const rows = await
|
|
237210
|
+
const rows = await storage2.scheduledTaskRuns.listRecentByProject(projectId, LIST_LIMIT);
|
|
237144
237211
|
const validRows = rows.filter((row) => isToolSelectorId(row.id));
|
|
237145
237212
|
await touchAll("schedule_run", validRows.map((row) => row.id));
|
|
237146
237213
|
return {
|
|
@@ -237160,9 +237227,9 @@ async function createProjectChatTools(options) {
|
|
|
237160
237227
|
description: "Inspect one project schedule run with server-bounded output and report previews.",
|
|
237161
237228
|
inputSchema: external_exports.object({ runId: external_exports.string().min(1).max(MAX_TOOL_SELECTOR_ID) }).strict(),
|
|
237162
237229
|
execute: readInScope(async ({ runId }) => {
|
|
237163
|
-
const run2 = await
|
|
237230
|
+
const run2 = await storage2.scheduledTaskRuns.getById(runId);
|
|
237164
237231
|
if (!run2) throw new Error("Schedule run not found");
|
|
237165
|
-
const schedule = await
|
|
237232
|
+
const schedule = await storage2.scheduledTasks.getById(run2.schedule_id);
|
|
237166
237233
|
if (!schedule) throw new Error("Schedule run not found");
|
|
237167
237234
|
if (schedule.project_id !== projectId) throw new Error("Object is not part of this project");
|
|
237168
237235
|
if (!isToolSelectorId(run2.id)) throw new Error("Schedule run not found");
|
|
@@ -237326,8 +237393,8 @@ async function* adaptProjectChatFullStream(fullStream, signal) {
|
|
|
237326
237393
|
if (pending) yield pending;
|
|
237327
237394
|
}
|
|
237328
237395
|
var DefaultProjectChatModelRunner = class {
|
|
237329
|
-
constructor(
|
|
237330
|
-
this.storage =
|
|
237396
|
+
constructor(storage2) {
|
|
237397
|
+
this.storage = storage2;
|
|
237331
237398
|
}
|
|
237332
237399
|
storage;
|
|
237333
237400
|
async *run(input) {
|
|
@@ -237389,9 +237456,9 @@ function projectChatAiTools(domainTools) {
|
|
|
237389
237456
|
return adapted;
|
|
237390
237457
|
}
|
|
237391
237458
|
var ProjectChatManager = class {
|
|
237392
|
-
constructor(
|
|
237393
|
-
this.storage =
|
|
237394
|
-
this.runner = runner ?? new DefaultProjectChatModelRunner(
|
|
237459
|
+
constructor(storage2, runner, options = {}) {
|
|
237460
|
+
this.storage = storage2;
|
|
237461
|
+
this.runner = runner ?? new DefaultProjectChatModelRunner(storage2);
|
|
237395
237462
|
this.drainTimeoutMs = options.drainTimeoutMs ?? 2e3;
|
|
237396
237463
|
this.idleEvictionMs = options.idleEvictionMs ?? 3e4;
|
|
237397
237464
|
this.terminalRetryDelayMs = options.terminalRetryDelayMs ?? 100;
|
|
@@ -239230,8 +239297,8 @@ var FINAL_VERDICT_PROMPT = [
|
|
|
239230
239297
|
].join("\n");
|
|
239231
239298
|
var REVIEWER_AGENT_TYPES = /* @__PURE__ */ new Set(["claude-code", "codex"]);
|
|
239232
239299
|
var WorkflowEngine = class {
|
|
239233
|
-
constructor(
|
|
239234
|
-
this.storage =
|
|
239300
|
+
constructor(storage2, agentOps) {
|
|
239301
|
+
this.storage = storage2;
|
|
239235
239302
|
this.agentOps = agentOps;
|
|
239236
239303
|
}
|
|
239237
239304
|
storage;
|
|
@@ -240186,7 +240253,7 @@ var ReverseConnectManager = class {
|
|
|
240186
240253
|
const conn = this.connections.get(this.resolveId(remoteServerId));
|
|
240187
240254
|
return conn !== void 0 && conn.ws.readyState === 1;
|
|
240188
240255
|
}
|
|
240189
|
-
async sendHttpRequest(remoteServerId, method, path23, body, timeoutMs = DEFAULT_HTTP_TIMEOUT_MS) {
|
|
240256
|
+
async sendHttpRequest(remoteServerId, method, path23, body, timeoutMs = DEFAULT_HTTP_TIMEOUT_MS, extraHeaders) {
|
|
240190
240257
|
const conn = this.connections.get(this.resolveId(remoteServerId));
|
|
240191
240258
|
if (!conn || conn.ws.readyState !== 1) {
|
|
240192
240259
|
return {
|
|
@@ -240202,7 +240269,10 @@ var ReverseConnectManager = class {
|
|
|
240202
240269
|
requestId,
|
|
240203
240270
|
method,
|
|
240204
240271
|
path: path23,
|
|
240205
|
-
headers:
|
|
240272
|
+
headers: {
|
|
240273
|
+
...body !== void 0 ? { "content-type": "application/json" } : {},
|
|
240274
|
+
...extraHeaders
|
|
240275
|
+
},
|
|
240206
240276
|
body: body !== void 0 ? JSON.stringify(body) : void 0
|
|
240207
240277
|
};
|
|
240208
240278
|
return new Promise((resolve3) => {
|
|
@@ -240566,10 +240636,10 @@ var BrowserManager = class {
|
|
|
240566
240636
|
// src/remote-executor-monitor.ts
|
|
240567
240637
|
import { randomUUID as randomUUID8 } from "crypto";
|
|
240568
240638
|
var RemoteExecutorMonitor = class {
|
|
240569
|
-
constructor(reverseConnectManager, eventBus,
|
|
240639
|
+
constructor(reverseConnectManager, eventBus, storage2, remoteExecutorMap) {
|
|
240570
240640
|
this.reverseConnectManager = reverseConnectManager;
|
|
240571
240641
|
this.eventBus = eventBus;
|
|
240572
|
-
this.storage =
|
|
240642
|
+
this.storage = storage2;
|
|
240573
240643
|
this.remoteExecutorMap = remoteExecutorMap;
|
|
240574
240644
|
this.reverseConnectManager.setStatusChangeHandler((_remoteServerId, status) => {
|
|
240575
240645
|
if (status !== "online") return;
|
|
@@ -240718,8 +240788,8 @@ function validateCron(expr, timezone) {
|
|
|
240718
240788
|
}
|
|
240719
240789
|
}
|
|
240720
240790
|
var SchedulerService = class {
|
|
240721
|
-
constructor(
|
|
240722
|
-
this.storage =
|
|
240791
|
+
constructor(storage2, processManager, remote) {
|
|
240792
|
+
this.storage = storage2;
|
|
240723
240793
|
this.processManager = processManager;
|
|
240724
240794
|
this.remote = remote;
|
|
240725
240795
|
}
|
|
@@ -241247,8 +241317,8 @@ function notificationTitle(kind) {
|
|
|
241247
241317
|
return TITLE_BY_KIND[kind] ?? "Update";
|
|
241248
241318
|
}
|
|
241249
241319
|
var NotificationService = class {
|
|
241250
|
-
constructor(
|
|
241251
|
-
this.storage =
|
|
241320
|
+
constructor(storage2, eventBus) {
|
|
241321
|
+
this.storage = storage2;
|
|
241252
241322
|
this.eventBus = eventBus;
|
|
241253
241323
|
}
|
|
241254
241324
|
storage;
|
|
@@ -241403,18 +241473,18 @@ var emptyReasons = () => ({
|
|
|
241403
241473
|
dangling_checkout: 0,
|
|
241404
241474
|
snapshot_mismatch: 0
|
|
241405
241475
|
});
|
|
241406
|
-
async function registerReportedWorktrees(
|
|
241476
|
+
async function registerReportedWorktrees(storage2, opts) {
|
|
241407
241477
|
for (const worktree of opts.worktrees) {
|
|
241408
241478
|
const branch = worktree.branch ?? "";
|
|
241409
241479
|
const fallbackPath = branch ? conventionalWorktreePath(opts.remotePath, branch) : opts.remotePath;
|
|
241410
241480
|
const reportedPath = typeof worktree.worktreePath === "string" ? worktree.worktreePath : null;
|
|
241411
|
-
const existing = await
|
|
241481
|
+
const existing = await storage2.workspaceRegistry.getByProjectBranch(
|
|
241412
241482
|
opts.projectId,
|
|
241413
241483
|
branch,
|
|
241414
241484
|
opts.targetId
|
|
241415
241485
|
);
|
|
241416
241486
|
if (existing && (!reportedPath || existing.checkout.path_source === "reported" && existing.checkout.worktree_path === reportedPath)) continue;
|
|
241417
|
-
await
|
|
241487
|
+
await storage2.workspaceRegistry.registerReadyCheckout({
|
|
241418
241488
|
projectId: opts.projectId,
|
|
241419
241489
|
branch,
|
|
241420
241490
|
targetId: opts.targetId,
|
|
@@ -241424,20 +241494,20 @@ async function registerReportedWorktrees(storage, opts) {
|
|
|
241424
241494
|
});
|
|
241425
241495
|
}
|
|
241426
241496
|
}
|
|
241427
|
-
async function syncLocalWorkspaceRegistry(
|
|
241428
|
-
const projects = await
|
|
241497
|
+
async function syncLocalWorkspaceRegistry(storage2) {
|
|
241498
|
+
const projects = await storage2.workspaceBindingMigration.listUnboundLocalProjects();
|
|
241429
241499
|
for (const project of projects) {
|
|
241430
241500
|
try {
|
|
241431
|
-
await getRegisteredWorktreeBranches(
|
|
241501
|
+
await getRegisteredWorktreeBranches(storage2, project.id, project.path);
|
|
241432
241502
|
} catch (error48) {
|
|
241433
241503
|
console.warn(`[WorkspaceBinding] Local registry sync failed for ${project.id}:`, error48);
|
|
241434
241504
|
}
|
|
241435
241505
|
}
|
|
241436
241506
|
}
|
|
241437
|
-
async function syncRemoteWorkspaceRegistry(
|
|
241438
|
-
const projects = await
|
|
241507
|
+
async function syncRemoteWorkspaceRegistry(storage2, listWorktrees, opts = {}) {
|
|
241508
|
+
const projects = await storage2.projects.getAll();
|
|
241439
241509
|
for (const project of projects) {
|
|
241440
|
-
const remotes = await
|
|
241510
|
+
const remotes = await storage2.projectRemotes.getByProject(project.id);
|
|
241441
241511
|
for (const remote of remotes) {
|
|
241442
241512
|
if (opts.remoteServerId && remote.remote_server_id !== opts.remoteServerId) continue;
|
|
241443
241513
|
try {
|
|
@@ -241445,7 +241515,7 @@ async function syncRemoteWorkspaceRegistry(storage, listWorktrees, opts = {}) {
|
|
|
241445
241515
|
if (!result.ok) continue;
|
|
241446
241516
|
const worktrees = result.data?.worktrees;
|
|
241447
241517
|
if (!Array.isArray(worktrees)) continue;
|
|
241448
|
-
await registerReportedWorktrees(
|
|
241518
|
+
await registerReportedWorktrees(storage2, {
|
|
241449
241519
|
projectId: project.id,
|
|
241450
241520
|
targetId: remote.remote_server_id,
|
|
241451
241521
|
remotePath: remote.remote_path,
|
|
@@ -241460,7 +241530,7 @@ async function syncRemoteWorkspaceRegistry(storage, listWorktrees, opts = {}) {
|
|
|
241460
241530
|
}
|
|
241461
241531
|
}
|
|
241462
241532
|
}
|
|
241463
|
-
async function runWorkspaceBindingBackfill(
|
|
241533
|
+
async function runWorkspaceBindingBackfill(storage2, kind, opts = {}) {
|
|
241464
241534
|
const now3 = opts.now ?? Date.now;
|
|
241465
241535
|
const deadline = now3() + (opts.budgetMs ?? DEFAULT_BUDGET_MS);
|
|
241466
241536
|
const summary = {
|
|
@@ -241471,7 +241541,7 @@ async function runWorkspaceBindingBackfill(storage, kind, opts = {}) {
|
|
|
241471
241541
|
};
|
|
241472
241542
|
let cursor = "";
|
|
241473
241543
|
for (; ; ) {
|
|
241474
|
-
const batch = await
|
|
241544
|
+
const batch = await storage2.workspaceBindingMigration.backfill({
|
|
241475
241545
|
kind,
|
|
241476
241546
|
dryRun: false,
|
|
241477
241547
|
batchSize: opts.batchSize ?? DEFAULT_BATCH_SIZE,
|
|
@@ -241490,22 +241560,22 @@ async function runWorkspaceBindingBackfill(storage, kind, opts = {}) {
|
|
|
241490
241560
|
}
|
|
241491
241561
|
}
|
|
241492
241562
|
}
|
|
241493
|
-
async function healWorkspaceBindings(
|
|
241494
|
-
const probes = await Promise.all(["local", "remote"].map((kind) =>
|
|
241563
|
+
async function healWorkspaceBindings(storage2, deps = {}, opts = {}) {
|
|
241564
|
+
const probes = await Promise.all(["local", "remote"].map((kind) => storage2.workspaceBindingMigration.backfill({ kind, dryRun: true, batchSize: 1 })));
|
|
241495
241565
|
if (probes.every((probe) => probe.scanned === 0)) {
|
|
241496
241566
|
return {
|
|
241497
241567
|
local: { scanned: 0, updated: 0, reasons: emptyReasons(), incomplete: false },
|
|
241498
241568
|
remote: { scanned: 0, updated: 0, reasons: emptyReasons(), incomplete: false }
|
|
241499
241569
|
};
|
|
241500
241570
|
}
|
|
241501
|
-
if (!opts.remoteServerId) await syncLocalWorkspaceRegistry(
|
|
241571
|
+
if (!opts.remoteServerId) await syncLocalWorkspaceRegistry(storage2);
|
|
241502
241572
|
if (deps.listRemoteWorktrees) {
|
|
241503
|
-
await syncRemoteWorkspaceRegistry(
|
|
241573
|
+
await syncRemoteWorkspaceRegistry(storage2, deps.listRemoteWorktrees, {
|
|
241504
241574
|
remoteServerId: opts.remoteServerId
|
|
241505
241575
|
});
|
|
241506
241576
|
}
|
|
241507
|
-
const local = opts.remoteServerId ? { scanned: 0, updated: 0, reasons: emptyReasons(), incomplete: false } : await runWorkspaceBindingBackfill(
|
|
241508
|
-
const remote = await runWorkspaceBindingBackfill(
|
|
241577
|
+
const local = opts.remoteServerId ? { scanned: 0, updated: 0, reasons: emptyReasons(), incomplete: false } : await runWorkspaceBindingBackfill(storage2, "local", opts);
|
|
241578
|
+
const remote = await runWorkspaceBindingBackfill(storage2, "remote", opts);
|
|
241509
241579
|
return { local, remote };
|
|
241510
241580
|
}
|
|
241511
241581
|
function formatBackfillSummary(scope, result) {
|
|
@@ -241536,8 +241606,8 @@ function parseRetentionDays(raw) {
|
|
|
241536
241606
|
if (value < SESSION_RETENTION_DAYS_MIN || value > SESSION_RETENTION_DAYS_MAX) return null;
|
|
241537
241607
|
return value;
|
|
241538
241608
|
}
|
|
241539
|
-
async function readRetentionDays(
|
|
241540
|
-
return parseRetentionDays(await
|
|
241609
|
+
async function readRetentionDays(storage2) {
|
|
241610
|
+
return parseRetentionDays(await storage2.settings.get(SESSION_RETENTION_SETTING_KEY));
|
|
241541
241611
|
}
|
|
241542
241612
|
function retentionCutoff(days, now3) {
|
|
241543
241613
|
return now3 - days * MS_PER_DAY;
|
|
@@ -241713,12 +241783,12 @@ var DEFAULT_DEADLINE_MS = 5e3;
|
|
|
241713
241783
|
var PER_WORKER_CONCURRENCY = 3;
|
|
241714
241784
|
var LOCAL_CONCURRENCY = 4;
|
|
241715
241785
|
var REMOTE_ACTIVITY_TARGET_LIMIT = 100;
|
|
241716
|
-
async function listSearchTargets(
|
|
241717
|
-
const projects = await
|
|
241786
|
+
async function listSearchTargets(storage2, userId) {
|
|
241787
|
+
const projects = await storage2.projects.getAll(userId);
|
|
241718
241788
|
const targets = [];
|
|
241719
241789
|
for (const p2 of projects) {
|
|
241720
241790
|
if (p2.path) targets.push({ projectId: p2.id, targetId: "local", projectPath: p2.path });
|
|
241721
|
-
const remotes = await
|
|
241791
|
+
const remotes = await storage2.projectRemotes.getByProject(p2.id);
|
|
241722
241792
|
for (const r of remotes) {
|
|
241723
241793
|
targets.push({
|
|
241724
241794
|
projectId: p2.id,
|
|
@@ -242582,11 +242652,21 @@ function resolveLevel(flagLevel) {
|
|
|
242582
242652
|
console.warn(`Warning: invalid log level "${requested}" (valid: ${[...VALID_LEVELS].join(", ")}); using "info"`);
|
|
242583
242653
|
return "info";
|
|
242584
242654
|
}
|
|
242655
|
+
var traceLoggers = /* @__PURE__ */ new WeakMap();
|
|
242656
|
+
function withTraceContext(base) {
|
|
242657
|
+
const ctx = getTraceContext();
|
|
242658
|
+
if (!ctx) return base;
|
|
242659
|
+
const cached2 = traceLoggers.get(ctx);
|
|
242660
|
+
if (cached2 && cached2.base === base) return cached2.child;
|
|
242661
|
+
const child = base.child({ traceId: ctx.traceId, spanId: ctx.spanId });
|
|
242662
|
+
traceLoggers.set(ctx, { base, child });
|
|
242663
|
+
return child;
|
|
242664
|
+
}
|
|
242585
242665
|
function getLogger() {
|
|
242586
242666
|
if (!rootLogger) {
|
|
242587
242667
|
rootLogger = (0, import_pino.pino)({ level: resolveLevel(void 0) });
|
|
242588
242668
|
}
|
|
242589
|
-
return rootLogger;
|
|
242669
|
+
return withTraceContext(rootLogger);
|
|
242590
242670
|
}
|
|
242591
242671
|
function setupLogging(opts) {
|
|
242592
242672
|
const level = resolveLevel(opts.level);
|
|
@@ -242649,11 +242729,11 @@ function installConsoleBridge(logger) {
|
|
|
242649
242729
|
debug: console.debug
|
|
242650
242730
|
};
|
|
242651
242731
|
}
|
|
242652
|
-
console.log = (...args) => logger.info(format(...args));
|
|
242653
|
-
console.info = (...args) => logger.info(format(...args));
|
|
242654
|
-
console.warn = (...args) => logger.warn(format(...args));
|
|
242655
|
-
console.error = (...args) => logger.error(format(...args));
|
|
242656
|
-
console.debug = (...args) => logger.debug(format(...args));
|
|
242732
|
+
console.log = (...args) => withTraceContext(logger).info(format(...args));
|
|
242733
|
+
console.info = (...args) => withTraceContext(logger).info(format(...args));
|
|
242734
|
+
console.warn = (...args) => withTraceContext(logger).warn(format(...args));
|
|
242735
|
+
console.error = (...args) => withTraceContext(logger).error(format(...args));
|
|
242736
|
+
console.debug = (...args) => withTraceContext(logger).debug(format(...args));
|
|
242657
242737
|
}
|
|
242658
242738
|
function installCrashHandlers(logger) {
|
|
242659
242739
|
if (crashHandlersInstalled) return;
|
|
@@ -246798,12 +246878,12 @@ function writeBriefCache(key2, brief) {
|
|
|
246798
246878
|
briefCache.delete(oldest.value);
|
|
246799
246879
|
}
|
|
246800
246880
|
}
|
|
246801
|
-
async function generateIntentBrief(
|
|
246881
|
+
async function generateIntentBrief(storage2, userId, messages) {
|
|
246802
246882
|
let conversation;
|
|
246803
246883
|
let mainOk;
|
|
246804
246884
|
let fastOk;
|
|
246805
246885
|
try {
|
|
246806
|
-
const config2 = await getChatProviderConfig(
|
|
246886
|
+
const config2 = await getChatProviderConfig(storage2, userId);
|
|
246807
246887
|
mainOk = isModelConfigured(config2, config2.main);
|
|
246808
246888
|
fastOk = isModelConfigured(config2, config2.fast);
|
|
246809
246889
|
if (!mainOk && !fastOk) return null;
|
|
@@ -246818,17 +246898,17 @@ async function generateIntentBrief(storage, userId, messages) {
|
|
|
246818
246898
|
if (cached2 !== null) return cached2;
|
|
246819
246899
|
const pending = briefInFlight.get(key2);
|
|
246820
246900
|
if (pending) return pending;
|
|
246821
|
-
const run2 = distillConversation(
|
|
246901
|
+
const run2 = distillConversation(storage2, userId, messages, conversation, mainOk, fastOk).then((brief) => {
|
|
246822
246902
|
if (brief !== null) writeBriefCache(key2, brief);
|
|
246823
246903
|
return brief;
|
|
246824
246904
|
}).finally(() => briefInFlight.delete(key2));
|
|
246825
246905
|
briefInFlight.set(key2, run2);
|
|
246826
246906
|
return run2;
|
|
246827
246907
|
}
|
|
246828
|
-
async function distillConversation(
|
|
246908
|
+
async function distillConversation(storage2, userId, messages, conversation, mainOk, fastOk) {
|
|
246829
246909
|
try {
|
|
246830
|
-
const distillModel = mainOk ? await resolveChatModel(
|
|
246831
|
-
const compactModel = fastOk ? await resolveFastChatModel(
|
|
246910
|
+
const distillModel = mainOk ? await resolveChatModel(storage2, userId) : await resolveFastChatModel(storage2, userId);
|
|
246911
|
+
const compactModel = fastOk ? await resolveFastChatModel(storage2, userId) : distillModel;
|
|
246832
246912
|
if (conversation.length <= COMPACT_TRIGGER_CHARS) {
|
|
246833
246913
|
try {
|
|
246834
246914
|
const brief = await distill(distillModel, conversation, userId, true);
|
|
@@ -246906,11 +246986,11 @@ function buildHistoryWindow(entries, historyEpoch, opts = {}) {
|
|
|
246906
246986
|
}
|
|
246907
246987
|
|
|
246908
246988
|
// src/routes/agent-session-routes.ts
|
|
246909
|
-
async function resolveProjectPath(projectId,
|
|
246989
|
+
async function resolveProjectPath(projectId, storage2) {
|
|
246910
246990
|
if (projectId.startsWith("path:")) {
|
|
246911
246991
|
return projectId.slice(5);
|
|
246912
246992
|
}
|
|
246913
|
-
const project = await
|
|
246993
|
+
const project = await storage2.projects.getById(projectId);
|
|
246914
246994
|
return project?.path ?? null;
|
|
246915
246995
|
}
|
|
246916
246996
|
var MESSAGE_TEXT_CHAR_LIMIT = 64 * 1024;
|
|
@@ -249461,7 +249541,7 @@ var mergeActivity = (local, remote, limit) => {
|
|
|
249461
249541
|
for (const row of [...local, ...remote]) if (!byId.has(row.id)) byId.set(row.id, row);
|
|
249462
249542
|
return [...byId.values()].sort((left, right) => (right.lastActiveAt ?? 0) - (left.lastActiveAt ?? 0) || left.id.localeCompare(right.id)).slice(0, limit);
|
|
249463
249543
|
};
|
|
249464
|
-
async function getProjectActivity(
|
|
249544
|
+
async function getProjectActivity(storage2, projectId, userId) {
|
|
249465
249545
|
const [
|
|
249466
249546
|
recentThreads,
|
|
249467
249547
|
localRecentSessions,
|
|
@@ -249476,18 +249556,18 @@ async function getProjectActivity(storage, projectId, userId) {
|
|
|
249476
249556
|
remoteCounts,
|
|
249477
249557
|
nextScheduleAt
|
|
249478
249558
|
] = await Promise.all([
|
|
249479
|
-
|
|
249480
|
-
|
|
249481
|
-
|
|
249482
|
-
|
|
249483
|
-
|
|
249484
|
-
|
|
249485
|
-
|
|
249486
|
-
|
|
249487
|
-
|
|
249488
|
-
|
|
249489
|
-
|
|
249490
|
-
|
|
249559
|
+
storage2.projectChatThreads.listByProject(projectId, userId, RECENT_THREAD_LIMIT),
|
|
249560
|
+
storage2.agentSessions.listRecentActivityByProject(projectId, RECENT_SESSION_LIMIT, "project-activity"),
|
|
249561
|
+
storage2.searchCache.listRemoteSessionActivityByProject(projectId, RECENT_SESSION_LIMIT, "project-activity"),
|
|
249562
|
+
storage2.scheduledTaskRuns.getRecentByProject(projectId, RECENT_RUN_LIMIT),
|
|
249563
|
+
storage2.tasks.listPriorityByProject(projectId, PRIORITY_TASK_LIMIT),
|
|
249564
|
+
storage2.agentSessions.listAttentionActivityByProject(projectId, ATTENTION_LIMIT, "project-activity"),
|
|
249565
|
+
storage2.searchCache.listRemoteSessionAttentionByProject(projectId, ATTENTION_LIMIT, "project-activity"),
|
|
249566
|
+
storage2.scheduledTaskRuns.getAttentionByProject(projectId, ATTENTION_LIMIT),
|
|
249567
|
+
storage2.agentSessions.countRunningActivityByProject(projectId),
|
|
249568
|
+
storage2.scheduledTaskRuns.countByProjectStatuses(projectId, ["starting", "running"]),
|
|
249569
|
+
storage2.searchCache.countRemoteSessionActivityByProject(projectId),
|
|
249570
|
+
storage2.scheduledTasks.getEarliestNextRunAt(projectId)
|
|
249491
249571
|
]);
|
|
249492
249572
|
const recentAgentSessions = mergeActivity(
|
|
249493
249573
|
localRecentSessions,
|
|
@@ -251701,7 +251781,7 @@ var websocket_routes_default = (0, import_fastify_plugin24.default)(routes23, {
|
|
|
251701
251781
|
|
|
251702
251782
|
// src/routes/reverse-connect-routes.ts
|
|
251703
251783
|
var import_fastify_plugin25 = __toESM(require_plugin2(), 1);
|
|
251704
|
-
import { randomBytes as
|
|
251784
|
+
import { randomBytes as randomBytes4, createHash as createHash8, verify as cryptoVerify } from "crypto";
|
|
251705
251785
|
|
|
251706
251786
|
// src/utils/rate-limited-warn.ts
|
|
251707
251787
|
function createRateLimitedWarn(windowMs, maxKeys) {
|
|
@@ -251784,7 +251864,7 @@ var routes24 = async (fastify2) => {
|
|
|
251784
251864
|
const ws = socket;
|
|
251785
251865
|
const serverId = server.id;
|
|
251786
251866
|
const ownerId = await fastify2.storage.remoteServers.getOwnerId(serverId) ?? "";
|
|
251787
|
-
const nonce =
|
|
251867
|
+
const nonce = randomBytes4(32);
|
|
251788
251868
|
let settled = false;
|
|
251789
251869
|
let stashedVersion;
|
|
251790
251870
|
const recordWorkerVersion = async (reported) => {
|
|
@@ -254244,6 +254324,43 @@ var getAuth = ((req, options) => {
|
|
|
254244
254324
|
return getAuthObjectForAcceptedToken({ authObject: authReq.auth, acceptsToken: options?.acceptsToken });
|
|
254245
254325
|
});
|
|
254246
254326
|
|
|
254327
|
+
// src/trace-context-hooks.ts
|
|
254328
|
+
function registerTraceContext(server) {
|
|
254329
|
+
server.addHook("onRequest", (req, _reply, done) => {
|
|
254330
|
+
const ctx = newTraceContext(req.headers["traceparent"]);
|
|
254331
|
+
req.traceContext = ctx;
|
|
254332
|
+
req.traceStartMs = Date.now();
|
|
254333
|
+
runWithTraceContext(ctx, done);
|
|
254334
|
+
});
|
|
254335
|
+
server.addHook("onSend", (req, reply, payload, done) => {
|
|
254336
|
+
if (req.traceContext) {
|
|
254337
|
+
reply.header("traceparent", formatTraceparent(req.traceContext));
|
|
254338
|
+
}
|
|
254339
|
+
done(null, payload);
|
|
254340
|
+
});
|
|
254341
|
+
server.addHook("onResponse", (req, reply, done) => {
|
|
254342
|
+
const ctx = req.traceContext;
|
|
254343
|
+
if (ctx) {
|
|
254344
|
+
const status = reply.statusCode;
|
|
254345
|
+
const level = status >= 500 ? "error" : status >= 400 ? "warn" : "debug";
|
|
254346
|
+
getLogger()[level](
|
|
254347
|
+
{
|
|
254348
|
+
method: req.method,
|
|
254349
|
+
// The route *pattern* (/api/projects/:id), not the concrete URL:
|
|
254350
|
+
// low-cardinality and structurally incapable of carrying the query
|
|
254351
|
+
// string, where WebSocket/SSE auth material rides.
|
|
254352
|
+
route: req.routeOptions?.url,
|
|
254353
|
+
statusCode: status,
|
|
254354
|
+
ms: req.traceStartMs ? Date.now() - req.traceStartMs : void 0,
|
|
254355
|
+
continuedTrace: ctx.continued
|
|
254356
|
+
},
|
|
254357
|
+
"request completed"
|
|
254358
|
+
);
|
|
254359
|
+
}
|
|
254360
|
+
done();
|
|
254361
|
+
});
|
|
254362
|
+
}
|
|
254363
|
+
|
|
254247
254364
|
// src/server.ts
|
|
254248
254365
|
var API_KEY2 = process.env.VIBEDECKX_API_KEY || void 0;
|
|
254249
254366
|
function requireAuth(req, reply) {
|
|
@@ -254322,10 +254439,12 @@ var createServer = async (opts) => {
|
|
|
254322
254439
|
});
|
|
254323
254440
|
server.decorate("authEnabled", authEnabled);
|
|
254324
254441
|
server.decorate("noLocalProjects", noLocalProjects);
|
|
254442
|
+
registerTraceContext(server);
|
|
254325
254443
|
server.addHook("onRequest", (req, reply, done) => {
|
|
254326
254444
|
reply.header("access-control-allow-origin", "*");
|
|
254327
254445
|
reply.header("access-control-allow-methods", "GET, POST, PUT, DELETE, OPTIONS");
|
|
254328
|
-
reply.header("access-control-allow-headers", "Content-Type, Upgrade, Connection, X-Vibedeckx-Api-Key, X-Request-Id, Authorization");
|
|
254446
|
+
reply.header("access-control-allow-headers", "Content-Type, Upgrade, Connection, X-Vibedeckx-Api-Key, X-Request-Id, Authorization, traceparent");
|
|
254447
|
+
reply.header("access-control-expose-headers", "traceparent");
|
|
254329
254448
|
done();
|
|
254330
254449
|
});
|
|
254331
254450
|
server.addHook("onRequest", (req, reply, done) => {
|
|
@@ -254353,23 +254472,6 @@ var createServer = async (opts) => {
|
|
|
254353
254472
|
done();
|
|
254354
254473
|
});
|
|
254355
254474
|
}
|
|
254356
|
-
server.addHook("onRequest", (req, _reply, done) => {
|
|
254357
|
-
const requestId = req.headers["x-request-id"];
|
|
254358
|
-
if (requestId) {
|
|
254359
|
-
req.startTime = Date.now();
|
|
254360
|
-
console.log(`[remote] ${requestId} ${req.method} ${redactUrlForLog(req.url)}`);
|
|
254361
|
-
}
|
|
254362
|
-
done();
|
|
254363
|
-
});
|
|
254364
|
-
server.addHook("onResponse", (req, reply, done) => {
|
|
254365
|
-
const requestId = req.headers["x-request-id"];
|
|
254366
|
-
if (requestId) {
|
|
254367
|
-
const startTime = req.startTime;
|
|
254368
|
-
const ms = startTime ? Date.now() - startTime : 0;
|
|
254369
|
-
console.log(`[remote] ${requestId} ${req.method} ${redactUrlForLog(req.url)} -> ${reply.statusCode} (${ms}ms)`);
|
|
254370
|
-
}
|
|
254371
|
-
done();
|
|
254372
|
-
});
|
|
254373
254475
|
server.options("/*", async (req, reply) => {
|
|
254374
254476
|
return reply.code(204).send();
|
|
254375
254477
|
});
|
|
@@ -256570,8 +256672,8 @@ an authenticating proxy in front, or keep the default loopback bind (127.0.0.1).
|
|
|
256570
256672
|
console.log(`Starting vibedeckx${tls ? " (HTTPS)" : ""}...`);
|
|
256571
256673
|
const uiRoot = await resolveUiRoot({ uiDir: flags["ui-dir"], noUi: flags["no-ui"] });
|
|
256572
256674
|
const dbPath = path22.join(dataDir, "data.sqlite");
|
|
256573
|
-
const
|
|
256574
|
-
const server = await createServer({ storage, authEnabled, noLocalProjects, tls, uiRoot });
|
|
256675
|
+
const storage2 = await createSqliteStorage(dbPath);
|
|
256676
|
+
const server = await createServer({ storage: storage2, authEnabled, noLocalProjects, tls, uiRoot });
|
|
256575
256677
|
const url2 = await server.start(port, host);
|
|
256576
256678
|
console.log(`Server running at ${url2}`);
|
|
256577
256679
|
if (!tls && uiRoot) {
|
|
@@ -256592,7 +256694,7 @@ an authenticating proxy in front, or keep the default loopback bind (127.0.0.1).
|
|
|
256592
256694
|
forceExit.unref();
|
|
256593
256695
|
try {
|
|
256594
256696
|
await server.close();
|
|
256595
|
-
await
|
|
256697
|
+
await storage2.close();
|
|
256596
256698
|
} catch (err) {
|
|
256597
256699
|
console.error("Error during shutdown:", err);
|
|
256598
256700
|
}
|
|
@@ -256676,7 +256778,7 @@ var connectCommand = buildCommand({
|
|
|
256676
256778
|
return;
|
|
256677
256779
|
}
|
|
256678
256780
|
const requestedPort = flags.port ?? 0;
|
|
256679
|
-
let
|
|
256781
|
+
let storage2;
|
|
256680
256782
|
let server;
|
|
256681
256783
|
let client;
|
|
256682
256784
|
let ownedState;
|
|
@@ -256698,7 +256800,7 @@ var connectCommand = buildCommand({
|
|
|
256698
256800
|
errors.push(error48);
|
|
256699
256801
|
}
|
|
256700
256802
|
try {
|
|
256701
|
-
await
|
|
256803
|
+
await storage2?.close();
|
|
256702
256804
|
} catch (error48) {
|
|
256703
256805
|
errors.push(error48);
|
|
256704
256806
|
}
|
|
@@ -256729,11 +256831,11 @@ var connectCommand = buildCommand({
|
|
|
256729
256831
|
});
|
|
256730
256832
|
console.log("Starting vibedeckx in reverse-connect mode...");
|
|
256731
256833
|
const dbPath = path22.join(dataDir, "data.sqlite");
|
|
256732
|
-
|
|
256834
|
+
storage2 = await createSqliteStorage(dbPath);
|
|
256733
256835
|
const preflight = await preflightIdentityCheck({
|
|
256734
256836
|
connectTo: flags["connect-to"],
|
|
256735
256837
|
token,
|
|
256736
|
-
settings:
|
|
256838
|
+
settings: storage2.settings,
|
|
256737
256839
|
force: flags.force ?? false
|
|
256738
256840
|
});
|
|
256739
256841
|
if (preflight.checked && preflight.identity) {
|
|
@@ -256742,7 +256844,7 @@ var connectCommand = buildCommand({
|
|
|
256742
256844
|
);
|
|
256743
256845
|
}
|
|
256744
256846
|
server = await createServer({
|
|
256745
|
-
storage,
|
|
256847
|
+
storage: storage2,
|
|
256746
256848
|
acceptRemote: true,
|
|
256747
256849
|
uiRoot: null
|
|
256748
256850
|
});
|