disunday 1.0.0

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 (83) hide show
  1. package/dist/ai-tool-to-genai.js +208 -0
  2. package/dist/ai-tool-to-genai.test.js +267 -0
  3. package/dist/channel-management.js +96 -0
  4. package/dist/cli.js +1674 -0
  5. package/dist/commands/abort.js +89 -0
  6. package/dist/commands/add-project.js +117 -0
  7. package/dist/commands/agent.js +250 -0
  8. package/dist/commands/ask-question.js +219 -0
  9. package/dist/commands/compact.js +126 -0
  10. package/dist/commands/context-menu.js +171 -0
  11. package/dist/commands/context.js +89 -0
  12. package/dist/commands/cost.js +93 -0
  13. package/dist/commands/create-new-project.js +111 -0
  14. package/dist/commands/diff.js +77 -0
  15. package/dist/commands/export.js +100 -0
  16. package/dist/commands/files.js +73 -0
  17. package/dist/commands/fork.js +199 -0
  18. package/dist/commands/help.js +54 -0
  19. package/dist/commands/login.js +488 -0
  20. package/dist/commands/merge-worktree.js +165 -0
  21. package/dist/commands/model.js +325 -0
  22. package/dist/commands/permissions.js +140 -0
  23. package/dist/commands/ping.js +13 -0
  24. package/dist/commands/queue.js +133 -0
  25. package/dist/commands/remove-project.js +119 -0
  26. package/dist/commands/rename.js +70 -0
  27. package/dist/commands/restart-opencode-server.js +77 -0
  28. package/dist/commands/resume.js +276 -0
  29. package/dist/commands/run-config.js +79 -0
  30. package/dist/commands/run.js +240 -0
  31. package/dist/commands/schedule.js +170 -0
  32. package/dist/commands/session-info.js +58 -0
  33. package/dist/commands/session.js +191 -0
  34. package/dist/commands/settings.js +84 -0
  35. package/dist/commands/share.js +89 -0
  36. package/dist/commands/status.js +79 -0
  37. package/dist/commands/sync.js +119 -0
  38. package/dist/commands/theme.js +53 -0
  39. package/dist/commands/types.js +2 -0
  40. package/dist/commands/undo-redo.js +170 -0
  41. package/dist/commands/user-command.js +135 -0
  42. package/dist/commands/verbosity.js +59 -0
  43. package/dist/commands/worktree-settings.js +50 -0
  44. package/dist/commands/worktree.js +288 -0
  45. package/dist/config.js +139 -0
  46. package/dist/database.js +585 -0
  47. package/dist/discord-bot.js +700 -0
  48. package/dist/discord-utils.js +336 -0
  49. package/dist/discord-utils.test.js +20 -0
  50. package/dist/errors.js +193 -0
  51. package/dist/escape-backticks.test.js +429 -0
  52. package/dist/format-tables.js +96 -0
  53. package/dist/format-tables.test.js +418 -0
  54. package/dist/genai-worker-wrapper.js +109 -0
  55. package/dist/genai-worker.js +299 -0
  56. package/dist/genai.js +230 -0
  57. package/dist/image-utils.js +107 -0
  58. package/dist/interaction-handler.js +289 -0
  59. package/dist/limit-heading-depth.js +25 -0
  60. package/dist/limit-heading-depth.test.js +105 -0
  61. package/dist/logger.js +111 -0
  62. package/dist/markdown.js +323 -0
  63. package/dist/markdown.test.js +269 -0
  64. package/dist/message-formatting.js +447 -0
  65. package/dist/message-formatting.test.js +73 -0
  66. package/dist/openai-realtime.js +226 -0
  67. package/dist/opencode.js +224 -0
  68. package/dist/reaction-handler.js +128 -0
  69. package/dist/scheduler.js +93 -0
  70. package/dist/security.js +200 -0
  71. package/dist/session-handler.js +1436 -0
  72. package/dist/system-message.js +138 -0
  73. package/dist/tools.js +354 -0
  74. package/dist/unnest-code-blocks.js +117 -0
  75. package/dist/unnest-code-blocks.test.js +432 -0
  76. package/dist/utils.js +95 -0
  77. package/dist/voice-handler.js +569 -0
  78. package/dist/voice.js +344 -0
  79. package/dist/worker-types.js +4 -0
  80. package/dist/worktree-utils.js +134 -0
  81. package/dist/xml.js +90 -0
  82. package/dist/xml.test.js +32 -0
  83. package/package.json +84 -0
