@raidiant/notifai 0.5.0 → 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 (74) hide show
  1. package/CHANGELOG.md +165 -0
  2. package/README.md +11 -4
  3. package/dist/claude-wake.d.ts +101 -0
  4. package/dist/claude-wake.js +397 -0
  5. package/dist/claude-wake.js.map +1 -0
  6. package/dist/codex-wake.d.ts +84 -0
  7. package/dist/codex-wake.js +238 -0
  8. package/dist/codex-wake.js.map +1 -0
  9. package/dist/commands.d.ts +31 -11
  10. package/dist/commands.js +679 -232
  11. package/dist/commands.js.map +1 -1
  12. package/dist/config-schema.d.ts +3 -3
  13. package/dist/config-schema.js +11 -49
  14. package/dist/config-schema.js.map +1 -1
  15. package/dist/config.d.ts +23 -45
  16. package/dist/config.js +61 -39
  17. package/dist/config.js.map +1 -1
  18. package/dist/harnesses.d.ts +4 -13
  19. package/dist/harnesses.js +12 -17
  20. package/dist/harnesses.js.map +1 -1
  21. package/dist/hook-adapter.d.ts +10 -1
  22. package/dist/hook-adapter.js +79 -10
  23. package/dist/hook-adapter.js.map +1 -1
  24. package/dist/hooks.d.ts +119 -65
  25. package/dist/hooks.js +330 -285
  26. package/dist/hooks.js.map +1 -1
  27. package/dist/install-hooks.d.ts +76 -24
  28. package/dist/install-hooks.js +301 -125
  29. package/dist/install-hooks.js.map +1 -1
  30. package/dist/interactive.d.ts +32 -1
  31. package/dist/interactive.js +165 -51
  32. package/dist/interactive.js.map +1 -1
  33. package/dist/main.js +14 -21
  34. package/dist/main.js.map +1 -1
  35. package/dist/native-skills.d.ts +1 -1
  36. package/dist/native-skills.js +23 -58
  37. package/dist/native-skills.js.map +1 -1
  38. package/dist/pack-feedback-slice.d.ts +35 -0
  39. package/dist/pack-feedback-slice.js +126 -0
  40. package/dist/pack-feedback-slice.js.map +1 -0
  41. package/dist/readiness.d.ts +20 -0
  42. package/dist/readiness.js +24 -0
  43. package/dist/readiness.js.map +1 -1
  44. package/dist/release.d.ts +31 -0
  45. package/dist/release.js +52 -0
  46. package/dist/release.js.map +1 -0
  47. package/dist/ui/theme.d.ts +1 -1
  48. package/package.json +11 -10
  49. package/src/commands.test.ts +386 -36
  50. package/src/commands.ts +473 -182
  51. package/src/config-schema.ts +2 -17
  52. package/src/config.test.ts +29 -4
  53. package/src/config.ts +67 -11
  54. package/src/harnesses.ts +7 -0
  55. package/src/hook-adapter.test.ts +43 -1
  56. package/src/hook-adapter.ts +83 -11
  57. package/src/hooks.test.ts +4 -5
  58. package/src/install-hooks.test.ts +154 -2
  59. package/src/install-hooks.ts +231 -44
  60. package/src/interactive.test.ts +338 -0
  61. package/src/interactive.ts +221 -49
  62. package/src/main.ts +14 -20
  63. package/src/native-skills.test.ts +75 -0
  64. package/src/native-skills.ts +31 -75
  65. package/src/pack-feedback-slice.test.ts +212 -0
  66. package/src/pack-feedback-slice.ts +187 -0
  67. package/src/readiness.test.ts +25 -0
  68. package/src/readiness.ts +38 -0
  69. package/src/release.ts +51 -0
  70. package/src/skill.test.ts +43 -0
  71. package/src/ui/config-view.test.ts +5 -4
  72. package/dist/idle.d.ts +0 -16
  73. package/dist/idle.js +0 -44
  74. package/dist/idle.js.map +0 -1
