BREAKING CHANGE(daemon): Refactor daemon and service management: remove IPC auto-spawn, add TspmServiceManager, tighten IPC/client/CLI behavior and tests

This commit is contained in:
2025-08-28 15:52:29 +00:00
parent 8e3cfb624b
commit e73f4acd63
38 changed files with 810 additions and 580 deletions

View File

@@ -1,5 +1,9 @@
import * as plugins from '../../plugins.js';
import type { CliArguments, CommandAction, IpcCommandOptions } from '../types.js';
import type {
CliArguments,
CommandAction,
IpcCommandOptions,
} from '../types.js';
import { handleDaemonError } from '../helpers/errors.js';
import { unknownError } from '../helpers/formatting.js';
import { runIpcCommand } from '../utils/ipc.js';
@@ -15,7 +19,7 @@ export function registerIpcCommand(
smartcli: plugins.smartcli.Smartcli,
name: string,
action: CommandAction,
opts: IpcCommandOptions = {}
opts: IpcCommandOptions = {},
) {
const { actionLabel = name, keepAlive = false, requireDaemon = true } = opts;
@@ -29,7 +33,8 @@ export function registerIpcCommand(
}
// Evaluate keepAlive - can be boolean or function
const shouldKeepAlive = typeof keepAlive === 'function' ? keepAlive(argv) : keepAlive;
const shouldKeepAlive =
typeof keepAlive === 'function' ? keepAlive(argv) : keepAlive;
if (shouldKeepAlive) {
// Let action manage its own connection/cleanup lifecycle
@@ -51,7 +56,10 @@ export function registerIpcCommand(
},
error: (err) => {
// Fallback error path (should be rare with try/catch in next)
console.error(`Unexpected error in command "${name}":`, unknownError(err));
console.error(
`Unexpected error in command "${name}":`,
unknownError(err),
);
process.exit(1);
},
complete: () => {},
@@ -66,7 +74,7 @@ export function registerLocalCommand(
smartcli: plugins.smartcli.Smartcli,
name: string,
action: (argv: CliArguments) => Promise<void>,
opts: { actionLabel?: string } = {}
opts: { actionLabel?: string } = {},
) {
const { actionLabel = name } = opts;
smartcli.addCommand(name).subscribe({
@@ -79,9 +87,12 @@ export function registerLocalCommand(
}
},
error: (err) => {
console.error(`Unexpected error in command "${name}":`, unknownError(err));
console.error(
`Unexpected error in command "${name}":`,
unknownError(err),
);
process.exit(1);
},
complete: () => {},
});
}
}