@dsh-workbench/adapter-probe 1.5.2 → 1.5.3-rc.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.
@@ -0,0 +1,38 @@
1
+ import { type PreflightBridgeIssue } from '../runtime/bridge-report.js';
2
+ export interface BridgeVerdict {
3
+ readonly ok: boolean;
4
+ readonly detail: string;
5
+ readonly issues: readonly PreflightBridgeIssue[];
6
+ readonly command?: string | undefined;
7
+ readonly stalled?: boolean | undefined;
8
+ readonly facts?: {
9
+ readonly extension?: string | undefined;
10
+ } | undefined;
11
+ }
12
+ export declare function canWarm(bridge: {
13
+ ok: boolean;
14
+ issues: readonly PreflightBridgeIssue[];
15
+ }): boolean;
16
+ export declare function bundledExtensionVersion(dir: string | undefined): string | undefined;
17
+ export declare function extensionDriftOf(installed: string | undefined, bundled: string | undefined): string | undefined;
18
+ export type BridgeExec = {
19
+ readonly kind: 'ok';
20
+ readonly stdout: string;
21
+ } | {
22
+ readonly kind: 'nonzero';
23
+ readonly detail: string;
24
+ } | {
25
+ readonly kind: 'error';
26
+ readonly detail: string;
27
+ } | {
28
+ readonly kind: 'stalled';
29
+ readonly detail: string;
30
+ };
31
+ export interface BridgeProbeDeps {
32
+ readonly doctor: () => Promise<BridgeExec>;
33
+ readonly stop: () => Promise<BridgeExec>;
34
+ readonly restart: () => Promise<BridgeExec>;
35
+ readonly log: (line: string) => void;
36
+ readonly fixCommand: (issues: readonly PreflightBridgeIssue[]) => string | undefined;
37
+ }
38
+ export declare function createBridgeProbe(deps: BridgeProbeDeps): () => Promise<BridgeVerdict>;
@@ -0,0 +1,56 @@
1
+ import { join } from 'node:path';
2
+ import { readJsonObject } from '@dsh-workbench/shared/host';
3
+ import { readBridgeReport } from '../runtime/bridge-report.js';
4
+ import { rememberBridgeFacts } from '../runtime/bridge-facts.js';
5
+ const WARMABLE_BRIDGE_ISSUES = ['daemon', 'stale'];
6
+ export function canWarm(bridge) {
7
+ return bridge.ok || bridge.issues.every((issue) => WARMABLE_BRIDGE_ISSUES.includes(issue));
8
+ }
9
+ export function bundledExtensionVersion(dir) {
10
+ if (dir === undefined)
11
+ return undefined;
12
+ const version = readJsonObject(join(dir, 'manifest.json'))?.['version'];
13
+ return typeof version === 'string' && version.trim() !== '' ? version.trim() : undefined;
14
+ }
15
+ export function extensionDriftOf(installed, bundled) {
16
+ if (installed === undefined || bundled === undefined || installed === bundled)
17
+ return undefined;
18
+ return `浏览器扩展是 v${installed},工作台需要 v${bundled}`;
19
+ }
20
+ export function createBridgeProbe(deps) {
21
+ let healed = false;
22
+ async function restartStaleDaemon(report) {
23
+ if (healed)
24
+ return undefined;
25
+ if (!report.issues.includes('stale'))
26
+ return undefined;
27
+ healed = true;
28
+ deps.log('先停旧 daemon 再起新的:版本不一致时 restart 顶不掉占着端口的那一个');
29
+ await deps.stop();
30
+ const started = await deps.restart();
31
+ if (started.kind !== 'ok')
32
+ return undefined;
33
+ const again = await deps.doctor();
34
+ if (again.kind !== 'ok')
35
+ return undefined;
36
+ const after = readBridgeReport(again.stdout);
37
+ rememberBridgeFacts(after.facts);
38
+ return after.ok ? after : { ...after, command: deps.fixCommand(after.issues) };
39
+ }
40
+ return async () => {
41
+ const result = await deps.doctor();
42
+ if (result.kind === 'stalled') {
43
+ return { ok: false, detail: result.detail, issues: ['unknown'], stalled: true };
44
+ }
45
+ if (result.kind !== 'ok')
46
+ return { ok: false, detail: result.detail, issues: ['unknown'] };
47
+ const report = readBridgeReport(result.stdout);
48
+ rememberBridgeFacts(report.facts);
49
+ if (report.ok)
50
+ return report;
51
+ const restarted = await restartStaleDaemon(report);
52
+ if (restarted !== undefined)
53
+ return restarted;
54
+ return { ...report, command: deps.fixCommand(report.issues) };
55
+ };
56
+ }
@@ -0,0 +1,11 @@
1
+ import type { BrowserExtension } from '@dsh-workbench/shared/host';
2
+ export interface ExtensionTarget {
3
+ readonly dir: string;
4
+ readonly version?: string | undefined;
5
+ }
6
+ export interface ExtensionResolverInput {
7
+ readonly extension?: (() => BrowserExtension | undefined) | undefined;
8
+ readonly extensionDir?: string | undefined;
9
+ readonly log?: ((message: string) => void) | undefined;
10
+ }
11
+ export declare function extensionResolverOf(input: ExtensionResolverInput): () => ExtensionTarget | undefined;
@@ -0,0 +1,18 @@
1
+ import { bundledExtensionVersion } from './preflight-bridge.js';
2
+ export function extensionResolverOf(input) {
3
+ return () => {
4
+ if (input.extension !== undefined) {
5
+ try {
6
+ const found = input.extension();
7
+ return found === undefined ? undefined : { dir: found.dir, version: found.version };
8
+ }
9
+ catch (error) {
10
+ input.log?.(`[dsh-workbench] 读取浏览器扩展目录失败:${String(error)}`);
11
+ return undefined;
12
+ }
13
+ }
14
+ if (input.extensionDir === undefined)
15
+ return undefined;
16
+ return { dir: input.extensionDir, version: bundledExtensionVersion(input.extensionDir) };
17
+ };
18
+ }
@@ -1,5 +1,5 @@
1
1
  import type { RuntimeCapabilities } from '@dsh-workbench/shared';
