@junctionpanel/server 0.1.77 → 0.1.79
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/server/server/agent/providers/gemini-agent.d.ts.map +1 -1
- package/dist/server/server/agent/providers/gemini-agent.js +272 -56
- package/dist/server/server/agent/providers/gemini-agent.js.map +1 -1
- package/dist/server/server/session.d.ts.map +1 -1
- package/dist/server/server/session.js +124 -68
- package/dist/server/server/session.js.map +1 -1
- package/dist/server/shared/messages.d.ts +48 -24
- package/dist/server/shared/messages.d.ts.map +1 -1
- package/dist/server/shared/messages.js +2 -1
- package/dist/server/shared/messages.js.map +1 -1
- package/package.json +2 -2
|
@@ -1672,11 +1672,14 @@ export class Session {
|
|
|
1672
1672
|
});
|
|
1673
1673
|
if (worktreeArchiveTarget) {
|
|
1674
1674
|
try {
|
|
1675
|
-
await this.archiveJunctionWorktree({
|
|
1675
|
+
const archiveResult = await this.archiveJunctionWorktree({
|
|
1676
1676
|
targetPath: worktreeArchiveTarget.targetPath,
|
|
1677
1677
|
repoRoot: worktreeArchiveTarget.repoRoot,
|
|
1678
1678
|
requestId,
|
|
1679
1679
|
});
|
|
1680
|
+
if (!archiveResult.success || archiveResult.error) {
|
|
1681
|
+
throw new Error(archiveResult.error?.message ?? 'Failed to auto-archive worktree');
|
|
1682
|
+
}
|
|
1680
1683
|
}
|
|
1681
1684
|
catch (error) {
|
|
1682
1685
|
this.sessionLogger.warn({ err: error, agentId, cwd: archivedRecord.cwd }, 'Failed to auto-archive worktree after agent archive');
|
|
@@ -5150,85 +5153,138 @@ export class Session {
|
|
|
5150
5153
|
if (resolvedWorktree) {
|
|
5151
5154
|
targetPath = resolvedWorktree.worktreePath;
|
|
5152
5155
|
}
|
|
5153
|
-
const
|
|
5154
|
-
const
|
|
5155
|
-
const
|
|
5156
|
-
const
|
|
5157
|
-
|
|
5158
|
-
|
|
5156
|
+
const archivedAt = new Date().toISOString();
|
|
5157
|
+
const preDeleteArchivedWorktree = await this.buildArchivedWorktreeState(targetPath, archivedAt);
|
|
5158
|
+
const recordsById = new Map((await this.agentStorage.list()).map((record) => [record.id, record]));
|
|
5159
|
+
const liveAgents = this.agentManager
|
|
5160
|
+
.listAgents()
|
|
5161
|
+
.filter((agent) => this.isPathWithinRoot(targetPath, agent.cwd));
|
|
5162
|
+
for (const agent of liveAgents) {
|
|
5163
|
+
if (recordsById.has(agent.id)) {
|
|
5164
|
+
continue;
|
|
5165
|
+
}
|
|
5166
|
+
await this.agentStorage.applySnapshot(agent, {
|
|
5167
|
+
internal: agent.internal,
|
|
5168
|
+
});
|
|
5169
|
+
const record = await this.agentStorage.get(agent.id);
|
|
5170
|
+
if (record) {
|
|
5171
|
+
recordsById.set(record.id, record);
|
|
5172
|
+
}
|
|
5173
|
+
}
|
|
5174
|
+
const internalRecordIds = new Set();
|
|
5175
|
+
const archivedRecords = new Map();
|
|
5176
|
+
const newlyArchivedRecordIds = new Set();
|
|
5177
|
+
for (const record of recordsById.values()) {
|
|
5178
|
+
if (!this.isPathWithinRoot(targetPath, record.cwd)) {
|
|
5179
|
+
continue;
|
|
5180
|
+
}
|
|
5181
|
+
if (record.internal) {
|
|
5182
|
+
internalRecordIds.add(record.id);
|
|
5183
|
+
continue;
|
|
5184
|
+
}
|
|
5185
|
+
if (!record.archivedAt) {
|
|
5186
|
+
newlyArchivedRecordIds.add(record.id);
|
|
5187
|
+
}
|
|
5188
|
+
archivedRecords.set(record.id, {
|
|
5189
|
+
...record,
|
|
5190
|
+
archivedAt: record.archivedAt ?? archivedAt,
|
|
5191
|
+
archivedWorktree: record.archivedWorktree ?? preDeleteArchivedWorktree,
|
|
5192
|
+
});
|
|
5193
|
+
}
|
|
5194
|
+
const succeededArchivedAgentIds = [];
|
|
5195
|
+
const succeededArchivedAgentIdSet = new Set();
|
|
5196
|
+
let responseArchivedAt = null;
|
|
5197
|
+
let responseError = null;
|
|
5198
|
+
for (const [recordId, record] of archivedRecords.entries()) {
|
|
5199
|
+
try {
|
|
5200
|
+
await this.agentStorage.upsert(record);
|
|
5201
|
+
if (newlyArchivedRecordIds.has(recordId) && !succeededArchivedAgentIdSet.has(recordId)) {
|
|
5202
|
+
succeededArchivedAgentIdSet.add(recordId);
|
|
5203
|
+
succeededArchivedAgentIds.push(recordId);
|
|
5204
|
+
responseArchivedAt = responseArchivedAt ?? record.archivedAt ?? archivedAt;
|
|
5205
|
+
}
|
|
5206
|
+
}
|
|
5207
|
+
catch (error) {
|
|
5208
|
+
if (!responseError) {
|
|
5209
|
+
responseError = this.toCheckoutError(error);
|
|
5210
|
+
}
|
|
5211
|
+
this.sessionLogger.warn({ err: error, agentId: recordId, cwd: record.cwd }, 'Failed to persist archived worktree record');
|
|
5212
|
+
}
|
|
5213
|
+
}
|
|
5214
|
+
if (succeededArchivedAgentIdSet.size !== newlyArchivedRecordIds.size) {
|
|
5215
|
+
return {
|
|
5216
|
+
success: false,
|
|
5217
|
+
archivedAgentIds: succeededArchivedAgentIds,
|
|
5218
|
+
archivedAt: responseArchivedAt,
|
|
5219
|
+
error: responseError ?? {
|
|
5220
|
+
code: 'UNKNOWN',
|
|
5221
|
+
message: 'Failed to persist archived records before worktree cleanup',
|
|
5222
|
+
},
|
|
5223
|
+
};
|
|
5224
|
+
}
|
|
5225
|
+
try {
|
|
5226
|
+
for (const agent of liveAgents) {
|
|
5159
5227
|
try {
|
|
5160
5228
|
await this.agentManager.closeAgent(agent.id);
|
|
5161
5229
|
}
|
|
5162
5230
|
catch {
|
|
5163
5231
|
// ignore cleanup errors
|
|
5164
5232
|
}
|
|
5165
|
-
|
|
5166
|
-
|
|
5167
|
-
|
|
5168
|
-
|
|
5169
|
-
|
|
5170
|
-
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
|
|
5176
|
-
|
|
5177
|
-
|
|
5178
|
-
|
|
5179
|
-
|
|
5233
|
+
}
|
|
5234
|
+
await this.killTerminalsUnderPath(targetPath);
|
|
5235
|
+
await deleteJunctionWorktree({
|
|
5236
|
+
cwd: options.repoRoot,
|
|
5237
|
+
worktreePath: targetPath,
|
|
5238
|
+
junctionHome: this.junctionHome,
|
|
5239
|
+
});
|
|
5240
|
+
const cleanedUpAt = new Date().toISOString();
|
|
5241
|
+
const finalizedArchivedRecords = Array.from(archivedRecords.values()).map((record) => ({
|
|
5242
|
+
...record,
|
|
5243
|
+
archivedWorktree: record.archivedWorktree
|
|
5244
|
+
? {
|
|
5245
|
+
...record.archivedWorktree,
|
|
5246
|
+
cleanupState: 'deleted',
|
|
5247
|
+
cleanedUpAt,
|
|
5248
|
+
}
|
|
5249
|
+
: record.archivedWorktree,
|
|
5250
|
+
}));
|
|
5251
|
+
const persistedFinalizedRecords = [];
|
|
5252
|
+
for (const record of finalizedArchivedRecords) {
|
|
5180
5253
|
try {
|
|
5181
|
-
await this.agentStorage.
|
|
5254
|
+
await this.agentStorage.upsert(record);
|
|
5255
|
+
persistedFinalizedRecords.push(record);
|
|
5182
5256
|
}
|
|
5183
|
-
catch {
|
|
5184
|
-
|
|
5257
|
+
catch (error) {
|
|
5258
|
+
if (!responseError) {
|
|
5259
|
+
responseError = this.toCheckoutError(error);
|
|
5260
|
+
}
|
|
5261
|
+
this.sessionLogger.warn({ err: error, agentId: record.id, cwd: record.cwd }, 'Failed to finalize archived worktree record');
|
|
5185
5262
|
}
|
|
5186
5263
|
}
|
|
5187
|
-
|
|
5188
|
-
const registryRecords = await this.agentStorage.list();
|
|
5189
|
-
for (const record of registryRecords) {
|
|
5190
|
-
if (this.isPathWithinRoot(targetPath, record.cwd)) {
|
|
5191
|
-
if (record.archivedAt) {
|
|
5192
|
-
preservedArchivedRecords.set(record.id, {
|
|
5193
|
-
...record,
|
|
5194
|
-
archivedWorktree: record.archivedWorktree
|
|
5195
|
-
? {
|
|
5196
|
-
...record.archivedWorktree,
|
|
5197
|
-
cleanupState: 'deleted',
|
|
5198
|
-
cleanedUpAt,
|
|
5199
|
-
}
|
|
5200
|
-
: record.archivedWorktree,
|
|
5201
|
-
});
|
|
5202
|
-
continue;
|
|
5203
|
-
}
|
|
5204
|
-
removedAgents.add(record.id);
|
|
5264
|
+
for (const recordId of internalRecordIds) {
|
|
5205
5265
|
try {
|
|
5206
|
-
await this.agentStorage.remove(
|
|
5266
|
+
await this.agentStorage.remove(recordId);
|
|
5207
5267
|
}
|
|
5208
5268
|
catch {
|
|
5209
5269
|
// ignore cleanup errors
|
|
5210
5270
|
}
|
|
5211
5271
|
}
|
|
5272
|
+
for (const record of persistedFinalizedRecords) {
|
|
5273
|
+
await this.forwardStoredAgentRecordUpdate(record);
|
|
5274
|
+
}
|
|
5212
5275
|
}
|
|
5213
|
-
|
|
5214
|
-
|
|
5215
|
-
|
|
5216
|
-
|
|
5217
|
-
junctionHome: this.junctionHome,
|
|
5218
|
-
});
|
|
5219
|
-
for (const record of preservedArchivedRecords.values()) {
|
|
5220
|
-
await this.agentStorage.upsert(record);
|
|
5221
|
-
}
|
|
5222
|
-
for (const agentId of removedAgents) {
|
|
5223
|
-
this.emit({
|
|
5224
|
-
type: 'agent_deleted',
|
|
5225
|
-
payload: {
|
|
5226
|
-
agentId,
|
|
5227
|
-
requestId: options.requestId,
|
|
5228
|
-
},
|
|
5229
|
-
});
|
|
5276
|
+
catch (error) {
|
|
5277
|
+
if (!responseError) {
|
|
5278
|
+
responseError = this.toCheckoutError(error);
|
|
5279
|
+
}
|
|
5230
5280
|
}
|
|
5231
|
-
|
|
5281
|
+
const success = responseError === null;
|
|
5282
|
+
return {
|
|
5283
|
+
success,
|
|
5284
|
+
archivedAgentIds: succeededArchivedAgentIds,
|
|
5285
|
+
archivedAt: succeededArchivedAgentIds.length > 0 ? responseArchivedAt ?? archivedAt : null,
|
|
5286
|
+
error: responseError,
|
|
5287
|
+
};
|
|
5232
5288
|
}
|
|
5233
5289
|
async handleJunctionWorktreeArchiveRequest(msg) {
|
|
5234
5290
|
const { requestId } = msg;
|
|
@@ -5254,7 +5310,8 @@ export class Session {
|
|
|
5254
5310
|
type: 'junction_worktree_archive_response',
|
|
5255
5311
|
payload: {
|
|
5256
5312
|
success: false,
|
|
5257
|
-
|
|
5313
|
+
archivedAgentIds: [],
|
|
5314
|
+
archivedAt: null,
|
|
5258
5315
|
error: {
|
|
5259
5316
|
code: 'NOT_ALLOWED',
|
|
5260
5317
|
message: 'Worktree is not a Junction-owned worktree',
|
|
@@ -5268,7 +5325,7 @@ export class Session {
|
|
|
5268
5325
|
if (!repoRoot) {
|
|
5269
5326
|
throw new Error('Unable to resolve repo root for worktree');
|
|
5270
5327
|
}
|
|
5271
|
-
const
|
|
5328
|
+
const archiveResult = await this.archiveJunctionWorktree({
|
|
5272
5329
|
targetPath,
|
|
5273
5330
|
repoRoot,
|
|
5274
5331
|
requestId,
|
|
@@ -5276,9 +5333,7 @@ export class Session {
|
|
|
5276
5333
|
this.emit({
|
|
5277
5334
|
type: 'junction_worktree_archive_response',
|
|
5278
5335
|
payload: {
|
|
5279
|
-
|
|
5280
|
-
removedAgents,
|
|
5281
|
-
error: null,
|
|
5336
|
+
...archiveResult,
|
|
5282
5337
|
requestId,
|
|
5283
5338
|
},
|
|
5284
5339
|
});
|
|
@@ -5288,7 +5343,8 @@ export class Session {
|
|
|
5288
5343
|
type: 'junction_worktree_archive_response',
|
|
5289
5344
|
payload: {
|
|
5290
5345
|
success: false,
|
|
5291
|
-
|
|
5346
|
+
archivedAgentIds: [],
|
|
5347
|
+
archivedAt: null,
|
|
5292
5348
|
error: this.toCheckoutError(error),
|
|
5293
5349
|
requestId,
|
|
5294
5350
|
},
|