@dsh-workbench/shared 1.5.2-alpha.0 → 1.5.2-alpha.2
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/contract/protocol/bundle-install.d.ts +7 -1
- package/dist/contract/protocol/bundle-install.js +1 -0
- package/dist/host/runtime/dsh-compat.js +20 -6
- package/dist/i18n/en.js +2 -0
- package/dist/i18n/index.d.ts +3 -1
- package/dist/i18n/zh.d.ts +2 -0
- package/dist/i18n/zh.js +2 -0
- package/dist/lib/dsh-client.d.ts +1 -1
- package/package.json +47 -51
- package/src/contract/protocol/bundle-install.ts +9 -1
- package/src/host/runtime/__tests__/dsh-compat.test.ts +23 -0
- package/src/host/runtime/dsh-compat.ts +18 -5
- package/src/i18n/en.ts +2 -0
- package/src/i18n/zh.ts +2 -0
- package/src/lib/dsh-client.ts +1 -2
- package/dist/components/Activity.css +0 -69
- package/dist/components/Activity.d.ts +0 -56
- package/dist/components/Activity.js +0 -47
- package/dist/components/ApprovalDetail.css +0 -3
- package/dist/components/ApprovalDetail.d.ts +0 -42
- package/dist/components/ApprovalDetail.js +0 -53
- package/dist/components/ApprovalPlan.css +0 -39
- package/dist/components/ApprovalPlan.d.ts +0 -27
- package/dist/components/ApprovalPlan.js +0 -19
- package/dist/components/Card.css +0 -19
- package/dist/components/Card.d.ts +0 -26
- package/dist/components/Card.js +0 -18
- package/dist/components/CardAnchor.d.ts +0 -21
- package/dist/components/CardAnchor.js +0 -19
- package/dist/components/CardAnchor.module.css +0 -3
- package/dist/components/CardBoundary.d.ts +0 -42
- package/dist/components/CardBoundary.js +0 -58
- package/dist/components/CardBoundary.module.css +0 -5
- package/dist/components/CardHead.css +0 -87
- package/dist/components/CardHead.d.ts +0 -30
- package/dist/components/CardHead.js +0 -27
- package/dist/components/ChoiceGroup.css +0 -182
- package/dist/components/ChoiceGroup.d.ts +0 -54
- package/dist/components/ChoiceGroup.js +0 -63
- package/dist/components/ConfirmBar.css +0 -26
- package/dist/components/ConfirmBar.d.ts +0 -36
- package/dist/components/ConfirmBar.js +0 -26
- package/dist/components/EmptyIllustration.d.ts +0 -12
- package/dist/components/EmptyIllustration.js +0 -32
- package/dist/components/Field.css +0 -20
- package/dist/components/Field.d.ts +0 -18
- package/dist/components/Field.js +0 -15
- package/dist/components/Form.css +0 -6
- package/dist/components/Form.d.ts +0 -22
- package/dist/components/Form.js +0 -60
- package/dist/components/FormActions.css +0 -13
- package/dist/components/FormActions.d.ts +0 -29
- package/dist/components/FormActions.js +0 -43
- package/dist/components/FormNodes.d.ts +0 -107
- package/dist/components/FormNodes.js +0 -165
- package/dist/components/FormRows.css +0 -107
- package/dist/components/FormRows.d.ts +0 -36
- package/dist/components/FormRows.js +0 -26
- package/dist/components/FormTypes.d.ts +0 -84
- package/dist/components/FormTypes.js +0 -1
- package/dist/components/Link.css +0 -22
- package/dist/components/Link.d.ts +0 -22
- package/dist/components/Link.js +0 -17
- package/dist/components/LongTaskRow.css +0 -171
- package/dist/components/LongTaskRow.d.ts +0 -94
- package/dist/components/LongTaskRow.js +0 -103
- package/dist/components/Note.css +0 -13
- package/dist/components/Note.d.ts +0 -20
- package/dist/components/Note.js +0 -14
- package/dist/components/ResourceStates.css +0 -114
- package/dist/components/ResourceStates.d.ts +0 -44
- package/dist/components/ResourceStates.js +0 -41
- package/dist/components/Rows.css +0 -42
- package/dist/components/Rows.d.ts +0 -28
- package/dist/components/Rows.js +0 -21
- package/dist/components/SaveBar.d.ts +0 -24
- package/dist/components/SaveBar.js +0 -25
- package/dist/components/SelectField.css +0 -182
- package/dist/components/SelectField.d.ts +0 -89
- package/dist/components/SelectField.js +0 -260
- package/dist/components/SelectFieldNodes.d.ts +0 -49
- package/dist/components/SelectFieldNodes.js +0 -43
- package/dist/components/SettingsSection.css +0 -25
- package/dist/components/SettingsSection.d.ts +0 -20
- package/dist/components/SettingsSection.js +0 -17
- package/dist/components/SetupShell.d.ts +0 -93
- package/dist/components/SetupShell.js +0 -64
- package/dist/components/SetupShell.module.css +0 -81
- package/dist/components/Spinner.css +0 -5
- package/dist/components/Spinner.d.ts +0 -15
- package/dist/components/Spinner.js +0 -13
- package/dist/components/Stack.css +0 -6
- package/dist/components/Stack.d.ts +0 -14
- package/dist/components/Stack.js +0 -10
- package/dist/components/StateBlock.css +0 -38
- package/dist/components/StateBlock.d.ts +0 -24
- package/dist/components/StateBlock.js +0 -22
- package/dist/components/TextField.css +0 -32
- package/dist/components/TextField.d.ts +0 -14
- package/dist/components/TextField.js +0 -10
- package/dist/components/board-module.d.ts +0 -307
- package/dist/components/board-module.js +0 -1
- package/dist/components/card-view-validate.d.ts +0 -5
- package/dist/components/card-view-validate.js +0 -256
- package/dist/components/icons.d.ts +0 -63
- package/dist/components/icons.js +0 -107
- package/dist/components/layout/icon-command.d.ts +0 -8
- package/dist/components/layout/icon-command.js +0 -21
- package/dist/contract/capture.d.ts +0 -16
- package/dist/contract/capture.js +0 -1
- package/dist/contract/diagnostics.d.ts +0 -34
- package/dist/contract/diagnostics.js +0 -124
- package/dist/contract/protocol/unit-manager.d.ts +0 -50
- package/dist/contract/protocol/unit-manager.js +0 -2
- package/dist/host/adapter-contract.d.ts +0 -3
- package/dist/host/adapter-contract.js +0 -95
- package/dist/host/adapter-set.d.ts +0 -27
- package/dist/host/adapter-set.js +0 -258
- package/dist/host/adapter-types.d.ts +0 -87
- package/dist/host/adapter-types.js +0 -23
- package/dist/host/adapters/platform.d.ts +0 -14
- package/dist/host/adapters/platform.js +0 -40
- package/dist/host/adapters.d.ts +0 -28
- package/dist/host/adapters.js +0 -9
- package/dist/host/auth-loss.d.ts +0 -33
- package/dist/host/auth-loss.js +0 -107
- package/dist/host/board-fact.d.ts +0 -8
- package/dist/host/board-fact.js +0 -16
- package/dist/host/boot-record.d.ts +0 -11
- package/dist/host/boot-record.js +0 -31
- package/dist/host/browser.d.ts +0 -3
- package/dist/host/browser.js +0 -3
- package/dist/host/bundle-manager.d.ts +0 -4
- package/dist/host/bundle-manager.js +0 -338
- package/dist/host/changelog.d.ts +0 -28
- package/dist/host/changelog.js +0 -201
- package/dist/host/cli-error.d.ts +0 -8
- package/dist/host/cli-error.js +0 -70
- package/dist/host/cli.d.ts +0 -4
- package/dist/host/cli.js +0 -9
- package/dist/host/config-sync.d.ts +0 -40
- package/dist/host/config-sync.js +0 -267
- package/dist/host/context-ref.d.ts +0 -13
- package/dist/host/context-ref.js +0 -41
- package/dist/host/data-error.d.ts +0 -15
- package/dist/host/data-error.js +0 -23
- package/dist/host/data-plan-check.d.ts +0 -10
- package/dist/host/data-plan-check.js +0 -315
- package/dist/host/data-plan.d.ts +0 -15
- package/dist/host/data-plan.js +0 -283
- package/dist/host/data-root.d.ts +0 -5
- package/dist/host/data-root.js +0 -23
- package/dist/host/diy-debug.d.ts +0 -80
- package/dist/host/diy-debug.js +0 -89
- package/dist/host/diy-preset.d.ts +0 -26
- package/dist/host/diy-preset.js +0 -115
- package/dist/host/diy-record.d.ts +0 -135
- package/dist/host/diy-record.js +0 -163
- package/dist/host/dsh-compat.d.ts +0 -27
- package/dist/host/dsh-compat.js +0 -75
- package/dist/host/dsh-plugins.d.ts +0 -5
- package/dist/host/dsh-plugins.js +0 -51
- package/dist/host/env-policy.d.ts +0 -82
- package/dist/host/env-policy.js +0 -181
- package/dist/host/extension.d.ts +0 -7
- package/dist/host/extension.js +0 -40
- package/dist/host/facts.d.ts +0 -31
- package/dist/host/facts.js +0 -58
- package/dist/host/fs-write.d.ts +0 -96
- package/dist/host/fs-write.js +0 -183
- package/dist/host/git.d.ts +0 -5
- package/dist/host/git.js +0 -1
- package/dist/host/host-actions.d.ts +0 -2
- package/dist/host/host-actions.js +0 -5
- package/dist/host/host-kit.d.ts +0 -37
- package/dist/host/host-kit.js +0 -27
- package/dist/host/http.d.ts +0 -47
- package/dist/host/http.js +0 -289
- package/dist/host/install-failure.d.ts +0 -50
- package/dist/host/install-failure.js +0 -184
- package/dist/host/installed-module.d.ts +0 -25
- package/dist/host/installed-module.js +0 -289
- package/dist/host/installed-sources.d.ts +0 -10
- package/dist/host/installed-sources.js +0 -63
- package/dist/host/lease.d.ts +0 -70
- package/dist/host/lease.js +0 -264
- package/dist/host/lib-capabilities.d.ts +0 -22
- package/dist/host/lib-capabilities.js +0 -37
- package/dist/host/lib-install.d.ts +0 -19
- package/dist/host/lib-install.js +0 -40
- package/dist/host/lib-runners.d.ts +0 -18
- package/dist/host/lib-runners.js +0 -46
- package/dist/host/local-declaration.d.ts +0 -7
- package/dist/host/local-declaration.js +0 -33
- package/dist/host/long-task.d.ts +0 -97
- package/dist/host/long-task.js +0 -297
- package/dist/host/market-index-claim.d.ts +0 -19
- package/dist/host/market-index-claim.js +0 -87
- package/dist/host/market-index-doc.d.ts +0 -12
- package/dist/host/market-index-doc.js +0 -1
- package/dist/host/market-index-parse.d.ts +0 -28
- package/dist/host/market-index-parse.js +0 -413
- package/dist/host/market-index.d.ts +0 -13
- package/dist/host/market-index.js +0 -105
- package/dist/host/module-root.d.ts +0 -1
- package/dist/host/module-root.js +0 -5
- package/dist/host/needs.d.ts +0 -4
- package/dist/host/needs.js +0 -2
- package/dist/host/npm-registry.d.ts +0 -10
- package/dist/host/npm-registry.js +0 -16
- package/dist/host/package-content.d.ts +0 -8
- package/dist/host/package-content.js +0 -90
- package/dist/host/package-kind.d.ts +0 -13
- package/dist/host/package-kind.js +0 -51
- package/dist/host/package-route.d.ts +0 -33
- package/dist/host/package-route.js +0 -68
- package/dist/host/panel-state.d.ts +0 -120
- package/dist/host/panel-state.js +0 -177
- package/dist/host/patch-blocks.d.ts +0 -13
- package/dist/host/patch-blocks.js +0 -52
- package/dist/host/patch.d.ts +0 -4
- package/dist/host/patch.js +0 -7
- package/dist/host/paths.d.ts +0 -12
- package/dist/host/paths.js +0 -20
- package/dist/host/payload.d.ts +0 -12
- package/dist/host/payload.js +0 -16
- package/dist/host/plan-results.d.ts +0 -5
- package/dist/host/plan-results.js +0 -71
- package/dist/host/plan-run.d.ts +0 -41
- package/dist/host/plan-run.js +0 -87
- package/dist/host/platform.d.ts +0 -14
- package/dist/host/platform.js +0 -40
- package/dist/host/plugin-ledger.d.ts +0 -32
- package/dist/host/plugin-ledger.js +0 -106
- package/dist/host/plugin.d.ts +0 -3
- package/dist/host/plugin.js +0 -38
- package/dist/host/port-types.d.ts +0 -233
- package/dist/host/port-types.js +0 -1
- package/dist/host/preflight.d.ts +0 -32
- package/dist/host/preflight.js +0 -1
- package/dist/host/process-alive.d.ts +0 -6
- package/dist/host/process-alive.js +0 -16
- package/dist/host/profile-bundles.d.ts +0 -20
- package/dist/host/profile-bundles.js +0 -48
- package/dist/host/profile-create.d.ts +0 -19
- package/dist/host/profile-create.js +0 -124
- package/dist/host/profile-port.d.ts +0 -4
- package/dist/host/profile-port.js +0 -4
- package/dist/host/profile-registries.d.ts +0 -10
- package/dist/host/profile-registries.js +0 -149
- package/dist/host/provision.d.ts +0 -32
- package/dist/host/provision.js +0 -105
- package/dist/host/read-json.d.ts +0 -1
- package/dist/host/read-json.js +0 -11
- package/dist/host/recipe-rules.d.ts +0 -5
- package/dist/host/recipe-rules.js +0 -412
- package/dist/host/recipe.d.ts +0 -14
- package/dist/host/recipe.js +0 -332
- package/dist/host/registry-declaration.d.ts +0 -21
- package/dist/host/registry-declaration.js +0 -42
- package/dist/host/reinstall-record.d.ts +0 -16
- package/dist/host/reinstall-record.js +0 -54
- package/dist/host/release-age.d.ts +0 -24
- package/dist/host/release-age.js +0 -92
- package/dist/host/release-packages.generated.d.ts +0 -1
- package/dist/host/release-packages.generated.js +0 -10
- package/dist/host/release-probe.d.ts +0 -37
- package/dist/host/release-probe.js +0 -156
- package/dist/host/runtime/browser-argv.d.ts +0 -1
- package/dist/host/runtime/browser-argv.js +0 -9
- package/dist/host/runtime/front-app.d.ts +0 -6
- package/dist/host/runtime/front-app.js +0 -70
- package/dist/host/shell-render.d.ts +0 -52
- package/dist/host/shell-render.js +0 -117
- package/dist/host/shell-text.d.ts +0 -30
- package/dist/host/shell-text.js +0 -40
- package/dist/host/shell.d.ts +0 -25
- package/dist/host/shell.js +0 -55
- package/dist/host/site.d.ts +0 -45
- package/dist/host/site.js +0 -182
- package/dist/host/spec.d.ts +0 -8
- package/dist/host/spec.js +0 -24
- package/dist/host/submit-confirm.d.ts +0 -19
- package/dist/host/submit-confirm.js +0 -45
- package/dist/host/supply-index.d.ts +0 -38
- package/dist/host/supply-index.js +0 -209
- package/dist/host/supply-port.d.ts +0 -5
- package/dist/host/supply-port.js +0 -50
- package/dist/host/time.d.ts +0 -22
- package/dist/host/time.js +0 -33
- package/dist/host/tokens.d.ts +0 -26
- package/dist/host/tokens.js +0 -154
- package/dist/host/tool-approval.d.ts +0 -86
- package/dist/host/tool-approval.js +0 -118
- package/dist/host/tool-kit.d.ts +0 -8
- package/dist/host/tool-kit.js +0 -22
- package/dist/host/toolbox-port.d.ts +0 -16
- package/dist/host/toolbox-port.js +0 -1
- package/dist/host/unit-config.d.ts +0 -34
- package/dist/host/unit-config.js +0 -28
- package/dist/host/unit-data.d.ts +0 -3
- package/dist/host/unit-data.js +0 -127
- package/dist/host/unit-face.d.ts +0 -95
- package/dist/host/unit-face.js +0 -1
- package/dist/host/unit-plugin.d.ts +0 -24
- package/dist/host/unit-plugin.js +0 -25
- package/dist/host/update-journal-manifest.d.ts +0 -19
- package/dist/host/update-journal-manifest.js +0 -134
- package/dist/host/update-journal-types.d.ts +0 -33
- package/dist/host/update-journal-types.js +0 -2
- package/dist/host/update-journal.d.ts +0 -43
- package/dist/host/update-journal.js +0 -409
- package/dist/host/value-handoff.d.ts +0 -16
- package/dist/host/value-handoff.js +0 -22
- package/dist/host/version-range.d.ts +0 -2
- package/dist/host/version-range.js +0 -13
- package/dist/host/version.d.ts +0 -4
- package/dist/host/version.js +0 -32
- package/dist/host/workspace-store.d.ts +0 -19
- package/dist/host/workspace-store.js +0 -133
- package/dist/host/write-result.d.ts +0 -1
- package/dist/host/write-result.js +0 -18
package/dist/host/changelog.js
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import { now as clockNow } from './time.js';
|
|
2
|
-
import dayjs from 'dayjs';
|
|
3
|
-
export const CHANGELOG_FILE = 'CHANGELOG.md';
|
|
4
|
-
export const CHANGELOG_KINDS = ['added', 'changed', 'fixed', 'removed', 'security', 'deprecated'];
|
|
5
|
-
const KIND_LABELS = {
|
|
6
|
-
added: '✨ 新增',
|
|
7
|
-
changed: '⚡ 改进',
|
|
8
|
-
fixed: '🐛 修复',
|
|
9
|
-
removed: '🗑️ 移除',
|
|
10
|
-
security: '🔒 安全',
|
|
11
|
-
deprecated: '⚠️ 弃用',
|
|
12
|
-
};
|
|
13
|
-
const VERSION_HEADING = /^##[ \t]+\[?v?(\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)\]?[ \t]*(?:-[ \t]*.*)?$/;
|
|
14
|
-
const ANY_SECTION = /^##[ \t]/;
|
|
15
|
-
const SUBSECTION = /^###[ \t]/;
|
|
16
|
-
export function changelogVersion(value) {
|
|
17
|
-
return String(value ?? '')
|
|
18
|
-
.trim()
|
|
19
|
-
.replace(/^v/, '');
|
|
20
|
-
}
|
|
21
|
-
export function changelogDate(now = new Date(clockNow())) {
|
|
22
|
-
return dayjs(now).format('YYYY-MM-DD');
|
|
23
|
-
}
|
|
24
|
-
export function normalizeChangelogText(text) {
|
|
25
|
-
return String(text ?? '').replace(/\r\n?/g, '\n');
|
|
26
|
-
}
|
|
27
|
-
function linesOf(text) {
|
|
28
|
-
return normalizeChangelogText(text).split('\n');
|
|
29
|
-
}
|
|
30
|
-
function bodyOf(rows) {
|
|
31
|
-
return rows.join('\n').trim();
|
|
32
|
-
}
|
|
33
|
-
function sectionRange(rows, version) {
|
|
34
|
-
const wanted = changelogVersion(version);
|
|
35
|
-
for (let index = 0; index < rows.length; index += 1) {
|
|
36
|
-
const row = rows[index] ?? '';
|
|
37
|
-
if (!ANY_SECTION.test(row))
|
|
38
|
-
continue;
|
|
39
|
-
const match = VERSION_HEADING.exec(row);
|
|
40
|
-
if (match === null || changelogVersion(match[1] ?? '') !== wanted)
|
|
41
|
-
continue;
|
|
42
|
-
let end = rows.length;
|
|
43
|
-
for (let next = index + 1; next < rows.length; next += 1) {
|
|
44
|
-
if (ANY_SECTION.test(rows[next] ?? '')) {
|
|
45
|
-
end = next;
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return { start: index, end };
|
|
50
|
-
}
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
53
|
-
export function changelogSkeleton() {
|
|
54
|
-
return '# 更新日志\n';
|
|
55
|
-
}
|
|
56
|
-
export function parseChangelog(text) {
|
|
57
|
-
const rows = linesOf(text);
|
|
58
|
-
const sections = [];
|
|
59
|
-
let current;
|
|
60
|
-
for (let index = 0; index < rows.length; index += 1) {
|
|
61
|
-
const row = rows[index] ?? '';
|
|
62
|
-
if (!ANY_SECTION.test(row))
|
|
63
|
-
continue;
|
|
64
|
-
if (current !== undefined) {
|
|
65
|
-
sections.push({ version: current.version, body: bodyOf(rows.slice(current.from, index)) });
|
|
66
|
-
}
|
|
67
|
-
const match = VERSION_HEADING.exec(row);
|
|
68
|
-
current =
|
|
69
|
-
match === null
|
|
70
|
-
? undefined
|
|
71
|
-
: { version: changelogVersion(match[1] ?? ''), from: index + 1 };
|
|
72
|
-
}
|
|
73
|
-
if (current !== undefined) {
|
|
74
|
-
sections.push({ version: current.version, body: bodyOf(rows.slice(current.from)) });
|
|
75
|
-
}
|
|
76
|
-
return sections;
|
|
77
|
-
}
|
|
78
|
-
export function changelogSectionOf(text, version) {
|
|
79
|
-
const wanted = changelogVersion(version);
|
|
80
|
-
return parseChangelog(text).find((one) => one.version === wanted)?.body;
|
|
81
|
-
}
|
|
82
|
-
export function changelogHasEntry(text, version) {
|
|
83
|
-
const body = changelogSectionOf(text, version);
|
|
84
|
-
if (body === undefined)
|
|
85
|
-
return false;
|
|
86
|
-
return body
|
|
87
|
-
.split('\n')
|
|
88
|
-
.map((one) => one.trim())
|
|
89
|
-
.some((one) => one !== '' && !one.startsWith('#') && !one.startsWith('<!--') && !/^`[^`]*`$/.test(one));
|
|
90
|
-
}
|
|
91
|
-
function bulletsOf(note) {
|
|
92
|
-
return note
|
|
93
|
-
.split('\n')
|
|
94
|
-
.map((one) => one.trim())
|
|
95
|
-
.filter((one) => one !== '')
|
|
96
|
-
.map((one) => `- ${one}`);
|
|
97
|
-
}
|
|
98
|
-
function blockOf(options, label, bullets) {
|
|
99
|
-
const date = (options.date ?? '').trim();
|
|
100
|
-
return [
|
|
101
|
-
`## v${changelogVersion(options.version)}`,
|
|
102
|
-
...(date === '' ? [] : ['', `\`${date}\``]),
|
|
103
|
-
'',
|
|
104
|
-
`### ${label}`,
|
|
105
|
-
'',
|
|
106
|
-
...bullets,
|
|
107
|
-
];
|
|
108
|
-
}
|
|
109
|
-
function insertBlock(rows, at, block) {
|
|
110
|
-
const before = rows.slice(0, at);
|
|
111
|
-
while (before.length > 0 && (before[before.length - 1] ?? '').trim() === '')
|
|
112
|
-
before.pop();
|
|
113
|
-
const after = rows.slice(at);
|
|
114
|
-
while (after.length > 0 && (after[0] ?? '').trim() === '')
|
|
115
|
-
after.shift();
|
|
116
|
-
const out = [...before];
|
|
117
|
-
if (out.length > 0)
|
|
118
|
-
out.push('');
|
|
119
|
-
out.push(...block);
|
|
120
|
-
if (after.length > 0) {
|
|
121
|
-
out.push('');
|
|
122
|
-
out.push(...after);
|
|
123
|
-
}
|
|
124
|
-
return out;
|
|
125
|
-
}
|
|
126
|
-
function newSectionAt(rows) {
|
|
127
|
-
for (let index = 0; index < rows.length; index += 1) {
|
|
128
|
-
if (/^##[ \t]+\[?unreleased\]?[ \t]*$/i.test(rows[index] ?? '')) {
|
|
129
|
-
for (let next = index + 1; next < rows.length; next += 1) {
|
|
130
|
-
if (ANY_SECTION.test(rows[next] ?? ''))
|
|
131
|
-
return next;
|
|
132
|
-
}
|
|
133
|
-
return rows.length;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
for (let index = 0; index < rows.length; index += 1) {
|
|
137
|
-
if (ANY_SECTION.test(rows[index] ?? ''))
|
|
138
|
-
return index;
|
|
139
|
-
}
|
|
140
|
-
return rows.length;
|
|
141
|
-
}
|
|
142
|
-
export function appendChangelogEntry(text, options) {
|
|
143
|
-
const kind = options.kind ?? 'changed';
|
|
144
|
-
const label = KIND_LABELS[kind];
|
|
145
|
-
const bullets = bulletsOf(options.note);
|
|
146
|
-
if (bullets.length === 0)
|
|
147
|
-
return normalizeChangelogText(text);
|
|
148
|
-
const blocks = blockOf(options, label, bullets);
|
|
149
|
-
const source = normalizeChangelogText(text).trim() === '' ? changelogSkeleton() : normalizeChangelogText(text);
|
|
150
|
-
const rows = linesOf(source);
|
|
151
|
-
const range = sectionRange(rows, options.version);
|
|
152
|
-
if (range === undefined)
|
|
153
|
-
return `${insertBlock(rows, newSectionAt(rows), blocks).join('\n').replace(/\n+$/, '')}\n`;
|
|
154
|
-
let subsection = -1;
|
|
155
|
-
for (let index = range.start + 1; index < range.end; index += 1) {
|
|
156
|
-
const heading = (rows[index] ?? '').trim();
|
|
157
|
-
if (SUBSECTION.test(heading) && heading.includes(label)) {
|
|
158
|
-
subsection = index;
|
|
159
|
-
break;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
if (subsection === -1) {
|
|
163
|
-
const out = [...rows];
|
|
164
|
-
out.splice(range.end, 0, '', `### ${label}`, '', ...bullets);
|
|
165
|
-
return `${normalizeWhitespace(out)}\n`;
|
|
166
|
-
}
|
|
167
|
-
let end = range.end;
|
|
168
|
-
for (let index = subsection + 1; index < range.end; index += 1) {
|
|
169
|
-
if (SUBSECTION.test(rows[index] ?? '')) {
|
|
170
|
-
end = index;
|
|
171
|
-
break;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
const out = [...rows];
|
|
175
|
-
let at = end;
|
|
176
|
-
while (at > subsection + 1 && (out[at - 1] ?? '').trim() === '')
|
|
177
|
-
at -= 1;
|
|
178
|
-
out.splice(at, 0, ...bullets);
|
|
179
|
-
return `${normalizeWhitespace(out)}\n`;
|
|
180
|
-
}
|
|
181
|
-
export function planChangelog(text, options) {
|
|
182
|
-
const source = normalizeChangelogText(text);
|
|
183
|
-
const version = changelogVersion(options.version);
|
|
184
|
-
const section = changelogSectionOf(source, version);
|
|
185
|
-
if (section !== undefined && changelogHasEntry(source, version)) {
|
|
186
|
-
return { action: 'kept', version, text: source, section };
|
|
187
|
-
}
|
|
188
|
-
if (bulletsOf(options.note).length === 0)
|
|
189
|
-
return undefined;
|
|
190
|
-
const next = appendChangelogEntry(source, options);
|
|
191
|
-
return { action: 'written', version, text: next, section: changelogSectionOf(next, version) ?? '' };
|
|
192
|
-
}
|
|
193
|
-
function normalizeWhitespace(rows) {
|
|
194
|
-
const out = [];
|
|
195
|
-
for (const row of rows) {
|
|
196
|
-
if (row.trim() === '' && out.length > 0 && (out[out.length - 1] ?? '').trim() === '')
|
|
197
|
-
continue;
|
|
198
|
-
out.push(row);
|
|
199
|
-
}
|
|
200
|
-
return out.join('\n').replace(/\n+$/, '');
|
|
201
|
-
}
|
package/dist/host/cli-error.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export interface CliErrorEnvelope {
|
|
2
|
-
readonly code: string;
|
|
3
|
-
readonly message: string;
|
|
4
|
-
readonly help?: string;
|
|
5
|
-
readonly exitCode?: number;
|
|
6
|
-
}
|
|
7
|
-
export declare function parseCliErrorEnvelope(text: string | undefined): CliErrorEnvelope | undefined;
|
|
8
|
-
export declare function helpUrlOf(envelope: CliErrorEnvelope): string | undefined;
|
package/dist/host/cli-error.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
function unquote(raw) {
|
|
2
|
-
const value = raw.trim();
|
|
3
|
-
if (value.length >= 2 && ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'")))) {
|
|
4
|
-
return value.slice(1, -1);
|
|
5
|
-
}
|
|
6
|
-
return value;
|
|
7
|
-
}
|
|
8
|
-
function joinBlock(previous, line, fold) {
|
|
9
|
-
if (previous === '')
|
|
10
|
-
return line;
|
|
11
|
-
return fold ? `${previous} ${line}` : `${previous}\n${line}`;
|
|
12
|
-
}
|
|
13
|
-
export function parseCliErrorEnvelope(text) {
|
|
14
|
-
if (text === undefined || text.trim() === '')
|
|
15
|
-
return undefined;
|
|
16
|
-
const lines = text.split('\n');
|
|
17
|
-
const start = lines.findIndex((line) => /^error:\s*$/.test(line.trim()) || /^error:\s*\S/.test(line.trim()));
|
|
18
|
-
if (start === -1)
|
|
19
|
-
return undefined;
|
|
20
|
-
const scalars = {};
|
|
21
|
-
let current;
|
|
22
|
-
let block;
|
|
23
|
-
const errorIndent = lines[start]?.search(/\S/) ?? 0;
|
|
24
|
-
for (const line of lines.slice(start + 1)) {
|
|
25
|
-
if (line.trim() === '')
|
|
26
|
-
continue;
|
|
27
|
-
const indent = line.search(/\S/);
|
|
28
|
-
if (block !== undefined && indent > block.indent) {
|
|
29
|
-
scalars[block.key] = joinBlock(scalars[block.key] ?? '', line.trim(), block.fold);
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
block = undefined;
|
|
33
|
-
if (indent <= errorIndent)
|
|
34
|
-
break;
|
|
35
|
-
const match = /^\s*(code|message|help|exitCode):\s*(.*)$/.exec(line);
|
|
36
|
-
if (match === null) {
|
|
37
|
-
if (current !== undefined)
|
|
38
|
-
scalars[current] = `${scalars[current] ?? ''} ${line.trim()}`.trim();
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
const [, key, value] = match;
|
|
42
|
-
if (key === undefined)
|
|
43
|
-
continue;
|
|
44
|
-
const raw = (value ?? '').trim();
|
|
45
|
-
const marker = /^([|>])[0-9]*([+-]?)$/.exec(raw);
|
|
46
|
-
if (marker !== null) {
|
|
47
|
-
scalars[key] = '';
|
|
48
|
-
block = { key, fold: marker[1] === '>', indent };
|
|
49
|
-
current = key;
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
scalars[key] = unquote(raw);
|
|
53
|
-
current = key;
|
|
54
|
-
}
|
|
55
|
-
const code = scalars['code'];
|
|
56
|
-
const message = scalars['message'];
|
|
57
|
-
if (code === undefined || code === '')
|
|
58
|
-
return undefined;
|
|
59
|
-
const exitCode = scalars['exitCode'];
|
|
60
|
-
return {
|
|
61
|
-
code,
|
|
62
|
-
message: message ?? code,
|
|
63
|
-
...(scalars['help'] === undefined || scalars['help'] === '' ? {} : { help: scalars['help'] }),
|
|
64
|
-
...(exitCode === undefined || Number.isNaN(Number(exitCode)) ? {} : { exitCode: Number(exitCode) }),
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
export function helpUrlOf(envelope) {
|
|
68
|
-
const match = /https?:\/\/[^\s"'`]+/.exec(envelope.help ?? '');
|
|
69
|
-
return match?.[0];
|
|
70
|
-
}
|
package/dist/host/cli.d.ts
DELETED
package/dist/host/cli.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { adaptersOf } from './adapters.js';
|
|
2
|
-
export function cliPortOf(ctx) {
|
|
3
|
-
const commands = adaptersOf(ctx).runtime.commands(ctx);
|
|
4
|
-
const first = Object.values(commands)[0];
|
|
5
|
-
return { command: first ?? '' };
|
|
6
|
-
}
|
|
7
|
-
export function cliCommandOf(ctx) {
|
|
8
|
-
return cliPortOf(ctx).command;
|
|
9
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { PostResource, RouteHandler } from './http.js';
|
|
2
|
-
import type { ConfigSyncRow, ConfigSyncSnapshot } from '../contract/protocol/config-sync.js';
|
|
3
|
-
import { type PatchBlock } from './patch-blocks.js';
|
|
4
|
-
export declare function normalizeBlock(body: string): string;
|
|
5
|
-
export declare function syncRows(source: readonly PatchBlock[], own: readonly PatchBlock[], missing: (block: PatchBlock) => readonly string[]): ConfigSyncRow[];
|
|
6
|
-
export declare function mergeBlocks(ownText: string, incoming: readonly PatchBlock[], overwrite: ReadonlySet<string>): {
|
|
7
|
-
ok: true;
|
|
8
|
-
text: string;
|
|
9
|
-
written: string[];
|
|
10
|
-
skipped: string[];
|
|
11
|
-
} | {
|
|
12
|
-
ok: false;
|
|
13
|
-
reason: string;
|
|
14
|
-
};
|
|
15
|
-
export declare function readPatchBlocks(path: string): {
|
|
16
|
-
ok: true;
|
|
17
|
-
text: string;
|
|
18
|
-
blocks: PatchBlock[];
|
|
19
|
-
} | {
|
|
20
|
-
ok: false;
|
|
21
|
-
reason: string;
|
|
22
|
-
};
|
|
23
|
-
export interface ConfigSyncDeps {
|
|
24
|
-
readonly home: string;
|
|
25
|
-
readonly self: string;
|
|
26
|
-
readonly profileDir: string | null;
|
|
27
|
-
readonly reconcile?: (() => Promise<boolean | void>) | undefined;
|
|
28
|
-
}
|
|
29
|
-
export declare function configSyncHandler(deps: ConfigSyncDeps): RouteHandler;
|
|
30
|
-
export declare function configSyncSnapshot(deps: ConfigSyncDeps, asked?: string): ConfigSyncSnapshot;
|
|
31
|
-
export declare function configSyncApply(deps: ConfigSyncDeps, payload: unknown): Promise<{
|
|
32
|
-
ok: true;
|
|
33
|
-
written: string[];
|
|
34
|
-
skipped: string[];
|
|
35
|
-
verified: boolean;
|
|
36
|
-
} | {
|
|
37
|
-
ok: false;
|
|
38
|
-
text: string;
|
|
39
|
-
}>;
|
|
40
|
-
export declare function configSyncAction(deps: ConfigSyncDeps): PostResource;
|
package/dist/host/config-sync.js
DELETED
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { CONFIG_SYNC_RESOURCE } from '../contract/protocol/config-sync.js';
|
|
4
|
-
import { writePatchFile } from './patch.js';
|
|
5
|
-
import { patchBlocks, spannedBlocks } from './patch-blocks.js';
|
|
6
|
-
const COMMENT_LINE = /^[ \t]*#/;
|
|
7
|
-
const ISOLATION_IDS = new Set([
|
|
8
|
-
'session-persistence-jsonl',
|
|
9
|
-
'storage-json',
|
|
10
|
-
'attachment-local',
|
|
11
|
-
'sandbox-policy',
|
|
12
|
-
]);
|
|
13
|
-
export function normalizeBlock(body) {
|
|
14
|
-
return body
|
|
15
|
-
.split('\n')
|
|
16
|
-
.map((line) => line.replace(/\s+$/, ''))
|
|
17
|
-
.filter((line) => line.trim() !== '' && !COMMENT_LINE.test(line))
|
|
18
|
-
.join('\n');
|
|
19
|
-
}
|
|
20
|
-
function rewriteForTarget(body, self) {
|
|
21
|
-
if (self === '' || self === 'workbench')
|
|
22
|
-
return body;
|
|
23
|
-
return body.replace(/(dshHomePath\(\s*['"])workbench(?=[/'"])/g, `$1${self}`);
|
|
24
|
-
}
|
|
25
|
-
function syncable(block) {
|
|
26
|
-
return !block.insert && !ISOLATION_IDS.has(block.id);
|
|
27
|
-
}
|
|
28
|
-
export function syncRows(source, own, missing) {
|
|
29
|
-
const mine = new Map(own.map((block) => [block.key, block]));
|
|
30
|
-
const rows = [];
|
|
31
|
-
for (const block of source) {
|
|
32
|
-
if (!syncable(block))
|
|
33
|
-
continue;
|
|
34
|
-
const here = mine.get(block.key);
|
|
35
|
-
if (here !== undefined && normalizeBlock(here.body) === normalizeBlock(block.body))
|
|
36
|
-
continue;
|
|
37
|
-
rows.push({
|
|
38
|
-
key: block.key,
|
|
39
|
-
id: block.id,
|
|
40
|
-
state: here === undefined ? 'new' : 'differs',
|
|
41
|
-
body: block.body,
|
|
42
|
-
ownBody: here === undefined ? null : here.body,
|
|
43
|
-
missing: missing(block),
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
return rows;
|
|
47
|
-
}
|
|
48
|
-
function replaceBlocks(text, blocks) {
|
|
49
|
-
const wanted = new Map(blocks.map((block) => [block.key, block]));
|
|
50
|
-
const spans = spannedBlocks(text).filter((span) => wanted.has(span.key));
|
|
51
|
-
const lines = text.split('\n');
|
|
52
|
-
for (const span of [...spans].reverse()) {
|
|
53
|
-
const replacement = (wanted.get(span.key)?.body ?? '').split('\n');
|
|
54
|
-
lines.splice(span.from, span.to - span.from, ...replacement);
|
|
55
|
-
}
|
|
56
|
-
return lines.join('\n');
|
|
57
|
-
}
|
|
58
|
-
function appendBlocks(text, blocks) {
|
|
59
|
-
const kept = text
|
|
60
|
-
.split('\n')
|
|
61
|
-
.filter((line) => line.trim() !== '[]')
|
|
62
|
-
.join('\n')
|
|
63
|
-
.replace(/\s+$/, '');
|
|
64
|
-
let out = kept === '' ? '' : `${kept}\n`;
|
|
65
|
-
for (const block of blocks)
|
|
66
|
-
out += `\n${block.body}\n`;
|
|
67
|
-
return out;
|
|
68
|
-
}
|
|
69
|
-
export function mergeBlocks(ownText, incoming, overwrite) {
|
|
70
|
-
const own = patchBlocks(ownText);
|
|
71
|
-
const mine = new Set(own.map((block) => block.key));
|
|
72
|
-
const written = [];
|
|
73
|
-
const skipped = [];
|
|
74
|
-
const take = [];
|
|
75
|
-
for (const block of incoming) {
|
|
76
|
-
if (!mine.has(block.key) || overwrite.has(block.key)) {
|
|
77
|
-
take.push(block);
|
|
78
|
-
written.push(block.id);
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
skipped.push(block.id);
|
|
82
|
-
}
|
|
83
|
-
if (take.length === 0)
|
|
84
|
-
return { ok: true, text: ownText, written, skipped };
|
|
85
|
-
const replaced = replaceBlocks(ownText, take.filter((block) => mine.has(block.key)));
|
|
86
|
-
const text = appendBlocks(replaced, take.filter((block) => !mine.has(block.key)));
|
|
87
|
-
const check = patchBlocks(text);
|
|
88
|
-
const expected = new Set([...mine, ...take.map((block) => block.key)]);
|
|
89
|
-
if (check.length !== expected.size || new Set(check.map((block) => block.key)).size !== expected.size) {
|
|
90
|
-
return { ok: false, reason: '写入前的自检没过:行的 id 会重复或丢行' };
|
|
91
|
-
}
|
|
92
|
-
return { ok: true, text, written, skipped };
|
|
93
|
-
}
|
|
94
|
-
export function readPatchBlocks(path) {
|
|
95
|
-
try {
|
|
96
|
-
const text = readFileSync(path, 'utf8');
|
|
97
|
-
return { ok: true, text, blocks: patchBlocks(text) };
|
|
98
|
-
}
|
|
99
|
-
catch (error) {
|
|
100
|
-
return { ok: false, reason: error instanceof Error ? error.message : String(error) };
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
export function configSyncHandler(deps) {
|
|
104
|
-
return (search) => ({ ok: true, ...configSyncSnapshot(deps, search.get('source') ?? undefined) });
|
|
105
|
-
}
|
|
106
|
-
function textOf(value) {
|
|
107
|
-
return typeof value === 'string' ? value : '';
|
|
108
|
-
}
|
|
109
|
-
function profileDependencies(dir) {
|
|
110
|
-
try {
|
|
111
|
-
const manifest = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'));
|
|
112
|
-
return new Set(Object.keys(manifest.dependencies ?? {}));
|
|
113
|
-
}
|
|
114
|
-
catch {
|
|
115
|
-
return new Set();
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
function profileNames(profilesDir) {
|
|
119
|
-
try {
|
|
120
|
-
return readdirSync(profilesDir, { withFileTypes: true })
|
|
121
|
-
.filter((entry) => entry.isDirectory() || entry.isSymbolicLink())
|
|
122
|
-
.map((entry) => entry.name)
|
|
123
|
-
.filter((name) => existsSync(join(profilesDir, name, 'package.json')))
|
|
124
|
-
.sort((a, b) => a.localeCompare(b));
|
|
125
|
-
}
|
|
126
|
-
catch {
|
|
127
|
-
return [];
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
export function configSyncSnapshot(deps, asked) {
|
|
131
|
-
const profilesDir = join(deps.home, 'profiles');
|
|
132
|
-
const names = profileNames(profilesDir);
|
|
133
|
-
const others = names.filter((name) => name !== deps.self);
|
|
134
|
-
const base = {
|
|
135
|
-
self: deps.self,
|
|
136
|
-
home: deps.home,
|
|
137
|
-
};
|
|
138
|
-
if (deps.profileDir === null) {
|
|
139
|
-
return {
|
|
140
|
-
...base,
|
|
141
|
-
source: '',
|
|
142
|
-
profiles: [],
|
|
143
|
-
rows: [],
|
|
144
|
-
emptyProviders: false,
|
|
145
|
-
reason: '拿不到当前 profile 目录',
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
const own = readPatchBlocks(join(deps.profileDir, 'cordis.patch.yml'));
|
|
149
|
-
const emptyProviders = own.ok && !own.blocks.some((block) => block.key.startsWith('id:llm-'));
|
|
150
|
-
const ownBlocks = own.ok ? own.blocks : [];
|
|
151
|
-
const profiles = others.map((name) => {
|
|
152
|
-
const read = readPatchBlocks(join(profilesDir, name, 'cordis.patch.yml'));
|
|
153
|
-
const blocks = read.ok
|
|
154
|
-
? read.blocks
|
|
155
|
-
.filter(syncable)
|
|
156
|
-
.map((block) => ({ ...block, body: rewriteForTarget(block.body, deps.self) }))
|
|
157
|
-
: [];
|
|
158
|
-
return {
|
|
159
|
-
name,
|
|
160
|
-
readable: read.ok,
|
|
161
|
-
candidates: read.ok ? syncRows(blocks, ownBlocks, () => []).length : 0,
|
|
162
|
-
};
|
|
163
|
-
});
|
|
164
|
-
if (others.length === 0) {
|
|
165
|
-
return {
|
|
166
|
-
...base,
|
|
167
|
-
source: '',
|
|
168
|
-
profiles,
|
|
169
|
-
rows: [],
|
|
170
|
-
emptyProviders,
|
|
171
|
-
reason: '这台机器上只有当前这个 profile,没有可同步的来源',
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
const source = others.includes(asked ?? '') ? (asked ?? '') : others.includes('web') ? 'web' : (others[0] ?? '');
|
|
175
|
-
const sourceDir = join(profilesDir, source);
|
|
176
|
-
const read = readPatchBlocks(join(sourceDir, 'cordis.patch.yml'));
|
|
177
|
-
if (!read.ok) {
|
|
178
|
-
return { ...base, source, profiles, rows: [], emptyProviders, reason: read.reason };
|
|
179
|
-
}
|
|
180
|
-
if (!own.ok) {
|
|
181
|
-
return { ...base, source, profiles, rows: [], emptyProviders, reason: own.reason };
|
|
182
|
-
}
|
|
183
|
-
const declared = profileDependencies(sourceDir);
|
|
184
|
-
const modulesDir = join(deps.profileDir, 'node_modules');
|
|
185
|
-
const sourceBlocks = read.blocks
|
|
186
|
-
.filter(syncable)
|
|
187
|
-
.map((block) => ({ ...block, body: rewriteForTarget(block.body, deps.self) }));
|
|
188
|
-
const rows = syncRows(sourceBlocks, own.blocks, (block) => block.names.filter((name) => declared.has(name) && !existsSync(join(modulesDir, name))));
|
|
189
|
-
return { ...base, source, profiles, rows, emptyProviders };
|
|
190
|
-
}
|
|
191
|
-
export async function configSyncApply(deps, payload) {
|
|
192
|
-
if (deps.profileDir === null)
|
|
193
|
-
return { ok: false, text: '拿不到当前 profile 目录,这次没写任何东西' };
|
|
194
|
-
const body = typeof payload === 'object' && payload !== null ? payload : {};
|
|
195
|
-
const source = textOf(body['source']);
|
|
196
|
-
const keys = new Set((Array.isArray(body['keys']) ? body['keys'] : []).map((item) => textOf(item)).filter((item) => item !== ''));
|
|
197
|
-
const overwrite = new Set((Array.isArray(body['overwrite']) ? body['overwrite'] : []).map((item) => textOf(item)));
|
|
198
|
-
if (source === '' || keys.size === 0) {
|
|
199
|
-
return { ok: false, text: '没说清从哪个 profile 同步哪几行' };
|
|
200
|
-
}
|
|
201
|
-
const profilesDir = join(deps.home, 'profiles');
|
|
202
|
-
if (!profileNames(profilesDir).includes(source))
|
|
203
|
-
return { ok: false, text: `没有这个 profile:${source}` };
|
|
204
|
-
if (source === deps.self)
|
|
205
|
-
return { ok: false, text: '来源不能是工作台自己' };
|
|
206
|
-
const sourceDir = join(profilesDir, source);
|
|
207
|
-
const read = readPatchBlocks(join(sourceDir, 'cordis.patch.yml'));
|
|
208
|
-
if (!read.ok)
|
|
209
|
-
return { ok: false, text: `读不到 ${source} 的配置:${read.reason}` };
|
|
210
|
-
const own = readPatchBlocks(join(deps.profileDir, 'cordis.patch.yml'));
|
|
211
|
-
if (!own.ok)
|
|
212
|
-
return { ok: false, text: `读不到工作台自己的配置:${own.reason}` };
|
|
213
|
-
if (read.blocks.some((block) => block.insert && keys.has(block.key))) {
|
|
214
|
-
return { ok: false, text: '插件行不同步:先把插件装到工作台这边,再同步它的设置' };
|
|
215
|
-
}
|
|
216
|
-
const picked = read.blocks
|
|
217
|
-
.filter((block) => keys.has(block.key) && syncable(block))
|
|
218
|
-
.map((block) => ({ ...block, body: rewriteForTarget(block.body, deps.self) }));
|
|
219
|
-
if (picked.length === 0) {
|
|
220
|
-
return { ok: false, text: '选中的行在来源里已经找不到了,重新读一遍再试' };
|
|
221
|
-
}
|
|
222
|
-
const merged = mergeBlocks(own.text, picked, overwrite);
|
|
223
|
-
if (!merged.ok)
|
|
224
|
-
return { ok: false, text: merged.reason };
|
|
225
|
-
const patchPath = join(deps.profileDir, 'cordis.patch.yml');
|
|
226
|
-
const patchChanged = merged.text !== own.text;
|
|
227
|
-
try {
|
|
228
|
-
if (patchChanged)
|
|
229
|
-
writePatchFile(patchPath, merged.text);
|
|
230
|
-
}
|
|
231
|
-
catch (error) {
|
|
232
|
-
return { ok: false, text: `写不进去:${error instanceof Error ? error.message : String(error)}` };
|
|
233
|
-
}
|
|
234
|
-
if (deps.reconcile === undefined) {
|
|
235
|
-
return { ok: true, written: merged.written, skipped: merged.skipped, verified: false };
|
|
236
|
-
}
|
|
237
|
-
try {
|
|
238
|
-
const verified = await deps.reconcile();
|
|
239
|
-
if (verified === false) {
|
|
240
|
-
return { ok: true, written: merged.written, skipped: merged.skipped, verified: false };
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
catch (error) {
|
|
244
|
-
if (patchChanged) {
|
|
245
|
-
try {
|
|
246
|
-
writePatchFile(patchPath, own.text);
|
|
247
|
-
}
|
|
248
|
-
catch {
|
|
249
|
-
return { ok: false, text: `写进去了,但启动检查没通过:${error instanceof Error ? error.message : String(error)}。原来的设置没能恢复,手动检查一下` };
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
try {
|
|
253
|
-
await deps.reconcile();
|
|
254
|
-
}
|
|
255
|
-
catch {
|
|
256
|
-
return { ok: false, text: `写进去了,但启动检查没通过:${error instanceof Error ? error.message : String(error)}。已恢复原来的设置` };
|
|
257
|
-
}
|
|
258
|
-
return { ok: false, text: `写进去了,但启动检查没通过:${error instanceof Error ? error.message : String(error)}。已恢复原来的设置` };
|
|
259
|
-
}
|
|
260
|
-
return { ok: true, written: merged.written, skipped: merged.skipped, verified: true };
|
|
261
|
-
}
|
|
262
|
-
export function configSyncAction(deps) {
|
|
263
|
-
return {
|
|
264
|
-
resource: CONFIG_SYNC_RESOURCE,
|
|
265
|
-
handle: (payload) => configSyncApply(deps, payload),
|
|
266
|
-
};
|
|
267
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { type ContextRef } from '../api/context-ref.js';
|
|
2
|
-
/**
|
|
3
|
-
* 把 kind:part/part 文本读回引用。
|
|
4
|
-
* @param text 待解析文本。
|
|
5
|
-
* @returns 没冒号、冒号在首尾、种类不是小写字母开头、或冒号后为空时给 undefined;不抛异常。
|
|
6
|
-
*/
|
|
7
|
-
export declare function decodeRef(text: string): ContextRef | undefined;
|
|
8
|
-
/**
|
|
9
|
-
* 从一段文本里按出现顺序捞出所有标记引用,同一个引用只留第一次。
|
|
10
|
-
* @param text 任意文本;null / undefined 当空串。
|
|
11
|
-
* @returns 解析不出来的标记会被丢掉,所以结果只含合法引用,可能为空数组。
|
|
12
|
-
*/
|
|
13
|
-
export declare function parseMarkers(text: string): ContextRef[];
|
package/dist/host/context-ref.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { CONTEXT_MARKER_NAME, encodeRef } from '../api/context-ref.js';
|
|
2
|
-
const MARKER = new RegExp(`@${CONTEXT_MARKER_NAME}:([a-z][a-z0-9-]*:[A-Za-z0-9._~%#/-]+)`, 'g');
|
|
3
|
-
const TRAILING_PUNCTUATION = /[.,;:!?]+$/;
|
|
4
|
-
/**
|
|
5
|
-
* 把 kind:part/part 文本读回引用。
|
|
6
|
-
* @param text 待解析文本。
|
|
7
|
-
* @returns 没冒号、冒号在首尾、种类不是小写字母开头、或冒号后为空时给 undefined;不抛异常。
|
|
8
|
-
*/
|
|
9
|
-
export function decodeRef(text) {
|
|
10
|
-
const at = text.indexOf(':');
|
|
11
|
-
if (at <= 0 || at === text.length - 1)
|
|
12
|
-
return undefined;
|
|
13
|
-
const kind = text.slice(0, at);
|
|
14
|
-
if (!/^[a-z][a-z0-9-]*$/.test(kind))
|
|
15
|
-
return undefined;
|
|
16
|
-
const parts = text.slice(at + 1).split('/').filter((part) => part !== '');
|
|
17
|
-
if (parts.length === 0)
|
|
18
|
-
return undefined;
|
|
19
|
-
return { kind, parts };
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* 从一段文本里按出现顺序捞出所有标记引用,同一个引用只留第一次。
|
|
23
|
-
* @param text 任意文本;null / undefined 当空串。
|
|
24
|
-
* @returns 解析不出来的标记会被丢掉,所以结果只含合法引用,可能为空数组。
|
|
25
|
-
*/
|
|
26
|
-
export function parseMarkers(text) {
|
|
27
|
-
const seen = new Set();
|
|
28
|
-
const refs = [];
|
|
29
|
-
for (const match of String(text ?? '').matchAll(MARKER)) {
|
|
30
|
-
const raw = match[1].replace(TRAILING_PUNCTUATION, '');
|
|
31
|
-
const ref = decodeRef(raw);
|
|
32
|
-
if (ref === undefined)
|
|
33
|
-
continue;
|
|
34
|
-
const key = encodeRef(ref);
|
|
35
|
-
if (seen.has(key))
|
|
36
|
-
continue;
|
|
37
|
-
seen.add(key);
|
|
38
|
-
refs.push(ref);
|
|
39
|
-
}
|
|
40
|
-
return refs;
|
|
41
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export declare class WorkbenchDataError extends Error {
|
|
2
|
-
readonly code: string;
|
|
3
|
-
readonly detail?: string;
|
|
4
|
-
readonly hint?: string;
|
|
5
|
-
readonly project?: unknown;
|
|
6
|
-
readonly helpUrl?: string;
|
|
7
|
-
readonly failure?: unknown;
|
|
8
|
-
constructor(code: string, message: string, extra?: {
|
|
9
|
-
detail?: string;
|
|
10
|
-
hint?: string;
|
|
11
|
-
project?: unknown;
|
|
12
|
-
helpUrl?: string;
|
|
13
|
-
failure?: unknown;
|
|
14
|
-
});
|
|
15
|
-
}
|