@raidiant/notifai 0.5.0 → 0.5.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.
@@ -0,0 +1,238 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { closeSync, constants, existsSync, openSync } from 'node:fs';
3
+ import path from 'node:path';
4
+ import { configHome } from './install-hooks.js';
5
+ import { hookContinuationRoute, } from './hooks.js';
6
+ /** Codex's per-thread writer lock directory, relative to `$CODEX_HOME`. */
7
+ export const CODEX_THREAD_LOCK_DIR = 'thread-writer-locks';
8
+ /**
9
+ * BSD `open(2)` lock flags. Node does not surface them in `fs.constants`, and
10
+ * they are the only way to take a non-blocking `flock` from Node without a
11
+ * native addon: the kernel takes the lock at open and drops it at close.
12
+ */
13
+ const O_EXLOCK = 0x20;
14
+ const O_NONBLOCK = 0x4;
15
+ /** Platforms whose `open(2)` implements `O_EXLOCK`. Everything else fails closed. */
16
+ const LOCK_PROBE_PLATFORMS = new Set(['darwin', 'freebsd', 'openbsd']);
17
+ /** Codex thread ids are UUIDs, and the lock file is named by the exact id. */
18
+ const THREAD_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
19
+ /**
20
+ * The one cross-process oracle for "who owns this Codex thread".
21
+ *
22
+ * Codex's thread store takes a non-blocking `flock(LOCK_EX)` on a zero-byte
23
+ * file per thread and holds it for as long as that process owns the thread —
24
+ * verified against both a hosted app-server thread sitting idle and an
25
+ * in-process `codex exec` run (2026-08-12). Because the kernel holds it, a
26
+ * crash, SIGKILL, or reboot releases it instantly, and the leftover file proves
27
+ * nothing: only the lock does. Codex fails closed itself with `-32600` when a
28
+ * second writer contends, but that is the backstop; this is the gate.
29
+ */
30
+ export function observeCodexThread(threadId, env, adapters) {
31
+ if (!THREAD_ID.test(threadId)) {
32
+ return { state: 'unknown', reason: 'the Codex session id is not a thread id' };
33
+ }
34
+ try {
35
+ return adapters.probeThreadWriter(codexThreadLockPath(threadId, env));
36
+ }
37
+ catch (err) {
38
+ return {
39
+ state: 'unknown',
40
+ reason: `Codex thread-writer lock probe failed: ${err instanceof Error ? err.message : String(err)}`,
41
+ };
42
+ }
43
+ }
44
+ export function codexThreadLockPath(threadId, env) {
45
+ return path.join(codexThreadLockDirectory(env), `${threadId}.lock`);
46
+ }
47
+ export function codexThreadLockDirectory(env) {
48
+ return path.join(configHome(env, 'CODEX_HOME', '.codex'), CODEX_THREAD_LOCK_DIR);
49
+ }
50
+ /**
51
+ * Whether a Codex thread whose Stop hook has already returned could still be
52
+ * cold-resumed, decided without taking any lock or spawning anything.
53
+ *
54
+ * Two things have to hold: this platform must implement the non-blocking
55
+ * `flock` the probe is built on, and `$CODEX_HOME` must actually have a
56
+ * thread-writer-lock directory — its absence is not evidence that a thread is
57
+ * unowned, so the gate fails closed and the answer waits for the next turn.
58
+ * Neither affects the ordinary path, where the hook's own stdout continues the
59
+ * held turn.
60
+ */
61
+ export function inspectCodexResume(env, options) {
62
+ const lockDirectory = codexThreadLockDirectory(env);
63
+ if (!LOCK_PROBE_PLATFORMS.has(options.platform)) {
64
+ return {
65
+ state: 'unavailable',
66
+ reason: `no non-blocking thread-writer lock probe exists on ${options.platform}`,
67
+ };
68
+ }
69
+ if (!options.directoryExists(lockDirectory)) {
70
+ return {
71
+ state: 'unavailable',
72
+ reason: `no thread-writer-lock directory at ${lockDirectory}, so no thread can be proven unowned`,
73
+ };
74
+ }
75
+ return { state: 'ready', lockDirectory };
76
+ }
77
+ /**
78
+ * Codex's answer-delivery route: the blocking Stop hook, then nothing else.
79
+ *
80
+ * The default is the hook continuation itself. While the Codex process that
81
+ * invoked this hook is alive it is reading this process's stdout, and
82
+ * `{"decision":"block"}` there creates a real new user turn — no launch
83
+ * ownership, no control plane, no probe required. That path must never depend
84
+ * on the lock probe: printing to a dead pipe cannot ghost-write anything, so
85
+ * an unreadable `$CODEX_HOME` is not a reason to withhold a continuation.
86
+ *
87
+ * Only when that process is gone does the answer need another last meter, and
88
+ * then exactly one is safe: a cold `codex exec resume` of a thread no live
89
+ * writer owns. Anything else — a live writer, an unprobeable platform, a thread
90
+ * id we cannot name — is journaled and replayed at the session's next Stop.
91
+ * That accepted gap is the honest floor of the Codex adapter: a session that
92
+ * went idle after its Stop returned, which Notifai did not launch, cannot be
93
+ * woken in place.
94
+ */
95
+ export function codexWakeRoute(options) {
96
+ const env = options.env ?? process.env;
97
+ const adapters = options.adapters ?? systemCodexWakeAdapters(env);
98
+ const continuation = hookContinuationRoute();
99
+ return {
100
+ kind: 'hook-continuation',
101
+ async deliver(event) {
102
+ if (adapters.sourceAlive(options.sourcePid))
103
+ return continuation.deliver(event);
104
+ // Probe immediately before the spawn, twice, and never trust the earlier
105
+ // answer: ownership is a kernel fact that can change between two syscalls,
106
+ // and resuming a thread someone else owns is the disqualifying failure.
107
+ const observed = observeCodexThread(options.threadId, env, adapters);
108
+ const held = holdForNextTurn(observed);
109
+ if (held !== null)
110
+ return held;
111
+ const confirmed = observeCodexThread(options.threadId, env, adapters);
112
+ const raced = holdForNextTurn(confirmed);
113
+ if (raced !== null)
114
+ return raced;
115
+ await adapters.resume(options.threadId, options.cwd, event.context);
116
+ return {
117
+ notes: ['cold-resumed the stopped Codex thread with its accepted answer'],
118
+ log: { route: 'cold-resume', stage: 'delivered' },
119
+ // The resume ran: the thread holds the answer, and no later hook of this
120
+ // session will report on a turn that started elsewhere.
121
+ acknowledgement: 'delivered',
122
+ };
123
+ },
124
+ };
125
+ }
126
+ /** The journal, with the exact reason the thread could not be resumed. */
127
+ function holdForNextTurn(observation) {
128
+ if (observation.state === 'stopped')
129
+ return null;
130
+ const reason = observation.state === 'live'
131
+ ? 'a live writer owns the Codex thread and this hook can no longer continue it'
132
+ : observation.reason;
133
+ return {
134
+ notes: [`holding the accepted answer for the next turn: ${reason}`],
135
+ log: { route: 'hold-for-next-turn', stage: 'queued', reason },
136
+ acknowledgement: 'held',
137
+ };
138
+ }
139
+ /**
140
+ * Take and release the writer lock in one open/close pair.
141
+ *
142
+ * The probe momentarily owns the lock when it is free, so it is held for
143
+ * microseconds and never across a spawn — a probe racing a legitimate resume
144
+ * must not be what makes that resume fail.
145
+ */
146
+ function probeThreadWriterLock(lockPath) {
147
+ if (!LOCK_PROBE_PLATFORMS.has(process.platform)) {
148
+ return {
149
+ state: 'unknown',
150
+ reason: `no non-blocking thread-writer lock probe exists on ${process.platform}`,
151
+ };
152
+ }
153
+ const directory = path.dirname(lockPath);
154
+ if (!existsSync(directory)) {
155
+ // No lock directory means this is not a Codex home that has ever opened a
156
+ // thread, so its silence is not evidence that nothing owns this one.
157
+ return { state: 'unknown', reason: `no Codex thread-writer lock directory at ${directory}` };
158
+ }
159
+ let handle;
160
+ try {
161
+ handle = openSync(lockPath, constants.O_RDONLY | O_EXLOCK | O_NONBLOCK);
162
+ }
163
+ catch (err) {
164
+ const code = err.code;
165
+ if (code === 'EAGAIN' || code === 'EWOULDBLOCK')
166
+ return { state: 'live' };
167
+ // Codex unlinks the lock file when its writer drops cleanly, so a missing
168
+ // file inside a real lock directory means the thread has no owner.
169
+ if (code === 'ENOENT')
170
+ return { state: 'stopped' };
171
+ return {
172
+ state: 'unknown',
173
+ reason: `Codex thread-writer lock probe failed: ${err instanceof Error ? err.message : String(err)}`,
174
+ };
175
+ }
176
+ closeSync(handle);
177
+ return { state: 'stopped' };
178
+ }
179
+ function runCodex(args, options) {
180
+ return new Promise((resolve, reject) => {
181
+ const child = spawn('codex', args, {
182
+ cwd: options.cwd,
183
+ env: options.env,
184
+ stdio: ['ignore', 'pipe', 'pipe'],
185
+ });
186
+ const stdout = [];
187
+ const stderr = [];
188
+ child.stdout?.on('data', (chunk) => stdout.push(Buffer.from(chunk)));
189
+ child.stderr?.on('data', (chunk) => stderr.push(Buffer.from(chunk)));
190
+ child.once('error', reject);
191
+ child.once('exit', (code, signal) => {
192
+ if (code === 0) {
193
+ resolve(Buffer.concat(stdout).toString());
194
+ return;
195
+ }
196
+ reject(new Error(`codex ${args[0] ?? ''} exited ${code === null ? `on ${String(signal)}` : String(code)}: ${Buffer.concat(stderr).toString().trim()}`));
197
+ });
198
+ });
199
+ }
200
+ /**
201
+ * The resumed process must not inherit the ended session's identity, or it
202
+ * reports itself as that thread to every hook it fires. `CODEX_HOME` is the one
203
+ * exception: it names the thread store the resume has to open.
204
+ */
205
+ function coldResumeEnvironment(env) {
206
+ const next = { ...env };
207
+ for (const key of Object.keys(next)) {
208
+ if (key.startsWith('CODEX_') && key !== 'CODEX_HOME')
209
+ delete next[key];
210
+ }
211
+ return next;
212
+ }
213
+ export function systemCodexWakeAdapters(env = process.env) {
214
+ return {
215
+ probeThreadWriter: probeThreadWriterLock,
216
+ sourceAlive(pid) {
217
+ if (!Number.isInteger(pid) || pid <= 1)
218
+ return false;
219
+ try {
220
+ process.kill(pid, 0);
221
+ return true;
222
+ }
223
+ catch (err) {
224
+ // Signalling a process we may not touch still proves it exists.
225
+ return err.code === 'EPERM';
226
+ }
227
+ },
228
+ async resume(threadId, cwd, context) {
229
+ if (!existsSync(cwd))
230
+ throw new Error(`Codex thread cwd no longer exists: ${cwd}`);
231
+ await runCodex(['exec', 'resume', threadId, context], {
232
+ cwd,
233
+ env: coldResumeEnvironment(env),
234
+ });
235
+ },
236
+ };
237
+ }
238
+ //# sourceMappingURL=codex-wake.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codex-wake.js","sourceRoot":"","sources":["../src/codex-wake.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AACpE,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EACL,qBAAqB,GAItB,MAAM,YAAY,CAAA;AAEnB,2EAA2E;AAC3E,MAAM,CAAC,MA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ACvB,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACpC,IAAI,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,GAAG,KAAK,YAAY;YAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAA;IACxE,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,MAAyB,OAAO,CAAC,GAAG;IAEpC,OAAO;QACL,iBAAiB,EAAE,qBAAqB;QACxC,WAAW,CAAC,GAAG;YACb,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;gBAAE,OAAO,KAAK,CAAA;YACpD,IAAI,CAAC;gBACH,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;gBACpB,OAAO,IAAI,CAAA;YACb,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,gEAAgE;gBAChE,OAAQ,GAA6B,CAAC,IAAI,KAAK,OAAO,CAAA;YACxD,CAAC;QACH,CAAC;QACD,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO;YACjC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;gBAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,GAAG,EAAE,CAAC,CAAA;YAClF,MAAM,QAAQ,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE;gBACpD,GAAG;gBACH,GAAG,EAAE,qBAAqB,CAAC,GAAG,CAAC;aAChC,CAAC,CAAA;QACJ,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -5,6 +5,8 @@ import { type Readiness } from './readiness.js';
5
5
  import type { Tone } from './ui/theme.js';
