Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,063 changes: 1,063 additions & 0 deletions docs/superpowers/plans/2026-05-07-tabs-registry-compact-state.md

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { getNetworkHost } from './get-network-host.js'
import { PortForwardManager } from './port-forward.js'
import { parseTrustProxyEnv } from './request-ip.js'
import { createTabsRegistryStore } from './tabs-registry/store.js'
import { createTabsSyncRouter } from './tabs-registry/client-retire-router.js'
import { checkForUpdate, createCachedUpdateChecker } from './updater/version-checker.js'
import { SessionAssociationCoordinator } from './session-association-coordinator.js'
import { broadcastTerminalSessionAssociation } from './session-association-broadcast.js'
Expand Down Expand Up @@ -188,7 +189,8 @@ async function main() {
const sessionMetadataStore = new SessionMetadataStore(freshellConfigDir)
const codingCliIndexer = new CodingCliSessionIndexer(codingCliProviders, {}, sessionMetadataStore)
const codingCliSessionManager = new CodingCliSessionManager(codingCliProviders)
const tabsRegistryStore = createTabsRegistryStore()
const tabsRegistryStore = await createTabsRegistryStore()
app.use('/api/tabs-sync', createTabsSyncRouter({ tabsRegistryStore }))

const settings = migrateSettingsSortMode(await configStore.getSettings())
AI_CONFIG.applySettingsKey(settings.ai?.geminiApiKey)
Expand Down
4 changes: 2 additions & 2 deletions server/mcp/freshell-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ FRESHELL_URL and FRESHELL_TOKEN are already set in your environment.
## Key gotchas

- **Tab and pane IDs are ephemeral.** IDs from open-browser, new-tab, and split-pane are valid only within the current session. If the Freshell server restarts or the agent conversation resumes after a disconnect, previously returned IDs may no longer exist. Always call open-browser or list-tabs fresh rather than reusing stale IDs.
- **Always screenshot with `screenshot({ scope: "tab", target: tabId })` after open-browser.** Network errors, CORS issues, or server problems can cause blank pages. open-browser returns a tabId — use it immediately to screenshot and confirm the page rendered before proceeding.
- **Always screenshot with \`screenshot({ scope: "tab", target: tabId })\` after open-browser.** Network errors, CORS issues, or server problems can cause blank pages. open-browser returns a tabId — use it immediately to screenshot and confirm the page rendered before proceeding.
- send-keys: use literal mode (literal: true + keys as a string) for natural-language prompts or multi-word text. Do NOT append "ENTER" as literal text -- send the command with literal:true, then send ["ENTER"] as a separate call in token mode.
- wait-for with stable (seconds of no output) is more reliable than pattern matching across different CLI providers.
- Editor panes show "Loading..." until the tab is visited in the browser. When screenshotting multiple tabs, visit each tab first (select-tab), then loop back for screenshots.
Expand Down Expand Up @@ -469,7 +469,7 @@ Meta:

## Screenshot guidance

- **Always screenshot with `screenshot({ scope: "tab", target: tabId })` after open-browser.** Network errors, blank pages, and CORS failures are silent unless you look. open-browser returns a tabId — use it immediately to confirm the page rendered before acting on it.
- **Always screenshot with \`screenshot({ scope: "tab", target: tabId })\` after open-browser.** Network errors, blank pages, and CORS failures are silent unless you look. open-browser returns a tabId — use it immediately to confirm the page rendered before acting on it.
- Tab and pane IDs from earlier in a session may become stale after reconnections or server restarts. If screenshot fails to find a tab/pane, call list-tabs or list-panes to get fresh IDs rather than reusing old ones.
- Use a dedicated canary tab when validating screenshot behavior so live project panes are not contaminated.
- Close temporary tabs/panes after verification unless user asked to keep them open.
Expand Down
42 changes: 42 additions & 0 deletions server/tabs-registry/client-retire-router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Router } from 'express'
import { z } from 'zod'

import type { TabsRegistryStore } from './store.js'

const TabsSyncClientRetireBodySchema = z.object({
deviceId: z.string().min(1),
clientInstanceId: z.string().min(1),
snapshotRevision: z.number().int().nonnegative(),
}).strict()

export function createTabsSyncRouter(deps: {
tabsRegistryStore: Pick<TabsRegistryStore, 'retireClientSnapshot'>
}): Router {
const router = Router()

router.post('/client-retire', async (req, res) => {
const parsed = TabsSyncClientRetireBodySchema.safeParse(req.body)
if (!parsed.success) {
res.status(400).json({
error: 'Invalid tabs registry retire payload',
details: parsed.error.issues.map((issue) => ({
code: issue.code,
path: issue.path,
message: issue.message,
})),
})
return
}

try {
const result = await deps.tabsRegistryStore.retireClientSnapshot(parsed.data)
res.json({ ok: true, accepted: result.accepted })
} catch (error) {
res.status(400).json({
error: error instanceof Error ? error.message : String(error),
})
}
})

return router
}
Loading