@@ -0,0 +1,429 @@
1
+ import { test, expect } from 'vitest';
2
+ import { Lexer } from 'marked';
3
+ import { escapeBackticksInCodeBlocks, splitMarkdownForDiscord } from './discord-utils.js';
4
+ test('escapes single backticks in code blocks', () => {
5
+ const input = '```js\nconst x = `hello`\n```';
6
+ const result = escapeBackticksInCodeBlocks(input);
7
+ expect(result).toMatchInlineSnapshot(`
8
+ "\`\`\`js
9
+ const x = \\\`hello\\\`
10
+ \`\`\`
11
+ "
12
+ `);
13
+ });
14
+ test('escapes backticks in code blocks with language', () => {
15
+ const input = '```typescript\nconst greeting = `Hello, ${name}!`\nconst inline = `test`\n```';
16
+ const result = escapeBackticksInCodeBlocks(input);
17
+ expect(result).toMatchInlineSnapshot(`
18
+ "\`\`\`typescript
19
+ const greeting = \\\`Hello, \${name}!\\\`
20
+ const inline = \\\`test\\\`
21
+ \`\`\`
22
+ "
23
+ `);
24
+ });
25
+ test('does not escape backticks outside code blocks', () => {
26
+ const input = 'This is `inline code` and this is a code block:\n```\nconst x = `template`\n```';
27
+ const result = escapeBackticksInCodeBlocks(input);
28
+ expect(result).toMatchInlineSnapshot(`
29
+ "This is \`inline code\` and this is a code block:
30
+ \`\`\`
31
+ const x = \\\`template\\\`
32
+ \`\`\`
33
+ "
34
+ `);
35
+ });
36
+ test('handles multiple code blocks', () => {
37
+ const input = `First block:
38
+ \`\`\`js
39
+ const a = \`test\`
40
+ \`\`\`
41
+
42
+ Some text with \`inline\` code
43
+
44
+ Second block:
45
+ \`\`\`python
46
+ name = f\`hello {world}\`
47
+ \`\`\``;
48
+ const result = escapeBackticksInCodeBlocks(input);
49
+ expect(result).toMatchInlineSnapshot(`
50
+ "First block:
51
+ \`\`\`js
52
+ const a = \\\`test\\\`
53
+ \`\`\`
54
+
55
+
56
+ Some text with \`inline\` code
57
+
58
+ Second block:
59
+ \`\`\`python
60
+ name = f\\\`hello {world}\\\`
61
+ \`\`\`
62
+ "
63
+ `);
64
+ });
65
+ test('handles code blocks without language', () => {
66
+ const input = '```\nconst x = `value`\n```';
67
+ const result = escapeBackticksInCodeBlocks(input);
68
+ expect(result).toMatchInlineSnapshot(`
69
+ "\`\`\`
70
+ const x = \\\`value\\\`
71
+ \`\`\`
72
+ "
73
+ `);
74
+ });
75
+ test('handles nested backticks in code blocks', () => {
76
+ const input = '```js\nconst nested = `outer ${`inner`} text`\n```';
77
+ const result = escapeBackticksInCodeBlocks(input);
78
+ expect(result).toMatchInlineSnapshot(`
79
+ "\`\`\`js
80
+ const nested = \\\`outer \${\\\`inner\\\`} text\\\`
81
+ \`\`\`
82
+ "
83
+ `);
84
+ });
85
+ test('preserves markdown outside code blocks', () => {
86
+ const input = `# Heading
87
+
88
+ This is **bold** and *italic* text
89
+
90
+ \`\`\`js
91
+ const code = \`with template\`
92
+ \`\`\`
93
+
94
+ - List item 1
95
+ - List item 2`;
96
+ const result = escapeBackticksInCodeBlocks(input);
97
+ expect(result).toMatchInlineSnapshot(`
98
+ "# Heading
99
+
100
+ This is **bold** and *italic* text
101
+
102
+ \`\`\`js
103
+ const code = \\\`with template\\\`
104
+ \`\`\`
105
+
106
+
107
+ - List item 1
108
+ - List item 2"
109
+ `);
110
+ });
111
+ test('does not escape code block delimiter backticks', () => {
112
+ const input = '```js\nconst x = `hello`\n```';
113
+ const result = escapeBackticksInCodeBlocks(input);
114
+ expect(result.startsWith('```')).toBe(true);
115
+ expect(result.endsWith('```\n')).toBe(true);
116
+ expect(result).toContain('\\`hello\\`');
117
+ expect(result).not.toContain('\\`\\`\\`js');
118
+ expect(result).not.toContain('\\`\\`\\`\n');
119
+ expect(result).toMatchInlineSnapshot(`
120
+ "\`\`\`js
121
+ const x = \\\`hello\\\`
122
+ \`\`\`
123
+ "
124
+ `);
125
+ });
126
+ test('splitMarkdownForDiscord returns single chunk for short content', () => {
127
+ const result = splitMarkdownForDiscord({
128
+ content: 'Hello world',
129
+ maxLength: 100,
130
+ });
131
+ expect(result).toMatchInlineSnapshot(`
132
+ [
133
+ "Hello world",
134
+ ]
135
+ `);
136
+ });
137
+ test('splitMarkdownForDiscord splits at line boundaries', () => {
138
+ const result = splitMarkdownForDiscord({
139
+ content: 'Line 1\nLine 2\nLine 3\nLine 4',
140
+ maxLength: 15,
141
+ });
142
+ expect(result).toMatchInlineSnapshot(`
143
+ [
144
+ "Line 1
145
+ Line 2
146
+ ",
147
+ "Line 3
148
+ Line 4",
149
+ ]
150
+ `);
151
+ });
152
+ test('splitMarkdownForDiscord preserves code blocks when not split', () => {
153
+ const result = splitMarkdownForDiscord({
154
+ content: '```js\nconst x = 1\n```',
155
+ maxLength: 100,
156
+ });
157
+ expect(result).toMatchInlineSnapshot(`
158
+ [
159
+ "\`\`\`js
160
+ const x = 1
161
+ \`\`\`",
162
+ ]
163
+ `);
164
+ });
165
+ test('splitMarkdownForDiscord adds closing and opening fences when splitting code block', () => {
166
+ const result = splitMarkdownForDiscord({
167
+ content: '```js\nline1\nline2\nline3\nline4\n```',
168
+ maxLength: 20,
169
+ });
170
+ expect(result).toMatchInlineSnapshot(`
171
+ [
172
+ "\`\`\`js
173
+ line1
174
+ \`\`\`
175
+ ",
176
+ "\`\`\`js
177
+ line2
178
+ \`\`\`
179
+ ",
180
+ "\`\`\`js
181
+ line3
182
+ \`\`\`
183
+ ",
184
+ "\`\`\`js
185
+ line4
186
+ \`\`\`
187
+ ",
188
+ ]
189
+ `);
190
+ });
191
+ test('splitMarkdownForDiscord handles code block with language', () => {
192
+ const result = splitMarkdownForDiscord({
193
+ content: '```typescript\nconst a = 1\nconst b = 2\n```',
194
+ maxLength: 30,
195
+ });
196
+ expect(result).toMatchInlineSnapshot(`
197
+ [
198
+ "\`\`\`typescript
199
+ const a = 1
200
+ \`\`\`
201
+ ",
202
+ "\`\`\`typescript
203
+ const b = 2
204
+ \`\`\`
205
+ ",
206
+ ]
207
+ `);
208
+ });
209
+ test('splitMarkdownForDiscord handles mixed content with code blocks', () => {
210
+ const result = splitMarkdownForDiscord({
211
+ content: 'Text before\n```js\ncode\n```\nText after',
212
+ maxLength: 25,
213
+ });
214
+ expect(result).toMatchInlineSnapshot(`
215
+ [
216
+ "Text before
217
+ \`\`\`js
218
+ \`\`\`
219
+ ",
220
+ "\`\`\`js
221
+ code
222
+ \`\`\`
223
+ Text after",
224
+ ]
225
+ `);
226
+ });
227
+ test('splitMarkdownForDiscord handles code block without language', () => {
228
+ const result = splitMarkdownForDiscord({
229
+ content: '```\nline1\nline2\n```',
230
+ maxLength: 12,
231
+ });
232
+ expect(result).toMatchInlineSnapshot(`
233
+ [
234
+ "\`\`\`
235
+ \`\`\`
236
+ ",
237
+ "\`\`\`
238
+ line1
239
+ \`\`\`
240
+ ",
241
+ "\`\`\`
242
+ line2
243
+ \`\`\`
244
+ ",
245
+ ]
246
+ `);
247
+ });
248
+ test('splitMarkdownForDiscord handles multiple consecutive code blocks', () => {
249
+ const result = splitMarkdownForDiscord({
250
+ content: '```js\nfoo\n```\n```py\nbar\n```',
251
+ maxLength: 20,
252
+ });
253
+ expect(result).toMatchInlineSnapshot(`
254
+ [
255
+ "\`\`\`js
256
+ foo
257
+ \`\`\`
258
+ \`\`\`py
259
+ \`\`\`
260
+ ",
261
+ "\`\`\`py
262
+ bar
263
+ \`\`\`
264
+ ",
265
+ ]
266
+ `);
267
+ });
268
+ test('splitMarkdownForDiscord handles empty code block', () => {
269
+ const result = splitMarkdownForDiscord({
270
+ content: 'before\n```\n```\nafter',
271
+ maxLength: 50,
272
+ });
273
+ expect(result).toMatchInlineSnapshot(`
274
+ [
275
+ "before
276
+ \`\`\`
277
+ \`\`\`
278
+ after",
279
+ ]
280
+ `);
281
+ });
282
+ test('splitMarkdownForDiscord handles content exactly at maxLength', () => {
283
+ const result = splitMarkdownForDiscord({
284
+ content: '12345678901234567890',
285
+ maxLength: 20,
286
+ });
287
+ expect(result).toMatchInlineSnapshot(`
288
+ [
289
+ "12345678901234567890",
290
+ ]
291
+ `);
292
+ });
293
+ test('splitMarkdownForDiscord handles code block only', () => {
294
+ const result = splitMarkdownForDiscord({
295
+ content: '```ts\nconst x = 1\n```',
296
+ maxLength: 15,
297
+ });
298
+ expect(result).toMatchInlineSnapshot(`
299
+ [
300
+ "\`\`\`ts
301
+ \`\`\`
302
+ ",
303
+ "\`\`\`ts
304
+ const x = 1
305
+ \`\`\`
306
+ ",
307
+ ]
308
+ `);
309
+ });
310
+ test('splitMarkdownForDiscord handles code block at start with text after', () => {
311
+ const result = splitMarkdownForDiscord({
312
+ content: '```js\ncode\n```\nSome text after',
313
+ maxLength: 20,
314
+ });
315
+ expect(result).toMatchInlineSnapshot(`
316
+ [
317
+ "\`\`\`js
318
+ code
319
+ \`\`\`
320
+ ",
321
+ "Some text after",
322
+ ]
323
+ `);
324
+ });
325
+ test('splitMarkdownForDiscord handles text before code block at end', () => {
326
+ const result = splitMarkdownForDiscord({
327
+ content: 'Some text before\n```js\ncode\n```',
328
+ maxLength: 25,
329
+ });
330
+ expect(result).toMatchInlineSnapshot(`
331
+ [
332
+ "Some text before
333
+ \`\`\`js
334
+ \`\`\`
335
+ ",
336
+ "\`\`\`js
337
+ code
338
+ \`\`\`
339
+ ",
340
+ ]
341
+ `);
342
+ });
343
+ test('splitMarkdownForDiscord handles very long line inside code block', () => {
344
+ const result = splitMarkdownForDiscord({
345
+ content: '```js\nshort\nveryverylonglinethatexceedsmaxlength\nshort\n```',
346
+ maxLength: 25,
347
+ });
348
+ expect(result).toMatchInlineSnapshot(`
349
+ [
350
+ "\`\`\`js
351
+ short
352
+ \`\`\`
353
+ ",
354
+ "\`\`\`js
355
+ veryverylo\`\`\`
356
+ ",
357
+ "\`\`\`js
358
+ nglinethat\`\`\`
359
+ ",
360
+ "\`\`\`js
361
+ exceedsmax\`\`\`
362
+ ",
363
+ "\`\`\`js
364
+ length
365
+ \`\`\`
366
+ ",
367
+ "short
368
+ \`\`\`
369
+ ",
370
+ ]
371
+ `);
372
+ });
373
+ test('splitMarkdownForDiscord handles realistic long markdown with code block', () => {
374
+ const content = `Here is some explanation text before the code.
375
+
376
+ \`\`\`typescript
377
+ export function calculateTotal(items: Item[]): number {
378
+ let total = 0
379
+ for (const item of items) {
380
+ total += item.price * item.quantity
381
+ }
382
+ return total
383
+ }
384
+
385
+ export function formatCurrency(amount: number): string {
386
+ return new Intl.NumberFormat('en-US', {
387
+ style: 'currency',
388
+ currency: 'USD',
389
+ }).format(amount)
390
+ }
391
+ \`\`\`
392
+
393
+ And here is some text after the code block.`;
394
+ const result = splitMarkdownForDiscord({
395
+ content,
396
+ maxLength: 200,
397
+ });
398
+ expect(result).toMatchInlineSnapshot(`
399
+ [
400
+ "Here is some explanation text before the code.
401
+
402
+ \`\`\`typescript
403
+ export function calculateTotal(items: Item[]): number {
404
+ let total = 0
405
+ for (const item of items) {
406
+ \`\`\`
407
+ ",
408
+ "\`\`\`typescript
409
+ total += item.price * item.quantity
410
+ }
411
+ return total
412
+ }
413
+
414
+ export function formatCurrency(amount: number): string {
415
+ return new Intl.NumberFormat('en-US', {
416
+ \`\`\`
417
+ ",
418
+ "\`\`\`typescript
419
+ style: 'currency',
420
+ currency: 'USD',
421
+ }).format(amount)
422
+ }
423
+ \`\`\`
424
+
425
+
426
+ And here is some text after the code block.",
427
+ ]
428
+ `);
429
+ });
@@ -0,0 +1,96 @@
1
+ // Markdown table to code block converter.
2
+ // Discord doesn't render GFM tables, so this converts them to
3
+ // space-aligned code blocks for proper monospace display.
4
+ import { Lexer } from 'marked';
5
+ export function formatMarkdownTables(markdown) {
6
+ const lexer = new Lexer();
7
+ const tokens = lexer.lex(markdown);
8
+ let result = '';
9
+ for (const token of tokens) {
10
+ if (token.type === 'table') {
11
+ result += formatTableToken(token);
12
+ }
13
+ else {
14
+ result += token.raw;
15
+ }
16
+ }
17
+ return result;
18
+ }
19
+ function formatTableToken(table) {
20
+ const headers = table.header.map((cell) => {
21
+ return extractCellText(cell.tokens);
22
+ });
23
+ const rows = table.rows.map((row) => {
24
+ return row.map((cell) => {
25
+ return extractCellText(cell.tokens);
26
+ });
27
+ });
28
+ const columnWidths = calculateColumnWidths(headers, rows);
29
+ const lines = [];
30
+ lines.push(formatRow(headers, columnWidths));
31
+ lines.push(formatSeparator(columnWidths));
32
+ for (const row of rows) {
33
+ lines.push(formatRow(row, columnWidths));
34
+ }
35
+ return '```\n' + lines.join('\n') + '\n```\n';
36
+ }
37
+ function extractCellText(tokens) {
38
+ const parts = [];
39
+ for (const token of tokens) {
40
+ parts.push(extractTokenText(token));
41
+ }
42
+ return parts.join('').trim();
43
+ }
44
+ function extractTokenText(token) {
45
+ switch (token.type) {
46
+ case 'text':
47
+ case 'codespan':
48
+ case 'escape':
49
+ return token.text;
50
+ case 'link':
51
+ return token.href;
52
+ case 'image':
53
+ return token.href;
54
+ case 'strong':
55
+ case 'em':
56
+ case 'del':
57
+ return token.tokens ? extractCellText(token.tokens) : token.text;
58
+ case 'br':
59
+ return ' ';
60
+ default: {
61
+ const tokenAny = token;
62
+ if (tokenAny.tokens && Array.isArray(tokenAny.tokens)) {
63
+ return extractCellText(tokenAny.tokens);
64
+ }
65
+ if (typeof tokenAny.text === 'string') {
66
+ return tokenAny.text;
67
+ }
68
+ return '';
69
+ }
70
+ }
71
+ }
72
+ function calculateColumnWidths(headers, rows) {
73
+ const widths = headers.map((h) => {
74
+ return h.length;
75
+ });
76
+ for (const row of rows) {
77
+ for (let i = 0; i < row.length; i++) {
78
+ const cell = row[i] ?? '';
79
+ widths[i] = Math.max(widths[i] ?? 0, cell.length);
80
+ }
81
+ }
82
+ return widths;
83
+ }
84
+ function formatRow(cells, widths) {
85
+ const paddedCells = cells.map((cell, i) => {
86
+ return cell.padEnd(widths[i] ?? 0);
87
+ });
88
+ return paddedCells.join(' ');
89
+ }
90
+ function formatSeparator(widths) {
91
+ return widths
92
+ .map((w) => {
93
+ return '-'.repeat(w);
94
+ })
95
+ .join(' ');
96
+ }