@dsh-workbench/shared 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.
Files changed (40) hide show
  1. package/dist/components/card/CardBoundary.js +2 -3
  2. package/dist/components/card/CardBoundary.module.css +0 -6
  3. package/dist/contract/blocker.d.ts +4 -0
  4. package/dist/contract/blocker.js +2 -1
  5. package/dist/contract/capabilities.d.ts +5 -0
  6. package/dist/contract/protocol/unit-manifests.d.ts +6 -0
  7. package/dist/host/adapters/port-types.d.ts +4 -2
  8. package/dist/host/runtime/diag-bundle.d.ts +3 -2
  9. package/dist/host/runtime/diag-bundle.js +2 -1
  10. package/dist/host/runtime/diag-records.d.ts +7 -0
  11. package/dist/host/runtime/diag-records.js +4 -0
  12. package/dist/host/runtime/diag-sink.d.ts +1 -0
  13. package/dist/host/runtime/diag-sink.js +17 -3
  14. package/dist/host/runtime/diag-summary.d.ts +6 -0
  15. package/dist/host/runtime/diag-summary.js +16 -0
  16. package/dist/host/supply/preflight.d.ts +1 -0
  17. package/dist/i18n/en.js +2 -2
  18. package/dist/i18n/index.d.ts +3 -3
  19. package/dist/i18n/zh.d.ts +2 -2
  20. package/dist/i18n/zh.js +2 -2
  21. package/package.json +1 -1
  22. package/src/components/card/CardBoundary.module.css +0 -6
  23. package/src/components/card/CardBoundary.tsx +1 -2
  24. package/src/components/card/__tests__/card-boundary.test.tsx +5 -4
  25. package/src/contract/blocker.ts +10 -2
  26. package/src/contract/capabilities.ts +6 -0
  27. package/src/contract/protocol/unit-manifests.ts +7 -0
  28. package/src/host/adapters/port-types.ts +4 -2
  29. package/src/host/runtime/__tests__/diag-bundle.test.ts +8 -0
  30. package/src/host/runtime/__tests__/diag-records.test.ts +33 -1
  31. package/src/host/runtime/__tests__/diag-sink.test.ts +43 -0
  32. package/src/host/runtime/__tests__/diag-summary.test.ts +29 -1
  33. package/src/host/runtime/diag-bundle.ts +4 -2
  34. package/src/host/runtime/diag-records.ts +12 -0
  35. package/src/host/runtime/diag-sink.ts +26 -4
  36. package/src/host/runtime/diag-summary.ts +22 -0
  37. package/src/host/supply/preflight.ts +1 -0
  38. package/src/host.ts +1 -1
  39. package/src/i18n/en.ts +2 -2
  40. package/src/i18n/zh.ts +2 -2
package/dist/i18n/zh.js CHANGED
@@ -239,7 +239,6 @@ export const zh = {
239
239
  'panels.market.failure.askAgentText': '安装这个模块时无法写入:`{command}` 退出码为 {code},受阻于 {path}。请确认是沙箱拦截还是权限问题,并换一个可写入的位置重新安装。',
240
240
  'panels.market.failure.askAgentAuth': '安装这个模块时,私有源 {registry} 拒绝了请求(401/403):`{command}` 退出码为 {code}。\n输出:{reason}\n先确认这台机器有没有这个源的凭据(~/.npmrc 里的 _authToken):登录、补 token 或换一个有权限的账号,再重试。',
241
241
  'panels.market.failure.askAgentUnknown': '安装这个模块失败:`{command}` 退出码为 {code},原因没能自动认出来。\n输出:{reason}\n请按这段输出定位(私有源没登录?网络不通?包名不对?),再重试。',
242
- 'panels.market.failure.askAgentHint': '粘贴到对话里,agent 会继续诊断。',
243
242
  'panels.market.failure.recheck': '再次检查',
244
243
  'panels.market.failure.showOutput': '查看安装输出',
245
244
  'panels.market.failure.hideOutput': '收起安装输出',
@@ -721,6 +720,8 @@ export const zh = {
721
720
  'env.bridge.why': '面板数据需要浏览器中的登录状态。连接未建立时,模块无法获取数据。可以修复后继续,也可以先进入工作台。',
722
721
  'env.bridge.extensionOffline': '扩展没有连接。可以任选一种安装方式:① 点击下面的链接,从 Chrome 应用商店安装;② 加载本地副本:打开 chrome://extensions,在右上角开启「开发者模式」,点击「加载已解压的扩展程序」,选择扩展目录。安装完成后回来点击「重试」。',
723
722
  'env.bridge.extensionLocal': '扩展没有连接。可以任选一种安装方式:① 使用工作台自带的副本:打开 chrome://extensions,在右上角开启「开发者模式」,点击「加载已解压的扩展程序」,选择 {dir};② 点击下面的链接,从 Chrome 应用商店安装。安装完成后回来点击「重试」。',
723
+ 'env.bridge.extensionIncompatible': '浏览器扩展和后台工具的版本不兼容:面板读不到数据。把扩展更新到 v{version},再回来点击「重试」。',
724
+ 'env.bridge.extensionIncompatibleAny': '浏览器扩展和后台工具的版本不兼容:面板读不到数据。换一个兼容的扩展版本,再回来点击「重试」。',
724
725
  'env.bridge.hold': '浏览器还没有连接。请按下面的步骤修复后点击「重试」,也可以先进入工作台。',
725
726
  'env.bridge.unknown': '浏览器连接有问题,但工作台没能识别是哪一类。可以展开原文查看,也可以让 agent 诊断。',
726
727
  'env.fix.title': '解决方法',
@@ -757,7 +758,6 @@ export const zh = {
757
758
  'askAgent.title': '需要 agent 诊断',
758
759
  'askAgent.copy': '复制给 agent',
759
760
  'askAgent.copied': '已复制',
760
- 'askAgent.hint': '粘贴到对话里,agent 会继续诊断。',
761
761
  'askAgent.prompt.head': '工作台遇到一个问题,需要你定位。',
762
762
  'askAgent.prompt.whereOnly': '位置:{screen}',
763
763
  'askAgent.screen.board': '看板',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsh-workbench/shared",
3
- "version": "1.5.2",
3
+ "version": "1.5.3-rc.0",
4
4
  "description": "工作台与模块共享的纯代码与契约类型:类型、纯逻辑、哑组件、平台解析。宿主侧的东西从 /host 进(不影响浏览器产物)。",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -7,9 +7,3 @@
7
7
  .raw {
8
8
  margin-top: var(--wb-len-4);
9
9
  }
10
-
11
- .hint {
12
- margin-top: var(--wb-len-4);
13
- font-size: var(--dsw-font-xxs-12-font-size);
14
- color: var(--dsw-alias-label-secondary);
15
- }
@@ -149,13 +149,12 @@ export class CardBoundary extends Component<CardBoundaryProps, CardBoundaryState
149
149
  },
150
150
  {
151
151
  key: 'ask-agent',
152
- label: this.props.t('askAgent.copy'),
152
+ label: this.props.t(copied ? 'askAgent.copied' : 'askAgent.copy'),
153
153
  kind: 'primary',
154
154
  onClick: this.copyPrompt,
155
155
  },
156
156
  ]}