6
6
  import { type HookHarness } from './hooks.js';
7
7
  import { type Logger } from './logging.js';
8
+ import { type ClaudeWakeAdapters } from './claude-wake.js';
9
+ import { type CodexWakeAdapters } from './codex-wake.js';
8
10
  import { type SendFlags } from './send.js';
9
11
  import type { NativeSkills, SkillScope } from './native-skills.js';
10
12
  export interface CommandIo {
@@ -56,8 +58,12 @@ export interface CommandDeps {
56
58
  now?: () => number;
57
59
  /** Test seam for retry/backoff timing. */
58
60
  sleep?: (milliseconds: number) => Promise<void>;
59
- /** Test seam for the OS idle probe; production shells out to the platform. */
60
- idleSeconds?: () => number | null;
61
+ /** Test seams for Claude liveness, socket delivery, and cold resume. */
62
+ claudeWake?: ClaudeWakeAdapters;
63
+ claudeSourcePid?: number;
64
+ /** Test seams for the Codex thread-writer probe and cold resume. */
65
+ codexWake?: CodexWakeAdapters;
66
+ codexSourcePid?: number;
61
67
  /** Test seam and production adapter for the external native skills installer. */
62
68
  nativeSkills?: NativeSkills;
63
69
  /**
@@ -208,10 +214,9 @@ export declare function buildQuestions(flags: AskFlags, question: string | undef
208
214
  error: string;
209
215
  };
210
216
  /**
211
- * Registers a question for turn-end routing under the user's presence config.
212
- * Returns immediately so the agent can ask in prose and end its turn. Presence
213
- * does not block the shipped default; `require_idle = true` intentionally keeps
214
- * the question local while the user is active.
217
+ * Registers a question for turn-end routing. Returns immediately so the agent
218
+ * can ask in prose and end its turn; the terminal keeps the question to itself
219
+ * for `ask_grace_seconds` before it reaches any device.
215
220
  */
216
221
  export declare function askCommand(deps: CommandDeps, question: string | undefined, flags: AskFlags): number;
217
222
  /** Retire a question so a late answer is rejected rather than silently lost. */
@@ -284,11 +289,11 @@ export declare function parseSince(raw: string, now: number): number | null;
284
289
  */
285
290
  export declare function logsCommand(deps: CommandDeps, flags: LogsFlags): number;
286
291
  /**
287
- * Where `npx skills add` fetches the optional agent skill from. In skills CLI
288
- * 1.5.x, `owner/repo@name` selects a skill; a Git ref belongs after `#`.
289
- * Keep this immutable and public because the command is printed to users.
292
+ * Where `npx skills add` fetches the optional agent skill from, derived from
293
+ * this build's own version so the pin cannot drift from the release it names.
294
+ * Null when the build cannot establish its version; see `./release.js`.
290
295
  */
291
- export declare const SKILLS_SOURCE = "Raidiant-io/notifai#v0.4.0";
296
+ export declare const SKILLS_SOURCE: string | null;
292
297
  /** Derive a contract-valid project slug from a directory name. */
293
298
  export declare function projectSlugFrom(name: string): string;
294
299
  export interface InitFlags {