@vivix-labs/studio-workbench 1.0.0-beta.5 → 1.0.0-beta.9

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/skills/SKILL.md CHANGED
@@ -34,6 +34,15 @@ revision and set `changes.coverRef` to a saved image's exact VersionRef from tha
34
34
  project, or to `null` to remove it. Verify the saved reference and refresh Manage
35
35
  Projects to see it on both the project card and sidebar.
36
36
 
37
+ ## Remove or restore a project in the workbench
38
+
39
+ Remove project hides the project from the sidebar, Home project cards, and
40
+ Manage Projects. The local directory, registration, and saved content remain
41
+ available. For a request to restore a project by name, match its registered
42
+ ID and discover `workspace.hiddenProjects` and `workspace.setProjectHidden`
43
+ on the user-scope workbench instance. Read the hidden IDs, set
44
+ `hidden: false` for the matching ID, and verify it is no longer hidden.
45
+
37
46
  ## Refresh the affected workbench
38
47
 
39
48
  After an operation succeeds and changes data shown in an open workbench, check that the
@@ -67,9 +76,10 @@ reference. Explicit roles keep their declared validation.
67
76
 
68
77
  After installing the matching official archives, run this package's
69
78
  `skills/scripts/initialize-home.mjs` with Node in the intended Studio profile.
70
- It applies the user preset and creates two editable example projects. Use
71
- `--no-open` to print their IDs and the Home bookmark. Rerun it to resume an
72
- incomplete setup.
79
+ It applies the user preset and opens Home. Use `--no-open` to print the Home
80
+ bookmark. The welcome dialog imports only the selected sample. Use
81
+ `--sample out-of-steps` or `--sample cobalt-headphones` to import a sample or
82
+ resume its interrupted import from the CLI.
73
83
 
74
84
  Home composes user-scope components from the workbench instance's
75
85
  `config.dashboard` array of `{ "plugin": "instance-id", "id": "ui-id" }`
@@ -1,37 +1,40 @@
1
1
  import { execFile, spawn } from 'node:child_process';
2
- import { mkdir, readFile, readdir, realpath, rename, rm, writeFile } from 'node:fs/promises';
2
+ import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
3
3
  import { homedir } from 'node:os';
4
- import { basename, dirname, join, resolve, sep } from 'node:path';
5
- import { fileURLToPath } from 'node:url';
6
- import { promisify } from 'node:util';
4
+ import { basename, dirname, join, resolve } from 'node:path';
5
+ import { parseArgs, promisify } from 'node:util';
7
6
 
8
7
  const exec = promisify(execFile);