2
- import type { DiagRecorder, DshHostContext } from '@dsh-workbench/shared/host';
2
+ import type { BrowserExtension, DiagRecorder, DshHostContext } from '@dsh-workbench/shared/host';
3
3
  import type { RouteTable } from '@dsh-workbench/shared/host';
4
4
  import { type Seam } from '@dsh-workbench/shared/host';
5
5
  import { type DesktopBrowser } from '../runtime/browser-wake.js';
@@ -25,6 +25,7 @@ export declare function registerPreflight(input: {
25
25
  runtimeLabel?: string | undefined;
26
26
  warmReads: () => readonly (readonly string[])[];
27
27
  desktopBrowser?: DesktopBrowser | undefined;
28
+ extension?: (() => BrowserExtension | undefined) | undefined;
28
29
  extensionDir?: string | undefined;
29
30
  diag?: DiagRecorder | undefined;
30
31
  }): void;
@@ -1,7 +1,7 @@
1
1
  import { existsSync, readdirSync } from 'node:fs';
2
2
  import { basename, join } from 'node:path';
3
3
  import { OPENCLI_PIN, PREFLIGHT_INSTALL_TIMEOUT_MS, PREFLIGHT_VERSION_TIMEOUT_MS, VERIFIED_DSH, dshHome, dshHostGapOf, dshTierOf, dshVersionFrom, hostOsOf, preflightHandler, quoteShellArgFor, workbenchRoot } from '@dsh-workbench/shared/host';
4
- import { isOpencliReady, isOpencliReadyAt, opencliBuiltAt, opencliPackageDir, opencliReadinessAt, storeDirFor, toolchainDir } from '@dsh-workbench/adapter-runtime';
4
+ import { isOpencliAtPin, isOpencliAtPinAt, isOpencliReady, opencliBuiltAt, opencliPackageDir, opencliReadinessAt, storeDirFor, toolchainDir } from '@dsh-workbench/adapter-runtime';
5
5
  import { WAKE_BROWSER_ROUTE } from '@dsh-workbench/shared/contract/protocol/preflight-wake';
6
6
  import { runBootstrapCommand } from '../runtime/bootstrap-run.js';
7
7
  import { createDiyPresetProbe, DIY_UPGRADE_COMMAND } from './diy-preset-health.js';
@@ -46,19 +46,6 @@ export async function provisionWorkbenchPnpm(input) {
46
46
  }
47
47
  return result;
48
48
  }
