mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 08:23:34 +00:00
Expose templates to the system prompt
This commit is contained in:
3 files changed
+131
-8
No files matched your search
@@ -266,6 +266,16 @@ export class SessionManager {
|
||||
// No repository URL available
|
||||
}
|
||||
|
||||
// Get project template metadata if available
|
||||
let projectTemplate: { name: string; description: string; url: string } | undefined;
|
||||
try {
|
||||
const dotai = new DotAI(this.fs, `${config.fsPathProjects}/${projectId}`);
|
||||
const template = await dotai.readTemplate();
|
||||
projectTemplate = template || undefined;
|
||||
} catch {
|
||||
// Template metadata not available
|
||||
}
|
||||
|
||||
const systemPrompt = await makeSystemPrompt({
|
||||
cwd: `${config.fsPathProjects}/${projectId}`,
|
||||
fs: this.fs,
|
||||
@@ -277,6 +287,7 @@ export class SessionManager {
|
||||
metadata,
|
||||
repositoryUrl,
|
||||
template: config.systemPrompt,
|
||||
projectTemplate,
|
||||
});
|
||||
|
||||
// Helper function to filter out unsupported image formats (keep only JPG/JPEG/PNG)
|
||||
|
||||
+98
-2
@@ -185,10 +185,11 @@ describe('makeSystemPrompt', () => {
|
||||
});
|
||||
|
||||
describe('tools section', () => {
|
||||
it('should not include tools section when no tools are provided', async () => {
|
||||
it('should show no tools message when no tools are provided', async () => {
|
||||
const result = await makeSystemPrompt(baseOpts);
|
||||
|
||||
expect(result).not.toContain('## Available Tools');
|
||||
expect(result).toContain('## Available Tools');
|
||||
expect(result).toContain('There are no tools available to you.');
|
||||
});
|
||||
|
||||
it('should list available tools with descriptions', async () => {
|
||||
@@ -425,6 +426,7 @@ describe('makeSystemPrompt', () => {
|
||||
expect(result).toContain('## User Actions');
|
||||
expect(result).toContain('## Virtual Filesystem Structure');
|
||||
expect(result).toContain('## Your Role');
|
||||
expect(result).toContain('## Project Templates');
|
||||
expect(result).toContain('## Skills');
|
||||
expect(result).toContain('## Working Around CORS Issues');
|
||||
expect(result).toContain('## Edit with Shakespeare');
|
||||
@@ -520,4 +522,98 @@ Skills: {{ skills.length }}`;
|
||||
expect(result).toContain('Skills: 0');
|
||||
});
|
||||
});
|
||||
|
||||
describe('project template metadata', () => {
|
||||
it('should include template name when projectTemplate is provided', async () => {
|
||||
const projectTemplate = {
|
||||
name: 'MKStack',
|
||||
description: 'Build Nostr clients with React.',
|
||||
url: 'https://gitlab.com/soapbox-pub/mkstack.git',
|
||||
};
|
||||
|
||||
const result = await makeSystemPrompt({
|
||||
...baseOpts,
|
||||
projectTemplate,
|
||||
});
|
||||
|
||||
expect(result).toContain('**Project Template**: MKStack');
|
||||
});
|
||||
|
||||
it('should not include template section when projectTemplate is undefined', async () => {
|
||||
const result = await makeSystemPrompt(baseOpts);
|
||||
|
||||
expect(result).not.toContain('**Project Template**:');
|
||||
});
|
||||
|
||||
it('should make projectTemplate accessible in custom templates', async () => {
|
||||
const projectTemplate = {
|
||||
name: 'MKStack',
|
||||
description: 'Build Nostr clients with React.',
|
||||
url: 'https://gitlab.com/soapbox-pub/mkstack.git',
|
||||
};
|
||||
|
||||
const customTemplate = `{% if projectTemplate %}Template: {{ projectTemplate.name }} - {{ projectTemplate.description }}{% else %}No template{% endif %}`;
|
||||
|
||||
const result = await makeSystemPrompt({
|
||||
...baseOpts,
|
||||
projectTemplate,
|
||||
template: customTemplate,
|
||||
});
|
||||
|
||||
expect(result).toContain('Template: MKStack - Build Nostr clients with React.');
|
||||
});
|
||||
|
||||
it('should handle missing projectTemplate in custom templates', async () => {
|
||||
const customTemplate = `{% if projectTemplate %}Template: {{ projectTemplate.name }}{% else %}No template{% endif %}`;
|
||||
|
||||
const result = await makeSystemPrompt({
|
||||
...baseOpts,
|
||||
template: customTemplate,
|
||||
});
|
||||
|
||||
expect(result).toContain('No template');
|
||||
});
|
||||
|
||||
it('should list all available templates from config', async () => {
|
||||
const result = await makeSystemPrompt(baseOpts);
|
||||
|
||||
expect(result).toContain('## Project Templates');
|
||||
expect(result).toContain('**Available Templates:**');
|
||||
expect(result).toContain('**MKStack**');
|
||||
expect(result).toContain('Build Nostr clients with React.');
|
||||
expect(result).toContain('https://gitlab.com/soapbox-pub/mkstack.git');
|
||||
expect(result).toContain('Settings > System');
|
||||
});
|
||||
|
||||
it('should highlight current template when it matches a configured template', async () => {
|
||||
const projectTemplate = {
|
||||
name: 'MKStack',
|
||||
description: 'Build Nostr clients with React.',
|
||||
url: 'https://gitlab.com/soapbox-pub/mkstack.git',
|
||||
};
|
||||
|
||||
const result = await makeSystemPrompt({
|
||||
...baseOpts,
|
||||
projectTemplate,
|
||||
});
|
||||
|
||||
expect(result).toContain('**MKStack** **(CURRENT TEMPLATE)**');
|
||||
});
|
||||
|
||||
it('should not highlight any template when current template does not match configured templates', async () => {
|
||||
const projectTemplate = {
|
||||
name: 'Custom Template',
|
||||
description: 'A custom template.',
|
||||
url: 'https://example.com/custom-template.git',
|
||||
};
|
||||
|
||||
const result = await makeSystemPrompt({
|
||||
...baseOpts,
|
||||
projectTemplate,
|
||||
});
|
||||
|
||||
expect(result).toContain('**MKStack**');
|
||||
expect(result).not.toContain('**(CURRENT TEMPLATE)**');
|
||||
});
|
||||
});
|
||||
});
|
||||
+22
-6
@@ -19,6 +19,7 @@ export interface MakeSystemPromptOpts {
|
||||
metadata?: NostrMetadata;
|
||||
repositoryUrl?: string;
|
||||
template?: string;
|
||||
projectTemplate?: { name: string; description: string; url: string };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,7 +35,10 @@ You are operating within **Shakespeare**, an AI-powered website builder that all
|
||||
- **Current Date**: {{ date }}
|
||||
- **Current Page**: {{ location.href }}
|
||||
- **Current Working Directory**: {{ cwd }}
|
||||
- **Repository URL**: {{ repositoryUrl }}
|
||||
- **Repository URL**: {{ repositoryUrl }}{% if projectTemplate %}
|
||||
- **Project Template**: {{ projectTemplate.name }}{% endif %}
|
||||
|
||||
Users can add or remove templates in Settings > System (\`{{ location.origin }}/settings/system\`).
|
||||
|
||||
## What Shakespeare Is
|
||||
|
||||
@@ -149,13 +153,24 @@ As the AI assistant in Shakespeare, you help users by:
|
||||
|
||||
The user expects you to handle all technical implementation while they focus on describing their vision and requirements. You can leverage the knowledge from other projects in the VFS to build better, more sophisticated applications.
|
||||
|
||||
**Always commit your code changes** after completing work on a feature, fix, or meaningful set of changes.{% if tools.length > 0 %}
|
||||
**Always commit your code changes** after completing work on a feature, fix, or meaningful set of changes.
|
||||
|
||||
## Project Templates
|
||||
|
||||
When a project is first created, you (the AI) choose an appropriate template from the available options based on the user's requirements. Once a project is created, the template cannot be changed—the user would need to create a new project to use a different template.
|
||||
|
||||
**Available Templates:**
|
||||
{% for template in config.templates %}
|
||||
- **{{ template.name }}**{% if projectTemplate and projectTemplate.url === template.url %} **(CURRENT TEMPLATE)**{% endif %}: {{ template.description }}
|
||||
- URL: {{ template.url }}
|
||||
{% endfor %}
|
||||
|
||||
## Available Tools
|
||||
|
||||
{% if tools.length > 0 %}
|
||||
You have access to the following tools:
|
||||
{% for tool in tools %}{% if tool.type === 'function' %}
|
||||
- **{{ tool.function.name }}**: {{ tool.function.description or 'No description available' }}{% endif %}{% endfor %}{% endif %}
|
||||
- **{{ tool.function.name }}**: {{ tool.function.description or 'No description available' }}{% endif %}{% endfor %}{% else %}
|
||||
There are no tools available to you.{% endif %}
|
||||
|
||||
## Skills
|
||||
|
||||
@@ -170,7 +185,7 @@ Available skills:
|
||||
|
||||
**Important**: When a task matches a skill's description, you MUST use that skill by calling the skill tool. Skills contain specialized workflows and best practices for specific tasks.{% else %}No skills are currently configured. Skills are reusable AI workflows that can be added via plugins.{% endif %}
|
||||
|
||||
Users can configure skills in Settings > AI ({{ location.origin }}/settings/ai) by adding plugins that contain skills.{% if config.corsProxy %}
|
||||
Users can configure skills in Settings > AI (\`{{ location.origin }}/settings/ai\`) by adding plugins that contain skills.{% if config.corsProxy %}
|
||||
|
||||
## Working Around CORS Issues
|
||||
|
||||
@@ -207,7 +222,7 @@ Note: the badge should be displayed at its natural size. It is recommended to om
|
||||
{{ AGENTS }}{% endif %}`;
|
||||
|
||||
export async function makeSystemPrompt(opts: MakeSystemPromptOpts): Promise<string> {
|
||||
const { tools, mode, fs, cwd, config, defaultConfig, user, metadata, repositoryUrl, template } = opts;
|
||||
const { tools, mode, fs, cwd, config, defaultConfig, user, metadata, repositoryUrl, template, projectTemplate } = opts;
|
||||
|
||||
// Add current date
|
||||
const date = new Date().toLocaleDateString("en-US", {
|
||||
@@ -288,6 +303,7 @@ export async function makeSystemPrompt(opts: MakeSystemPromptOpts): Promise<stri
|
||||
editUrl,
|
||||
README: readmeText,
|
||||
AGENTS: agentsText,
|
||||
projectTemplate,
|
||||
};
|
||||
|
||||
// Render the template with the context
|
||||
|
||||
Reference in new issue
Block a user