work-agent 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.
- package/README.md +234 -0
- package/app/(admin)/approvals/page.tsx +16 -0
- package/app/(admin)/audit/page.tsx +18 -0
- package/app/(admin)/layout.tsx +47 -0
- package/app/(admin)/scheduled-tasks/page.tsx +17 -0
- package/app/(admin)/settings/page.tsx +46 -0
- package/app/(admin)/skills/[name]/page.tsx +378 -0
- package/app/(admin)/skills/page.tsx +406 -0
- package/app/(admin)/statistics/page.tsx +416 -0
- package/app/(admin)/tickets/[id]/page.tsx +348 -0
- package/app/(admin)/tickets/new/page.tsx +309 -0
- package/app/(admin)/tickets/page.tsx +27 -0
- package/app/api/audit/route.ts +30 -0
- package/app/api/auth/feishu/callback/route.ts +72 -0
- package/app/api/auth/feishu/login/route.ts +17 -0
- package/app/api/auth/feishu/sso/route.ts +78 -0
- package/app/api/auth/login/route.ts +85 -0
- package/app/api/auth/oauth/route.ts +168 -0
- package/app/api/config/providers/route.ts +105 -0
- package/app/api/config/route.ts +115 -0
- package/app/api/config/status/route.ts +56 -0
- package/app/api/config/test/route.ts +212 -0
- package/app/api/documents/[id]/route.ts +88 -0
- package/app/api/documents/route.ts +53 -0
- package/app/api/health/route.ts +32 -0
- package/app/api/knowledge/[id]/route.ts +152 -0
- package/app/api/knowledge/from-session/route.ts +27 -0
- package/app/api/knowledge/route.ts +100 -0
- package/app/api/market/knowledge/[id]/route.ts +92 -0
- package/app/api/market/knowledge/route.ts +130 -0
- package/app/api/marketplace/skills/[id]/approve/route.ts +68 -0
- package/app/api/marketplace/skills/[id]/certify/route.ts +54 -0
- package/app/api/marketplace/skills/[id]/install/route.ts +180 -0
- package/app/api/marketplace/skills/[id]/promote-to-system/route.ts +219 -0
- package/app/api/marketplace/skills/[id]/rate/route.ts +90 -0
- package/app/api/marketplace/skills/[id]/ratings/route.ts +55 -0
- package/app/api/marketplace/skills/[id]/reject/route.ts +68 -0
- package/app/api/marketplace/skills/[id]/route.ts +177 -0
- package/app/api/marketplace/skills/route.ts +235 -0
- package/app/api/memory/route.ts +40 -0
- package/app/api/my/files/[id]/route.ts +52 -0
- package/app/api/my/files/route.ts +230 -0
- package/app/api/my/knowledge/route.ts +36 -0
- package/app/api/pi-chat/route.ts +443 -0
- package/app/api/recommend/route.ts +38 -0
- package/app/api/scheduled-tasks/[id]/execute/route.ts +132 -0
- package/app/api/scheduled-tasks/[id]/route.ts +165 -0
- package/app/api/scheduled-tasks/[id]/toggle/route.ts +53 -0
- package/app/api/scheduled-tasks/route.ts +101 -0
- package/app/api/sessions/[id]/messages/route.ts +212 -0
- package/app/api/sessions/route.ts +101 -0
- package/app/api/share/file/[id]/route.ts +37 -0
- package/app/api/skills/[name]/execute/route.ts +121 -0
- package/app/api/skills/[name]/route.ts +167 -0
- package/app/api/skills/create/route.ts +65 -0
- package/app/api/skills/generate/route.ts +405 -0
- package/app/api/skills/installed/route.ts +151 -0
- package/app/api/skills/route.ts +174 -0
- package/app/api/skills/translate/route.ts +40 -0
- package/app/api/skills/user/[name]/route.ts +159 -0
- package/app/api/skills/user/route.ts +90 -0
- package/app/api/statistics/route.ts +94 -0
- package/app/api/task-executions/[id]/route.ts +34 -0
- package/app/api/task-executions/route.ts +29 -0
- package/app/api/tickets/[id]/approve/route.ts +129 -0
- package/app/api/tickets/[id]/execute/route.ts +201 -0
- package/app/api/tickets/[id]/route.ts +127 -0
- package/app/api/tickets/route.ts +103 -0
- package/app/api/user/skills/route.ts +175 -0
- package/app/api/users/route.ts +80 -0
- package/app/chat/page.tsx +5 -0
- package/app/globals.css +84 -0
- package/app/h5/layout.tsx +5 -0
- package/app/h5/mobile-approvals-page.tsx +167 -0
- package/app/h5/mobile-chat-page.tsx +951 -0
- package/app/h5/mobile-profile-page.tsx +147 -0
- package/app/h5/mobile-tickets-page.tsx +121 -0
- package/app/h5/page.tsx +23 -0
- package/app/h5/ticket-action-buttons.tsx +80 -0
- package/app/layout.tsx +26 -0
- package/app/login/page.tsx +318 -0
- package/app/market/knowledge/[id]/page.tsx +77 -0
- package/app/market/knowledge/page.tsx +358 -0
- package/app/market/layout.tsx +29 -0
- package/app/market/page.tsx +18 -0
- package/app/market/skills/page.tsx +397 -0
- package/app/my/files/page.tsx +511 -0
- package/app/my/knowledge/[id]/page.tsx +271 -0
- package/app/my/knowledge/new/page.tsx +234 -0
- package/app/my/knowledge/page.tsx +248 -0
- package/app/my/layout.tsx +32 -0
- package/app/my/memory/page.tsx +164 -0
- package/app/my/page.tsx +18 -0
- package/app/my/scheduled-tasks/[id]/edit/page.tsx +290 -0
- package/app/my/scheduled-tasks/[id]/executions/page.tsx +275 -0
- package/app/my/scheduled-tasks/[id]/page.tsx +284 -0
- package/app/my/scheduled-tasks/new/page.tsx +230 -0
- package/app/my/scheduled-tasks/page.tsx +27 -0
- package/app/my/skills/[name]/page.tsx +320 -0
- package/app/my/skills/new/page.tsx +394 -0
- package/app/my/skills/page.tsx +303 -0
- package/app/page.tsx +2288 -0
- package/app/share/[sessionId]/page.tsx +226 -0
- package/app/share/file/[id]/page.tsx +140 -0
- package/bin/README.md +63 -0
- package/bin/generate-api-system +300 -0
- package/bin/postinstall.js +95 -0
- package/bin/work-agent.js +173 -0
- package/components/ai-elements/agent.tsx +142 -0
- package/components/ai-elements/artifact.tsx +149 -0
- package/components/ai-elements/attachments.tsx +427 -0
- package/components/ai-elements/audio-player.tsx +232 -0
- package/components/ai-elements/canvas.tsx +26 -0
- package/components/ai-elements/chain-of-thought.tsx +223 -0
- package/components/ai-elements/checkpoint.tsx +72 -0
- package/components/ai-elements/code-block.tsx +555 -0
- package/components/ai-elements/commit.tsx +449 -0
- package/components/ai-elements/confirmation.tsx +173 -0
- package/components/ai-elements/connection.tsx +28 -0
- package/components/ai-elements/context.tsx +410 -0
- package/components/ai-elements/controls.tsx +19 -0
- package/components/ai-elements/conversation.tsx +167 -0
- package/components/ai-elements/edge.tsx +144 -0
- package/components/ai-elements/environment-variables.tsx +325 -0
- package/components/ai-elements/file-tree.tsx +298 -0
- package/components/ai-elements/image.tsx +25 -0
- package/components/ai-elements/inline-citation.tsx +294 -0
- package/components/ai-elements/jsx-preview.tsx +250 -0
- package/components/ai-elements/message.tsx +367 -0
- package/components/ai-elements/mic-selector.tsx +372 -0
- package/components/ai-elements/model-selector.tsx +214 -0
- package/components/ai-elements/node.tsx +72 -0
- package/components/ai-elements/open-in-chat.tsx +367 -0
- package/components/ai-elements/package-info.tsx +235 -0
- package/components/ai-elements/panel.tsx +16 -0
- package/components/ai-elements/persona.tsx +280 -0
- package/components/ai-elements/plan.tsx +144 -0
- package/components/ai-elements/prompt-input.tsx +1341 -0
- package/components/ai-elements/queue.tsx +275 -0
- package/components/ai-elements/reasoning.tsx +355 -0
- package/components/ai-elements/sandbox.tsx +133 -0
- package/components/ai-elements/schema-display.tsx +473 -0
- package/components/ai-elements/shimmer.tsx +78 -0
- package/components/ai-elements/snippet.tsx +141 -0
- package/components/ai-elements/sources.tsx +78 -0
- package/components/ai-elements/speech-input.tsx +324 -0
- package/components/ai-elements/stack-trace.tsx +531 -0
- package/components/ai-elements/suggestion.tsx +58 -0
- package/components/ai-elements/task.tsx +88 -0
- package/components/ai-elements/terminal.tsx +277 -0
- package/components/ai-elements/test-results.tsx +497 -0
- package/components/ai-elements/tool.tsx +174 -0
- package/components/ai-elements/toolbar.tsx +17 -0
- package/components/ai-elements/transcription.tsx +126 -0
- package/components/ai-elements/voice-selector.tsx +525 -0
- package/components/ai-elements/web-preview.tsx +282 -0
- package/components/audit-log-list.tsx +114 -0
- package/components/chat/EmptyPreviewState.tsx +12 -0
- package/components/chat/KnowledgePickerDialog.tsx +464 -0
- package/components/chat/KnowledgePreview.tsx +70 -0
- package/components/chat/KnowledgePreviewPanel.tsx +86 -0
- package/components/chat/MentionInput.tsx +309 -0
- package/components/chat/OrganizeDialog.tsx +258 -0
- package/components/chat/RecommendationBanner.tsx +94 -0
- package/components/chat/SaveToKnowledgeDialog.tsx +193 -0
- package/components/chat/SkillSelector.tsx +305 -0
- package/components/chat/SkillSwitcher.tsx +163 -0
- package/components/client-layout.tsx +15 -0
- package/components/knowledge/KnowledgeMetadataPanel.tsx +293 -0
- package/components/layout-wrapper.tsx +18 -0
- package/components/mobile-layout.tsx +62 -0
- package/components/scheduled-task-list.tsx +356 -0
- package/components/setup-guide.tsx +484 -0
- package/components/sub-nav.tsx +54 -0
- package/components/ticket-detail-content.tsx +383 -0
- package/components/ticket-list.tsx +366 -0
- package/components/top-nav.tsx +132 -0
- package/components/ui/accordion.tsx +58 -0
- package/components/ui/alert.tsx +59 -0
- package/components/ui/avatar.tsx +50 -0
- package/components/ui/badge.tsx +36 -0
- package/components/ui/button-group.tsx +83 -0
- package/components/ui/button.tsx +57 -0
- package/components/ui/card.tsx +91 -0
- package/components/ui/carousel.tsx +262 -0
- package/components/ui/collapsible.tsx +11 -0
- package/components/ui/command.tsx +153 -0
- package/components/ui/dialog.tsx +122 -0
- package/components/ui/dropdown-menu.tsx +200 -0
- package/components/ui/hover-card.tsx +29 -0
- package/components/ui/input-group.tsx +170 -0
- package/components/ui/input.tsx +22 -0
- package/components/ui/label.tsx +26 -0
- package/components/ui/popover.tsx +31 -0
- package/components/ui/progress.tsx +28 -0
- package/components/ui/scroll-area.tsx +48 -0
- package/components/ui/select.tsx +174 -0
- package/components/ui/separator.tsx +31 -0
- package/components/ui/spinner.tsx +16 -0
- package/components/ui/switch.tsx +29 -0
- package/components/ui/table.tsx +120 -0
- package/components/ui/tabs.tsx +55 -0
- package/components/ui/textarea.tsx +22 -0
- package/components/ui/tooltip.tsx +30 -0
- package/components/welcome-guide.tsx +182 -0
- package/components.json +24 -0
- package/lib/command-parser.ts +331 -0
- package/lib/dangerous-commands.ts +672 -0
- package/lib/db.ts +2250 -0
- package/lib/feishu-auth.ts +135 -0
- package/lib/file-storage.ts +306 -0
- package/lib/file-tool.ts +583 -0
- package/lib/knowledge-tool.ts +152 -0
- package/lib/knowledge-types.ts +66 -0
- package/lib/market-client.ts +313 -0
- package/lib/market-db.ts +736 -0
- package/lib/market-types.ts +51 -0
- package/lib/memory-tool.ts +211 -0
- package/lib/memory.ts +197 -0
- package/lib/pi-config.ts +436 -0
- package/lib/pi-session.ts +799 -0
- package/lib/pinyin.ts +13 -0
- package/lib/recommendation.ts +227 -0
- package/lib/risk-estimator.ts +350 -0
- package/lib/scheduled-task-tool.ts +184 -0
- package/lib/scheduler-init.ts +43 -0
- package/lib/scheduler.ts +416 -0
- package/lib/secure-bash-tool.ts +413 -0
- package/lib/skill-engine.ts +396 -0
- package/lib/skill-generator.ts +269 -0
- package/lib/skill-loader.ts +234 -0
- package/lib/skill-tool.ts +188 -0
- package/lib/skill-types.ts +82 -0
- package/lib/skills-init.ts +58 -0
- package/lib/ticket-tool.ts +246 -0
- package/lib/user-skill-types.ts +30 -0
- package/lib/user-skills.ts +362 -0
- package/lib/utils.ts +6 -0
- package/lib/workflow.ts +154 -0
- package/lib/zip-tool.ts +191 -0
- package/next.config.js +8 -0
- package/package.json +106 -0
- package/public/.gitkeep +1 -0
- package/public/icon.svg +1 -0
- package/tsconfig.json +42 -0
package/components.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema.json",
|
|
3
|
+
"style": "default",
|
|
4
|
+
"rsc": true,
|
|
5
|
+
"tsx": true,
|
|
6
|
+
"tailwind": {
|
|
7
|
+
"config": "tailwind.config.js",
|
|
8
|
+
"css": "app/globals.css",
|
|
9
|
+
"baseColor": "slate",
|
|
10
|
+
"cssVariables": true,
|
|
11
|
+
"prefix": ""
|
|
12
|
+
},
|
|
13
|
+
"iconLibrary": "lucide",
|
|
14
|
+
"aliases": {
|
|
15
|
+
"components": "@/components",
|
|
16
|
+
"utils": "@/lib/utils",
|
|
17
|
+
"ui": "@/components/ui",
|
|
18
|
+
"lib": "@/lib",
|
|
19
|
+
"hooks": "@/hooks"
|
|
20
|
+
},
|
|
21
|
+
"registries": {
|
|
22
|
+
"@ai-elements": "https://ai-sdk.dev/elements/api/registry/{name}.json"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command Parser
|
|
3
|
+
*
|
|
4
|
+
* Parses commands to extract:
|
|
5
|
+
* - Command type (kubectl, docker, bash, etc.)
|
|
6
|
+
* - Verb/action
|
|
7
|
+
* - Resources
|
|
8
|
+
* - Options
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export type CommandType = 'kubectl' | 'docker' | 'git' | 'npm' | 'bash' | 'unknown';
|
|
12
|
+
|
|
13
|
+
export interface ParsedCommand {
|
|
14
|
+
raw: string;
|
|
15
|
+
type: CommandType;
|
|
16
|
+
verb?: string;
|
|
17
|
+
subverb?: string;
|
|
18
|
+
resources: string[];
|
|
19
|
+
namespace?: string;
|
|
20
|
+
options: Record<string, string>;
|
|
21
|
+
target?: string;
|
|
22
|
+
commandString: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function parseCommand(command: string): ParsedCommand {
|
|
26
|
+
const trimmed = command.trim();
|
|
27
|
+
const tokens = tokenize(trimmed);
|
|
28
|
+
|
|
29
|
+
if (tokens.length === 0) {
|
|
30
|
+
return createEmptyParsedCommand(trimmed);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const commandType = detectCommandType(tokens[0]);
|
|
34
|
+
|
|
35
|
+
switch (commandType) {
|
|
36
|
+
case 'kubectl':
|
|
37
|
+
return parseKubectlCommand(tokens, trimmed);
|
|
38
|
+
case 'docker':
|
|
39
|
+
return parseDockerCommand(tokens, trimmed);
|
|
40
|
+
case 'git':
|
|
41
|
+
return parseGitCommand(tokens, trimmed);
|
|
42
|
+
default:
|
|
43
|
+
return parseBashCommand(tokens, trimmed);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function tokenize(command: string): string[] {
|
|
48
|
+
const tokens: string[] = [];
|
|
49
|
+
let current = '';
|
|
50
|
+
let inQuote = false;
|
|
51
|
+
let quoteChar = '';
|
|
52
|
+
|
|
53
|
+
for (let i = 0; i < command.length; i++) {
|
|
54
|
+
const char = command[i];
|
|
55
|
+
|
|
56
|
+
if ((char === '"' || char === "'") && !inQuote) {
|
|
57
|
+
inQuote = true;
|
|
58
|
+
quoteChar = char;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (char === quoteChar && inQuote) {
|
|
63
|
+
inQuote = false;
|
|
64
|
+
quoteChar = '';
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (!inQuote && char === ' ') {
|
|
69
|
+
if (current) {
|
|
70
|
+
tokens.push(current);
|
|
71
|
+
current = '';
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
current += char;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (current) {
|
|
79
|
+
tokens.push(current);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return tokens;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function detectCommandType(cmd: string): CommandType {
|
|
86
|
+
const lower = cmd.toLowerCase();
|
|
87
|
+
|
|
88
|
+
if (lower === 'kubectl' || lower === 'k') return 'kubectl';
|
|
89
|
+
if (lower === 'docker') return 'docker';
|
|
90
|
+
if (lower === 'git') return 'git';
|
|
91
|
+
if (lower === 'npm') return 'npm';
|
|
92
|
+
if (lower === 'bash' || lower === 'sh' || lower === 'zsh') return 'bash';
|
|
93
|
+
|
|
94
|
+
return 'unknown';
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function parseKubectlCommand(tokens: string[], raw: string): ParsedCommand {
|
|
98
|
+
const result: ParsedCommand = {
|
|
99
|
+
raw,
|
|
100
|
+
type: 'kubectl',
|
|
101
|
+
resources: [],
|
|
102
|
+
options: {},
|
|
103
|
+
commandString: raw,
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
let i = 0;
|
|
107
|
+
|
|
108
|
+
// Skip 'kubectl'
|
|
109
|
+
if (tokens[i]?.toLowerCase() === 'kubectl' || tokens[i] === 'k') {
|
|
110
|
+
i++;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (i >= tokens.length) {
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Get verb
|
|
118
|
+
result.verb = tokens[i].toLowerCase();
|
|
119
|
+
i++;
|
|
120
|
+
|
|
121
|
+
// Get subverb (like 'rollout restart')
|
|
122
|
+
if (i < tokens.length && tokens[i] !== '-' && !tokens[i].startsWith('--')) {
|
|
123
|
+
result.subverb = tokens[i].toLowerCase();
|
|
124
|
+
i++;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Parse remaining tokens
|
|
128
|
+
while (i < tokens.length) {
|
|
129
|
+
const token = tokens[i];
|
|
130
|
+
|
|
131
|
+
if (token.startsWith('--')) {
|
|
132
|
+
// Long option
|
|
133
|
+
const [key, ...valueParts] = token.slice(2).split('=');
|
|
134
|
+
result.options[key] = valueParts.join('=') || 'true';
|
|
135
|
+
} else if (token.startsWith('-') && token.length > 1) {
|
|
136
|
+
// Short option
|
|
137
|
+
const key = token[1];
|
|
138
|
+
result.options[key] = 'true';
|
|
139
|
+
} else if (!token.startsWith('-')) {
|
|
140
|
+
// Resource or target
|
|
141
|
+
const resourceMatch = token.match(/^([a-zA-Z]+)\/([a-zA-Z0-9-]+)$/);
|
|
142
|
+
|
|
143
|
+
if (resourceMatch) {
|
|
144
|
+
result.resources.push(resourceMatch[1]);
|
|
145
|
+
result.target = resourceMatch[2];
|
|
146
|
+
} else if (result.verb === 'delete' || result.verb === 'describe' || result.verb === 'get') {
|
|
147
|
+
result.resources.push(token);
|
|
148
|
+
if (!result.target && !token.includes('/')) {
|
|
149
|
+
result.target = token;
|
|
150
|
+
}
|
|
151
|
+
} else if (!result.target) {
|
|
152
|
+
result.target = token;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
i++;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Extract namespace from options
|
|
160
|
+
if (result.options['n'] || result.options['namespace']) {
|
|
161
|
+
result.namespace = result.options['n'] || result.options['namespace'];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Build readable command string
|
|
165
|
+
result.commandString = buildCommandString(result);
|
|
166
|
+
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function parseDockerCommand(tokens: string[], raw: string): ParsedCommand {
|
|
171
|
+
const result: ParsedCommand = {
|
|
172
|
+
raw,
|
|
173
|
+
type: 'docker',
|
|
174
|
+
resources: [],
|
|
175
|
+
options: {},
|
|
176
|
+
commandString: raw,
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
let i = 0;
|
|
180
|
+
|
|
181
|
+
// Skip 'docker'
|
|
182
|
+
if (tokens[i]?.toLowerCase() === 'docker') {
|
|
183
|
+
i++;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (i >= tokens.length) {
|
|
187
|
+
return result;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Get verb
|
|
191
|
+
result.verb = tokens[i].toLowerCase();
|
|
192
|
+
i++;
|
|
193
|
+
|
|
194
|
+
// Parse remaining tokens
|
|
195
|
+
while (i < tokens.length) {
|
|
196
|
+
const token = tokens[i];
|
|
197
|
+
|
|
198
|
+
if (token.startsWith('--')) {
|
|
199
|
+
const [key, ...valueParts] = token.slice(2).split('=');
|
|
200
|
+
result.options[key] = valueParts.join('=') || 'true';
|
|
201
|
+
} else if (token.startsWith('-') && token.length > 1) {
|
|
202
|
+
const key = token[1];
|
|
203
|
+
result.options[key] = 'true';
|
|
204
|
+
} else if (!token.startsWith('-')) {
|
|
205
|
+
if (!result.target) {
|
|
206
|
+
result.target = token;
|
|
207
|
+
}
|
|
208
|
+
result.resources.push(token);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
i++;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
result.commandString = buildCommandString(result);
|
|
215
|
+
|
|
216
|
+
return result;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function parseGitCommand(tokens: string[], raw: string): ParsedCommand {
|
|
220
|
+
const result: ParsedCommand = {
|
|
221
|
+
raw,
|
|
222
|
+
type: 'git',
|
|
223
|
+
resources: [],
|
|
224
|
+
options: {},
|
|
225
|
+
commandString: raw,
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
let i = 0;
|
|
229
|
+
|
|
230
|
+
if (tokens[i]?.toLowerCase() === 'git') {
|
|
231
|
+
i++;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (i >= tokens.length) {
|
|
235
|
+
return result;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
result.verb = tokens[i].toLowerCase();
|
|
239
|
+
i++;
|
|
240
|
+
|
|
241
|
+
if (i < tokens.length) {
|
|
242
|
+
result.target = tokens[i];
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
result.commandString = buildCommandString(result);
|
|
246
|
+
|
|
247
|
+
return result;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function parseBashCommand(tokens: string[], raw: string): ParsedCommand {
|
|
251
|
+
const result: ParsedCommand = {
|
|
252
|
+
raw,
|
|
253
|
+
type: 'bash',
|
|
254
|
+
options: {},
|
|
255
|
+
resources: [],
|
|
256
|
+
commandString: raw,
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
if (tokens.length > 0) {
|
|
260
|
+
result.verb = tokens[0].toLowerCase();
|
|
261
|
+
result.target = tokens.slice(1).join(' ');
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return result;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function createEmptyParsedCommand(raw: string): ParsedCommand {
|
|
268
|
+
return {
|
|
269
|
+
raw,
|
|
270
|
+
type: 'unknown',
|
|
271
|
+
resources: [],
|
|
272
|
+
options: {},
|
|
273
|
+
commandString: raw,
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function buildCommandString(parsed: ParsedCommand): string {
|
|
278
|
+
const parts: string[] = [parsed.type];
|
|
279
|
+
|
|
280
|
+
if (parsed.verb) {
|
|
281
|
+
parts.push(parsed.verb);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (parsed.subverb) {
|
|
285
|
+
parts.push(parsed.subverb);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (parsed.target) {
|
|
289
|
+
parts.push(parsed.target);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return parts.join(' ');
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export function extractAffectedResources(command: ParsedCommand): string[] {
|
|
296
|
+
const resources: string[] = [];
|
|
297
|
+
|
|
298
|
+
if (command.type === 'kubectl') {
|
|
299
|
+
const verb = command.verb;
|
|
300
|
+
|
|
301
|
+
if (verb === 'delete' || verb === 'describe' || verb === 'get' || verb === 'edit') {
|
|
302
|
+
resources.push(...command.resources);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (command.namespace) {
|
|
306
|
+
resources.push(`namespace/${command.namespace}`);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// Add resource type based on verb
|
|
310
|
+
const resourceMap: Record<string, string> = {
|
|
311
|
+
'pod': 'pods',
|
|
312
|
+
'deployment': 'deployments',
|
|
313
|
+
'service': 'services',
|
|
314
|
+
'configmap': 'configmaps',
|
|
315
|
+
'secret': 'secrets',
|
|
316
|
+
'statefulset': 'statefulsets',
|
|
317
|
+
'daemonset': 'daemonsets',
|
|
318
|
+
'ingress': 'ingresses',
|
|
319
|
+
'node': 'nodes',
|
|
320
|
+
'namespace': 'namespaces',
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
for (const [singular, plural] of Object.entries(resourceMap)) {
|
|
324
|
+
if (command.raw.includes(singular)) {
|
|
325
|
+
resources.push(plural);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return [...new Set(resources)];
|
|
331
|
+
}
|