9
- const args = process.argv.slice(2);
10
- if (args.includes('--help')) {
8
+ const { values } = parseArgs({
9
+ options: {
10
+ help: { type: 'boolean' },
11
+ 'no-open': { type: 'boolean' },
12
+ sample: { type: 'string' },
13
+ },
14
+ });
15
+ if (values.help) {
11
16
  console.log(
12
- 'Usage: node initialize-home.mjs [--no-open] [--add-cobalt]\nUse VIVIX_STUDIO_CLI to select a CLI executable or built JS entry.',
17
+ 'Usage: node initialize-home.mjs [--no-open] [--sample out-of-steps|cobalt-headphones]\nUse VIVIX_STUDIO_CLI to select a CLI executable or built JS entry.',
13
18
  );
14
19
  process.exit(0);
15
20
  }
16
- if (args.some((arg) => !['--no-open', '--add-cobalt'].includes(arg)))
17
- throw Error('Unknown option. Use --help.');
18
21
  const executable = process.env.VIVIX_STUDIO_CLI || 'vivix-studio';
19
22
  const js = /\.[cm]?js$/.test(executable);
20
23
  const command = js ? process.execPath : executable;
21
24
  const prefix = js ? [resolve(executable)] : [];
22
- const root = join(process.env.XDG_CONFIG_HOME || join(homedir(), '.config'), 'vivix-studio');
25
+ const root = process.env.XDG_CONFIG_HOME
26
+ ? join(process.env.XDG_CONFIG_HOME, 'vivix-studio')
27
+ : join(homedir(), '.vivix-studio');
23
28
  const userPackage = JSON.parse(
24
29
  await readFile(new URL('../../package.json', import.meta.url), 'utf8'),
25
30
  );
26
31
  const userPreset = `${userPackage.name}@${userPackage.version}:user-base`;
27
- const adsPackage = '@vivix-labs/ads-workbench';
28
- const adsVersion = userPackage.vivixStudio.runtimePlugins[adsPackage];
29
- const adsPreset = `${adsPackage}@${adsVersion}:ads`;
30
- const dramaPreset = '@vivix-labs/short-drama-workbench:short-drama';
31
- const scopes = [
32
- { id: 'out-of-steps', preset: dramaPreset, skill: 'vivix-out-of-steps-example' },
33
- { id: 'cobalt-headphones', preset: adsPreset, skill: 'vivix-cobalt-example' },
34
- ];
32
+ const samples = {
33
+ 'out-of-steps': { package: '@vivix-labs/short-drama-workbench', presetId: 'short-drama' },
34
+ 'cobalt-headphones': { package: '@vivix-labs/ads-workbench', presetId: 'ads' },
35
+ };
36
+ const sample = values.sample;
37
+ if (sample !== undefined && !Object.hasOwn(samples, sample)) throw Error('Unknown sample.');
35
38
  const access =
36
39
  'project.content.read,project.content.write,official.request,events.publish,events.subscribe';
37
40
  const homeState = join(root, 'home-initialization.json');
@@ -43,20 +46,6 @@ const save = async () => {
43
46
  await rename(homeState + '.tmp', homeState);
44
47
  };
45
48
 
46
- async function linkedSeed(project, skill, packageName, version) {
47
- const links = join(project.root, '.agents', 'skills');
48
- const pluginRoot = await realpath(join(root, 'plugins'));
49
- for (const entry of await readdir(links, { withFileTypes: true })) {
50
- if (!entry.isSymbolicLink()) continue;
51
- const target = await realpath(join(links, entry.name)).catch(() => null);
52
- if (!target?.startsWith(pluginRoot + sep) || basename(target) !== skill) continue;
53
- const pkg = await read(join(target, '..', '..', 'package.json'));
54
- if (pkg.name === packageName && pkg.version === version)
55
- return join(target, 'scripts', 'initialize.mjs');
56
- }
57
- throw Error('Cannot find the installed seed Skill: ' + skill);
58
- }
59
-
60
49
  async function cli(...arguments_) {
61
50
  let stdout;
62
51
  try {
@@ -79,12 +68,19 @@ function interrupt(signal) {
79
68
  }
80
69
  function runSeed(path, project) {
81
70
  return new Promise((done, reject) => {
82
- child = spawn(process.execPath, [path, '--project', project, '--apply'], { stdio: 'inherit' });
71
+ child = spawn(process.execPath, [path, '--project', project, '--apply'], {
72
+ stdio: ['ignore', 'ignore', 'pipe'],
73
+ });
74
+ let failure = '';
75
+ child.stderr.setEncoding('utf8').on('data', (chunk) => {
76
+ failure = (failure + chunk).slice(-4096);
77
+ });
83
78
  child.on('error', reject);
84
79
  child.on('close', (code) => {
85
80
  child = undefined;
86
81
  if (code === 0) done();
87
- else reject(Error('Example import stopped. Rerun initialization to resume.'));
82
+ else
83
+ reject(Error(failure.trim() || 'Example import stopped. Rerun initialization to resume.'));
88
84
  });
89
85
  });
90
86
  }
@@ -92,6 +88,51 @@ function assertRunning() {
92
88
  if (stopped) throw Error('Initialization stopped. Rerun it to resume.');
93
89
  }
94
90
 
91
+ async function warmDramaWorkbenches() {
92
+ const { stdout } = await exec(command, [...prefix, 'preset', '--help']);
93
+ if (!stdout.includes('warm-client')) return;
94
+ const name = samples['out-of-steps'].package;
95
+ const version = userPackage.vivixStudio.runtimePlugins[name];
96
+ for (const id of ['out-of-steps', 'short-drama'])
97
+ await cli('preset', 'warm-client', `${name}@${version}:${id}`);
98
+ }
99
+
100
+ async function configureDramaChat(projectId) {
101
+ // Trial setup can enable chat before the on-demand drama project exists.
102
+ const user = await cli('plugin', 'list', '--scope', 'user');
103
+ const chat = user.instances.find(
104
+ (item) =>
105
+ item.id === 'chat-components' &&
106
+ item.package === '@vivix-labs/chat-components' &&
107
+ item.state === 'ready',
108
+ );
109
+ if (!chat) return;
110
+ const project = await cli('plugin', 'list', '--project', projectId);
111
+ if (project.instances.some((item) => item.id === chat.id)) return;
112
+ const config = join(lock, 'chat-components.json');
113
+ await writeFile(
114
+ config,
115
+ JSON.stringify({
116
+ targets: { character: { instanceId: 'authoring', operationId: 'characters.receiveCard' } },
117
+ }),
118
+ { mode: 0o600 },
119
+ );
120
+ await cli(
121
+ 'plugin',
122
+ 'enable',
123
+ chat.package,
124
+ '--version',
125
+ chat.version,
126
+ '--project',
127
+ projectId,
128
+ '--instance',
129
+ chat.id,
130
+ '--config',
131
+ config,
132
+ '--trust',
133
+ );
134
+ }
135
+
95
136
  await mkdir(dirname(homeState), { recursive: true, mode: 0o700 });
96
137
  try {
97
138
  await mkdir(lock, { mode: 0o700 });
@@ -112,79 +153,77 @@ try {
112
153
  } catch (error) {
113
154
  if (error.code !== 'ENOENT') throw error;
114
155
  }
115
- const addingCobalt = args.includes('--add-cobalt');
116
- if (!state.complete || (addingCobalt && !state.projects['cobalt-headphones']?.complete)) {
117
- // Resume an older unfinished Home using its original project identities.
118
- const requested =
119
- state.projects['rhode-summer-launch'] && !state.complete && !addingCobalt
120
- ? [
121
- scopes[0],
122
- { id: 'rhode-summer-launch', preset: adsPreset, skill: 'vivix-rhode-example' },
123
- ]
124
- : scopes;
125
- const { presets } = await cli('preset', 'list');
126
- const dramaPackage = '@vivix-labs/short-drama-workbench';
127
- const drama = presets.find(
128
- (item) =>
129
- item.package === dramaPackage &&
130
- item.version === userPackage.vivixStudio.runtimePlugins[dramaPackage] &&
131
- item.presetId === 'short-drama',
132
- );
133
- if (
134
- !drama ||
135
- !presets.some(
136
- (item) =>
137
- item.package === adsPackage && item.version === adsVersion && item.presetId === 'ads',
138
- ) ||
139
- !['user-base'].every((presetId) =>
140
- presets.some(
141
- (item) =>
142
- item.package === userPackage.name &&
143
- item.version === userPackage.version &&
144
- item.presetId === presetId,
145
- ),
146
- )
147
- )
148
- throw Error(
149
- 'Install the matching Home, Short Drama and Advertising preset packages before initializing Home.',
156
+ if (!state.workspace) {
157
+ const user = await cli('plugin', 'list', '--scope', 'user');
158
+ if (user.instances.length) {
159
+ const installed = user.instances.find((item) => item.id === 'workbench');
160
+ if (installed?.package !== userPackage.name || installed.version !== userPackage.version)
161
+ throw Error(
162
+ 'This profile already has a different user workbench. Use a fresh profile for first setup.',
163
+ );
164
+ } else {
165
+ await cli(
166
+ 'preset',
167
+ 'apply',
168
+ userPreset,
169
+ '--scope',
170
+ 'user',
171
+ '--trust',
172
+ '--allow-access',
173
+ access,
150
174
  );
151
- if (!state.workspace) {
152
- const user = await cli('plugin', 'list', '--scope', 'user');
153
- if (user.instances.length) {
154
- const installed = user.instances.find((item) => item.id === 'workbench');
155
- if (installed?.package !== userPackage.name || installed.version !== userPackage.version)
156
- throw Error(
157
- 'This profile already has a different user workbench. Use a fresh profile for first setup.',
158
- );
159
- } else {
160
- await cli(
161
- 'preset',
162
- 'apply',
163
- userPreset,
164
- '--scope',
165
- 'user',
166
- '--trust',
167
- '--allow-access',
168
- access,
175
+ }
176
+ state.workspace = true;
177
+ await save();
178
+ }
179
+ if (sample) {
180
+ assertRunning();
181
+ const directory = join(root, 'projects', 'studio-home-examples', sample);
182
+ const { projects } = await cli('project', 'list');
183
+ let receipt = state.projects[sample];
184
+ if (!receipt && sample === 'out-of-steps') {
185
+ // Match the browser creation receipt, so CLI and Welcome share the prepared project.
186
+ const requestId = '66067767-ff7a-4c73-9cd2-debde07b6ea2';
187
+ for (const project of projects) {
188
+ if (!project.available || basename(project.root) !== `project-${requestId}`) continue;
189
+ const created = await read(join(project.root, '.vivix/workbench-create.json')).catch(
190
+ (error) => {
191
+ if (error.code !== 'ENOENT') throw error;
192
+ return undefined;
193
+ },
169
194
  );
195
+ if (created?.requestId !== requestId || !created.preset.endsWith(':out-of-steps')) continue;
196
+ await read(join(project.root, '.vivix/out-of-steps.initialized.json'));
197
+ receipt = state.projects[sample] = {
198
+ directory: project.root,
199
+ preset: created.preset,
200
+ projectId: project.id,
201
+ complete: true,
202
+ };
203
+ await save();
170
204
  }
171
- state.workspace = true;
172
- await save();
173
205
  }
174
- for (const spec of requested) {
175
- assertRunning();
176
- const preset =
177
- spec.preset === dramaPreset ? `${drama.package}@${drama.version}:short-drama` : spec.preset;
178
- let receipt = state.projects[spec.id];
179
- const directory = join(root, 'projects', 'studio-home-examples', spec.id);
180
- const { projects } = await cli('project', 'list');
206
+ if (!receipt?.complete) {
207
+ const spec = samples[sample];
208
+ const samplePreset = `${spec.package}@${userPackage.vivixStudio.runtimePlugins[spec.package]}:${spec.presetId}`;
209
+ const { presets } = await cli('preset', 'list');
210
+ const preparedPreset = samplePreset.replace(/:short-drama$/, ':out-of-steps');
211
+ const hasPrepared =
212
+ sample === 'out-of-steps' &&
213
+ presets.some(
214
+ (item) => `${item.package}@${item.version}:${item.presetId}` === preparedPreset,
215
+ );
216
+ const preset = receipt?.preset ?? (hasPrepared ? preparedPreset : samplePreset);
217
+ const installed = presets.find(
218
+ (item) => `${item.package}@${item.version}:${item.presetId}` === samplePreset,
219
+ );
220
+ if (!installed) throw Error('Install the matching workbench plugin to load this sample.');
181
221
  if (!receipt) {
182
222
  if (projects.some((item) => item.root === directory))
183
223
  throw Error('The example directory is already registered: ' + directory);
184
- receipt = state.projects[spec.id] = { directory, preset };
224
+ receipt = state.projects[sample] = { directory, preset };
185
225
  await save();
186
226
  }
187
- if (receipt.complete) continue;
188
227
  if (!receipt.projectId) {
189
228
  const registered = projects.find(
190
229
  (item) => item.root === receipt.directory && item.available,
@@ -194,7 +233,7 @@ try {
194
233
  (await cli(
195
234
  'project',
196
235
  'init',
197
- spec.id,
236
+ sample,
198
237
  '--directory',
199
238
  receipt.directory,
200
239
  '--preset',
@@ -207,32 +246,29 @@ try {
207
246
  await save();
208
247
  }
209
248
  assertRunning();
210
- const project = (await cli('project', 'list')).projects.find(
211
- (item) => item.id === receipt.projectId && item.available,
212
- );
213
- if (!project) throw Error('The example project is unavailable: ' + receipt.projectId);
214
- await cli('project', 'open', '--project', project.id, '--no-open');
215
- const seed =
216
- spec.preset === adsPreset
217
- ? await linkedSeed(project, spec.skill, adsPackage, adsVersion)
218
- : await linkedSeed(
219
- project,
220
- spec.skill,
221
- drama.package,
222
- receipt.preset.split('@').at(-1).split(':')[0],
223
- );
224
- await runSeed(seed, project.id);
249
+ if (receipt.preset.endsWith(':out-of-steps')) {
250
+ await read(join(receipt.directory, '.vivix/out-of-steps.initialized.json'));
251
+ } else {
252
+ await runSeed(
253
+ join(installed.packageRoot, 'samples', sample, 'scripts/initialize.mjs'),
254
+ receipt.projectId,
255
+ );
256
+ if (sample === 'out-of-steps') await configureDramaChat(receipt.projectId);
257
+ }
225
258
  receipt.complete = true;
226
259
  await save();
227
260
  }
228
- state.complete = true;
229
- await save();
230
- }
231
- assertRunning();
232
- if (args.includes('--no-open')) {
261
+ const project = (await cli('project', 'list')).projects.find(
262
+ (item) => item.id === receipt.projectId && item.available,
263
+ );
264
+ if (!project) throw Error('The sample project is unavailable: ' + receipt.projectId);
265
+ console.log(JSON.stringify({ ok: true, project }));
266
+ } else if (values['no-open']) {
267
+ await warmDramaWorkbenches();
233
268
  const { workbenchUrl } = await cli('project', 'open', '--scope', 'user', '--no-open');
234
269
  console.log(JSON.stringify({ ok: true, projects: state.projects, workbenchUrl }));
235
270
  } else {
271
+ await warmDramaWorkbenches();
236
272
  await exec(command, [...prefix, 'project', 'open', '--scope', 'user']);
237
273
  }
238
274
  } catch (error) {
@@ -1,4 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="white" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round">
2
- <path d="M8 1.5v9m-3.5-3.5L8 10.5 11.5 7"/>
3
- <path d="M2 10.5v1.75A1.75 1.75 0 0 0 3.75 14h8.5A1.75 1.75 0 0 0 14 12.25V10.5"/>
4
- </svg>