@raidiant/notifai 0.1.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 (54) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +76 -0
  3. package/dist/client.d.ts +40 -0
  4. package/dist/client.js +118 -0
  5. package/dist/client.js.map +1 -0
  6. package/dist/commands.d.ts +225 -0
  7. package/dist/commands.js +1855 -0
  8. package/dist/commands.js.map +1 -0
  9. package/dist/config.d.ts +138 -0
  10. package/dist/config.js +224 -0
  11. package/dist/config.js.map +1 -0
  12. package/dist/credentials.d.ts +31 -0
  13. package/dist/credentials.js +94 -0
  14. package/dist/credentials.js.map +1 -0
  15. package/dist/hooks.d.ts +250 -0
  16. package/dist/hooks.js +792 -0
  17. package/dist/hooks.js.map +1 -0
  18. package/dist/idle.d.ts +16 -0
  19. package/dist/idle.js +44 -0
  20. package/dist/idle.js.map +1 -0
  21. package/dist/install-hooks.d.ts +194 -0
  22. package/dist/install-hooks.js +579 -0
  23. package/dist/install-hooks.js.map +1 -0
  24. package/dist/main.d.ts +2 -0
  25. package/dist/main.js +259 -0
  26. package/dist/main.js.map +1 -0
  27. package/dist/opencode-plugin.d.ts +65 -0
  28. package/dist/opencode-plugin.js +181 -0
  29. package/dist/opencode-plugin.js.map +1 -0
  30. package/dist/readiness.d.ts +87 -0
  31. package/dist/readiness.js +40 -0
  32. package/dist/readiness.js.map +1 -0
  33. package/dist/send.d.ts +86 -0
  34. package/dist/send.js +202 -0
  35. package/dist/send.js.map +1 -0
  36. package/package.json +56 -0
  37. package/src/client.test.ts +83 -0
  38. package/src/client.ts +183 -0
  39. package/src/commands.test.ts +1199 -0
  40. package/src/commands.ts +2201 -0
  41. package/src/config.test.ts +243 -0
  42. package/src/config.ts +347 -0
  43. package/src/credentials.ts +119 -0
  44. package/src/hooks.test.ts +1030 -0
  45. package/src/hooks.ts +1099 -0
  46. package/src/idle.test.ts +32 -0
  47. package/src/idle.ts +41 -0
  48. package/src/install-hooks.test.ts +500 -0
  49. package/src/install-hooks.ts +708 -0
  50. package/src/main.ts +315 -0
  51. package/src/opencode-plugin.ts +203 -0
  52. package/src/readiness.ts +88 -0
  53. package/src/send.ts +272 -0
  54. package/tsconfig.json +10 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Rafael Vidaurre
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # notifai
2
+
3
+ Send native phone notifications from agents and local programs.
4
+
5
+ An agent working while you are away has no way to reach you, so it either
6
+ guesses or sits blocked in a terminal nobody is watching. `notifai` gives
7
+ it a way to tell you something finished, and a way to ask you a question
8
+ and get your answer back — as a banner on your phone, with buttons.
9
+
10
+ ```sh
11
+ npm install -g @raidiant/notifai
12
+ notifai init
13
+ ```
14
+
15
+ `init` walks the setup one step at a time and tells you the single next
16
+ thing to do. Run it again after each step; it works out what remains.
17
+
18
+ ## Telling you something happened
19
+
20
+ ```sh
21
+ notifai send --title "Deploy finished" --body "staging, 2m14s" --kind done
22
+ ```
23
+
24
+ Write for a lock screen. The title gets a couple of seconds of attention
25
+ and usually has to carry the whole message; assume the body may never be
26
+ read. Long-form content belongs in `--detail`, which never appears on the
27
+ banner and is shown in the companion app for when you sit down.
28
+
29
+ ## Asking you a question
30
+
31
+ ```sh
32
+ notifai ask "Deploy the migration to production?" --choice "Yes,No"
33
+ ```
34
+
35
+ The agent registers the question, ends its turn, and your answer comes
36
+ back on its next turn. On iPhone the choices are buttons on the banner
37
+ itself.
38
+
39
+ By default a question stays in your terminal while you are actually at
40
+ the keyboard, and only reaches your devices once you have stepped away —
41
+ a push you are sitting in front of is just noise. `require_idle = false`
42
+ turns that off if you would rather always be notified.
43
+
44
+ For a harness that cannot resume an idle agent turn, `notifai send
45
+ --reply` blocks and waits for the answer instead.
46
+
47
+ ## Agent harnesses
48
+
49
+ ```sh
50
+ notifai hooks install
51
+ ```
52
+
53
+ Wires question routing into Claude Code, Codex, Cursor or OpenCode. This
54
+ is what lets an agent's question reach your phone without the agent
55
+ having to cooperate — no question detection, no state in a context window
56
+ that compaction will eat.
57
+
58
+ ## Checking it works
59
+
60
+ ```sh
61
+ notifai doctor
62
+ ```
63
+
64
+ Reports every part of the setup and names where to start if something is
65
+ wrong. `--json` for machine-readable output.
66
+
67
+ ## Reference
68
+
69
+ `notifai <command> --help` is the exhaustive and current flag surface.
70
+ Everything useful is possible non-interactively, so an agent never
71
+ reaches a prompt and hangs.
72
+
73
+ Source, issues and the security policy:
74
+ <https://github.com/RafaelVidaurre/notifai>
75
+
76
+ Apache-2.0.
@@ -0,0 +1,40 @@
1
+ import type { BeginPairingResponse, CapabilityDocument, CreateMediaUploadRequestT, CreateMediaUploadResponse, EvidenceSnapshot, ListDevicesResponse, ListRepliesResponse, Platform, PollPairingResponse, SubmissionReceipt, SubmitNotificationRequestT } from '@raidiant/notifai-protocol';
2
+ export declare class ApiCallError extends Error {
3
+ status: number;
4
+ code: string;
5
+ nextAction: string | null;
6
+ details: unknown;
7
+ constructor(status: number, code: string, message: string, nextAction?: string | null, details?: unknown);
8
+ }
9
+ export declare class NetworkError extends Error {
10
+ }
11
+ export interface ApiClient {
12
+ beginPairing(body: {
13
+ machine_name: string;
14
+ credential_hash: string;
15
+ poll_verifier_hash: string;
16
+ }): Promise<BeginPairingResponse>;
17
+ pollPairing(pairingId: string, pollVerifier: string): Promise<PollPairingResponse>;
18
+ listDevices(): Promise<ListDevicesResponse>;
19
+ capabilities(platform?: Platform): Promise<CapabilityDocument>;
20
+ submit(body: SubmitNotificationRequestT, waitSeconds: number): Promise<SubmissionReceipt>;
21
+ evidence(requestId: string): Promise<EvidenceSnapshot>;
22
+ replies(requestId: string, options: {
23
+ waitSeconds: number;
24
+ afterSeq: number;
25
+ }): Promise<ListRepliesResponse>;
26
+ /** Retire a question so a late device answer is rejected rather than lost. */
27
+ closeReplies(requestId: string): Promise<void>;
28
+ createMediaUpload(body: CreateMediaUploadRequestT): Promise<CreateMediaUploadResponse>;
29
+ uploadMedia(grant: CreateMediaUploadResponse, bytes: Uint8Array): Promise<void>;
30
+ health(): Promise<boolean>;
31
+ }
32
+ export interface ClientOptions {
33
+ /**
34
+ * Ceiling for a single request, on top of any long poll the server has been
35
+ * asked to hold. Callers running inside a harness hook shrink this so their
36
+ * whole network path stays inside the budget the harness allows them.
37
+ */
38
+ timeoutMs?: number;
39
+ }
40
+ export declare function createClient(baseUrl: string, bearer: string | null, options?: ClientOptions): ApiClient;
package/dist/client.js ADDED
@@ -0,0 +1,118 @@
1
+ export class ApiCallError extends Error {
2
+ status;
3
+ code;
4
+ nextAction;
5
+ details;
6
+ constructor(status, code, message, nextAction = null, details = null) {
7
+ super(message);
8
+ this.status = status;
9
+ this.code = code;
10
+ this.nextAction = nextAction;
11
+ this.details = details;
12
+ }
13
+ }
14
+ export class NetworkError extends Error {
15
+ }
16
+ /**
17
+ * A deadline that fired reads as an abort, which says nothing useful on its
18
+ * own. Naming the timeout is what lets someone tell a hung server apart from a
19
+ * refused connection.
20
+ */
21
+ function networkFailure(err, root, limitMs) {
22
+ const name = err instanceof Error ? err.name : '';
23
+ if (name === 'TimeoutError' || name === 'AbortError') {
24
+ return new NetworkError(`${root} did not respond within ${Math.round(limitMs / 1000)}s`);
25
+ }
26
+ return new NetworkError(`Could not reach ${root}: ${String(err)}`);
27
+ }
28
+ /** Generous enough for a slow link, short enough that nothing hangs for ever. */
29
+ const DEFAULT_TIMEOUT_MS = 20_000;
30
+ export function createClient(baseUrl, bearer, options = {}) {
31
+ const root = baseUrl.replace(/\/$/, '');
32
+ const budgetMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
33
+ async function call(method, apiPath, body,
34
+ /** Seconds the server was asked to hold the connection open. */
35
+ serverWaitSeconds = 0) {
36
+ // Without this, a server that accepts the connection and then never answers
37
+ // hangs until the harness kills the whole hook — and the reply-poll deadline
38
+ // cannot interrupt an individual fetch. The signal covers the
39
+ // body read too, not just the response headers.
40
+ const limitMs = budgetMs + serverWaitSeconds * 1000;
41
+ const signal = AbortSignal.timeout(limitMs);
42
+ let response;
43
+ try {
44
+ response = await fetch(`${root}${apiPath}`, {
45
+ method,
46
+ headers: {
47
+ ...(body !== undefined ? { 'content-type': 'application/json' } : {}),
48
+ ...(bearer ? { authorization: bearer } : {}),
49
+ },
50
+ signal,
51
+ ...(body !== undefined ? { body: JSON.stringify(body) } : {}),
52
+ });
53
+ }
54
+ catch (err) {
55
+ throw networkFailure(err, root, limitMs);
56
+ }
57
+ if (!response.ok) {
58
+ let parsed = null;
59
+ try {
60
+ parsed = (await response.json());
61
+ }
62
+ catch {
63
+ // non-JSON body
64
+ }
65
+ throw new ApiCallError(response.status, parsed?.error.code ?? 'internal_error', parsed?.error.message ?? `Request failed with status ${response.status}`, parsed?.error.next_action ?? null, parsed?.error.details ?? null);
66
+ }
67
+ if (response.status === 204)
68
+ return undefined;
69
+ try {
70
+ return (await response.json());
71
+ }
72
+ catch (err) {
73
+ // A truncated or abandoned body is a transport failure, not a protocol
74
+ // one: it must be retryable like any other, not surface as a raw abort.
75
+ throw networkFailure(err, root, limitMs);
76
+ }
77
+ }
78
+ return {
79
+ beginPairing: (body) => call('POST', '/api/v1/pairings', body),
80
+ pollPairing: (pairingId, pollVerifier) => call('POST', `/api/v1/pairings/${pairingId}/poll`, { poll_verifier: pollVerifier }),
81
+ listDevices: () => call('GET', '/api/v1/devices'),
82
+ capabilities: (platform = 'ios') => call('GET', `/api/v1/capabilities/${platform}`),
83
+ submit: (body, waitSeconds) => call('POST', `/api/v1/notifications?wait_seconds=${waitSeconds}`, body, waitSeconds),
84
+ evidence: (requestId) => call('GET', `/api/v1/notifications/${requestId}`),
85
+ replies: (requestId, { waitSeconds, afterSeq }) => call('GET', `/api/v1/notifications/${encodeURIComponent(requestId)}/replies?wait_seconds=${waitSeconds}&after_seq=${afterSeq}`, undefined, waitSeconds),
86
+ closeReplies: (requestId) => call('POST', `/api/v1/notifications/${encodeURIComponent(requestId)}/replies/close`),
87
+ createMediaUpload: (body) => call('POST', '/api/v1/media', body),
88
+ uploadMedia: async (grant, bytes) => {
89
+ let response;
90
+ try {
91
+ response = await fetch(grant.upload_url, {
92
+ method: 'PUT',
93
+ headers: grant.upload_headers,
94
+ body: bytes,
95
+ // Media can be large, so this gets its own allowance rather than the
96
+ // per-request budget — but still a finite one.
97
+ signal: AbortSignal.timeout(Math.max(budgetMs, 60_000)),
98
+ });
99
+ }
100
+ catch (err) {
101
+ throw new NetworkError(`Upload failed: ${String(err)}`);
102
+ }
103
+ if (!response.ok) {
104
+ throw new NetworkError(`Upload rejected with status ${response.status}`);
105
+ }
106
+ },
107
+ health: async () => {
108
+ try {
109
+ await call('GET', '/healthz');
110
+ return true;
111
+ }
112
+ catch {
113
+ return false;
114
+ }
115
+ },
116
+ };
117
+ }
118
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAeA,MAAM,OAAO,YAAa,SAAQ,KAAK;IAE5B;IACA;IAEA;IACA;IALT,YACS,MAAc,EACd,IAAY,EACnB,OAAe,EACR,aAA4B,IAAI,EAChC,UAAmB,IAAI;QAE9B,KAAK,CAAC,OAAO,CAAC,CAAA;QANP,WAAM,GAAN,MAAM,CAAQ;QACd,SAAI,GAAJ,IAAI,CAAQ;QAEZ,eAAU,GAAV,UAAU,CAAsB;QAChC,YAAO,GAAP,OAAO,CAAgB;IAGhC,CAAC;CACF;AAED,MAAM,OAAO,YAAa,SAAQ,KAAK;CAAG;AAE1C;;;;GAIG;AACH,SAAS,cAAc,CAAC,GAAY,EAAE,IAAY,EAAE,OAAe;IACjE,MAAM,IAAI,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAA;IACjD,IAAI,IAAI,KAAK,cAAc,IAAI,IAAI,KAAK,YAAY,EAAE,CAAC;QACrD,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W,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;iBACxD,CAAC,CAAA;YACJ,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,MAAM,IAAI,YAAY,CAAC,kBAAkB,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;YACzD,CAAC;YACD,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,MAAM,IAAI,YAAY,CAAC,+BAA+B,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;YAC1E,CAAC;QACH,CAAC;QACD,MAAM,EAAE,KAAK,IAAI,EAAE;YACjB,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;gBAC7B,OAAO,IAAI,CAAA;YACb,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,KAAK,CAAA;YACd,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,225 @@
1
+ import { type ListRepliesResponse, type Platform, type ReplyView } from '@raidiant/notifai-protocol';
2
+ import { type ApiClient, type ClientOptions } from './client.js';
3
+ import type { CredentialStore } from './credentials.js';
4
+ import { type Readiness } from './readiness.js';
5
+ import { type SendFlags } from './send.js';
6
+ export interface CommandIo {
7
+ out(line: string): void;
8
+ err(line: string): void;
9
+ /** Interactive confirmation; resolves `fallback` (default false) when not interactive. */
10
+ confirm(question: string, fallback?: boolean): Promise<boolean>;
11
+ openUrl(url: string): void;
12
+ /**
13
+ * True only when a human is demonstrably driving a terminal. Everything below
14
+ * is optional sugar that MUST only be called behind this flag: an agent that
15
+ * reaches an interactive prompt does not error, it hangs — the prompt
16
+ * libraries wait on stdin for ever — so the gate is bypass, not handling.
17
+ * Test fakes leave all of this undefined and exercise the plain paths.
18
+ */
19
+ interactive?: boolean;
20
+ select?(message: string, options: {
21
+ value: string;
22
+ label: string;
23
+ hint?: string;
24
+ }[]): Promise<string | null>;
25
+ intro?(title: string): Promise<void>;
26
+ outro?(message: string): Promise<void>;
27
+ note?(message: string, title?: string): Promise<void>;
28
+ spinner?(message: string): Promise<CommandSpinner | null>;
29
+ check?(ok: boolean, message: string): Promise<void>;
30
+ }
31
+ export interface CommandSpinner {
32
+ message(message: string): void;
33
+ stop(message: string): void;
34
+ error(message: string): void;
35
+ }
36
+ export interface CommandDeps {
37
+ io: CommandIo;
38
+ store: CredentialStore;
39
+ env: NodeJS.ProcessEnv;
40
+ cwd: string;
41
+ /** Test seam; production uses fetch against base_url. */
42
+ clientFactory?: (baseUrl: string, bearer: string | null, options?: ClientOptions) => ApiClient;
43
+ /** Test seam for bounded polling without wall-clock sleeps. */
44
+ now?: () => number;
45
+ /** Test seam for retry/backoff timing. */
46
+ sleep?: (milliseconds: number) => Promise<void>;
47
+ /** Test seam for the OS idle probe; production shells out to the platform. */
48
+ idleSeconds?: () => number | null;
49
+ }
50
+ export declare const EXIT: {
51
+ readonly ok: 0;
52
+ readonly failed: 1;
53
+ readonly usage: 2;
54
+ readonly noReply: 3;
55
+ readonly auth: 4;
56
+ readonly network: 5;
57
+ };
58
+ export declare function loginCommand(deps: CommandDeps, flags: {
59
+ name?: string;
60
+ baseUrl?: string;
61
+ open?: boolean;
62
+ }): Promise<number>;
63
+ export declare function logoutCommand(deps: CommandDeps): number;
64
+ export declare function authStatusCommand(deps: CommandDeps, flags: {
65
+ json?: boolean;
66
+ }): number;
67
+ export declare function devicesCommand(deps: CommandDeps, flags: {
68
+ json?: boolean;
69
+ }): Promise<number>;
70
+ export declare function capabilitiesCommand(deps: CommandDeps, flags: {
71
+ json?: boolean;
72
+ platform?: Platform;
73
+ }): Promise<number>;
74
+ export declare function sendCommand(deps: CommandDeps, flags: SendFlags & {
75
+ json?: boolean;
76
+ wait?: number;
77
+ noWait?: boolean;
78
+ replyTimeout?: number;
79
+ noBlock?: boolean;
80
+ idempotencyKey?: string;
81
+ baseUrl?: string;
82
+ }): Promise<number>;
83
+ export declare function repliesCommand(deps: CommandDeps, requestId: string, flags: {
84
+ wait?: number;
85
+ after?: number;
86
+ json?: boolean;
87
+ }): Promise<number>;
88
+ interface ReplyWaitOptions {
89
+ timeoutSeconds: number;
90
+ afterSeq: number;
91
+ now?: (() => number) | undefined;
92
+ sleep?: ((milliseconds: number) => Promise<void>) | undefined;
93
+ }
94
+ interface ReplyWaitResult {
95
+ response: ListRepliesResponse;
96
+ timedOut: boolean;
97
+ /**
98
+ * The wait ended while polls were failing, so silence is unproven: the user
99
+ * may well have answered and we could not see it.
100
+ */
101
+ degraded: boolean;
102
+ }
103
+ /** Loop over server-capped long polls until a reply arrives or the caller's deadline passes. */
104
+ export declare function waitForReply(client: ApiClient, requestId: string, options: ReplyWaitOptions): Promise<ReplyWaitResult>;
105
+ /**
106
+ * The other half of first-reply-wins.
107
+ *
108
+ * A blocking send returns the first non-empty batch and acts on it, so a later
109
+ * answer that disagrees is silently ignored. That is the right default — an
110
+ * agent wants one answer, not a quorum — but silently is the wrong way to do
111
+ * it. The server now retires the question on the other devices the moment one
112
+ * answers, which makes this rare; it is still reachable, because a device can
113
+ * answer between the first reply landing and its retirement arriving.
114
+ *
115
+ * Ordered by seq, so `replies[0]` is the one that won.
116
+ */
117
+ export declare function contradictingAnswer(replies: ReplyView[]): string | null;
118
+ export declare function statusCommand(deps: CommandDeps, requestId: string, flags: {
119
+ json?: boolean;
120
+ }): Promise<number>;
121
+ export declare const HOOK_EVENTS: readonly ["user-prompt-submit", "stop", "session-end"];
122
+ export type HookEvent = (typeof HOOK_EVENTS)[number];
123
+ /**
124
+ * Runs one harness hook. Contract with every harness: hook JSON arrives on
125
+ * stdin, the decision (if any) goes to stdout, diagnostics go to stderr, and
126
+ * exit 0 with no stdout means "no decision — carry on as normal".
127
+ *
128
+ * Every failure path in here must reach that no-decision state. A hook that
129
+ * throws, or that blocks past the harness's timeout, degrades the agent for a
130
+ * feature the user only asked to make it more convenient.
131
+ */
132
+ export declare function hookRunCommand(deps: CommandDeps, event: string, readStdin: () => Promise<string>, harness?: 'cursor'): Promise<number>;
133
+ /**
134
+ * What went wrong, in terms of what to do about it.
135
+ *
136
+ * On 2026-08-03 a contract change shipped without the server deploy that goes
137
+ * with it. The CLI stamped `lifecycle` on every question draft, the deployed
138
+ * server rejected the unknown field, and escalation stopped working entirely —
139
+ * announced as "hook failed, deferring to the terminal", which reads like a
140
+ * flaky network. The information needed to diagnose it in one second was
141
+ * already in hand: a 422 whose details name the offending path. It was being
142
+ * thrown away by `String(err)`.
143
+ *
144
+ * A hook still exits 0 whatever this says. Handing the terminal back is always
145
+ * right; the only question is whether the user is told anything they can use.
146
+ */
147
+ export declare function describeHookFailure(err: unknown): string[];
148
+ export interface AskFlags {
149
+ choice?: string | string[];
150
+ session?: string;
151
+ }
152
+ /**
153
+ * Registers a question for turn-end routing under the user's presence config.
154
+ * Returns immediately so the agent can ask in prose and end its turn. With the
155
+ * default presence gate, recent keyboard or mouse activity keeps it local;
156
+ * `require_idle = false` intentionally permits a push while the user is active.
157
+ */
158
+ export declare function askCommand(deps: CommandDeps, question: string, flags: AskFlags): number;
159
+ /** Retire a question so a late answer is rejected rather than silently lost. */
160
+ export declare function closeCommand(deps: CommandDeps, requestId: string): Promise<number>;
161
+ export interface HooksInstallFlags {
162
+ harness?: string;
163
+ global?: boolean;
164
+ /** Test seam; production resolves the running CLI. */
165
+ execPath?: string;
166
+ scriptPath?: string;
167
+ }
168
+ export declare function hooksInstallCommand(deps: CommandDeps, flags: HooksInstallFlags): number;
169
+ export declare function hooksUninstallCommand(deps: CommandDeps, flags: HooksInstallFlags): number;
170
+ export declare function configShowCommand(deps: CommandDeps, flags: {
171
+ json?: boolean;
172
+ explain?: boolean;
173
+ }): number;
174
+ export declare function configSetCommand(deps: CommandDeps, key: string, rawValue: string, flags: {
175
+ project?: boolean;
176
+ local?: boolean;
177
+ session?: string;
178
+ yes?: boolean;
179
+ }): Promise<number>;
180
+ /** Derive a contract-valid project slug from a directory name. */
181
+ export declare function projectSlugFrom(name: string): string;
182
+ export interface InitFlags {
183
+ projectId?: string;
184
+ /**
185
+ * Install the agent guidance skill. Tri-state on purpose:
186
+ * true installs, false skips silently, and undefined means "offer it when a
187
+ * human is present, do nothing when one is not" — an unattended run must
188
+ * never spawn npx against the network by default.
189
+ */
190
+ skills?: boolean;
191
+ /** Same tri-state, for the harness hooks. */
192
+ hooks?: boolean;
193
+ }
194
+ /**
195
+ * Setup as one step at a time.
196
+ *
197
+ * The old version ran five steps in a fixed order and ended with a list of
198
+ * everything still outstanding. That is a report, and a report is the wrong
199
+ * output here: someone handed five things to do does none of them, and the
200
+ * order was the script's rather than the dependency graph's — it offered to
201
+ * install hooks after a sign-in that had just failed.
202
+ *
203
+ * So this closes what it can, then surfaces exactly one thing, the first that
204
+ * stands in the way. Re-running advances by one. Idempotence stops being a
205
+ * property to preserve and becomes the mechanism: every decision is derived
206
+ * from observed state, so a partial run, a second project, a fresh worktree
207
+ * and a revoked credential are the same code path arriving at different
208
+ * states rather than four branches to enumerate.
209
+ */
210
+ export declare function initCommand(deps: CommandDeps, flags: InitFlags): Promise<number>;
211
+ /**
212
+ * Read the whole setup once, in dependency order.
213
+ *
214
+ * Descent stops where a prerequisite is missing: without a credential there is
215
+ * nothing to ask the server with, and without a reachable server a contract
216
+ * mismatch is unknowable rather than absent. Those downstream states report
217
+ * `unknown`, which is the honest answer and keeps a network outage from
218
+ * looking like a broken install.
219
+ */
220
+ export declare function assessReadiness(deps: CommandDeps): Promise<Readiness>;
221
+ export declare function doctorCommand(deps: CommandDeps, flags: {
222
+ json?: boolean;
223
+ }): Promise<number>;
224
+ export declare function realIo(env?: NodeJS.ProcessEnv): CommandIo;
225
+ export {};