()
| 121 | } |
| 122 | |
| 123 | async function start(): Promise<LifecycleResult> { |
| 124 | const plistPath = deps.plistPath(); |
| 125 | if (!existsSync(plistPath)) { |
| 126 | return { |
| 127 | ok: false, |
| 128 | message: 'LaunchAgent is not installed. Run `kimi server install` first.', |
| 129 | }; |
| 130 | } |
| 131 | const target = `${deps.guiDomain()}/${KIMI_SERVER_LABEL}`; |
| 132 | |
| 133 | const result = await deps.execLaunchctl(['kickstart', '-k', target]); |
| 134 | if (result.code !== 0) { |
| 135 | |
| 136 | const bootstrap = await deps.execLaunchctl(['bootstrap', deps.guiDomain(), plistPath]); |
| 137 | if (bootstrap.code !== 0 && !isAlreadyLoaded(bootstrap)) { |
| 138 | return { |
| 139 | ok: false, |
| 140 | message: `launchctl kickstart + bootstrap both failed: ${detail(result) ?? 'unknown'} / ${detail(bootstrap) ?? 'unknown'}`, |
| 141 | }; |
| 142 | } |
| 143 | const retry = await deps.execLaunchctl(['kickstart', target]); |
| 144 | if (retry.code !== 0) { |
| 145 | return { |
| 146 | ok: false, |
| 147 | message: `launchctl kickstart failed after bootstrap: ${detail(retry) ?? 'unknown error'}`, |
| 148 | }; |
| 149 | } |
| 150 | } |
| 151 | return { ok: true, message: `Kimi server started (${KIMI_SERVER_LABEL}).` }; |
| 152 | } |
| 153 | |
| 154 | async function stop(): Promise<LifecycleResult> { |
| 155 | const target = `${deps.guiDomain()}/${KIMI_SERVER_LABEL}`; |
nothing calls this directly
no test coverage detected