@raidiant/notifai 7.0.2 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/CHANGELOG.md +75 -0
  2. package/README.md +20 -13
  3. package/dist/atomic-file.d.ts +14 -0
  4. package/dist/atomic-file.js +27 -2
  5. package/dist/atomic-file.js.map +1 -1
  6. package/dist/cli-bin.d.ts +4 -0
  7. package/dist/cli-bin.js +62 -0
  8. package/dist/cli-bin.js.map +1 -0
  9. package/dist/cli-release.d.ts +10 -0
  10. package/dist/cli-release.js +75 -0
  11. package/dist/cli-release.js.map +1 -0
  12. package/dist/client.d.ts +1 -0
  13. package/dist/client.js +13 -3
  14. package/dist/client.js.map +1 -1
  15. package/dist/commands-auth.d.ts +6 -0
  16. package/dist/commands-auth.js +28 -3
  17. package/dist/commands-auth.js.map +1 -1
  18. package/dist/commands-config.js +22 -3
  19. package/dist/commands-config.js.map +1 -1
  20. package/dist/commands-core.d.ts +12 -0
  21. package/dist/commands-core.js +27 -3
  22. package/dist/commands-core.js.map +1 -1
  23. package/dist/commands-devices.d.ts +2 -1
  24. package/dist/commands-devices.js +20 -8
  25. package/dist/commands-devices.js.map +1 -1
  26. package/dist/commands-doctor.d.ts +1 -0
  27. package/dist/commands-doctor.js +85 -27
  28. package/dist/commands-doctor.js.map +1 -1
  29. package/dist/commands-guidance.d.ts +27 -0
  30. package/dist/commands-guidance.js +163 -0
  31. package/dist/commands-guidance.js.map +1 -0
  32. package/dist/commands-hooks.d.ts +16 -5
  33. package/dist/commands-hooks.js +433 -38
  34. package/dist/commands-hooks.js.map +1 -1
  35. package/dist/commands-init.d.ts +10 -18
  36. package/dist/commands-init.js +139 -54
  37. package/dist/commands-init.js.map +1 -1
  38. package/dist/commands-send-support.d.ts +17 -2
  39. package/dist/commands-send-support.js +66 -8
  40. package/dist/commands-send-support.js.map +1 -1
  41. package/dist/commands-send.d.ts +0 -1
  42. package/dist/commands-send.js +105 -39
  43. package/dist/commands-send.js.map +1 -1
  44. package/dist/commands-setup-proof.d.ts +8 -0
  45. package/dist/commands-setup-proof.js +31 -2
  46. package/dist/commands-setup-proof.js.map +1 -1
  47. package/dist/commands-skill.d.ts +11 -1
  48. package/dist/commands-skill.js +61 -11
  49. package/dist/commands-skill.js.map +1 -1
  50. package/dist/commands.d.ts +2 -1
  51. package/dist/commands.js +1 -0
  52. package/dist/commands.js.map +1 -1
  53. package/dist/config-schema.d.ts +1 -1
  54. package/dist/config-schema.js +30 -14
  55. package/dist/config-schema.js.map +1 -1
  56. package/dist/config.d.ts +24 -5
  57. package/dist/config.js +37 -8
  58. package/dist/config.js.map +1 -1
  59. package/dist/credentials.d.ts +10 -1
  60. package/dist/credentials.js +25 -12
  61. package/dist/credentials.js.map +1 -1
  62. package/dist/guidance-content.d.ts +50 -0
  63. package/dist/guidance-content.js +240 -0
  64. package/dist/guidance-content.js.map +1 -0
  65. package/dist/guidance.d.ts +69 -0
  66. package/dist/guidance.js +173 -0
  67. package/dist/guidance.js.map +1 -0
  68. package/dist/hook-adapter.js +37 -3
  69. package/dist/hook-adapter.js.map +1 -1
  70. package/dist/hooks.d.ts +68 -7
  71. package/dist/hooks.js +238 -92
  72. package/dist/hooks.js.map +1 -1
  73. package/dist/install-hooks.d.ts +10 -18
  74. package/dist/install-hooks.js +110 -23
  75. package/dist/install-hooks.js.map +1 -1
  76. package/dist/interactive.d.ts +1 -1
  77. package/dist/interactive.js +14 -9
  78. package/dist/interactive.js.map +1 -1
  79. package/dist/logging.d.ts +8 -1
  80. package/dist/logging.js +43 -2
  81. package/dist/logging.js.map +1 -1
  82. package/dist/main.js +5 -487
  83. package/dist/main.js.map +1 -1
  84. package/dist/native-skills.d.ts +19 -0
  85. package/dist/native-skills.js +30 -8
  86. package/dist/native-skills.js.map +1 -1
  87. package/dist/opencode-plugin.js +14 -1
  88. package/dist/opencode-plugin.js.map +1 -1
  89. package/dist/program.d.ts +49 -0
  90. package/dist/program.js +576 -0
  91. package/dist/program.js.map +1 -0
  92. package/dist/send.d.ts +12 -10
  93. package/dist/send.js +65 -29
  94. package/dist/send.js.map +1 -1
  95. package/dist/session-activation.d.ts +15 -0
  96. package/dist/session-activation.js +35 -0
  97. package/dist/session-activation.js.map +1 -0
  98. package/dist/session-labels.d.ts +9 -3
  99. package/dist/session-labels.js +38 -7
  100. package/dist/session-labels.js.map +1 -1
  101. package/dist/url-policy.d.ts +85 -0
  102. package/dist/url-policy.js +369 -0
  103. package/dist/url-policy.js.map +1 -0
  104. package/package.json +6 -4
  105. package/src/atomic-file.ts +36 -2
  106. package/src/cli-bin.test.ts +38 -0
  107. package/src/cli-bin.ts +67 -0
  108. package/src/cli-release.test.ts +46 -0
  109. package/src/cli-release.ts +78 -0
  110. package/src/client.test.ts +95 -0
  111. package/src/client.ts +16 -3
  112. package/src/commands-auth.ts +32 -3
  113. package/src/commands-config.ts +25 -2
  114. package/src/commands-core.ts +38 -3
  115. package/src/commands-devices.ts +28 -9
  116. package/src/commands-doctor.ts +116 -25
  117. package/src/commands-guidance.ts +216 -0
  118. package/src/commands-hooks.ts +513 -42
  119. package/src/commands-init.ts +170 -60
  120. package/src/commands-send-support.test.ts +156 -0
  121. package/src/commands-send-support.ts +72 -8
  122. package/src/commands-send.ts +123 -38
  123. package/src/commands-setup-proof.ts +36 -2
  124. package/src/commands-skill.ts +78 -15
  125. package/src/commands.test.ts +1490 -197
  126. package/src/commands.ts +6 -0
  127. package/src/config-schema.ts +32 -16
  128. package/src/config.test.ts +57 -2
  129. package/src/config.ts +49 -10
  130. package/src/credentials.test.ts +71 -3
  131. package/src/credentials.ts +29 -15
  132. package/src/guidance-content.ts +256 -0
  133. package/src/guidance.test.ts +299 -0
  134. package/src/guidance.ts +233 -0
  135. package/src/hook-adapter.test.ts +113 -1
  136. package/src/hook-adapter.ts +37 -3
  137. package/src/hooks.test.ts +783 -170
  138. package/src/hooks.ts +306 -131
  139. package/src/install-hooks.test.ts +135 -16
  140. package/src/install-hooks.ts +113 -25
  141. package/src/interactive.ts +14 -9
  142. package/src/logging.test.ts +66 -3
  143. package/src/logging.ts +45 -2
  144. package/src/main.ts +6 -614
  145. package/src/native-skills.test.ts +41 -1
  146. package/src/native-skills.ts +40 -6
  147. package/src/opencode-plugin.ts +14 -1
  148. package/src/program.test.ts +237 -0
  149. package/src/program.ts +751 -0
  150. package/src/send.test.ts +28 -0
  151. package/src/send.ts +81 -34
  152. package/src/session-activation.ts +45 -0
  153. package/src/session-labels.test.ts +120 -3
  154. package/src/session-labels.ts +38 -7
  155. package/src/skill.test.ts +153 -12
  156. package/src/trust-policy.test.ts +701 -0
  157. package/src/url-policy.ts +399 -0
