officepals 0.3.0 → 0.3.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "officepals",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "A cozy 3D office for your AI coding agents — they'll go on strike if you keep them waiting.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/server.mjs CHANGED
@@ -11,7 +11,7 @@ import * as fs from 'node:fs';
11
11
  import * as http from 'node:http';
12
12
  import * as path from 'node:path';
13
13
 
14
- import { serverFile, statsFile } from './paths.mjs';
14
+ import { codexIndexPath, serverFile, statsFile } from './paths.mjs';
15
15
  import { runningSessions, registryDir } from './sessions.mjs';
16
16
  import { adopt, apply, createState, prune, setTitle } from './state.mjs';
17
17
  import { createStats, dayKey, loadStats, record, saveStats, today } from './stats.mjs';
@@ -29,6 +29,8 @@ const RUNNING_EVERY_MS = 4_000;
29
29
  const MISSES_TO_LEAVE = 2;
30
30
  /** A session that just said goodbye isn't let back in while its process exits. */
31
31
  const ENDED_GRACE_MS = 60_000;
32
+ /** A rename lands in a file; react this soon after it changes (debounced). */
33
+ const WATCH_DEBOUNCE_MS = 120;
32
34
  /** Stats are written this long after the last change (and on close). */
33
35
  const SAVE_STATS_AFTER_MS = 2_000;
