@dsh-workbench/adapter-probe 1.5.2-alpha.5 → 1.5.2-rc.1

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.
@@ -1,10 +1,10 @@
1
1
  import { existsSync, readdirSync } from 'node:fs';
2
2
  import { basename, join } from 'node:path';
3
- import { OPENCLI_PIN, PREFLIGHT_INSTALL_TIMEOUT_MS, PREFLIGHT_VERSION_TIMEOUT_MS, hostOsOf, preflightHandler, quoteShellArgFor, workbenchRoot } from '@dsh-workbench/shared/host';
3
+ import { OPENCLI_PIN, PREFLIGHT_INSTALL_TIMEOUT_MS, PREFLIGHT_VERSION_TIMEOUT_MS, dshHostGapOf, dshTierOf, dshVersionFrom, hostOsOf, preflightHandler, quoteShellArgFor, workbenchRoot } from '@dsh-workbench/shared/host';
4
4
  import { isOpencliReady, isOpencliReadyAt, 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
- import { createDiyPresetProbe } from './diy-preset-health.js';
7
+ import { createDiyPresetProbe, DIY_UPGRADE_COMMAND } from './diy-preset-health.js';
8
8
  import { installIsolatedRuntime } from '../install/isolated-install.js';
9
9
  import { describeInstallRecord, installRecordFile, readInstallRecord } from '../install/install-record.js';
10
10
  import { smokeInstalledCli } from '../install/install-smoke.js';
@@ -103,6 +103,14 @@ export function registerPreflight(input) {
103
103
  });
104
104
  const installLogger = input.ctx.logger;
105
105
  const installLog = installLogger === undefined ? undefined : (message) => installLogger.warn?.(message);