package/src/main.ts CHANGED
@@ -1,42 +1,9 @@
1
1
  #!/usr/bin/env node
2
- import { readFileSync } from 'node:fs'
3
- import { Command } from 'commander'
4
- import {
5
- acknowledgeCommand,
6
- askCommand,
7
- accessStatusCommand,
8
- authStatusCommand,
9
- capabilitiesCommand,
10
- closeCommand,
11
- configExplainCommand,
12
- configSetCommand,
13
- configShowCommand,
14
- configUnsetCommand,
15
- devicesCommand,
16
- doctorCommand,
17
- hookDefersDiagnosticsUntilAfterCleanup,
18
- hookRunCommand,
19
- hooksInstallCommand,
20
- hooksUninstallCommand,
21
- initCommand,
22
- loginCommand,
23
- logoutCommand,
24
- logsCommand,
25
- realIo,
26
- repliesCommand,
27
- sendCommand,
28
- statusCommand,
29
- type CommandDeps,
30
- } from './commands.js'
2
+ import { realIo, type CommandDeps } from './commands.js'
31
3
  import { defaultCredentialStore } from './credentials.js'
32
- import { packageVersion } from './release.js'
33
- import { HARNESSES } from './install-hooks.js'
34
- import type { Platform } from '@raidiant/notifai-protocol'
35
- import { nativeSkills, type SkillScope } from './native-skills.js'
36
- import { GROUP, SEND_GROUP, helpConfiguration, rootHelpFooter } from './ui/help.js'
37
-
38
- import { readStdinWithTimeout } from './hook-input.js'
39
- import { bootstrapLogger } from './logging.js'
4
+ import { nativeSkills } from './native-skills.js'
5
+ import { argvFlagNames, bootstrapLogger } from './logging.js'
6
+ import { buildProgram } from './program.js'
40
7
 
