@dsh-workbench/shared 0.1.1 → 0.1.3
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/dist/api/workbench-contract.d.ts +1 -1
- package/dist/components/ApprovalDetail.css +4 -0
- package/dist/components/ApprovalDetail.d.ts +1 -0
- package/dist/components/ApprovalDetail.js +5 -1
- package/dist/components/CardHead.css +92 -0
- package/dist/components/CardHead.d.ts +1 -0
- package/dist/components/CardHead.js +9 -7
- package/dist/components/ChoiceGroup.css +75 -0
- package/dist/components/ChoiceGroup.d.ts +1 -0
- package/dist/components/ChoiceGroup.js +1 -0
- package/dist/components/LongTaskRow.css +53 -0
- package/dist/components/LongTaskRow.d.ts +3 -0
- package/dist/components/LongTaskRow.js +11 -11
- package/dist/components/MockStrip.css +39 -0
- package/dist/components/MockStrip.d.ts +1 -0
- package/dist/components/MockStrip.js +1 -0
- package/dist/components/ResourceStates.css +111 -0
- package/dist/components/ResourceStates.d.ts +2 -1
- package/dist/components/ResourceStates.js +1 -0
- package/dist/components/SaveBar.css +7 -0
- package/dist/components/SaveBar.d.ts +1 -0
- package/dist/components/SaveBar.js +4 -2
- package/dist/components/TextField.css +22 -0
- package/dist/components/TextField.d.ts +6 -0
- package/dist/components/TextField.js +5 -0
- package/dist/components/icons.d.ts +0 -12
- package/dist/components/icons.js +0 -61
- package/dist/host/http.js +5 -29
- package/dist/host/provision.d.ts +18 -1
- package/dist/host/provision.js +73 -0
- package/dist/host.d.ts +6 -0
- package/dist/host.js +6 -0
- package/dist/i18n/en.js +126 -1
- package/dist/i18n/index.d.ts +129 -4
- package/dist/i18n/zh.d.ts +128 -3
- package/dist/i18n/zh.js +128 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +5 -3
- package/src/api/workbench-contract.ts +5 -1
- package/src/components/ApprovalDetail.css +4 -0
- package/src/components/ApprovalDetail.tsx +11 -1
- package/src/components/CardHead.css +92 -0
- package/src/components/CardHead.tsx +43 -31
- package/src/components/ChoiceGroup.css +75 -0
- package/src/components/ChoiceGroup.tsx +1 -0
- package/src/components/LongTaskRow.css +53 -0
- package/src/components/LongTaskRow.tsx +52 -13
- package/src/components/MockStrip.css +39 -0
- package/src/components/MockStrip.tsx +1 -0
- package/src/components/ResourceStates.css +111 -0
- package/src/components/ResourceStates.tsx +2 -1
- package/src/components/SaveBar.css +7 -0
- package/src/components/SaveBar.tsx +8 -5
- package/src/components/TextField.css +22 -0
- package/src/components/TextField.tsx +17 -0
- package/src/components/icons.tsx +0 -164
- package/src/host/__tests__/provision.test.ts +90 -0
- package/src/host/http.ts +5 -33
- package/src/host/provision.ts +87 -0
- package/src/host.ts +6 -0
- package/src/i18n/en.ts +127 -1
- package/src/i18n/zh.ts +128 -4
- package/src/index.ts +1 -1
- package/dist/components/StateDot.d.ts +0 -5
- package/dist/components/StateDot.js +0 -10
- package/dist/host/__tests__/fakes.d.ts +0 -41
- package/dist/host/__tests__/fakes.js +0 -76
- package/dist/host/__tests__/preflight-fixtures.d.ts +0 -19
- package/dist/host/__tests__/preflight-fixtures.js +0 -47
- package/dist/host/context-inject.d.ts +0 -24
- package/dist/host/context-inject.js +0 -74
- package/dist/host/events.d.ts +0 -9
- package/dist/host/events.js +0 -70
- package/dist/host/mount-units.d.ts +0 -52
- package/dist/host/mount-units.js +0 -186
- package/dist/host/preflight.d.ts +0 -58
- package/dist/host/preflight.js +0 -233
- package/dist/host/probe-cache.d.ts +0 -6
- package/dist/host/probe-cache.js +0 -19
- package/dist/host/probe-libs.d.ts +0 -45
- package/dist/host/probe-libs.js +0 -61
- package/dist/host/probe-units.d.ts +0 -17
- package/dist/host/probe-units.js +0 -102
- package/dist/host/probe-verdict.d.ts +0 -7
- package/dist/host/probe-verdict.js +0 -143
- package/dist/host/tool-scope.d.ts +0 -32
- package/dist/host/tool-scope.js +0 -84
- package/dist/host/unit-readiness.d.ts +0 -7
- package/dist/host/unit-readiness.js +0 -5
- package/dist/host/unit-registry.d.ts +0 -9
- package/dist/host/unit-registry.js +0 -33
- package/dist/host/version-range.d.ts +0 -2
- package/dist/host/version-range.js +0 -73
- package/src/components/StateDot.tsx +0 -31
package/dist/host/tool-scope.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
function agentOf(value) {
|
|
2
|
-
return typeof value === 'object' && value !== null ? value : undefined;
|
|
3
|
-
}
|
|
4
|
-
function workspaceOf(handle) {
|
|
5
|
-
const cwd = handle.session?.header?.cwd;
|
|
6
|
-
return typeof cwd === 'string' && cwd !== '' ? cwd : null;
|
|
7
|
-
}
|
|
8
|
-
export function createToolScope(options) {
|
|
9
|
-
const applied = new WeakMap();
|
|
10
|
-
const seen = new Set();
|
|
11
|
-
function toolsOf(handle) {
|
|
12
|
-
const byProperty = handle.ctx?.tools;
|
|
13
|
-
if (byProperty?.restrict !== undefined)
|
|
14
|
-
return byProperty;
|
|
15
|
-
const byGet = handle.ctx?.get?.('tools');
|
|
16
|
-
return byGet?.restrict === undefined ? undefined : byGet;
|
|
17
|
-
}
|
|
18
|
-
function sync(handle) {
|
|
19
|
-
const tools = toolsOf(handle);
|
|
20
|
-
if (tools === undefined) {
|
|
21
|
-
options.logger?.warn?.('[dsh-workbench] 拿不到 agent 作用域的工具面:这次不收窄(下次再试)');
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
const workspace = workspaceOf(handle);
|
|
25
|
-
const deny = [...options.deniedTools(workspace)];
|
|
26
|
-
const signature = `${workspace ?? ''}\u0000${deny.join(',')}`;
|
|
27
|
-
const previous = applied.get(handle);
|
|
28
|
-
if (previous !== undefined && previous.signature === signature)
|
|
29
|
-
return;
|
|
30
|
-
if (previous === undefined)
|
|
31
|
-
seen.add(new WeakRef(handle));
|
|
32
|
-
previous?.dispose();
|
|
33
|
-
if (deny.length === 0) {
|
|
34
|
-
options.logger?.info?.('[dsh-workbench] 这个工作区启用了全部套件:不收窄工具面');
|
|
35
|
-
applied.delete(handle);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
try {
|
|
39
|
-
applied.set(handle, { signature, dispose: tools.restrict({ deny }) });
|
|
40
|
-
options.logger?.info?.(`[dsh-workbench] 按工作区收窄工具面:${workspace ?? '(未知工作区)'} 里收起 ${deny.length} 个工具(${deny.join(', ')})`);
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
options.logger?.warn?.(`[dsh-workbench] 收窄工具面失败:${String(error)}`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
apply(agent) {
|
|
48
|
-
const handle = agentOf(agent);
|
|
49
|
-
if (handle === undefined)
|
|
50
|
-
return;
|
|
51
|
-
sync(handle);
|
|
52
|
-
},
|
|
53
|
-
narrow(assembly, agent) {
|
|
54
|
-
const handle = agentOf(agent);
|
|
55
|
-
const tools = assembly?.tools;
|
|
56
|
-
if (handle === undefined || tools === undefined)
|
|
57
|
-
return assembly;
|
|
58
|
-
const deny = new Set(options.deniedTools(workspaceOf(handle)));
|
|
59
|
-
if (deny.size === 0)
|
|
60
|
-
return assembly;
|
|
61
|
-
const kept = tools.filter((tool) => !deny.has(tool.name));
|
|
62
|
-
return kept.length === tools.length ? assembly : { ...assembly, tools: kept };
|
|
63
|
-
},
|
|
64
|
-
reapply() {
|
|
65
|
-
for (const ref of [...seen]) {
|
|
66
|
-
const handle = ref.deref();
|
|
67
|
-
if (handle === undefined)
|
|
68
|
-
seen.delete(ref);
|
|
69
|
-
else
|
|
70
|
-
sync(handle);
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
disposeAll() {
|
|
74
|
-
for (const ref of [...seen]) {
|
|
75
|
-
const handle = ref.deref();
|
|
76
|
-
if (handle === undefined)
|
|
77
|
-
continue;
|
|
78
|
-
applied.get(handle)?.dispose();
|
|
79
|
-
applied.delete(handle);
|
|
80
|
-
}
|
|
81
|
-
seen.clear();
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { UnitManifest } from '@dsh-workbench/shared';
|
|
2
|
-
export interface UnitReadiness {
|
|
3
|
-
readonly canMount: boolean;
|
|
4
|
-
readonly missingHard: readonly string[];
|
|
5
|
-
readonly missingSoft: readonly string[];
|
|
6
|
-
}
|
|
7
|
-
export declare function unitReadiness(manifest: UnitManifest, lookup: (name: string) => unknown): UnitReadiness;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export function unitReadiness(manifest, lookup) {
|
|
2
|
-
const missingHard = manifest.host.inject.filter((name) => lookup(name) === undefined);
|
|
3
|
-
const missingSoft = (manifest.host.optional ?? []).filter((name) => lookup(name) === undefined);
|
|
4
|
-
return { canMount: missingHard.length === 0, missingHard, missingSoft };
|
|
5
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { UnitManifest } from '@dsh-workbench/shared';
|
|
2
|
-
import type { UnitHostFace } from './unit-face';
|
|
3
|
-
export interface UnitRegistry {
|
|
4
|
-
register(face: UnitHostFace): () => void;
|
|
5
|
-
all(): readonly UnitHostFace[];
|
|
6
|
-
manifests(): readonly UnitManifest[];
|
|
7
|
-
subscribe(listener: () => void): () => void;
|
|
8
|
-
}
|
|
9
|
-
export declare function createUnitRegistry(): UnitRegistry;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export function createUnitRegistry() {
|
|
2
|
-
const faces = [];
|
|
3
|
-
const ids = new Set();
|
|
4
|
-
const listeners = new Set();
|
|
5
|
-
function notify() {
|
|
6
|
-
for (const listener of listeners)
|
|
7
|
-
listener();
|
|
8
|
-
}
|
|
9
|
-
return {
|
|
10
|
-
register(face) {
|
|
11
|
-
const id = face.manifest.id;
|
|
12
|
-
if (ids.has(id))
|
|
13
|
-
throw new Error(`套件 id 重复:${id}(id 会进持久化配置,不能撞)`);
|
|
14
|
-
ids.add(id);
|
|
15
|
-
faces.push(face);
|
|
16
|
-
notify();
|
|
17
|
-
return () => {
|
|
18
|
-
const index = faces.indexOf(face);
|
|
19
|
-
if (index < 0)
|
|
20
|
-
return;
|
|
21
|
-
faces.splice(index, 1);
|
|
22
|
-
ids.delete(id);
|
|
23
|
-
notify();
|
|
24
|
-
};
|
|
25
|
-
},
|
|
26
|
-
all: () => faces,
|
|
27
|
-
manifests: () => faces.map((face) => face.manifest),
|
|
28
|
-
subscribe(listener) {
|
|
29
|
-
listeners.add(listener);
|
|
30
|
-
return () => listeners.delete(listener);
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { compareVersions } from './release';
|
|
2
|
-
function readable(version) {
|
|
3
|
-
return compareVersions(version, '0.0.0') !== undefined;
|
|
4
|
-
}
|
|
5
|
-
function segmentsOf(version) {
|
|
6
|
-
if (!readable(version))
|
|
7
|
-
return undefined;
|
|
8
|
-
return version.split('.').map((part) => Number.parseInt(part, 10));
|
|
9
|
-
}
|
|
10
|
-
function caretUpper(base) {
|
|
11
|
-
const [major = 0, minor = 0, patch = 0] = base;
|
|
12
|
-
if (major > 0)
|
|
13
|
-
return `${major + 1}.0.0`;
|
|
14
|
-
return minor > 0 ? `0.${minor + 1}.0` : `0.0.${patch + 1}`;
|
|
15
|
-
}
|
|
16
|
-
function tildeUpper(base) {
|
|
17
|
-
const [major = 0, minor = 0] = base;
|
|
18
|
-
return `${major}.${minor + 1}.0`;
|
|
19
|
-
}
|
|
20
|
-
function comparator(token, version) {
|
|
21
|
-
const match = /^(>=|<=|>|<|=|\^|~)?\s*(.+)$/.exec(token.trim());
|
|
22
|
-
if (match === null)
|
|
23
|
-
return undefined;
|
|
24
|
-
const [, operator = '', raw = ''] = match;
|
|
25
|
-
const base = segmentsOf(raw.trim());
|
|
26
|
-
if (base === undefined)
|
|
27
|
-
return undefined;
|
|
28
|
-
const at = (other) => compareVersions(version, other);
|
|
29
|
-
switch (operator) {
|
|
30
|
-
case '^':
|
|
31
|
-
return (at(raw) ?? -1) >= 0 && (at(caretUpper(base)) ?? 1) < 0;
|
|
32
|
-
case '~':
|
|
33
|
-
return (at(raw) ?? -1) >= 0 && (at(tildeUpper(base)) ?? 1) < 0;
|
|
34
|
-
default:
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
const compared = at(raw.trim());
|
|
38
|
-
if (compared === undefined)
|
|
39
|
-
return undefined;
|
|
40
|
-
switch (operator) {
|
|
41
|
-
case '>=':
|
|
42
|
-
return compared >= 0;
|
|
43
|
-
case '<=':
|
|
44
|
-
return compared <= 0;
|
|
45
|
-
case '>':
|
|
46
|
-
return compared > 0;
|
|
47
|
-
case '<':
|
|
48
|
-
return compared < 0;
|
|
49
|
-
case '=':
|
|
50
|
-
case '':
|
|
51
|
-
return compared === 0;
|
|
52
|
-
default:
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
export function checkVersionRange(contract, version) {
|
|
57
|
-
const spec = contract?.trim() ?? '';
|
|
58
|
-
if (spec === '')
|
|
59
|
-
return 'satisfied';
|
|
60
|
-
if (!readable(version))
|
|
61
|
-
return 'malformed';
|
|
62
|
-
const tokens = spec.split(/\s+/).filter((token) => token !== '');
|
|
63
|
-
if (tokens.length === 0)
|
|
64
|
-
return 'satisfied';
|
|
65
|
-
for (const token of tokens) {
|
|
66
|
-
const verdict = comparator(token, version);
|
|
67
|
-
if (verdict === undefined)
|
|
68
|
-
return 'malformed';
|
|
69
|
-
if (!verdict)
|
|
70
|
-
return 'unsatisfied';
|
|
71
|
-
}
|
|
72
|
-
return 'satisfied';
|
|
73
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { h } from '../lib/react.js';
|
|
2
|
-
|
|
3
|
-
export type DotState = 'ongoing' | 'warning' | 'done' | 'idle' | string;
|
|
4
|
-
|
|
5
|
-
export function StateDot({ state, size }: { state: DotState; size: number }) {
|
|
6
|
-
if (state === 'ongoing') {
|
|
7
|
-
return (
|
|
8
|
-
<svg
|
|
9
|
-
className="wb-loading"
|
|
10
|
-
viewBox="0 0 24 24"
|
|
11
|
-
width={size}
|
|
12
|
-
height={size}
|
|
13
|
-
aria-hidden="true"
|
|
14
|
-
style={{ display: 'block' }}
|
|
15
|
-
>
|
|
16
|
-
<g className="wb-loadingMotion">
|
|
17
|
-
<circle className="wb-loadingTrack" cx={12} cy={12} r={9.5} />
|
|
18
|
-
<circle className="wb-loadingArc" cx={12} cy={12} r={9.5} />
|
|
19
|
-
</g>
|
|
20
|
-
</svg>
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
return (
|
|
24
|
-
<span
|
|
25
|
-
className="wb-stateDot"
|
|
26
|
-
data-state={state}
|
|
27
|
-
style={{ width: size, height: size }}
|
|
28
|
-
aria-hidden="true"
|
|
29
|
-
/>
|
|
30
|
-
);
|
|
31
|
-
}
|