dsh-env-manager-plugin 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +274 -250
  3. package/client.js +2581 -2581
  4. package/cordis.patch.yml +4 -4
  5. package/docs/00-project/current-state.md +32 -6
  6. package/docs/00-project/glossary.md +215 -215
  7. package/docs/00-project/project-brief.md +114 -114
  8. package/docs/00-project/roadmap.md +89 -89
  9. package/docs/01-architecture/DSH_Environment_Service_Memory_Skill_Brainstorm.md +493 -493
  10. package/docs/01-architecture/api-verification.md +416 -416
  11. package/docs/01-architecture/architecture-overview.md +222 -222
  12. package/docs/01-architecture/data-model.md +930 -930
  13. package/docs/01-architecture/decisions/ADR-0001-plugin-as-bundle.md +29 -29
  14. package/docs/01-architecture/decisions/ADR-0002-file-based-storage.md +25 -25
  15. package/docs/01-architecture/decisions/ADR-0003-skill-router-over-search.md +25 -25
  16. package/docs/01-architecture/decisions/ADR-0004-typescript-host-js-client.md +31 -31
  17. package/docs/01-architecture/decisions/ADR-0005-layered-rule-resolution.md +36 -36
  18. package/docs/01-architecture/decisions/ADR-0006-credentials-as-references.md +30 -30
  19. package/docs/01-architecture/decisions/ADR-0007-session-scoped-default-environment.md +28 -28
  20. package/docs/01-architecture/decisions/ADR-0008-memory-bridge-not-second-store.md +31 -31
  21. package/docs/01-architecture/decisions/ADR-0009-client-host-http-transport.md +87 -87
  22. package/docs/01-architecture/decisions/ADR-0010-environment-plane-model.md +87 -87
  23. package/docs/01-architecture/decisions/ADR-0011-k8s-node-execution-model.md +92 -92
  24. package/docs/01-architecture/design.md +666 -666
  25. package/docs/01-architecture/detailed-design.md +961 -961
  26. package/docs/01-architecture/implementation-plan.md +323 -323
  27. package/docs/01-architecture/module-boundaries.md +306 -306
  28. package/docs/01-architecture/security-model.md +227 -227
  29. package/docs/01-architecture/storage-contract.md +224 -224
  30. package/docs/01-architecture/tool-contract.md +438 -438
  31. package/docs/01-architecture/ui-design.md +587 -587
  32. package/docs/02-harness/agent-behavior.md +36 -36
  33. package/docs/02-harness/change-snapshot-policy.md +29 -29
  34. package/docs/02-harness/client-ui-integration.md +110 -110
  35. package/docs/02-harness/context-policy.md +43 -43
  36. package/docs/02-harness/harness-standard.md +91 -91
  37. package/docs/02-harness/task-execution-policy.md +26 -26
  38. package/docs/02-harness/verification-policy.md +97 -97
  39. package/docs/03-openspec/archive-rule.md +25 -25
  40. package/docs/03-openspec/bugfix-rule.md +30 -30
  41. package/docs/03-openspec/design-rule.md +33 -33
  42. package/docs/03-openspec/openspec-usage-guide.md +31 -31
  43. package/docs/03-openspec/proposal-rule.md +70 -70
  44. package/docs/03-openspec/spec-rule.md +33 -33
  45. package/docs/03-openspec/tasks-rule.md +31 -31
  46. package/docs/04-development/coding-style.md +67 -67
  47. package/docs/04-development/dependency-policy.md +43 -43
  48. package/docs/04-development/development-guide.md +85 -85
  49. package/docs/04-development/directory-convention.md +105 -105
  50. package/docs/04-development/local-run-guide.md +61 -55
  51. package/docs/04-development/testing-guide.md +102 -102
  52. package/docs/05-domain/deployment-template.md +76 -76
  53. package/docs/05-domain/environment-template.md +165 -165
  54. package/docs/05-domain/operation-binding-template.md +55 -55
  55. package/docs/05-domain/operation-record-template.md +55 -55
  56. package/docs/05-domain/prompt-template.md +90 -90
  57. package/docs/05-domain/rule-template.md +73 -73
  58. package/docs/05-domain/service-template.md +39 -39
  59. package/docs/06-operations/deployment-guide.md +54 -54
  60. package/docs/06-operations/release.md +198 -188
  61. package/docs/06-operations/security-policy.md +53 -53
  62. package/docs/06-operations/troubleshooting.md +141 -91
  63. package/docs/07-templates/adr-template.md +21 -21
  64. package/docs/07-templates/bugfix-template.md +11 -11
  65. package/docs/07-templates/case-template.md +15 -15
  66. package/docs/07-templates/design-template.md +29 -29
  67. package/docs/07-templates/proposal-template.md +19 -19
  68. package/docs/07-templates/spec-template.md +15 -15
  69. package/docs/07-templates/tasks-template.md +12 -12
  70. package/docs/99-archive/README.md +13 -13
  71. package/docs/README.md +142 -142
  72. package/icon.svg +4 -4
  73. package/index.js +31 -8
  74. package/lib/app/app.d.ts +1 -1
  75. package/lib/app/app.js +4 -1
  76. package/lib/app/app.js.map +1 -1
  77. package/lib/skill.js +37 -37
  78. package/locale/en.json +6 -6
  79. package/locale/zh.json +6 -6
  80. package/package.json +101 -99
  81. package/scripts/repair-profile.mjs +141 -0