41
8
  /**
42
9
  * The local record for this invocation.
@@ -57,588 +24,13 @@ const deps: CommandDeps = {
57
24
  logger,
58
25
  }
59
26
 
60
- /**
61
- * One source of truth for the version: the manifest npm actually published.
62
- *
63
- * It was hardcoded here as well, and the first patch release proved why that
64
- * does not hold — `package.json` moved and `notifai --version` kept reporting
65
- * the old number, which is exactly the string someone pastes into a bug report
66
- * to say what they are running.
67
- *
68
- * `unknown` is the display form of "this build cannot tell"; the skill pin
69
- * derived from the same source refuses instead, because a wrong ref installs
70
- * the wrong thing while a wrong version string only misinforms.
71
- */
72
- function version(): string {
73
- return packageVersion() ?? 'unknown'
74
- }
75
-
76
- /**
77
- * The full command path, e.g. `config set`, so a filter on `cmd` distinguishes
78
- * subcommands that share a leaf name.
79
- */
80
- function commandPath(command: Command): string {
81
- const parts: string[] = []
82
- for (let node: Command | null = command; node?.parent != null; node = node.parent) {
83
- parts.unshift(node.name())
84
- }
85
- return parts.join(' ') || 'notifai'
86
- }
87
-
88
- /**
89
- * Which flags were passed, without their values.
90
- *
91
- * The flag names answer nearly every question worth asking of an invocation —
92
- * was `--reply` set, was `--all` — while the values are notification content
93
- * and user text that has no business being recorded merely because a command
94
- * ran. Values are available under `log_level = debug`, which is a deliberate act.
95
- */
96
- function flagNames(argv: readonly string[]): string[] {
97
- return argv.filter((token) => token.startsWith('--'))
98
- }
99
-
100
27
  const startedAt = Date.now()
101
28
  process.on('exit', (code) => {
102
29
  logger.info('cli.end', {
103
30
  exit: code,
104
31
  duration_ms: Date.now() - startedAt,
105
- flags: flagNames(process.argv.slice(2)),
106
- })
107
- })
108
-
109
- const program = new Command('notifai')
110
- .description('Send native device notifications from agents and local programs')
111
- .version(version())
112
- .configureHelp(helpConfiguration)
113
- // Lazy on purpose. `addHelpText` also takes a string, but that builds the
114
- // footer on every invocation — including the hook that runs in front of
115
- // every prompt the user types, which never renders help at all.
116
- .addHelpText('after', () => rootHelpFooter())
117
- // Commander's default is to print the full help and exit 0 for an unknown
118
- // `help` topic, so `notifai help nonsense` looked like it had worked. A
119
- // reader who mistyped a command deserves to be told, and a script deserves
120
- // a nonzero code.
121
- .showSuggestionAfterError(true)
122
- // Commander drops the implicit `help [command]` as soon as the program
123
- // itself has an action handler — which the interactive default below gives
124
- // it. Without this, adding that default would silently break
125
- // `notifai help send` for everyone who reaches for it before `--help`.
126
- .helpCommand(true)
127
- .hook('preAction', (_program, actionCommand) => {
128
- logger.bind({ cmd: commandPath(actionCommand) })
129
- // SessionEnd uses the hook policy shared with commands.ts: local cleanup
130
- // precedes every diagnostic that can wait on the shared log lock.
131
- const deferDiagnostics =
132
- actionCommand.name() === 'hook' &&
133
- hookDefersDiagnosticsUntilAfterCleanup(actionCommand.processedArgs[0])
134
- // Values only at `debug`; `cli.end` carries the flag names at every level.
135
- if (!deferDiagnostics) {
136
- logger.debug('cli.start', {
137
- version: version(),
138
- argv: process.argv.slice(2),
139
- cwd: process.cwd(),
140
- })
141
- }
32
+ flags: argvFlagNames(process.argv.slice(2)),
142
33
  })