106
+ const runtimeDsh = () => {
107
+ const dir = profileDirOf(input.ctx);
108
+ if (dir === null)
109
+ return { log: ['profile: 取不到这份工作台的配置目录'] };
110
+ const found = dshVersionFrom(dir);
111
+ const log = [`profile: ${dir}`, ...(found === undefined ? ['dsh: 读不到版本'] : [`dsh: ${found.version}`, `from: ${found.from}`])];
112
+ return found === undefined ? { log } : { version: found.version, log };
113
+ };
106
114
  const preflight = createPreflight({
107
115
  seam: input.seam,
108
116
  snapshotRoot: workbenchRoot(),
@@ -152,6 +160,15 @@ export function registerPreflight(input) {
152
160
  ...(input.runtimeCheck === undefined ? {} : { runtimeCheck: input.runtimeCheck }),
153
161
  ...(input.runtimeLabel === undefined ? {} : { runtimeLabel: input.runtimeLabel }),
154
162
  probeDiy: createDiyPresetProbe(input.ctx),
163
+ probeHost: () => {
164
+ const runtime = runtimeDsh();
165
+ const gap = dshHostGapOf(runtime.version);
166
+ if (gap === undefined) {
167
+ return dshTierOf(runtime.version) === 'ok' ? { tier: 'ok', log: runtime.log } : undefined;
168
+ }
169
+ const command = gap.tier === 'older' ? { command: DIY_UPGRADE_COMMAND } : {};
170
+ return { ...gap, ...command, log: runtime.log };
171
+ },
155
172
  probeToolchain: () => probeDesktopToolchain(input.seam),
156
173
  provisionPnpm: async () => {
157
174
  const root = runtimeSeedRootOf(input.ctx);
@@ -0,0 +1,12 @@
1
+ import type { PreflightDiyGap, PreflightHostGap, PreflightHostStanding, PreflightStep, PreflightStepId } from '@dsh-workbench/shared/host';
2
+ import { type DiyPresetVerdict } from './diy-preset-health.js';
3
+ export interface StepSink {
4
+ readonly steps: readonly PreflightStep[];
5
+ patch(id: PreflightStepId, patch: Partial<PreflightStep>): void;
6
+ drop(id: PreflightStepId): void;
7
+ }
8
+ export declare function pendingStep(id: PreflightStepId, label?: string): PreflightStep;
9
+ export declare function settleHostStep(standing: PreflightHostStanding | undefined, sink: StepSink): PreflightHostGap | undefined;
10
+ export declare function settleDiyStep(started: Promise<DiyPresetVerdict | undefined> | undefined, sink: StepSink, logger?: {
11
+ warn?(message: string): void;
12
+ }): Promise<PreflightDiyGap | undefined>;
@@ -0,0 +1,40 @@
1
+ import { DIY_UPGRADE_COMMAND } from './diy-preset-health.js';
2
+ export function pendingStep(id, label) {
3
+ return { id, status: 'pending', ...(label === undefined || label === '' ? {} : { label }) };
4
+ }
5
+ export function settleHostStep(standing, sink) {
6
+ if (standing === undefined) {
7
+ sink.drop('host');
8
+ return undefined;
9
+ }
10
+ const log = standing.log === undefined ? {} : { log: [...standing.log] };
11
+ if (standing.tier === 'ok') {
12
+ sink.patch('host', { status: 'ok', ...log });
13
+ return undefined;
14
+ }
15
+ sink.patch('host', {
16
+ status: 'warn',
17
+ detail: standing.runtime,
18
+ ...(standing.command === undefined ? {} : { command: standing.command }),
19
+ ...log,
20
+ });
21
+ return standing;
22
+ }
23
+ export async function settleDiyStep(started, sink, logger) {
24
+ if (started === undefined)
25
+ return undefined;
26
+ const verdict = await started.catch((error) => {
27
+ logger?.warn?.(`[dsh-workbench] 启动检查读 DIY 模式列表失败:${error instanceof Error ? error.message : String(error)}`);
28
+ return undefined;
29
+ });
30
+ if (verdict === undefined) {
31
+ sink.drop('diy');
32
+ return undefined;
33
+ }
34
+ if (verdict.ok) {
35
+ sink.patch('diy', { status: 'ok', detail: verdict.detail });
36
+ return undefined;
37
+ }
38
+ sink.patch('diy', { status: 'warn', detail: verdict.detail, command: DIY_UPGRADE_COMMAND });
39
+ return { rows: verdict.rows, detail: verdict.detail, command: DIY_UPGRADE_COMMAND };
40
+ }
@@ -7,13 +7,13 @@ import type { DesktopBrowser } from '../runtime/browser-wake.js';
7
7
  export type PreflightFailure = 'permission' | 'network' | 'missing' | 'host' | 'unknown';
8
8
  export declare function classifyFailure(text: string): PreflightFailure;
9
9
  export type PreflightGuidance = 'install' | 'path' | 'shell' | 'host';
10
- export type PreflightStepId = 'toolchain' | 'runtime' | 'cli' | 'bridge' | 'diy' | 'warm';
10
+ export type PreflightStepId = 'toolchain' | 'runtime' | 'host' | 'cli' | 'bridge' | 'diy' | 'warm';
11
11
  export type PreflightStepStatus = 'pending' | 'running' | 'ok' | 'warn' | 'failed';
12
- import type { PreflightSnapshot } from '@dsh-workbench/shared/host';
12
+ import type { PreflightHostStanding, PreflightSnapshot } from '@dsh-workbench/shared/host';
13
13
  import { type PreflightBridgeIssue } from '../runtime/bridge-report.js';
14
14
  export { BRIDGE_ISSUE_ORDER, readBridgeReport } from '../runtime/bridge-report.js';
15
15
  export type { PreflightBridgeIssue } from '../runtime/bridge-report.js';
16
- export type { PreflightDiyGap, PreflightSnapshot, PreflightStep } from '@dsh-workbench/shared/host';
16
+ export type { PreflightDiyGap, PreflightHostGap, PreflightHostStanding, PreflightSnapshot, PreflightStep } from '@dsh-workbench/shared/host';
17
17
  export interface Preflight {
18
18
  run(options?: {
19
19
  hard?: boolean;
@@ -51,6 +51,7 @@ export declare function createPreflight(options: {
51
51
  withToolchainLock?: (<T>(run: () => Promise<T>) => Promise<T>) | undefined;
52
52
  warmReads?: (() => readonly (readonly string[])[]) | undefined;
53
53
  probeDiy?: (() => Promise<DiyPresetVerdict | undefined>) | undefined;
54
+ probeHost?: (() => PreflightHostStanding | undefined) | undefined;
54
55
  probeToolchain?: (() => Promise<ToolchainReport>) | undefined;
55
56
  provisionNpm?: (() => Promise<LocalNpmProvision>) | undefined;
56
57
  provisionPnpm?: (() => Promise<LocalPnpmProvision>) | undefined;
@@ -2,7 +2,7 @@ import { PREFLIGHT_DOCTOR_TIMEOUT_MS, PREFLIGHT_FRESH_MS, PREFLIGHT_INSTALL_TIME
2
2
  import { opencliCommandLine, OPENCLI_SITE_SESSION_ENV, OPENCLI_WINDOW_ENV } from '@dsh-workbench/adapter-runtime';
3
3
  import { notePreflightFailed } from './preflight-note.js';
4
4
  import { persistPreflightSnapshot } from './preflight-snapshot.js';
5
- import { DIY_UPGRADE_COMMAND } from './diy-preset-health.js';
5
+ import { pendingStep, settleDiyStep, settleHostStep } from './preflight-steps.js';
6
6
  import { opencliInstallCommand } from '../install/install.js';
7
7
  import { LOCAL_PNPM_VERSION } from '../toolchain/toolchain.js';
8
8
  import { bridgeFixCommand } from '../runtime/browser-wake.js';
@@ -29,9 +29,6 @@ const WARMABLE_BRIDGE_ISSUES = ['daemon', 'stale'];
29
29
  export function canWarm(bridge) {
30
30
  return bridge.ok || bridge.issues.every((issue) => WARMABLE_BRIDGE_ISSUES.includes(issue));
31
31
  }
32
- function step(id, label) {
33
- return { id, status: 'pending', ...(label === undefined || label === '' ? {} : { label }) };
34
- }
35
32
  export function createPreflight(options) {
36
33
  const { seam, command = 'opencli', logger } = options;
37
34
  const platform = options.platform;
@@ -43,12 +40,13 @@ export function createPreflight(options) {
43
40
  const installCommand = options.installCommand ?? opencliInstallCommandDefault();
44
41
  const warmReads = () => options.warmReads?.() ?? [];
45
42
  const steps = () => [
46
- ...(options.probeToolchain === undefined ? [] : [step('toolchain')]),
47
- ...(options.runtimeCheck === undefined ? [] : [step('runtime', options.runtimeLabel)]),
48
- ...(withConsole ? [step('cli')] : []),
49
- ...(withBridge ? [step('bridge')] : []),
50
- ...(options.probeDiy === undefined ? [] : [step('diy')]),
51
- ...(warmReads().length === 0 ? [] : [step('warm')]),
43
+ ...(options.probeToolchain === undefined ? [] : [pendingStep('toolchain')]),
44
+ ...(options.runtimeCheck === undefined ? [] : [pendingStep('runtime', options.runtimeLabel)]),
45
+ ...(options.probeHost === undefined ? [] : [pendingStep('host')]),
46
+ ...(withConsole ? [pendingStep('cli')] : []),
47
+ ...(withBridge ? [pendingStep('bridge')] : []),
48
+ ...(options.probeDiy === undefined ? [] : [pendingStep('diy')]),
49
+ ...(warmReads().length === 0 ? [] : [pendingStep('warm')]),
52
50
  ];
53
51
  let logLines = [];
54
52
  const stepLogs = new Map();
@@ -222,23 +220,19 @@ export function createPreflight(options) {
222
220
  });
223
221
  return again;
224
222
  }
225
- async function settleDiy(started) {
226
- if (started === undefined)
227
- return undefined;
228
- const verdict = await started.catch(() => undefined);
229
- if (verdict === undefined) {
230
- set({ steps: current.steps.filter((item) => item.id !== 'diy') });
231
- return undefined;
232
- }
233
- if (verdict.ok) {
234
- patchStep('diy', { status: 'ok', detail: verdict.detail });
235
- return undefined;
236
- }
237
- patchStep('diy', { status: 'warn', detail: verdict.detail, command: DIY_UPGRADE_COMMAND });
238
- return { rows: verdict.rows, detail: verdict.detail, command: DIY_UPGRADE_COMMAND };
239
- }
223
+ const stepSink = {
224
+ get steps() {
225
+ return current.steps;
226
+ },
227
+ patch: (id, patch) => {
228
+ patchStep(id, patch);
229
+ },
230
+ drop: (id) => {
231
+ set({ steps: current.steps.filter((item) => item.id !== id) });
232
+ },
233
+ };
240
234
  async function doRun(from) {
241
- const order = ['toolchain', 'runtime', 'cli', 'bridge', 'diy', 'warm'];
235
+ const order = ['toolchain', 'runtime', 'host', 'cli', 'bridge', 'diy', 'warm'];
242
236
  const skip = (id) => from !== undefined && order.indexOf(id) >= 0 && order.indexOf(id) < order.indexOf(from);
243
237
  const previous = new Map(current.steps.map((item) => [item.id, item]));
244
238
  shellStalled = false;
@@ -250,6 +244,7 @@ export function createPreflight(options) {
250
244
  failure: undefined,
251
245
  guidance: undefined,
252
246
  bridgeIssues: undefined,
247
+ hostGap: undefined,
253
248
  diyGap: undefined,
254
249
  steps: steps().map((item) => {
255
250
  const kept = skip(item.id) ? previous.get(item.id) : undefined;
@@ -319,6 +314,7 @@ export function createPreflight(options) {
319
314
  if (!verdict.ok)
320
315
  return set({ phase: 'failed', error: verdict.detail, failure: 'missing', guidance: 'install' });
321
316
  }
317
+ const hostGap = settleHostStep(options.probeHost?.(), stepSink);
322
318
  const diyStarted = skip('diy') ? undefined : options.probeDiy?.();
323
319
  if (withConsole && !skip('cli')) {
324
320
  patchStep('cli', { status: 'running', action: '检查 opencli 版本' });
@@ -415,11 +411,12 @@ export function createPreflight(options) {
415
411
  });
416
412
  }
417
413
  const settled = withBridge ? await warmSites(bridge) : bridge;
418
- const diyGap = await settleDiy(diyStarted);
414
+ const diyGap = await settleDiyStep(diyStarted, stepSink, logger);
419
415
  logger?.warn?.(`[dsh-workbench] 环境体检:${current.steps.map((item) => `${item.id}=${item.status}`).join(' ')}`);
420
416
  return set({
421
417
  phase: 'ready',
422
418
  ...(settled.ok ? {} : { bridgeIssues: settled.issues }),
419
+ ...(hostGap === undefined ? {} : { hostGap }),
423
420
  ...(diyGap === undefined ? {} : { diyGap }),
424
421
  });
425
422
  }
@@ -1,10 +1,11 @@
1
1
  import { opencliResultOf } from '@dsh-workbench/adapter-runtime';
2
2
  import { commandNamesMatch } from './command-name.js';
3
- import { OPENCLI_TIMEOUT_MS, PROBE_TTL_MS, buildSupplyIndex, NEED_KIND_SPECS, needIdOf, hostOsOf, noWrite, npmSourceOf, productWrite, quoteShellArgFor, toolLookupOf, mapWithLimit, } from '@dsh-workbench/shared/host';
3
+ import { OPENCLI_TIMEOUT_MS, PROBE_TTL_MS, builtinCommandsOf, buildSupplyIndex, NEED_KIND_SPECS, needIdOf, hostOsOf, noWrite, npmSourceOf, productWrite, quoteShellArgFor, toolLookupOf, mapWithLimit, } from '@dsh-workbench/shared/host';
4
4
  import { npmRegistryOf } from '@dsh-workbench/adapter-supply';
5
5
  import { probeRelease } from './release-port.js';
6
6
  import { createTimedMemo } from './probe-cache.js';
7
7
  import { probeLibs } from './probe-libs.js';
8
+ import { cliCatalogPath } from '@dsh-workbench/adapter-runtime';
8
9
  import { aggregate, binStateOf, envStateOf, extensionStateOf } from './probe-verdict.js';
9
10
  const BINARY_PROBE_TIMEOUT_MS = 5_000;
10
11
  const PROBE_CONCURRENCY = 4;
@@ -178,6 +179,7 @@ async function loadCapabilities(options) {
178
179
  const libProbes = probeLibs({ needs: libNeeds, seam, force, index });
179
180
  const releaseProbes = releasesOf(index, { seam, force });
180
181
  const [, , libStates, releases] = await Promise.all([binProbes, runtimeProbes, libProbes, releaseProbes]);
182
+ const builtin = builtinCommandsOf(cliCatalogPath());
181
183
  const runtimeProblems = runtimeMismatchOf(options.runtimeReport);
182
184
  const statesOfUnit = (unit) => unit.needs.map((need) => {
183
185
  const conflict = need.kind === 'extension' || need.kind === 'lib' ? conflictOf(index, need) : undefined;
@@ -215,11 +217,15 @@ async function loadCapabilities(options) {
215
217
  }
216
218
  const probe = lists.get(need.runtime) ?? { failure: '没跑这一轮探测' };
217
219
  const command = runtimeCommandOf(need, runtimeCommands) ?? need.runtime;
218
- const hit = probe.list?.find((item) => typeof item === 'object' && item !== null && String(item.name) === need.name);
220
+ const usesBuiltin = need.runtime === 'opencli' && (need.sources ?? []).some((one) => one.kind === 'builtin');
221
+ const builtinCommands = usesBuiltin ? builtin.get(need.name) : undefined;
222
+ const listed = probe.list?.find((item) => typeof item === 'object' && item !== null && String(item.name) === need.name);
223
+ const hit = builtinCommands === undefined ? listed : { commands: builtinCommands };
219
224
  return extensionStateOf({
220
225
  need,
221
- ...(probe.list === undefined ? {} : { hit }),
222
- ...(probe.failure === undefined ? {} : { failure: probe.failure }),
226
+ ...(hit === undefined ? {} : { hit }),
227
+ ...(usesBuiltin ? { builtin: true } : {}),
228
+ ...(hit === undefined && !usesBuiltin && probe.failure !== undefined ? { failure: probe.failure } : {}),
223
229
  command,
224
230
  ...(releases.get(`${need.runtime}:${need.name}`) === undefined
225
231
  ? {}
@@ -7,6 +7,7 @@ export declare function extensionStateOf(options: {
7
7
  readonly commands?: unknown;
8
8
  } | undefined;
9
9
  readonly failure?: string | undefined;
10
+ readonly builtin?: boolean | undefined;
10
11
  readonly command: string;
11
12
  readonly release?: PluginRelease | undefined;
12
13
  readonly sources: readonly SupplySource[];
@@ -45,6 +45,14 @@ export function extensionStateOf(options) {
45
45
  return { ...base, status: 'unchecked', detail: options.failure };
46
46
  }
47
47
  if (options.hit === undefined) {
48
+ if (options.builtin === true) {
49
+ return {
50
+ ...base,
51
+ status: 'missing',
52
+ detail: `当前 ${options.command} 的清单里没有 ${options.need.name}:${options.command} 版本旧,或这个站点不存在`,
53
+ provision: 'ready',
54
+ };
55
+ }
48
56
  const resolved = firstResolvable(options.need, options.command, options.sources);
49
57
  return {
50
58
  ...base,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsh-workbench/adapter-probe",
3
- "version": "1.5.2-alpha.5",
3
+ "version": "1.5.2-rc.1",
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-supply": "1.5.2-alpha.5",
18
- "@dsh-workbench/adapter-runtime": "1.5.2-alpha.5",
19
- "@dsh-workbench/adapter-profile": "1.5.2-alpha.5",
20
- "@dsh-workbench/shared": "1.5.2-alpha.5"
17
+ "@dsh-workbench/adapter-profile": "1.5.2-rc.1",
18
+ "@dsh-workbench/adapter-supply": "1.5.2-rc.1",
19
+ "@dsh-workbench/adapter-runtime": "1.5.2-rc.1",
20
+ "@dsh-workbench/shared": "1.5.2-rc.1"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/node": "^24.19.0",