@dsh-cc/settings-cascade 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 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.
@@ -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-cascade/README.md
5
+ README.md: db5b2923ecf21475673eee83e27fc76de1f8caa3
6
+ README.zh.md: e57ba534c84da51f4ec75e398c2ebcc54e4703fe
package/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # @dsh-cc/settings-cascade
2
+
3
+ English | [中文](README.zh.md)
4
+
5
+ Claude Code-style five-level settings cascade provider for `ctx.settings`. Five sources merge low-to-high — user settings, project settings, local settings, flag settings, policy settings — under a plugin-default base. The merged raw document feeds the user-settings seam, whose namespace resolution layers schema defaults, the registrant `base`, and this user layer in turn.
6
+
7
+ ## Config
8
+
9
+ | Field | Meaning | Default |
10
+ |---|---|---|
11
+ | `userSettingsPath` | User settings file | `settings.json` under the harness home |
12
+ | `projectSettingsPath` | Project settings file | `<project>/.claude/settings.json` |
13
+ | `localSettingsPath` | Local (gitignored) settings file | git main-checkout root (linked worktree) or git toplevel `.claude/settings.local.json` |
14
+ | `flagSettingsPath` | Command-line `--settings` file | none |
15
+ | `flagSettingsInline` | Inline `--settings` content, merged over the flag file | none |
16
+ | `projectDir` | Seeds the **project** settings path and is the launch directory for the git probe behind the local settings path | current working directory |
17
+ | `dshHome` | Harness home for the default user settings path | `$DSH_HOME` or `~/.dsh` |
18
+ | `policy.remoteSettings` | Hosted policy settings; highest policy priority | none |
19
+ | `policy.systemPath` | System-level managed settings file | none |
20
+ | `policy.userPath` | User-writable managed settings file | none |
21
+
22
+ Defaulting is one explicit `resolveSpec(config)` step.
23
+
24
+ ## Behavior
25
+
26
+ - **Priority order from low to high.** user < project < local < flag < policy. Sources deep-merge recursively; a higher source fills keys a lower one omitted and replaces the values it does carry.
27
+ - **Plugin defaults sit at the bottom.** Registration `base` and schema defaults resolve below every file source, so a missing document resolves exactly as a leaf provider would.
28
+ - **Permission arrays union, `deny` wins.** `allow`, `deny`, and `ask` rule arrays concatenate and deduplicate across layers, and the unioned `deny` set is removed from `allow` — a higher-layer deny always beats a lower-layer allow. Empty permission arrays are omitted. Other arrays (for example `additionalDirectories`) let the higher layer override wholesale.
29
+ - **Policy is first-source-wins.** The policy layer takes the first non-empty of its sub-sources in priority order: remote > system file > user file. An empty or absent higher source falls through to the next.
30
+ - **Flag settings merge file-then-inline.** If both a `--settings` file and inline content are present, the inline content merges over the file within the flag layer.
31
+ - **Misconfiguration fails loud.** A present-but-invalid settings document (unparsable JSON, or a non-object root) fails plugin load; an absent source file contributes nothing and is not an error.
32
+ - **The provider is writable through the user layer.** `writable` is `true`, so the seam's in-process `update()`/`replace()`/`mutate()` paths are accepted. A write is applied as a surgical delta onto the user-layer settings file (default `$DSH_HOME/settings.json`): only the keys the caller actually changed land in the user file. Values the write did not touch are not copied in, even if they were inherited from a higher layer. The seam still owns validation, revision, and update events; project/local/flag/policy sources remain read-side-only contributors.
33
+ - **The local settings file path hoists git-style.** When the launch directory is a git worktree or a subdirectory of a git repo, `.claude/settings.local.json` is read from the git **main checkout root** (worktree) or **toplevel** (subdirectory start), matching Claude Code. Project `settings.json` stays at the launch directory, the session cwd and git operations are unaffected, and paths *inside* the file still resolve against the launch directory. Fallbacks that keep the file at the launch directory: not a git repo, Windows (`win32`), the repo root is `$HOME`, a bare-main hoist target without `.git`, a git probe failure, or ownership of the repo root / `.git` / `.claude` not confirmed as the current user (fail-closed). A worktree-local `settings.local.json` is silently not loaded (merging both is unconfirmed in Claude Code). No hot-reload: entering a worktree mid-session does not re-resolve.
34
+ - **CC camelCase keys alias onto kebab namespaces.** After the five-layer merge (and before publish), a fixed whitelist of Claude Code camelCase top-level keys (`statusLine` → `statusline`) is copied onto its dsh-native kebab namespace. The alias is injected only when the CC key's value is a plain object AND the kebab key is absent from the merged document — a dsh-native key already present wins untouched, and non-object CC values are ignored. No fuzzy matching: the whitelist map is the contract; unknown camelCase keys are never aliased.
35
+ - **`env` applies in two stages.** A top-level `env` section is split out of the merged document and exposed through `getEnv()` with every value coerced to a string. `applyEnv()` assigns ordinary variables; `applyTrustedEnv()` additionally assigns environment-altering variables (`LD_PRELOAD`, `PATH`, `DYLD_INSERT_LIBRARIES`, and the other `DANGEROUS_ENV_VARS`) and runs only after the user grants trust.
36
+
37
+ ## Permissions schema
38
+
39
+ The `permissions` field schema (`allow`, `deny`, `ask`, `defaultMode`, `disableBypassPermissionsMode`, `additionalDirectories`, `protectedFiles`, `dangerousPatterns`), matching Claude Code's settings.json, is exported as `PermissionsSchema` (with `PermissionRuleSchema` and `PERMISSION_MODES`) for the permission-rule engine. The optional LLM risk-classifier section is exported as `AutoModeSchema` (delivered as `permissions.autoMode`, not a root-level `autoMode` key — a documented deviation from Claude Code's settings surface).
40
+
41
+ ## Model Experience
42
+
43
+ Indirectly, through consumers of `ctx.settings`: composition remains the read model, with writes supported through the user layer, and each consumer's own surface documents any model effect.
44
+
45
+ #### KV Cache effect
46
+
47
+ No direct invalidation; the consuming plugin owns any request-prefix changes.
48
+
49
+ ## Known Limitations and Deferred Work
50
+
51
+ - **JSON-only sources.** Sources must be `.json` (the settings.json convention); YAML is deferred.
52
+ - **Unsetting an inherited key is not persisted.** Unsetting a key that comes from a lower-priority source (project/local/flag/policy) cannot be persisted to the user file; the unset holds for the running process, but the value reappears on restart. Also, `describe()`'s `user` field reflects the merged section rather than the literal user file, so GUI override markers are approximate (pre-existing behavior).
53
+ - **Concurrent writers can lose updates.** Concurrent writes from multiple dsh processes to the same user settings file can silently lose updates — atomic rename prevents file corruption, not lost writes; the stock provider's cross-process lock was dropped for this port. Single-process profiles (the norm) are unaffected.
54
+ - **Writes go to the user layer, not the hoisted local file.** `persist()` writes to the user settings file (pre-existing); an always-allow granted in a worktree therefore still does not update the main checkout's `settings.local.json`.
55
+ - **No file hot-reload.** External edits to any source file take effect only on restart (pre-existing).
56
+ - **No per-source provenance.** The merged result does not record which source supplied each resolved value, and `describe()` cannot mark a field's origin across the five layers the way a single user layer does.
57
+ - **Dangerous env is a static allowlist.** `DANGEROUS_ENV_VARS` names a fixed set; deployment-specific variables need an explicit extension point before first use.
package/README.zh.md ADDED
@@ -0,0 +1,56 @@
1
+ # @dsh-cc/settings-cascade
2
+
3
+ [English](README.md) | 中文
4
+
5
+ 面向 `ctx.settings` 的 Claude Code 风格五级设置级联提供方。五级来源按优先级从低到高合并——用户设置、项目设置、本地设置、flag 设置、策略设置——其下是插件默认基底。合并后的原始文档进入用户设置 seam,其 namespace 解析按 schema 默认、注册方 `base`、本用户层依次叠放。
6
+
7
+ ## 配置
8
+
9
+ | 字段 | 含义 | 默认 |
10
+ |---|---|---|
11
+ | `userSettingsPath` | 用户设置文件 | harness home 下的 `settings.json` |
12
+ | `projectSettingsPath` | 项目设置文件 | `<project>/.claude/settings.json` |
13
+ | `localSettingsPath` | 本地(被 git 忽略的)设置文件 | git 主检出根(linked worktree)或 git 顶层目录下的 `.claude/settings.local.json` |
14
+ | `flagSettingsPath` | 命令行 `--settings` 文件 | 无 |
15
+ | `flagSettingsInline` | 内联 `--settings` 内容,在 flag 文件之上合并 | 无 |
16
+ | `projectDir` | 决定**项目**设置路径,并作为本地设置路径 git 探测的启动目录 | 当前工作目录 |
17
+ | `dshHome` | 默认用户设置路径所用的 harness home | `$DSH_HOME` 或 `~/.dsh` |
18
+ | `policy.remoteSettings` | 托管策略设置;策略最高优先级 | 无 |
19
+ | `policy.systemPath` | 系统级托管设置文件 | 无 |
20
+ | `policy.userPath` | 用户可写的托管设置文件 | 无 |
21
+
22
+ 默认值解析是一步显式的 `resolveSpec(config)`。
23
+
24
+ ## 行为
25
+
26
+ - **优先级从低到高。** user < project < local < flag < policy。各来源递归深合并;高层来源补上低层缺失的键,并替换其携带的值。
27
+ - **插件默认位于最底层。** 注册 `base` 与 schema 默认值解析于每个文件来源之下,因此文档缺失时解析结果与叶子提供方完全一致。
28
+ - **权限数组取并集,`deny` 优先。** `allow`、`deny`、`ask` 规则数组跨层拼接去重,合并后的 `deny` 集合会从 `allow` 中剔除——高层 deny 始终压过低层 allow。空的权限数组被省略。其余数组(例如 `additionalDirectories`)由高层整体覆盖。
29
+ - **策略是首个来源胜出。** 策略层按其子来源优先级取第一个非空者:remote > 系统文件 > 用户文件。较高来源为空或缺失时回退到下一来源。
30
+ - **flag 设置先文件后内联。** 若同时存在 `--settings` 文件与内联内容,内联内容在 flag 层内部覆盖文件。
31
+ - **坏配置加载期明确报错。** 存在但非法的设置文档(不可解析的 JSON,或非对象根)使插件加载失败;来源文件缺失不算错误,不贡献任何内容。
32
+ - **提供方经用户层可写。** `writable` 为 `true`,seam 的进程内 `update()`/`replace()`/`mutate()` 路径被接受。写入以 surgical delta(外科手术式增量)应用到用户层设置文件(默认 `$DSH_HOME/settings.json`):只有调用方实际改动的键才落入用户文件。写入未触及的值——即使源自更高层——也不会被带进来。校验、修订号与更新事件仍由 seam 负责;project/local/flag/policy 来源仍是只读侧贡献者。
33
+ - **本地设置文件路径按 git 语义上提。** 启动目录位于 git worktree 或 git 仓库子目录时,`.claude/settings.local.json` 改从 git **主检出根**(worktree)或**顶层目录**(子目录启动)读取,与 Claude Code 一致。项目 `settings.json` 仍留在启动目录,会话 cwd 与 git 操作不受影响,文件内部的路径仍相对启动目录解析。以下情形回退到启动目录本身:非 git 仓库、Windows(`win32`)、仓库根为 `$HOME`、上提目标缺少 `.git` 的裸主仓库、git 探测失败,或仓库根 / `.git` / `.claude` 的属主未确认为当前用户(fail-closed)。worktree 本地的 `settings.local.json` 不会被读取(两者合并的行为在 Claude Code 中未确认)。无热重载:会话中途进入 worktree 不会重新解析。
34
+ - **`env` 分两阶段应用。** 顶层 `env` 分节从合并文档中拆出,经 `getEnv()` 暴露,所有值已强制转为字符串。`applyEnv()` 赋值普通变量;`applyTrustedEnv()` 另赋值改变环境的变量(`LD_PRELOAD`、`PATH`、`DYLD_INSERT_LIBRARIES` 及其余 `DANGEROUS_ENV_VARS`),仅在用户授予信任后运行。
35
+
36
+ ## 权限 schema
37
+
38
+ `permissions` 字段 schema(`allow`、`deny`、`ask`、`defaultMode`、`disableBypassPermissionsMode`、`additionalDirectories`、`protectedFiles`、`dangerousPatterns`)与 Claude Code 的 settings.json 一致,以 `PermissionsSchema` 导出(连同 `PermissionRuleSchema` 与 `PERMISSION_MODES`),供权限规则引擎使用。
39
+
40
+ ## 模型体验
41
+
42
+ 间接生效:组合仍是读模型,写入经用户层得到支持;任何模型效果都经由 `ctx.settings` 的消费方产生,并由各消费方自己的接口文档说明。
43
+
44
+ #### KV Cache 影响
45
+
46
+ 无直接失效;请求前缀的任何变更均由消费方插件负责。
47
+
48
+ ## 已知限制与暂缓事项
49
+
50
+ - **仅 JSON 来源。** 来源必须是 `.json`(settings.json 惯例);YAML 暂缓实现。
51
+ - **取消继承键不落盘。** 取消一个来自更低优先级来源(project/local/flag/policy)的键无法写入用户文件;该取消对运行中的进程生效,但重启后该值重现。此外,`describe()` 的 `user` 字段反映合并段而非用户文件实含量,因此 GUI 的 override 标记为近似(既有行为)。
52
+ - **并发写入可能丢更新。** 多个 dsh 进程并发写同一个用户设置文件可能静默丢失更新——原子 rename 只防文件损坏、不防丢写;原生提供方的跨进程锁已在本移植中移除。单进程配置(通常情况)不受影响。
53
+ - **写入仍走用户层,而非上提后的本地文件。** `persist()` 写入用户设置文件(既有行为);因此在 worktree 中授予的 always-allow 仍不会更新主检出的 `settings.local.json`。
54
+ - **无文件热重载。** 任何来源文件的外部编辑均在重启后才生效(既有)。
55
+ - **无逐来源出处。** 合并结果不记录每个解析值来自哪个来源,`describe()` 也无法像单一用户层那样标注字段在五层之间的出处。
56
+ - **危险环境变量是静态白名单。** `DANGEROUS_ENV_VARS` 命名固定集合;部署专属变量在首次使用前需要显式的扩展点。
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Claude Code-compatible `autoMode` schema — the settings surface for the LLM
3
+ * risk classifier (design doc §4.5). The delivery route is the `autoMode` key
4
+ * INSIDE the existing `permissions` namespace (`permissions.autoMode`), not a
5
+ * root-level key: top-level settings namespaces must be kebab-case upstream,
6
+ * so Claude Code's root `autoMode` location is a documented deviation (the
7
+ * cascade registers no root `autoMode` namespace). Exported as a standalone
8
+ * value so the settings cascade and the permission-rules plugin (which
9
+ * hand-mirrors the shape) share one definition of the section.
10
+ * @module @dsh-cc/settings-cascade/auto-mode
11
+ */
12
+ import z from '@deepseek-ai/schemastery';
13
+ /** `autoMode.classifier` — only defaults apply when the object itself is present. */
14
+ export interface AutoModeClassifier {
15
+ /** Master switch for the LLM risk classifier stage (default `false`). */
16
+ enabled?: boolean;
17
+ /** Model route used for classification (default `'haiku'`). */
18
+ route?: string;
19
+ /** Per-call timeout in milliseconds (default `8000`). */
20
+ timeoutMs?: number;
21
+ /** Verdict cache size in entries (default `256`). */
22
+ cacheMaxEntries?: number;
23
+ }
24
+ /** The `autoMode` section (delivered as `permissions.autoMode`). */
25
+ export interface AutoMode {
26
+ /**
27
+ * Soft-deny hints evaluated by the classifier, in CC's snake_case spelling.
28
+ * `$defaults` expansion happens at consumption time in the classifier
29
+ * module — the schema never expands it, so merging never sees the expansion.
30
+ */
31
+ soft_deny?: string[];
32
+ /** LLM risk classifier configuration; absent when the section omits it. */
33
+ classifier?: AutoModeClassifier;
34
+ }
35
+ /**
36
+ * Schemastery schema for `autoMode.classifier`. Defaults apply only when the
37
+ * object itself is present (the parent uses a union-with-`undefined` so an
38
+ * absent key stays absent instead of materializing defaults).
39
+ */
40
+ export declare const AutoModeClassifierSchema: z<AutoModeClassifier>;
41
+ /**
42
+ * Schemastery schema for the `autoMode` section. The section itself stays
43
+ * `undefined` when absent from every settings layer — the classifier remains
44
+ * disarmed.
45
+ */
46
+ export declare const AutoModeSchema: z<AutoMode | undefined>;
47
+ //# sourceMappingURL=auto-mode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto-mode.d.ts","sourceRoot":"","sources":["../src/auto-mode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAExC,qFAAqF;AACrF,MAAM,WAAW,kBAAkB;IACjC,yEAAyE;IACzE,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,yDAAyD;IACzD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,qDAAqD;IACrD,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB;AAED,oEAAoE;AACpE,MAAM,WAAW,QAAQ;IACvB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB,2EAA2E;IAC3E,UAAU,CAAC,EAAE,kBAAkB,CAAA;CAChC;AAED;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,EAAE,CAAC,CAAC,kBAAkB,CAKzD,CAAA;AAgBF;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,CAAC,CAAC,QAAQ,GAAG,SAAS,CAGtB,CAAA"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Claude Code-compatible `autoMode` schema — the settings surface for the LLM
3
+ * risk classifier (design doc §4.5). The delivery route is the `autoMode` key
4
+ * INSIDE the existing `permissions` namespace (`permissions.autoMode`), not a
5
+ * root-level key: top-level settings namespaces must be kebab-case upstream,
6
+ * so Claude Code's root `autoMode` location is a documented deviation (the
7
+ * cascade registers no root `autoMode` namespace). Exported as a standalone
8
+ * value so the settings cascade and the permission-rules plugin (which
9
+ * hand-mirrors the shape) share one definition of the section.
10
+ * @module @dsh-cc/settings-cascade/auto-mode
11
+ */
12
+ import z from '@deepseek-ai/schemastery';
13
+ /**
14
+ * Schemastery schema for `autoMode.classifier`. Defaults apply only when the
15
+ * object itself is present (the parent uses a union-with-`undefined` so an
16
+ * absent key stays absent instead of materializing defaults).
17
+ */
18
+ export const AutoModeClassifierSchema = z.object({
19
+ enabled: z.boolean().default(false),
20
+ route: z.string().default('haiku'),
21
+ timeoutMs: z.number().default(8000),
22
+ cacheMaxEntries: z.number().default(256),
23
+ });
24
+ /**
25
+ * Schemastery schema for the `autoMode` section body. Unknown fields pass
26
+ * through unmodified, matching {@link PermissionsSchema}. Sub-keys stay
27
+ * absent when absent from every settings layer.
28
+ */
29
+ const AutoModeSectionSchema = z.object({
30
+ // Union with `undefined` keeps an absent `soft_deny` key absent — no empty
31
+ // array is materialized (permissive array, no default).
32
+ soft_deny: z.union([z.array(z.string()), z.const(undefined)]),
33
+ // Union with `undefined` keeps an absent `classifier` key absent; a present
34
+ // object resolves through AutoModeClassifierSchema (defaults apply there).
35
+ classifier: z.union([AutoModeClassifierSchema, z.const(undefined)]),
36
+ });
37
+ /**
38
+ * Schemastery schema for the `autoMode` section. The section itself stays
39
+ * `undefined` when absent from every settings layer — the classifier remains
40
+ * disarmed.
41
+ */
42
+ export const AutoModeSchema = z.union([
43
+ AutoModeSectionSchema,
44
+ z.const(undefined),
45
+ ]);
46
+ //# sourceMappingURL=auto-mode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto-mode.js","sourceRoot":"","sources":["../src/auto-mode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,CAAC,MAAM,0BAA0B,CAAA;AA0BxC;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAA0B,CAAC,CAAC,MAAM,CAAC;IACtE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;IACnC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC;IAClC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IACnC,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC;CACzC,CAAC,CAAA;AAEF;;;;GAIG;AACH,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,2EAA2E;IAC3E,wDAAwD;IACxD,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;IAC7D,4EAA4E;IAC5E,2EAA2E;IAC3E,UAAU,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,wBAAwB,EAAE,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;CACpE,CAAC,CAAA;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAA4B,CAAC,CAAC,KAAK,CAAC;IAC7D,qBAAqB;IACrB,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC;CACnB,CAA4B,CAAA"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * CC-key aliasing for the settings cascade: recognized Claude Code camelCase
3
+ * top-level keys are aliased onto dsh-native kebab-case namespaces so a
4
+ * `settings.json` shared verbatim with a real CC checkout resolves through
5
+ * `settingsNamespace`. The whitelist map is the contract — no fuzzy matching.
6
+ * @module @dsh-cc/settings-cascade/cc-key-aliases
7
+ */
8
+ /**
9
+ * Explicit whitelist of CC camelCase top-level keys → dsh-native kebab-case
10
+ * namespaces. Unknown camelCase keys are never auto-aliased.
11
+ */
12
+ export declare const CC_KEY_ALIASES: Readonly<Record<string, string>>;
13
+ /**
14
+ * Inject aliases for recognized CC keys into a merged settings document.
15
+ * Mutates and returns the document: a whitelisted CC key whose value is a
16
+ * plain object is copied onto its kebab namespace ONLY when that namespace
17
+ * key is absent — a dsh-native key already present wins untouched.
18
+ * @param document - merged settings document (aliased in place).
19
+ * @returns the same document, with aliases injected.
20
+ */
21
+ export declare function applyCcKeyAliases(document: Record<string, unknown>): Record<string, unknown>;
22
+ //# sourceMappingURL=cc-key-aliases.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cc-key-aliases.d.ts","sourceRoot":"","sources":["../src/cc-key-aliases.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAE3D,CAAA;AASD;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAS5F"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * CC-key aliasing for the settings cascade: recognized Claude Code camelCase
3
+ * top-level keys are aliased onto dsh-native kebab-case namespaces so a
4
+ * `settings.json` shared verbatim with a real CC checkout resolves through
5
+ * `settingsNamespace`. The whitelist map is the contract — no fuzzy matching.
6
+ * @module @dsh-cc/settings-cascade/cc-key-aliases
7
+ */
8
+ /**
9
+ * Explicit whitelist of CC camelCase top-level keys → dsh-native kebab-case
10
+ * namespaces. Unknown camelCase keys are never auto-aliased.
11
+ */
12
+ export const CC_KEY_ALIASES = {
13
+ statusLine: 'statusline',
14
+ };
15
+ /** Whether a value is a plain data object (not an array, null, or instance). */
16
+ function isPlainObject(value) {
17
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
18
+ return false;
19
+ const proto = Object.getPrototypeOf(value);
20
+ return proto === Object.prototype || proto === null;
21
+ }
22
+ /**
23
+ * Inject aliases for recognized CC keys into a merged settings document.
24
+ * Mutates and returns the document: a whitelisted CC key whose value is a
25
+ * plain object is copied onto its kebab namespace ONLY when that namespace
26
+ * key is absent — a dsh-native key already present wins untouched.
27
+ * @param document - merged settings document (aliased in place).
28
+ * @returns the same document, with aliases injected.
29
+ */
30
+ export function applyCcKeyAliases(document) {
31
+ for (const [ccKey, namespace] of Object.entries(CC_KEY_ALIASES)) {
32
+ if (!(ccKey in document))
33
+ continue;
34
+ if (namespace in document)
35
+ continue;
36
+ const value = document[ccKey];
37
+ if (!isPlainObject(value))
38
+ continue;
39
+ document[namespace] = structuredClone(value);
40
+ }
41
+ return document;
42
+ }
43
+ //# sourceMappingURL=cc-key-aliases.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cc-key-aliases.js","sourceRoot":"","sources":["../src/cc-key-aliases.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAqC;IAC9D,UAAU,EAAE,YAAY;CACzB,CAAA;AAED,gFAAgF;AAChF,SAAS,aAAa,CAAC,KAAc;IACnC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IACrF,MAAM,KAAK,GAAY,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA;IACnD,OAAO,KAAK,KAAK,MAAM,CAAC,SAAS,IAAI,KAAK,KAAK,IAAI,CAAA;AACrD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAAiC;IACjE,KAAK,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;QAChE,IAAI,CAAC,CAAC,KAAK,IAAI,QAAQ,CAAC;YAAE,SAAQ;QAClC,IAAI,SAAS,IAAI,QAAQ;YAAE,SAAQ;QACnC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;QAC7B,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC;YAAE,SAAQ;QACnC,QAAQ,CAAC,SAAS,CAAC,GAAG,eAAe,CAAC,KAAK,CAAC,CAAA;IAC9C,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC"}
package/lib/env.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Two-phase application of the cascade's top-level `env` section. Ordinary
3
+ * variables apply in the first stage; environment-altering variables
4
+ * (`LD_PRELOAD`, `PATH`, and similar) defer to `applyTrustedEnv`, run only
5
+ * after the user grants trust for them. Values are coerced to strings.
6
+ * @module @dsh-cc/settings-cascade/env
7
+ */
8
+ /** Environment variables that alter process behavior or library loading. */
9
+ export declare const DANGEROUS_ENV_VARS: readonly string[];
10
+ /** One parsed `env` entry: variable name to a value coerced to string on apply. */
11
+ export type EnvSettings = Record<string, unknown>;
12
+ /**
13
+ * Coerce one configured `env` value into the string a process environment
14
+ * carries. Numbers and booleans stringify literally; objects and arrays
15
+ * serialize as JSON; a string passes through unchanged.
16
+ * @param value - the configured raw value.
17
+ * @returns the string form to assign to the environment variable.
18
+ */
19
+ export declare function coerceEnv(value: unknown): string;
20
+ /**
21
+ * Apply the first (untrusted) stage of an `env` section: every ordinary
22
+ * variable is assigned, dangerous variables are held back for the trusted
23
+ * stage. The returned mapping is a new object; neither input is mutated.
24
+ * @param env - the parsed `env` section.
25
+ * @param target - optional existing environment mapping to merge over.
26
+ * @returns the next environment mapping without dangerous variables.
27
+ */
28
+ export declare function applyEnv(env: EnvSettings, target?: Record<string, string>): Record<string, string>;
29
+ /**
30
+ * Apply the trusted stage of an `env` section: dangerous variables are
31
+ * assigned together with ordinary ones. Call only after the user has granted
32
+ * trust for environment-altering variables.
33
+ * @param env - the parsed `env` section.
34
+ * @param target - optional existing environment mapping to merge over.
35
+ * @returns the complete next environment mapping including dangerous variables.
36
+ */
37
+ export declare function applyTrustedEnv(env: EnvSettings, target?: Record<string, string>): Record<string, string>;
38
+ //# sourceMappingURL=env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,4EAA4E;AAC5E,eAAO,MAAM,kBAAkB,EAAE,SAAS,MAAM,EAWtC,CAAA;AAIV,mFAAmF;AACnF,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEjD;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAMhD;AAYD;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAElG;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAEzG"}
package/lib/env.js ADDED
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Two-phase application of the cascade's top-level `env` section. Ordinary
3
+ * variables apply in the first stage; environment-altering variables
4
+ * (`LD_PRELOAD`, `PATH`, and similar) defer to `applyTrustedEnv`, run only
5
+ * after the user grants trust for them. Values are coerced to strings.
6
+ * @module @dsh-cc/settings-cascade/env
7
+ */
8
+ /** Environment variables that alter process behavior or library loading. */
9
+ export const DANGEROUS_ENV_VARS = [
10
+ 'LD_PRELOAD',
11
+ 'LD_LIBRARY_PATH',
12
+ 'DYLD_INSERT_LIBRARIES',
13
+ 'DYLD_LIBRARY_PATH',
14
+ 'PATH',
15
+ 'PYTHONPATH',
16
+ 'NODE_OPTIONS',
17
+ 'NODE_PATH',
18
+ 'RUBYLIB',
19
+ 'PERL5LIB',
20
+ ];
21
+ const DANGEROUS = new Set(DANGEROUS_ENV_VARS);
22
+ /**
23
+ * Coerce one configured `env` value into the string a process environment
24
+ * carries. Numbers and booleans stringify literally; objects and arrays
25
+ * serialize as JSON; a string passes through unchanged.
26
+ * @param value - the configured raw value.
27
+ * @returns the string form to assign to the environment variable.
28
+ */
29
+ export function coerceEnv(value) {
30
+ if (typeof value === 'string')
31
+ return value;
32
+ if (typeof value === 'number' || typeof value === 'boolean' || value === null || value === undefined) {
33
+ return String(value);
34
+ }
35
+ return JSON.stringify(value);
36
+ }
37
+ /** Write a new environment mapping from an env section merged over a base. */
38
+ function apply(env, target, includeDangerous) {
39
+ const out = { ...target };
40
+ for (const [name, raw] of Object.entries(env)) {
41
+ if (!includeDangerous && DANGEROUS.has(name))
42
+ continue;
43
+ out[name] = coerceEnv(raw);
44
+ }
45
+ return out;
46
+ }
47
+ /**
48
+ * Apply the first (untrusted) stage of an `env` section: every ordinary
49
+ * variable is assigned, dangerous variables are held back for the trusted
50
+ * stage. The returned mapping is a new object; neither input is mutated.
51
+ * @param env - the parsed `env` section.
52
+ * @param target - optional existing environment mapping to merge over.
53
+ * @returns the next environment mapping without dangerous variables.
54
+ */
55
+ export function applyEnv(env, target) {
56
+ return apply(env, target, false);
57
+ }
58
+ /**
59
+ * Apply the trusted stage of an `env` section: dangerous variables are
60
+ * assigned together with ordinary ones. Call only after the user has granted
61
+ * trust for environment-altering variables.
62
+ * @param env - the parsed `env` section.
63
+ * @param target - optional existing environment mapping to merge over.
64
+ * @returns the complete next environment mapping including dangerous variables.
65
+ */
66
+ export function applyTrustedEnv(env, target) {
67
+ return apply(env, target, true);
68
+ }
69
+ //# sourceMappingURL=env.js.map
package/lib/env.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,4EAA4E;AAC5E,MAAM,CAAC,MAAM,kBAAkB,GAAsB;IACnD,YAAY;IACZ,iBAAiB;IACjB,uBAAuB;IACvB,mBAAmB;IACnB,MAAM;IACN,YAAY;IACZ,cAAc;IACd,WAAW;IACX,SAAS;IACT,UAAU;CACF,CAAA;AAEV,MAAM,SAAS,GAAG,IAAI,GAAG,CAAS,kBAAkB,CAAC,CAAA;AAKrD;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,KAAc;IACtC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAC3C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACrG,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;IACtB,CAAC;IACD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;AAC9B,CAAC;AAED,8EAA8E;AAC9E,SAAS,KAAK,CAAC,GAAgB,EAAE,MAA0C,EAAE,gBAAyB;IACpG,MAAM,GAAG,GAA2B,EAAE,GAAG,MAAM,EAAE,CAAA;IACjD,KAAK,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC9C,IAAI,CAAC,gBAAgB,IAAI,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,SAAQ;QACtD,GAAG,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,CAAA;IAC5B,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAgB,EAAE,MAA+B;IACxE,OAAO,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;AAClC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,GAAgB,EAAE,MAA+B;IAC/E,OAAO,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,CAAA;AACjC,CAAC"}