34
36
  const TYPES = {
@@ -45,7 +47,7 @@ function loopbackHost(hostHeader, port) {
45
47
  return allowed.includes(String(hostHeader).toLowerCase());
46
48
  }
47
49
 
48
- export async function startServer({ port, webDir, log = () => {}, writeServerFile = true, sessionsDir = registryDir(), stats: statsPath = statsFile() }) {
50
+ export async function startServer({ port, webDir, log = () => {}, writeServerFile = true, sessionsDir = registryDir(), stats: statsPath = statsFile(), codexIndex = codexIndexPath() }) {
49
51
  const token = crypto.randomBytes(24).toString('hex');
50
52
  const state = createState();
51
53
  // Daily stats: loaded from disk, saved shortly after each change.
@@ -66,6 +68,7 @@ export async function startServer({ port, webDir, log = () => {}, writeServerFil
66
68
  const clients = new Set();
67
69
  const titleReadAt = new Map(); // session id -> last read
68
70
  const misses = new Map(); // tracked session id -> checks it was missing from
71
+ const registryName = new Map(); // session id -> the name Claude Code lists it under
69
72
  const endedAt = new Map(); // session id -> when SessionEnd arrived
70
73
 
71
74
  /** Let in sessions that are running but not here yet; see off those whose
@@ -85,6 +88,11 @@ export async function startServer({ port, webDir, log = () => {}, writeServerFil
85
88
  changed = true;
86
89
  log(`found running session · ${r.project ?? r.id.slice(0, 8)}`);
87
90
  }
91
+ // Renamed in Claude Code: the list has the new name at once.
92
+ if (r.name && registryName.get(r.id) !== r.name) {
93
+ registryName.set(r.id, r.name);
94
+ if (setTitle(state, r.id, r.name) && !changed) announceTitle(r.id);
95
+ }
88
96
  }
89
97
  for (const [id, s] of Object.entries(state.sessions)) {
90
98
  if (!s.tracked || ids.has(id)) continue;
@@ -95,6 +103,7 @@ export async function startServer({ port, webDir, log = () => {}, writeServerFil
95
103
  }
96
104
  misses.delete(id);
97
105
  titleReadAt.delete(id);
106
+ registryName.delete(id);
98
107
  delete state.sessions[id];
99
108
  changed = true;
100
109
  log(`session gone · ${s.project ?? id.slice(0, 8)}`);
@@ -107,6 +116,7 @@ export async function startServer({ port, webDir, log = () => {}, writeServerFil
107
116
  const s = state.sessions[ev.session];
108
117
  const codex = ev.provider === 'codex';
109
118
  if (!s || (!codex && !ev.transcript)) return;
119
+ if (registryName.has(ev.session)) return; // Claude Code's own list has the current name
110
120
  const last = titleReadAt.get(ev.session) ?? 0;
111
121
  if (s.title && !TITLE_EVENTS.has(ev.event) && Date.now() - last < TITLE_EVERY_MS) return;
112
122
  titleReadAt.set(ev.session, Date.now());
@@ -116,6 +126,34 @@ export async function startServer({ port, webDir, log = () => {}, writeServerFil
116
126
  }
117
127
  }
118
128
 
129
+ const announceTitle = (id) =>
130
+ broadcast({ type: 'update', ts: Date.now(), event: { session: id, event: 'TitleChanged' }, session: state.sessions[id] });
131
+
132
+ /** Codex's session index changed (a rename, a new title): re-read its sessions' titles. */
133
+ async function refreshCodexTitles() {
134
+ for (const [id, s] of Object.entries(state.sessions)) {
135
+ if (s.provider !== 'codex') continue;
136
+ const title = await readCodexTitle(id, codexIndex);
137
+ if (title && setTitle(state, id, title)) announceTitle(id);
138
+ }
139
+ }
140
+
141
+ /** Watch a folder for changes (to one file, if named), debounced; null if it can't be watched. */
142
+ function watch(dir, file, onChange) {
143
+ let timer = null;
144
+ try {
145
+ const w = fs.watch(dir, (_, name) => {
146
+ if (file && name && name !== file) return;
147
+ clearTimeout(timer);
148
+ timer = setTimeout(onChange, WATCH_DEBOUNCE_MS);
149
+ });
150
+ w.on('error', () => w.close());
151
+ return { close: () => { clearTimeout(timer); w.close(); } };
152
+ } catch {
153
+ return null; // missing folder: the timers still catch changes, just later
154
+ }
155
+ }
156
+
119
157
  const send = (res, msg) => res.write(`data: ${JSON.stringify(msg)}\n\n`);
120
158
  const broadcast = (msg) => clients.forEach((res) => send(res, msg));
121
159
  const snapshot = () => ({ type: 'snapshot', now: Date.now(), sessions: state.sessions, stats: today(stats, Date.now()) });
@@ -205,6 +243,11 @@ export async function startServer({ port, webDir, log = () => {}, writeServerFil
205
243
  }
206
244
 
207
245
  syncRunning();
246
+ // Renames show up at once: watch the files the names live in.
247
+ const watchers = [
248
+ sessionsDir && watch(sessionsDir, null, syncRunning),
249
+ codexIndex && watch(path.dirname(codexIndex), path.basename(codexIndex), refreshCodexTitles),
250
+ ].filter(Boolean);
208
251
  const timers = [
209
252
  setInterval(syncRunning, RUNNING_EVERY_MS),
210
253
  setInterval(() => {
@@ -225,9 +268,11 @@ export async function startServer({ port, webDir, log = () => {}, writeServerFil
225
268
  token,
226
269
  state,
227
270
  syncRunning, // checks now (tests; it also runs on a timer)
271
+ refreshCodexTitles,
228
272
  stats,
229
273
  close() {
230
274
  timers.forEach(clearInterval);
275
+ watchers.forEach((w) => w.close());
231
276
  if (saveTimer) saveNow();
232
277
  clients.forEach((res) => res.end());
233
278
  if (writeServerFile) {
package/web/index.html CHANGED
@@ -2246,17 +2246,16 @@ pipBtn.addEventListener('click', popOut);
2246
2246
  document.getElementById('pip-back').addEventListener('click', () => pipWindow?.close());
2247
2247
  renderPipButton();
2248
2248
 
2249
- // ── Power: small windows draw less; the loop draws only as often as needed ──
2250
- // A small window (the pop-out, ?mini, a narrow tab) can't show fine detail, so
2251
- // it renders fewer pixels and a smaller shadow map.
2252
- const SMALL_SHADOW = 1024, FULL_SHADOW = 2048;
2253
- function applyQuality(w) {
2254
- const small = MINI || !!pipWindow || w < COMPACT_BELOW_PX;
2249
+ // ── Power: the loop draws only as often as needed ──────────────
2250
+ // Sharpness: every window, the pop-out included, renders at the screen's own
2251
+ // pixel density (up to 2×). A small window is few pixels even at 2×, so
2252
+ // dropping the density there saved little and made it blurry on Retina.
2253
+ const SHADOW_SIZE = 2048;
2254
+ function applyQuality() {
2255
2255
  const dpr = (pipWindow ?? window).devicePixelRatio || 1;
2256
- renderer.setPixelRatio(Math.min(dpr, small ? 1.25 : 2));
2257
- const size = small ? SMALL_SHADOW : FULL_SHADOW;
2258
- if (sun.shadow.mapSize.x !== size) {
2259
- sun.shadow.mapSize.set(size, size);
2256
+ renderer.setPixelRatio(Math.min(dpr, 2));
2257
+ if (sun.shadow.mapSize.x !== SHADOW_SIZE) {
2258
+ sun.shadow.mapSize.set(SHADOW_SIZE, SHADOW_SIZE);
2260
2259
  sun.shadow.map?.dispose();
2261
2260
  sun.shadow.map = null; // rebuilt at the new size on the next draw
2262
2261
  }