@myrialabs/clopen 0.4.40 → 0.4.42

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 (141) hide show
  1. package/.env.example +1 -1
  2. package/backend/artifacts/detect.ts +15 -3
  3. package/backend/artifacts/generate.ts +2 -2
  4. package/backend/artifacts/index.ts +12 -4
  5. package/backend/artifacts/markers.ts +24 -1
  6. package/backend/artifacts/matrix.ts +47 -3
  7. package/backend/artifacts/sync.test.ts +3 -3
  8. package/backend/artifacts/sync.ts +8 -20
  9. package/backend/artifacts/types.ts +9 -3
  10. package/backend/auth/permissions.ts +6 -11
  11. package/backend/auth/session-cleanup.ts +10 -1
  12. package/backend/auth/tokens.ts +9 -1
  13. package/backend/chat/stream-manager.ts +50 -0
  14. package/backend/database/crypto/secret-columns.ts +5 -1
  15. package/backend/database/index.ts +18 -0
  16. package/backend/database/migrations/079_merge_commands_into_skills.ts +222 -0
  17. package/backend/database/migrations/080_create_file_shares.ts +111 -0
  18. package/backend/database/migrations/081_create_push_subscriptions.ts +32 -0
  19. package/backend/database/migrations/082_create_git_identities.test.ts +186 -0
  20. package/backend/database/migrations/082_create_git_identities.ts +122 -0
  21. package/backend/database/migrations/index.ts +28 -0
  22. package/backend/database/queries/file-share-queries.ts +163 -0
  23. package/backend/database/queries/git-identity-queries.ts +290 -0
  24. package/backend/database/queries/index.ts +8 -4
  25. package/backend/database/queries/profile-queries.ts +5 -3
  26. package/backend/database/queries/push-subscription-queries.test.ts +90 -0
  27. package/backend/database/queries/push-subscription-queries.ts +99 -0
  28. package/backend/database/queries/skill-queries.ts +96 -18
  29. package/backend/engine/adapters/claude/environment.ts +11 -1
  30. package/backend/engine/adapters/claude/stream.ts +3 -2
  31. package/backend/engine/adapters/cline/stream.ts +3 -3
  32. package/backend/engine/adapters/codex/stream.ts +38 -6
  33. package/backend/engine/adapters/copilot/stream.ts +3 -3
  34. package/backend/engine/adapters/cursor/stream.ts +25 -3
  35. package/backend/engine/adapters/opencode/server.ts +26 -2
  36. package/backend/engine/adapters/opencode/stream.ts +8 -7
  37. package/backend/engine/adapters/pi/stream.ts +2 -2
  38. package/backend/engine/adapters/qwen/stream.ts +5 -3
  39. package/backend/engine/artifact-sync.ts +26 -20
  40. package/backend/engine/docs/artifacts.md +81 -22
  41. package/backend/engine/docs/quick-reference.md +2 -1
  42. package/backend/engine/resolve-model.test.ts +108 -0
  43. package/backend/engine/resolve-model.ts +53 -10
  44. package/backend/engine/structured-helpers.ts +22 -0
  45. package/backend/engine/types.ts +10 -0
  46. package/backend/files/file-shares.ts +369 -0
  47. package/backend/files/path-browsing.ts +27 -21
  48. package/backend/git/git-executor.ts +28 -2
  49. package/backend/git/git-service.ts +59 -40
  50. package/backend/git/identity/cli.test.ts +58 -0
  51. package/backend/git/identity/cli.ts +201 -0
  52. package/backend/git/identity/credential-helper.test.ts +242 -0
  53. package/backend/git/identity/env.test.ts +214 -0
  54. package/backend/git/identity/env.ts +193 -0
  55. package/backend/git/identity/import-local.test.ts +199 -0
  56. package/backend/git/identity/import-local.ts +141 -0
  57. package/backend/git/identity/index.ts +78 -0
  58. package/backend/git/identity/keys.ts +183 -0
  59. package/backend/git/identity/resolve.ts +140 -0
  60. package/backend/git/identity/scope-config.test.ts +145 -0
  61. package/backend/git/identity/scope-config.ts +175 -0
  62. package/backend/git/identity/service.ts +297 -0
  63. package/backend/http/files-shared.test.ts +505 -0
  64. package/backend/http/files-shared.ts +351 -0
  65. package/backend/http/push.ts +150 -0
  66. package/backend/index.ts +24 -0
  67. package/backend/instructions/index.ts +1 -1
  68. package/backend/instructions/sync.ts +30 -6
  69. package/backend/memory/compose.ts +2 -2
  70. package/backend/memory/consolidate.ts +2 -2
  71. package/backend/memory/extract/episodic.ts +2 -2
  72. package/backend/memory/judge.ts +2 -2
  73. package/backend/preview/browser/browser-console-manager.ts +214 -34
  74. package/backend/preview/browser/browser-pool.ts +526 -123
  75. package/backend/preview/browser/browser-preview-service.ts +192 -8
  76. package/backend/preview/browser/browser-tab-lifecycle.test.ts +240 -0
  77. package/backend/preview/browser/browser-tab-lifecycle.ts +495 -0
  78. package/backend/preview/browser/browser-tab-manager.ts +291 -65
  79. package/backend/preview/browser/capture-profile.ts +15 -1
  80. package/backend/preview/browser/types.ts +26 -1
  81. package/backend/profiles/service.ts +7 -6
  82. package/backend/push/sender.ts +172 -0
  83. package/backend/push/tags.ts +25 -0
  84. package/backend/push/vapid-keys.ts +77 -0
  85. package/backend/push/webpush-crypto.test.ts +200 -0
  86. package/backend/push/webpush-crypto.ts +231 -0
  87. package/backend/skills/detect.ts +28 -0
  88. package/backend/skills/index.ts +22 -4
  89. package/backend/skills/invoke.test.ts +114 -0
  90. package/backend/skills/invoke.ts +222 -0
  91. package/backend/skills/service.ts +194 -44
  92. package/backend/skills/spec.ts +35 -0
  93. package/backend/skills/sync.ts +85 -55
  94. package/backend/subagents/detect.ts +2 -3
  95. package/backend/subagents/sync.ts +15 -8
  96. package/backend/terminal/ptykit.ts +24 -0
  97. package/backend/work/pull-requests.ts +2 -2
  98. package/backend/ws/chat/stream.ts +100 -8
  99. package/backend/ws/files/index.ts +4 -0
  100. package/backend/ws/files/share.ts +95 -0
  101. package/backend/ws/git/branch-name.ts +2 -2
  102. package/backend/ws/git/branch.ts +17 -6
  103. package/backend/ws/git/commit-message.ts +2 -2
  104. package/backend/ws/git/commit.ts +6 -5
  105. package/backend/ws/git/conflict.ts +3 -2
  106. package/backend/ws/git/identity-context.ts +91 -0
  107. package/backend/ws/git/identity.ts +200 -0
  108. package/backend/ws/git/index.ts +3 -1
  109. package/backend/ws/git/remote.ts +57 -11
  110. package/backend/ws/index.ts +3 -4
  111. package/backend/ws/preview/browser/data.ts +60 -0
  112. package/backend/ws/preview/browser/interact.ts +6 -0
  113. package/backend/ws/preview/browser/tab-info.ts +9 -1
  114. package/backend/ws/preview/browser/tab.ts +64 -8
  115. package/backend/ws/preview/index.ts +21 -0
  116. package/backend/ws/profiles/crud.ts +2 -3
  117. package/backend/ws/skills/catalog.ts +5 -1
  118. package/backend/ws/skills/crud.ts +128 -22
  119. package/backend/ws/skills/index.ts +4 -1
  120. package/backend/ws/user/crud.ts +12 -3
  121. package/bin/clopen.ts +9 -0
  122. package/dist/assets/{index-D4igjF6e.js → index-BynqyvF4.js} +1 -1
  123. package/dist/assets/{index-DONNwiXm.js → index-DLoJsmNQ.js} +1 -1
  124. package/dist/assets/{main-BrfXH1bL.js → main-CUyZAmqt.js} +601 -592
  125. package/dist/assets/main-DVCW3cfr.css +1 -0
  126. package/dist/index.html +7 -2
  127. package/dist/sw.js +112 -0
  128. package/package.json +2 -2
  129. package/shared/constants/engine-tools.ts +31 -6
  130. package/shared/constants/notification-messages.ts +142 -0
  131. package/shared/types/git-identity.ts +112 -0
  132. package/shared/types/unified/stream.ts +7 -0
  133. package/backend/commands/detect.ts +0 -25
  134. package/backend/commands/index.ts +0 -9
  135. package/backend/commands/service.ts +0 -178
  136. package/backend/commands/store.ts +0 -45
  137. package/backend/commands/sync.ts +0 -94
  138. package/backend/database/queries/command-queries.ts +0 -82
  139. package/backend/ws/commands/crud.ts +0 -157
  140. package/backend/ws/commands/index.ts +0 -8
  141. package/dist/assets/main-CT1PygsW.css +0 -1
