@mebular/mcp 0.1.2 → 0.2.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/bin/mebular.mjs CHANGED
@@ -19,7 +19,13 @@ function parseFlags(list) {
19
19
  for (let i = 0; i < list.length; i++) {
20
20
  const token = list[i];
21
21
  if (token.startsWith('--')) {
22
- const key = token.slice(2);
22
+ const body = token.slice(2);
23
+ const eq = body.indexOf('=');
24
+ if (eq >= 0) {
25
+ flags[body.slice(0, eq)] = body.slice(eq + 1);
26
+ continue;
27
+ }
28
+ const key = body;
23
29
  const next = list[i + 1];
24
30
  if (next === undefined || next.startsWith('--')) flags[key] = true;
25
31
  else {
@@ -996,6 +1002,477 @@ async function runCloud(action, args, flags) {
996
1002
  process.exit(2);
997
1003
  }
998
1004
 
1005
+ // ---------- 共享 runtime:resolve / ensure / status + provider 注册表 ----------
1006
+
1007
+ function runtimeCliError(error) {
1008
+ return {
1009
+ ok: false,
1010
+ mode: 'error',
1011
+ reason: error?.code ?? 'error',
1012
+ message: error?.message ?? String(error),
1013
+ };
1014
+ }
1015
+
1016
+ function printRuntimeJson(value, exitCode = 0) {
1017
+ console.log(JSON.stringify(value, null, 2));
1018
+ process.exit(exitCode);
1019
+ }
1020
+
1021
+ async function runtimeRootForCli() {
1022
+ const { resolveCloudRoot } = await import('../src/profiles.mjs');
1023
+ const cloud = resolveCloudRoot({ env: process.env });
1024
+ if (!cloud.available) {
1025
+ const error = new Error(`runtime 上下文不可用(${cloud.reason ?? 'cloud_unavailable'})`);
1026
+ error.code = 'CLOUD_UNAVAILABLE';
1027
+ throw error;
1028
+ }
1029
+ return cloud.root;
1030
+ }
1031
+
1032
+ async function runRuntimeProvider(args, flags) {
1033
+ const { listRuntimeProviders, registerRuntimeProvider, removeRuntimeProvider } = await import('../src/runtime-providers.mjs');
1034
+ const root = await runtimeRootForCli();
1035
+ const sub = args[0];
1036
+ if (sub === 'list') {
1037
+ const state = await listRuntimeProviders(root);
1038
+ printRuntimeJson({
1039
+ ok: true,
1040
+ root,
1041
+ source: state.source,
1042
+ providers: state.providers,
1043
+ warnings: state.warnings,
1044
+ });
1045
+ return;
1046
+ }
1047
+ if (sub === 'add') {
1048
+ if (typeof flags.kind !== 'string' || typeof flags.path !== 'string') {
1049
+ const error = new Error('用法:mebular runtime provider add --kind app|cli|shared --path <abs> [--version V] [--capabilities a,b]');
1050
+ error.code = 'USAGE';
1051
+ throw error;
1052
+ }
1053
+ if (!existsSync(flags.path)) {
1054
+ const error = new Error(`provider 路径不存在:${flags.path}`);
1055
+ error.code = 'PROVIDER_PATH_MISSING';
1056
+ throw error;
1057
+ }
1058
+ const capabilities = typeof flags.capabilities === 'string'
1059
+ ? flags.capabilities.split(',').map((item) => item.trim()).filter(Boolean)
1060
+ : [];
1061
+ const result = await registerRuntimeProvider(root, {
1062
+ kind: flags.kind,
1063
+ path: flags.path,
1064
+ version: typeof flags.version === 'string' ? flags.version : null,
1065
+ capabilities,
1066
+ });
1067
+ printRuntimeJson({
1068
+ ok: true,
1069
+ root,
1070
+ created: result.created,
1071
+ provider: { ...result.provider, available: true },
1072
+ warnings: result.warnings,
1073
+ });
1074
+ return;
1075
+ }
1076
+ if (sub === 'remove') {
1077
+ const result = await removeRuntimeProvider(root, {
1078
+ id: typeof flags.id === 'string' ? flags.id : undefined,
1079
+ kind: typeof flags.kind === 'string' ? flags.kind : undefined,
1080
+ path: typeof flags.path === 'string' ? flags.path : undefined,
1081
+ });
1082
+ printRuntimeJson({
1083
+ ok: true,
1084
+ root,
1085
+ removed: result.removed,
1086
+ warnings: result.warnings,
1087
+ });
1088
+ return;
1089
+ }
1090
+ const error = new Error('用法:mebular runtime provider <list|add|remove> [--kind ...] [--path ...] [--id ...]');
1091
+ error.code = 'USAGE';
1092
+ throw error;
1093
+ }
1094
+
1095
+ async function runRuntimeInstall(action, flags) {
1096
+ const controller = new AbortController();
1097
+ const onSignal = () => controller.abort();
1098
+ process.once('SIGINT', onSignal);
1099
+ process.once('SIGTERM', onSignal);
1100
+
1101
+ let result;
1102
+ try {
1103
+ const { installRuntime } = await import('../src/runtime-installer.mjs');
1104
+ let home;
1105
+ try {
1106
+ // 只用于检测是否有正在运行的 daemon/service;失败不影响安装。
1107
+ const { resolveRuntimeContext } = await import('../src/runtime-supervisor.mjs');
1108
+ const context = await resolveRuntimeContext({ env: process.env });
1109
+ if (context.ok) home = context.home;
1110
+ } catch {
1111
+ home = undefined;
1112
+ }
1113
+ const inlineVersion = process.argv.slice(2).find((token) => token.startsWith('--version='));
1114
+ const requestedVersion = inlineVersion === undefined
1115
+ ? flags.version
1116
+ : inlineVersion.slice('--version='.length);
1117
+ result = await installRuntime({
1118
+ version: requestedVersion,
1119
+ reinstall: action === 'reinstall',
1120
+ home,
1121
+ env: process.env,
1122
+ signal: controller.signal,
1123
+ });
1124
+ } catch (error) {
1125
+ result = {
1126
+ ok: false,
1127
+ code: error?.code ?? 'install_failed',
1128
+ reason: error?.code ?? 'install_failed',
1129
+ message: `runtime 安装失败(${error?.code ?? 'install_failed'})`,
1130
+ command: action,
1131
+ version: null,
1132
+ manualCommand: null,
1133
+ runtimeInstalled: false,
1134
+ providerRegistered: false,
1135
+ };
1136
+ } finally {
1137
+ process.removeListener('SIGINT', onSignal);
1138
+ process.removeListener('SIGTERM', onSignal);
1139
+ }
1140
+ printRuntimeJson(result, result.ok ? 0 : 2);
1141
+ }
1142
+
1143
+ async function runRuntimeCurrent(args, flags) {
1144
+ const { readRuntimeCurrent, writeRuntimeCurrent, clearRuntimeCurrent, publicRuntimeCurrent } = await import('../src/runtime-current.mjs');
1145
+ const root = await runtimeRootForCli();
1146
+ const sub = args[0];
1147
+ if (sub === 'show' || sub === undefined) {
1148
+ const state = await readRuntimeCurrent(root);
1149
+ printRuntimeJson({
1150
+ ok: true,
1151
+ root,
1152
+ current: publicRuntimeCurrent(state.current),
1153
+ usable: state.usable === true,
1154
+ source: state.source,
1155
+ warnings: state.warnings,
1156
+ });
1157
+ return;
1158
+ }
1159
+ if (sub === 'set') {
1160
+ if (typeof flags.version !== 'string' || typeof flags['runtime-path'] !== 'string' || typeof flags.cli !== 'string') {
1161
+ const error = new Error('用法:mebular runtime current set --version V --runtime-path P --cli C [--provider shared] [--owner O] [--installed-at ISO] [--json]');
1162
+ error.code = 'USAGE';
1163
+ throw error;
1164
+ }
1165
+ const current = await writeRuntimeCurrent(root, {
1166
+ version: flags.version,
1167
+ runtimePath: flags['runtime-path'],
1168
+ cliPath: flags.cli,
1169
+ provider: typeof flags.provider === 'string' ? flags.provider : 'shared',
1170
+ owner: typeof flags.owner === 'string' ? flags.owner : 'shared',
1171
+ ...(typeof flags['installed-at'] === 'string' ? { installedAt: flags['installed-at'] } : {}),
1172
+ });
1173
+ printRuntimeJson({ ok: true, root, current });
1174
+ return;
1175
+ }
1176
+ if (sub === 'clear') {
1177
+ const cleared = await clearRuntimeCurrent(root);
1178
+ printRuntimeJson({ ok: true, root, cleared });
1179
+ return;
1180
+ }
1181
+ const error = new Error('用法:mebular runtime current <show|set|clear> [--version V --runtime-path P --cli C] [--json]');
1182
+ error.code = 'USAGE';
1183
+ throw error;
1184
+ }
1185
+
1186
+ async function runtimeContextForService() {
1187
+ const { resolveRuntimeContext } = await import('../src/runtime-supervisor.mjs');
1188
+ const context = await resolveRuntimeContext({ env: process.env });
1189
+ if (!context.ok) {
1190
+ const error = new Error(`runtime 上下文不可用(${context.reason ?? 'cloud_unavailable'})`);
1191
+ error.code = context.reason ?? 'CLOUD_UNAVAILABLE';
1192
+ throw error;
1193
+ }
1194
+ return context;
1195
+ }
1196
+
1197
+ async function runRuntimeService(action) {
1198
+ if (!['install', 'uninstall', 'restart', 'status'].includes(action)) {
1199
+ const error = new Error('用法:mebular runtime service <install|uninstall|restart|status> [--json]');
1200
+ error.code = 'USAGE';
1201
+ throw error;
1202
+ }
1203
+ const context = await runtimeContextForService();
1204
+ const {
1205
+ installRuntimeService,
1206
+ restartRuntimeService,
1207
+ runtimeServiceStatus,
1208
+ uninstallRuntimeService,
1209
+ } = await import('../src/runtime-service.mjs');
1210
+ const common = {
1211
+ root: context.cloudRoot,
1212
+ home: context.home,
1213
+ env: process.env,
1214
+ };
1215
+ let result;
1216
+ if (action === 'install') {
1217
+ result = await installRuntimeService({ ...common, http: context.http });
1218
+ printRuntimeJson({ ...result, action }, result.ok ? 0 : 2);
1219
+ return;
1220
+ }
1221
+ if (action === 'uninstall') {
1222
+ result = await uninstallRuntimeService(common);
1223
+ printRuntimeJson({ ...result, action }, result.ok ? 0 : 2);
1224
+ return;
1225
+ }
1226
+ if (action === 'restart') {
1227
+ result = await restartRuntimeService(common);
1228
+ printRuntimeJson({ ...result, action }, result.ok ? 0 : 2);
1229
+ return;
1230
+ }
1231
+ result = await runtimeServiceStatus(common);
1232
+ printRuntimeJson({ ...result, action }, result.ok ? 0 : 2);
1233
+ }
1234
+
1235
+ async function detectRunningRuntimeVersion() {
1236
+ try {
1237
+ const { resolveRuntimeContext, probeRuntimeHealth } = await import('../src/runtime-supervisor.mjs');
1238
+ const context = await resolveRuntimeContext({ env: process.env });
1239
+ if (!context.ok || !context.http) return null;
1240
+ const health = await probeRuntimeHealth(fetch, context.http, {
1241
+ expectedInstance: context.homeKey,
1242
+ cloudId: context.profileId,
1243
+ timeoutMs: 800,
1244
+ });
1245
+ return health?.ok === true ? (health.body?.version ?? null) : null;
1246
+ } catch {
1247
+ return null;
1248
+ }
1249
+ }
1250
+
1251
+ async function runRuntimeCheckUpdate(flags) {
1252
+ const { checkRuntimeUpdate, runtimeUpdateExitCode } = await import('../src/runtime-update.mjs');
1253
+ const result = await checkRuntimeUpdate({
1254
+ env: process.env,
1255
+ force: flags.force === true,
1256
+ entry: 'cli',
1257
+ detectRunningVersion: detectRunningRuntimeVersion,
1258
+ });
1259
+ printRuntimeJson(result, runtimeUpdateExitCode(result));
1260
+ }
1261
+
1262
+ async function runRuntimeUpdateState(args, flags = {}) {
1263
+ const sub = args[0] ?? 'show';
1264
+ const {
1265
+ publicRuntimeUpdateState,
1266
+ readRuntimeUpdateState,
1267
+ runtimeUpdateStatePath,
1268
+ setRuntimeUpdatePromptedVersion,
1269
+ setRuntimeUpdateSkippedVersion,
1270
+ } = await import('../src/runtime-update.mjs');
1271
+ const root = await runtimeRootForCli();
1272
+ if (sub === 'skip' || sub === 'prompted') {
1273
+ if (typeof flags.version !== 'string' || flags.version.length === 0) {
1274
+ const error = new Error(`用法:mebular runtime update-state ${sub} --version V [--json]`);
1275
+ error.code = 'USAGE';
1276
+ throw error;
1277
+ }
1278
+ const result = sub === 'skip'
1279
+ ? await setRuntimeUpdateSkippedVersion(root, flags.version)
1280
+ : await setRuntimeUpdatePromptedVersion(root, flags.version);
1281
+ printRuntimeJson({
1282
+ ok: true,
1283
+ root,
1284
+ path: runtimeUpdateStatePath(root),
1285
+ source: result.source,
1286
+ state: publicRuntimeUpdateState(result.state),
1287
+ warnings: result.warnings,
1288
+ });
1289
+ return;
1290
+ }
1291
+ if (sub !== 'show') {
1292
+ const error = new Error('用法:mebular runtime update-state <show|skip|prompted> [--version V] [--json]');
1293
+ error.code = 'USAGE';
1294
+ throw error;
1295
+ }
1296
+ const state = await readRuntimeUpdateState(root);
1297
+ printRuntimeJson({
1298
+ ok: true,
1299
+ root,
1300
+ path: runtimeUpdateStatePath(root),
1301
+ source: state.source,
1302
+ state: publicRuntimeUpdateState(state.state),
1303
+ warnings: state.warnings,
1304
+ });
1305
+ }
1306
+
1307
+ async function runRuntimeUpgradeState(args) {
1308
+ const sub = args[0] ?? 'show';
1309
+ if (sub !== 'show') {
1310
+ const error = new Error('用法:mebular runtime upgrade-state show [--json]');
1311
+ error.code = 'USAGE';
1312
+ throw error;
1313
+ }
1314
+ const {
1315
+ inspectRuntimeUpgradeLock,
1316
+ publicRuntimeUpgradeState,
1317
+ readRuntimeUpgradeState,
1318
+ runtimeUpgradeStatePath,
1319
+ } = await import('../src/runtime-upgrade.mjs');
1320
+ const root = await runtimeRootForCli();
1321
+ const [state, lock] = await Promise.all([
1322
+ readRuntimeUpgradeState(root),
1323
+ inspectRuntimeUpgradeLock(root),
1324
+ ]);
1325
+ printRuntimeJson({
1326
+ ok: true,
1327
+ root,
1328
+ path: runtimeUpgradeStatePath(root),
1329
+ source: state.source,
1330
+ state: publicRuntimeUpgradeState(state.state),
1331
+ lock: {
1332
+ busy: lock.busy === true,
1333
+ stale: lock.stale !== false,
1334
+ holder: lock.holder ?? null,
1335
+ },
1336
+ warnings: state.warnings,
1337
+ });
1338
+ }
1339
+
1340
+ /** `--to latest`:只接受共享 check 缓存里的 stable 目标,不接受任意 URL/registry。 */
1341
+ async function resolveUpgradeTarget(to) {
1342
+ if (to !== 'latest') return { target: to, check: null };
1343
+ const { checkRuntimeUpdate } = await import('../src/runtime-update.mjs');
1344
+ const check = await checkRuntimeUpdate({
1345
+ env: process.env,
1346
+ entry: 'cli',
1347
+ detectRunningVersion: detectRunningRuntimeVersion,
1348
+ });
1349
+ if (check.available !== true || typeof check.latestVersion !== 'string') {
1350
+ return {
1351
+ target: null,
1352
+ check,
1353
+ error: {
1354
+ ok: false,
1355
+ action: 'upgrade',
1356
+ command: 'upgrade',
1357
+ reason: check.reason ?? check.decision ?? check.status ?? 'no_update_available',
1358
+ message: check.message ?? '没有可用的共享 runtime 更新;请先运行 runtime check-update',
1359
+ to: 'latest',
1360
+ status: check.status,
1361
+ currentVersion: check.currentVersion ?? null,
1362
+ latestVersion: check.latestVersion ?? null,
1363
+ available: false,
1364
+ busy: check.busy === true,
1365
+ runtimeChanged: false,
1366
+ serviceChanged: false,
1367
+ },
1368
+ };
1369
+ }
1370
+ return { target: check.latestVersion, check };
1371
+ }
1372
+
1373
+ async function runRuntimeUpgrade(flags) {
1374
+ const { upgradeRuntime } = await import('../src/runtime-upgrade.mjs');
1375
+ const context = await runtimeContextForService().catch(() => null);
1376
+ const requested = typeof flags.to === 'string' ? flags.to : undefined;
1377
+ const resolved = await resolveUpgradeTarget(requested);
1378
+ if (resolved.error) {
1379
+ printRuntimeJson(resolved.error, 2);
1380
+ return;
1381
+ }
1382
+ const result = await upgradeRuntime({
1383
+ to: resolved.target,
1384
+ entry: 'cli',
1385
+ env: process.env,
1386
+ ...(context ? { root: context.cloudRoot, home: context.home } : {}),
1387
+ });
1388
+ printRuntimeJson(result, result.ok ? 0 : 2);
1389
+ }
1390
+
1391
+ async function runRuntime(action, args, flags) {
1392
+ try {
1393
+ if (action === 'provider') {
1394
+ await runRuntimeProvider(args, flags);
1395
+ return;
1396
+ }
1397
+ if (action === 'current') {
1398
+ await runRuntimeCurrent(args, flags);
1399
+ return;
1400
+ }
1401
+ if (action === 'service') {
1402
+ await runRuntimeService(args[0], flags);
1403
+ return;
1404
+ }
1405
+ if (action === 'upgrade') {
1406
+ await runRuntimeUpgrade(flags);
1407
+ return;
1408
+ }
1409
+ if (action === 'upgrade-state') {
1410
+ await runRuntimeUpgradeState(args);
1411
+ return;
1412
+ }
1413
+ if (action === 'check-update') {
1414
+ await runRuntimeCheckUpdate(flags);
1415
+ return;
1416
+ }
1417
+ if (action === 'update-state') {
1418
+ await runRuntimeUpdateState(args, flags);
1419
+ return;
1420
+ }
1421
+ if (action === 'install' || action === 'reinstall') {
1422
+ await runRuntimeInstall(action, flags);
1423
+ return;
1424
+ }
1425
+ if (action === 'resolve' || action === 'ensure' || action === 'status' || action === 'supervise') {
1426
+ const {
1427
+ ensureRuntime,
1428
+ resolveRuntime,
1429
+ runtimeStatus,
1430
+ superviseRuntime,
1431
+ toPublicRuntimeResult,
1432
+ } = await import('../src/runtime-supervisor.mjs');
1433
+ const mode = typeof flags.start === 'string' ? flags.start : 'auto';
1434
+ const options = { env: process.env, mode, allowDownload: false };
1435
+ if (flags.port !== undefined) {
1436
+ const port = Number(flags.port);
1437
+ if (!Number.isInteger(port) || port <= 0 || port > 65535) {
1438
+ const error = new Error(`端口非法:${flags.port}`);
1439
+ error.code = 'INVALID_PORT';
1440
+ throw error;
1441
+ }
1442
+ options.port = port;
1443
+ }
1444
+ if (action === 'resolve') {
1445
+ const result = await resolveRuntime(options);
1446
+ printRuntimeJson(toPublicRuntimeResult(result), result.ok ? 0 : 2);
1447
+ }
1448
+ if (action === 'status') {
1449
+ const result = await runtimeStatus(options);
1450
+ printRuntimeJson(toPublicRuntimeResult(result), result.ok ? 0 : 2);
1451
+ }
1452
+ if (action === 'supervise') {
1453
+ // 入口所有权路径:前台持有 child;SIGTERM/SIGINT 时只停止自己拉起的 child。
1454
+ const exitCode = await superviseRuntime({ ...options, detached: false });
1455
+ process.exit(exitCode);
1456
+ }
1457
+ // ensure 默认成为 detached child 的 owner;CLI 退出后 daemon 继续运行。
1458
+ // 这是人工/诊断路径;入口(App/Plugin)不得依赖它拥有 child。
1459
+ options.detached = true;
1460
+ const result = await ensureRuntime(options);
1461
+ if (result.ok && result.mode === 'child') {
1462
+ console.error('note: runtime ensure 以 detached 方式启动 child(诊断用途);入口请使用 mebular runtime supervise 持有 child');
1463
+ }
1464
+ printRuntimeJson(toPublicRuntimeResult(result), result.ok ? 0 : 2);
1465
+ }
1466
+ const error = new Error(
1467
+ '用法:mebular runtime <resolve|ensure|status|supervise|provider|install|reinstall|current|service|upgrade|upgrade-state|check-update|update-state> [--start auto|child|service] [--port N] [--version V] [--to V|latest] [--force] [--json]',
1468
+ );
1469
+ error.code = 'USAGE';
1470
+ throw error;
1471
+ } catch (error) {
1472
+ printRuntimeJson(runtimeCliError(error), 2);
1473
+ }
1474
+ }
1475
+
999
1476
  async function main() {
1000
1477
  const flags = parseFlags(argv.slice(1));
1001
1478
  switch (command) {
@@ -1017,7 +1494,8 @@ async function main() {
1017
1494
  const httpConf = fileConfig.mcp?.http ?? {};
1018
1495
  // D4:常驻进程写 service.heartbeat(role=mebular-serve),供 `service status`/doctor 判定。
1019
1496
  try {
1020
- const { startHeartbeat, resolveBuildSha } = await import('@mebular/service');
1497
+ const { loadServiceModule } = await import('../src/service-loader.mjs');
1498
+ const { startHeartbeat, resolveBuildSha } = await loadServiceModule();
1021
1499
  startHeartbeat(homeDir(), { role: 'mebular-serve', sha: resolveBuildSha() });
1022
1500
  } catch {
1023
1501
  // service 包缺失不应阻止 serve。
@@ -1044,7 +1522,15 @@ async function main() {
1044
1522
  return;
1045
1523
  }
1046
1524
  case 'service': {
1047
- const { runServiceCli } = await import('@mebular/service');
1525
+ const { loadServiceModule } = await import('../src/service-loader.mjs');
1526
+ let serviceLib;
1527
+ try {
1528
+ serviceLib = await loadServiceModule();
1529
+ } catch (error) {
1530
+ console.error(`✗ service 不可用(${error?.code ?? 'ERROR'}):${error?.message ?? error}`);
1531
+ process.exit(2);
1532
+ }
1533
+ const { runServiceCli } = serviceLib;
1048
1534
  const home = homeDir();
1049
1535
  const bin = process.argv[1];
1050
1536
  const descriptor = {
@@ -1065,6 +1551,10 @@ async function main() {
1065
1551
  await runCloud(argv[1], argv.slice(2), flags);
1066
1552
  return;
1067
1553
  }
1554
+ case 'runtime': {
1555
+ await runRuntime(argv[1], argv.slice(2), flags);
1556
+ return;
1557
+ }
1068
1558
  case 'token': {
1069
1559
  await runToken(argv[1], flags, argv[2]);
1070
1560
  return;
@@ -1082,6 +1572,17 @@ async function main() {
1082
1572
  ' service install|uninstall|restart|status|logs [--no-autostart --label L] 常驻服务管理(mebular-serve)',
1083
1573
  ' console [--host --port] 打印控制台 URL(需 serve 正在运行)',
1084
1574
  ' cloud list|use|rename [id] [name] [--force] 忆云管理(use 停旧/起新/失败回滚)',
1575
+ ' runtime resolve|ensure|status|supervise [--start auto|child|service] [--port N] [--json] 共享 runtime(supervise 持有 child)',
1576
+ ' runtime install|reinstall [--version V] [--json] 安装/重装共享 runtime(固定 @mebular/core 版本)',
1577
+ ' runtime upgrade --to V|latest [--json] 显式升级共享 runtime(复用 installer;service 存在时更新并重启;跨入口 upgrade.lock)',
1578
+ ' runtime upgrade-state show [--json] 查看共享升级状态(只读诊断,不联网)',
1579
+ ' runtime check-update [--force] [--json] 只读检查官方 npm @mebular/core stable 更新(24h 节流;不安装)',
1580
+ ' runtime update-state show [--json] 查看共享更新状态(只读诊断,不联网)',
1581
+ ' runtime update-state skip --version V [--json] 跳过此版本(写共享 skippedVersion,两个入口都遵守)',
1582
+ ' runtime update-state prompted --version V [--json] 记录已提示版本(两入口共享去重)',
1583
+ ' runtime current show|set|clear [--version V --runtime-path P --cli C --provider shared --owner O --installed-at ISO] current 指针(非敏感)',
1584
+ ' runtime service install|uninstall|restart|status [--json] 共享 mebular-serve 所有权/生命周期',
1585
+ ' runtime provider list|add|remove [--kind app|cli|shared --path P --version V --capabilities a,b --id ID] runtime provider 注册表',
1085
1586
  ' token grant|list|revoke [--scope a,b] [--id x] [--tokens-file p] bearer 令牌管理',
1086
1587
  ' token client add|list|remove [--redirect uri] [--scope a,b] [--id x] OAuth 客户端预注册',
1087
1588
  ' token consent [--scope a,b] [--ttl sec] 生成一次性本地同意码(/authorize 用)',
package/package.json CHANGED
@@ -1,8 +1,13 @@
1
1
  {
2
2
  "name": "@mebular/mcp",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Mebular MCP server(stdio + Streamable HTTP):把 Mebular 记忆能力暴露给任意 MCP client",
5
5
  "license": "MIT",
6
+ "author": {
7
+ "name": "Sobert Li (Windsander)",
8
+ "email": "Windsander@users.noreply.github.com",
9
+ "url": "https://github.com/Windsander"
10
+ },
6
11
  "private": false,
7
12
  "type": "module",
8
13
  "bin": {
@@ -24,9 +29,9 @@
24
29
  "access": "public"
25
30
  },
26
31
  "dependencies": {
27
- "@mebular/core": "^0.1.2",
32
+ "@mebular/core": "^0.2.0",
28
33
  "@modelcontextprotocol/server": "^2.3.1",
29
34
  "zod": "^4.6.7",
30
- "@mebular/fleet": "^0.1.2"
35
+ "@mebular/fleet": "^0.2.0"
31
36
  }
32
37
  }
package/src/admin.mjs CHANGED
@@ -16,7 +16,7 @@ import { join } from 'node:path';
16
16
  import { readFile } from 'node:fs/promises';
17
17
  import { POLICY_NAMESPACE, normalizeNamespace } from '@mebular/core';
18
18
  import { configPath } from './config.mjs';
19
- import { cloudError, displayPath, readRegistry } from './profiles.mjs';
19
+ import { cloudError, displayPath, readRegistry, resolveCloudRoot } from './profiles.mjs';
20
20
  import { TOOL_NAMES } from './tools.mjs';
21
21
  import { hotPaths, readApplyPending, readApplyResult } from './config-apply.mjs';
22
22
  import {
@@ -1239,15 +1239,30 @@ export async function buildNetStatusView({ app }) {
1239
1239
 
1240
1240
  /** H-1 · GET /admin/api/service:常驻运行状态(registered/running/autostart/heartbeat)。 */
1241
1241
  export async function buildServiceView({ home: instanceHome }) {
1242
- const { serviceStatusForHome, registeredForHome, resolveServiceHome, SERVICE_KIND } = await import('./service-control.mjs');
1242
+ const { runtimeServiceStatus, runtimeProviderFromEnv, RUNTIME_SERVICE_KIND } = await import('./runtime-service.mjs');
1243
+ const { registeredForHome, resolveServiceHome, SERVICE_KIND } = await import('./service-control.mjs');
1243
1244
  const platform = process.platform;
1244
1245
  // 两套 home:home 是实例身份(descriptor 的 MEBULAR_HOME/心跳),serviceHome 是 unit/manifest 落盘位置。
1245
1246
  // 旧实现把两者混用 → 控制台去实例 home 下找 unit,对 CLI 装在 OS home 的服务误报「未常驻」。
1246
1247
  const serviceHome = resolveServiceHome();
1248
+ const cloud = resolveCloudRoot({ home: instanceHome, env: process.env });
1249
+ const fallbackProvider = runtimeProviderFromEnv({ cliPath: process.argv[1] });
1247
1250
  let status = null;
1248
1251
  let error = null;
1249
1252
  try {
1250
- status = serviceStatusForHome({ home: instanceHome, serviceHome, platform });
1253
+ if (cloud.available) {
1254
+ status = await runtimeServiceStatus({
1255
+ root: cloud.root,
1256
+ home: instanceHome,
1257
+ serviceHome,
1258
+ platform,
1259
+ fallbackProvider,
1260
+ });
1261
+ if (status.ok !== true) error = status.message ?? status.reason ?? 'service_unknown';
1262
+ } else {
1263
+ const { serviceStatusForHome } = await import('./service-control.mjs');
1264
+ status = serviceStatusForHome({ home: instanceHome, serviceHome, platform });
1265
+ }
1251
1266
  } catch (cause) {
1252
1267
  error = String(cause?.message ?? cause);
1253
1268
  }
@@ -1259,7 +1274,7 @@ export async function buildServiceView({ home: instanceHome }) {
1259
1274
  }
1260
1275
  return {
1261
1276
  platform,
1262
- kind: SERVICE_KIND,
1277
+ kind: RUNTIME_SERVICE_KIND ?? SERVICE_KIND,
1263
1278
  home: instanceHome,
1264
1279
  serviceHome,
1265
1280
  serviceManaged: Boolean(process.env.MEBULAR_SERVICE_KIND || process.env.MEBULAR_SERVICE_SHA),
@@ -1267,6 +1282,13 @@ export async function buildServiceView({ home: instanceHome }) {
1267
1282
  running: status?.running ?? false,
1268
1283
  autostart: status?.autostart ?? null,
1269
1284
  unitPath: status?.unitPath ?? null,
1285
+ version: status?.version ?? null,
1286
+ runtimePath: status?.runtimePath ?? null,
1287
+ provider: status?.provider ?? null,
1288
+ owner: status?.owner ?? null,
1289
+ current: status?.current ?? null,
1290
+ currentUsable: status?.currentUsable === true,
1291
+ ...(error ? { error } : {}),
1270
1292
  sha: status?.sha ?? null,
1271
1293
  heartbeat: status?.heartbeat ?? null,
1272
1294
  ...(error ? { error } : {}),
@@ -18,6 +18,7 @@ import {
18
18
  readRegistry,
19
19
  setCurrentProfile,
20
20
  } from './profiles.mjs';
21
+ import { loadServiceModule } from './service-loader.mjs';
21
22
 
22
23
  export const SWITCH_INTENT_FILE = 'switch.intent.json';
23
24
 
@@ -218,13 +219,31 @@ export function profileServiceDescriptor({
218
219
  heartbeatDir: home,
219
220
  workingDir: home,
220
221
  execPath,
221
- env: { MEBULAR_HOME: home, MEBULAR_CLOUD_ROOT: root },
222
+ env: {
223
+ MEBULAR_HOME: home,
224
+ MEBULAR_CLOUD_ROOT: root,
225
+ MEBULAR_RUNTIME_PROVIDER: 'cli',
226
+ MEBULAR_RUNTIME_OWNER: 'cli',
227
+ MEBULAR_RUNTIME_PATH: cliBin,
228
+ },
229
+ runtime: {
230
+ version: null,
231
+ runtimePath: null,
232
+ cliPath: cliBin,
233
+ provider: 'cli',
234
+ owner: 'cli',
235
+ execPath,
236
+ electron: false,
237
+ cloudRoot: root,
238
+ home,
239
+ },
222
240
  };
223
241
  }
224
242
 
225
243
  async function serviceLib(deps) {
244
+ // App 仍可注入自己的 service adapter;默认共享 core/CLI 走 loader(bare → bundled dist)。
226
245
  if (deps) return deps;
227
- return import('@mebular/service');
246
+ return loadServiceModule();
228
247
  }
229
248
 
230
249
  export async function profileServiceStatus({ descriptor, serviceHome = homedir(), deps } = {}) {