@polka-codes/cli 0.10.23 ā 0.10.24
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.
- package/dist/index.js +1 -1
- package/package.json +3 -3
- package/dist/ApiProviderConfig.js +0 -57
- package/dist/ApiProviderConfig.js.map +0 -1
- package/dist/ApiProviderConfig.test.js +0 -278
- package/dist/ApiProviderConfig.test.js.map +0 -1
- package/dist/agent/advanced-discovery.js +0 -604
- package/dist/agent/advanced-discovery.js.map +0 -1
- package/dist/agent/config.js +0 -139
- package/dist/agent/config.js.map +0 -1
- package/dist/agent/config.test.js +0 -140
- package/dist/agent/config.test.js.map +0 -1
- package/dist/agent/constants.js +0 -172
- package/dist/agent/constants.js.map +0 -1
- package/dist/agent/constants.test.js +0 -132
- package/dist/agent/constants.test.js.map +0 -1
- package/dist/agent/debug-logger.js +0 -281
- package/dist/agent/debug-logger.js.map +0 -1
- package/dist/agent/debug-logger.test.js +0 -294
- package/dist/agent/debug-logger.test.js.map +0 -1
- package/dist/agent/error-handling.js +0 -114
- package/dist/agent/error-handling.js.map +0 -1
- package/dist/agent/error-handling.test.js +0 -191
- package/dist/agent/error-handling.test.js.map +0 -1
- package/dist/agent/errors.js +0 -301
- package/dist/agent/errors.js.map +0 -1
- package/dist/agent/executor.js +0 -206
- package/dist/agent/executor.js.map +0 -1
- package/dist/agent/executor.test.js +0 -228
- package/dist/agent/executor.test.js.map +0 -1
- package/dist/agent/goal-decomposer.js +0 -281
- package/dist/agent/goal-decomposer.js.map +0 -1
- package/dist/agent/goal-decomposer.test.js +0 -225
- package/dist/agent/goal-decomposer.test.js.map +0 -1
- package/dist/agent/health-monitor.js +0 -89
- package/dist/agent/health-monitor.js.map +0 -1
- package/dist/agent/improvement-loop.js +0 -177
- package/dist/agent/improvement-loop.js.map +0 -1
- package/dist/agent/index.js +0 -38
- package/dist/agent/index.js.map +0 -1
- package/dist/agent/metrics.js +0 -158
- package/dist/agent/metrics.js.map +0 -1
- package/dist/agent/metrics.test.js +0 -311
- package/dist/agent/metrics.test.js.map +0 -1
- package/dist/agent/orchestrator.js +0 -438
- package/dist/agent/orchestrator.js.map +0 -1
- package/dist/agent/planner.js +0 -199
- package/dist/agent/planner.js.map +0 -1
- package/dist/agent/planner.test.js +0 -135
- package/dist/agent/planner.test.js.map +0 -1
- package/dist/agent/progress.js +0 -298
- package/dist/agent/progress.js.map +0 -1
- package/dist/agent/progress.test.js +0 -255
- package/dist/agent/progress.test.js.map +0 -1
- package/dist/agent/resource-monitor.js +0 -114
- package/dist/agent/resource-monitor.js.map +0 -1
- package/dist/agent/safety/approval.js +0 -178
- package/dist/agent/safety/approval.js.map +0 -1
- package/dist/agent/safety/approval.test.js +0 -142
- package/dist/agent/safety/approval.test.js.map +0 -1
- package/dist/agent/safety/checks.js +0 -152
- package/dist/agent/safety/checks.js.map +0 -1
- package/dist/agent/safety/checks.test.js +0 -89
- package/dist/agent/safety/checks.test.js.map +0 -1
- package/dist/agent/safety/interrupt.js +0 -92
- package/dist/agent/safety/interrupt.js.map +0 -1
- package/dist/agent/safety/interrupt.test.js +0 -53
- package/dist/agent/safety/interrupt.test.js.map +0 -1
- package/dist/agent/session.js +0 -117
- package/dist/agent/session.js.map +0 -1
- package/dist/agent/session.test.js +0 -213
- package/dist/agent/session.test.js.map +0 -1
- package/dist/agent/state-manager.js +0 -287
- package/dist/agent/state-manager.js.map +0 -1
- package/dist/agent/task-discovery.js +0 -433
- package/dist/agent/task-discovery.js.map +0 -1
- package/dist/agent/task-discovery.test.js +0 -40
- package/dist/agent/task-discovery.test.js.map +0 -1
- package/dist/agent/task-history.js +0 -128
- package/dist/agent/task-history.js.map +0 -1
- package/dist/agent/task-prioritizer.js +0 -286
- package/dist/agent/task-prioritizer.js.map +0 -1
- package/dist/agent/test-fixtures.js +0 -112
- package/dist/agent/test-fixtures.js.map +0 -1
- package/dist/agent/types.js +0 -15
- package/dist/agent/types.js.map +0 -1
- package/dist/agent/workflow-adapter.js +0 -219
- package/dist/agent/workflow-adapter.js.map +0 -1
- package/dist/agent/workflow-adapter.test.js +0 -11
- package/dist/agent/workflow-adapter.test.js.map +0 -1
- package/dist/agent/working-dir-discovery.js +0 -54
- package/dist/agent/working-dir-discovery.js.map +0 -1
- package/dist/agent/working-space.js +0 -484
- package/dist/agent/working-space.js.map +0 -1
- package/dist/agent/working-space.test.js +0 -436
- package/dist/agent/working-space.test.js.map +0 -1
- package/dist/api.js +0 -279
- package/dist/api.js.map +0 -1
- package/dist/builtin-commands.js +0 -20
- package/dist/builtin-commands.js.map +0 -1
- package/dist/commandSummarizer.js +0 -96
- package/dist/commandSummarizer.js.map +0 -1
- package/dist/commands/__tests__/command-detection.integration.test.js +0 -238
- package/dist/commands/__tests__/command-detection.integration.test.js.map +0 -1
- package/dist/commands/__tests__/script-generator.integration.test.js +0 -271
- package/dist/commands/__tests__/script-generator.integration.test.js.map +0 -1
- package/dist/commands/agent.js +0 -218
- package/dist/commands/agent.js.map +0 -1
- package/dist/commands/code.js +0 -102
- package/dist/commands/code.js.map +0 -1
- package/dist/commands/command.constants.js +0 -13
- package/dist/commands/command.constants.js.map +0 -1
- package/dist/commands/commit.js +0 -17
- package/dist/commands/commit.js.map +0 -1
- package/dist/commands/fix.js +0 -17
- package/dist/commands/fix.js.map +0 -1
- package/dist/commands/init.js +0 -501
- package/dist/commands/init.js.map +0 -1
- package/dist/commands/mcp-server.js +0 -122
- package/dist/commands/mcp-server.js.map +0 -1
- package/dist/commands/memory.js +0 -410
- package/dist/commands/memory.js.map +0 -1
- package/dist/commands/memory.test.js +0 -453
- package/dist/commands/memory.test.js.map +0 -1
- package/dist/commands/meta.js +0 -142
- package/dist/commands/meta.js.map +0 -1
- package/dist/commands/plan.js +0 -39
- package/dist/commands/plan.js.map +0 -1
- package/dist/commands/pr.js +0 -14
- package/dist/commands/pr.js.map +0 -1
- package/dist/commands/review-json.test.js +0 -33
- package/dist/commands/review-json.test.js.map +0 -1
- package/dist/commands/review.js +0 -137
- package/dist/commands/review.js.map +0 -1
- package/dist/commands/review.usage.test.js +0 -41
- package/dist/commands/review.usage.test.js.map +0 -1
- package/dist/commands/run.js +0 -107
- package/dist/commands/run.js.map +0 -1
- package/dist/commands/skills.js +0 -175
- package/dist/commands/skills.js.map +0 -1
- package/dist/commands/task.js +0 -34
- package/dist/commands/task.js.map +0 -1
- package/dist/commands/workflow.js +0 -117
- package/dist/commands/workflow.js.map +0 -1
- package/dist/configPrompt.js +0 -39
- package/dist/configPrompt.js.map +0 -1
- package/dist/env.js +0 -22
- package/dist/env.js.map +0 -1
- package/dist/errors.js +0 -132
- package/dist/errors.js.map +0 -1
- package/dist/errors.test.js +0 -21
- package/dist/errors.test.js.map +0 -1
- package/dist/file-attachments.js +0 -77
- package/dist/file-attachments.js.map +0 -1
- package/dist/file-attachments.test.js +0 -214
- package/dist/file-attachments.test.js.map +0 -1
- package/dist/getModel.js +0 -229
- package/dist/getModel.js.map +0 -1
- package/dist/getModel.test.js +0 -67
- package/dist/getModel.test.js.map +0 -1
- package/dist/getProviderOptions.js +0 -58
- package/dist/getProviderOptions.js.map +0 -1
- package/dist/git-operations.js +0 -363
- package/dist/git-operations.js.map +0 -1
- package/dist/git-operations.test.js +0 -81
- package/dist/git-operations.test.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/logger.js +0 -41
- package/dist/logger.js.map +0 -1
- package/dist/mcp/client.js +0 -11
- package/dist/mcp/client.js.map +0 -1
- package/dist/mcp/error-scenarios.test.js +0 -206
- package/dist/mcp/error-scenarios.test.js.map +0 -1
- package/dist/mcp/errors.js +0 -63
- package/dist/mcp/errors.js.map +0 -1
- package/dist/mcp/index.js +0 -9
- package/dist/mcp/index.js.map +0 -1
- package/dist/mcp/manager.js +0 -231
- package/dist/mcp/manager.js.map +0 -1
- package/dist/mcp/manager.test.js +0 -40
- package/dist/mcp/manager.test.js.map +0 -1
- package/dist/mcp/sdk-client.js +0 -166
- package/dist/mcp/sdk-client.js.map +0 -1
- package/dist/mcp/shared-types.js +0 -3
- package/dist/mcp/shared-types.js.map +0 -1
- package/dist/mcp/tools-integration.test.js +0 -198
- package/dist/mcp/tools-integration.test.js.map +0 -1
- package/dist/mcp/tools.js +0 -60
- package/dist/mcp/tools.js.map +0 -1
- package/dist/mcp/transport.js +0 -257
- package/dist/mcp/transport.js.map +0 -1
- package/dist/mcp/types.js +0 -3
- package/dist/mcp/types.js.map +0 -1
- package/dist/mcp-server/index.js +0 -5
- package/dist/mcp-server/index.js.map +0 -1
- package/dist/mcp-server/plan-formatting.test.js +0 -74
- package/dist/mcp-server/plan-formatting.test.js.map +0 -1
- package/dist/mcp-server/sdk-server.js +0 -102
- package/dist/mcp-server/sdk-server.js.map +0 -1
- package/dist/mcp-server/sdk-server.test.js +0 -363
- package/dist/mcp-server/sdk-server.test.js.map +0 -1
- package/dist/mcp-server/tools.js +0 -785
- package/dist/mcp-server/tools.js.map +0 -1
- package/dist/mcp-server/types.js +0 -3
- package/dist/mcp-server/types.js.map +0 -1
- package/dist/options.js +0 -85
- package/dist/options.js.map +0 -1
- package/dist/options.test.js +0 -177
- package/dist/options.test.js.map +0 -1
- package/dist/prices.js +0 -61
- package/dist/prices.js.map +0 -1
- package/dist/prices.test.js +0 -148
- package/dist/prices.test.js.map +0 -1
- package/dist/runWorkflow.js +0 -313
- package/dist/runWorkflow.js.map +0 -1
- package/dist/script/__tests__/execution.integration.test.js +0 -274
- package/dist/script/__tests__/execution.integration.test.js.map +0 -1
- package/dist/script/__tests__/runner.test.js +0 -176
- package/dist/script/__tests__/runner.test.js.map +0 -1
- package/dist/script/__tests__/validator.test.js +0 -180
- package/dist/script/__tests__/validator.test.js.map +0 -1
- package/dist/script/executor.js +0 -127
- package/dist/script/executor.js.map +0 -1
- package/dist/script/index.js +0 -4
- package/dist/script/index.js.map +0 -1
- package/dist/script/runner.js +0 -258
- package/dist/script/runner.js.map +0 -1
- package/dist/skillIntegration.js +0 -46
- package/dist/skillIntegration.js.map +0 -1
- package/dist/skillIntegration.test.js +0 -128
- package/dist/skillIntegration.test.js.map +0 -1
- package/dist/test/utils.js +0 -200
- package/dist/test/utils.js.map +0 -1
- package/dist/test/workflow-fixtures.js +0 -120
- package/dist/test/workflow-fixtures.js.map +0 -1
- package/dist/tool-implementations.js +0 -521
- package/dist/tool-implementations.js.map +0 -1
- package/dist/tool-implementations.skill-tools.test.js +0 -106
- package/dist/tool-implementations.skill-tools.test.js.map +0 -1
- package/dist/tools/getTodoItem.js +0 -33
- package/dist/tools/getTodoItem.js.map +0 -1
- package/dist/tools/gitDiff.js +0 -108
- package/dist/tools/gitDiff.js.map +0 -1
- package/dist/tools/index.js +0 -8
- package/dist/tools/index.js.map +0 -1
- package/dist/tools/listMemoryTopics.js +0 -24
- package/dist/tools/listMemoryTopics.js.map +0 -1
- package/dist/tools/listTodoItems.js +0 -35
- package/dist/tools/listTodoItems.js.map +0 -1
- package/dist/tools/listTodoItems.test.js +0 -89
- package/dist/tools/listTodoItems.test.js.map +0 -1
- package/dist/tools/readMemory.js +0 -33
- package/dist/tools/readMemory.js.map +0 -1
- package/dist/tools/updateMemory.js +0 -62
- package/dist/tools/updateMemory.js.map +0 -1
- package/dist/tools/updateMemory.test.js +0 -109
- package/dist/tools/updateMemory.test.js.map +0 -1
- package/dist/tools/updateTodoItem.js +0 -31
- package/dist/tools/updateTodoItem.js.map +0 -1
- package/dist/tools/utils/diffLineNumbers.js +0 -178
- package/dist/tools/utils/diffLineNumbers.js.map +0 -1
- package/dist/utils/cacheControl.js +0 -59
- package/dist/utils/cacheControl.js.map +0 -1
- package/dist/utils/cacheControl.test.js +0 -128
- package/dist/utils/cacheControl.test.js.map +0 -1
- package/dist/utils/command.js +0 -50
- package/dist/utils/command.js.map +0 -1
- package/dist/utils/shell.js +0 -56
- package/dist/utils/shell.js.map +0 -1
- package/dist/utils/userInput.js +0 -47
- package/dist/utils/userInput.js.map +0 -1
- package/dist/workflow-tools.js +0 -21
- package/dist/workflow-tools.js.map +0 -1
- package/dist/workflows/agent-builder.js +0 -90
- package/dist/workflows/agent-builder.js.map +0 -1
- package/dist/workflows/agent-builder.test.js +0 -115
- package/dist/workflows/agent-builder.test.js.map +0 -1
- package/dist/workflows/code.workflow.js +0 -145
- package/dist/workflows/code.workflow.js.map +0 -1
- package/dist/workflows/commit.workflow.js +0 -111
- package/dist/workflows/commit.workflow.js.map +0 -1
- package/dist/workflows/commit.workflow.test.js +0 -141
- package/dist/workflows/commit.workflow.test.js.map +0 -1
- package/dist/workflows/fix.workflow.js +0 -172
- package/dist/workflows/fix.workflow.js.map +0 -1
- package/dist/workflows/fix.workflow.test.js +0 -137
- package/dist/workflows/fix.workflow.test.js.map +0 -1
- package/dist/workflows/git-file-tools.js +0 -408
- package/dist/workflows/git-file-tools.js.map +0 -1
- package/dist/workflows/index.js +0 -12
- package/dist/workflows/index.js.map +0 -1
- package/dist/workflows/init-interactive.workflow.js +0 -198
- package/dist/workflows/init-interactive.workflow.js.map +0 -1
- package/dist/workflows/init.workflow.js +0 -41
- package/dist/workflows/init.workflow.js.map +0 -1
- package/dist/workflows/meta.workflow.js +0 -107
- package/dist/workflows/meta.workflow.js.map +0 -1
- package/dist/workflows/plan.workflow.js +0 -275
- package/dist/workflows/plan.workflow.js.map +0 -1
- package/dist/workflows/plan.workflow.test.js +0 -419
- package/dist/workflows/plan.workflow.test.js.map +0 -1
- package/dist/workflows/pr.workflow.js +0 -54
- package/dist/workflows/pr.workflow.js.map +0 -1
- package/dist/workflows/pr.workflow.test.js +0 -98
- package/dist/workflows/pr.workflow.test.js.map +0 -1
- package/dist/workflows/prompts/coder.js +0 -85
- package/dist/workflows/prompts/coder.js.map +0 -1
- package/dist/workflows/prompts/commit.js +0 -16
- package/dist/workflows/prompts/commit.js.map +0 -1
- package/dist/workflows/prompts/fix.js +0 -44
- package/dist/workflows/prompts/fix.js.map +0 -1
- package/dist/workflows/prompts/index.js +0 -10
- package/dist/workflows/prompts/index.js.map +0 -1
- package/dist/workflows/prompts/init.js +0 -48
- package/dist/workflows/prompts/init.js.map +0 -1
- package/dist/workflows/prompts/meta.js +0 -17
- package/dist/workflows/prompts/meta.js.map +0 -1
- package/dist/workflows/prompts/plan.js +0 -212
- package/dist/workflows/prompts/plan.js.map +0 -1
- package/dist/workflows/prompts/pr.js +0 -15
- package/dist/workflows/prompts/pr.js.map +0 -1
- package/dist/workflows/prompts/review.js +0 -145
- package/dist/workflows/prompts/review.js.map +0 -1
- package/dist/workflows/prompts/shared.js +0 -93
- package/dist/workflows/prompts/shared.js.map +0 -1
- package/dist/workflows/review.workflow.js +0 -357
- package/dist/workflows/review.workflow.js.map +0 -1
- package/dist/workflows/task.workflow.js +0 -47
- package/dist/workflows/task.workflow.js.map +0 -1
- package/dist/workflows/testing/helper.js +0 -41
- package/dist/workflows/testing/helper.js.map +0 -1
- package/dist/workflows/workflow.utils.js +0 -351
- package/dist/workflows/workflow.utils.js.map +0 -1
- package/dist/workflows/workflow.utils.test.js +0 -45
- package/dist/workflows/workflow.utils.test.js.map +0 -1
|
@@ -1,408 +0,0 @@
|
|
|
1
|
-
// generated by polka.codes
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { annotateDiffWithLineNumbers } from '../tools/utils/diffLineNumbers';
|
|
4
|
-
import { quoteForShell } from '../utils/shell';
|
|
5
|
-
function getMediaType(path) {
|
|
6
|
-
// Use lastIndexOf to handle paths with dots, and basename to handle dotfiles correctly
|
|
7
|
-
const lastDotIndex = path.lastIndexOf('.');
|
|
8
|
-
const ext = lastDotIndex > 0 && lastDotIndex < path.length - 1 ? path.slice(lastDotIndex + 1).toLowerCase() : undefined;
|
|
9
|
-
const mediaTypes = {
|
|
10
|
-
// Images
|
|
11
|
-
png: 'image/png',
|
|
12
|
-
jpg: 'image/jpeg',
|
|
13
|
-
jpeg: 'image/jpeg',
|
|
14
|
-
gif: 'image/gif',
|
|
15
|
-
svg: 'image/svg+xml',
|
|
16
|
-
webp: 'image/webp',
|
|
17
|
-
ico: 'image/x-icon',
|
|
18
|
-
bmp: 'image/bmp',
|
|
19
|
-
// Fonts
|
|
20
|
-
woff: 'font/woff',
|
|
21
|
-
woff2: 'font/woff2',
|
|
22
|
-
ttf: 'font/ttf',
|
|
23
|
-
otf: 'font/otf',
|
|
24
|
-
eot: 'application/vnd.ms-fontobject',
|
|
25
|
-
// Documents
|
|
26
|
-
pdf: 'application/pdf',
|
|
27
|
-
// Audio
|
|
28
|
-
mp3: 'audio/mpeg',
|
|
29
|
-
wav: 'audio/wav',
|
|
30
|
-
ogg: 'audio/ogg',
|
|
31
|
-
// Video
|
|
32
|
-
mp4: 'video/mp4',
|
|
33
|
-
webm: 'video/webm',
|
|
34
|
-
avi: 'video/x-msvideo',
|
|
35
|
-
};
|
|
36
|
-
return mediaTypes[ext || ''] || 'application/octet-stream';
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Helper to extract the target commit from a git range
|
|
40
|
-
* For ranges like "A..B", "A...B", or "HEAD~3..HEAD", returns B
|
|
41
|
-
* For single commit, returns the commit
|
|
42
|
-
* For local changes, returns null
|
|
43
|
-
*/
|
|
44
|
-
export function extractTargetCommit(range, pr) {
|
|
45
|
-
// PR reviews checkout the branch, so working directory is correct
|
|
46
|
-
if (pr) {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
// No range or empty range means local changes, use working directory
|
|
50
|
-
if (!range || range.trim() === '') {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
// Parse the range to extract the target commit
|
|
54
|
-
// Supports formats: "A..B", "A...B", "commit", "HEAD~3", etc.
|
|
55
|
-
const parts = range.split(/\.\.\.?/);
|
|
56
|
-
if (parts.length > 1) {
|
|
57
|
-
// Range format: "A..B" or "A...B"
|
|
58
|
-
// The second part is the target commit (B)
|
|
59
|
-
return parts[1].trim() || null;
|
|
60
|
-
}
|
|
61
|
-
// Single commit reference
|
|
62
|
-
const trimmed = range.trim();
|
|
63
|
-
return trimmed || null;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Create git-aware version of readFile that reads from a specific commit
|
|
67
|
-
*/
|
|
68
|
-
export function createGitReadFile(commit) {
|
|
69
|
-
const toolInfo = {
|
|
70
|
-
name: 'readFile',
|
|
71
|
-
description: `Read file contents from git commit ${commit}. Use this to examine files at the specific commit being reviewed.`,
|
|
72
|
-
parameters: z
|
|
73
|
-
.object({
|
|
74
|
-
path: z
|
|
75
|
-
.preprocess((val) => {
|
|
76
|
-
if (!val)
|
|
77
|
-
return [];
|
|
78
|
-
const values = Array.isArray(val) ? val : [val];
|
|
79
|
-
// NOTE: Comma-splitting matches standard readFile tool behavior
|
|
80
|
-
// This prevents reading files with commas in their names, but allows
|
|
81
|
-
// reading multiple files in a single call (e.g., "file1.ts,file2.ts")
|
|
82
|
-
return values.flatMap((i) => (typeof i === 'string' ? i.split(',') : [])).filter((s) => s.length > 0);
|
|
83
|
-
}, z.array(z.string()))
|
|
84
|
-
.describe('The path of the file to read (relative to git root)')
|
|
85
|
-
.meta({ usageValue: 'Comma separated paths here' }),
|
|
86
|
-
})
|
|
87
|
-
.meta({
|
|
88
|
-
examples: [
|
|
89
|
-
{
|
|
90
|
-
description: 'Read the contents of a file at the commit',
|
|
91
|
-
input: {
|
|
92
|
-
path: 'src/main.ts',
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
],
|
|
96
|
-
}),
|
|
97
|
-
};
|
|
98
|
-
const handler = async (provider, args) => {
|
|
99
|
-
if (!provider.executeCommand) {
|
|
100
|
-
return {
|
|
101
|
-
success: false,
|
|
102
|
-
message: {
|
|
103
|
-
type: 'error-text',
|
|
104
|
-
value: 'Not possible to execute command.',
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
const { path: paths } = toolInfo.parameters.parse(args);
|
|
109
|
-
const results = [];
|
|
110
|
-
for (const filePath of paths) {
|
|
111
|
-
// SECURITY: Use quoteForShell to prevent command injection
|
|
112
|
-
// Both commit and filePath could contain shell metacharacters
|
|
113
|
-
const quotedCommit = quoteForShell(commit);
|
|
114
|
-
const quotedPath = quoteForShell(filePath);
|
|
115
|
-
const result = await provider.executeCommand(`git show ${quotedCommit}:${quotedPath}`, false);
|
|
116
|
-
if (result.exitCode === 0) {
|
|
117
|
-
results.push(`<read_file_file_content path="${filePath}">${result.stdout}</read_file_file_content>`);
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
// File not found or doesn't exist at this commit
|
|
121
|
-
results.push(`<read_file_file_content path="${filePath}" file_not_found="true"></read_file_file_content>`);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return {
|
|
125
|
-
success: true,
|
|
126
|
-
message: {
|
|
127
|
-
type: 'text',
|
|
128
|
-
value: results.join('\n'),
|
|
129
|
-
},
|
|
130
|
-
};
|
|
131
|
-
};
|
|
132
|
-
return {
|
|
133
|
-
...toolInfo,
|
|
134
|
-
handler,
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Create git-aware version of listFiles that lists files at a specific commit
|
|
139
|
-
*/
|
|
140
|
-
export function createGitListFiles(commit) {
|
|
141
|
-
const toolInfo = {
|
|
142
|
-
name: 'listFiles',
|
|
143
|
-
description: `List files and directories at git commit ${commit}. Shows the file tree as it existed at that commit.`,
|
|
144
|
-
parameters: z.object({
|
|
145
|
-
path: z
|
|
146
|
-
.string()
|
|
147
|
-
.optional()
|
|
148
|
-
.describe('The path of the directory to list (relative to git root). Default is root.')
|
|
149
|
-
.meta({ usageValue: 'Directory path here (optional)' }),
|
|
150
|
-
maxCount: z.coerce
|
|
151
|
-
.number()
|
|
152
|
-
.optional()
|
|
153
|
-
.default(2000)
|
|
154
|
-
.describe('The maximum number of files to list. Default to 2000')
|
|
155
|
-
.meta({ usageValue: 'Maximum number of files to list (optional)' }),
|
|
156
|
-
}),
|
|
157
|
-
};
|
|
158
|
-
const handler = async (provider, args) => {
|
|
159
|
-
if (!provider.executeCommand) {
|
|
160
|
-
return {
|
|
161
|
-
success: false,
|
|
162
|
-
message: {
|
|
163
|
-
type: 'error-text',
|
|
164
|
-
value: 'Not possible to execute command.',
|
|
165
|
-
},
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
// Parse with fallback for empty string to '.'
|
|
169
|
-
const parsed = toolInfo.parameters.parse(args);
|
|
170
|
-
const path = parsed.path || '.';
|
|
171
|
-
// SECURITY: Use quoteForShell to prevent command injection
|
|
172
|
-
const quotedCommit = quoteForShell(commit);
|
|
173
|
-
const quotedPath = quoteForShell(path);
|
|
174
|
-
// Use git ls-tree to list files at the specific commit
|
|
175
|
-
const result = await provider.executeCommand(`git ls-tree -r --name-only ${quotedCommit} ${quotedPath}`, false);
|
|
176
|
-
if (result.exitCode !== 0) {
|
|
177
|
-
return {
|
|
178
|
-
success: false,
|
|
179
|
-
message: {
|
|
180
|
-
type: 'error-text',
|
|
181
|
-
value: `Failed to list files at commit ${commit}: ${result.stderr}`,
|
|
182
|
-
},
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
const files = result.stdout
|
|
186
|
-
.trim()
|
|
187
|
-
.split('\n')
|
|
188
|
-
.filter((f) => f.length > 0);
|
|
189
|
-
const truncated = files.length > parsed.maxCount;
|
|
190
|
-
const displayFiles = truncated ? files.slice(0, parsed.maxCount) : files;
|
|
191
|
-
return {
|
|
192
|
-
success: true,
|
|
193
|
-
message: {
|
|
194
|
-
type: 'text',
|
|
195
|
-
value: `<list_files_path>${path}</list_files_path>
|
|
196
|
-
<list_files_files>
|
|
197
|
-
${displayFiles.join('\n')}
|
|
198
|
-
</list_files_files>
|
|
199
|
-
<list_files_truncated>${truncated}</list_files_truncated>`,
|
|
200
|
-
},
|
|
201
|
-
};
|
|
202
|
-
};
|
|
203
|
-
return {
|
|
204
|
-
...toolInfo,
|
|
205
|
-
handler,
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Create git-aware version of readBinaryFile that reads binary files at a specific commit
|
|
210
|
-
*/
|
|
211
|
-
export function createGitReadBinaryFile(commit) {
|
|
212
|
-
const toolInfo = {
|
|
213
|
-
name: 'readBinaryFile',
|
|
214
|
-
description: `Read binary file contents from git commit ${commit} and return as base64 encoded data. Use for images, fonts, and other binary files.`,
|
|
215
|
-
parameters: z.object({
|
|
216
|
-
url: z.string().describe('The URL or path of the binary file to read (relative to git root)'),
|
|
217
|
-
}),
|
|
218
|
-
};
|
|
219
|
-
const handler = async (provider, args) => {
|
|
220
|
-
if (!provider.executeCommand) {
|
|
221
|
-
return {
|
|
222
|
-
success: false,
|
|
223
|
-
message: {
|
|
224
|
-
type: 'error-text',
|
|
225
|
-
value: 'Not possible to execute command.',
|
|
226
|
-
},
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
const { url } = toolInfo.parameters.parse(args);
|
|
230
|
-
// SECURITY: Use quoteForShell to prevent command injection
|
|
231
|
-
const quotedCommit = quoteForShell(commit);
|
|
232
|
-
const quotedUrl = quoteForShell(url);
|
|
233
|
-
// First verify the file exists at the commit to avoid pipe masking errors
|
|
234
|
-
const checkResult = await provider.executeCommand(`git cat-file -e ${quotedCommit}:${quotedUrl}`, false);
|
|
235
|
-
if (checkResult.exitCode !== 0) {
|
|
236
|
-
return {
|
|
237
|
-
success: true,
|
|
238
|
-
message: {
|
|
239
|
-
type: 'text',
|
|
240
|
-
value: `<read_binary_file_file_content url="${url}" file_not_found="true"></read_binary_file_file_content>`,
|
|
241
|
-
},
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
// File exists, read it and encode as base64
|
|
245
|
-
// Use git show piped to base64 for cross-platform binary file handling
|
|
246
|
-
// Windows: requires Git Bash or Unix tools in PATH (base64 command)
|
|
247
|
-
// Unix: always available
|
|
248
|
-
// Note: On Windows without Git Bash, this will fail with a clear error
|
|
249
|
-
const isWindows = process.platform === 'win32';
|
|
250
|
-
const command = isWindows
|
|
251
|
-
? `cmd /c "git show ${quotedCommit}:${quotedUrl} | base64 -w 0"`
|
|
252
|
-
: `sh -c "git show ${quotedCommit}:${quotedUrl} | base64"`;
|
|
253
|
-
const result = await provider.executeCommand(command, false);
|
|
254
|
-
if (result.exitCode === 0) {
|
|
255
|
-
// The output is base64-encoded text, remove any newlines for consistent output
|
|
256
|
-
// Unix base64 wraps at 76 chars by default, Windows with -w 0 doesn't wrap
|
|
257
|
-
const base64Data = result.stdout.replace(/\n/g, '');
|
|
258
|
-
return {
|
|
259
|
-
success: true,
|
|
260
|
-
message: {
|
|
261
|
-
type: 'content',
|
|
262
|
-
value: [
|
|
263
|
-
{
|
|
264
|
-
type: 'media',
|
|
265
|
-
url,
|
|
266
|
-
data: base64Data,
|
|
267
|
-
mediaType: getMediaType(url),
|
|
268
|
-
},
|
|
269
|
-
],
|
|
270
|
-
},
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
else {
|
|
274
|
-
// Provide helpful error message if base64 command is not available
|
|
275
|
-
const isBase64Error = result.stderr.includes('not recognized') || result.stderr.includes('command not found') || result.stderr.includes('base64');
|
|
276
|
-
const errorMessage = isBase64Error
|
|
277
|
-
? `Failed to read binary file: base64 command not found. On Windows, ensure Git Bash or Unix tools are installed and in PATH.`
|
|
278
|
-
: `Failed to read binary file: ${result.stderr}`;
|
|
279
|
-
return {
|
|
280
|
-
success: false,
|
|
281
|
-
message: {
|
|
282
|
-
type: 'error-text',
|
|
283
|
-
value: errorMessage,
|
|
284
|
-
},
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
};
|
|
288
|
-
return {
|
|
289
|
-
...toolInfo,
|
|
290
|
-
handler,
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Create git-aware file tools for reviewing a specific commit
|
|
295
|
-
* Returns wrapped versions of readFile, listFiles, and readBinaryFile
|
|
296
|
-
*/
|
|
297
|
-
export function createGitAwareTools(commit) {
|
|
298
|
-
return {
|
|
299
|
-
readFile: createGitReadFile(commit),
|
|
300
|
-
listFiles: createGitListFiles(commit),
|
|
301
|
-
readBinaryFile: createGitReadBinaryFile(commit),
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* Create git-aware version of gitDiff that shows changes introduced by a specific commit
|
|
306
|
-
* Uses `git show <commit>` to display the diff for that commit
|
|
307
|
-
*/
|
|
308
|
-
export function createGitAwareDiff(commit) {
|
|
309
|
-
const toolInfo = {
|
|
310
|
-
name: 'git_diff',
|
|
311
|
-
description: `Get the git diff for commit ${commit}. Shows the exact changes introduced by this specific commit. Use this to inspect what changed in each file. Always specify a file path.`,
|
|
312
|
-
parameters: z.object({
|
|
313
|
-
file: z
|
|
314
|
-
.string()
|
|
315
|
-
.describe('Get the diff for a specific file within the commit. This parameter is required.')
|
|
316
|
-
.meta({ usageValue: 'File path here (required)' }),
|
|
317
|
-
contextLines: z.coerce
|
|
318
|
-
.number()
|
|
319
|
-
.int()
|
|
320
|
-
.min(0)
|
|
321
|
-
.optional()
|
|
322
|
-
.default(5)
|
|
323
|
-
.describe('Number of context lines to include around changes.')
|
|
324
|
-
.meta({ usageValue: 'Context lines count (optional)' }),
|
|
325
|
-
includeLineNumbers: z
|
|
326
|
-
.preprocess((val) => {
|
|
327
|
-
if (typeof val === 'string') {
|
|
328
|
-
const lower = val.toLowerCase();
|
|
329
|
-
if (lower === 'false')
|
|
330
|
-
return false;
|
|
331
|
-
if (lower === 'true')
|
|
332
|
-
return true;
|
|
333
|
-
}
|
|
334
|
-
return val;
|
|
335
|
-
}, z.boolean().optional().default(true))
|
|
336
|
-
.describe('Annotate the diff with line numbers for additions and deletions.')
|
|
337
|
-
.meta({ usageValue: 'true or false (optional)' }),
|
|
338
|
-
}),
|
|
339
|
-
};
|
|
340
|
-
const handler = async (provider, args) => {
|
|
341
|
-
if (!provider.executeCommand) {
|
|
342
|
-
return {
|
|
343
|
-
success: false,
|
|
344
|
-
message: {
|
|
345
|
-
type: 'error-text',
|
|
346
|
-
value: 'Not possible to execute command.',
|
|
347
|
-
},
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
const { file, contextLines, includeLineNumbers } = toolInfo.parameters.parse(args);
|
|
351
|
-
// SECURITY: Use quoteForShell to prevent command injection
|
|
352
|
-
const quotedCommit = quoteForShell(commit);
|
|
353
|
-
// Build git show command to display commit diff
|
|
354
|
-
// Use --no-color and -U for context lines
|
|
355
|
-
let command = `git show --no-color --format= -U${contextLines} ${quotedCommit}`;
|
|
356
|
-
// If a specific file is requested, filter the output
|
|
357
|
-
if (file) {
|
|
358
|
-
const quotedFile = quoteForShell(file);
|
|
359
|
-
command = `git show --no-color --format= -U${contextLines} ${quotedCommit} -- ${quotedFile}`;
|
|
360
|
-
}
|
|
361
|
-
try {
|
|
362
|
-
const result = await provider.executeCommand(command, false);
|
|
363
|
-
if (result.exitCode === 0) {
|
|
364
|
-
if (!result.stdout.trim()) {
|
|
365
|
-
return {
|
|
366
|
-
success: true,
|
|
367
|
-
message: {
|
|
368
|
-
type: 'text',
|
|
369
|
-
value: 'No diff found.',
|
|
370
|
-
},
|
|
371
|
-
};
|
|
372
|
-
}
|
|
373
|
-
let diffOutput = result.stdout;
|
|
374
|
-
if (includeLineNumbers) {
|
|
375
|
-
diffOutput = annotateDiffWithLineNumbers(diffOutput);
|
|
376
|
-
}
|
|
377
|
-
return {
|
|
378
|
-
success: true,
|
|
379
|
-
message: {
|
|
380
|
-
type: 'text',
|
|
381
|
-
value: `<diff file="${file ?? 'all'}">\n${diffOutput}\n</diff>`,
|
|
382
|
-
},
|
|
383
|
-
};
|
|
384
|
-
}
|
|
385
|
-
return {
|
|
386
|
-
success: false,
|
|
387
|
-
message: {
|
|
388
|
-
type: 'error-text',
|
|
389
|
-
value: `\`${command}\` exited with code ${result.exitCode}:\n${result.stderr}`,
|
|
390
|
-
},
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
catch (error) {
|
|
394
|
-
return {
|
|
395
|
-
success: false,
|
|
396
|
-
message: {
|
|
397
|
-
type: 'error-text',
|
|
398
|
-
value: error instanceof Error ? error.message : String(error),
|
|
399
|
-
},
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
};
|
|
403
|
-
return {
|
|
404
|
-
...toolInfo,
|
|
405
|
-
handler,
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
|
-
//# sourceMappingURL=git-file-tools.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"git-file-tools.js","sourceRoot":"","sources":["../../src/workflows/git-file-tools.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAG3B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAA;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAE9C,SAAS,YAAY,CAAC,IAAY;IAChC,uFAAuF;IACvF,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;IAC1C,MAAM,GAAG,GAAG,YAAY,GAAG,CAAC,IAAI,YAAY,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS,CAAA;IAEvH,MAAM,UAAU,GAA2B;QACzC,SAAS;QACT,GAAG,EAAE,WAAW;QAChB,GAAG,EAAE,YAAY;QACjB,IAAI,EAAE,YAAY;QAClB,GAAG,EAAE,WAAW;QAChB,GAAG,EAAE,eAAe;QACpB,IAAI,EAAE,YAAY;QAClB,GAAG,EAAE,cAAc;QACnB,GAAG,EAAE,WAAW;QAEhB,QAAQ;QACR,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,YAAY;QACnB,GAAG,EAAE,UAAU;QACf,GAAG,EAAE,UAAU;QACf,GAAG,EAAE,+BAA+B;QAEpC,YAAY;QACZ,GAAG,EAAE,iBAAiB;QAEtB,QAAQ;QACR,GAAG,EAAE,YAAY;QACjB,GAAG,EAAE,WA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E5D,IAAI,MAAM,CAAC,QAAQ,KAAK,CAAC,EAAE,CAAC;gBAC1B,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;oBAC1B,OAAO;wBACL,OAAO,EAAE,IAAI;wBACb,OAAO,EAAE;4BACP,IAAI,EAAE,MAAM;4BACZ,KAAK,EAAE,gBAAgB;yBACxB;qBACF,CAAA;gBACH,CAAC;gBAED,IAAI,UAAU,GAAG,MAAM,CAAC,MAAM,CAAA;gBAC9B,IAAI,kBAAkB,EAAE,CAAC;oBACvB,UAAU,GAAG,2BAA2B,CAAC,UAAU,CAAC,CAAA;gBACtD,CAAC;gBAED,OAAO;oBACL,OAAO,EAAE,IAAI;oBACb,OAAO,EAAE;wBACP,IAAI,EAAE,MAAM;wBACZ,KAAK,EAAE,eAAe,IAAI,IAAI,KAAK,OAAO,UAAU,WAAW;qBAChE;iBACF,CAAA;YACH,CAAC;YAED,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE;oBACP,IAAI,EAAE,YAAY;oBAClB,KAAK,EAAE,KAAK,OAAO,uBAAuB,MAAM,CAAC,QAAQ,MAAM,MAAM,CAAC,MAAM,EAAE;iBAC/E;aACF,CAAA;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE;oBACP,IAAI,EAAE,YAAY;oBAClB,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;iBAC9D;aACF,CAAA;QACH,CAAC;IACH,CAAC,CAAA;IAED,OAAO;QACL,GAAG,QAAQ;QACX,OAAO;KACe,CAAA;AAC1B,CAAC"}
|
package/dist/workflows/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// generated by polka.codes
|
|
2
|
-
export * from './code.workflow';
|
|
3
|
-
export * from './commit.workflow';
|
|
4
|
-
export * from './fix.workflow';
|
|
5
|
-
export * from './init.workflow';
|
|
6
|
-
export * from './meta.workflow';
|
|
7
|
-
export * from './plan.workflow';
|
|
8
|
-
export * from './pr.workflow';
|
|
9
|
-
export * from './review.workflow';
|
|
10
|
-
export * from './task.workflow';
|
|
11
|
-
export * from './workflow.utils';
|
|
12
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/workflows/index.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAE3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA"}
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
// generated by polka.codes
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { loadConfigAtPath } from '@polka-codes/cli-shared';
|
|
4
|
-
import { agentWorkflow, askFollowupQuestion, listFiles, readFile, searchFiles } from '@polka-codes/core';
|
|
5
|
-
import { parse, stringify } from 'yaml';
|
|
6
|
-
import { z } from 'zod';
|
|
7
|
-
import { INIT_WORKFLOW_ANALYZE_SYSTEM_PROMPT } from './prompts';
|
|
8
|
-
const scriptGenerationSystemPrompt = `Role: Expert TypeScript Developer and Automation Specialist
|
|
9
|
-
|
|
10
|
-
Goal: Generate a custom polka script based on user requirements.
|
|
11
|
-
|
|
12
|
-
You have access to:
|
|
13
|
-
- readFile: Read any file in the project
|
|
14
|
-
- listFiles: Discover project structure
|
|
15
|
-
- searchFiles: Find specific patterns
|
|
16
|
-
- askFollowupQuestion: Ask the user for clarification
|
|
17
|
-
|
|
18
|
-
Your task:
|
|
19
|
-
1. Understand the user's automation requirements
|
|
20
|
-
2. Analyze the project structure to understand the codebase
|
|
21
|
-
3. Ask clarifying questions if requirements are unclear
|
|
22
|
-
4. Generate a TypeScript script that combines polka workflows
|
|
23
|
-
5. Present the plan to the user and confirm before generating
|
|
24
|
-
|
|
25
|
-
Script Guidelines:
|
|
26
|
-
- Use existing polka workflows: code, fix, review, commit, plan
|
|
27
|
-
- Include proper error handling and logging
|
|
28
|
-
- Add comments explaining each step
|
|
29
|
-
- Make scripts configurable via command-line arguments
|
|
30
|
-
- Export a main() function that accepts args: string[]
|
|
31
|
-
- Include usage examples in comments
|
|
32
|
-
|
|
33
|
-
Available Workflows:
|
|
34
|
-
- code({ task, interactive }): Implement coding tasks
|
|
35
|
-
- fix({ task }): Fix bugs and issues
|
|
36
|
-
- review({ range, pr, files, context }): Review code changes
|
|
37
|
-
- commit({ message, stageFiles }): Create git commits
|
|
38
|
-
- plan({ task }): Create implementation plans
|
|
39
|
-
|
|
40
|
-
Script Template:
|
|
41
|
-
\`\`\`typescript
|
|
42
|
-
// Generated by polka.codes
|
|
43
|
-
import { code, fix, review, commit } from '@polka-codes/cli'
|
|
44
|
-
|
|
45
|
-
export interface ScriptOptions {
|
|
46
|
-
// Add your options here
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export async function main(args: string[]) {
|
|
50
|
-
// Parse arguments if needed
|
|
51
|
-
// Your automation logic here
|
|
52
|
-
|
|
53
|
-
console.log('Script completed successfully')
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Only run main if this is the entry point
|
|
57
|
-
if (import.meta.main) {
|
|
58
|
-
main(process.argv.slice(2))
|
|
59
|
-
}
|
|
60
|
-
\`\`\`
|
|
61
|
-
|
|
62
|
-
Response Format:
|
|
63
|
-
Return a JSON object with:
|
|
64
|
-
- plan: string describing the script approach
|
|
65
|
-
- questions: array of questions to ask the user (if needed)
|
|
66
|
-
- script: the generated TypeScript code
|
|
67
|
-
- config: any additional configuration needed
|
|
68
|
-
|
|
69
|
-
Example response format:
|
|
70
|
-
\`\`\`json
|
|
71
|
-
{
|
|
72
|
-
"plan": "Step-by-step plan for the script",
|
|
73
|
-
"script": "// Generated TypeScript code"
|
|
74
|
-
}
|
|
75
|
-
\`\`\``;
|
|
76
|
-
export const initInteractiveWorkflow = async (input, context) => {
|
|
77
|
-
const { step, logger, tools } = context;
|
|
78
|
-
const { configPath, scriptName, scriptInstructions, generateScript = false, skipConfirmation = false } = input;
|
|
79
|
-
let generatedConfig = {};
|
|
80
|
-
let generatedScriptPath;
|
|
81
|
-
// Only analyze and generate config if we're NOT generating a script
|
|
82
|
-
if (!generateScript) {
|
|
83
|
-
// Step 1: Analyze project and generate config
|
|
84
|
-
const analyzeResult = await step('analyze-project', async () => {
|
|
85
|
-
logger.info('Analyzing project structure and configuration...');
|
|
86
|
-
return await agentWorkflow({
|
|
87
|
-
systemPrompt: INIT_WORKFLOW_ANALYZE_SYSTEM_PROMPT,
|
|
88
|
-
userMessage: [
|
|
89
|
-
{
|
|
90
|
-
role: 'user',
|
|
91
|
-
content: 'Please provide a valid polkacodes YAML configuration for the project.',
|
|
92
|
-
},
|
|
93
|
-
],
|
|
94
|
-
tools: [readFile, listFiles, searchFiles],
|
|
95
|
-
outputSchema: z.object({ yaml: z.string() }),
|
|
96
|
-
}, { logger, tools, step });
|
|
97
|
-
});
|
|
98
|
-
if (analyzeResult.type === 'Exit' && analyzeResult.object) {
|
|
99
|
-
const yamlConfig = analyzeResult.object.yaml;
|
|
100
|
-
generatedConfig = yamlConfig ? parse(yamlConfig) : {};
|
|
101
|
-
}
|
|
102
|
-
// Step 2: Save generated config
|
|
103
|
-
await step('save-config', async () => {
|
|
104
|
-
const existingConfig = loadConfigAtPath(configPath) ?? {};
|
|
105
|
-
const finalConfig = {
|
|
106
|
-
...existingConfig,
|
|
107
|
-
...generatedConfig,
|
|
108
|
-
};
|
|
109
|
-
await tools.writeToFile({ path: configPath, content: stringify(finalConfig) });
|
|
110
|
-
logger.info(`ā
Configuration saved to ${configPath}`);
|
|
111
|
-
// Show what was generated
|
|
112
|
-
if (generatedConfig.scripts) {
|
|
113
|
-
logger.info('\nš Generated scripts:');
|
|
114
|
-
Object.entries(generatedConfig.scripts).forEach(([name, scriptConfig]) => {
|
|
115
|
-
if (typeof scriptConfig === 'string') {
|
|
116
|
-
logger.info(` - ${name}: ${scriptConfig}`);
|
|
117
|
-
}
|
|
118
|
-
else if (typeof scriptConfig === 'object' && scriptConfig !== null) {
|
|
119
|
-
logger.info(` - ${name}: ${scriptConfig.description || JSON.stringify(scriptConfig)}`);
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
if (generatedConfig.rules) {
|
|
124
|
-
const rules = Array.isArray(generatedConfig.rules) ? generatedConfig.rules : [generatedConfig.rules];
|
|
125
|
-
logger.info('\nš Identified project rules:');
|
|
126
|
-
rules.forEach((rule) => {
|
|
127
|
-
if (typeof rule === 'string') {
|
|
128
|
-
logger.info(` - ${rule}`);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
// Step 3: Generate custom script if requested
|
|
135
|
-
if (generateScript && scriptName && scriptInstructions) {
|
|
136
|
-
const scriptResult = await step('generate-script', async () => {
|
|
137
|
-
logger.info(`\nš§ Generating custom script: ${scriptName}`);
|
|
138
|
-
logger.info(`Requirements: ${scriptInstructions}`);
|
|
139
|
-
// Use agent workflow with askFollowupQuestion tool
|
|
140
|
-
return await agentWorkflow({
|
|
141
|
-
systemPrompt: scriptGenerationSystemPrompt,
|
|
142
|
-
userMessage: [
|
|
143
|
-
{
|
|
144
|
-
role: 'user',
|
|
145
|
-
content: `Generate a polka script with these requirements:
|
|
146
|
-
Script name: ${scriptName}
|
|
147
|
-
|
|
148
|
-
Instructions: ${scriptInstructions}
|
|
149
|
-
|
|
150
|
-
Please:
|
|
151
|
-
1. Ask clarifying questions if needed
|
|
152
|
-
2. Analyze the project structure
|
|
153
|
-
3. Present your plan before generating the script
|
|
154
|
-
4. Generate a complete, working TypeScript script`,
|
|
155
|
-
},
|
|
156
|
-
],
|
|
157
|
-
tools: [readFile, listFiles, searchFiles, askFollowupQuestion],
|
|
158
|
-
outputSchema: z.object({
|
|
159
|
-
plan: z.string(),
|
|
160
|
-
script: z.string(),
|
|
161
|
-
config: z.record(z.string(), z.unknown()).optional(),
|
|
162
|
-
}),
|
|
163
|
-
}, { logger, tools, step });
|
|
164
|
-
});
|
|
165
|
-
if (scriptResult.type === 'Exit' && scriptResult.object) {
|
|
166
|
-
const { plan, script, config: scriptConfig } = scriptResult.object;
|
|
167
|
-
// Show plan if not skipped
|
|
168
|
-
if (!skipConfirmation) {
|
|
169
|
-
logger.info('\nš Script Generation Plan:');
|
|
170
|
-
logger.info(plan);
|
|
171
|
-
}
|
|
172
|
-
// Save the script
|
|
173
|
-
const scriptDir = '.polka-scripts';
|
|
174
|
-
const scriptFileName = `${scriptName}.ts`;
|
|
175
|
-
const scriptFilePath = join(scriptDir, scriptFileName);
|
|
176
|
-
await step('save-script', async () => {
|
|
177
|
-
await tools.writeToFile({ path: scriptFilePath, content: script });
|
|
178
|
-
logger.info(`\nā
Script generated: ${scriptFilePath}`);
|
|
179
|
-
logger.info(`\nRun with: bun run polka run ${scriptName}`);
|
|
180
|
-
// Update config if additional config provided
|
|
181
|
-
// Note: We don't merge scriptConfig directly to avoid type safety issues
|
|
182
|
-
// The AI-generated config is untyped and could corrupt the configuration
|
|
183
|
-
if (scriptConfig && Object.keys(scriptConfig).length > 0) {
|
|
184
|
-
logger.warn(`ā ļø AI suggested config updates, but they were not merged for safety:`);
|
|
185
|
-
logger.warn(JSON.stringify(scriptConfig, null, 2));
|
|
186
|
-
logger.warn(`To apply these changes, manually edit ${configPath}`);
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
generatedScriptPath = scriptFilePath;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return {
|
|
193
|
-
configPath,
|
|
194
|
-
scriptPath: generatedScriptPath,
|
|
195
|
-
generatedConfig,
|
|
196
|
-
};
|
|
197
|
-
};
|
|
198
|
-
//# sourceMappingURL=init-interactive.workflow.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"init-interactive.workflow.js","sourceRoot":"","sources":["../../src/workflows/init-interactive.workflow.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAe,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AACvE,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAmB,MAAM,mBAAmB,CAAA;AACzH,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AACvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,mCAAmC,EAAE,MAAM,WAAW,CAAA;AAiB/D,MAAM,4BAA4B,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmE9B,CAAA;AAEP,MAAM,CAAC,MAAM,uBAAuB,GAIhC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;IAC3B,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAA;IACvC,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,kBAAkB,EAAE,cAAc,GAAG,KAAK,EAAE,gBAAgB,GAAG,KAAK,EAAE,GAAG,KAAK,CAAA;IAE9G,IAAI,eAAe,GAAoB,EAAE,CAAA;IACzC,IAAI,mBAAuC,CAAA;IAE3C,oEAAoE;IACpE,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,8CAA8C;QAC9C,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,iBAAiB,EAAE,KAAK,IAA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