tycono 0.1.37 → 0.1.39

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.37",
3
+ "version": "0.1.39",
4
4
  "description": "Build an AI company. Watch them work.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,4 +1,6 @@
1
1
  import type { IncomingMessage, ServerResponse } from 'node:http';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
2
4
  import { COMPANY_ROOT } from '../services/file-reader.js';
3
5
  import { getAllActivities, setActivity, updateActivity, completeActivity } from '../services/activity-tracker.js';
4
6
  import { buildOrgTree, canDispatchTo, getSubordinates } from '../engine/org-tree.js';
@@ -29,6 +31,12 @@ export function handleExecRequest(req: IncomingMessage, res: ServerResponse): vo
29
31
  const url = req.url ?? '';
30
32
  const method = req.method ?? '';
31
33
 
34
+ // ── /api/waves/save ──
35
+ if (method === 'POST' && url === '/api/waves/save') {
36
+ readBody(req).then((body) => handleSaveWave(body, res));
37
+ return;
38
+ }
39
+
32
40
  // ── /api/jobs/* routes ──
33
41
  if (url.startsWith('/api/jobs')) {
34
42
  handleJobsRequest(url, method, req, res);
@@ -295,6 +303,79 @@ function handleReplyToJob(jobId: string, body: Record<string, unknown>, res: Ser
295
303
  jsonResponse(res, 200, { jobId: newJob.id, roleId: newJob.roleId });
296
304
  }
297
305
 
306
+ /* ─── POST /api/waves/save ──────────────── */
307
+
308
+ function handleSaveWave(body: Record<string, unknown>, res: ServerResponse): void {
309
+ const directive = body.directive as string;
310
+ const jobIds = body.jobIds as string[];
311
+
312
+ if (!directive || !jobIds || jobIds.length === 0) {
313
+ jsonResponse(res, 400, { error: 'directive and jobIds are required' });
314
+ return;
315
+ }
316
+
317
+ // Build wave summary from job streams
318
+ const now = new Date();
319
+ const dateStr = now.toISOString().slice(0, 10);
320
+ const timeStr = now.toTimeString().slice(0, 5);
321
+ const lines: string[] = [
322
+ `# Wave — ${dateStr} ${timeStr}`,
323
+ '',
324
+ `> ${directive}`,
325
+ '',
326
+ ];
327
+
328
+ for (const jobId of jobIds) {
329
+ const events = ActivityStream.readAll(jobId);
330
+ const startEvent = events.find(e => e.type === 'job:start');
331
+ const roleId = startEvent?.roleId ?? 'unknown';
332
+ const doneEvent = events.find(e => e.type === 'job:done' || e.type === 'job:awaiting_input');
333
+
334
+ lines.push(`## ${roleId.toUpperCase()}`);
335
+ lines.push('');
336
+
337
+ // Collect text output
338
+ const textParts: string[] = [];
339
+ for (const e of events) {
340
+ if (e.type === 'text' && typeof e.data.text === 'string') {
341
+ textParts.push(e.data.text);
342
+ }
343
+ }
344
+ const fullText = textParts.join('');
345
+ // Take last 1500 chars as summary
346
+ const summary = fullText.length > 1500
347
+ ? '...' + fullText.slice(-1500)
348
+ : fullText;
349
+
350
+ if (summary.trim()) {
351
+ lines.push(summary.trim());
352
+ } else {
353
+ lines.push('(No text output)');
354
+ }
355
+
356
+ if (doneEvent) {
357
+ const turns = doneEvent.data.turns as number ?? 0;
358
+ const tools = doneEvent.data.toolCalls as number ?? 0;
359
+ lines.push('');
360
+ lines.push(`*${turns} turns, ${tools} tool calls*`);
361
+ }
362
+ lines.push('');
363
+ lines.push('---');
364
+ lines.push('');
365
+ }
366
+
367
+ // Write to operations/waves/
368
+ const wavesDir = path.join(COMPANY_ROOT, 'operations', 'waves');
369
+ if (!fs.existsSync(wavesDir)) {
370
+ fs.mkdirSync(wavesDir, { recursive: true });
371
+ }
372
+ const filename = `wave-${dateStr}-${Date.now()}.md`;
373
+ const filePath = path.join(wavesDir, filename);
374
+ fs.writeFileSync(filePath, lines.join('\n'), 'utf-8');
375
+
376
+ jsonResponse(res, 200, { ok: true, path: `operations/waves/${filename}` });
377
+ }
378
+
298
379
  /* ═══════════════════════════════════════════════
299
380
  Legacy /api/exec/* — kept for backward compat
300
381
  Now internally delegates to JobManager where possible