paneful 0.9.10 → 0.9.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,6 +46,12 @@ func getWindowTitle(pid: pid_t) -> String {
46
46
  return title as? String ?? ""
47
47
  }
48
48
 
49
+ // Quick AX trust check mode: print status and exit
50
+ if CommandLine.arguments.contains("--check") {
51
+ print(AXIsProcessTrusted() ? "ok" : "needs-accessibility")
52
+ exit(0)
53
+ }
54
+
49
55
  setbuf(stdout, nil)
50
56
  setbuf(stderr, nil)
51
57
 
@@ -117,15 +123,19 @@ RunLoop.main.run()
117
123
  `;
118
124
  export class EditorMonitor {
119
125
  onChange;
126
+ onStatusChange;
120
127
  proc = null;
121
128
  destroyed = false;
122
129
  lineBuffer = '';
123
130
  cache = { projectName: null };
124
131
  restartTimer = null;
132
+ accessibilityProbeTimer = null;
125
133
  mode = 'osascript';
126
134
  compiling = false;
127
- constructor(onChange) {
135
+ lastNeedsAccessibility = false;
136
+ constructor(onChange, onStatusChange) {
128
137
  this.onChange = onChange;
138
+ this.onStatusChange = onStatusChange;
129
139
  }
130
140
  getState() {
131
141
  return this.cache;
@@ -173,11 +183,35 @@ export class EditorMonitor {
173
183
  catch { }
174
184
  }
175
185
  }
186
+ probeAccessibility() {
187
+ if (!existsSync(this.helperPath))
188
+ return;
189
+ execFile(this.helperPath, ['--check'], { timeout: 3000 }, (err, stdout) => {
190
+ if (this.destroyed)
191
+ return;
192
+ if (err)
193
+ return;
194
+ const needs = stdout.trim() === 'needs-accessibility';
195
+ this.cache = { ...this.cache, needsAccessibility: needs || undefined };
196
+ this.emitStatusChange(needs);
197
+ });
198
+ }
199
+ startAccessibilityProbe() {
200
+ this.probeAccessibility();
201
+ this.accessibilityProbeTimer = setInterval(() => this.probeAccessibility(), 5000);
202
+ }
203
+ stopAccessibilityProbe() {
204
+ if (this.accessibilityProbeTimer) {
205
+ clearInterval(this.accessibilityProbeTimer);
206
+ this.accessibilityProbeTimer = null;
207
+ }
208
+ }
176
209
  resume() {
177
210
  if (this.destroyed || this.proc)
178
211
  return;
179
212
  if (process.platform !== 'darwin')
180
213
  return;
214
+ this.startAccessibilityProbe();
181
215
  if (this.isHelperCurrent()) {
182
216
  this.mode = 'native';
183
217
  console.log('[editor-monitor] native helper is current, starting directly');
@@ -203,10 +237,12 @@ export class EditorMonitor {
203
237
  }
204
238
  }
205
239
  pause() {
240
+ this.stopAccessibilityProbe();
206
241
  this.stopProcess();
207
242
  }
208
243
  destroy() {
209
244
  this.destroyed = true;
245
+ this.stopAccessibilityProbe();
210
246
  this.stopProcess();
211
247
  }
212
248
  startProcess() {
@@ -252,12 +288,9 @@ export class EditorMonitor {
252
288
  proc.on('error', (err) => {
253
289
  if (this.proc !== proc)
254
290
  return;
255
- const msg = err.message || '';
256
- const needsAccess = msg.includes('not allowed assistive access') || msg.includes('1719');
257
- this.cache = { projectName: null, needsAccessibility: needsAccess || undefined };
258
291
  this.proc = null;
259
292
  if (currentMode === 'native') {
260
- console.log(`[editor-monitor] native helper error, falling back to osascript: ${msg}`);
293
+ console.log(`[editor-monitor] native helper error, falling back to osascript: ${err.message}`);
261
294
  this.mode = 'osascript';
262
295
  }
263
296
  this.scheduleRestart();
@@ -273,6 +306,12 @@ export class EditorMonitor {
273
306
  this.scheduleRestart();
274
307
  });
275
308
  }
309
+ emitStatusChange(needsAccessibility) {
310
+ if (needsAccessibility !== this.lastNeedsAccessibility) {
311
+ this.lastNeedsAccessibility = needsAccessibility;
312
+ this.onStatusChange?.(needsAccessibility);
313
+ }
314
+ }
276
315
  feedData(chunk) {
277
316
  this.lineBuffer += chunk.toString();
278
317
  const lines = this.lineBuffer.split('\n');
@@ -0,0 +1,79 @@
1
+ import { watch, readFileSync, unlinkSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ const INBOX_FILE = 'inbox.json';
4
+ export class InboxMonitor {
5
+ dir;
6
+ onChange;
7
+ watcher = null;
8
+ destroyed = false;
9
+ debounceTimer = null;
10
+ constructor(dataDir, onChange) {
11
+ this.dir = dataDir;
12
+ this.onChange = onChange;
13
+ }
14
+ resume() {
15
+ if (this.destroyed || this.watcher)
16
+ return;
17
+ try {
18
+ this.watcher = watch(this.dir, (event, filename) => {
19
+ if (filename !== INBOX_FILE)
20
+ return;
21
+ if (event !== 'rename' && event !== 'change')
22
+ return;
23
+ this.scheduleRead();
24
+ });
25
+ this.watcher.on('error', () => {
26
+ this.stopWatcher();
27
+ });
28
+ }
29
+ catch {
30
+ // Directory may not exist yet — that's fine
31
+ }
32
+ }
33
+ pause() {
34
+ this.stopWatcher();
35
+ }
36
+ destroy() {
37
+ this.destroyed = true;
38
+ this.stopWatcher();
39
+ }
40
+ stopWatcher() {
41
+ if (this.debounceTimer) {
42
+ clearTimeout(this.debounceTimer);
43
+ this.debounceTimer = null;
44
+ }
45
+ if (this.watcher) {
46
+ this.watcher.close();
47
+ this.watcher = null;
48
+ }
49
+ }
50
+ scheduleRead() {
51
+ if (this.debounceTimer)
52
+ clearTimeout(this.debounceTimer);
53
+ this.debounceTimer = setTimeout(() => {
54
+ this.debounceTimer = null;
55
+ this.readAndProcess();
56
+ }, 50);
57
+ }
58
+ readAndProcess() {
59
+ const filePath = join(this.dir, INBOX_FILE);
60
+ try {
61
+ const raw = readFileSync(filePath, 'utf-8');
62
+ // Delete the file immediately after reading
63
+ try {
64
+ unlinkSync(filePath);
65
+ }
66
+ catch { }
67
+ const data = JSON.parse(raw);
68
+ if (data && Array.isArray(data.files) && data.files.length > 0) {
69
+ const files = data.files.filter((f) => typeof f === 'string');
70
+ if (files.length > 0) {
71
+ this.onChange(files);
72
+ }
73
+ }
74
+ }
75
+ catch {
76
+ // ENOENT, malformed JSON — ignore
77
+ }
78
+ }
79
+ }
@@ -446,7 +446,7 @@ async function startServer(devMode, port) {
446
446
  }
447
447
  const server = http.createServer(app);
448
448
  // WebSocket handler
449
- const wsHandler = new WsHandler(server, ptyManager, projectStore, { onIdle: () => shutdown() });
449
+ const wsHandler = new WsHandler(server, ptyManager, projectStore, dataDir(), { onIdle: () => shutdown() });
450
450
  app.get('/api/active-editor', (_req, res) => {
451
451
  res.json(wsHandler.getEditorState());
452
452
  });
@@ -4,6 +4,7 @@ import { PortMonitor } from './port-monitor.js';
4
4
  import { ClaudeMonitor } from './claude-monitor.js';
5
5
  import { GitMonitor } from './git-monitor.js';
6
6
  import { EditorMonitor } from './editor-monitor.js';
7
+ import { InboxMonitor } from './inbox-monitor.js';
7
8
  export class WsHandler {
8
9
  wss;
9
10
  client = null;
@@ -13,9 +14,10 @@ export class WsHandler {
13
14
  claudeMonitor;
14
15
  gitMonitor;
15
16
  editorMonitor;
17
+ inboxMonitor;
16
18
  idleTimer = null;
17
19
  onIdle;
18
- constructor(server, ptyManager, projectStore, options) {
20
+ constructor(server, ptyManager, projectStore, dataDir, options) {
19
21
  this.ptyManager = ptyManager;
20
22
  this.projectStore = projectStore;
21
23
  this.onIdle = options?.onIdle;
@@ -30,6 +32,11 @@ export class WsHandler {
30
32
  });
31
33
  this.editorMonitor = new EditorMonitor((projectName) => {
32
34
  this.send({ type: 'editor:active', projectName });
35
+ }, (needsAccessibility) => {
36
+ this.send({ type: 'editor:status', needsAccessibility });
37
+ });
38
+ this.inboxMonitor = new InboxMonitor(dataDir, (files) => {
39
+ this.send({ type: 'inbox:paste', files });
33
40
  });
34
41
  this.wss = new WebSocketServer({ noServer: true });
35
42
  server.on('upgrade', (req, socket, head) => {
@@ -64,10 +71,6 @@ export class WsHandler {
64
71
  if (Object.keys(statuses).length > 0) {
65
72
  this.send({ type: 'claude:status', statuses });
66
73
  }
67
- const editorState = this.editorMonitor.getState();
68
- if (editorState.projectName) {
69
- this.send({ type: 'editor:active', projectName: editorState.projectName });
70
- }
71
74
  ws.on('message', (raw) => {
72
75
  try {
73
76
  const msg = JSON.parse(raw.toString());
@@ -161,6 +164,24 @@ export class WsHandler {
161
164
  }
162
165
  break;
163
166
  }
167
+ case 'editor:sync': {
168
+ if (msg.enabled) {
169
+ this.editorMonitor.resume();
170
+ // Send cached state
171
+ const editorState = this.editorMonitor.getState();
172
+ if (editorState.projectName) {
173
+ this.send({ type: 'editor:active', projectName: editorState.projectName });
174
+ }
175
+ if (editorState.needsAccessibility) {
176
+ this.send({ type: 'editor:status', needsAccessibility: true });
177
+ }
178
+ }
179
+ else {
180
+ this.editorMonitor.pause();
181
+ this.send({ type: 'editor:status', needsAccessibility: false });
182
+ }
183
+ break;
184
+ }
164
185
  }
165
186
  }
166
187
  getEditorState() {
@@ -170,19 +191,22 @@ export class WsHandler {
170
191
  this.portMonitor.resume();
171
192
  this.claudeMonitor.resume();
172
193
  this.gitMonitor.resume();
173
- this.editorMonitor.resume();
194
+ // Editor monitor is started on-demand via editor:sync message
195
+ this.inboxMonitor.resume();
174
196
  }
175
197
  pauseMonitors() {
176
198
  this.portMonitor.pause();
177
199
  this.claudeMonitor.pause();
178
200
  this.gitMonitor.pause();
179
201
  this.editorMonitor.pause();
202
+ this.inboxMonitor.pause();
180
203
  }
181
204
  destroy() {
182
205
  this.portMonitor.destroy();
183
206
  this.claudeMonitor.destroy();
184
207
  this.gitMonitor.destroy();
185
208
  this.editorMonitor.destroy();
209
+ this.inboxMonitor.destroy();
186
210
  }
187
211
  handlePtySpawn(terminalId, projectId, cwd) {
188
212
  try {