@raidiant/notifai 10.1.0 → 10.1.1

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 (97) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +3 -0
  3. package/dist/cli-bin.d.ts +21 -1
  4. package/dist/cli-bin.js +141 -10
  5. package/dist/cli-bin.js.map +1 -1
  6. package/dist/cli-update-contract.d.ts +7 -0
  7. package/dist/cli-update-contract.js +10 -0
  8. package/dist/cli-update-contract.js.map +1 -0
  9. package/dist/client.d.ts +6 -1
  10. package/dist/client.js +1 -0
  11. package/dist/client.js.map +1 -1
  12. package/dist/codex-wake.d.ts +2 -0
  13. package/dist/codex-wake.js +2 -1
  14. package/dist/codex-wake.js.map +1 -1
  15. package/dist/commands-auth.d.ts +15 -1
  16. package/dist/commands-auth.js +29 -11
  17. package/dist/commands-auth.js.map +1 -1
  18. package/dist/commands-core.d.ts +8 -1
  19. package/dist/commands-core.js +11 -4
  20. package/dist/commands-core.js.map +1 -1
  21. package/dist/commands-devices.d.ts +10 -1
  22. package/dist/commands-devices.js +17 -13
  23. package/dist/commands-devices.js.map +1 -1
  24. package/dist/commands-doctor.js +93 -49
  25. package/dist/commands-doctor.js.map +1 -1
  26. package/dist/commands-hooks.js +47 -10
  27. package/dist/commands-hooks.js.map +1 -1
  28. package/dist/commands-init.d.ts +16 -0
  29. package/dist/commands-init.js +245 -87
  30. package/dist/commands-init.js.map +1 -1
  31. package/dist/commands-send.d.ts +1 -1
  32. package/dist/commands-send.js +121 -35
  33. package/dist/commands-send.js.map +1 -1
  34. package/dist/commands-update.d.ts +10 -0
  35. package/dist/commands-update.js +141 -0
  36. package/dist/commands-update.js.map +1 -0
  37. package/dist/commands.d.ts +2 -1
  38. package/dist/commands.js +2 -1
  39. package/dist/commands.js.map +1 -1
  40. package/dist/hook-adapter.d.ts +2 -0
  41. package/dist/hook-adapter.js +12 -1
  42. package/dist/hook-adapter.js.map +1 -1
  43. package/dist/hooks.d.ts +43 -2
  44. package/dist/hooks.js +163 -21
  45. package/dist/hooks.js.map +1 -1
  46. package/dist/main-run.d.ts +1 -0
  47. package/dist/main-run.js +42 -0
  48. package/dist/main-run.js.map +1 -0
  49. package/dist/main.js +10 -31
  50. package/dist/main.js.map +1 -1
  51. package/dist/node-floor.d.ts +18 -0
  52. package/dist/node-floor.js +35 -0
  53. package/dist/node-floor.js.map +1 -0
  54. package/dist/program.d.ts +2 -1
  55. package/dist/program.js +22 -5
  56. package/dist/program.js.map +1 -1
  57. package/dist/question-settlement-process.d.ts +15 -0
  58. package/dist/question-settlement-process.js +35 -0
  59. package/dist/question-settlement-process.js.map +1 -0
  60. package/dist/readiness.d.ts +25 -1
  61. package/dist/readiness.js +32 -2
  62. package/dist/readiness.js.map +1 -1
  63. package/dist/setup-destinations.d.ts +23 -0
  64. package/dist/setup-destinations.js +44 -0
  65. package/dist/setup-destinations.js.map +1 -0
  66. package/package.json +2 -2
  67. package/src/cli-bin.test.ts +145 -7
  68. package/src/cli-bin.ts +176 -10
  69. package/src/cli-update-contract.ts +9 -0
  70. package/src/cli-update.test.ts +125 -0
  71. package/src/client.ts +7 -0
  72. package/src/codex-wake.ts +5 -1
  73. package/src/commands-auth.ts +44 -11
  74. package/src/commands-core.ts +18 -4
  75. package/src/commands-devices.ts +23 -16
  76. package/src/commands-doctor.ts +116 -55
  77. package/src/commands-hooks.ts +66 -16
  78. package/src/commands-init.ts +265 -88
  79. package/src/commands-send.ts +145 -39
  80. package/src/commands-update.ts +180 -0
  81. package/src/commands.test.ts +518 -49
  82. package/src/commands.ts +2 -0
  83. package/src/hook-adapter.ts +14 -0
  84. package/src/hooks.test.ts +275 -0
  85. package/src/hooks.ts +270 -18
  86. package/src/main-run.ts +45 -0
  87. package/src/main.ts +9 -33
  88. package/src/node-floor.test.ts +27 -0
  89. package/src/node-floor.ts +37 -0
  90. package/src/program.test.ts +35 -0
  91. package/src/program.ts +28 -4
  92. package/src/question-settlement-process.ts +47 -0
  93. package/src/readiness.ts +35 -2
  94. package/src/setup-destinations.test.ts +41 -0
  95. package/src/setup-destinations.ts +50 -0
  96. package/src/skill.test.ts +11 -0
  97. package/src/commands-devices.test.ts +0 -15
