@onmars/lunar-core 0.1.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 (92) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +13 -0
  3. package/package.json +32 -0
  4. package/src/__tests__/clear-command.test.ts +214 -0
  5. package/src/__tests__/command-handler.test.ts +169 -0
  6. package/src/__tests__/compact-command.test.ts +80 -0
  7. package/src/__tests__/config-command.test.ts +240 -0
  8. package/src/__tests__/config-loader.test.ts +1512 -0
  9. package/src/__tests__/config.test.ts +429 -0
  10. package/src/__tests__/cron-command.test.ts +418 -0
  11. package/src/__tests__/cron-parser.test.ts +259 -0
  12. package/src/__tests__/daemon.test.ts +346 -0
  13. package/src/__tests__/dedup.test.ts +404 -0
  14. package/src/__tests__/e2e-sanitization.ts +168 -0
  15. package/src/__tests__/e2e-skill-loader.test.ts +176 -0
  16. package/src/__tests__/fixtures/AGENTS.md +4 -0
  17. package/src/__tests__/fixtures/IDENTITY.md +2 -0
  18. package/src/__tests__/fixtures/SOUL.md +3 -0
  19. package/src/__tests__/fixtures/moons/athena/IDENTITY.md +2 -0
  20. package/src/__tests__/fixtures/moons/athena/SOUL.md +3 -0
  21. package/src/__tests__/fixtures/moons/hermes/SOUL.md +3 -0
  22. package/src/__tests__/fixtures/skills/brain/SKILL.md +6 -0
  23. package/src/__tests__/fixtures/skills/empty/SKILL.md +3 -0
  24. package/src/__tests__/fixtures/skills/multiline/SKILL.md +7 -0
  25. package/src/__tests__/fixtures/skills/no-desc/SKILL.md +5 -0
  26. package/src/__tests__/fixtures/skills/notion/SKILL.md +6 -0
  27. package/src/__tests__/fixtures/skills/quoted/SKILL.md +6 -0
  28. package/src/__tests__/hook-runner.test.ts +1689 -0
  29. package/src/__tests__/input-sanitization.test.ts +367 -0
  30. package/src/__tests__/logger.test.ts +163 -0
  31. package/src/__tests__/memory-orchestrator.test.ts +552 -0
  32. package/src/__tests__/model-catalog.test.ts +215 -0
  33. package/src/__tests__/model-command.test.ts +185 -0
  34. package/src/__tests__/moon-loader.test.ts +398 -0
  35. package/src/__tests__/ping-command.test.ts +85 -0
  36. package/src/__tests__/plugin.test.ts +258 -0
  37. package/src/__tests__/remind-command.test.ts +368 -0
  38. package/src/__tests__/reset-command.test.ts +92 -0
  39. package/src/__tests__/router.test.ts +1246 -0
  40. package/src/__tests__/scheduler.test.ts +469 -0
  41. package/src/__tests__/security.test.ts +214 -0
  42. package/src/__tests__/session-meta.test.ts +101 -0
  43. package/src/__tests__/session-tracker.test.ts +389 -0
  44. package/src/__tests__/session.test.ts +241 -0
  45. package/src/__tests__/skill-loader.test.ts +153 -0
  46. package/src/__tests__/status-command.test.ts +153 -0
  47. package/src/__tests__/stop-command.test.ts +60 -0
  48. package/src/__tests__/think-command.test.ts +146 -0
  49. package/src/__tests__/usage-api.test.ts +222 -0
  50. package/src/__tests__/usage-command-api-fail.test.ts +48 -0
  51. package/src/__tests__/usage-command-no-oauth.test.ts +48 -0
  52. package/src/__tests__/usage-command.test.ts +173 -0
  53. package/src/__tests__/whoami-command.test.ts +124 -0
  54. package/src/index.ts +122 -0
  55. package/src/lib/command-handler.ts +135 -0
  56. package/src/lib/commands/clear.ts +69 -0
  57. package/src/lib/commands/compact.ts +14 -0
  58. package/src/lib/commands/config-show.ts +49 -0
  59. package/src/lib/commands/cron.ts +118 -0
  60. package/src/lib/commands/help.ts +26 -0
  61. package/src/lib/commands/model.ts +71 -0
  62. package/src/lib/commands/ping.ts +24 -0
  63. package/src/lib/commands/remind.ts +75 -0
  64. package/src/lib/commands/status.ts +118 -0
  65. package/src/lib/commands/stop.ts +18 -0
  66. package/src/lib/commands/think.ts +42 -0
  67. package/src/lib/commands/usage.ts +56 -0
  68. package/src/lib/commands/whoami.ts +23 -0
  69. package/src/lib/config-loader.ts +1449 -0
  70. package/src/lib/config.ts +202 -0
  71. package/src/lib/cron-parser.ts +388 -0
  72. package/src/lib/daemon.ts +216 -0
  73. package/src/lib/dedup.ts +414 -0
  74. package/src/lib/hook-runner.ts +1270 -0
  75. package/src/lib/logger.ts +55 -0
  76. package/src/lib/memory-orchestrator.ts +415 -0
  77. package/src/lib/model-catalog.ts +240 -0
  78. package/src/lib/moon-loader.ts +291 -0
  79. package/src/lib/plugin.ts +148 -0
  80. package/src/lib/router.ts +1135 -0
  81. package/src/lib/scheduler.ts +422 -0
  82. package/src/lib/security.ts +259 -0
  83. package/src/lib/session-tracker.ts +222 -0
  84. package/src/lib/session.ts +158 -0
  85. package/src/lib/skill-loader.ts +166 -0
  86. package/src/lib/usage-api.ts +145 -0
  87. package/src/types/agent.ts +86 -0
  88. package/src/types/channel.ts +93 -0
  89. package/src/types/index.ts +32 -0
  90. package/src/types/memory.ts +92 -0
  91. package/src/types/moon.ts +56 -0
  92. package/src/types/voice.ts +74 -0
