@dsh-cc/settings-migrations 0.5.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/LICENSE +201 -0
- package/README.i18n.yaml +6 -0
- package/README.md +76 -0
- package/README.zh.md +76 -0
- package/lib/index.d.ts +39 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +51 -0
- package/lib/index.js.map +1 -0
- package/lib/migrate.d.ts +68 -0
- package/lib/migrate.d.ts.map +1 -0
- package/lib/migrate.js +118 -0
- package/lib/migrate.js.map +1 -0
- package/package.json +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.i18n.yaml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
|
|
2
|
+
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
|
3
|
+
# after editing either side, bring the other along and re-record with:
|
|
4
|
+
# pnpm run verify-translation-pairing --write packages/settings/settings-migrations/README.md
|
|
5
|
+
README.md: 0b6a83bf901d2dcc5d114d646e0e3386fb779657
|
|
6
|
+
README.zh.md: 8775b046dcecb51630282bec43b56c1eae65abc4
|
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# @dsh-cc/settings-migrations
|
|
2
|
+
|
|
3
|
+
English | [中文](README.zh.md)
|
|
4
|
+
|
|
5
|
+
Claude Code-style settings migration mechanism for the DeepSeek Harness. A versioned `defineMigration` list is applied by `runMigrations()` against an atomically-written `settings.json`, mirroring CC's run-at-startup migrations. The bundled plugin auto-runs pending migrations on mount without ever taking down the host.
|
|
6
|
+
|
|
7
|
+
## Status: mechanism ready, no real migrations yet
|
|
8
|
+
|
|
9
|
+
This batch ships the machinery but **no concrete migrations** — neither cc nor dsh has a legacy settings format to migrate. The first real migration will land with the first settings-shape change (for example a renamed or removed key). Until then the registry is empty and mounting the plugin is a no-op.
|
|
10
|
+
|
|
11
|
+
## Mechanism
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { defineMigration, runMigrations, readMigrationState } from '@dsh-cc/settings-migrations'
|
|
15
|
+
|
|
16
|
+
defineMigration({
|
|
17
|
+
version: 1,
|
|
18
|
+
name: 'rename-field',
|
|
19
|
+
migrate: (ctx) => {
|
|
20
|
+
ctx.settings.theme = ctx.settings['ui-theme'] // mutate the raw settings doc
|
|
21
|
+
delete ctx.settings['ui-theme']
|
|
22
|
+
},
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
await runMigrations() // applies every registered migration
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
- **`defineMigration({ version, name, migrate(ctx) })`** registers a migration into the module registry (deduplicated by `version` + `name`). `ctx.settings` is the mutable raw JSON document; a migration rewrites it in place.
|
|
29
|
+
- **`runMigrations(migrations?, options?)`** applies every migration whose `version` exceeds the recorded `migrationVersion`, in ascending version order. Pass an explicit list for tests/direct invocation, or omit it to use the registry. Options: `home` (harness home), `settingsPath`, `statePath`.
|
|
30
|
+
- **`readMigrationState(statePath)`** returns `{ migrationVersion }`, defaulting to `0` when the state file is absent.
|
|
31
|
+
|
|
32
|
+
## Version storage
|
|
33
|
+
|
|
34
|
+
The recorded version lives in a **dedicated state file** in the harness home (resolved via the harness home-paths tooling — `$DSH_HOME` or `~/.dsh`), defaulting to `<home>/migrations.json`; the settings document defaults to `<home>/settings.json`. The state shape is `{ "migrationVersion": N }`. Both locations are overridable per run / per plugin config for tests and constrained deployments.
|
|
35
|
+
|
|
36
|
+
## Semantics (the contract)
|
|
37
|
+
|
|
38
|
+
- **Ascending version order.** pending = migrations with `version > migrationVersion`, sorted low to high.
|
|
39
|
+
- **Whole-batch atomicity.** The batch succeeds only when every pending migration completes; the version then advances to the latest pending version. A single throw aborts the run: nothing is written and the version stays put, so the next run re-attempts the failing survivors.
|
|
40
|
+
- **Migrations must be idempotent.** Because a mid-batch failure leaves the version behind, earlier migrations in the batch may run again on the next attempt (and CC's startup runner re-runs the whole set). Write your migration so running it twice is harmless — CC's own migrations encode a self-guard on the source data for exactly this reason.
|
|
41
|
+
- **`guard` skips without blocking.** A `guard(ctx)` returning `false` skips that migration but still counts as success for version advancement (CC treats a skipped run as completing the set). A `guard` returning `true` runs the migration.
|
|
42
|
+
- **Atomic write path.** Settings and state are written via a sibling temp file then `rename`, so a reader never observes a partially-written document and no temp files are left behind.
|
|
43
|
+
|
|
44
|
+
## Plugin
|
|
45
|
+
|
|
46
|
+
`name`, `Config`, `apply(ctx, config)`:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
await ctx.plugin(SettingsMigrations, { dshHome, autoRunOnMount: true })
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
| Config | Meaning | Default |
|
|
53
|
+
|---|---|---|
|
|
54
|
+
| `dshHome` | Harness home for the default paths | `$DSH_HOME` or `~/.dsh` |
|
|
55
|
+
| `settingsPath` | `settings.json` override | `<home>/settings.json` |
|
|
56
|
+
| `statePath` | migration state file override | `<home>/migrations.json` |
|
|
57
|
+
| `autoRunOnMount` | run pending migrations on mount | `true` |
|
|
58
|
+
|
|
59
|
+
Mounting runs pending registered migrations (equivalent to CC running migrations at startup). A failed batch never takes down the host: the error is logged as a warning and the recorded version is retained so the next mount re-attempts the survivors.
|
|
60
|
+
|
|
61
|
+
## Install / registration
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import * as SettingsMigrations from '@dsh-cc/settings-migrations'
|
|
65
|
+
await ctx.plugin(SettingsMigrations)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Build order
|
|
69
|
+
|
|
70
|
+
`settings-migrations` depends on the harness base packages (`@deepseek-ai/cordis`, `@deepseek-ai/schemastery`, `@deepseek-ai/dsh-home-paths`, `@deepseek-ai/dsh-invariants`) and no workspace package, so it builds as soon as those are available.
|
|
71
|
+
|
|
72
|
+
## Known limitations
|
|
73
|
+
|
|
74
|
+
- **Mechanism only.** No migrations ship yet; seeding them for local verification is the owner's call per environment.
|
|
75
|
+
- **Single settings document.** The runner targets the user `settings.json`; project/local/flag layers (see `settings-cascade`) are not yet migration targets.
|
|
76
|
+
- **Best-effort failure report.** The plugin warns and retains the version on failure; it does not surface a structured migration report to the seam.
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# @dsh-cc/settings-migrations
|
|
2
|
+
|
|
3
|
+
[English](README.md) | 中文
|
|
4
|
+
|
|
5
|
+
面向 DeepSeek Harness 的 Claude Code 式设置迁移机制。`defineMigration` 定义一个带版本号的迁移,`runMigrations()` 对原子写入的 `settings.json` 应用迁移,对齐 CC 启动时运行的 migration。打包的插件在挂载时自动运行待办迁移,且绝不让宿主崩溃。
|
|
6
|
+
|
|
7
|
+
## 状态:机制就绪,尚无真实迁移
|
|
8
|
+
|
|
9
|
+
本批只交付机制,**不落地具体迁移** —— cc/dsh 目前都没有旧版设置格式需要迁移。首个真实迁移将随首个 settings 格式变更(例如更名或删除某个键)落地。在此之前注册表为空,挂载插件是一个空操作。
|
|
10
|
+
|
|
11
|
+
## 机制
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { defineMigration, runMigrations, readMigrationState } from '@dsh-cc/settings-migrations'
|
|
15
|
+
|
|
16
|
+
defineMigration({
|
|
17
|
+
version: 1,
|
|
18
|
+
name: 'rename-field',
|
|
19
|
+
migrate: (ctx) => {
|
|
20
|
+
ctx.settings.theme = ctx.settings['ui-theme'] // 原地改写原始 settings 文档
|
|
21
|
+
delete ctx.settings['ui-theme']
|
|
22
|
+
},
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
await runMigrations() // 应用所有已注册迁移
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
- **`defineMigration({ version, name, migrate(ctx) })`** 将迁移注册进模块注册表(按 `version` + `name` 去重)。`ctx.settings` 是可变的原始 JSON 文档,迁移在其中原地改写。
|
|
29
|
+
- **`runMigrations(migrations?, options?)`** 应用所有 `version` 大于已记录 `migrationVersion` 的迁移,按版本升序。测试/直调可传入显式列表,省略则使用注册表。选项:`home`(harness 家目录)、`settingsPath`、`statePath`。
|
|
30
|
+
- **`readMigrationState(statePath)`** 返回 `{ migrationVersion }`,状态文件缺失时默认 `0`。
|
|
31
|
+
|
|
32
|
+
## 版本存储
|
|
33
|
+
|
|
34
|
+
已记录版本存放在 harness 家目录下的**独立状态文件**里(经 harness 的 home-paths 工具解析——`$DSH_HOME` 或 `~/.dsh`),默认 `<home>/migrations.json`;settings 文档默认 `<home>/settings.json`。状态形如 `{ "migrationVersion": N }`。测试或受限部署可按次运行/按插件配置覆盖这两个位置。
|
|
35
|
+
|
|
36
|
+
## 语义(即契约)
|
|
37
|
+
|
|
38
|
+
- **版本升序。** 待办 = 满足 `version > migrationVersion` 的迁移,低到高排序。
|
|
39
|
+
- **整批原子性。** 仅当所有待办迁移都完成,批次才算成功,随后版本推进到最新待办版本。任一次抛错即中止运行:不写任何内容、版本保持不变,下次运行会重试失败的幸存者。
|
|
40
|
+
- **迁移器必须幂等。** 因为批次中途失败会留下旧版本,批次中较早的迁移在下次尝试时会再次运行(CC 的启动运行器同样会重跑整套)。请把迁移写成“跑两次也无害”——CC 自身正是为此在源数据上编码了自守条件。
|
|
41
|
+
- **`guard` 跳过不阻塞版本。** `guard(ctx)` 返回 `false` 会跳过该迁移,但仍被当作成功计入版本推进(CC 把跳过视为完成整套)。返回 `true` 则执行迁移。
|
|
42
|
+
- **原子写路径。** settings 与状态均通过同级临时文件再 `rename` 写入,读取方永远不会看到半写文档,也不会残留临时文件。
|
|
43
|
+
|
|
44
|
+
## 插件
|
|
45
|
+
|
|
46
|
+
`name`、`Config`、`apply(ctx, config)`:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
await ctx.plugin(SettingsMigrations, { dshHome, autoRunOnMount: true })
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
| Config | 含义 | 默认 |
|
|
53
|
+
|---|---|---|
|
|
54
|
+
| `dshHome` | 用于默认路径的 harness 家目录 | `$DSH_HOME` 或 `~/.dsh` |
|
|
55
|
+
| `settingsPath` | `settings.json` 覆盖 | `<home>/settings.json` |
|
|
56
|
+
| `statePath` | 迁移状态文件覆盖 | `<home>/migrations.json` |
|
|
57
|
+
| `autoRunOnMount` | 挂载时运行待办迁移 | `true` |
|
|
58
|
+
|
|
59
|
+
挂载即运行待办已注册迁移(等价于 CC 启动时运行迁移)。失败的批次绝不会让宿主崩溃:错误仅记录为警告并保留已记录版本,下次挂载重试幸存者。
|
|
60
|
+
|
|
61
|
+
## 安装 / 注册
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import * as SettingsMigrations from '@dsh-cc/settings-migrations'
|
|
65
|
+
await ctx.plugin(SettingsMigrations)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## 构建顺序
|
|
69
|
+
|
|
70
|
+
`settings-migrations` 只依赖 harness 基础包(`@deepseek-ai/cordis`、`@deepseek-ai/schemastery`、`@deepseek-ai/dsh-home-paths`、`@deepseek-ai/dsh-invariants`),不依赖任何 workspace 包,这些就绪即可构建。
|
|
71
|
+
|
|
72
|
+
## 已知限制
|
|
73
|
+
|
|
74
|
+
- **仅机制。** 尚未携带任何迁移;是否植入用于本地验证的迁移由各环境自行决定。
|
|
75
|
+
- **单份 settings 文档。** 运行器只针对用户 `settings.json`;project/local/flag 各层(见 `settings-cascade`)暂不是迁移目标。
|
|
76
|
+
- **尽力而为的失败上报。** 失败时插件只警告并保留版本,不向 seam 上报结构化的迁移报告。
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code-style settings migration plugin. On mount it runs every registered
|
|
3
|
+
* migration whose version exceeds the recorded `migrationVersion`, mirroring CC's
|
|
4
|
+
* run-at-startup behavior. A failed batch never takes down the host: the error is
|
|
5
|
+
* logged as a warning and the recorded version is retained so the next mount
|
|
6
|
+
* re-attempts the survivors. The mechanism itself — `defineMigration`,
|
|
7
|
+
* `runMigrations`, `readMigrationState` — is exported for direct invocation.
|
|
8
|
+
*
|
|
9
|
+
* This batch ships no real migrations: cc/dsh has no legacy format to migrate yet.
|
|
10
|
+
* The first concrete migration will land with the first settings-shape change.
|
|
11
|
+
* @module @dsh-cc/settings-migrations
|
|
12
|
+
*/
|
|
13
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
14
|
+
import z from '@deepseek-ai/schemastery';
|
|
15
|
+
export { DEFAULT_STATE_FILENAME, defineMigration, listMigrations, readMigrationState, runMigrations, type MigrateOptions, type Migration, type MigrationContext, type MigrationState, } from './migrate.ts';
|
|
16
|
+
/** Cordis plugin id. */
|
|
17
|
+
export declare const name = "settings-migrations";
|
|
18
|
+
/** Plugin configuration: file locations and the auto-run switch. */
|
|
19
|
+
export interface Config {
|
|
20
|
+
/** Harness home used to derive the default settings/state paths. */
|
|
21
|
+
dshHome?: string;
|
|
22
|
+
/** `settings.json` path override (defaults to `<home>/settings.json`). */
|
|
23
|
+
settingsPath?: string;
|
|
24
|
+
/** Migration state path override (defaults to `<home>/migrations.json`). */
|
|
25
|
+
statePath?: string;
|
|
26
|
+
/** Run pending migrations on mount. Defaults to true (CC runs at startup). */
|
|
27
|
+
autoRunOnMount?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** Runtime config schema (all fields optional). */
|
|
30
|
+
export declare const Config: z<Config>;
|
|
31
|
+
/**
|
|
32
|
+
* Mount the migration runner. With `autoRunOnMount` (the default) pending
|
|
33
|
+
* registered migrations run against the resolved settings/state paths; a failure
|
|
34
|
+
* warms but never crashes the host and retains the recorded version.
|
|
35
|
+
* @param ctx - the plug context.
|
|
36
|
+
* @param config - plugin configuration.
|
|
37
|
+
*/
|
|
38
|
+
export declare function apply(ctx: Context, config?: Config): Promise<void>;
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAGxC,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,cAAc,GACpB,MAAM,cAAc,CAAA;AAErB,wBAAwB;AACxB,eAAO,MAAM,IAAI,wBAAwB,CAAA;AAEzC,oEAAoE;AACpE,MAAM,WAAW,MAAM;IACrB,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,0EAA0E;IAC1E,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,4EAA4E;IAC5E,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,8EAA8E;IAC9E,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAED,mDAAmD;AACnD,eAAO,MAAM,MAAM,EAAE,CAAC,CAAC,MAAM,CAK3B,CAAA;AAEF;;;;;;GAMG;AACH,wBAAsB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,GAAE,MAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAa5E"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code-style settings migration plugin. On mount it runs every registered
|
|
3
|
+
* migration whose version exceeds the recorded `migrationVersion`, mirroring CC's
|
|
4
|
+
* run-at-startup behavior. A failed batch never takes down the host: the error is
|
|
5
|
+
* logged as a warning and the recorded version is retained so the next mount
|
|
6
|
+
* re-attempts the survivors. The mechanism itself — `defineMigration`,
|
|
7
|
+
* `runMigrations`, `readMigrationState` — is exported for direct invocation.
|
|
8
|
+
*
|
|
9
|
+
* This batch ships no real migrations: cc/dsh has no legacy format to migrate yet.
|
|
10
|
+
* The first concrete migration will land with the first settings-shape change.
|
|
11
|
+
* @module @dsh-cc/settings-migrations
|
|
12
|
+
*/
|
|
13
|
+
import z from '@deepseek-ai/schemastery';
|
|
14
|
+
import { listMigrations, runMigrations } from "./migrate.js";
|
|
15
|
+
export { DEFAULT_STATE_FILENAME, defineMigration, listMigrations, readMigrationState, runMigrations, } from "./migrate.js";
|
|
16
|
+
/** Cordis plugin id. */
|
|
17
|
+
export const name = 'settings-migrations';
|
|
18
|
+
/** Runtime config schema (all fields optional). */
|
|
19
|
+
export const Config = z.object({
|
|
20
|
+
dshHome: z.string(),
|
|
21
|
+
settingsPath: z.string(),
|
|
22
|
+
statePath: z.string(),
|
|
23
|
+
autoRunOnMount: z.boolean(),
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
26
|
+
* Mount the migration runner. With `autoRunOnMount` (the default) pending
|
|
27
|
+
* registered migrations run against the resolved settings/state paths; a failure
|
|
28
|
+
* warms but never crashes the host and retains the recorded version.
|
|
29
|
+
* @param ctx - the plug context.
|
|
30
|
+
* @param config - plugin configuration.
|
|
31
|
+
*/
|
|
32
|
+
export async function apply(ctx, config = {}) {
|
|
33
|
+
if (config.autoRunOnMount === false)
|
|
34
|
+
return;
|
|
35
|
+
const options = {};
|
|
36
|
+
if (config.dshHome !== undefined)
|
|
37
|
+
options.home = config.dshHome;
|
|
38
|
+
if (config.settingsPath !== undefined)
|
|
39
|
+
options.settingsPath = config.settingsPath;
|
|
40
|
+
if (config.statePath !== undefined)
|
|
41
|
+
options.statePath = config.statePath;
|
|
42
|
+
try {
|
|
43
|
+
const state = await runMigrations(listMigrations(), options);
|
|
44
|
+
ctx.logger.info(`settings-migrations: at migrationVersion ${state.migrationVersion}`);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
// A failed batch must never take down the host: warn and retain the version.
|
|
48
|
+
ctx.logger.warn(`settings-migrations: batch failed, version retained: ${String(error)}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,CAAC,MAAM,0BAA0B,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,aAAa,EAAuB,MAAM,cAAc,CAAA;AAEjF,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,aAAa,GAKd,MAAM,cAAc,CAAA;AAErB,wBAAwB;AACxB,MAAM,CAAC,MAAM,IAAI,GAAG,qBAAqB,CAAA;AAczC,mDAAmD;AACnD,MAAM,CAAC,MAAM,MAAM,GAAc,CAAC,CAAC,MAAM,CAAC;IACxC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE;IACxB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,cAAc,EAAE,CAAC,CAAC,OAAO,EAAE;CAC5B,CAAC,CAAA;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,GAAY,EAAE,SAAiB,EAAE;IAC3D,IAAI,MAAM,CAAC,cAAc,KAAK,KAAK;QAAE,OAAM;IAC3C,MAAM,OAAO,GAAmB,EAAE,CAAA;IAClC,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS;QAAE,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,OAAO,CAAA;IAC/D,IAAI,MAAM,CAAC,YAAY,KAAK,SAAS;QAAE,OAAO,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAA;IACjF,IAAI,MAAM,CAAC,SAAS,KAAK,SAAS;QAAE,OAAO,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAA;IACxE,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,MAAM,aAAa,CAAC,cAAc,EAAE,EAAE,OAAO,CAAC,CAAA;QAC5D,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,4CAA4C,KAAK,CAAC,gBAAgB,EAAE,CAAC,CAAA;IACvF,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,6EAA6E;QAC7E,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,wDAAwD,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IAC1F,CAAC;AACH,CAAC"}
|
package/lib/migrate.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code-style settings migration mechanism. `defineMigration()` registers a
|
|
3
|
+
* versioned, named migration; `runMigrations()` applies every registered migration
|
|
4
|
+
* whose version exceeds the recorded `migrationVersion`, in ascending order, against
|
|
5
|
+
* an atomically-written `settings.json`.
|
|
6
|
+
*
|
|
7
|
+
* The whole batch succeeds only when every pending migration completes: a single
|
|
8
|
+
* throw keeps the old recorded version and leaves the settings document untouched,
|
|
9
|
+
* so the next run re-attempts the failing survivors. A guard returning `false`
|
|
10
|
+
* skips a migration without blocking version advancement (mirroring Claude Code).
|
|
11
|
+
* Migrations MUST be idempotent — see the README for the contract.
|
|
12
|
+
* @module @dsh-cc/settings-migrations
|
|
13
|
+
*/
|
|
14
|
+
/** A migration mutates the raw settings document in place via `ctx.settings`. */
|
|
15
|
+
export interface MigrationContext {
|
|
16
|
+
/** The mutable raw settings document shared across the running batch. */
|
|
17
|
+
settings: Record<string, unknown>;
|
|
18
|
+
}
|
|
19
|
+
/** One versioned, named migration in the Claude Code style. */
|
|
20
|
+
export interface Migration {
|
|
21
|
+
/** Monotonic version; migrations run in ascending version order. */
|
|
22
|
+
version: number;
|
|
23
|
+
/** Human-readable name, surfaced in logs and errors. */
|
|
24
|
+
name: string;
|
|
25
|
+
/** Optional self-guard; a `false` return skips the migration without blocking the batch. */
|
|
26
|
+
guard?(ctx: MigrationContext): boolean | Promise<boolean>;
|
|
27
|
+
/** Apply the migration by mutating `ctx.settings` (must be idempotent). */
|
|
28
|
+
migrate(ctx: MigrationContext): void | Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
/** Recorded migration state document. */
|
|
31
|
+
export interface MigrationState {
|
|
32
|
+
/** The highest migration version whose batch has fully applied. */
|
|
33
|
+
migrationVersion: number;
|
|
34
|
+
}
|
|
35
|
+
/** Options controlling the default file locations for a migration run. */
|
|
36
|
+
export interface MigrateOptions {
|
|
37
|
+
/** Harness home used to derive the default settings/state paths. */
|
|
38
|
+
home?: string;
|
|
39
|
+
/** `settings.json` path; defaults to `<home>/settings.json`. */
|
|
40
|
+
settingsPath?: string;
|
|
41
|
+
/** Migration state file path; defaults to `<home>/migrations.json`. */
|
|
42
|
+
statePath?: string;
|
|
43
|
+
}
|
|
44
|
+
/** Default migration-state filename inside the harness home. */
|
|
45
|
+
export declare const DEFAULT_STATE_FILENAME = "migrations.json";
|
|
46
|
+
/** Read the recorded migration state; an absent file yields version 0. */
|
|
47
|
+
export declare function readMigrationState(statePath: string): Promise<MigrationState>;
|
|
48
|
+
/**
|
|
49
|
+
* Register a migration into the module-level registry, deduplicated by
|
|
50
|
+
* `version` + `name` so re-registration is idempotent. Returns the migration.
|
|
51
|
+
*/
|
|
52
|
+
export declare function defineMigration(migration: Migration): Migration;
|
|
53
|
+
/** Snapshot of the currently registered migrations, ascending by version. */
|
|
54
|
+
export declare function listMigrations(): Migration[];
|
|
55
|
+
/**
|
|
56
|
+
* Apply every migration whose version exceeds the recorded `migrationVersion`, in
|
|
57
|
+
* ascending order, against the settings document. The batch succeeds only when all
|
|
58
|
+
* pending migrations complete (a guard-`false` skip counts as success and does not
|
|
59
|
+
* block version advancement). On success the possibly-mutated settings document is
|
|
60
|
+
* written atomically and the recorded version advances to the latest pending version.
|
|
61
|
+
* A single throw aborts the batch: nothing is written and the version stays put, so
|
|
62
|
+
* the next run re-attempts the failing survivors.
|
|
63
|
+
* @param migrations - the migrations to consider; a snapshot of the registry when omitted.
|
|
64
|
+
* @param options - optional file-location overrides.
|
|
65
|
+
* @returns the recorded state after the run (unchanged when nothing was pending).
|
|
66
|
+
*/
|
|
67
|
+
export declare function runMigrations(migrations?: readonly Migration[], options?: MigrateOptions): Promise<MigrationState>;
|
|
68
|
+
//# sourceMappingURL=migrate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAMH,iFAAiF;AACjF,MAAM,WAAW,gBAAgB;IAC/B,yEAAyE;IACzE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAClC;AAED,+DAA+D;AAC/D,MAAM,WAAW,SAAS;IACxB,oEAAoE;IACpE,OAAO,EAAE,MAAM,CAAA;IACf,wDAAwD;IACxD,IAAI,EAAE,MAAM,CAAA;IACZ,4FAA4F;IAC5F,KAAK,CAAC,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IACzD,2EAA2E;IAC3E,OAAO,CAAC,GAAG,EAAE,gBAAgB,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACrD;AAED,yCAAyC;AACzC,MAAM,WAAW,cAAc;IAC7B,mEAAmE;IACnE,gBAAgB,EAAE,MAAM,CAAA;CACzB;AAED,0EAA0E;AAC1E,MAAM,WAAW,cAAc;IAC7B,oEAAoE;IACpE,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,gEAAgE;IAChE,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,uEAAuE;IACvE,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,gEAAgE;AAChE,eAAO,MAAM,sBAAsB,oBAAoB,CAAA;AA8BvD,0EAA0E;AAC1E,wBAAsB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAInF;AAoBD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,CAK/D;AAED,6EAA6E;AAC7E,wBAAgB,cAAc,IAAI,SAAS,EAAE,CAE5C;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CACjC,UAAU,CAAC,EAAE,SAAS,SAAS,EAAE,EACjC,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,cAAc,CAAC,CAoBzB"}
|
package/lib/migrate.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code-style settings migration mechanism. `defineMigration()` registers a
|
|
3
|
+
* versioned, named migration; `runMigrations()` applies every registered migration
|
|
4
|
+
* whose version exceeds the recorded `migrationVersion`, in ascending order, against
|
|
5
|
+
* an atomically-written `settings.json`.
|
|
6
|
+
*
|
|
7
|
+
* The whole batch succeeds only when every pending migration completes: a single
|
|
8
|
+
* throw keeps the old recorded version and leaves the settings document untouched,
|
|
9
|
+
* so the next run re-attempts the failing survivors. A guard returning `false`
|
|
10
|
+
* skips a migration without blocking version advancement (mirroring Claude Code).
|
|
11
|
+
* Migrations MUST be idempotent — see the README for the contract.
|
|
12
|
+
* @module @dsh-cc/settings-migrations
|
|
13
|
+
*/
|
|
14
|
+
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
15
|
+
import { dirname, join } from 'node:path';
|
|
16
|
+
import { resolveDshHome } from '@deepseek-ai/dsh-home-paths';
|
|
17
|
+
/** Default migration-state filename inside the harness home. */
|
|
18
|
+
export const DEFAULT_STATE_FILENAME = 'migrations.json';
|
|
19
|
+
/** Registry of migrations contributed via {@link defineMigration}. */
|
|
20
|
+
const registry = [];
|
|
21
|
+
function isENOENT(error) {
|
|
22
|
+
return error?.code === 'ENOENT';
|
|
23
|
+
}
|
|
24
|
+
/** Resolve the settings/state paths, defaulting both from the harness home. */
|
|
25
|
+
function resolveOptions(options = {}) {
|
|
26
|
+
const home = resolveDshHome(options.home);
|
|
27
|
+
return {
|
|
28
|
+
settingsPath: options.settingsPath ?? join(home, 'settings.json'),
|
|
29
|
+
statePath: options.statePath ?? join(home, DEFAULT_STATE_FILENAME),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** Read a JSON file, returning `undefined` when it is absent. */
|
|
33
|
+
async function readJson(path) {
|
|
34
|
+
let text;
|
|
35
|
+
try {
|
|
36
|
+
text = await readFile(path, 'utf8');
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (isENOENT(error))
|
|
40
|
+
return undefined;
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
return JSON.parse(text);
|
|
44
|
+
}
|
|
45
|
+
/** Read the recorded migration state; an absent file yields version 0. */
|
|
46
|
+
export async function readMigrationState(statePath) {
|
|
47
|
+
const state = await readJson(statePath);
|
|
48
|
+
const version = typeof state?.migrationVersion === 'number' ? state.migrationVersion : 0;
|
|
49
|
+
return { migrationVersion: version };
|
|
50
|
+
}
|
|
51
|
+
/** Read the raw settings document; an absent file yields an empty object. */
|
|
52
|
+
async function readSettingsDocument(path) {
|
|
53
|
+
const doc = await readJson(path);
|
|
54
|
+
if (doc === undefined)
|
|
55
|
+
return {};
|
|
56
|
+
if (typeof doc !== 'object' || doc === null || Array.isArray(doc)) {
|
|
57
|
+
throw new TypeError(`settings-migrations: ${path} must be a JSON object`);
|
|
58
|
+
}
|
|
59
|
+
return doc;
|
|
60
|
+
}
|
|
61
|
+
/** Write a file atomically: write to a sibling temp path, then rename into place. */
|
|
62
|
+
async function writeJsonAtomic(path, value) {
|
|
63
|
+
await mkdir(dirname(path), { recursive: true });
|
|
64
|
+
const tmp = `${path}.tmp`;
|
|
65
|
+
await writeFile(tmp, JSON.stringify(value, null, 2), 'utf8');
|
|
66
|
+
await rename(tmp, path);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Register a migration into the module-level registry, deduplicated by
|
|
70
|
+
* `version` + `name` so re-registration is idempotent. Returns the migration.
|
|
71
|
+
*/
|
|
72
|
+
export function defineMigration(migration) {
|
|
73
|
+
const index = registry.findIndex(m => m.version === migration.version && m.name === migration.name);
|
|
74
|
+
if (index === -1)
|
|
75
|
+
registry.push(migration);
|
|
76
|
+
else
|
|
77
|
+
registry[index] = migration;
|
|
78
|
+
return migration;
|
|
79
|
+
}
|
|
80
|
+
/** Snapshot of the currently registered migrations, ascending by version. */
|
|
81
|
+
export function listMigrations() {
|
|
82
|
+
return [...registry].sort((a, b) => a.version - b.version);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Apply every migration whose version exceeds the recorded `migrationVersion`, in
|
|
86
|
+
* ascending order, against the settings document. The batch succeeds only when all
|
|
87
|
+
* pending migrations complete (a guard-`false` skip counts as success and does not
|
|
88
|
+
* block version advancement). On success the possibly-mutated settings document is
|
|
89
|
+
* written atomically and the recorded version advances to the latest pending version.
|
|
90
|
+
* A single throw aborts the batch: nothing is written and the version stays put, so
|
|
91
|
+
* the next run re-attempts the failing survivors.
|
|
92
|
+
* @param migrations - the migrations to consider; a snapshot of the registry when omitted.
|
|
93
|
+
* @param options - optional file-location overrides.
|
|
94
|
+
* @returns the recorded state after the run (unchanged when nothing was pending).
|
|
95
|
+
*/
|
|
96
|
+
export async function runMigrations(migrations, options) {
|
|
97
|
+
const list = migrations ?? listMigrations();
|
|
98
|
+
const { settingsPath, statePath } = resolveOptions(options);
|
|
99
|
+
const settings = await readSettingsDocument(settingsPath);
|
|
100
|
+
const state = await readMigrationState(statePath);
|
|
101
|
+
const pending = list
|
|
102
|
+
.filter(m => m.version > state.migrationVersion)
|
|
103
|
+
.sort((a, b) => a.version - b.version);
|
|
104
|
+
if (pending.length === 0)
|
|
105
|
+
return state;
|
|
106
|
+
const context = { settings };
|
|
107
|
+
for (const migration of pending) {
|
|
108
|
+
if (migration.guard !== undefined && !(await migration.guard(context)))
|
|
109
|
+
continue;
|
|
110
|
+
await migration.migrate(context);
|
|
111
|
+
}
|
|
112
|
+
const latest = pending[pending.length - 1].version;
|
|
113
|
+
const next = { migrationVersion: latest };
|
|
114
|
+
await writeJsonAtomic(settingsPath, settings);
|
|
115
|
+
await writeJsonAtomic(statePath, next);
|
|
116
|
+
return next;
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=migrate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate.js","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dsh-cc/settings-migrations",
|
|
3
|
+
"description": "Claude Code-style settings migration mechanism for the DeepSeek Harness: defineMigration list, version-gated runMigrations, and an atomic read/write settings.json seam",
|
|
4
|
+
"version": "0.5.0",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/dsh-cc/dsh-cc.git",
|
|
8
|
+
"directory": "packages/settings/settings-migrations"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./lib/index.d.ts",
|
|
14
|
+
"default": "./lib/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./src/*": "./src/*",
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"lib"
|
|
21
|
+
],
|
|
22
|
+
"license": "Apache-2.0",
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@deepseek-ai/dsh-home-paths": ">=0.1.1-rc.2",
|
|
25
|
+
"@deepseek-ai/dsh-invariants": ">=0.1.1-rc.2",
|
|
26
|
+
"@deepseek-ai/cordis": ">=0.1.1-rc.2",
|
|
27
|
+
"@deepseek-ai/schemastery": ">=0.1.1-rc.2"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@deepseek-ai/dsh-home-paths": "link:../../../../deepseek-harness/packages/util/home-paths",
|
|
31
|
+
"@deepseek-ai/dsh-invariants": "link:../../../../deepseek-harness/packages/runtime-diagnostics/invariants",
|
|
32
|
+
"@deepseek-ai/cordis": "link:../../../../deepseek-harness/vendor/cordis",
|
|
33
|
+
"@deepseek-ai/schemastery": "link:../../../../deepseek-harness/vendor/schemastery"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
}
|
|
38
|
+
}
|