@rozek/nanoclaw 0.0.4 → 0.0.6

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 (132) hide show
  1. package/container/agent-runner/package-lock.json +1524 -0
  2. package/dist/cli.js +75 -4
  3. package/dist/cli.js.map +1 -1
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +34 -0
  6. package/dist/index.js.map +1 -1
  7. package/package.json +7 -1
  8. package/.claude/settings.json +0 -1
  9. package/.claude/skills/add-compact/SKILL.md +0 -135
  10. package/.claude/skills/add-discord/SKILL.md +0 -203
  11. package/.claude/skills/add-gmail/SKILL.md +0 -220
  12. package/.claude/skills/add-image-vision/SKILL.md +0 -94
  13. package/.claude/skills/add-ollama-tool/SKILL.md +0 -153
  14. package/.claude/skills/add-parallel/SKILL.md +0 -290
  15. package/.claude/skills/add-pdf-reader/SKILL.md +0 -104
  16. package/.claude/skills/add-reactions/SKILL.md +0 -117
  17. package/.claude/skills/add-slack/SKILL.md +0 -207
  18. package/.claude/skills/add-telegram/SKILL.md +0 -222
  19. package/.claude/skills/add-telegram-swarm/SKILL.md +0 -384
  20. package/.claude/skills/add-voice-transcription/SKILL.md +0 -148
  21. package/.claude/skills/add-whatsapp/SKILL.md +0 -372
  22. package/.claude/skills/convert-to-apple-container/SKILL.md +0 -175
  23. package/.claude/skills/customize/SKILL.md +0 -110
  24. package/.claude/skills/debug/SKILL.md +0 -349
  25. package/.claude/skills/get-qodo-rules/SKILL.md +0 -122
  26. package/.claude/skills/get-qodo-rules/references/output-format.md +0 -41
  27. package/.claude/skills/get-qodo-rules/references/pagination.md +0 -33
  28. package/.claude/skills/get-qodo-rules/references/repository-scope.md +0 -26
  29. package/.claude/skills/qodo-pr-resolver/SKILL.md +0 -326
  30. package/.claude/skills/qodo-pr-resolver/resources/providers.md +0 -329
  31. package/.claude/skills/setup/SKILL.md +0 -218
  32. package/.claude/skills/update-nanoclaw/SKILL.md +0 -235
  33. package/.claude/skills/update-skills/SKILL.md +0 -130
  34. package/.claude/skills/use-local-whisper/SKILL.md +0 -152
  35. package/.claude/skills/x-integration/SKILL.md +0 -417
  36. package/.claude/skills/x-integration/agent.ts +0 -243
  37. package/.claude/skills/x-integration/host.ts +0 -159
  38. package/.claude/skills/x-integration/lib/browser.ts +0 -148
  39. package/.claude/skills/x-integration/lib/config.ts +0 -62
  40. package/.claude/skills/x-integration/scripts/like.ts +0 -56
  41. package/.claude/skills/x-integration/scripts/post.ts +0 -66
  42. package/.claude/skills/x-integration/scripts/quote.ts +0 -80
  43. package/.claude/skills/x-integration/scripts/reply.ts +0 -74
  44. package/.claude/skills/x-integration/scripts/retweet.ts +0 -62
  45. package/.claude/skills/x-integration/scripts/setup.ts +0 -87
  46. package/.env.example +0 -1
  47. package/.github/CODEOWNERS +0 -10
  48. package/.github/PULL_REQUEST_TEMPLATE.md +0 -14
  49. package/.github/workflows/bump-version.yml +0 -32
  50. package/.github/workflows/ci.yml +0 -25
  51. package/.github/workflows/merge-forward-skills.yml +0 -160
  52. package/.github/workflows/update-tokens.yml +0 -42
  53. package/.husky/pre-commit +0 -1
  54. package/.mcp.json +0 -3
  55. package/.nvmrc +0 -1
  56. package/.prettierrc +0 -3
  57. package/CHANGELOG.md +0 -8
  58. package/CONTRIBUTING.md +0 -23
  59. package/CONTRIBUTORS.md +0 -15
  60. package/NanoClaw_with_Web-Support.md +0 -325
  61. package/README_zh.md +0 -200
  62. package/assets/nanoclaw-favicon.png +0 -0
  63. package/assets/nanoclaw-icon.png +0 -0
  64. package/assets/nanoclaw-logo-dark.png +0 -0
  65. package/assets/nanoclaw-logo.png +0 -0
  66. package/assets/nanoclaw-profile.jpeg +0 -0
  67. package/assets/nanoclaw-sales.png +0 -0
  68. package/assets/social-preview.jpg +0 -0
  69. package/config-examples/mount-allowlist.json +0 -25
  70. package/docs/APPLE-CONTAINER-NETWORKING.md +0 -90
  71. package/docs/DEBUG_CHECKLIST.md +0 -143
  72. package/docs/REQUIREMENTS.md +0 -196
  73. package/docs/SDK_DEEP_DIVE.md +0 -643
  74. package/docs/SECURITY.md +0 -122
  75. package/docs/SPEC.md +0 -785
  76. package/docs/docker-sandboxes.md +0 -359
  77. package/docs/nanoclaw-architecture-final.md +0 -1063
  78. package/docs/nanorepo-architecture.md +0 -168
  79. package/docs/skills-as-branches.md +0 -662
  80. package/groups/global/CLAUDE.md +0 -58
  81. package/groups/main/CLAUDE.md +0 -246
  82. package/launchd/com.nanoclaw.plist +0 -32
  83. package/repo-tokens/README.md +0 -113
  84. package/repo-tokens/action.yml +0 -186
  85. package/repo-tokens/badge.svg +0 -23
  86. package/repo-tokens/examples/green.svg +0 -14
  87. package/repo-tokens/examples/red.svg +0 -14
  88. package/repo-tokens/examples/yellow-green.svg +0 -14
  89. package/repo-tokens/examples/yellow.svg +0 -14
  90. package/scripts/run-migrations.ts +0 -105
  91. package/setup.sh +0 -161
  92. package/src/channels/index.ts +0 -15
  93. package/src/channels/registry.test.ts +0 -42
  94. package/src/channels/registry.ts +0 -32
  95. package/src/channels/web.ts +0 -1931
  96. package/src/cli.ts +0 -210
  97. package/src/config.ts +0 -73
  98. package/src/container-runner.test.ts +0 -210
  99. package/src/container-runner.ts +0 -768
  100. package/src/container-runtime.test.ts +0 -149
  101. package/src/container-runtime.ts +0 -127
  102. package/src/credential-proxy.test.ts +0 -192
  103. package/src/credential-proxy.ts +0 -125
  104. package/src/db.test.ts +0 -484
  105. package/src/db.ts +0 -803
  106. package/src/env.ts +0 -42
  107. package/src/formatting.test.ts +0 -256
  108. package/src/group-folder.test.ts +0 -43
  109. package/src/group-folder.ts +0 -44
  110. package/src/group-queue.test.ts +0 -484
  111. package/src/group-queue.ts +0 -379
  112. package/src/index.ts +0 -854
  113. package/src/ipc-auth.test.ts +0 -679
  114. package/src/ipc.ts +0 -461
  115. package/src/logger.ts +0 -16
  116. package/src/mount-security.ts +0 -419
  117. package/src/remote-control.test.ts +0 -397
  118. package/src/remote-control.ts +0 -224
  119. package/src/router.ts +0 -52
  120. package/src/routing.test.ts +0 -170
  121. package/src/sender-allowlist.test.ts +0 -216
  122. package/src/sender-allowlist.ts +0 -128
  123. package/src/session-commands.test.ts +0 -247
  124. package/src/session-commands.ts +0 -163
  125. package/src/task-scheduler.test.ts +0 -129
  126. package/src/task-scheduler.ts +0 -328
  127. package/src/timezone.test.ts +0 -29
  128. package/src/timezone.ts +0 -16
  129. package/src/types.ts +0 -109
  130. package/tsconfig.json +0 -20
  131. package/vitest.config.ts +0 -7
  132. package/vitest.skills.config.ts +0 -7
