@controlflow-ai/daemon 0.1.2 → 0.1.4

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.
Files changed (62) hide show
  1. package/README.md +54 -6
  2. package/bin/daemon.js +6 -1
  3. package/package.json +3 -1
  4. package/src/agent-avatar.ts +30 -0
  5. package/src/agent-key.ts +28 -0
  6. package/src/agent-permissions.ts +359 -0
  7. package/src/agent-runtime.ts +795 -28
  8. package/src/agent-workspace.ts +183 -0
  9. package/src/app.ts +1970 -79
  10. package/src/args.ts +54 -7
  11. package/src/cli.ts +873 -14
  12. package/src/client.ts +472 -10
  13. package/src/coco.ts +9 -40
  14. package/src/codex.ts +33 -5
  15. package/src/config.ts +28 -4
  16. package/src/console.ts +230 -20
  17. package/src/daemon-client.ts +116 -3
  18. package/src/daemon.ts +937 -99
  19. package/src/db.ts +3128 -122
  20. package/src/delivery-ws.ts +269 -0
  21. package/src/format.ts +4 -1
  22. package/src/lark/cli.ts +3 -3
  23. package/src/lark/event-router.ts +60 -4
  24. package/src/lark/inbound-events.ts +156 -3
  25. package/src/lark/server-integration.ts +659 -111
  26. package/src/lark/ws-daemon.ts +136 -10
  27. package/src/local-api.ts +545 -15
  28. package/src/local-auth.ts +33 -1
  29. package/src/message-attachments.ts +71 -0
  30. package/src/messaging-cli.ts +741 -0
  31. package/src/messaging-status.ts +669 -0
  32. package/src/migrations/024_agents_model.ts +10 -0
  33. package/src/migrations/025_room_archive.ts +44 -0
  34. package/src/migrations/026_project_archive.ts +44 -0
  35. package/src/migrations/027_agent_permission_profiles.ts +16 -0
  36. package/src/migrations/028_lark_websocket_restart_state.ts +16 -0
  37. package/src/migrations/029_held_message_drafts.ts +32 -0
  38. package/src/migrations/030_agent_room_read_state.ts +25 -0
  39. package/src/migrations/031_room_tasks.ts +29 -0
  40. package/src/migrations/032_room_reminders.ts +29 -0
  41. package/src/migrations/033_room_saved_messages.ts +25 -0
  42. package/src/migrations/034_agent_activity_events.ts +27 -0
  43. package/src/migrations/035_agent_avatars.ts +17 -0
  44. package/src/migrations/036_project_agent_defaults.ts +21 -0
  45. package/src/migrations/037_message_attachments.ts +36 -0
  46. package/src/migrations/038_agent_activity_room_scope.ts +64 -0
  47. package/src/migrations/039_message_attachments_path.ts +34 -0
  48. package/src/migrations/040_message_attachments_file_schema.ts +80 -0
  49. package/src/migrations/041_room_system_events.ts +30 -0
  50. package/src/migrations/042_message_attachment_file_kind.ts +52 -0
  51. package/src/migrations/043_room_mode_skill_registry.ts +92 -0
  52. package/src/migrations/044_workflow_runtime.ts +69 -0
  53. package/src/migrations/045_skill_repository_ownership.ts +64 -0
  54. package/src/migrations.ts +69 -1
  55. package/src/neeko.ts +40 -4
  56. package/src/runtime-env.ts +179 -0
  57. package/src/runtime-registry.ts +83 -13
  58. package/src/server.ts +244 -4
  59. package/src/token-file.ts +13 -6
  60. package/src/types.ts +362 -0
  61. package/src/workflow-runtime.ts +275 -0
  62. package/src/web.ts +0 -904
package/src/types.ts CHANGED
@@ -1,8 +1,13 @@
1
1
  export type ChatKind = 'group' | 'dm';
2
+ export type ChatStatus = 'active' | 'archived';
3
+ export type RoomMode = 'standard' | 'idea_development';
4
+ export type ProjectStatus = 'active' | 'archived';
2
5
  export type MessageType = 'message' | 'system';
