@hyperdreamer/pi-webui 1.26.1 → 1.27.1
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/README.md +1 -1
- package/dist/client/assets/CodeViewer-sU_VxkJa.js +4 -0
- package/dist/client/assets/UnifiedDiffViewer-CPyC9e0o.js +39 -0
- package/dist/client/assets/decorate-85DywWfW.js +2 -0
- package/dist/client/assets/index-RPVQJ86w.js +7874 -0
- package/dist/client/assets/mathjaxEngine-dxhgEVSy.js +19 -0
- package/dist/client/assets/vendor-editor-core-DHpQKRa6.js +12 -0
- package/dist/client/assets/vendor-editor-languages-D-ZESBBF.js +46 -0
- package/dist/client/assets/vendor-terminal-BEifzAF_.js +16 -0
- package/dist/client/index.html +6 -50
- package/dist/server/sessions/modelHttpErrorStream.js +301 -0
- package/dist/server/sessions/modelHttpErrorStream.js.map +1 -0
- package/dist/server/sessions/piSessionService.js +141 -43
- package/dist/server/sessions/piSessionService.js.map +1 -1
- package/dist/server/sessions/sessionArchiveStore.js +48 -16
- package/dist/server/sessions/sessionArchiveStore.js.map +1 -1
- package/dist/server/sessions/sessionCommandService.js +2 -0
- package/dist/server/sessions/sessionCommandService.js.map +1 -1
- package/dist/server/sessions/sessionForkCommit.js +27 -0
- package/dist/server/sessions/sessionForkCommit.js.map +1 -0
- package/dist/shared/apiTypes.d.ts +4 -1
- package/dist/shared/modelHttpError.js +33 -0
- package/dist/shared/modelHttpError.js.map +1 -0
- package/package.json +8 -8
- package/dist/client/assets/CodeViewer-DAKOouFS.js +0 -4
- package/dist/client/assets/UnifiedDiffViewer-CIfQkwSQ.js +0 -39
- package/dist/client/assets/index-Jx8Fnguv.js +0 -7875
- package/dist/client/assets/mathjaxEngine-WPWR2qyM.js +0 -19
- package/dist/client/assets/vendor-editor-core-vyMPzMNA.js +0 -12
- package/dist/client/assets/vendor-editor-languages-DlEQaRIv.js +0 -46
- package/dist/client/assets/vendor-terminal-D8k4UKM2.js +0 -35
|
@@ -6,11 +6,12 @@ import { createAgentSessionFromServices, createAgentSessionRuntime, createAgentS
|
|
|
6
6
|
import { projectBrowserMessage } from "../browserMessageProjection.js";
|
|
7
7
|
import { pageMessagesAtSafeBoundary } from "./messagePaging.js";
|
|
8
8
|
import { sessionExtensionEntriesFromBranch, sessionExtensionEntry } from "./extensionEntries.js";
|
|
9
|
+
import { captureDurableForkCommit } from "./sessionForkCommit.js";
|
|
9
10
|
import { exportSessionHistoryHtml } from "./sessionHistoryExport.js";
|
|
10
11
|
import { BUILTIN_COMMANDS } from "./builtinCommands.js";
|
|
11
12
|
import { SessionCommandService, clientSessionFromRuntime, } from "./sessionCommandService.js";
|
|
12
13
|
import { projectSessionTree, } from "./sessionTreeProjection.js";
|
|
13
|
-
import { SessionArchiveStore, } from "./sessionArchiveStore.js";
|
|
14
|
+
import { SessionArchiveStore, SessionArchiveMutationError, } from "./sessionArchiveStore.js";
|
|
14
15
|
import { SessionMetadataStore, SessionMetadataOrderConflictError } from "./sessionMetadataStore.js";
|
|
15
16
|
import { findArchiveCandidateByIdOrPrefix, planSessionArchiveTree, } from "./sessionArchiveTree.js";
|
|
16
17
|
import { deterministicSessionName, fallbackSessionName, generateShortSessionName, } from "./sessionNameGenerator.js";
|
|
@@ -41,6 +42,7 @@ import { RememberCurrentModelPolicyCommand, } from "./rememberCurrentModelPolicy
|
|
|
41
42
|
import { StarterModelPolicyPreferenceStore } from "./starterModelPolicyPreferenceStore.js";
|
|
42
43
|
import { captureModelPolicySettings, modelPolicySettingsPersistence, restoreModelPolicySettings, settleModelPolicySettings, } from "./modelPolicySettingsPersistence.js";
|
|
43
44
|
import { wrapModelStream } from "../rateLimits/modelRateLimitAdapters.js";
|
|
45
|
+
import { withModelHttpErrorStatusRuntime } from "./modelHttpErrorStream.js";
|
|
44
46
|
const noopLogger = {
|
|
45
47
|
info() {
|
|
46
48
|
/* no-op */
|
|
@@ -327,18 +329,19 @@ export function createDefaultRuntimeFactory(modelRuntime, sessionManagers, utili
|
|
|
327
329
|
createFromServices: createAgentSessionFromServices,
|
|
328
330
|
}) {
|
|
329
331
|
return async ({ cwd, agentDir, sessionManager, sessionStartEvent, initialModel, initialThinkingLevel, delegationToolsEnabled, }) => {
|
|
332
|
+
const statusModelRuntime = withModelHttpErrorStatusRuntime(modelRuntime);
|
|
330
333
|
const runtimeRefs = {};
|
|
331
334
|
const services = await sdk.createServices({
|
|
332
335
|
cwd,
|
|
333
336
|
agentDir,
|
|
334
|
-
modelRuntime,
|
|
337
|
+
modelRuntime: statusModelRuntime,
|
|
335
338
|
resourceLoaderOptions: {
|
|
336
339
|
extensionFactories: [
|
|
337
340
|
createUtilityModelExtension({
|
|
338
341
|
// Pi's ExtensionContext exposes Model<any>; production candidates still come from ModelRuntime's Model<Api> snapshot.
|
|
339
342
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
340
343
|
resolver: utilityModelResolver,
|
|
341
|
-
modelRuntime,
|
|
344
|
+
modelRuntime: statusModelRuntime,
|
|
342
345
|
refs: runtimeRefs,
|
|
343
346
|
logger,
|
|
344
347
|
}),
|
|
@@ -417,6 +420,9 @@ export class PiSessionService {
|
|
|
417
420
|
constructor(events, deps) {
|
|
418
421
|
this.events = events;
|
|
419
422
|
this.active = new Map();
|
|
423
|
+
// SDK starts may remain memory-only until the first message. Keep only
|
|
424
|
+
// published creates visible in authoritative lists, not in-progress runtimes.
|
|
425
|
+
this.transientCreatedSessions = new Map();
|
|
420
426
|
/**
|
|
421
427
|
* Read ordering for extension entries, monotonic for this service lifetime.
|
|
422
428
|
*
|
|
@@ -610,7 +616,7 @@ export class PiSessionService {
|
|
|
610
616
|
},
|
|
611
617
|
hasActiveWork: (session) => this.hasActiveWork(session),
|
|
612
618
|
isTreeNavigationActive: (session) => this.treeNavigations.has(session),
|
|
613
|
-
runSessionReplacement: (session, operation) => this.runTreeExclusiveOperation([{ sessionId: session.sessionId, session }], "Stop current session activity before replacing the session", operation),
|
|
619
|
+
runSessionReplacement: (session, operation) => this.runTreeExclusiveOperation([{ sessionId: session.sessionId, session }], "Stop current session activity before replacing the session", () => this.runSessionFork(session, operation)),
|
|
614
620
|
}, { listSessionNames: (cwd) => this.listSessionNames(cwd) });
|
|
615
621
|
}
|
|
616
622
|
activeCount() {
|
|
@@ -685,7 +691,7 @@ export class PiSessionService {
|
|
|
685
691
|
readyDeleteRecords.push(record);
|
|
686
692
|
}
|
|
687
693
|
await this.ensureArchivedRecordsMoved(readyDeleteRecords);
|
|
688
|
-
const deletedSessionIds = new Set(await this.archiveStoreDeleteArchivedMany(readyDeleteRecords
|
|
694
|
+
const deletedSessionIds = new Set(await this.archiveStoreDeleteArchivedMany(readyDeleteRecords));
|
|
689
695
|
deleteRecords.push(...readyDeleteRecords.filter((record) => deletedSessionIds.has(record.sessionId)));
|
|
690
696
|
await this.forgetUnreadSessions(deleteRecords);
|
|
691
697
|
return summarizeSessionCleanupExecution({
|
|
@@ -721,7 +727,7 @@ export class PiSessionService {
|
|
|
721
727
|
readyDeleteRecords.push(record);
|
|
722
728
|
}
|
|
723
729
|
await this.ensureArchivedRecordsMoved(readyDeleteRecords);
|
|
724
|
-
const deletedSessionIds = new Set(await this.archiveStoreDeleteArchivedMany(readyDeleteRecords
|
|
730
|
+
const deletedSessionIds = new Set(await this.archiveStoreDeleteArchivedMany(readyDeleteRecords));
|
|
725
731
|
const deleteRecords = readyDeleteRecords.filter((record) => deletedSessionIds.has(record.sessionId));
|
|
726
732
|
await this.forgetUnreadSessions(deleteRecords);
|
|
727
733
|
return summarizeForceCleanupExecution({
|
|
@@ -742,6 +748,7 @@ export class PiSessionService {
|
|
|
742
748
|
for (const active of activeSessions)
|
|
743
749
|
this.forgetUnreadActivity(active.runtime.session);
|
|
744
750
|
this.active.clear();
|
|
751
|
+
this.transientCreatedSessions.clear();
|
|
745
752
|
this.pendingSessionOpens.clear();
|
|
746
753
|
this.activities.clear();
|
|
747
754
|
this.compactionPromptQueues.clear();
|
|
@@ -842,6 +849,22 @@ export class PiSessionService {
|
|
|
842
849
|
const unarchivedSessions = sessions
|
|
843
850
|
.filter((session) => !archivedById.has(session.id))
|
|
844
851
|
.map((entry) => mergeSessionMetadata(clientSessionFromListEntry(entry), metadata));
|
|
852
|
+
for (const [id, created] of this.transientCreatedSessions) {
|
|
853
|
+
const active = this.active.get(id);
|
|
854
|
+
if (active === undefined || sessionsById.has(id)) {
|
|
855
|
+
this.transientCreatedSessions.delete(id);
|
|
856
|
+
continue;
|
|
857
|
+
}
|
|
858
|
+
if (canonicalizeStoredCwd(created.cwd) !== canonicalizeStoredCwd(cwd) || archivedById.has(id))
|
|
859
|
+
continue;
|
|
860
|
+
const session = active.runtime.session;
|
|
861
|
+
unarchivedSessions.push(mergeSessionMetadata({
|
|
862
|
+
...created,
|
|
863
|
+
persisted: sessionFileExists(session.sessionFile),
|
|
864
|
+
messageCount: session.messages.length,
|
|
865
|
+
...(session.sessionName === undefined ? {} : { name: session.sessionName }),
|
|
866
|
+
}, metadata));
|
|
867
|
+
}
|
|
845
868
|
const reconcilableSessionIds = this.reconcilableSessionIds(cwd, unarchivedSessions.map((session) => session.id), archivedById);
|
|
846
869
|
this.workspaceActivity?.reconcileSessionActivity(cwd, reconcilableSessionIds);
|
|
847
870
|
await this.publishUnreadMutations(this.unreadStore.reconcileCwd(canonicalizeStoredCwd(cwd), reconcilableSessionIds));
|
|
@@ -913,9 +936,13 @@ export class PiSessionService {
|
|
|
913
936
|
: { parentSessionPath: options.parentSession }),
|
|
914
937
|
...(creationSource === undefined ? {} : { creationSource }),
|
|
915
938
|
};
|
|
939
|
+
// The SDK's disk catalog omits starts without a first message. They are
|
|
940
|
+
// nevertheless valid published sessions, including for non-creator clients.
|
|
941
|
+
this.rememberPublishedSession(created);
|
|
916
942
|
// Broadcast so other clients (and the spawning agent's UI) can add the new
|
|
917
943
|
// session to their list without a manual reload.
|
|
918
944
|
this.events.publishGlobal({ type: "session.created", session: created });
|
|
945
|
+
this.publishSessionsChanged([created.cwd]);
|
|
919
946
|
return created;
|
|
920
947
|
}
|
|
921
948
|
/**
|
|
@@ -1794,18 +1821,21 @@ export class PiSessionService {
|
|
|
1794
1821
|
await this.assertWritable(ref);
|
|
1795
1822
|
const active = await this.getActive(ref);
|
|
1796
1823
|
const sourceSession = active.runtime.session;
|
|
1797
|
-
|
|
1824
|
+
return this.runTreeExclusiveOperation([
|
|
1798
1825
|
{
|
|
1799
1826
|
sessionId: sourceSession.sessionId,
|
|
1800
1827
|
session: sourceSession,
|
|
1801
1828
|
runtime: active.runtime,
|
|
1802
1829
|
},
|
|
1803
|
-
], "Stop current session activity before replacing the session", () =>
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1830
|
+
], "Stop current session activity before replacing the session", () => this.runSessionFork(sourceSession, async () => {
|
|
1831
|
+
const result = await active.runtime.fork(entryId);
|
|
1832
|
+
if (result.cancelled)
|
|
1833
|
+
return { cancelled: true };
|
|
1834
|
+
const session = clientSessionFromRuntime(active.runtime);
|
|
1835
|
+
this.rememberPublishedSession(session);
|
|
1836
|
+
this.events.publishGlobal({ type: "session.created", session });
|
|
1837
|
+
return { cancelled: false, session };
|
|
1838
|
+
}));
|
|
1809
1839
|
}
|
|
1810
1840
|
async navigateToTreeEntry(ref, targetId, options, expectedLeafId) {
|
|
1811
1841
|
if (targetId.trim() === "")
|
|
@@ -1924,7 +1954,7 @@ export class PiSessionService {
|
|
|
1924
1954
|
kind: "clear",
|
|
1925
1955
|
reason: "archive",
|
|
1926
1956
|
});
|
|
1927
|
-
await this.
|
|
1957
|
+
await this.archiveStoreArchive(archiveInput);
|
|
1928
1958
|
await this.forgetUnreadSessions([archiveInput]);
|
|
1929
1959
|
});
|
|
1930
1960
|
});
|
|
@@ -2086,7 +2116,7 @@ export class PiSessionService {
|
|
|
2086
2116
|
kind: "clear",
|
|
2087
2117
|
reason: "restore",
|
|
2088
2118
|
});
|
|
2089
|
-
await this.archiveStore.restore(archived.sessionId);
|
|
2119
|
+
await this.publishArchiveMutation(() => this.archiveStore.restore(archived.sessionId), () => [archived.cwd]);
|
|
2090
2120
|
await this.forgetUnreadSessions([archived]);
|
|
2091
2121
|
});
|
|
2092
2122
|
}
|
|
@@ -2102,7 +2132,7 @@ export class PiSessionService {
|
|
|
2102
2132
|
});
|
|
2103
2133
|
if (record.archivePath === undefined)
|
|
2104
2134
|
await this.ensureArchivedRecordMoved(record);
|
|
2105
|
-
await this.
|
|
2135
|
+
await this.archiveStoreDeleteArchivedMany([record]);
|
|
2106
2136
|
await this.forgetUnreadSessions([record]);
|
|
2107
2137
|
}
|
|
2108
2138
|
async deleteArchivedMany(refs) {
|
|
@@ -2159,7 +2189,8 @@ export class PiSessionService {
|
|
|
2159
2189
|
.filter((sessionId) => !moveFailureIds.has(sessionId));
|
|
2160
2190
|
let deletedSessionIds = [];
|
|
2161
2191
|
try {
|
|
2162
|
-
|
|
2192
|
+
const deleteIdSet = new Set(deleteIds);
|
|
2193
|
+
deletedSessionIds = await this.archiveStoreDeleteArchivedMany(readyRecords.filter((record) => deleteIdSet.has(record.sessionId)));
|
|
2163
2194
|
}
|
|
2164
2195
|
catch (error) {
|
|
2165
2196
|
for (const sessionId of deleteIds)
|
|
@@ -2336,26 +2367,60 @@ export class PiSessionService {
|
|
|
2336
2367
|
const entries = await Promise.all(uniqueCwds.map(async (cwd) => [cwd, await this.sessionManager.list(cwd)]));
|
|
2337
2368
|
return new Map(entries);
|
|
2338
2369
|
}
|
|
2370
|
+
rememberPublishedSession(session) {
|
|
2371
|
+
if (session.persisted === false && !this.transientCreatedSessions.has(session.id)) {
|
|
2372
|
+
this.transientCreatedSessions.set(session.id, session);
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2375
|
+
publishSessionsChanged(cwds) {
|
|
2376
|
+
for (const cwd of new Set(cwds.map(canonicalizeStoredCwd)))
|
|
2377
|
+
this.events.publishGlobal({ type: "sessions.changed", cwd });
|
|
2378
|
+
}
|
|
2379
|
+
async publishArchiveMutation(operation, changedCwds) {
|
|
2380
|
+
let result;
|
|
2381
|
+
try {
|
|
2382
|
+
result = await operation();
|
|
2383
|
+
}
|
|
2384
|
+
catch (error) {
|
|
2385
|
+
// A rejected operation may already have changed durable history. Closing
|
|
2386
|
+
// a runtime alone is not evidence of a list mutation.
|
|
2387
|
+
if (error instanceof SessionArchiveMutationError)
|
|
2388
|
+
this.publishSessionsChanged(error.changedCwds);
|
|
2389
|
+
throw error;
|
|
2390
|
+
}
|
|
2391
|
+
this.publishSessionsChanged(changedCwds(result));
|
|
2392
|
+
return result;
|
|
2393
|
+
}
|
|
2394
|
+
async archiveStoreArchive(input) {
|
|
2395
|
+
return this.publishArchiveMutation(() => this.archiveStore.archive(input), (record) => [record.cwd]);
|
|
2396
|
+
}
|
|
2339
2397
|
async archiveStoreArchiveMany(inputs) {
|
|
2340
2398
|
if (inputs.length === 0)
|
|
2341
2399
|
return [];
|
|
2342
|
-
|
|
2343
|
-
|
|
2400
|
+
const archiveMany = this.archiveStore.archiveMany?.bind(this.archiveStore);
|
|
2401
|
+
if (archiveMany !== undefined)
|
|
2402
|
+
return this.publishArchiveMutation(() => archiveMany(inputs), (records) => records.map((record) => record.cwd));
|
|
2344
2403
|
const records = [];
|
|
2345
2404
|
for (const input of inputs)
|
|
2346
|
-
records.push(await this.
|
|
2405
|
+
records.push(await this.archiveStoreArchive(input));
|
|
2347
2406
|
return records;
|
|
2348
2407
|
}
|
|
2349
|
-
async archiveStoreDeleteArchivedMany(
|
|
2350
|
-
if (
|
|
2408
|
+
async archiveStoreDeleteArchivedMany(records) {
|
|
2409
|
+
if (records.length === 0)
|
|
2351
2410
|
return [];
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
if (
|
|
2411
|
+
const sessionIds = records.map((record) => record.sessionId);
|
|
2412
|
+
const deleteMany = this.archiveStore.deleteArchivedMany?.bind(this.archiveStore);
|
|
2413
|
+
if (deleteMany !== undefined)
|
|
2414
|
+
return this.publishArchiveMutation(() => deleteMany(sessionIds), (deletedIds) => {
|
|
2415
|
+
const deleted = new Set(deletedIds);
|
|
2416
|
+
return records.filter((record) => deleted.has(record.sessionId)).map((record) => record.cwd);
|
|
2417
|
+
});
|
|
2418
|
+
const deleteOne = this.archiveStore.deleteArchived?.bind(this.archiveStore);
|
|
2419
|
+
if (deleteOne === undefined)
|
|
2355
2420
|
throw new Error("Archive store does not support deletion");
|
|
2356
|
-
for (const
|
|
2357
|
-
await this.
|
|
2358
|
-
return
|
|
2421
|
+
for (const record of records)
|
|
2422
|
+
await this.publishArchiveMutation(() => deleteOne(record.sessionId), () => [record.cwd]);
|
|
2423
|
+
return sessionIds;
|
|
2359
2424
|
}
|
|
2360
2425
|
async moveLegacyArchivedRecordsForDelete(records) {
|
|
2361
2426
|
const legacyRecords = records.filter((record) => record.archivePath === undefined);
|
|
@@ -2431,7 +2496,7 @@ export class PiSessionService {
|
|
|
2431
2496
|
if (session === undefined || this.active.has(record.sessionId))
|
|
2432
2497
|
return record;
|
|
2433
2498
|
try {
|
|
2434
|
-
return await this.
|
|
2499
|
+
return await this.archiveStoreArchive(archiveInputFromListEntry(session));
|
|
2435
2500
|
}
|
|
2436
2501
|
catch {
|
|
2437
2502
|
return record;
|
|
@@ -2547,23 +2612,34 @@ export class PiSessionService {
|
|
|
2547
2612
|
return;
|
|
2548
2613
|
this.forgetUnreadActivity(active.runtime.session);
|
|
2549
2614
|
this.active.delete(sessionId);
|
|
2550
|
-
this.
|
|
2551
|
-
|
|
2552
|
-
this.
|
|
2553
|
-
this.clearCompactionPromptQueue(sessionId);
|
|
2554
|
-
// Disarm subsession notification before teardown so the abort below cannot
|
|
2555
|
-
// emit a "stopped working" event that notifies the parent (e.g. on archive).
|
|
2556
|
-
// The parent/children link is kept so the parent can still see the child.
|
|
2557
|
-
if (this.subsessionLinkForActiveChild(active.runtime.session) !== undefined)
|
|
2558
|
-
this.subsessionNotifyArmed.delete(sessionId);
|
|
2559
|
-
clearSessionQueue(active.runtime.session);
|
|
2560
|
-
active.unsubscribe();
|
|
2561
|
-
active.runtime.setRebindSession(undefined);
|
|
2615
|
+
const transient = this.transientCreatedSessions.get(sessionId);
|
|
2616
|
+
const removedMemoryOnly = transient !== undefined && !sessionFileExists(active.runtime.session.sessionFile);
|
|
2617
|
+
this.transientCreatedSessions.delete(sessionId);
|
|
2562
2618
|
try {
|
|
2563
|
-
|
|
2619
|
+
this.activities.delete(sessionId);
|
|
2620
|
+
this.workspaceActivity?.removeSession(sessionId, active.runtime.session.sessionManager.getCwd());
|
|
2621
|
+
this.clearAuthLossWarningsForSession(sessionId);
|
|
2622
|
+
this.clearCompactionPromptQueue(sessionId);
|
|
2623
|
+
// Disarm subsession notification before teardown so the abort below cannot
|
|
2624
|
+
// emit a "stopped working" event that notifies the parent (e.g. on archive).
|
|
2625
|
+
// The parent/children link is kept so the parent can still see the child.
|
|
2626
|
+
if (this.subsessionLinkForActiveChild(active.runtime.session) !== undefined)
|
|
2627
|
+
this.subsessionNotifyArmed.delete(sessionId);
|
|
2628
|
+
clearSessionQueue(active.runtime.session);
|
|
2629
|
+
active.unsubscribe();
|
|
2630
|
+
active.runtime.setRebindSession(undefined);
|
|
2631
|
+
try {
|
|
2632
|
+
await this.abortSessionOperations(active.runtime.session);
|
|
2633
|
+
}
|
|
2634
|
+
finally {
|
|
2635
|
+
await active.runtime.dispose();
|
|
2636
|
+
}
|
|
2564
2637
|
}
|
|
2565
2638
|
finally {
|
|
2566
|
-
|
|
2639
|
+
// Removing published memory-only membership changes the catalog even if
|
|
2640
|
+
// teardown fails. Notify after teardown so any final SDK writes are visible.
|
|
2641
|
+
if (removedMemoryOnly)
|
|
2642
|
+
this.publishSessionsChanged([transient.cwd]);
|
|
2567
2643
|
}
|
|
2568
2644
|
}
|
|
2569
2645
|
async abortSessionOperations(session) {
|
|
@@ -3303,6 +3379,28 @@ export class PiSessionService {
|
|
|
3303
3379
|
this.isTreeExclusiveOperationActive(session) ||
|
|
3304
3380
|
sessionHasActiveWork(session, this.compactionQueuedMessages(session.sessionId).length));
|
|
3305
3381
|
}
|
|
3382
|
+
async runSessionFork(source, operation) {
|
|
3383
|
+
// Called inside the tree-exclusive lock. A rejected SDK fork may already
|
|
3384
|
+
// have committed history, even if teardown prevented createRuntime running.
|
|
3385
|
+
const hasDurableCommit = await captureDurableForkCommit(source.sessionManager);
|
|
3386
|
+
const active = this.active.get(source.sessionId);
|
|
3387
|
+
let result;
|
|
3388
|
+
try {
|
|
3389
|
+
result = await operation();
|
|
3390
|
+
// Forking before the first user message succeeds with a new live runtime
|
|
3391
|
+
// but no JSONL yet. Commands return that identity too, so it must join the
|
|
3392
|
+
// same authoritative live catalog as starts before broadcasting invalidation.
|
|
3393
|
+
if (!result.cancelled && active !== undefined) {
|
|
3394
|
+
this.rememberPublishedSession(clientSessionFromRuntime(active.runtime));
|
|
3395
|
+
}
|
|
3396
|
+
return result;
|
|
3397
|
+
}
|
|
3398
|
+
finally {
|
|
3399
|
+
if (result?.cancelled === false ||
|
|
3400
|
+
(result === undefined && await hasDurableCommit()))
|
|
3401
|
+
this.publishSessionsChanged([source.sessionManager.getCwd()]);
|
|
3402
|
+
}
|
|
3403
|
+
}
|
|
3306
3404
|
async runTreeExclusiveOperation(targets, activeError, operation) {
|
|
3307
3405
|
const sessionIds = new Set();
|
|
3308
3406
|
const runtimes = new Set();
|