@controlflow-ai/daemon 0.1.1 → 0.1.3

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 (65) hide show
  1. package/README.md +66 -24
  2. package/package.json +16 -3
  3. package/src/agent-avatar.ts +30 -0
  4. package/src/agent-key.ts +28 -0
  5. package/src/agent-permissions.ts +359 -0
  6. package/src/agent-runtime.ts +810 -28
  7. package/src/agent-workspace.ts +183 -0
  8. package/src/app.ts +2183 -79
  9. package/src/args.ts +54 -7
  10. package/src/cli.ts +873 -14
  11. package/src/client.ts +482 -12
  12. package/src/coco.ts +9 -40
  13. package/src/codex.ts +33 -5
  14. package/src/config.ts +28 -4
  15. package/src/console.ts +460 -26
  16. package/src/daemon-client.ts +116 -3
  17. package/src/daemon.ts +958 -101
  18. package/src/db.ts +3216 -113
  19. package/src/delivery-ws.ts +269 -0
  20. package/src/format.ts +4 -1
  21. package/src/lark/app-registration.ts +141 -0
  22. package/src/lark/cli.ts +7 -137
  23. package/src/lark/credentials.ts +36 -3
  24. package/src/lark/event-router.ts +61 -5
  25. package/src/lark/inbound-events.ts +156 -3
  26. package/src/lark/server-integration.ts +659 -111
  27. package/src/lark/setup.ts +74 -5
  28. package/src/lark/ws-daemon.ts +136 -10
  29. package/src/local-api.ts +611 -14
  30. package/src/local-auth.ts +36 -3
  31. package/src/message-attachments.ts +71 -0
  32. package/src/messaging-cli.ts +741 -0
  33. package/src/messaging-status.ts +669 -0
  34. package/src/migrations/023_projects.ts +65 -0
  35. package/src/migrations/024_agents_model.ts +10 -0
  36. package/src/migrations/025_room_archive.ts +44 -0
  37. package/src/migrations/026_project_archive.ts +44 -0
  38. package/src/migrations/027_agent_permission_profiles.ts +16 -0
  39. package/src/migrations/028_lark_websocket_restart_state.ts +16 -0
  40. package/src/migrations/029_held_message_drafts.ts +32 -0
  41. package/src/migrations/030_agent_room_read_state.ts +25 -0
  42. package/src/migrations/031_room_tasks.ts +29 -0
  43. package/src/migrations/032_room_reminders.ts +29 -0
  44. package/src/migrations/033_room_saved_messages.ts +25 -0
  45. package/src/migrations/034_agent_activity_events.ts +27 -0
  46. package/src/migrations/035_agent_avatars.ts +17 -0
  47. package/src/migrations/036_project_agent_defaults.ts +21 -0
  48. package/src/migrations/037_message_attachments.ts +36 -0
  49. package/src/migrations/038_agent_activity_room_scope.ts +64 -0
  50. package/src/migrations/039_message_attachments_path.ts +34 -0
  51. package/src/migrations/040_message_attachments_file_schema.ts +80 -0
  52. package/src/migrations/041_room_system_events.ts +30 -0
  53. package/src/migrations/042_message_attachment_file_kind.ts +52 -0
  54. package/src/migrations/043_room_mode_skill_registry.ts +92 -0
  55. package/src/migrations/044_workflow_runtime.ts +69 -0
  56. package/src/migrations/045_skill_repository_ownership.ts +64 -0
  57. package/src/migrations.ts +70 -1
  58. package/src/neeko.ts +40 -4
  59. package/src/runtime-env.ts +179 -0
  60. package/src/runtime-registry.ts +83 -13
  61. package/src/server.ts +244 -4
  62. package/src/token-file.ts +13 -6
  63. package/src/types.ts +394 -0
  64. package/src/workflow-runtime.ts +275 -0
  65. 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,11 +21,92 @@ 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;
26
+ project_id: string | null;
27
+ project_name: string | null;
28
+ project_root_path: string | null;
29
+ project_computer_id: string | null;
30
+ project_computer_name: string | null;
19
31
  created_at: string;
20
32
  message_count: number;
21
33
  last_message_at: string | null;
22
34
  }
23
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
+
72
+ export interface Project {
73
+ id: string;
74
+ name: string;
75
+ computer_id: string;
76
+ computer_name: string | null;
77
+ root_path: string;
78
+ status: ProjectStatus;
79
+ room_count: number;
80
+ created_at: string;
81
+ updated_at: string;
82
+ }
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
+
94
+ export interface RemoteFileEntry {
95
+ name: string;
96
+ path: string;
97
+ type: 'directory' | 'file' | 'other';
98
+ hidden: boolean;
99
+ readable: boolean;
100
+ selectable: boolean;
101
+ }
102
+
103
+ export interface RemoteFileList {
104
+ path: string;
105
+ parent: string | null;
106
+ home: string;
107
+ entries: RemoteFileEntry[];
108
+ }
109
+
24
110
  export type RoomParticipantKind = 'user' | 'bot' | 'agent';
25
111
  export type RoomParticipantSource = 'lark_member_api' | 'known_bot' | 'event' | 'local_agent';
26
112
 
@@ -54,11 +140,166 @@ export interface Message {
54
140
  channel_id?: string | null;
55
141
  provider?: RoomProvider;
56
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;
57
182
  }
58
183
 
59
184
  export type RunStatus = 'running' | 'completed' | 'failed' | 'killed' | 'restarted';
60
185
  export type RunAction = 'kill' | 'restart';
61
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
+ }
62
303
 
63
304
  export interface AgentDefinition {
64
305
  id: string;
@@ -66,6 +307,51 @@ export interface AgentDefinition {
66
307
  display_name: string;
67
308
  description: string | null;
68
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[];
69
355
  created_at: string;
70
356
  updated_at: string;
71
357
  }
@@ -74,6 +360,7 @@ export interface ComputerAgentAssignment {
74
360
  agent: string;
75
361
  display_name: string;
76
362
  runtime: string | null;
363
+ model: string | null;
77
364
  computer_id: string;
78
365
  cwd: string;
79
366
  status: 'active' | 'disabled';
@@ -87,6 +374,19 @@ export interface ProvisionedComputer {
87
374
  command: string;
88
375
  }
89
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
+
90
390
  export interface AgentValidationResult {
91
391
  ok: boolean;
92
392
  diagnostics: Array<{ level: 'error'; code: string; message: string }>;
@@ -116,6 +416,30 @@ export interface AgentRun {
116
416
  delivery_id: string | null;
117
417
  }
118
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
+
119
443
  export interface AgentSession {
120
444
  id: string;
121
445
  chat_id: string;
@@ -131,6 +455,73 @@ export interface AgentSession {
131
455
  runtime_session_id: string | null;
132
456
  }
133
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
+
134
525
  export interface DaemonInstance {
135
526
  id: string;
136
527
  name: string;
@@ -166,6 +557,7 @@ export interface MessageDelivery {
166
557
  id: string;
167
558
  message_id: number;
168
559
  chat_id: string;
560
+ chat_name?: string | null;
169
561
  agent: string;
170
562
  status: DeliveryStatus;
171
563
  daemon_id: string | null;
@@ -377,6 +769,8 @@ export interface AgentRoomSubscription {
377
769
  room_id: string;
378
770
  channel_id: string | null;
379
771
  mode: AgentRoomSubscriptionMode;
772
+ last_read_message_id: number;
773
+ last_read_at: string | null;
380
774
  created_at: string;
381
775
  updated_at: string;
382
776
  }