package/src/program.ts CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  authStatusCommand,
9
9
  capabilitiesCommand,
10
10
  closeCommand,
11
+ cliUpdateCommand,
11
12
  configExplainCommand,
12
13
  configSetCommand,
13
14
  configShowCommand,
@@ -42,6 +43,7 @@ import type { SkillScope } from './native-skills.js'
42
43
  import { GROUP, SEND_GROUP, helpConfiguration, rootHelpFooter } from './ui/help.js'
43
44
  import { readStdinWithTimeout } from './hook-input.js'
44
45
  import { argvFlagNames } from './logging.js'
46
+ import { QUESTION_SETTLEMENT_INPUT_ENV } from './question-settlement-process.js'
45
47
 
46
48
  /**
47
49
  * One source of truth for the version: the manifest npm actually published.
@@ -80,6 +82,7 @@ function commandPath(command: Command): string {
80
82
  const defaultRunners = {
81
83
  init: initCommand,
82
84
  doctor: doctorCommand,
85
+ update: cliUpdateCommand,
83
86
  login: loginCommand,
84
87
  logout: logoutCommand,
85
88
  authStatus: authStatusCommand,
@@ -261,6 +264,16 @@ export function buildProgram(deps: CommandDeps, options: BuildProgramOptions = {
261
264
  exit(await runners.doctor(deps, opts))
262
265
  })
263
266
 
267
+ program
268
+ .command('update')
269
+ .helpGroup(GROUP.start)
270
+ .summary('Update the Notifai command this shell uses')
271
+ .description('Update the effective global Notifai installation and keep Question Routing on it')
272
+ .option('--json', 'machine-readable installation and adapter result')
273
+ .action((opts: { json?: boolean }) => {
274
+ exit(runners.update(deps, opts))
275
+ })
276
+
264
277
  const project = program
265
278
  .command('project')
266
279
  .helpGroup(GROUP.daily)
@@ -500,10 +513,10 @@ export function buildProgram(deps: CommandDeps, options: BuildProgramOptions = {
500
513
  })
501
514
 
502
515
  program
503
- .command('status <request_id>')
516
+ .command('status <question_or_request_id>')
504
517
  .helpGroup(GROUP.agent)
505
- .summary('Show the evidence trail for a request')
506
- .description('Show the evidence trail for a notification request')
518
+ .summary('Show question state or request evidence')
519
+ .description('Show local question state and, once submitted, the notification request evidence trail')
507
520
  .option('--json', 'machine-readable output')
508
521
  .action(async (requestId: string, opts: { json?: boolean }) => {
509
522
  exit(await runners.status(deps, requestId, opts))
@@ -629,7 +642,18 @@ export function buildProgram(deps: CommandDeps, options: BuildProgramOptions = {
629
642
  .option('--harness <name>', 'internal harness output adapter')
630
643
  .action(async (event: string, opts: { harness?: string }) => {
631
644
  const harness = HOOK_INSTALLABLE_HARNESSES.find((candidate) => candidate === opts.harness)
632
- exit(await runners.hookRun(deps, event, () => readStdinWithTimeout(), harness))
645
+ const settlementInput = deps.env[QUESTION_SETTLEMENT_INPUT_ENV]
646
+ if (event === 'question-settlement') {
647
+ delete deps.env[QUESTION_SETTLEMENT_INPUT_ENV]
648
+ }
649
+ exit(await runners.hookRun(
650
+ deps,
651
+ event,
652
+ event === 'question-settlement' && settlementInput !== undefined
653
+ ? async () => settlementInput
654
+ : () => readStdinWithTimeout(),
655
+ harness,
656
+ ))
633
657
  })
634
658
 
635
659
  const hooks = program
@@ -0,0 +1,47 @@
1
+ import { spawn } from 'node:child_process'
2
+ import { fileURLToPath } from 'node:url'
3
+ import type { HookInstallableHarness } from './harnesses.js'
4
+ import type { HookEnvelope } from './hooks.js'
5
+
6
+ /** Private handoff from the short prompt hook to its detached question owner. */
7
+ export const QUESTION_SETTLEMENT_INPUT_ENV = 'NOTIFAI_INTERNAL_QUESTION_SETTLEMENT_INPUT'
8
+
9
+ export interface QuestionSettlementLaunch {
10
+ envelope: Pick<HookEnvelope, 'session_id' | 'cwd'>
11
+ harness: HookInstallableHarness
12
+ }
13
+
14
+ /**
15
+ * Launch the exact installed CLI build as a detached owner.
16
+ *
17
+ * UserPromptSubmit sits in front of the User's new turn, so it may only pay the
18
+ * process-spawn cost. The child owns submission and the complete answer window.
19
+ */
20
+ export function spawnQuestionSettlement(launch: QuestionSettlementLaunch): void {
21
+ const child = spawn(
22
+ process.execPath,
23
+ [
24
+ fileURLToPath(new URL('./main.js', import.meta.url)),
25
+ 'hook',
26
+ 'question-settlement',
27
+ '--owner',
28
+ 'notifai',
29
+ '--harness',
30
+ launch.harness,
31
+ ],
32
+ {
33
+ cwd: launch.envelope.cwd ?? process.cwd(),
34
+ detached: true,
35
+ env: {
36
+ ...process.env,
37
+ [QUESTION_SETTLEMENT_INPUT_ENV]: JSON.stringify(launch.envelope),
38
+ },
39
+ stdio: 'ignore',
40
+ windowsHide: true,
41
+ },
42
+ )
43
+ // Spawn failures are diagnosed by the next ordinary lifecycle hook, which
44
+ // still owns the durable registration. Never turn one into a prompt delay.
45
+ child.once('error', () => undefined)
46
+ child.unref()
47
+ }
package/src/readiness.ts CHANGED
@@ -80,15 +80,48 @@ export function firstBlocker(readiness: Readiness): ReadinessState | null {
80
80
  return readiness.states.find((s) => s.status === 'gap') ?? null
81
81
  }
