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,222 +1,222 @@
1
- # Architecture Overview
2
-
3
- Status: V1.
4
-
5
- Related: [design.md](./design.md), [detailed-design.md](./detailed-design.md), [module-boundaries.md](./module-boundaries.md), [data-model.md](./data-model.md).
6
-
7
- ---
8
-
9
- ## 1. Layers
10
-
11
- ```text
12
- DSH Web / Desktop UI
13
- └── Client module (client.js): panels, context preview, YAML editor
14
- │
15
- ▼ POST /env-manager/api
16
- DSH Host process
17
- ├── transport header/origin/size checks, op dispatch
18
- ├── tools Agent-facing schemas, approval gates
19
- ├── app use cases shared by tools and transport
20
- ├── session per-session default environment
21
- ├── router operation → Skill matching
22
- ├── resolver context + rule resolution with provenance
23
- ├── registry validated in-memory snapshot
24
- ├── storage atomic YAML persistence
25
- └── memory-bridge (P1 contract, null adapter in V1)
26
- │
27
- ▼
28
- Plugin data directory (YAML records + session JSON)
29
- ```
30
-
31
- `tools` and `transport` are sibling adapters over `app`; neither contains business
32
- logic. This is the core boundary that keeps the Agent path and the UI path consistent.
33
-
34
- ---
35
-
36
- ## 2. Major components
37
-
38
- ### 2.1 Client module
39
-
40
- Runs inside DSH Web/Desktop as a `sidebar.panellist` entry plus the `main` panel keyed
41
- `env-manager`.
42
-
43
- Responsibilities:
44
-
45
- - Environment, service, deployment, rule and binding lists and YAML editors.
46
- - Context preview with provenance badges.
47
- - Operation preview with skill availability and conflict display.
48
- - Validation and diagnostics display.
49
- - Locale-aware text (`en`, `zh`).
50
-
51
- It calls the plugin HTTP API and renders the results. It holds no business logic and no
52
- durable state.
53
-
54
- ### 2.2 Tools
55
-
56
- The Agent-facing surface: ten `env_*` tools.
57
-
58
- Read tools answer questions about the registry. Management tools validate and write
59
- records, with approval gates for production.
60
-
61
- Tool handlers are thin; they resolve ids, call `app`, and map results to the declared
62
- JSON value and `render` text. Expected failures throw `EnvManagerError`.
63
-
64
- ### 2.3 Transport
65
-
66
- The Client-facing surface: one same-origin route, `POST /env-manager/api`.
67
-
68
- - Requires `x-env-manager-request: 1`, JSON content type and a same-origin `Origin`.
69
- - Body limit 2 MiB; no CORS, no cookies.
70
- - Dispatches `{ op, payload }` to `app` and maps codes to HTTP statuses.
71
-
72
- ### 2.4 App
73
-
74
- The use-case layer shared by both adapters.
75
-
76
- - Composes storage, registry, resolver, router and session.
77
- - Applies the record cap, timestamps, actor policy and dry-run.
78
- - Reloads the registry after a write.
79
- - Returns domain results or throws `EnvManagerError`.
80
-
81
- ### 2.5 Registry
82
-
83
- Loads all record files into an in-memory snapshot and validates them.
84
-
85
- - Ids are unique per record type.
86
- - References resolve.
87
- - Invalid files are skipped with diagnostics, never deleted.
88
- - V1 loads at the start of every application request; a write triggers a reload before
89
- returning.
90
-
91
- ### 2.6 Resolver
92
-
93
- Pure functions that combine records into a `ServiceContext`.
94
-
95
- - Merges rule layers field by field.
96
- - Resolves `${...}` templates with cycle and undefined-variable detection.
97
- - Rejects path traversal.
98
- - Attaches provenance to every returned field.
99
-
100
- ### 2.7 Router
101
-
102
- Pure functions that map an operation to a bound Skill.
103
-
104
- - Groups bindings by match level.
105
- - Fails on same-level conflicts.
106
- - Checks Skill availability through an injected interface (`ctx.skills.snapshot`).
107
- - Evaluates approval and production policy.
108
- - Maps parameters and returns diagnostics.
109
-
110
- The router never executes anything.
111
-
112
- ### 2.8 Session
113
-
114
- Stores the current session's default environment.
115
-
116
- - Per-session isolation.
117
- - V1 persists `sessions/<sessionId>.json`; a projection is a later refinement.
118
- - Never affects other sessions or registry files.
119
-
120
- ### 2.9 Memory bridge
121
-
122
- P1 integration with the memory plugin.
123
-
124
- - V1 defines types and a null adapter.
125
- - Emits redacted operation records.
126
- - Proposes rule/skill changes for review.
127
- - Never applies changes.
128
-
129
- ### 2.10 Storage
130
-
131
- Atomic YAML persistence.
132
-
133
- - Directory per record type.
134
- - Temp file + fsync + rename.
135
- - Rolling backups (5 per record).
136
- - Bounded and validated.
137
-
138
- ---
139
-
140
- ## 3. Request flows
141
-
142
- ### 3.1 Resolve a service context
143
-
144
- ```text
145
- env_resolve(environmentId?, serviceId, deploymentId?)
146
- → tools: validate input, resolve session default if needed
147
- → app: fetch env, service, deployments from the registry
148
- → resolver: select deployment, merge rules, resolve templates
149
- → app: attach credential status (describe only)
150
- → tools: return ServiceContext
151
- ```
152
-
153
- ### 3.2 Route an operation
154
-
155
- ```text
156
- env_resolve_operation(operation, environmentId?, serviceId?, deploymentId?)
157
- → resolve context (above)
158
- → router: classify bindings, detect conflict, snapshot skills, evaluate policy
159
- → app: resolve parameters
160
- → tools: return OperationResolution
161
- ```
162
-
163
- ### 3.3 Save a record
164
-
165
- ```text
166
- env_save(kind, record, dryRun?)
167
- → tools: parse the JSON parameter
168
- → app: validate with Zod, stamp timestamps, enforce the record cap
169
- → approval gate when production is affected
170
- → storage: atomic write + backup
171
- → app: reload registry, re-run integrity checks
172
- → tools: return id, created flag, warnings
173
- ```
174
-
175
- ### 3.4 Validate the registry
176
-
177
- ```text
178
- env_validate
179
- → app: load snapshot and integrity diagnostics
180
- → tools: summarize counts and diagnostics
181
- ```
182
-
183
- ### 3.5 UI read and write
184
-
185
- ```text
186
- client: call('record.get', { kind, id })
187
- → transport: header + origin + size checks
188
- → app.get(kind, id)
189
- → transport: { ok: true, data: { record, yaml } }
190
- → client: render the editor
191
- ```
192
-
193
- Writes follow the same path with actor `'ui'` and the production policy in
194
- `writePolicy.allowUiProductionWrites`.
195
-
196
- ---
197
-
198
- ## 4. Cross-cutting concerns
199
-
200
- | Concern | Approach |
201
- |---|---|
202
- | Credentials | references only; status via `describe` |
203
- | Approval | policy in router; `ctx.approval` for management writes |
204
- | Rule safety | interpolation only, cycle/traversal detection |
205
- | Redaction | shared function before diagnostics and P1 records |
206
- | Persistence | atomic write, bounded backups, no hidden state |
207
- | Performance | small YAML scans; no indexes in V1 |
208
- | Compatibility | `schemaVersion` gate; unknown versions skipped |
209
- | Client security | same-origin route, custom header, no CORS, actor policy |
210
-
211
- ---
212
-
213
- ## 5. What is deliberately absent
214
-
215
- - No network calls.
216
- - No remote execution.
217
- - No database.
218
- - No vector search.
219
- - No background jobs.
220
- - No telemetry.
221
-
222
- Each absence is a V1 scope decision, not an oversight.
1
+ # Architecture Overview
2
+
3
+ Status: V1.
4
+
5
+ Related: [design.md](./design.md), [detailed-design.md](./detailed-design.md), [module-boundaries.md](./module-boundaries.md), [data-model.md](./data-model.md).
6
+
7
+ ---
8
+
9
+ ## 1. Layers
10
+
11
+ ```text
12
+ DSH Web / Desktop UI
13
+ └── Client module (client.js): panels, context preview, YAML editor
14
+ │
15
+ ▼ POST /env-manager/api
16
+ DSH Host process
17
+ ├── transport header/origin/size checks, op dispatch
18
+ ├── tools Agent-facing schemas, approval gates
19
+ ├── app use cases shared by tools and transport
20
+ ├── session per-session default environment
21
+ ├── router operation → Skill matching
22
+ ├── resolver context + rule resolution with provenance
23
+ ├── registry validated in-memory snapshot
24
+ ├── storage atomic YAML persistence
25
+ └── memory-bridge (P1 contract, null adapter in V1)
26
+ │
27
+ ▼
28
+ Plugin data directory (YAML records + session JSON)
29
+ ```
30
+
31
+ `tools` and `transport` are sibling adapters over `app`; neither contains business
32
+ logic. This is the core boundary that keeps the Agent path and the UI path consistent.
33
+
34
+ ---
35
+
36
+ ## 2. Major components
37
+
38
+ ### 2.1 Client module
39
+
40
+ Runs inside DSH Web/Desktop as a `sidebar.panellist` entry plus the `main` panel keyed
41
+ `env-manager`.
42
+
43
+ Responsibilities:
44
+
45
+ - Environment, service, deployment, rule and binding lists and YAML editors.
46
+ - Context preview with provenance badges.
47
+ - Operation preview with skill availability and conflict display.
48
+ - Validation and diagnostics display.
49
+ - Locale-aware text (`en`, `zh`).
50
+
51
+ It calls the plugin HTTP API and renders the results. It holds no business logic and no
52
+ durable state.
53
+
54
+ ### 2.2 Tools
55
+
56
+ The Agent-facing surface: ten `env_*` tools.
57
+
58
+ Read tools answer questions about the registry. Management tools validate and write
59
+ records, with approval gates for production.
60
+
61
+ Tool handlers are thin; they resolve ids, call `app`, and map results to the declared
62
+ JSON value and `render` text. Expected failures throw `EnvManagerError`.
63
+
64
+ ### 2.3 Transport
65
+
66
+ The Client-facing surface: one same-origin route, `POST /env-manager/api`.
67
+
68
+ - Requires `x-env-manager-request: 1`, JSON content type and a same-origin `Origin`.
69
+ - Body limit 2 MiB; no CORS, no cookies.
70
+ - Dispatches `{ op, payload }` to `app` and maps codes to HTTP statuses.
71
+
72
+ ### 2.4 App
73
+
74
+ The use-case layer shared by both adapters.
75
+
76
+ - Composes storage, registry, resolver, router and session.
77
+ - Applies the record cap, timestamps, actor policy and dry-run.
78
+ - Reloads the registry after a write.
79
+ - Returns domain results or throws `EnvManagerError`.
80
+
81
+ ### 2.5 Registry
82
+
83
+ Loads all record files into an in-memory snapshot and validates them.
84
+
85
+ - Ids are unique per record type.
86
+ - References resolve.
87
+ - Invalid files are skipped with diagnostics, never deleted.
88
+ - V1 loads at the start of every application request; a write triggers a reload before
89
+ returning.
90
+
91
+ ### 2.6 Resolver
92
+
93
+ Pure functions that combine records into a `ServiceContext`.
94
+
95
+ - Merges rule layers field by field.
96
+ - Resolves `${...}` templates with cycle and undefined-variable detection.
97
+ - Rejects path traversal.
98
+ - Attaches provenance to every returned field.
99
+
100
+ ### 2.7 Router
101
+
102
+ Pure functions that map an operation to a bound Skill.
103
+
104
+ - Groups bindings by match level.
105
+ - Fails on same-level conflicts.
106
+ - Checks Skill availability through an injected interface (`ctx.skills.snapshot`).
107
+ - Evaluates approval and production policy.
108
+ - Maps parameters and returns diagnostics.
109
+
110
+ The router never executes anything.
111
+
112
+ ### 2.8 Session
113
+
114
+ Stores the current session's default environment.
115
+
116
+ - Per-session isolation.
117
+ - V1 persists `sessions/<sessionId>.json`; a projection is a later refinement.
118
+ - Never affects other sessions or registry files.
119
+
120
+ ### 2.9 Memory bridge
121
+
122
+ P1 integration with the memory plugin.
123
+
124
+ - V1 defines types and a null adapter.
125
+ - Emits redacted operation records.
126
+ - Proposes rule/skill changes for review.
127
+ - Never applies changes.
128
+
129
+ ### 2.10 Storage
130
+
131
+ Atomic YAML persistence.
132
+
133
+ - Directory per record type.
134
+ - Temp file + fsync + rename.
135
+ - Rolling backups (5 per record).
136
+ - Bounded and validated.
137
+
138
+ ---
139
+
140
+ ## 3. Request flows
141
+
142
+ ### 3.1 Resolve a service context
143
+
144
+ ```text
145
+ env_resolve(environmentId?, serviceId, deploymentId?)
146
+ → tools: validate input, resolve session default if needed
147
+ → app: fetch env, service, deployments from the registry
148
+ → resolver: select deployment, merge rules, resolve templates
149
+ → app: attach credential status (describe only)
150
+ → tools: return ServiceContext
151
+ ```
152
+
153
+ ### 3.2 Route an operation
154
+
155
+ ```text
156
+ env_resolve_operation(operation, environmentId?, serviceId?, deploymentId?)
157
+ → resolve context (above)
158
+ → router: classify bindings, detect conflict, snapshot skills, evaluate policy
159
+ → app: resolve parameters
160
+ → tools: return OperationResolution
161
+ ```
162
+
163
+ ### 3.3 Save a record
164
+
165
+ ```text
166
+ env_save(kind, record, dryRun?)
167
+ → tools: parse the JSON parameter
168
+ → app: validate with Zod, stamp timestamps, enforce the record cap
169
+ → approval gate when production is affected
170
+ → storage: atomic write + backup
171
+ → app: reload registry, re-run integrity checks
172
+ → tools: return id, created flag, warnings
173
+ ```
174
+
175
+ ### 3.4 Validate the registry
176
+
177
+ ```text
178
+ env_validate
179
+ → app: load snapshot and integrity diagnostics
180
+ → tools: summarize counts and diagnostics
181
+ ```
182
+
183
+ ### 3.5 UI read and write
184
+
185
+ ```text
186
+ client: call('record.get', { kind, id })
187
+ → transport: header + origin + size checks
188
+ → app.get(kind, id)
189
+ → transport: { ok: true, data: { record, yaml } }
190
+ → client: render the editor
191
+ ```
192
+
193
+ Writes follow the same path with actor `'ui'` and the production policy in
194
+ `writePolicy.allowUiProductionWrites`.
195
+
196
+ ---
197
+
198
+ ## 4. Cross-cutting concerns
199
+
200
+ | Concern | Approach |
201
+ |---|---|
202
+ | Credentials | references only; status via `describe` |
203
+ | Approval | policy in router; `ctx.approval` for management writes |
204
+ | Rule safety | interpolation only, cycle/traversal detection |
205
+ | Redaction | shared function before diagnostics and P1 records |
206
+ | Persistence | atomic write, bounded backups, no hidden state |
207
+ | Performance | small YAML scans; no indexes in V1 |
208
+ | Compatibility | `schemaVersion` gate; unknown versions skipped |
209
+ | Client security | same-origin route, custom header, no CORS, actor policy |
210
+
211
+ ---
212
+
213
+ ## 5. What is deliberately absent
214
+
215
+ - No network calls.
216
+ - No remote execution.
217
+ - No database.
218
+ - No vector search.
219
+ - No background jobs.
220
+ - No telemetry.
221
+
222
+ Each absence is a V1 scope decision, not an oversight.