@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.
- package/LICENSE +202 -0
- package/README.md +76 -0
- package/dist/client.d.ts +40 -0
- package/dist/client.js +118 -0
- package/dist/client.js.map +1 -0
- package/dist/commands.d.ts +225 -0
- package/dist/commands.js +1855 -0
- package/dist/commands.js.map +1 -0
- package/dist/config.d.ts +138 -0
- package/dist/config.js +224 -0
- package/dist/config.js.map +1 -0
- package/dist/credentials.d.ts +31 -0
- package/dist/credentials.js +94 -0
- package/dist/credentials.js.map +1 -0
- package/dist/hooks.d.ts +250 -0
- package/dist/hooks.js +792 -0
- package/dist/hooks.js.map +1 -0
- package/dist/idle.d.ts +16 -0
- package/dist/idle.js +44 -0
- package/dist/idle.js.map +1 -0
- package/dist/install-hooks.d.ts +194 -0
- package/dist/install-hooks.js +579 -0
- package/dist/install-hooks.js.map +1 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +259 -0
- package/dist/main.js.map +1 -0
- package/dist/opencode-plugin.d.ts +65 -0
- package/dist/opencode-plugin.js +181 -0
- package/dist/opencode-plugin.js.map +1 -0
- package/dist/readiness.d.ts +87 -0
- package/dist/readiness.js +40 -0
- package/dist/readiness.js.map +1 -0
- package/dist/send.d.ts +86 -0
- package/dist/send.js +202 -0
- package/dist/send.js.map +1 -0
- package/package.json +56 -0
- package/src/client.test.ts +83 -0
- package/src/client.ts +183 -0
- package/src/commands.test.ts +1199 -0
- package/src/commands.ts +2201 -0
- package/src/config.test.ts +243 -0
- package/src/config.ts +347 -0
- package/src/credentials.ts +119 -0
- package/src/hooks.test.ts +1030 -0
- package/src/hooks.ts +1099 -0
- package/src/idle.test.ts +32 -0
- package/src/idle.ts +41 -0
- package/src/install-hooks.test.ts +500 -0
- package/src/install-hooks.ts +708 -0
- package/src/main.ts +315 -0
- package/src/opencode-plugin.ts +203 -0
- package/src/readiness.ts +88 -0
- package/src/send.ts +272 -0
- 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
|
+
}
|