tycono 0.1.108 → 0.1.110

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": "tycono",
3
- "version": "0.1.108",
3
+ "version": "0.1.110",
4
4
  "description": "Build an AI company. Watch them work.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -129,8 +129,35 @@ class SupervisorHeartbeat {
129
129
  * Dispatch Protocol Principle 2: tick이 유일한 동기화 지점.
130
130
  */
131
131
  addDirective(waveId: string, text: string): PendingDirective | null {
132
- const state = this.supervisors.get(waveId);
133
- if (!state) return null;
132
+ let state = this.supervisors.get(waveId);
133
+
134
+ // If wave not in memory (e.g., server restarted), restore from disk
135
+ if (!state) {
136
+ // Check if this wave existed before (has sessions in session-store)
137
+ const waveSessions = listSessions().filter(s => s.waveId === waveId);
138
+ if (waveSessions.length > 0) {
139
+ // Restore supervisor state for this wave
140
+ const ceoSession = waveSessions.find(s => s.roleId === 'ceo');
141
+ state = {
142
+ waveId,
143
+ directive: text,
144
+ continuous: false,
145
+ supervisorSessionId: ceoSession?.id ?? null,
146
+ executionId: null,
147
+ status: 'stopped',
148
+ crashCount: 0,
149
+ maxCrashRetries: 10,
150
+ restartTimer: null,
151
+ pendingDirectives: [],
152
+ pendingQuestions: [],
153
+ createdAt: ceoSession?.createdAt ?? new Date().toISOString(),
154
+ };
155
+ this.supervisors.set(waveId, state);
156
+ console.log(`[Supervisor] Restored wave ${waveId} from disk (${waveSessions.length} sessions)`);
157
+ } else {
158
+ return null;
159
+ }
160
+ }
134
161
 
135
162
  const directive: PendingDirective = {
136
163
  id: `dir-${Date.now()}`,
@@ -297,35 +324,49 @@ class SupervisorHeartbeat {
297
324
 
298
325
  if (waveCeoSessions.length === 0) return '';
299
326
 
300
- const history: string[] = [];
301
- for (const ses of waveCeoSessions) {
327
+ const exchanges: Array<{ role: 'ceo' | 'supervisor'; text: string }> = [];
328
+ for (const ses of waveCeoSessions.slice(-3)) { // Last 3 sessions only
302
329
  if (!ActivityStream.exists(ses.id)) continue;
303
330
  const events = ActivityStream.readAll(ses.id);
304
331
 
305
- // Extract CEO directives (from messages) and supervisor text responses
332
+ let lastSupervisorText = '';
306
333
  for (const e of events) {
307
334
  if (e.type === 'msg:start' && e.data.task) {
308
- // Extract directive from task (remove system prompt noise)
309
335
  const task = String(e.data.task);
310
336
  const directiveMatch = task.match(/\[CEO (?:Supervisor|Question)\]\s*(.*?)(?:\n|$)/);
311
337
  if (directiveMatch) {
312
- history.push(`CEO: "${directiveMatch[1].slice(0, 100)}"`);
338
+ // Flush previous supervisor response
339
+ if (lastSupervisorText) {
340
+ exchanges.push({ role: 'supervisor', text: lastSupervisorText.slice(0, 100) });
341
+ lastSupervisorText = '';
342
+ }
343
+ exchanges.push({ role: 'ceo', text: directiveMatch[1].slice(0, 80) });
313
344
  }
314
345
  }
346
+ // Accumulate text chunks into one response (not one entry per chunk)
315
347
  if (e.type === 'text' && e.roleId === 'ceo') {
316
348
  const text = String(e.data.text ?? '').trim();
317
- if (text && text.length > 10 && !text.startsWith('#') && !text.startsWith('')) {
318
- history.push(`Supervisor: ${text.slice(0, 150)}`);
349
+ if (text && !text.startsWith('#') && !text.startsWith('\u26D4')) {
350
+ lastSupervisorText += text + ' ';
319
351
  }
320
352
  }
353
+ if (e.type === 'msg:done' && lastSupervisorText) {
354
+ exchanges.push({ role: 'supervisor', text: lastSupervisorText.trim().slice(0, 100) });
355
+ lastSupervisorText = '';
356
+ }
321
357
  }
322
358
  }
323
359
 
324
- if (history.length === 0) return '';
360
+ if (exchanges.length === 0) return '';
361
+
362
+ // Keep last 4 exchanges (2 Q&A pairs), cap total at 500 chars
363
+ const recent = exchanges.slice(-4);
364
+ const formatted = recent.map(e =>
365
+ e.role === 'ceo' ? `CEO: "${e.text}"` : `→ ${e.text}`
366
+ ).join('\n');
325
367
 
326
- // Keep last 10 exchanges to fit in context
327
- const recent = history.slice(-10);
328
- return `\n[Previous Conversation in Wave ${waveId}]\n${recent.join('\n')}\n`;
368
+ if (formatted.length > 500) return `\n[Previous conversation]\n${formatted.slice(-500)}\n`;
369
+ return `\n[Previous conversation]\n${formatted}\n`;
329
370
  } catch {
330
371
  return '';
331
372
  }