157
157
  />
158
- {copied ? <p className={styles.hint}>{this.props.t('askAgent.hint')}</p> : null}
159
158
  </div>
160
159
  </Note>
161
160
  );
@@ -96,13 +96,14 @@ describe('卡片渲染崩溃:事实 + 折叠原文 + 两个出口', () => {
96
96
  expect(actions[1]?.kind).toBe('primary');
97
97
  });
98
98
 
99
- it('复制成功后出提示;按钮态由外层按 copied 渲染', () => {
100
- const rendered = JSON.stringify(renderOf(boundary()));
101
- expect(rendered).not.toContain('askAgent.hint');
99
+ it('★ 复制成功后按钮自己变「已复制」,不另加一句提示', () => {
100
+ const before = JSON.stringify(renderOf(boundary()));
101
+ expect(before).toContain('askAgent.copy');
102
+ expect(before).not.toContain('askAgent.copied');
102
103
 
103
104
  const one = boundary();
104
105
  one.setState({ copied: true });
105
- expect(JSON.stringify(renderOf(one))).toContain('askAgent.hint');
106
+ expect(JSON.stringify(renderOf(one))).toContain('askAgent.copied');
106
107
  });
107
108
 
108
109
  it('★ 复制走的是提示词构造器:位置 + 哪个模块 + 报错首行', async () => {
@@ -168,10 +168,17 @@ export interface DiagFilter {
168
168
  readonly area?: DiagArea;
169
169
  readonly class?: DiagClass;
170
170
  readonly code?: string;
171
+ readonly host?: string;
171
172
  }
172
173
 
173
174
  export function diagMatches(
174
- record: { readonly ts: number; readonly area: DiagArea; readonly class: DiagClass; readonly code: string },
175
+ record: {
176
+ readonly ts: number;
177
+ readonly area: DiagArea;
178
+ readonly class: DiagClass;
179
+ readonly code: string;
180
+ readonly host?: { readonly profile?: string } | undefined;
181
+ },
175
182
  filter: DiagFilter,
176
183
  ): boolean {
177
184
  return (
@@ -179,7 +186,8 @@ export function diagMatches(
179
186
  (filter.until === undefined || record.ts <= filter.until) &&
180
187
  (filter.area === undefined || record.area === filter.area) &&
181
188
  (filter.class === undefined || record.class === filter.class) &&
182
- (filter.code === undefined || record.code === filter.code)
189
+ (filter.code === undefined || record.code === filter.code) &&
190
+ (filter.host === undefined || filter.host === '*' || (record.host?.profile ?? 'unknown') === filter.host)
183
191
  );
184
192
  }
185
193
 
@@ -29,6 +29,12 @@ export interface RuntimeProfile {
29
29
  readonly bridge?: Readonly<Partial<Record<string, RuntimeBridgeFix>>>;
30
30
  }
31
31
 
32
+ export interface BrowserExtension {
33
+ readonly dir: string;
34
+ readonly version: string;
35
+ readonly source: 'env' | 'bundled';
36
+ }
37
+
32
38
  export interface RuntimeBridgeStatus {
33
39
  readonly extension?: string;
34
40
  readonly connectivityMs?: number;
@@ -2,7 +2,14 @@ import type { UnitManifest } from '../unit.js';
2
2
 
3
3
  export const UNIT_MANIFESTS_ROUTE = 'unit-manifests';
4
4
 
5
+ export interface UnitManifestRefusal {
6
+ readonly unit: string;
7
+ readonly pkg?: string;
8
+ readonly reasons: readonly string[];
9
+ }
10
+
5
11
  export interface UnitManifestsPayload {
6
12
  readonly manifests: readonly UnitManifest[];
7
13
  readonly installable: readonly string[];
14
+ readonly refusals?: readonly UnitManifestRefusal[];
8
15
  }
@@ -1,7 +1,7 @@
1
1
  import type { DshHostContext } from '../../api/dsh.js';
2
2
  import type { DiagRecorder } from '../runtime/diag-records.js';
3
3
  import type { Seam } from '../seam/run.js';
4
- import type { RuntimeCapabilities, RuntimeProfile } from '../../contract/capabilities.js';
4
+ import type { BrowserExtension, RuntimeCapabilities, RuntimeProfile } from '../../contract/capabilities.js';
5
5
  import type { BrowserCaptureRow } from '../../contract/data.js';
6
6
  import type { PluginPackageKind } from '../../contract/protocol/bundle-install.js';
7
7
  import type { LibNeed, SupplySource } from '../../contract/needs.js';
@@ -176,6 +176,7 @@ export interface ProbePreflightInput {
176
176
  readonly runtimeCheck?: (() => Promise<RuntimeCheck>) | undefined;
177
177
  readonly runtimeLabel?: string | undefined;
178
178
  readonly warmReads: () => readonly (readonly string[])[];
179
+ readonly extension?: (() => BrowserExtension | undefined) | undefined;
179
180
  readonly extensionDir?: string | undefined;
180
181
  readonly diag?: DiagRecorder | undefined;
181
182
  }
@@ -191,7 +192,7 @@ export interface RuntimeSeedOptions {
191
192
  readonly log: (message: string) => void;
192
193
  }
193
194
 
194
- export type { RuntimeCapabilities, RuntimeProfile, RuntimeTerms } from '../../contract/capabilities.js';
195
+ export type { BrowserExtension, RuntimeCapabilities, RuntimeProfile, RuntimeTerms } from '../../contract/capabilities.js';
195
196
 
196
197
  export interface RuntimeCheck {
197
198
  readonly ok: boolean;
@@ -225,6 +226,7 @@ export interface RuntimePort {
225
226
  frontApp?(ctx: DshHostContext): Promise<string | undefined>;
226
227
  bringToFront?(ctx: DshHostContext, app: string): Promise<boolean>;
227
228
  raiseBrowser?(ctx: DshHostContext): Promise<boolean>;
229
+ browserExtension?(ctx: DshHostContext): BrowserExtension | undefined;
228
230
  }
229
231
 
230
232
  export interface PluginDeclarationSource {
@@ -37,6 +37,14 @@ describe('诊断目录', () => {
37
37
  expect(bundle.truncated).toEqual([]);
38
38
  });
39
39
 
40
+ it('★ manifest 写明宿主,schema 已升到 2', () => {
41
+ const host = { profile: 'web', deployment: 'web', pid: 11 } as const;
42
+ const bundle = buildDiagBundle(inputOf({ host }));
43
+
44
+ expect(bundle.manifest['schema']).toBe(2);
45
+ expect(bundle.manifest['host']).toEqual(host);
46
+ });
47
+
40
48
  it('★ 脱敏:敏感键剔除、绝对路径换成片段+短哈希', () => {
41
49
  const bundle = buildDiagBundle(
42
50
  inputOf({
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it, vi } from 'vitest';
2
- import { createDiagRecorder, type DiagRecord } from '../diag-records.js';
2
+ import { createDiagRecorder, type DiagHost, type DiagRecord } from '../diag-records.js';
3
3
 
4
4
  function fixedClock(): () => number {
5
5
  let now = 1_000;
@@ -146,6 +146,38 @@ describe('诊断记录器', () => {
146
146
  expect(recorder.once('k', { code: 'READ_FAILED', level: 'error' })).not.toBeNull();
147
147
  });
148
148
 
149
+ it('★ 记录带宿主来源:写入时盖章,once 与 sink 失败记录同样带', () => {
150
+ const host: DiagHost = { profile: 'web', deployment: 'web', pid: 42 };
151
+ const recorder = recorderOf({
152
+ host,
153
+ sinks: [
154
+ () => {
155
+ throw new Error('boom');
156
+ },
157
+ ],
158
+ });
159
+
160
+ const record = recorder.record({ code: 'READ_FAILED' });
161
+ expect(record?.host).toEqual(host);
162
+ expect(recorder.once('k', { code: 'READ_FAILED' })?.host).toEqual(host);
163
+ expect(recorder.recent({ code: 'DIAG_SINK_FAILED' })[0]?.host).toEqual(host);
164
+ });
165
+
166
+ it('★ 按宿主过滤:指定 profile、*、旧记录归 unknown', () => {
167
+ const host: DiagHost = { profile: 'web', deployment: 'web', pid: 42 };
168
+ const recorder = recorderOf({ host });
169
+ recorder.record({ code: 'READ_FAILED' });
170
+
171
+ expect(recorder.recent({ host: 'web' })).toHaveLength(1);
172
+ expect(recorder.recent({ host: 'desktop' })).toHaveLength(0);
173
+ expect(recorder.recent({ host: '*' })).toHaveLength(1);
174
+
175
+ const legacy = recorderOf();
176
+ legacy.record({ code: 'READ_FAILED' });
177
+ expect(legacy.recent({ host: 'unknown' })).toHaveLength(1);
178
+ expect(legacy.recent({ host: 'web' })).toHaveLength(0);
179
+ });
180
+
149
181
  it('级别过滤:低于阈值的记录不落内存、不进 sink', () => {
150
182
  const seen: DiagRecord[] = [];
151
183
  const recorder = recorderOf({ level: 'error', sinks: [(record) => seen.push(record)] });
@@ -130,6 +130,49 @@ describe('诊断记录的落盘 sink', () => {
130
130
  expect(read).toEqual(written);
131
131
  });
132
132
 
133
+ it('★ 分片名带宿主 profile;读回给缺 host 的记录补上', () => {
134
+ const clock = clockAt(Date.parse('2026-11-21T10:00:00.000Z'));
135
+ const sink = createDiagFileSink({ dir, clock, pid: 4242, profile: 'web' });
136
+
137
+ expect(sink.pathOf('2026-11-21')).toBe(path.join(dir, 'record-2026-11-21-4242-web.jsonl'));
138
+ sink.sink(recordAt(clock()));
139
+
140
+ expect(sink.readDay('2026-11-21').records[0]?.host).toEqual({
141
+ profile: 'web',
142
+ deployment: 'unknown',
143
+ pid: 4242,
144
+ });
145
+ });
146
+
147
+ it('旧三段分片仍能读,且不硬补宿主', () => {
148
+ const clock = clockAt(Date.parse('2026-11-21T10:00:00.000Z'));
149
+ const sink = createDiagFileSink({ dir, clock, pid: 7 });
150
+
151
+ sink.sink(recordAt(clock()));
152
+
153
+ expect(sink.pathOf('2026-11-21')).toBe(path.join(dir, 'record-2026-11-21-7.jsonl'));
154
+ expect(sink.readDay('2026-11-21').records[0]?.host).toBeUndefined();
155
+ });
156
+
157
+ it('清理同时认旧名与新名,profile 做安全字符替换', () => {
158
+ const old = path.join(dir, 'record-2026-11-01-9-web.jsonl');
159
+ const fresh = path.join(dir, 'record-2026-11-20-9-web.jsonl');
160
+ fs.writeFileSync(old, `${JSON.stringify(recordAt(1))}\n`, 'utf8');
161
+ fs.writeFileSync(fresh, `${JSON.stringify(recordAt(2))}\n`, 'utf8');
162
+ const sink = createDiagFileSink({
163
+ dir,
164
+ clock: clockAt(Date.parse('2026-11-21T12:00:00.000Z')),
165
+ pid: 9,
166
+ profile: 'a/b',
167
+ retentionDays: 7,
168
+ });
169
+
170
+ expect(sink.pathOf('2026-11-21')).toBe(path.join(dir, 'record-2026-11-21-9-a_b.jsonl'));
171
+ expect(sink.cleanup()).toBe(1);
172
+ expect(fs.existsSync(old)).toBe(false);
173
+ expect(fs.existsSync(fresh)).toBe(true);
174
+ });
175
+
133
176
  it('没有目录 / 没有分片时读回是空的,不抛', () => {
134
177
  const sink = createDiagFileSink({ dir: path.join(dir, 'missing'), pid: 1 });
135
178
  expect(sink.readDay('2026-11-21')).toEqual({ records: [], skipped: 0, read: 0 });
@@ -1,13 +1,41 @@
1
1
  import { describe, expect, it } from 'vitest';
2
2
  import { createDiagRecorder } from '../diag-records.js';
3
- import { diagSummary } from '../diag-summary.js';
3
+ import type { DiagHost, DiagRecord } from '../diag-records.js';
4
+ import { diagSummary, originsOf } from '../diag-summary.js';
4
5
 
5
6
  function recorderOf() {
6
7
  let at = 1_000;
7
8
  return createDiagRecorder({ clock: () => (at += 10), nextCorrId: () => 'c-1', level: 'info' });
8
9
  }
9
10
 
11
+ function recordOf(ts: number, host?: DiagHost): DiagRecord {
12
+ return {
13
+ ts,
14
+ level: 'warn',
15
+ code: 'READ_FAILED',
16
+ class: 'env',
17
+ area: 'panels',
18
+ corrId: `c-${String(ts)}`,
19
+ ...(host === undefined ? {} : { host }),
20
+ };
21
+ }
22
+
10
23
  describe('诊断摘要(给 agent 读的那份)', () => {
24
+ it('★ 来源摘要:按 profile 计数与最后时间,可排除当前来源', () => {
25
+ const web: DiagHost = { profile: 'web', deployment: 'web', pid: 1 };
26
+ const desktop: DiagHost = { profile: 'desktop', deployment: 'desktop', pid: 2 };
27
+ const records = [recordOf(10, web), recordOf(30, desktop), recordOf(20, web), recordOf(40)];
28
+
29
+ expect(originsOf(records)).toEqual([
30
+ { host: 'unknown', count: 1, lastAt: 40 },
31
+ { host: 'desktop', count: 1, lastAt: 30 },
32
+ { host: 'web', count: 2, lastAt: 20 },
33
+ ]);
34
+ expect(originsOf(records, 'web')).toEqual([
35
+ { host: 'unknown', count: 1, lastAt: 40 },
36
+ { host: 'desktop', count: 1, lastAt: 30 },
37
+ ]);
38
+ });
11
39
  it('★ 返回最近记录与按码计数,计数按最近时间倒序', () => {
12
40
  const diag = recorderOf();
13
41
  diag.record({ code: 'READ_FAILED' });
@@ -2,9 +2,9 @@ import { createHash } from 'node:crypto';
2
2
  import { join } from 'node:path';
3
3
  import { basename } from 'node:path';
4
4
  import { writeTextFile } from './fs-write.js';
5
- import type { DiagRecord } from './diag-records.js';
5
+ import type { DiagHost, DiagRecord } from './diag-records.js';
6
6
 
7
- export const DIAG_BUNDLE_SCHEMA = 1;
7
+ export const DIAG_BUNDLE_SCHEMA = 2;
8
8
  export const DIAG_BUNDLE_MAX_BYTES = 8 * 1024 * 1024;
9
9
  const SECRET_KEY = /token|secret|password|passwd|auth|api[-_]?key|credential/i;
10
10
  const ABSOLUTE = /(^|["'\s])((?:\/|[A-Za-z]:\\)[^"'\s]*)/g;
@@ -16,6 +16,7 @@ export interface DiagBundleInput {
16
16
  readonly runtime: Readonly<Record<string, unknown>>;
17
17
  readonly records: readonly DiagRecord[];
18
18
  readonly checks: Readonly<Record<string, unknown>>;
19
+ readonly host?: DiagHost | undefined;
19
20
  readonly maxBytes?: number | undefined;
20
21
  }
21
22
 
@@ -87,6 +88,7 @@ export function buildDiagBundle(input: DiagBundleInput): DiagBundle {
87
88
  bytes: sizeOf(files),
88
89
  truncated,
89
90
  files: Object.keys({ ...files, 'manifest.json': '' }).sort(),
91
+ ...(input.host === undefined ? {} : { host: input.host }),
90
92
  };
91
93
  return {
92
94
  files: { ...files, 'manifest.json': JSON.stringify(manifest, null, 2) },
@@ -21,6 +21,12 @@ export interface DiagSubject {
21
21
  readonly pkg?: string;
22
22
  }
23
23
 
24
+ export interface DiagHost {
25
+ readonly profile: string;
26
+ readonly deployment: 'web' | 'desktop' | 'unknown';
27
+ readonly pid: number;
28
+ }
29
+
24
30
  export interface DiagCause {
25
31
  readonly code?: string;
26
32
  readonly message: string;
@@ -36,6 +42,7 @@ export interface DiagRecord {
36
42
  readonly class: DiagClass;
37
43
  readonly area: DiagArea;
38
44
  readonly subject?: DiagSubject;
45
+ readonly host?: DiagHost;
39
46
  readonly corrId: string;
40
47
  readonly cause?: DiagCause;
41
48
  readonly detail?: Readonly<Record<string, DiagDetailValue>>;
@@ -68,6 +75,7 @@ export interface DiagRecorderOptions {
68
75
  readonly cap?: number | undefined;
69
76
  readonly sinks?: readonly DiagSink[] | undefined;
70
77
  readonly level?: DiagLevel | undefined;
78
+ readonly host?: DiagHost | undefined;
71
79
  }
72
80
 
73
81
  export interface DiagRecorder {
@@ -124,6 +132,7 @@ export function createDiagRecorder(options: DiagRecorderOptions = {}): DiagRecor
124
132
  const countsByCode = new Map<string, DiagCount>();
125
133
  const ring: DiagRecord[] = [];
126
134
  const threshold = options.level ?? defaultLevel();
135
+ const host = options.host;
127
136
 
128
137
  const emit = (record: DiagRecord): void => {
129
138
  ring.push(record);
@@ -156,6 +165,7 @@ export function createDiagRecorder(options: DiagRecorderOptions = {}): DiagRecor
156
165
  class: spec.class,
157
166
  area: spec.area,
158
167
  ...(input.subject === undefined ? {} : { subject: input.subject }),
168
+ ...(host === undefined ? {} : { host }),
159
169
  corrId: input.corrId ?? nextCorrId(),
160
170
  cause: unknown
161
171
  ? { code: input.code, message: input.cause?.message ?? input.code }
@@ -170,6 +180,7 @@ export function createDiagRecorder(options: DiagRecorderOptions = {}): DiagRecor
170
180
  class: full.class,
171
181
  area: full.area,
172
182
  ...(full.subject === undefined ? {} : { subject: full.subject }),
183
+ ...(full.host === undefined ? {} : { host: full.host }),
173
184
  corrId: full.corrId,
174
185
  ...(full.cause === undefined ? {} : { cause: full.cause }),
175
186
  ...(full.detail === undefined ? {} : { detail: full.detail }),
@@ -189,6 +200,7 @@ export function createDiagRecorder(options: DiagRecorderOptions = {}): DiagRecor
189
200
  class: 'bug',
190
201
  area: 'diag',
191
202
  corrId: clean.corrId,
203
+ ...(host === undefined ? {} : { host }),
192
204
  cause: { message: error instanceof Error ? error.message : String(error) },
193
205
  detail: { sink: index },
194
206
  });
@@ -4,7 +4,7 @@ import utc from 'dayjs/plugin/utc.js';
4
4
  import { join } from 'node:path';
5
5
  import { appendTextFile } from './fs-write.js';
6
6
  import { now } from './time.js';
7
- import type { DiagRecord, DiagSink } from './diag-records.js';
7
+ import type { DiagHost, DiagRecord, DiagSink } from './diag-records.js';
8
8
 
9
9
  export const DIAG_RETENTION_DAYS = 7;
10
10
  export const DIAG_DAY_BYTES = 5 * 1024 * 1024;
@@ -12,7 +12,7 @@ export const DIAG_FILE_PREFIX = 'record-';
12
12
 
13
13
  dayjs.extend(utc);
14
14
 
15
- const SHARD = /^record-(\d{4}-\d{2}-\d{2})-(\d+)\.jsonl$/;
15
+ const SHARD = /^record-(\d{4}-\d{2}-\d{2})-(\d+)(?:-([A-Za-z0-9._-]+))?\.jsonl$/;
16
16
  const DAY_MS = 24 * 60 * 60 * 1000;
17
17
 
18
18
  export interface DiagFileSinkOptions {
@@ -21,6 +21,7 @@ export interface DiagFileSinkOptions {
21
21
  readonly dayBytes?: number | undefined;
22
22
  readonly clock?: (() => number) | undefined;
23
23
  readonly pid?: number | undefined;
24
+ readonly profile?: string | undefined;
24
25
  }
25
26
 
26
27
  export interface DiagReadResult {
@@ -40,6 +41,12 @@ function dayOf(ts: number): string {
40
41
  return dayjs(ts).utc().format('YYYY-MM-DD');
41
42
  }
42
43
 
44
+ function profileOf(raw: string | undefined): string | undefined {
45
+ if (raw === undefined) return undefined;
46
+ const safe = raw.replace(/[^A-Za-z0-9._-]/g, '_');
47
+ return safe === '' ? 'unknown' : safe;
48
+ }
49
+
43
50
  function shardsIn(dir: string): string[] {
44
51
  if (!existsSync(dir)) return [];
45
52
  return readdirSync(dir).filter((name) => SHARD.test(name));
@@ -50,12 +57,17 @@ export function createDiagFileSink(options: DiagFileSinkOptions): DiagFileSink {
50
57
  const capBytes = options.dayBytes ?? DIAG_DAY_BYTES;
51
58
  const clock = options.clock ?? now;
52
59
  const pid = options.pid ?? process.pid;
60
+ const profile = profileOf(options.profile);
53
61
  let day = '';
54
62
  let path = '';
55
63
  let bytes = 0;
56
64
  let capped = false;
57
65
 
58
- const pathOf = (at: string): string => join(options.dir, `${DIAG_FILE_PREFIX}${at}-${String(pid)}.jsonl`);
66
+ const pathOf = (at: string): string =>
67
+ join(
68
+ options.dir,
69
+ `${DIAG_FILE_PREFIX}${at}-${String(pid)}${profile === undefined ? '' : `-${profile}`}.jsonl`,
70
+ );
59
71
 
60
72
  const cleanup = (): number => {
61
73
  const cutoff = clock() - retained * DAY_MS;
@@ -89,12 +101,22 @@ export function createDiagFileSink(options: DiagFileSinkOptions): DiagFileSink {
89
101
  skipped += 1;
90
102
  };
91
103
  for (const name of names) {
104
+ const match = SHARD.exec(name);
105
+ const fileProfile = match?.[3];
106
+ const filePid = Number.parseInt(match?.[2] ?? '', 10);
107
+ const fallback: DiagHost | undefined =
108
+ fileProfile === undefined || !Number.isInteger(filePid)
109
+ ? undefined
110
+ : { profile: fileProfile, deployment: 'unknown', pid: filePid };
92
111
  const text = readFileSync(join(options.dir, name), 'utf8');
93
112
  for (const line of text.split('\n')) {
94
113
  if (line.trim() === '') continue;
95
114
  read += 1;
96
115
  try {
97
- records.push(JSON.parse(line) as DiagRecord);
116
+ const record = JSON.parse(line) as DiagRecord;
117
+ records.push(
118
+ fallback === undefined || record.host !== undefined ? record : { ...record, host: fallback },
119
+ );
98
120
  } catch {
99
121
  noteBroken();
100
122
  }
@@ -6,8 +6,30 @@ export interface DiagSummary {
6
6
  readonly total: number;
7
7
  }
8
8
 
9
+ export interface DiagHostCount {
10
+ readonly host: string;
11
+ readonly count: number;
12
+ readonly lastAt: number;
13
+ }
14
+
9
15
  export const DIAG_SUMMARY_LIMIT = 50;
10
16
 
17
+ export function originsOf(records: readonly DiagRecord[], exclude?: string): readonly DiagHostCount[] {
18
+ const byHost = new Map<string, { count: number; lastAt: number }>();
19
+ for (const record of records) {
20
+ const host = record.host?.profile ?? 'unknown';
21
+ if (host === exclude) continue;
22
+ const seat = byHost.get(host);
23
+ byHost.set(host, {
24
+ count: (seat?.count ?? 0) + 1,
25
+ lastAt: Math.max(seat?.lastAt ?? 0, record.ts),
26
+ });
27
+ }
28
+ return [...byHost.entries()]
29
+ .map(([host, one]) => ({ host, count: one.count, lastAt: one.lastAt }))
30
+ .sort((left, right) => right.lastAt - left.lastAt || left.host.localeCompare(right.host));
31
+ }
32
+
11
33
  export function diagSummary(recorder: DiagRecorder, limit = DIAG_SUMMARY_LIMIT): DiagSummary {
12
34
  const records = recorder.recent({ limit });
13
35
  const counts = [...recorder.counts().entries()]
@@ -56,6 +56,7 @@ export interface PreflightSnapshot {
56
56
  readonly failure?: PreflightFailure;
57
57
  readonly guidance?: PreflightGuidance;
58
58
  readonly bridgeIssues?: readonly PreflightBridgeIssue[];
59
+ readonly extensionTarget?: string;
59
60
  readonly hostGap?: PreflightHostGap;
60
61
  readonly hostFacts?: PreflightHostFacts;
61
62
  readonly paths?: PreflightPaths;
package/src/host.ts CHANGED
@@ -181,4 +181,4 @@ export * from './host/unit/unit-config.js';
181
181
  export * from './host/unit/unit-data.js';
182
182
  export * from './host/unit/unit-face.js';
183
183
  export * from './host/unit/unit-plugin.js';
184
- export * from './host/unit/value-handoff.js';
184
+ export * from './host/unit/value-handoff.js';
package/src/i18n/en.ts CHANGED
@@ -247,7 +247,6 @@ export const en: Record<keyof WorkbenchMessages, string> = {
247
247
  'panels.market.failure.askAgentText': 'Installing this module could not write: `{command}` returned exit code {code} at {path}. Check whether the sandbox or file permissions blocked it, then install again at a writable location.',
248
248
  'panels.market.failure.askAgentAuth': 'Installing this module failed: the private source {registry} rejected the request (401/403): `{command}` returned exit code {code}.\nOutput: {reason}\nFirst check whether this machine has credentials for that source (`_authToken` in ~/.npmrc). Log in, add the token, or switch to an account with access, then retry.',
249
249
  'panels.market.failure.askAgentUnknown': 'Installing this module failed: `{command}` returned exit code {code}, and the cause could not be identified automatically.\nOutput: {reason}\nUse that output to pin down the cause (private source not logged in? network down? wrong package name?), then retry.',
250
- 'panels.market.failure.askAgentHint': 'Paste it into the chat; the agent will continue the diagnosis.',
251
250
  'panels.market.failure.recheck': 'Check again',
252
251
  'panels.market.failure.showOutput': 'Show install output',
253
252
  'panels.market.failure.hideOutput': 'Hide install output',
@@ -738,6 +737,8 @@ export const en: Record<keyof WorkbenchMessages, string> = {
738
737
  'env.bridge.why': 'Panel data needs the sign-in state in your browser. When the connection is not established, modules cannot fetch data. You can fix it and continue, or enter the workbench first.',
739
738
  'env.bridge.extensionOffline': 'The extension is not connected. Choose either install method: (1) click the link below to install it from the Chrome Web Store; (2) load a local copy: open chrome://extensions, turn on Developer mode in the top right, click Load unpacked, and choose the extension folder. When done, come back and click Retry.',
740
739
  'env.bridge.extensionLocal': 'The extension is not connected. Choose either install method: (1) use the copy shipped with the workbench: open chrome://extensions, turn on Developer mode in the top right, click Load unpacked, and choose {dir}; (2) click the link below to install it from the Chrome Web Store. When done, come back and click Retry.',
740
+ 'env.bridge.extensionIncompatible': 'The browser extension and the background tools are on incompatible versions, so panels cannot read data. Update the extension to v{version}, then come back and click Retry.',
741
+ 'env.bridge.extensionIncompatibleAny': 'The browser extension and the background tools are on incompatible versions, so panels cannot read data. Switch to a compatible extension version, then come back and click Retry.',
741
742
  'env.bridge.hold': 'The browser is not connected yet. Fix it with the steps below and click Retry, or enter the workbench first.',
742
743
  'env.bridge.unknown': 'The browser connection reported a problem this workbench cannot classify. You can expand the original output, or let the agent diagnose.',
743
744
  'env.fix.title': 'How to fix this',
@@ -775,7 +776,6 @@ export const en: Record<keyof WorkbenchMessages, string> = {
775
776
  'askAgent.title': 'Agent diagnosis needed',
776
777
  'askAgent.copy': 'Copy for the agent',
777
778
  'askAgent.copied': 'Copied',
778
- 'askAgent.hint': 'Paste it into the chat; the agent will continue the diagnosis.',
779
779
  'askAgent.prompt.head': 'The workbench ran into a problem that needs your diagnosis.',
780
780
  'askAgent.prompt.whereOnly': 'Where: {screen}',
781
781
  'askAgent.screen.board': 'Board',
package/src/i18n/zh.ts CHANGED
@@ -243,7 +243,6 @@ export const zh = {
243
243
  'panels.market.failure.askAgentText': '安装这个模块时无法写入:`{command}` 退出码为 {code},受阻于 {path}。请确认是沙箱拦截还是权限问题,并换一个可写入的位置重新安装。',
244
244
  'panels.market.failure.askAgentAuth': '安装这个模块时,私有源 {registry} 拒绝了请求(401/403):`{command}` 退出码为 {code}。\n输出:{reason}\n先确认这台机器有没有这个源的凭据(~/.npmrc 里的 _authToken):登录、补 token 或换一个有权限的账号,再重试。',
245
245
  'panels.market.failure.askAgentUnknown': '安装这个模块失败:`{command}` 退出码为 {code},原因没能自动认出来。\n输出:{reason}\n请按这段输出定位(私有源没登录?网络不通?包名不对?),再重试。',
246
- 'panels.market.failure.askAgentHint': '粘贴到对话里,agent 会继续诊断。',
247
246
  'panels.market.failure.recheck': '再次检查',
248
247
  'panels.market.failure.showOutput': '查看安装输出',
249
248
  'panels.market.failure.hideOutput': '收起安装输出',
@@ -733,6 +732,8 @@ export const zh = {
733
732
  'env.bridge.why': '面板数据需要浏览器中的登录状态。连接未建立时,模块无法获取数据。可以修复后继续,也可以先进入工作台。',
734
733
  'env.bridge.extensionOffline': '扩展没有连接。可以任选一种安装方式:① 点击下面的链接,从 Chrome 应用商店安装;② 加载本地副本:打开 chrome://extensions,在右上角开启「开发者模式」,点击「加载已解压的扩展程序」,选择扩展目录。安装完成后回来点击「重试」。',
735
734
  'env.bridge.extensionLocal': '扩展没有连接。可以任选一种安装方式:① 使用工作台自带的副本:打开 chrome://extensions,在右上角开启「开发者模式」,点击「加载已解压的扩展程序」,选择 {dir};② 点击下面的链接,从 Chrome 应用商店安装。安装完成后回来点击「重试」。',
735
+ 'env.bridge.extensionIncompatible': '浏览器扩展和后台工具的版本不兼容:面板读不到数据。把扩展更新到 v{version},再回来点击「重试」。',
736
+ 'env.bridge.extensionIncompatibleAny': '浏览器扩展和后台工具的版本不兼容:面板读不到数据。换一个兼容的扩展版本,再回来点击「重试」。',
736
737
  'env.bridge.hold': '浏览器还没有连接。请按下面的步骤修复后点击「重试」,也可以先进入工作台。',
737
738
  'env.bridge.unknown': '浏览器连接有问题,但工作台没能识别是哪一类。可以展开原文查看,也可以让 agent 诊断。',
738
739
  'env.fix.title': '解决方法',
@@ -770,7 +771,6 @@ export const zh = {
770
771
  'askAgent.title': '需要 agent 诊断',
771
772
  'askAgent.copy': '复制给 agent',
772
773
  'askAgent.copied': '已复制',
773
- 'askAgent.hint': '粘贴到对话里,agent 会继续诊断。',
774
774
  'askAgent.prompt.head': '工作台遇到一个问题,需要你定位。',
775
775
  'askAgent.prompt.whereOnly': '位置:{screen}',
776
776
  'askAgent.screen.board': '看板',