pi-ui-extend 1.0.42 → 1.0.45
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 +41 -12
- package/dist/app/app.d.ts +10 -0
- package/dist/app/app.js +132 -8
- package/dist/app/cli/install.js +2 -2
- package/dist/app/commands/command-controller.d.ts +4 -0
- package/dist/app/commands/command-controller.js +11 -0
- package/dist/app/commands/command-git-actions.d.ts +25 -0
- package/dist/app/commands/command-git-actions.js +381 -0
- package/dist/app/commands/command-host.d.ts +3 -0
- package/dist/app/commands/command-host.js +5 -2
- package/dist/app/commands/command-model-actions.d.ts +1 -0
- package/dist/app/commands/command-model-actions.js +51 -34
- package/dist/app/commands/command-navigation-actions.d.ts +1 -0
- package/dist/app/commands/command-navigation-actions.js +16 -3
- package/dist/app/commands/command-registry.d.ts +2 -0
- package/dist/app/commands/command-registry.js +14 -0
- package/dist/app/commands/reload-context-inventory.js +12 -1
- package/dist/app/input/autocomplete-controller.js +61 -34
- package/dist/app/input/input-action-controller.d.ts +2 -0
- package/dist/app/input/input-action-controller.js +8 -1
- package/dist/app/input/input-controller.d.ts +2 -1
- package/dist/app/input/input-controller.js +7 -2
- package/dist/app/input/prompt-enhancer-controller.js +53 -35
- package/dist/app/input/voice-controller.d.ts +41 -45
- package/dist/app/input/voice-controller.js +351 -419
- package/dist/app/model/model-usage-controller.js +17 -7
- package/dist/app/model/model-usage-status.d.ts +4 -1
- package/dist/app/model/model-usage-status.js +270 -46
- package/dist/app/popup/menu-items-controller.d.ts +13 -3
- package/dist/app/popup/menu-items-controller.js +37 -21
- package/dist/app/popup/popup-action-controller.d.ts +12 -2
- package/dist/app/popup/popup-action-controller.js +77 -24
- package/dist/app/popup/popup-menu-controller.d.ts +36 -14
- package/dist/app/popup/popup-menu-controller.js +239 -69
- package/dist/app/rendering/dcp-stats.d.ts +9 -4
- package/dist/app/rendering/dcp-stats.js +40 -425
- package/dist/app/rendering/popup-menu-renderer.d.ts +3 -5
- package/dist/app/rendering/popup-menu-renderer.js +42 -37
- package/dist/app/rendering/render-controller.js +23 -2
- package/dist/app/rendering/status-line-renderer.d.ts +5 -0
- package/dist/app/rendering/status-line-renderer.js +41 -5
- package/dist/app/rendering/tab-line-renderer.js +26 -20
- package/dist/app/runtime.d.ts +12 -1
- package/dist/app/runtime.js +120 -12
- package/dist/app/screen/mouse-controller.d.ts +2 -0
- package/dist/app/screen/mouse-controller.js +17 -7
- package/dist/app/screen/status-controller.d.ts +4 -0
- package/dist/app/screen/status-controller.js +5 -0
- package/dist/app/session/lazy-session-manager.js +34 -0
- package/dist/app/session/session-event-controller.d.ts +1 -0
- package/dist/app/session/session-event-controller.js +10 -1
- package/dist/app/session/session-history.d.ts +1 -0
- package/dist/app/session/session-history.js +12 -1
- package/dist/app/session/session-lifecycle-controller.d.ts +6 -1
- package/dist/app/session/session-lifecycle-controller.js +10 -1
- package/dist/app/session/tabs-controller.d.ts +25 -1
- package/dist/app/session/tabs-controller.js +442 -153
- package/dist/app/subagents/subagents-widget-controller.d.ts +1 -0
- package/dist/app/subagents/subagents-widget-controller.js +6 -0
- package/dist/app/types.d.ts +11 -1
- package/dist/app/workspace/workspace-actions-controller.js +10 -2
- package/dist/app/workspace/workspace-undo.d.ts +1 -0
- package/dist/app/workspace/workspace-undo.js +1 -0
- package/dist/bundled-extensions/question/index.js +9 -1
- package/dist/bundled-extensions/question/remote.d.ts +4 -0
- package/dist/bundled-extensions/question/remote.js +33 -0
- package/dist/bundled-extensions/telegram-connector/bot.d.ts +43 -0
- package/dist/bundled-extensions/telegram-connector/bot.js +166 -0
- package/dist/bundled-extensions/telegram-connector/config.d.ts +8 -0
- package/dist/bundled-extensions/telegram-connector/config.js +87 -0
- package/dist/bundled-extensions/telegram-connector/coordinator.d.ts +66 -0
- package/dist/bundled-extensions/telegram-connector/coordinator.js +413 -0
- package/dist/bundled-extensions/telegram-connector/index.d.ts +3 -0
- package/dist/bundled-extensions/telegram-connector/index.js +195 -0
- package/dist/bundled-extensions/terminal-bell/index.d.ts +0 -8
- package/dist/bundled-extensions/terminal-bell/index.js +0 -76
- package/dist/bundled-extensions/workspace-undo/index.d.ts +26 -0
- package/dist/bundled-extensions/workspace-undo/index.js +191 -0
- package/dist/config.d.ts +21 -2
- package/dist/config.js +159 -32
- package/dist/default-pix-config.js +20 -10
- package/dist/schemas/pi-tools-suite-schema.d.ts +8 -4
- package/dist/schemas/pi-tools-suite-schema.js +11 -5
- package/dist/schemas/pix-schema.d.ts +12 -2
- package/dist/schemas/pix-schema.js +37 -9
- package/dist/schemas/tasks-schema.js +1 -1
- package/docs/concurrency.md +3 -1
- package/docs/desktop-mvp.md +10 -5
- package/docs/desktop-task-manager.md +81 -28
- package/docs/release.md +30 -6
- package/external/pi-tools-suite/README.md +165 -39
- package/external/pi-tools-suite/docs/session-recovery.md +7 -0
- package/external/pi-tools-suite/docs/subagent-model-pools.md +12 -5
- package/external/pi-tools-suite/docs/ui-qa-subagent.md +440 -0
- package/external/pi-tools-suite/package.json +6 -1
- package/external/pi-tools-suite/src/antigravity-auth/auth-store.ts +2 -1
- package/external/pi-tools-suite/src/antigravity-auth/constants.ts +9 -3
- package/external/pi-tools-suite/src/antigravity-auth/headers.ts +41 -3
- package/external/pi-tools-suite/src/antigravity-auth/models.ts +94 -21
- package/external/pi-tools-suite/src/antigravity-auth/oauth.ts +5 -17
- package/external/pi-tools-suite/src/antigravity-auth/payload.ts +72 -7
- package/external/pi-tools-suite/src/antigravity-auth/stream.ts +13 -1
- package/external/pi-tools-suite/src/async-subagents/agents/implement.md +1 -1
- package/external/pi-tools-suite/src/async-subagents/agents/ui-qa/backends/browser.mjs +346 -0
- package/external/pi-tools-suite/src/async-subagents/agents/ui-qa/backends/desktop.mjs +1038 -0
- package/external/pi-tools-suite/src/async-subagents/agents/ui-qa/backends/tui.mjs +759 -0
- package/external/pi-tools-suite/src/async-subagents/agents/{browser-qa → ui-qa/browser}/scripts/browser-qa-runner.mjs +32 -23
- package/external/pi-tools-suite/src/async-subagents/agents/ui-qa/drivers/chrome-devtools/chrome-devtools-provider.mjs +895 -0
- package/external/pi-tools-suite/src/async-subagents/agents/ui-qa/drivers/linux/linux-atspi.py +494 -0
- package/external/pi-tools-suite/src/async-subagents/agents/ui-qa/drivers/macos/macos-accessibility.swift +1085 -0
- package/external/pi-tools-suite/src/async-subagents/agents/ui-qa/drivers/native-terminal/bridge-client.mjs +50 -0
- package/external/pi-tools-suite/src/async-subagents/agents/ui-qa/drivers/native-terminal/native-terminal-host.mjs +501 -0
- package/external/pi-tools-suite/src/async-subagents/agents/ui-qa/drivers/windows/windows-uia.ps1 +454 -0
- package/external/pi-tools-suite/src/async-subagents/agents/ui-qa/guides/browser-auth.md +114 -0
- package/external/pi-tools-suite/src/async-subagents/agents/ui-qa/guides/browser-chrome-devtools.md +91 -0
- package/external/pi-tools-suite/src/async-subagents/agents/ui-qa/guides/browser-playwright.md +145 -0
- package/external/pi-tools-suite/src/async-subagents/agents/ui-qa/guides/browser.md +82 -0
- package/external/pi-tools-suite/src/async-subagents/agents/ui-qa/guides/desktop-linux.md +26 -0
- package/external/pi-tools-suite/src/async-subagents/agents/ui-qa/guides/desktop-macos.md +29 -0
- package/external/pi-tools-suite/src/async-subagents/agents/ui-qa/guides/desktop-windows.md +23 -0
- package/external/pi-tools-suite/src/async-subagents/agents/ui-qa/guides/desktop.md +54 -0
- package/external/pi-tools-suite/src/async-subagents/agents/ui-qa/guides/tui-native-terminal.md +59 -0
- package/external/pi-tools-suite/src/async-subagents/agents/ui-qa/guides/tui-pty.md +37 -0
- package/external/pi-tools-suite/src/async-subagents/agents/ui-qa/guides/tui.md +60 -0
- package/external/pi-tools-suite/src/async-subagents/agents/ui-qa/scripts/ui-qa-runner.mjs +535 -0
- package/external/pi-tools-suite/src/async-subagents/agents/ui-qa.md +75 -0
- package/external/pi-tools-suite/src/async-subagents/commands.ts +1 -1
- package/external/pi-tools-suite/src/async-subagents/core/agent-strategy.ts +1 -1
- package/external/pi-tools-suite/src/async-subagents/core/agents-dir.ts +0 -2
- package/external/pi-tools-suite/src/async-subagents/core/browser-qa.ts +16 -2
- package/external/pi-tools-suite/src/async-subagents/core/config.ts +40 -17
- package/external/pi-tools-suite/src/async-subagents/core/model-selection.ts +2 -1
- package/external/pi-tools-suite/src/async-subagents/core/registry.ts +158 -33
- package/external/pi-tools-suite/src/async-subagents/core/routing.ts +7 -4
- package/external/pi-tools-suite/src/async-subagents/core/spawn.ts +34 -24
- package/external/pi-tools-suite/src/async-subagents/core/ultrawork-auto.ts +51 -45
- package/external/pi-tools-suite/src/async-subagents/lib.ts +9 -1
- package/external/pi-tools-suite/src/async-subagents/tools/spawn.ts +0 -1
- package/external/pi-tools-suite/src/async-subagents/tools/subagents.ts +2 -2
- package/external/pi-tools-suite/src/coding-discipline/index.ts +90 -59
- package/external/pi-tools-suite/src/config.ts +14 -0
- package/external/pi-tools-suite/src/context-gateway/accounting-log.ts +282 -0
- package/external/pi-tools-suite/src/context-gateway/config.ts +66 -1
- package/external/pi-tools-suite/src/context-gateway/efficiency.ts +414 -0
- package/external/pi-tools-suite/src/context-gateway/enforcement.ts +123 -3
- package/external/pi-tools-suite/src/context-gateway/index.ts +137 -4
- package/external/pi-tools-suite/src/context-gateway/storeless-capabilities.ts +5 -5
- package/external/pi-tools-suite/src/context-gateway/telemetry.ts +2 -2
- package/external/pi-tools-suite/src/context-gateway/types.ts +8 -1
- package/external/pi-tools-suite/src/dcp/auto-compress-budget.ts +39 -4
- package/external/pi-tools-suite/src/dcp/auto-compress.ts +41 -14
- package/external/pi-tools-suite/src/dcp/commands.ts +14 -156
- package/external/pi-tools-suite/src/dcp/compress-tool.ts +8 -2
- package/external/pi-tools-suite/src/dcp/compression-progress.ts +22 -0
- package/external/pi-tools-suite/src/dcp/config.ts +58 -4
- package/external/pi-tools-suite/src/dcp/conversation-index.ts +36 -9
- package/external/pi-tools-suite/src/dcp/diagnostics.ts +41 -0
- package/external/pi-tools-suite/src/dcp/fresh-tool-results.ts +38 -0
- package/external/pi-tools-suite/src/dcp/index.ts +338 -66
- package/external/pi-tools-suite/src/dcp/journal.ts +126 -4
- package/external/pi-tools-suite/src/dcp/progress-controller.ts +2 -1
- package/external/pi-tools-suite/src/dcp/pruner-candidates.ts +92 -2
- package/external/pi-tools-suite/src/dcp/pruner-nudge.ts +36 -33
- package/external/pi-tools-suite/src/dcp/pruner.ts +1 -0
- package/external/pi-tools-suite/src/dcp/routine-pressure.ts +86 -0
- package/external/pi-tools-suite/src/dcp/state.ts +9 -0
- package/external/pi-tools-suite/src/dcp/statistics.d.ts +8 -0
- package/external/pi-tools-suite/src/dcp/statistics.js +156 -0
- package/external/pi-tools-suite/src/default-pi-tools-suite-config.ts +68 -16
- package/external/pi-tools-suite/src/lib/project.ts +36 -1
- package/external/pi-tools-suite/src/model-tools/index.ts +10 -7
- package/external/pi-tools-suite/src/repo-discovery/index.ts +304 -4
- package/external/pi-tools-suite/src/resource-registry/index.ts +282 -21
- package/external/pi-tools-suite/src/session-recovery/index.ts +17 -0
- package/external/pi-tools-suite/src/todo/index.ts +21 -0
- package/external/pi-tools-suite/src/todo/todo.ts +19 -1
- package/external/pi-tools-suite/src/tool-descriptions.ts +44 -15
- package/package.json +7 -8
- package/schemas/pi-tools-suite.json +44 -12
- package/schemas/pix.json +109 -15
- package/schemas/tasks.json +1 -2
- package/skills/simplify/SKILL.md +33 -5
- package/external/pi-tools-suite/docs/browser-qa-subagent.md +0 -196
- package/external/pi-tools-suite/src/async-subagents/agents/browser-qa.md +0 -598
- package/skills/playwright-cli/SKILL.md +0 -420
- package/skills/playwright-cli/references/element-attributes.md +0 -23
- package/skills/playwright-cli/references/playwright-tests.md +0 -50
- package/skills/playwright-cli/references/request-mocking.md +0 -87
- package/skills/playwright-cli/references/running-code.md +0 -241
- package/skills/playwright-cli/references/session-management.md +0 -273
- package/skills/playwright-cli/references/spec-driven-testing.md +0 -311
- package/skills/playwright-cli/references/storage-state.md +0 -290
- package/skills/playwright-cli/references/test-generation.md +0 -142
- package/skills/playwright-cli/references/tracing.md +0 -154
- package/skills/playwright-cli/references/video-recording.md +0 -147
- package/skills/spec-wiki/SKILL.md +0 -55
- package/skills/spec-wiki/evals/evals.json +0 -132
- package/skills/spec-wiki/evals/files/bootstrap/architecture/rfc-007.md +0 -14
- package/skills/spec-wiki/evals/files/bootstrap/docs/how-to-pay.md +0 -4
- package/skills/spec-wiki/evals/files/bootstrap/docs/overview.md +0 -9
- package/skills/spec-wiki/evals/files/bootstrap/requirements/payment-behavior.md +0 -17
- package/skills/spec-wiki/evals/files/bootstrap/src/payments.ts +0 -12
- package/skills/spec-wiki/evals/files/bootstrap/tests/payments.test.ts +0 -11
- package/skills/spec-wiki/evals/files/focused/src/session.ts +0 -5
- package/skills/spec-wiki/evals/files/focused/tests/session.test.ts +0 -17
- package/skills/spec-wiki/evals/files/maintenance/low-signal/incoming/capture.txt +0 -2
- package/skills/spec-wiki/evals/files/maintenance/low-signal/src/capture.ts +0 -3
- package/skills/spec-wiki/evals/files/maintenance/move/docs/old-job-contract.md +0 -18
- package/skills/spec-wiki/evals/files/maintenance/move/src/job.ts +0 -5
- package/skills/spec-wiki/evals/files/maintenance/new-relation/docs/session-refresh.md +0 -24
- package/skills/spec-wiki/evals/files/maintenance/new-relation/incoming/refresh-worker.ts +0 -7
- package/skills/spec-wiki/evals/files/maintenance/new-relation/src/session.ts +0 -7
- package/skills/spec-wiki/evals/files/maintenance/no-impact/docs/auth-contract.md +0 -17
- package/skills/spec-wiki/evals/files/maintenance/no-impact/incoming/telemetry-format.ts +0 -3
- package/skills/spec-wiki/evals/files/maintenance/no-impact/src/auth.ts +0 -3
- package/skills/spec-wiki/evals/files/query/docs/how-to-run-jobs.md +0 -4
- package/skills/spec-wiki/evals/files/query/docs/spec-overview.md +0 -9
- package/skills/spec-wiki/evals/files/query/features/jobs/cancellation-contract.md +0 -15
- package/skills/spec-wiki/evals/files/query/features/jobs/retry-spec.md +0 -6
- package/skills/spec-wiki/evals/maintenance_regression.py +0 -311
- package/skills/spec-wiki/evals/retrieval-eval.md +0 -37
- package/skills/spec-wiki/evals/retrieval-evals.json +0 -37
- package/skills/spec-wiki/evals/trigger-evals.json +0 -94
- package/skills/spec-wiki/references/bootstrap.md +0 -100
- package/skills/spec-wiki/references/focused-spec.md +0 -117
- package/skills/spec-wiki/references/index-schema.md +0 -330
- package/skills/spec-wiki/references/maintenance.md +0 -134
- package/skills/spec-wiki/references/query.md +0 -74
- package/skills/spec-wiki/scripts/spec_wiki.py +0 -2076
- /package/external/pi-tools-suite/src/async-subagents/agents/{browser-qa → ui-qa/browser}/examples/qa-auth.example.jsonc +0 -0
- /package/external/pi-tools-suite/src/async-subagents/agents/{browser-qa → ui-qa/browser}/examples/qa-flow.example.jsonc +0 -0
- /package/external/pi-tools-suite/src/async-subagents/agents/{browser-qa → ui-qa/browser}/vendor/fflate.LICENSE +0 -0
- /package/external/pi-tools-suite/src/async-subagents/agents/{browser-qa → ui-qa/browser}/vendor/fflate.mjs +0 -0
|
@@ -32,6 +32,7 @@ export class AppTabsController {
|
|
|
32
32
|
tabIdsNeedingHistoryReload = new Set();
|
|
33
33
|
historyInvalidationGenerationByTabId = new Map();
|
|
34
34
|
runtimeOwnershipGenerationByTabId = new Map();
|
|
35
|
+
touchedDraftTabIds = new Set();
|
|
35
36
|
orphanRuntimeDisposals = new WeakSet();
|
|
36
37
|
lifecycleMutationQueue = [];
|
|
37
38
|
activeTabId;
|
|
@@ -42,6 +43,9 @@ export class AppTabsController {
|
|
|
42
43
|
lifecycleGeneration = 0;
|
|
43
44
|
lifecycleMutationRunning = false;
|
|
44
45
|
saveTabsWriteTail = Promise.resolve();
|
|
46
|
+
startupSavedTabs;
|
|
47
|
+
startupPrepared = false;
|
|
48
|
+
startupRuntimePlan;
|
|
45
49
|
restored = false;
|
|
46
50
|
retentionCleanupRunning = false;
|
|
47
51
|
retentionCleanupScheduled = false;
|
|
@@ -127,6 +131,22 @@ export class AppTabsController {
|
|
|
127
131
|
this.syncActiveTabFromRuntime({ save: false });
|
|
128
132
|
return this.activeTabId;
|
|
129
133
|
}
|
|
134
|
+
isDraftTabActive() {
|
|
135
|
+
return this.activeTab()?.draft === true;
|
|
136
|
+
}
|
|
137
|
+
openSessionPaths() {
|
|
138
|
+
return this.tabItems.flatMap((tab) => tab.sessionPath ? [resolve(tab.sessionPath)] : []);
|
|
139
|
+
}
|
|
140
|
+
noteActiveDraftInputChanged() {
|
|
141
|
+
const tab = this.activeTab();
|
|
142
|
+
if (!tab?.draft)
|
|
143
|
+
return;
|
|
144
|
+
const input = this.host.captureInputState();
|
|
145
|
+
if (input.text.length === 0 && (input.attachments?.length ?? 0) === 0)
|
|
146
|
+
return;
|
|
147
|
+
this.touchedDraftTabIds.add(tab.id);
|
|
148
|
+
this.host.closeDraftSessionSelector?.();
|
|
149
|
+
}
|
|
130
150
|
inputStateForTab(tabId) {
|
|
131
151
|
if (!tabId)
|
|
132
152
|
return this.host.captureInputState();
|
|
@@ -233,6 +253,26 @@ export class AppTabsController {
|
|
|
233
253
|
if (options.save !== false)
|
|
234
254
|
void this.saveTabs();
|
|
235
255
|
}
|
|
256
|
+
async prepareStartupRuntime() {
|
|
257
|
+
if (this.startupPrepared)
|
|
258
|
+
return this.startupRuntimePlan ?? null;
|
|
259
|
+
this.startupPrepared = true;
|
|
260
|
+
if (this.host.options.noSession) {
|
|
261
|
+
this.startupRuntimePlan = {};
|
|
262
|
+
return this.startupRuntimePlan;
|
|
263
|
+
}
|
|
264
|
+
if (this.host.options.sessionPath) {
|
|
265
|
+
this.startupRuntimePlan = { sessionPath: resolve(this.host.options.sessionPath) };
|
|
266
|
+
return this.startupRuntimePlan;
|
|
267
|
+
}
|
|
268
|
+
const saved = await this.loadTabs();
|
|
269
|
+
this.startupSavedTabs = saved ?? null;
|
|
270
|
+
const paths = saved?.tabs.map((tab) => resolve(tab.path)).filter((path) => existsSync(path)) ?? [];
|
|
271
|
+
const activePath = saved?.activePath ? resolve(saved.activePath) : undefined;
|
|
272
|
+
const sessionPath = activePath && paths.includes(activePath) ? activePath : paths[0];
|
|
273
|
+
this.startupRuntimePlan = sessionPath ? { sessionPath } : null;
|
|
274
|
+
return this.startupRuntimePlan;
|
|
275
|
+
}
|
|
236
276
|
restoreAfterStartup() {
|
|
237
277
|
return this.runLifecycleMutation((generation) => this.restoreAfterStartupMutation(generation));
|
|
238
278
|
}
|
|
@@ -241,15 +281,24 @@ export class AppTabsController {
|
|
|
241
281
|
return;
|
|
242
282
|
this.restored = true;
|
|
243
283
|
const runtime = this.host.runtime();
|
|
244
|
-
|
|
284
|
+
const saved = this.startupSavedTabs === undefined
|
|
285
|
+
? await this.loadTabs()
|
|
286
|
+
: this.startupSavedTabs ?? undefined;
|
|
287
|
+
if (!runtime) {
|
|
288
|
+
if (this.host.options.noSession)
|
|
289
|
+
return;
|
|
290
|
+
const draft = this.createDraftTab();
|
|
291
|
+
this.tabItems.splice(0, this.tabItems.length, draft);
|
|
292
|
+
this.activateDraftTab(draft, { resetInput: true, openSelector: true });
|
|
293
|
+
await this.saveTabs();
|
|
245
294
|
return;
|
|
295
|
+
}
|
|
246
296
|
const startupSession = runtime.session;
|
|
247
297
|
this.syncActiveTabFromRuntime({ save: false });
|
|
248
298
|
if (this.host.options.noSession) {
|
|
249
299
|
this.clearStartupTabPlaceholders();
|
|
250
300
|
return;
|
|
251
301
|
}
|
|
252
|
-
const saved = await this.loadTabs();
|
|
253
302
|
if (!this.isLifecycleOwner(generation, runtime, startupSession)) {
|
|
254
303
|
this.syncActiveTabFromRuntime({ save: false, force: true });
|
|
255
304
|
return;
|
|
@@ -366,139 +415,181 @@ export class AppTabsController {
|
|
|
366
415
|
this.host.showToast("Wait for the tab to finish loading", "info");
|
|
367
416
|
return;
|
|
368
417
|
}
|
|
369
|
-
|
|
370
|
-
|
|
418
|
+
if (this.host.options.noSession) {
|
|
419
|
+
this.host.showToast("/new_tab is unavailable with --no-session", "warning");
|
|
371
420
|
return;
|
|
372
|
-
|
|
421
|
+
}
|
|
422
|
+
const existingDraft = this.tabItems.find((tab) => tab.draft === true);
|
|
423
|
+
if (existingDraft) {
|
|
424
|
+
await this.switchToTabMutation(existingDraft.id, generation);
|
|
373
425
|
return;
|
|
426
|
+
}
|
|
427
|
+
const runtime = this.host.runtime();
|
|
374
428
|
this.cancelHistoryLoad();
|
|
375
|
-
|
|
376
|
-
|
|
429
|
+
if (runtime) {
|
|
430
|
+
this.syncActiveTabFromRuntime({ save: false });
|
|
431
|
+
this.storeActiveRuntime(runtime);
|
|
432
|
+
this.storeActiveSessionView();
|
|
433
|
+
}
|
|
377
434
|
this.storeActiveInputState();
|
|
378
435
|
this.storeActiveDeferredUserMessages();
|
|
379
|
-
const
|
|
380
|
-
const previousRuntime = runtime;
|
|
381
|
-
const previousSession = runtime.session;
|
|
382
|
-
const tab = {
|
|
383
|
-
id: createId("tab"),
|
|
384
|
-
title: "new",
|
|
385
|
-
titlePlaceholder: "new",
|
|
386
|
-
status: "active",
|
|
387
|
-
activity: "thinking",
|
|
388
|
-
};
|
|
436
|
+
const tab = this.createDraftTab();
|
|
389
437
|
this.tabItems.push(tab);
|
|
390
|
-
this.
|
|
438
|
+
this.activateDraftTab(tab, { resetInput: true, openSelector: true });
|
|
439
|
+
await this.saveTabs();
|
|
440
|
+
}
|
|
441
|
+
materializeActiveDraftTab() {
|
|
442
|
+
return this.runLifecycleMutation((generation) => this.materializeActiveDraftTabMutation(generation));
|
|
443
|
+
}
|
|
444
|
+
async materializeActiveDraftTabMutation(generation) {
|
|
445
|
+
if (this.pendingActiveTabId)
|
|
446
|
+
return undefined;
|
|
447
|
+
const tab = this.activeTab();
|
|
448
|
+
if (!tab?.draft)
|
|
449
|
+
return this.host.runtime();
|
|
450
|
+
if (this.host.options.noSession) {
|
|
451
|
+
this.host.showToast("A persisted session is unavailable with --no-session", "warning");
|
|
452
|
+
return undefined;
|
|
453
|
+
}
|
|
454
|
+
this.storeActiveInputState();
|
|
455
|
+
this.storeActiveDeferredUserMessages();
|
|
391
456
|
this.pendingActiveTabId = tab.id;
|
|
392
|
-
this.
|
|
393
|
-
this.
|
|
394
|
-
this.host.closeMenusForTabSwitch?.();
|
|
395
|
-
this.host.resetSessionView();
|
|
396
|
-
this.restoreDeferredUserMessages(tab.id);
|
|
457
|
+
this.host.closeDraftSessionSelector?.();
|
|
458
|
+
this.host.setStatus("starting new session");
|
|
397
459
|
this.host.setSessionActivity("thinking");
|
|
398
|
-
this.host.setStatus("starting new tab");
|
|
399
460
|
this.host.render();
|
|
400
461
|
let newRuntime;
|
|
401
462
|
try {
|
|
402
|
-
newRuntime = await this.host.createRuntimeForNewSession();
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
this.
|
|
408
|
-
this.
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
463
|
+
newRuntime = await this.host.createRuntimeForNewSession(this.host.draftModelOverrideRef?.());
|
|
464
|
+
if (!this.ownsDraftLifecycle(tab.id, generation)) {
|
|
465
|
+
await this.disposeRuntimeIfOrphan(newRuntime);
|
|
466
|
+
return undefined;
|
|
467
|
+
}
|
|
468
|
+
await this.host.activateRuntime(newRuntime, { awaitExtensions: false });
|
|
469
|
+
if (!this.ownsDraftLifecycle(tab.id, generation) || this.host.runtime() !== newRuntime) {
|
|
470
|
+
if (this.host.runtime() === newRuntime)
|
|
471
|
+
this.host.deactivateRuntimeForDraft?.();
|
|
472
|
+
await this.disposeRuntimeIfOrphan(newRuntime);
|
|
473
|
+
return undefined;
|
|
474
|
+
}
|
|
475
|
+
await this.host.awaitCurrentSessionExtensions?.(newRuntime);
|
|
476
|
+
if (!this.ownsDraftLifecycle(tab.id, generation) || this.host.runtime() !== newRuntime) {
|
|
477
|
+
if (this.host.runtime() === newRuntime)
|
|
478
|
+
this.host.deactivateRuntimeForDraft?.();
|
|
479
|
+
await this.disposeRuntimeIfOrphan(newRuntime);
|
|
480
|
+
return undefined;
|
|
481
|
+
}
|
|
482
|
+
this.pendingActiveTabId = undefined;
|
|
483
|
+
delete tab.draft;
|
|
484
|
+
delete tab.titlePlaceholder;
|
|
485
|
+
this.touchedDraftTabIds.delete(tab.id);
|
|
486
|
+
this.updateTabFromSession(tab, newRuntime.session);
|
|
487
|
+
this.setRuntimeForTab(tab.id, newRuntime);
|
|
488
|
+
this.host.closeDraftSessionSelector?.();
|
|
412
489
|
this.host.resetSessionView();
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
this.host.
|
|
416
|
-
this.
|
|
417
|
-
this.
|
|
490
|
+
this.restoreDeferredUserMessages(tab.id);
|
|
491
|
+
this.host.setSessionStatus(newRuntime.session);
|
|
492
|
+
this.host.setSessionActivity(this.sessionActivity(newRuntime.session));
|
|
493
|
+
void this.saveTabs();
|
|
494
|
+
this.scheduleProjectSessionRetention();
|
|
418
495
|
this.host.render();
|
|
419
|
-
|
|
496
|
+
return newRuntime;
|
|
420
497
|
}
|
|
421
|
-
|
|
498
|
+
catch {
|
|
499
|
+
if (newRuntime && this.host.runtime() === newRuntime)
|
|
500
|
+
this.host.deactivateRuntimeForDraft?.();
|
|
501
|
+
if (newRuntime)
|
|
502
|
+
await this.disposeRuntimeIfOrphan(newRuntime);
|
|
422
503
|
if (this.pendingActiveTabId === tab.id)
|
|
423
504
|
this.pendingActiveTabId = undefined;
|
|
424
|
-
this.
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
return;
|
|
505
|
+
if (this.tabItems.some((item) => item.id === tab.id) && this.activeTabId === tab.id) {
|
|
506
|
+
this.activateDraftTab(tab, { openSelector: !this.touchedDraftTabIds.has(tab.id) });
|
|
507
|
+
this.host.showToast("Could not start new conversation", "error");
|
|
508
|
+
}
|
|
509
|
+
return undefined;
|
|
429
510
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
this.pendingActiveTabId
|
|
436
|
-
|
|
437
|
-
this.
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
this.
|
|
511
|
+
}
|
|
512
|
+
openSessionInActiveDraftTab(sessionPath) {
|
|
513
|
+
return this.runLifecycleMutation((generation) => this.openSessionInActiveDraftTabMutation(sessionPath, generation));
|
|
514
|
+
}
|
|
515
|
+
async openSessionInActiveDraftTabMutation(sessionPath, generation) {
|
|
516
|
+
if (this.pendingActiveTabId)
|
|
517
|
+
return false;
|
|
518
|
+
const draft = this.activeTab();
|
|
519
|
+
if (!draft?.draft)
|
|
520
|
+
return false;
|
|
521
|
+
const resolvedSessionPath = resolve(this.host.options.cwd, sessionPath);
|
|
522
|
+
const existing = this.findTabBySessionPath(resolvedSessionPath);
|
|
523
|
+
if (existing) {
|
|
524
|
+
await this.switchDraftToPersistedTab(existing, generation);
|
|
525
|
+
if (this.activeTabId !== existing.id)
|
|
526
|
+
return false;
|
|
527
|
+
this.removeTab(draft.id);
|
|
528
|
+
this.inputStatesByTabId.delete(draft.id);
|
|
529
|
+
this.autoUserMessagesByTabId.delete(draft.id);
|
|
530
|
+
this.deferredUserMessagesByTabId.delete(draft.id);
|
|
531
|
+
this.touchedDraftTabIds.delete(draft.id);
|
|
532
|
+
void this.saveTabs();
|
|
533
|
+
return true;
|
|
534
|
+
}
|
|
535
|
+
this.cancelHistoryLoad();
|
|
536
|
+
this.storeActiveInputState();
|
|
537
|
+
this.pendingActiveTabId = draft.id;
|
|
538
|
+
this.host.closeDraftSessionSelector?.();
|
|
539
|
+
this.host.setStatus("opening session");
|
|
441
540
|
this.host.setSessionActivity("thinking");
|
|
442
541
|
this.host.render();
|
|
542
|
+
let targetRuntime;
|
|
443
543
|
try {
|
|
444
|
-
await this.host.
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
if (this.pendingActiveTabId === targetTab.id)
|
|
449
|
-
this.pendingActiveTabId = undefined;
|
|
450
|
-
if (targetTab === tab)
|
|
451
|
-
this.removeTab(tab.id);
|
|
452
|
-
this.activeTabId = previousTabId;
|
|
453
|
-
if (this.host.runtime() !== previousRuntime) {
|
|
454
|
-
try {
|
|
455
|
-
await this.host.activateRuntime(previousRuntime, { awaitExtensions: false });
|
|
456
|
-
}
|
|
457
|
-
catch {
|
|
458
|
-
// Keep the best available runtime and preserve the original activation error.
|
|
459
|
-
}
|
|
544
|
+
targetRuntime = await this.host.createRuntimeForSession(resolvedSessionPath);
|
|
545
|
+
if (!this.ownsDraftLifecycle(draft.id, generation)) {
|
|
546
|
+
await this.disposeRuntimeIfOrphan(targetRuntime);
|
|
547
|
+
return false;
|
|
460
548
|
}
|
|
461
|
-
await this.
|
|
462
|
-
if (this.
|
|
463
|
-
this.host.
|
|
464
|
-
|
|
465
|
-
this.
|
|
466
|
-
|
|
549
|
+
await this.host.activateRuntime(targetRuntime, { awaitExtensions: false });
|
|
550
|
+
if (!this.ownsDraftLifecycle(draft.id, generation) || this.host.runtime() !== targetRuntime) {
|
|
551
|
+
if (this.host.runtime() === targetRuntime)
|
|
552
|
+
this.host.deactivateRuntimeForDraft?.();
|
|
553
|
+
await this.disposeRuntimeIfOrphan(targetRuntime);
|
|
554
|
+
return false;
|
|
467
555
|
}
|
|
468
|
-
|
|
469
|
-
|
|
556
|
+
this.pendingActiveTabId = undefined;
|
|
557
|
+
delete draft.draft;
|
|
558
|
+
delete draft.titlePlaceholder;
|
|
559
|
+
this.touchedDraftTabIds.delete(draft.id);
|
|
560
|
+
this.updateTabFromSession(draft, targetRuntime.session);
|
|
561
|
+
this.setRuntimeForTab(draft.id, targetRuntime);
|
|
562
|
+
this.inputStatesByTabId.delete(draft.id);
|
|
563
|
+
this.autoUserMessagesByTabId.delete(draft.id);
|
|
564
|
+
this.deferredUserMessagesByTabId.delete(draft.id);
|
|
565
|
+
this.restoreInputState(draft.id);
|
|
470
566
|
this.host.closeMenusForTabSwitch?.();
|
|
471
|
-
this.
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
this.
|
|
475
|
-
|
|
476
|
-
this.host.setSessionActivity(this.sessionActivity(this.host.runtime()?.session));
|
|
477
|
-
this.host.render();
|
|
478
|
-
throw error;
|
|
567
|
+
void this.saveTabs();
|
|
568
|
+
this.scheduleProjectSessionRetention();
|
|
569
|
+
await this.loadActiveSessionHistory(targetRuntime, generation);
|
|
570
|
+
this.scheduleDelayedHistoryReload(draft.id, targetRuntime, generation);
|
|
571
|
+
return true;
|
|
479
572
|
}
|
|
480
|
-
|
|
481
|
-
this.
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
this.
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
this.host.setSessionActivity(this.sessionActivity(newRuntime.session));
|
|
501
|
-
this.host.render();
|
|
573
|
+
catch {
|
|
574
|
+
if (targetRuntime && this.host.runtime() === targetRuntime)
|
|
575
|
+
this.host.deactivateRuntimeForDraft?.();
|
|
576
|
+
if (targetRuntime)
|
|
577
|
+
await this.disposeRuntimeIfOrphan(targetRuntime);
|
|
578
|
+
if (this.pendingActiveTabId === draft.id)
|
|
579
|
+
this.pendingActiveTabId = undefined;
|
|
580
|
+
if (this.tabItems.some((item) => item.id === draft.id) && this.activeTabId === draft.id) {
|
|
581
|
+
this.activateDraftTab(draft, { openSelector: true });
|
|
582
|
+
this.host.showToast("Could not open conversation", "warning");
|
|
583
|
+
}
|
|
584
|
+
return false;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
ownsDraftLifecycle(tabId, generation) {
|
|
588
|
+
return this.host.isRunning()
|
|
589
|
+
&& generation === this.lifecycleGeneration
|
|
590
|
+
&& this.activeTabId === tabId
|
|
591
|
+
&& this.pendingActiveTabId === tabId
|
|
592
|
+
&& this.tabItems.some((tab) => tab.id === tabId && tab.draft === true);
|
|
502
593
|
}
|
|
503
594
|
openSessionInNewTab(sessionPath) {
|
|
504
595
|
return this.runLifecycleMutation((generation) => this.openSessionInNewTabMutation(sessionPath, generation));
|
|
@@ -781,17 +872,34 @@ export class AppTabsController {
|
|
|
781
872
|
}
|
|
782
873
|
if (tabId === this.activeTabId)
|
|
783
874
|
return;
|
|
784
|
-
const runtime = this.runtimeForCommand("tab switch");
|
|
785
|
-
if (!runtime)
|
|
786
|
-
return;
|
|
787
|
-
this.syncActiveTabFromRuntime({ save: false });
|
|
788
875
|
const target = this.tabItems.find((tab) => tab.id === tabId);
|
|
789
876
|
if (!target)
|
|
790
877
|
return;
|
|
878
|
+
if (target.draft) {
|
|
879
|
+
const runtime = this.host.runtime();
|
|
880
|
+
if (runtime) {
|
|
881
|
+
this.syncActiveTabFromRuntime({ save: false });
|
|
882
|
+
this.storeActiveRuntime(runtime);
|
|
883
|
+
this.storeActiveSessionView();
|
|
884
|
+
}
|
|
885
|
+
this.storeActiveInputState();
|
|
886
|
+
this.storeActiveDeferredUserMessages();
|
|
887
|
+
this.activateDraftTab(target, { openSelector: !this.touchedDraftTabIds.has(target.id) });
|
|
888
|
+
await this.saveTabs();
|
|
889
|
+
return;
|
|
890
|
+
}
|
|
791
891
|
if (!target.sessionPath) {
|
|
792
892
|
this.host.showToast("Tab has no persisted session path", "warning");
|
|
793
893
|
return;
|
|
794
894
|
}
|
|
895
|
+
if (this.activeTab()?.draft) {
|
|
896
|
+
await this.switchDraftToPersistedTab(target, generation);
|
|
897
|
+
return;
|
|
898
|
+
}
|
|
899
|
+
const runtime = this.runtimeForCommand("tab switch");
|
|
900
|
+
if (!runtime)
|
|
901
|
+
return;
|
|
902
|
+
this.syncActiveTabFromRuntime({ save: false });
|
|
795
903
|
this.cancelHistoryLoad();
|
|
796
904
|
const previousTabId = this.activeTabId;
|
|
797
905
|
const previousRuntime = runtime;
|
|
@@ -876,6 +984,84 @@ export class AppTabsController {
|
|
|
876
984
|
}
|
|
877
985
|
this.scheduleDelayedHistoryReload(target.id, targetRuntime, generation);
|
|
878
986
|
}
|
|
987
|
+
async switchDraftToPersistedTab(target, generation) {
|
|
988
|
+
const draft = this.activeTab();
|
|
989
|
+
if (!draft?.draft || !target.sessionPath)
|
|
990
|
+
return;
|
|
991
|
+
this.cancelHistoryLoad();
|
|
992
|
+
this.storeActiveInputState();
|
|
993
|
+
this.storeActiveDeferredUserMessages();
|
|
994
|
+
this.pendingActiveTabId = target.id;
|
|
995
|
+
const previousTargetActivity = target.activity;
|
|
996
|
+
target.activity = "thinking";
|
|
997
|
+
this.clearTabAttention(target);
|
|
998
|
+
this.host.closeDraftSessionSelector?.();
|
|
999
|
+
this.host.setStatus("switching tab");
|
|
1000
|
+
this.host.setSessionActivity("thinking");
|
|
1001
|
+
this.host.render();
|
|
1002
|
+
let targetRuntime;
|
|
1003
|
+
try {
|
|
1004
|
+
targetRuntime = await this.runtimeForTab(target);
|
|
1005
|
+
if (!targetRuntime)
|
|
1006
|
+
throw new Error("Could not load tab runtime");
|
|
1007
|
+
if (generation !== this.lifecycleGeneration
|
|
1008
|
+
|| this.activeTabId !== draft.id
|
|
1009
|
+
|| this.pendingActiveTabId !== target.id)
|
|
1010
|
+
throw new Error("Tab ownership changed while loading the runtime");
|
|
1011
|
+
await this.host.activateRuntime(targetRuntime, { awaitExtensions: false });
|
|
1012
|
+
}
|
|
1013
|
+
catch {
|
|
1014
|
+
if (this.pendingActiveTabId === target.id)
|
|
1015
|
+
this.pendingActiveTabId = undefined;
|
|
1016
|
+
if (previousTargetActivity === undefined)
|
|
1017
|
+
delete target.activity;
|
|
1018
|
+
else
|
|
1019
|
+
target.activity = previousTargetActivity;
|
|
1020
|
+
if (targetRuntime && this.host.runtime() === targetRuntime)
|
|
1021
|
+
this.host.deactivateRuntimeForDraft?.();
|
|
1022
|
+
if (targetRuntime)
|
|
1023
|
+
await this.disposeRuntimeIfOrphan(targetRuntime);
|
|
1024
|
+
this.activateDraftTab(draft, { openSelector: !this.touchedDraftTabIds.has(draft.id) });
|
|
1025
|
+
this.host.showToast("Could not switch tab", "warning");
|
|
1026
|
+
return;
|
|
1027
|
+
}
|
|
1028
|
+
if (this.pendingActiveTabId === target.id)
|
|
1029
|
+
this.pendingActiveTabId = undefined;
|
|
1030
|
+
this.activeTabId = target.id;
|
|
1031
|
+
this.clearTabAttention(target);
|
|
1032
|
+
this.updateTabFromSession(target, targetRuntime.session);
|
|
1033
|
+
this.setRuntimeForTab(target.id, targetRuntime);
|
|
1034
|
+
this.restoreInputState(target.id);
|
|
1035
|
+
this.host.closeMenusForTabSwitch?.();
|
|
1036
|
+
void this.saveTabs();
|
|
1037
|
+
this.scheduleTabPrewarm();
|
|
1038
|
+
const cachedView = this.sessionViewsByTabId.get(target.id);
|
|
1039
|
+
const cachedViewNeedsHistoryReload = this.tabIdsNeedingHistoryReload.has(target.id);
|
|
1040
|
+
const restoreCachedView = () => {
|
|
1041
|
+
if (!cachedView || !this.host.restoreSessionView)
|
|
1042
|
+
return false;
|
|
1043
|
+
if (this.activeTabId !== target.id || this.host.runtime() !== targetRuntime)
|
|
1044
|
+
return false;
|
|
1045
|
+
this.host.restoreSessionView(cachedView);
|
|
1046
|
+
this.restoreDeferredUserMessages(target.id);
|
|
1047
|
+
this.host.setSessionStatus(targetRuntime.session);
|
|
1048
|
+
this.host.setSessionActivity(this.sessionActivity(targetRuntime.session));
|
|
1049
|
+
this.host.render();
|
|
1050
|
+
return true;
|
|
1051
|
+
};
|
|
1052
|
+
if (cachedView && !cachedViewNeedsHistoryReload) {
|
|
1053
|
+
restoreCachedView();
|
|
1054
|
+
}
|
|
1055
|
+
else {
|
|
1056
|
+
const loaded = await this.loadActiveSessionHistory(targetRuntime, generation);
|
|
1057
|
+
// Returning from a transient draft must never strand a real tab on the
|
|
1058
|
+
// blank view used by the draft. If a stale-history refresh is cancelled
|
|
1059
|
+
// or fails, fall back to the snapshot captured when the draft opened.
|
|
1060
|
+
if (!loaded)
|
|
1061
|
+
restoreCachedView();
|
|
1062
|
+
}
|
|
1063
|
+
this.scheduleDelayedHistoryReload(target.id, targetRuntime, generation);
|
|
1064
|
+
}
|
|
879
1065
|
closeTab(tabId) {
|
|
880
1066
|
return this.runLifecycleMutation((generation) => this.closeTabMutation(tabId, generation));
|
|
881
1067
|
}
|
|
@@ -887,6 +1073,13 @@ export class AppTabsController {
|
|
|
887
1073
|
const index = this.tabItems.findIndex((tab) => tab.id === tabId);
|
|
888
1074
|
if (index < 0)
|
|
889
1075
|
return;
|
|
1076
|
+
const closingTab = this.tabItems[index];
|
|
1077
|
+
if (closingTab?.draft) {
|
|
1078
|
+
if (this.tabItems.length <= 1)
|
|
1079
|
+
return;
|
|
1080
|
+
await this.closeDraftTabMutation(closingTab, index, generation);
|
|
1081
|
+
return;
|
|
1082
|
+
}
|
|
890
1083
|
this.cancelHistoryLoad();
|
|
891
1084
|
if (this.tabItems.length <= 1) {
|
|
892
1085
|
await this.replaceLastTabWithNewSession(tabId, generation);
|
|
@@ -974,6 +1167,48 @@ export class AppTabsController {
|
|
|
974
1167
|
this.scheduleTabPrewarm();
|
|
975
1168
|
await this.loadActiveSessionHistory(nextRuntime, generation);
|
|
976
1169
|
}
|
|
1170
|
+
async closeDraftTabMutation(tab, index, generation) {
|
|
1171
|
+
this.cancelHistoryLoad();
|
|
1172
|
+
if (tab.id !== this.activeTabId) {
|
|
1173
|
+
this.removeTab(tab.id);
|
|
1174
|
+
this.inputStatesByTabId.delete(tab.id);
|
|
1175
|
+
this.autoUserMessagesByTabId.delete(tab.id);
|
|
1176
|
+
this.deferredUserMessagesByTabId.delete(tab.id);
|
|
1177
|
+
this.touchedDraftTabIds.delete(tab.id);
|
|
1178
|
+
await this.saveTabs();
|
|
1179
|
+
this.host.render();
|
|
1180
|
+
return;
|
|
1181
|
+
}
|
|
1182
|
+
const nextTab = this.tabItems[index + 1] ?? this.tabItems[index - 1];
|
|
1183
|
+
if (nextTab?.sessionPath) {
|
|
1184
|
+
await this.switchDraftToPersistedTab(nextTab, generation);
|
|
1185
|
+
if (this.activeTabId !== nextTab.id)
|
|
1186
|
+
return;
|
|
1187
|
+
this.removeTab(tab.id);
|
|
1188
|
+
this.inputStatesByTabId.delete(tab.id);
|
|
1189
|
+
this.autoUserMessagesByTabId.delete(tab.id);
|
|
1190
|
+
this.deferredUserMessagesByTabId.delete(tab.id);
|
|
1191
|
+
this.touchedDraftTabIds.delete(tab.id);
|
|
1192
|
+
await this.saveTabs();
|
|
1193
|
+
this.host.render();
|
|
1194
|
+
return;
|
|
1195
|
+
}
|
|
1196
|
+
this.removeTab(tab.id);
|
|
1197
|
+
this.inputStatesByTabId.delete(tab.id);
|
|
1198
|
+
this.autoUserMessagesByTabId.delete(tab.id);
|
|
1199
|
+
this.deferredUserMessagesByTabId.delete(tab.id);
|
|
1200
|
+
this.touchedDraftTabIds.delete(tab.id);
|
|
1201
|
+
this.activeTabId = undefined;
|
|
1202
|
+
this.host.closeDraftSessionSelector?.();
|
|
1203
|
+
this.host.deactivateRuntimeForDraft?.();
|
|
1204
|
+
this.host.restoreInputState({ text: "", cursor: 0 });
|
|
1205
|
+
this.host.resetSessionView();
|
|
1206
|
+
this.host.setSessionStatus(undefined);
|
|
1207
|
+
this.host.setSessionActivity("idle");
|
|
1208
|
+
this.host.setStatus("no conversation");
|
|
1209
|
+
await this.saveTabs();
|
|
1210
|
+
this.host.render();
|
|
1211
|
+
}
|
|
977
1212
|
async replaceLastTabWithNewSession(tabId, generation) {
|
|
978
1213
|
const tab = this.tabItems.find((item) => item.id === tabId);
|
|
979
1214
|
if (!tab)
|
|
@@ -981,52 +1216,66 @@ export class AppTabsController {
|
|
|
981
1216
|
const runtime = this.idleRuntime("new");
|
|
982
1217
|
if (!runtime)
|
|
983
1218
|
return;
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
1219
|
+
if (this.host.options.noSession) {
|
|
1220
|
+
const session = runtime.session;
|
|
1221
|
+
this.activeTabId = tab.id;
|
|
1222
|
+
this.pendingActiveTabId = tab.id;
|
|
1223
|
+
this.host.setStatus("starting new session");
|
|
1224
|
+
this.host.render();
|
|
1225
|
+
let result;
|
|
1226
|
+
try {
|
|
1227
|
+
await this.host.awaitCurrentSessionExtensions?.(runtime);
|
|
1228
|
+
if (!this.isLifecycleOwner(generation, runtime, session))
|
|
1229
|
+
return;
|
|
1230
|
+
result = await runtime.newSession();
|
|
1231
|
+
}
|
|
1232
|
+
finally {
|
|
1233
|
+
if (this.pendingActiveTabId === tab.id)
|
|
1234
|
+
this.pendingActiveTabId = undefined;
|
|
1235
|
+
}
|
|
1236
|
+
if (result.cancelled) {
|
|
1237
|
+
this.host.addEntry({ id: createId("system"), kind: "system", text: "New session cancelled." });
|
|
1238
|
+
this.host.setSessionStatus(runtime.session);
|
|
1239
|
+
this.host.setSessionActivity(this.sessionActivity(runtime.session));
|
|
1240
|
+
this.host.render();
|
|
993
1241
|
return;
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
this.
|
|
1242
|
+
}
|
|
1243
|
+
this.clearTabAttention(tab);
|
|
1244
|
+
this.updateTabFromSession(tab, runtime.session);
|
|
1245
|
+
this.setRuntimeForTab(tab.id, runtime);
|
|
1246
|
+
this.inputStatesByTabId.delete(tab.id);
|
|
1247
|
+
this.autoUserMessagesByTabId.delete(tab.id);
|
|
1248
|
+
this.deferredUserMessagesByTabId.delete(tab.id);
|
|
1249
|
+
this.restoreInputState(tab.id);
|
|
1250
|
+
this.host.closeMenusForTabSwitch?.();
|
|
1251
|
+
this.stopAttentionBlinkIfIdle();
|
|
1252
|
+
this.host.resetSessionView();
|
|
1253
|
+
this.restoreDeferredUserMessages(tab.id);
|
|
1254
|
+
this.host.addEntry({ id: createId("system"), kind: "system", text: `Started a new session. cwd=${runtime.cwd}` });
|
|
1002
1255
|
this.host.setSessionStatus(runtime.session);
|
|
1003
1256
|
this.host.setSessionActivity(this.sessionActivity(runtime.session));
|
|
1257
|
+
void this.saveTabs();
|
|
1004
1258
|
this.host.render();
|
|
1005
1259
|
return;
|
|
1006
1260
|
}
|
|
1007
|
-
this.
|
|
1008
|
-
|
|
1009
|
-
this.
|
|
1261
|
+
if (!this.isLifecycleOwner(generation, runtime, runtime.session))
|
|
1262
|
+
return;
|
|
1263
|
+
this.host.deactivateRuntimeForDraft?.();
|
|
1264
|
+
this.deleteRuntimeForTab(tab.id);
|
|
1265
|
+
await this.host.disposeRuntime(runtime).catch(() => undefined);
|
|
1266
|
+
tab.title = "new";
|
|
1267
|
+
tab.titlePlaceholder = "new";
|
|
1268
|
+
tab.draft = true;
|
|
1269
|
+
delete tab.isFork;
|
|
1270
|
+
delete tab.sessionPath;
|
|
1271
|
+
tab.activity = "idle";
|
|
1272
|
+
this.touchedDraftTabIds.delete(tab.id);
|
|
1010
1273
|
this.inputStatesByTabId.delete(tab.id);
|
|
1011
1274
|
this.autoUserMessagesByTabId.delete(tab.id);
|
|
1012
1275
|
this.deferredUserMessagesByTabId.delete(tab.id);
|
|
1013
|
-
this.restoreInputState(tab.id);
|
|
1014
|
-
this.host.closeMenusForTabSwitch?.();
|
|
1015
1276
|
this.stopAttentionBlinkIfIdle();
|
|
1016
|
-
this.
|
|
1017
|
-
this.
|
|
1018
|
-
this.host.addEntry({ id: createId("system"), kind: "system", text: `Started a new session. cwd=${runtime.cwd}` });
|
|
1019
|
-
if (runtime.modelFallbackMessage)
|
|
1020
|
-
this.host.addEntry({ id: createId("system"), kind: "system", text: runtime.modelFallbackMessage });
|
|
1021
|
-
for (const diag of runtime.diagnostics ?? []) {
|
|
1022
|
-
const kind = diag.type === "error" ? "error" : "system";
|
|
1023
|
-
this.host.addEntry({ id: createId("system"), kind, text: `[${diag.type}] ${diag.message}` });
|
|
1024
|
-
}
|
|
1025
|
-
this.host.setSessionStatus(runtime.session);
|
|
1026
|
-
this.host.setSessionActivity(this.sessionActivity(runtime.session));
|
|
1027
|
-
void this.saveTabs();
|
|
1028
|
-
this.scheduleProjectSessionRetention();
|
|
1029
|
-
this.host.render();
|
|
1277
|
+
this.activateDraftTab(tab, { resetInput: true, openSelector: true });
|
|
1278
|
+
await this.saveTabs();
|
|
1030
1279
|
}
|
|
1031
1280
|
async loadActiveSessionHistory(runtime, lifecycleGeneration) {
|
|
1032
1281
|
const tabId = this.activeTabId;
|
|
@@ -1105,6 +1354,48 @@ export class AppTabsController {
|
|
|
1105
1354
|
activeTab() {
|
|
1106
1355
|
return this.activeTabId ? this.tabItems.find((tab) => tab.id === this.activeTabId) : undefined;
|
|
1107
1356
|
}
|
|
1357
|
+
createDraftTab() {
|
|
1358
|
+
return {
|
|
1359
|
+
id: createId("tab"),
|
|
1360
|
+
title: "new",
|
|
1361
|
+
titlePlaceholder: "new",
|
|
1362
|
+
draft: true,
|
|
1363
|
+
status: "active",
|
|
1364
|
+
activity: "idle",
|
|
1365
|
+
};
|
|
1366
|
+
}
|
|
1367
|
+
activateDraftTab(tab, options = {}) {
|
|
1368
|
+
this.cancelHistoryLoad();
|
|
1369
|
+
// Draft activation must be atomic from the renderer's point of view.
|
|
1370
|
+
// Host cleanup (extension UI / voice / runtime teardown) may synchronously
|
|
1371
|
+
// render. While that is happening, keep the draft as the pending target so
|
|
1372
|
+
// tabs() cannot resync the old still-attached runtime back into activeTabId.
|
|
1373
|
+
this.pendingActiveTabId = tab.id;
|
|
1374
|
+
this.activeTabId = tab.id;
|
|
1375
|
+
this.clearTabAttention(tab);
|
|
1376
|
+
if (options.resetInput) {
|
|
1377
|
+
this.inputStatesByTabId.delete(tab.id);
|
|
1378
|
+
this.autoUserMessagesByTabId.delete(tab.id);
|
|
1379
|
+
this.deferredUserMessagesByTabId.delete(tab.id);
|
|
1380
|
+
this.touchedDraftTabIds.delete(tab.id);
|
|
1381
|
+
this.host.resetDraftModelSelection?.();
|
|
1382
|
+
}
|
|
1383
|
+
this.restoreInputState(tab.id);
|
|
1384
|
+
this.host.closeMenusForTabSwitch?.();
|
|
1385
|
+
this.host.resetSessionView();
|
|
1386
|
+
this.restoreDeferredUserMessages(tab.id);
|
|
1387
|
+
this.host.deactivateRuntimeForDraft?.();
|
|
1388
|
+
this.host.setSessionStatus(undefined);
|
|
1389
|
+
this.host.setSessionActivity("idle");
|
|
1390
|
+
this.host.setStatus("new conversation");
|
|
1391
|
+
if (options.openSelector !== false && !this.touchedDraftTabIds.has(tab.id))
|
|
1392
|
+
this.host.openDraftSessionSelector?.();
|
|
1393
|
+
else
|
|
1394
|
+
this.host.closeDraftSessionSelector?.();
|
|
1395
|
+
if (this.pendingActiveTabId === tab.id)
|
|
1396
|
+
this.pendingActiveTabId = undefined;
|
|
1397
|
+
this.host.render();
|
|
1398
|
+
}
|
|
1108
1399
|
clearStartupTabPlaceholders() {
|
|
1109
1400
|
for (const tab of this.tabItems) {
|
|
1110
1401
|
delete tab.titlePlaceholder;
|
|
@@ -1850,8 +2141,6 @@ export class AppTabsController {
|
|
|
1850
2141
|
}
|
|
1851
2142
|
tabs.push(persistedTab);
|
|
1852
2143
|
}
|
|
1853
|
-
if (tabs.length === 0)
|
|
1854
|
-
return Promise.resolve();
|
|
1855
2144
|
const activePath = this.activeTab()?.sessionPath;
|
|
1856
2145
|
const payload = JSON.stringify({
|
|
1857
2146
|
version: TAB_STATE_VERSION,
|