diff options
| author | Tianren Dong <tianrendong.dtr@gmail.com> | 2026-05-31 14:51:07 -0400 |
|---|---|---|
| committer | Tianren Dong <tianrendong.dtr@gmail.com> | 2026-05-31 14:51:07 -0400 |
| commit | 745d1eee66cf86305934e3ad57f7019ccb249a45 (patch) | |
| tree | f5564a93c442dfdc04e8414014bd8e2e0c9a5d4b /extensions/chrome-profile-bridge/index.ts | |
| parent | d57dc6583953fcb652db5bd222698d58d3090e20 (diff) | |
0.15.31: per-session tab groups named 'Pi Session <name-or-id>'
Diffstat (limited to 'extensions/chrome-profile-bridge/index.ts')
| -rw-r--r-- | extensions/chrome-profile-bridge/index.ts | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/extensions/chrome-profile-bridge/index.ts b/extensions/chrome-profile-bridge/index.ts index 7e34887..46a5a65 100644 --- a/extensions/chrome-profile-bridge/index.ts +++ b/extensions/chrome-profile-bridge/index.ts @@ -599,6 +599,14 @@ export default function (pi: ExtensionAPI): void { } }; + // Tab-group title for this Pi session: prefer the user-set display name, else the session id. + const sessionGroupTitle = (ctx: ExtensionContext): string => { + const sm = ctx.sessionManager; + const name = sm.getSessionName?.(); + const id = sm.getSessionId?.(); + return `Pi Session ${name || id || "unknown"}`; + }; + const updateChromeStatus = (ctx: ExtensionContext): void => { if (chromeControlAuthorized()) { ctx.ui.setStatus("chrome", ctx.ui.theme.fg("success", "●") + " Chrome Bridge"); @@ -1037,14 +1045,21 @@ Usage rules: targetId: Type.Optional(Type.String({ description: "Chrome tab id for activate/close/group/ungroup." })), urlIncludes: Type.Optional(Type.String({ description: "Match the target tab by URL substring for activate/close/group/ungroup." })), titleIncludes: Type.Optional(Type.String({ description: "Match the target tab by title substring for activate/close/group/ungroup." })), - group: Type.Optional(Type.Boolean({ description: "action=new only: pass false to open an ungrouped tab. By default every Pi-opened tab joins the window's 'Pi' tab group." })), - groupTitle: Type.Optional(Type.String({ description: "Tab group title for action=group (or action=new to open into a named group). Defaults to 'Pi'. Pass an empty string on action=new to opt out of grouping." })), + group: Type.Optional(Type.Boolean({ description: "action=new only: pass false to open an ungrouped tab. By default every Pi-opened tab joins this session's own tab group." })), + groupTitle: Type.Optional(Type.String({ description: "Tab group title for action=group/new. Defaults to this Pi session's group ('Pi Session <name-or-id>'). Pass an empty string on action=new to opt out of grouping." })), groupColor: Type.Optional(Type.String({ description: "Tab group color for action=group/new: grey, blue, red, yellow, green, pink, purple, cyan, or orange. Defaults to blue." })), host: Type.Optional(Type.String()), port: Type.Optional(Type.Number()), }), - async execute(_id, params, signal): Promise<ToolTextResult> { - const result = await authorizedBridgeSend(`tab.${params.action}`, params, DEFAULT_TIMEOUT_MS, signal); + async execute(_id, params, signal, _onUpdate, ctx): Promise<ToolTextResult> { + const forwarded = { ...params } as typeof params & { groupTitle?: string }; + // Default every Pi-opened/explicitly-grouped tab into this session's own group, + // named after the session display name (falling back to the session id), unless + // the caller specified a group title or opted out with group:false. + if ((params.action === "new" || params.action === "group") && params.groupTitle === undefined && params.group !== false) { + forwarded.groupTitle = sessionGroupTitle(ctx); + } + const result = await authorizedBridgeSend(`tab.${params.action}`, forwarded, DEFAULT_TIMEOUT_MS, signal); if (params.action === "list") { const tabs = result as Array<{ id: number; title: string; url: string; active: boolean; windowId: number; group?: { title?: string } | null }>; const text = tabs.map((tab) => `${tab.id}\t${tab.active ? "*" : " "}\t${tab.group?.title ? `[${tab.group.title}] ` : ""}${tab.title || "(untitled)"}\t${tab.url}`).join("\n") || "No tabs."; |