@@ -1,306 +1,306 @@
1
- # Module Boundaries
2
-
3
- Status: normative for V1.
4
-
5
- Modules are directories under `src/` (Host, TypeScript). The Client half is a single `client.js` module at the repository root.
6
-
7
- Related: [design.md](./design.md) §3, [detailed-design.md](./detailed-design.md) §2, [storage-contract.md](./storage-contract.md), [tool-contract.md](./tool-contract.md).
8
-
9
- ---
10
-
11
- ## 1. Dependency direction
12
-
13
- ```text
14
- tools ────────┐
15
- ├──▶ app ──▶ resolver ──▶ registry ──▶ storage ──▶ fs
16
- transport ────┘ │ │ │
17
- │ └──▶ domain ◀┘
18
- ├──▶ router ──▶ resolver (context only)
19
- ├──▶ session ──▶ storage
20
- └──▶ memory-bridge ──▶ (external contract)
21
-
22
- client ──▶ transport (HTTP) ──▶ app
23
- ```
24
-
25
- Rules:
26
-
27
- - `domain` has no dependencies.
28
- - `storage` depends on `domain`.
29
- - `registry` depends on `storage` and `domain`.
30
- - `resolver` and `router` depend on `domain` and `registry` types, never on `storage` or `tools`.
31
- - `app` composes storage, registry, resolver, router, session and config; it is the only
32
- module that knows all of them.
33
- - `tools` and `transport` depend on `app` and `domain`; neither contains business logic
34
- and neither imports the other.
35
- - No module imports `tools` or `transport` except the Host entry point (`src/index.ts`).
36
- - `client.js` depends on the HTTP API, never on `src/` modules.
37
-
38
- Cycles are forbidden. A cycle means the boundary is wrong.
39
-
40
- ---
41
-
42
- ## 2. `domain`
43
-
44
- Owns the shapes.
45
-
46
- Allowed:
47
-
48
- - TypeScript interfaces and type guards for all records, results and diagnostics.
49
- - Zod schemas that mirror the interfaces.
50
- - Enums and constants (operation ids, categories, runtime modes).
51
- - Pure helpers that operate on the types.
52
-
53
- Forbidden:
54
-
55
- - File I/O.
56
- - Tool registration.
57
- - Resolution or routing logic.
58
- - Importing any other project module.
59
-
60
- ---
61
-
62
- ## 3. `storage`
63
-
64
- Owns bytes on disk.
65
-
66
- Responsibilities:
67
-
68
- - Resolve `dataDir` and create directories.
69
- - Read, parse, validate and write one record file.
70
- - Atomic write protocol.
71
- - Rolling backups.
72
- - Session state files.
73
- - Surface storage errors as typed errors with codes.
74
-
75
- Forbidden:
76
-
77
- - Cross-record validation (registry owns it).
78
- - Template resolution.
79
- - Skill matching.
80
- - Credential access.
81
-
82
- ---
83
-
84
- ## 4. `registry`
85
-
86
- Owns the in-memory view.
87
-
88
- Responsibilities:
89
-
90
- - Load all record directories into maps.
91
- - Reload affected entries after writes.
92
- - Enforce id uniqueness and filename/id agreement.
93
- - Enforce referential integrity (data-model §12).
94
- - Provide lookups: by id, by alias, list by category, deployments by service, deployments by environment.
95
- - Produce load diagnostics.
96
-
97
- Forbidden:
98
-
99
- - Writing files (uses `storage`).
100
- - Running templates.
101
- - Registering tools.
102
- - Holding mutable session state.
103
-
104
- ---
105
-
106
- ## 5. `resolver`
107
-
108
- Owns context and rule resolution.
109
-
110
- Responsibilities:
111
-
112
- - Select the deployment binding (explicit id or unique match).
113
- - Merge rule layers with field-level precedence.
114
- - Resolve templates with cycle detection and undefined-variable detection.
115
- - Validate resolved paths.
116
- - Build `ServiceContext` with provenance.
117
- - Build `ProvenanceEntry[]`.
118
-
119
- Forbidden:
120
-
121
- - File I/O.
122
- - Tool registration.
123
- - Credential resolution (status is injected by the caller).
124
- - Skill matching.
125
-
126
- Purity is required: all inputs are passed in, no globals, no clocks, no randomness.
127
-
128
- ---
129
-
130
- ## 6. `router`
131
-
132
- Owns operation-to-Skill matching.
133
-
134
- Responsibilities:
135
-
136
- - Classify each binding's match level.
137
- - Filter by eligibility.
138
- - Detect same-level conflicts.
139
- - Verify Skill references through an injected `SkillDirectory` interface.
140
- - Evaluate approval and production policy.
141
- - Map parameters with the resolver's template engine.
142
- - Build `OperationResolution` with diagnostics.
143
-
144
- Forbidden:
145
-
146
- - Executing Skills.
147
- - Reading files.
148
- - Accessing credentials.
149
- - Choosing a fallback binding.
150
-
151
- `SkillDirectory` is an interface, so tests use a fake and the Host adapter uses the real registry when available.
152
-
153
- ---
154
-
155
- ## 7. `session`
156
-
157
- Owns per-session default environment.
158
-
159
- Responsibilities:
160
-
161
- - `get(sessionId)`, `set(sessionId, environmentId | null)`.
162
- - Persist through `storage` (or the DSH session API when available).
163
- - Expose `{ environmentId, persisted }` to tools.
164
-
165
- Forbidden:
166
-
167
- - Mutating registry records.
168
- - Reading other sessions' state.
169
- - Deciding policy.
170
-
171
- ---
172
-
173
- ## 8. `app`
174
-
175
- Owns the use cases. One function per tool and per HTTP operation.
176
-
177
- Responsibilities:
178
-
179
- - Compose storage, registry, resolver, router and session for a request.
180
- - Apply the record cap, actor policy and dry-run.
181
- - Reload the registry after a successful write.
182
- - Return domain results or throw `EnvManagerError`.
183
-
184
- Forbidden:
185
-
186
- - Tool registration or HTTP parsing.
187
- - Rendering text for the model or the UI.
188
- - Re-implementing resolution, routing or persistence.
189
-
190
- `app` is the only module both `tools` and `transport` call, so the two surfaces cannot
191
- drift.
192
-
193
- ---
194
-
195
- ## 9. `memory-bridge`
196
-
197
- Owns the optional P1 integration.
198
-
199
- Responsibilities:
200
-
201
- - Define `MemoryBridge`, `MemoryScope`, `OperationRecord`, proposal types.
202
- - Provide a null adapter that reports `MEMORY_BRIDGE_UNAVAILABLE`.
203
- - Redact and bound records before emission.
204
-
205
- Forbidden:
206
-
207
- - Writing registry files.
208
- - Auto-applying proposals.
209
- - Owning a second copy of environment facts.
210
-
211
- ---
212
-
213
- ## 10. `tools`
214
-
215
- Owns the Agent-facing surface.
216
-
217
- Responsibilities:
218
-
219
- - Register `defineTool` definitions with `ctx.tools.register`.
220
- - Declare parameter and output schemas.
221
- - Apply approval gates for management writes.
222
- - Map `app` results to the declared JSON value and `render` text.
223
- - Throw `EnvManagerError` for expected failures.
224
-
225
- Forbidden:
226
-
227
- - Business logic beyond orchestration.
228
- - Direct file access.
229
- - Re-implementing resolution, routing or persistence.
230
-
231
- ---
232
-
233
- ## 11. `transport`
234
-
235
- Owns the Client-facing HTTP surface.
236
-
237
- Responsibilities:
238
-
239
- - Register and dispose the `/env-manager/api` route.
240
- - Enforce method, content type, request header, origin and body limits.
241
- - Map `{ op, payload }` to `app` calls.
242
- - Map `EnvManagerError` codes to status codes.
243
- - Log writes with actor, op, kind, id and outcome.
244
-
245
- Forbidden:
246
-
247
- - Business logic.
248
- - Reading credentials.
249
- - CORS headers or cookie handling.
250
- - Serving files or static assets.
251
-
252
- ---
253
-
254
- ## 12. `config`
255
-
256
- Owns plugin configuration.
257
-
258
- Responsibilities:
259
-
260
- - Define the config schema (`dataDir`, limits).
261
- - Validate at activation.
262
- - Provide resolved defaults.
263
-
264
- Forbidden:
265
-
266
- - Reading registry files at config-validation time.
267
- - Network access.
268
-
269
- ---
270
-
271
- ## 13. `client.js`
272
-
273
- Owns the Web/Desktop surface.
274
-
275
- Allowed:
276
-
277
- - Render panels and forms.
278
- - Call the plugin HTTP API.
279
- - Use the client locale, slots and theme services.
280
- - Register slots and clean up on unmount.
281
-
282
- Forbidden:
283
-
284
- - Reading or writing registry files.
285
- - Re-implementing rule resolution or routing.
286
- - Holding durable state outside the Host.
287
- - Global side effects at module load.
288
-
289
- ---
290
-
291
- ## 14. Host entry
292
-
293
- `src/index.ts` is the only place that wires modules together.
294
-
295
- Responsibilities:
296
-
297
- - Read config, build storage/registry/resolver/router/session/app.
298
- - Register tools and their cleanup.
299
- - Register the HTTP route and its cleanup.
300
- - Register the Client module metadata.
301
- - Log the resolved data directory once.
302
-
303
- Forbidden:
304
-
305
- - Business logic.
306
- - Direct tool or transport implementations.
1
+ # Module Boundaries
2
+
3
+ Status: normative for V1.
4
+
5
+ Modules are directories under `src/` (Host, TypeScript). The Client half is a single `client.js` module at the repository root.
6
+
7
+ Related: [design.md](./design.md) §3, [detailed-design.md](./detailed-design.md) §2, [storage-contract.md](./storage-contract.md), [tool-contract.md](./tool-contract.md).
8
+
9
+ ---
10
+
11
+ ## 1. Dependency direction
12
+
13
+ ```text
14
+ tools ────────┐
15
+ ├──▶ app ──▶ resolver ──▶ registry ──▶ storage ──▶ fs
16
+ transport ────┘ │ │ │
17
+ │ └──▶ domain ◀┘
18
+ ├──▶ router ──▶ resolver (context only)
19
+ ├──▶ session ──▶ storage
20
+ └──▶ memory-bridge ──▶ (external contract)
21
+
22
+ client ──▶ transport (HTTP) ──▶ app
23
+ ```
24
+
25
+ Rules:
26
+
27
+ - `domain` has no dependencies.
28
+ - `storage` depends on `domain`.
29
+ - `registry` depends on `storage` and `domain`.
30
+ - `resolver` and `router` depend on `domain` and `registry` types, never on `storage` or `tools`.
31
+ - `app` composes storage, registry, resolver, router, session and config; it is the only
32
+ module that knows all of them.
33
+ - `tools` and `transport` depend on `app` and `domain`; neither contains business logic
34
+ and neither imports the other.
35
+ - No module imports `tools` or `transport` except the Host entry point (`src/index.ts`).
36
+ - `client.js` depends on the HTTP API, never on `src/` modules.
37
+
38
+ Cycles are forbidden. A cycle means the boundary is wrong.
39
+
40
+ ---
41
+
42
+ ## 2. `domain`
43
+
44
+ Owns the shapes.
45
+
46
+ Allowed:
47
+
48
+ - TypeScript interfaces and type guards for all records, results and diagnostics.
49
+ - Zod schemas that mirror the interfaces.
50
+ - Enums and constants (operation ids, categories, runtime modes).
51
+ - Pure helpers that operate on the types.
52
+
53
+ Forbidden:
54
+
55
+ - File I/O.
56
+ - Tool registration.
57
+ - Resolution or routing logic.
58
+ - Importing any other project module.
59
+
60
+ ---
61
+
62
+ ## 3. `storage`
63
+
64
+ Owns bytes on disk.
65
+
66
+ Responsibilities:
67
+
68
+ - Resolve `dataDir` and create directories.
69
+ - Read, parse, validate and write one record file.
70
+ - Atomic write protocol.
71
+ - Rolling backups.
72
+ - Session state files.
73
+ - Surface storage errors as typed errors with codes.
74
+
75
+ Forbidden:
76
+
77
+ - Cross-record validation (registry owns it).
78
+ - Template resolution.
79
+ - Skill matching.
80
+ - Credential access.
81
+
82
+ ---
83
+
84
+ ## 4. `registry`
85
+
86
+ Owns the in-memory view.
87
+
88
+ Responsibilities:
89
+
90
+ - Load all record directories into maps.
91
+ - Reload affected entries after writes.
92
+ - Enforce id uniqueness and filename/id agreement.
93
+ - Enforce referential integrity (data-model §12).
94
+ - Provide lookups: by id, by alias, list by category, deployments by service, deployments by environment.
95
+ - Produce load diagnostics.
96
+
97
+ Forbidden:
98
+
99
+ - Writing files (uses `storage`).
100
+ - Running templates.
101
+ - Registering tools.
102
+ - Holding mutable session state.
103
+
104
+ ---
105
+
106
+ ## 5. `resolver`
107
+
108
+ Owns context and rule resolution.
109
+
110
+ Responsibilities:
111
+
112
+ - Select the deployment binding (explicit id or unique match).
113
+ - Merge rule layers with field-level precedence.
114
+ - Resolve templates with cycle detection and undefined-variable detection.
115
+ - Validate resolved paths.
116
+ - Build `ServiceContext` with provenance.
117
+ - Build `ProvenanceEntry[]`.
118
+
119
+ Forbidden:
120
+
121
+ - File I/O.
122
+ - Tool registration.
123
+ - Credential resolution (status is injected by the caller).
124
+ - Skill matching.
125
+
126
+ Purity is required: all inputs are passed in, no globals, no clocks, no randomness.
127
+
128
+ ---
129
+
130
+ ## 6. `router`
131
+
132
+ Owns operation-to-Skill matching.
133
+
134
+ Responsibilities:
135
+
136
+ - Classify each binding's match level.
137
+ - Filter by eligibility.
138
+ - Detect same-level conflicts.
139
+ - Verify Skill references through an injected `SkillDirectory` interface.
140
+ - Evaluate approval and production policy.
141
+ - Map parameters with the resolver's template engine.
142
+ - Build `OperationResolution` with diagnostics.
143
+
144
+ Forbidden:
145
+
146
+ - Executing Skills.
147
+ - Reading files.
148
+ - Accessing credentials.
149
+ - Choosing a fallback binding.
150
+
151
+ `SkillDirectory` is an interface, so tests use a fake and the Host adapter uses the real registry when available.
152
+
153
+ ---
154
+
155
+ ## 7. `session`
156
+
157
+ Owns per-session default environment.
158
+
159
+ Responsibilities:
160
+
161
+ - `get(sessionId)`, `set(sessionId, environmentId | null)`.
162
+ - Persist through `storage` (or the DSH session API when available).
163
+ - Expose `{ environmentId, persisted }` to tools.
164
+
165
+ Forbidden:
166
+
167
+ - Mutating registry records.
168
+ - Reading other sessions' state.
169
+ - Deciding policy.
170
+
171
+ ---
172
+
173
+ ## 8. `app`
174
+
175
+ Owns the use cases. One function per tool and per HTTP operation.
176
+
177
+ Responsibilities:
178
+
179
+ - Compose storage, registry, resolver, router and session for a request.
180
+ - Apply the record cap, actor policy and dry-run.
181
+ - Reload the registry after a successful write.
182
+ - Return domain results or throw `EnvManagerError`.
183
+
184
+ Forbidden:
185
+
186
+ - Tool registration or HTTP parsing.
187
+ - Rendering text for the model or the UI.
188
+ - Re-implementing resolution, routing or persistence.
189
+
190
+ `app` is the only module both `tools` and `transport` call, so the two surfaces cannot
191
+ drift.
192
+
193
+ ---
194
+
195
+ ## 9. `memory-bridge`
196
+
197
+ Owns the optional P1 integration.
198
+
199
+ Responsibilities:
200
+
201
+ - Define `MemoryBridge`, `MemoryScope`, `OperationRecord`, proposal types.
202
+ - Provide a null adapter that reports `MEMORY_BRIDGE_UNAVAILABLE`.
203
+ - Redact and bound records before emission.
204
+
205
+ Forbidden:
206
+
207
+ - Writing registry files.
208
+ - Auto-applying proposals.
209
+ - Owning a second copy of environment facts.
210
+
211
+ ---
212
+
213
+ ## 10. `tools`
214
+
215
+ Owns the Agent-facing surface.
216
+
217
+ Responsibilities:
218
+
219
+ - Register `defineTool` definitions with `ctx.tools.register`.
220
+ - Declare parameter and output schemas.
221
+ - Apply approval gates for management writes.
222
+ - Map `app` results to the declared JSON value and `render` text.
223
+ - Throw `EnvManagerError` for expected failures.
224
+
225
+ Forbidden:
226
+
227
+ - Business logic beyond orchestration.
228
+ - Direct file access.
229
+ - Re-implementing resolution, routing or persistence.
230
+
231
+ ---
232
+
233
+ ## 11. `transport`
234
+
235
+ Owns the Client-facing HTTP surface.
236
+
237
+ Responsibilities:
238
+
239
+ - Register and dispose the `/env-manager/api` route.
240
+ - Enforce method, content type, request header, origin and body limits.
241
+ - Map `{ op, payload }` to `app` calls.
242
+ - Map `EnvManagerError` codes to status codes.
243
+ - Log writes with actor, op, kind, id and outcome.
244
+
245
+ Forbidden:
246
+
247
+ - Business logic.
248
+ - Reading credentials.
249
+ - CORS headers or cookie handling.
250
+ - Serving files or static assets.
251
+
252
+ ---
253
+
254
+ ## 12. `config`
255
+
256
+ Owns plugin configuration.
257
+
258
+ Responsibilities:
259
+
260
+ - Define the config schema (`dataDir`, limits).
261
+ - Validate at activation.
262
+ - Provide resolved defaults.
263
+
264
+ Forbidden:
265
+
266
+ - Reading registry files at config-validation time.
267
+ - Network access.
268
+
269
+ ---
270
+
271
+ ## 13. `client.js`
272
+
273
+ Owns the Web/Desktop surface.
274
+
275
+ Allowed:
276
+
277
+ - Render panels and forms.
278
+ - Call the plugin HTTP API.
279
+ - Use the client locale, slots and theme services.
280
+ - Register slots and clean up on unmount.
281
+
282
+ Forbidden:
283
+
284
+ - Reading or writing registry files.
285
+ - Re-implementing rule resolution or routing.
286
+ - Holding durable state outside the Host.
287
+ - Global side effects at module load.
288
+
289
+ ---
290
+
291
+ ## 14. Host entry
292
+
293
+ `src/index.ts` is the only place that wires modules together.
294
+
295
+ Responsibilities:
296
+
297
+ - Read config, build storage/registry/resolver/router/session/app.
298
+ - Register tools and their cleanup.
299
+ - Register the HTTP route and its cleanup.
300
+ - Register the Client module metadata.
301
+ - Log the resolved data directory once.
302
+
303
+ Forbidden:
304
+
305
+ - Business logic.
306
+ - Direct tool or transport implementations.