82
82
 
83
+ /**
84
+ * Question Routing: what lets a question reach a phone when nobody is at the
85
+ * terminal. Hooks, their sub-states, and the setting that admits them.
86
+ *
87
+ * Separate from `isOptionalSetup` because these are also the states a human
88
+ * should not be handed as leftovers — "Optional, not set up" is a fair line
89
+ * about the agent skill and a confusing one about a session pointer.
90
+ */
91
+ export function isOptionalAutomation(id: string): boolean {
92
+ return id === 'hooks' || id.startsWith('hooks-') || id === 'question-routing-settings'
93
+ }
94
+
95
+ /**
96
+ * Automation layered on top of a product that already sends: Question Routing
97
+ * and the agent guidance skill.
98
+ *
99
+ * Real, and reported. `doctor` is the report and judges it strictly. Anything
100
+ * whose job is to get a first notification delivered treats it as a line to
101
+ * print, never a gate — a hook diagnostic or a duplicate skill install in
102
+ * front of the delivery proof means a setup that can already send never proves
103
+ * that it can. The one that fires most often, a turn that has not ended yet,
104
+ * cannot be closed by the agent standing inside that turn at all.
105
+ */
106
+ export function isOptionalSetup(id: string): boolean {
107
+ return id === 'skill' || isOptionalAutomation(id)
108
+ }
109
+
110
+ /** The first thing in the way that is not optional automation. */
111
+ export function firstRequiredBlocker(readiness: Readiness): ReadinessState | null {
112
+ return readiness.states.find((s) => s.status === 'gap' && !isOptionalSetup(s.id)) ?? null
113
+ }
114
+
83
115
  /**
84
116
  * Ready enough to be useful, which is not the same as every box ticked.
85
117
  *
86
118
  * Hooks and the agent skill are genuinely optional — `send` works without
87
119
  * them — so an install that declined both is finished, not half-done. Saying
88
- * otherwise trains people to ignore the summary line.
120
+ * otherwise trains people to ignore the summary line, and it is the summary
121
+ * line an agent branches on.
89
122
  */