@@ -0,0 +1,338 @@
1
+ import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs'
2
+ import os from 'node:os'
3
+ import path from 'node:path'
4
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
5
+ import type { ApiClient } from './client.js'
6
+ import { EXIT, type CommandDeps } from './commands.js'
7
+ import { findInstallations } from './install-hooks.js'
8
+
9
+ const CANCEL = Symbol.for('notifai-clack-cancel')
10
+
11
+ type PromptCall = {
12
+ kind: 'select' | 'text' | 'confirm' | 'multiselect'
13
+ message: string
14
+ options?: { value: string; label: string; hint?: string }[]
15
+ }
16
+
17
+ const promptLog: PromptCall[] = []
18
+ let answers: Array<unknown | ((call: PromptCall) => unknown)> = []
19
+
20
+ function takeAnswer(call: PromptCall): unknown {
21
+ promptLog.push(call)
22
+ const next = answers.shift()
23
+ if (next === undefined) {
24
+ throw new Error(`unexpected ${call.kind}: ${call.message}`)
25
+ }
26
+ return typeof next === 'function' ? next(call) : next
27
+ }
28
+
29
+ vi.mock('@clack/prompts', () => ({
30
+ isCancel: (value: unknown) => value === CANCEL,
31
+ select: async (args: { message: string; options: { value: string; label: string; hint?: string }[] }) =>
32
+ takeAnswer({ kind: 'select', message: args.message, options: args.options }),
33
+ text: async (args: { message: string }) => takeAnswer({ kind: 'text', message: args.message }),
34
+ confirm: async (args: { message: string }) => takeAnswer({ kind: 'confirm', message: args.message }),
35
+ multiselect: async (args: { message: string; options: { value: string; label: string; hint?: string }[] }) =>
36
+ takeAnswer({ kind: 'multiselect', message: args.message, options: args.options }),
37
+ note: () => {},
38
+ outro: vi.fn(),
39
+ log: { step: () => {}, success: () => {}, error: () => {}, warn: () => {} },
40
+ spinner: () => ({ start: () => {}, stop: () => {} }),
41
+ }))
42
+
43
+ const { interactiveCommand, routingHookActions, uninstallScopeOptions } = await import('./interactive.js')
44
+ const clack = await import('@clack/prompts')
45
+
46
+ function isolatedEnv(cwd: string): NodeJS.ProcessEnv {
47
+ const home = path.join(cwd, 'home')
48
+ return {
49
+ HOME: home,
50
+ CLAUDE_CONFIG_DIR: path.join(home, '.claude'),
51
+ CODEX_HOME: path.join(home, '.codex'),
52
+ XDG_CONFIG_HOME: path.join(cwd, 'config'),
53
+ XDG_STATE_HOME: path.join(cwd, 'state'),
54
+ NOTIFAI_NO_ANIMATION: '1',
55
+ }
56
+ }
57
+
58
+ function makeClient(): ApiClient {
59
+ return {
60
+ health: async () => true,
61
+ capabilities: async () => ({ schema_version: 1, platform: 'ios' }),
62
+ listDevices: async () => ({ devices: [] }),
63
+ accessStatus: async () => ({ email: 'rafael@example.test' }),
64
+ } as unknown as ApiClient
65
+ }
66
+
67
+ function makeDeps(cwd: string, env: NodeJS.ProcessEnv = isolatedEnv(cwd)): CommandDeps {
68
+ return {
69
+ io: {
70
+ out: () => {},
71
+ err: () => {},
72
+ confirm: async () => false,
73
+ openUrl: () => {},
74
+ },
75
+ store: {
76
+ load: () => ({
77
+ machineId: 'mac_test',
78
+ secret: 'test-secret',
79
+ baseUrl: 'https://test.notifai.invalid',
80
+ machineName: 'test-machine',
81
+ }),
82
+ save: () => {},
83
+ clear: () => {},
84
+ describe: () => 'test credential store',
85
+ },
86
+ env,
87
+ cwd,
88
+ hookAdapterHome: path.join(cwd, 'adapter-home'),
89
+ clientFactory: () => makeClient(),
90
+ }
91
+ }
92
+
93
+ function markClaudeProject(cwd: string): void {
94
+ mkdirSync(path.join(cwd, '.claude'), { recursive: true })
95
+ }
96
+
97
+ function writeClaudeHooks(file: string): void {
98
+ mkdirSync(path.dirname(file), { recursive: true })
99
+ writeFileSync(
100
+ file,
101
+ `${JSON.stringify(
102
+ {
103
+ hooks: {
104
+ UserPromptSubmit: [
105
+ { hooks: [{ type: 'command', command: 'notifai hook user-prompt-submit --owner notifai' }] },
106
+ ],
107
+ Stop: [{ hooks: [{ type: 'command', command: 'notifai hook stop --owner notifai' }] }],
108
+ },
109
+ },
110
+ null,
111
+ 2,
112
+ )}\n`,
113
+ )
114
+ }
115
+
116
+ function routingCall(): PromptCall {
117
+ const call = promptLog.find((entry) => entry.kind === 'select' && entry.message === 'Question routing')
118
+ if (call === undefined) throw new Error('Question routing was not shown')
119
+ return call
120
+ }
121
+
122
+ function optionValues(call: PromptCall): string[] {
123
+ return (call.options ?? []).map((option) => option.value)
124
+ }
125
+
126
+ function optionLabels(call: PromptCall): string[] {
127
+ return (call.options ?? []).map((option) => option.label)
128
+ }
129
+
130
+ describe('routingHookActions', () => {
131
+ it('hides install and uninstall when this directory cannot apply hooks', () => {
132
+ const options = routingHookActions({
133
+ canInstall: false,
134
+ projectInstallations: [],
135
+ machineInstallations: [],
136
+ hooksReady: false,
137
+ })
138
+ expect(options.map((option) => option.value)).toEqual(['settings', 'back'])
139
+ })
140
+
141
+ it('offers install labeled as hooks, without uninstall, when nothing is wired', () => {
142
+ const options = routingHookActions({
143
+ canInstall: true,
144
+ projectInstallations: [],
145
+ machineInstallations: [],
146
+ hooksReady: false,
147
+ })
148
+ expect(options.find((option) => option.value === 'install')).toMatchObject({
149
+ label: 'Install hooks',
150
+ hint: 'this project or this machine',
151
+ })
152
+ expect(options.some((option) => option.value === 'uninstall')).toBe(false)
153
+ })
154
+
155
+ it('names the project scope when only project hooks exist', () => {
156
+ const options = routingHookActions({
157
+ canInstall: true,
158
+ projectInstallations: [{ harness: 'claude-code' }],
159
+ machineInstallations: [],
160
+ hooksReady: true,
161
+ })
162
+ expect(options.find((option) => option.value === 'install')?.label).toBe('Re-install hooks')
163
+ expect(options.find((option) => option.value === 'uninstall')).toMatchObject({
164
+ label: 'Uninstall hooks for this project',
165
+ hint: 'claude-code',
166
+ })
167
+ })
168
+
169
+ it('names the machine scope when only machine hooks exist', () => {
170
+ const options = routingHookActions({
171
+ canInstall: false,
172
+ projectInstallations: [],
173
+ machineInstallations: [{ harness: 'claude-code' }],
174
+ hooksReady: true,
175
+ })
176
+ expect(options.some((option) => option.value === 'install')).toBe(false)
177
+ expect(options.find((option) => option.value === 'uninstall')).toMatchObject({
178
+ label: 'Uninstall hooks on this machine',
179
+ })
180
+ })
181
+
182
+ it('asks which scope to remove when both are present', () => {
183
+ const options = routingHookActions({
184
+ canInstall: true,
185
+ projectInstallations: [{ harness: 'claude-code' }],
186
+ machineInstallations: [{ harness: 'claude-code' }],
187
+ hooksReady: true,
188
+ })
189
+ expect(options.find((option) => option.value === 'uninstall')).toMatchObject({
190
+ label: 'Uninstall hooks',
191
+ hint: 'this project or this machine',
192
+ })
193
+ expect(uninstallScopeOptions([{ harness: 'claude-code' }], [{ harness: 'codex' }])).toEqual([
194
+ { value: 'project', label: 'This project', hint: 'remove hooks from this directory' },
195
+ { value: 'machine', label: 'This machine', hint: 'remove hooks for every project here' },
196
+ ])
197
+ })
198
+ })
199
+
200
+ describe('interactiveCommand', () => {
201
+ beforeEach(() => {
202
+ promptLog.length = 0
203
+ answers = []
204
+ vi.mocked(clack.outro).mockClear()
205
+ })
206
+
207
+ afterEach(() => {
208
+ answers = []
209
+ })
210
+
211
+ it('quits from the root menu on Escape', async () => {
212
+ const cwd = mkdtempSync(path.join(os.tmpdir(), 'notifai-interactive-root-esc-'))
213
+ answers = [CANCEL]
214
+
215
+ expect(await interactiveCommand(makeDeps(cwd), '0.0.0-test')).toBe(EXIT.ok)
216
+ expect(promptLog.map((entry) => entry.message)).toEqual(['What would you like to do?'])
217
+ expect(clack.outro).toHaveBeenCalledOnce()
218
+ })
219
+
220
+ it('goes back to the root menu when Escape is pressed on question routing', async () => {
221
+ const cwd = mkdtempSync(path.join(os.tmpdir(), 'notifai-interactive-routing-esc-'))
222
+ markClaudeProject(cwd)
223
+ answers = ['routing', CANCEL, CANCEL]
224
+
225
+ expect(await interactiveCommand(makeDeps(cwd), '0.0.0-test')).toBe(EXIT.ok)
226
+ expect(promptLog.filter((entry) => entry.message === 'What would you like to do?')).toHaveLength(2)
227
+ expect(clack.outro).toHaveBeenCalledOnce()
228
+ })
229
+
230
+ it('goes back from settings and account instead of quitting', async () => {
231
+ const cwd = mkdtempSync(path.join(os.tmpdir(), 'notifai-interactive-nested-esc-'))
232
+ answers = ['settings', CANCEL, 'account', CANCEL, 'quit']
233
+
234
+ expect(await interactiveCommand(makeDeps(cwd), '0.0.0-test')).toBe(EXIT.ok)
235
+ expect(promptLog.filter((entry) => entry.message === 'What would you like to do?')).toHaveLength(3)
236
+ expect(clack.outro).toHaveBeenCalledOnce()
237
+ })
238
+
239
+ it('does not install hooks when Escape is pressed on the install scope picker', async () => {
240
+ const cwd = mkdtempSync(path.join(os.tmpdir(), 'notifai-interactive-install-esc-'))
241
+ markClaudeProject(cwd)
242
+ const deps = makeDeps(cwd)
243
+ answers = ['routing', 'install', CANCEL, 'quit']
244
+
245
+ expect(await interactiveCommand(deps, '0.0.0-test')).toBe(EXIT.ok)
246
+ expect(findInstallations(cwd, deps.env, deps.hookAdapterHome)).toEqual([])
247
+ expect(promptLog.some((entry) => entry.message === 'Install hooks for')).toBe(true)
248
+ expect(promptLog.filter((entry) => entry.message === 'What would you like to do?')).toHaveLength(2)
249
+ })
250
+
251
+ it('offers install hooks when a harness applies here and omits uninstall when none are wired', async () => {
252
+ const cwd = mkdtempSync(path.join(os.tmpdir(), 'notifai-interactive-install-offer-'))
253
+ markClaudeProject(cwd)
254
+ answers = ['routing', 'back', 'quit']
255
+
256
+ expect(await interactiveCommand(makeDeps(cwd), '0.0.0-test')).toBe(EXIT.ok)
257
+ expect(optionLabels(routingCall())).toContain('Install hooks')
258
+ expect(optionValues(routingCall())).not.toContain('uninstall')
259
+ })
260
+
261
+ it('hides install when no harness applies in this directory', async () => {
262
+ const cwd = mkdtempSync(path.join(os.tmpdir(), 'notifai-interactive-no-harness-'))
263
+ answers = ['routing', 'back', 'quit']
264
+
265
+ expect(await interactiveCommand(makeDeps(cwd), '0.0.0-test')).toBe(EXIT.ok)
266
+ expect(optionValues(routingCall())).toEqual(['settings', 'back'])
267
+ })
268
+
269
+ it('names machine uninstall and does not strip it on Escape', async () => {
270
+ const cwd = mkdtempSync(path.join(os.tmpdir(), 'notifai-interactive-machine-esc-'))
271
+ const env = isolatedEnv(cwd)
272
+ const deps = makeDeps(cwd, env)
273
+ writeClaudeHooks(path.join(env.CLAUDE_CONFIG_DIR!, 'settings.json'))
274
+ expect(findInstallations(cwd, env, deps.hookAdapterHome).some((item) => item.global)).toBe(true)
275
+
276
+ answers = ['routing', CANCEL, 'quit']
277
+ expect(await interactiveCommand(deps, '0.0.0-test')).toBe(EXIT.ok)
278
+ expect(optionLabels(routingCall())).toContain('Uninstall hooks on this machine')
279
+ expect(findInstallations(cwd, env, deps.hookAdapterHome).some((item) => item.global)).toBe(true)
280
+ })
281
+
282
+ it('uninstalls only the named project scope and leaves machine hooks', async () => {
283
+ const cwd = mkdtempSync(path.join(os.tmpdir(), 'notifai-interactive-scope-'))
284
+ markClaudeProject(cwd)
285
+ const env = isolatedEnv(cwd)
286
+ const deps = makeDeps(cwd, env)
287
+ writeClaudeHooks(path.join(cwd, '.claude', 'settings.local.json'))
288
+ writeClaudeHooks(path.join(env.CLAUDE_CONFIG_DIR!, 'settings.json'))
289
+
290
+ answers = ['routing', 'uninstall', 'project', 'quit']
291
+ expect(await interactiveCommand(deps, '0.0.0-test')).toBe(EXIT.ok)
292
+
293
+ const remaining = findInstallations(cwd, env, deps.hookAdapterHome)
294
+ expect(remaining.some((item) => !item.global && item.harness === 'claude-code')).toBe(false)
295
+ expect(remaining.some((item) => item.global && item.harness === 'claude-code')).toBe(true)
296
+ const scopeCall = promptLog.find((entry) => entry.message === 'Uninstall hooks from')
297
+ expect(scopeCall).toBeDefined()
298
+ expect(optionLabels(scopeCall!)).toEqual(['This project', 'This machine', '← Back'])
299
+ })
300
+
301
+ it('does not strip either scope when Escape is pressed on the uninstall picker', async () => {
302
+ const cwd = mkdtempSync(path.join(os.tmpdir(), 'notifai-interactive-uninstall-esc-'))
303
+ markClaudeProject(cwd)
304
+ const env = isolatedEnv(cwd)
305
+ const deps = makeDeps(cwd, env)
306
+ writeClaudeHooks(path.join(cwd, '.claude', 'settings.local.json'))
307
+ writeClaudeHooks(path.join(env.CLAUDE_CONFIG_DIR!, 'settings.json'))
308
+
309
+ answers = ['routing', 'uninstall', CANCEL, 'quit']
310
+ expect(await interactiveCommand(deps, '0.0.0-test')).toBe(EXIT.ok)
311
+
312
+ const remaining = findInstallations(cwd, env, deps.hookAdapterHome)
313
+ expect(remaining.some((item) => !item.global && item.harness === 'claude-code')).toBe(true)
314
+ expect(remaining.some((item) => item.global && item.harness === 'claude-code')).toBe(true)
315
+ })
316
+
317
+ it('goes back from a test notification prompt instead of quitting', async () => {
318
+ const cwd = mkdtempSync(path.join(os.tmpdir(), 'notifai-interactive-test-esc-'))
319
+ answers = ['test', CANCEL, 'quit']
320
+
321
+ expect(await interactiveCommand(makeDeps(cwd), '0.0.0-test')).toBe(EXIT.ok)
322
+ expect(promptLog.filter((entry) => entry.message === 'What would you like to do?')).toHaveLength(2)
323
+ expect(promptLog.some((entry) => entry.message === 'Title')).toBe(true)
324
+ expect(clack.outro).toHaveBeenCalledOnce()
325
+ })
326
+
327
+ it('uninstalls machine hooks only after that scope is chosen by name', async () => {
328
+ const cwd = mkdtempSync(path.join(os.tmpdir(), 'notifai-interactive-machine-remove-'))
329
+ const env = isolatedEnv(cwd)
330
+ const deps = makeDeps(cwd, env)
331
+ writeClaudeHooks(path.join(env.CLAUDE_CONFIG_DIR!, 'settings.json'))
332
+
333
+ answers = ['routing', 'uninstall', 'quit']
334
+ expect(await interactiveCommand(deps, '0.0.0-test')).toBe(EXIT.ok)
335
+ expect(optionLabels(routingCall())).toContain('Uninstall hooks on this machine')
336
+ expect(findInstallations(cwd, env, deps.hookAdapterHome)).toEqual([])
337
+ })
338
+ })