@lesliechan721/aw-plugin-core 0.1.0-beta.1

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 (66) hide show
  1. package/dist/file-rules.d.ts +2 -0
  2. package/dist/file-rules.js +42 -0
  3. package/dist/file-rules.js.map +1 -0
  4. package/dist/generated/plugin-manifest-v1.d.ts +368 -0
  5. package/dist/generated/plugin-manifest-v1.js +3 -0
  6. package/dist/generated/plugin-manifest-v1.js.map +1 -0
  7. package/dist/hooks-contract.d.ts +189 -0
  8. package/dist/hooks-contract.js +967 -0
  9. package/dist/hooks-contract.js.map +1 -0
  10. package/dist/index.d.ts +4 -0
  11. package/dist/index.js +4 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/manifest-contract.d.ts +96 -0
  14. package/dist/manifest-contract.js +2730 -0
  15. package/dist/manifest-contract.js.map +1 -0
  16. package/dist/manifest-type-contract.d.ts +7 -0
  17. package/dist/manifest-type-contract.js +2 -0
  18. package/dist/manifest-type-contract.js.map +1 -0
  19. package/dist/manifest.d.ts +27 -0
  20. package/dist/manifest.js +59 -0
  21. package/dist/manifest.js.map +1 -0
  22. package/dist/permission-command.d.ts +3 -0
  23. package/dist/permission-command.js +11 -0
  24. package/dist/permission-command.js.map +1 -0
  25. package/dist/platform-entries.d.ts +13 -0
  26. package/dist/platform-entries.js +20 -0
  27. package/dist/platform-entries.js.map +1 -0
  28. package/dist/platform-support.d.ts +6 -0
  29. package/dist/platform-support.js +38 -0
  30. package/dist/platform-support.js.map +1 -0
  31. package/dist/plugin-release.d.ts +30 -0
  32. package/dist/plugin-release.js +187 -0
  33. package/dist/plugin-release.js.map +1 -0
  34. package/dist/plugin-script-contract.d.ts +33 -0
  35. package/dist/plugin-script-contract.js +599 -0
  36. package/dist/plugin-script-contract.js.map +1 -0
  37. package/dist/portable-skill-validation.d.ts +7 -0
  38. package/dist/portable-skill-validation.js +111 -0
  39. package/dist/portable-skill-validation.js.map +1 -0
  40. package/dist/read-json.d.ts +1 -0
  41. package/dist/read-json.js +5 -0
  42. package/dist/read-json.js.map +1 -0
  43. package/dist/runtime-export-source.d.ts +14 -0
  44. package/dist/runtime-export-source.js +73 -0
  45. package/dist/runtime-export-source.js.map +1 -0
  46. package/dist/skill-authoring.d.ts +2 -0
  47. package/dist/skill-authoring.js +13 -0
  48. package/dist/skill-authoring.js.map +1 -0
  49. package/dist/skill-frontmatter-capabilities.d.ts +36 -0
  50. package/dist/skill-frontmatter-capabilities.js +120 -0
  51. package/dist/skill-frontmatter-capabilities.js.map +1 -0
  52. package/dist/skill-frontmatter-capabilities.json +200 -0
  53. package/dist/slash-commands.d.ts +43 -0
  54. package/dist/slash-commands.js +394 -0
  55. package/dist/slash-commands.js.map +1 -0
  56. package/dist/template-engine.d.ts +2 -0
  57. package/dist/template-engine.js +26 -0
  58. package/dist/template-engine.js.map +1 -0
  59. package/dist/types.d.ts +428 -0
  60. package/dist/types.js +2 -0
  61. package/dist/types.js.map +1 -0
  62. package/dist/workspace.d.ts +105 -0
  63. package/dist/workspace.js +963 -0
  64. package/dist/workspace.js.map +1 -0
  65. package/package.json +46 -0
  66. package/schemas/plugin-manifest-v1.json +329 -0
