@raidiant/notifai 5.0.0 → 7.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.
- package/CHANGELOG.md +51 -0
- package/README.md +2 -2
- package/dist/atomic-file.js +13 -0
- package/dist/atomic-file.js.map +1 -1
- package/dist/client.d.ts +8 -3
- package/dist/client.js +24 -3
- package/dist/client.js.map +1 -1
- package/dist/commands-auth.d.ts +14 -0
- package/dist/commands-auth.js +154 -0
- package/dist/commands-auth.js.map +1 -0
- package/dist/commands-config.d.ts +31 -0
- package/dist/commands-config.js +246 -0
- package/dist/commands-config.js.map +1 -0
- package/dist/commands-core.d.ts +102 -0
- package/dist/commands-core.js +135 -0
- package/dist/commands-core.js.map +1 -0
- package/dist/commands-devices.d.ts +31 -0
- package/dist/commands-devices.js +124 -0
- package/dist/commands-devices.js.map +1 -0
- package/dist/commands-doctor.d.ts +24 -0
- package/dist/commands-doctor.js +1011 -0
- package/dist/commands-doctor.js.map +1 -0
- package/dist/commands-harness-context.d.ts +65 -0
- package/dist/commands-harness-context.js +97 -0
- package/dist/commands-harness-context.js.map +1 -0
- package/dist/commands-hook-shape.d.ts +17 -0
- package/dist/commands-hook-shape.js +37 -0
- package/dist/commands-hook-shape.js.map +1 -0
- package/dist/commands-hooks.d.ts +115 -0
- package/dist/commands-hooks.js +1225 -0
- package/dist/commands-hooks.js.map +1 -0
- package/dist/commands-init.d.ts +35 -0
- package/dist/commands-init.js +580 -0
- package/dist/commands-init.js.map +1 -0
- package/dist/commands-io.d.ts +2 -0
- package/dist/commands-io.js +110 -0
- package/dist/commands-io.js.map +1 -0
- package/dist/commands-logs.d.ts +30 -0
- package/dist/commands-logs.js +201 -0
- package/dist/commands-logs.js.map +1 -0
- package/dist/commands-send-support.d.ts +44 -0
- package/dist/commands-send-support.js +183 -0
- package/dist/commands-send-support.js.map +1 -0
- package/dist/commands-send.d.ts +33 -0
- package/dist/commands-send.js +519 -0
- package/dist/commands-send.js.map +1 -0
- package/dist/commands-setup-proof.d.ts +15 -0
- package/dist/commands-setup-proof.js +53 -0
- package/dist/commands-setup-proof.js.map +1 -0
- package/dist/commands-skill.d.ts +10 -0
- package/dist/commands-skill.js +71 -0
- package/dist/commands-skill.js.map +1 -0
- package/dist/commands.d.ts +12 -387
- package/dist/commands.js +12 -4536
- package/dist/commands.js.map +1 -1
- package/dist/config-schema.js +1 -1
- package/dist/config-schema.js.map +1 -1
- package/dist/config.d.ts +4 -4
- package/dist/config.js +6 -4
- package/dist/config.js.map +1 -1
- package/dist/credentials.js +13 -3
- package/dist/credentials.js.map +1 -1
- package/dist/generated-session-label.d.ts +2 -0
- package/dist/generated-session-label.js +152 -0
- package/dist/generated-session-label.js.map +1 -0
- package/dist/hooks.d.ts +2 -2
- package/dist/hooks.js +127 -99
- package/dist/hooks.js.map +1 -1
- package/dist/interactive.js +4 -4
- package/dist/interactive.js.map +1 -1
- package/dist/invocation-context.d.ts +3 -0
- package/dist/invocation-context.js +23 -6
- package/dist/invocation-context.js.map +1 -1
- package/dist/logging.js +1 -0
- package/dist/logging.js.map +1 -1
- package/dist/main.js +3 -3
- package/dist/main.js.map +1 -1
- package/dist/opencode-plugin.js +18 -3
- package/dist/opencode-plugin.js.map +1 -1
- package/dist/readiness.d.ts +3 -1
- package/dist/readiness.js.map +1 -1
- package/dist/session-labels.d.ts +30 -0
- package/dist/session-labels.js +278 -0
- package/dist/session-labels.js.map +1 -0
- package/package.json +2 -2
- package/src/atomic-file.ts +12 -0
- package/src/client.test.ts +90 -1
- package/src/client.ts +35 -2
- package/src/commands-auth.ts +174 -0
- package/src/commands-config.ts +307 -0
- package/src/commands-core.ts +240 -0
- package/src/commands-devices.ts +150 -0
- package/src/commands-doctor.ts +1209 -0
- package/src/commands-harness-context.ts +134 -0
- package/src/commands-hook-shape.ts +53 -0
- package/src/commands-hooks.ts +1586 -0
- package/src/commands-init.ts +721 -0
- package/src/commands-io.ts +108 -0
- package/src/commands-logs.ts +243 -0
- package/src/commands-send-support.ts +227 -0
- package/src/commands-send.ts +623 -0
- package/src/commands-setup-proof.ts +71 -0
- package/src/commands-skill.ts +84 -0
- package/src/commands.test.ts +567 -42
- package/src/commands.ts +58 -5614
- package/src/config-schema.ts +1 -1
- package/src/config.test.ts +9 -0
- package/src/config.ts +10 -5
- package/src/credentials.test.ts +25 -1
- package/src/credentials.ts +13 -3
- package/src/generated-session-label.ts +155 -0
- package/src/hooks.test.ts +355 -16
- package/src/hooks.ts +145 -97
- package/src/install-hooks.test.ts +84 -1
- package/src/interactive.test.ts +19 -1
- package/src/interactive.ts +4 -4
- package/src/invocation-context.test.ts +115 -16
- package/src/invocation-context.ts +32 -11
- package/src/logging.test.ts +15 -2
- package/src/logging.ts +1 -0
- package/src/main.ts +9 -3
- package/src/opencode-plugin.ts +18 -3
- package/src/readiness.ts +3 -1
- package/src/session-labels.test.ts +303 -0
- package/src/session-labels.ts +360 -0
- package/src/skill.test.ts +13 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { readLiveProjectSessionPointers } from './hooks.js'
|
|
2
|
+
import { type Harness } from './install-hooks.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Exact evidence that this shell command is running inside one supported
|
|
6
|
+
* harness. Configuration-directory variables are deliberately absent: they
|
|
7
|
+
* describe where a tool stores files, not which tool owns the current shell.
|
|
8
|
+
* OpenCode's generated plugin supplies the Notifai-owned marker because its
|
|
9
|
+
* plugin API exposes session identity but the ordinary environment does not.
|
|
10
|
+
*/
|
|
11
|
+
export interface ActiveHarnessSession {
|
|
12
|
+
harness: Harness
|
|
13
|
+
label: string
|
|
14
|
+
sessionId?: string
|
|
15
|
+
/** Trusted human title published by this harness's managed adapter. */
|
|
16
|
+
sessionLabel?: string
|
|
17
|
+
/** The harness has only a temporary placeholder title so far. */
|
|
18
|
+
sessionLabelPending?: boolean
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Every harness marker present in this environment, in declared order.
|
|
23
|
+
*
|
|
24
|
+
* Order here is a last resort, not an answer. A harness exports its markers
|
|
25
|
+
* into every process it starts, so a nested harness inherits its parent's
|
|
26
|
+
* markers alongside its own and the environment alone cannot say which of them
|
|
27
|
+
* owns this shell; `resolveActiveHarness` settles that with live evidence.
|
|
28
|
+
*/
|
|
29
|
+
function harnessEnvCandidates(env: NodeJS.ProcessEnv): ActiveHarnessSession[] {
|
|
30
|
+
const candidates: ActiveHarnessSession[] = []
|
|
31
|
+
if (env['NOTIFAI_ACTIVE_HARNESS'] === 'opencode') {
|
|
32
|
+
const sessionId = env['NOTIFAI_ACTIVE_SESSION_ID']
|
|
33
|
+
const sessionLabel = env['NOTIFAI_ACTIVE_SESSION_LABEL']
|
|
34
|
+
const sessionLabelPending = env['NOTIFAI_ACTIVE_SESSION_LABEL_PENDING'] === '1'
|
|
35
|
+
candidates.push({
|
|
36
|
+
harness: 'opencode',
|
|
37
|
+
label: 'OpenCode',
|
|
38
|
+
...(sessionId === undefined || sessionId === '' ? {} : { sessionId }),
|
|
39
|
+
...(sessionLabel === undefined || sessionLabel === '' ? {} : { sessionLabel }),
|
|
40
|
+
...(sessionLabelPending ? { sessionLabelPending: true } : {}),
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
if (env['CLAUDECODE'] === '1') {
|
|
44
|
+
const sessionId = env['CLAUDE_CODE_SESSION_ID']
|
|
45
|
+
candidates.push({
|
|
46
|
+
harness: 'claude-code',
|
|
47
|
+
label: 'Claude Code',
|
|
48
|
+
...(sessionId === undefined || sessionId === '' ? {} : { sessionId }),
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
const codexSession = env['CODEX_THREAD_ID']
|
|
52
|
+
if (codexSession !== undefined && codexSession !== '') {
|
|
53
|
+
candidates.push({ harness: 'codex', label: 'Codex', sessionId: codexSession })
|
|
54
|
+
}
|
|
55
|
+
if ((env['CURSOR_AGENT'] ?? '') !== '') candidates.push({ harness: 'cursor', label: 'Cursor' })
|
|
56
|
+
return candidates
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface ActiveHarnessResolution {
|
|
60
|
+
active: ActiveHarnessSession | null
|
|
61
|
+
/**
|
|
62
|
+
* Markers of harnesses that could equally own this shell, present only when
|
|
63
|
+
* nothing here has fired yet and declared order had to pick. Whatever is
|
|
64
|
+
* reported then has to hold for every one of them.
|
|
65
|
+
*/
|
|
66
|
+
contested: ActiveHarnessSession[]
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Which harness session owns this shell, when several claim to.
|
|
71
|
+
*
|
|
72
|
+
* Nesting is ordinary: an orchestrator running inside Claude Code starts a
|
|
73
|
+
* Codex session, and that Codex process inherits `CLAUDECODE` and
|
|
74
|
+
* `CLAUDE_CODE_SESSION_ID` on top of its own `CODEX_THREAD_ID`. The mirror is
|
|
75
|
+
* just as ordinary, so no fixed precedence between two markers can be right —
|
|
76
|
+
* whichever one it favours is wrong in the opposite nesting, and the cost is
|
|
77
|
+
* silent: `ask` looks up a session that is not this one, and every remedy the
|
|
78
|
+
* agent is told to try addresses a harness that is not running here.
|
|
79
|
+
*
|
|
80
|
+
* The general rule is to prefer the most specific *live* signal over inherited
|
|
81
|
+
* environment. An inherited marker is a claim about some ancestor process; a
|
|
82
|
+
* session id that names an entry in this directory's live pointer index is
|
|
83
|
+
* evidence that that exact session fired a hook here and its state still
|
|
84
|
+
* exists. Live evidence therefore wins over declared order, and the most
|
|
85
|
+
* recently active pointer wins between two live candidates: the harness whose
|
|
86
|
+
* turn is running is the one that fired last, while its parent sits blocked on
|
|
87
|
+
* the child it started. Declared order decides only when nothing here has
|
|
88
|
+
* fired yet, and it says so — every route fails closed there anyway.
|
|
89
|
+
*/
|
|
90
|
+
export function resolveActiveHarness(
|
|
91
|
+
env: NodeJS.ProcessEnv,
|
|
92
|
+
cwd: string,
|
|
93
|
+
now: number,
|
|
94
|
+
): ActiveHarnessResolution {
|
|
95
|
+
const candidates = harnessEnvCandidates(env)
|
|
96
|
+
const first = candidates[0]
|
|
97
|
+
if (first === undefined) return { active: null, contested: [] }
|
|
98
|
+
if (candidates.length === 1) return { active: first, contested: [] }
|
|
99
|
+
for (const pointer of readLiveProjectSessionPointers(cwd, env, now)) {
|
|
100
|
+
const owner = candidates.find(
|
|
101
|
+
(candidate) =>
|
|
102
|
+
candidate.harness === pointer.harness && candidate.sessionId === pointer.sessionId,
|
|
103
|
+
)
|
|
104
|
+
if (owner !== undefined) return { active: owner, contested: [] }
|
|
105
|
+
}
|
|
106
|
+
return { active: first, contested: candidates }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function activeHarnessSession(
|
|
110
|
+
env: NodeJS.ProcessEnv,
|
|
111
|
+
cwd: string,
|
|
112
|
+
now: number,
|
|
113
|
+
): ActiveHarnessSession | null {
|
|
114
|
+
return resolveActiveHarness(env, cwd, now).active
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The pid of the Claude Code session this hook belongs to.
|
|
119
|
+
*
|
|
120
|
+
* Claude exports `CLAUDE_PID` to its hooks, and that is the authoritative
|
|
121
|
+
* answer. `process.ppid` agrees with it today — the hook command runs through
|
|
122
|
+
* a shell, but the shell `exec`s, so this process's parent *is* the session
|
|
123
|
+
* (probed against a live 2.1.228 session) — and it remains the fallback for a
|
|
124
|
+
* harness build that stops exporting the variable.
|
|
125
|
+
*
|
|
126
|
+
* Preferring the explicit value costs a line and removes a silent failure: if
|
|
127
|
+
* this ever resolved to a shell instead, no session descriptor would match, the
|
|
128
|
+
* route could not prove own-child ownership, and every answer would degrade to
|
|
129
|
+
* hold-for-next-turn with nothing reported as wrong.
|
|
130
|
+
*/
|
|
131
|
+
export function claudeSessionPid(env: NodeJS.ProcessEnv): number {
|
|
132
|
+
const declared = Number(env['CLAUDE_PID'])
|
|
133
|
+
return Number.isInteger(declared) && declared > 0 ? declared : process.ppid
|
|
134
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BLOCKING_STOP_TIMEOUT_SECONDS,
|
|
3
|
+
CLAUDE_ASYNC_STOP_TIMEOUT_SECONDS,
|
|
4
|
+
handlerEvent,
|
|
5
|
+
stopHandlerIsDetached,
|
|
6
|
+
type Installation,
|
|
7
|
+
} from './install-hooks.js'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Whether an installed Stop handler declares the shape its harness needs.
|
|
11
|
+
*
|
|
12
|
+
* The three answers differ, and getting one wrong fails silently in a
|
|
13
|
+
* different way each time:
|
|
14
|
+
*
|
|
15
|
+
* - Claude Code's handler must be `async: true`, or the waiter holds the
|
|
16
|
+
* user's turn for its whole wait instead of returning at once. It must
|
|
17
|
+
* also declare a `timeout`, because the harness default is 600 s and the
|
|
18
|
+
* kill is silent — the backgrounded waiter vanishes and the answer the
|
|
19
|
+
* user already gave is never delivered.
|
|
20
|
+
* - Codex owns its Stop timeout. Declaring one changes the definition it
|
|
21
|
+
* hashes into `trusted_hash`, and an untrusted handler is simply not run.
|
|
22
|
+
* - Everything else blocks its turn and needs a ceiling above the wait.
|
|
23
|
+
*/
|
|
24
|
+
export function stopShapeProblems(
|
|
25
|
+
installation: Installation,
|
|
26
|
+
platform: NodeJS.Platform = process.platform,
|
|
27
|
+
): string[] {
|
|
28
|
+
if (installation.harness === 'codex') return []
|
|
29
|
+
const problems: string[] = []
|
|
30
|
+
for (const handler of installation.handlers.filter(
|
|
31
|
+
(entry) => handlerEvent(entry.command) === 'stop',
|
|
32
|
+
)) {
|
|
33
|
+
if (stopHandlerIsDetached(installation.harness, platform)) {
|
|
34
|
+
if (handler.async !== true) {
|
|
35
|
+
problems.push(
|
|
36
|
+
`${installation.file} declares a blocking Stop handler; the Claude Code wake route needs \`async: true\` so the turn ends while the waiter runs`,
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
if (handler.timeout === undefined || handler.timeout < CLAUDE_ASYNC_STOP_TIMEOUT_SECONDS) {
|
|
40
|
+
problems.push(
|
|
41
|
+
`${installation.file} gives Stop ${handler.timeout ?? 'no'} declared seconds; Claude Code then kills the backgrounded waiter at its 600s default without reporting anything, so it needs an explicit ${CLAUDE_ASYNC_STOP_TIMEOUT_SECONDS}s`,
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
continue
|
|
45
|
+
}
|
|
46
|
+
if (handler.timeout === undefined || handler.timeout < BLOCKING_STOP_TIMEOUT_SECONDS) {
|
|
47
|
+
problems.push(
|
|
48
|
+
`${installation.file} gives Stop ${handler.timeout ?? 'no'}s, but the blocking answer owner requires ${BLOCKING_STOP_TIMEOUT_SECONDS}s`,
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return problems
|
|
53
|
+
}
|