Repository navigation
Expand file tree
/
Copy pathpreload.js
More file actions
313 lines (301 loc) · 20.6 KB
/
Copy pathpreload.js
File metadata and controls
313 lines (301 loc) · 20.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
const { contextBridge, ipcRenderer, webUtils } = require('electron');
contextBridge.exposeInMainWorld('api', {
getInitialTheme: () => ipcRenderer.sendSync('get-initial-theme'),
// Invoke (request-response)
getStatsFromDb: () => ipcRenderer.invoke('get-stats-from-db'),
refreshStats: () => ipcRenderer.invoke('refresh-stats'),
getUsage: () => ipcRenderer.invoke('get-usage'),
getCodexUsage: () => ipcRenderer.invoke('get-codex-usage'),
getMemories: () => ipcRenderer.invoke('get-memories'),
listSchedules: () => ipcRenderer.invoke('list-schedules'),
getScheduleHealth: () => ipcRenderer.invoke('get-schedule-health'),
setScheduleEnabled: (filePath, enabled) => ipcRenderer.invoke('set-schedule-enabled', filePath, enabled),
deleteScheduleFile: (filePath) => ipcRenderer.invoke('delete-schedule-file', filePath),
createScheduleFile: (projectPath, fields) => ipcRenderer.invoke('create-schedule-file', projectPath, fields),
readMemory: (filePath) => ipcRenderer.invoke('read-memory', filePath),
saveMemory: (filePath, content, expected) => ipcRenderer.invoke('save-memory', filePath, content, expected),
getIndexingState: () => ipcRenderer.invoke('get-indexing-state'),
getLastKnownProjects: () => ipcRenderer.invoke('get-last-known-projects'),
getProjects: async (showArchived) => {
const reply = await ipcRenderer.invoke('get-projects', showArchived);
if (reply?.projectsError?.code === 'PROJECTS_SNAPSHOT_CONFLICT'
&& reply.projectsError.message === 'Projects changed while loading; reload to retry.'
&& !Array.isArray(reply) && Object.keys(reply).length === 1 && Object.keys(reply.projectsError).length === 2) {
throw Object.assign(new Error(reply.projectsError.message), { code: reply.projectsError.code });
}
return reply;
},
sessionProjectionChanged: record => ipcRenderer.send('session-projection-changed', record),
reportTerminalBacklog: record => ipcRenderer.send('terminal-backlog', record),
onTerminalBacklogRequest: callback => ipcRenderer.on('terminal-backlog-request', (_event) => callback()),
rebuildCache: () => ipcRenderer.invoke('rebuild-cache'),
getActiveSessions: () => ipcRenderer.invoke('get-active-sessions'),
triggerActionsReady: () => ipcRenderer.invoke('trigger-actions-ready'),
triggerSessionActionResult: result => ipcRenderer.send('trigger-session-action-result', result),
onTriggerSessionAction: callback => {
const listener = (_event, payload) => callback(payload);
ipcRenderer.on('trigger-session-action', listener);
return () => ipcRenderer.removeListener('trigger-session-action', listener);
},
getSessionLiveElsewhere: (id) => ipcRenderer.invoke('session-live-elsewhere', id),
restartNoCliSession: (id) => ipcRenderer.invoke('restart-no-cli-session', id),
noCliRestartSpent: (id) => ipcRenderer.invoke('no-cli-restart-spent', id),
getSessionContinuations: (id) => ipcRenderer.invoke('session-continuations', id),
getSessionsLiveElsewhere: (ids) => ipcRenderer.invoke('sessions-live-elsewhere', ids),
getActiveTerminals: () => ipcRenderer.invoke('get-active-terminals'),
stopSession: (id) => ipcRenderer.invoke('stop-session', id),
sendSessionToBackground: (id, options) => ipcRenderer.invoke('send-session-to-background', id, options),
exitBackground: (id, detail, ids) => ipcRenderer.invoke('exit-background', id, detail, ids),
exitBackgroundCancel: (id, detail) => ipcRenderer.send('exit-background-cancel', id, detail),
onExitBackgroundProgress: callback => ipcRenderer.on('exit-background-progress', (_event, attempt, progress) => callback(attempt, progress)),
onBgContinuationChoice: callback => ipcRenderer.on('bg-continuation-choice', (_event, token, sessionId, jobs) => callback(token, sessionId, jobs)),
onBgContinuationChoiceCancel: callback => ipcRenderer.on('bg-continuation-choice-cancel', (_event, token) => callback(token)),
showBgContinuationChoice: token => ipcRenderer.send('bg-continuation-choice-shown', token),
answerBgContinuationChoice: (token, choice) => ipcRenderer.send('bg-continuation-choice-answer', token, choice),
onBgHandoffNotice: (callback) => ipcRenderer.on('bg-handoff-notice', (_event, sessionId, message) => callback(sessionId, message)),
// see .ai/contexts/bg-agents.md
getBgAgents: () => ipcRenderer.invoke('get-bg-agents'),
bgAgentVerb: (verb, id) => ipcRenderer.invoke('bg-agent-verb', verb, id),
checkBgAgentVerb: (verb, id) => ipcRenderer.invoke('check-bg-agent-verb', verb, id),
dispatchBgAgent: (fields) => ipcRenderer.invoke('dispatch-bg-agent', fields),
bgAgentLiveJob: (sessionId) => ipcRenderer.invoke('bg-agent-live-job', sessionId),
restoreBackgroundJob: (sessionId, options) => ipcRenderer.invoke('restore-background-job', sessionId, options),
// see .ai/contexts/session-state.md ("The two lifecycle verbs: detach and stop")
remoteStopSession: (alias, sessionId) => ipcRenderer.invoke('remote-stop-session', { alias, sessionId }),
remoteLaunchSession: (payload) => ipcRenderer.invoke('remote-launch-session', payload),
remoteSendPrompt: (alias, sessionId, text) => ipcRenderer.invoke('remote-send-prompt', { alias, sessionId, text }),
setStar: (id, starred) => ipcRenderer.invoke('set-star', id, starred),
renameSession: (id, name) => ipcRenderer.invoke('rename-session', id, name),
archiveSession: (id, archived) => ipcRenderer.invoke('archive-session', id, archived),
getProjectArchivePlan: (groups) => ipcRenderer.invoke('get-project-archive-plan', groups),
archiveProject: (groups, opts) => ipcRenderer.invoke('archive-project', groups, opts),
undoArchiveProject: (groups, archivedAt) => ipcRenderer.invoke('undo-archive-project', groups, archivedAt),
reenableProjectSchedules: (projectPath, folderKey) => ipcRenderer.invoke('reenable-project-schedules', projectPath, folderKey),
dismissScheduleReenableOffer: (projectPath, folderKey) => ipcRenderer.invoke('dismiss-schedule-reenable-offer', projectPath, folderKey),
deleteSession: (id, partIds) => ipcRenderer.invoke('delete-session', id, partIds),
deleteSessionPreview: (id) => ipcRenderer.invoke('delete-session-preview', id),
// initialSize: { cols, rows } measured by the renderer before the spawn, so
// the PTY never runs against a placeholder geometry. May be null.
openTerminal: (id, projectPath, isNew, sessionOptions, initialSize, triggerRequestId) => triggerRequestId === undefined
? ipcRenderer.invoke('open-terminal', id, projectPath, isNew, sessionOptions, initialSize)
: ipcRenderer.invoke('open-terminal', id, projectPath, isNew, sessionOptions, initialSize, triggerRequestId),
search: (type, query, titleOnly) => ipcRenderer.invoke('search', type, query, titleOnly),
searchRevealHidden: (ids) => ipcRenderer.invoke('search-reveal-hidden', ids),
readSessionJsonl: (sessionId, options) => options === undefined
? ipcRenderer.invoke('read-session-jsonl', sessionId)
: ipcRenderer.invoke('read-session-jsonl', sessionId, options),
readSubagentJsonl: (parentSessionId, agentId) => ipcRenderer.invoke('read-subagent-jsonl', parentSessionId, agentId),
listSubagents: (parentSessionId) => ipcRenderer.invoke('list-subagents', parentSessionId),
startSubagentWatch: (parentSessionId, agentId) => ipcRenderer.invoke('start-subagent-watch', parentSessionId, agentId),
stopSubagentWatch: (watchId) => ipcRenderer.invoke('stop-subagent-watch', watchId),
// see .ai/contexts/changes-view.md
gitChangesStatus: (sessionId) => ipcRenderer.invoke('git-changes-status', sessionId),
gitChangesDiff: (sessionId, filePath, staged, untracked) => ipcRenderer.invoke('git-changes-diff', sessionId, filePath, staged, untracked),
gitChangesFile: (sessionId, filePath, opts) => ipcRenderer.invoke('git-changes-file', sessionId, filePath, opts),
gitChangesSave: (sessionId, filePath, content, version) => ipcRenderer.invoke('git-changes-save', sessionId, filePath, content, version),
gitChangesWatch: (sessionId, filePath) => ipcRenderer.invoke('git-changes-watch', sessionId, filePath),
gitChangesUnwatch: (sessionId, filePath) => ipcRenderer.invoke('git-changes-unwatch', sessionId, filePath),
// see .ai/contexts/touched-files.md
sessionTouchedFiles: (sessionId, options) => ipcRenderer.invoke('session-touched-files', sessionId, options),
onGitChangesFileChanged: (callback) => {
ipcRenderer.on('git-changes-file-changed', (_event, sessionId, filePath) => callback(sessionId, filePath));
},
// Settings
getSetting: (key) => ipcRenderer.invoke('get-setting', key),
getSettingsByPrefix: (prefix) => ipcRenderer.invoke('get-settings-by-prefix', prefix),
setSetting: (key, value) => ipcRenderer.invoke('set-setting', key, value),
mergeGlobalSettings: (patch, remove) => ipcRenderer.invoke('merge-global-settings', patch, remove),
deleteSetting: (key) => ipcRenderer.invoke('delete-setting', key),
getEffectiveSettings: (projectPath) => ipcRenderer.invoke('get-effective-settings', projectPath),
getHarnesses: () => ipcRenderer.invoke('get-harnesses'),
getHarnessModels: (runtime) => ipcRenderer.invoke('get-harness-models', runtime),
whatsNewStartup: () => ipcRenderer.invoke('whats-new-startup'),
whatsNewDismissed: () => ipcRenderer.invoke('whats-new-dismissed'),
onShowWhatsNew: (callback) => {
ipcRenderer.on('show-whats-new', (_event, payload) => callback(payload));
},
remoteHostsApply: () => ipcRenderer.invoke('remote-hosts-apply'),
remoteHostsRefresh: () => ipcRenderer.invoke('remote-hosts-refresh'),
remoteHostRefresh: (alias) => ipcRenderer.invoke('remote-host-refresh', alias),
remoteHostEnrolCheck: (alias) => ipcRenderer.invoke('remote-host-enrol-check', alias),
getScheduleCreatorCommand: () => ipcRenderer.invoke('get-schedule-creator-command'),
createScheduleSession: (projectPath) => ipcRenderer.invoke('create-schedule-session', projectPath),
runScheduleNow: (filePath) => ipcRenderer.invoke('run-schedule-now', filePath),
onScheduleRunExit: callback => ipcRenderer.on('schedule-run-exit', (_event, result) => callback(result)),
onScheduleHealth: callback => ipcRenderer.on('schedule-health', (_event, health) => callback(health)),
onScheduleHistoryImported: callback => ipcRenderer.on('schedule-history-imported', () => callback()),
getShellProfiles: () => ipcRenderer.invoke('get-shell-profiles'),
browseFolder: () => ipcRenderer.invoke('browse-folder'),
addProject: (projectPath) => ipcRenderer.invoke('add-project', projectPath),
removeProjectLegacy: (projectPath, folderKey) => ipcRenderer.invoke('remove-project', projectPath, folderKey),
previewProjectDelete: request => ipcRenderer.invoke('preview-project-delete', request),
deleteProject: request => ipcRenderer.invoke('delete-project', request),
projectDeleteState: request => ipcRenderer.invoke('project-delete-state', request),
onProjectDeleteRecovery: callback => ipcRenderer.on('project-delete-recovery', (_event, payload) => callback(payload)),
onProjectDeleteSchedulesChanged: callback => ipcRenderer.on('project-delete-schedules-changed', (_event, payload) => callback(payload)),
archiveProjectSettings: (projectPath, folderKey) => ipcRenderer.invoke('archive-project-settings', projectPath, folderKey),
unarchiveProject: (entry) => ipcRenderer.invoke('unarchive-project', entry),
unarchiveFolder: (entry) => ipcRenderer.invoke('unarchive-folder', entry),
remapProject: (oldPath, newPath) => ipcRenderer.invoke('remap-project', oldPath, newPath),
checkRemapProject: (oldPath) => ipcRenderer.invoke('check-remap-project', oldPath),
deleteWorktree: (worktreePath, shown) => ipcRenderer.invoke('delete-worktree', worktreePath, shown),
checkDeleteWorktree: (worktreePath) => ipcRenderer.invoke('check-delete-worktree', worktreePath),
worktreeStatus: (worktreePath) => ipcRenderer.invoke('worktree-status', worktreePath),
openExternal: (url) => ipcRenderer.invoke('open-external', url),
openPath: (filePath, opts) => ipcRenderer.invoke('open-path', filePath, opts),
showItemInFolder: (filePath) => ipcRenderer.invoke('show-item-in-folder', filePath),
toggleFullScreen: () => ipcRenderer.invoke('toggle-full-screen'),
popupAppMenu: (x, y) => ipcRenderer.invoke('popup-app-menu', { x, y }),
writeClipboard: (text) => ipcRenderer.invoke('clipboard-write-text', text),
readClipboard: () => ipcRenderer.invoke('read-clipboard'),
clipboardHasImage: () => ipcRenderer.invoke('clipboard-has-image'),
// Opt-in activity trace — see docs/activity-trace.md. Main resolves the state
// (activity-trace.js) and passes the startup value as an argument; never
// re-parsed here. Later changes arrive on the onActivityTraceState channel.
activityTraceEnabled: process.argv.includes('--switchboard-activity-trace'),
traceActivity: (cat, sid, fields) => ipcRenderer.send('activity-trace', cat, sid, fields),
getActivityTraceState: () => ipcRenderer.invoke('get-activity-trace-state'),
setActivityTraceEnabled: (enabled) => ipcRenderer.invoke('set-activity-trace-enabled', enabled),
listActivityTraceFiles: () => ipcRenderer.invoke('list-activity-trace-files'),
getDiagnosticFiles: (days) => ipcRenderer.invoke('get-diagnostic-files', days),
pruneDiagnosticFiles: (days, files) => ipcRenderer.invoke('prune-diagnostic-files', days, files),
readActivityTraceFile: (filePath) => ipcRenderer.invoke('read-activity-trace-file', filePath),
deleteActivityTraceFile: (filePath) => ipcRenderer.invoke('delete-activity-trace-file', filePath),
// see .ai/contexts/activitywatch.md
getActivityReportingState: () => ipcRenderer.invoke('get-activity-reporting-state'),
setActivityReportingEnabled: (enabled) => ipcRenderer.invoke('set-activity-reporting-enabled', enabled),
reportActivityFocus: (focus) => ipcRenderer.send('activity-focus', focus),
reportActivityTitles: (list) => ipcRenderer.send('activity-titles', list),
onActivityTraceState: (cb) => ipcRenderer.on('activity-trace-state', (_e, enabled) => cb(enabled)),
// Send (fire-and-forget)
sendInput: (id, data) => ipcRenderer.send('terminal-input', id, data),
resizeTerminal: (id, cols, rows, options) => ipcRenderer.send('terminal-resize', id, cols, rows, options?.refresh === true),
closeTerminal: (id) => ipcRenderer.send('close-terminal', id),
// Listeners (main → renderer)
onTerminalData: (callback) => {
ipcRenderer.on('terminal-data', (_event, sessionId, data) => callback(sessionId, data));
},
onSessionDetected: (callback) => {
ipcRenderer.on('session-detected', (_event, tempId, realId) => callback(tempId, realId));
},
onProcessExited: (callback) => {
ipcRenderer.on('process-exited', (_event, sessionId, exitCode, signal, stopped, generation) => callback(sessionId, exitCode, signal, stopped, generation));
},
onRemoteResizeAllowed: (callback) => {
ipcRenderer.on('remote-resize-allowed', (_event, sessionId) => callback(sessionId));
},
onTerminalNotification: (callback) => {
ipcRenderer.on('terminal-notification', (_event, sessionId, message, kind) => callback(sessionId, message, kind));
},
onCliBusyState: (callback) => {
ipcRenderer.on('cli-busy-state', (_event, sessionId, busy) => callback(sessionId, busy));
},
onSessionForked: (callback) => {
ipcRenderer.on('session-forked', (_event, oldId, newId, kind, background) => callback(oldId, newId, kind, background));
},
getTaskSnapshots: () => ipcRenderer.invoke('get-task-snapshots'),
onTaskRekey: cb => {
const listener = (_event, payload) => cb(payload);
ipcRenderer.on('task-rekey', listener);
return () => ipcRenderer.removeListener('task-rekey', listener);
},
onTaskSnapshot: (cb) => {
const listener = (_event, snapshot) => cb(snapshot);
ipcRenderer.on('task-snapshot', listener);
return () => ipcRenderer.removeListener('task-snapshot', listener);
},
onSubagentSpawned: (cb) => ipcRenderer.on('subagent-spawned', (_e, payload) => cb(payload)),
onSubagentCompleted: (cb) => ipcRenderer.on('subagent-completed', (_e, payload) => cb(payload)),
onSubagentWatchEvent: (cb) => ipcRenderer.on('subagent-watch-event', (_e, payload) => cb(payload)),
onBgAgentsChanged: (cb) => ipcRenderer.on('bg-agents-changed', (_e, payload) => cb(payload)),
onSchedulesTabMigrated: (callback) => ipcRenderer.on('schedules-tab-migrated', () => callback()),
onProjectsChanged: (callback) => {
ipcRenderer.on('projects-changed', (_event, payload) => callback(payload));
},
onRemoteActivity: (callback) => {
ipcRenderer.on('remote-activity', (_event, payload) => callback(payload));
},
onSessionTranscriptActivity: (callback) => {
ipcRenderer.on('session-transcript-activity', (_event, payload) => callback(payload));
},
onStatusUpdate: (callback) => {
ipcRenderer.on('status-update', (_event, text, type) => callback(text, type));
},
onIndexingProgress: (callback) => {
ipcRenderer.on('indexing-progress', (_event, payload) => callback(payload));
},
onIndexingFinished: (callback) => {
ipcRenderer.on('indexing-finished', () => callback());
},
onExitAttemptInvalidated: callback => ipcRenderer.on('exit-attempt-invalidated', (_event, attempt, outcome) => callback(attempt, outcome)),
getExitAttemptSnapshot: (id, detail) => ipcRenderer.invoke('exit-attempt-snapshot', id, detail),
unsavedCheckPhase: (id, detail, phase) => ipcRenderer.send('unsaved-check-phase', id, detail, phase),
onUnsavedCheck: (callback) => {
ipcRenderer.on('unsaved-check', (_event, id, reason, detail) => callback(id, reason, detail));
// see .ai/contexts/window-frame.md ("A window that stops answering")
ipcRenderer.on('unsaved-ping', (_event, token) => ipcRenderer.send('unsaved-pong', token));
ipcRenderer.send('unsaved-ready');
},
onUnsavedCheckReason: (callback) => {
ipcRenderer.on('unsaved-check-reason', (_event, id, reason, token, detail) => callback(id, reason, token, detail));
},
unsavedCheckAck: (id) => ipcRenderer.send('unsaved-check-ack', id),
unsavedDialog: (open) => ipcRenderer.send('unsaved-dialog', open === true),
unsavedCheckResult: (id, proceed, detail) => ipcRenderer.send('unsaved-check-result', id, proceed, detail),
unsavedCheckReasonDone: (id, token, proceed = true) => ipcRenderer.send('unsaved-check-reason-done', id, token, proceed),
onExitFlush: (callback) => {
ipcRenderer.on('exit-flush', () => callback());
},
onFullScreenChanged: (callback) => {
ipcRenderer.on('full-screen-changed', (_event, isFullScreen) => callback(isFullScreen));
},
// File drag-and-drop
getPathForFile: (file) => webUtils.getPathForFile(file),
// Platform
platform: process.platform,
// App version
getAppVersion: () => ipcRenderer.invoke('get-app-version'),
// Auto-updater
updaterCheck: () => ipcRenderer.invoke('updater-check'),
updaterDownload: () => ipcRenderer.invoke('updater-download'),
updaterInstall: () => ipcRenderer.invoke('updater-install'),
updaterClose: () => ipcRenderer.send('updater-close'),
openMainLog: () => ipcRenderer.invoke('open-main-log'),
logUiNotice: event => { ipcRenderer.send('ui-notice-log', event); },
mainErrorNoticesReady: () => { ipcRenderer.send('main-error-notices-ready'); },
mainErrorNoticesDismissed: ids => { ipcRenderer.send('main-error-notices-dismissed', ids); },
onMainProcessError: callback => {
ipcRenderer.on('main-process-error', (_event, notice) => callback(notice));
},
onUpdaterEvent: (callback) => {
ipcRenderer.on('updater-event', (_event, type, data) => callback(type, data));
},
// MCP bridge (main → renderer)
onMcpOpenDiff: (callback) => {
ipcRenderer.on('mcp-open-diff', (_event, sessionId, diffId, data) => callback(sessionId, diffId, data));
},
onMcpOpenFile: (callback) => {
ipcRenderer.on('mcp-open-file', (_event, sessionId, data) => callback(sessionId, data));
},
onMcpCloseAllDiffs: (callback) => {
ipcRenderer.on('mcp-close-all-diffs', (_event, sessionId) => callback(sessionId));
},
onMcpStatus: (callback) => {
ipcRenderer.on('mcp-status', (_event, sessionId, state) => callback(sessionId, state));
},
onMcpCloseTab: (callback) => {
ipcRenderer.on('mcp-close-tab', (_event, sessionId, diffId) => callback(sessionId, diffId));
},
// MCP bridge (renderer → main)
mcpDiffResponse: (sessionId, diffId, action, editedContent) => {
ipcRenderer.send('mcp-diff-response', sessionId, diffId, action, editedContent);
},
resolveTerminalPaths: (sessionId, texts) => ipcRenderer.invoke('resolve-terminal-paths', sessionId, texts),
readFileForPanel: (filePath, opts) => ipcRenderer.invoke('read-file-for-panel', filePath, opts),
saveFileForPanel: (filePath, content, expected, opts) => ipcRenderer.invoke('save-file-for-panel', filePath, content, expected, opts),
watchFile: (filePath) => ipcRenderer.invoke('watch-file', filePath),
unwatchFile: (filePath) => ipcRenderer.invoke('unwatch-file', filePath),
onFileChanged: (callback) => {
ipcRenderer.on('file-changed', (_event, filePath) => callback(filePath));
},
});