@@ -0,0 +1,92 @@
1
+ /**
2
+ * /reset Command — Test Suite
3
+ *
4
+ * Spec: /reset is an alias for /clear, using the same handler function.
5
+ *
6
+ * Key contracts:
7
+ * - /reset delegates to the clearCommand handler
8
+ * - The command is registered in CommandHandler
9
+ */
10
+ import { describe, expect, test } from 'bun:test'
11
+ import type { CommandContext } from '../lib/command-handler'
12
+ import { CommandHandler } from '../lib/command-handler'
13
+ import { clearCommand } from '../lib/commands/clear'
14
+ import { SessionTracker } from '../lib/session-tracker'
15
+
16
+ function makeCtx(overrides?: Partial<CommandContext>): CommandContext {
17
+ return {
18
+ sessionKey: 'test:channel-1',
19
+ message: {
20
+ id: 'msg-1',
21
+ channelId: 'channel-1',
22
+ sender: { id: 'user-1', name: 'Test User' },
23
+ text: '/reset',
24
+ timestamp: new Date(),
25
+ },
26
+ tracker: new SessionTracker(),
27
+ daemonStartedAt: Date.now(),
28
+ agent: { id: 'claude', name: 'Claude Code (CLI)' },
29
+ clearSession: async () => ({ sessionCleared: true, hooksRan: false }),
30
+ ...overrides,
31
+ }
32
+ }
33
+
34
+ // ═══════════════════════════════════════════════════════════
35
+ // Registration
36
+ // ═══════════════════════════════════════════════════════════
37
+
38
+ describe('/reset registration', () => {
39
+ test('command is recognized after registration', () => {
40
+ const handler = new CommandHandler()
41
+ handler.register('reset', 'Reset session (alias for /clear)', clearCommand)
42
+
43
+ expect(handler.isCommand('/reset')).toBe(true)
44
+ })
45
+
46
+ test('command appears in list', () => {
47
+ const handler = new CommandHandler()
48
+ handler.register('reset', 'Reset session (alias for /clear)', clearCommand)
49
+
50
+ const commands = handler.list()
51
+ const resetCmd = commands.find((c) => c.name === 'reset')
52
+ expect(resetCmd).toBeDefined()
53
+ expect(resetCmd!.description).toContain('alias')
54
+ })
55
+ })
56
+
57
+ // ═══════════════════════════════════════════════════════════
58
+ // Delegation
59
+ // ═══════════════════════════════════════════════════════════
60
+
61
+ describe('/reset delegates to clearCommand', () => {
62
+ test('calls clearSession when handled via CommandHandler', async () => {
63
+ let clearCalled = false
64
+ const handler = new CommandHandler()
65
+ handler.register('reset', 'Reset session (alias for /clear)', clearCommand)
66
+
67
+ const ctx = makeCtx({
68
+ clearSession: async () => {
69
+ clearCalled = true
70
+ return { sessionCleared: true, hooksRan: false }
71
+ },
72
+ })
73
+
74
+ const result = await handler.handle('/reset', ctx)
75
+ expect(clearCalled).toBe(true)
76
+ expect(result).toContain('Session Cleared')
77
+ })
78
+
79
+ test('produces the same output as /clear', async () => {
80
+ const handler = new CommandHandler()
81
+ handler.register('reset', 'Reset session (alias for /clear)', clearCommand)
82
+ handler.register('clear', 'Clear session', clearCommand)
83
+
84
+ const ctx1 = makeCtx()
85
+ const ctx2 = makeCtx()
86
+
87
+ const resetResult = await handler.handle('/reset', ctx1)
88
+ const clearResult = await handler.handle('/clear', ctx2)
89
+
90
+ expect(resetResult).toEqual(clearResult)
91
+ })
92
+ })