@@ -0,0 +1,43 @@
1
+ import type { NormalizedPluginManifest, SupportedPlatformSet } from './types.js';
2
+ export declare const DEFAULT_SLASH_COMMANDS_DIR = "slash-commands";
3
+ export declare const DEFAULT_SLASH_COMMANDS_PATH = "./slash-commands";
4
+ export interface ResolvedSlashCommandAsset {
5
+ generatedRelativePath: string;
6
+ sourceRelativePath: string;
7
+ }
8
+ export interface ResolvedSlashCommand {
9
+ name: string;
10
+ sourceRelativePath: string;
11
+ claude?: {
12
+ allowedTools?: string | string[];
13
+ argumentHint?: string;
14
+ body: string;
15
+ description: string;
16
+ model?: string;
17
+ shell?: string;
18
+ };
19
+ codex?: {
20
+ assets: ResolvedSlashCommandAsset[];
21
+ body: string;
22
+ description: string;
23
+ interface: {
24
+ brandColor?: string;
25
+ defaultPrompt: string;
26
+ displayName: string;
27
+ iconLarge?: string;
28
+ iconSmall?: string;
29
+ shortDescription: string;
30
+ };
31
+ };
32
+ }
33
+ export interface ResolvedSlashCommands {
34
+ commands: ResolvedSlashCommand[];
35
+ rootRelativePath: string;
36
+ }
37
+ export interface ResolveSlashCommandsOptions {
38
+ targetPlatforms: SupportedPlatformSet;
39
+ }
40
+ export declare function resolveSlashCommands(pluginRoot: string, manifest: NormalizedPluginManifest, options?: ResolveSlashCommandsOptions): Promise<ResolvedSlashCommands | undefined>;
41
+ export declare function renderClaudeSlashCommand(command: ResolvedSlashCommand): string;
42
+ export declare function renderCodexSlashCommandSkillMarkdown(command: ResolvedSlashCommand): string;
43
+ export declare function renderCodexSlashCommandOpenAiYaml(command: ResolvedSlashCommand): string;
@@ -0,0 +1,394 @@
1
+ import path from 'node:path';
2
+ import fs from 'fs-extra';
3
+ import YAML from 'yaml';
4
+ import { applyFileRules } from './file-rules.js';
5
+ import { resolveSupportedPlatforms } from './platform-support.js';
6
+ import { renderTemplate } from './template-engine.js';
7
+ const SLASH_COMMAND_NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
8
+ const MAX_SLASH_COMMAND_NAME_LENGTH = 64;
9
+ const CLAUDE_SHELLS = new Set(['bash', 'powershell']);
10
+ const CLAUDE_ONLY_TOP_LEVEL_FIELDS = new Set([
11
+ 'allowed-tools',
12
+ 'model',
13
+ 'argument-hint',
14
+ 'disable-model-invocation',
15
+ 'shell',
16
+ ]);
17
+ const CODEX_INTERFACE_FIELDS = new Set([
18
+ 'display_name',
19
+ 'short_description',
20
+ 'icon_small',
21
+ 'icon_large',
22
+ 'brand_color',
23
+ 'default_prompt',
24
+ ]);
25
+ const CODEX_ALLOWED_FIELDS = new Set(['description', 'interface']);
26
+ export const DEFAULT_SLASH_COMMANDS_DIR = 'slash-commands';
27
+ export const DEFAULT_SLASH_COMMANDS_PATH = `./${DEFAULT_SLASH_COMMANDS_DIR}`;
28
+ function ensureTrailingNewline(value) {
29
+ return value.endsWith('\n') ? value : `${value}\n`;
30
+ }
31
+ function stripDotSlash(value) {
32
+ return value.startsWith('./') ? value.slice(2) : value;
33
+ }
34
+ function normalizeRelativePath(value) {
35
+ return value.split(path.sep).join('/');
36
+ }
37
+ function commandBaseField(commandPath) {
38
+ return `slashCommands command "${commandPath}"`;
39
+ }
40
+ function ensureObject(value, fieldName) {
41
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
42
+ throw new Error(`Invalid ${fieldName}: expected an object.`);
43
+ }
44
+ return value;
45
+ }
46
+ function ensureString(value, fieldName) {
47
+ if (typeof value !== 'string' || value.trim() === '') {
48
+ throw new Error(`Invalid ${fieldName}: expected a non-empty string.`);
49
+ }
50
+ return value.trim();
51
+ }
52
+ function ensureOptionalString(value, fieldName) {
53
+ if (value === undefined) {
54
+ return undefined;
55
+ }
56
+ return ensureString(value, fieldName);
57
+ }
58
+ function ensureAllowedKeys(value, fieldName, allowedKeys) {
59
+ const allowed = new Set(allowedKeys);
60
+ for (const key of Object.keys(value)) {
61
+ if (!allowed.has(key)) {
62
+ throw new Error(`Invalid ${fieldName}: unknown field "${key}".`);
63
+ }
64
+ }
65
+ }
66
+ function ensureAllowedTools(value, fieldName) {
67
+ if (value === undefined) {
68
+ return undefined;
69
+ }
70
+ if (typeof value === 'string') {
71
+ return ensureString(value, fieldName);
72
+ }
73
+ if (!Array.isArray(value)) {
74
+ throw new Error(`Invalid ${fieldName}: expected a string or an array of strings.`);
75
+ }
76
+ return value.map((entry, index) => ensureString(entry, `${fieldName}[${index}]`));
77
+ }
78
+ function parseMarkdownFrontmatter(content, fieldName) {
79
+ const normalized = content.replace(/\r\n/g, '\n');
80
+ if (!normalized.startsWith('---\n')) {
81
+ throw new Error(`Invalid ${fieldName}: missing YAML frontmatter.`);
82
+ }
83
+ const closingIndex = normalized.indexOf('\n---\n', 4);
84
+ const closingAtEof = closingIndex === -1 && normalized.endsWith('\n---');
85
+ if (closingIndex === -1 && !closingAtEof) {
86
+ throw new Error(`Invalid ${fieldName}: YAML frontmatter is missing the closing delimiter.`);
87
+ }
88
+ const yamlEndIndex = closingAtEof ? normalized.length - '\n---'.length : closingIndex;
89
+ const yamlContent = normalized.slice(4, yamlEndIndex);
90
+ const body = closingAtEof ? '' : normalized.slice(yamlEndIndex + '\n---\n'.length);
91
+ let parsed;
92
+ try {
93
+ parsed = YAML.parse(yamlContent);
94
+ }
95
+ catch (error) {
96
+ const message = error instanceof Error ? error.message : String(error);
97
+ throw new Error(`Invalid ${fieldName}: YAML frontmatter parse failed (${message}).`);
98
+ }
99
+ return {
100
+ body,
101
+ frontmatter: ensureObject(parsed, `${fieldName} frontmatter`),
102
+ };
103
+ }
104
+ function isTemplatedSlashCommand(manifest, relativePath) {
105
+ const include = manifest.buildConfig?.templates?.include ?? [];
106
+ return include.length > 0 && applyFileRules([relativePath], include, []).length > 0;
107
+ }
108
+ function renderSlashCommandSource(manifest, relativePath, content, platform) {
109
+ if (!isTemplatedSlashCommand(manifest, relativePath)) {
110
+ return content;
111
+ }
112
+ const templateVars = manifest.buildConfig?.templates?.vars ?? {};
113
+ return renderTemplate(content, templateVars, platform);
114
+ }
115
+ function detectCodexForbiddenSyntax(content) {
116
+ const checks = [
117
+ [/\$ARGUMENTS\b/, '$ARGUMENTS'],
118
+ [/\$\d+\b/, '$1'],
119
+ [/```!/, '```!'],
120
+ [/!`[^`\r\n]+`/, '!`command`'],
121
+ ];
122
+ for (const [pattern, label] of checks) {
123
+ if (pattern.test(content)) {
124
+ return label;
125
+ }
126
+ }
127
+ return undefined;
128
+ }
129
+ function normalizeCodexAssetPath(pluginRoot, slashCommandsRoot, commandPath, value, fieldName) {
130
+ if (value === undefined) {
131
+ return undefined;
132
+ }
133
+ const rawValue = ensureString(value, fieldName);
134
+ if (path.isAbsolute(rawValue) || path.win32.isAbsolute(rawValue) || rawValue.includes('\\')) {
135
+ throw new Error(`Invalid ${commandBaseField(commandPath)}.${fieldName}: must use "./assets/...".`);
136
+ }
137
+ if (!rawValue.startsWith('./assets/')) {
138
+ throw new Error(`Invalid ${commandBaseField(commandPath)}.${fieldName}: must use "./assets/...".`);
139
+ }
140
+ const normalized = path.posix.normalize(rawValue);
141
+ if (normalized === './assets' ||
142
+ normalized === 'assets' ||
143
+ normalized.startsWith('../') ||
144
+ normalized.includes('/../')) {
145
+ throw new Error(`Invalid ${commandBaseField(commandPath)}.${fieldName}: must use "./assets/...".`);
146
+ }
147
+ const normalizedChildPath = stripDotSlash(normalized);
148
+ if (!normalizedChildPath.startsWith('assets/')) {
149
+ throw new Error(`Invalid ${commandBaseField(commandPath)}.${fieldName}: must use "./assets/...".`);
150
+ }
151
+ const sourceRelativePath = normalizeRelativePath(path.join(stripDotSlash(slashCommandsRoot), normalizedChildPath));
152
+ const absolutePath = path.join(pluginRoot, sourceRelativePath);
153
+ const stats = fs.statSync(absolutePath, { throwIfNoEntry: false });
154
+ if (!stats) {
155
+ throw new Error(`Invalid ${commandBaseField(commandPath)}.${fieldName}: referenced asset "${rawValue}" does not exist.`);
156
+ }
157
+ if (!stats.isFile()) {
158
+ throw new Error(`Invalid ${commandBaseField(commandPath)}.${fieldName}: referenced asset "${rawValue}" must be a file.`);
159
+ }
160
+ return {
161
+ generatedRelativePath: `./${normalizedChildPath}`,
162
+ sourceRelativePath,
163
+ };
164
+ }
165
+ function titleCaseSlashCommandName(name) {
166
+ return name
167
+ .split('-')
168
+ .filter(Boolean)
169
+ .map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1))
170
+ .join(' ');
171
+ }
172
+ function buildDefaultPrompt(name, description) {
173
+ const trimmedDescription = description.trim();
174
+ const suffix = /[.!?。!?]$/.test(trimmedDescription) ? '' : '.';
175
+ return `Use $${name} to ${trimmedDescription}${suffix}`;
176
+ }
177
+ function normalizeCodexInterfaceBlock(pluginRoot, slashCommandsRoot, commandName, commandPath, description, value) {
178
+ const fieldName = `${commandBaseField(commandPath)}.codex.interface`;
179
+ const input = value === undefined ? {} : ensureObject(value, fieldName);
180
+ ensureAllowedKeys(input, fieldName, CODEX_INTERFACE_FIELDS);
181
+ const iconSmall = normalizeCodexAssetPath(pluginRoot, slashCommandsRoot, commandPath, input.icon_small, 'codex.interface.icon_small');
182
+ const iconLarge = normalizeCodexAssetPath(pluginRoot, slashCommandsRoot, commandPath, input.icon_large, 'codex.interface.icon_large');
183
+ const brandColor = ensureOptionalString(input.brand_color, `${fieldName}.brand_color`);
184
+ if (brandColor !== undefined && !/^#[0-9A-Fa-f]{6}$/.test(brandColor)) {
185
+ throw new Error(`Invalid ${fieldName}.brand_color: expected a "#RRGGBB" value.`);
186
+ }
187
+ const assets = [iconSmall, iconLarge].filter((entry) => entry !== undefined);
188
+ return {
189
+ assets,
190
+ brandColor,
191
+ defaultPrompt: ensureOptionalString(input.default_prompt, `${fieldName}.default_prompt`) ??
192
+ buildDefaultPrompt(commandName, description),
193
+ displayName: ensureOptionalString(input.display_name, `${fieldName}.display_name`) ??
194
+ titleCaseSlashCommandName(commandName),
195
+ iconLarge: iconLarge?.generatedRelativePath,
196
+ iconSmall: iconSmall?.generatedRelativePath,
197
+ shortDescription: ensureOptionalString(input.short_description, `${fieldName}.short_description`) ??
198
+ description,
199
+ };
200
+ }
201
+ function parseRenderedSlashCommand(pluginRoot, slashCommandsRoot, commandName, commandPath, content, platform) {
202
+ const { body, frontmatter } = parseMarkdownFrontmatter(content, commandBaseField(commandPath));
203
+ for (const key of Object.keys(frontmatter)) {
204
+ if (CLAUDE_ONLY_TOP_LEVEL_FIELDS.has(key)) {
205
+ throw new Error(`Invalid ${commandBaseField(commandPath)} frontmatter: "${key}" must be nested under "claude".`);
206
+ }
207
+ }
208
+ ensureAllowedKeys(frontmatter, `${commandBaseField(commandPath)} frontmatter`, ['description', 'claude', 'codex']);
209
+ const sharedDescription = ensureString(frontmatter.description, `${commandBaseField(commandPath)} frontmatter.description`);
210
+ const command = {
211
+ name: commandName,
212
+ sourceRelativePath: commandPath,
213
+ };
214
+ if (platform === 'claude') {
215
+ const claudeBlock = frontmatter.claude === undefined
216
+ ? {}
217
+ : ensureObject(frontmatter.claude, `${commandBaseField(commandPath)} frontmatter.claude`);
218
+ ensureAllowedKeys(claudeBlock, `${commandBaseField(commandPath)} frontmatter.claude`, ['description', 'allowed-tools', 'model', 'argument-hint', 'shell']);
219
+ const shell = ensureOptionalString(claudeBlock.shell, `${commandBaseField(commandPath)} frontmatter.claude.shell`);
220
+ if (shell !== undefined && !CLAUDE_SHELLS.has(shell.toLowerCase())) {
221
+ throw new Error(`Invalid ${commandBaseField(commandPath)} frontmatter.claude.shell: expected "bash" or "powershell".`);
222
+ }
223
+ command.claude = {
224
+ allowedTools: ensureAllowedTools(claudeBlock['allowed-tools'], `${commandBaseField(commandPath)} frontmatter.claude.allowed-tools`),
225
+ argumentHint: ensureOptionalString(claudeBlock['argument-hint'], `${commandBaseField(commandPath)} frontmatter.claude.argument-hint`),
226
+ body,
227
+ description: ensureOptionalString(claudeBlock.description, `${commandBaseField(commandPath)} frontmatter.claude.description`) ?? sharedDescription,
228
+ model: ensureOptionalString(claudeBlock.model, `${commandBaseField(commandPath)} frontmatter.claude.model`),
229
+ shell,
230
+ };
231
+ }
232
+ if (platform === 'codex') {
233
+ const codexBlock = frontmatter.codex === undefined
234
+ ? {}
235
+ : ensureObject(frontmatter.codex, `${commandBaseField(commandPath)} frontmatter.codex`);
236
+ if ('policy' in codexBlock) {
237
+ throw new Error(`Invalid ${commandBaseField(commandPath)} frontmatter.codex.policy: generated slashCommands skills are always manual-only.`);
238
+ }
239
+ ensureAllowedKeys(codexBlock, `${commandBaseField(commandPath)} frontmatter.codex`, CODEX_ALLOWED_FIELDS);
240
+ const codexDescription = ensureOptionalString(codexBlock.description, `${commandBaseField(commandPath)} frontmatter.codex.description`) ?? sharedDescription;
241
+ const codexInterface = normalizeCodexInterfaceBlock(pluginRoot, slashCommandsRoot, commandName, commandPath, codexDescription, codexBlock.interface);
242
+ command.codex = {
243
+ assets: codexInterface.assets,
244
+ body,
245
+ description: codexDescription,
246
+ interface: {
247
+ brandColor: codexInterface.brandColor,
248
+ defaultPrompt: codexInterface.defaultPrompt,
249
+ displayName: codexInterface.displayName,
250
+ iconLarge: codexInterface.iconLarge,
251
+ iconSmall: codexInterface.iconSmall,
252
+ shortDescription: codexInterface.shortDescription,
253
+ },
254
+ };
255
+ }
256
+ return command;
257
+ }
258
+ function listExplicitSkillNames(pluginRoot, manifest) {
259
+ if (!manifest.skills) {
260
+ return [];
261
+ }
262
+ const skillsRoot = path.join(pluginRoot, stripDotSlash(manifest.skills));
263
+ const entries = fs.readdirSync(skillsRoot, { withFileTypes: true });
264
+ return entries
265
+ .filter((entry) => entry.isDirectory())
266
+ .map((entry) => entry.name);
267
+ }
268
+ export async function resolveSlashCommands(pluginRoot, manifest, options) {
269
+ const slashCommandsRoot = manifest.slashCommands;
270
+ if (!slashCommandsRoot) {
271
+ return undefined;
272
+ }
273
+ const targetPlatforms = options?.targetPlatforms ?? resolveSupportedPlatforms(manifest);
274
+ const absoluteRoot = path.join(pluginRoot, stripDotSlash(slashCommandsRoot));
275
+ const rootStats = await fs.stat(absoluteRoot).catch(() => null);
276
+ if (!rootStats) {
277
+ throw new Error(`Invalid slashCommands: "${slashCommandsRoot}" does not exist.`);
278
+ }
279
+ if (!rootStats.isDirectory()) {
280
+ throw new Error(`Invalid slashCommands: "${slashCommandsRoot}" must point to a directory.`);
281
+ }
282
+ const explicitSkillNames = new Set(listExplicitSkillNames(pluginRoot, manifest));
283
+ const commandEntries = await fs.readdir(absoluteRoot, { withFileTypes: true });
284
+ const seenNames = new Set();
285
+ const commands = [];
286
+ for (const entry of commandEntries.sort((left, right) => left.name.localeCompare(right.name))) {
287
+ const relativeEntryPath = normalizeRelativePath(path.join(stripDotSlash(slashCommandsRoot), entry.name));
288
+ if (entry.isDirectory()) {
289
+ if (entry.name !== 'assets') {
290
+ throw new Error(`Invalid slashCommands: nested directory "${relativeEntryPath}" is not supported; only root "*.md" commands and "assets/" are allowed.`);
291
+ }
292
+ continue;
293
+ }
294
+ if (!entry.isFile()) {
295
+ throw new Error(`Invalid slashCommands: unexpected entry "${relativeEntryPath}".`);
296
+ }
297
+ if (path.posix.extname(entry.name) !== '.md') {
298
+ throw new Error(`Invalid slashCommands: unexpected file "${relativeEntryPath}"; only root "*.md" commands and "assets/" are allowed.`);
299
+ }
300
+ const commandName = path.posix.basename(entry.name, '.md');
301
+ if (commandName.length === 0 ||
302
+ commandName.length > MAX_SLASH_COMMAND_NAME_LENGTH ||
303
+ !SLASH_COMMAND_NAME_PATTERN.test(commandName)) {
304
+ throw new Error(`Invalid ${commandBaseField(relativeEntryPath)}: command names must use lowercase hyphen-case and be at most ${MAX_SLASH_COMMAND_NAME_LENGTH} characters.`);
305
+ }
306
+ if (seenNames.has(commandName)) {
307
+ throw new Error(`Invalid slashCommands: duplicate command name "${commandName}".`);
308
+ }
309
+ if (explicitSkillNames.has(commandName)) {
310
+ throw new Error(`Invalid slashCommands: command "${commandName}" conflicts with source skill "${commandName}".`);
311
+ }
312
+ seenNames.add(commandName);
313
+ const rawContent = await fs.readFile(path.join(absoluteRoot, entry.name), 'utf8');
314
+ const sourceRelativePath = normalizeRelativePath(path.join(stripDotSlash(slashCommandsRoot), entry.name));
315
+ const command = {
316
+ name: commandName,
317
+ sourceRelativePath,
318
+ };
319
+ if (targetPlatforms.has('claude')) {
320
+ const claudeRendered = renderSlashCommandSource(manifest, sourceRelativePath, rawContent, 'claude');
321
+ command.claude = parseRenderedSlashCommand(pluginRoot, slashCommandsRoot, commandName, sourceRelativePath, claudeRendered, 'claude').claude;
322
+ }
323
+ if (targetPlatforms.has('codex')) {
324
+ const codexRendered = renderSlashCommandSource(manifest, sourceRelativePath, rawContent, 'codex');
325
+ const forbiddenSyntax = detectCodexForbiddenSyntax(codexRendered);
326
+ if (forbiddenSyntax) {
327
+ throw new Error(`Invalid ${commandBaseField(sourceRelativePath)}: Codex render still contains Claude-only syntax "${forbiddenSyntax}".`);
328
+ }
329
+ command.codex = parseRenderedSlashCommand(pluginRoot, slashCommandsRoot, commandName, sourceRelativePath, codexRendered, 'codex').codex;
330
+ }
331
+ commands.push(command);
332
+ }
333
+ if (commands.length === 0) {
334
+ throw new Error(`Invalid slashCommands: "${slashCommandsRoot}" must contain at least one root "*.md" command file.`);
335
+ }
336
+ return {
337
+ commands,
338
+ rootRelativePath: slashCommandsRoot,
339
+ };
340
+ }
341
+ export function renderClaudeSlashCommand(command) {
342
+ if (!command.claude) {
343
+ throw new Error(`Missing Claude slashCommand payload for "${command.name}".`);
344
+ }
345
+ const frontmatter = {
346
+ description: command.claude.description,
347
+ 'disable-model-invocation': true,
348
+ };
349
+ if (command.claude.allowedTools !== undefined) {
350
+ frontmatter['allowed-tools'] = command.claude.allowedTools;
351
+ }
352
+ if (command.claude.model !== undefined) {
353
+ frontmatter.model = command.claude.model;
354
+ }
355
+ if (command.claude.argumentHint !== undefined) {
356
+ frontmatter['argument-hint'] = command.claude.argumentHint;
357
+ }
358
+ if (command.claude.shell !== undefined) {
359
+ frontmatter.shell = command.claude.shell;
360
+ }
361
+ return ensureTrailingNewline(`---\n${YAML.stringify(frontmatter).trimEnd()}\n---\n${command.claude.body}`);
362
+ }
363
+ export function renderCodexSlashCommandSkillMarkdown(command) {
364
+ if (!command.codex) {
365
+ throw new Error(`Missing Codex slashCommand payload for "${command.name}".`);
366
+ }
367
+ return ensureTrailingNewline(command.codex.body);
368
+ }
369
+ export function renderCodexSlashCommandOpenAiYaml(command) {
370
+ if (!command.codex) {
371
+ throw new Error(`Missing Codex slashCommand payload for "${command.name}".`);
372
+ }
373
+ const interfaceBlock = {
374
+ display_name: command.codex.interface.displayName,
375
+ short_description: command.codex.interface.shortDescription,
376
+ default_prompt: command.codex.interface.defaultPrompt,
377
+ };
378
+ if (command.codex.interface.iconSmall) {
379
+ interfaceBlock.icon_small = command.codex.interface.iconSmall;
380
+ }
381
+ if (command.codex.interface.iconLarge) {
382
+ interfaceBlock.icon_large = command.codex.interface.iconLarge;
383
+ }
384
+ if (command.codex.interface.brandColor) {
385
+ interfaceBlock.brand_color = command.codex.interface.brandColor;
386
+ }
387
+ return ensureTrailingNewline(YAML.stringify({
388
+ interface: interfaceBlock,
389
+ policy: {
390
+ allow_implicit_invocation: false,
391
+ },
392
+ }));
393
+ }
394
+ //# sourceMappingURL=slash-commands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slash-commands.js","sourceRoot":"","sources":["../src/slash-commands.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AAQxB,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,MAAM,0BAA0B,GAAG,4BAA4B,CAAC;AAChE,MAAM,6BAA6B,GAAG,EAAE,CAAC;AACzC,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;AACtD,MAAM,4BAA4B,GAAG,IAAI,GAAG,CAAC;IAC3C,eAAe;IACf,OAAO;IACP,eAAe;IACf,0BAA0B;IAC1B,OAAO;CACR,CAAC,CAAC;AACH,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC;IACrC,cAAc;IACd,mBAAmB;IACnB,YAAY;IACZ,YAAY;IACZ,aAAa;IACb,gBAAgB;CACjB,CAAC,CAAC;AACH,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC,CAAC;AAEnE,MAAM,CAAC,MAAM,0BAA0B,GAAG,gBAAgB,CAAC;AAC3D,MAAM,CAAC,MAAM,2BAA2B,GAAG,KAAK,0BAA0B,EAAE,CAAC;AA0C7E,SAAS,qBAAqB,CAAC,KAAa;IAC1C,OAAO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CAAC,SAAS,CAAC;QACb,SAAS,EAAE,cAAc;QACzB,MAAM,EAAE;YACN,yBAAyB,EAAE,KAAK;SACjC;KACF,CAAC,CACH,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { PlatformName, TemplateVarByPlatform } from './types.js';
2
+ export declare function renderTemplate(input: string, vars: Record<string, TemplateVarByPlatform>, platform: PlatformName): string;
@@ -0,0 +1,26 @@
1
+ function resolveTemplateValue(vars, platform) {
2
+ return Object.fromEntries(Object.entries(vars).map(([key, value]) => [key, value[platform]]));
3
+ }
4
+ function replaceConditionalBlocks(input, resolvedVars, tagName) {
5
+ const pattern = new RegExp(`{{#${tagName}\\s+([a-zA-Z0-9_]+)}}([\\s\\S]*?){{\\/${tagName}}}`, 'g');
6
+ return input.replace(pattern, (_match, rawKey, content) => {
7
+ const value = resolvedVars[rawKey];
8
+ const truthy = value === true;
9
+ if (tagName === 'if') {
10
+ return truthy ? content : '';
11
+ }
12
+ return truthy ? '' : content;
13
+ });
14
+ }
15
+ export function renderTemplate(input, vars, platform) {
16
+ const resolvedVars = resolveTemplateValue(vars, platform);
17
+ const withConditionals = replaceConditionalBlocks(replaceConditionalBlocks(input, resolvedVars, 'if'), resolvedVars, 'unless');
18
+ return withConditionals.replace(/{{([a-zA-Z0-9_]+)}}/g, (_match, rawKey) => {
19
+ const value = resolvedVars[rawKey];
20
+ if (value === undefined) {
21
+ return '';
22
+ }
23
+ return String(value);
24
+ });
25
+ }
26
+ //# sourceMappingURL=template-engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template-engine.js","sourceRoot":"","sources":["../src/template-engine.ts"],"names":[],"mappings":"AAEA,SAAS,oBAAoB,CAC3B,IAA2C,EAC3C,QAAsB;IAEtB,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,GAA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