@raidiant/notifai 0.5.1 → 1.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 +165 -0
- package/README.md +11 -4
- package/dist/commands.d.ts +16 -1
- package/dist/commands.js +371 -157
- package/dist/commands.js.map +1 -1
- package/dist/config-schema.d.ts +1 -1
- package/dist/config-schema.js +2 -14
- package/dist/config-schema.js.map +1 -1
- package/dist/config.d.ts +19 -8
- package/dist/config.js +50 -7
- package/dist/config.js.map +1 -1
- package/dist/harnesses.d.ts +1 -0
- package/dist/harnesses.js +6 -0
- package/dist/harnesses.js.map +1 -1
- package/dist/hook-adapter.d.ts +10 -1
- package/dist/hook-adapter.js +79 -10
- package/dist/hook-adapter.js.map +1 -1
- package/dist/install-hooks.d.ts +54 -17
- package/dist/install-hooks.js +258 -97
- package/dist/install-hooks.js.map +1 -1
- package/dist/interactive.d.ts +32 -1
- package/dist/interactive.js +163 -47
- package/dist/interactive.js.map +1 -1
- package/dist/main.js +8 -8
- package/dist/main.js.map +1 -1
- package/dist/native-skills.d.ts +1 -1
- package/dist/native-skills.js +23 -58
- package/dist/native-skills.js.map +1 -1
- package/dist/pack-feedback-slice.d.ts +35 -0
- package/dist/pack-feedback-slice.js +126 -0
- package/dist/pack-feedback-slice.js.map +1 -0
- package/dist/readiness.d.ts +20 -0
- package/dist/readiness.js +24 -0
- package/dist/readiness.js.map +1 -1
- package/package.json +3 -2
- package/src/commands.test.ts +364 -31
- package/src/commands.ts +450 -177
- package/src/config-schema.ts +2 -17
- package/src/config.test.ts +29 -4
- package/src/config.ts +67 -11
- package/src/harnesses.ts +7 -0
- package/src/hook-adapter.test.ts +43 -1
- package/src/hook-adapter.ts +83 -11
- package/src/hooks.test.ts +4 -5
- package/src/install-hooks.test.ts +154 -2
- package/src/install-hooks.ts +231 -44
- package/src/interactive.test.ts +338 -0
- package/src/interactive.ts +221 -49
- package/src/main.ts +8 -8
- package/src/native-skills.test.ts +75 -0
- package/src/native-skills.ts +31 -75
- package/src/pack-feedback-slice.test.ts +212 -0
- package/src/pack-feedback-slice.ts +187 -0
- package/src/readiness.test.ts +25 -0
- package/src/readiness.ts +38 -0
- package/src/skill.test.ts +43 -0
- package/src/ui/config-view.test.ts +5 -4
package/src/commands.ts
CHANGED
|
@@ -36,7 +36,7 @@ import {
|
|
|
36
36
|
configBounds,
|
|
37
37
|
configDefaultValue,
|
|
38
38
|
findProjectConfigPath,
|
|
39
|
-
|
|
39
|
+
personalProjectConfigPath,
|
|
40
40
|
globalConfigPath,
|
|
41
41
|
loadConfig,
|
|
42
42
|
sessionConfigPath,
|
|
@@ -46,7 +46,7 @@ import {
|
|
|
46
46
|
type LogLevel,
|
|
47
47
|
} from './config.js'
|
|
48
48
|
import { acceptedValues, configInfo } from './config-schema.js'
|
|
49
|
-
import { skillsSource } from './release.js'
|
|
49
|
+
import { packageVersion, skillsSource } from './release.js'
|
|
50
50
|
import { atomicWriteFileSync } from './atomic-file.js'
|
|
51
51
|
import { withTargetFileLock } from './file-lock.js'
|
|
52
52
|
import {
|
|
@@ -57,8 +57,8 @@ import {
|
|
|
57
57
|
import type { CredentialStore, MachineCredential } from './credentials.js'
|
|
58
58
|
import {
|
|
59
59
|
firstBlocker,
|
|
60
|
-
openItems,
|
|
61
60
|
type Readiness,
|
|
61
|
+
type ReadinessRefresh,
|
|
62
62
|
type ReadinessState,
|
|
63
63
|
type StateStatus,
|
|
64
64
|
} from './readiness.js'
|
|
@@ -100,12 +100,18 @@ import {
|
|
|
100
100
|
applyPlan,
|
|
101
101
|
buildCursorHookConfig,
|
|
102
102
|
buildHookConfig,
|
|
103
|
+
collapseUnusedCodexRepresentation,
|
|
103
104
|
codexLayerDir,
|
|
105
|
+
codexLayerPaths,
|
|
106
|
+
codexRepresentationProblems,
|
|
104
107
|
codexTrustProblems,
|
|
105
108
|
codexProjectRoot,
|
|
106
109
|
detectHarness,
|
|
110
|
+
detectedHarnesses,
|
|
107
111
|
findInstallations,
|
|
108
112
|
handlerEvent,
|
|
113
|
+
hookDefinitionFiles,
|
|
114
|
+
inspectCodexLayer,
|
|
109
115
|
loadCursorSettings,
|
|
110
116
|
loadSettings,
|
|
111
117
|
mergeCursorHooks,
|
|
@@ -116,7 +122,7 @@ import {
|
|
|
116
122
|
type Harness,
|
|
117
123
|
type Installation,
|
|
118
124
|
} from './install-hooks.js'
|
|
119
|
-
import { HARNESS_CAPABILITIES } from './harnesses.js'
|
|
125
|
+
import { HARNESS_CAPABILITIES, HARNESS_LABELS } from './harnesses.js'
|
|
120
126
|
import {
|
|
121
127
|
claudeWakeRoute,
|
|
122
128
|
inspectClaudeInbox,
|
|
@@ -131,6 +137,8 @@ import {
|
|
|
131
137
|
import {
|
|
132
138
|
inspectHookAdapter,
|
|
133
139
|
installHookAdapter,
|
|
140
|
+
isNpxAdapterTarget,
|
|
141
|
+
type HookAdapterTarget,
|
|
134
142
|
} from './hook-adapter.js'
|
|
135
143
|
import {
|
|
136
144
|
isOurOpencodePlugin,
|
|
@@ -162,6 +170,12 @@ export interface CommandIo {
|
|
|
162
170
|
*/
|
|
163
171
|
interactive?: boolean
|
|
164
172
|
select?(message: string, options: { value: string; label: string; hint?: string }[]): Promise<string | null>
|
|
173
|
+
/** Interactive multi-select. `initial` are pre-selected values. */
|
|
174
|
+
multiselect?(
|
|
175
|
+
message: string,
|
|
176
|
+
options: { value: string; label: string; hint?: string }[],
|
|
177
|
+
initial?: string[],
|
|
178
|
+
): Promise<string[] | null>
|
|
165
179
|
intro?(title: string): Promise<void>
|
|
166
180
|
outro?(message: string): Promise<void>
|
|
167
181
|
note?(message: string, title?: string): Promise<void>
|
|
@@ -188,6 +202,8 @@ export interface CommandDeps {
|
|
|
188
202
|
cwd: string
|
|
189
203
|
/** Test seam; production fixes the hook adapter under os.homedir(). */
|
|
190
204
|
hookAdapterHome?: string
|
|
205
|
+
/** Test seam; production uses this process's Node and CLI paths. */
|
|
206
|
+
hookInstallTarget?: HookAdapterTarget
|
|
191
207
|
/** Test seam; production uses fetch against base_url. */
|
|
192
208
|
clientFactory?: (baseUrl: string, bearer: string | null, options?: ClientOptions) => ApiClient
|
|
193
209
|
/** Test seam for bounded polling without wall-clock sleeps. */
|
|
@@ -2125,19 +2141,79 @@ export interface HooksInstallFlags {
|
|
|
2125
2141
|
scriptPath?: string
|
|
2126
2142
|
}
|
|
2127
2143
|
|
|
2144
|
+
/** True when this process is `npx` / `npm exec`, not a global or linked install. */
|
|
2145
|
+
export function runningViaNpx(env: NodeJS.ProcessEnv, scriptPath: string): boolean {
|
|
2146
|
+
if (env['npm_command'] === 'exec') return true
|
|
2147
|
+
return scriptPath.includes(`${path.sep}_npx${path.sep}`)
|
|
2148
|
+
}
|
|
2149
|
+
|
|
2150
|
+
function fileHookInstallTarget(
|
|
2151
|
+
target: HookAdapterTarget | undefined,
|
|
2152
|
+
): { execPath: string; scriptPath: string } | undefined {
|
|
2153
|
+
if (target === undefined || isNpxAdapterTarget(target)) return undefined
|
|
2154
|
+
return target
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
function resolveHookAdapterTarget(deps: CommandDeps, flags: HooksInstallFlags): HookAdapterTarget {
|
|
2158
|
+
if (deps.hookInstallTarget !== undefined && isNpxAdapterTarget(deps.hookInstallTarget)) {
|
|
2159
|
+
return deps.hookInstallTarget
|
|
2160
|
+
}
|
|
2161
|
+
const fileTarget = fileHookInstallTarget(deps.hookInstallTarget)
|
|
2162
|
+
const execPath = flags.execPath ?? fileTarget?.execPath ?? process.execPath
|
|
2163
|
+
const scriptPath = flags.scriptPath ?? fileTarget?.scriptPath ?? process.argv[1] ?? 'notifai'
|
|
2164
|
+
if (runningViaNpx(deps.env, scriptPath)) {
|
|
2165
|
+
const version = packageVersion()
|
|
2166
|
+
const npmCli = deps.env['npm_execpath']
|
|
2167
|
+
if (version === null) {
|
|
2168
|
+
throw new Error(
|
|
2169
|
+
'Could not read this CLI version, so an npx hook target cannot be pinned. Install `@raidiant/notifai` globally and rerun `notifai hooks install`.',
|
|
2170
|
+
)
|
|
2171
|
+
}
|
|
2172
|
+
if (typeof npmCli !== 'string' || npmCli === '') {
|
|
2173
|
+
throw new Error(
|
|
2174
|
+
'This process looks like npx but npm_execpath is missing. Install `@raidiant/notifai` globally and rerun `notifai hooks install`.',
|
|
2175
|
+
)
|
|
2176
|
+
}
|
|
2177
|
+
return { kind: 'npx', execPath, npmCli, spec: `@raidiant/notifai@${version}` }
|
|
2178
|
+
}
|
|
2179
|
+
return { execPath, scriptPath }
|
|
2180
|
+
}
|
|
2181
|
+
|
|
2182
|
+
function printHooksInstallClose(deps: CommandDeps, harness: Harness, file: string): void {
|
|
2183
|
+
const label = HARNESS_LABELS[harness]
|
|
2184
|
+
if (deps.io.interactive === true && deps.io.note) {
|
|
2185
|
+
void deps.io.note(`${file}\nSend one ${label} prompt, then run \`notifai doctor\`.`, `${label} hooks installed`)
|
|
2186
|
+
return
|
|
2187
|
+
}
|
|
2188
|
+
deps.io.out(`Installed ${harness} hooks in ${file}`)
|
|
2189
|
+
deps.io.out(`Send one ${label} prompt, then check \`notifai doctor\`.`)
|
|
2190
|
+
}
|
|
2191
|
+
|
|
2128
2192
|
export function hooksInstallCommand(deps: CommandDeps, flags: HooksInstallFlags): number {
|
|
2193
|
+
if (flags.harness === undefined) {
|
|
2194
|
+
const detected = detectedHarnesses(deps.cwd, deps.env)
|
|
2195
|
+
if (detected.length === 0) {
|
|
2196
|
+
deps.io.err(`Could not tell which harness to install for — pass --harness <${HARNESSES.join('|')}>.`)
|
|
2197
|
+
return EXIT.usage
|
|
2198
|
+
}
|
|
2199
|
+
let ok = true
|
|
2200
|
+
for (const harness of detected) {
|
|
2201
|
+
if (hooksInstallCommand(deps, { ...flags, harness }) !== EXIT.ok) ok = false
|
|
2202
|
+
}
|
|
2203
|
+
return ok ? EXIT.ok : EXIT.failed
|
|
2204
|
+
}
|
|
2129
2205
|
const harness = resolveHarness(deps, flags.harness)
|
|
2130
2206
|
if (!harness) return EXIT.usage
|
|
2131
|
-
const
|
|
2132
|
-
const scriptPath =
|
|
2207
|
+
const adapterTarget = resolveHookAdapterTarget(deps, flags)
|
|
2208
|
+
const scriptPath =
|
|
2209
|
+
flags.scriptPath ?? fileHookInstallTarget(adapterTarget)?.scriptPath ?? process.argv[1] ?? 'notifai'
|
|
2133
2210
|
let adapterPath: string
|
|
2134
2211
|
try {
|
|
2135
|
-
adapterPath = installHookAdapter(
|
|
2212
|
+
adapterPath = installHookAdapter(adapterTarget, deps.hookAdapterHome).path
|
|
2136
2213
|
} catch (err) {
|
|
2137
2214
|
deps.io.err(`Could not prepare the stable hook adapter: ${String(err)}`)
|
|
2138
2215
|
return EXIT.failed
|
|
2139
2216
|
}
|
|
2140
|
-
const config = loadLoggedConfig(deps, { cwd: deps.cwd, env: deps.env })
|
|
2141
2217
|
const file = settingsFile(harness, flags.global ?? false, deps.cwd, deps.env)
|
|
2142
2218
|
|
|
2143
2219
|
// OpenCode's adapter is a generated plugin module rather than a handler
|
|
@@ -2150,9 +2226,8 @@ export function hooksInstallCommand(deps: CommandDeps, flags: HooksInstallFlags)
|
|
|
2150
2226
|
}
|
|
2151
2227
|
|
|
2152
2228
|
if (harness === 'cursor') {
|
|
2153
|
-
let merged: ReturnType<typeof mergeCursorHooks>
|
|
2154
2229
|
try {
|
|
2155
|
-
|
|
2230
|
+
withTargetFileLock(file, () => {
|
|
2156
2231
|
const document = loadCursorSettings(file)
|
|
2157
2232
|
const result = mergeCursorHooks(
|
|
2158
2233
|
document,
|
|
@@ -2169,26 +2244,16 @@ export function hooksInstallCommand(deps: CommandDeps, flags: HooksInstallFlags)
|
|
|
2169
2244
|
deps.io.err(String(err))
|
|
2170
2245
|
return EXIT.failed
|
|
2171
2246
|
}
|
|
2172
|
-
deps
|
|
2173
|
-
if (merged.replaced.length > 0) deps.io.out(` replaced: ${merged.replaced.join(', ')}`)
|
|
2174
|
-
if (merged.added.length > 0) deps.io.out(` added: ${merged.added.join(', ')}`)
|
|
2175
|
-
if (flags.global) {
|
|
2176
|
-
deps.io.out('Send one Cursor prompt, then check `notifai doctor`. If the hook has not fired,')
|
|
2177
|
-
deps.io.out('start a new Cursor session and try one prompt again.')
|
|
2178
|
-
} else {
|
|
2179
|
-
deps.io.out('Send one Cursor prompt, then check `notifai doctor`. If the hook has not fired,')
|
|
2180
|
-
deps.io.out('start a new Cursor session and try one prompt again.')
|
|
2181
|
-
}
|
|
2182
|
-
deps.io.out('Cursor hooks can emit a native follow-up, but its agent shell does not expose')
|
|
2183
|
-
deps.io.out('the exact conversation id needed to register safely. `notifai ask` therefore')
|
|
2184
|
-
deps.io.out('fails closed; use blocking `notifai send --reply` for questions.')
|
|
2247
|
+
printHooksInstallClose(deps, harness, file)
|
|
2185
2248
|
return EXIT.ok
|
|
2186
2249
|
}
|
|
2187
2250
|
|
|
2188
|
-
let
|
|
2251
|
+
let foreignStopCount = 0
|
|
2252
|
+
let collapsedFrom: string | null = null
|
|
2189
2253
|
try {
|
|
2190
|
-
|
|
2254
|
+
withTargetFileLock(file, () => {
|
|
2191
2255
|
const document = loadSettings(file)
|
|
2256
|
+
foreignStopCount = foreignStopHandlers(document).length
|
|
2192
2257
|
const result = mergeHooks(
|
|
2193
2258
|
document,
|
|
2194
2259
|
buildHookConfig({
|
|
@@ -2200,62 +2265,47 @@ export function hooksInstallCommand(deps: CommandDeps, flags: HooksInstallFlags)
|
|
|
2200
2265
|
applyPlan(file, result.document)
|
|
2201
2266
|
return result
|
|
2202
2267
|
})
|
|
2268
|
+
if (harness === 'codex') {
|
|
2269
|
+
collapsedFrom = collapseUnusedCodexRepresentation(
|
|
2270
|
+
file,
|
|
2271
|
+
scriptPath,
|
|
2272
|
+
codexLayerPaths(flags.global ?? false, deps.cwd, deps.env),
|
|
2273
|
+
)
|
|
2274
|
+
}
|
|
2203
2275
|
} catch (err) {
|
|
2204
2276
|
deps.io.err(String(err))
|
|
2205
2277
|
return EXIT.failed
|
|
2206
2278
|
}
|
|
2207
2279
|
|
|
2208
|
-
deps.io.out(`Installed ${harness} hooks in ${file}`)
|
|
2209
|
-
if (merged.replaced.length > 0) deps.io.out(` replaced: ${merged.replaced.join(', ')}`)
|
|
2210
|
-
if (merged.added.length > 0) deps.io.out(` added: ${merged.added.join(', ')}`)
|
|
2211
|
-
if (merged.removed.length > 0) {
|
|
2212
|
-
deps.io.out(` removed: ${merged.removed.join(', ')} (this build no longer serves them)`)
|
|
2213
|
-
}
|
|
2214
|
-
deps.io.out('')
|
|
2215
|
-
deps.io.out(
|
|
2216
|
-
config.ask_grace_seconds.value === 0
|
|
2217
|
-
? 'A question registered with `notifai ask` goes to your devices immediately when the agent turn ends, whether or not you are at this machine.'
|
|
2218
|
-
: `A question registered with \`notifai ask\` stays in the terminal for ${config.ask_grace_seconds.value}s from registration and then goes to your devices whether or not you are at this machine.`,
|
|
2219
|
-
)
|
|
2220
2280
|
if (harness === 'codex') {
|
|
2221
2281
|
const layer = flags.global ? null : codexLayerDir(deps.cwd)
|
|
2222
|
-
if (layer !== null) {
|
|
2223
|
-
// Codex reads project hooks from the main repository but only looks when
|
|
2224
|
-
// a `.codex` directory sits at or above cwd, so a worktree install has to
|
|
2225
|
-
// write one file and create one directory in two different places. Doing
|
|
2226
|
-
// it silently would leave the next person deriving this the hard way
|
|
2227
|
-
//.
|
|
2228
|
-
mkdirSync(layer, { recursive: true })
|
|
2229
|
-
deps.io.out('')
|
|
2230
|
-
deps.io.out('You are in a worktree. Codex reads project hooks from the main repository,')
|
|
2231
|
-
deps.io.out(`so they were written to ${file}. ${layer} was created so this`)
|
|
2232
|
-
deps.io.out('worktree discovers that file. Each other worktree needs its own `.codex`')
|
|
2233
|
-
deps.io.out('directory; rerun this installer from that worktree to create it.')
|
|
2234
|
-
}
|
|
2282
|
+
if (layer !== null) mkdirSync(layer, { recursive: true })
|
|
2235
2283
|
}
|
|
2236
|
-
deps
|
|
2237
|
-
if (
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2284
|
+
printHooksInstallClose(deps, harness, file)
|
|
2285
|
+
if (collapsedFrom !== null) {
|
|
2286
|
+
deps.io.out(`Collapsed ${collapsedFrom} onto ${file} so this layer has one representation.`)
|
|
2287
|
+
}
|
|
2288
|
+
if (foreignStopCount > 0) {
|
|
2241
2289
|
deps.io.out(
|
|
2242
|
-
|
|
2290
|
+
"This layer already has a Stop handler. Codex runs every matching handler, so Notifai's Stop and the existing one will both fire.",
|
|
2243
2291
|
)
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
} else if (harness === 'claude-code') {
|
|
2250
|
-
deps.io.out('Send one new Claude Code prompt, then check `notifai doctor`. If the hook has')
|
|
2251
|
-
deps.io.out('not fired, start a new Claude Code session and try one prompt again.')
|
|
2252
|
-
} else {
|
|
2253
|
-
deps.io.out('Send one Codex prompt, then check `notifai doctor`. If the hook has not fired,')
|
|
2254
|
-
deps.io.out('start a new Codex session and try one prompt again.')
|
|
2292
|
+
}
|
|
2293
|
+
if (harness === 'codex') {
|
|
2294
|
+
for (const problem of codexRepresentationProblems(deps.cwd, deps.env)) {
|
|
2295
|
+
deps.io.out(problem)
|
|
2296
|
+
}
|
|
2255
2297
|
}
|
|
2256
2298
|
return EXIT.ok
|
|
2257
2299
|
}
|
|
2258
2300
|
|
|
2301
|
+
function foreignStopHandlers(document: { hooks?: Record<string, { hooks?: { command: string }[] }[]> }): { command: string }[] {
|
|
2302
|
+
const groups = document.hooks?.['Stop']
|
|
2303
|
+
if (!Array.isArray(groups)) return []
|
|
2304
|
+
return groups
|
|
2305
|
+
.flatMap((group) => group.hooks ?? [])
|
|
2306
|
+
.filter((handler) => !/ hook (user-prompt-submit|stop|session-end)\b/.test(handler.command))
|
|
2307
|
+
}
|
|
2308
|
+
|
|
2259
2309
|
/**
|
|
2260
2310
|
* Writes the OpenCode plugin, replacing any Notifai plugin already there —
|
|
2261
2311
|
* including one a different checkout wrote, matched on the managed marker for
|
|
@@ -2285,16 +2335,7 @@ function installOpencodePlugin(
|
|
|
2285
2335
|
deps.io.err(String(err))
|
|
2286
2336
|
return EXIT.failed
|
|
2287
2337
|
}
|
|
2288
|
-
deps
|
|
2289
|
-
deps.io.out('')
|
|
2290
|
-
deps.io.out('It maps chat.message to presence, session.idle to question escalation, and')
|
|
2291
|
-
deps.io.out('session.deleted to local cleanup through the same `notifai hook` commands')
|
|
2292
|
-
deps.io.out('the other harnesses run. Permission prompts stay in OpenCode.')
|
|
2293
|
-
deps.io.out('OpenCode does not expose a proven exactly-once continuation after session.idle,')
|
|
2294
|
-
deps.io.out('so `notifai ask` fails closed there. Use blocking `notifai send --reply` when')
|
|
2295
|
-
deps.io.out('the answer must return to the agent without another human prompt.')
|
|
2296
|
-
deps.io.out('')
|
|
2297
|
-
deps.io.out('Restart OpenCode: it loads plugins once at start.')
|
|
2338
|
+
printHooksInstallClose(deps, 'opencode', file)
|
|
2298
2339
|
return EXIT.ok
|
|
2299
2340
|
}
|
|
2300
2341
|
|
|
@@ -2350,28 +2391,33 @@ export function hooksUninstallCommand(deps: CommandDeps, flags: HooksInstallFlag
|
|
|
2350
2391
|
)
|
|
2351
2392
|
return EXIT.ok
|
|
2352
2393
|
}
|
|
2353
|
-
|
|
2394
|
+
const files = hookDefinitionFiles(harness, flags.global ?? false, deps.cwd, deps.env)
|
|
2395
|
+
const existing = files.filter((candidate) => existsSync(candidate))
|
|
2396
|
+
if (existing.length === 0) {
|
|
2397
|
+
deps.io.out(`Nothing to remove: ${file} does not exist.`)
|
|
2398
|
+
return EXIT.ok
|
|
2399
|
+
}
|
|
2400
|
+
let removedAny = false
|
|
2354
2401
|
try {
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2402
|
+
for (const candidate of existing) {
|
|
2403
|
+
const stripped = withTargetFileLock(candidate, () => {
|
|
2404
|
+
const document = loadSettings(candidate)
|
|
2405
|
+
const result = removeHooks(document, scriptPath)
|
|
2406
|
+
applyPlan(candidate, result.document)
|
|
2407
|
+
return result
|
|
2408
|
+
})
|
|
2409
|
+
if (stripped.replaced.length > 0) {
|
|
2410
|
+
removedAny = true
|
|
2411
|
+
deps.io.out(`Removed Notifai hooks (${stripped.replaced.join(', ')}) from ${candidate}`)
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2362
2414
|
} catch (err) {
|
|
2363
2415
|
deps.io.err(String(err))
|
|
2364
2416
|
return EXIT.failed
|
|
2365
2417
|
}
|
|
2366
|
-
if (
|
|
2367
|
-
deps.io.out(`
|
|
2368
|
-
return EXIT.ok
|
|
2418
|
+
if (!removedAny) {
|
|
2419
|
+
deps.io.out(`No Notifai hooks found in ${existing.join(', ')}`)
|
|
2369
2420
|
}
|
|
2370
|
-
deps.io.out(
|
|
2371
|
-
stripped.replaced.length > 0
|
|
2372
|
-
? `Removed Notifai hooks (${stripped.replaced.join(', ')}) from ${file}`
|
|
2373
|
-
: `No Notifai hooks found in ${file}`,
|
|
2374
|
-
)
|
|
2375
2421
|
return EXIT.ok
|
|
2376
2422
|
}
|
|
2377
2423
|
|
|
@@ -2386,6 +2432,13 @@ function assertOwnedRegularFile(file: string): void {
|
|
|
2386
2432
|
}
|
|
2387
2433
|
}
|
|
2388
2434
|
|
|
2435
|
+
const HARNESS_LABEL: Record<Harness, string> = {
|
|
2436
|
+
'claude-code': 'Claude Code',
|
|
2437
|
+
codex: 'Codex',
|
|
2438
|
+
cursor: 'Cursor',
|
|
2439
|
+
opencode: 'OpenCode',
|
|
2440
|
+
}
|
|
2441
|
+
|
|
2389
2442
|
function resolveHarness(deps: CommandDeps, requested: string | undefined): Harness | null {
|
|
2390
2443
|
if (requested !== undefined) {
|
|
2391
2444
|
if ((HARNESSES as readonly string[]).includes(requested)) return requested as Harness
|
|
@@ -2394,7 +2447,7 @@ function resolveHarness(deps: CommandDeps, requested: string | undefined): Harne
|
|
|
2394
2447
|
)
|
|
2395
2448
|
return null
|
|
2396
2449
|
}
|
|
2397
|
-
const detected = detectHarness(deps.cwd)
|
|
2450
|
+
const detected = detectHarness(deps.cwd, deps.env)
|
|
2398
2451
|
if (!detected) {
|
|
2399
2452
|
deps.io.err(`Could not tell which harness to install for — pass --harness <${HARNESSES.join('|')}>.`)
|
|
2400
2453
|
return null
|
|
@@ -2402,6 +2455,48 @@ function resolveHarness(deps: CommandDeps, requested: string | undefined): Harne
|
|
|
2402
2455
|
return detected
|
|
2403
2456
|
}
|
|
2404
2457
|
|
|
2458
|
+
/**
|
|
2459
|
+
* Which harnesses to wire. An explicit `--harness` still wins as a singleton.
|
|
2460
|
+
* Otherwise: every detected harness, or a human picker when detection is empty
|
|
2461
|
+
* or names more than one.
|
|
2462
|
+
*/
|
|
2463
|
+
async function pickHarnessesToInstall(
|
|
2464
|
+
deps: CommandDeps,
|
|
2465
|
+
requested?: string,
|
|
2466
|
+
): Promise<Harness[] | null> {
|
|
2467
|
+
if (requested !== undefined) {
|
|
2468
|
+
const harness = resolveHarness(deps, requested)
|
|
2469
|
+
return harness === null ? null : [harness]
|
|
2470
|
+
}
|
|
2471
|
+
const detected = detectedHarnesses(deps.cwd, deps.env)
|
|
2472
|
+
if (detected.length === 1) return detected
|
|
2473
|
+
if (deps.io.interactive === true && deps.io.multiselect) {
|
|
2474
|
+
const picked = await deps.io.multiselect(
|
|
2475
|
+
'Which agent harnesses should Notifai wire here?',
|
|
2476
|
+
HARNESSES.map((name) => ({
|
|
2477
|
+
value: name,
|
|
2478
|
+
label: HARNESS_LABEL[name],
|
|
2479
|
+
...(detected.includes(name) ? { hint: 'detected on this machine' } : {}),
|
|
2480
|
+
})),
|
|
2481
|
+
detected,
|
|
2482
|
+
)
|
|
2483
|
+
if (picked === null) return null
|
|
2484
|
+
const unknown = picked.filter((name) => !(HARNESSES as readonly string[]).includes(name))
|
|
2485
|
+
if (unknown.length > 0) {
|
|
2486
|
+
deps.io.err(`Unknown harness "${unknown[0]}". Supported: ${HARNESSES.join(', ')}.`)
|
|
2487
|
+
return null
|
|
2488
|
+
}
|
|
2489
|
+
return picked as Harness[]
|
|
2490
|
+
}
|
|
2491
|
+
if (detected.length === 0) {
|
|
2492
|
+
deps.io.err(
|
|
2493
|
+
`Could not tell which harness to wire. Run: notifai hooks install --harness <${HARNESSES.join('|')}>`,
|
|
2494
|
+
)
|
|
2495
|
+
return null
|
|
2496
|
+
}
|
|
2497
|
+
return detected
|
|
2498
|
+
}
|
|
2499
|
+
|
|
2405
2500
|
// ---------------------------------------------------------------------------
|
|
2406
2501
|
// config show / set / unset
|
|
2407
2502
|
// ---------------------------------------------------------------------------
|
|
@@ -2413,7 +2508,14 @@ export function configShowCommand(
|
|
|
2413
2508
|
const config = loadLoggedConfig(deps, { cwd: deps.cwd, env: deps.env })
|
|
2414
2509
|
if (flags.json) {
|
|
2415
2510
|
const output = Object.fromEntries(
|
|
2416
|
-
CONFIG_KEYS.map((key) => [
|
|
2511
|
+
CONFIG_KEYS.map((key) => [
|
|
2512
|
+
key,
|
|
2513
|
+
{
|
|
2514
|
+
value: config[key].value,
|
|
2515
|
+
source: config[key].source,
|
|
2516
|
+
summary: configInfo(key).summary,
|
|
2517
|
+
},
|
|
2518
|
+
]),
|
|
2417
2519
|
)
|
|
2418
2520
|
deps.io.out(JSON.stringify(output, null, 2))
|
|
2419
2521
|
return EXIT.ok
|
|
@@ -2622,7 +2724,7 @@ async function configMutationTarget(
|
|
|
2622
2724
|
const selected = await deps.io.select('Where should this setting live?', [
|
|
2623
2725
|
{ value: 'global', label: 'This machine', hint: 'applies across projects' },
|
|
2624
2726
|
{ value: 'project', label: 'This project (shared)', hint: '.notifai/config.toml' },
|
|
2625
|
-
{ value: 'local', label: 'This project (personal)', hint: '
|
|
2727
|
+
{ value: 'local', label: 'This project (personal)', hint: 'stored on this machine, not in the repo' },
|
|
2626
2728
|
])
|
|
2627
2729
|
if (selected === null) {
|
|
2628
2730
|
deps.io.err('No configuration layer selected.')
|
|
@@ -2634,7 +2736,7 @@ async function configMutationTarget(
|
|
|
2634
2736
|
const targetPath = flags.session
|
|
2635
2737
|
? sessionConfigPath(flags.session, deps.env)
|
|
2636
2738
|
: layer === 'local'
|
|
2637
|
-
? (
|
|
2739
|
+
? personalProjectConfigPath(deps.cwd, deps.env)
|
|
2638
2740
|
: layer === 'project'
|
|
2639
2741
|
? (findProjectConfigPath(deps.cwd) ?? path.join(deps.cwd, '.notifai', 'config.toml'))
|
|
2640
2742
|
: globalConfigPath(deps.env)
|
|
@@ -3127,8 +3229,8 @@ function observedCompanionReceipt(
|
|
|
3127
3229
|
* gap, so re-running is how you check the setup as much as how you create it.
|
|
3128
3230
|
* With a human at a terminal it walks them through the missing pieces; run by
|
|
3129
3231
|
* an agent it never prompts — each optional step is answered by a flag, and
|
|
3130
|
-
* whatever only the user can do (signing in, pairing a companion device) is
|
|
3131
|
-
* the
|
|
3232
|
+
* whatever only the user can do (signing in, pairing a companion device) is
|
|
3233
|
+
* printed as the next human action. An agent runs every CLI command itself.
|
|
3132
3234
|
*/
|
|
3133
3235
|
/**
|
|
3134
3236
|
* Close a gap the CLI is allowed to close on its own, without asking.
|
|
@@ -3159,21 +3261,13 @@ async function closeGap(
|
|
|
3159
3261
|
}
|
|
3160
3262
|
|
|
3161
3263
|
if (state.id === 'hooks') {
|
|
3162
|
-
|
|
3163
|
-
if (
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
)
|
|
3168
|
-
if (picked !== null) harness = picked as Harness
|
|
3169
|
-
}
|
|
3170
|
-
if (harness === null) {
|
|
3171
|
-
deps.io.err(
|
|
3172
|
-
`Could not tell which harness to wire. Run: notifai hooks install --harness <${HARNESSES.join('|')}>`,
|
|
3173
|
-
)
|
|
3174
|
-
return 'failed'
|
|
3264
|
+
const harnesses = await pickHarnessesToInstall(deps)
|
|
3265
|
+
if (harnesses === null || harnesses.length === 0) return 'failed'
|
|
3266
|
+
let ok = true
|
|
3267
|
+
for (const harness of harnesses) {
|
|
3268
|
+
if (hooksInstallCommand(deps, { harness }) !== EXIT.ok) ok = false
|
|
3175
3269
|
}
|
|
3176
|
-
return
|
|
3270
|
+
return ok ? 'closed' : 'failed'
|
|
3177
3271
|
}
|
|
3178
3272
|
|
|
3179
3273
|
if (state.id === 'skill') {
|
|
@@ -3517,6 +3611,13 @@ async function runSetupProof(deps: CommandDeps): Promise<GapCloseResult> {
|
|
|
3517
3611
|
return 'pending'
|
|
3518
3612
|
}
|
|
3519
3613
|
|
|
3614
|
+
/** Closing a local gap cannot have changed the service, the keychain, or devices. */
|
|
3615
|
+
function refreshAfterClose(id: string): readonly ReadinessRefresh[] | undefined {
|
|
3616
|
+
return id === 'project' || id === 'hooks' || id === 'skill' || id === 'question-routing-settings'
|
|
3617
|
+
? ['local']
|
|
3618
|
+
: undefined
|
|
3619
|
+
}
|
|
3620
|
+
|
|
3520
3621
|
/** Whether an optional gap should be closed, given flags and who is watching. */
|
|
3521
3622
|
function wantsOptional(deps: CommandDeps, state: ReadinessState, flags: InitFlags): Promise<boolean> {
|
|
3522
3623
|
// Naming the project is init's whole reason to touch the filesystem, costs
|
|
@@ -3576,12 +3677,13 @@ export async function initCommand(deps: CommandDeps, flags: InitFlags): Promise<
|
|
|
3576
3677
|
}
|
|
3577
3678
|
await deps.io.intro?.('Notifai setup')
|
|
3578
3679
|
|
|
3579
|
-
const
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3680
|
+
const skillOpts = flags.skillsScope === undefined ? {} : { skillScope: flags.skillsScope }
|
|
3681
|
+
let readiness = await assessReadiness(deps, skillOpts)
|
|
3682
|
+
const reassess = (refresh?: readonly ReadinessRefresh[]) =>
|
|
3683
|
+
assessReadiness(deps, {
|
|
3684
|
+
...skillOpts,
|
|
3685
|
+
...(refresh === undefined ? {} : { previous: readiness, refresh }),
|
|
3686
|
+
})
|
|
3585
3687
|
let failed = false
|
|
3586
3688
|
const attempted = new Set<string>()
|
|
3587
3689
|
|
|
@@ -3612,7 +3714,7 @@ export async function initCommand(deps: CommandDeps, flags: InitFlags): Promise<
|
|
|
3612
3714
|
const result = await closeGap(deps, state, flags)
|
|
3613
3715
|
if (result === 'failed') failed = true
|
|
3614
3716
|
if (result === 'failed' && state.status === 'optional-gap') {
|
|
3615
|
-
readiness = await reassess()
|
|
3717
|
+
readiness = await reassess(refreshAfterClose(state.id))
|
|
3616
3718
|
advanced = true
|
|
3617
3719
|
break
|
|
3618
3720
|
}
|
|
@@ -3620,7 +3722,7 @@ export async function initCommand(deps: CommandDeps, flags: InitFlags): Promise<
|
|
|
3620
3722
|
stop = true
|
|
3621
3723
|
break
|
|
3622
3724
|
}
|
|
3623
|
-
readiness = await reassess()
|
|
3725
|
+
readiness = await reassess(refreshAfterClose(state.id))
|
|
3624
3726
|
advanced = true
|
|
3625
3727
|
break
|
|
3626
3728
|
}
|
|
@@ -3633,7 +3735,7 @@ export async function initCommand(deps: CommandDeps, flags: InitFlags): Promise<
|
|
|
3633
3735
|
stop = true
|
|
3634
3736
|
break
|
|
3635
3737
|
}
|
|
3636
|
-
readiness = await reassess()
|
|
3738
|
+
readiness = await reassess(refreshAfterClose(state.id))
|
|
3637
3739
|
advanced = true
|
|
3638
3740
|
break
|
|
3639
3741
|
}
|
|
@@ -3682,37 +3784,81 @@ export async function initCommand(deps: CommandDeps, flags: InitFlags): Promise<
|
|
|
3682
3784
|
if (stop || !advanced) break
|
|
3683
3785
|
}
|
|
3684
3786
|
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3787
|
+
await printInitClose(deps, readiness, flags)
|
|
3788
|
+
const blocker = firstBlocker(readiness)
|
|
3789
|
+
if (blocker === null) return failed ? EXIT.failed : EXIT.ok
|
|
3790
|
+
return failed || deps.io.interactive !== true ? EXIT.failed : EXIT.ok
|
|
3791
|
+
}
|
|
3792
|
+
|
|
3793
|
+
function isHookSubstate(id: string): boolean {
|
|
3794
|
+
return id === 'hooks' || id.startsWith('hooks-') || id === 'question-routing-settings'
|
|
3795
|
+
}
|
|
3796
|
+
|
|
3797
|
+
function leftoverOptionals(readiness: Readiness, flags: InitFlags): ReadinessState[] {
|
|
3798
|
+
return readiness.states.filter((state) => {
|
|
3799
|
+
if (state.status !== 'optional-gap') return false
|
|
3800
|
+
if (isHookSubstate(state.id)) return false
|
|
3801
|
+
if (state.id === 'skill' && flags.skills === false) return false
|
|
3802
|
+
return true
|
|
3803
|
+
})
|
|
3804
|
+
}
|
|
3805
|
+
|
|
3806
|
+
function printOptionalLeftovers(deps: CommandDeps, leftovers: readonly ReadinessState[]): void {
|
|
3807
|
+
for (const state of leftovers) {
|
|
3808
|
+
deps.io.out(`Optional, not set up — ${remedyLine(state)}`)
|
|
3688
3809
|
}
|
|
3810
|
+
}
|
|
3689
3811
|
|
|
3812
|
+
function questionsWillRoute(readiness: Readiness): boolean {
|
|
3813
|
+
const hooks = readiness.states.find((state) => state.id === 'hooks')
|
|
3814
|
+
const settings = readiness.states.find((state) => state.id === 'question-routing-settings')
|
|
3815
|
+
return hooks?.status === 'ready' && settings?.status !== 'gap'
|
|
3816
|
+
}
|
|
3817
|
+
|
|
3818
|
+
async function printInitClose(
|
|
3819
|
+
deps: CommandDeps,
|
|
3820
|
+
readiness: Readiness,
|
|
3821
|
+
flags: InitFlags,
|
|
3822
|
+
): Promise<void> {
|
|
3690
3823
|
const blocker = firstBlocker(readiness)
|
|
3824
|
+
const canSend = readiness.states.find((state) => state.id === 'devices')?.status === 'ready'
|
|
3825
|
+
const questions = questionsWillRoute(readiness)
|
|
3826
|
+
const leftovers = leftoverOptionals(readiness, flags)
|
|
3827
|
+
|
|
3828
|
+
if (deps.io.interactive === true) {
|
|
3829
|
+
if (blocker === null) {
|
|
3830
|
+
const lines = [
|
|
3831
|
+
canSend ? 'You can send notifications.' : 'You are signed in.',
|
|
3832
|
+
questions
|
|
3833
|
+
? 'Questions will reach your devices.'
|
|
3834
|
+
: 'Questions stay in the terminal until hooks are installed.',
|
|
3835
|
+
]
|
|
3836
|
+
await deps.io.note?.(lines.join('\n'), 'Ready')
|
|
3837
|
+
printOptionalLeftovers(deps, leftovers)
|
|
3838
|
+
deps.io.out('All set. Agents in this project can notify you and ask questions.')
|
|
3839
|
+
await deps.io.outro?.('All set ✨')
|
|
3840
|
+
return
|
|
3841
|
+
}
|
|
3842
|
+
await deps.io.note?.(`${blocker.title} — ${blocker.detail}\n${remedyLine(blocker)}`, 'Next')
|
|
3843
|
+
deps.io.out(`Next: ${blocker.title} — ${blocker.detail}`)
|
|
3844
|
+
deps.io.out(` ${remedyLine(blocker)}`)
|
|
3845
|
+
if (blocker.remedy?.by === 'user-elsewhere' || blocker.remedy?.by === 'user-here') {
|
|
3846
|
+
deps.io.out(' Then re-run `notifai init` and it will pick up from here.')
|
|
3847
|
+
}
|
|
3848
|
+
await deps.io.outro?.('One step remains (above)')
|
|
3849
|
+
return
|
|
3850
|
+
}
|
|
3851
|
+
|
|
3691
3852
|
if (blocker === null) {
|
|
3692
|
-
|
|
3693
|
-
(state) => !(state.id === 'skill' && flags.skills === false),
|
|
3694
|
-
)
|
|
3695
|
-
for (const state of skipped) deps.io.out(`Optional, not set up — ${remedyLine(state)}`)
|
|
3853
|
+
printOptionalLeftovers(deps, leftovers)
|
|
3696
3854
|
deps.io.out('All set. Agents in this project can notify you and ask questions.')
|
|
3697
|
-
|
|
3698
|
-
return failed ? EXIT.failed : EXIT.ok
|
|
3855
|
+
return
|
|
3699
3856
|
}
|
|
3700
|
-
|
|
3701
|
-
// Exactly one. Everything else waits until this is done, because the next
|
|
3702
|
-
// gap is frequently a consequence of this one and naming it now would send
|
|
3703
|
-
// the reader off to fix something that is not actually wrong.
|
|
3704
|
-
deps.io.out('')
|
|
3705
3857
|
deps.io.out(`Next: ${blocker.title} — ${blocker.detail}`)
|
|
3706
3858
|
deps.io.out(` ${remedyLine(blocker)}`)
|
|
3707
|
-
// Both "do it here" and "do it elsewhere" leave setup mid-journey; re-run is
|
|
3708
|
-
// how the rest is recovered either way.
|
|
3709
3859
|
if (blocker.remedy?.by === 'user-elsewhere' || blocker.remedy?.by === 'user-here') {
|
|
3710
3860
|
deps.io.out(' Then re-run `notifai init` and it will pick up from here.')
|
|
3711
3861
|
}
|
|
3712
|
-
await deps.io.outro?.('One step remains (above)')
|
|
3713
|
-
// An agent must be able to branch on setup being blocked without parsing
|
|
3714
|
-
// prose. A present human may deliberately leave and resume later.
|
|
3715
|
-
return failed || deps.io.interactive !== true ? EXIT.failed : EXIT.ok
|
|
3716
3862
|
}
|
|
3717
3863
|
|
|
3718
3864
|
// ---------------------------------------------------------------------------
|
|
@@ -3758,6 +3904,66 @@ async function contractCheck(client: ApiClient): Promise<{ name: string; ok: boo
|
|
|
3758
3904
|
}
|
|
3759
3905
|
}
|
|
3760
3906
|
|
|
3907
|
+
function projectReadiness(deps: CommandDeps, config: CliConfig): ReadinessState {
|
|
3908
|
+
const configPath = path.join(deps.cwd, '.notifai', 'config.toml')
|
|
3909
|
+
const projectSlug = config.project.value
|
|
3910
|
+
return projectSlug !== null
|
|
3911
|
+
? {
|
|
3912
|
+
id: 'project',
|
|
3913
|
+
title: 'Project identity',
|
|
3914
|
+
status: 'ready',
|
|
3915
|
+
detail: `"${projectSlug}" (${config.project.source})`,
|
|
3916
|
+
}
|
|
3917
|
+
: {
|
|
3918
|
+
id: 'project',
|
|
3919
|
+
title: 'Project identity',
|
|
3920
|
+
// Not a blocker: a send without a project simply carries no project
|
|
3921
|
+
// identity. init always sets one because it is free and reversible,
|
|
3922
|
+
// but an unlabelled setup works, so this must not go red.
|
|
3923
|
+
status: 'optional-gap',
|
|
3924
|
+
detail: `not set in ${configPath} — sends from here carry no project identity`,
|
|
3925
|
+
remedy: {
|
|
3926
|
+
by: 'cli',
|
|
3927
|
+
summary: 'name this project after its directory',
|
|
3928
|
+
command: 'notifai init',
|
|
3929
|
+
},
|
|
3930
|
+
}
|
|
3931
|
+
}
|
|
3932
|
+
|
|
3933
|
+
function remoteStatesFrom(previous: Readiness): {
|
|
3934
|
+
credential: ReadinessState
|
|
3935
|
+
server: ReadinessState
|
|
3936
|
+
contract: ReadinessState
|
|
3937
|
+
auth: ReadinessState
|
|
3938
|
+
devices: ReadinessState
|
|
3939
|
+
proof: ReadinessState
|
|
3940
|
+
} | null {
|
|
3941
|
+
const pick = (id: string): ReadinessState | undefined => previous.states.find((state) => state.id === id)
|
|
3942
|
+
const credential = pick('credential')
|
|
3943
|
+
const server = pick('server')
|
|
3944
|
+
const contract = pick('contract')
|
|
3945
|
+
const auth = pick('auth')
|
|
3946
|
+
const devices = pick('devices')
|
|
3947
|
+
const proof = pick('proof')
|
|
3948
|
+
if (
|
|
3949
|
+
credential === undefined ||
|
|
3950
|
+
server === undefined ||
|
|
3951
|
+
contract === undefined ||
|
|
3952
|
+
auth === undefined ||
|
|
3953
|
+
devices === undefined ||
|
|
3954
|
+
proof === undefined
|
|
3955
|
+
) {
|
|
3956
|
+
return null
|
|
3957
|
+
}
|
|
3958
|
+
return { credential, server, contract, auth, devices, proof }
|
|
3959
|
+
}
|
|
3960
|
+
|
|
3961
|
+
function remoteInvalidatedByConfig(previous: Readiness, config: CliConfig): boolean {
|
|
3962
|
+
if (config.base_url.source === 'default') return false
|
|
3963
|
+
const server = previous.states.find((state) => state.id === 'server')
|
|
3964
|
+
return server === undefined || !server.detail.includes(config.base_url.value)
|
|
3965
|
+
}
|
|
3966
|
+
|
|
3761
3967
|
/**
|
|
3762
3968
|
* Read the whole setup once, in dependency order.
|
|
3763
3969
|
*
|
|
@@ -3769,38 +3975,46 @@ async function contractCheck(client: ApiClient): Promise<{ name: string; ok: boo
|
|
|
3769
3975
|
*/
|
|
3770
3976
|
export async function assessReadiness(
|
|
3771
3977
|
deps: CommandDeps,
|
|
3772
|
-
options: {
|
|
3978
|
+
options: {
|
|
3979
|
+
skillScope?: SkillScope
|
|
3980
|
+
previous?: Readiness
|
|
3981
|
+
refresh?: readonly ReadinessRefresh[]
|
|
3982
|
+
} = {},
|
|
3773
3983
|
): Promise<Readiness> {
|
|
3774
3984
|
const config = loadLoggedConfig(deps, { cwd: deps.cwd, env: deps.env })
|
|
3985
|
+
const previous = options.previous
|
|
3986
|
+
const refresh = options.refresh
|
|
3987
|
+
if (previous !== undefined && refresh !== undefined && refresh.length === 0) return previous
|
|
3988
|
+
|
|
3989
|
+
const reuseRemote =
|
|
3990
|
+
previous !== undefined &&
|
|
3991
|
+
refresh !== undefined &&
|
|
3992
|
+
!refresh.includes('remote') &&
|
|
3993
|
+
!remoteInvalidatedByConfig(previous, config)
|
|
3994
|
+
if (reuseRemote) {
|
|
3995
|
+
const reused = remoteStatesFrom(previous)
|
|
3996
|
+
if (reused !== null) {
|
|
3997
|
+
return {
|
|
3998
|
+
states: [
|
|
3999
|
+
projectReadiness(deps, config),
|
|
4000
|
+
reused.credential,
|
|
4001
|
+
reused.server,
|
|
4002
|
+
reused.contract,
|
|
4003
|
+
reused.auth,
|
|
4004
|
+
...hookStates(deps),
|
|
4005
|
+
await skillReadiness(deps, options.skillScope),
|
|
4006
|
+
reused.devices,
|
|
4007
|
+
reused.proof,
|
|
4008
|
+
],
|
|
4009
|
+
}
|
|
4010
|
+
}
|
|
4011
|
+
}
|
|
4012
|
+
|
|
3775
4013
|
const states: ReadinessState[] = []
|
|
3776
4014
|
let accountClient: ApiClient | null = null
|
|
3777
4015
|
let accountDevices: RoutableDevice[] | null = null
|
|
3778
4016
|
|
|
3779
|
-
|
|
3780
|
-
const projectSlug = config.project.value
|
|
3781
|
-
states.push(
|
|
3782
|
-
projectSlug !== null
|
|
3783
|
-
? {
|
|
3784
|
-
id: 'project',
|
|
3785
|
-
title: 'Project identity',
|
|
3786
|
-
status: 'ready',
|
|
3787
|
-
detail: `"${projectSlug}" (${config.project.source})`,
|
|
3788
|
-
}
|
|
3789
|
-
: {
|
|
3790
|
-
id: 'project',
|
|
3791
|
-
title: 'Project identity',
|
|
3792
|
-
// Not a blocker: a send without a project simply carries no project
|
|
3793
|
-
// identity. init always sets one because it is free and reversible,
|
|
3794
|
-
// but an unlabelled setup works, so this must not go red.
|
|
3795
|
-
status: 'optional-gap',
|
|
3796
|
-
detail: `not set in ${configPath} — sends from here carry no project identity`,
|
|
3797
|
-
remedy: {
|
|
3798
|
-
by: 'cli',
|
|
3799
|
-
summary: 'name this project after its directory',
|
|
3800
|
-
command: 'notifai init',
|
|
3801
|
-
},
|
|
3802
|
-
},
|
|
3803
|
-
)
|
|
4017
|
+
states.push(projectReadiness(deps, config))
|
|
3804
4018
|
|
|
3805
4019
|
const credential = deps.store.load()
|
|
3806
4020
|
states.push(
|
|
@@ -3843,10 +4057,10 @@ export async function assessReadiness(
|
|
|
3843
4057
|
id: 'server',
|
|
3844
4058
|
title: 'Service',
|
|
3845
4059
|
status: 'gap',
|
|
3846
|
-
detail: `cannot reach ${baseUrl}
|
|
4060
|
+
detail: `cannot reach ${baseUrl}`,
|
|
3847
4061
|
remedy: {
|
|
3848
4062
|
by: 'user-here',
|
|
3849
|
-
summary: 'check your network
|
|
4063
|
+
summary: 'check your network',
|
|
3850
4064
|
command: 'notifai doctor',
|
|
3851
4065
|
},
|
|
3852
4066
|
},
|
|
@@ -4072,8 +4286,12 @@ async function setupProofState(
|
|
|
4072
4286
|
}
|
|
4073
4287
|
}
|
|
4074
4288
|
|
|
4075
|
-
export async function doctorCommand(
|
|
4076
|
-
|
|
4289
|
+
export async function doctorCommand(
|
|
4290
|
+
deps: CommandDeps,
|
|
4291
|
+
flags: { json?: boolean },
|
|
4292
|
+
options: { readiness?: Readiness } = {},
|
|
4293
|
+
): Promise<number> {
|
|
4294
|
+
const readiness = options.readiness ?? (await assessReadiness(deps))
|
|
4077
4295
|
const blocker = firstBlocker(readiness)
|
|
4078
4296
|
const ok = blocker === null
|
|
4079
4297
|
|
|
@@ -4317,6 +4535,21 @@ function hookChecks(deps: CommandDeps): HookCheck[] {
|
|
|
4317
4535
|
.join(', '),
|
|
4318
4536
|
})
|
|
4319
4537
|
|
|
4538
|
+
const wired = new Set(installations.map((installation) => installation.harness))
|
|
4539
|
+
const unwired = detectedHarnesses(deps.cwd, deps.env).filter((harness) => !wired.has(harness))
|
|
4540
|
+
if (unwired.length > 0) {
|
|
4541
|
+
checks.push({
|
|
4542
|
+
name: 'hooks (detected)',
|
|
4543
|
+
ok: false,
|
|
4544
|
+
informational: true,
|
|
4545
|
+
detail: `${unwired.map((harness) => HARNESS_LABEL[harness]).join(', ')} detected on this machine but not wired`,
|
|
4546
|
+
remedy: {
|
|
4547
|
+
summary: 'install hooks for every detected harness',
|
|
4548
|
+
command: 'notifai hooks install',
|
|
4549
|
+
},
|
|
4550
|
+
})
|
|
4551
|
+
}
|
|
4552
|
+
|
|
4320
4553
|
const { active, contested } = resolveActiveHarness(
|
|
4321
4554
|
deps.env,
|
|
4322
4555
|
deps.cwd,
|
|
@@ -4456,7 +4689,11 @@ function hookChecks(deps: CommandDeps): HookCheck[] {
|
|
|
4456
4689
|
harness,
|
|
4457
4690
|
installations: installations.filter((i) => i.harness === harness),
|
|
4458
4691
|
}))
|
|
4459
|
-
.filter(
|
|
4692
|
+
.filter(
|
|
4693
|
+
(entry) =>
|
|
4694
|
+
entry.installations.some((installation) => installation.global) &&
|
|
4695
|
+
entry.installations.some((installation) => !installation.global),
|
|
4696
|
+
)
|
|
4460
4697
|
if (duplicated.length > 0) {
|
|
4461
4698
|
checks.push({
|
|
4462
4699
|
name: 'hooks (duplicates)',
|
|
@@ -4470,6 +4707,26 @@ function hookChecks(deps: CommandDeps): HookCheck[] {
|
|
|
4470
4707
|
})
|
|
4471
4708
|
}
|
|
4472
4709
|
|
|
4710
|
+
const representationProblems = codexRepresentationProblems(deps.cwd, deps.env)
|
|
4711
|
+
if (representationProblems.length > 0) {
|
|
4712
|
+
const collapseCommand = representationProblems.some((problem) => problem.includes('--global'))
|
|
4713
|
+
? 'notifai hooks install --harness codex --global'
|
|
4714
|
+
: 'notifai hooks install --harness codex'
|
|
4715
|
+
checks.push({
|
|
4716
|
+
name: 'hooks (codex representation)',
|
|
4717
|
+
ok: false,
|
|
4718
|
+
detail: representationProblems.join('; '),
|
|
4719
|
+
...(representationProblems.some((problem) => problem.includes('to collapse onto'))
|
|
4720
|
+
? {
|
|
4721
|
+
remedy: {
|
|
4722
|
+
summary: 'collapse this Codex layer onto a single hook file',
|
|
4723
|
+
command: collapseCommand,
|
|
4724
|
+
},
|
|
4725
|
+
}
|
|
4726
|
+
: {}),
|
|
4727
|
+
})
|
|
4728
|
+
}
|
|
4729
|
+
|
|
4473
4730
|
if (active !== null && activeInstallations.length > 0) {
|
|
4474
4731
|
const admissionProblems = activeQuestionRouteProblems(deps, active, installations)
|
|
4475
4732
|
checks.push({
|
|
@@ -4669,14 +4926,19 @@ function codexStrayWorktreeCheck(
|
|
|
4669
4926
|
const layer = codexLayerDir(deps.cwd)
|
|
4670
4927
|
if (layer === null) return null
|
|
4671
4928
|
const root = codexProjectRoot(deps.cwd)
|
|
4672
|
-
const
|
|
4673
|
-
if (
|
|
4929
|
+
const project = inspectCodexLayer(codexLayerPaths(false, deps.cwd, deps.env))
|
|
4930
|
+
if (project.jsonEvents.length === 0 && project.tomlEvents.length === 0) return null
|
|
4931
|
+
const strayJson = path.join(path.dirname(layer), '.codex', 'hooks.json')
|
|
4932
|
+
const strayToml = path.join(path.dirname(layer), '.codex', 'config.toml')
|
|
4674
4933
|
const problems: string[] = []
|
|
4675
4934
|
if (!existsSync(layer)) {
|
|
4676
4935
|
problems.push(`${layer} is missing, so Codex never looks for project hooks here`)
|
|
4677
4936
|
}
|
|
4678
|
-
if (existsSync(
|
|
4679
|
-
problems.push(`${
|
|
4937
|
+
if (existsSync(strayJson) && path.resolve(strayJson) !== path.resolve(project.paths.hooksJson)) {
|
|
4938
|
+
problems.push(`${strayJson} is never read — Codex reads ${project.writeTarget} instead`)
|
|
4939
|
+
}
|
|
4940
|
+
if (existsSync(strayToml) && path.resolve(strayToml) !== path.resolve(project.paths.configToml)) {
|
|
4941
|
+
problems.push(`${strayToml} is never read — Codex reads ${project.writeTarget} instead`)
|
|
4680
4942
|
}
|
|
4681
4943
|
return {
|
|
4682
4944
|
name: 'hooks (codex worktree)',
|
|
@@ -4741,6 +5003,17 @@ export function realIo(env: NodeJS.ProcessEnv = process.env): CommandIo {
|
|
|
4741
5003
|
const answer = await p.select({ message, options })
|
|
4742
5004
|
return p.isCancel(answer) ? null : (answer as string)
|
|
4743
5005
|
},
|
|
5006
|
+
multiselect: async (message, options, initial) => {
|
|
5007
|
+
if (!interactive()) return null
|
|
5008
|
+
const p = await clack()
|
|
5009
|
+
const answer = await p.multiselect({
|
|
5010
|
+
message,
|
|
5011
|
+
options,
|
|
5012
|
+
required: true,
|
|
5013
|
+
...(initial !== undefined && initial.length > 0 ? { initialValues: initial } : {}),
|
|
5014
|
+
})
|
|
5015
|
+
return p.isCancel(answer) ? null : (answer as string[])
|
|
5016
|
+
},
|
|
4744
5017
|
intro: async (title) => {
|
|
4745
5018
|
if (!interactive()) return
|
|
4746
5019
|
;(await clack()).intro(title)
|