@@ -2,9 +2,25 @@
2
2
  * Skill service — orchestrates the DB metadata table and the on-disk canonical
3
3
  * store for the Settings → Skills CRUD surface. The WS layer calls these; they
4
4
  * keep the `skills` table and `{clopenDir}/skills/<slug>/` in lockstep.
5
+ *
6
+ * Since migration 079 a skill covers BOTH ways of invoking a reusable prompt:
7
+ * - `auto` — the model reads the description and loads the skill when it fits;
8
+ * - `slash` — the user types `/<slug>` and Clopen expands the body into the
9
+ * prompt (see `./invoke.ts`). This is what the old Commands feature was.
10
+ * The two are independent switches, so one skill can be both.
5
11
  */
6
12
 
7
- import { skillQueries, type SkillRow, type SkillSource } from '$backend/database/queries';
13
+ import {
14
+ skillQueries,
15
+ parseTriggers,
16
+ stringifyTriggers,
17
+ parseUses,
18
+ stringifyUses,
19
+ type SkillRow,
20
+ type SkillSource,
21
+ type SkillTrigger
22
+ } from '$backend/database/queries';
23
+ import { uniqueSlug } from '$backend/artifacts';
8
24
  import { debug } from '$shared/utils/logger';
9
25
  import {
10
26
  parseSkillMd,
@@ -32,21 +48,58 @@ export interface SkillDTO {
32
48
  marketplaceRef: string | null;
33
49
  version: string | null;
34
50
  license: string | null;
51
+ /** How the skill can be invoked — `auto` and/or `slash`. Never empty. */
52
+ triggers: SkillTrigger[];
53
+ /** Argument hint shown beside `/slug` in the chat picker. */
54
+ argumentHint: string | null;
55
+ /** Sibling slugs force-loaded whenever this skill runs. */
56
+ uses: string[];
35
57
  enabled: boolean;
36
58
  /** False when the DB row exists but its SKILL.md is missing on disk. */
37
59
  present: boolean;
38
60
  createdAt: string;
39
61
  }
40
62
 
63
+ /** Editable fields shared by create / update. */
64
+ export interface SkillInputFields {
65
+ /**
66
+ * Machine id, settable only at creation.
67
+ *
68
+ * It is the folder name on disk, the `/<slug>` a user types in chat, and what
69
+ * `uses:` lists and Profile bundles reference — so renaming it after the fact
70
+ * would break every one of those silently. Blank means "derive it from the
71
+ * name". {@link skillService.update} ignores this field entirely.
72
+ */
73
+ slug?: string;
74
+ name: string;
75
+ description: string;
76
+ body: string;
77
+ license?: string | null;
78
+ triggers?: SkillTrigger[];
79
+ argumentHint?: string | null;
80
+ uses?: string[];
81
+ }
82
+
41
83
  /** A previewed skill parsed from pasted/imported SKILL.md text. */
42
84
  export interface ParsedSkillPreview {
43
85
  name: string;
44
86
  description: string;
45
87
  license: string | null;
88
+ triggers: SkillTrigger[];
89
+ argumentHint: string | null;
90
+ uses: string[];
46
91
  body: string;
47
92
  warnings: string[];
48
93
  }
49
94
 
95
+ /** One slash-invocable skill as offered to the chat "/" picker. */
96
+ export interface AvailableSkill {
97
+ slug: string;
98
+ name: string;
99
+ description: string;
100
+ argumentHint: string | null;
101
+ }
102
+
50
103
  function toDTO(row: SkillRow, present: boolean): SkillDTO {
51
104
  return {
52
105
  id: row.id,
@@ -57,21 +110,41 @@ function toDTO(row: SkillRow, present: boolean): SkillDTO {
57
110
  marketplaceRef: row.marketplace_ref,
58
111
  version: row.version,
59
112
  license: row.license,
113
+ triggers: parseTriggers(row.triggers),
114
+ argumentHint: row.argument_hint,
115
+ uses: parseUses(row.uses),
60
116
  enabled: row.is_enabled === 1,
61
117
  present,
62
118
  createdAt: row.created_at
63
119
  };
64
120
  }
65
121
 
66
- /** Derive a slug that doesn't collide with an existing skill. */
67
- function uniqueSlug(base: string): string {
68
- const root = slugifySkillName(base);
69
- if (!skillQueries.getBySlug(root)) return root;
70
- for (let i = 2; i < 1000; i++) {
71
- const candidate = `${root}-${i}`.slice(0, 64).replace(/-+$/g, '');
72
- if (!skillQueries.getBySlug(candidate)) return candidate;
73
- }
74
- return slugifySkillName(`${root}-${Date.now()}`);
122
+ /** Normalise a comma list of trigger names into the validated set. */
123
+ function triggersFromFrontmatter(raw: string | undefined): SkillTrigger[] {
124
+ return parseTriggers(raw);
125
+ }
126
+
127
+ /** `uses` round-trips through frontmatter as a comma list, and through the DB as JSON. */
128
+ function usesFromFrontmatter(raw: string | undefined): string[] {
129
+ return (raw ?? '').split(',').map(u => u.trim()).filter(Boolean);
130
+ }
131
+
132
+ /** Build the canonical SKILL.md frontmatter for a set of editor fields. */
133
+ function frontmatterFor(slug: string, input: SkillInputFields): ParsedSkill['frontmatter'] {
134
+ const triggers = input.triggers?.length ? input.triggers : (['auto'] as SkillTrigger[]);
135
+ const uses = (input.uses ?? []).map(u => u.trim()).filter(Boolean);
136
+ return {
137
+ name: slug,
138
+ description: input.description.trim(),
139
+ license: input.license?.trim() || undefined,
140
+ // `triggers` is always written, even when it is the default: an explicit
141
+ // value is what makes an exported SKILL.md round-trip into another Clopen
142
+ // with the same behaviour instead of silently reverting to `auto`.
143
+ triggers: stringifyTriggers(triggers),
144
+ argumentHint: input.argumentHint?.trim() || undefined,
145
+ uses: uses.length ? uses.join(', ') : undefined,
146
+ extra: {}
147
+ };
75
148
  }
76
149
 
77
150
  /** Throw a single combined error if frontmatter validation fails. */
@@ -80,6 +153,29 @@ function assertValid(skill: ParsedSkill, expectedName: string): void {
80
153
  if (!result.valid) throw new Error(result.errors.join(' '));
81
154
  }
82
155
 
156
+ /** Derive a slug that doesn't collide with an existing skill. */
157
+ function nextSlug(base: string): string {
158
+ return uniqueSlug(slugifySkillName(base), s => !!skillQueries.getBySlug(s));
159
+ }
160
+
161
+ /**
162
+ * Resolve the slug for a new skill.
163
+ *
164
+ * A slug the user typed is normalised but never silently de-duplicated: they
165
+ * asked for that exact id, so a clash is reported instead of quietly becoming
166
+ * `<slug>-2`. A derived slug keeps the old auto-suffix behaviour, because there
167
+ * the user expressed no preference.
168
+ */
169
+ function resolveNewSlug(input: SkillInputFields): string {
170
+ const requested = input.slug?.trim();
171
+ if (!requested) return nextSlug(input.name);
172
+ const slug = slugifySkillName(requested);
173
+ if (skillQueries.getBySlug(slug)) {
174
+ throw new Error(`The id "${slug}" is already used by another skill. Pick a different one.`);
175
+ }
176
+ return slug;
177
+ }
178
+
83
179
  export const skillService = {
84
180
  async list(): Promise<SkillDTO[]> {
85
181
  const rows = skillQueries.getAll();
@@ -87,6 +183,29 @@ export const skillService = {
87
183
  return rows.map((row, i) => toDTO(row, presence[i]));
88
184
  },
89
185
 
186
+ /**
187
+ * Minimal list of slash-invocable skills for the chat "/" picker. Non-admin
188
+ * surface (any user can invoke one), so it exposes only display fields — no
189
+ * bodies, no source/disk metadata.
190
+ *
191
+ * `profileFilter` mirrors the stream-time semantics: when an active profile
192
+ * references ≥1 skill, the picker shows exactly that set (even if a referenced
193
+ * skill is globally disabled) instead of the enabled set.
194
+ */
195
+ available(profileFilter?: Set<string> | null): AvailableSkill[] {
196
+ const rows = profileFilter
197
+ ? skillQueries.getAll().filter(r => profileFilter.has(r.slug))
198
+ : skillQueries.getEnabled();
199
+ return rows
200
+ .filter(r => parseTriggers(r.triggers).includes('slash'))
201
+ .map(r => ({
202
+ slug: r.slug,
203
+ name: r.name,
204
+ description: r.description,
205
+ argumentHint: r.argument_hint
206
+ }));
207
+ },
208
+
90
209
  async get(id: number): Promise<{ skill: SkillDTO; body: string } | null> {
91
210
  const row = skillQueries.getById(id);
92
211
  if (!row) return null;
@@ -95,18 +214,13 @@ export const skillService = {
95
214
  return { skill: toDTO(row, raw !== null), body };
96
215
  },
97
216
 
98
- /** Create a skill from in-app editor fields (name + description + markdown body). */
99
- async create(input: { name: string; description: string; body: string; license?: string | null }): Promise<SkillDTO> {
100
- const slug = uniqueSlug(input.name);
101
- const skill: ParsedSkill = {
102
- frontmatter: {
103
- name: slug,
104
- description: input.description.trim(),
105
- license: input.license?.trim() || undefined,
106
- extra: {}
107
- },
108
- body: input.body
109
- };
217
+ /** Create a skill from in-app editor fields. */
218
+ async create(input: SkillInputFields): Promise<SkillDTO> {
219
+ if (!input.name.trim()) throw new Error('A skill name is required');
220
+ // The body IS the skill — an empty one loads nothing and runs nothing.
221
+ if (!input.body.trim()) throw new Error('Instructions are required');
222
+ const slug = resolveNewSlug(input);
223
+ const skill: ParsedSkill = { frontmatter: frontmatterFor(slug, input), body: input.body };
110
224
  assertValid(skill, slug);
111
225
  await writeSkillMd(slug, serializeSkillMd(skill));
112
226
  const row = skillQueries.insert({
@@ -114,30 +228,35 @@ export const skillService = {
114
228
  name: input.name.trim(),
115
229
  description: input.description.trim(),
116
230
  source: 'custom',
117
- license: input.license?.trim() || null
231
+ license: input.license?.trim() || null,
232
+ triggers: stringifyTriggers(input.triggers),
233
+ argumentHint: input.argumentHint?.trim() || null,
234
+ uses: stringifyUses(input.uses)
118
235
  });
119
- debug.log('skills', `📦 Created skill: ${slug}`);
236
+ debug.log('skills', `📦 Created skill: ${slug} (${stringifyTriggers(input.triggers)})`);
120
237
  return toDTO(row, true);
121
238
  },
122
239
 
123
240
  /** Update an existing skill's editable fields and rewrite its SKILL.md. */
124
- async update(id: number, input: { name: string; description: string; body: string; license?: string | null }): Promise<SkillDTO> {
241
+ async update(id: number, input: SkillInputFields): Promise<SkillDTO> {
125
242
  const row = skillQueries.getById(id);
126
243
  if (!row) throw new Error('Skill not found');
127
- // `name` (frontmatter) must keep matching the folder slug — only the
128
- // display name, description, license and body are editable here.
129
- const skill: ParsedSkill = {
130
- frontmatter: {
131
- name: row.slug,
132
- description: input.description.trim(),
133
- license: input.license?.trim() || undefined,
134
- extra: {}
135
- },
136
- body: input.body
137
- };
244
+ if (!input.body.trim()) throw new Error('Instructions are required');
245
+ // The slug is frozen after creation: it is the folder on disk, the `/<slug>`
246
+ // typed in chat, and what `uses:` lists and Profiles reference. Only the
247
+ // display name, description, license, triggers, hint, `uses` and body are
248
+ // editable here — `input.slug` is deliberately ignored.
249
+ const skill: ParsedSkill = { frontmatter: frontmatterFor(row.slug, input), body: input.body };
138
250
  assertValid(skill, row.slug);
139
251
  await writeSkillMd(row.slug, serializeSkillMd(skill));
140
- skillQueries.updateMeta(id, input.name.trim(), input.description.trim(), input.license?.trim() || null);
252
+ skillQueries.updateMeta(id, {
253
+ name: input.name.trim(),
254
+ description: input.description.trim(),
255
+ license: input.license?.trim() || null,
256
+ triggers: stringifyTriggers(input.triggers),
257
+ argumentHint: input.argumentHint?.trim() || null,
258
+ uses: stringifyUses(input.uses)
259
+ });
141
260
  debug.log('skills', `🔧 Updated skill: ${row.slug}`);
142
261
  return toDTO(skillQueries.getById(id)!, true);
143
262
  },
@@ -145,28 +264,51 @@ export const skillService = {
145
264
  /**
146
265
  * Parse pasted/uploaded SKILL.md text into a reviewable preview. Nothing is
147
266
  * persisted — the UI shows the result, then calls `import` to commit it.
267
+ *
268
+ * A pasted document with no `name` but an `argument-hint` is almost certainly
269
+ * a pre-merge Clopen/Claude command file, so it previews as a slash skill.
148
270
  */
149
271
  parsePreview(raw: string): ParsedSkillPreview {
150
272
  const parsed = parseSkillMd(raw);
151
273
  const warnings: string[] = [];
274
+ const triggers = parsed.frontmatter.triggers
275
+ ? triggersFromFrontmatter(parsed.frontmatter.triggers)
276
+ : parsed.frontmatter.argumentHint
277
+ ? (['slash'] as SkillTrigger[])
278
+ : (['auto'] as SkillTrigger[]);
152
279
  const result = validateFrontmatter(parsed.frontmatter, undefined);
153
280
  if (!result.valid) warnings.push(...result.errors);
154
281
  return {
155
282
  name: parsed.frontmatter.name,
156
283
  description: parsed.frontmatter.description,
157
284
  license: parsed.frontmatter.license ?? null,
285
+ triggers,
286
+ argumentHint: parsed.frontmatter.argumentHint ?? null,
287
+ uses: usesFromFrontmatter(parsed.frontmatter.uses),
158
288
  body: parsed.body,
159
289
  warnings
160
290
  };
161
291
  },
162
292
 
163
- /** Persist a skill from pasted/uploaded SKILL.md text. */
164
- async import(raw: string): Promise<SkillDTO> {
293
+ /**
294
+ * Persist a skill from pasted/uploaded SKILL.md text. Accepts both a real
295
+ * SKILL.md and a bare command document (frontmatter with only
296
+ * `description`/`argument-hint`, no `name`) — the latter is what users paste
297
+ * from a `.claude/commands/*.md`.
298
+ */
299
+ async import(raw: string, nameHint?: string): Promise<SkillDTO> {
300
+ const preview = this.parsePreview(raw);
165
301
  const parsed = parseSkillMd(raw);
166
- const displayName = parsed.frontmatter.name || 'Imported skill';
167
- const slug = uniqueSlug(parsed.frontmatter.name || displayName);
302
+ const displayName = (nameHint?.trim() || preview.name || preview.description || 'Imported skill').trim();
303
+ const slug = nextSlug(preview.name || displayName);
168
304
  // Re-key the frontmatter `name` to the de-duped slug so it matches the folder.
169
305
  parsed.frontmatter.name = slug;
306
+ parsed.frontmatter.triggers = stringifyTriggers(preview.triggers);
307
+ if (!parsed.frontmatter.description.trim()) {
308
+ // The spec requires a description and the "/" picker shows it; fall back
309
+ // to the display name rather than rejecting a valid command paste.
310
+ parsed.frontmatter.description = displayName;
311
+ }
170
312
  assertValid(parsed, slug);
171
313
  await writeSkillMd(slug, serializeSkillMd(parsed));
172
314
  const row = skillQueries.insert({
@@ -174,7 +316,10 @@ export const skillService = {
174
316
  name: displayName,
175
317
  description: parsed.frontmatter.description,
176
318
  source: 'imported',
177
- license: parsed.frontmatter.license ?? null
319
+ license: parsed.frontmatter.license ?? null,
320
+ triggers: stringifyTriggers(preview.triggers),
321
+ argumentHint: preview.argumentHint,
322
+ uses: stringifyUses(preview.uses)
178
323
  });
179
324
  debug.log('skills', `📥 Imported skill: ${slug}`);
180
325
  return toDTO(row, true);
@@ -208,8 +353,10 @@ export const skillService = {
208
353
  if (override?.license !== undefined) parsed.frontmatter.license = override.license?.trim() || undefined;
209
354
  if (override?.body !== undefined) parsed.body = override.body;
210
355
  const displayName = override?.name?.trim() || parsed.frontmatter.name || ref.split(/[:/]/).pop() || 'Skill';
211
- const slug = uniqueSlug(parsed.frontmatter.name || displayName);
356
+ const slug = nextSlug(parsed.frontmatter.name || displayName);
212
357
  parsed.frontmatter.name = slug;
358
+ const triggers = triggersFromFrontmatter(parsed.frontmatter.triggers);
359
+ parsed.frontmatter.triggers = stringifyTriggers(triggers);
213
360
  assertValid(parsed, slug);
214
361
  await writeSkillMd(slug, serializeSkillMd(parsed));
215
362
  for (const resource of fetched.resources) {
@@ -222,7 +369,10 @@ export const skillService = {
222
369
  source: 'marketplace',
223
370
  marketplaceRef: ref,
224
371
  version: parsed.frontmatter.metadata?.version ?? null,
225
- license: parsed.frontmatter.license ?? null
372
+ license: parsed.frontmatter.license ?? null,
373
+ triggers: stringifyTriggers(triggers),
374
+ argumentHint: parsed.frontmatter.argumentHint ?? null,
375
+ uses: stringifyUses(usesFromFrontmatter(parsed.frontmatter.uses))
226
376
  });
227
377
  debug.log('skills', `📥 Installed marketplace skill: ${slug} (${ref})`);
228
378
  return toDTO(row, true);
@@ -6,6 +6,10 @@
6
6
  * `description`, optional `license`/`compatibility`/`metadata`/`allowed-tools`)
7
7
  * followed by a Markdown instruction body.
8
8
  *
9
+ * Clopen adds three keys of its own — `triggers`, `argument-hint` and `uses`
10
+ * (see {@link SkillFrontmatter}). The spec tells runtimes to ignore frontmatter
11
+ * keys they don't model, so a Clopen skill stays a valid, portable SKILL.md.
12
+ *
9
13
  * We deliberately hand-roll a tiny frontmatter parser rather than pull in a YAML
10
14
  * dependency: the spec's frontmatter surface is small and flat (one nested
11
15
  * `metadata` map), and skills we author in-app are written back in this exact
@@ -20,6 +24,20 @@ export interface SkillFrontmatter {
20
24
  compatibility?: string;
21
25
  allowedTools?: string;
22
26
  metadata?: Record<string, string>;
27
+ /**
28
+ * Clopen extension — how the skill is invoked, as a comma list of `auto`
29
+ * (the model decides from `description`) and/or `slash` (the user types
30
+ * `/<name>`). Absent means `auto`, which is what every pre-merge skill was.
31
+ */
32
+ triggers?: string;
33
+ /** Clopen extension — argument hint shown beside `/<name>` in the chat picker. */
34
+ argumentHint?: string;
35
+ /**
36
+ * Clopen extension — comma list of sibling skill slugs force-loaded whenever
37
+ * this skill runs. This is what lets one `/slash` skill pull in several
38
+ * skills deterministically instead of hoping the model picks them up.
39
+ */
40
+ uses?: string;
23
41
  /** Frontmatter keys we don't model, kept verbatim for lossless round-trips. */
24
42
  extra: Record<string, string>;
25
43
  }
@@ -123,6 +141,9 @@ export function parseSkillMd(raw: string): ParsedSkill {
123
141
  case 'license': fm.license = value; break;
124
142
  case 'compatibility': fm.compatibility = value; break;
125
143
  case 'allowed-tools': fm.allowedTools = value; break;
144
+ case 'triggers': fm.triggers = value; break;
145
+ case 'argument-hint': fm.argumentHint = value; break;
146
+ case 'uses': fm.uses = value; break;
126
147
  default: fm.extra[key] = value;
127
148
  }
128
149
  }
@@ -140,6 +161,9 @@ export function serializeSkillMd(skill: ParsedSkill): string {
140
161
  if (fm.license) lines.push(`license: ${quoteIfNeeded(fm.license)}`);
141
162
  if (fm.compatibility) lines.push(`compatibility: ${quoteIfNeeded(fm.compatibility)}`);
142
163
  if (fm.allowedTools) lines.push(`allowed-tools: ${quoteIfNeeded(fm.allowedTools)}`);
164
+ if (fm.triggers) lines.push(`triggers: ${quoteIfNeeded(fm.triggers)}`);
165
+ if (fm.argumentHint) lines.push(`argument-hint: ${quoteIfNeeded(fm.argumentHint)}`);
166
+ if (fm.uses) lines.push(`uses: ${quoteIfNeeded(fm.uses)}`);
143
167
  for (const [k, v] of Object.entries(fm.extra)) lines.push(`${k}: ${quoteIfNeeded(v)}`);
144
168
  if (fm.metadata && Object.keys(fm.metadata).length > 0) {
145
169
  lines.push('metadata:');
@@ -184,6 +208,17 @@ export function validateFrontmatter(fm: SkillFrontmatter, expectedName?: string)
184
208
  errors.push('`compatibility` must be at most 500 characters.');
185
209
  }
186
210
 
211
+ if (fm.triggers) {
212
+ const parsed = fm.triggers.split(',').map(t => t.trim().toLowerCase()).filter(Boolean);
213
+ const unknown = parsed.filter(t => t !== 'auto' && t !== 'slash');
214
+ if (unknown.length > 0) {
215
+ errors.push(`\`triggers\` may only contain "auto" and "slash" (got: ${unknown.join(', ')}).`);
216
+ }
217
+ if (parsed.length === 0) {
218
+ errors.push('`triggers` must name at least one of "auto" or "slash".');
219
+ }
220
+ }
221
+
187
222
  // Angle brackets in frontmatter can inject unintended system-prompt content.
188
223
  for (const [label, value] of [
189
224
  ['name', fm.name],
@@ -1,23 +1,34 @@
1
1
  /**
2
- * Engine sync for Skills — now a thin adapter over the shared artifact framework
3
- * (`backend/artifacts/`). Skills were the original per-feature sync; that logic
4
- * has been generalized into {@link materializeArtifacts}, and this module simply
5
- * supplies the skill item set plus the exact preamble text skills have always
6
- * emitted (preserved verbatim so retrofitting introduces no behavior change).
2
+ * Engine sync for Skills — a thin adapter over the shared artifact framework
3
+ * (`backend/artifacts/`).
7
4
  *
8
- * Materialization by engine (unchanged):
9
- * - NATIVE (Claude, Qwen, Copilot): mirror each enabled skill folder into the
10
- * engine's skills dir.
11
- * - SYNTHETIC (Codex, OpenCode): inject a marker-delimited "skills preamble"
12
- * (name + description + absolute SKILL.md path) into the engine's global
13
- * memory file. These synthetic targets are best-effort/unverified.
5
+ * Materialization by engine:
6
+ * - NATIVE (Claude, Qwen, Copilot, Pi): mirror each enabled skill folder into
7
+ * the engine's skills dir.
8
+ * - SYNTHETIC (Codex, OpenCode, Cline, Cursor): no native skills dir, so the
9
+ * preamble (name + description + absolute SKILL.md path) is injected into
10
+ * each turn's prompt instead of a shared global memory file — a global file
11
+ * can't encode a per-session Profile and leaks across concurrent sessions.
12
+ *
13
+ * Only `auto`-triggered skills are ADVERTISED. A `slash`-only skill is invoked
14
+ * by the user and expanded by Clopen (see `./invoke.ts`), so listing it here
15
+ * would just invite the model to run it unprompted.
14
16
  *
15
17
  * Sync never throws — a stream never breaks because skills couldn't sync.
16
18
  */
17
19
 
18
- import { skillQueries } from '$backend/database/queries';
20
+ import { skillQueries, parseTriggers } from '$backend/database/queries';
19
21
  import { debug } from '$shared/utils/logger';
20
- import { materializeArtifacts, resolveArtifact, isPromptScopedEngine, type ManagedArtifact, type ArtifactEngine } from '$backend/artifacts';
22
+ import {
23
+ materializeArtifacts,
24
+ resolveArtifact,
25
+ isPromptScopedEngine,
26
+ writeManagedBlock,
27
+ markersForType,
28
+ ARTIFACT_ENGINES,
29
+ type ManagedArtifact,
30
+ type ArtifactEngine
31
+ } from '$backend/artifacts';
21
32
  import { artifactFilter } from '$backend/profiles';
22
33
  import { getSkillMdPath, getSkillDir } from './store';
23
34
  import { stat } from 'node:fs/promises';
@@ -25,16 +36,6 @@ import { stat } from 'node:fs/promises';
25
36
  /** Kept for backwards-compatible imports; identical to {@link ArtifactEngine}. */
26
37
  export type SkillEngine = ArtifactEngine;
27
38
 
28
- interface EnabledSkill {
29
- slug: string;
30
- name: string;
31
- description: string;
32
- }
33
-
34
- function getEnabledSkills(): EnabledSkill[] {
35
- return skillQueries.getEnabled().map(r => ({ slug: r.slug, name: r.name, description: r.description }));
36
- }
37
-
38
39
  /** The skills preamble — exact original wording, without the markers (added by the writer). */
39
40
  function buildSkillsPreamble(items: ManagedArtifact[]): string {
40
41
  if (items.length === 0) return '';
@@ -66,28 +67,31 @@ async function pathExists(path: string): Promise<boolean> {
66
67
  *
67
68
  * A profile is the source of truth for what's active: an item it references is
68
69
  * included even if globally disabled, and its enable toggle is ignored. With no
69
- * profile filter, only the globally-enabled set applies (unchanged behaviour).
70
+ * profile filter, only the globally-enabled set applies.
71
+ *
72
+ * With `autoOnly`, `slash`-only skills are excluded. They exist to be invoked by
73
+ * name, and Clopen expands them itself, so an engine must neither be told about
74
+ * them nor be given a copy it could act on. Their content is still reachable —
75
+ * the canonical store is what the preamble and `uses:` reference by path.
70
76
  */
71
- export function resolveEnabledSkills(profileId?: number): ManagedArtifact[] {
77
+ export function resolveEnabledSkills(profileId?: number, options?: { autoOnly?: boolean }): ManagedArtifact[] {
72
78
  const filter = artifactFilter(profileId, 'skill');
73
- const source = filter
74
- ? skillQueries.getAll().map(r => ({ slug: r.slug, name: r.name, description: r.description }))
75
- : getEnabledSkills();
76
- return source
77
- .filter(s => !filter || filter.has(s.slug))
78
- .map(s => ({
79
- slug: s.slug,
80
- name: s.name,
81
- description: s.description,
82
- sourceDir: getSkillDir(s.slug)
83
- }));
79
+ const rows = (filter ? skillQueries.getAll() : skillQueries.getEnabled())
80
+ .filter(r => !filter || filter.has(r.slug))
81
+ .filter(r => !options?.autoOnly || parseTriggers(r.triggers).includes('auto'));
82
+ return rows.map(r => ({
83
+ slug: r.slug,
84
+ name: r.name,
85
+ description: r.description,
86
+ sourceDir: getSkillDir(r.slug)
87
+ }));
84
88
  }
85
89
 
86
90
  /**
87
91
  * Whether skills for this engine are delivered per-session via prompt injection
88
92
  * INSTEAD of the shared global memory file — true only for a synthetic (no native
89
93
  * dir) skill target on a prompt-scoped engine. Native skill engines
90
- * (Claude/Qwen/Copilot) keep the folder mirror+prune.
94
+ * (Claude/Qwen/Copilot/Pi) keep the folder mirror+prune.
91
95
  */
92
96
  function skillsViaPromptInjection(engine: SkillEngine): boolean {
93
97
  const synthetic = resolveArtifact('skill', { engine, scope: 'global' }).format === 'preamble-region';
@@ -96,33 +100,26 @@ function skillsViaPromptInjection(engine: SkillEngine): boolean {
96
100
 
97
101
  /**
98
102
  * The profile-scoped skills preamble for PER-SESSION injection into a synthetic
99
- * engine's prompt (OpenCode/Codex). Returns '' when no skill applies. Uses the
100
- * exact wording of the old global block, so model behaviour is unchanged apart
101
- * from now being correctly scoped to the session's active Profile.
103
+ * engine's prompt (Codex/OpenCode/Copilot/Cline/Cursor). Returns '' when no skill
104
+ * applies.
102
105
  */
103
106
  export function buildSkillsPromptContext(profileId?: number): string {
104
- return buildSkillsPreamble(resolveEnabledSkills(profileId));
107
+ return buildSkillsPreamble(resolveEnabledSkills(profileId, { autoOnly: true }));
105
108
  }
106
109
 
107
110
  /**
108
111
  * Sync enabled skills for one engine. Safe to call at every stream start.
109
112
  * Never throws: failures are logged and swallowed so streaming is unaffected.
110
- *
111
- * NATIVE engines (Claude/Qwen/Copilot) mirror the profile-narrowed skill folders
112
- * into the engine's skills dir and prune the rest — a per-query-correct filter.
113
- *
114
- * SYNTHETIC engines (OpenCode/Codex) do NOT advertise skills through the shared
115
- * global memory file here: a single global file can't encode a per-session
116
- * profile choice and would leak across concurrent sessions (and their persistent
117
- * server may not re-read it). Instead they inject the resolved preamble into each
118
- * turn's prompt (see the adapters + {@link buildSkillsPromptContext}). We still
119
- * materialize an EMPTY set for them so any legacy `CLOPEN:SKILLS` block left in
120
- * AGENTS.md is stripped.
121
113
  */
122
114
  export async function syncSkills(engine: SkillEngine, profileId?: number): Promise<void> {
123
115
  try {
124
116
  const viaPrompt = skillsViaPromptInjection(engine);
125
- const enabled: ManagedArtifact[] = viaPrompt ? [] : resolveEnabledSkills(profileId);
117
+ // Auto-only, in the native dir as well as the preamble. Mirroring a
118
+ // slash-only skill into e.g. Claude's `skills/` would hand it to Claude's
119
+ // own Skill tool, which is precisely the autonomous invocation that trigger
120
+ // rules out. Nothing is lost by withholding it: the canonical store is what
121
+ // the preamble and `uses:` point at, and Clopen expands `/slug` itself.
122
+ const enabled: ManagedArtifact[] = viaPrompt ? [] : resolveEnabledSkills(profileId, { autoOnly: true });
126
123
  const managedSlugs = skillQueries.getAll().map(s => s.slug);
127
124
  await materializeArtifacts('skill', { engine, scope: 'global' }, {
128
125
  enabled,
@@ -135,10 +132,43 @@ export async function syncSkills(engine: SkillEngine, profileId?: number): Promi
135
132
  }
136
133
  }
137
134
 
135
+ /**
136
+ * Remove everything earlier versions materialized for the separate Commands
137
+ * feature: the per-engine command/prompt directories AND any `CLOPEN:COMMANDS`
138
+ * block left inside a memory file.
139
+ *
140
+ * Commands are `slash` Skills now and are expanded by Clopen before the prompt
141
+ * reaches the engine (see `./invoke.ts`), so nothing should be written to those
142
+ * locations any more. Without this sweep a renamed or deleted command would keep
143
+ * being offered by Claude's or Codex's own command picker forever.
144
+ *
145
+ * Materializing an EMPTY set is exactly the right primitive: in an exclusive
146
+ * (Clopen-owned, isolated) directory it prunes every entry, and for a synthetic
147
+ * target it strips the managed block while preserving the user's own content.
148
+ */
149
+ export async function stripLegacyCommandArtifacts(engine: ArtifactEngine): Promise<void> {
150
+ try {
151
+ const ctx = { engine, scope: 'global' } as const;
152
+ const resolution = resolveArtifact('command', ctx);
153
+ const directoryBacked = resolution.format === 'folder-md' || resolution.format === 'single-md';
154
+ if (directoryBacked && !(await pathExists(resolution.locateEffective(ctx)))) {
155
+ // Nothing was ever written there. Don't let the generic materializer
156
+ // create the directory just to find it empty — but a stale managed block
157
+ // can still exist in the memory file from before this engine had a
158
+ // native command dir, so clear that unconditionally.
159
+ const memoryFile = resolveArtifact('instruction', ctx).locateEffective(ctx);
160
+ if (memoryFile) await writeManagedBlock(memoryFile, '', markersForType('command'));
161
+ return;
162
+ }
163
+ await materializeArtifacts('command', ctx, { enabled: [], managedSlugs: [] });
164
+ } catch (error) {
165
+ debug.warn('skills', `⚠️ Legacy command cleanup for ${engine} failed (continuing):`, error);
166
+ }
167
+ }
168
+
138
169
  /** Re-sync every engine — used after a mutation so changes propagate eagerly. */
139
170
  export async function syncSkillsAllEngines(): Promise<void> {
140
- const engines: SkillEngine[] = ['claude', 'codex', 'copilot', 'qwen', 'opencode', 'pi'];
141
- await Promise.all(engines.map(syncSkills));
171
+ await Promise.all(ARTIFACT_ENGINES.map(engine => syncSkills(engine)));
142
172
  }
143
173
 
144
174
  /** Validate that a skill's SKILL.md exists on disk (used by the WS status surface). */
@@ -3,7 +3,7 @@
3
3
  * the Settings UI.
4
4
  */
5
5
 
6
- import { detectArtifacts, type DetectedArtifact, type ArtifactEngine } from '$backend/artifacts';
6
+ import { detectArtifacts, ARTIFACT_ENGINES, type DetectedArtifact, type ArtifactEngine } from '$backend/artifacts';
7
7
 
8
8
  export interface DetectedSubagentGroup {
9
9
  engine: ArtifactEngine;
@@ -11,10 +11,9 @@ export interface DetectedSubagentGroup {
11
11
  }
12
12
 
13
13
  export async function detectSubagents(projectPath?: string): Promise<DetectedSubagentGroup[]> {
14
- const engines: ArtifactEngine[] = ['claude', 'codex', 'copilot', 'qwen', 'opencode', 'pi'];
15
14
  const scope = projectPath ? 'project' : 'global';
16
15
  const groups = await Promise.all(
17
- engines.map(async engine => ({
16
+ ARTIFACT_ENGINES.map(async engine => ({
18
17
  engine,
19
18
  detected: await detectArtifacts('subagent', { engine, scope, projectPath })
20
19
  }))