workflow-agent-vscode 0.1.0

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.
@@ -0,0 +1,116 @@
1
+ import * as vscode from "vscode";
2
+ import { ConfigManager } from "./config";
3
+
4
+ export class ValidationProvider {
5
+ private diagnosticCollection: vscode.DiagnosticCollection;
6
+
7
+ constructor(private configManager: ConfigManager) {
8
+ this.diagnosticCollection =
9
+ vscode.languages.createDiagnosticCollection("workflow-agent");
10
+ }
11
+
12
+ activate(context: vscode.ExtensionContext): void {
13
+ context.subscriptions.push(this.diagnosticCollection);
14
+
15
+ // Validate on file open
16
+ vscode.workspace.onDidOpenTextDocument((doc) => {
17
+ if (doc.fileName.includes(".git/COMMIT_EDITMSG")) {
18
+ this.validateCommitMessage(doc);
19
+ }
20
+ });
21
+
22
+ // Validate on change
23
+ vscode.workspace.onDidChangeTextDocument((e) => {
24
+ if (
25
+ this.configManager.shouldValidateOnType() &&
26
+ e.document.fileName.includes(".git/COMMIT_EDITMSG")
27
+ ) {
28
+ this.validateCommitMessage(e.document);
29
+ }
30
+ });
31
+ }
32
+
33
+ validateCommitMessage(document: vscode.TextDocument): void {
34
+ const text = document.getText();
35
+ const firstLine = text.split("\n")[0];
36
+
37
+ if (!firstLine || firstLine.startsWith("#")) {
38
+ return; // Empty or comment
39
+ }
40
+
41
+ const diagnostics: vscode.Diagnostic[] = [];
42
+
43
+ // Check conventional commit format: type(scope): description
44
+ const commitPattern =
45
+ /^(feat|fix|refactor|chore|docs|test|perf|style|ci|build|revert)\(([a-z0-9-]+)\): .{10,}/;
46
+
47
+ if (!commitPattern.test(firstLine)) {
48
+ const diagnostic = new vscode.Diagnostic(
49
+ new vscode.Range(0, 0, 0, firstLine.length),
50
+ "Commit message must follow format: type(scope): description",
51
+ vscode.DiagnosticSeverity.Error,
52
+ );
53
+ diagnostic.code = "workflow-commit-format";
54
+ diagnostic.source = "workflow-agent";
55
+ diagnostics.push(diagnostic);
56
+ } else {
57
+ // Validate scope
58
+ const match = firstLine.match(/\(([a-z0-9-]+)\)/);
59
+ if (match) {
60
+ const scope = match[1];
61
+ const validScopes = this.configManager.getScopes();
62
+
63
+ if (validScopes.length > 0 && !validScopes.includes(scope)) {
64
+ const diagnostic = new vscode.Diagnostic(
65
+ new vscode.Range(
66
+ 0,
67
+ firstLine.indexOf(scope),
68
+ 0,
69
+ firstLine.indexOf(scope) + scope.length,
70
+ ),
71
+ `Invalid scope '${scope}'. Valid scopes: ${validScopes.join(", ")}`,
72
+ vscode.DiagnosticSeverity.Warning,
73
+ );
74
+ diagnostic.code = "workflow-invalid-scope";
75
+ diagnostic.source = "workflow-agent";
76
+ diagnostics.push(diagnostic);
77
+ }
78
+ }
79
+ }
80
+
81
+ this.diagnosticCollection.set(document.uri, diagnostics);
82
+ }
83
+
84
+ validateBranch(branchName: string): { valid: boolean; message?: string } {
85
+ // Branch pattern: <type>/<scope>/<description>
86
+ const branchPattern =
87
+ /^(feature|bugfix|hotfix|chore|refactor|docs|test)\/([a-z0-9-]+)\/[a-z0-9-]+$/;
88
+
89
+ if (!branchPattern.test(branchName)) {
90
+ return {
91
+ valid: false,
92
+ message: "Branch name must follow: <type>/<scope>/<description>",
93
+ };
94
+ }
95
+
96
+ // Extract and validate scope
97
+ const parts = branchName.split("/");
98
+ if (parts.length >= 2) {
99
+ const scope = parts[1];
100
+ const validScopes = this.configManager.getScopes();
101
+
102
+ if (validScopes.length > 0 && !validScopes.includes(scope)) {
103
+ return {
104
+ valid: false,
105
+ message: `Invalid scope '${scope}'. Valid: ${validScopes.join(", ")}`,
106
+ };
107
+ }
108
+ }
109
+
110
+ return { valid: true };
111
+ }
112
+
113
+ dispose(): void {
114
+ this.diagnosticCollection.dispose();
115
+ }
116
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src",
6
+ "lib": ["ES2022"],
7
+ "types": ["node", "vscode"]
8
+ },
9
+ "include": ["src/**/*"],
10
+ "exclude": ["node_modules", "dist"]
11
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { defineConfig } from "tsup";
2
+
3
+ export default defineConfig({
4
+ entry: ["src/extension.ts"],
5
+ format: ["cjs"], // VS Code extensions must use CommonJS
6
+ dts: false,
7
+ sourcemap: true,
8
+ clean: true,
9
+ external: ["vscode"],
10
+ platform: "node",
11
+ target: "node18",
12
+ });