kimaki 0.4.20 → 0.4.22

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.
@@ -0,0 +1,418 @@
1
+ import { test, expect } from 'vitest';
2
+ import { formatMarkdownTables } from './format-tables.js';
3
+ test('formats simple table', () => {
4
+ const input = `| Name | Age |
5
+ | --- | --- |
6
+ | Alice | 30 |
7
+ | Bob | 25 |`;
8
+ const result = formatMarkdownTables(input);
9
+ expect(result).toMatchInlineSnapshot(`
10
+ "\`\`\`
11
+ Name Age
12
+ ----- ---
13
+ Alice 30
14
+ Bob 25
15
+ \`\`\`
16
+ "
17
+ `);
18
+ });
19
+ test('formats table with varying column widths', () => {
20
+ const input = `| Item | Quantity | Price |
21
+ | --- | --- | --- |
22
+ | Apples | 10 | $5 |
23
+ | Oranges | 3 | $2 |
24
+ | Bananas with long name | 100 | $15.99 |`;
25
+ const result = formatMarkdownTables(input);
26
+ expect(result).toMatchInlineSnapshot(`
27
+ "\`\`\`
28
+ Item Quantity Price
29
+ ---------------------- -------- ------
30
+ Apples 10 $5
31
+ Oranges 3 $2
32
+ Bananas with long name 100 $15.99
33
+ \`\`\`
34
+ "
35
+ `);
36
+ });
37
+ test('strips bold formatting from cells', () => {
38
+ const input = `| Header | Value |
39
+ | --- | --- |
40
+ | **Bold text** | Normal |
41
+ | Mixed **bold** text | Another |`;
42
+ const result = formatMarkdownTables(input);
43
+ expect(result).toMatchInlineSnapshot(`
44
+ "\`\`\`
45
+ Header Value
46
+ --------------- -------
47
+ Bold text Normal
48
+ Mixed bold text Another
49
+ \`\`\`
50
+ "
51
+ `);
52
+ });
53
+ test('strips italic formatting from cells', () => {
54
+ const input = `| Header | Value |
55
+ | --- | --- |
56
+ | *Italic text* | Normal |
57
+ | _Also italic_ | Another |`;
58
+ const result = formatMarkdownTables(input);
59
+ expect(result).toMatchInlineSnapshot(`
60
+ "\`\`\`
61
+ Header Value
62
+ ----------- -------
63
+ Italic text Normal
64
+ Also italic Another
65
+ \`\`\`
66
+ "
67
+ `);
68
+ });
69
+ test('extracts URL from links', () => {
70
+ const input = `| Name | Link |
71
+ | --- | --- |
72
+ | Google | [Click here](https://google.com) |
73
+ | GitHub | [GitHub Home](https://github.com) |`;
74
+ const result = formatMarkdownTables(input);
75
+ expect(result).toMatchInlineSnapshot(`
76
+ "\`\`\`
77
+ Name Link
78
+ ------ ------------------
79
+ Google https://google.com
80
+ GitHub https://github.com
81
+ \`\`\`
82
+ "
83
+ `);
84
+ });
85
+ test('handles inline code in cells', () => {
86
+ const input = `| Function | Description |
87
+ | --- | --- |
88
+ | \`console.log\` | Logs to console |
89
+ | \`Array.map\` | Maps array items |`;
90
+ const result = formatMarkdownTables(input);
91
+ expect(result).toMatchInlineSnapshot(`
92
+ "\`\`\`
93
+ Function Description
94
+ ----------- ----------------
95
+ console.log Logs to console
96
+ Array.map Maps array items
97
+ \`\`\`
98
+ "
99
+ `);
100
+ });
101
+ test('handles mixed formatting in single cell', () => {
102
+ const input = `| Description |
103
+ | --- |
104
+ | This has **bold**, *italic*, and \`code\` |
105
+ | Also [a link](https://example.com) here |`;
106
+ const result = formatMarkdownTables(input);
107
+ expect(result).toMatchInlineSnapshot(`
108
+ "\`\`\`
109
+ Description
110
+ -------------------------------
111
+ This has bold, italic, and code
112
+ Also https://example.com here
113
+ \`\`\`
114
+ "
115
+ `);
116
+ });
117
+ test('handles strikethrough text', () => {
118
+ const input = `| Status | Item |
119
+ | --- | --- |
120
+ | Done | ~~Deleted item~~ |
121
+ | Active | Normal item |`;
122
+ const result = formatMarkdownTables(input);
123
+ expect(result).toMatchInlineSnapshot(`
124
+ "\`\`\`
125
+ Status Item
126
+ ------ ------------
127
+ Done Deleted item
128
+ Active Normal item
129
+ \`\`\`
130
+ "
131
+ `);
132
+ });
133
+ test('preserves content before table', () => {
134
+ const input = `Here is some text before the table.
135
+
136
+ | Col A | Col B |
137
+ | --- | --- |
138
+ | 1 | 2 |`;
139
+ const result = formatMarkdownTables(input);
140
+ expect(result).toMatchInlineSnapshot(`
141
+ "Here is some text before the table.
142
+
143
+ \`\`\`
144
+ Col A Col B
145
+ ----- -----
146
+ 1 2
147
+ \`\`\`
148
+ "
149
+ `);
150
+ });
151
+ test('preserves content after table', () => {
152
+ const input = `| Col A | Col B |
153
+ | --- | --- |
154
+ | 1 | 2 |
155
+
156
+ And here is text after.`;
157
+ const result = formatMarkdownTables(input);
158
+ expect(result).toMatchInlineSnapshot(`
159
+ "\`\`\`
160
+ Col A Col B
161
+ ----- -----
162
+ 1 2
163
+ \`\`\`
164
+ And here is text after."
165
+ `);
166
+ });
167
+ test('preserves content before and after table', () => {
168
+ const input = `Some intro text.
169
+
170
+ | Name | Value |
171
+ | --- | --- |
172
+ | Key | 123 |
173
+
174
+ Some outro text.`;
175
+ const result = formatMarkdownTables(input);
176
+ expect(result).toMatchInlineSnapshot(`
177
+ "Some intro text.
178
+
179
+ \`\`\`
180
+ Name Value
181
+ ---- -----
182
+ Key 123
183
+ \`\`\`
184
+ Some outro text."
185
+ `);
186
+ });
187
+ test('handles multiple tables in same content', () => {
188
+ const input = `First table:
189
+
190
+ | A | B |
191
+ | --- | --- |
192
+ | 1 | 2 |
193
+
194
+ Some text between.
195
+
196
+ Second table:
197
+
198
+ | X | Y | Z |
199
+ | --- | --- | --- |
200
+ | a | b | c |`;
201
+ const result = formatMarkdownTables(input);
202
+ expect(result).toMatchInlineSnapshot(`
203
+ "First table:
204
+
205
+ \`\`\`
206
+ A B
207
+ - -
208
+ 1 2
209
+ \`\`\`
210
+ Some text between.
211
+
212
+ Second table:
213
+
214
+ \`\`\`
215
+ X Y Z
216
+ - - -
217
+ a b c
218
+ \`\`\`
219
+ "
220
+ `);
221
+ });
222
+ test('handles empty cells', () => {
223
+ const input = `| Name | Optional |
224
+ | --- | --- |
225
+ | Alice | |
226
+ | | Bob |
227
+ | | |`;
228
+ const result = formatMarkdownTables(input);
229
+ expect(result).toMatchInlineSnapshot(`
230
+ "\`\`\`
231
+ Name Optional
232
+ ----- --------
233
+ Alice
234
+ Bob
235
+
236
+ \`\`\`
237
+ "
238
+ `);
239
+ });
240
+ test('handles single column table', () => {
241
+ const input = `| Items |
242
+ | --- |
243
+ | Apple |
244
+ | Banana |
245
+ | Cherry |`;
246
+ const result = formatMarkdownTables(input);
247
+ expect(result).toMatchInlineSnapshot(`
248
+ "\`\`\`
249
+ Items
250
+ ------
251
+ Apple
252
+ Banana
253
+ Cherry
254
+ \`\`\`
255
+ "
256
+ `);
257
+ });
258
+ test('handles single row table', () => {
259
+ const input = `| A | B | C | D |
260
+ | --- | --- | --- | --- |
261
+ | 1 | 2 | 3 | 4 |`;
262
+ const result = formatMarkdownTables(input);
263
+ expect(result).toMatchInlineSnapshot(`
264
+ "\`\`\`
265
+ A B C D
266
+ - - - -
267
+ 1 2 3 4
268
+ \`\`\`
269
+ "
270
+ `);
271
+ });
272
+ test('handles nested formatting', () => {
273
+ const input = `| Description |
274
+ | --- |
275
+ | **Bold with *nested italic* inside** |
276
+ | *Italic with **nested bold** inside* |`;
277
+ const result = formatMarkdownTables(input);
278
+ expect(result).toMatchInlineSnapshot(`
279
+ "\`\`\`
280
+ Description
281
+ ------------------------------
282
+ Bold with nested italic inside
283
+ Italic with nested bold inside
284
+ \`\`\`
285
+ "
286
+ `);
287
+ });
288
+ test('handles image references', () => {
289
+ const input = `| Icon | Name |
290
+ | --- | --- |
291
+ | ![alt](https://example.com/icon.png) | Item 1 |
292
+ | ![](https://cdn.test.com/img.jpg) | Item 2 |`;
293
+ const result = formatMarkdownTables(input);
294
+ expect(result).toMatchInlineSnapshot(`
295
+ "\`\`\`
296
+ Icon Name
297
+ ---------------------------- ------
298
+ https://example.com/icon.png Item 1
299
+ https://cdn.test.com/img.jpg Item 2
300
+ \`\`\`
301
+ "
302
+ `);
303
+ });
304
+ test('preserves code blocks alongside tables', () => {
305
+ const input = `Some code:
306
+
307
+ \`\`\`js
308
+ const x = 1
309
+ \`\`\`
310
+
311
+ A table:
312
+
313
+ | Key | Value |
314
+ | --- | --- |
315
+ | a | 1 |
316
+
317
+ More code:
318
+
319
+ \`\`\`python
320
+ print("hello")
321
+ \`\`\``;
322
+ const result = formatMarkdownTables(input);
323
+ expect(result).toMatchInlineSnapshot(`
324
+ "Some code:
325
+
326
+ \`\`\`js
327
+ const x = 1
328
+ \`\`\`
329
+
330
+ A table:
331
+
332
+ \`\`\`
333
+ Key Value
334
+ --- -----
335
+ a 1
336
+ \`\`\`
337
+ More code:
338
+
339
+ \`\`\`python
340
+ print("hello")
341
+ \`\`\`"
342
+ `);
343
+ });
344
+ test('handles content without tables', () => {
345
+ const input = `Just some regular markdown.
346
+
347
+ - List item 1
348
+ - List item 2
349
+
350
+ **Bold text** and *italic*.`;
351
+ const result = formatMarkdownTables(input);
352
+ expect(result).toMatchInlineSnapshot(`
353
+ "Just some regular markdown.
354
+
355
+ - List item 1
356
+ - List item 2
357
+
358
+ **Bold text** and *italic*."
359
+ `);
360
+ });
361
+ test('handles complex real-world table', () => {
362
+ const input = `## API Endpoints
363
+
364
+ | Method | Endpoint | Description | Auth |
365
+ | --- | --- | --- | --- |
366
+ | GET | \`/api/users\` | List all users | [Bearer token](https://docs.example.com/auth) |
367
+ | POST | \`/api/users\` | Create **new** user | Required |
368
+ | DELETE | \`/api/users/:id\` | ~~Remove~~ *Deactivate* user | Admin only |`;
369
+ const result = formatMarkdownTables(input);
370
+ expect(result).toMatchInlineSnapshot(`
371
+ "## API Endpoints
372
+
373
+ \`\`\`
374
+ Method Endpoint Description Auth
375
+ ------ -------------- ---------------------- -----------------------------
376
+ GET /api/users List all users https://docs.example.com/auth
377
+ POST /api/users Create new user Required
378
+ DELETE /api/users/:id Remove Deactivate user Admin only
379
+ \`\`\`
380
+ "
381
+ `);
382
+ });
383
+ test('handles unicode content', () => {
384
+ const input = `| Emoji | Name | Country |
385
+ | --- | --- | --- |
386
+ | 🍎 | Apple | 日本 |
387
+ | 🍊 | Orange | España |
388
+ | 🍌 | Banana | Ελλάδα |`;
389
+ const result = formatMarkdownTables(input);
390
+ expect(result).toMatchInlineSnapshot(`
391
+ "\`\`\`
392
+ Emoji Name Country
393
+ ----- ------ -------
394
+ 🍎 Apple 日本
395
+ 🍊 Orange España
396
+ 🍌 Banana Ελλάδα
397
+ \`\`\`
398
+ "
399
+ `);
400
+ });
401
+ test('handles numbers and special characters', () => {
402
+ const input = `| Price | Discount | Final |
403
+ | --- | --- | --- |
404
+ | $100.00 | -15% | $85.00 |
405
+ | €50,00 | -10% | €45,00 |
406
+ | £75.99 | N/A | £75.99 |`;
407
+ const result = formatMarkdownTables(input);
408
+ expect(result).toMatchInlineSnapshot(`
409
+ "\`\`\`
410
+ Price Discount Final
411
+ ------- -------- ------
412
+ $100.00 -15% $85.00
413
+ €50,00 -10% €45,00
414
+ £75.99 N/A £75.99
415
+ \`\`\`
416
+ "
417
+ `);
418
+ });
package/dist/markdown.js CHANGED
@@ -1,5 +1,5 @@
1
- import { format } from 'date-fns';
2
1
  import * as yaml from 'js-yaml';
