Refactored agent command handling to remove redundant boiler-plate code. Commands are parsed dynamically based on a single definition. Command-specific actions might still need distinct implementations.

This commit is contained in:
Jakob Friedl
2025-07-14 22:14:27 +02:00
parent 2d2c94ed38
commit b8b276d887
5 changed files with 240 additions and 129 deletions

View File

@@ -8,8 +8,7 @@ import terminal
Agent types & procs
]#
type
TaskCommand* = enum
CommandType* = enum
ExecuteShell = "shell"
ExecuteBof = "bof"
ExecuteAssembly = "dotnet"
@@ -23,6 +22,27 @@ type
Move = "move"
Copy = "copy"
ArgumentType* = enum
String = 0
Int = 1
Long = 2
Bool = 3
Binary = 4
Argument* = object
name*: string
description*: string
argumentType*: ArgumentType
isRequired*: bool
Command* = object
name*: string
commandType*: CommandType
description*: string
example*: string
arguments*: seq[Argument]
dispatchMessage*: string
TaskStatus* = enum
Completed = "completed"
Created = "created"
@@ -39,7 +59,7 @@ type
Task* = ref object
id*: string
agent*: string
command*: TaskCommand
command*: CommandType
args*: string # Json string containing all the positional arguments
# Example: """{"command": "whoami", "arguments": "/all"}"""
@@ -181,7 +201,7 @@ template clear*(cq: Conquest) =
cq.prompt.clear()
# Overwrite withOutput function to handle function arguments
proc withOutput*(cq: Conquest, outputFunction: proc(cq: Conquest, args: varargs[string]), args: varargs[string]) =
proc withOutput*(cq: Conquest, outputFunction: proc(cq: Conquest, args: string), args: string) =
cq.hidePrompt()
outputFunction(cq, args)
cq.showPrompt()