Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 633aec9

Browse filesBrowse files
improvement: stabilize AI editing flow with explicit process diagram (#446)
* improvement: stabilize AI editing flow with explicit process diagram - Add Mermaid diagram for AI editing process flow (3 branches: question/edit/unclear) - Include ALL node types' data fields in prompt (not just skill nodes) - Separate Mermaid flow to markdown file for easier maintenance - Add build-time generation script for editing flow constants Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * improvement: enforce single JSON output format in AI refinement prompt - Add explicit description requiring ONE JSON object output - Clarify that workflow must be nested inside values.workflow - Prohibit multiple JSON blocks and markdown code blocks - Add concrete examples for success/clarification/error responses Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e2607e2 commit 633aec9
Copy full SHA for 633aec9

5 files changed

+355-38Lines changed: 355 additions & 38 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.gitignore‎

Copy file name to clipboardExpand all lines: .gitignore
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ out/
66
dist/
77
*.vsix
88

9+
# Generated files
10+
*.generated.ts
11+
912
# IDE
1013
.idea/
1114

Collapse file

‎package.json‎

Copy file name to clipboardExpand all lines: package.json
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@
8989
"scripts": {
9090
"vscode:prepublish": "npm run build",
9191
"generate:toon": "npx tsx scripts/generate-toon-schema.ts",
92-
"build": "npm run generate:toon && npm run build:webview && npm run build:extension",
92+
"generate:editing-flow": "npx tsx scripts/generate-editing-flow.ts",
93+
"build": "npm run generate:toon && npm run generate:editing-flow && npm run build:webview && npm run build:extension",
9394
"build:dev": "npm run build:webview:dev && npm run build:extension:dev",
9495
"build:webview": "cd src/webview && npm run build",
9596
"build:webview:dev": "cd src/webview && npm run build:dev",
Collapse file
+68Lines changed: 68 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# AI Editing Process Flow
2+
3+
This file defines the AI editing process flow for workflow refinement.
4+
It is used by the `generate-editing-flow.ts` script to generate TypeScript constants.
5+
6+
## Mermaid Diagram
7+
8+
```mermaid
9+
flowchart TD
10+
A[1. Review current workflow completely] --> B[2. Analyze user request]
11+
B --> C{3. Request type?}
12+
C -->|Question/Understanding| D[Answer without editing - use clarification status]
13+
C -->|Edit request| E{4. Is request clear and specific?}
14+
C -->|Cannot determine| F[Return clarification request]
15+
E -->|Unclear/Ambiguous| F
16+
E -->|Clear| G[5. Identify ONLY the specific changes needed]
17+
G --> H{6. Change type?}
18+
H -->|Add| I[7a. Add new nodes/connections]
19+
H -->|Modify| J[7b. Modify ONLY target nodes]
20+
H -->|Delete| K[7c. Delete target nodes/connections]
21+
I --> L[8. COPY unchanged nodes with their EXACT original data]
22+
J --> L
23+
K --> L
24+
L --> M[9. Output complete workflow JSON]
25+
```
26+
27+
## Process Steps
28+
29+
1. Review current workflow: Understand ALL existing nodes and their data fields completely
30+
2. Analyze user request: Identify what the user wants
31+
3. Request type check: Is this a question/understanding request OR an edit request?
32+
4. Clarity check: If edit request is vague or ambiguous, return clarification
33+
5. Identify changes: List ONLY the specific nodes/connections that need modification
34+
6. Determine change type: Categorize as add, modify, or delete operation
35+
7. Apply minimal changes: Execute ONLY the identified changes
36+
8. Preserve unchanged: COPY ALL unchanged nodes with their EXACT original data field
37+
9. Output: Return the complete workflow with changes applied
38+
39+
## Request Type Guidelines
40+
41+
### Question or Understanding Request
42+
43+
- Questions starting with "What", "Why", "How", "Explain", "Tell me"
44+
- Requests for explanation or clarification about the workflow
45+
- No action verbs like "add", "modify", "delete", "change", "update", "remove"
46+
- Response: Use `{ status: "clarification", message: "your answer" }`
47+
48+
### Edit Request
49+
50+
- Contains action verbs: "add", "modify", "delete", "change", "update", "remove", "insert"
51+
- Specifies target node or location
52+
- Describes desired outcome or new content
53+
- Response: Process through steps 4-9, then use `{ status: "success", ... }`
54+
55+
### Unclear Request
56+
57+
- Vague instructions like "improve", "make better", "fix", "optimize"
58+
- Missing target specification (which node? where?)
59+
- Ambiguous or multiple interpretations possible
60+
- Response: Use `{ status: "clarification", message: "ask for details" }`
61+
62+
## Clarification Triggers
63+
64+
- User request does not specify which node to modify
65+
- User request is ambiguous about the desired outcome
66+
- Multiple valid interpretations exist for the request
67+
- Required information (node name, position, content) is missing
68+
- User request conflicts with existing workflow structure
Collapse file

‎scripts/generate-editing-flow.ts‎

Copy file name to clipboard
+224Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
/**
2+
* AI Editing Flow Generator
3+
*
4+
* Parses ai-editing-process-flow.md and generates TypeScript constants.
5+
* This allows the Mermaid diagram and process steps to be maintained in a
6+
* human-readable markdown file while being embedded in the prompt builder.
7+
*
8+
* Executed during build: npm run build
9+
*/
10+
11+
import * as fs from 'node:fs/promises';
12+
import * as path from 'node:path';
13+
14+
const RESOURCES_DIR = path.resolve(__dirname, '../resources');
15+
const MD_PATH = path.join(RESOURCES_DIR, 'ai-editing-process-flow.md');
16+
const OUTPUT_PATH = path.resolve(
17+
__dirname,
18+
'../src/extension/services/editing-flow-constants.generated.ts'
19+
);
20+
21+
interface EditingFlowData {
22+
mermaidDiagram: string;
23+
steps: string[];
24+
requestTypeGuidelines: {
25+
questionOrUnderstanding: string[];
26+
editRequest: string[];
27+
unclearRequest: string[];
28+
};
29+
clarificationTriggers: string[];
30+
}
31+
32+
/**
33+
* Extract content between ```mermaid and ``` markers
34+
*/
35+
function extractMermaidDiagram(content: string): string {
36+
const match = content.match(/```mermaid\n([\s\S]*?)```/);
37+
if (!match) {
38+
throw new Error('Mermaid diagram not found in markdown file');
39+
}
40+
return match[1].trim();
41+
}
42+
43+
/**
44+
* Extract numbered list items under a heading
45+
*/
46+
function extractNumberedList(content: string, heading: string): string[] {
47+
const headingRegex = new RegExp(`## ${heading}\\n\\n([\\s\\S]*?)(?=\\n## |$)`);
48+
const match = content.match(headingRegex);
49+
if (!match) {
50+
return [];
51+
}
52+
53+
const section = match[1];
54+
const items: string[] = [];
55+
const lines = section.split('\n');
56+
57+
for (const line of lines) {
58+
const numberedMatch = line.match(/^\d+\.\s+(.+)$/);
59+
if (numberedMatch) {
60+
items.push(numberedMatch[1].trim());
61+
}
62+
}
63+
64+
return items;
65+
}
66+
67+
/**
68+
* Extract bullet list items under a subsection heading
69+
*/
70+
function extractBulletList(content: string, mainHeading: string, subHeading: string): string[] {
71+
// Find the main section
72+
const mainRegex = new RegExp(`## ${mainHeading}\\n\\n([\\s\\S]*?)(?=\\n## [^#]|$)`);
73+
const mainMatch = content.match(mainRegex);
74+
if (!mainMatch) {
75+
return [];
76+
}
77+
78+
const mainSection = mainMatch[1];
79+
80+
// Find the subsection
81+
const subRegex = new RegExp(`### ${subHeading}\\n\\n([\\s\\S]*?)(?=\\n### |$)`);
82+
const subMatch = mainSection.match(subRegex);
83+
if (!subMatch) {
84+
return [];
85+
}
86+
87+
const subSection = subMatch[1];
88+
const items: string[] = [];
89+
const lines = subSection.split('\n');
90+
91+
for (const line of lines) {
92+
const bulletMatch = line.match(/^-\s+(.+)$/);
93+
if (bulletMatch) {
94+
// Remove backticks from inline code
95+
items.push(bulletMatch[1].trim().replace(/`/g, ''));
96+
}
97+
}
98+
99+
return items;
100+
}
101+
102+
/**
103+
* Extract bullet list items under a heading (top-level)
104+
*/
105+
function extractTopLevelBulletList(content: string, heading: string): string[] {
106+
const headingRegex = new RegExp(`## ${heading}\\n\\n([\\s\\S]*?)(?=\\n## |$)`);
107+
const match = content.match(headingRegex);
108+
if (!match) {
109+
return [];
110+
}
111+
112+
const section = match[1];
113+
const items: string[] = [];
114+
const lines = section.split('\n');
115+
116+
for (const line of lines) {
117+
const bulletMatch = line.match(/^-\s+(.+)$/);
118+
if (bulletMatch) {
119+
items.push(bulletMatch[1].trim());
120+
}
121+
}
122+
123+
return items;
124+
}
125+
126+
/**
127+
* Parse the markdown file and extract all data
128+
*/
129+
function parseMarkdown(content: string): EditingFlowData {
130+
return {
131+
mermaidDiagram: extractMermaidDiagram(content),
132+
steps: extractNumberedList(content, 'Process Steps'),
133+
requestTypeGuidelines: {
134+
questionOrUnderstanding: extractBulletList(
135+
content,
136+
'Request Type Guidelines',
137+
'Question or Understanding Request'
138+
),
139+
editRequest: extractBulletList(content, 'Request Type Guidelines', 'Edit Request'),
140+
unclearRequest: extractBulletList(content, 'Request Type Guidelines', 'Unclear Request'),
141+
},
142+
clarificationTriggers: extractTopLevelBulletList(content, 'Clarification Triggers'),
143+
};
144+
}
145+
146+
/**
147+
* Generate TypeScript code from parsed data
148+
*/
149+
function generateTypeScript(data: EditingFlowData): string {
150+
const toStringArray = (arr: string[]) =>
151+
arr.map((item) => ` '${item.replace(/'/g, "\\'")}',`).join('\n');
152+
153+
return `/**
154+
* AI Editing Flow Constants
155+
*
156+
* AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY
157+
* Generated from: resources/ai-editing-process-flow.md
158+
* To modify, edit the markdown file and run: npm run generate:editing-flow
159+
*/
160+
161+
/**
162+
* Mermaid diagram representing the AI editing process flow
163+
*/
164+
export const EDITING_PROCESS_MERMAID_DIAGRAM = \`${data.mermaidDiagram}\`;
165+
166+
/**
167+
* Step-by-step process for AI editing
168+
*/
169+
export const EDITING_PROCESS_STEPS: readonly string[] = [
170+
${toStringArray(data.steps)}
171+
] as const;
172+
173+
/**
174+
* Guidelines for identifying request types
175+
*/
176+
export const REQUEST_TYPE_GUIDELINES = {
177+
questionOrUnderstanding: [
178+
${toStringArray(data.requestTypeGuidelines.questionOrUnderstanding)}
179+
] as const,
180+
editRequest: [
181+
${toStringArray(data.requestTypeGuidelines.editRequest)}
182+
] as const,
183+
unclearRequest: [
184+
${toStringArray(data.requestTypeGuidelines.unclearRequest)}
185+
] as const,
186+
} as const;
187+
188+
/**
189+
* Conditions that should trigger a clarification request
190+
*/
191+
export const CLARIFICATION_TRIGGERS: readonly string[] = [
192+
${toStringArray(data.clarificationTriggers)}
193+
] as const;
194+
`;
195+
}
196+
197+
async function generateEditingFlow(): Promise<void> {
198+
console.log('Generating editing flow constants from ai-editing-process-flow.md...');
199+
200+
try {
201+
// Read markdown file
202+
const mdContent = await fs.readFile(MD_PATH, 'utf-8');
203+
204+
// Parse markdown
205+
const data = parseMarkdown(mdContent);
206+
207+
// Generate TypeScript
208+
const tsContent = generateTypeScript(data);
209+
210+
// Write output file
211+
await fs.writeFile(OUTPUT_PATH, tsContent, 'utf-8');
212+
213+
console.log('Editing flow constants generated successfully:');
214+
console.log(` Source: ${path.relative(process.cwd(), MD_PATH)}`);
215+
console.log(` Output: ${path.relative(process.cwd(), OUTPUT_PATH)}`);
216+
console.log(` Steps: ${data.steps.length}`);
217+
console.log(` Clarification triggers: ${data.clarificationTriggers.length}`);
218+
} catch (error) {
219+
console.error('Failed to generate editing flow constants:', error);
220+
process.exit(1);
221+
}
222+
}
223+
224+
generateEditingFlow();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.