@untools/devflow 0.2.11 → 0.2.13

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 (106) hide show
  1. package/dist/agent/client.d.ts +50 -0
  2. package/dist/agent/client.d.ts.map +1 -0
  3. package/dist/agent/client.js +52 -0
  4. package/dist/agent/client.js.map +1 -0
  5. package/dist/auth/github-token.d.ts +16 -0
  6. package/dist/auth/github-token.d.ts.map +1 -0
  7. package/dist/auth/github-token.js +69 -0
  8. package/dist/auth/github-token.js.map +1 -0
  9. package/dist/auth/oauth.d.ts +16 -0
  10. package/dist/auth/oauth.d.ts.map +1 -0
  11. package/dist/auth/oauth.js +146 -0
  12. package/dist/auth/oauth.js.map +1 -0
  13. package/dist/cli.d.ts +2 -0
  14. package/dist/cli.d.ts.map +1 -0
  15. package/dist/cli.js +363 -0
  16. package/dist/cli.js.map +1 -0
  17. package/dist/config.d.ts +35 -0
  18. package/dist/config.d.ts.map +1 -0
  19. package/dist/config.js +78 -0
  20. package/dist/config.js.map +1 -0
  21. package/dist/copilot/client.d.ts +75 -0
  22. package/dist/copilot/client.d.ts.map +1 -0
  23. package/dist/copilot/client.js +226 -0
  24. package/dist/copilot/client.js.map +1 -0
  25. package/dist/copilot/flows/base.d.ts +47 -0
  26. package/dist/copilot/flows/base.d.ts.map +1 -0
  27. package/dist/copilot/flows/base.js +235 -0
  28. package/dist/copilot/flows/base.js.map +1 -0
  29. package/dist/copilot/flows/explain.d.ts +5 -0
  30. package/dist/copilot/flows/explain.d.ts.map +1 -0
  31. package/dist/copilot/flows/explain.js +76 -0
  32. package/dist/copilot/flows/explain.js.map +1 -0
  33. package/dist/copilot/flows/feature.d.ts +5 -0
  34. package/dist/copilot/flows/feature.d.ts.map +1 -0
  35. package/dist/copilot/flows/feature.js +83 -0
  36. package/dist/copilot/flows/feature.js.map +1 -0
  37. package/dist/copilot/flows/fix-bug.d.ts +5 -0
  38. package/dist/copilot/flows/fix-bug.d.ts.map +1 -0
  39. package/dist/copilot/flows/fix-bug.js +56 -0
  40. package/dist/copilot/flows/fix-bug.js.map +1 -0
  41. package/dist/copilot/flows/index.d.ts +17 -0
  42. package/dist/copilot/flows/index.d.ts.map +1 -0
  43. package/dist/copilot/flows/index.js +41 -0
  44. package/dist/copilot/flows/index.js.map +1 -0
  45. package/dist/copilot/flows/review-pr.d.ts +5 -0
  46. package/dist/copilot/flows/review-pr.d.ts.map +1 -0
  47. package/dist/copilot/flows/review-pr.js +84 -0
  48. package/dist/copilot/flows/review-pr.js.map +1 -0
  49. package/dist/copilot/session-registry.d.ts +12 -0
  50. package/dist/copilot/session-registry.d.ts.map +1 -0
  51. package/dist/copilot/session-registry.js +39 -0
  52. package/dist/copilot/session-registry.js.map +1 -0
  53. package/dist/copilot/tools/files.d.ts +53 -0
  54. package/dist/copilot/tools/files.d.ts.map +1 -0
  55. package/dist/copilot/tools/files.js +250 -0
  56. package/dist/copilot/tools/files.js.map +1 -0
  57. package/dist/copilot/tools/git.d.ts +37 -0
  58. package/dist/copilot/tools/git.d.ts.map +1 -0
  59. package/dist/copilot/tools/git.js +246 -0
  60. package/dist/copilot/tools/git.js.map +1 -0
  61. package/dist/copilot/tools/github.d.ts +36 -0
  62. package/dist/copilot/tools/github.d.ts.map +1 -0
  63. package/dist/copilot/tools/github.js +216 -0
  64. package/dist/copilot/tools/github.js.map +1 -0
  65. package/dist/copilot/tools/index.d.ts +26 -0
  66. package/dist/copilot/tools/index.d.ts.map +1 -0
  67. package/dist/copilot/tools/index.js +25 -0
  68. package/dist/copilot/tools/index.js.map +1 -0
  69. package/dist/copilot/tools/progress.d.ts +19 -0
  70. package/dist/copilot/tools/progress.d.ts.map +1 -0
  71. package/dist/copilot/tools/progress.js +87 -0
  72. package/dist/copilot/tools/progress.js.map +1 -0
  73. package/dist/copilot/tools/tests.d.ts +29 -0
  74. package/dist/copilot/tools/tests.d.ts.map +1 -0
  75. package/dist/copilot/tools/tests.js +136 -0
  76. package/dist/copilot/tools/tests.js.map +1 -0
  77. package/dist/copilot/tools/utils.d.ts +14 -0
  78. package/dist/copilot/tools/utils.d.ts.map +1 -0
  79. package/dist/copilot/tools/utils.js +89 -0
  80. package/dist/copilot/tools/utils.js.map +1 -0
  81. package/dist/credentials.d.ts +21 -0
  82. package/dist/credentials.d.ts.map +1 -0
  83. package/dist/credentials.js +62 -0
  84. package/dist/credentials.js.map +1 -0
  85. package/dist/devflow/client.d.ts +16 -0
  86. package/dist/devflow/client.d.ts.map +1 -0
  87. package/dist/devflow/client.js +61 -0
  88. package/dist/devflow/client.js.map +1 -0
  89. package/dist/index.d.ts +2 -0
  90. package/dist/index.d.ts.map +1 -0
  91. package/dist/index.js +7 -0
  92. package/dist/index.js.map +1 -0
  93. package/dist/pinga/client.d.ts +16 -0
  94. package/dist/pinga/client.d.ts.map +1 -0
  95. package/dist/pinga/client.js +61 -0
  96. package/dist/pinga/client.js.map +1 -0
  97. package/dist/types.d.ts +58 -0
  98. package/dist/types.d.ts.map +1 -0
  99. package/dist/types.js +2 -0
  100. package/dist/types.js.map +1 -0
  101. package/dist/verify-full-flow.d.ts +2 -0
  102. package/dist/verify-full-flow.d.ts.map +1 -0
  103. package/dist/verify-full-flow.js +81 -0
  104. package/dist/verify-full-flow.js.map +1 -0
  105. package/package.json +8 -1
  106. package/.versionrc.json +0 -53
