@raidiant/notifai 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 (54) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +76 -0
  3. package/dist/client.d.ts +40 -0
  4. package/dist/client.js +118 -0
  5. package/dist/client.js.map +1 -0
  6. package/dist/commands.d.ts +225 -0
  7. package/dist/commands.js +1855 -0
  8. package/dist/commands.js.map +1 -0
  9. package/dist/config.d.ts +138 -0
  10. package/dist/config.js +224 -0
  11. package/dist/config.js.map +1 -0
  12. package/dist/credentials.d.ts +31 -0
  13. package/dist/credentials.js +94 -0
  14. package/dist/credentials.js.map +1 -0
  15. package/dist/hooks.d.ts +250 -0
  16. package/dist/hooks.js +792 -0
  17. package/dist/hooks.js.map +1 -0
  18. package/dist/idle.d.ts +16 -0
  19. package/dist/idle.js +44 -0
  20. package/dist/idle.js.map +1 -0
  21. package/dist/install-hooks.d.ts +194 -0
  22. package/dist/install-hooks.js +579 -0
  23. package/dist/install-hooks.js.map +1 -0
  24. package/dist/main.d.ts +2 -0
  25. package/dist/main.js +259 -0
  26. package/dist/main.js.map +1 -0
  27. package/dist/opencode-plugin.d.ts +65 -0
  28. package/dist/opencode-plugin.js +181 -0
  29. package/dist/opencode-plugin.js.map +1 -0
  30. package/dist/readiness.d.ts +87 -0
  31. package/dist/readiness.js +40 -0
  32. package/dist/readiness.js.map +1 -0
  33. package/dist/send.d.ts +86 -0
  34. package/dist/send.js +202 -0
  35. package/dist/send.js.map +1 -0
  36. package/package.json +56 -0
  37. package/src/client.test.ts +83 -0
  38. package/src/client.ts +183 -0
  39. package/src/commands.test.ts +1199 -0
  40. package/src/commands.ts +2201 -0
  41. package/src/config.test.ts +243 -0
  42. package/src/config.ts +347 -0
  43. package/src/credentials.ts +119 -0
  44. package/src/hooks.test.ts +1030 -0
  45. package/src/hooks.ts +1099 -0
  46. package/src/idle.test.ts +32 -0
  47. package/src/idle.ts +41 -0
  48. package/src/install-hooks.test.ts +500 -0
  49. package/src/install-hooks.ts +708 -0
  50. package/src/main.ts +315 -0
  51. package/src/opencode-plugin.ts +203 -0
  52. package/src/readiness.ts +88 -0
  53. package/src/send.ts +272 -0
  54. package/tsconfig.json +10 -0
@@ -0,0 +1,119 @@
1
+ import { execFileSync } from 'node:child_process'
2
+ import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
3
+ import path from 'node:path'
4
+ import { globalConfigDir } from './config.js'
5
+
6
+ export interface MachineCredential {
7
+ machineId: string
8
+ secret: string
9
+ baseUrl: string
10
+ machineName: string
11
+ }
12
+
13
+ export interface CredentialStore {
14
+ load(): MachineCredential | null
15
+ save(credential: MachineCredential): void
16
+ clear(): void
17
+ /** Where the secret lives, for `doctor` and docs. */
18
+ describe(): string
19
+ }
20
+
21
+ const SERVICE = 'io.notifai.cli'
22
+
23
+ /** macOS Keychain via the `security` CLI — no native addons (proposal concern). */
24
+ export class KeychainStore implements CredentialStore {
25
+ load(): MachineCredential | null {
26
+ try {
27
+ const raw = execFileSync(
28
+ 'security',
29
+ ['find-generic-password', '-s', SERVICE, '-a', 'machine', '-w'],
30
+ { stdio: ['ignore', 'pipe', 'ignore'] },
31
+ )
32
+ .toString()
33
+ .trim()
34
+ return JSON.parse(raw) as MachineCredential
35
+ } catch {
36
+ return null
37
+ }
38
+ }
39
+
40
+ save(credential: MachineCredential): void {
41
+ execFileSync(
42
+ 'security',
43
+ [
44
+ 'add-generic-password',
45
+ '-U',
46
+ '-s',
47
+ SERVICE,
48
+ '-a',
49
+ 'machine',
50
+ '-w',
51
+ JSON.stringify(credential),
52
+ ],
53
+ { stdio: 'ignore' },
54
+ )
55
+ }
56
+
57
+ clear(): void {
58
+ try {
59
+ execFileSync('security', ['delete-generic-password', '-s', SERVICE, '-a', 'machine'], {
60
+ stdio: 'ignore',
61
+ })
62
+ } catch {
63
+ // nothing stored
64
+ }
65
+ }
66
+
67
+ describe(): string {
68
+ return `macOS Keychain (${SERVICE})`
69
+ }
70
+ }
71
+
72
+ /** 0600 file fallback for hosts without a keychain. */
73
+ export class FileStore implements CredentialStore {
74
+ constructor(private readonly env: NodeJS.ProcessEnv = process.env) {}
75
+
76
+ private filePath(): string {
77
+ return path.join(globalConfigDir(this.env), 'credentials.json')
78
+ }
79
+
80
+ load(): MachineCredential | null {
81
+ const file = this.filePath()
82
+ if (!existsSync(file)) return null
83
+ try {
84
+ return JSON.parse(readFileSync(file, 'utf8')) as MachineCredential
85
+ } catch {
86
+ return null
87
+ }
88
+ }
89
+
90
+ save(credential: MachineCredential): void {
91
+ const file = this.filePath()
92
+ mkdirSync(path.dirname(file), { recursive: true })
93
+ writeFileSync(file, `${JSON.stringify(credential, null, 2)}\n`, { mode: 0o600 })
94
+ chmodSync(file, 0o600)
95
+ }
96
+
97
+ clear(): void {
98
+ rmSync(this.filePath(), { force: true })
99
+ }
100
+
101
+ describe(): string {
102
+ return this.filePath()
103
+ }
104
+ }
105
+
106
+ function keychainAvailable(): boolean {
107
+ if (process.platform !== 'darwin') return false
108
+ try {
109
+ execFileSync('security', ['help'], { stdio: 'ignore' })
110
+ return true
111
+ } catch {
112
+ return false
113
+ }
114
+ }
115
+
116
+ export function defaultCredentialStore(env: NodeJS.ProcessEnv = process.env): CredentialStore {
117
+ if (env['NOTIFAI_CREDENTIALS'] === 'file') return new FileStore(env)
118
+ return keychainAvailable() ? new KeychainStore() : new FileStore(env)
119
+ }