2
+ import { formatDateTime } from './utils.js';
3
3
  import { extractNonXmlContent } from './xml.js';
4
4
  export class ShareMarkdown {
5
5
  client;
@@ -49,8 +49,8 @@ export class ShareMarkdown {
49
49
  if (includeSystemInfo === true) {
50
50
  lines.push('## Session Information');
51
51
  lines.push('');
52
- lines.push(`- **Created**: ${format(new Date(session.time.created), 'MMM d, yyyy, h:mm a')}`);
53
- lines.push(`- **Updated**: ${format(new Date(session.time.updated), 'MMM d, yyyy, h:mm a')}`);
52
+ lines.push(`- **Created**: ${formatDateTime(new Date(session.time.created))}`);
53
+ lines.push(`- **Updated**: ${formatDateTime(new Date(session.time.updated))}`);
54
54
  if (session.version) {
55
55
  lines.push(`- **OpenCode Version**: v${session.version}`);
56
56
  }
package/dist/tools.js CHANGED
@@ -5,8 +5,8 @@ import net from 'node:net';
5
5
  import { createOpencodeClient, } from '@opencode-ai/sdk';
6
6
  import { createLogger } from './logger.js';
7
7
  const toolsLogger = createLogger('TOOLS');
8
- import { formatDistanceToNow } from 'date-fns';
9
8
  import { ShareMarkdown } from './markdown.js';
9
+ import { formatDistanceToNow } from './utils.js';
10
10
  import pc from 'picocolors';
11
11
  import { initializeOpencodeForDirectory, getOpencodeSystemMessage, } from './discordBot.js';
12
12
  export async function getTools({ onMessageCompleted, directory, }) {
@@ -187,9 +187,7 @@ export async function getTools({ onMessageCompleted, directory, }) {
187
187
  id: session.id,
188
188
  folder: session.directory,
189
189
  status,
190
- finishedAt: formatDistanceToNow(new Date(finishedAt), {
191
- addSuffix: true,
192
- }),
190
+ finishedAt: formatDistanceToNow(new Date(finishedAt)),
193
191
  title: session.title,
194
192
  prompt: session.title,
195
193
  };
package/dist/utils.js CHANGED
@@ -49,3 +49,34 @@ export function isAbortError(error, signal) {
49
49
  (signal?.aborted ?? false))) ||
50
50
  (error instanceof DOMException && error.name === 'AbortError'));
51
51
  }
52
+ const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto' });
53
+ const TIME_DIVISIONS = [
54
+ { amount: 60, name: 'seconds' },
55
+ { amount: 60, name: 'minutes' },
56
+ { amount: 24, name: 'hours' },
57
+ { amount: 7, name: 'days' },
58
+ { amount: 4.34524, name: 'weeks' },
59
+ { amount: 12, name: 'months' },
60
+ { amount: Number.POSITIVE_INFINITY, name: 'years' },
61
+ ];
62
+ export function formatDistanceToNow(date) {
63
+ let duration = (date.getTime() - Date.now()) / 1000;
64
+ for (const division of TIME_DIVISIONS) {
65
+ if (Math.abs(duration) < division.amount) {
66
+ return rtf.format(Math.round(duration), division.name);
67
+ }
68
+ duration /= division.amount;
69
+ }
70
+ return rtf.format(Math.round(duration), 'years');
71
+ }
72
+ const dtf = new Intl.DateTimeFormat('en-US', {
73
+ month: 'short',
74
+ day: 'numeric',
75
+ year: 'numeric',
76
+ hour: 'numeric',
77
+ minute: '2-digit',
78
+ hour12: true,
79
+ });
80
+ export function formatDateTime(date) {
81
+ return dtf.format(date);
82
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "kimaki",
3
3
  "module": "index.ts",
4
4
  "type": "module",
5
- "version": "0.4.20",
5
+ "version": "0.4.22",
6
6
  "scripts": {
7
7
  "dev": "tsx --env-file .env src/cli.ts",
8
8
  "prepublishOnly": "pnpm tsc",
@@ -41,7 +41,6 @@
41
41
  "ai": "^5.0.114",
42
42
  "better-sqlite3": "^12.3.0",
43
43
  "cac": "^6.7.14",
44
- "date-fns": "^4.1.0",
45
44
  "discord.js": "^14.16.3",
46
45
  "domhandler": "^5.0.3",
47
46
  "go-try": "^3.0.2",
package/src/cli.ts CHANGED
@@ -149,7 +149,7 @@ async function registerCommands(token: string, appId: string) {
149
149
  })
150
150
  .toJSON(),
151
151
  new SlashCommandBuilder()
152
- .setName('add-new-project')
152
+ .setName('create-new-project')
153
153
  .setDescription('Create a new project folder, initialize git, and start a session')
154
154
  .addStringOption((option) => {
155
155
  option