3
6
  export type RoomProvider = 'web' | 'lark' | 'wechat';
4
7
  export type RoomTopicCapability = 'native' | 'unsupported';
5
8
  export type AgentRoomSubscriptionMode = 'all' | 'periodic' | 'mentions' | 'muted' | 'off';
9
+ export type RoomSystemEventType = 'agent_invited' | 'agent_removed' | 'agent_receive_mode_changed';
10
+ export type RoomSystemEventActorKind = 'user' | 'agent' | 'system';
6
11
  export type PalIdentityKind = 'user' | 'bot' | 'agent' | 'room';
7
12
  export type ProviderExternalType = 'user' | 'bot' | 'room';
8
13
 
@@ -16,6 +21,8 @@ export interface Chat {
16
21
  dm_type: 'agent_agent' | 'user_agent' | 'user_user' | null;
17
22
  capabilities_json: string;
18
23
  audit_visibility: 'members' | 'admins';
24
+ status: ChatStatus;
25
+ mode: RoomMode;
19
26
  project_id: string | null;
20
27
  project_name: string | null;
21
28
  project_root_path: string | null;
@@ -26,17 +33,64 @@ export interface Chat {
26
33
  last_message_at: string | null;
27
34
  }
28
35
 
36
+ export type SkillStatus = 'active' | 'disabled';
37
+ export type SkillSource = 'system' | 'user' | 'project';
38
+ export type SkillBindingScope = 'project' | 'room' | 'agent';
39
+
40
+ export interface SkillDefinition {
41
+ key: string;
42
+ name: string;
43
+ description: string;
44
+ instruction_content: string;
45
+ status: SkillStatus;
46
+ version: string;
47
+ source: SkillSource;
48
+ owner_user_id: string | null;
49
+ project_id: string | null;
50
+ repository_path: string | null;
51
+ created_at: string;
52
+ updated_at: string;
53
+ }
54
+
55
+ export interface SkillBinding {
56
+ id: string;
57
+ scope: SkillBindingScope;
58
+ scope_id: string;
59
+ skill_key: string;
60
+ enabled: boolean;
61
+ priority: number;
62
+ created_at: string;
63
+ updated_at: string;
64
+ }
65
+
66
+ export interface EnabledSkill extends SkillDefinition {
67
+ binding_scope: SkillBindingScope;
68
+ binding_scope_id: string;
69
+ binding_priority: number;
70
+ }
71
+
29
72
  export interface Project {
30
73
  id: string;
31
74
  name: string;
32
75
  computer_id: string;
33
76
  computer_name: string | null;
34
77
  root_path: string;
78
+ status: ProjectStatus;
35
79
  room_count: number;
36
80
  created_at: string;
37
81
  updated_at: string;
38
82
  }
39
83
 
84
+ export interface ProjectAgentDefault {
85
+ id: string;
86
+ project_id: string;
87
+ agent: string;
88
+ display_name: string | null;
89
+ mode: AgentRoomSubscriptionMode;
90
+ created_at: string;
91
+ updated_at: string;
92
+ }
93
+
40
94
  export interface RemoteFileEntry {
41
95
  name: string;
42
96
  path: string;
@@ -86,11 +140,166 @@ export interface Message {
86
140
  channel_id?: string | null;
87
141
  provider?: RoomProvider;
88
142
  mentions?: string[];
143
+ attachments?: MessageAttachmentMetadata[];
144
+ }
145
+
146
+ export interface RoomSystemEvent {
147
+ id: string;
148
+ room_id: string;
149
+ message_id: number;
150
+ event_type: RoomSystemEventType;
151
+ actor_kind: RoomSystemEventActorKind;
152
+ actor_id: string | null;
153
+ subject_agent: string | null;
154
+ metadata: Record<string, unknown>;
155
+ created_at: string;
156
+ }
157
+
158
+ export interface DeliveryContext {
159
+ startMessageId: number;
160
+ totalCount: number;
161
+ omittedCount: number;
162
+ messages: Message[];
163
+ savedMessages?: RoomSavedMessage[];
164
+ }
165
+
166
+ export type MessageAttachmentKind = 'image' | 'file';
167
+
168
+ export interface MessageAttachmentMetadata {
169
+ id: string;
170
+ message_id: number;
171
+ kind: MessageAttachmentKind;
172
+ mime_type: string;
173
+ filename: string;
174
+ size_bytes: number;
175
+ path: string;
176
+ source_provider: RoomProvider | null;
177
+ created_at: string;
178
+ }
179
+
180
+ export interface MessageAttachment extends MessageAttachmentMetadata {
181
+ source_ref: string | null;
89
182
  }
90
183
 
91
184
  export type RunStatus = 'running' | 'completed' | 'failed' | 'killed' | 'restarted';
92
185
  export type RunAction = 'kill' | 'restart';
93
186
  export type DeliveryStatus = 'pending' | 'claimed' | 'processing_completed' | 'acked' | 'failed' | 'canceled';
187
+ export type HeldDraftStatus = 'held' | 'abandoned' | 'sent_anyway';
188
+ export type RoomTaskStatus = 'todo' | 'in_progress' | 'in_review' | 'done' | 'closed';
189
+ export type RoomReminderStatus = 'scheduled' | 'fired' | 'canceled';
190
+ export type WorkflowRunStatus = 'running' | 'completed' | 'failed';
191
+ export type WorkflowNodeKind = 'phase' | 'agent' | 'task' | 'message' | 'final';
192
+ export type WorkflowNodeStatus = 'pending' | 'running' | 'done' | 'failed';
193
+
194
+ export interface HeldMessageDraft {
195
+ id: string;
196
+ chat_id: string;
197
+ chat_name: string;
198
+ chat_display_name: string | null;
199
+ agent: string;
200
+ sender: string;
201
+ content: string;
202
+ mentions: string[];
203
+ base_message_id: number;
204
+ latest_message_id_at_hold: number;
205
+ status: HeldDraftStatus;
206
+ hold_reason: string;
207
+ hold_count: number;
208
+ intervening_message_count: number;
209
+ resolved_message_id: number | null;
210
+ created_at: string;
211
+ updated_at: string;
212
+ resolved_at: string | null;
213
+ }
214
+
215
+ export interface RoomTask {
216
+ id: string;
217
+ room_id: string;
218
+ room_name: string;
219
+ task_number: number;
220
+ title: string;
221
+ status: RoomTaskStatus;
222
+ assignee: string | null;
223
+ created_by: string | null;
224
+ source_message_id: number | null;
225
+ created_at: string;
226
+ updated_at: string;
227
+ completed_at: string | null;
228
+ }
229
+
230
+ export interface RoomReminder {
231
+ id: string;
232
+ room_id: string;
233
+ room_name: string;
234
+ source_message_id: number;
235
+ title: string;
236
+ status: RoomReminderStatus;
237
+ created_by: string | null;
238
+ fire_at: string;
239
+ repeat: string | null;
240
+ fired_at: string | null;
241
+ canceled_at: string | null;
242
+ created_at: string;
243
+ updated_at: string;
244
+ }
245
+
246
+ export interface RoomSavedMessage {
247
+ id: string;
248
+ room_id: string;
249
+ room_name: string;
250
+ message_id: number;
251
+ message_sender: string;
252
+ message_content: string;
253
+ message_created_at: string;
254
+ saved_by: string;
255
+ note: string | null;
256
+ created_at: string;
257
+ updated_at: string;
258
+ }
259
+
260
+ export interface WorkflowRun {
261
+ id: string;
262
+ file_path: string;
263
+ goal: string | null;
264
+ status: WorkflowRunStatus;
265
+ created_by: string | null;
266
+ final_output: Record<string, unknown> | null;
267
+ error: string | null;
268
+ created_at: string;
269
+ updated_at: string;
270
+ completed_at: string | null;
271
+ }
272
+
273
+ export interface WorkflowNode {
274
+ id: string;
275
+ run_id: string;
276
+ parent_id: string | null;
277
+ kind: WorkflowNodeKind;
278
+ title: string;
279
+ role: string | null;
280
+ status: WorkflowNodeStatus;
281
+ context: Record<string, unknown> | null;
282
+ instruction: string | null;
283
+ capabilities: string[];
284
+ output_contract: Record<string, unknown> | null;
285
+ output: Record<string, unknown> | null;
286
+ evidence: Record<string, unknown> | null;
287
+ task_id: string | null;
288
+ message_id: number | null;
289
+ created_at: string;
290
+ updated_at: string;
291
+ completed_at: string | null;
292
+ }
293
+
294
+ export interface WorkflowRunRecord {
295
+ run: WorkflowRun;
296
+ nodes: WorkflowNode[];
297
+ }
298
+
299
+ export interface MessageFreshnessInput {
300
+ base_message_id: number;
301
+ on_stale: 'hold' | 'send_anyway';
302
+ }
94
303
 
95
304
  export interface AgentDefinition {
96
305
  id: string;
@@ -98,6 +307,51 @@ export interface AgentDefinition {
98
307
  display_name: string;
99
308
  description: string | null;
100
309
  runtime: string | null;
310
+ model: string | null;
311
+ avatar: string;
312
+ created_at: string;
313
+ updated_at: string;
314
+ }
315
+
316
+ export interface AgentDeletionResult {
317
+ agent: AgentDefinition;
318
+ rooms_left: number;
319
+ subscriptions_removed: number;
320
+ assignments_removed: number;
321
+ daemon_registrations_removed: number;
322
+ provider_accounts_disabled: number;
323
+ channel_accounts_disabled: number;
324
+ active_deliveries_canceled: number;
325
+ running_runs_marked_kill: number;
326
+ }
327
+
328
+ export interface AgentDeletionRoomImpact {
329
+ id: string;
330
+ name: string;
331
+ display_name: string | null;
332
+ kind: ChatKind;
333
+ provider: RoomProvider;
334
+ status: ChatStatus;
335
+ }
336
+
337
+ export interface AgentDeletionLarkBindingImpact {
338
+ source: 'provider_account' | 'channel_account' | 'credential';
339
+ app_id: string;
340
+ label: string | null;
341
+ }
342
+
343
+ export interface AgentDeletionImpact {
344
+ agent: AgentDefinition;
345
+ rooms: AgentDeletionRoomImpact[];
346
+ lark_bindings: AgentDeletionLarkBindingImpact[];
347
+ }
348
+
349
+ export type FilesystemPermissionMode = 'project-write' | 'scoped-write' | 'full-access';
350
+
351
+ export interface AgentPermissionProfile {
352
+ agent_key: string;
353
+ filesystem_mode: FilesystemPermissionMode;
354
+ extra_writable_roots: string[];
101
355
  created_at: string;
102
356
  updated_at: string;
103
357
  }
@@ -106,6 +360,7 @@ export interface ComputerAgentAssignment {
106
360
  agent: string;
107
361
  display_name: string;
108
362
  runtime: string | null;
363
+ model: string | null;
109
364
  computer_id: string;
110
365
  cwd: string;
111
366
  status: 'active' | 'disabled';
@@ -119,6 +374,19 @@ export interface ProvisionedComputer {
119
374
  command: string;
120
375
  }
121
376
 
377
+ export interface ComputerDeletionImpact {
378
+ computer: Computer;
379
+ projects: Project[];
380
+ assignments: ComputerAgentAssignment[];
381
+ }
382
+
383
+ export interface ComputerDeletionResult {
384
+ computer: Computer;
385
+ projects_removed: number;
386
+ assignments_removed: number;
387
+ connections_removed: number;
388
+ }
389
+
122
390
  export interface AgentValidationResult {
123
391
  ok: boolean;
124
392
  diagnostics: Array<{ level: 'error'; code: string; message: string }>;
@@ -148,6 +416,30 @@ export interface AgentRun {
148
416
  delivery_id: string | null;
149
417
  }
150
418
 
419
+ export type AgentActivityKind = 'lifecycle' | 'working' | 'thinking' | 'output' | 'tool' | 'error';
420
+
421
+ export interface AgentActivityEvent {
422
+ id: string;
423
+ run_id: string;
424
+ session_id: string | null;
425
+ agent: string;
426
+ room_id: string;
427
+ kind: AgentActivityKind;
428
+ title: string;
429
+ detail: string;
430
+ metadata: Record<string, unknown>;
431
+ created_at: string;
432
+ }
433
+
434
+ export interface RoomAgentActivityStatus {
435
+ agent: string;
436
+ run_id: string;
437
+ status: 'working';
438
+ kind: AgentActivityKind | 'running';
439
+ title: string;
440
+ updated_at: string;
441
+ }
442
+
151
443
  export interface AgentSession {
152
444
  id: string;
153
445
  chat_id: string;
@@ -163,6 +455,73 @@ export interface AgentSession {
163
455
  runtime_session_id: string | null;
164
456
  }
165
457
 
458
+ export interface AgentWorkbenchRoom extends Chat {
459
+ participant: RoomParticipant | null;
460
+ subscription: AgentRoomSubscription | null;
461
+ held_draft_count: number;
462
+ latest_message_id: number;
463
+ last_read_message_id: number;
464
+ last_read_at: string | null;
465
+ unread_count: number;
466
+ is_followed: boolean;
467
+ task_count: number;
468
+ open_task_count: number;
469
+ scheduled_reminder_count: number;
470
+ saved_message_count: number;
471
+ }
472
+
473
+ export interface AgentWorkbenchLarkBinding {
474
+ source: 'provider_account' | 'channel_account';
475
+ app_id: string;
476
+ label: string | null;
477
+ bot_open_id: string | null;
478
+ status: 'active' | 'disabled';
479
+ }
480
+
481
+ export interface AgentWorkbenchCollaboration {
482
+ tasks: RoomTask[];
483
+ reminders: RoomReminder[];
484
+ saved_messages: RoomSavedMessage[];
485
+ }
486
+
487
+ export type AgentWorkspaceFileKind = 'memory' | 'soul' | 'state' | 'knowledge';
488
+
489
+ export interface AgentWorkspaceFile {
490
+ path: string;
491
+ label: string;
492
+ kind: AgentWorkspaceFileKind;
493
+ size_bytes: number;
494
+ updated_at: string;
495
+ content: string;
496
+ truncated: boolean;
497
+ }
498
+
499
+ export interface AgentWorkbench {
500
+ agent: AgentDefinition;
501
+ permissions: AgentPermissionProfile;
502
+ assignment: ComputerAgentAssignment | null;
503
+ machine: Computer | null;
504
+ project: Project | null;
505
+ rooms: AgentWorkbenchRoom[];
506
+ inbox: Message[];
507
+ deliveries: MessageDelivery[];
508
+ runs: AgentRun[];
509
+ activity: AgentActivityEvent[];
510
+ sessions: AgentSession[];
511
+ held_drafts: HeldMessageDraft[];
512
+ collaboration: AgentWorkbenchCollaboration;
513
+ lark_bindings: AgentWorkbenchLarkBinding[];
514
+ }
515
+
516
+ export interface ComputerWorkload {
517
+ computer: Computer;
518
+ connection: ComputerConnection | null;
519
+ daemon: DaemonInstance | null;
520
+ assignments: ComputerAgentAssignment[];
521
+ runs: AgentRun[];
522
+ deliveries: MessageDelivery[];
523
+ }
524
+
166
525
  export interface DaemonInstance {
167
526
  id: string;
168
527
  name: string;
@@ -198,6 +557,7 @@ export interface MessageDelivery {
198
557
  id: string;
199
558
  message_id: number;
200
559
  chat_id: string;
560
+ chat_name?: string | null;
201
561
  agent: string;
202
562
  status: DeliveryStatus;
203
563
  daemon_id: string | null;
@@ -409,6 +769,8 @@ export interface AgentRoomSubscription {
409
769
  room_id: string;
410
770
  channel_id: string | null;
411
771
  mode: AgentRoomSubscriptionMode;
772
+ last_read_message_id: number;
773
+ last_read_at: string | null;
412
774
  created_at: string;
413
775
  updated_at: string;
414
776
  }