@mobius-os/mobius 0.3.79 → 0.3.82
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/README.md +8 -0
- package/package.json +1 -1
- package/src/aimux.ts +116 -0
- package/src/easy-mode-defaults.ts +10 -6
- package/tests/aimux.test.tsx +24 -1
- package/tests/ui.test.tsx +1 -1
package/README.md
CHANGED
|
@@ -84,6 +84,14 @@ child and reconnect with 1/2/4/8/15-second capped exponential backoff. A
|
|
|
84
84
|
successful bridge heartbeat resets the backoff and changes the status indicator
|
|
85
85
|
to green.
|
|
86
86
|
|
|
87
|
+
Every 30 minutes the TUI also reads `/aimux_bridge/api/health` and compares the
|
|
88
|
+
broker's aimux version with the one in use. A newer server version installs that
|
|
89
|
+
exact version locally and restarts the reverse connection, so a Mobius upgrade
|
|
90
|
+
reaches TUIs that were left open; an older version is never forced on the client
|
|
91
|
+
(the next TUI start aligns in either direction). Failures keep the existing
|
|
92
|
+
version connected and are retried at most three times per version. Set
|
|
93
|
+
`MOBIUS_TUI_AIMUX_FOLLOW_MS` to change the interval, or to `0` to disable it.
|
|
94
|
+
|
|
87
95
|
## Flow
|
|
88
96
|
|
|
89
97
|
1. **Login** — server / username / password → `POST /api/auth/login` → save
|
package/package.json
CHANGED
package/src/aimux.ts
CHANGED
|
@@ -883,6 +883,9 @@ export class AimuxSupervisor {
|
|
|
883
883
|
if (this.stopping) return
|
|
884
884
|
if (!token) throw new Error('登录接口未返回新 JWT')
|
|
885
885
|
this.opts.token = token
|
|
886
|
+
// 跟随检查用的是 lastStartOpts 里的 token;JWT 刷新后必须一起更新,
|
|
887
|
+
// 否则 TUI 连过一周之后定时探测会一直 401。
|
|
888
|
+
if (lastStartOpts && lastStartOpts.server === this.opts.server) lastStartOpts.token = token
|
|
886
889
|
this.reconnectAttempt = 0
|
|
887
890
|
appendAimuxLog(installLogQueue, `AIMUX JWT refreshed at ${new Date().toISOString()}; restarting bridge client\n`)
|
|
888
891
|
this.opts.onStatus({ state: 'starting', phase: 'connecting', detail: 'JWT 已刷新,正在重新连接 AIMUX bridge…', identifier: this.opts.identifier })
|
|
@@ -916,6 +919,48 @@ let lastStartOpts: StartOptions | null = null
|
|
|
916
919
|
let skipAutoAlignOnce = false
|
|
917
920
|
/** 实际装着的 aimux 版本,供状态行显示(自动对齐后可能和 pin 不同)。 */
|
|
918
921
|
let runtimeAimuxVersion: string | null = null
|
|
922
|
+
/** 跟随服务端版本的定时器(TUI 开着的时候才跑)。 */
|
|
923
|
+
let followTimer: ReturnType<typeof setInterval> | null = null
|
|
924
|
+
let followInFlight = false
|
|
925
|
+
/** 同一个服务端版本连续升级失败的次数;到上限就停止重试,等版本再变或 TUI 重启。 */
|
|
926
|
+
let followFailedVersion: string | null = null
|
|
927
|
+
let followFailureCount = 0
|
|
928
|
+
const FOLLOW_MAX_FAILURES = 3
|
|
929
|
+
|
|
930
|
+
/**
|
|
931
|
+
* 跟随检查间隔。默认 30 分钟;设 0 关闭(离线/受控环境)。
|
|
932
|
+
* 单独抽出来是为了测试和排障时不必等半小时。
|
|
933
|
+
*/
|
|
934
|
+
export function followCheckIntervalMs(): number {
|
|
935
|
+
const raw = process.env.MOBIUS_TUI_AIMUX_FOLLOW_MS
|
|
936
|
+
if (raw !== undefined && raw !== '') {
|
|
937
|
+
const n = Number(raw)
|
|
938
|
+
if (Number.isFinite(n) && n >= 0) return n
|
|
939
|
+
}
|
|
940
|
+
return 30 * 60 * 1000
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
/**
|
|
944
|
+
* 按数字段比较两个 aimux 版本,返回 -1/0/1;任一侧不是纯数字点分版本时返回 null。
|
|
945
|
+
* 不能用字符串比较:'0.3.9' > '0.3.10' 是错的,而这里恰好只关心谁更新。
|
|
946
|
+
*/
|
|
947
|
+
export function compareAimuxVersions(a: string | null | undefined, b: string | null | undefined): number | null {
|
|
948
|
+
const parse = (value: string | null | undefined): number[] | null => {
|
|
949
|
+
const text = typeof value === 'string' ? value.trim().replace(/^v/i, '') : ''
|
|
950
|
+
if (!/^\d+(\.\d+)*$/.test(text)) return null
|
|
951
|
+
return text.split('.').map(part => Number(part))
|
|
952
|
+
}
|
|
953
|
+
const left = parse(a)
|
|
954
|
+
const right = parse(b)
|
|
955
|
+
if (!left || !right) return null
|
|
956
|
+
const length = Math.max(left.length, right.length)
|
|
957
|
+
for (let i = 0; i < length; i += 1) {
|
|
958
|
+
const x = left[i] ?? 0
|
|
959
|
+
const y = right[i] ?? 0
|
|
960
|
+
if (x !== y) return x > y ? 1 : -1
|
|
961
|
+
}
|
|
962
|
+
return 0
|
|
963
|
+
}
|
|
919
964
|
|
|
920
965
|
interface StartOptions {
|
|
921
966
|
server: string
|
|
@@ -1024,15 +1069,86 @@ export async function startAimuxConnection(opts: StartOptions): Promise<void> {
|
|
|
1024
1069
|
spawnProcess: token => spawnDetachedDaemon(launcher, reverseConnectArgs(opts.server, identifier, token, process.platform, silentFlag, runtimePath(aimuxWorkspaceHash()), gui.enableGui, gui.guiNoElevate)),
|
|
1025
1070
|
})
|
|
1026
1071
|
await supervisor.start()
|
|
1072
|
+
scheduleFollowCheck(opts)
|
|
1027
1073
|
})().finally(() => { installing = null })
|
|
1028
1074
|
await installing
|
|
1029
1075
|
}
|
|
1030
1076
|
|
|
1031
1077
|
export async function stopAimuxConnection(): Promise<void> {
|
|
1078
|
+
clearFollowCheck()
|
|
1032
1079
|
const current = supervisor; supervisor = null
|
|
1033
1080
|
await current?.stop()
|
|
1034
1081
|
}
|
|
1035
1082
|
|
|
1083
|
+
/** 重新开始计时;每次连接成功都重置,避免旧定时器指向已废弃的 opts。 */
|
|
1084
|
+
function scheduleFollowCheck(opts: StartOptions): void {
|
|
1085
|
+
clearFollowCheck()
|
|
1086
|
+
const intervalMs = followCheckIntervalMs()
|
|
1087
|
+
if (!(intervalMs > 0)) {
|
|
1088
|
+
logInstall('aimux follow: disabled by MOBIUS_TUI_AIMUX_FOLLOW_MS=0\n')
|
|
1089
|
+
return
|
|
1090
|
+
}
|
|
1091
|
+
followTimer = setInterval(() => { void followServerVersion(opts) }, intervalMs)
|
|
1092
|
+
followTimer.unref?.()
|
|
1093
|
+
logInstall(`aimux follow: checking the server version every ${Math.round(intervalMs / 1000)}s\n`)
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
function clearFollowCheck(): void {
|
|
1097
|
+
if (followTimer) { clearInterval(followTimer); followTimer = null }
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
/**
|
|
1101
|
+
* “Mobius 升级 aimux,连着的 TUI 跟着升级”的落点。
|
|
1102
|
+
*
|
|
1103
|
+
* 每 30 分钟读一次服务端 broker 版本;只有服务端**更新**时才动手(回滚不把用户
|
|
1104
|
+
* 往回拽 —— 那是下次启动对齐的事)。升级不复用连接期的对齐逻辑,而是先停掉
|
|
1105
|
+
* supervisor 和旧守护进程,再走一遍 startAimuxConnection:它会重新读版本、装到
|
|
1106
|
+
* 目标版本、版本变化时丢弃旧 daemon 并重新探测命令行开关,失败也会带着旧版本
|
|
1107
|
+
* 连回去,不会把设备留在离线状态。
|
|
1108
|
+
*/
|
|
1109
|
+
async function followServerVersion(opts: StartOptions): Promise<void> {
|
|
1110
|
+
if (followInFlight || installing || !supervisor) return
|
|
1111
|
+
if (process.env.MOBIUS_TUI_DISABLE_AIMUX === '1') return
|
|
1112
|
+
const current = runtimeAimuxVersion
|
|
1113
|
+
const serverVersion = await fetchServerAimuxVersion(opts.server, opts.token)
|
|
1114
|
+
if (!serverVersion) return
|
|
1115
|
+
if (followFailedVersion && followFailedVersion !== serverVersion) {
|
|
1116
|
+
followFailedVersion = null
|
|
1117
|
+
followFailureCount = 0
|
|
1118
|
+
}
|
|
1119
|
+
if (followFailedVersion === serverVersion && followFailureCount >= FOLLOW_MAX_FAILURES) {
|
|
1120
|
+
logInstall(`aimux follow: ${serverVersion} already failed ${followFailureCount} times; waiting for a different version\n`)
|
|
1121
|
+
return
|
|
1122
|
+
}
|
|
1123
|
+
const cmp = compareAimuxVersions(serverVersion, current)
|
|
1124
|
+
if (cmp === null || cmp <= 0) return
|
|
1125
|
+
followInFlight = true
|
|
1126
|
+
logInstall(`\n########## aimux follow: server ${serverVersion} > local ${current ?? '(unknown)'} at ${new Date().toISOString()} ##########\n`)
|
|
1127
|
+
opts.onStatus?.({ state: 'starting', phase: 'install', detail: `服务端 AIMUX 已升级到 ${serverVersion},正在跟随升级…` })
|
|
1128
|
+
try {
|
|
1129
|
+
await stopAimuxConnection()
|
|
1130
|
+
await stopDaemonFromRuntime()
|
|
1131
|
+
await startAimuxConnection(opts)
|
|
1132
|
+
if (runtimeAimuxVersion === serverVersion) {
|
|
1133
|
+
logInstall(`aimux follow: now running ${runtimeAimuxVersion}\n`)
|
|
1134
|
+
followFailedVersion = null
|
|
1135
|
+
followFailureCount = 0
|
|
1136
|
+
} else {
|
|
1137
|
+
followFailedVersion = serverVersion
|
|
1138
|
+
followFailureCount += 1
|
|
1139
|
+
logInstall(`aimux follow: still on ${runtimeAimuxVersion ?? '(unknown)'} after the attempt (${followFailureCount}/${FOLLOW_MAX_FAILURES})\n`)
|
|
1140
|
+
}
|
|
1141
|
+
} catch (e: any) {
|
|
1142
|
+
followFailedVersion = serverVersion
|
|
1143
|
+
followFailureCount += 1
|
|
1144
|
+
logInstall(`aimux follow failed: ${e?.stack || e?.message || String(e)}\n`)
|
|
1145
|
+
// 别把设备留在离线状态:升级链路异常时用旧版本把连接拉回来。
|
|
1146
|
+
if (!supervisor) { try { await startAimuxConnection(opts) } catch { /* 下一轮定时器再试 */ } }
|
|
1147
|
+
} finally {
|
|
1148
|
+
followInFlight = false
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1036
1152
|
/**
|
|
1037
1153
|
* Re-do the reverse connection after the GUI authorization choice changed.
|
|
1038
1154
|
* The old daemon must die first (its runtime JSON is keyed by workspace hash,
|
|
@@ -6,9 +6,13 @@
|
|
|
6
6
|
export const EASY_DEFAULT_PROJECT_NAME = '快捷任务'
|
|
7
7
|
export const EASY_DEFAULT_ISSUE_TITLE = '日常会话'
|
|
8
8
|
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export const
|
|
9
|
+
/**
|
|
10
|
+
* Picker labels: the easy default reads as "skip the choice".
|
|
11
|
+
* Icons carry a trailing space: emoji glyphs fill their two cells edge-to-edge,
|
|
12
|
+
* so an unspaced `📁name` reads as glued together in most terminal fonts.
|
|
13
|
+
*/
|
|
14
|
+
export const EASY_PROJECT_LABEL = '🕊️ 不使用任何项目'
|
|
15
|
+
export const EASY_ISSUE_LABEL = '🕊️ 不使用任何任务'
|
|
16
|
+
export const CREATE_ITEM_ICON = '🚀 '
|
|
17
|
+
export const PROJECT_ITEM_ICON = '📁 '
|
|
18
|
+
export const ISSUE_ITEM_ICON = '💡 '
|
package/tests/aimux.test.tsx
CHANGED
|
@@ -7,7 +7,7 @@ import os from 'node:os'
|
|
|
7
7
|
import path from 'node:path'
|
|
8
8
|
import { render } from 'ink-testing-library'
|
|
9
9
|
import { AimuxStatusLine } from '../src/components/AimuxStatus.js'
|
|
10
|
-
import { AimuxSupervisor, probeAimuxBridgeConnection, BUNDLE_VER, bundleArch, bundleUrl, spawnLauncher, ensureFromBundle, ensureAimux, downloadBundleForTest, reverseConnectArgs, pickSilentFlag, alignTarget, fetchServerAimuxVersion, aimuxLogPath, bundleHealthCheckCode, tuiAimuxIdentifier, AIMUX_VERSION, tuiGuiAuthorized, setTuiGuiAuthorized, pickEnableGuiFlag, pickGuiNoElevateFlag, tuiGuiMode, tuiGuiNoElevate, setTuiGuiMode, readGuiModeForTest, pidAlive, aimuxWorkspaceHash, guiModeAvailability, guiModeOptions, pickGuiArgs, hasGuiSupport, effectiveGuiMode } from '../src/aimux.js'
|
|
10
|
+
import { AimuxSupervisor, probeAimuxBridgeConnection, BUNDLE_VER, bundleArch, bundleUrl, spawnLauncher, ensureFromBundle, ensureAimux, downloadBundleForTest, reverseConnectArgs, pickSilentFlag, alignTarget, compareAimuxVersions, followCheckIntervalMs, fetchServerAimuxVersion, aimuxLogPath, bundleHealthCheckCode, tuiAimuxIdentifier, AIMUX_VERSION, tuiGuiAuthorized, setTuiGuiAuthorized, pickEnableGuiFlag, pickGuiNoElevateFlag, tuiGuiMode, tuiGuiNoElevate, setTuiGuiMode, readGuiModeForTest, pidAlive, aimuxWorkspaceHash, guiModeAvailability, guiModeOptions, pickGuiArgs, hasGuiSupport, effectiveGuiMode } from '../src/aimux.js'
|
|
11
11
|
import { parseElevatedGroups } from '../src/lib/windows-admin.js'
|
|
12
12
|
|
|
13
13
|
const delay = (ms: number) => new Promise<void>(resolve => setTimeout(resolve, ms))
|
|
@@ -470,6 +470,28 @@ function testAlignTarget() {
|
|
|
470
470
|
ok(alignTarget('0.3.71', '0.3.71') === '0.3.71', 'an exact match targets that same version (no swap happens)')
|
|
471
471
|
}
|
|
472
472
|
|
|
473
|
+
function testFollowServerVersion() {
|
|
474
|
+
console.log('\n[AIMUX 6h] follow the server version while the TUI stays open')
|
|
475
|
+
// 数字段比较:字符串比较会把 0.3.9 判成比 0.3.10 新。
|
|
476
|
+
ok(compareAimuxVersions('0.3.81', '0.3.77') === 1, 'a newer server version compares as newer')
|
|
477
|
+
ok(compareAimuxVersions('0.3.9', '0.3.10') === -1, 'numeric comparison handles multi-digit segments')
|
|
478
|
+
ok(compareAimuxVersions('0.3.81', '0.3.81') === 0, 'equal versions do not trigger an upgrade')
|
|
479
|
+
ok(compareAimuxVersions('0.3.77', '0.3.81') === -1, 'an older server version is never followed (no auto-downgrade)')
|
|
480
|
+
ok(compareAimuxVersions('v0.4.0', '0.3.81') === 1, 'a leading v is tolerated')
|
|
481
|
+
ok(compareAimuxVersions('0.3.81-beta', '0.3.81') === null, 'a non-numeric version is not acted on')
|
|
482
|
+
ok(compareAimuxVersions(null, '0.3.81') === null, 'an unknown server version is not acted on')
|
|
483
|
+
// 默认 30 分钟一轮;可被环境变量覆盖或关闭。
|
|
484
|
+
const previous = process.env.MOBIUS_TUI_AIMUX_FOLLOW_MS
|
|
485
|
+
delete process.env.MOBIUS_TUI_AIMUX_FOLLOW_MS
|
|
486
|
+
ok(followCheckIntervalMs() === 30 * 60 * 1000, 'the default follow interval is 30 minutes')
|
|
487
|
+
process.env.MOBIUS_TUI_AIMUX_FOLLOW_MS = '0'
|
|
488
|
+
ok(followCheckIntervalMs() === 0, 'setting 0 disables the follow check')
|
|
489
|
+
process.env.MOBIUS_TUI_AIMUX_FOLLOW_MS = '1234'
|
|
490
|
+
ok(followCheckIntervalMs() === 1234, 'an explicit interval is honoured')
|
|
491
|
+
if (previous === undefined) delete process.env.MOBIUS_TUI_AIMUX_FOLLOW_MS
|
|
492
|
+
else process.env.MOBIUS_TUI_AIMUX_FOLLOW_MS = previous
|
|
493
|
+
}
|
|
494
|
+
|
|
473
495
|
function testAimuxIdentifierScopesWorkspace() {
|
|
474
496
|
console.log('\n[AIMUX 6a] reverse client identifier workspace isolation')
|
|
475
497
|
const first = tuiAimuxIdentifier('same-host', '/work/project-a')
|
|
@@ -630,6 +652,7 @@ async function main() {
|
|
|
630
652
|
testElevationDetection()
|
|
631
653
|
testGuiModeAvailability()
|
|
632
654
|
testAlignTarget()
|
|
655
|
+
testFollowServerVersion()
|
|
633
656
|
await testFetchServerAimuxVersion()
|
|
634
657
|
await testEnsureAimuxVersionSwap()
|
|
635
658
|
testAimuxIdentifierScopesWorkspace()
|
package/tests/ui.test.tsx
CHANGED
|
@@ -472,7 +472,7 @@ async function testPrepRender() {
|
|
|
472
472
|
ok(!frame.includes('已有项目A - 第一行') && !frame.includes('已有项目B - 单行描述'), 'unfocused project rows omit their descriptions')
|
|
473
473
|
stdin.write('\x1b[B'); await delay(15) // move focus from search to the list
|
|
474
474
|
stdin.write('\x1b[B'); await delay(15) // highlight the pinned easy-default row
|
|
475
|
-
ok((lastFrame() ?? '').includes('
|
|
475
|
+
ok((lastFrame() ?? '').includes('🕊️ 不使用任何项目 - 一键创建并进入'), 'easy-default project is pinned above the list')
|
|
476
476
|
stdin.write('\x1b[B'); await delay(15) // step over the blank separator to the first project
|
|
477
477
|
const selectedFrame = lastFrame() ?? ''
|
|
478
478
|
ok(selectedFrame.includes('已有项目A - 第一行 ⏎ 第二行'), 'selected multi-line description stays on the main row')
|