@raidiant/notifai 10.1.1 → 10.1.2

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 (156) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/commands-core.d.ts +1 -1
  3. package/dist/commands-init.js +9 -6
  4. package/dist/commands-init.js.map +1 -1
  5. package/dist/commands-send-support.js +3 -0
  6. package/dist/commands-send-support.js.map +1 -1
  7. package/dist/commands-skill.js +72 -54
  8. package/dist/commands-skill.js.map +1 -1
  9. package/dist/invocation-context.d.ts +1 -0
  10. package/dist/invocation-context.js +9 -1
  11. package/dist/invocation-context.js.map +1 -1
  12. package/dist/native-skills.d.ts +13 -3
  13. package/dist/native-skills.js +51 -12
  14. package/dist/native-skills.js.map +1 -1
  15. package/dist/node-floor.d.ts +2 -1
  16. package/dist/node-floor.js +9 -5
  17. package/dist/node-floor.js.map +1 -1
  18. package/dist/orca-session-title.d.ts +5 -4
  19. package/dist/orca-session-title.js +32 -19
  20. package/dist/orca-session-title.js.map +1 -1
  21. package/dist/platform.d.ts +11 -17
  22. package/dist/platform.js +20 -23
  23. package/dist/platform.js.map +1 -1
  24. package/dist/release.d.ts +5 -5
  25. package/dist/release.js +5 -5
  26. package/dist/setup-destinations.js +1 -1
  27. package/dist/setup-destinations.js.map +1 -1
  28. package/dist/skill-integrity.d.ts +49 -0
  29. package/dist/skill-integrity.js +154 -0
  30. package/dist/skill-integrity.js.map +1 -0
  31. package/dist/skill-source/manifest.json +16 -0
  32. package/dist/skill-source/notifai/SKILL.md +390 -0
  33. package/dist/skill-source/notifai/references/harness-setup.md +220 -0
  34. package/package.json +11 -14
  35. package/src/atomic-file.ts +0 -198
  36. package/src/claude-wake.test.ts +0 -321
  37. package/src/claude-wake.ts +0 -499
  38. package/src/cli-bin.test.ts +0 -176
  39. package/src/cli-bin.ts +0 -233
  40. package/src/cli-release.test.ts +0 -46
  41. package/src/cli-release.ts +0 -78
  42. package/src/cli-update-contract.ts +0 -9
  43. package/src/cli-update.test.ts +0 -125
  44. package/src/client.test.ts +0 -390
  45. package/src/client.ts +0 -352
  46. package/src/codex-wake.test.ts +0 -254
  47. package/src/codex-wake.ts +0 -301
  48. package/src/command-session.ts +0 -38
  49. package/src/commands-agent-sessions.ts +0 -72
  50. package/src/commands-auth.ts +0 -238
  51. package/src/commands-config.ts +0 -336
  52. package/src/commands-core.ts +0 -312
  53. package/src/commands-devices.ts +0 -180
  54. package/src/commands-doctor.ts +0 -1501
  55. package/src/commands-guidance.ts +0 -181
  56. package/src/commands-harness-context.ts +0 -207
  57. package/src/commands-hook-shape.ts +0 -69
  58. package/src/commands-hooks.ts +0 -2318
  59. package/src/commands-init.ts +0 -1055
  60. package/src/commands-io.ts +0 -108
  61. package/src/commands-logs.ts +0 -243
  62. package/src/commands-project.ts +0 -47
  63. package/src/commands-send-support.test.ts +0 -156
  64. package/src/commands-send-support.ts +0 -311
  65. package/src/commands-send.ts +0 -875
  66. package/src/commands-setup-proof.test.ts +0 -72
  67. package/src/commands-setup-proof.ts +0 -124
  68. package/src/commands-skill.test.ts +0 -44
  69. package/src/commands-skill.ts +0 -204
  70. package/src/commands-sounds.test.ts +0 -106
  71. package/src/commands-sounds.ts +0 -49
  72. package/src/commands-update.ts +0 -180
  73. package/src/commands.test.ts +0 -8297
  74. package/src/commands.ts +0 -77
  75. package/src/config-schema.test.ts +0 -153
  76. package/src/config-schema.ts +0 -349
  77. package/src/config.test.ts +0 -581
  78. package/src/config.ts +0 -475
  79. package/src/credentials.test.ts +0 -403
  80. package/src/credentials.ts +0 -403
  81. package/src/file-lock-process-worker.test.ts +0 -64
  82. package/src/file-lock.test.ts +0 -320
  83. package/src/file-lock.ts +0 -393
  84. package/src/fixtures/hermes-0.20.6-classic-cli-local.json +0 -50
  85. package/src/fixtures/openclaw-2026.7.1-2-agent-local.json +0 -57
  86. package/src/generated-session-label.ts +0 -155
  87. package/src/guidance-content.ts +0 -278
  88. package/src/guidance-render.ts +0 -56
  89. package/src/guidance.test.ts +0 -327
  90. package/src/guidance.ts +0 -233
  91. package/src/harness-integration.test.ts +0 -294
  92. package/src/harnesses.test.ts +0 -149
  93. package/src/harnesses.ts +0 -164
  94. package/src/hook-adapter.test.ts +0 -496
  95. package/src/hook-adapter.ts +0 -424
  96. package/src/hook-input.test.ts +0 -39
  97. package/src/hook-input.ts +0 -72
  98. package/src/hooks.test.ts +0 -5824
  99. package/src/hooks.ts +0 -4011
  100. package/src/install-hooks.test.ts +0 -1614
  101. package/src/install-hooks.ts +0 -1501
  102. package/src/interactive.test.ts +0 -387
  103. package/src/interactive.ts +0 -858
  104. package/src/invocation-context.test.ts +0 -352
  105. package/src/invocation-context.ts +0 -197
  106. package/src/logging-process-worker.test.ts +0 -45
  107. package/src/logging.test.ts +0 -544
  108. package/src/logging.ts +0 -698
  109. package/src/main-run.ts +0 -45
  110. package/src/main.ts +0 -12
  111. package/src/native-skills.test.ts +0 -115
  112. package/src/native-skills.ts +0 -162
  113. package/src/node-floor.test.ts +0 -27
  114. package/src/node-floor.ts +0 -37
  115. package/src/onboarding-docs.test.ts +0 -25
  116. package/src/openclaw-plugin.ts +0 -409
  117. package/src/opencode-plugin.ts +0 -298
  118. package/src/orca-session-title.test.ts +0 -54
  119. package/src/orca-session-title.ts +0 -103
  120. package/src/pack-feedback-slice.test.ts +0 -212
  121. package/src/pack-feedback-slice.ts +0 -187
  122. package/src/platform.test.ts +0 -152
  123. package/src/platform.ts +0 -173
  124. package/src/program.test.ts +0 -317
  125. package/src/program.ts +0 -842
  126. package/src/project-enablement.test.ts +0 -55
  127. package/src/project-enablement.ts +0 -99
  128. package/src/question-caps.test.ts +0 -49
  129. package/src/question-settlement-process.ts +0 -47
  130. package/src/question-timing.ts +0 -56
  131. package/src/readiness.test.ts +0 -25
  132. package/src/readiness.ts +0 -212
  133. package/src/release.ts +0 -51
  134. package/src/send-attempts.test.ts +0 -143
  135. package/src/send-attempts.ts +0 -188
  136. package/src/send.test.ts +0 -28
  137. package/src/send.ts +0 -436
  138. package/src/session-activation.ts +0 -61
  139. package/src/session-end-log-lock-worker.test.ts +0 -35
  140. package/src/session-labels.test.ts +0 -490
  141. package/src/session-labels.ts +0 -474
  142. package/src/setup-destinations.test.ts +0 -41
  143. package/src/setup-destinations.ts +0 -50
  144. package/src/skill.test.ts +0 -426
  145. package/src/sound-ref.test.ts +0 -31
  146. package/src/sound-ref.ts +0 -34
  147. package/src/trust-policy.test.ts +0 -701
  148. package/src/ui/banner.ts +0 -95
  149. package/src/ui/config-view.test.ts +0 -90
  150. package/src/ui/config-view.ts +0 -138
  151. package/src/ui/help.test.ts +0 -16
  152. package/src/ui/help.ts +0 -128
  153. package/src/ui/theme.test.ts +0 -92
  154. package/src/ui/theme.ts +0 -265
  155. package/src/url-policy.ts +0 -399
  156. package/tsconfig.json +0 -10
