dsh-artifact-studio 0.7.1 → 0.7.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.
- package/THIRD_PARTY_NOTICES.md +3 -2
- package/assets/canvas.engine.js +1 -1
- package/client.canvas.js +1 -1
- package/client.doc.js +79 -67
- package/dist/host/lib/rpc.js +0 -11
- package/dist/host/lib/service.js +0 -19
- package/dist/host/lib/skill.js +10 -2
- package/dist/host/lib/store.js +0 -48
- package/dist/host/lib/tools.js +2 -17
- package/package.json +3 -1
- package/dist/host/lib/editor-leases.js +0 -63
package/dist/host/lib/rpc.js
CHANGED
|
@@ -4,9 +4,6 @@ import { fieldsOf, optionalEdits, optionalInteger, optionalScope, optionalString
|
|
|
4
4
|
export const ENDPOINTS = [
|
|
5
5
|
'list',
|
|
6
6
|
'get',
|
|
7
|
-
'openEditor',
|
|
8
|
-
'closeEditor',
|
|
9
|
-
'move',
|
|
10
7
|
'create',
|
|
11
8
|
'update',
|
|
12
9
|
'delete',
|
|
@@ -53,14 +50,6 @@ async function dispatch(service, endpoint, fields) {
|
|
|
53
50
|
});
|
|
54
51
|
case 'get':
|
|
55
52
|
return service.read(target, requiredString(fields, 'id'), optionalInteger(fields, 'version'));
|
|
56
|
-
case 'openEditor':
|
|
57
|
-
await service.openEditor(target, requiredString(fields, 'id'), requiredString(fields, 'token'));
|
|
58
|
-
return { ok: true };
|
|
59
|
-
case 'closeEditor':
|
|
60
|
-
await service.closeEditor(target, requiredString(fields, 'id'), requiredString(fields, 'token'));
|
|
61
|
-
return { ok: true };
|
|
62
|
-
case 'move':
|
|
63
|
-
return { manifest: await service.move(target, requiredString(fields, 'id'), requiredString(fields, 'destinationWorkspaceId'), requiredInteger(fields, 'baseVersion'), requiredString(fields, 'token')) };
|
|
64
53
|
case 'create':
|
|
65
54
|
return {
|
|
66
55
|
manifest: await service.create(target, {
|
package/dist/host/lib/service.js
CHANGED
|
@@ -5,7 +5,6 @@ import { PAGE_CSP, composePage } from '../../render.js';
|
|
|
5
5
|
import { DesignRenderer, PREVIEW_MAX_SIDE } from './design-render.js';
|
|
6
6
|
import { clearWorkspaceDesignSystem, resolveDesignSystem, saveDesignSystem } from './design-system.js';
|
|
7
7
|
import { ArtifactError } from './errors.js';
|
|
8
|
-
import { acquireEditor, releaseEditor } from './editor-leases.js';
|
|
9
8
|
import { docToHtml, writeExport } from './export.js';
|
|
10
9
|
import { assertWithin, withLock, writeAtomic } from './fsutil.js';
|
|
11
10
|
import { assertPlainFile, libraryRoot, requireWorkspace, workspaceRoot, workspaceRootExisting } from './paths.js';
|
|
@@ -176,24 +175,6 @@ export class ArtifactService {
|
|
|
176
175
|
async restore(target, id, version, source, baseVersion) {
|
|
177
176
|
return this.store.restore(await this.root(target, id), id, version, source, baseVersion);
|
|
178
177
|
}
|
|
179
|
-
async openEditor(target, id, token) {
|
|
180
|
-
const root = await this.root(target, id);
|
|
181
|
-
const key = path.join(root.root, id);
|
|
182
|
-
await acquireEditor(key, token, async () => { await this.store.manifest(root, id); });
|
|
183
|
-
}
|
|
184
|
-
async closeEditor(target, id, token) {
|
|
185
|
-
const root = await this.root(target, id);
|
|
186
|
-
await releaseEditor(path.join(root.root, id), token);
|
|
187
|
-
}
|
|
188
|
-
async move(target, id, destinationWorkspaceId, baseVersion, ownToken) {
|
|
189
|
-
if (scopeOfId(id) !== 'workspace' || target.workspaceId === undefined || destinationWorkspaceId === target.workspaceId) {
|
|
190
|
-
throw new ArtifactError('artifact/bad-request', 'Choose a different workspace for a workspace artifact.');
|
|
191
|
-
}
|
|
192
|
-
requireWorkspace(this.registry, destinationWorkspaceId);
|
|
193
|
-
const source = await this.root({ scope: 'workspace', workspaceId: target.workspaceId }, id);
|
|
194
|
-
const destination = await this.root({ scope: 'workspace', workspaceId: destinationWorkspaceId });
|
|
195
|
-
return this.store.move(source, destination, id, baseVersion, ownToken);
|
|
196
|
-
}
|
|
197
178
|
async history(target, id) {
|
|
198
179
|
return this.store.history(await this.root(target, id), id);
|
|
199
180
|
}
|
package/dist/host/lib/skill.js
CHANGED
|
@@ -16,8 +16,10 @@ Use \`artifact_create\` when the user asks for an artifact, an artifact page, an
|
|
|
16
16
|
## Pick the type
|
|
17
17
|
|
|
18
18
|
- \`doc\` for prose: reports, briefs, plans, specs, notes. It is Markdown, edited in a rich-text editor, and exported to Word, Markdown, and HTML. Use headings, short paragraphs, lists, tables, task lists, quotes, and fenced code. Do not paste HTML into a doc.
|
|
19
|
-
- \`page\` for anything visual or interactive: dashboards, one-pagers, explainers, calculators, diagrams, prototypes.
|
|
20
|
-
- \`design\` for a layout the user will open on a canvas: UI mockups, layout explorations, and screens that export as PNG, SVG, or a \`.fig\` document.
|
|
19
|
+
- \`page\` for anything visual or interactive: dashboards, one-pagers, explainers, calculators, diagrams, and clickable prototypes the user asks for as a page.
|
|
20
|
+
- \`design\` for a layout the user will open on a canvas: UI mockups, wireframes, layout explorations, and screens that export as PNG, SVG, or a \`.fig\` document.
|
|
21
|
+
|
|
22
|
+
A request for a mockup or a wireframe always gets \`design\`, even when it shows a flow. Draw each step of the flow as its own frame. If the user offers both, such as "a page or a mockup", make a mockup. Use \`page\` for a mockup only when the user asks for a page or for something clickable. Never title or describe a page as a mockup.
|
|
21
23
|
|
|
22
24
|
## Designs (OpenPencil Design JSX)
|
|
23
25
|
|
|
@@ -37,6 +39,12 @@ Call this artifact a mockup when you talk to the user. The tools still take type
|
|
|
37
39
|
- The stored artifact is the JSX source. Send the complete source as \`content\` when you update a design. The host compiles and validates before saving, so a compile error refuses the write and returns the compiler message.
|
|
38
40
|
- Export is PNG, SVG, or \`.fig\`. The user can open the \`.fig\` in OpenPencil for a full canvas editor.
|
|
39
41
|
|
|
42
|
+
### When a design write fails
|
|
43
|
+
|
|
44
|
+
- A compile, icon, or validation error names a problem in your source. Fix the source and try again.
|
|
45
|
+
- Any other error, such as "The design renderer stopped" or a missing module, is a fault in the plugin, not in your source. Stop and show the user the exact error.
|
|
46
|
+
- Never switch to a \`page\` or a \`doc\` to work around a failed design. Do it only when the user tells you to.
|
|
47
|
+
|
|
40
48
|
## The page sandbox
|
|
41
49
|
|
|
42
50
|
A page renders in an opaque-origin iframe with every network request blocked.
|
package/dist/host/lib/store.js
CHANGED
|
@@ -3,7 +3,6 @@ import fs from 'node:fs/promises';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { CONTENT_FILE, ID_PATTERN, MAX_LIST_LIMIT, MAX_TITLE, isArtifactType, isManifest, isVersionSource } from '../../contract.js';
|
|
5
5
|
import { ArtifactError, errnoCode } from './errors.js';
|
|
6
|
-
import { assertNoEditors } from './editor-leases.js';
|
|
7
6
|
import { assertWithin, withLock, writeAtomic } from './fsutil.js';
|
|
8
7
|
import { artifactDir, assertPlainFile } from './paths.js';
|
|
9
8
|
export const DEFAULT_LIMITS = {
|
|
@@ -490,53 +489,6 @@ export class ArtifactStore {
|
|
|
490
489
|
const items = filtered.slice(offset, offset + limit);
|
|
491
490
|
return { items, total: filtered.length, hasMore: offset + items.length < filtered.length, truncated };
|
|
492
491
|
}
|
|
493
|
-
/** Transfer saved files under source and destination locks. */
|
|
494
|
-
async move(source, destination, id, baseVersion, ownToken) {
|
|
495
|
-
if (source.scope !== 'workspace' || destination.scope !== 'workspace' || source.root === destination.root) {
|
|
496
|
-
throw new ArtifactError('artifact/bad-request', 'Choose a different workspace.');
|
|
497
|
-
}
|
|
498
|
-
const dir = await artifactDir(source, id);
|
|
499
|
-
const target = path.join(destination.root, id);
|
|
500
|
-
await assertWithin(destination.root, target);
|
|
501
|
-
const first = dir < target ? dir : target;
|
|
502
|
-
const second = dir < target ? target : dir;
|
|
503
|
-
return withLock(first, () => withLock(second, async () => {
|
|
504
|
-
await assertNoEditors(dir, ownToken);
|
|
505
|
-
const manifest = await this.readManifest(dir);
|
|
506
|
-
if (manifest.version !== baseVersion) {
|
|
507
|
-
throw new ArtifactError('artifact/stale-version', 'The artifact changed before it could be moved.', { current: manifest.version, baseVersion });
|
|
508
|
-
}
|
|
509
|
-
try {
|
|
510
|
-
await fs.lstat(target);
|
|
511
|
-
throw new ArtifactError('artifact/bad-request', 'The destination already contains this artifact.', { id });
|
|
512
|
-
}
|
|
513
|
-
catch (error) {
|
|
514
|
-
if (error instanceof ArtifactError || errnoCode(error) !== 'ENOENT')
|
|
515
|
-
throw error;
|
|
516
|
-
}
|
|
517
|
-
const inspect = async (entry) => {
|
|
518
|
-
await assertWithin(source.root, entry);
|
|
519
|
-
const stat = await fs.lstat(entry);
|
|
520
|
-
if (stat.isSymbolicLink() || (!stat.isFile() && !stat.isDirectory())) {
|
|
521
|
-
throw new ArtifactError('artifact/forbidden-path', 'An artifact contains an unsafe file.');
|
|
522
|
-
}
|
|
523
|
-
if (stat.isDirectory())
|
|
524
|
-
for (const name of await fs.readdir(entry))
|
|
525
|
-
await inspect(path.join(entry, name));
|
|
526
|
-
};
|
|
527
|
-
await inspect(dir);
|
|
528
|
-
await assertWithin(destination.root, target);
|
|
529
|
-
try {
|
|
530
|
-
await fs.rename(dir, target);
|
|
531
|
-
}
|
|
532
|
-
catch (error) {
|
|
533
|
-
if (errnoCode(error) === 'EXDEV')
|
|
534
|
-
throw new ArtifactError('artifact/storage-failure', 'Source and destination must be on the same filesystem. The artifact was not moved.');
|
|
535
|
-
throw error;
|
|
536
|
-
}
|
|
537
|
-
return manifest;
|
|
538
|
-
}));
|
|
539
|
-
}
|
|
540
492
|
/**
|
|
541
493
|
* Move an artifact into the scope's trash, then sweep trash entries past retention.
|
|
542
494
|
* @param root the scope root.
|
package/dist/host/lib/tools.js
CHANGED
|
@@ -167,7 +167,7 @@ export function createTools(host) {
|
|
|
167
167
|
additionalProperties: false,
|
|
168
168
|
required: ['type', 'title', 'content'],
|
|
169
169
|
properties: {
|
|
170
|
-
type: { type: 'string', enum: ['page', 'doc', 'design'], description: 'page for HTML, doc for Markdown, design for OpenPencil Design JSX. For a design, load the artifact-design skill first: no imports, no HTML.' },
|
|
170
|
+
type: { type: 'string', enum: ['page', 'doc', 'design'], description: 'page for HTML, doc for Markdown, design for OpenPencil Design JSX. A mockup or wireframe is always design. For a design, load the artifact-design skill first: no imports, no HTML. If a design fails for a reason other than its source, report the error; never redo it as a page.' },
|
|
171
171
|
title: { type: 'string', description: 'Short title, 1 to 120 characters.' },
|
|
172
172
|
content: { type: 'string', description: 'The full HTML document, Markdown text, or Design JSX source, up to 2 MiB.' },
|
|
173
173
|
scope: SCOPE_PARAM,
|
|
@@ -312,21 +312,6 @@ export function createTools(host) {
|
|
|
312
312
|
return { ...summary(manifest, target), warnings };
|
|
313
313
|
},
|
|
314
314
|
};
|
|
315
|
-
const move = {
|
|
316
|
-
name: 'artifact_move',
|
|
317
|
-
description: 'Move a saved workspace artifact to another registered workspace. Ask the user first. Close all editors for the artifact before moving it.',
|
|
318
|
-
parameters: { type: 'object', additionalProperties: false, required: ['id', 'destinationWorkspaceId', 'baseVersion'], properties: {
|
|
319
|
-
id: { type: 'string' }, destinationWorkspaceId: { type: 'string' }, baseVersion: { type: 'integer' },
|
|
320
|
-
} },
|
|
321
|
-
output: { schema: SUMMARY_SCHEMA, render: (_args, value) => [{ type: 'text', text: 'Moved artifact: ' + String(record(value).id) + ' to workspace ' + String(record(value).workspaceId) }] },
|
|
322
|
-
async execute(args, exec) {
|
|
323
|
-
const fields = fieldsOf(args);
|
|
324
|
-
const target = await targetFor(host, exec, undefined);
|
|
325
|
-
const destinationWorkspaceId = requiredString(fields, 'destinationWorkspaceId');
|
|
326
|
-
const manifest = await service.move(target, requiredString(fields, 'id'), destinationWorkspaceId, requiredInteger(fields, 'baseVersion'));
|
|
327
|
-
return summary(manifest, { scope: 'workspace', workspaceId: destinationWorkspaceId });
|
|
328
|
-
},
|
|
329
|
-
};
|
|
330
315
|
const list = {
|
|
331
316
|
name: 'artifact_list',
|
|
332
317
|
description: 'List artifacts in this project or the profile library, newest first, at most 50 per call.',
|
|
@@ -460,5 +445,5 @@ export function createTools(host) {
|
|
|
460
445
|
return { scope: saved.scope, tokens: JSON.stringify(saved.tokens, null, 2) };
|
|
461
446
|
},
|
|
462
447
|
};
|
|
463
|
-
return [create, read, update,
|
|
448
|
+
return [create, read, update, list, remove, exportTool, designRead, designUpdate];
|
|
464
449
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-artifact-studio",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Local-first artifacts for DeepSeek Harness: the agent creates pages and documents as versioned files, and you open, edit, restore, and export them beside the chat.",
|
|
6
6
|
"keywords": [
|
|
@@ -63,11 +63,13 @@
|
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@open-pencil/core": "0.16.0",
|
|
66
|
+
"@open-pencil/scene-graph": "0.16.0",
|
|
66
67
|
"docx": "9.15.3",
|
|
67
68
|
"marked": "^17.0.1"
|
|
68
69
|
},
|
|
69
70
|
"devDependencies": {
|
|
70
71
|
"@iconify-json/mdi": "1.2.3",
|
|
72
|
+
"@open-pencil/design-jsx": "0.16.0",
|
|
71
73
|
"@open-pencil/vue": "0.16.0",
|
|
72
74
|
"@tiptap/core": "3.33.1",
|
|
73
75
|
"@tiptap/extension-list": "^3.33.1",
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { ArtifactError } from './errors.js';
|
|
2
|
-
import fs from 'node:fs/promises';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { assertWithin, withLock } from './fsutil.js';
|
|
5
|
-
export async function acquireEditor(key, token, check) {
|
|
6
|
-
await withLock(key, async () => {
|
|
7
|
-
await check();
|
|
8
|
-
if (!/^[a-zA-Z0-9-]{1,100}$/.test(token))
|
|
9
|
-
throw new ArtifactError('artifact/bad-request', 'Invalid editor token.');
|
|
10
|
-
const leaseDir = path.join(key, '.editors');
|
|
11
|
-
await assertWithin(key, leaseDir);
|
|
12
|
-
await fs.mkdir(leaseDir, { recursive: true });
|
|
13
|
-
const artifactDirectory = await fs.open(key, 'r');
|
|
14
|
-
try {
|
|
15
|
-
await artifactDirectory.sync();
|
|
16
|
-
}
|
|
17
|
-
finally {
|
|
18
|
-
await artifactDirectory.close();
|
|
19
|
-
}
|
|
20
|
-
const marker = path.join(leaseDir, token);
|
|
21
|
-
await assertWithin(key, marker);
|
|
22
|
-
const handle = await fs.open(marker, 'a', 0o600);
|
|
23
|
-
try {
|
|
24
|
-
await handle.sync();
|
|
25
|
-
}
|
|
26
|
-
finally {
|
|
27
|
-
await handle.close();
|
|
28
|
-
}
|
|
29
|
-
const directory = await fs.open(leaseDir, 'r');
|
|
30
|
-
try {
|
|
31
|
-
await directory.sync();
|
|
32
|
-
}
|
|
33
|
-
finally {
|
|
34
|
-
await directory.close();
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
export async function releaseEditor(key, token) {
|
|
39
|
-
await withLock(key, async () => {
|
|
40
|
-
if (!/^[a-zA-Z0-9-]{1,100}$/.test(token))
|
|
41
|
-
throw new ArtifactError('artifact/bad-request', 'Invalid editor token.');
|
|
42
|
-
const marker = path.join(key, '.editors', token);
|
|
43
|
-
await assertWithin(key, marker);
|
|
44
|
-
await fs.rm(marker, { force: true });
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
/** Call only while holding the same artifact lock as acquireEditor. */
|
|
48
|
-
export async function assertNoEditors(key, ownToken) {
|
|
49
|
-
const directory = path.join(key, '.editors');
|
|
50
|
-
await assertWithin(key, directory);
|
|
51
|
-
let holders;
|
|
52
|
-
try {
|
|
53
|
-
holders = await fs.readdir(directory);
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
if (!(error instanceof Error) || !('code' in error) || error.code !== 'ENOENT')
|
|
57
|
-
throw error;
|
|
58
|
-
holders = [];
|
|
59
|
-
}
|
|
60
|
-
if ((ownToken !== undefined && !holders.includes(ownToken)) || holders.some(token => token !== ownToken)) {
|
|
61
|
-
throw new ArtifactError('artifact/editor-open', 'Close all open editors for this artifact before moving it.');
|
|
62
|
-
}
|
|
63
|
-
}
|