@@ -0,0 +1,226 @@
1
+ // Copilot SDK client - Real SDK Integration
2
+ // Uses @github/copilot-sdk for agent control
3
+ // Reference: https://github.com/github/copilot-sdk
4
+ import { CopilotClient as RealCopilotClient, } from "@github/copilot-sdk";
5
+ /**
6
+ * CopilotClient - Wrapper for GitHub Copilot SDK
7
+ *
8
+ * This uses the real @github/copilot-sdk package installed from npm.
9
+ *
10
+ * Requirements:
11
+ * - GitHub Copilot CLI installed and authenticated (copilot --version)
12
+ * - @github/copilot-sdk package installed (npm install @github/copilot-sdk)
13
+ */
14
+ export class CopilotClient {
15
+ constructor() {
16
+ this.model = "gpt-4";
17
+ this.eventListeners = [];
18
+ // Initialize the real SDK client
19
+ // Ensure we have authentication
20
+ const token = process.env.GITHUB_TOKEN || process.env.GITHUB_COPILOT_TOKEN;
21
+ if (!token) {
22
+ console.warn("⚠️ [CopilotClient] No GITHUB_TOKEN or GITHUB_COPILOT_TOKEN found in environment!");
23
+ console.warn(" The Copilot SDK may fail to authenticate.");
24
+ }
25
+ this.client = new RealCopilotClient({
26
+ // The SDK uses GITHUB_TOKEN or GH_TOKEN from env by default, but we can pass explicit auth or env.
27
+ // Based on demo, passing env explicitly with multiple token vars helps robustness.
28
+ env: {
29
+ ...process.env,
30
+ GITHUB_TOKEN: token, // Ensure it's set if we found it
31
+ GH_TOKEN: token,
32
+ COPILOT_GITHUB_TOKEN: token,
33
+ },
34
+ });
35
+ }
36
+ async createSession(options) {
37
+ const self = this;
38
+ const model = options.model || this.model;
39
+ console.log(`[CopilotClient] 🚀 Creating session with model: ${model}`);
40
+ console.log(`[CopilotClient] Streaming: ${options.streaming !== false}`);
41
+ if (options.tools?.length) {
42
+ console.log(`[CopilotClient] Tools: ${options.tools.map((t) => t.name || "unknown").join(", ")}`);
43
+ }
44
+ // Re-initialize client if a specific token is provided (e.g. from user credentials)
45
+ if (options.githubToken) {
46
+ console.log("[CopilotClient] 🔄 Re-initializing SDK with provided user token");
47
+ this.client = new RealCopilotClient({
48
+ env: {
49
+ ...process.env,
50
+ GITHUB_TOKEN: options.githubToken,
51
+ GH_TOKEN: options.githubToken,
52
+ COPILOT_GITHUB_TOKEN: options.githubToken,
53
+ },
54
+ });
55
+ }
56
+ try {
57
+ // Ensure client is started
58
+ // The SDK's start() is usually idempotent or we can check state if needed,
59
+ // but simplistic approach: just call it.
60
+ console.log("[CopilotClient] Starting SDK client...");
61
+ await this.client.start();
62
+ console.log("[CopilotClient] Verifying authentication...");
63
+ const authStatus = await this.client.getAuthStatus();
64
+ console.log(`[CopilotClient] Auth Status: ${JSON.stringify(authStatus)}`);
65
+ const statusAny = authStatus;
66
+ if (statusAny.status === "NotAuthenticated" ||
67
+ statusAny.status === "error" ||
68
+ statusAny.isAuthenticated === false) {
69
+ throw new Error(`Copilot Authentication Failed: ${authStatus.statusMessage || "Unknown reason"}`);
70
+ }
71
+ // Create real SDK session
72
+ const realSession = await this.client.createSession({
73
+ model,
74
+ streaming: options.streaming !== false,
75
+ tools: options.tools, // Pass undefined if not provided, allowing SDK defaults
76
+ });
77
+ // Wrap the real session to normalize event types
78
+ return {
79
+ async sendAndWait(request) {
80
+ let output = "";
81
+ realSession.on((event) => {
82
+ // console.log(
83
+ // `[CopilotClient] Raw Event: ${event.type}`,
84
+ // JSON.stringify(event.data || {}, null, 2),
85
+ // );
86
+ // Wrapper to map internal types to our exported types
87
+ let mappedEvent = null;
88
+ switch (event.type) {
89
+ case "assistant.message_delta":
90
+ mappedEvent = {
91
+ type: "assistant.message_delta",
92
+ data: {
93
+ deltaContent: event.data?.deltaContent,
94
+ messageId: event.data?.messageId,
95
+ },
96
+ };
97
+ output += event.data?.deltaContent || "";
98
+ break;
99
+ case "assistant.turn_start":
100
+ mappedEvent = {
101
+ type: "assistant.turn_start",
102
+ data: { turnId: event.data?.turnId },
103
+ };
104
+ break;
105
+ case "assistant.turn_end":
106
+ mappedEvent = {
107
+ type: "assistant.turn_end",
108
+ data: { turnId: event.data?.turnId },
109
+ };
110
+ break;
111
+ case "session.usage_info":
112
+ mappedEvent = {
113
+ type: "session.usage_info",
114
+ data: event.data,
115
+ };
116
+ break;
117
+ case "session.idle":
118
+ mappedEvent = { type: "session.idle" };
119
+ break;
120
+ case "tool.start":
121
+ case "tool_start": // Fallback for older SDK versions
122
+ case "tool.execution_start":
123
+ mappedEvent = {
124
+ type: "tool.execution_start",
125
+ data: {
126
+ toolName: event.data?.toolName,
127
+ toolCallId: event.data?.toolCallId,
128
+ arguments: event.data?.arguments,
129
+ },
130
+ };
131
+ break;
132
+ case "tool.end":
133
+ case "tool_end":
134
+ case "tool.execution_complete":
135
+ mappedEvent = {
136
+ type: "tool.execution_complete",
137
+ data: {
138
+ toolCallId: event.data?.toolCallId,
139
+ result: event.data?.result,
140
+ success: event.data?.success,
141
+ },
142
+ };
143
+ break;
144
+ case "error":
145
+ case "session.error":
146
+ mappedEvent = {
147
+ type: "error",
148
+ data: { message: event.data?.message || "Unknown error" },
149
+ };
150
+ break;
151
+ }
152
+ if (mappedEvent) {
153
+ self.eventListeners.forEach((listener) => listener(mappedEvent));
154
+ }
155
+ });
156
+ console.log(`[CopilotClient] Sending Prompt: ${request.prompt.substring(0, 50)}...`);
157
+ try {
158
+ // Increase timeout to 10 minutes for complex workflows
159
+ // The SDK's default 60s is too short for comprehensive tasks
160
+ const response = await realSession.sendAndWait(request, 600000); // 10 min timeout
161
+ console.log(`[CopilotClient] Final Response:`, JSON.stringify(response, null, 2));
162
+ return response;
163
+ }
164
+ catch (err) {
165
+ // Check if it's a timeout error
166
+ const isTimeout = err instanceof Error &&
167
+ err.message.includes("Timeout after") &&
168
+ err.message.includes("waiting for session.idle");
169
+ if (isTimeout) {
170
+ console.warn(`[CopilotClient] Session timed out after 10 minutes, but workflow may still` +
171
+ ` be running. The session will continue in the background.`);
172
+ // Don't throw - allow the workflow to continue and send completion when done
173
+ // The `send_progress_update` tool will handle final status
174
+ return {
175
+ output,
176
+ warning: "Workflow timed out but may still complete",
177
+ };
178
+ }
179
+ console.error(`[CopilotClient] sendAndWait failed:`, err);
180
+ throw err;
181
+ }
182
+ },
183
+ on(callback) {
184
+ self.eventListeners.push(callback);
185
+ },
186
+ };
187
+ }
188
+ catch (error) {
189
+ console.error("[CopilotClient] Failed to create session:", error);
190
+ throw error;
191
+ }
192
+ }
193
+ async stop() {
194
+ console.log("[CopilotClient] Stopping session...");
195
+ // Real SDK cleanup if needed
196
+ }
197
+ }
198
+ let copilotInstance = null;
199
+ export function getCopilotClient() {
200
+ if (!copilotInstance) {
201
+ copilotInstance = new CopilotClient();
202
+ }
203
+ return copilotInstance;
204
+ }
205
+ /**
206
+ * Tool Definition Helper
207
+ * Creates Copilot SDK-compatible tool definitions
208
+ *
209
+ * Example:
210
+ * const gitTool = defineTool("git_ops", {
211
+ * description: "Execute git operations",
212
+ * parameters: {
213
+ * type: "object",
214
+ * properties: { ... },
215
+ * required: [...]
216
+ * },
217
+ * handler: async (args) => ({ ... })
218
+ * });
219
+ */
220
+ export function defineTool(name, definition) {
221
+ return {
222
+ name,
223
+ ...definition,
224
+ };
225
+ }
226
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/copilot/client.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,6CAA6C;AAC7C,mDAAmD;AAEnD,OAAO,EACL,aAAa,IAAI,iBAAiB,GAEnC,MAAM,qBAAqB,CAAC;AA6C7B;;;;;;;;GAQG;AACH,MAAM,OAAO,aAAa;IAKxB;QAJQ,UAAK,GAAW,OAAO,CAAC;QAExB,mBAAc,GAAyC,EAAE,CAAC;QAGhE,iCAAiC;QACjC,gCAAgC;QAChC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC;QAC3E,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,CAAC,IAAI,CACV,kFAAkF,CACnF,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,8CAA8C,CAAC,CAAC;QAC/D,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,IAAI,iBAAiB,CAAC;YAClC,mGAAmG;YACnG,mFAAmF;YACnF,GAAG,EAAE;gBACH,GAAG,OAAO,CAAC,GAAG;gBACd,YAAY,EAAE,KAAK,EAAE,iCAAiC;gBACtD,QAAQ,EAAE,KAAK;gBACf,oBAAoB,EAAE,KAAK;aAC5B;SACK,CAAC,CAAC;IACZ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,OAA6B;QAC/C,MAAM,IAAI,GAAG,IAAI,CAAC;QAElB,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK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AAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,2CAA2C,EAAE,KAAK,CAAC,CAAC;YAClE,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED,KAAK,CAAC,IAAI;QACR,OAAO,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAC;QACnD,6BAA6B;IAC/B,CAAC;CACF;AAED,IAAI,eAAe,GAAyB,IAAI,CAAC;AAEjD,MAAM,UAAU,gBAAgB;IAC9B,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,eAAe,GAAG,IAAI,aAAa,EAAE,CAAC;IACxC,CAAC;IACD,OAAO,eAAe,CAAC;AACzB,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,UAAU,CACxB,IAAY,EACZ,UAIC;IAED,OAAO;QACL,IAAI;QACJ,GAAG,UAAU;KACd,CAAC;AACJ,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { CopilotClient, Session } from "../client.js";
2
+ import DevflowClient from "../../devflow/client.js";
3
+ export interface WorkflowContext {
4
+ taskId: string;
5
+ intent: string;
6
+ repo: string;
7
+ localPath?: string;
8
+ branch?: string;
9
+ naturalLanguage: string;
10
+ context?: Record<string, any>;
11
+ source: {
12
+ channel: "telegram" | "slack" | "cli";
13
+ chatId: string;
14
+ messageId: string;
15
+ };
16
+ credentials?: {
17
+ github?: string;
18
+ };
19
+ sessionId?: string;
20
+ localGitHubToken?: string;
21
+ }
22
+ export interface WorkflowResult {
23
+ success: boolean;
24
+ output?: string;
25
+ prUrl?: string;
26
+ summary?: string;
27
+ error?: string;
28
+ }
29
+ export declare class WorkflowExecutor {
30
+ protected devflowClient: DevflowClient;
31
+ protected copilot: CopilotClient;
32
+ protected devflowConfig: {
33
+ url: string;
34
+ secret: string;
35
+ };
36
+ private progressUpdateCount;
37
+ private readonly ESTIMATED_MAX_UPDATES;
38
+ private readonly MAX_AUTO_PROGRESS;
39
+ constructor(devflowUrl: string, devflowSecret: string);
40
+ protected sendProgress(taskId: string, step: string, progress: number, details?: string): Promise<void>;
41
+ protected sendCompletion(taskId: string, result: WorkflowResult): Promise<void>;
42
+ protected buildSystemPrompt(intent: string, context: WorkflowContext): string;
43
+ protected setupSession(context: WorkflowContext): Promise<Session>;
44
+ protected executeWorkflow(prompt: string, context: WorkflowContext): Promise<WorkflowResult>;
45
+ execute(context: WorkflowContext): Promise<WorkflowResult>;
46
+ }
47
+ //# sourceMappingURL=base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/copilot/flows/base.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,OAAO,EAAgB,MAAM,cAAc,CAAC;AAEpE,OAAO,aAAa,MAAM,yBAAyB,CAAC;AAGpD,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,MAAM,EAAE;QACN,OAAO,EAAE,UAAU,GAAG,OAAO,GAAG,KAAK,CAAC;QACtC,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IAEF,WAAW,CAAC,EAAE;QACZ,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,gBAAgB;IAC3B,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC;IACvC,SAAS,CAAC,OAAO,EAAE,aAAa,CAAC;IACjC,SAAS,CAAC,aAAa,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAGzD,OAAO,CAAC,mBAAmB,CAAK;IAChC,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAM;IAC5C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAQ;gBAE9B,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM;cAMrC,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC;cAkBA,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,IAAI,CAAC;IA4BhB,SAAS,CAAC,iBAAiB,CACzB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,eAAe,GACvB,MAAM;cA0BO,YAAY,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC;cA2ExD,eAAe,CAC7B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,cAAc,CAAC;IA4IpB,OAAO,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;CAGjE"}
@@ -0,0 +1,235 @@
1
+ // Workflow executor base and orchestration logic
2
+ import { CopilotClient } from "../client.js";
3
+ import DevflowClient from "../../devflow/client.js";
4
+ import { getAllTools } from "../tools/index.js";
5
+ export class WorkflowExecutor {
6
+ constructor(devflowUrl, devflowSecret) {
7
+ // Auto-incrementing progress tracking
8
+ this.progressUpdateCount = 0;
9
+ this.ESTIMATED_MAX_UPDATES = 30; // Rough estimate of updates per workflow
10
+ this.MAX_AUTO_PROGRESS = 0.95; // Cap at 95%, leave 5% for completion
11
+ this.devflowConfig = { url: devflowUrl, secret: devflowSecret };
12
+ this.devflowClient = new DevflowClient(devflowUrl, devflowSecret);
13
+ this.copilot = new CopilotClient(); // Will be replaced with actual SDK when available
14
+ }
15
+ async sendProgress(taskId, step, progress, details) {
16
+ // Auto-increment progress instead of using Copilot's arbitrary values
17
+ this.progressUpdateCount++;
18
+ const autoProgress = Math.min(this.MAX_AUTO_PROGRESS, this.progressUpdateCount / this.ESTIMATED_MAX_UPDATES);
19
+ await this.devflowClient.sendProgressUpdate({
20
+ taskId,
21
+ status: "in_progress",
22
+ step,
23
+ progress: autoProgress, // Use calculated progress instead of Copilot's value
24
+ details,
25
+ timestamp: Date.now(),
26
+ });
27
+ }
28
+ async sendCompletion(taskId, result) {
29
+ console.log(`[WorkflowExecutor] Sending completion for ${taskId}, success: ${result.success}`);
30
+ try {
31
+ if (result.success) {
32
+ await this.devflowClient.notifyCompletion(taskId, {
33
+ summary: result.summary || "Workflow completed successfully",
34
+ prUrl: result.prUrl,
35
+ output: result.output,
36
+ });
37
+ console.log(`[WorkflowExecutor] Completion notification sent for ${taskId}`);
38
+ }
39
+ else {
40
+ await this.devflowClient.notifyError(taskId, result.error || "Workflow failed");
41
+ console.log(`[WorkflowExecutor] Error notification sent for ${taskId}`);
42
+ }
43
+ }
44
+ catch (error) {
45
+ console.error(`[WorkflowExecutor] Failed to send completion notification: ${error}`);
46
+ }
47
+ }
48
+ buildSystemPrompt(intent, context) {
49
+ return `You are Devflow, an AI DevOps agent integrated with GitHub Copilot.
50
+
51
+ Your task: ${intent}
52
+ Repository: ${context.repo}
53
+ Branch: ${context.branch || "main"}
54
+ Request: ${context.naturalLanguage}
55
+ Task ID: ${context.taskId}
56
+
57
+ You have access to these tools:
58
+ - git_operations: Clone, branch, commit, push repositories
59
+ - run_tests: Run test suites and capture results
60
+ - read_file, write_file, list_files: File operations
61
+ - open_pull_request: Create and manage pull requests
62
+ - send_progress_update: Send progress updates to the user
63
+
64
+ IMPORTANT:
65
+ 1. Always send progress updates at key milestones
66
+ 2. Use read_file to examine code before making changes
67
+ 3. Verify changes with run_tests before pushing
68
+ 4. Create pull requests with clear descriptions
69
+ 5. Report all errors clearly with context
70
+
71
+ Begin by understanding the repository structure.`;
72
+ }
73
+ async setupSession(context) {
74
+ try {
75
+ // Check for existing session
76
+ if (context.sessionId) {
77
+ const { SessionRegistry } = await import("../session-registry.js");
78
+ const existingSession = SessionRegistry.get(context.sessionId);
79
+ if (existingSession) {
80
+ return existingSession;
81
+ }
82
+ }
83
+ // Determine GitHub token source (Priority: local > platform > env)
84
+ let userGitHubToken;
85
+ // 1. Check local config token (most secure, recommended)
86
+ if (context.localGitHubToken) {
87
+ userGitHubToken = context.localGitHubToken;
88
+ console.log("[Workflow] Using local GitHub token from config");
89
+ }
90
+ // 2. Try platform-provided encrypted credentials (legacy/SaaS mode)
91
+ else if (context.credentials?.github) {
92
+ try {
93
+ const { decryptCredentials } = await import("../../credentials.js");
94
+ const decrypted = decryptCredentials(context.credentials);
95
+ userGitHubToken = decrypted.github;
96
+ console.log("[Workflow] Using decrypted user credentials (managed SaaS)");
97
+ }
98
+ catch (error) {
99
+ console.warn("[Workflow] Failed to decrypt credentials, falling back to env var:", error instanceof Error ? error.message : error);
100
+ }
101
+ }
102
+ // 3. Fall back to environment variable
103
+ else {
104
+ console.log("[Workflow] No local token or platform credentials. Using GITHUB_TOKEN from environment (if set)");
105
+ }
106
+ const session = await this.copilot.createSession({
107
+ model: process.env.COPILOT_MODEL || "gpt-3.5-turbo",
108
+ streaming: true,
109
+ tools: getAllTools({
110
+ githubToken: userGitHubToken,
111
+ localPath: context.localPath,
112
+ devflowUrl: this.devflowConfig.url,
113
+ devflowSecret: this.devflowConfig.secret,
114
+ }),
115
+ githubToken: userGitHubToken,
116
+ mcpServers: process.env.COPILOT_ENABLE_MCP === "true"
117
+ ? {
118
+ github: {
119
+ type: "http",
120
+ url: "https://api.github.com/mcp/",
121
+ },
122
+ }
123
+ : undefined,
124
+ });
125
+ // Register new session if ID provided
126
+ if (context.sessionId) {
127
+ const { SessionRegistry } = await import("../session-registry.js");
128
+ SessionRegistry.register(context.sessionId, session);
129
+ }
130
+ return session;
131
+ }
132
+ catch (error) {
133
+ throw new Error(`Failed to create Copilot session: ${error}`);
134
+ }
135
+ }
136
+ async executeWorkflow(prompt, context) {
137
+ try {
138
+ // Reset progress counter for this workflow
139
+ this.progressUpdateCount = 0;
140
+ const session = await this.setupSession(context);
141
+ this.devflowClient.sendLog(context.taskId, "info", `Starting workflow execution for task: ${context.intent}`);
142
+ this.devflowClient.sendLog(context.taskId, "info", `Context: Repo=${context.repo}, Branch=${context.branch || "default"}, LocalPath=${context.localPath || "N/A"}`);
143
+ let output = "";
144
+ let hasError = false;
145
+ let errorMessage = "";
146
+ // Listen for session events
147
+ let pendingDeltaBuffer = "";
148
+ let lastProgressUpdate = 0;
149
+ const PROGRESS_THROTTLE_MS = 2000; // Throttle text updates to every 2s
150
+ session.on((event) => {
151
+ // console.log(`[${context.taskId}] Event:`, event.type); // Debug logging
152
+ if (event.type === "tool.execution_start" ||
153
+ event.type === "tool.start") {
154
+ const toolName = event.data?.toolName || "unknown";
155
+ console.log(`[${context.taskId}] Tool Start: ${toolName}`);
156
+ // Flush any pending text before announcing tool start
157
+ if (pendingDeltaBuffer.trim().length > 0) {
158
+ this.sendProgress(context.taskId, pendingDeltaBuffer, // Send the accumulated text as the "step" description/output
159
+ 0.3).catch(console.error);
160
+ pendingDeltaBuffer = "";
161
+ }
162
+ this.sendProgress(context.taskId, `Executing: ${toolName}`, 0.3).catch(console.error);
163
+ }
164
+ if (event.type === "tool.execution_complete" ||
165
+ event.type === "tool.end") {
166
+ const result = event.data?.result;
167
+ console.log(`[${context.taskId}] Tool Result:`, JSON.stringify(result).substring(0, 100) + "...");
168
+ // We don't send a separate update for tool end to avoid noise, unless it failed
169
+ }
170
+ if (event.type === "assistant.message_delta") {
171
+ const chunk = event.data?.deltaContent || "";
172
+ output += chunk;
173
+ pendingDeltaBuffer += chunk;
174
+ // Periodically flush buffer to keep user engaged if response is long
175
+ const now = Date.now();
176
+ if (now - lastProgressUpdate > PROGRESS_THROTTLE_MS &&
177
+ pendingDeltaBuffer.length > 20) {
178
+ // Send what we have so far
179
+ // Note: In a real streaming architecture, we'd append.
180
+ // Here we are updating the "step" which might overwrite previous "step" text in UI
181
+ // depending on how frontend handles it.
182
+ // For "smart batching" in a chat context, we mainly want to avoid network spam.
183
+ this.sendProgress(context.taskId, pendingDeltaBuffer, // Update current "step" with latest text chunk
184
+ 0.4).catch(console.error);
185
+ lastProgressUpdate = now;
186
+ // We keep buffer growing? Or reset?
187
+ // If we reset, the UI might see "..." -> "Hello" -> "World".
188
+ // If the UI replaces the text, we should probably send the *accumulated* buffer for this turn if possible,
189
+ // or just send the delta if the UI appends.
190
+ // Assuming the UI replaces "step" description:
191
+ // Let's NOT reset buffer here if we want to show full message building up in the "step" field.
192
+ // But pendingDeltaBuffer is meant to be "whats new".
193
+ // Let's assume the UI shows a log or chat bubble.
194
+ // To be safe, we just throttle.
195
+ // Actually, flushing effectively clears the "pending" state for the *next* update.
196
+ pendingDeltaBuffer = "";
197
+ }
198
+ }
199
+ if (event.type === "session.usage_info") {
200
+ console.log(`[${context.taskId}] Token Usage: ${event.data?.currentTokens}/${event.data?.tokenLimit}`);
201
+ }
202
+ if (event.type === "error") {
203
+ hasError = true;
204
+ errorMessage = event.data?.message || "Unknown error";
205
+ console.error(`[${context.taskId}] Error:`, errorMessage);
206
+ }
207
+ });
208
+ // Send the workflow prompt
209
+ await session.sendAndWait({ prompt });
210
+ if (hasError) {
211
+ return {
212
+ success: false,
213
+ error: errorMessage,
214
+ output,
215
+ };
216
+ }
217
+ return {
218
+ success: true,
219
+ output,
220
+ summary: "Workflow completed successfully",
221
+ };
222
+ }
223
+ catch (error) {
224
+ const errorMsg = error instanceof Error ? error.message : String(error);
225
+ return {
226
+ success: false,
227
+ error: errorMsg,
228
+ };
229
+ }
230
+ }
231
+ async execute(context) {
232
+ throw new Error("execute() must be implemented by subclasses");
233
+ }
234
+ }
235
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/copilot/flows/base.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,OAAO,EAAE,aAAa,EAAyB,MAAM,cAAc,CAAC;AAEpE,OAAO,aAAa,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AA+BhD,MAAM,OAAO,gBAAgB;IAU3B,YAAY,UAAkB,EAAE,aAAqB;QALrD,sCAAsC;QAC9B,wBAAmB,GAAG,CAAC,CAAC;QACf,0BAAqB,GAAG,EAAE,CAAC,CAAC,yCAAyC;QACrE,sBAAiB,GAAG,IAAI,CAAC,CAAC,sCAAsC;QAG/E,IAAI,CAAC,aAAa,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC;QAChE,IAAI,CAAC,aAAa,GAAG,IAAI,aAAa,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;QAClE,IAAI,CAAC,OAAO,GAAG,IAAI,aAAa,EAAE,CAAC,CAAC,kDAAkD;IACxF,CAAC;IAES,KAAK,CAAC,YAAY,CAC1B,MAAc,EACd,IAAY,EACZ,QAAgB,EAChB,OAAgB;QAEhB,sEAAsE;QACtE,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAC3B,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,CAC3B,IAAI,CAAC,iBAAiB,EACtB,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,qBAAqB,CACtD,CAAC;QAEF,MAAM,IAAI,CAAC,aAAa,CAAC,kBAAkB,CAAC;YAC1C,MAAM;YACN,MAAM,EAAE,aAAa;YACrB,IAAI;YACJ,QA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K,CAAC,IAAI,EAAE,UAAU,EAAE,CAC1F,CAAC;gBACJ,CAAC;gBAED,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;oBAC3B,QAAQ,GAAG,IAAI,CAAC;oBAChB,YAAY,GAAG,KAAK,CAAC,IAAI,EAAE,OAAO,IAAI,eAAe,CAAC;oBACtD,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC,MAAM,UAAU,EAAE,YAAY,CAAC,CAAC;gBAC5D,CAAC;YACH,CAAC,CAAC,CAAC;YAEH,2BAA2B;YAC3B,MAAM,OAAO,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;YAEtC,IAAI,QAAQ,EAAE,CAAC;gBACb,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,YAAY;oBACnB,MAAM;iBACP,CAAC;YACJ,CAAC;YAED,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,MAAM;gBACN,OAAO,EAAE,iCAAiC;aAC3C,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,QAAQ,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACxE,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,QAAQ;aAChB,CAAC;QACJ,CAAC;IACH,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,OAAwB;QACpC,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IACjE,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ import { WorkflowExecutor, WorkflowContext, WorkflowResult } from "./base.js";
2
+ export declare class ExplainWorkflow extends WorkflowExecutor {
3
+ execute(context: WorkflowContext): Promise<WorkflowResult>;
4
+ }
5
+ //# sourceMappingURL=explain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"explain.d.ts","sourceRoot":"","sources":["../../../src/copilot/flows/explain.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE9E,qBAAa,eAAgB,SAAQ,gBAAgB;IAC7C,OAAO,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;CAuFjE"}
@@ -0,0 +1,76 @@
1
+ // Code Explanation Workflow
2
+ // Explains code, architecture, or specific features
3
+ import { WorkflowExecutor } from "./base.js";
4
+ export class ExplainWorkflow extends WorkflowExecutor {
5
+ async execute(context) {
6
+ try {
7
+ await this.sendProgress(context.taskId, "Starting code explanation workflow", 0.05);
8
+ const systemPrompt = `You are Devflow, an expert code explanation assistant.
9
+
10
+ Your task: Provide clear, comprehensive explanations of code, architecture, or features.
11
+ Repository: ${context.repo}
12
+ Request: ${context.naturalLanguage}
13
+
14
+ You have access to these tools:
15
+ - git_operations: Clone repositories
16
+ - read_file: Read source code files
17
+ - list_files: List files in the repository
18
+ - send_progress_update: Send updates to the user
19
+
20
+ IMPORTANT:
21
+ 1. Clone the repository first
22
+ 2. Examine the relevant code files
23
+ 3. Provide clear, well-structured explanations
24
+ 4. Include code examples where helpful
25
+ 5. Explain design patterns and architectural decisions
26
+ 6. Mention dependencies and how they're used
27
+ 7. Send progress updates as you explore
28
+ `;
29
+ const userPrompt = `
30
+ Please explain the following:
31
+
32
+ ${context.naturalLanguage}
33
+
34
+ ${context.context?.files ? `Focus on these files:\n${context.context.files}` : ""}
35
+ ${context.context?.focusArea ? `Focus area: ${context.context.focusArea}` : ""}
36
+
37
+ Follow these steps:
38
+ 1. Clone the repository
39
+ 2. List the directory structure to understand the layout
40
+ 3. Identify the relevant files for this explanation
41
+ 4. Read and analyze the code
42
+ 5. Provide a comprehensive explanation that includes:
43
+ - What the code does
44
+ - How it works
45
+ - Key components and their relationships
46
+ - Important design decisions
47
+ - Dependencies and external integrations
48
+ - Examples of usage
49
+ 6. Send a progress update with the complete explanation
50
+
51
+ Format your explanation clearly with:
52
+ - Headings for different sections
53
+ - Code snippets for important parts
54
+ - Clear descriptions of flow and logic
55
+ - Diagrams or ASCII art if helpful (use markdown code blocks)
56
+ `;
57
+ const result = await this.executeWorkflow(`${systemPrompt}\n\n${userPrompt}`, context);
58
+ if (result.success) {
59
+ await this.sendProgress(context.taskId, "Explanation complete", 1.0, "Code explanation has been prepared and sent");
60
+ }
61
+ return result;
62
+ }
63
+ catch (error) {
64
+ const errorMsg = error instanceof Error ? error.message : String(error);
65
+ await this.sendCompletion(context.taskId, {
66
+ success: false,
67
+ error: errorMsg,
68
+ });
69
+ return {
70
+ success: false,
71
+ error: errorMsg,
72
+ };
73
+ }
74
+ }
75
+ }
76
+ //# sourceMappingURL=explain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"explain.js","sourceRoot":"","sources":["../../../src/copilot/flows/explain.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,oDAAoD;AACpD,OAAO,EAAE,gBAAgB,EAAmC,MAAM,WAAW,CAAC;AAE9E,MAAM,OAAO,eAAgB,SAAQ,gBAAgB;IACnD,KAAK,CAAC,OAAO,CAAC,OAAwB;QACpC,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,YAAY,CACrB,OAAO,CAAC,MAAM,EACd,oCAAoC,EACpC,IAAI,CACL,CAAC;YAEF,MAAM,YAAY,GAAG;;;cAGb,OAAO,CAAC,IAAI;WACf,OAAO,CAAC,eAAe;;;;;;;;;;;;;;;;CAgBjC,CAAC;YAEI,MAAM,UAAU,GAAG;;;EAGvB,OAAO,CAAC,eAAe;;EAEvB,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,0BAA0B,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE;EAC/E,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,eAAe,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE;;;;;;;;;;;;;;;;;;;;;CAqB7E,CAAC;YAEI,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,eAAe,CACvC,GAAG,YAAY,OAAO,UAAU,EAAE,EAClC,OAAO,CACR,CAAC;YAEF,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;gBACnB,MAAM,IAAI,CAAC,YAAY,CACrB,OAAO,CAAC,MAAM,EACd,sBAAsB,EACtB,GAAG,EACH,6CAA6C,CAC9C,CAAC;YACJ,CAAC;YAED,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,QAAQ,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACxE,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,EAAE;gBACxC,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,QAAQ;aAChB,CAAC,CAAC;YAEH,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,QAAQ;aAChB,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ import { WorkflowExecutor, WorkflowContext, WorkflowResult } from "./base.js";
2
+ export declare class FeatureWorkflow extends WorkflowExecutor {
3
+ execute(context: WorkflowContext): Promise<WorkflowResult>;
4
+ }
5
+ //# sourceMappingURL=feature.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature.d.ts","sourceRoot":"","sources":["../../../src/copilot/flows/feature.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE9E,qBAAa,eAAgB,SAAQ,gBAAgB;IAC7C,OAAO,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;CAgGjE"}