@raidiant/notifai 10.1.1 → 10.1.3
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/CHANGELOG.md +35 -0
- package/dist/commands-core.d.ts +4 -1
- package/dist/commands-core.js.map +1 -1
- package/dist/commands-doctor.js +2 -7
- package/dist/commands-doctor.js.map +1 -1
- package/dist/commands-hooks.d.ts +12 -0
- package/dist/commands-hooks.js +15 -1
- package/dist/commands-hooks.js.map +1 -1
- package/dist/commands-init.js +9 -6
- package/dist/commands-init.js.map +1 -1
- package/dist/commands-send-support.js +10 -11
- package/dist/commands-send-support.js.map +1 -1
- package/dist/commands-skill.js +72 -54
- package/dist/commands-skill.js.map +1 -1
- package/dist/harness-session-title.d.ts +22 -0
- package/dist/harness-session-title.js +74 -0
- package/dist/harness-session-title.js.map +1 -0
- package/dist/invocation-context.d.ts +1 -0
- package/dist/invocation-context.js +15 -1
- package/dist/invocation-context.js.map +1 -1
- package/dist/native-skills.d.ts +13 -3
- package/dist/native-skills.js +51 -12
- package/dist/native-skills.js.map +1 -1
- package/dist/node-floor.d.ts +2 -1
- package/dist/node-floor.js +9 -5
- package/dist/node-floor.js.map +1 -1
- package/dist/orca-session-title.d.ts +5 -4
- package/dist/orca-session-title.js +32 -19
- package/dist/orca-session-title.js.map +1 -1
- package/dist/platform.d.ts +11 -17
- package/dist/platform.js +20 -23
- package/dist/platform.js.map +1 -1
- package/dist/release.d.ts +5 -5
- package/dist/release.js +5 -5
- package/dist/session-labels.d.ts +2 -0
- package/dist/session-labels.js +20 -9
- package/dist/session-labels.js.map +1 -1
- package/dist/setup-destinations.js +1 -1
- package/dist/setup-destinations.js.map +1 -1
- package/dist/skill-integrity.d.ts +49 -0
- package/dist/skill-integrity.js +154 -0
- package/dist/skill-integrity.js.map +1 -0
- package/dist/skill-source/manifest.json +16 -0
- package/dist/skill-source/notifai/SKILL.md +390 -0
- package/dist/skill-source/notifai/references/harness-setup.md +220 -0
- package/package.json +11 -14
- package/src/atomic-file.ts +0 -198
- package/src/claude-wake.test.ts +0 -321
- package/src/claude-wake.ts +0 -499
- package/src/cli-bin.test.ts +0 -176
- package/src/cli-bin.ts +0 -233
- package/src/cli-release.test.ts +0 -46
- package/src/cli-release.ts +0 -78
- package/src/cli-update-contract.ts +0 -9
- package/src/cli-update.test.ts +0 -125
- package/src/client.test.ts +0 -390
- package/src/client.ts +0 -352
- package/src/codex-wake.test.ts +0 -254
- package/src/codex-wake.ts +0 -301
- package/src/command-session.ts +0 -38
- package/src/commands-agent-sessions.ts +0 -72
- package/src/commands-auth.ts +0 -238
- package/src/commands-config.ts +0 -336
- package/src/commands-core.ts +0 -312
- package/src/commands-devices.ts +0 -180
- package/src/commands-doctor.ts +0 -1501
- package/src/commands-guidance.ts +0 -181
- package/src/commands-harness-context.ts +0 -207
- package/src/commands-hook-shape.ts +0 -69
- package/src/commands-hooks.ts +0 -2318
- package/src/commands-init.ts +0 -1055
- package/src/commands-io.ts +0 -108
- package/src/commands-logs.ts +0 -243
- package/src/commands-project.ts +0 -47
- package/src/commands-send-support.test.ts +0 -156
- package/src/commands-send-support.ts +0 -311
- package/src/commands-send.ts +0 -875
- package/src/commands-setup-proof.test.ts +0 -72
- package/src/commands-setup-proof.ts +0 -124
- package/src/commands-skill.test.ts +0 -44
- package/src/commands-skill.ts +0 -204
- package/src/commands-sounds.test.ts +0 -106
- package/src/commands-sounds.ts +0 -49
- package/src/commands-update.ts +0 -180
- package/src/commands.test.ts +0 -8297
- package/src/commands.ts +0 -77
- package/src/config-schema.test.ts +0 -153
- package/src/config-schema.ts +0 -349
- package/src/config.test.ts +0 -581
- package/src/config.ts +0 -475
- package/src/credentials.test.ts +0 -403
- package/src/credentials.ts +0 -403
- package/src/file-lock-process-worker.test.ts +0 -64
- package/src/file-lock.test.ts +0 -320
- package/src/file-lock.ts +0 -393
- package/src/fixtures/hermes-0.20.6-classic-cli-local.json +0 -50
- package/src/fixtures/openclaw-2026.7.1-2-agent-local.json +0 -57
- package/src/generated-session-label.ts +0 -155
- package/src/guidance-content.ts +0 -278
- package/src/guidance-render.ts +0 -56
- package/src/guidance.test.ts +0 -327
- package/src/guidance.ts +0 -233
- package/src/harness-integration.test.ts +0 -294
- package/src/harnesses.test.ts +0 -149
- package/src/harnesses.ts +0 -164
- package/src/hook-adapter.test.ts +0 -496
- package/src/hook-adapter.ts +0 -424
- package/src/hook-input.test.ts +0 -39
- package/src/hook-input.ts +0 -72
- package/src/hooks.test.ts +0 -5824
- package/src/hooks.ts +0 -4011
- package/src/install-hooks.test.ts +0 -1614
- package/src/install-hooks.ts +0 -1501
- package/src/interactive.test.ts +0 -387
- package/src/interactive.ts +0 -858
- package/src/invocation-context.test.ts +0 -352
- package/src/invocation-context.ts +0 -197
- package/src/logging-process-worker.test.ts +0 -45
- package/src/logging.test.ts +0 -544
- package/src/logging.ts +0 -698
- package/src/main-run.ts +0 -45
- package/src/main.ts +0 -12
- package/src/native-skills.test.ts +0 -115
- package/src/native-skills.ts +0 -162
- package/src/node-floor.test.ts +0 -27
- package/src/node-floor.ts +0 -37
- package/src/onboarding-docs.test.ts +0 -25
- package/src/openclaw-plugin.ts +0 -409
- package/src/opencode-plugin.ts +0 -298
- package/src/orca-session-title.test.ts +0 -54
- package/src/orca-session-title.ts +0 -103
- package/src/pack-feedback-slice.test.ts +0 -212
- package/src/pack-feedback-slice.ts +0 -187
- package/src/platform.test.ts +0 -152
- package/src/platform.ts +0 -173
- package/src/program.test.ts +0 -317
- package/src/program.ts +0 -842
- package/src/project-enablement.test.ts +0 -55
- package/src/project-enablement.ts +0 -99
- package/src/question-caps.test.ts +0 -49
- package/src/question-settlement-process.ts +0 -47
- package/src/question-timing.ts +0 -56
- package/src/readiness.test.ts +0 -25
- package/src/readiness.ts +0 -212
- package/src/release.ts +0 -51
- package/src/send-attempts.test.ts +0 -143
- package/src/send-attempts.ts +0 -188
- package/src/send.test.ts +0 -28
- package/src/send.ts +0 -436
- package/src/session-activation.ts +0 -61
- package/src/session-end-log-lock-worker.test.ts +0 -35
- package/src/session-labels.test.ts +0 -490
- package/src/session-labels.ts +0 -474
- package/src/setup-destinations.test.ts +0 -41
- package/src/setup-destinations.ts +0 -50
- package/src/skill.test.ts +0 -426
- package/src/sound-ref.test.ts +0 -31
- package/src/sound-ref.ts +0 -34
- package/src/trust-policy.test.ts +0 -701
- package/src/ui/banner.ts +0 -95
- package/src/ui/config-view.test.ts +0 -90
- package/src/ui/config-view.ts +0 -138
- package/src/ui/help.test.ts +0 -16
- package/src/ui/help.ts +0 -128
- package/src/ui/theme.test.ts +0 -92
- package/src/ui/theme.ts +0 -265
- package/src/url-policy.ts +0 -399
- package/tsconfig.json +0 -10
package/src/hook-adapter.ts
DELETED
|
@@ -1,424 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
chmodSync,
|
|
3
|
-
existsSync,
|
|
4
|
-
lstatSync,
|
|
5
|
-
mkdirSync,
|
|
6
|
-
readFileSync,
|
|
7
|
-
realpathSync,
|
|
8
|
-
statSync,
|
|
9
|
-
} from 'node:fs'
|
|
10
|
-
import os from 'node:os'
|
|
11
|
-
import path from 'node:path'
|
|
12
|
-
import { atomicWriteFileSync } from './atomic-file.js'
|
|
13
|
-
import { withTargetFileLock } from './file-lock.js'
|
|
14
|
-
|
|
15
|
-
const ADAPTER_MARKER = '# notifai managed hook adapter'
|
|
16
|
-
const WIN32_ADAPTER_MARKER = '// notifai managed hook adapter'
|
|
17
|
-
const ADAPTER_VERSION = 2
|
|
18
|
-
|
|
19
|
-
export type HookHostPlatform = 'posix' | 'win32'
|
|
20
|
-
|
|
21
|
-
export interface HookAdapterFileTarget {
|
|
22
|
-
kind?: 'file'
|
|
23
|
-
execPath: string
|
|
24
|
-
scriptPath: string
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface HookAdapterNpxTarget {
|
|
28
|
-
kind: 'npx'
|
|
29
|
-
execPath: string
|
|
30
|
-
npmCli: string
|
|
31
|
-
spec: string
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export type HookAdapterTarget = HookAdapterFileTarget | HookAdapterNpxTarget
|
|
35
|
-
|
|
36
|
-
export function isNpxAdapterTarget(target: HookAdapterTarget): target is HookAdapterNpxTarget {
|
|
37
|
-
return target.kind === 'npx'
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface HookAdapterInspection {
|
|
41
|
-
path: string
|
|
42
|
-
target: HookAdapterTarget | null
|
|
43
|
-
problems: string[]
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** Whether a parsed adapter runs the same installed CLI artifact as PATH. */
|
|
47
|
-
export function hookAdapterTargetsArtifact(
|
|
48
|
-
target: HookAdapterTarget | null,
|
|
49
|
-
artifactPath: string,
|
|
50
|
-
): boolean {
|
|
51
|
-
if (target === null || isNpxAdapterTarget(target)) return false
|
|
52
|
-
try {
|
|
53
|
-
return realpathSync(target.scriptPath) === realpathSync(artifactPath)
|
|
54
|
-
} catch {
|
|
55
|
-
return false
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function hookHostPlatform(
|
|
60
|
-
platform: NodeJS.Platform | HookHostPlatform = process.platform,
|
|
61
|
-
): HookHostPlatform {
|
|
62
|
-
return platform === 'win32' ? 'win32' : 'posix'
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* One user-level identity for every harness and every project/global install.
|
|
67
|
-
*
|
|
68
|
-
* The pathname is deliberately outside XDG configuration/state routing. XDG
|
|
69
|
-
* overrides routinely differ between shells, package managers, and harness
|
|
70
|
-
* processes; allowing one to select this path would put mutable environment
|
|
71
|
-
* back into every trusted definition. Only the user's home boundary selects
|
|
72
|
-
* it; CLI, Node, package-manager, checkout, and preference paths stay behind
|
|
73
|
-
* it and may change without changing hook identity.
|
|
74
|
-
*/
|
|
75
|
-
export function hookAdapterPath(homeDir: string = os.userInfo().homedir): string {
|
|
76
|
-
return path.join(homeDir, '.notifai', 'bin', 'hook-adapter')
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** Install or repair the stable adapter and atomically retarget its implementation. */
|
|
80
|
-
export function installHookAdapter(
|
|
81
|
-
target: HookAdapterTarget,
|
|
82
|
-
homeDir?: string,
|
|
83
|
-
platform: NodeJS.Platform | HookHostPlatform = process.platform,
|
|
84
|
-
): { path: string; changed: boolean } {
|
|
85
|
-
const host = hookHostPlatform(platform)
|
|
86
|
-
assertUsableTarget(target, host)
|
|
87
|
-
const file = hookAdapterPath(homeDir)
|
|
88
|
-
ensureManagedDirectories(homeDir ?? os.userInfo().homedir, host)
|
|
89
|
-
const source = hookAdapterSource(target, host)
|
|
90
|
-
return withTargetFileLock(file, () => {
|
|
91
|
-
const existing = existsSync(file) ? readSafeManagedFile(file) : null
|
|
92
|
-
const modeDrift =
|
|
93
|
-
host === 'posix' && existing !== null && (existing.mode & 0o777) !== 0o700
|
|
94
|
-
const changed = existing === null || existing.contents !== source || modeDrift
|
|
95
|
-
if (changed) {
|
|
96
|
-
atomicWriteFileSync(file, source, {
|
|
97
|
-
mode: host === 'posix' ? 0o700 : 0o600,
|
|
98
|
-
preserveMode: false,
|
|
99
|
-
requireCurrentUserOwner: true,
|
|
100
|
-
})
|
|
101
|
-
}
|
|
102
|
-
return { path: file, changed }
|
|
103
|
-
})
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function assertUsableTarget(target: HookAdapterTarget, host: HookHostPlatform): void {
|
|
107
|
-
let exec
|
|
108
|
-
try {
|
|
109
|
-
exec = statSync(target.execPath)
|
|
110
|
-
} catch {
|
|
111
|
-
throw new Error(`Hook adapter runtime ${target.execPath} does not exist.`)
|
|
112
|
-
}
|
|
113
|
-
if (!exec.isFile() || (host === 'posix' && (exec.mode & 0o111) === 0)) {
|
|
114
|
-
throw new Error(`Hook adapter runtime ${target.execPath} is not executable.`)
|
|
115
|
-
}
|
|
116
|
-
if (isNpxAdapterTarget(target)) {
|
|
117
|
-
if (target.spec.trim() === '') {
|
|
118
|
-
throw new Error('Hook adapter npx spec is empty.')
|
|
119
|
-
}
|
|
120
|
-
try {
|
|
121
|
-
if (!statSync(target.npmCli).isFile()) {
|
|
122
|
-
throw new Error(`Hook adapter npm CLI ${target.npmCli} is not a regular file.`)
|
|
123
|
-
}
|
|
124
|
-
} catch (err) {
|
|
125
|
-
if (err instanceof Error && err.message.startsWith('Hook adapter npm CLI ')) throw err
|
|
126
|
-
throw new Error(`Hook adapter npm CLI ${target.npmCli} does not exist.`)
|
|
127
|
-
}
|
|
128
|
-
return
|
|
129
|
-
}
|
|
130
|
-
try {
|
|
131
|
-
if (!statSync(target.scriptPath).isFile()) {
|
|
132
|
-
throw new Error(`Hook adapter CLI ${target.scriptPath} is not a regular file.`)
|
|
133
|
-
}
|
|
134
|
-
} catch (err) {
|
|
135
|
-
if (err instanceof Error && err.message.startsWith('Hook adapter CLI ')) throw err
|
|
136
|
-
throw new Error(`Hook adapter CLI ${target.scriptPath} does not exist.`)
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/** Inspect the shared adapter without executing either it or its registered CLI. */
|
|
141
|
-
export function inspectHookAdapter(
|
|
142
|
-
homeDir?: string,
|
|
143
|
-
platform: NodeJS.Platform | HookHostPlatform = process.platform,
|
|
144
|
-
): HookAdapterInspection {
|
|
145
|
-
const host = hookHostPlatform(platform)
|
|
146
|
-
const file = hookAdapterPath(homeDir)
|
|
147
|
-
if (!existsSync(file)) {
|
|
148
|
-
return { path: file, target: null, problems: [`${file} is missing; rerun \`notifai hooks install\``] }
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
let stat
|
|
152
|
-
try {
|
|
153
|
-
stat = lstatSync(file)
|
|
154
|
-
} catch (err) {
|
|
155
|
-
return { path: file, target: null, problems: [String(err)] }
|
|
156
|
-
}
|
|
157
|
-
if (stat.isSymbolicLink() || !stat.isFile()) {
|
|
158
|
-
return {
|
|
159
|
-
path: file,
|
|
160
|
-
target: null,
|
|
161
|
-
problems: [`${file} is not a regular file; refusing the adapter`],
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const problems: string[] = []
|
|
166
|
-
if (host === 'posix') {
|
|
167
|
-
const uid = typeof process.getuid === 'function' ? process.getuid() : undefined
|
|
168
|
-
if (uid !== undefined && stat.uid !== uid) {
|
|
169
|
-
problems.push(`${file} is owned by uid ${stat.uid}, not the current user`)
|
|
170
|
-
}
|
|
171
|
-
if ((stat.mode & 0o077) !== 0 || (stat.mode & 0o700) !== 0o700) {
|
|
172
|
-
problems.push(`${file} permissions are ${(stat.mode & 0o777).toString(8)}, expected 700`)
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const contents = readFileSync(file, 'utf8')
|
|
177
|
-
const format = adapterFormat(contents)
|
|
178
|
-
if (format === null) {
|
|
179
|
-
problems.push(`${file} has no managed adapter marker`)
|
|
180
|
-
} else if (format !== host) {
|
|
181
|
-
problems.push(`${file} is not a ${host} managed adapter; rerun \`notifai hooks install\``)
|
|
182
|
-
}
|
|
183
|
-
const version = Number(meta(contents, 'adapter-version') ?? Number.NaN)
|
|
184
|
-
if (version !== ADAPTER_VERSION) problems.push(`${file} uses obsolete adapter version ${version}`)
|
|
185
|
-
const target = parseTarget(contents)
|
|
186
|
-
if (target === null) {
|
|
187
|
-
problems.push(`${file} has malformed target metadata`)
|
|
188
|
-
} else {
|
|
189
|
-
try {
|
|
190
|
-
const exec = statSync(target.execPath)
|
|
191
|
-
if (!exec.isFile() || (host === 'posix' && (exec.mode & 0o111) === 0)) {
|
|
192
|
-
problems.push(`registered runtime ${target.execPath} is not executable`)
|
|
193
|
-
}
|
|
194
|
-
} catch {
|
|
195
|
-
problems.push(`registered runtime ${target.execPath} is missing`)
|
|
196
|
-
}
|
|
197
|
-
if (isNpxAdapterTarget(target)) {
|
|
198
|
-
if (target.spec.trim() === '') problems.push('registered npx spec is empty')
|
|
199
|
-
try {
|
|
200
|
-
if (!statSync(target.npmCli).isFile()) {
|
|
201
|
-
problems.push(`registered npm CLI ${target.npmCli} is not a regular file`)
|
|
202
|
-
}
|
|
203
|
-
} catch {
|
|
204
|
-
problems.push(`registered npm CLI ${target.npmCli} is missing`)
|
|
205
|
-
}
|
|
206
|
-
} else {
|
|
207
|
-
try {
|
|
208
|
-
if (!statSync(target.scriptPath).isFile()) {
|
|
209
|
-
problems.push(`registered CLI ${target.scriptPath} is not a regular file`)
|
|
210
|
-
}
|
|
211
|
-
} catch {
|
|
212
|
-
problems.push(`registered CLI ${target.scriptPath} is missing`)
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
return { path: file, target, problems }
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/** Generate the managed adapter source for one host. Exported so tests can pin bytes. */
|
|
220
|
-
export function hookAdapterSource(
|
|
221
|
-
target: HookAdapterTarget,
|
|
222
|
-
platform: NodeJS.Platform | HookHostPlatform = process.platform,
|
|
223
|
-
): string {
|
|
224
|
-
return hookHostPlatform(platform) === 'win32'
|
|
225
|
-
? win32HookAdapterSource(target)
|
|
226
|
-
: posixHookAdapterSource(target)
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Two rungs, and the difference between them is the whole safety argument.
|
|
231
|
-
*
|
|
232
|
-
* The registered runtime is a resolved path, so every node version manager
|
|
233
|
-
* makes it version-scoped: a Homebrew upgrade renames its Cellar directory, an
|
|
234
|
-
* nvm version gets pruned, and the pinned interpreter stops existing. The npm
|
|
235
|
-
* shim this adapter wraps already survives that — `main.ts` starts with
|
|
236
|
-
* `#!/usr/bin/env node` — so pinning the interpreter here was stricter than the
|
|
237
|
-
* binary it stands in front of, and the strictness bought nothing.
|
|
238
|
-
*
|
|
239
|
-
* So PATH may supply the *interpreter*, and never the *code*: both rungs keep
|
|
240
|
-
* the registered script path, and no rung resolves `notifai` from PATH. Which
|
|
241
|
-
* Notifai build a trusted hook definition runs stays a property of the
|
|
242
|
-
* installation, not of whatever environment the harness happens to hand us.
|
|
243
|
-
*/
|
|
244
|
-
function posixHookAdapterSource(target: HookAdapterTarget): string {
|
|
245
|
-
if (isNpxAdapterTarget(target)) {
|
|
246
|
-
return `#!/bin/sh
|
|
247
|
-
${ADAPTER_MARKER}
|
|
248
|
-
# adapter-version: ${ADAPTER_VERSION}
|
|
249
|
-
# target-kind: npx
|
|
250
|
-
# target-exec-json: ${JSON.stringify(target.execPath)}
|
|
251
|
-
# target-npm-cli-json: ${JSON.stringify(target.npmCli)}
|
|
252
|
-
# target-spec-json: ${JSON.stringify(target.spec)}
|
|
253
|
-
set -eu
|
|
254
|
-
|
|
255
|
-
NOTIFAI_HOOK_SOURCE_PID=$PPID
|
|
256
|
-
export NOTIFAI_HOOK_SOURCE_PID
|
|
257
|
-
|
|
258
|
-
registered_exec=${quote(target.execPath)}
|
|
259
|
-
registered_npm_cli=${quote(target.npmCli)}
|
|
260
|
-
registered_spec=${quote(target.spec)}
|
|
261
|
-
|
|
262
|
-
if [ -x "$registered_exec" ] && [ -f "$registered_npm_cli" ]; then
|
|
263
|
-
exec "$registered_exec" "$registered_npm_cli" exec --yes --package "$registered_spec" -- notifai "$@"
|
|
264
|
-
fi
|
|
265
|
-
|
|
266
|
-
if [ -f "$registered_npm_cli" ] && command -v node >/dev/null 2>&1; then
|
|
267
|
-
exec node "$registered_npm_cli" exec --yes --package "$registered_spec" -- notifai "$@"
|
|
268
|
-
fi
|
|
269
|
-
|
|
270
|
-
printf '%s\n' 'Notifai hook adapter target is stale; run notifai hooks install.' >&2
|
|
271
|
-
exit 127
|
|
272
|
-
`
|
|
273
|
-
}
|
|
274
|
-
return `#!/bin/sh
|
|
275
|
-
${ADAPTER_MARKER}
|
|
276
|
-
# adapter-version: ${ADAPTER_VERSION}
|
|
277
|
-
# target-exec-json: ${JSON.stringify(target.execPath)}
|
|
278
|
-
# target-script-json: ${JSON.stringify(target.scriptPath)}
|
|
279
|
-
set -eu
|
|
280
|
-
|
|
281
|
-
NOTIFAI_HOOK_SOURCE_PID=$PPID
|
|
282
|
-
export NOTIFAI_HOOK_SOURCE_PID
|
|
283
|
-
|
|
284
|
-
registered_exec=${quote(target.execPath)}
|
|
285
|
-
registered_script=${quote(target.scriptPath)}
|
|
286
|
-
|
|
287
|
-
if [ -x "$registered_exec" ] && [ -f "$registered_script" ]; then
|
|
288
|
-
exec "$registered_exec" "$registered_script" "$@"
|
|
289
|
-
fi
|
|
290
|
-
|
|
291
|
-
if [ -f "$registered_script" ] && command -v node >/dev/null 2>&1; then
|
|
292
|
-
exec node "$registered_script" "$@"
|
|
293
|
-
fi
|
|
294
|
-
|
|
295
|
-
printf '%s\n' 'Notifai hook adapter target is stale; run notifai hooks install.' >&2
|
|
296
|
-
exit 127
|
|
297
|
-
`
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
function win32HookAdapterSource(target: HookAdapterTarget): string {
|
|
301
|
-
const header = isNpxAdapterTarget(target)
|
|
302
|
-
? `${WIN32_ADAPTER_MARKER}
|
|
303
|
-
// adapter-version: ${ADAPTER_VERSION}
|
|
304
|
-
// target-kind: npx
|
|
305
|
-
// target-exec-json: ${JSON.stringify(target.execPath)}
|
|
306
|
-
// target-npm-cli-json: ${JSON.stringify(target.npmCli)}
|
|
307
|
-
// target-spec-json: ${JSON.stringify(target.spec)}
|
|
308
|
-
`
|
|
309
|
-
: `${WIN32_ADAPTER_MARKER}
|
|
310
|
-
// adapter-version: ${ADAPTER_VERSION}
|
|
311
|
-
// target-exec-json: ${JSON.stringify(target.execPath)}
|
|
312
|
-
// target-script-json: ${JSON.stringify(target.scriptPath)}
|
|
313
|
-
`
|
|
314
|
-
const argv = isNpxAdapterTarget(target)
|
|
315
|
-
? `[${JSON.stringify(target.npmCli)}, "exec", "--yes", "--package", ${JSON.stringify(target.spec)}, "--", "notifai", ...process.argv.slice(2)]`
|
|
316
|
-
: `[${JSON.stringify(target.scriptPath)}, ...process.argv.slice(2)]`
|
|
317
|
-
const companion = isNpxAdapterTarget(target)
|
|
318
|
-
? JSON.stringify(target.npmCli)
|
|
319
|
-
: JSON.stringify(target.scriptPath)
|
|
320
|
-
return `${header}"use strict";
|
|
321
|
-
const { spawnSync } = require("node:child_process");
|
|
322
|
-
const { statSync } = require("node:fs");
|
|
323
|
-
const registeredExec = ${JSON.stringify(target.execPath)};
|
|
324
|
-
const registeredCompanion = ${companion};
|
|
325
|
-
|
|
326
|
-
function isFile(file) {
|
|
327
|
-
try {
|
|
328
|
-
return statSync(file).isFile();
|
|
329
|
-
} catch {
|
|
330
|
-
return false;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
// The pinned runtime is preferred; the runtime already executing this shim is
|
|
335
|
-
// the fallback. Only the interpreter is allowed to move — the code stays pinned.
|
|
336
|
-
const runtime = isFile(registeredExec) ? registeredExec : process.execPath;
|
|
337
|
-
|
|
338
|
-
if (isFile(registeredCompanion)) {
|
|
339
|
-
const result = spawnSync(runtime, ${argv}, {
|
|
340
|
-
stdio: "inherit",
|
|
341
|
-
windowsHide: true,
|
|
342
|
-
env: { ...process.env, NOTIFAI_HOOK_SOURCE_PID: String(process.ppid) },
|
|
343
|
-
});
|
|
344
|
-
if (result.error) {
|
|
345
|
-
process.stderr.write("Notifai hook adapter target is stale; run notifai hooks install.\\n");
|
|
346
|
-
process.exit(127);
|
|
347
|
-
}
|
|
348
|
-
process.exit(result.status === null ? 1 : result.status);
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
process.stderr.write("Notifai hook adapter target is stale; run notifai hooks install.\\n");
|
|
352
|
-
process.exit(127);
|
|
353
|
-
`
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
function adapterFormat(contents: string): HookHostPlatform | null {
|
|
357
|
-
if (contents.startsWith(`#!/bin/sh\n${ADAPTER_MARKER}\n`)) return 'posix'
|
|
358
|
-
if (contents.startsWith(`${WIN32_ADAPTER_MARKER}\n`)) return 'win32'
|
|
359
|
-
return null
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
function meta(contents: string, key: string): string | undefined {
|
|
363
|
-
return new RegExp(`^(?:#|//) ${key}: (.+)$`, 'm').exec(contents)?.[1]
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
function parseTarget(contents: string): HookAdapterTarget | null {
|
|
367
|
-
const kind = meta(contents, 'target-kind')
|
|
368
|
-
const exec = meta(contents, 'target-exec-json')
|
|
369
|
-
if (exec === undefined) return null
|
|
370
|
-
try {
|
|
371
|
-
const execPath: unknown = JSON.parse(exec)
|
|
372
|
-
if (typeof execPath !== 'string') return null
|
|
373
|
-
if (kind === 'npx') {
|
|
374
|
-
const npmCliRaw = meta(contents, 'target-npm-cli-json')
|
|
375
|
-
const specRaw = meta(contents, 'target-spec-json')
|
|
376
|
-
if (npmCliRaw === undefined || specRaw === undefined) return null
|
|
377
|
-
const npmCli: unknown = JSON.parse(npmCliRaw)
|
|
378
|
-
const spec: unknown = JSON.parse(specRaw)
|
|
379
|
-
return typeof npmCli === 'string' && typeof spec === 'string'
|
|
380
|
-
? { kind: 'npx', execPath, npmCli, spec }
|
|
381
|
-
: null
|
|
382
|
-
}
|
|
383
|
-
const script = meta(contents, 'target-script-json')
|
|
384
|
-
if (script === undefined) return null
|
|
385
|
-
const scriptPath: unknown = JSON.parse(script)
|
|
386
|
-
return typeof scriptPath === 'string' ? { execPath, scriptPath } : null
|
|
387
|
-
} catch {
|
|
388
|
-
return null
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
function quote(value: string): string {
|
|
393
|
-
return `'${value.replaceAll("'", `'\\''`)}'`
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
function ensureManagedDirectories(homeDir: string, host: HookHostPlatform): void {
|
|
397
|
-
if (!existsSync(homeDir)) mkdirSync(homeDir, { recursive: true, mode: 0o700 })
|
|
398
|
-
for (const dir of [path.join(homeDir, '.notifai'), path.join(homeDir, '.notifai', 'bin')]) {
|
|
399
|
-
if (!existsSync(dir)) mkdirSync(dir, { mode: 0o700 })
|
|
400
|
-
const stat = lstatSync(dir)
|
|
401
|
-
if (stat.isSymbolicLink() || !stat.isDirectory()) {
|
|
402
|
-
throw new Error(`${dir} is not a regular directory; refusing to install the hook adapter.`)
|
|
403
|
-
}
|
|
404
|
-
if (host === 'posix') {
|
|
405
|
-
const uid = typeof process.getuid === 'function' ? process.getuid() : undefined
|
|
406
|
-
if (uid !== undefined && stat.uid !== uid) {
|
|
407
|
-
throw new Error(`${dir} is owned by uid ${stat.uid}, not the current user.`)
|
|
408
|
-
}
|
|
409
|
-
chmodSync(dir, 0o700)
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
function readSafeManagedFile(file: string): { contents: string; mode: number } {
|
|
415
|
-
const stat = lstatSync(file)
|
|
416
|
-
if (stat.isSymbolicLink() || !stat.isFile()) {
|
|
417
|
-
throw new Error(`${file} is not a regular file; refusing to replace it.`)
|
|
418
|
-
}
|
|
419
|
-
const uid = typeof process.getuid === 'function' ? process.getuid() : undefined
|
|
420
|
-
if (uid !== undefined && stat.uid !== uid) {
|
|
421
|
-
throw new Error(`${file} is owned by uid ${stat.uid}, not the current user.`)
|
|
422
|
-
}
|
|
423
|
-
return { contents: readFileSync(file, 'utf8'), mode: stat.mode }
|
|
424
|
-
}
|
package/src/hook-input.test.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { PassThrough } from 'node:stream'
|
|
2
|
-
import { describe, expect, it } from 'vitest'
|
|
3
|
-
import { readStdinWithTimeout } from './hook-input.js'
|
|
4
|
-
|
|
5
|
-
describe('hook input reader', () => {
|
|
6
|
-
it('rejects a timeout when the harness pipe delivered no bytes', async () => {
|
|
7
|
-
const input = new PassThrough()
|
|
8
|
-
await expect(readStdinWithTimeout(input, 5)).rejects.toThrow(/timed out waiting 5ms/)
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
it('rejects a stream failure when no useful input exists', async () => {
|
|
12
|
-
const input = new PassThrough()
|
|
13
|
-
const reading = readStdinWithTimeout(input, 1_000)
|
|
14
|
-
input.destroy(new Error('stdin disappeared'))
|
|
15
|
-
await expect(reading).rejects.toThrow('stdin disappeared')
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
it('returns partial bytes on timeout so the hook can diagnose truncation', async () => {
|
|
19
|
-
const input = new PassThrough()
|
|
20
|
-
const reading = readStdinWithTimeout(input, 5)
|
|
21
|
-
input.write('{"session_id":')
|
|
22
|
-
await expect(reading).resolves.toBe('{"session_id":')
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
it('preserves complete buffered JSON when the stream fails after delivering it', async () => {
|
|
26
|
-
const input = new PassThrough()
|
|
27
|
-
const reading = readStdinWithTimeout(input, 1_000)
|
|
28
|
-
input.write('{"session_id":"kept"}')
|
|
29
|
-
input.destroy(new Error('late pipe failure'))
|
|
30
|
-
await expect(reading).resolves.toBe('{"session_id":"kept"}')
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
it('marks an oversized payload as truncated instead of treating it as empty', async () => {
|
|
34
|
-
const input = new PassThrough()
|
|
35
|
-
const reading = readStdinWithTimeout(input, 1_000, 12)
|
|
36
|
-
input.end('{"session_id":"far-too-long"}')
|
|
37
|
-
await expect(reading).resolves.toMatch(/hook input truncated/)
|
|
38
|
-
})
|
|
39
|
-
})
|
package/src/hook-input.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import type { Readable } from 'node:stream'
|
|
2
|
-
|
|
3
|
-
const TRUNCATED_INPUT_SUFFIX = '\n[notifai: hook input truncated]\n'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Read one harness-hook envelope without letting a stuck pipe hold the prompt.
|
|
7
|
-
*
|
|
8
|
-
* A timeout or stream error before any bytes arrive rejects, so the hook can
|
|
9
|
-
* record that its input was unavailable. Once bytes exist they are more useful
|
|
10
|
-
* than the transport failure: complete JSON can still run, while partial or
|
|
11
|
-
* capped JSON reaches the hook's malformed/truncated diagnostic.
|
|
12
|
-
*/
|
|
13
|
-
export function readStdinWithTimeout(
|
|
14
|
-
input: Readable = process.stdin,
|
|
15
|
-
timeoutMs = 2_000,
|
|
16
|
-
maxBytes = 1_000_000,
|
|
17
|
-
): Promise<string> {
|
|
18
|
-
if ((input as Readable & { isTTY?: boolean }).isTTY === true) return Promise.resolve('')
|
|
19
|
-
|
|
20
|
-
return new Promise<string>((resolve, reject) => {
|
|
21
|
-
const chunks: Buffer[] = []
|
|
22
|
-
let total = 0
|
|
23
|
-
let settled = false
|
|
24
|
-
|
|
25
|
-
const cleanup = (): void => {
|
|
26
|
-
clearTimeout(timer)
|
|
27
|
-
input.off('data', onData)
|
|
28
|
-
input.off('end', onEnd)
|
|
29
|
-
input.off('error', onError)
|
|
30
|
-
input.destroy()
|
|
31
|
-
}
|
|
32
|
-
const finishBuffered = (): void => {
|
|
33
|
-
if (settled) return
|
|
34
|
-
settled = true
|
|
35
|
-
cleanup()
|
|
36
|
-
resolve(Buffer.concat(chunks).toString('utf8'))
|
|
37
|
-
}
|
|
38
|
-
const failEmpty = (err: Error): void => {
|
|
39
|
-
if (settled) return
|
|
40
|
-
if (chunks.length > 0) return finishBuffered()
|
|
41
|
-
settled = true
|
|
42
|
-
cleanup()
|
|
43
|
-
reject(err)
|
|
44
|
-
}
|
|
45
|
-
const onData = (chunk: Buffer | string): void => {
|
|
46
|
-
const bytes = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)
|
|
47
|
-
const remaining = Math.max(0, maxBytes - total)
|
|
48
|
-
if (bytes.length <= remaining) {
|
|
49
|
-
chunks.push(bytes)
|
|
50
|
-
total += bytes.length
|
|
51
|
-
return
|
|
52
|
-
}
|
|
53
|
-
if (remaining > 0) {
|
|
54
|
-
chunks.push(bytes.subarray(0, remaining))
|
|
55
|
-
total += remaining
|
|
56
|
-
}
|
|
57
|
-
chunks.push(Buffer.from(TRUNCATED_INPUT_SUFFIX))
|
|
58
|
-
finishBuffered()
|
|
59
|
-
}
|
|
60
|
-
const onEnd = (): void => finishBuffered()
|
|
61
|
-
const onError = (err: Error): void => failEmpty(err)
|
|
62
|
-
|
|
63
|
-
const timer = setTimeout(
|
|
64
|
-
() => failEmpty(new Error(`timed out waiting ${timeoutMs}ms for hook input`)),
|
|
65
|
-
timeoutMs,
|
|
66
|
-
)
|
|
67
|
-
timer.unref?.()
|
|
68
|
-
input.on('data', onData)
|
|
69
|
-
input.once('end', onEnd)
|
|
70
|
-
input.once('error', onError)
|
|
71
|
-
})
|
|
72
|
-
}
|