49
- const EXTENSION_ENV = 'DSH_WB_OPENCLI_EXTENSION';
50
- function hasManifest(dir) {
51
- return existsSync(join(dir, 'manifest.json'));
52
- }
53
- function extensionDirOf(bundled) {
54
- const asked = process.env[EXTENSION_ENV]?.trim();
55
- if (asked !== undefined && asked !== '')
56
- return asked;
57
- const local = join(toolchainDir(), '..', 'extension');
58
- if (hasManifest(local))
59
- return local;
60
- return bundled !== undefined && hasManifest(bundled) ? bundled : undefined;
61
- }
62
49
  function describeToolchain(toolchain, pkgDir) {
63
50
  if (!existsSync(toolchain))
64
51
  return `${toolchain} 不存在`;
@@ -117,7 +104,8 @@ export function registerPreflight(input) {
117
104
  paths: { workbenchRoot: workbenchRoot(), dshHome: dshHome() },
118
105
  command,
119
106
  installCommand,
120
- ...(extensionDirOf(input.extensionDir) === undefined ? {} : { extensionDir: extensionDirOf(input.extensionDir) }),
107
+ ...(input.extension === undefined ? {} : { extension: input.extension }),
108
+ ...(input.extensionDir === undefined ? {} : { extensionDir: input.extensionDir }),
121
109
  installed: () => isOpencliReady(),
122
110
  installedNote: () => {
123
111
  if (!isOpencliReady())
@@ -129,7 +117,7 @@ export function registerPreflight(input) {
129
117
  versionAttempts: 3,
130
118
  withToolchainLock: (run) => holdToolchainLock(toolchainDir(), run).catch(() => run()),
131
119
  install: () => holdToolchainLock(toolchainDir(), async () => {
132
- if (isOpencliReady())
120
+ if (isOpencliAtPin())
133
121
  return { ok: true, detail: '另一个实例已经装好,不再重装' };
134
122
  const store = storeDirFor(toolchainDir());
135
123
  const installed = await installIsolatedRuntime({
@@ -139,7 +127,7 @@ export function registerPreflight(input) {
139
127
  timeoutMs: PREFLIGHT_INSTALL_TIMEOUT_MS,
140
128
  seam: input.seam,
141
129
  }),
142
- ready: (dir) => isOpencliReadyAt(dir),
130
+ ready: (dir) => isOpencliAtPinAt(dir),
143
131
  describe: (dir) => describeToolchain(dir, opencliPackageDir(dir)),
144
132
  ...(installLog === undefined ? {} : { log: installLog }),
145
133
  });
@@ -1,5 +1,5 @@
1
1
  import type { RuntimeCapabilities } from '@dsh-workbench/shared';
2
- import { type Seam } from '@dsh-workbench/shared/host';
2
+ import { type BrowserExtension, type Seam } from '@dsh-workbench/shared/host';
3
3
  import type { DiyPresetVerdict } from './diy-preset-health.js';
4
4
  import { type LocalNpmProvision, type LocalPnpmProvision } from '../toolchain/toolchain.js';
5
5
  import type { ToolchainReport } from '../toolchain/toolchain-probe.js';
@@ -9,7 +9,6 @@ export type PreflightGuidance = 'install' | 'path' | 'shell' | 'host';
9
9
  export type PreflightStepId = 'toolchain' | 'runtime' | 'host' | 'cli' | 'bridge' | 'diy' | 'warm';
10
10
  export type PreflightStepStatus = 'pending' | 'running' | 'ok' | 'warn' | 'failed';
11
11
  import type { PreflightHostStanding, PreflightPaths, PreflightSnapshot } from '@dsh-workbench/shared/host';
12
- import { type PreflightBridgeIssue } from '../runtime/bridge-report.js';
13
12
  export { BRIDGE_ISSUE_ORDER, readBridgeReport } from '../runtime/bridge-report.js';
14
13
  export type { PreflightBridgeIssue } from '../runtime/bridge-report.js';
15
14
  export type { PreflightDiyGap, PreflightHostGap, PreflightHostStanding, PreflightSnapshot, PreflightStep } from '@dsh-workbench/shared/host';
@@ -21,17 +20,7 @@ export interface Preflight {
21
20
  snapshot(): PreflightSnapshot;
22
21
  }
23
22
  export declare function opencliInstallCommandDefault(): string;
24
- export interface BridgeVerdict {
25
- readonly ok: boolean;
26
- readonly detail: string;
27
- readonly issues: readonly PreflightBridgeIssue[];
28
- readonly command?: string | undefined;
29
- readonly stalled?: boolean | undefined;
30
- }
31
- export declare function canWarm(bridge: {
32
- ok: boolean;
33
- issues: readonly PreflightBridgeIssue[];
34
- }): boolean;
23
+ export { canWarm, type BridgeVerdict } from './preflight-bridge.js';
35
24
  export declare function createPreflight(options: {
36
25
  seam: Seam;
37
26
  command?: string;
@@ -55,6 +44,7 @@ export declare function createPreflight(options: {
55
44
  provisionNpm?: (() => Promise<LocalNpmProvision>) | undefined;
56
45
  provisionPnpm?: (() => Promise<LocalPnpmProvision>) | undefined;
57
46
  desktopBrowser?: DesktopBrowser | undefined;
47
+ extension?: (() => BrowserExtension | undefined) | undefined;
58
48
  extensionDir?: string | undefined;
59
49
  capabilities?: RuntimeCapabilities | undefined;
60
50
  runtimeCheck?: (() => Promise<{
@@ -1,5 +1,7 @@
1
1
  import { PREFLIGHT_DOCTOR_TIMEOUT_MS, PREFLIGHT_FRESH_MS, PREFLIGHT_INSTALL_TIMEOUT_MS, PREFLIGHT_VERSION_TIMEOUT_MS, WARM_TIMEOUT_MS, hostOsOf, now, productWrite, quoteShellArgFor, tailLines } from '@dsh-workbench/shared/host';
2
+ import { canWarm, createBridgeProbe, extensionDriftOf } from './preflight-bridge.js';
2
3
  import { opencliCommandLine, OPENCLI_SITE_SESSION_ENV, OPENCLI_WINDOW_ENV } from '@dsh-workbench/adapter-runtime';
4
+ import { extensionResolverOf } from './preflight-extension.js';
3
5
  import { classifyFailure } from './preflight-failure.js';
4
6
  import { notePreflightFailed, notePreflightHold } from './preflight-note.js';
5
7
  import { persistPreflightSnapshot } from './preflight-snapshot.js';
@@ -10,16 +12,11 @@ import { bridgeFixCommand } from '../runtime/browser-wake.js';
10
12
  import { probeOpencliVersion } from '../self-update/version/version-probe.js';
11
13
  export { classifyFailure } from './preflight-failure.js';
12
14
  const WARM_ENV = { ...OPENCLI_WINDOW_ENV, ...OPENCLI_SITE_SESSION_ENV };
13
- import { readBridgeReport } from '../runtime/bridge-report.js';
14
- import { rememberBridgeFacts } from '../runtime/bridge-facts.js';
15
15
  export { BRIDGE_ISSUE_ORDER, readBridgeReport } from '../runtime/bridge-report.js';
16
16
  export function opencliInstallCommandDefault() {
17
17
  return opencliInstallCommand();
18
18
  }
19
- const WARMABLE_BRIDGE_ISSUES = ['daemon', 'stale'];
20
- export function canWarm(bridge) {
21
- return bridge.ok || bridge.issues.every((issue) => WARMABLE_BRIDGE_ISSUES.includes(issue));
22
- }
19
+ export { canWarm } from './preflight-bridge.js';
23
20
  export function createPreflight(options) {
24
21
  const { seam, command = 'opencli', logger } = options;
25
22
  const platform = options.platform;
@@ -70,7 +67,6 @@ export function createPreflight(options) {
70
67
  };
71
68
  let running = null;
72
69
  let shellStalled = false;
73
- let daemonHealed = false;
74
70
  function set(next) {
75
71
  if (next.phase === 'failed') {
76
72
  const stage = (next.steps ?? current.steps).find((item) => item.status === 'failed')?.id;
@@ -137,40 +133,13 @@ export function createPreflight(options) {
137
133
  log: (line) => appendLog('cli', line),
138
134
  });
139
135
  }
140
- async function probeBridge() {
141
- const result = await exec('bridge', `${commandToken} doctor`, PREFLIGHT_DOCTOR_TIMEOUT_MS);
142
- if (result.kind === 'stalled') {
143
- return { ok: false, detail: result.detail, issues: ['unknown'], stalled: true };
144
- }
145
- if (result.kind !== 'ok')
146
- return { ok: false, detail: result.detail, issues: ['unknown'] };
147
- const report = readBridgeReport(result.stdout);
148
- rememberBridgeFacts(report.facts);
149
- if (report.ok)
150
- return report;
151
- const healed = await restartStaleDaemon(report);
152
- if (healed !== undefined)
153
- return healed;
154
- return { ...report, command: bridgeFixCommand(command, report.issues, platform) };
155
- }
156
- async function restartStaleDaemon(report) {
157
- if (daemonHealed)
158
- return undefined;
159
- if (!report.issues.includes('stale'))
160
- return undefined;
161
- daemonHealed = true;
162
- appendLog('bridge', '先停旧 daemon 再起新的:版本不一致时 restart 顶不掉占着端口的那一个');
163
- await exec('bridge', `${commandToken} daemon stop`, PREFLIGHT_DOCTOR_TIMEOUT_MS, 'never');
164
- const started = await exec('bridge', `${commandToken} daemon restart`, PREFLIGHT_DOCTOR_TIMEOUT_MS, 'never');
165
- if (started.kind !== 'ok')
166
- return undefined;
167
- const again = await exec('bridge', `${commandToken} doctor`, PREFLIGHT_DOCTOR_TIMEOUT_MS);
168
- if (again.kind !== 'ok')
169
- return undefined;
170
- const healed = readBridgeReport(again.stdout);
171
- rememberBridgeFacts(healed.facts);
172
- return healed.ok ? healed : { ...healed, command: bridgeFixCommand(command, healed.issues, platform) };
173
- }
136
+ const probeBridge = createBridgeProbe({
137
+ doctor: () => exec('bridge', `${commandToken} doctor`, PREFLIGHT_DOCTOR_TIMEOUT_MS),
138
+ stop: () => exec('bridge', `${commandToken} daemon stop`, PREFLIGHT_DOCTOR_TIMEOUT_MS, 'never'),
139
+ restart: () => exec('bridge', `${commandToken} daemon restart`, PREFLIGHT_DOCTOR_TIMEOUT_MS, 'never'),
140
+ log: (line) => appendLog('bridge', line),
141
+ fixCommand: (issues) => bridgeFixCommand(command, issues, platform),
142
+ });
174
143
  async function installOpencli() {
175
144
  if (options.install !== undefined) {
176
145
  appendLog('cli', '> 安装 opencli');
@@ -226,6 +195,11 @@ export function createPreflight(options) {
226
195
  },
227
196
  };
228
197
  async function doRun(from) {
198
+ const extension = extensionResolverOf({
199
+ extension: options.extension,
200
+ extensionDir: options.extensionDir,
201
+ ...(logger === undefined ? {} : { log: (message) => logger.warn?.(message) }),
202
+ })();
229
203
  const order = ['toolchain', 'runtime', 'host', 'cli', 'bridge', 'diy', 'warm'];
230
204
  const skip = (id) => from !== undefined && order.indexOf(id) >= 0 && order.indexOf(id) < order.indexOf(from);
231
205
  const previous = new Map(current.steps.map((item) => [item.id, item]));
@@ -323,7 +297,8 @@ export function createPreflight(options) {
323
297
  patchStep('cli', { status: 'failed', detail: version.detail, action: undefined });
324
298
  return hostFailure(version.detail);
325
299
  }
326
- if (!version.ok && !version.missing) {
300
+ const behind = version.behind === true;
301
+ if (!version.ok && !version.missing && !behind) {
327
302
  patchStep('cli', { status: 'failed', detail: version.detail, action: undefined });
328
303
  return set({
329
304
  phase: 'failed',
@@ -332,50 +307,75 @@ export function createPreflight(options) {
332
307
  guidance: 'shell',
333
308
  });
334
309
  }
310
+ let keptOld = false;
335
311
  if (!version.ok) {
336
312
  appendLog('cli', `> 体检为何要装:${version.detail}`);
337
- if (toolchain?.npmMissing === true && installCommand.trim().startsWith('npm ')) {
338
- patchStep('cli', { status: 'failed', detail: '没有 npm:装不了 opencli(只影响 opencli 安装)' });
339
- return set({
340
- phase: 'failed',
341
- error: '没有 npm:装不了 opencli(只影响 opencli 安装)',
342
- failure: 'missing',
343
- guidance: 'install',
344
- });
345
- }
346
- set({ phase: 'installing' });
347
- patchStep('cli', { status: 'running', action: '安装 opencli', command: installCommand });
348
- const installed = await installOpencli();
349
- if (!installed.ok) {
313
+ const keepOld = (detail, command) => {
314
+ keptOld = true;
315
+ appendLog('cli', `> 先按现有的版本用:${detail}`);
350
316
  patchStep('cli', {
351
- status: 'failed',
352
- detail: installed.detail,
353
- command: installCommand,
354
- });
355
- return set({
356
- phase: 'failed',
357
- error: installed.detail,
358
- failure: classifyFailure(installed.detail),
359
- guidance: 'install',
317
+ status: 'warn',
318
+ detail: `升级没成:${detail}`,
319
+ ...(command === undefined ? {} : { command }),
360
320
  });
321
+ };
322
+ if (toolchain?.npmMissing === true && installCommand.trim().startsWith('npm ')) {
323
+ const detail = '没有 npm:装不了 opencli(只影响 opencli 安装)';
324
+ if (!behind) {
325
+ patchStep('cli', { status: 'failed', detail });
326
+ return set({
327
+ phase: 'failed',
328
+ error: detail,
329
+ failure: 'missing',
330
+ guidance: 'install',
331
+ });
332
+ }
333
+ keepOld(detail);
361
334
  }
362
- patchStep('cli', { status: 'running', action: '检查 opencli 版本' });
363
- version = await probeVersion();
364
- if (version.stalled) {
365
- patchStep('cli', { status: 'failed', detail: version.detail, action: undefined });
366
- return hostFailure(version.detail);
367
- }
368
- if (!version.ok) {
369
- patchStep('cli', { status: 'failed', detail: version.detail, command: installCommand });
370
- return set({
371
- phase: 'failed',
372
- error: version.detail,
373
- failure: classifyFailure(version.detail),
374
- guidance: 'path',
375
- });
335
+ else {
336
+ set({ phase: 'installing' });
337
+ patchStep('cli', { status: 'running', action: behind ? '升级 opencli' : '安装 opencli', command: installCommand });
338
+ const installed = await installOpencli();
339
+ if (!installed.ok) {
340
+ if (!behind) {
341
+ patchStep('cli', {
342
+ status: 'failed',
343
+ detail: installed.detail,
344
+ command: installCommand,
345
+ });
346
+ return set({
347
+ phase: 'failed',
348
+ error: installed.detail,
349
+ failure: classifyFailure(installed.detail),
350
+ guidance: 'install',
351
+ });
352
+ }
353
+ keepOld(installed.detail, installCommand);
354
+ }
355
+ else {
356
+ patchStep('cli', { status: 'running', action: '检查 opencli 版本' });
357
+ version = await probeVersion();
358
+ if (version.stalled) {
359
+ patchStep('cli', { status: 'failed', detail: version.detail, action: undefined });
360
+ return hostFailure(version.detail);
361
+ }
362
+ if (!version.ok) {
363
+ if (!behind) {
364
+ patchStep('cli', { status: 'failed', detail: version.detail, command: installCommand });
365
+ return set({
366
+ phase: 'failed',
367
+ error: version.detail,
368
+ failure: classifyFailure(version.detail),
369
+ guidance: 'path',
370
+ });
371
+ }
372
+ keepOld(version.detail, installCommand);
373
+ }
374
+ }
376
375
  }
377
376
  }
378
- patchStep('cli', { status: 'ok', detail: version.detail, action: undefined });
377
+ if (!keptOld)
378
+ patchStep('cli', { status: 'ok', detail: version.detail, action: undefined });
379
379
  }
380
380
  const keptBridge = previous.get('bridge');
381
381
  if (!skip('bridge'))
@@ -397,10 +397,14 @@ export function createPreflight(options) {
397
397
  await options.desktopBrowser.observe().catch(() => undefined);
398
398
  }
399
399
  const healable = !bridge.ok && warmReads().length > 0 && canWarm(bridge);
400
+ const drift = bridge.ok
401
+ ? extensionDriftOf(bridge.facts?.extension, extension?.version)
402
+ : undefined;
403
+ const incompatible = bridge.issues.includes('extension-incompatible');
400
404
  if (!healable) {
401
405
  patchStep('bridge', {
402
- status: bridge.ok ? 'ok' : 'warn',
403
- detail: bridge.detail,
406
+ status: bridge.ok ? (drift === undefined ? 'ok' : 'warn') : incompatible ? 'failed' : 'warn',
407
+ detail: drift === undefined ? bridge.detail : [bridge.detail, drift].filter((one) => one !== '').join(' · '),
404
408
  action: undefined,
405
409
  ...(bridge.command === undefined ? {} : { command: bridge.command }),
406
410
  });
@@ -408,9 +412,12 @@ export function createPreflight(options) {
408
412
  const settled = withBridge ? await warmSites(bridge) : bridge;
409
413
  const diyGap = await settleDiyStep(diyStarted, stepSink, logger, host.gap?.tier === 'older');
410
414
  logger?.warn?.(`[dsh-workbench] 环境体检:${current.steps.map((item) => `${item.id}=${item.status}`).join(' ')}`);
415
+ const extensionTarget = incompatible ? extension?.version : undefined;
411
416
  const ready = set({
412
417
  phase: 'ready',
413
418
  ...(settled.ok ? {} : { bridgeIssues: settled.issues }),
419
+ ...(extensionTarget === undefined ? {} : { extensionTarget }),
420
+ ...(extension === undefined ? {} : { extensionDir: extension.dir }),
414
421
  ...(host.gap === undefined ? {} : { hostGap: host.gap }),
415
422
  ...(host.facts === undefined ? {} : { hostFacts: host.facts }),
416
423
  ...(diyGap === undefined ? {} : { diyGap }),
@@ -1,4 +1,4 @@
1
- export type PreflightBridgeIssue = 'daemon' | 'extension' | 'profile' | 'stale' | 'unknown';
1
+ export type PreflightBridgeIssue = 'daemon' | 'extension' | 'extension-incompatible' | 'profile' | 'stale' | 'unknown';
2
2
  export declare const BRIDGE_ISSUE_ORDER: readonly PreflightBridgeIssue[];
3
3
  export interface BridgeReport {
4
4
  readonly ok: boolean;
@@ -1,6 +1,27 @@
1
1
  import { tailLines } from '@dsh-workbench/shared/host';
2
2
  import { opencliResultOf } from '@dsh-workbench/adapter-runtime';
3
- export const BRIDGE_ISSUE_ORDER = ['profile', 'stale', 'daemon', 'extension', 'unknown'];
3
+ const EXTENSION_INCOMPATIBLE = /CLI version incompatible with extension|does not report command journal support/iu;
4
+ function extensionVersionOf(text) {
5
+ const line = /^\[OK\] Extension:[^\n]*$/mu.exec(text)?.[0] ?? '';
6
+ return /(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)/.exec(line)?.[1];
7
+ }
8
+ function textFactsOf(text) {
9
+ const extension = extensionVersionOf(text);
10
+ const daemonLine = /^\[[A-Z]+\] Daemon:[^\n]*$/mu.exec(text)?.[0] ?? '';
11
+ return {
12
+ ...(extension === undefined ? {} : { extension }),
13
+ ...(/^\[OK\] Extension:/m.test(text) ? { connected: true } : {}),
14
+ ...(/stale|!=/iu.test(daemonLine) ? { stale: true } : {}),
15
+ };
16
+ }
17
+ export const BRIDGE_ISSUE_ORDER = [
18
+ 'profile',
19
+ 'stale',
20
+ 'daemon',
21
+ 'extension',
22
+ 'extension-incompatible',
23
+ 'unknown',
24
+ ];
4
25
  function jsonReportOf(text) {
5
26
  const trimmed = text.trim();
6
27
  if (!trimmed.startsWith('{'))
@@ -64,10 +85,11 @@ export function readBridgeReport(stdout) {
64
85
  const fromJson = jsonReportOf(text);
65
86
  if (fromJson !== undefined)
66
87
  return fromJson;
88
+ const incompatible = EXTENSION_INCOMPATIBLE.test(text);
67
89
  const ok = /^\[OK\] Daemon:/m.test(text) && /^\[OK\] Extension:/m.test(text) && /^\[OK\] Connectivity:/m.test(text);
68
- if (ok) {
90
+ if (ok && !incompatible) {
69
91
  const good = text.split('\n').find((line) => line.trim() === 'Everything looks good!');
70
- return { ok: true, issues: [], detail: good?.trim() ?? tailLines(text, 1) };
92
+ return { ok: true, issues: [], detail: good?.trim() ?? tailLines(text, 1), facts: textFactsOf(text) };
71
93
  }
72
94
  const found = new Set();
73
95
  if (!/^\[OK\] Daemon:/m.test(text))
@@ -77,6 +99,8 @@ export function readBridgeReport(stdout) {
77
99
  found.add('stale');
78
100
  if (!/^\[OK\] Extension:/m.test(text))
79
101
  found.add('extension');
102
+ if (incompatible)
103
+ found.add('extension-incompatible');
80
104
  if (/Multiple Chrome profiles are connected/i.test(text))
81
105
  found.add('profile');
82
106
  if (/Default browser profile is stale|Selected browser profile is not connected/i.test(text)) {
@@ -86,7 +110,12 @@ export function readBridgeReport(stdout) {
86
110
  found.delete('extension');
87
111
  if (found.size === 0)
88
112
  found.add('unknown');
89
- return { ok: false, issues: BRIDGE_ISSUE_ORDER.filter((issue) => found.has(issue)), detail: issuesSection(text) };
113
+ return {
114
+ ok: false,
115
+ issues: BRIDGE_ISSUE_ORDER.filter((issue) => found.has(issue)),
116
+ detail: issuesSection(text),
117
+ facts: textFactsOf(text),
118
+ };
90
119
  }
91
120
  function issuesSection(text) {
92
121
  const lines = text.split('\n');
@@ -1,4 +1,4 @@
1
- import { opencliResultOf } from '@dsh-workbench/adapter-runtime';
1
+ import { backgroundLine, installedOpencliVersion, opencliResultOf, sessionDialectOf, } from '@dsh-workbench/adapter-runtime';
2
2
  import { activateAppCommand, bringBackCommand, browserAppNamesOf, frontAppCommand, frontAppOf, isBrowserAppName, noWrite } from '@dsh-workbench/shared/host';
3
3
  import { currentHostOs } from './platform.js';
4
4
  const TIMEOUT_MS = 5000;
@@ -37,7 +37,7 @@ const browserAppOf = (app) => isBrowserAppName(app);
37
37
  async function chromeCall(seam, command, method, args) {
38
38
  const result = await seam
39
39
  .run({
40
- argv: [command, 'browser', '--session', 'workbench-probe', 'chrome', 'call', method, args],
40
+ command: backgroundLine(command, ['browser', 'workbench-probe', 'chrome', 'call', method, args], { dialect: sessionDialectOf(installedOpencliVersion()) }),
41
41
  intent: noWrite(),
42
42
  timeoutMs: 10_000,
43
43
  bestEffort: true,
@@ -20,6 +20,7 @@ export interface VersionProbeInput {
20
20
  export interface OpencliVersionVerdict {
21
21
  readonly ok: boolean;
22
22
  readonly missing: boolean;
23
+ readonly behind?: boolean | undefined;
23
24
  readonly detail: string;
24
25
  readonly stalled: boolean;
25
26
  }
@@ -1,5 +1,5 @@
1
1
  import { setTimeout as delay } from 'node:timers/promises';
2
- import { OPENCLI_SUPPORTED_RANGE, checkVersionRange } from '@dsh-workbench/shared/host';
2
+ import { OPENCLI_PIN, OPENCLI_PIN_ENV, OPENCLI_SUPPORTED_RANGE, checkVersionRange, runtimePinOf, } from '@dsh-workbench/shared/host';
3
3
  const RETRY_DELAY_MS = 1_000;
4
4
  function versionOf(text) {
5
5
  const match = /\bv?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)/.exec(text);
@@ -16,8 +16,12 @@ export async function probeOpencliVersion(input) {
16
16
  if (result.kind === 'ok') {
17
17
  const detail = result.stdout.trim().split('\n')[0] ?? '';
18
18
  const version = versionOf(detail);
19
- if (version !== undefined && checkVersionRange(OPENCLI_SUPPORTED_RANGE, version) === 'unsatisfied') {
20
- return { ok: false, missing: true, detail: `装的是 ${version},这段只认 ${OPENCLI_SUPPORTED_RANGE}`, stalled: false };
19
+ const pin = runtimePinOf(OPENCLI_PIN, OPENCLI_PIN_ENV);
20
+ if (version !== undefined && version !== pin) {
21
+ if (checkVersionRange(OPENCLI_SUPPORTED_RANGE, version) === 'unsatisfied') {
22
+ return { ok: false, missing: true, detail: `装的是 ${version},这段只认 ${OPENCLI_SUPPORTED_RANGE}`, stalled: false };
23
+ }
24
+ return { ok: false, missing: false, behind: true, detail: `装的是 ${version},这段固定 ${pin}`, stalled: false };
21
25
  }
22
26
  return { ok: true, missing: false, detail, stalled: false };
23
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsh-workbench/adapter-probe",
3
- "version": "1.5.2",
3
+ "version": "1.5.3-rc.0",
4
4
  "description": "Workbench adapter-probe adapter.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -14,10 +14,10 @@
14
14
  ],
15
15
  "dependencies": {
16
16
  "proper-lockfile": "^4.1.2",
17
- "@dsh-workbench/adapter-profile": "1.5.2",
18
- "@dsh-workbench/adapter-runtime": "1.5.2",
19
- "@dsh-workbench/shared": "1.5.2",
20
- "@dsh-workbench/adapter-supply": "1.5.2"
17
+ "@dsh-workbench/adapter-profile": "1.5.3-rc.0",
18
+ "@dsh-workbench/adapter-runtime": "1.5.3-rc.0",
19
+ "@dsh-workbench/adapter-supply": "1.5.3-rc.0",
20
+ "@dsh-workbench/shared": "1.5.3-rc.0"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/node": "^24.19.0",