90
123
  export function isReady(readiness: Readiness): boolean {
91
- return firstBlocker(readiness) === null
124
+ return firstRequiredBlocker(readiness) === null
92
125
  }
93
126
 
94
127
  const SEND_PREREQUISITES = new Set([
@@ -0,0 +1,41 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import {
3
+ companionPlatformLabel,
4
+ setupAccessUrl,
5
+ setupCompanionUrl,
6
+ supportPageUrl,
7
+ } from './setup-destinations.js'
8
+
9
+ describe('focused setup destinations', () => {
10
+ it('sends a hosted reader to the dashboard they can sign in to', () => {
11
+ expect(setupAccessUrl('https://api.notifai.sh')).toBe('https://app.notifai.sh/setup/access')
12
+ expect(setupCompanionUrl('https://notifai.fly.dev')).toBe(
13
+ 'https://app.notifai.sh/setup/companion',
14
+ )
15
+ })
16
+
17
+ it('keeps a self-host on its own origin', () => {
18
+ expect(setupAccessUrl('https://notify.example.com/')).toBe(
19
+ 'https://notify.example.com/setup/access',
20
+ )
21
+ })
22
+
23
+ it('carries the platform this terminal already asked about', () => {
24
+ expect(setupCompanionUrl('https://api.notifai.sh', 'iphone')).toBe(
25
+ 'https://app.notifai.sh/setup/companion?platform=iphone',
26
+ )
27
+ expect(setupAccessUrl('https://api.notifai.sh', 'android')).toBe(
28
+ 'https://app.notifai.sh/setup/access?platform=android',
29
+ )
30
+ })
31
+
32
+ it('keeps the omnibus help page separate from any setup errand', () => {
33
+ expect(supportPageUrl('https://api.notifai.sh')).toBe('https://app.notifai.sh/support')
34
+ expect(setupAccessUrl('https://api.notifai.sh')).not.toContain('/support')
35
+ })
36
+
37
+ it('names each platform the way a reader would', () => {
38
+ expect(companionPlatformLabel('iphone')).toBe('iPhone')
39
+ expect(companionPlatformLabel('android')).toBe('Android')
40
+ })
41
+ })
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Where a cross-surface setup errand is finished.
3
+ *
4
+ * Every handoff opens the destination for exactly one errand, carrying the
5
+ * platform when this terminal already asked for it. The omnibus help page is
6
+ * help: it covers access, two install routes, billing, refunds, deletion,
7
+ * privacy and terms, and its own next step is to go somewhere else. Sending
8
+ * someone there for a named gate makes them find it themselves.
9
+ *
10
+ * The server prints these same paths into `next_action`, which is the value
11
+ * this CLI prefers whenever it has one. These builders are the fallback for
12
+ * the paths where it does not, and they must stay spelled the same.
13
+ */
14
+
15
+ /** The two platforms that can receive a notification. Mac is not one. */
16
+ export const COMPANION_PLATFORMS = ['iphone', 'android'] as const
17
+ export type CompanionPlatform = (typeof COMPANION_PLATFORMS)[number]
18
+
19
+ export function companionPlatformLabel(platform: CompanionPlatform): string {
20
+ return platform === 'iphone' ? 'iPhone' : 'Android'
21
+ }
22
+
23
+ /**
24
+ * The dashboard a reader can sign in to, which is not always the API origin.
25
+ * Only the hosted deployment splits them; a self-host serves both from one.
26
+ */
27
+ function dashboardOrigin(baseUrl: string): string {
28
+ const normalized = baseUrl.replace(/\/+$/, '')
29
+ if (normalized === 'https://api.notifai.sh' || normalized === 'https://notifai.fly.dev') {
30
+ return 'https://app.notifai.sh'
31
+ }
32
+ return normalized
33
+ }
34
+
35
+ /** Getting this Account access to Notifai, and nothing else. */
36
+ export function setupAccessUrl(baseUrl: string, platform?: CompanionPlatform): string {
37
+ const base = `${dashboardOrigin(baseUrl)}/setup/access`
38
+ return platform === undefined ? base : `${base}?platform=${platform}`
39
+ }
40
+
41
+ /** Installing the Companion App on one named platform. */
42
+ export function setupCompanionUrl(baseUrl: string, platform?: CompanionPlatform): string {
43
+ const base = `${dashboardOrigin(baseUrl)}/setup/companion`
44
+ return platform === undefined ? base : `${base}?platform=${platform}`
45
+ }
46
+
47
+ /** General help: billing, policies, and everything setup is not. */
48
+ export function supportPageUrl(baseUrl: string): string {
49
+ return `${dashboardOrigin(baseUrl)}/support`
50
+ }
package/src/skill.test.ts CHANGED
@@ -278,6 +278,17 @@ describe('Notifai agent skill', () => {
278
278
  expect(ask).toMatch(/tell me here/i)
279
279
  })
280
280
 
281
+ it('keeps local registration distinct from submission and delivery evidence', () => {
282
+ const ask = section('## Ask a question')
283
+ expect(ask).toMatch(/`registered: true`[\s\S]{0,180}local/i)
284
+ expect(ask).toMatch(/not yet been submitted as a\s+Notification\s+Request/i)
285
+ expect(ask).toMatch(/no Provider Acceptance/i)
286
+ expect(ask).toContain('notifai status <question_id> --json')
287
+ expect(ask).toMatch(/local.*frozen.*live.*answered.*withdrawn.*retired/is)
288
+ expect(ask).toMatch(/never call a question\s+sent\s+or\s+delivered\s+from registration alone/i)
289
+ expect(ask).toMatch(/inspect or close the original[\s\S]{0,160}do not register/i)
290
+ })
291
+
281
292
  it('requires an acknowledgement before any resumed work', () => {
282
293
  const answers = section('## When the answer arrives')
283
294
  const acknowledge = answers.indexOf('notifai acknowledge')
@@ -1,15 +0,0 @@
1
- import { describe, expect, it } from 'vitest'
2
- import { supportPageUrl } from './commands-devices.js'
3
-
4
- describe('supportPageUrl', () => {
5
- it('routes hosted control-plane origins to the dashboard support surface', () => {
6
- expect(supportPageUrl('https://api.notifai.sh')).toBe('https://app.notifai.sh/support')
7
- expect(supportPageUrl('https://notifai.fly.dev/')).toBe('https://app.notifai.sh/support')
8
- })
9
-
10
- it('keeps a self-hosted deployment on its own support route', () => {
11
- expect(supportPageUrl('https://notifai.example.test/')).toBe(
12
- 'https://notifai.example.test/support',
13
- )
14
- })
15
- })