@@ -1,499 +0,0 @@
1
- import { spawn } from 'node:child_process'
2
- import { existsSync, readFileSync } from 'node:fs'
3
- import os from 'node:os'
4
- import path from 'node:path'
5
- import { createConnection } from 'node:net'
6
- import type {
7
- ContinuationEvent,
8
- DeliveryOutcome,
9
- EscalationDeliveryRoute,
10
- } from './hooks.js'
11
-
12
- /** Claude Code's currently observed inbox protocol. Unknown versions fail closed. */
13
- export const CLAUDE_PEER_PROTOCOL = 1
14
-
15
- /** The first Claude Code release that publishes a session inbox socket. */
16
- export const CLAUDE_MIN_INBOX_VERSION = '2.1.224'
17
-
18
- /** The inbox socket is a Unix domain socket; no Windows implementation exists. */
19
- const INBOX_PLATFORMS: ReadonlySet<string> = new Set(['darwin', 'linux'])
20
-
21
- /** macOS verifies own-child ancestry only while the posting process is alive. */
22
- export const CLAUDE_POST_SEND_LIVENESS_MS = 8_000
23
-
24
- export type ClaudeLiveStatus = 'idle' | 'busy'
25
-
26
- export interface ClaudeSessionDescriptor {
27
- pid: number
28
- sessionId: string
29
- cwd: string
30
- startedAt: number
31
- procStart: string
32
- version: string
33
- peerProtocol: number
34
- messagingSocketPath: string
35
- status: string
36
- }
37
-
38
- export interface ClaudeAgentObservation {
39
- pid: number
40
- sessionId: string
41
- startedAt: number
42
- status: string
43
- }
44
-
45
- export interface ClaudeWakeAdapters {
46
- listAgents(): Promise<unknown>
47
- readDescriptor(pid: number): unknown
48
- sendSocket(socketPath: string, line: string): Promise<void>
49
- resume(sessionId: string, cwd: string, context: string): Promise<void>
50
- sleep(milliseconds: number): Promise<void>
51
- }
52
-
53
- export type ClaudeWakeObservation =
54
- | {
55
- state: 'live-idle' | 'live-busy'
56
- descriptor: ClaudeSessionDescriptor
57
- }
58
- | { state: 'stopped' }
59
- | { state: 'unknown'; reason: string }
60
-
61
- const LIVE_STATUSES: ReadonlySet<string> = new Set(['idle', 'busy'])
62
-
63
- function isRecord(value: unknown): value is Record<string, unknown> {
64
- return typeof value === 'object' && value !== null && !Array.isArray(value)
65
- }
66
-
67
- function parseAgent(value: unknown): ClaudeAgentObservation | null {
68
- if (!isRecord(value)) return null
69
- if (
70
- typeof value['pid'] !== 'number' ||
71
- !Number.isInteger(value['pid']) ||
72
- value['pid'] <= 0 ||
73
- typeof value['sessionId'] !== 'string' ||
74
- value['sessionId'] === '' ||
75
- typeof value['startedAt'] !== 'number' ||
76
- !Number.isFinite(value['startedAt']) ||
77
- typeof value['status'] !== 'string'
78
- ) {
79
- return null
80
- }
81
- return {
82
- pid: value['pid'],
83
- sessionId: value['sessionId'],
84
- startedAt: value['startedAt'],
85
- status: value['status'],
86
- }
87
- }
88
-
89
- function parseDescriptor(value: unknown): ClaudeSessionDescriptor | null {
90
- if (!isRecord(value)) return null
91
- if (
92
- typeof value['pid'] !== 'number' ||
93
- !Number.isInteger(value['pid']) ||
94
- value['pid'] <= 0 ||
95
- typeof value['sessionId'] !== 'string' ||
96
- value['sessionId'] === '' ||
97
- typeof value['cwd'] !== 'string' ||
98
- value['cwd'] === '' ||
99
- typeof value['startedAt'] !== 'number' ||
100
- !Number.isFinite(value['startedAt']) ||
101
- typeof value['procStart'] !== 'string' ||
102
- value['procStart'] === '' ||
103
- typeof value['version'] !== 'string' ||
104
- value['version'] === '' ||
105
- typeof value['peerProtocol'] !== 'number' ||
106
- !Number.isInteger(value['peerProtocol']) ||
107
- typeof value['messagingSocketPath'] !== 'string' ||
108
- value['messagingSocketPath'] === '' ||
109
- typeof value['status'] !== 'string'
110
- ) {
111
- return null
112
- }
113
- return {
114
- pid: value['pid'],
115
- sessionId: value['sessionId'],
116
- cwd: value['cwd'],
117
- startedAt: value['startedAt'],
118
- procStart: value['procStart'],
119
- version: value['version'],
120
- peerProtocol: value['peerProtocol'],
121
- messagingSocketPath: value['messagingSocketPath'],
122
- status: value['status'],
123
- }
124
- }
125
-
126
- /**
127
- * Observe one exact Claude Code session without guessing.
128
- *
129
- * `claude agents --json` is the liveness oracle: Claude Code itself validates
130
- * each registry row against both PID and process start time before returning it.
131
- * The descriptor supplies the socket and peer protocol, but is never trusted as
132
- * proof that a process still owns the session.
133
- */
134
- export async function observeClaudeSession(
135
- sessionId: string,
136
- adapters: Pick<ClaudeWakeAdapters, 'listAgents' | 'readDescriptor'>,
137
- ): Promise<ClaudeWakeObservation> {
138
- let listed: unknown
139
- try {
140
- listed = await adapters.listAgents()
141
- } catch (err) {
142
- return {
143
- state: 'unknown',
144
- reason: `claude agents probe failed: ${err instanceof Error ? err.message : String(err)}`,
145
- }
146
- }
147
- if (!Array.isArray(listed)) {
148
- return { state: 'unknown', reason: 'claude agents returned an invalid document' }
149
- }
150
-
151
- const matchingRaw = listed.filter(
152
- (value) => isRecord(value) && value['sessionId'] === sessionId,
153
- )
154
- if (matchingRaw.length === 0) return { state: 'stopped' }
155
- if (matchingRaw.length !== 1) {
156
- return { state: 'unknown', reason: 'claude agents returned duplicate session owners' }
157
- }
158
- const agent = parseAgent(matchingRaw[0])
159
- if (agent === null) {
160
- return { state: 'unknown', reason: 'claude agents returned an invalid matching row' }
161
- }
162
-
163
- let descriptorRaw: unknown
164
- try {
165
- descriptorRaw = adapters.readDescriptor(agent.pid)
166
- } catch (err) {
167
- return {
168
- state: 'unknown',
169
- reason: `Claude session descriptor could not be read: ${err instanceof Error ? err.message : String(err)}`,
170
- }
171
- }
172
- const descriptor = parseDescriptor(descriptorRaw)
173
- if (descriptor === null) {
174
- return { state: 'unknown', reason: 'Claude session descriptor has an unknown shape' }
175
- }
176
- if (
177
- descriptor.pid !== agent.pid ||
178
- descriptor.sessionId !== agent.sessionId ||
179
- descriptor.startedAt !== agent.startedAt
180
- ) {
181
- return { state: 'unknown', reason: 'Claude liveness probe and descriptor disagree' }
182
- }
183
- if (descriptor.peerProtocol !== CLAUDE_PEER_PROTOCOL) {
184
- return {
185
- state: 'unknown',
186
- reason: `unsupported Claude peer protocol ${descriptor.peerProtocol}`,
187
- }
188
- }
189
- if (!LIVE_STATUSES.has(agent.status)) {
190
- return { state: 'unknown', reason: `Claude session status ${agent.status} is not wakeable` }
191
- }
192
- return {
193
- state: agent.status === 'idle' ? 'live-idle' : 'live-busy',
194
- descriptor,
195
- }
196
- }
197
-
198
- export type ClaudeInboxReadiness =
199
- | { state: 'ready'; socketPath: string; version: string }
200
- | { state: 'unavailable'; reason: string }
201
-
202
- /** Ordered comparison of dotted release numbers, ignoring any suffix. */
203
- function versionAtLeast(version: string, minimum: string): boolean {
204
- const parse = (value: string): number[] =>
205
- value.split('.').map((part) => Number.parseInt(part, 10) || 0)
206
- const left = parse(version)
207
- const right = parse(minimum)
208
- for (let index = 0; index < Math.max(left.length, right.length); index += 1) {
209
- const a = left[index] ?? 0
210
- const b = right[index] ?? 0
211
- if (a !== b) return a > b
212
- }
213
- return true
214
- }
215
-
216
- /**
217
- * Whether an answer could reach this exact Claude session over its inbox
218
- * socket, decided from evidence already on disk.
219
- *
220
- * Read-only by construction: it reads the session descriptor and asks whether
221
- * the socket file exists, and never connects to it. A diagnostic that delivers
222
- * a message is not a diagnostic.
223
- *
224
- * Every negative answer here is a degradation, not a failure — the accepted
225
- * journal still replays the answer at the session's next turn. What it buys is
226
- * that the reason is nameable in advance instead of being discovered as
227
- * silence. The common one is `--bare`, which binds no socket at all (and runs
228
- * no hooks either, so nothing would have registered a question in the first
229
- * place).
230
- */
231
- export function inspectClaudeInbox(options: {
232
- pid: number
233
- platform: NodeJS.Platform
234
- readDescriptor: (pid: number) => unknown
235
- socketExists: (socketPath: string) => boolean
236
- }): ClaudeInboxReadiness {
237
- if (!INBOX_PLATFORMS.has(options.platform)) {
238
- return {
239
- state: 'unavailable',
240
- reason: `Claude Code publishes no inbox socket on ${options.platform}; it exists on macOS and Linux only`,
241
- }
242
- }
243
- let raw: unknown
244
- try {
245
- raw = options.readDescriptor(options.pid)
246
- } catch (err) {
247
- return {
248
- state: 'unavailable',
249
- reason: `no session descriptor for pid ${options.pid} (${err instanceof Error ? err.message : String(err)}); a session started with \`--bare\` binds no inbox socket`,
250
- }
251
- }
252
- const descriptor = parseDescriptor(raw)
253
- if (descriptor === null) {
254
- return {
255
- state: 'unavailable',
256
- reason: `the session descriptor for pid ${options.pid} has an unknown shape`,
257
- }
258
- }
259
- if (descriptor.peerProtocol !== CLAUDE_PEER_PROTOCOL) {
260
- return {
261
- state: 'unavailable',
262
- reason: `this session speaks inbox protocol ${descriptor.peerProtocol}, and only ${CLAUDE_PEER_PROTOCOL} is known; refusing to guess at an undocumented wire format`,
263
- }
264
- }
265
- if (!versionAtLeast(descriptor.version, CLAUDE_MIN_INBOX_VERSION)) {
266
- return {
267
- state: 'unavailable',
268
- reason: `Claude Code ${descriptor.version} is older than ${CLAUDE_MIN_INBOX_VERSION}, which is where the inbox socket starts`,
269
- }
270
- }
271
- if (!options.socketExists(descriptor.messagingSocketPath)) {
272
- return {
273
- state: 'unavailable',
274
- reason: `the descriptor names ${descriptor.messagingSocketPath}, but no socket exists there`,
275
- }
276
- }
277
- return {
278
- state: 'ready',
279
- socketPath: descriptor.messagingSocketPath,
280
- version: descriptor.version,
281
- }
282
- }
283
-
284
- function socketLine(context: string): string {
285
- return `${JSON.stringify({
286
- type: 'user',
287
- message: { role: 'user', content: context },
288
- })}\n`
289
- }
290
-
291
- /**
292
- * Claude's own-child delivery route.
293
- *
294
- * A successful socket write proves delivery to Claude Code, not model
295
- * consumption — and this route reports exactly that, no more. It reports
296
- * `delivered` all the same, because the write is the strongest acknowledgement
297
- * this route can ever obtain: the message it posts starts a brand-new turn
298
- * rather than continuing this one, so no later hook will confirm anything about
299
- * it. An answer delivered once and settled is strictly better than an answer
300
- * redelivered on every turn-end for ever.
301
- *
302
- * Every path that hands nothing over reports `held`, so the accepted journal
303
- * replays it. Unknown state deliberately returns without throwing, so the
304
- * journal becomes `hold-for-next-turn` instead of failing the hook.
305
- */
306
- export function claudeWakeRoute(options: {
307
- sessionId: string
308
- cwd: string
309
- sourcePid: number
310
- adapters?: ClaudeWakeAdapters
311
- }): EscalationDeliveryRoute {
312
- const adapters = options.adapters ?? systemClaudeWakeAdapters()
313
- let sourceDescriptor: ClaudeSessionDescriptor | null = null
314
- try {
315
- const parsed = parseDescriptor(adapters.readDescriptor(options.sourcePid))
316
- if (
317
- parsed !== null &&
318
- parsed.sessionId === options.sessionId &&
319
- parsed.pid === options.sourcePid
320
- ) {
321
- sourceDescriptor = parsed
322
- }
323
- } catch {
324
- // Delivery fails closed below; route construction must never break the hook.
325
- }
326
- return {
327
- kind: 'inbox-socket',
328
- async deliver(event: ContinuationEvent): Promise<DeliveryOutcome> {
329
- const observation = await observeClaudeSession(options.sessionId, adapters)
330
- if (observation.state === 'unknown') {
331
- return {
332
- notes: [`holding the accepted answer for the next turn: ${observation.reason}`],
333
- log: { route: 'hold-for-next-turn', stage: 'queued', reason: observation.reason },
334
- acknowledgement: 'held',
335
- }
336
- }
337
- if (sourceDescriptor === null) {
338
- const reason = 'the Stop-hook process cannot prove exact Claude session ownership'
339
- return {
340
- notes: [`holding the accepted answer for the next turn: ${reason}`],
341
- log: { route: 'hold-for-next-turn', stage: 'queued', reason },
342
- acknowledgement: 'held',
343
- }
344
- }
345
- if (observation.state === 'stopped') {
346
- // Probe immediately before spawn. A prior descriptor or dead socket is
347
- // never sufficient: resuming a live session creates a divergent ghost.
348
- const confirmed = await observeClaudeSession(options.sessionId, adapters)
349
- if (confirmed.state !== 'stopped') {
350
- const reason =
351
- confirmed.state === 'unknown'
352
- ? confirmed.reason
353
- : 'the Claude session became live before cold resume'
354
- return {
355
- notes: [`holding the accepted answer for the next turn: ${reason}`],
356
- log: { route: 'hold-for-next-turn', stage: 'queued', reason },
357
- acknowledgement: 'held',
358
- }
359
- }
360
- if (!event.commitDelivery()) return cancelledDelivery()
361
- await adapters.resume(options.sessionId, sourceDescriptor.cwd, event.context)
362
- return {
363
- notes: ['cold-resumed the stopped Claude session with its accepted answer'],
364
- log: { route: 'cold-resume', stage: 'delivered' },
365
- acknowledgement: 'delivered',
366
- }
367
- }
368
-
369
- if (
370
- observation.descriptor.pid !== options.sourcePid ||
371
- sourceDescriptor.startedAt !== observation.descriptor.startedAt
372
- ) {
373
- const reason = 'the Stop-hook process is not the observed exact Claude session child'
374
- return {
375
- notes: [`holding the accepted answer for the next turn: ${reason}`],
376
- log: { route: 'hold-for-next-turn', stage: 'queued', reason },
377
- acknowledgement: 'held',
378
- }
379
- }
380
- if (!event.commitDelivery()) return cancelledDelivery()
381
- await adapters.sendSocket(
382
- observation.descriptor.messagingSocketPath,
383
- socketLine(event.context),
384
- )
385
- await adapters.sleep(CLAUDE_POST_SEND_LIVENESS_MS)
386
- return {
387
- notes: [
388
- observation.state === 'live-idle'
389
- ? 'posted the accepted answer to the live Claude session'
390
- : 'queued the accepted answer for the busy Claude session',
391
- ],
392
- log: {
393
- route: 'inbox-socket',
394
- stage: 'delivered',
395
- session_state: observation.state,
396
- },
397
- // The write completed: Claude Code holds the message. Nothing later
398
- // reports on it, so this is where the journal settles.
399
- acknowledgement: 'delivered',
400
- }
401
- },
402
- }
403
- }
404
-
405
- function cancelledDelivery(): DeliveryOutcome {
406
- return {
407
- notes: ['the Agent Session ended before answer delivery; stopping this observer'],
408
- log: { route: 'hold-for-next-turn', stage: 'queued', reason: 'session-ended' },
409
- acknowledgement: 'held',
410
- }
411
- }
412
-
413
- function runClaude(args: string[], options: { cwd?: string; env?: NodeJS.ProcessEnv } = {}): Promise<string> {
414
- return new Promise((resolve, reject) => {
415
- const child = spawn('claude', args, {
416
- ...(options.cwd === undefined ? {} : { cwd: options.cwd }),
417
- ...(options.env === undefined ? {} : { env: options.env }),
418
- stdio: ['ignore', 'pipe', 'pipe'],
419
- })
420
- const stdout: Buffer[] = []
421
- const stderr: Buffer[] = []
422
- child.stdout?.on('data', (chunk: Buffer | string) => stdout.push(Buffer.from(chunk)))
423
- child.stderr?.on('data', (chunk: Buffer | string) => stderr.push(Buffer.from(chunk)))
424
- child.once('error', reject)
425
- child.once('exit', (code, signal) => {
426
- if (code === 0) {
427
- resolve(Buffer.concat(stdout).toString())
428
- return
429
- }
430
- reject(
431
- new Error(
432
- `claude ${args[0] ?? ''} exited ${code === null ? `on ${String(signal)}` : String(code)}: ${Buffer.concat(stderr).toString().trim()}`,
433
- ),
434
- )
435
- })
436
- })
437
- }
438
-
439
- function coldResumeEnvironment(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
440
- const next = { ...env }
441
- for (const key of Object.keys(next)) {
442
- if (key === 'CLAUDECODE' || key === 'CLAUDE_PID' || key.startsWith('CLAUDE_CODE_')) {
443
- delete next[key]
444
- }
445
- }
446
- return next
447
- }
448
-
449
- export function systemClaudeWakeAdapters(
450
- env: NodeJS.ProcessEnv = process.env,
451
- ): ClaudeWakeAdapters {
452
- return {
453
- async listAgents() {
454
- const output = await runClaude(['agents', '--json'], { env })
455
- return JSON.parse(output) as unknown
456
- },
457
- readDescriptor(pid) {
458
- const file = path.join(os.homedir(), '.claude', 'sessions', `${pid}.json`)
459
- return JSON.parse(readFileSync(file, 'utf8')) as unknown
460
- },
461
- sendSocket(socketPath, line) {
462
- return new Promise<void>((resolve, reject) => {
463
- const socket = createConnection(socketPath)
464
- let settled = false
465
- const fail = (err: Error): void => {
466
- if (settled) return
467
- settled = true
468
- socket.destroy()
469
- reject(err)
470
- }
471
- socket.once('error', fail)
472
- socket.once('connect', () => {
473
- socket.end(line, () => {
474
- if (settled) return
475
- settled = true
476
- resolve()
477
- })
478
- })
479
- })
480
- },
481
- async resume(sessionId, cwd, context) {
482
- if (!existsSync(cwd)) throw new Error(`Claude session cwd no longer exists: ${cwd}`)
483
- await runClaude(
484
- [
485
- '-p',
486
- '--resume',
487
- sessionId,
488
- '--output-format',
489
- 'json',
490
- context,
491
- ],
492
- { cwd, env: coldResumeEnvironment(env) },
493
- )
494
- },
495
- sleep(milliseconds) {
496
- return new Promise((resolve) => setTimeout(resolve, milliseconds))
497
- },
498
- }
499
- }
@@ -1,176 +0,0 @@
1
- import {
2
- chmodSync,
3
- mkdirSync,
4
- mkdtempSync,
5
- realpathSync,
6
- symlinkSync,
7
- writeFileSync,
8
- } from 'node:fs'
9
- import os from 'node:os'
10
- import path from 'node:path'
11
- import { describe, expect, it } from 'vitest'
12
- import { cliBinReadiness, isExecutablePath, pathNotifaiEntries } from './cli-bin.js'
13
- import { cliUpdateRecoveryCommand } from './cli-update-contract.js'
14
-
15
- describe('PATH notifai diagnosis', () => {
16
- function posixInstall(root: string, name: string, version: string) {
17
- const prefix = path.join(root, name)
18
- const artifact = path.join(
19
- prefix,
20
- 'lib',
21
- 'node_modules',
22
- '@raidiant',
23
- 'notifai',
24
- 'dist',
25
- 'main.js',
26
- )
27
- const command = path.join(prefix, 'bin', 'notifai')
28
- mkdirSync(path.dirname(artifact), { recursive: true })
29
- mkdirSync(path.dirname(command), { recursive: true })
30
- writeFileSync(path.join(path.dirname(path.dirname(artifact)), 'package.json'), JSON.stringify({ version }))
31
- writeFileSync(artifact, '#!/usr/bin/env node\n')
32
- chmodSync(artifact, 0o755)
33
- symlinkSync(path.relative(path.dirname(command), artifact), command)
34
- return { prefix, artifact, command }
35
- }
36
-
37
- function windowsInstall(root: string, name: string, version: string) {
38
- const prefix = path.join(root, name)
39
- const artifact = path.join(
40
- prefix,
41
- 'node_modules',
42
- '@raidiant',
43
- 'notifai',
44
- 'dist',
45
- 'main.js',
46
- )
47
- const command = path.join(prefix, 'notifai.cmd')
48
- mkdirSync(path.dirname(artifact), { recursive: true })
49
- writeFileSync(path.join(path.dirname(path.dirname(artifact)), 'package.json'), JSON.stringify({ version }))
50
- writeFileSync(artifact, '#!/usr/bin/env node\n')
51
- writeFileSync(
52
- command,
53
- '@ECHO off\r\nnode "%dp0%node_modules\\@raidiant\\notifai\\dist\\main.js" %*\r\n',
54
- )
55
- return { prefix, artifact, command }
56
- }
57
-
58
- it('reports a non-executable PATH binary as a gap', () => {
59
- if (process.platform === 'win32') return
60
- const directory = mkdtempSync(path.join(os.tmpdir(), 'notifai-bin-gap-'))
61
- const file = path.join(directory, 'notifai')
62
- writeFileSync(file, '#!/usr/bin/env node\n')
63
- chmodSync(file, 0o644)
64
- expect(isExecutablePath(file, 'darwin')).toBe(false)
65
- const state = cliBinReadiness({ PATH: directory }, 'darwin')
66
- expect(state.status).toBe('gap')
67
- expect(state.detail).not.toContain(file)
68
- expect(state.technical).toMatchObject({ entries: [{ command_path: file, executable: false }] })
69
- expect(state.remedy?.command).not.toBe('notifai update')
70
- expect(state.remedy?.command).toMatch(/ update$/)
71
- })
72
-
73
- it('treats an executable PATH binary as ready', () => {
74
- if (process.platform === 'win32') return
75
- const directory = mkdtempSync(path.join(os.tmpdir(), 'notifai-bin-ok-'))
76
- const file = path.join(directory, 'notifai')
77
- writeFileSync(file, '#!/usr/bin/env node\n')
78
- chmodSync(file, 0o755)
79
- expect(pathNotifaiEntries({ PATH: directory }, 'darwin')).toEqual([file])
80
- expect(
81
- cliBinReadiness({ PATH: directory }, 'darwin', {
82
- runningArtifactPath: file,
83
- currentVersion: null,
84
- }).status,
85
- ).toBe('ready')
86
- })
87
-
88
- it('does not call an older executable PATH winner ready when this process is the current CLI', () => {
89
- const root = mkdtempSync(path.join(os.tmpdir(), 'notifai-bin-stale-winner-'))
90
- const old = posixInstall(root, 'old', '3.0.1')
91
- const current = posixInstall(root, 'current', '10.1.0')
92
-
93
- const state = cliBinReadiness(
94
- { PATH: `${path.dirname(old.command)}:${path.dirname(current.command)}` },
95
- 'darwin',
96
- {
97
- runningArtifactPath: current.artifact,
98
- currentVersion: '10.1.0',
99
- },
100
- )
101
-
102
- expect(state.status).toBe('gap')
103
- expect(state.detail).not.toContain(old.command)
104
- expect(state.remedy?.command).toBe(
105
- cliUpdateRecoveryCommand(),
106
- )
107
- expect(state.remedy?.command).not.toContain(old.command)
108
- expect(state.technical).toMatchObject({
109
- current: { artifact_path: realpathSync(current.artifact), version: '10.1.0' },
110
- effective: { command_path: old.command, artifact_path: realpathSync(old.artifact), version: '3.0.1' },
111
- })
112
- })
113
-
114
- it('uses Windows Path order to reject an older executable winner', () => {
115
- const root = mkdtempSync(path.join(os.tmpdir(), 'notifai-bin-windows-winner-'))
116
- const old = windowsInstall(root, 'old', '3.0.1')
117
- const current = windowsInstall(root, 'current', '10.1.0')
118
-
119
- const state = cliBinReadiness(
120
- { Path: `${old.prefix};${current.prefix}` },
121
- 'win32',
122
- {
123
- runningArtifactPath: current.artifact,
124
- currentVersion: '10.1.0',
125
- },
126
- )
127
-
128
- expect(state.status).toBe('gap')
129
- expect(state.remedy?.command).toBe(
130
- cliUpdateRecoveryCommand(),
131
- )
132
- expect(state.technical).toMatchObject({
133
- effective: {
134
- command_path: old.command,
135
- artifact_path: realpathSync(old.artifact),
136
- version: '3.0.1',
137
- },
138
- })
139
- })
140
-
141
- it('keeps a healthy winner ready while reporting a later broken duplicate for cleanup', () => {
142
- const root = mkdtempSync(path.join(os.tmpdir(), 'notifai-bin-later-broken-'))
143
- const current = posixInstall(root, 'current', '10.1.0')
144
- const broken = posixInstall(root, 'broken', '3.0.1')
145
- chmodSync(broken.artifact, 0o644)
146
-
147
- const state = cliBinReadiness(
148
- { PATH: `${path.dirname(current.command)}:${path.dirname(broken.command)}` },
149
- 'darwin',
150
- { runningArtifactPath: current.artifact, currentVersion: '10.1.0' },
151
- )
152
-
153
- expect(state.status).toBe('optional-gap')
154
- expect(state.detail).toContain('ready')
155
- expect(state.detail).not.toContain(broken.command)
156
- expect(state.technical).toMatchObject({
157
- effective: { command_path: current.command, executable: true },
158
- entries: [
159
- { command_path: current.command, executable: true },
160
- { command_path: broken.command, executable: false },
161
- ],
162
- })
163
- })
164
-
165
- it('does not call a PATH with no notifai entry ready', () => {
166
- const directory = mkdtempSync(path.join(os.tmpdir(), 'notifai-bin-empty-'))
167
- mkdirSync(directory, { recursive: true })
168
- const state = cliBinReadiness({ PATH: directory }, process.platform)
169
- // The running process proves nothing about the command every printed next
170
- // step names — but it is running, so this cannot stand in the way either.
171
- expect(state.status).toBe('optional-gap')
172
- expect(state.detail).toContain('will not be found')
173
- expect(state.remedy?.command).not.toBe('notifai update')
174
- expect(state.remedy?.command).toMatch(/ update$/)
175
- })
176
- })