|
1 | 1 | import type { DaemonIdentity } from '@agent-device/contracts/client'; |
2 | 2 | import { |
3 | 3 | DAEMON_QUIESCE_REASONS, |
4 | | - resolveDaemonPaths, |
| 4 | + type DaemonPaths, |
5 | 5 | type DaemonQuiesceCensus, |
6 | 6 | } from '@agent-device/daemon-contracts/daemon-resolution'; |
| 7 | +import type { DaemonRetirementResult } from '@agent-device/daemon-contracts/daemon-registration-owner'; |
7 | 8 | import { AppError } from '@agent-device/kernel/errors'; |
8 | 9 | import { shellQuoteIfNeeded } from '@agent-device/kernel/device-shell'; |
9 | 10 | import { readVersion } from '@agent-device/host-kit/version'; |
10 | 11 | import type { DaemonClientSettings } from './daemon-client-lifecycle.ts'; |
11 | | -import type { DaemonInfo } from './daemon-client-metadata.ts'; |
| 12 | +import { |
| 13 | + getDaemonMetadataState, |
| 14 | + resolveDaemonStartupHint, |
| 15 | + type DaemonInfo, |
| 16 | +} from './daemon-client-metadata.ts'; |
12 | 17 | import { resolveLocalDaemonCodeIdentity, type DaemonTakeoverCause } from './daemon-launch-spec.ts'; |
13 | 18 |
|
14 | 19 | // The four ways an explicit lifecycle stops short of a usable daemon. Callers branch on |
@@ -58,15 +63,22 @@ export function daemonContendedError(): AppError { |
58 | 63 | } |
59 | 64 |
|
60 | 65 | export function daemonNotRunningError(stateDir: string, registered?: DaemonInfo): AppError { |
61 | | - const stateDirFlag = |
62 | | - stateDir === resolveDaemonPaths(undefined).baseDir |
63 | | - ? '' |
64 | | - : ` --state-dir ${shellQuoteIfNeeded(stateDir)}`; |
65 | 66 | return new AppError('COMMAND_FAILED', 'No daemon is running for this state directory.', { |
66 | 67 | reason: DAEMON_LIFECYCLE_REASONS.notRunning, |
67 | 68 | stateDir, |
68 | 69 | ...(registered ? { daemon: daemonIdentityOf(registered) } : {}), |
69 | | - hint: `Start one with a local agent-device command that uses the daemon (agent-device devices${stateDirFlag}, for example), or with ensureDaemon({ stateDir: ${JSON.stringify(stateDir)} }) from the SDK, before attaching.${registered ? ` The registered daemon (pid ${registered.pid}) does not answer; ${daemonStopCommand(stateDir)} clears it.` : ''}`, |
| 70 | + hint: `Start one with a local agent-device command that uses the daemon (agent-device devices --state-dir ${shellQuoteIfNeeded(stateDir)}, for example), or with ensureDaemon({ stateDir: ${JSON.stringify(stateDir)} }) from the SDK, before attaching.${registered ? ` The registered daemon (pid ${registered.pid}) does not answer; ${daemonStopCommand(stateDir)} clears it.` : ''}`, |
| 71 | + }); |
| 72 | +} |
| 73 | + |
| 74 | +export function daemonRetirementUnconfirmedError( |
| 75 | + retirement: Extract<DaemonRetirementResult, { status: 'retained' }>, |
| 76 | + paths: DaemonPaths, |
| 77 | +): AppError { |
| 78 | + return new AppError('COMMAND_FAILED', 'Daemon replacement could not be confirmed.', { |
| 79 | + reason: 'daemon_retirement_unconfirmed', |
| 80 | + retirement, |
| 81 | + hint: retirement.error?.hint ?? resolveDaemonStartupHint(getDaemonMetadataState(paths), paths), |
70 | 82 | }); |
71 | 83 | } |
72 | 84 |
|
|
0 commit comments