-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpreload.js
More file actions
160 lines (153 loc) · 5.17 KB
/
Copy pathpreload.js
File metadata and controls
160 lines (153 loc) · 5.17 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
// ============================================================
// GENESIS AGENT — preload.js (KERNEL — CJS FALLBACK)
// Secure bridge. Only exposes whitelisted channels.
//
// v7.5.1.x: CJS counterpart to preload.mjs. Both files MUST be
// kept in sync — same channels, same validation logic. The CJS
// version is used as Tier 3 fallback on Windows + Electron 33,
// where ESM preload reliably fails with "Cannot use import
// statement outside a module" in the sandboxed renderer.
// Tier 1 (ESM) is preferred when supported; Tier 2 (bundled)
// is preferred when esbuild has produced dist/preload.js;
// Tier 3 (this file) keeps the agent functional everywhere.
// ============================================================
const { contextBridge, ipcRenderer } = require('electron');
const ALLOWED_INVOKE = [
'archive:ensure',
'archive:status',
'agent:chat',
'agent:chat:stop',
'agent:get-self-model',
'agent:get-file',
'agent:save-file',
'agent:open-path',
'agent:run-in-sandbox',
'agent:get-file-tree',
'agent:get-health',
'agent:switch-model',
'agent:list-models',
'agent:clone',
'agent:file-info',
'agent:execute-file',
'agent:read-external-file',
'agent:get-settings',
'agent:set-setting',
'agent:set-settings-batch',
'agent:get-goals',
'agent:get-goal-tree',
// v7.9.20 (Dashboard): self-improvement proposals
'agent:get-proposals',
'agent:accept-proposal',
'agent:reject-proposal',
'agent:undo',
'agent:undo-available',
'agent:get-lang-strings',
'agent:set-lang',
'agent:mcp-status',
'agent:mcp-add-server',
'agent:mcp-remove-server',
'agent:mcp-reconnect',
'agent:mcp-start-server',
'agent:mcp-stop-server',
// v3.5.0: Agent Loop + Session
'agent:loop-status',
'agent:loop-approve',
'agent:loop-reject',
'agent:loop-stop',
'agent:get-session',
// v4.0.0: Dashboard event debug
'agent:get-event-debug',
// v5.5.0: Reasoning Trace UI
'agent:get-reasoning-traces',
// v5.8.0: Dashboard cognitive panels
'agent:get-architecture',
'agent:get-architecture-graph',
'agent:get-project-intel',
'agent:get-tool-synthesis',
'agent:get-task-outcomes',
'agent:get-selfmodel-report',
// v6.1.0: Self-modification gate statistics
'agent:get-gate-stats',
// v6.0.0: Memory consolidation + Replay
'agent:get-consolidation-report',
'agent:trigger-consolidation',
'agent:get-replay-report',
'agent:get-replay-diff',
// v6.0.1: Safety infrastructure
'agent:get-cost-budget',
'agent:export-data',
'agent:import-data',
'agent:get-crash-log',
'agent:check-update',
// v6.0.2: Meta-cognitive adaptation loop
'agent:get-adaptation-report',
'agent:run-adaptation-cycle',
// v6.0.5: Network + Provenance
'agent:get-network-status',
'agent:force-network-probe',
'agent:get-provenance-report',
// v6.0.7: Earned Autonomy
'agent:get-autonomy-report',
// v7.2.4: Filesystem-based first-boot detection
'agent:is-first-boot',
// v7.4.5: GoalDriver
'agent:goal-driver-status',
'agent:goal-driver-queue',
'agent:resume-decision', 'archive:drop-file',
];
const ALLOWED_SEND = [
'agent:request-stream',
'ui:heartbeat', // v5.6.0 SA-P4: UI embodied perception
];
const ALLOWED_RECEIVE = [
'agent:stream-chunk',
'agent:tool-status', // v7.9.37 (W6a): live tool lifecycle (Agent -> UI push)
'agent:stream-done',
'agent:status-update',
'agent:open-in-editor',
// v3.5.0: Agent Loop events
'agent:loop-progress',
'agent:loop-approval-needed',
// v7.4.7: Settings toggle confirmation messages
'agent:chat-system-message',
// v7.4.5: GoalDriver resume-prompt (only event with UI-anchored schema; the
// 4 sibling telemetry events — goal:driver-pickup / goal:resumed-auto /
// goal:discarded / driver:unresponsive — were removed in v7.5.1 because
// they had no UI consumer; they remain backend-only telemetry on the bus)
'ui:resume-prompt',
// v7.7.9 Phase 2: ProactiveSelfExpression bridges self-initiated chat
// messages from ChatOrchestrator over this channel. Payload mirrors
// the chat:self-message-appended bus event (role, content, timestamp,
// initiatedBy, selfMeta).
'genesis:self-message',
// v7.9.4 Können Phase 3: skill lifecycle toasts. Bridged by AgentCoreWire
// as pure pushes — UI shows a toast and re-renders the Skills dashboard.
'skill:promoted',
'skill:discarded',
'skill:quarantined',
'skill:discard-suggested',
// v7.9.12: cloud-model-without-fallback boot warning toast.
'model:cloud-without-fallback',
];
contextBridge.exposeInMainWorld('genesis', {
invoke: (channel, ...args) => {
if (!ALLOWED_INVOKE.includes(channel)) {
throw new Error(`IPC channel not allowed: ${channel}`);
}
return ipcRenderer.invoke(channel, ...args);
},
send: (channel, data) => {
if (!ALLOWED_SEND.includes(channel)) {
throw new Error(`IPC send channel not allowed: ${channel}`);
}
ipcRenderer.send(channel, data);
},
on: (channel, callback) => {
if (!ALLOWED_RECEIVE.includes(channel)) {
throw new Error(`IPC receive channel not allowed: ${channel}`);
}
const sub = (event, ...args) => callback(...args);
ipcRenderer.on(channel, sub);
return () => ipcRenderer.removeListener(channel, sub);
},
});