@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,75 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import semver from 'semver';
|
|
3
|
+
import { readJsonObject } from './read-json.js';
|
|
4
|
+
export function dshRequirementsOf(manifest) {
|
|
5
|
+
const pkg = typeof manifest.name === 'string' && manifest.name !== '' ? manifest.name : '(unknown)';
|
|
6
|
+
const engines = manifest.engines ?? {};
|
|
7
|
+
const engineRange = engines['dsh'];
|
|
8
|
+
if (typeof engineRange === 'string' && engineRange.trim() !== '') {
|
|
9
|
+
return [{ pkg, range: engineRange.trim(), source: 'engines' }];
|
|
10
|
+
}
|
|
11
|
+
const peers = manifest.peerDependencies ?? {};
|
|
12
|
+
const found = [];
|
|
13
|
+
for (const [name, range] of Object.entries(peers)) {
|
|
14
|
+
if (name !== '@deepseek-ai/dsh' && !name.startsWith('@deepseek-ai/dsh-'))
|
|
15
|
+
continue;
|
|
16
|
+
if (typeof range !== 'string' || range.trim() === '')
|
|
17
|
+
continue;
|
|
18
|
+
found.push({ pkg, range: range.trim(), source: 'peer' });
|
|
19
|
+
}
|
|
20
|
+
return found;
|
|
21
|
+
}
|
|
22
|
+
export function dshCompatibilityOf(input) {
|
|
23
|
+
const requirements = input.requirements;
|
|
24
|
+
if (requirements.length === 0)
|
|
25
|
+
return { verdict: 'unknown', reason: 'no-requirement', requirements };
|
|
26
|
+
const version = input.dshVersion?.trim() ?? '';
|
|
27
|
+
if (version === '' || semver.valid(version) === null) {
|
|
28
|
+
return { verdict: 'unknown', reason: 'missing-dsh-version', requirements };
|
|
29
|
+
}
|
|
30
|
+
const unsatisfied = [];
|
|
31
|
+
let malformed = false;
|
|
32
|
+
for (const requirement of requirements) {
|
|
33
|
+
const range = semver.validRange(requirement.range);
|
|
34
|
+
if (range === null) {
|
|
35
|
+
malformed = true;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (!semver.satisfies(version, range, { includePrerelease: true }))
|
|
39
|
+
unsatisfied.push(requirement);
|
|
40
|
+
}
|
|
41
|
+
if (unsatisfied.length > 0)
|
|
42
|
+
return { verdict: 'incompatible', requirements: unsatisfied };
|
|
43
|
+
if (malformed)
|
|
44
|
+
return { verdict: 'unknown', reason: 'malformed', requirements };
|
|
45
|
+
return { verdict: 'compatible' };
|
|
46
|
+
}
|
|
47
|
+
export function dshVersionIn(profileDir) {
|
|
48
|
+
const own = readManifest(join(profileDir, 'node_modules', '@deepseek-ai', 'dsh', 'package.json'))?.['version'];
|
|
49
|
+
if (typeof own === 'string' && semver.valid(own) !== null)
|
|
50
|
+
return own;
|
|
51
|
+
const fromEnv = process.env['DSH_VERSION'];
|
|
52
|
+
if (typeof fromEnv === 'string' && semver.valid(fromEnv.trim()) !== null)
|
|
53
|
+
return fromEnv.trim();
|
|
54
|
+
const anchor = readManifest(join(profileDir, 'node_modules', '@deepseek-ai', 'dsh-app-boot', 'package.json'));
|
|
55
|
+
return dependencyVersionOf(anchor, '@deepseek-ai/dsh');
|
|
56
|
+
}
|
|
57
|
+
function dependencyVersionOf(manifest, name) {
|
|
58
|
+
if (manifest === undefined)
|
|
59
|
+
return undefined;
|
|
60
|
+
for (const key of ['dependencies', 'peerDependencies']) {
|
|
61
|
+
const table = manifest[key];
|
|
62
|
+
if (typeof table !== 'object' || table === null)
|
|
63
|
+
continue;
|
|
64
|
+
const range = table[name];
|
|
65
|
+
if (typeof range !== 'string' || range.trim() === '')
|
|
66
|
+
continue;
|
|
67
|
+
const exact = semver.valid(range.trim());
|
|
68
|
+
if (exact !== null)
|
|
69
|
+
return exact;
|
|
70
|
+
}
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
function readManifest(file) {
|
|
74
|
+
return readJsonObject(file);
|
|
75
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { DshHostContext } from '../api/dsh.js';
|
|
2
|
+
import type { RouteHandler } from './http.js';
|
|
3
|
+
import type { DshPluginsSnapshot } from '../contract/protocol/dsh-plugins.js';
|
|
4
|
+
export declare function readDshPlugins(ctx: DshHostContext): Promise<DshPluginsSnapshot>;
|
|
5
|
+
export declare function dshPluginsHandler(ctx: DshHostContext): RouteHandler;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { PLUGIN_MANAGER_SERVICE } from './bundle-manager.js';
|
|
2
|
+
function asRecord(value) {
|
|
3
|
+
return typeof value === 'object' && value !== null ? value : undefined;
|
|
4
|
+
}
|
|
5
|
+
function asArray(value) {
|
|
6
|
+
if (Array.isArray(value))
|
|
7
|
+
return value;
|
|
8
|
+
const record = asRecord(value);
|
|
9
|
+
if (record === undefined)
|
|
10
|
+
return [];
|
|
11
|
+
for (const key of ['rows', 'items', 'list', 'bundles', 'plugins']) {
|
|
12
|
+
const inner = record[key];
|
|
13
|
+
if (Array.isArray(inner))
|
|
14
|
+
return inner;
|
|
15
|
+
}
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
function asText(value) {
|
|
19
|
+
return typeof value === 'string' ? value : '';
|
|
20
|
+
}
|
|
21
|
+
function rowOf(value) {
|
|
22
|
+
const record = asRecord(value);
|
|
23
|
+
if (record === undefined)
|
|
24
|
+
return undefined;
|
|
25
|
+
const name = asText(record.name) || asText(record.id);
|
|
26
|
+
if (name === '')
|
|
27
|
+
return undefined;
|
|
28
|
+
return { name, version: asText(record.version), enabled: record.disabled !== true && record.enabled !== false };
|
|
29
|
+
}
|
|
30
|
+
function rowsOf(value) {
|
|
31
|
+
const rows = [];
|
|
32
|
+
for (const item of asArray(value)) {
|
|
33
|
+
const row = rowOf(item);
|
|
34
|
+
if (row !== undefined)
|
|
35
|
+
rows.push(row);
|
|
36
|
+
}
|
|
37
|
+
return rows;
|
|
38
|
+
}
|
|
39
|
+
export async function readDshPlugins(ctx) {
|
|
40
|
+
const manager = ctx.get(PLUGIN_MANAGER_SERVICE);
|
|
41
|
+
if (manager === undefined)
|
|
42
|
+
return { available: false, bundles: [], plugins: [] };
|
|
43
|
+
const [bundles, plugins] = await Promise.all([
|
|
44
|
+
manager.listBundles === undefined ? undefined : manager.listBundles(),
|
|
45
|
+
manager.listPlugins === undefined ? undefined : manager.listPlugins(),
|
|
46
|
+
]);
|
|
47
|
+
return { available: true, bundles: rowsOf(bundles), plugins: rowsOf(plugins) };
|
|
48
|
+
}
|
|
49
|
+
export function dshPluginsHandler(ctx) {
|
|
50
|
+
return () => readDshPlugins(ctx);
|
|
51
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { ShellKind } from './shell-text.js';
|
|
2
|
+
export type EnvLayer = Readonly<Record<string, string | undefined>>;
|
|
3
|
+
/**
|
|
4
|
+
* 把父进程环境里的字符串值拷成一层 env(丢掉 undefined)。
|
|
5
|
+
* @param parent 父环境(通常是 `process.env`)。
|
|
6
|
+
* @returns 可继续叠加的 env 层。
|
|
7
|
+
*/
|
|
8
|
+
export declare function inheritedEnvOf(parent: NodeJS.ProcessEnv | EnvLayer): Record<string, string>;
|
|
9
|
+
/**
|
|
10
|
+
* 在一层 env 上叠另一层;`undefined` 表示删掉这个键。
|
|
11
|
+
* @param base 底层 env。
|
|
12
|
+
* @param layer 上层 env;值为 undefined 的键被删除。
|
|
13
|
+
* @returns 叠加后的新对象。
|
|
14
|
+
*/
|
|
15
|
+
export declare function overlayEnvOf(base: EnvLayer, layer: EnvLayer | undefined): Record<string, string | undefined>;
|
|
16
|
+
/**
|
|
17
|
+
* 把 env 层收成只含字符串的 env(用于执行缝 `env` 参数)。
|
|
18
|
+
* @param layer env 层。
|
|
19
|
+
* @returns 只含字符串键值的对象。
|
|
20
|
+
*/
|
|
21
|
+
export declare function envTextOf(layer: EnvLayer): Record<string, string>;
|
|
22
|
+
/**
|
|
23
|
+
* 在 PATH 前面插一组目录(去重、空项丢掉)。
|
|
24
|
+
* @param parentPath 原来的 PATH。
|
|
25
|
+
* @param bins 要前插的目录,按顺序。
|
|
26
|
+
* @param separator 平台分隔符,默认 `path.delimiter`。
|
|
27
|
+
* @returns 新的 PATH。
|
|
28
|
+
*/
|
|
29
|
+
export declare function pathWithBinsOf(parentPath: string | undefined, bins: readonly string[], separator?: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* 产品域隔离 home 的那层 env:`HOME`(POSIX 看它)+ `USERPROFILE`(Windows 的 node `os.homedir()` 看它),
|
|
32
|
+
* Windows 盘符路径再补 `HOMEDRIVE`/`HOMEPATH`。宿主与 launcher 都从这里取,别各写一套。
|
|
33
|
+
* @param home 隔离 home 的绝对路径。
|
|
34
|
+
* @returns 只含 home 相关的 env 层。
|
|
35
|
+
*/
|
|
36
|
+
export declare function productHomeEnv(home: string): Record<string, string>;
|
|
37
|
+
export interface ProductEnvInput {
|
|
38
|
+
readonly runtimeRoot: string;
|
|
39
|
+
readonly home?: string | undefined;
|
|
40
|
+
readonly realHome?: string | undefined;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 产品域(运行时根)的受控 env:隔离 HOME、npm/pnpm 缓存都钉在运行时根,真 npmrc/gitconfig 只读指过去。
|
|
44
|
+
* @param input 运行时根、可选的 HOME 与真实用户目录。
|
|
45
|
+
* @returns 产品域 env。
|
|
46
|
+
*/
|
|
47
|
+
export declare function productEnvOf(input: ProductEnvInput): Record<string, string>;
|
|
48
|
+
export interface UnitEnvInput extends ProductEnvInput {
|
|
49
|
+
readonly unitRoot: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 模块单元的受控 env:在产品域基础上把 HOME 与 npm/pnpm 目录全钉到单元数据目录。
|
|
53
|
+
* @param input 运行时根、单元数据目录、可选的 TRUE 用户目录。
|
|
54
|
+
* @returns 单元 env。
|
|
55
|
+
*/
|
|
56
|
+
export declare function unitEnvOf(input: UnitEnvInput): Record<string, string>;
|
|
57
|
+
export interface BootstrapEnvInput {
|
|
58
|
+
readonly root: string;
|
|
59
|
+
readonly realHome: string;
|
|
60
|
+
readonly shellKind: ShellKind;
|
|
61
|
+
readonly parent?: NodeJS.ProcessEnv | EnvLayer | undefined;
|
|
62
|
+
readonly path?: string | undefined;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 自举/装工具链的受控 env:继承父环境,HOME 与 npm 缓存钉到运行时根,PATH 可换成桌面自带 bin。
|
|
66
|
+
* @param input 运行时根、真实用户目录、shell 种类、父环境与可选的 PATH。
|
|
67
|
+
* @returns 自举 env。
|
|
68
|
+
*/
|
|
69
|
+
export declare function bootstrapEnvOf(input: BootstrapEnvInput): Record<string, string>;
|
|
70
|
+
/**
|
|
71
|
+
* git 的非交互 env:关掉终端提示/askpass;Windows 上不给 askpass 指 POSIX 路径(那台机器上没有)。
|
|
72
|
+
* @param platform 宿主平台。
|
|
73
|
+
* @returns git 非交互 env。
|
|
74
|
+
*/
|
|
75
|
+
export declare function promptlessGitEnvOf(platform: NodeJS.Platform): Record<string, string>;
|
|
76
|
+
/**
|
|
77
|
+
* 在父环境上叠加 `promptlessGitEnvOf`,得到可传给执行缝的 git env。
|
|
78
|
+
* @param parent 父环境。
|
|
79
|
+
* @param platform 宿主平台。
|
|
80
|
+
* @returns 只含字符串的 env。
|
|
81
|
+
*/
|
|
82
|
+
export declare function promptlessProcessEnvOf(parent: NodeJS.ProcessEnv, platform: NodeJS.Platform): Record<string, string>;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { delimiter, join, win32 } from 'node:path';
|
|
4
|
+
import { dshHome } from './data-root.js';
|
|
5
|
+
/**
|
|
6
|
+
* 把父进程环境里的字符串值拷成一层 env(丢掉 undefined)。
|
|
7
|
+
* @param parent 父环境(通常是 `process.env`)。
|
|
8
|
+
* @returns 可继续叠加的 env 层。
|
|
9
|
+
*/
|
|
10
|
+
export function inheritedEnvOf(parent) {
|
|
11
|
+
const out = {};
|
|
12
|
+
for (const [key, value] of Object.entries(parent)) {
|
|
13
|
+
if (typeof value === 'string')
|
|
14
|
+
out[key] = value;
|
|
15
|
+
}
|
|
16
|
+
return out;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 在一层 env 上叠另一层;`undefined` 表示删掉这个键。
|
|
20
|
+
* @param base 底层 env。
|
|
21
|
+
* @param layer 上层 env;值为 undefined 的键被删除。
|
|
22
|
+
* @returns 叠加后的新对象。
|
|
23
|
+
*/
|
|
24
|
+
export function overlayEnvOf(base, layer) {
|
|
25
|
+
const merged = { ...base };
|
|
26
|
+
for (const [key, value] of Object.entries(layer ?? {})) {
|
|
27
|
+
if (value === undefined)
|
|
28
|
+
delete merged[key];
|
|
29
|
+
else
|
|
30
|
+
merged[key] = value;
|
|
31
|
+
}
|
|
32
|
+
return merged;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 把 env 层收成只含字符串的 env(用于执行缝 `env` 参数)。
|
|
36
|
+
* @param layer env 层。
|
|
37
|
+
* @returns 只含字符串键值的对象。
|
|
38
|
+
*/
|
|
39
|
+
export function envTextOf(layer) {
|
|
40
|
+
const out = {};
|
|
41
|
+
for (const [key, value] of Object.entries(layer)) {
|
|
42
|
+
if (value !== undefined)
|
|
43
|
+
out[key] = value;
|
|
44
|
+
}
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 在 PATH 前面插一组目录(去重、空项丢掉)。
|
|
49
|
+
* @param parentPath 原来的 PATH。
|
|
50
|
+
* @param bins 要前插的目录,按顺序。
|
|
51
|
+
* @param separator 平台分隔符,默认 `path.delimiter`。
|
|
52
|
+
* @returns 新的 PATH。
|
|
53
|
+
*/
|
|
54
|
+
export function pathWithBinsOf(parentPath, bins, separator = delimiter) {
|
|
55
|
+
const parts = (parentPath ?? '').split(separator).filter((part) => part !== '' && !bins.includes(part));
|
|
56
|
+
return [...bins, ...parts].join(separator);
|
|
57
|
+
}
|
|
58
|
+
function existingPointer(realHome, name) {
|
|
59
|
+
const file = join(realHome, name);
|
|
60
|
+
return existsSync(file) ? file : undefined;
|
|
61
|
+
}
|
|
62
|
+
function homeEnvOf(home) {
|
|
63
|
+
if (!/^[A-Za-z]:[\\/]/.test(home))
|
|
64
|
+
return { USERPROFILE: home };
|
|
65
|
+
const root = win32.parse(home).root;
|
|
66
|
+
return {
|
|
67
|
+
USERPROFILE: home,
|
|
68
|
+
HOMEDRIVE: root.replace(/[\\/]+$/, ''),
|
|
69
|
+
HOMEPATH: `\\${home.slice(root.length)}`,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 产品域隔离 home 的那层 env:`HOME`(POSIX 看它)+ `USERPROFILE`(Windows 的 node `os.homedir()` 看它),
|
|
74
|
+
* Windows 盘符路径再补 `HOMEDRIVE`/`HOMEPATH`。宿主与 launcher 都从这里取,别各写一套。
|
|
75
|
+
* @param home 隔离 home 的绝对路径。
|
|
76
|
+
* @returns 只含 home 相关的 env 层。
|
|
77
|
+
*/
|
|
78
|
+
export function productHomeEnv(home) {
|
|
79
|
+
return { ...homeEnvOf(home), HOME: home };
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* 产品域(运行时根)的受控 env:隔离 HOME、npm/pnpm 缓存都钉在运行时根,真 npmrc/gitconfig 只读指过去。
|
|
83
|
+
* @param input 运行时根、可选的 HOME 与真实用户目录。
|
|
84
|
+
* @returns 产品域 env。
|
|
85
|
+
*/
|
|
86
|
+
export function productEnvOf(input) {
|
|
87
|
+
const runtimeRoot = input.runtimeRoot;
|
|
88
|
+
const realHome = input.realHome ?? homedir();
|
|
89
|
+
const home = input.home ?? join(runtimeRoot, 'home');
|
|
90
|
+
const env = {
|
|
91
|
+
...productHomeEnv(home),
|
|
92
|
+
DSH_HOME: dshHome(),
|
|
93
|
+
DSH_WORKBENCH_HOME: runtimeRoot,
|
|
94
|
+
npm_config_cache: join(runtimeRoot, 'npm-cache'),
|
|
95
|
+
NPM_CONFIG_CACHE: join(runtimeRoot, 'npm-cache'),
|
|
96
|
+
npm_config_logs_dir: join(runtimeRoot, 'npm-logs'),
|
|
97
|
+
npm_config_store_dir: join(runtimeRoot, 'pnpm-store'),
|
|
98
|
+
npm_config_cache_dir: join(runtimeRoot, 'pnpm-cache'),
|
|
99
|
+
npm_config_state_dir: join(runtimeRoot, 'pnpm-state'),
|
|
100
|
+
npm_config_update_notifier: 'false',
|
|
101
|
+
npm_config_fund: 'false',
|
|
102
|
+
NO_UPDATE_NOTIFIER: '1',
|
|
103
|
+
};
|
|
104
|
+
const npmrc = existingPointer(realHome, '.npmrc');
|
|
105
|
+
if (npmrc !== undefined)
|
|
106
|
+
env['NPM_CONFIG_USERCONFIG'] = npmrc;
|
|
107
|
+
const gitconfig = existingPointer(realHome, '.gitconfig');
|
|
108
|
+
if (gitconfig !== undefined)
|
|
109
|
+
env['GIT_CONFIG_GLOBAL'] = gitconfig;
|
|
110
|
+
return env;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* 模块单元的受控 env:在产品域基础上把 HOME 与 npm/pnpm 目录全钉到单元数据目录。
|
|
114
|
+
* @param input 运行时根、单元数据目录、可选的 TRUE 用户目录。
|
|
115
|
+
* @returns 单元 env。
|
|
116
|
+
*/
|
|
117
|
+
export function unitEnvOf(input) {
|
|
118
|
+
const unitRoot = input.unitRoot;
|
|
119
|
+
return {
|
|
120
|
+
...productEnvOf({ ...input, home: join(unitRoot, 'home') }),
|
|
121
|
+
npm_config_cache: join(unitRoot, 'npm-cache'),
|
|
122
|
+
NPM_CONFIG_CACHE: join(unitRoot, 'npm-cache'),
|
|
123
|
+
npm_config_logs_dir: join(unitRoot, 'npm-logs'),
|
|
124
|
+
npm_config_store_dir: join(unitRoot, 'pnpm-store'),
|
|
125
|
+
npm_config_cache_dir: join(unitRoot, 'pnpm-cache'),
|
|
126
|
+
npm_config_state_dir: join(unitRoot, 'pnpm-state'),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* 自举/装工具链的受控 env:继承父环境,HOME 与 npm 缓存钉到运行时根,PATH 可换成桌面自带 bin。
|
|
131
|
+
* @param input 运行时根、真实用户目录、shell 种类、父环境与可选的 PATH。
|
|
132
|
+
* @returns 自举 env。
|
|
133
|
+
*/
|
|
134
|
+
export function bootstrapEnvOf(input) {
|
|
135
|
+
const env = inheritedEnvOf(input.parent ?? process.env);
|
|
136
|
+
if (input.path !== undefined)
|
|
137
|
+
env['PATH'] = input.path;
|
|
138
|
+
const home = join(input.root, 'home');
|
|
139
|
+
env['HOME'] = home;
|
|
140
|
+
if (input.shellKind === 'pwsh')
|
|
141
|
+
Object.assign(env, homeEnvOf(home));
|
|
142
|
+
const userConfig = existingPointer(input.realHome, '.npmrc');
|
|
143
|
+
if (userConfig !== undefined)
|
|
144
|
+
env['NPM_CONFIG_USERCONFIG'] = userConfig;
|
|
145
|
+
const cache = join(input.root, 'npm-cache');
|
|
146
|
+
env['npm_config_cache'] = cache;
|
|
147
|
+
env['NPM_CONFIG_CACHE'] = cache;
|
|
148
|
+
env['NO_COLOR'] = '1';
|
|
149
|
+
env['TERM'] = 'dumb';
|
|
150
|
+
return env;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* git 的非交互 env:关掉终端提示/askpass;Windows 上不给 askpass 指 POSIX 路径(那台机器上没有)。
|
|
154
|
+
* @param platform 宿主平台。
|
|
155
|
+
* @returns git 非交互 env。
|
|
156
|
+
*/
|
|
157
|
+
export function promptlessGitEnvOf(platform) {
|
|
158
|
+
const shared = {
|
|
159
|
+
GIT_TERMINAL_PROMPT: '0',
|
|
160
|
+
SSH_ASKPASS_REQUIRE: 'never',
|
|
161
|
+
GCM_INTERACTIVE: 'never',
|
|
162
|
+
GIT_SSH_COMMAND: 'ssh -o BatchMode=yes -o StrictHostKeyChecking=accept-new',
|
|
163
|
+
};
|
|
164
|
+
if (platform === 'win32')
|
|
165
|
+
return shared;
|
|
166
|
+
return { ...shared, GIT_ASKPASS: '/usr/bin/false', SSH_ASKPASS: '/usr/bin/false' };
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* 在父环境上叠加 `promptlessGitEnvOf`,得到可传给执行缝的 git env。
|
|
170
|
+
* @param parent 父环境。
|
|
171
|
+
* @param platform 宿主平台。
|
|
172
|
+
* @returns 只含字符串的 env。
|
|
173
|
+
*/
|
|
174
|
+
export function promptlessProcessEnvOf(parent, platform) {
|
|
175
|
+
const env = { ...inheritedEnvOf(parent), ...promptlessGitEnvOf(platform) };
|
|
176
|
+
if (platform === 'win32') {
|
|
177
|
+
delete env['GIT_ASKPASS'];
|
|
178
|
+
delete env['SSH_ASKPASS'];
|
|
179
|
+
}
|
|
180
|
+
return env;
|
|
181
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DataReader } from '../contract/data.js';
|
|
2
|
+
import type { ExtensionCaller } from '../contract/extension.js';
|
|
3
|
+
import type { ExtensionNeed } from '../contract/needs.js';
|
|
4
|
+
export interface ExtensionCallerOptions {
|
|
5
|
+
readonly suiteId?: string | undefined;
|
|
6
|
+
}
|
|
7
|
+
export declare function extensionCallerOf(data: DataReader, need: ExtensionNeed, callerOptions?: ExtensionCallerOptions): ExtensionCaller;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { now } from './time.js';
|
|
2
|
+
import { WorkbenchDataError } from './data-error.js';
|
|
3
|
+
function cliCodeOf(code) {
|
|
4
|
+
if (code === 'auth')
|
|
5
|
+
return 'auth-required';
|
|
6
|
+
if (code === 'timeout')
|
|
7
|
+
return 'cli-timeout';
|
|
8
|
+
if (code === 'parse')
|
|
9
|
+
return 'cli-bad-output';
|
|
10
|
+
return 'cli-exec-failed';
|
|
11
|
+
}
|
|
12
|
+
export function extensionCallerOf(data, need, callerOptions = {}) {
|
|
13
|
+
return {
|
|
14
|
+
async json(args, options = {}) {
|
|
15
|
+
const result = await data.read({
|
|
16
|
+
kind: 'command',
|
|
17
|
+
adapter: need.runtime,
|
|
18
|
+
argv: [need.name, ...args],
|
|
19
|
+
...(options.timeoutMs === undefined ? {} : { timeoutMs: options.timeoutMs }),
|
|
20
|
+
});
|
|
21
|
+
if (result.ok)
|
|
22
|
+
return { value: result.data, at: now() };
|
|
23
|
+
const code = result.error.pageCode ?? cliCodeOf(result.error.code);
|
|
24
|
+
const command = [need.name, ...args].join(' ');
|
|
25
|
+
const advice = code === 'cli-unclassified'
|
|
26
|
+
? `这条命令(${command})在这份 ${need.name} 插件里可能不存在(插件版本旧就会缺):用 workbench_modules_update(id=${callerOptions.suiteId ?? need.name})升级,或在面板的模块状态里点更新,再重试。终端确认:${need.name} ${args[0] ?? ''} --help`
|
|
27
|
+
: undefined;
|
|
28
|
+
const hint = advice === undefined
|
|
29
|
+
? result.error.hint
|
|
30
|
+
: result.error.hint === undefined
|
|
31
|
+
? advice
|
|
32
|
+
: `${advice}\n${result.error.hint}`;
|
|
33
|
+
throw new WorkbenchDataError(code, advice === undefined ? result.error.message : `${result.error.message}。${advice}`, {
|
|
34
|
+
...(result.error.detail === undefined ? {} : { detail: result.error.detail }),
|
|
35
|
+
...(hint === undefined ? {} : { hint }),
|
|
36
|
+
...(result.error.helpUrl === undefined ? {} : { helpUrl: result.error.helpUrl }),
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { UnitManifest } from '../contract/unit.js';
|
|
2
|
+
export interface FactChange {
|
|
3
|
+
readonly rev: number;
|
|
4
|
+
readonly facts: readonly string[];
|
|
5
|
+
}
|
|
6
|
+
export interface FactSnapshot extends FactChange {
|
|
7
|
+
readonly epoch: string;
|
|
8
|
+
}
|
|
9
|
+
export interface FactLog {
|
|
10
|
+
bump(facts: readonly string[]): FactChange;
|
|
11
|
+
revision(): number;
|
|
12
|
+
epoch(): string;
|
|
13
|
+
since(rev: number): FactSnapshot;
|
|
14
|
+
subscribe(listener: (change: FactChange) => void): () => void;
|
|
15
|
+
}
|
|
16
|
+
export declare function createFactLog(options?: {
|
|
17
|
+
readonly epoch?: string;
|
|
18
|
+
}): FactLog;
|
|
19
|
+
export interface ToolUnit {
|
|
20
|
+
readonly unit: string;
|
|
21
|
+
readonly writes: boolean;
|
|
22
|
+
readonly elevates?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare function toolUnits(manifests: readonly UnitManifest[]): Map<string, ToolUnit>;
|
|
25
|
+
export declare function wroteNow(result: unknown): boolean | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* 由单元 id 拼出它那一族事实的范围名。
|
|
28
|
+
* @param unit 单元 id,不带后缀。
|
|
29
|
+
* @returns <unit>* —— 永远是范围名,不是某一条事实。
|
|
30
|
+
*/
|
|
31
|
+
export declare function unitFactScope(unit: string): string;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { FACT_SCOPE_SUFFIX } from '../contract/facts.js';
|
|
3
|
+
export function createFactLog(options = {}) {
|
|
4
|
+
const epoch = options.epoch ?? `e${randomUUID()}`;
|
|
5
|
+
let rev = 0;
|
|
6
|
+
const last = new Map();
|
|
7
|
+
const listeners = new Set();
|
|
8
|
+
return {
|
|
9
|
+
epoch: () => epoch,
|
|
10
|
+
revision: () => rev,
|
|
11
|
+
bump(facts) {
|
|
12
|
+
rev += 1;
|
|
13
|
+
const named = [...new Set(facts.filter((name) => name !== ''))];
|
|
14
|
+
for (const name of named)
|
|
15
|
+
last.set(name, rev);
|
|
16
|
+
const change = { rev, facts: named };
|
|
17
|
+
for (const listener of [...listeners])
|
|
18
|
+
listener(change);
|
|
19
|
+
return change;
|
|
20
|
+
},
|
|
21
|
+
since(seen) {
|
|
22
|
+
const facts = [...last.entries()].filter(([, at]) => at > seen).map(([name]) => name);
|
|
23
|
+
return { epoch, rev, facts };
|
|
24
|
+
},
|
|
25
|
+
subscribe(listener) {
|
|
26
|
+
listeners.add(listener);
|
|
27
|
+
return () => {
|
|
28
|
+
listeners.delete(listener);
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function toolUnits(manifests) {
|
|
34
|
+
const map = new Map();
|
|
35
|
+
for (const manifest of manifests) {
|
|
36
|
+
for (const tool of manifest.tools ?? []) {
|
|
37
|
+
map.set(tool.name, {
|
|
38
|
+
unit: manifest.id,
|
|
39
|
+
writes: tool.writes,
|
|
40
|
+
...(tool.elevates === true ? { elevates: true } : {}),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return map;
|
|
45
|
+
}
|
|
46
|
+
export function wroteNow(result) {
|
|
47
|
+
const value = result?.value;
|
|
48
|
+
const wrote = value?.wrote;
|
|
49
|
+
return typeof wrote === 'boolean' ? wrote : undefined;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 由单元 id 拼出它那一族事实的范围名。
|
|
53
|
+
* @param unit 单元 id,不带后缀。
|
|
54
|
+
* @returns <unit>* —— 永远是范围名,不是某一条事实。
|
|
55
|
+
*/
|
|
56
|
+
export function unitFactScope(unit) {
|
|
57
|
+
return `${unit}${FACT_SCOPE_SUFFIX}`;
|
|
58
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { ShellKind } from './shell-text.js';
|
|
2
|
+
export type WriteMode = number | 'keep';
|
|
3
|
+
export interface WriteFileOptions {
|
|
4
|
+
readonly atomic?: boolean | undefined;
|
|
5
|
+
readonly mkdir?: boolean | undefined;
|
|
6
|
+
readonly fsync?: boolean | undefined;
|
|
7
|
+
readonly mode?: WriteMode | undefined;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* 把文本写进文件;默认原子写(temp + rename)、目录不存在就建、已有文件保留原权限。
|
|
11
|
+
* @param path 目标文件;父目录按 `mkdir` 决定是否创建。
|
|
12
|
+
* @param text 文本内容。
|
|
13
|
+
* @param options 原子/目录/权限/fsync;`mode` 默认 `'keep'`(新文件 0644)。
|
|
14
|
+
*/
|
|
15
|
+
export declare function writeTextFile(path: string, text: string, options?: WriteFileOptions): void;
|
|
16
|
+
/**
|
|
17
|
+
* 只在文件不存在时创建,已存在返回 `false`(不覆盖)。
|
|
18
|
+
* @param path 目标文件。
|
|
19
|
+
* @param text 文本内容。
|
|
20
|
+
* @param options 目录/权限;不参与原子写。
|
|
21
|
+
* @returns 真的创建了为 `true`。
|
|
22
|
+
*/
|
|
23
|
+
export declare function writeTextFileExclusive(path: string, text: string, options?: WriteFileOptions): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* 往文件末尾追加文本;文件或目录不存在就建。追加不是原子写,只给「日志/采集」这类只增不改的流。
|
|
26
|
+
* @param path 目标文件。
|
|
27
|
+
* @param text 追加内容。
|
|
28
|
+
*/
|
|
29
|
+
export declare function appendTextFile(path: string, text: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* `writeTextFile` 的异步版;语义与默认值相同。
|
|
32
|
+
* @param path 目标文件。
|
|
33
|
+
* @param text 文本内容。
|
|
34
|
+
* @param options 原子/目录/权限/fsync。
|
|
35
|
+
* @returns 落盘完成。
|
|
36
|
+
*/
|
|
37
|
+
export declare function writeTextFileAsync(path: string, text: string, options?: WriteFileOptions): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* 把二进制写进文件;语义与默认值同 `writeTextFile`。
|
|
40
|
+
* @param path 目标文件。
|
|
41
|
+
* @param bytes 二进制内容。
|
|
42
|
+
* @param options 原子/目录/权限/fsync。
|
|
43
|
+
*/
|
|
44
|
+
export declare function writeBytesFile(path: string, bytes: Uint8Array, options?: WriteFileOptions): void;
|
|
45
|
+
/**
|
|
46
|
+
* `writeBytesFile` 的异步版;语义与默认值相同。
|
|
47
|
+
* @param path 目标文件。
|
|
48
|
+
* @param bytes 二进制内容。
|
|
49
|
+
* @param options 原子/目录/权限/fsync。
|
|
50
|
+
* @returns 落盘完成。
|
|
51
|
+
*/
|
|
52
|
+
export declare function writeBytesFileAsync(path: string, bytes: Uint8Array, options?: WriteFileOptions): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* 把 JSON 写进文件:`JSON.stringify(value, null, 2)` 加末尾换行;语义与默认值同 `writeTextFile`。
|
|
55
|
+
* @param path 目标文件。
|
|
56
|
+
* @param value 可序列化的值。
|
|
57
|
+
* @param options 原子/目录/权限/fsync。
|
|
58
|
+
*/
|
|
59
|
+
export declare function writeJsonFile(path: string, value: unknown, options?: WriteFileOptions): void;
|
|
60
|
+
/**
|
|
61
|
+
* `writeJsonFile` 的异步版;语义与默认值相同。
|
|
62
|
+
* @param path 目标文件。
|
|
63
|
+
* @param value 可序列化的值。
|
|
64
|
+
* @param options 原子/目录/权限/fsync。
|
|
65
|
+
* @returns 落盘完成。
|
|
66
|
+
*/
|
|
67
|
+
export declare function writeJsonFileAsync(path: string, value: unknown, options?: WriteFileOptions): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* 确保目录存在(`mkdir -p`)。
|
|
70
|
+
* @param dir 目录路径。
|
|
71
|
+
*/
|
|
72
|
+
export declare function ensureDir(dir: string): void;
|
|
73
|
+
/**
|
|
74
|
+
* 把已存在的文件设成可执行(0755)。
|
|
75
|
+
* @param path 文件路径。
|
|
76
|
+
*/
|
|
77
|
+
export declare function makeExecutable(path: string): void;
|
|
78
|
+
/**
|
|
79
|
+
* 删掉一个路径(目录整棵删),不存在当成功。
|
|
80
|
+
* @param path 目标路径。
|
|
81
|
+
*/
|
|
82
|
+
export declare function removePath(path: string): void;
|
|
83
|
+
/**
|
|
84
|
+
* 把 `from` 目录里的内容倒进 `to` 目录(等价 `cp -R from/. to/`):`to` 先清空再建。
|
|
85
|
+
* @param from 源目录。
|
|
86
|
+
* @param to 目标目录。
|
|
87
|
+
*/
|
|
88
|
+
export declare function copyDirInto(from: string, to: string): void;
|
|
89
|
+
export declare function moveDir(source: string, target: string): void;
|
|
90
|
+
/**
|
|
91
|
+
* 建一条指向目录的链接:POSIX 是符号链接,Windows 是 junction(不需要开发者模式或管理员)。
|
|
92
|
+
* @param target 被指向的目录。
|
|
93
|
+
* @param path 链接落在哪。
|
|
94
|
+
* @param kind 目标 shell 种类,默认当前平台。
|
|
95
|
+
*/
|
|
96
|
+
export declare function linkDir(target: string, path: string, kind?: ShellKind): void;
|