dsh-config-manager 0.8.2 → 0.9.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/lib/adapters/mcp.js +42 -13
- package/lib/adapters/messages.d.ts +1 -0
- package/lib/adapters/messages.js +2 -0
- package/lib/adapters/patch-key-guard.d.ts +23 -0
- package/lib/adapters/patch-key-guard.js +13 -0
- package/lib/adapters/plugin-data.d.ts +19 -5
- package/lib/adapters/plugin-data.js +76 -22
- package/lib/adapters/plugins.d.ts +14 -1
- package/lib/adapters/plugins.js +147 -4
- package/lib/cli/actions.d.ts +7 -105
- package/lib/cli/actions.js +16 -172
- package/lib/cli/control-state.d.ts +54 -0
- package/lib/cli/control-state.js +107 -0
- package/lib/cli/index.js +14 -0
- package/lib/cli/write-gates.d.ts +61 -0
- package/lib/cli/write-gates.js +110 -0
- package/lib/client.d.ts +104 -49
- package/lib/client.js +12536 -12006
- package/lib/core/backup.d.ts +0 -4
- package/lib/core/backup.js +21 -4
- package/lib/core/boot-rescue.d.ts +1 -1
- package/lib/core/boot-rescue.js +12 -1
- package/lib/core/boot-safety.js +37 -2
- package/lib/core/conflict-decisions.js +2 -1
- package/lib/core/exporter.js +22 -1
- package/lib/core/journal.d.ts +54 -4
- package/lib/core/journal.js +158 -35
- package/lib/core/local-plugin-host.d.ts +29 -0
- package/lib/core/local-plugin-host.js +55 -48
- package/lib/core/messages.d.ts +7 -0
- package/lib/core/messages.js +14 -0
- package/lib/core/migration-history.js +16 -9
- package/lib/core/model-tools.d.ts +2 -2
- package/lib/core/model-tools.js +14 -2
- package/lib/core/patch-secret-guard.d.ts +49 -0
- package/lib/core/patch-secret-guard.js +164 -0
- package/lib/core/reconcile.d.ts +8 -0
- package/lib/core/reconcile.js +18 -3
- package/lib/core/reinstall.d.ts +2 -0
- package/lib/core/reinstall.js +6 -2
- package/lib/core/restore.js +31 -6
- package/lib/core/section-sanitize.d.ts +32 -0
- package/lib/core/section-sanitize.js +13 -0
- package/lib/core/snapshot-diff.d.ts +30 -0
- package/lib/core/snapshot-diff.js +56 -20
- package/lib/core/startup-barrier.js +8 -2
- package/lib/core/types.d.ts +22 -0
- package/lib/core/update-check.js +51 -2
- package/lib/foreign/kernel.js +9 -2
- package/lib/foreign/read-claude-plugins.js +29 -11
- package/lib/foreign/read-dsh.js +31 -2
- package/lib/foreign/session-ir.js +50 -9
- package/lib/foreign/session-read.d.ts +8 -0
- package/lib/foreign/session-read.js +26 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/profiles/dsh-profile-io.d.ts +20 -0
- package/lib/profiles/dsh-profile-io.js +27 -0
- package/lib/profiles/dsh-profile-manager.d.ts +27 -0
- package/lib/profiles/dsh-profile-manager.js +45 -4
- package/lib/profiles/dsh-profile-runtime.d.ts +5 -1
- package/lib/profiles/dsh-profile-runtime.js +16 -3
- package/lib/profiles/process-control.d.ts +18 -1
- package/lib/profiles/process-control.js +25 -1
- package/lib/routes/profiles.js +2 -1
- package/lib/routes/sync.js +13 -1
- package/lib/schema/types.d.ts +11 -0
- package/lib/security/redaction.js +22 -6
- package/lib/sync/autosync-repeat.d.ts +27 -0
- package/lib/sync/autosync-repeat.js +23 -0
- package/lib/sync/autosync-scheduler.d.ts +34 -1
- package/lib/sync/autosync-scheduler.js +151 -43
- package/lib/sync/baseline-heal.js +7 -0
- package/lib/sync/baseline-record.d.ts +67 -0
- package/lib/sync/baseline-record.js +74 -0
- package/lib/sync/blob-store.js +13 -0
- package/lib/sync/content-diff.d.ts +39 -0
- package/lib/sync/content-diff.js +46 -0
- package/lib/sync/git/git-transport.d.ts +32 -1
- package/lib/sync/git/git-transport.js +146 -26
- package/lib/sync/github-auth.d.ts +17 -1
- package/lib/sync/github-auth.js +37 -1
- package/lib/sync/merge-apply-plan.d.ts +38 -0
- package/lib/sync/merge-apply-plan.js +76 -0
- package/lib/sync/messages.d.ts +1 -0
- package/lib/sync/messages.js +2 -0
- package/lib/sync/pending-merge.d.ts +34 -0
- package/lib/sync/pending-merge.js +53 -0
- package/lib/sync/s3/s3-transport.d.ts +14 -2
- package/lib/sync/s3/s3-transport.js +72 -48
- package/lib/sync/sync-engine.d.ts +23 -40
- package/lib/sync/sync-engine.js +115 -132
- package/lib/sync/sync-history.d.ts +7 -0
- package/lib/sync/sync-state.d.ts +28 -0
- package/lib/sync/sync-state.js +20 -0
- package/lib/sync/transport.d.ts +12 -3
- package/lib/sync/transport.js +13 -4
- package/lib/sync/webdav/webdav-transport.d.ts +19 -2
- package/lib/sync/webdav/webdav-transport.js +81 -40
- package/lib/ui/commands.js +5 -11
- package/lib/ui/dsh-profiles-view.d.ts +8 -3
- package/lib/ui/dsh-profiles-view.js +9 -5
- package/lib/ui/i18n.d.ts +2 -1
- package/lib/ui/i18n.js +4 -2
- package/lib/ui/menu-placement.js +1 -1
- package/lib/ui/migration-consult-view.d.ts +11 -0
- package/lib/ui/migration-consult-view.js +15 -0
- package/lib/ui/overview-view.d.ts +7 -0
- package/lib/ui/overview-view.js +3 -0
- package/lib/ui/report.d.ts +9 -0
- package/lib/ui/report.js +17 -4
- package/lib/ui/selection-model.d.ts +8 -0
- package/lib/ui/selection-model.js +16 -0
- package/lib/utils/patch-yaml.d.ts +39 -1
- package/lib/utils/patch-yaml.js +82 -2
- package/lib/utils/paths.d.ts +13 -0
- package/lib/utils/paths.js +35 -0
- package/lib/utils/workdir-lock.js +18 -3
- package/package.json +2 -1
- package/src/adapters/mcp.test.ts +29 -0
- package/src/adapters/mcp.ts +43 -12
- package/src/adapters/messages.ts +2 -0
- package/src/adapters/patch-key-guard.ts +29 -0
- package/src/adapters/plugin-data.test.ts +126 -0
- package/src/adapters/plugin-data.ts +97 -26
- package/src/adapters/plugins.test.ts +288 -0
- package/src/adapters/plugins.ts +141 -4
- package/src/cli/actions.test.ts +74 -1
- package/src/cli/actions.ts +27 -246
- package/src/cli/control-state.ts +143 -0
- package/src/cli/index.ts +18 -0
- package/src/cli/web/web.test.ts +27 -0
- package/src/cli/write-gates.ts +149 -0
- package/src/client/about/AboutPanel.tsx +7 -6
- package/src/client/about/release-notes-view.test.ts +17 -0
- package/src/client/about/release-notes-view.ts +49 -24
- package/src/client/chat/ChatEntryView.tsx +2 -2
- package/src/client/chat/rollback-entry-view.ts +6 -1
- package/src/client/common/CommandPalette.tsx +6 -3
- package/src/client/common/ConfirmDialog.tsx +29 -12
- package/src/client/common/ContentPicker.tsx +13 -12
- package/src/client/common/Modal.tsx +12 -5
- package/src/client/common/MoreMenu.tsx +4 -1
- package/src/client/common/RunsCenter.tsx +103 -32
- package/src/client/common/Select.tsx +2 -2
- package/src/client/common/floating-bounds.ts +1 -1
- package/src/client/common/floating-units.test.ts +1 -2
- package/src/client/common/plan-text-redaction.test.ts +188 -3
- package/src/client/common/runs-center-guard.test.ts +60 -0
- package/src/client/common/runs-center-view.test.ts +128 -0
- package/src/client/common/runs-center-view.ts +96 -0
- package/src/client/common/section-title-action.test.ts +66 -0
- package/src/client/common/ui.tsx +93 -30
- package/src/client/config-manager.module.css +1507 -272
- package/src/client/consult/ConsultCard.tsx +7 -6
- package/src/client/environment/EnvironmentPanel.tsx +20 -21
- package/src/client/environment/maintenance/DiskUsageCard.tsx +65 -91
- package/src/client/environment/profiles-incomplete-ui.test.ts +8 -8
- package/src/client/export/ExportView.tsx +7 -16
- package/src/client/history/HistoryPanel.tsx +88 -28
- package/src/client/history/history-locales.ts +3 -3
- package/src/client/home/BackupScheduleCard.tsx +35 -30
- package/src/client/home/HomePanel.tsx +45 -10
- package/src/client/import/ConflictList.tsx +13 -13
- package/src/client/import/ForeignImportView.tsx +7 -6
- package/src/client/import/ImportWizardView.tsx +2 -3
- package/src/client/import/PathMappingForm.tsx +4 -4
- package/src/client/import/PathPickerDialog.tsx +2 -1
- package/src/client/import/import-wizard-steps.tsx +51 -39
- package/src/client/import/use-import-wizard-controller.test.ts +129 -0
- package/src/client/import/use-import-wizard-controller.ts +116 -22
- package/src/client/library/ArtifactRow.tsx +2 -2
- package/src/client/library/BackupInspectView.tsx +19 -15
- package/src/client/library/LibraryActions.tsx +56 -16
- package/src/client/library/LibraryPanel.tsx +7 -7
- package/src/client/library/RestorePlanView.tsx +13 -8
- package/src/client/locales/about.ts +0 -2
- package/src/client/locales/backup.ts +10 -12
- package/src/client/locales/common.ts +2 -0
- package/src/client/locales/export.ts +5 -12
- package/src/client/locales/foreign.ts +2 -2
- package/src/client/locales/import.ts +3 -2
- package/src/client/locales/overview.ts +4 -0
- package/src/client/locales/profiles.ts +32 -4
- package/src/client/locales/restore.ts +0 -2
- package/src/client/locales/sessions.ts +0 -2
- package/src/client/locales/shell.ts +2 -2
- package/src/client/market/MarketPanel.tsx +38 -20
- package/src/client/market/MyConfigsList.tsx +34 -32
- package/src/client/market/MyConfigsLoginCard.tsx +12 -15
- package/src/client/market/MyConfigsView.tsx +5 -5
- package/src/client/market/MyConfigsWizard.tsx +7 -12
- package/src/client/market/market-locales.ts +0 -6
- package/src/client/market/my-configs-split.test.ts +2 -1
- package/src/client/nav-menu-clip-guard.test.ts +52 -0
- package/src/client/recovery/IncompleteCopiesSection.tsx +1 -3
- package/src/client/recovery/RecoveryPanel.tsx +31 -16
- package/src/client/recovery/RollbackCard.tsx +58 -16
- package/src/client/recovery/RollbackFileChanges.tsx +40 -27
- package/src/client/recovery/SessionHealthCard.tsx +2 -2
- package/src/client/recovery/SessionHealthDialog.tsx +5 -7
- package/src/client/recovery/SessionLayoutSection.tsx +3 -5
- package/src/client/recovery/recovery-locales.ts +12 -8
- package/src/client/run-store.test.ts +30 -0
- package/src/client/run-store.ts +21 -1
- package/src/client/sync/AddChannelCard.tsx +65 -0
- package/src/client/sync/AutosyncCard.tsx +182 -108
- package/src/client/sync/ChannelClearConfirmDialog.tsx +5 -1
- package/src/client/sync/ChannelConfigDialog.tsx +27 -48
- package/src/client/sync/MergePreviewView.tsx +3 -5
- package/src/client/sync/PushReportSections.tsx +35 -0
- package/src/client/sync/SyncChannelEntryCard.tsx +33 -24
- package/src/client/sync/SyncConfirmView.tsx +3 -3
- package/src/client/sync/SyncLogList.tsx +16 -5
- package/src/client/sync/SyncPanel.tsx +153 -159
- package/src/client/sync/SyncProbeRow.tsx +5 -7
- package/src/client/sync/SyncRepositoryPicker.tsx +17 -4
- package/src/client/sync/SyncSecuritySection.tsx +157 -0
- package/src/client/sync/SyncSettingsDialog.tsx +304 -0
- package/src/client/sync/SyncSettingsView.test.ts +26 -8
- package/src/client/sync/WorkDirCard.tsx +2 -4
- package/src/client/sync/config-clear-guard.test.ts +94 -0
- package/src/client/sync/config-clear-guard.ts +98 -0
- package/src/client/sync/config-dirty.test.ts +91 -0
- package/src/client/sync/config-dirty.ts +88 -0
- package/src/client/sync/history-model.test.ts +2 -0
- package/src/client/sync/history-model.ts +3 -0
- package/src/client/sync/merge-request.ts +20 -0
- package/src/client/sync/sync-api.ts +12 -0
- package/src/client/sync/sync-locales.ts +87 -47
- package/src/client/sync/sync-panel-clear.test.ts +44 -0
- package/src/client/sync/sync-view.test.ts +20 -0
- package/src/client/sync/sync-view.ts +42 -4
- package/src/core/backup.test.ts +61 -1
- package/src/core/backup.ts +21 -4
- package/src/core/boot-rescue.test.ts +35 -0
- package/src/core/boot-rescue.ts +13 -2
- package/src/core/boot-safety.test.ts +25 -0
- package/src/core/boot-safety.ts +37 -2
- package/src/core/conflict-decisions.ts +2 -1
- package/src/core/exporter.ts +21 -1
- package/src/core/journal.test.ts +183 -0
- package/src/core/journal.ts +163 -25
- package/src/core/local-plugin-host.test.ts +68 -2
- package/src/core/local-plugin-host.ts +31 -4
- package/src/core/messages.ts +14 -0
- package/src/core/migration-history.test.ts +27 -0
- package/src/core/migration-history.ts +12 -4
- package/src/core/model-tools.test.ts +67 -0
- package/src/core/model-tools.ts +16 -4
- package/src/core/patch-secret-guard.test.ts +110 -0
- package/src/core/patch-secret-guard.ts +176 -0
- package/src/core/reconcile.ts +32 -4
- package/src/core/reinstall.ts +8 -2
- package/src/core/restore.ts +32 -7
- package/src/core/section-sanitize.ts +37 -0
- package/src/core/snapshot-diff.test.ts +73 -1
- package/src/core/snapshot-diff.ts +66 -21
- package/src/core/startup-barrier.test.ts +64 -0
- package/src/core/startup-barrier.ts +8 -2
- package/src/core/types.ts +27 -1
- package/src/core/update-check.test.ts +40 -0
- package/src/core/update-check.ts +53 -2
- package/src/foreign/claude-code.test.ts +5 -0
- package/src/foreign/claude-plugins.test.ts +57 -0
- package/src/foreign/claude-sessions-bytes.test.ts +7 -1
- package/src/foreign/dsh.test.ts +23 -0
- package/src/foreign/kernel.ts +9 -2
- package/src/foreign/read-claude-plugins.ts +32 -11
- package/src/foreign/read-dsh.ts +33 -2
- package/src/foreign/session-ir.test.ts +67 -0
- package/src/foreign/session-ir.ts +54 -14
- package/src/foreign/session-read.ts +23 -0
- package/src/index.ts +1 -1
- package/src/profiles/dsh-profile-copy-rollback.test.ts +58 -4
- package/src/profiles/dsh-profile-io.ts +29 -0
- package/src/profiles/dsh-profile-manager.test.ts +30 -0
- package/src/profiles/dsh-profile-manager.ts +53 -5
- package/src/profiles/dsh-profile-runtime.test.ts +29 -7
- package/src/profiles/dsh-profile-runtime.ts +17 -3
- package/src/profiles/process-control.test.ts +97 -0
- package/src/profiles/process-control.ts +28 -1
- package/src/routes/profiles.ts +2 -1
- package/src/routes/sync.ts +13 -1
- package/src/schema/types.ts +16 -1
- package/src/security/redaction.test.ts +31 -0
- package/src/security/redaction.ts +23 -6
- package/src/sync/autosync-repeat.test.ts +58 -0
- package/src/sync/autosync-repeat.ts +55 -0
- package/src/sync/autosync-scheduler.test.ts +417 -0
- package/src/sync/autosync-scheduler.ts +154 -41
- package/src/sync/baseline-heal.ts +6 -0
- package/src/sync/baseline-record.ts +135 -0
- package/src/sync/blob-store.test.ts +16 -0
- package/src/sync/blob-store.ts +13 -0
- package/src/sync/content-diff.test.ts +95 -0
- package/src/sync/content-diff.ts +79 -0
- package/src/sync/git/git-transport.test.ts +151 -4
- package/src/sync/git/git-transport.ts +143 -27
- package/src/sync/github-auth.test.ts +26 -1
- package/src/sync/github-auth.ts +37 -1
- package/src/sync/merge-apply-plan.ts +117 -0
- package/src/sync/messages.ts +2 -0
- package/src/sync/pending-merge.ts +77 -0
- package/src/sync/s3/s3-delete-and-blob-index.test.ts +249 -0
- package/src/sync/s3/s3-transport.ts +76 -42
- package/src/sync/sync-config.test.ts +39 -12
- package/src/sync/sync-device-identity.test.ts +3 -0
- package/src/sync/sync-engine.test.ts +465 -12
- package/src/sync/sync-engine.ts +130 -135
- package/src/sync/sync-history.ts +7 -0
- package/src/sync/sync-state.ts +48 -0
- package/src/sync/transport.test.ts +13 -1
- package/src/sync/transport.ts +12 -4
- package/src/sync/webdav/webdav-delete-and-blob-index.test.ts +249 -0
- package/src/sync/webdav/webdav-transport.ts +86 -34
- package/src/ui/commands.test.ts +11 -0
- package/src/ui/commands.ts +5 -14
- package/src/ui/dsh-profiles-view.test.ts +16 -0
- package/src/ui/dsh-profiles-view.ts +11 -5
- package/src/ui/i18n.ts +4 -2
- package/src/ui/menu-placement.ts +1 -1
- package/src/ui/migration-consult-view.test.ts +20 -1
- package/src/ui/migration-consult-view.ts +17 -0
- package/src/ui/overview-view.ts +10 -0
- package/src/ui/report.test.ts +25 -1
- package/src/ui/report.ts +15 -4
- package/src/ui/selection-model.test.ts +15 -1
- package/src/ui/selection-model.ts +18 -0
- package/src/utils/js-yaml4.d.ts +35 -0
- package/src/utils/patch-yaml.test.ts +207 -1
- package/src/utils/patch-yaml.ts +98 -2
- package/src/utils/paths.test.ts +14 -1
- package/src/utils/paths.ts +35 -0
- package/src/utils/workdir-lock.test.ts +69 -0
- package/src/utils/workdir-lock.ts +17 -3
- package/lib/ui/path-mapping.d.ts +0 -38
- package/lib/ui/path-mapping.js +0 -75
- package/src/client/common/InfoHint.tsx +0 -289
- package/src/client/common/info-hint-guard.test.ts +0 -1119
- package/src/client/sync/DecryptPasswordCard.tsx +0 -48
- package/src/client/sync/SecurityOptionsCard.tsx +0 -97
- package/src/client/sync/SyncSectionPickerDialog.tsx +0 -213
- package/src/ui/path-mapping.test.ts +0 -67
- package/src/ui/path-mapping.ts +0 -103
|
@@ -156,6 +156,12 @@ export function synthesizeDshRows(session, hints, stats, now) {
|
|
|
156
156
|
};
|
|
157
157
|
const closeTurn = () => {
|
|
158
158
|
closeStep();
|
|
159
|
+
/**
|
|
160
|
+
* 回合闭合后再到的结果**不许**回填到本回合的调用上:`openCallIds` 是跨 step 共享的 FIFO,
|
|
161
|
+
* 若不在回合边界清空,下一回合缺 id 的 tool_result 会消费到上一回合已结束的 callId
|
|
162
|
+
* (结果落在 turn N+1、却引用 turn N 的调用,DSH 侧配对不上)。
|
|
163
|
+
*/
|
|
164
|
+
openCallIds.length = 0;
|
|
159
165
|
if (turnOpen) {
|
|
160
166
|
push('turn/end', now, { turn, reason: { kind: 'completed' } });
|
|
161
167
|
turnOpen = false;
|
|
@@ -170,6 +176,16 @@ export function synthesizeDshRows(session, hints, stats, now) {
|
|
|
170
176
|
});
|
|
171
177
|
turnOpen = true;
|
|
172
178
|
};
|
|
179
|
+
/** 发一条**人类** user/message(唯一形状出口:两条路径共用,避免字段漂移) */
|
|
180
|
+
const emitUserMessage = (text, at, id) => {
|
|
181
|
+
push('user/message', at, {
|
|
182
|
+
content: [irTextBlock(text)],
|
|
183
|
+
source: { kind: 'user' },
|
|
184
|
+
role: 'user',
|
|
185
|
+
id,
|
|
186
|
+
}, 'append');
|
|
187
|
+
stats.userMessages++;
|
|
188
|
+
};
|
|
173
189
|
for (const message of session.messages) {
|
|
174
190
|
// time 缺省(源没给可解析时间)→ 用调用方的时间兜底;安全整数校验在 IR 层已完成
|
|
175
191
|
const time = message.passthrough?.['time'];
|
|
@@ -178,6 +194,15 @@ export function synthesizeDshRows(session, hints, stats, now) {
|
|
|
178
194
|
if (message.role === 'assistant') {
|
|
179
195
|
const text = irTextOfBlocks(blocks);
|
|
180
196
|
const calls = blocks.filter((b) => b.type === 'tool_call');
|
|
197
|
+
/**
|
|
198
|
+
* 助手记录里携带的 tool_result:本分支只消费 text/tool_call,这类结果**无处归位**
|
|
199
|
+
* (opencode 等来源把 call 与 result 写进同一条记录,由 `splitToolResults` 先拆开;
|
|
200
|
+
* 没拆到这里的不能静默消失)。计数后丢弃 —— 绝不产出悬空引用,也绝不无声丢内容。
|
|
201
|
+
*/
|
|
202
|
+
const assistantResults = blocks.filter((b) => b.type === 'tool_result');
|
|
203
|
+
if (assistantResults.length > 0) {
|
|
204
|
+
irBump(stats.ignored, 'assistant-tool-result', assistantResults.length);
|
|
205
|
+
}
|
|
181
206
|
const source = message.passthrough?.['source'];
|
|
182
207
|
const m = irStr(source?.['model']);
|
|
183
208
|
if (m !== undefined)
|
|
@@ -186,7 +211,9 @@ export function synthesizeDshRows(session, hints, stats, now) {
|
|
|
186
211
|
const providerName = hints.provider === '' ? 'foreign' : hints.provider;
|
|
187
212
|
const modelName = model === '' ? 'unknown' : model;
|
|
188
213
|
if (text.trim() === '' && calls.length === 0) {
|
|
189
|
-
|
|
214
|
+
// 只有 tool_result 的助手记录已按 assistant-tool-result 计数,不再重复记 assistant-empty
|
|
215
|
+
if (assistantResults.length === 0)
|
|
216
|
+
irBump(stats.ignored, 'assistant-empty');
|
|
190
217
|
continue;
|
|
191
218
|
}
|
|
192
219
|
if (!turnOpen)
|
|
@@ -293,8 +320,18 @@ export function synthesizeDshRows(session, hints, stats, now) {
|
|
|
293
320
|
}
|
|
294
321
|
else {
|
|
295
322
|
const idx = openCallIds.indexOf(callId);
|
|
296
|
-
if (idx >= 0)
|
|
323
|
+
if (idx >= 0) {
|
|
297
324
|
openCallIds.splice(idx, 1);
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
/**
|
|
328
|
+
* 非空 id 但不在未决表里 = 悬空引用(调用已在上一回合闭合,或源侧 id 与真正发出的
|
|
329
|
+
* callId 不同)。与「缺 id 且无未决调用」同口径:计数后丢弃,绝不发指向不存在
|
|
330
|
+
* tool/call 的结果(DSH 侧会按损坏流拒读整条会话)。
|
|
331
|
+
*/
|
|
332
|
+
irBump(stats.ignored, 'orphan-tool-result');
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
298
335
|
}
|
|
299
336
|
if (callId === '') {
|
|
300
337
|
irBump(stats.ignored, 'orphan-tool-result');
|
|
@@ -319,6 +356,16 @@ export function synthesizeDshRows(session, hints, stats, now) {
|
|
|
319
356
|
},
|
|
320
357
|
}, 'append');
|
|
321
358
|
}
|
|
359
|
+
/**
|
|
360
|
+
* 同一条 user 记录里既有 tool_result 又有 text(Anthropic 形状里很常见:结果块后跟人类补充):
|
|
361
|
+
* 结果先收进当前 step,文本必须**再发一条真正的 user/message** —— 否则这段用户输入
|
|
362
|
+
* 既到不了目标机、也不进 ignored,属于静默丢失。
|
|
363
|
+
*/
|
|
364
|
+
const trailing = irTextOfBlocks(blocks);
|
|
365
|
+
if (trailing.trim() !== '') {
|
|
366
|
+
closeTurn();
|
|
367
|
+
emitUserMessage(trailing, at, message.id);
|
|
368
|
+
}
|
|
322
369
|
messageIndex++;
|
|
323
370
|
continue;
|
|
324
371
|
}
|
|
@@ -329,13 +376,7 @@ export function synthesizeDshRows(session, hints, stats, now) {
|
|
|
329
376
|
continue;
|
|
330
377
|
}
|
|
331
378
|
closeTurn();
|
|
332
|
-
|
|
333
|
-
content: [irTextBlock(text)],
|
|
334
|
-
source: { kind: 'user' },
|
|
335
|
-
role: 'user',
|
|
336
|
-
id: message.id,
|
|
337
|
-
}, 'append');
|
|
338
|
-
stats.userMessages++;
|
|
379
|
+
emitUserMessage(text, at, message.id);
|
|
339
380
|
messageIndex++;
|
|
340
381
|
}
|
|
341
382
|
closeTurn();
|
|
@@ -11,6 +11,14 @@ export declare function isDirectory(p: string): Promise<boolean>;
|
|
|
11
11
|
export declare function isFile(p: string): Promise<boolean>;
|
|
12
12
|
export declare function listDirSafe(p: string): Promise<Dirent[]>;
|
|
13
13
|
export declare function readBytesSafe(p: string, maxBytes?: number): Promise<Uint8Array | null>;
|
|
14
|
+
/**
|
|
15
|
+
* 只读文件**头部窗口**(审计 P7-7):给「先看 header 再决定要不要整读」的场景用。
|
|
16
|
+
*
|
|
17
|
+
* 与 readBytesSafe 的区别只有一点:不超过 maxBytes 时只取前 maxBytes 字节,而不是整份读。
|
|
18
|
+
* 语义仍守四条硬边界(读不到返回 null、绝不抛、超上限不读)。调用方必须自己处理
|
|
19
|
+
* 「头部窗口不足以判定」的退化路径 —— 不要把它当成整份内容。
|
|
20
|
+
*/
|
|
21
|
+
export declare function readBytesPrefixSafe(p: string, maxBytes: number): Promise<Uint8Array | null>;
|
|
14
22
|
export declare function readTextSafe(p: string, maxBytes?: number): Promise<string | null>;
|
|
15
23
|
/** 读 + 解析 JSON:**失败给出稳定原因**(0 字节与畸形必须能区分 —— 前者是空文件码,后者是解析错) */
|
|
16
24
|
export type JsonReadResult = {
|
|
@@ -55,6 +55,32 @@ export async function readBytesSafe(p, maxBytes = DEFAULT_MAX_FILE_BYTES) {
|
|
|
55
55
|
return null;
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* 只读文件**头部窗口**(审计 P7-7):给「先看 header 再决定要不要整读」的场景用。
|
|
60
|
+
*
|
|
61
|
+
* 与 readBytesSafe 的区别只有一点:不超过 maxBytes 时只取前 maxBytes 字节,而不是整份读。
|
|
62
|
+
* 语义仍守四条硬边界(读不到返回 null、绝不抛、超上限不读)。调用方必须自己处理
|
|
63
|
+
* 「头部窗口不足以判定」的退化路径 —— 不要把它当成整份内容。
|
|
64
|
+
*/
|
|
65
|
+
export async function readBytesPrefixSafe(p, maxBytes) {
|
|
66
|
+
const st = await statOrNull(p);
|
|
67
|
+
if (st === null || !st.isFile() || maxBytes <= 0)
|
|
68
|
+
return null;
|
|
69
|
+
let handle = null;
|
|
70
|
+
try {
|
|
71
|
+
handle = await fs.open(p, 'r');
|
|
72
|
+
const buf = new Uint8Array(Math.min(maxBytes, st.size));
|
|
73
|
+
const { bytesRead } = await handle.read(buf, 0, buf.byteLength, 0);
|
|
74
|
+
return bytesRead === buf.byteLength ? buf : buf.subarray(0, bytesRead);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
if (handle !== null)
|
|
81
|
+
await handle.close().catch(() => undefined);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
58
84
|
export async function readTextSafe(p, maxBytes = DEFAULT_MAX_FILE_BYTES) {
|
|
59
85
|
const st = await statOrNull(p);
|
|
60
86
|
if (st === null || !st.isFile() || st.size > maxBytes)
|
package/lib/index.d.ts
CHANGED
|
@@ -75,7 +75,7 @@ export declare const name = "config-manager";
|
|
|
75
75
|
/** Services required before the engine can mount (present in every profile). */
|
|
76
76
|
export declare const inject: string[];
|
|
77
77
|
/** Plugin version, kept in sync with package.json ("version"). */
|
|
78
|
-
export declare const PLUGIN_VERSION = "0.
|
|
78
|
+
export declare const PLUGIN_VERSION = "0.9.0";
|
|
79
79
|
/**
|
|
80
80
|
* Star 引导弹窗指向的 GitHub 仓库(用户引导点 Star 的目标)。
|
|
81
81
|
* 与 package.json 的 repository 字段保持一致;界面不可改(硬编码,参照
|
package/lib/index.js
CHANGED
|
@@ -149,7 +149,7 @@ export const name = 'config-manager';
|
|
|
149
149
|
/** Services required before the engine can mount (present in every profile). */
|
|
150
150
|
export const inject = ['settings', 'credentials'];
|
|
151
151
|
/** Plugin version, kept in sync with package.json ("version"). */
|
|
152
|
-
export const PLUGIN_VERSION = '0.
|
|
152
|
+
export const PLUGIN_VERSION = '0.9.0';
|
|
153
153
|
/** Plugin own package name — excluded from its own exported plugins list. */
|
|
154
154
|
const PLUGIN_NAME = 'dsh-config-manager';
|
|
155
155
|
/**
|
|
@@ -6,3 +6,23 @@
|
|
|
6
6
|
export declare function readTextSafe(path: string): string | null;
|
|
7
7
|
/** 文件名片段清洗(profile 名已过校验;这里只是防意外字符)。 */
|
|
8
8
|
export declare function sanitizeFilePart(name: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* 运行心跳文件名(**唯一实现**)—— 可读前缀 + 名字哈希。
|
|
11
|
+
*
|
|
12
|
+
* 为什么必须带哈希(审计 P11-2 P1,2026-11-13 实测):心跳文件此前叫
|
|
13
|
+
* `<sanitizeFilePart(name)>.json`,而清洗是**多对一**的 —— `web` 与 `web!` 都落到
|
|
14
|
+
* `web.json`,于是两个实例共享同一个心跳文件:后写的覆盖先写的,`listActive()` 只看得到
|
|
15
|
+
* 一个,`stopExternal` 可能停错人,`withdraw()` 也会删掉别人的心跳(对方从此「不可见」,
|
|
16
|
+
* 界面上又能被重复启动 —— 正是这套机制要防的事)。
|
|
17
|
+
*
|
|
18
|
+
* 判据:清洗只用于可读性(截断到 48 字符、去掉结尾的点/空格,Windows 会吃掉结尾点),
|
|
19
|
+
* **唯一性由 sha256(原名) 的前 12 hex 保证**;\0 之类不可达字符也天然被哈希区隔。
|
|
20
|
+
*/
|
|
21
|
+
export declare function runtimeFileName(name: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* 旧版心跳文件名(升级清理专用):`<sanitizeFilePart(name)>.json`。
|
|
24
|
+
*
|
|
25
|
+
* 只用于「自报/自撤时顺手删掉自己那份旧文件」—— 否则升级后同一个 profile 会留下两份心跳,
|
|
26
|
+
* `listActive` 对同名记录会看到两条。绝不用于读别人的记录。
|
|
27
|
+
*/
|
|
28
|
+
export declare function legacyRuntimeFileName(name: string): string;
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* `sanitizeFilePart`(同一正则)。
|
|
12
12
|
*/
|
|
13
13
|
import { readFileSync } from 'node:fs';
|
|
14
|
+
import { createHash } from 'node:crypto';
|
|
14
15
|
/**
|
|
15
16
|
* 读文本文件;不可读返回 **null** —— 语义差异由调用方显式表达(**不得把 null 统一成 ''**):
|
|
16
17
|
* - 档案管理器用 null 参与「该档案没有清单 → 视为非 DSH profile」的判定;
|
|
@@ -28,4 +29,30 @@ export function readTextSafe(path) {
|
|
|
28
29
|
export function sanitizeFilePart(name) {
|
|
29
30
|
return name.replace(/[^A-Za-z0-9._-]/g, '_');
|
|
30
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* 运行心跳文件名(**唯一实现**)—— 可读前缀 + 名字哈希。
|
|
34
|
+
*
|
|
35
|
+
* 为什么必须带哈希(审计 P11-2 P1,2026-11-13 实测):心跳文件此前叫
|
|
36
|
+
* `<sanitizeFilePart(name)>.json`,而清洗是**多对一**的 —— `web` 与 `web!` 都落到
|
|
37
|
+
* `web.json`,于是两个实例共享同一个心跳文件:后写的覆盖先写的,`listActive()` 只看得到
|
|
38
|
+
* 一个,`stopExternal` 可能停错人,`withdraw()` 也会删掉别人的心跳(对方从此「不可见」,
|
|
39
|
+
* 界面上又能被重复启动 —— 正是这套机制要防的事)。
|
|
40
|
+
*
|
|
41
|
+
* 判据:清洗只用于可读性(截断到 48 字符、去掉结尾的点/空格,Windows 会吃掉结尾点),
|
|
42
|
+
* **唯一性由 sha256(原名) 的前 12 hex 保证**;\0 之类不可达字符也天然被哈希区隔。
|
|
43
|
+
*/
|
|
44
|
+
export function runtimeFileName(name) {
|
|
45
|
+
const readable = sanitizeFilePart(name).replace(/[. ]+$/, '').slice(0, 48);
|
|
46
|
+
const digest = createHash('sha256').update(name, 'utf8').digest('hex').slice(0, 12);
|
|
47
|
+
return readable === '' ? `${digest}.json` : `${readable}-${digest}.json`;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 旧版心跳文件名(升级清理专用):`<sanitizeFilePart(name)>.json`。
|
|
51
|
+
*
|
|
52
|
+
* 只用于「自报/自撤时顺手删掉自己那份旧文件」—— 否则升级后同一个 profile 会留下两份心跳,
|
|
53
|
+
* `listActive` 对同名记录会看到两条。绝不用于读别人的记录。
|
|
54
|
+
*/
|
|
55
|
+
export function legacyRuntimeFileName(name) {
|
|
56
|
+
return `${sanitizeFilePart(name)}.json`;
|
|
57
|
+
}
|
|
31
58
|
//# sourceMappingURL=dsh-profile-io.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type AtomicIoSync } from '../utils/atomic-write.ts';
|
|
1
2
|
import { type DshProfileCopyMarker, type DshProfileCopyWarning, type DshProfileDetail, type DshProfileErrorCode, type DshProfileIncompleteCopy, type DshProfileMeta } from './dsh-profile-shared.ts';
|
|
2
3
|
/** DSH home 下的 profile 根目录名(与 dsh-app-boot 的 PROFILES_DIR 一致)。 */
|
|
3
4
|
export declare const PROFILES_DIR = "profiles";
|
|
@@ -13,6 +14,13 @@ export interface DshProfileManagerOptions {
|
|
|
13
14
|
/** 插件 dataDir(保留给调用方复用;本引擎不再落任何状态) */
|
|
14
15
|
/** 当前运行中的 profile 名(惰性读取,宿主注入) */
|
|
15
16
|
currentProfile?: () => string;
|
|
17
|
+
/**
|
|
18
|
+
* 「复制进行中标记」那一次写盘用的可注入同步 io(缺省 undefined = 真实 fs)。
|
|
19
|
+
*
|
|
20
|
+
* 只给单测用:Windows 上造不出「目录建好、标记写不出来」的真实故障(写完立刻腾空间就失败了),
|
|
21
|
+
* 而这条窄缝恰恰会留下既不在 list() 里、remove() 又报 notFound 的空目录。
|
|
22
|
+
*/
|
|
23
|
+
markerIo?: AtomicIoSync;
|
|
16
24
|
}
|
|
17
25
|
/**
|
|
18
26
|
* t89:残留枚举结果 —— `unreadable` 让「枚举失败」与「确实没有残留」可区分;
|
|
@@ -51,6 +59,8 @@ export declare function rollbackCopiedProfileDir(destDir: string, marker: DshPro
|
|
|
51
59
|
export declare class DshProfileManager {
|
|
52
60
|
private readonly homeDir;
|
|
53
61
|
private readonly currentProfile;
|
|
62
|
+
/** 见 DshProfileManagerOptions.markerIo:只作用于「复制进行中标记」的写入 */
|
|
63
|
+
private readonly markerIo;
|
|
54
64
|
constructor(options: DshProfileManagerOptions);
|
|
55
65
|
/** profiles 根目录(`$DSH_HOME/profiles`) */
|
|
56
66
|
profilesRoot(): string;
|
|
@@ -121,11 +131,28 @@ export declare class DshProfileManager {
|
|
|
121
131
|
remove(name: string, opts?: {
|
|
122
132
|
allowCurrent?: boolean;
|
|
123
133
|
}): void;
|
|
134
|
+
/**
|
|
135
|
+
* remove() 的异步版本:语义、护栏、错误码完全一致,只是不阻塞事件循环(审计 P11-9)。
|
|
136
|
+
*
|
|
137
|
+
* 为什么需要两份:档案目录是整仓里最大的一棵树(含 node_modules,真机 2 万文件)。实测
|
|
138
|
+
* removeTreeSync 删 2 万文件耗 15.5 s,期间宿主 20 ms 定时器 0/776 次触发 —— 心跳、实例
|
|
139
|
+
* 存活探测、同步定时器全停摆,面板表现成「后端卡死」。HTTP 删除走这里;只有确实同步
|
|
140
|
+
* 上下文(脚本、收尾清理)才用 remove(),且必须是自己知道很小的树。
|
|
141
|
+
*/
|
|
142
|
+
removeAsync(name: string, opts?: {
|
|
143
|
+
allowCurrent?: boolean;
|
|
144
|
+
}): Promise<void>;
|
|
124
145
|
/**
|
|
125
146
|
* cross-F3:目标目录 = **正常 profile(有 package.json)** 或 **中断的复制残留(有进行中标记)**;
|
|
126
147
|
* 两者都没有 → notFound。残余标记的目录必须能被定位与删除,否则就是孤儿。
|
|
127
148
|
*/
|
|
128
149
|
private requireManagedDir;
|
|
150
|
+
/**
|
|
151
|
+
* 落「复制进行中标记」(cross-F3 的唯一凭据)。
|
|
152
|
+
*
|
|
153
|
+
* 单独抽出来只为把注入点收窄到这一处写入:调用方(copy)据此保证「标记写失败 ⇒ 目录一起回滚」。
|
|
154
|
+
*/
|
|
155
|
+
private writeCopyMarker;
|
|
129
156
|
/** 复制进行中标记的路径。 */
|
|
130
157
|
private copyMarkerPath;
|
|
131
158
|
/**
|
|
@@ -153,9 +153,12 @@ export async function rollbackCopiedProfileDir(destDir, marker, remove = default
|
|
|
153
153
|
export class DshProfileManager {
|
|
154
154
|
homeDir;
|
|
155
155
|
currentProfile;
|
|
156
|
+
/** 见 DshProfileManagerOptions.markerIo:只作用于「复制进行中标记」的写入 */
|
|
157
|
+
markerIo;
|
|
156
158
|
constructor(options) {
|
|
157
159
|
this.homeDir = options.homeDir;
|
|
158
160
|
this.currentProfile = options.currentProfile ?? (() => 'web');
|
|
161
|
+
this.markerIo = options.markerIo;
|
|
159
162
|
}
|
|
160
163
|
/** profiles 根目录(`$DSH_HOME/profiles`) */
|
|
161
164
|
profilesRoot() {
|
|
@@ -271,9 +274,6 @@ export class DshProfileManager {
|
|
|
271
274
|
throw new DshProfileError('exists');
|
|
272
275
|
const includeNodeModules = opts.includeNodeModules !== false;
|
|
273
276
|
const startedAt = Date.now();
|
|
274
|
-
await mkdir(destDir, { recursive: true });
|
|
275
|
-
// cross-F3:**先落标记再拷文件**。进程被强杀时标记留在目标目录里,使这个半截副本可被
|
|
276
|
-
// 档案列表 / 恢复面板辨识并物理删除;不留标记的话它既不在列表里、删除又报 notFound。
|
|
277
277
|
const marker = {
|
|
278
278
|
sourceName: name,
|
|
279
279
|
newName,
|
|
@@ -281,8 +281,13 @@ export class DshProfileManager {
|
|
|
281
281
|
includeNodeModules,
|
|
282
282
|
pid: process.pid,
|
|
283
283
|
};
|
|
284
|
-
|
|
284
|
+
// 建目录与落标记同属一个回滚范围:标记写不出来时这个目录还没有任何可辨认身份,
|
|
285
|
+
// 留在盘上就是「list() 看不到、remove() 报 notFound」的空壳 —— 必须在 catch 里一并清掉。
|
|
285
286
|
try {
|
|
287
|
+
await mkdir(destDir, { recursive: true });
|
|
288
|
+
// cross-F3:**先落标记再拷文件**。进程被强杀时标记留在目标目录里,使这个半截副本可被
|
|
289
|
+
// 档案列表 / 恢复面板辨识并物理删除;不留标记的话它既不在列表里、删除又报 notFound。
|
|
290
|
+
this.writeCopyMarker(destDir, marker);
|
|
286
291
|
const entries = await readdir(srcDir, { withFileTypes: true });
|
|
287
292
|
for (const entry of entries) {
|
|
288
293
|
// node_modules 与 DSH 投影出来的 .dsh-module-fallback 同进同出(后者的链接都指向前者)
|
|
@@ -435,6 +440,31 @@ export class DshProfileManager {
|
|
|
435
440
|
throw new DshProfileError('deleteFailed', `profile directory still exists after removal: ${dir}`);
|
|
436
441
|
}
|
|
437
442
|
}
|
|
443
|
+
/**
|
|
444
|
+
* remove() 的异步版本:语义、护栏、错误码完全一致,只是不阻塞事件循环(审计 P11-9)。
|
|
445
|
+
*
|
|
446
|
+
* 为什么需要两份:档案目录是整仓里最大的一棵树(含 node_modules,真机 2 万文件)。实测
|
|
447
|
+
* removeTreeSync 删 2 万文件耗 15.5 s,期间宿主 20 ms 定时器 0/776 次触发 —— 心跳、实例
|
|
448
|
+
* 存活探测、同步定时器全停摆,面板表现成「后端卡死」。HTTP 删除走这里;只有确实同步
|
|
449
|
+
* 上下文(脚本、收尾清理)才用 remove(),且必须是自己知道很小的树。
|
|
450
|
+
*/
|
|
451
|
+
async removeAsync(name, opts = {}) {
|
|
452
|
+
if (isManagedProfileName(name))
|
|
453
|
+
throw new DshProfileError('managedProfile');
|
|
454
|
+
const dir = this.requireManagedDir(name);
|
|
455
|
+
if (name === this.currentProfile() && opts.allowCurrent !== true) {
|
|
456
|
+
throw new DshProfileError('currentProfile');
|
|
457
|
+
}
|
|
458
|
+
try {
|
|
459
|
+
await removeTree(dir);
|
|
460
|
+
}
|
|
461
|
+
catch (error) {
|
|
462
|
+
throw new DshProfileError('deleteFailed', error instanceof Error ? error.message : String(error));
|
|
463
|
+
}
|
|
464
|
+
if (existsSync(dir)) {
|
|
465
|
+
throw new DshProfileError('deleteFailed', `profile directory still exists after removal: ${dir}`);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
438
468
|
/**
|
|
439
469
|
* cross-F3:目标目录 = **正常 profile(有 package.json)** 或 **中断的复制残留(有进行中标记)**;
|
|
440
470
|
* 两者都没有 → notFound。残余标记的目录必须能被定位与删除,否则就是孤儿。
|
|
@@ -453,6 +483,17 @@ export class DshProfileManager {
|
|
|
453
483
|
return dir;
|
|
454
484
|
throw new DshProfileError('notFound');
|
|
455
485
|
}
|
|
486
|
+
/**
|
|
487
|
+
* 落「复制进行中标记」(cross-F3 的唯一凭据)。
|
|
488
|
+
*
|
|
489
|
+
* 单独抽出来只为把注入点收窄到这一处写入:调用方(copy)据此保证「标记写失败 ⇒ 目录一起回滚」。
|
|
490
|
+
*/
|
|
491
|
+
writeCopyMarker(dir, marker) {
|
|
492
|
+
atomicWriteFileSync(this.copyMarkerPath(dir), `${JSON.stringify(marker, null, 2)}\n`, {
|
|
493
|
+
mode: 0o644,
|
|
494
|
+
...(this.markerIo === undefined ? {} : { syncIo: this.markerIo }),
|
|
495
|
+
});
|
|
496
|
+
}
|
|
456
497
|
/** 复制进行中标记的路径。 */
|
|
457
498
|
copyMarkerPath(dir) {
|
|
458
499
|
return join(dir, PROFILE_COPY_MARKER_FILENAME);
|
|
@@ -59,8 +59,12 @@ export declare class DshProfileRuntimeRegistry {
|
|
|
59
59
|
constructor(options: DshProfileRuntimeOptions);
|
|
60
60
|
/** 心跳目录(`<dataDir>/running`) */
|
|
61
61
|
dir(): string;
|
|
62
|
-
/** 某个 profile
|
|
62
|
+
/** 某个 profile 的心跳文件绝对路径(名字哈希保证唯一,见 runtimeFileName) */
|
|
63
63
|
fileFor(name: string): string;
|
|
64
|
+
/** 旧版心跳文件(升级清理用:名字清洗多对一,旧文件可能已被别的 profile 覆盖过) */
|
|
65
|
+
private legacyFileFor;
|
|
66
|
+
/** 删掉自己那份旧版心跳(升级后不留双份;不碰别人的文件) */
|
|
67
|
+
private dropLegacyHeartbeat;
|
|
64
68
|
/** 自报/刷新心跳(幂等;apply 时写一次,之后由 startHeartbeat 定期刷)。 */
|
|
65
69
|
announce(): DshProfileRuntimeRecord;
|
|
66
70
|
/** 撤回自己的心跳(dispose 时;正常退出的实例不留垃圾文件)。 */
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
import { existsSync, mkdirSync, readdirSync, rmSync } from 'node:fs';
|
|
20
20
|
import { join } from 'node:path';
|
|
21
21
|
import { atomicWriteFileSync } from '../utils/atomic-write.js';
|
|
22
|
-
import { readTextSafe,
|
|
22
|
+
import { legacyRuntimeFileName, readTextSafe, runtimeFileName } from './dsh-profile-io.js';
|
|
23
23
|
import { DshProfileError } from './dsh-profile-manager.js';
|
|
24
24
|
import { profilesMsg } from './messages.js';
|
|
25
25
|
import { resolveProcessControl, stopPid } from './process-control.js';
|
|
@@ -97,9 +97,20 @@ export class DshProfileRuntimeRegistry {
|
|
|
97
97
|
dir() {
|
|
98
98
|
return join(this.dataDir, RUNTIME_DIR_NAME);
|
|
99
99
|
}
|
|
100
|
-
/** 某个 profile
|
|
100
|
+
/** 某个 profile 的心跳文件绝对路径(名字哈希保证唯一,见 runtimeFileName) */
|
|
101
101
|
fileFor(name) {
|
|
102
|
-
return join(this.dir(),
|
|
102
|
+
return join(this.dir(), runtimeFileName(name));
|
|
103
|
+
}
|
|
104
|
+
/** 旧版心跳文件(升级清理用:名字清洗多对一,旧文件可能已被别的 profile 覆盖过) */
|
|
105
|
+
legacyFileFor(name) {
|
|
106
|
+
return join(this.dir(), legacyRuntimeFileName(name));
|
|
107
|
+
}
|
|
108
|
+
/** 删掉自己那份旧版心跳(升级后不留双份;不碰别人的文件) */
|
|
109
|
+
dropLegacyHeartbeat(name) {
|
|
110
|
+
const legacy = this.legacyFileFor(name);
|
|
111
|
+
if (legacy === this.fileFor(name))
|
|
112
|
+
return;
|
|
113
|
+
rmSync(legacy, { force: true });
|
|
103
114
|
}
|
|
104
115
|
/** 自报/刷新心跳(幂等;apply 时写一次,之后由 startHeartbeat 定期刷)。 */
|
|
105
116
|
announce() {
|
|
@@ -113,11 +124,13 @@ export class DshProfileRuntimeRegistry {
|
|
|
113
124
|
};
|
|
114
125
|
mkdirSync(this.dir(), { recursive: true });
|
|
115
126
|
atomicWriteFileSync(this.fileFor(this.name), `${JSON.stringify(record, null, 2)}\n`, { mode: 0o644 });
|
|
127
|
+
this.dropLegacyHeartbeat(this.name);
|
|
116
128
|
return record;
|
|
117
129
|
}
|
|
118
130
|
/** 撤回自己的心跳(dispose 时;正常退出的实例不留垃圾文件)。 */
|
|
119
131
|
withdraw() {
|
|
120
132
|
rmSync(this.fileFor(this.name), { force: true });
|
|
133
|
+
this.dropLegacyHeartbeat(this.name);
|
|
121
134
|
}
|
|
122
135
|
/**
|
|
123
136
|
* 定时刷新(返回停止函数;调用方必须用 ctx.effect 绑定生命周期)。
|
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
export declare const PROFILE_STOP_GRACE_MS = 6000;
|
|
3
3
|
/** Windows 的优雅期(更短,原因见文件头)。 */
|
|
4
4
|
export declare const PROFILE_STOP_GRACE_MS_WINDOWS = 1500;
|
|
5
|
+
/**
|
|
6
|
+
* 强杀后的**有限等待**(ms):`taskkill /F` 返回 ≠ 进程已消失。
|
|
7
|
+
*
|
|
8
|
+
* Windows 上 TerminateProcess 只是投递终止请求,进程表项与句柄回收是异步的(真机上有几十毫秒窗口);
|
|
9
|
+
* 强杀后立刻回查会把「刚被杀、正在消失」判成 failed,调用方(launcher / runtime)据此抛 stopFailed
|
|
10
|
+
* 并保留心跳 —— 而进程其实已经没了(审计 P11-3)。POSIX 的 SIGKILL 也有同样的(更短的)窗口。
|
|
11
|
+
* 所以强杀后与优雅阶段同构地轮询:窗口内消失即 killed,窗口耗尽才 failed。
|
|
12
|
+
*/
|
|
13
|
+
export declare const PROFILE_FORCE_EXIT_WAIT_MS = 1000;
|
|
14
|
+
/** 强杀后的回查间隔(ms):强杀预期立即生效,轮询比优雅期(200ms)更密。 */
|
|
15
|
+
export declare const PROFILE_FORCE_EXIT_POLL_MS = 50;
|
|
5
16
|
/** 一次停止的终态;failed = 强杀后仍活着(调用方必须如实报错,不许说成已停止)。 */
|
|
6
17
|
export type StopPidOutcome = 'graceful' | 'killed' | 'already-stopped' | 'failed';
|
|
7
18
|
/** 可注入的进程控制副作用(测试用;缺省即真实实现)。 */
|
|
@@ -14,6 +25,8 @@ export interface ProcessControlDeps {
|
|
|
14
25
|
now?: () => number;
|
|
15
26
|
/** 优雅期(缺省按平台:POSIX 6s / Windows 1.5s) */
|
|
16
27
|
graceMs?: number;
|
|
28
|
+
/** 强杀后等待进程消失的上限(缺省 PROFILE_FORCE_EXIT_WAIT_MS) */
|
|
29
|
+
forceWaitMs?: number;
|
|
17
30
|
}
|
|
18
31
|
/** 解析后的进程控制依赖(构造器注入一次,后续只读)。 */
|
|
19
32
|
export interface ResolvedProcessControl {
|
|
@@ -22,13 +35,17 @@ export interface ResolvedProcessControl {
|
|
|
22
35
|
sleep: (ms: number) => Promise<void>;
|
|
23
36
|
now: () => number;
|
|
24
37
|
graceMs: number;
|
|
38
|
+
forceWaitMs: number;
|
|
25
39
|
}
|
|
26
40
|
/** 缺省优雅期(按平台)。 */
|
|
27
41
|
export declare function defaultStopGraceMs(): number;
|
|
28
42
|
export declare function resolveProcessControl(deps?: ProcessControlDeps): ResolvedProcessControl;
|
|
29
43
|
/**
|
|
30
|
-
* 停一个 pid:先优雅 → 等 graceMs → 仍活着则强杀 →
|
|
44
|
+
* 停一个 pid:先优雅 → 等 graceMs → 仍活着则强杀 → 强杀后再等 forceWaitMs → 仍活着才返回 'failed'。
|
|
31
45
|
* 只做进程动作,不碰任何台账/心跳文件(那是调用方的事)。
|
|
46
|
+
*
|
|
47
|
+
* 强杀阶段为什么不能「杀完立刻查一次」:见 PROFILE_FORCE_EXIT_WAIT_MS(审计 P11-3:
|
|
48
|
+
* 立刻回查会把「正在消失」误判成 failed,调用方保留心跳、UI 报「停不掉」,而进程其实已死)。
|
|
32
49
|
*/
|
|
33
50
|
export declare function stopPid(pid: number, deps: ResolvedProcessControl): Promise<StopPidOutcome>;
|
|
34
51
|
/** 真实存活判定:kill(pid, 0);EPERM 说明进程存在但没权限 → 仍视为存活。 */
|
|
@@ -16,6 +16,17 @@ import { setTimeout as delay } from 'node:timers/promises';
|
|
|
16
16
|
export const PROFILE_STOP_GRACE_MS = 6_000;
|
|
17
17
|
/** Windows 的优雅期(更短,原因见文件头)。 */
|
|
18
18
|
export const PROFILE_STOP_GRACE_MS_WINDOWS = 1_500;
|
|
19
|
+
/**
|
|
20
|
+
* 强杀后的**有限等待**(ms):`taskkill /F` 返回 ≠ 进程已消失。
|
|
21
|
+
*
|
|
22
|
+
* Windows 上 TerminateProcess 只是投递终止请求,进程表项与句柄回收是异步的(真机上有几十毫秒窗口);
|
|
23
|
+
* 强杀后立刻回查会把「刚被杀、正在消失」判成 failed,调用方(launcher / runtime)据此抛 stopFailed
|
|
24
|
+
* 并保留心跳 —— 而进程其实已经没了(审计 P11-3)。POSIX 的 SIGKILL 也有同样的(更短的)窗口。
|
|
25
|
+
* 所以强杀后与优雅阶段同构地轮询:窗口内消失即 killed,窗口耗尽才 failed。
|
|
26
|
+
*/
|
|
27
|
+
export const PROFILE_FORCE_EXIT_WAIT_MS = 1_000;
|
|
28
|
+
/** 强杀后的回查间隔(ms):强杀预期立即生效,轮询比优雅期(200ms)更密。 */
|
|
29
|
+
export const PROFILE_FORCE_EXIT_POLL_MS = 50;
|
|
19
30
|
/** 缺省优雅期(按平台)。 */
|
|
20
31
|
export function defaultStopGraceMs() {
|
|
21
32
|
return process.platform === 'win32' ? PROFILE_STOP_GRACE_MS_WINDOWS : PROFILE_STOP_GRACE_MS;
|
|
@@ -27,11 +38,15 @@ export function resolveProcessControl(deps = {}) {
|
|
|
27
38
|
sleep: deps.sleep ?? ((ms) => delay(ms)),
|
|
28
39
|
now: deps.now ?? (() => Date.now()),
|
|
29
40
|
graceMs: deps.graceMs ?? defaultStopGraceMs(),
|
|
41
|
+
forceWaitMs: deps.forceWaitMs ?? PROFILE_FORCE_EXIT_WAIT_MS,
|
|
30
42
|
};
|
|
31
43
|
}
|
|
32
44
|
/**
|
|
33
|
-
* 停一个 pid:先优雅 → 等 graceMs → 仍活着则强杀 →
|
|
45
|
+
* 停一个 pid:先优雅 → 等 graceMs → 仍活着则强杀 → 强杀后再等 forceWaitMs → 仍活着才返回 'failed'。
|
|
34
46
|
* 只做进程动作,不碰任何台账/心跳文件(那是调用方的事)。
|
|
47
|
+
*
|
|
48
|
+
* 强杀阶段为什么不能「杀完立刻查一次」:见 PROFILE_FORCE_EXIT_WAIT_MS(审计 P11-3:
|
|
49
|
+
* 立刻回查会把「正在消失」误判成 failed,调用方保留心跳、UI 报「停不掉」,而进程其实已死)。
|
|
35
50
|
*/
|
|
36
51
|
export async function stopPid(pid, deps) {
|
|
37
52
|
if (!deps.isAlivePid(pid))
|
|
@@ -46,6 +61,15 @@ export async function stopPid(pid, deps) {
|
|
|
46
61
|
if (!deps.isAlivePid(pid))
|
|
47
62
|
return 'graceful';
|
|
48
63
|
deps.killPid(pid, 'force');
|
|
64
|
+
// 与优雅阶段同构:强杀生效是异步的,窗口内消失即 killed,窗口耗尽才 failed。
|
|
65
|
+
// 缺省兜底:直接调 stopPid 且只给了部分 deps 的调用方(脚本/复现)也不该退化成「杀完立刻查一次」。
|
|
66
|
+
const forceWaitMs = deps.forceWaitMs ?? PROFILE_FORCE_EXIT_WAIT_MS;
|
|
67
|
+
const forceDeadline = deps.now() + forceWaitMs;
|
|
68
|
+
while (deps.now() < forceDeadline) {
|
|
69
|
+
if (!deps.isAlivePid(pid))
|
|
70
|
+
return 'killed';
|
|
71
|
+
await deps.sleep(PROFILE_FORCE_EXIT_POLL_MS);
|
|
72
|
+
}
|
|
49
73
|
return deps.isAlivePid(pid) ? 'failed' : 'killed';
|
|
50
74
|
}
|
|
51
75
|
/** 真实存活判定:kill(pid, 0);EPERM 说明进程存在但没权限 → 仍视为存活。 */
|
package/lib/routes/profiles.js
CHANGED
|
@@ -207,7 +207,8 @@ export function profileRoutes(env) {
|
|
|
207
207
|
try {
|
|
208
208
|
if (runningView().some((r) => r.name === name))
|
|
209
209
|
throw new DshProfileError('instanceRunning');
|
|
210
|
-
|
|
210
|
+
// 档案目录是整仓最大的树:异步删除,别让事件循环停摆十几秒(审计 P11-9)。
|
|
211
|
+
await profiles.removeAsync(name, { allowCurrent });
|
|
211
212
|
const historyError = await tryAppendHistory({
|
|
212
213
|
kind: 'profile-delete',
|
|
213
214
|
result: 'success',
|
package/lib/routes/sync.js
CHANGED
|
@@ -230,6 +230,14 @@ export function syncRoutes(env) {
|
|
|
230
230
|
autosync: await buildAutosyncStatus(syncDir, transport),
|
|
231
231
|
// 全部通道的自动同步状态(git/webdav 各自独立;UI 按当前 tab 取对应通道)
|
|
232
232
|
autosyncByChannel: await buildAutosyncStatusByChannel(syncDir),
|
|
233
|
+
// 待裁决分区(P2,2026-11-14 真机事故):远端有比基线新的快照、且自动同步撞上冲突时,
|
|
234
|
+
// sync-state.pendingMerge 会记录「哪些分区等人裁决」与「从什么时候开始挂着的」。
|
|
235
|
+
// 首页「待裁决」徽章据此从纯颜色变成可点击入口(跳同步页打开裁决视图)。
|
|
236
|
+
// **绝不回 remoteSnapshotId**:与 hasBaseline 同一纪律 —— 界面只需要知不知道该裁决,
|
|
237
|
+
// 不需要(也不该拿到)远端快照坐标。
|
|
238
|
+
...(state.pendingMerge === undefined
|
|
239
|
+
? {}
|
|
240
|
+
: { pendingMerge: { sections: [...state.pendingMerge.sections], since: state.pendingMerge.since } }),
|
|
233
241
|
// 工作副本事实(仅 git 且配置了地址时返回;'facts' = 自检成功,'error' = 自检读不出来)
|
|
234
242
|
...(workDir === null ? {} : { workDir }),
|
|
235
243
|
};
|
|
@@ -425,6 +433,9 @@ export function syncRoutes(env) {
|
|
|
425
433
|
const sessionsOpt = sections !== undefined && sections.includes('sessions') && sessions !== undefined
|
|
426
434
|
? { sessions }
|
|
427
435
|
: {};
|
|
436
|
+
// issue #140:强制推送(GUI 等价入口,agent 侧早已有 force)。缺省 false = 内容与远端
|
|
437
|
+
// 最新快照一致时不新建快照(引擎返回 skipped:'unchanged');true 时即使一致也新建。
|
|
438
|
+
const force = body['force'] === true;
|
|
428
439
|
// P0-②:push 前只读预览(body.preview === true → 不写远端,只返回「将推送什么」)
|
|
429
440
|
const preview = body['preview'] === true;
|
|
430
441
|
// 分支调用以保证 withTimeout 的泛型结果类型正确(SyncPushReport | SyncPushPreview)
|
|
@@ -439,6 +450,7 @@ export function syncRoutes(env) {
|
|
|
439
450
|
...(sections === undefined ? {} : { sections }),
|
|
440
451
|
...sessionsOpt,
|
|
441
452
|
...(encrypt || includeSecrets ? { encrypt: true, includeSecrets, password: effectiveEncryptPassword ?? '' } : {}),
|
|
453
|
+
...(force ? { force: true } : {}),
|
|
442
454
|
}), ROUTE_TIMEOUT_MS, msg('host.syncPushTimeout'));
|
|
443
455
|
await writeSyncConfig(syncDir, syncCfg, cloudSecrets);
|
|
444
456
|
writeJson(res, 200, report);
|
|
@@ -963,7 +975,7 @@ export function syncRoutes(env) {
|
|
|
963
975
|
...item,
|
|
964
976
|
kind: 'Update',
|
|
965
977
|
severity: 'info',
|
|
966
|
-
conflict: { itemId: c?.itemId ?? item.id, resolution: 'useImported' },
|
|
978
|
+
conflict: { itemId: c?.itemId ?? item.id, resolution: 'useImported', decidedBy: 'item' },
|
|
967
979
|
}];
|
|
968
980
|
}
|
|
969
981
|
return [item];
|
package/lib/schema/types.d.ts
CHANGED
|
@@ -179,6 +179,17 @@ export interface PatchLine {
|
|
|
179
179
|
file: string;
|
|
180
180
|
lineId: string;
|
|
181
181
|
raw: unknown;
|
|
182
|
+
/**
|
|
183
|
+
* 本行 `raw` 里**被脱敏剥空**的叶子路径(行内相对,如 `raw.mcp.args.token`),issue #136 C。
|
|
184
|
+
*
|
|
185
|
+
* 语义:这些路径上的值**不是**用户在源机写空,而是导出侧 SecretScanner 剥掉的(占位符 = 空串),
|
|
186
|
+
* 目标机不得据此覆盖本机同叶子的非空值。写回侧据此精确保护(见
|
|
187
|
+
* `src/core/patch-secret-guard.ts`)。
|
|
188
|
+
*
|
|
189
|
+
* 兼容:字段只增不改。**缺省 = 未知**(老快照没有这个信息)→ 写回侧走保守分支
|
|
190
|
+
* (导入空 + 本机非空即保留本机),绝不假定「空值一定来自用户主动清空」。
|
|
191
|
+
*/
|
|
192
|
+
redactedPaths?: string[];
|
|
182
193
|
}
|
|
183
194
|
/**
|
|
184
195
|
* 本地源插件的打包产物(T1)。
|