@yugoo-design/dsh-design-studio 0.1.0 → 0.2.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.
@@ -0,0 +1,280 @@
1
+ import { DesignKit, DesignSkill, KitResourceContent } from "@yugoo-design/dsh-design-core";
2
+ //#region src/types.d.ts
3
+ /**
4
+ * Host-neutral Design Studio ports and read-model vocabulary.
5
+ *
6
+ * The Studio is a pure domain library: every filesystem operation goes through
7
+ * an injected port so each Agent Host adapter (DSH, Codex, Claude Code, SDK
8
+ * Pilot) supplies its own native file operations. Nothing here imports an
9
+ * Agent Host runtime, Cordis, or `node:fs`. Installed content remains read-only;
10
+ * editable drafts use separate injected snapshot and persistence ports.
11
+ */
12
+ /**
13
+ * Read-only filesystem surface the Studio needs to enumerate and validate
14
+ * Kits. Structurally compatible with the Design Core `KitFsLike` loader port.
15
+ */
16
+ interface StudioReadFs {
17
+ /** Read one UTF-8 text file; `undefined` when absent. */
18
+ readText(path: string): Promise<string | undefined>;
19
+ /** Optional attached-resource text/opaque projection; never used for definition slots. */
20
+ readResource?(path: string): Promise<KitResourceContent | undefined>;
21
+ /** List one directory's entry names. */
22
+ listDir(path: string): Promise<string[]>;
23
+ /** Whether a path is a directory; adapters without it fall back to read probes. */
24
+ isDirectory?(path: string): Promise<boolean>;
25
+ /** Resolve symlinks for confinement checks. */
26
+ realPath?(path: string): Promise<string>;
27
+ }
28
+ /** One explicit Studio diagnostic (a stable code plus a locatable message). */
29
+ interface StudioDiagnostic {
30
+ /** Stable diagnostic code, e.g. `kit.load`. */
31
+ readonly code: string;
32
+ /** Human-readable, locatable message. */
33
+ readonly message: string;
34
+ /** The Kit or Bundle the diagnostic is about, when known. */
35
+ readonly subject?: string;
36
+ /** Omitted means error, preserving existing error-only consumers. */
37
+ readonly severity?: 'warning';
38
+ }
39
+ /** The outcome of validating one Kit or Bundle definition. */
40
+ interface StudioValidationReport {
41
+ /** True when the definition loads without errors; warnings do not block use. */
42
+ readonly valid: boolean;
43
+ /** Definition errors or non-blocking authoring warnings. */
44
+ readonly diagnostics: readonly StudioDiagnostic[];
45
+ }
46
+ /** Exact identity of one published Kit version. */
47
+ interface DesignKitVersionPin {
48
+ /** Published Kit name. */
49
+ readonly name: string;
50
+ /** Exact declared Kit version (`major.minor`). */
51
+ readonly version: string;
52
+ }
53
+ /** Exact identity of one published Bundle version. */
54
+ interface DesignBundleVersionPin {
55
+ /** Published Bundle name. */
56
+ readonly name: string;
57
+ /** Explicit declared Bundle version (`major.minor`). */
58
+ readonly version: string;
59
+ }
60
+ /**
61
+ * Thrown by a Bundle source port when a file exists but is not decodable
62
+ * UTF-8 text. The Studio surfaces binary content as an explicit diagnostic
63
+ * instead of lossy-decoding it into a text viewer.
64
+ */
65
+ declare class StudioBinaryContentError extends Error {
66
+ /** The path whose content is not UTF-8 text. */
67
+ readonly path: string;
68
+ /** @param path - absolute path of the non-text file. */
69
+ constructor(path: string);
70
+ }
71
+ //#endregion
72
+ //#region src/load.d.ts
73
+ /**
74
+ * Load a Kit with authority derived from the Studio-controlled directory.
75
+ * @param fs - Studio file-ops port.
76
+ * @param kitRoot - absolute Kit directory.
77
+ * @returns the assembled Kit.
78
+ */
79
+ interface StudioKitLoadOptions {
80
+ readonly sourceId?: string;
81
+ readonly bundles?: readonly {
82
+ name: string;
83
+ version: string;
84
+ rootDir: string;
85
+ sourceId: string;
86
+ }[];
87
+ }
88
+ declare function loadStudioKit(fs: StudioReadFs, kitRoot: string, options?: StudioKitLoadOptions): Promise<DesignKit>;
89
+ //#endregion
90
+ //#region src/panel-preview.d.ts
91
+ /** One editor revision and its isolated sample, not a runtime publication. */
92
+ interface StudioPanelPreviewRequest {
93
+ readonly kit: DesignKitVersionPin;
94
+ readonly bundle: DesignBundleVersionPin;
95
+ readonly revision: number;
96
+ readonly panelSource: string;
97
+ readonly sampleSource: string;
98
+ }
99
+ /** Runtime-interpreter input derived from a validated draft revision. */
100
+ interface StudioPanelPreview {
101
+ readonly revision: number;
102
+ /** Absent only for a real independently loaded Bundle preview. */
103
+ readonly kit?: DesignKitVersionPin;
104
+ readonly bundle: DesignBundleVersionPin;
105
+ /** Loader-resolved YAML, including the installed Bundle's translations. */
106
+ readonly panelYaml: string;
107
+ readonly sample: Readonly<Record<string, unknown>>;
108
+ /** Explicit bounded synthetic files; never project artifacts or filesystem access. */
109
+ readonly artifacts?: Readonly<Record<string, string>>;
110
+ }
111
+ interface StudioPanelPreviewResult {
112
+ readonly preview?: StudioPanelPreview;
113
+ readonly diagnostics: readonly StudioDiagnostic[];
114
+ }
115
+ /**
116
+ * Compile one Panel edit against an exact, host-resolved Kit snapshot.
117
+ *
118
+ * The host must supply an immutable/read-confined source port and root for the
119
+ * selected pin, not arbitrary browser paths or a mutable production project.
120
+ * Only panel.yaml is overlaid. All schemas, methods, locales and renderer
121
+ * contracts still come from that snapshot and pass through the runtime loader.
122
+ * The returned sample is fresh JSON and can be edited in a sandboxed preview;
123
+ * this function grants no artifact, filesystem, model or publication authority.
124
+ * A preview consumer must discard a result if its editor revision has changed.
125
+ */
126
+ declare function prepareStudioPanelPreview(source: StudioReadFs, kitRoot: string, request: StudioPanelPreviewRequest, loadOptions?: StudioKitLoadOptions): Promise<StudioPanelPreviewResult>;
127
+ //#endregion
128
+ //#region src/content-archive.d.ts
129
+ interface StudioArchivePin {
130
+ readonly name: string;
131
+ readonly version: string;
132
+ }
133
+ interface StudioArchiveFile {
134
+ readonly path: string;
135
+ readonly base64: string;
136
+ readonly bytes: number;
137
+ readonly sha256: string;
138
+ }
139
+ interface StudioContentArchive {
140
+ readonly format: 'studio-content-archive/v1';
141
+ readonly kind: 'kit' | 'bundle';
142
+ readonly pin: StudioArchivePin;
143
+ /** Optional bilingual working-copy display name, independent of catalog/runtime identity. */
144
+ readonly title?: {
145
+ readonly zh: string;
146
+ readonly en: string;
147
+ };
148
+ /** Declared provenance, not verified authorship or redistribution permission. */
149
+ readonly provenance?: {
150
+ readonly source?: string;
151
+ readonly license?: string;
152
+ };
153
+ /** Kit membership pins in catalog order; Bundle explicitly declared requirements. */
154
+ readonly dependencies: readonly DesignBundleVersionPin[];
155
+ readonly files: readonly StudioArchiveFile[];
156
+ /** SHA-256 of the canonical envelope excluding this field; not a signature. */
157
+ readonly sha256: string;
158
+ }
159
+ interface StudioArchiveBundleSource extends StudioArchivePin {
160
+ readonly sourceId: string;
161
+ readonly snapshot: StudioArchiveSource;
162
+ }
163
+ interface StudioArchiveSource {
164
+ readonly sourceId?: string;
165
+ /** Explicit standalone source, not an invented Kit or a fallback after Kit validation. */
166
+ readonly bundle?: StudioArchivePin;
167
+ /** Trusted immutable Bundle snapshots, never paths supplied by an archive. */
168
+ readonly bundles?: readonly StudioArchiveBundleSource[];
169
+ readonly root: string;
170
+ readonly fs: StudioReadFs;
171
+ /** Host supplies a complete, immutable regular-file snapshot; no live fallback. */
172
+ listFiles(): Promise<readonly string[]>;
173
+ /** Byte-preserving read. Host rejects links and non-regular files before reading. */
174
+ readBytes(path: string): Promise<Uint8Array>;
175
+ }
176
+ /** Parse a bounded JSON envelope; hashes include metadata and every original byte. */
177
+ declare function readStudioContentArchive(source: string): StudioContentArchive;
178
+ /** Capture only immutable host snapshots, preserving full exact referenced trees. */
179
+ declare function exportStudioContentArchive(snapshot: StudioArchiveSource, input: StudioArchiveExportInput): Promise<string>;
180
+ /** Capture saved source bytes, including incomplete working copies, without definition validation. */
181
+ declare function exportStudioSourceArchive(snapshot: StudioArchiveSource, input: StudioArchiveExportInput): Promise<string>;
182
+ interface StudioArchiveExportInput {
183
+ kind: 'kit' | 'bundle';
184
+ pin: StudioArchivePin;
185
+ title?: StudioContentArchive['title'];
186
+ provenance?: StudioContentArchive['provenance'];
187
+ dependencies?: readonly DesignBundleVersionPin[];
188
+ }
189
+ //#endregion
190
+ //#region src/panel-drafts.d.ts
191
+ interface StudioPanelDraftContent {
192
+ readonly kit: DesignKitVersionPin;
193
+ readonly bundle: DesignBundleVersionPin;
194
+ readonly baseSnapshot: string;
195
+ readonly panelSource: string;
196
+ readonly sampleSource: string;
197
+ /** Historical metadata only; never used to lock current authoring. */
198
+ readonly confirmed?: boolean;
199
+ }
200
+ interface StudioPanelDraftRecord extends StudioPanelDraftContent {
201
+ readonly id: string;
202
+ readonly revision: number;
203
+ }
204
+ type StudioPanelDraftSummary = Pick<StudioPanelDraftRecord, 'id' | 'revision' | 'kit' | 'bundle' | 'confirmed'>;
205
+ interface StudioPanelDraftRepository {
206
+ read(id: string): Promise<StudioPanelDraftRecord>;
207
+ list(): Promise<readonly StudioPanelDraftRecord[]>;
208
+ }
209
+ interface StudioSourceSnapshot {
210
+ readonly id: string;
211
+ readonly fs: StudioReadFs;
212
+ readonly root: string;
213
+ /** Bounded closure root; the Kit and independently retained Bundles may be siblings. */
214
+ readonly storageRoot?: string;
215
+ readonly loadOptions?: StudioKitLoadOptions;
216
+ }
217
+ interface StudioDraftSources {
218
+ /** Host captures complete current installed source bytes for an isolated Bundle trial. */
219
+ capture(kit: DesignKitVersionPin): Promise<StudioSourceSnapshot>;
220
+ open(id: string): Promise<StudioSourceSnapshot>;
221
+ }
222
+ //#endregion
223
+ //#region src/instance-changes.d.ts
224
+ declare const STUDIO_INSTANCE_CHANGE_LIMITS: Readonly<{
225
+ files: 64;
226
+ fileBytes: 1048576;
227
+ totalBytes: 4194304;
228
+ diffBytes: 8388608;
229
+ sampleBytes: 262144;
230
+ }>;
231
+ interface StudioInstanceFileChange {
232
+ readonly path: string;
233
+ /** UTF-8 replacement/addition; null explicitly removes a text file. */
234
+ readonly content: string | null;
235
+ }
236
+ interface StudioInstanceChangeRequest {
237
+ readonly id: string;
238
+ readonly expectedRevision: number;
239
+ readonly changes: readonly StudioInstanceFileChange[];
240
+ readonly bundle?: DesignBundleVersionPin;
241
+ readonly sampleSource?: string;
242
+ }
243
+ interface StudioInstanceFileDiff {
244
+ readonly path: string;
245
+ /** Missing means the file is added/removed; empty text remains an existing file. */
246
+ readonly before?: string;
247
+ readonly after?: string;
248
+ }
249
+ interface StudioInstanceCandidate {
250
+ readonly id: string;
251
+ readonly baseRevision: number;
252
+ readonly revision: number;
253
+ /** Binds the exact base, full candidate source, mount pins and preview sample. */
254
+ readonly digest: string;
255
+ readonly diff: readonly StudioInstanceFileDiff[];
256
+ /** Core definition passed; declarative Bundles and explicitly selected Kit previews also require a valid Panel/sample. */
257
+ readonly valid: boolean;
258
+ readonly diagnostics: readonly StudioDiagnostic[];
259
+ readonly preview?: StudioPanelPreview;
260
+ }
261
+ /** Draft is the default; validated requests require the exact prepared digest. */
262
+ type StudioInstanceSaveChanges = StudioInstanceChangeRequest & ({
263
+ readonly mode?: 'draft';
264
+ readonly digest?: string;
265
+ } | {
266
+ readonly mode: 'validated';
267
+ readonly digest: string;
268
+ });
269
+ interface StudioInstanceChangeReceipt {
270
+ readonly baseRevision: number;
271
+ readonly revision: number;
272
+ readonly digest: string;
273
+ readonly mode: 'draft' | 'validated';
274
+ /** Neither mode publishes or grants execution authority. */
275
+ readonly validation: 'not_requested' | 'definition_passed' | 'preview_passed';
276
+ }
277
+ /** Copy before any asynchronous host work so callers cannot mutate an in-flight edit. */
278
+ declare function normalizeStudioInstanceChanges(value: StudioInstanceChangeRequest): StudioInstanceChangeRequest;
279
+ //#endregion
280
+ export { StudioDiagnostic as A, StudioPanelPreviewRequest as C, DesignBundleVersionPin as D, loadStudioKit as E, StudioValidationReport as M, DesignKitVersionPin as O, StudioPanelPreview as S, prepareStudioPanelPreview as T, StudioArchiveSource as _, StudioInstanceFileChange as a, exportStudioSourceArchive as b, normalizeStudioInstanceChanges as c, StudioPanelDraftRecord as d, StudioPanelDraftRepository as f, StudioArchivePin as g, StudioArchiveFile as h, StudioInstanceChangeRequest as i, StudioReadFs as j, StudioBinaryContentError as k, StudioDraftSources as l, StudioSourceSnapshot as m, StudioInstanceCandidate as n, StudioInstanceFileDiff as o, StudioPanelDraftSummary as p, StudioInstanceChangeReceipt as r, StudioInstanceSaveChanges as s, STUDIO_INSTANCE_CHANGE_LIMITS as t, StudioPanelDraftContent as u, StudioContentArchive as v, StudioPanelPreviewResult as w, readStudioContentArchive as x, exportStudioContentArchive as y };