@dsh-workbench/shared 1.5.2-alpha.4 → 1.5.2-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.
- package/dist/components/Activity.css +69 -0
- package/dist/components/Activity.d.ts +56 -0
- package/dist/components/Activity.js +47 -0
- package/dist/components/ApprovalDetail.css +3 -0
- package/dist/components/ApprovalDetail.d.ts +42 -0
- package/dist/components/ApprovalDetail.js +53 -0
- package/dist/components/ApprovalPlan.css +39 -0
- package/dist/components/ApprovalPlan.d.ts +27 -0
- package/dist/components/ApprovalPlan.js +19 -0
- package/dist/components/Card.css +19 -0
- package/dist/components/Card.d.ts +26 -0
- package/dist/components/Card.js +18 -0
- package/dist/components/CardAnchor.d.ts +21 -0
- package/dist/components/CardAnchor.js +19 -0
- package/dist/components/CardAnchor.module.css +3 -0
- package/dist/components/CardBoundary.d.ts +42 -0
- package/dist/components/CardBoundary.js +58 -0
- package/dist/components/CardBoundary.module.css +5 -0
- package/dist/components/CardHead.css +87 -0
- package/dist/components/CardHead.d.ts +30 -0
- package/dist/components/CardHead.js +27 -0
- package/dist/components/ChoiceGroup.css +182 -0
- package/dist/components/ChoiceGroup.d.ts +54 -0
- package/dist/components/ChoiceGroup.js +63 -0
- package/dist/components/ConfirmBar.css +26 -0
- package/dist/components/ConfirmBar.d.ts +36 -0
- package/dist/components/ConfirmBar.js +26 -0
- package/dist/components/EmptyIllustration.d.ts +12 -0
- package/dist/components/EmptyIllustration.js +32 -0
- package/dist/components/Field.css +20 -0
- package/dist/components/Field.d.ts +18 -0
- package/dist/components/Field.js +15 -0
- package/dist/components/Form.css +6 -0
- package/dist/components/Form.d.ts +22 -0
- package/dist/components/Form.js +60 -0
- package/dist/components/FormActions.css +13 -0
- package/dist/components/FormActions.d.ts +29 -0
- package/dist/components/FormActions.js +43 -0
- package/dist/components/FormNodes.d.ts +107 -0
- package/dist/components/FormNodes.js +165 -0
- package/dist/components/FormRows.css +107 -0
- package/dist/components/FormRows.d.ts +36 -0
- package/dist/components/FormRows.js +26 -0
- package/dist/components/FormTypes.d.ts +84 -0
- package/dist/components/FormTypes.js +1 -0
- package/dist/components/Link.css +22 -0
- package/dist/components/Link.d.ts +22 -0
- package/dist/components/Link.js +17 -0
- package/dist/components/LongTaskRow.css +171 -0
- package/dist/components/LongTaskRow.d.ts +94 -0
- package/dist/components/LongTaskRow.js +103 -0
- package/dist/components/Note.css +13 -0
- package/dist/components/Note.d.ts +20 -0
- package/dist/components/Note.js +14 -0
- package/dist/components/ResourceStates.css +114 -0
- package/dist/components/ResourceStates.d.ts +44 -0
- package/dist/components/ResourceStates.js +41 -0
- package/dist/components/Rows.css +42 -0
- package/dist/components/Rows.d.ts +28 -0
- package/dist/components/Rows.js +21 -0
- package/dist/components/SaveBar.d.ts +24 -0
- package/dist/components/SaveBar.js +25 -0
- package/dist/components/SelectField.css +182 -0
- package/dist/components/SelectField.d.ts +89 -0
- package/dist/components/SelectField.js +260 -0
- package/dist/components/SelectFieldNodes.d.ts +49 -0
- package/dist/components/SelectFieldNodes.js +43 -0
- package/dist/components/SettingsSection.css +25 -0
- package/dist/components/SettingsSection.d.ts +20 -0
- package/dist/components/SettingsSection.js +17 -0
- package/dist/components/SetupShell.d.ts +93 -0
- package/dist/components/SetupShell.js +64 -0
- package/dist/components/SetupShell.module.css +81 -0
- package/dist/components/Spinner.css +5 -0
- package/dist/components/Spinner.d.ts +15 -0
- package/dist/components/Spinner.js +13 -0
- package/dist/components/Stack.css +6 -0
- package/dist/components/Stack.d.ts +14 -0
- package/dist/components/Stack.js +10 -0
- package/dist/components/StateBlock.css +38 -0
- package/dist/components/StateBlock.d.ts +24 -0
- package/dist/components/StateBlock.js +22 -0
- package/dist/components/TextField.css +32 -0
- package/dist/components/TextField.d.ts +14 -0
- package/dist/components/TextField.js +10 -0
- package/dist/components/board-module.d.ts +307 -0
- package/dist/components/board-module.js +1 -0
- package/dist/components/card-view-validate.d.ts +5 -0
- package/dist/components/card-view-validate.js +256 -0
- package/dist/components/icons.d.ts +63 -0
- package/dist/components/icons.js +107 -0
- package/dist/components/layout/icon-command.d.ts +8 -0
- package/dist/components/layout/icon-command.js +21 -0
- package/dist/contract/capture.d.ts +16 -0
- package/dist/contract/capture.js +1 -0
- package/dist/contract/diagnostics.d.ts +34 -0
- package/dist/contract/diagnostics.js +124 -0
- package/dist/contract/needs.d.ts +3 -1
- package/dist/contract/needs.js +4 -2
- package/dist/contract/protocol/bundle-install.d.ts +1 -1
- package/dist/contract/protocol/unit-manager.d.ts +50 -0
- package/dist/contract/protocol/unit-manager.js +2 -0
- package/dist/contract/unit.js +2 -1
- package/dist/host/adapter-contract.d.ts +3 -0
- package/dist/host/adapter-contract.js +95 -0
- package/dist/host/adapter-set.d.ts +27 -0
- package/dist/host/adapter-set.js +258 -0
- package/dist/host/adapter-types.d.ts +87 -0
- package/dist/host/adapter-types.js +23 -0
- package/dist/host/adapters/platform.d.ts +14 -0
- package/dist/host/adapters/platform.js +40 -0
- package/dist/host/adapters.d.ts +28 -0
- package/dist/host/adapters.js +9 -0
- package/dist/host/auth-loss.d.ts +33 -0
- package/dist/host/auth-loss.js +107 -0
- package/dist/host/board-fact.d.ts +8 -0
- package/dist/host/board-fact.js +16 -0
- package/dist/host/boot-record.d.ts +11 -0
- package/dist/host/boot-record.js +31 -0
- package/dist/host/browser.d.ts +3 -0
- package/dist/host/browser.js +3 -0
- package/dist/host/bundle-manager.d.ts +4 -0
- package/dist/host/bundle-manager.js +338 -0
- package/dist/host/changelog.d.ts +28 -0
- package/dist/host/changelog.js +201 -0
- package/dist/host/cli-error.d.ts +8 -0
- package/dist/host/cli-error.js +70 -0
- package/dist/host/cli.d.ts +4 -0
- package/dist/host/cli.js +9 -0
- package/dist/host/config-sync.d.ts +40 -0
- package/dist/host/config-sync.js +267 -0
- package/dist/host/context-ref.d.ts +13 -0
- package/dist/host/context-ref.js +41 -0
- package/dist/host/data-error.d.ts +15 -0
- package/dist/host/data-error.js +23 -0
- package/dist/host/data-plan-check.d.ts +10 -0
- package/dist/host/data-plan-check.js +315 -0
- package/dist/host/data-plan.d.ts +15 -0
- package/dist/host/data-plan.js +283 -0
- package/dist/host/data-root.d.ts +5 -0
- package/dist/host/data-root.js +23 -0
- package/dist/host/diy-debug.d.ts +80 -0
- package/dist/host/diy-debug.js +89 -0
- package/dist/host/diy-preset.d.ts +26 -0
- package/dist/host/diy-preset.js +115 -0
- package/dist/host/diy-record.d.ts +135 -0
- package/dist/host/diy-record.js +163 -0
- package/dist/host/dsh-compat.d.ts +27 -0
- package/dist/host/dsh-compat.js +75 -0
- package/dist/host/dsh-plugins.d.ts +5 -0
- package/dist/host/dsh-plugins.js +51 -0
- package/dist/host/env-policy.d.ts +82 -0
- package/dist/host/env-policy.js +181 -0
- package/dist/host/extension.d.ts +7 -0
- package/dist/host/extension.js +40 -0
- package/dist/host/facts.d.ts +31 -0
- package/dist/host/facts.js +58 -0
- package/dist/host/fs-write.d.ts +96 -0
- package/dist/host/fs-write.js +183 -0
- package/dist/host/git.d.ts +5 -0
- package/dist/host/git.js +1 -0
- package/dist/host/host-actions.d.ts +2 -0
- package/dist/host/host-actions.js +5 -0
- package/dist/host/host-kit.d.ts +37 -0
- package/dist/host/host-kit.js +27 -0
- package/dist/host/http.d.ts +47 -0
- package/dist/host/http.js +289 -0
- package/dist/host/install-failure.d.ts +50 -0
- package/dist/host/install-failure.js +184 -0
- package/dist/host/installed-module.d.ts +25 -0
- package/dist/host/installed-module.js +289 -0
- package/dist/host/installed-sources.d.ts +10 -0
- package/dist/host/installed-sources.js +63 -0
- package/dist/host/lease.d.ts +70 -0
- package/dist/host/lease.js +264 -0
- package/dist/host/lib-capabilities.d.ts +22 -0
- package/dist/host/lib-capabilities.js +37 -0
- package/dist/host/lib-install.d.ts +19 -0
- package/dist/host/lib-install.js +40 -0
- package/dist/host/lib-runners.d.ts +18 -0
- package/dist/host/lib-runners.js +46 -0
- package/dist/host/local-declaration.d.ts +7 -0
- package/dist/host/local-declaration.js +33 -0
- package/dist/host/long-task.d.ts +97 -0
- package/dist/host/long-task.js +297 -0
- package/dist/host/market-index-claim.d.ts +19 -0
- package/dist/host/market-index-claim.js +87 -0
- package/dist/host/market-index-doc.d.ts +12 -0
- package/dist/host/market-index-doc.js +1 -0
- package/dist/host/market-index-parse.d.ts +28 -0
- package/dist/host/market-index-parse.js +413 -0
- package/dist/host/market-index.d.ts +13 -0
- package/dist/host/market-index.js +105 -0
- package/dist/host/module-root.d.ts +1 -0
- package/dist/host/module-root.js +5 -0
- package/dist/host/needs.d.ts +4 -0
- package/dist/host/needs.js +2 -0
- package/dist/host/npm-registry.d.ts +10 -0
- package/dist/host/npm-registry.js +16 -0
- package/dist/host/package-content.d.ts +8 -0
- package/dist/host/package-content.js +90 -0
- package/dist/host/package-kind.d.ts +13 -0
- package/dist/host/package-kind.js +51 -0
- package/dist/host/package-route.d.ts +33 -0
- package/dist/host/package-route.js +68 -0
- package/dist/host/panel-state.d.ts +120 -0
- package/dist/host/panel-state.js +177 -0
- package/dist/host/patch-blocks.d.ts +13 -0
- package/dist/host/patch-blocks.js +52 -0
- package/dist/host/patch.d.ts +4 -0
- package/dist/host/patch.js +7 -0
- package/dist/host/paths.d.ts +12 -0
- package/dist/host/paths.js +20 -0
- package/dist/host/payload.d.ts +12 -0
- package/dist/host/payload.js +16 -0
- package/dist/host/plan-results.d.ts +5 -0
- package/dist/host/plan-results.js +71 -0
- package/dist/host/plan-run.d.ts +41 -0
- package/dist/host/plan-run.js +87 -0
- package/dist/host/platform.d.ts +14 -0
- package/dist/host/platform.js +40 -0
- package/dist/host/plugin-ledger.d.ts +32 -0
- package/dist/host/plugin-ledger.js +106 -0
- package/dist/host/plugin.d.ts +3 -0
- package/dist/host/plugin.js +38 -0
- package/dist/host/port-types.d.ts +233 -0
- package/dist/host/port-types.js +1 -0
- package/dist/host/preflight.d.ts +32 -0
- package/dist/host/preflight.js +1 -0
- package/dist/host/process-alive.d.ts +6 -0
- package/dist/host/process-alive.js +16 -0
- package/dist/host/profile-bundles.d.ts +20 -0
- package/dist/host/profile-bundles.js +48 -0
- package/dist/host/profile-create.d.ts +19 -0
- package/dist/host/profile-create.js +124 -0
- package/dist/host/profile-port.d.ts +4 -0
- package/dist/host/profile-port.js +4 -0
- package/dist/host/profile-registries.d.ts +10 -0
- package/dist/host/profile-registries.js +149 -0
- package/dist/host/provision.d.ts +32 -0
- package/dist/host/provision.js +105 -0
- package/dist/host/read-json.d.ts +1 -0
- package/dist/host/read-json.js +11 -0
- package/dist/host/recipe-rules.d.ts +5 -0
- package/dist/host/recipe-rules.js +412 -0
- package/dist/host/recipe.d.ts +14 -0
- package/dist/host/recipe.js +332 -0
- package/dist/host/registry-declaration.d.ts +21 -0
- package/dist/host/registry-declaration.js +42 -0
- package/dist/host/reinstall-record.d.ts +16 -0
- package/dist/host/reinstall-record.js +54 -0
- package/dist/host/release-age.d.ts +24 -0
- package/dist/host/release-age.js +92 -0
- package/dist/host/release-packages.generated.d.ts +1 -0
- package/dist/host/release-packages.generated.js +10 -0
- package/dist/host/release-probe.d.ts +37 -0
- package/dist/host/release-probe.js +156 -0
- package/dist/host/runtime/browser-argv.d.ts +1 -0
- package/dist/host/runtime/browser-argv.js +9 -0
- package/dist/host/runtime/dsh-compat.d.ts +4 -0
- package/dist/host/runtime/dsh-compat.js +32 -16
- package/dist/host/runtime/front-app.d.ts +6 -0
- package/dist/host/runtime/front-app.js +70 -0
- package/dist/host/runtime/verified-dsh.d.ts +5 -0
- package/dist/host/runtime/verified-dsh.js +20 -0
- package/dist/host/shell-render.d.ts +52 -0
- package/dist/host/shell-render.js +117 -0
- package/dist/host/shell-text.d.ts +30 -0
- package/dist/host/shell-text.js +40 -0
- package/dist/host/shell.d.ts +25 -0
- package/dist/host/shell.js +55 -0
- package/dist/host/site.d.ts +45 -0
- package/dist/host/site.js +182 -0
- package/dist/host/spec.d.ts +8 -0
- package/dist/host/spec.js +24 -0
- package/dist/host/submit-confirm.d.ts +19 -0
- package/dist/host/submit-confirm.js +45 -0
- package/dist/host/supply/builtin-catalog.d.ts +3 -0
- package/dist/host/supply/builtin-catalog.js +38 -0
- package/dist/host/supply/preflight.d.ts +14 -1
- package/dist/host/supply/supply-index.js +6 -0
- package/dist/host/supply-index.d.ts +38 -0
- package/dist/host/supply-index.js +209 -0
- package/dist/host/supply-port.d.ts +5 -0
- package/dist/host/supply-port.js +50 -0
- package/dist/host/time.d.ts +22 -0
- package/dist/host/time.js +33 -0
- package/dist/host/tokens.d.ts +26 -0
- package/dist/host/tokens.js +154 -0
- package/dist/host/tool-approval.d.ts +86 -0
- package/dist/host/tool-approval.js +118 -0
- package/dist/host/tool-kit.d.ts +8 -0
- package/dist/host/tool-kit.js +22 -0
- package/dist/host/toolbox-port.d.ts +16 -0
- package/dist/host/toolbox-port.js +1 -0
- package/dist/host/unit-config.d.ts +34 -0
- package/dist/host/unit-config.js +28 -0
- package/dist/host/unit-data.d.ts +3 -0
- package/dist/host/unit-data.js +127 -0
- package/dist/host/unit-face.d.ts +95 -0
- package/dist/host/unit-face.js +1 -0
- package/dist/host/unit-plugin.d.ts +24 -0
- package/dist/host/unit-plugin.js +25 -0
- package/dist/host/update-journal-manifest.d.ts +19 -0
- package/dist/host/update-journal-manifest.js +134 -0
- package/dist/host/update-journal-types.d.ts +33 -0
- package/dist/host/update-journal-types.js +2 -0
- package/dist/host/update-journal.d.ts +43 -0
- package/dist/host/update-journal.js +409 -0
- package/dist/host/value-handoff.d.ts +16 -0
- package/dist/host/value-handoff.js +22 -0
- package/dist/host/version-range.d.ts +2 -0
- package/dist/host/version-range.js +13 -0
- package/dist/host/version.d.ts +4 -0
- package/dist/host/version.js +32 -0
- package/dist/host/workspace-store.d.ts +19 -0
- package/dist/host/workspace-store.js +133 -0
- package/dist/host/write-result.d.ts +1 -0
- package/dist/host/write-result.js +18 -0
- package/dist/host.d.ts +2 -0
- package/dist/host.js +2 -0
- package/dist/i18n/en.js +14 -3
- package/dist/i18n/index.d.ts +15 -4
- package/dist/i18n/zh.d.ts +14 -3
- package/dist/i18n/zh.js +14 -3
- package/dist/lib/bundle-requirements.d.ts +1 -0
- package/dist/lib/bundle-requirements.js +9 -0
- package/package.json +1 -1
- package/src/contract/__tests__/unit.test.ts +7 -0
- package/src/contract/needs.ts +5 -3
- package/src/contract/protocol/bundle-install.ts +1 -0
- package/src/contract/unit.ts +2 -1
- package/src/host/runtime/__tests__/dsh-compat.test.ts +19 -1
- package/src/host/runtime/__tests__/verified-dsh.test.ts +55 -0
- package/src/host/runtime/dsh-compat.ts +36 -12
- package/src/host/runtime/verified-dsh.ts +22 -0
- package/src/host/supply/__tests__/builtin-catalog.test.ts +44 -0
- package/src/host/supply/builtin-catalog.ts +38 -0
- package/src/host/supply/preflight.ts +16 -1
- package/src/host/supply/supply-index.ts +3 -0
- package/src/host.ts +2 -0
- package/src/i18n/en.ts +17 -3
- package/src/i18n/zh.ts +16 -3
- package/src/lib/bundle-requirements.ts +11 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { npmRegistryOf } from './npm-registry.js';
|
|
2
|
+
export function npmSourceOf(sources) {
|
|
3
|
+
return sources?.find((source) => source.kind === 'npm');
|
|
4
|
+
}
|
|
5
|
+
function text(value) {
|
|
6
|
+
return value === undefined ? '' : value.trim();
|
|
7
|
+
}
|
|
8
|
+
function conventionPackage(name, prefix) {
|
|
9
|
+
return `${prefix}${name}`;
|
|
10
|
+
}
|
|
11
|
+
function nativeSourcePackage(source) {
|
|
12
|
+
if (source.kind === 'npm')
|
|
13
|
+
return text(source.package);
|
|
14
|
+
if (source.kind === 'git')
|
|
15
|
+
return `git:${text(source.url)}`;
|
|
16
|
+
return `local:${text(source.env) || text(source.path)}`;
|
|
17
|
+
}
|
|
18
|
+
function packageOf(need, prefix) {
|
|
19
|
+
if (need.kind === 'lib')
|
|
20
|
+
return text(need.name);
|
|
21
|
+
const first = need.sources?.[0];
|
|
22
|
+
if (first === undefined)
|
|
23
|
+
return conventionPackage(need.name, prefix);
|
|
24
|
+
if (first.kind === 'npm') {
|
|
25
|
+
const pkg = text(first.package);
|
|
26
|
+
return pkg === '' ? conventionPackage(need.name, prefix) : pkg;
|
|
27
|
+
}
|
|
28
|
+
return nativeSourcePackage(first);
|
|
29
|
+
}
|
|
30
|
+
function keyOf(kind, pkg) {
|
|
31
|
+
return `${kind}:${pkg}`;
|
|
32
|
+
}
|
|
33
|
+
function registryAddressOf(source, env) {
|
|
34
|
+
const resolved = npmRegistryOf(source, env);
|
|
35
|
+
return resolved.ok ? resolved.value : undefined;
|
|
36
|
+
}
|
|
37
|
+
function sourceCompatible(left, right, env) {
|
|
38
|
+
if (left.kind !== right.kind)
|
|
39
|
+
return false;
|
|
40
|
+
if (left.kind === 'npm' && right.kind === 'npm') {
|
|
41
|
+
if (text(left.package) !== '' && text(right.package) !== '' && text(left.package) !== text(right.package)) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
const l = registryAddressOf(left, env);
|
|
45
|
+
const r = registryAddressOf(right, env);
|
|
46
|
+
if (l !== undefined && r !== undefined)
|
|
47
|
+
return l === r;
|
|
48
|
+
return text(left.registryEnv) === text(right.registryEnv);
|
|
49
|
+
}
|
|
50
|
+
if (left.kind === 'git' && right.kind === 'git')
|
|
51
|
+
return text(left.url) === text(right.url);
|
|
52
|
+
if (left.kind === 'local' && right.kind === 'local') {
|
|
53
|
+
return text(left.env) === text(right.env) && text(left.path) === text(right.path);
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
function sourcesCompatible(left, right, env) {
|
|
58
|
+
if (left.length !== right.length)
|
|
59
|
+
return false;
|
|
60
|
+
return left.every((source, index) => {
|
|
61
|
+
const other = right[index];
|
|
62
|
+
return other !== undefined && sourceCompatible(source, other, env);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function mergedSource(left, right) {
|
|
66
|
+
if (left.kind === 'npm' && right.kind === 'npm') {
|
|
67
|
+
const pkg = text(left.package) === '' ? right.package : left.package;
|
|
68
|
+
const registryDefault = text(left.registryDefault) === '' ? right.registryDefault : left.registryDefault;
|
|
69
|
+
return {
|
|
70
|
+
...left,
|
|
71
|
+
...(pkg === undefined ? {} : { package: pkg }),
|
|
72
|
+
...(registryDefault === undefined ? {} : { registryDefault }),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return left;
|
|
76
|
+
}
|
|
77
|
+
function mergeSources(entry, sources, env) {
|
|
78
|
+
if (!entry.declared) {
|
|
79
|
+
entry.declared = true;
|
|
80
|
+
entry.sources = [...sources];
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
if (!sourcesCompatible(entry.sources, sources, env)) {
|
|
84
|
+
entry.conflicted = true;
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
entry.sources = entry.sources.map((source, index) => {
|
|
88
|
+
const other = sources[index];
|
|
89
|
+
return other === undefined ? source : mergedSource(source, other);
|
|
90
|
+
});
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
function sourceText(source) {
|
|
94
|
+
if (source.kind === 'npm') {
|
|
95
|
+
return `${source.package === undefined ? '按包名约定' : source.package}(${source.registryEnv ?? '默认源'})`;
|
|
96
|
+
}
|
|
97
|
+
if (source.kind === 'git')
|
|
98
|
+
return `git:${source.url}`;
|
|
99
|
+
return `local:${source.env ?? source.path ?? ''}`;
|
|
100
|
+
}
|
|
101
|
+
function addDeclarer(entry, unit, commands) {
|
|
102
|
+
if (!entry.declarers.includes(unit))
|
|
103
|
+
entry.declarers.push(unit);
|
|
104
|
+
for (const command of commands)
|
|
105
|
+
if (!entry.commands.includes(command))
|
|
106
|
+
entry.commands.push(command);
|
|
107
|
+
}
|
|
108
|
+
export function buildSupplyIndex(declarations, options = {}) {
|
|
109
|
+
const env = options.env ?? {};
|
|
110
|
+
const prefix = options.packagePrefix ?? '';
|
|
111
|
+
const entries = new Map();
|
|
112
|
+
const byName = new Map();
|
|
113
|
+
const conflicts = [];
|
|
114
|
+
const ensure = (kind, pkg) => {
|
|
115
|
+
const key = keyOf(kind, pkg);
|
|
116
|
+
const found = entries.get(key);
|
|
117
|
+
if (found !== undefined)
|
|
118
|
+
return found;
|
|
119
|
+
const created = {
|
|
120
|
+
key,
|
|
121
|
+
kind,
|
|
122
|
+
package: pkg,
|
|
123
|
+
declared: false,
|
|
124
|
+
names: [],
|
|
125
|
+
sources: [],
|
|
126
|
+
declarers: [],
|
|
127
|
+
commands: [],
|
|
128
|
+
conflicted: false,
|
|
129
|
+
};
|
|
130
|
+
entries.set(key, created);
|
|
131
|
+
return created;
|
|
132
|
+
};
|
|
133
|
+
for (const declaration of declarations) {
|
|
134
|
+
for (const need of declaration.needs ?? []) {
|
|
135
|
+
if (need.kind !== 'extension' && need.kind !== 'lib')
|
|
136
|
+
continue;
|
|
137
|
+
const pkg = packageOf(need, prefix);
|
|
138
|
+
const entry = ensure(need.kind, pkg);
|
|
139
|
+
if (!entry.names.includes(need.name))
|
|
140
|
+
entry.names.push(need.name);
|
|
141
|
+
if (need.kind === 'extension') {
|
|
142
|
+
entry.runtime = need.runtime;
|
|
143
|
+
addDeclarer(entry, declaration.id, need.commands ?? []);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
addDeclarer(entry, declaration.id, []);
|
|
147
|
+
}
|
|
148
|
+
const same = mergeSources(entry, need.sources ?? [], env);
|
|
149
|
+
if (!same) {
|
|
150
|
+
conflicts.push({
|
|
151
|
+
kind: 'source-mismatch',
|
|
152
|
+
key: entry.key,
|
|
153
|
+
names: [...entry.names],
|
|
154
|
+
declarers: [...entry.declarers],
|
|
155
|
+
detail: `${entry.kind === 'extension' ? '插件' : '共用库'} ${entry.names.join('、')} 被 ` +
|
|
156
|
+
`${entry.declarers.join('、')} 声明成了不同的来源(` +
|
|
157
|
+
`${entry.sources.map(sourceText).join(' / ') || '无来源'})`,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
const nameKey = `${need.kind}:${need.name}`;
|
|
161
|
+
const seen = byName.get(nameKey);
|
|
162
|
+
if (seen !== undefined && seen.key !== entry.key) {
|
|
163
|
+
const detail = `${need.kind === 'extension' ? '插件' : '共用库'} ${need.name} 来自不同的包:` +
|
|
164
|
+
`${seen.package} / ${entry.package}`;
|
|
165
|
+
entry.conflicted = true;
|
|
166
|
+
seen.conflicted = true;
|
|
167
|
+
conflicts.push({
|
|
168
|
+
kind: 'name-mismatch',
|
|
169
|
+
key: entry.key,
|
|
170
|
+
names: [need.name],
|
|
171
|
+
declarers: [...new Set([...seen.declarers, ...entry.declarers])],
|
|
172
|
+
detail,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
else if (seen === undefined) {
|
|
176
|
+
byName.set(nameKey, entry);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const deduped = new Map();
|
|
181
|
+
for (const conflict of conflicts) {
|
|
182
|
+
deduped.set(`${conflict.kind}:${conflict.key}`, conflict);
|
|
183
|
+
}
|
|
184
|
+
const frozenEntries = new Map();
|
|
185
|
+
for (const [key, entry] of entries) {
|
|
186
|
+
frozenEntries.set(key, {
|
|
187
|
+
key: entry.key,
|
|
188
|
+
kind: entry.kind,
|
|
189
|
+
names: [...entry.names],
|
|
190
|
+
package: entry.package,
|
|
191
|
+
...(entry.runtime === undefined ? {} : { runtime: entry.runtime }),
|
|
192
|
+
sources: entry.sources.map((source) => ({ ...source })),
|
|
193
|
+
declarers: [...entry.declarers],
|
|
194
|
+
commands: [...entry.commands],
|
|
195
|
+
conflicted: entry.conflicted,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
const entryOf = (kind, name) => byName.get(`${kind}:${name}`);
|
|
199
|
+
return {
|
|
200
|
+
entries: frozenEntries,
|
|
201
|
+
conflicts: [...deduped.values()],
|
|
202
|
+
problems: [...deduped.values()].map((conflict) => conflict.detail),
|
|
203
|
+
entryOf,
|
|
204
|
+
sourcesOf: (kind, name) => {
|
|
205
|
+
const entry = entryOf(kind, name);
|
|
206
|
+
return entry === undefined || entry.conflicted ? [] : entry.sources;
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { DshHostContext } from '../api/dsh.js';
|
|
2
|
+
import type { SupplyPort } from './port-types.js';
|
|
3
|
+
export type { SupplyPort } from './port-types.js';
|
|
4
|
+
export declare function supplyPortOf(ctx: DshHostContext): SupplyPort;
|
|
5
|
+
export declare function requireSupply(): SupplyPort;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { adaptersOf } from './adapters.js';
|
|
2
|
+
export function supplyPortOf(ctx) {
|
|
3
|
+
const set = adaptersOf(ctx);
|
|
4
|
+
const env = set.supply;
|
|
5
|
+
const modules = set.modules;
|
|
6
|
+
const pluginPackagePrefix = modules.pluginPackagePrefix;
|
|
7
|
+
const pluginManifestFile = modules.pluginManifestFile;
|
|
8
|
+
const cliCatalogPath = modules.cliCatalogPath;
|
|
9
|
+
const vendorPluginsDir = modules.vendorPluginsDir;
|
|
10
|
+
const runtimeInstallCommand = modules.runtimeInstallCommand;
|
|
11
|
+
return {
|
|
12
|
+
env,
|
|
13
|
+
modules,
|
|
14
|
+
resolvePluginSource: (source, environment, options) => env.resolvePluginSource(source, environment, options),
|
|
15
|
+
libInstallCommand: (options) => env.libInstallCommand(options),
|
|
16
|
+
libUninstallCommand: (options) => env.libUninstallCommand(options),
|
|
17
|
+
pluginInstallPlan: (options) => env.pluginInstallPlan(options),
|
|
18
|
+
recoveryCommand: (options) => env.recoveryCommand(options),
|
|
19
|
+
latestVersion: (options) => env.latestVersion(options),
|
|
20
|
+
missingReleaseParts: (options) => env.missingReleaseParts(options),
|
|
21
|
+
probeRelease: (options) => env.probeRelease(options),
|
|
22
|
+
splitNpmSpec: (spec) => env.splitNpmSpec(spec),
|
|
23
|
+
isolatedRoot: () => modules.isolatedRoot(),
|
|
24
|
+
isolatedHome: () => modules.isolatedHome(),
|
|
25
|
+
...(pluginPackagePrefix === undefined ? {} : { pluginPackagePrefix: () => pluginPackagePrefix() }),
|
|
26
|
+
...(pluginManifestFile === undefined ? {} : { pluginManifestFile: () => pluginManifestFile() }),
|
|
27
|
+
...(cliCatalogPath === undefined ? {} : { cliCatalogPath: () => cliCatalogPath() }),
|
|
28
|
+
...(vendorPluginsDir === undefined ? {} : { vendorPluginsDir: () => vendorPluginsDir() }),
|
|
29
|
+
...(runtimeInstallCommand === undefined ? {} : { runtimeInstallCommand: () => runtimeInstallCommand() }),
|
|
30
|
+
afterLibInstall: () => modules.afterLibInstall(),
|
|
31
|
+
profileDirOf: (context) => modules.profileDirOf(context),
|
|
32
|
+
profileModules: (dir) => modules.profileModules(dir),
|
|
33
|
+
readInstalledModule: (dir, pkg) => modules.readInstalledModule(dir, pkg),
|
|
34
|
+
readProfilePackage: (dir, pkg) => modules.readProfilePackage(dir, pkg),
|
|
35
|
+
readBundleManager: (context) => modules.readBundleManager(context),
|
|
36
|
+
createRegistryNotebook: (dir) => modules.createRegistryNotebook(dir),
|
|
37
|
+
declarationGaps: (dir) => modules.declarationGaps(dir),
|
|
38
|
+
moduleDeclarationOf: (dir, pkg) => modules.moduleDeclarationOf(dir, pkg),
|
|
39
|
+
registryDeclarationOf: (options) => modules.registryDeclarationOf(options),
|
|
40
|
+
pathDeclarationOf: (spec) => modules.pathDeclarationOf(spec),
|
|
41
|
+
declarationRefusalOf: (name, raw) => modules.declarationRefusalOf(name, raw),
|
|
42
|
+
refusalReason: () => modules.refusalReason(),
|
|
43
|
+
packageRouteOf: (options) => modules.packageRouteOf(options),
|
|
44
|
+
isNewerVersion: (left, right) => modules.isNewerVersion(left, right),
|
|
45
|
+
startSelfUpdate: (request, onError) => modules.startSelfUpdate(request, onError),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export function requireSupply() {
|
|
49
|
+
throw new Error('workbenchSupply 未提供');
|
|
50
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UTC 时钟(`HH:mm:ss`):日志与状态行只给人看时分秒,不带日期。
|
|
3
|
+
* @param value ISO 字符串、时间戳或 Date。
|
|
4
|
+
* @returns `HH:mm:ss`;非法时间返回 `Invalid Date`。
|
|
5
|
+
*/
|
|
6
|
+
export declare function clockOf(value: string | number | Date): string;
|
|
7
|
+
/**
|
|
8
|
+
* 把时间戳/ISO 字符串转成毫秒;非法输入给 `NaN`(调用方据此回退)。
|
|
9
|
+
* @param value ISO 字符串、时间戳或 Date。
|
|
10
|
+
* @returns 毫秒时间戳或 `NaN`。
|
|
11
|
+
*/
|
|
12
|
+
export declare function epochOf(value: string | number | Date): number;
|
|
13
|
+
/**
|
|
14
|
+
* 当前时间(毫秒)。宿主里要「现在几点」只走这里,测试可以点住 `Date.now`。
|
|
15
|
+
* @returns 毫秒时间戳。
|
|
16
|
+
*/
|
|
17
|
+
export declare function now(): number;
|
|
18
|
+
/**
|
|
19
|
+
* 当前时间的 ISO 字符串。
|
|
20
|
+
* @returns `new Date().toISOString()` 的等价物。
|
|
21
|
+
*/
|
|
22
|
+
export declare function nowIso(): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import utc from 'dayjs/plugin/utc.js';
|
|
3
|
+
dayjs.extend(utc);
|
|
4
|
+
/**
|
|
5
|
+
* UTC 时钟(`HH:mm:ss`):日志与状态行只给人看时分秒,不带日期。
|
|
6
|
+
* @param value ISO 字符串、时间戳或 Date。
|
|
7
|
+
* @returns `HH:mm:ss`;非法时间返回 `Invalid Date`。
|
|
8
|
+
*/
|
|
9
|
+
export function clockOf(value) {
|
|
10
|
+
return dayjs(value).utc().format('HH:mm:ss');
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 把时间戳/ISO 字符串转成毫秒;非法输入给 `NaN`(调用方据此回退)。
|
|
14
|
+
* @param value ISO 字符串、时间戳或 Date。
|
|
15
|
+
* @returns 毫秒时间戳或 `NaN`。
|
|
16
|
+
*/
|
|
17
|
+
export function epochOf(value) {
|
|
18
|
+
return dayjs(value).valueOf();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 当前时间(毫秒)。宿主里要「现在几点」只走这里,测试可以点住 `Date.now`。
|
|
22
|
+
* @returns 毫秒时间戳。
|
|
23
|
+
*/
|
|
24
|
+
export function now() {
|
|
25
|
+
return Date.now();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 当前时间的 ISO 字符串。
|
|
29
|
+
* @returns `new Date().toISOString()` 的等价物。
|
|
30
|
+
*/
|
|
31
|
+
export function nowIso() {
|
|
32
|
+
return new Date(now()).toISOString();
|
|
33
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare const DSH_THEME_PACKAGE = "@deepseek-ai/dsh-client-ui-theme";
|
|
2
|
+
export declare const SHELL_PACKAGE = "@dsh-workbench/core";
|
|
3
|
+
export declare const DSW_PREFIX = "--dsw-";
|
|
4
|
+
export declare const WB_PREFIX = "--wb-";
|
|
5
|
+
export interface TokenValues {
|
|
6
|
+
readonly light: string | null;
|
|
7
|
+
readonly dark: string | null;
|
|
8
|
+
}
|
|
9
|
+
export interface TokenEntry {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly values: TokenValues;
|
|
12
|
+
}
|
|
13
|
+
export interface TokenSource {
|
|
14
|
+
readonly package: string;
|
|
15
|
+
readonly version: string | null;
|
|
16
|
+
readonly file: string;
|
|
17
|
+
readonly entries: readonly TokenEntry[];
|
|
18
|
+
}
|
|
19
|
+
export interface TokenSet {
|
|
20
|
+
readonly dsw: TokenSource | null;
|
|
21
|
+
readonly wb: TokenSource | null;
|
|
22
|
+
}
|
|
23
|
+
export declare function tokenEntriesIn(text: string, prefix: string): readonly TokenEntry[];
|
|
24
|
+
export declare function readTokens(startDirs: readonly string[]): TokenSet;
|
|
25
|
+
export declare function nearestTokens(name: string, names: readonly string[], limit?: number): readonly string[];
|
|
26
|
+
export declare function tokenFamilyOf(name: string): string;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join, resolve } from 'node:path';
|
|
3
|
+
export const DSH_THEME_PACKAGE = '@deepseek-ai/dsh-client-ui-theme';
|
|
4
|
+
export const SHELL_PACKAGE = '@dsh-workbench/core';
|
|
5
|
+
export const DSW_PREFIX = '--dsw-';
|
|
6
|
+
export const WB_PREFIX = '--wb-';
|
|
7
|
+
const BLOCK = /([^{}]*)\{([^{}]*)\}/g;
|
|
8
|
+
const DECLARATION = /(--[a-z0-9-]+)\s*:\s*([^;{}]+)/g;
|
|
9
|
+
const DARK_BLOCK = /data-ds-dark-theme/;
|
|
10
|
+
const VAR_USE = /var\(\s*(--[a-z0-9-]+)\s*(?:,[^()]*)?\)/g;
|
|
11
|
+
function rawDefinitionsIn(text, prefix) {
|
|
12
|
+
const defs = new Map();
|
|
13
|
+
for (const block of text.matchAll(BLOCK)) {
|
|
14
|
+
const selector = block[1] ?? '';
|
|
15
|
+
const dark = DARK_BLOCK.test(selector);
|
|
16
|
+
for (const declaration of (block[2] ?? '').matchAll(DECLARATION)) {
|
|
17
|
+
const name = declaration[1] ?? '';
|
|
18
|
+
const value = (declaration[2] ?? '').trim();
|
|
19
|
+
if (!name.startsWith(prefix) || value === '')
|
|
20
|
+
continue;
|
|
21
|
+
const found = defs.get(name) ?? {};
|
|
22
|
+
const key = dark ? 'dark' : 'light';
|
|
23
|
+
if (found[key] === undefined)
|
|
24
|
+
found[key] = value;
|
|
25
|
+
defs.set(name, found);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return defs;
|
|
29
|
+
}
|
|
30
|
+
function resolved(value, scheme, defs, depth = 0) {
|
|
31
|
+
if (depth >= 4 || !value.includes('var('))
|
|
32
|
+
return value;
|
|
33
|
+
return value.replace(VAR_USE, (whole, name) => {
|
|
34
|
+
const found = defs.get(name);
|
|
35
|
+
if (found === undefined)
|
|
36
|
+
return whole;
|
|
37
|
+
const next = scheme === 'dark' ? found.dark ?? found.light : found.light ?? found.dark;
|
|
38
|
+
return next === undefined ? whole : resolved(next, scheme, defs, depth + 1);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
export function tokenEntriesIn(text, prefix) {
|
|
42
|
+
const defs = rawDefinitionsIn(text, prefix);
|
|
43
|
+
return [...defs.entries()]
|
|
44
|
+
.map(([name, found]) => ({
|
|
45
|
+
name,
|
|
46
|
+
values: {
|
|
47
|
+
light: found.light === undefined ? null : resolved(found.light, 'light', defs),
|
|
48
|
+
dark: found.dark === undefined ? null : resolved(found.dark, 'dark', defs),
|
|
49
|
+
},
|
|
50
|
+
}))
|
|
51
|
+
.sort((left, right) => left.name.localeCompare(right.name));
|
|
52
|
+
}
|
|
53
|
+
function manifestAt(root) {
|
|
54
|
+
try {
|
|
55
|
+
const manifest = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'));
|
|
56
|
+
if (typeof manifest !== 'object' || manifest === null)
|
|
57
|
+
return null;
|
|
58
|
+
const record = manifest;
|
|
59
|
+
return {
|
|
60
|
+
name: typeof record.name === 'string' ? record.name : null,
|
|
61
|
+
version: typeof record.version === 'string' ? record.version : null,
|
|
62
|
+
root,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function findPackage(startDirs, packageName) {
|
|
70
|
+
for (const start of startDirs) {
|
|
71
|
+
if (start.trim() === '')
|
|
72
|
+
continue;
|
|
73
|
+
const own = manifestAt(start);
|
|
74
|
+
if (own !== null && own.name === packageName)
|
|
75
|
+
return own;
|
|
76
|
+
let at = resolve(start);
|
|
77
|
+
for (;;) {
|
|
78
|
+
const candidate = join(at, 'node_modules', ...packageName.split('/'));
|
|
79
|
+
const manifest = manifestAt(candidate);
|
|
80
|
+
if (manifest !== null && (manifest.name === null || manifest.name === packageName))
|
|
81
|
+
return manifest;
|
|
82
|
+
const parent = dirname(at);
|
|
83
|
+
if (parent === at)
|
|
84
|
+
break;
|
|
85
|
+
at = parent;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
function sourceAt(startDirs, packageName, tail, prefix) {
|
|
91
|
+
const manifest = findPackage(startDirs, packageName);
|
|
92
|
+
if (manifest === null)
|
|
93
|
+
return null;
|
|
94
|
+
const file = join(manifest.root, tail);
|
|
95
|
+
if (!existsSync(file))
|
|
96
|
+
return null;
|
|
97
|
+
return {
|
|
98
|
+
package: packageName,
|
|
99
|
+
version: manifest.version,
|
|
100
|
+
file,
|
|
101
|
+
entries: tokenEntriesIn(readFileSync(file, 'utf8'), prefix),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export function readTokens(startDirs) {
|
|
105
|
+
const dsw = sourceAt(startDirs, DSH_THEME_PACKAGE, join('lib', 'client.js'), DSW_PREFIX);
|
|
106
|
+
const wb = sourceAt(startDirs, SHELL_PACKAGE, 'client.js', WB_PREFIX);
|
|
107
|
+
return { dsw, wb };
|
|
108
|
+
}
|
|
109
|
+
function distance(left, right) {
|
|
110
|
+
let previous = Array.from({ length: right.length + 1 }, (_unused, index) => index);
|
|
111
|
+
for (let row = 1; row <= left.length; row += 1) {
|
|
112
|
+
const current = [row];
|
|
113
|
+
for (let column = 1; column <= right.length; column += 1) {
|
|
114
|
+
const same = left[row - 1] === right[column - 1] ? 0 : 1;
|
|
115
|
+
current.push(Math.min((previous[column] ?? 0) + 1, (current[column - 1] ?? 0) + 1, (previous[column - 1] ?? 0) + same));
|
|
116
|
+
}
|
|
117
|
+
previous = current;
|
|
118
|
+
}
|
|
119
|
+
return previous[right.length] ?? 0;
|
|
120
|
+
}
|
|
121
|
+
function commonPrefixLength(left, right) {
|
|
122
|
+
const cap = Math.min(left.length, right.length);
|
|
123
|
+
let at = 0;
|
|
124
|
+
while (at < cap && left[at] === right[at])
|
|
125
|
+
at += 1;
|
|
126
|
+
return at;
|
|
127
|
+
}
|
|
128
|
+
export function nearestTokens(name, names, limit = 6) {
|
|
129
|
+
const wanted = name.trim().toLowerCase();
|
|
130
|
+
if (wanted === '')
|
|
131
|
+
return [];
|
|
132
|
+
const shared = wanted.slice(0, wanted.lastIndexOf('-') + 1);
|
|
133
|
+
return names
|
|
134
|
+
.flatMap((one) => {
|
|
135
|
+
const lower = one.toLowerCase();
|
|
136
|
+
const typos = lower.length < 3 ? Number.POSITIVE_INFINITY : distance(lower, wanted);
|
|
137
|
+
if (typos <= 2)
|
|
138
|
+
return [{ one, typos }];
|
|
139
|
+
const prefix = commonPrefixLength(lower, wanted);
|
|
140
|
+
if (prefix < 8)
|
|
141
|
+
return [];
|
|
142
|
+
const sameStem = shared.length >= 8 && lower.startsWith(shared);
|
|
143
|
+
const score = 10 + typos - prefix + (sameStem ? 0 : 20);
|
|
144
|
+
return score < 20 ? [{ one, typos: score }] : [];
|
|
145
|
+
})
|
|
146
|
+
.sort((left, right) => left.typos - right.typos || left.one.length - right.one.length || left.one.localeCompare(right.one))
|
|
147
|
+
.slice(0, limit)
|
|
148
|
+
.map((one) => one.one);
|
|
149
|
+
}
|
|
150
|
+
export function tokenFamilyOf(name) {
|
|
151
|
+
const rest = name.startsWith(DSW_PREFIX) ? name.slice(DSW_PREFIX.length) : name.startsWith(WB_PREFIX) ? name.slice(WB_PREFIX.length) : name;
|
|
152
|
+
const cut = rest.indexOf('-');
|
|
153
|
+
return cut === -1 ? rest : rest.slice(0, cut);
|
|
154
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export { APPROVAL_NOTE_ARG } from '../contract/approval.js';
|
|
2
|
+
export type AskDecision = {
|
|
3
|
+
readonly kind: 'ask';
|
|
4
|
+
readonly reason: string;
|
|
5
|
+
readonly displayReason: {
|
|
6
|
+
readonly en: string;
|
|
7
|
+
readonly zh: string;
|
|
8
|
+
};
|
|
9
|
+
} | {
|
|
10
|
+
readonly kind: 'deny';
|
|
11
|
+
readonly reason: string;
|
|
12
|
+
};
|
|
13
|
+
export interface ApprovalDetail {
|
|
14
|
+
readonly en: string;
|
|
15
|
+
readonly zh: string;
|
|
16
|
+
}
|
|
17
|
+
export type ApprovalFacts = ApprovalDetail | {
|
|
18
|
+
readonly blocked: string;
|
|
19
|
+
};
|
|
20
|
+
export declare const APPROVAL_NOTE_LIMIT = 40;
|
|
21
|
+
export declare const APPROVAL_DETAIL_LIMIT = 20;
|
|
22
|
+
export declare const APPROVAL_QUESTION_LIMIT = 40;
|
|
23
|
+
export declare const APPROVAL_SEPARATOR_LIMIT = 8;
|
|
24
|
+
export declare const APPROVAL_HEADLINE_LIMIT: number;
|
|
25
|
+
export declare function withApprovalNote(parameters: Record<string, unknown>, options?: {
|
|
26
|
+
readonly required?: boolean | undefined;
|
|
27
|
+
}): Record<string, unknown>;
|
|
28
|
+
export interface ApprovalCall {
|
|
29
|
+
readonly name?: string | undefined;
|
|
30
|
+
readonly arguments?: unknown;
|
|
31
|
+
readonly workspace?: string | undefined;
|
|
32
|
+
readonly session?: string | undefined;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 套件对一次写调用给出的判定:`read` 只是看看、`allow` 会写但本套件不问、`deny` 这一次根本跑不成
|
|
36
|
+
* (连问都不该问,`reason` 原样交给 agent)、`ask` 要用户点头(`question` 接在明细后,`fallback` 是没明细时的整句;
|
|
37
|
+
* `noteInDetail` 为真表示套件把 agent 的附注画在自己的详情座里,标题只留动作、不再追加)。
|
|
38
|
+
*/
|
|
39
|
+
export type ApprovalVerdict = {
|
|
40
|
+
readonly kind: 'read';
|
|
41
|
+
} | {
|
|
42
|
+
readonly kind: 'allow';
|
|
43
|
+
} | {
|
|
44
|
+
readonly kind: 'deny';
|
|
45
|
+
readonly reason: string;
|
|
46
|
+
} | {
|
|
47
|
+
readonly kind: 'ask';
|
|
48
|
+
readonly reason: string;
|
|
49
|
+
readonly question: ApprovalDetail;
|
|
50
|
+
readonly fallback: ApprovalDetail;
|
|
51
|
+
readonly noteInDetail?: boolean;
|
|
52
|
+
};
|
|
53
|
+
export type ApprovalPolicy = (call: ApprovalCall) => ApprovalVerdict | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* 闸门的输入:`skipAsk` 为真表示会话已经不要审批提示(完全权限)—— 认领检查、`{blocked}` 与套件自己的
|
|
56
|
+
* `deny` 照旧,只是不再返回 `ask`;dsh 在 `approval: never` 下会把 `ask` 直接拒掉。
|
|
57
|
+
*/
|
|
58
|
+
export interface ApprovalContext {
|
|
59
|
+
readonly writes?: boolean | undefined;
|
|
60
|
+
readonly elevates?: boolean | undefined;
|
|
61
|
+
readonly policy?: ApprovalPolicy | undefined;
|
|
62
|
+
readonly declaredNote?: boolean | undefined;
|
|
63
|
+
readonly skipAsk?: boolean | undefined;
|
|
64
|
+
readonly detailOf?: ((call: ApprovalCall) => ApprovalFacts | undefined | Promise<ApprovalFacts | undefined>) | undefined;
|
|
65
|
+
}
|
|
66
|
+
export declare function approvalFor(call: ApprovalCall, context?: ApprovalContext): Promise<AskDecision | undefined>;
|
|
67
|
+
/**
|
|
68
|
+
* 「写工具要点头」那一对的默认口径:点名的工具一律 `ask` + 同一份明细,其余一律 `read`。
|
|
69
|
+
* 把它直接摊在 `mount()` 的返回值里:`...writeApprovalOf({ … })`。
|
|
70
|
+
* @param options.tools 需要点头的工具名。
|
|
71
|
+
* @param options.reason 为什么问(给 agent 看的理由)。
|
|
72
|
+
* @param options.question 问句(zh / en,≤40 字)。
|
|
73
|
+
* @param options.fallback 没有明细时的整句(zh / en,≤40 字)。
|
|
74
|
+
* @param options.detail 审批屏头行那句明细(zh / en,≤20 字)。
|
|
75
|
+
* @returns `{ needsApproval, approvalDetail }`。
|
|
76
|
+
*/
|
|
77
|
+
export declare function writeApprovalOf(options: {
|
|
78
|
+
readonly tools: readonly string[];
|
|
79
|
+
readonly reason: string;
|
|
80
|
+
readonly question: ApprovalDetail;
|
|
81
|
+
readonly fallback: ApprovalDetail;
|
|
82
|
+
readonly detail: ApprovalDetail;
|
|
83
|
+
}): {
|
|
84
|
+
needsApproval(call: ApprovalCall): ApprovalVerdict;
|
|
85
|
+
approvalDetail(call: ApprovalCall): ApprovalFacts | undefined;
|
|
86
|
+
};
|