@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.
Files changed (168) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/commands-core.d.ts +4 -1
  3. package/dist/commands-core.js.map +1 -1
  4. package/dist/commands-doctor.js +2 -7
  5. package/dist/commands-doctor.js.map +1 -1
  6. package/dist/commands-hooks.d.ts +12 -0
  7. package/dist/commands-hooks.js +15 -1
  8. package/dist/commands-hooks.js.map +1 -1
  9. package/dist/commands-init.js +9 -6
  10. package/dist/commands-init.js.map +1 -1
  11. package/dist/commands-send-support.js +10 -11
  12. package/dist/commands-send-support.js.map +1 -1
  13. package/dist/commands-skill.js +72 -54
  14. package/dist/commands-skill.js.map +1 -1
  15. package/dist/harness-session-title.d.ts +22 -0
  16. package/dist/harness-session-title.js +74 -0
  17. package/dist/harness-session-title.js.map +1 -0
  18. package/dist/invocation-context.d.ts +1 -0
  19. package/dist/invocation-context.js +15 -1
  20. package/dist/invocation-context.js.map +1 -1
  21. package/dist/native-skills.d.ts +13 -3
  22. package/dist/native-skills.js +51 -12
  23. package/dist/native-skills.js.map +1 -1
  24. package/dist/node-floor.d.ts +2 -1
  25. package/dist/node-floor.js +9 -5
  26. package/dist/node-floor.js.map +1 -1
  27. package/dist/orca-session-title.d.ts +5 -4
  28. package/dist/orca-session-title.js +32 -19
  29. package/dist/orca-session-title.js.map +1 -1
  30. package/dist/platform.d.ts +11 -17
  31. package/dist/platform.js +20 -23
  32. package/dist/platform.js.map +1 -1
  33. package/dist/release.d.ts +5 -5
  34. package/dist/release.js +5 -5
  35. package/dist/session-labels.d.ts +2 -0
  36. package/dist/session-labels.js +20 -9
  37. package/dist/session-labels.js.map +1 -1
  38. package/dist/setup-destinations.js +1 -1
  39. package/dist/setup-destinations.js.map +1 -1
  40. package/dist/skill-integrity.d.ts +49 -0
  41. package/dist/skill-integrity.js +154 -0
  42. package/dist/skill-integrity.js.map +1 -0
  43. package/dist/skill-source/manifest.json +16 -0
  44. package/dist/skill-source/notifai/SKILL.md +390 -0
  45. package/dist/skill-source/notifai/references/harness-setup.md +220 -0
  46. package/package.json +11 -14
  47. package/src/atomic-file.ts +0 -198
  48. package/src/claude-wake.test.ts +0 -321
  49. package/src/claude-wake.ts +0 -499
  50. package/src/cli-bin.test.ts +0 -176
  51. package/src/cli-bin.ts +0 -233
  52. package/src/cli-release.test.ts +0 -46
  53. package/src/cli-release.ts +0 -78
  54. package/src/cli-update-contract.ts +0 -9
  55. package/src/cli-update.test.ts +0 -125
  56. package/src/client.test.ts +0 -390
  57. package/src/client.ts +0 -352
  58. package/src/codex-wake.test.ts +0 -254
  59. package/src/codex-wake.ts +0 -301
  60. package/src/command-session.ts +0 -38
  61. package/src/commands-agent-sessions.ts +0 -72
  62. package/src/commands-auth.ts +0 -238
  63. package/src/commands-config.ts +0 -336
  64. package/src/commands-core.ts +0 -312
  65. package/src/commands-devices.ts +0 -180
  66. package/src/commands-doctor.ts +0 -1501
  67. package/src/commands-guidance.ts +0 -181
  68. package/src/commands-harness-context.ts +0 -207
  69. package/src/commands-hook-shape.ts +0 -69
  70. package/src/commands-hooks.ts +0 -2318
  71. package/src/commands-init.ts +0 -1055
  72. package/src/commands-io.ts +0 -108
  73. package/src/commands-logs.ts +0 -243
  74. package/src/commands-project.ts +0 -47
  75. package/src/commands-send-support.test.ts +0 -156
  76. package/src/commands-send-support.ts +0 -311
  77. package/src/commands-send.ts +0 -875
  78. package/src/commands-setup-proof.test.ts +0 -72
  79. package/src/commands-setup-proof.ts +0 -124
  80. package/src/commands-skill.test.ts +0 -44
  81. package/src/commands-skill.ts +0 -204
  82. package/src/commands-sounds.test.ts +0 -106
  83. package/src/commands-sounds.ts +0 -49
  84. package/src/commands-update.ts +0 -180
  85. package/src/commands.test.ts +0 -8297
  86. package/src/commands.ts +0 -77
  87. package/src/config-schema.test.ts +0 -153
  88. package/src/config-schema.ts +0 -349
  89. package/src/config.test.ts +0 -581
  90. package/src/config.ts +0 -475
  91. package/src/credentials.test.ts +0 -403
  92. package/src/credentials.ts +0 -403
  93. package/src/file-lock-process-worker.test.ts +0 -64
  94. package/src/file-lock.test.ts +0 -320
  95. package/src/file-lock.ts +0 -393
  96. package/src/fixtures/hermes-0.20.6-classic-cli-local.json +0 -50
  97. package/src/fixtures/openclaw-2026.7.1-2-agent-local.json +0 -57
  98. package/src/generated-session-label.ts +0 -155
  99. package/src/guidance-content.ts +0 -278
  100. package/src/guidance-render.ts +0 -56
  101. package/src/guidance.test.ts +0 -327
  102. package/src/guidance.ts +0 -233
  103. package/src/harness-integration.test.ts +0 -294
  104. package/src/harnesses.test.ts +0 -149
  105. package/src/harnesses.ts +0 -164
  106. package/src/hook-adapter.test.ts +0 -496
  107. package/src/hook-adapter.ts +0 -424
  108. package/src/hook-input.test.ts +0 -39
  109. package/src/hook-input.ts +0 -72
  110. package/src/hooks.test.ts +0 -5824
  111. package/src/hooks.ts +0 -4011
  112. package/src/install-hooks.test.ts +0 -1614
  113. package/src/install-hooks.ts +0 -1501
  114. package/src/interactive.test.ts +0 -387
  115. package/src/interactive.ts +0 -858
  116. package/src/invocation-context.test.ts +0 -352
  117. package/src/invocation-context.ts +0 -197
  118. package/src/logging-process-worker.test.ts +0 -45
  119. package/src/logging.test.ts +0 -544
  120. package/src/logging.ts +0 -698
  121. package/src/main-run.ts +0 -45
  122. package/src/main.ts +0 -12
  123. package/src/native-skills.test.ts +0 -115
  124. package/src/native-skills.ts +0 -162
  125. package/src/node-floor.test.ts +0 -27
  126. package/src/node-floor.ts +0 -37
  127. package/src/onboarding-docs.test.ts +0 -25
  128. package/src/openclaw-plugin.ts +0 -409
  129. package/src/opencode-plugin.ts +0 -298
  130. package/src/orca-session-title.test.ts +0 -54
  131. package/src/orca-session-title.ts +0 -103
  132. package/src/pack-feedback-slice.test.ts +0 -212
  133. package/src/pack-feedback-slice.ts +0 -187
  134. package/src/platform.test.ts +0 -152
  135. package/src/platform.ts +0 -173
  136. package/src/program.test.ts +0 -317
  137. package/src/program.ts +0 -842
  138. package/src/project-enablement.test.ts +0 -55
  139. package/src/project-enablement.ts +0 -99
  140. package/src/question-caps.test.ts +0 -49
  141. package/src/question-settlement-process.ts +0 -47
  142. package/src/question-timing.ts +0 -56
  143. package/src/readiness.test.ts +0 -25
  144. package/src/readiness.ts +0 -212
  145. package/src/release.ts +0 -51
  146. package/src/send-attempts.test.ts +0 -143
  147. package/src/send-attempts.ts +0 -188
  148. package/src/send.test.ts +0 -28
  149. package/src/send.ts +0 -436
  150. package/src/session-activation.ts +0 -61
  151. package/src/session-end-log-lock-worker.test.ts +0 -35
  152. package/src/session-labels.test.ts +0 -490
  153. package/src/session-labels.ts +0 -474
  154. package/src/setup-destinations.test.ts +0 -41
  155. package/src/setup-destinations.ts +0 -50
  156. package/src/skill.test.ts +0 -426
  157. package/src/sound-ref.test.ts +0 -31
  158. package/src/sound-ref.ts +0 -34
  159. package/src/trust-policy.test.ts +0 -701
  160. package/src/ui/banner.ts +0 -95
  161. package/src/ui/config-view.test.ts +0 -90
  162. package/src/ui/config-view.ts +0 -138
  163. package/src/ui/help.test.ts +0 -16
  164. package/src/ui/help.ts +0 -128
  165. package/src/ui/theme.test.ts +0 -92
  166. package/src/ui/theme.ts +0 -265
  167. package/src/url-policy.ts +0 -399
  168. 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
- })