Skip to content

Commit 5ce04d6

Browse files
feat(tmux): add pane spawn callbacks for background and sync sessions
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <[email protected]>
1 parent 57ec6e1 commit 5ce04d6

File tree

2 files changed

+66
-10
lines changed

2 files changed

+66
-10
lines changed

src/index.ts

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
9494
enabled: pluginConfig.tmux?.enabled ?? false,
9595
layout: pluginConfig.tmux?.layout ?? 'main-vertical',
9696
main_pane_size: pluginConfig.tmux?.main_pane_size ?? 60,
97+
main_pane_min_width: pluginConfig.tmux?.main_pane_min_width ?? 120,
98+
agent_pane_min_width: pluginConfig.tmux?.agent_pane_min_width ?? 40,
9799
} as const;
98100
const isHookEnabled = (hookName: HookName) => !disabledHooks.has(hookName);
99101

@@ -220,10 +222,30 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
220222

221223
const taskResumeInfo = createTaskResumeInfoHook();
222224

223-
const backgroundManager = new BackgroundManager(ctx, pluginConfig.background_task);
224-
225225
const tmuxSessionManager = new TmuxSessionManager(ctx, tmuxConfig);
226226

227+
const backgroundManager = new BackgroundManager(ctx, pluginConfig.background_task, {
228+
tmuxConfig,
229+
onSubagentSessionCreated: async (event) => {
230+
log("[index] onSubagentSessionCreated callback received", {
231+
sessionID: event.sessionID,
232+
parentID: event.parentID,
233+
title: event.title,
234+
});
235+
await tmuxSessionManager.onSessionCreated({
236+
type: "session.created",
237+
properties: {
238+
info: {
239+
id: event.sessionID,
240+
parentID: event.parentID,
241+
title: event.title,
242+
},
243+
},
244+
});
245+
log("[index] onSubagentSessionCreated callback completed");
246+
},
247+
});
248+
227249
const atlasHook = isHookEnabled("atlas")
228250
? createAtlasHook(ctx, { directory: ctx.directory, backgroundManager })
229251
: null;
@@ -261,6 +283,23 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
261283
gitMasterConfig: pluginConfig.git_master,
262284
sisyphusJuniorModel: pluginConfig.agents?.["sisyphus-junior"]?.model,
263285
browserProvider,
286+
onSyncSessionCreated: async (event) => {
287+
log("[index] onSyncSessionCreated callback", {
288+
sessionID: event.sessionID,
289+
parentID: event.parentID,
290+
title: event.title,
291+
});
292+
await tmuxSessionManager.onSessionCreated({
293+
type: "session.created",
294+
properties: {
295+
info: {
296+
id: event.sessionID,
297+
parentID: event.parentID,
298+
title: event.title,
299+
},
300+
},
301+
});
302+
},
264303
});
265304
const disabledSkills = new Set(pluginConfig.disabled_skills ?? []);
266305
const systemMcpNames = getSystemMcpServerNames();
@@ -445,17 +484,14 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
445484
const sessionInfo = props?.info as
446485
| { id?: string; title?: string; parentID?: string }
447486
| undefined;
487+
log("[event] session.created", { sessionInfo, props });
448488
if (!sessionInfo?.parentID) {
449489
setMainSession(sessionInfo?.id);
450490
}
451491
firstMessageVariantGate.markSessionCreated(sessionInfo);
452-
if (sessionInfo?.id && sessionInfo?.title) {
453-
await tmuxSessionManager.onSessionCreated({
454-
sessionID: sessionInfo.id,
455-
parentID: sessionInfo.parentID,
456-
title: sessionInfo.title,
457-
});
458-
}
492+
await tmuxSessionManager.onSessionCreated(
493+
event as { type: string; properties?: { info?: { id?: string; parentID?: string; title?: string } } }
494+
);
459495
}
460496

461497
if (event.type === "session.deleted") {

src/tools/delegate-task/tools.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ export function resolveCategoryConfig(
150150
return { config, promptAppend, model }
151151
}
152152

153+
export interface SyncSessionCreatedEvent {
154+
sessionID: string
155+
parentID: string
156+
title: string
157+
}
158+
153159
export interface DelegateTaskToolOptions {
154160
manager: BackgroundManager
155161
client: OpencodeClient
@@ -158,6 +164,7 @@ export interface DelegateTaskToolOptions {
158164
gitMasterConfig?: GitMasterConfig
159165
sisyphusJuniorModel?: string
160166
browserProvider?: BrowserAutomationProvider
167+
onSyncSessionCreated?: (event: SyncSessionCreatedEvent) => Promise<void>
161168
}
162169

163170
export interface BuildSystemContentInput {
@@ -180,7 +187,7 @@ export function buildSystemContent(input: BuildSystemContentInput): string | und
180187
}
181188

182189
export function createDelegateTask(options: DelegateTaskToolOptions): ToolDefinition {
183-
const { manager, client, directory, userCategories, gitMasterConfig, sisyphusJuniorModel, browserProvider } = options
190+
const { manager, client, directory, userCategories, gitMasterConfig, sisyphusJuniorModel, browserProvider, onSyncSessionCreated } = options
184191

185192
const allCategories = { ...DEFAULT_CATEGORIES, ...userCategories }
186193
const categoryNames = Object.keys(allCategories)
@@ -845,6 +852,19 @@ To continue this session: session_id="${task.sessionID}"`
845852
const sessionID = createResult.data.id
846853
syncSessionID = sessionID
847854
subagentSessions.add(sessionID)
855+
856+
if (onSyncSessionCreated) {
857+
log("[delegate_task] Invoking onSyncSessionCreated callback", { sessionID, parentID: ctx.sessionID })
858+
await onSyncSessionCreated({
859+
sessionID,
860+
parentID: ctx.sessionID,
861+
title: args.description,
862+
}).catch((err) => {
863+
log("[delegate_task] onSyncSessionCreated callback failed", { error: String(err) })
864+
})
865+
await new Promise(r => setTimeout(r, 200))
866+
}
867+
848868
taskId = `sync_${sessionID.slice(0, 8)}`
849869
const startTime = new Date()
850870

0 commit comments

Comments
 (0)