143
-
144
- /**
145
- * Bare `notifai`.
146
- *
147
- * At a human terminal this opens the interactive app; anywhere else it prints
148
- * help exactly as before. The check is the same one every other prompt in this
149
- * CLI is gated on — stdin and stdout both TTYs, not CI, `NOTIFAI_NO_INPUT`
150
- * unset — because an agent that reaches a prompt does not fail, it hangs
151
- * for ever waiting on a stdin nobody is typing into.
152
- *
153
- * The import is dynamic so that the prompt library, the banner and the whole
154
- * interactive tree cost nothing to the paths that never draw them — `send`,
155
- * `ask`, and the hook that runs in front of every prompt the user types.
156
- */
157
- /**
158
- * Commander exits 1 for every usage error it detects itself, which contradicts
159
- * the exit vocabulary this CLI documents and every hand-written usage error it
160
- * returns. A caller branching on exit codes should not have to know which layer
161
- * rejected it. Help and version stay successful.
162
- */
163
- program.exitOverride((err) => {
164
- process.exit(err.exitCode === 0 ? 0 : 2)
165
34
  })
166
35
 
167
- /**
168
- * An unrecognised subcommand reaches the root as an excess argument, and
169
- * "expected 0 arguments but got 1" tells a caller nothing about what it typed
170
- * or what exists. Naming it — with the nearest real command when there is one —
171
- * turns a dead end into one more try.
172
- */
173
- program.usage('[options] [command]')
174
- program.argument('[command]').action(async (command?: string) => {
175
- if (command !== undefined) {
176
- const names = program.commands.map((cmd) => cmd.name())
177
- const near = names.filter(
178
- (name) =>
179
- name.startsWith(command.slice(0, 2)) ||
180
- command.startsWith(name.slice(0, 2)) ||
181
- name.includes(command) ||
182
- command.includes(name),
183
- )
184
- deps.io.err(
185
- `Unknown command "${command}".` +
186
- (near.length > 0 ? ` Did you mean: ${near.slice(0, 3).join(', ')}?` : '') +
187
- ' Run notifai --help for the full list.',
188
- )
189
- process.exit(2)
190
- }
191
- if (deps.io.interactive !== true) {
192
- program.outputHelp()
193
- return
194
- }
195
- const { interactiveCommand } = await import('./interactive.js')
196
- process.exit(await interactiveCommand(deps, version()))
197
- })
198
-
199
- // Setup leads: `init` is the single entry command for first-run friendliness.
200
- program
201
- .command('init')
202
- .helpGroup(GROUP.start)
203
- .summary('Set this project up, step by step')
204
- .description(
205
- 'Set up Notifai here, idempotently: sign-in, project id, hooks, device readiness, live receipt proof. ' +
206
- 'Interactive at a human terminal; never prompts otherwise (agents: pass flags)',
207
- )
208
- .option('--project-id <id>', 'project identifier slug (default: derived from the directory name)')
209
- .option('--skills', 'install/update the agent skill from its pinned public release')
210
- .option('--no-skills', 'suppress the optional agent-skill status line')
211
- .option('--skills-scope <scope>', 'unattended skill scope: project or global')
212
- .option('--hooks', 'install harness hooks for registered-question routing')
213
- .option('--no-hooks', 'skip the hooks without being asked')
214
- .action(async (opts: { projectId?: string; skills?: boolean; skillsScope?: SkillScope; hooks?: boolean }) => {
215
- process.exit(await initCommand(deps, opts))
216
- })
217
-
218
- program
219
- .command('doctor')
220
- .helpGroup(GROUP.daily)
221
- .summary('Check every part of the setup')
222
- .description('Audit config, credential, server, contract, device, hook, and saved receipt proof; exits nonzero when any line is FAIL (no live send)')
223
- .option('--json', 'machine-readable output')
224
- .action(async (opts: { json?: boolean }) => {
225
- process.exit(await doctorCommand(deps, opts))
226
- })
227
-
228
- program
229
- .command('login')
230
- .helpGroup(GROUP.start)
231
- .summary('Sign in and pair this machine')
232
- .description('Pair this machine with your Notifai account via browser approval')
233
- .option('--name <name>', 'machine name shown in the dashboard (default: hostname)')
234
- .option('--base-url <url>', 'developer override for the service origin (also NOTIFAI_BASE_URL)')
235
- .option('--no-open', 'do not open the approval page in a browser')
236
- .action(async (opts: { name?: string; baseUrl?: string; open?: boolean }) => {
237
- process.exit(await loginCommand(deps, opts))
238
- })
239
-
240
- program
241
- .command('logout')
242
- .helpGroup(GROUP.advanced)
243
- .summary('Remove the stored machine credential')
244
- .description('Remove the stored machine credential')
245
- .action(() => {
246
- process.exit(logoutCommand(deps))
247
- })
248
-
249
- const auth = program
250
- .command('auth')
251
- .description('Authentication helpers')
252
- .summary('Machine identity and account plan')
253
- .helpGroup(GROUP.advanced)
254
- auth
255
- .command('status')
256
- .description('Show the stored machine identity')
257
- .option('--json', 'machine-readable output')
258
- .action((opts: { json?: boolean }) => {
259
- process.exit(authStatusCommand(deps, opts))
260
- })
261
- auth
262
- .command('access')
263
- .description('Show the account plan and access decision')
264
- .option('--json', 'machine-readable output')
265
- .action(async (opts: { json?: boolean }) => {
266
- process.exit(await accessStatusCommand(deps, opts))
267
- })
268
-
269
- program
270
- .command('devices')
271
- .helpGroup(GROUP.daily)
272
- .summary('List your devices and whether they can receive')
273
- .description('List registered devices and their delivery readiness')
274
- .option('--json', 'machine-readable output')
275
- .action(async (opts: { json?: boolean }) => {
276
- process.exit(await devicesCommand(deps, opts))
277
- })
278
-
279
- program
280
- .command('capabilities')
281
- .helpGroup(GROUP.advanced)
282
- .summary('Show what a platform can render')
283
- .description('Show a platform capability contract')
284
- .option('--platform <platform>', 'platform to describe (default: ios)')
285
- .option('--json', 'machine-readable output')
286
- .action(async (opts: { json?: boolean; platform?: Platform }) => {
287
- process.exit(await capabilitiesCommand(deps, opts))
288
- })
289
-
290
- const send = program
291
- .command('send')
292
- .helpGroup(GROUP.agent)
293
- .summary('Send a notification')
294
- .description('Send a notification')
295
- .optionsGroup(SEND_GROUP.content)
296
- .requiredOption('--title <title>', 'brief title whose substance is immediately understandable')
297
- .option('--body <markdown>', 'canonical Markdown body')
298
- .option('--body-file <path>', 'read the canonical Markdown body from a file (use - for stdin)')
299
- .option('--subtitle <subtitle>', 'a plain-text line between the title and body')
300
- .option(
301
- '--image <path|url|media_id>',
302
- 'upload or attach an image in collection order (repeatable, maximum 8)',
303
- (v: string, all: string[] = []) => [...all, v],
304
- )
305
- .option(
306
- '--image-alt <text>',
307
- 'alt text paired with --image occurrences by position (repeatable)',
308
- (v: string, all: string[] = []) => [...all, v],
309
- )
310
- .optionsGroup(SEND_GROUP.routing)
311
- .option('--kind <kind>', 'what this is (required): update | done | failed | blocked — question is set by --reply')
312
- .option('--project <id>', 'project identifier override (otherwise configured or inferred)')
313
- .option('--device <id>', 'target a device id (repeatable)', (v: string, all: string[] = []) => [...all, v])
314
- .option('--all', 'target all routable devices (overrides configured devices)')
315
- .option('--session-id <id>', 'opaque exact-session override (env: NOTIFAI_SESSION_ID)')
316
- .option(
317
- '--session-label <text>',
318
- 'first human session name, frozen locally (env: NOTIFAI_SESSION_LABEL)',
319
- )
320
- .option('--event <event>', 'agent event name, e.g. tests_passed')
321
- .optionsGroup(SEND_GROUP.presentation)
322
- .option('--collapse-key <key>', 'replace earlier notifications with the same key')
323
- .option('--thread-id <id>', 'group related notifications')
324
- .option('--ttl <seconds>', 'delivery window in seconds', (v: string) => Number(v))
325
- .option('--platform <platform>', 'limit optional fields to one supported platform')
326
- .optionsGroup(SEND_GROUP.reply)
327
- .option('--reply', 'enable the inline reply action and block for the answer')
328
- .option('--reply-timeout <seconds>', 'how long to wait for a reply (default: 900)', (v: string) => Number(v))
329
- .option(
330
- '--reply-window <seconds>',
331
- 'how long an answer is still accepted, 60-259200 (default: reply_window_seconds, a day)',
332
- (v: string) => Number(v),
333
- )
334
- .option(
335
- '--reply-choice <label>',
336
- 'with --reply, ask a closed question; repeat the flag once per answer (2-6)',
337
- (v: string, all: string[] = []) => [...all, v],
338
- )
339
- .option('--reply-multi', 'with --reply-choice, several answers may be selected')
340
- // Kept registered, and always a usage error with --reply, so the caller gets
341
- // a message pointing at `ask` instead of "unknown option".
342
- .option('--no-block', 'rejected with --reply; use `notifai ask` to ask and end the turn')
343
- .optionsGroup(SEND_GROUP.advanced)
344
- .option('--sound <sound>', 'override saved sound: default | done | attention | alert | none')
345
- .option('--level <level>', 'override saved interruption level: passive | active | time_sensitive')
346
- .option('--wait <seconds>', 'how long to wait for provider outcomes', (v: string) => Number(v))
347
- .option('--no-wait', 'return immediately after acceptance')
348
- .option('--data <key=value>', 'custom data (repeatable)', (v: string, all: string[] = []) => [...all, v])
349
- .option('--idempotency-key <key>', 'safe-retry key (default: random)')
350
- .option('--base-url <url>', 'developer override for the service origin (also NOTIFAI_BASE_URL)')
351
- .option('--json', 'print the full submission receipt as JSON')
352
- .action(async (opts: Record<string, unknown>) => {
353
- // commander maps --no-wait onto the same "wait" flag; disentangle.
354
- const noWait = opts['wait'] === false
355
- const wait = typeof opts['wait'] === 'number' ? opts['wait'] : undefined
356
- const noBlock = opts['block'] === false
357
- const sendOpts = { ...opts }
358
- // Commander collectors default to []; an empty list means "not passed".
359
- for (const key of ['replyChoice', 'image', 'imageAlt']) {
360
- if (Array.isArray(sendOpts[key]) && sendOpts[key].length === 0) delete sendOpts[key]
361
- }
362
- delete sendOpts['block']
363
- const bodyFile = sendOpts['bodyFile']
364
- delete sendOpts['bodyFile']
365
- if (typeof bodyFile === 'string') {
366
- if (sendOpts['body'] !== undefined) {
367
- deps.io.err('Pass either --body or --body-file, not both.')
368
- process.exit(2)
369
- }
370
- try {
371
- sendOpts['body'] = readFileSync(bodyFile === '-' ? 0 : bodyFile, 'utf8')
372
- } catch (err) {
373
- deps.io.err(`Could not read ${bodyFile}: ${String(err)}`)
374
- process.exit(2)
375
- }
376
- }
377
- const flags = { ...sendOpts, noWait, noBlock } as Parameters<typeof sendCommand>[1]
378
- if (wait === undefined) delete (flags as { wait?: number }).wait
379
- else flags.wait = wait
380
- process.exit(await sendCommand(deps, flags))
381
- })
382
-
383
- send.addHelpText(
384
- 'after',
385
- `\nKind is required, and it selects the sound the notification arrives with: done rings the completion chime, failed the most insistent tone, blocked and question a distinct attention tone, update the standard one.\nAn explicit --sound or --level, and the user's saved preference, both outrank that default.\n`,
386
- )
387
-
388
- program
389
- .command('replies [request_id]')
390
- .helpGroup(GROUP.agent)
391
- .summary('Retrieve replies to a question')
392
- .description('Retrieve replies for a notification request')
393
- .option('--pending', 'use the pushed question pending for this project session')
394
- .option('--wait <seconds>', 'how long to wait for a reply', (v: string) => Number(v))
395
- .option('--after <seq>', 'return replies after this sequence number', (v: string) => Number(v))
396
- .option('--json', 'machine-readable output')
397
- .action(async (requestId: string | undefined, opts: { wait?: number; after?: number; json?: boolean; pending?: boolean }) => {
398
- process.exit(await repliesCommand(deps, requestId, opts))
399
- })
400
-
401
- program
402
- .command('acknowledge <request_id>')
403
- .helpGroup(GROUP.agent)
404
- .summary("Tell the user what you'll do because of their reply")
405
- .description(
406
- 'Record the required Agent Acknowledgement for a replied-to notification request; never prompts',
407
- )
408
- .option('--text <text>', 'concrete work you will do because of the reply')
409
- .option('--json', 'machine-readable output')
410
- .action(async (requestId: string, opts: { text?: string; json?: boolean }) => {
411
- process.exit(await acknowledgeCommand(deps, requestId, opts))
412
- })
413
-
414
- program
415
- .command('status <request_id>')
416
- .helpGroup(GROUP.agent)
417
- .summary('Show the evidence trail for a request')
418
- .description('Show the evidence trail for a notification request')
419
- .option('--json', 'machine-readable output')
420
- .action(async (requestId: string, opts: { json?: boolean }) => {
421
- process.exit(await statusCommand(deps, requestId, opts))
422
- })
423
-
424
- program
425
- .command('ask [question]')
426
- .helpGroup(GROUP.agent)
427
- .summary('Register a question, then end the turn')
428
- .description('Register a question for the turn-end hook to route to your devices, subject to your question-routing settings')
429
- .option(
430
- '--choice <label>',
431
- 'answers to offer instead of free text; repeat the flag once per answer (2-6)',
432
- (v: string, all: string[] = []) => [...all, v],
433
- )
434
- .option('--multi', 'with --choice, several answers may be selected')
435
- .option('--json', 'machine-readable output')
436
- .option('--body <markdown>', 'optional Markdown context appended after the question block')
437
- .option('--body-file <path>', 'read optional Markdown context from a file (use - for stdin)')
438
- .option('--form <path>', 'ask several questions as one form; JSON file (use - for stdin)')
439
- .option(
440
- '--image <path|url|media_id>',
441
- 'upload or attach an image in collection order (repeatable, maximum 8)',
442
- (v: string, all: string[] = []) => [...all, v],
443
- )
444
- .option(
445
- '--image-alt <text>',
446
- 'alt text paired with --image occurrences by position (repeatable)',
447
- (v: string, all: string[] = []) => [...all, v],
448
- )
449
- .option('--project <id>', 'project identifier override (otherwise configured or inferred)')
450
- .option('--session-id <id>', 'opaque exact-session override (env: NOTIFAI_SESSION_ID)')
451
- .option(
452
- '--session-label <text>',
453
- 'first human session name, frozen locally (env: NOTIFAI_SESSION_LABEL)',
454
- )
455
- .action(async (question: string | undefined, opts: {
456
- choice?: string[]
457
- multi?: boolean
458
- json?: boolean
459
- body?: string
460
- bodyFile?: string
461
- form?: string
462
- image?: string[]
463
- imageAlt?: string[]
464
- project?: string
465
- sessionId?: string
466
- sessionLabel?: string
467
- }) => {
468
- let body = opts.body
469
- if (typeof opts.bodyFile === 'string') {
470
- if (body !== undefined) {
471
- deps.io.err('Pass either --body or --body-file, not both.')
472
- process.exit(2)
473
- }
474
- try {
475
- body = readFileSync(opts.bodyFile === '-' ? 0 : opts.bodyFile, 'utf8')
476
- } catch (err) {
477
- deps.io.err(`Could not read ${opts.bodyFile}: ${String(err)}`)
478
- process.exit(2)
479
- }
480
- }
481
- let form: string | undefined
482
- if (typeof opts.form === 'string') {
483
- try {
484
- form = readFileSync(opts.form === '-' ? 0 : opts.form, 'utf8')
485
- } catch (err) {
486
- deps.io.err(`Could not read ${opts.form}: ${String(err)}`)
487
- process.exit(2)
488
- }
489
- }
490
- // Commander collectors default to []; an empty list means "not passed".
491
- const flags: Parameters<typeof askCommand>[2] = {
492
- ...(opts.choice?.length ? { choice: opts.choice } : {}),
493
- ...(opts.multi ? { multi: true } : {}),
494
- ...(body !== undefined ? { body } : {}),
495
- ...(form !== undefined ? { form } : {}),
496
- ...(opts.image?.length ? { image: opts.image } : {}),
497
- ...(opts.imageAlt?.length ? { imageAlt: opts.imageAlt } : {}),
498
- ...(opts.project !== undefined ? { project: opts.project } : {}),
499
- ...(opts.sessionId !== undefined ? { sessionId: opts.sessionId } : {}),
500
- ...(opts.sessionLabel !== undefined ? { sessionLabel: opts.sessionLabel } : {}),
501
- ...(opts.json === true ? { json: true } : {}),
502
- }
503
- process.exit(await askCommand(deps, question, flags))
504
- })
505
-
506
- program
507
- .command('close <request_id>')
508
- .helpGroup(GROUP.agent)
509
- .summary('Retire a question so late answers are rejected')
510
- .description('Retire a question so late answers are rejected rather than lost')
511
- .option('--json', 'machine-readable output')
512
- .action(async (requestId: string, opts: { json?: boolean }) => {
513
- process.exit(await closeCommand(deps, requestId, opts))
514
- })
515
-
516
- // Hidden, not removed. It is an entry point the hook installer writes into a
517
- // harness config file, never something a person types — and listing it beside
518
- // `send` invited exactly one reading, which is that you were supposed to.
519
- program
520
- .command('hook <event>', { hidden: true })
521
- .description('Internal: run a harness hook (reads hook JSON on stdin)')
522
- // Inert, and the point of it is that it is inert: the installed command line
523
- // carries a marker that says "Notifai wrote this" independently of which
524
- // checkout wrote it.
525
- .option('--owner <name>', 'internal ownership marker')
526
- .option('--harness <name>', 'internal harness output adapter')
527
- .action(async (event: string, opts: { harness?: string }) => {
528
- const harness = HARNESSES.find((candidate) => candidate === opts.harness)
529
- process.exit(
530
- await hookRunCommand(deps, event, () => readStdinWithTimeout(), harness),
531
- )
532
- })
533
-
534
- const hooks = program
535
- .command('hooks')
536
- .description('Install harness hooks for registered-question routing')
537
- .summary('Wire a harness to route questions to your devices')
538
- .helpGroup(GROUP.advanced)
539
- hooks
540
- .command('install')
541
- .description('Wire this harness to route registered questions to your devices')
542
- .option(
543
- '--harness <name>',
544
- 'claude-code | codex | cursor | opencode (default: every detected harness)',
545
- )
546
- .option('--global', 'install for every project instead of just this one')
547
- .action((opts: { harness?: string; global?: boolean }) => {
548
- process.exit(hooksInstallCommand(deps, opts))
549
- })
550
- hooks
551
- .command('uninstall')
552
- .description('Remove the hooks this CLI installed')
553
- .option('--harness <name>', 'claude-code | codex | cursor | opencode (default: detected)')
554
- .option('--global', 'remove the machine-wide install')
555
- .action((opts: { harness?: string; global?: boolean }) => {
556
- process.exit(hooksUninstallCommand(deps, opts))
557
- })
558
-
559
- program
560
- .command('logs')
561
- .helpGroup(GROUP.daily)
562
- .summary('Show what this machine recorded about what it did')
563
- .description(
564
- 'Read the local record of commands, notifications, and the question decisions harness hooks made. ' +
565
- 'Bounded and scoped to this project by default; never leaves this machine',
566
- )
567
- .option('-n, --limit <count>', 'how many records to show (default: 30)', (v: string) => Number(v))
568
- .option('--all', 'lift the default limit, up to a hard cap')
569
- .option('--since <when>', 'only records newer than this: 10m, 2h, 1d, or an ISO 8601 instant')
570
- .option('--level <level>', 'minimum severity: error | info | debug (error shows only failures)')
571
- .option('--event <name>', 'only this event; repeatable', (v: string, all: string[] = []) => [...all, v])
572
- .option('--run <id>', 'everything one command invocation did')
573
- .option('--request <id>', 'everything about one notification request')
574
- .option('--session <id>', 'only this harness session')
575
- .option('--project <id>', 'only this project')
576
- .option('--all-projects', 'do not scope to the project in this directory')
577
- .option('--grep <text>', 'only records containing this text')
578
- .option('--json', 'one JSON record per line on stdout')
579
- .option('--path', 'print the log file paths instead of the records')
580
- .option('--clear', 'delete the log files')
581
- .action((opts: Record<string, unknown>) => {
582
- const flags = { ...opts } as Parameters<typeof logsCommand>[1]
583
- if (Array.isArray(flags.event) && flags.event.length === 0) delete flags.event
584
- process.exit(logsCommand(deps, flags))
585
- })
586
-
587
- const config = program
588
- .command('config')
589
- .description('Show or change settings')
590
- .summary('Show or change settings')
591
- .helpGroup(GROUP.daily)
592
- config
593
- .command('show')
594
- .description('Show every setting, what it does, and where its value came from')
595
- .option('--explain', 'include advanced settings and the file each value came from')
596
- .option('--plain', 'the flat key = value form, even at a terminal')
597
- .option('--json', 'machine-readable output')
598
- .action((opts: { json?: boolean; explain?: boolean; plain?: boolean }) => {
599
- process.exit(configShowCommand(deps, opts))
600
- })
601
- config
602
- .command('explain <key>')
603
- .description('Explain one setting in full: what it does, what it accepts, what it is now')
604
- .option('--json', 'machine-readable output')
605
- .action((key: string, opts: { json?: boolean }) => {
606
- process.exit(configExplainCommand(deps, key, opts))
607
- })
608
- config
609
- .command('set <key> <value>')
610
- .description(
611
- 'Set a configuration value (choose a layer interactively; unattended defaults machine-global and requires --yes)',
612
- )
613
- .option('--project', 'write to the shared .notifai/config.toml instead')
614
- .option('--local', 'write a personal project preference on this machine (not in the repo)')
615
- .option('--session <id>', 'apply only to one session')
616
- .option('--yes', 'skip the confirmation gate')
617
- .action(
618
- async (
619
- key: string,
620
- value: string,
621
- opts: { project?: boolean; local?: boolean; session?: string; yes?: boolean },
622
- ) => {
623
- process.exit(await configSetCommand(deps, key, value, opts))
624
- },
625
- )
626
- config
627
- .command('unset <key>')
628
- .description(
629
- 'Remove a configuration value so the next layer or shipped default applies (choose a layer interactively; unattended defaults machine-global and requires --yes)',
630
- )
631
- .option('--project', 'remove from the shared .notifai/config.toml instead')
632
- .option('--local', 'remove a personal project preference stored on this machine')
633
- .option('--session <id>', 'remove from one session')
634
- .option('--yes', 'skip the confirmation gate')
635
- .action(
636
- async (
637
- key: string,
638
- opts: { project?: boolean; local?: boolean; session?: string; yes?: boolean },
639
- ) => {
640
- process.exit(await configUnsetCommand(deps, key, opts))
641
- },
642
- )
643
-
644
- await program.parseAsync(process.argv)
36
+ await buildProgram(deps).parseAsync(process.argv)