@@ -1,679 +0,0 @@
1
- import { describe, it, expect, beforeEach } from 'vitest';
2
-
3
- import {
4
- _initTestDatabase,
5
- createTask,
6
- getAllTasks,
7
- getRegisteredGroup,
8
- getTaskById,
9
- setRegisteredGroup,
10
- } from './db.js';
11
- import { processTaskIpc, IpcDeps } from './ipc.js';
12
- import { RegisteredGroup } from './types.js';
13
-
14
- // Set up registered groups used across tests
15
- const MAIN_GROUP: RegisteredGroup = {
16
- name: 'Main',
17
- folder: 'whatsapp_main',
18
- trigger: 'always',
19
- added_at: '2024-01-01T00:00:00.000Z',
20
- isMain: true,
21
- };
22
-
23
- const OTHER_GROUP: RegisteredGroup = {
24
- name: 'Other',
25
- folder: 'other-group',
26
- trigger: '@Andy',
27
- added_at: '2024-01-01T00:00:00.000Z',
28
- };
29
-
30
- const THIRD_GROUP: RegisteredGroup = {
31
- name: 'Third',
32
- folder: 'third-group',
33
- trigger: '@Andy',
34
- added_at: '2024-01-01T00:00:00.000Z',
35
- };
36
-
37
- let groups: Record<string, RegisteredGroup>;
38
- let deps: IpcDeps;
39
-
40
- beforeEach(() => {
41
- _initTestDatabase();
42
-
43
- groups = {
44
- 'main@g.us': MAIN_GROUP,
45
- 'other@g.us': OTHER_GROUP,
46
- 'third@g.us': THIRD_GROUP,
47
- };
48
-
49
- // Populate DB as well
50
- setRegisteredGroup('main@g.us', MAIN_GROUP);
51
- setRegisteredGroup('other@g.us', OTHER_GROUP);
52
- setRegisteredGroup('third@g.us', THIRD_GROUP);
53
-
54
- deps = {
55
- sendMessage: async () => {},
56
- registeredGroups: () => groups,
57
- registerGroup: (jid, group) => {
58
- groups[jid] = group;
59
- setRegisteredGroup(jid, group);
60
- // Mock the fs.mkdirSync that registerGroup does
61
- },
62
- syncGroups: async () => {},
63
- getAvailableGroups: () => [],
64
- writeGroupsSnapshot: () => {},
65
- onTasksChanged: () => {},
66
- };
67
- });
68
-
69
- // --- schedule_task authorization ---
70
-
71
- describe('schedule_task authorization', () => {
72
- it('main group can schedule for another group', async () => {
73
- await processTaskIpc(
74
- {
75
- type: 'schedule_task',
76
- prompt: 'do something',
77
- schedule_type: 'once',
78
- schedule_value: '2025-06-01T00:00:00',
79
- targetJid: 'other@g.us',
80
- },
81
- 'whatsapp_main',
82
- true,
83
- deps,
84
- );
85
-
86
- // Verify task was created in DB for the other group
87
- const allTasks = getAllTasks();
88
- expect(allTasks.length).toBe(1);
89
- expect(allTasks[0].group_folder).toBe('other-group');
90
- });
91
-
92
- it('non-main group can schedule for itself', async () => {
93
- await processTaskIpc(
94
- {
95
- type: 'schedule_task',
96
- prompt: 'self task',
97
- schedule_type: 'once',
98
- schedule_value: '2025-06-01T00:00:00',
99
- targetJid: 'other@g.us',
100
- },
101
- 'other-group',
102
- false,
103
- deps,
104
- );
105
-
106
- const allTasks = getAllTasks();
107
- expect(allTasks.length).toBe(1);
108
- expect(allTasks[0].group_folder).toBe('other-group');
109
- });
110
-
111
- it('non-main group cannot schedule for another group', async () => {
112
- await processTaskIpc(
113
- {
114
- type: 'schedule_task',
115
- prompt: 'unauthorized',
116
- schedule_type: 'once',
117
- schedule_value: '2025-06-01T00:00:00',
118
- targetJid: 'main@g.us',
119
- },
120
- 'other-group',
121
- false,
122
- deps,
123
- );
124
-
125
- const allTasks = getAllTasks();
126
- expect(allTasks.length).toBe(0);
127
- });
128
-
129
- it('rejects schedule_task for unregistered target JID', async () => {
130
- await processTaskIpc(
131
- {
132
- type: 'schedule_task',
133
- prompt: 'no target',
134
- schedule_type: 'once',
135
- schedule_value: '2025-06-01T00:00:00',
136
- targetJid: 'unknown@g.us',
137
- },
138
- 'whatsapp_main',
139
- true,
140
- deps,
141
- );
142
-
143
- const allTasks = getAllTasks();
144
- expect(allTasks.length).toBe(0);
145
- });
146
- });
147
-
148
- // --- pause_task authorization ---
149
-
150
- describe('pause_task authorization', () => {
151
- beforeEach(() => {
152
- createTask({
153
- id: 'task-main',
154
- group_folder: 'whatsapp_main',
155
- chat_jid: 'main@g.us',
156
- prompt: 'main task',
157
- schedule_type: 'once',
158
- schedule_value: '2025-06-01T00:00:00',
159
- context_mode: 'isolated',
160
- next_run: '2025-06-01T00:00:00.000Z',
161
- status: 'active',
162
- created_at: '2024-01-01T00:00:00.000Z',
163
- });
164
- createTask({
165
- id: 'task-other',
166
- group_folder: 'other-group',
167
- chat_jid: 'other@g.us',
168
- prompt: 'other task',
169
- schedule_type: 'once',
170
- schedule_value: '2025-06-01T00:00:00',
171
- context_mode: 'isolated',
172
- next_run: '2025-06-01T00:00:00.000Z',
173
- status: 'active',
174
- created_at: '2024-01-01T00:00:00.000Z',
175
- });
176
- });
177
-
178
- it('main group can pause any task', async () => {
179
- await processTaskIpc(
180
- { type: 'pause_task', taskId: 'task-other' },
181
- 'whatsapp_main',
182
- true,
183
- deps,
184
- );
185
- expect(getTaskById('task-other')!.status).toBe('paused');
186
- });
187
-
188
- it('non-main group can pause its own task', async () => {
189
- await processTaskIpc(
190
- { type: 'pause_task', taskId: 'task-other' },
191
- 'other-group',
192
- false,
193
- deps,
194
- );
195
- expect(getTaskById('task-other')!.status).toBe('paused');
196
- });
197
-
198
- it('non-main group cannot pause another groups task', async () => {
199
- await processTaskIpc(
200
- { type: 'pause_task', taskId: 'task-main' },
201
- 'other-group',
202
- false,
203
- deps,
204
- );
205
- expect(getTaskById('task-main')!.status).toBe('active');
206
- });
207
- });
208
-
209
- // --- resume_task authorization ---
210
-
211
- describe('resume_task authorization', () => {
212
- beforeEach(() => {
213
- createTask({
214
- id: 'task-paused',
215
- group_folder: 'other-group',
216
- chat_jid: 'other@g.us',
217
- prompt: 'paused task',
218
- schedule_type: 'once',
219
- schedule_value: '2025-06-01T00:00:00',
220
- context_mode: 'isolated',
221
- next_run: '2025-06-01T00:00:00.000Z',
222
- status: 'paused',
223
- created_at: '2024-01-01T00:00:00.000Z',
224
- });
225
- });
226
-
227
- it('main group can resume any task', async () => {
228
- await processTaskIpc(
229
- { type: 'resume_task', taskId: 'task-paused' },
230
- 'whatsapp_main',
231
- true,
232
- deps,
233
- );
234
- expect(getTaskById('task-paused')!.status).toBe('active');
235
- });
236
-
237
- it('non-main group can resume its own task', async () => {
238
- await processTaskIpc(
239
- { type: 'resume_task', taskId: 'task-paused' },
240
- 'other-group',
241
- false,
242
- deps,
243
- );
244
- expect(getTaskById('task-paused')!.status).toBe('active');
245
- });
246
-
247
- it('non-main group cannot resume another groups task', async () => {
248
- await processTaskIpc(
249
- { type: 'resume_task', taskId: 'task-paused' },
250
- 'third-group',
251
- false,
252
- deps,
253
- );
254
- expect(getTaskById('task-paused')!.status).toBe('paused');
255
- });
256
- });
257
-
258
- // --- cancel_task authorization ---
259
-
260
- describe('cancel_task authorization', () => {
261
- it('main group can cancel any task', async () => {
262
- createTask({
263
- id: 'task-to-cancel',
264
- group_folder: 'other-group',
265
- chat_jid: 'other@g.us',
266
- prompt: 'cancel me',
267
- schedule_type: 'once',
268
- schedule_value: '2025-06-01T00:00:00',
269
- context_mode: 'isolated',
270
- next_run: null,
271
- status: 'active',
272
- created_at: '2024-01-01T00:00:00.000Z',
273
- });
274
-
275
- await processTaskIpc(
276
- { type: 'cancel_task', taskId: 'task-to-cancel' },
277
- 'whatsapp_main',
278
- true,
279
- deps,
280
- );
281
- expect(getTaskById('task-to-cancel')).toBeUndefined();
282
- });
283
-
284
- it('non-main group can cancel its own task', async () => {
285
- createTask({
286
- id: 'task-own',
287
- group_folder: 'other-group',
288
- chat_jid: 'other@g.us',
289
- prompt: 'my task',
290
- schedule_type: 'once',
291
- schedule_value: '2025-06-01T00:00:00',
292
- context_mode: 'isolated',
293
- next_run: null,
294
- status: 'active',
295
- created_at: '2024-01-01T00:00:00.000Z',
296
- });
297
-
298
- await processTaskIpc(
299
- { type: 'cancel_task', taskId: 'task-own' },
300
- 'other-group',
301
- false,
302
- deps,
303
- );
304
- expect(getTaskById('task-own')).toBeUndefined();
305
- });
306
-
307
- it('non-main group cannot cancel another groups task', async () => {
308
- createTask({
309
- id: 'task-foreign',
310
- group_folder: 'whatsapp_main',
311
- chat_jid: 'main@g.us',
312
- prompt: 'not yours',
313
- schedule_type: 'once',
314
- schedule_value: '2025-06-01T00:00:00',
315
- context_mode: 'isolated',
316
- next_run: null,
317
- status: 'active',
318
- created_at: '2024-01-01T00:00:00.000Z',
319
- });
320
-
321
- await processTaskIpc(
322
- { type: 'cancel_task', taskId: 'task-foreign' },
323
- 'other-group',
324
- false,
325
- deps,
326
- );
327
- expect(getTaskById('task-foreign')).toBeDefined();
328
- });
329
- });
330
-
331
- // --- register_group authorization ---
332
-
333
- describe('register_group authorization', () => {
334
- it('non-main group cannot register a group', async () => {
335
- await processTaskIpc(
336
- {
337
- type: 'register_group',
338
- jid: 'new@g.us',
339
- name: 'New Group',
340
- folder: 'new-group',
341
- trigger: '@Andy',
342
- },
343
- 'other-group',
344
- false,
345
- deps,
346
- );
347
-
348
- // registeredGroups should not have changed
349
- expect(groups['new@g.us']).toBeUndefined();
350
- });
351
-
352
- it('main group cannot register with unsafe folder path', async () => {
353
- await processTaskIpc(
354
- {
355
- type: 'register_group',
356
- jid: 'new@g.us',
357
- name: 'New Group',
358
- folder: '../../outside',
359
- trigger: '@Andy',
360
- },
361
- 'whatsapp_main',
362
- true,
363
- deps,
364
- );
365
-
366
- expect(groups['new@g.us']).toBeUndefined();
367
- });
368
- });
369
-
370
- // --- refresh_groups authorization ---
371
-
372
- describe('refresh_groups authorization', () => {
373
- it('non-main group cannot trigger refresh', async () => {
374
- // This should be silently blocked (no crash, no effect)
375
- await processTaskIpc(
376
- { type: 'refresh_groups' },
377
- 'other-group',
378
- false,
379
- deps,
380
- );
381
- // If we got here without error, the auth gate worked
382
- });
383
- });
384
-
385
- // --- IPC message authorization ---
386
- // Tests the authorization pattern from startIpcWatcher (ipc.ts).
387
- // The logic: isMain || (targetGroup && targetGroup.folder === sourceGroup)
388
-
389
- describe('IPC message authorization', () => {
390
- // Replicate the exact check from the IPC watcher
391
- function isMessageAuthorized(
392
- sourceGroup: string,
393
- isMain: boolean,
394
- targetChatJid: string,
395
- registeredGroups: Record<string, RegisteredGroup>,
396
- ): boolean {
397
- const targetGroup = registeredGroups[targetChatJid];
398
- return isMain || (!!targetGroup && targetGroup.folder === sourceGroup);
399
- }
400
-
401
- it('main group can send to any group', () => {
402
- expect(
403
- isMessageAuthorized('whatsapp_main', true, 'other@g.us', groups),
404
- ).toBe(true);
405
- expect(
406
- isMessageAuthorized('whatsapp_main', true, 'third@g.us', groups),
407
- ).toBe(true);
408
- });
409
-
410
- it('non-main group can send to its own chat', () => {
411
- expect(
412
- isMessageAuthorized('other-group', false, 'other@g.us', groups),
413
- ).toBe(true);
414
- });
415
-
416
- it('non-main group cannot send to another groups chat', () => {
417
- expect(isMessageAuthorized('other-group', false, 'main@g.us', groups)).toBe(
418
- false,
419
- );
420
- expect(
421
- isMessageAuthorized('other-group', false, 'third@g.us', groups),
422
- ).toBe(false);
423
- });
424
-
425
- it('non-main group cannot send to unregistered JID', () => {
426
- expect(
427
- isMessageAuthorized('other-group', false, 'unknown@g.us', groups),
428
- ).toBe(false);
429
- });
430
-
431
- it('main group can send to unregistered JID', () => {
432
- // Main is always authorized regardless of target
433
- expect(
434
- isMessageAuthorized('whatsapp_main', true, 'unknown@g.us', groups),
435
- ).toBe(true);
436
- });
437
- });
438
-
439
- // --- schedule_task with cron and interval types ---
440
-
441
- describe('schedule_task schedule types', () => {
442
- it('creates task with cron schedule and computes next_run', async () => {
443
- await processTaskIpc(
444
- {
445
- type: 'schedule_task',
446
- prompt: 'cron task',
447
- schedule_type: 'cron',
448
- schedule_value: '0 9 * * *', // every day at 9am
449
- targetJid: 'other@g.us',
450
- },
451
- 'whatsapp_main',
452
- true,
453
- deps,
454
- );
455
-
456
- const tasks = getAllTasks();
457
- expect(tasks).toHaveLength(1);
458
- expect(tasks[0].schedule_type).toBe('cron');
459
- expect(tasks[0].next_run).toBeTruthy();
460
- // next_run should be a valid ISO date in the future
461
- expect(new Date(tasks[0].next_run!).getTime()).toBeGreaterThan(
462
- Date.now() - 60000,
463
- );
464
- });
465
-
466
- it('rejects invalid cron expression', async () => {
467
- await processTaskIpc(
468
- {
469
- type: 'schedule_task',
470
- prompt: 'bad cron',
471
- schedule_type: 'cron',
472
- schedule_value: 'not a cron',
473
- targetJid: 'other@g.us',
474
- },
475
- 'whatsapp_main',
476
- true,
477
- deps,
478
- );
479
-
480
- expect(getAllTasks()).toHaveLength(0);
481
- });
482
-
483
- it('creates task with interval schedule', async () => {
484
- const before = Date.now();
485
-
486
- await processTaskIpc(
487
- {
488
- type: 'schedule_task',
489
- prompt: 'interval task',
490
- schedule_type: 'interval',
491
- schedule_value: '3600000', // 1 hour
492
- targetJid: 'other@g.us',
493
- },
494
- 'whatsapp_main',
495
- true,
496
- deps,
497
- );
498
-
499
- const tasks = getAllTasks();
500
- expect(tasks).toHaveLength(1);
501
- expect(tasks[0].schedule_type).toBe('interval');
502
- // next_run should be ~1 hour from now
503
- const nextRun = new Date(tasks[0].next_run!).getTime();
504
- expect(nextRun).toBeGreaterThanOrEqual(before + 3600000 - 1000);
505
- expect(nextRun).toBeLessThanOrEqual(Date.now() + 3600000 + 1000);
506
- });
507
-
508
- it('rejects invalid interval (non-numeric)', async () => {
509
- await processTaskIpc(
510
- {
511
- type: 'schedule_task',
512
- prompt: 'bad interval',
513
- schedule_type: 'interval',
514
- schedule_value: 'abc',
515
- targetJid: 'other@g.us',
516
- },
517
- 'whatsapp_main',
518
- true,
519
- deps,
520
- );
521
-
522
- expect(getAllTasks()).toHaveLength(0);
523
- });
524
-
525
- it('rejects invalid interval (zero)', async () => {
526
- await processTaskIpc(
527
- {
528
- type: 'schedule_task',
529
- prompt: 'zero interval',
530
- schedule_type: 'interval',
531
- schedule_value: '0',
532
- targetJid: 'other@g.us',
533
- },
534
- 'whatsapp_main',
535
- true,
536
- deps,
537
- );
538
-
539
- expect(getAllTasks()).toHaveLength(0);
540
- });
541
-
542
- it('rejects invalid once timestamp', async () => {
543
- await processTaskIpc(
544
- {
545
- type: 'schedule_task',
546
- prompt: 'bad once',
547
- schedule_type: 'once',
548
- schedule_value: 'not-a-date',
549
- targetJid: 'other@g.us',
550
- },
551
- 'whatsapp_main',
552
- true,
553
- deps,
554
- );
555
-
556
- expect(getAllTasks()).toHaveLength(0);
557
- });
558
- });
559
-
560
- // --- context_mode defaulting ---
561
-
562
- describe('schedule_task context_mode', () => {
563
- it('accepts context_mode=group', async () => {
564
- await processTaskIpc(
565
- {
566
- type: 'schedule_task',
567
- prompt: 'group context',
568
- schedule_type: 'once',
569
- schedule_value: '2025-06-01T00:00:00',
570
- context_mode: 'group',
571
- targetJid: 'other@g.us',
572
- },
573
- 'whatsapp_main',
574
- true,
575
- deps,
576
- );
577
-
578
- const tasks = getAllTasks();
579
- expect(tasks[0].context_mode).toBe('group');
580
- });
581
-
582
- it('accepts context_mode=isolated', async () => {
583
- await processTaskIpc(
584
- {
585
- type: 'schedule_task',
586
- prompt: 'isolated context',
587
- schedule_type: 'once',
588
- schedule_value: '2025-06-01T00:00:00',
589
- context_mode: 'isolated',
590
- targetJid: 'other@g.us',
591
- },
592
- 'whatsapp_main',
593
- true,
594
- deps,
595
- );
596
-
597
- const tasks = getAllTasks();
598
- expect(tasks[0].context_mode).toBe('isolated');
599
- });
600
-
601
- it('defaults invalid context_mode to isolated', async () => {
602
- await processTaskIpc(
603
- {
604
- type: 'schedule_task',
605
- prompt: 'bad context',
606
- schedule_type: 'once',
607
- schedule_value: '2025-06-01T00:00:00',
608
- context_mode: 'bogus' as any,
609
- targetJid: 'other@g.us',
610
- },
611
- 'whatsapp_main',
612
- true,
613
- deps,
614
- );
615
-
616
- const tasks = getAllTasks();
617
- expect(tasks[0].context_mode).toBe('isolated');
618
- });
619
-
620
- it('defaults missing context_mode to isolated', async () => {
621
- await processTaskIpc(
622
- {
623
- type: 'schedule_task',
624
- prompt: 'no context mode',
625
- schedule_type: 'once',
626
- schedule_value: '2025-06-01T00:00:00',
627
- targetJid: 'other@g.us',
628
- },
629
- 'whatsapp_main',
630
- true,
631
- deps,
632
- );
633
-
634
- const tasks = getAllTasks();
635
- expect(tasks[0].context_mode).toBe('isolated');
636
- });
637
- });
638
-
639
- // --- register_group success path ---
640
-
641
- describe('register_group success', () => {
642
- it('main group can register a new group', async () => {
643
- await processTaskIpc(
644
- {
645
- type: 'register_group',
646
- jid: 'new@g.us',
647
- name: 'New Group',
648
- folder: 'new-group',
649
- trigger: '@Andy',
650
- },
651
- 'whatsapp_main',
652
- true,
653
- deps,
654
- );
655
-
656
- // Verify group was registered in DB
657
- const group = getRegisteredGroup('new@g.us');
658
- expect(group).toBeDefined();
659
- expect(group!.name).toBe('New Group');
660
- expect(group!.folder).toBe('new-group');
661
- expect(group!.trigger).toBe('@Andy');
662
- });
663
-
664
- it('register_group rejects request with missing fields', async () => {
665
- await processTaskIpc(
666
- {
667
- type: 'register_group',
668
- jid: 'partial@g.us',
669
- name: 'Partial',
670
- // missing folder and trigger
671
- },
672
- 'whatsapp_main',
673
- true,
674
- deps,
675
- );
676
-
677
- expect(getRegisteredGroup('partial@g.us')).toBeUndefined();
678
- });
679
- });