diff --git a/KitX Core Contracts/KitX.Core.Contract/Device/IDeviceService.cs b/KitX Core Contracts/KitX.Core.Contract/Device/IDeviceService.cs index cd709c2..790c82c 100644 --- a/KitX Core Contracts/KitX.Core.Contract/Device/IDeviceService.cs +++ b/KitX Core Contracts/KitX.Core.Contract/Device/IDeviceService.cs @@ -1,5 +1,7 @@ using System; using System.ComponentModel; +using System.Net.Http; +using System.Threading; using System.Threading.Tasks; using System.Collections.Generic; using KitX.Shared.CSharp.Device; @@ -238,3 +240,26 @@ public class MainDeviceChangedEventArgs : EventArgs /// public string NewMainDeviceId { get; set; } = string.Empty; } + +/// +/// Device HTTP client interface — sends requests to remote DevicesServer instances. +/// Used for cross-device plugin invocation via the /Api/V1/Plugin/Invoke endpoint. +/// (Moved to Contract so the Workflow library can depend on the abstraction without +/// referencing KitX.Core.) +/// +public interface IDeviceHttpClient +{ + /// + /// Invokes a plugin method on a remote device via HTTP POST to /Api/V1/Plugin/Invoke. + /// + /// Target device info (contains IPv4 and DevicesServerPort) + /// Valid session token for the target device + /// The Request object to send + /// Cancellation token + /// HTTP response from remote device, or null on network error + Task InvokePluginAsync( + DeviceInfo targetDevice, + string token, + KitX.Shared.CSharp.WebCommand.Request request, + CancellationToken ct = default); +} diff --git a/KitX Core Contracts/KitX.Core.Contract/Event/WorkflowEventNames.cs b/KitX Core Contracts/KitX.Core.Contract/Event/WorkflowEventNames.cs new file mode 100644 index 0000000..b7985bb --- /dev/null +++ b/KitX Core Contracts/KitX.Core.Contract/Event/WorkflowEventNames.cs @@ -0,0 +1,21 @@ +namespace KitX.Core.Contract.Event; + +/// +/// Event-bus channel names shared between the Workflow library and its host +/// (KitX.Core / KitX.Dashboard). Centralized here so the workflow library can +/// publish/subscribe on the bus without referencing +/// KitX.Core's own EventNames table. +/// +public static class WorkflowEventNames +{ + /// + /// Plugin response event (carries a RequestId so callers can correlate + /// a fire-and-forget plugin invocation with its reply). + /// + public const string PluginResponse = "PluginResponse"; + + /// + /// Workflow execution result event (success or failure of a workflow run). + /// + public const string WorkflowExecutionResult = "WorkflowExecutionResult"; +} diff --git a/KitX Core Contracts/KitX.Core.Contract/Workflow/BlockDefinition.cs b/KitX Core Contracts/KitX.Core.Contract/Workflow/BlockDefinition.cs deleted file mode 100644 index 9dff4d6..0000000 --- a/KitX Core Contracts/KitX.Core.Contract/Workflow/BlockDefinition.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System.Collections.Generic; - -namespace KitX.Core.Contract.Workflow; - -/// -/// Represents a single block definition in the script -/// -public class BlockDefinition -{ - /// - /// Block type - /// - public BlockType Type { get; set; } - - /// - /// Block name (for NamedBlock) - /// - public string Name { get; set; } = string.Empty; - - /// - /// Variable declarations in this block - /// - public List Variables { get; set; } = []; - - /// - /// Statements in this block (excluding Loop statements, which are separated) - /// - public List Statements { get; set; } = []; - - /// - /// Line number in source where this block starts - /// - public int LineNumber { get; set; } - - /// - /// Name of the next block to execute when this block ends naturally - /// (i.e., not ended by Branch/Loop/ToLoopCond) - /// - public string? NextBlockName { get; set; } - - /// - /// For LoopBlock: the block name containing this loop (i.e., the parent block) - /// - public string? ParentBlockName { get; set; } -} \ No newline at end of file diff --git a/KitX Core Contracts/KitX.Core.Contract/Workflow/BlockScript.cs b/KitX Core Contracts/KitX.Core.Contract/Workflow/BlockScript.cs deleted file mode 100644 index 919ab65..0000000 --- a/KitX Core Contracts/KitX.Core.Contract/Workflow/BlockScript.cs +++ /dev/null @@ -1,93 +0,0 @@ -using System.Collections.Generic; - -namespace KitX.Core.Contract.Workflow; - -/// -/// Parsed block script container -/// -public class BlockScript -{ - /// - /// Global constants block (ConstBlock) - /// - public BlockDefinition? ConstBlock { get; set; } - - /// - /// Public variables block (PubVarBlock) - optional - /// - public BlockDefinition? PubVarBlock { get; set; } - - /// - /// Main entry block (MainBlock) - /// - public BlockDefinition? MainBlock { get; set; } - - /// - /// Named blocks dictionary by name - /// - public Dictionary NamedBlocks { get; set; } = []; - - /// - /// All blocks in order of appearance - /// - public List AllBlocks { get; set; } = []; - - /// - /// Loop blocks dictionary by parent block name - /// (e.g., "MainBlock" -> LoopBlock for MainBlock's Loop statement) - /// - public Dictionary LoopBlocks { get; set; } = []; - - /// - /// Raw source code (parsed input, may not include helper functions) - /// - public string SourceCode { get; set; } = string.Empty; - - /// - /// Full source code including merged helper functions (for execution) - /// - public string FullSourceCode { get; set; } = string.Empty; - - /// - /// Debug mapping from CFG statement IDs to Blueprint node IDs. - /// Populated during BP→BS conversion for use by the debug execution pipeline. - /// - public Dictionary? DebugNodeMapping { get; set; } - - /// - /// Helper functions to be made available in script execution context - /// - public List HelperFunctions { get; set; } = []; - - - /// - /// Gets a block by name (checks LoopBlocks first by block name, then NamedBlocks, then standard blocks) - /// IMPORTANT: LoopBlocks are checked FIRST because LoopBlock names (like "LoopBody") should NOT be - /// shadowed by user-defined NamedBlocks with the same name. - /// - public BlockDefinition? GetBlockByName(string name) - { - // First check LoopBlocks by the block's own name (not parent block name) - // This is critical because LoopBlocks are created for "NextBlock = Loop(...)" statements - // and their names (like "LoopBody") should take precedence over user-defined blocks - foreach (var kvp in LoopBlocks) - { - if (kvp.Value.Name == name) - return kvp.Value; - } - - // Then check NamedBlocks (user-defined blocks) - if (NamedBlocks.TryGetValue(name, out var namedBlock)) - return namedBlock; - - // Then check the standard blocks by name match - if (MainBlock?.Name == name) - return MainBlock; - if (ConstBlock?.Name == name) - return ConstBlock; - if (PubVarBlock?.Name == name) - return PubVarBlock; - - return null; - } -} \ No newline at end of file diff --git a/KitX Core Contracts/KitX.Core.Contract/Workflow/BlockScriptModels.cs b/KitX Core Contracts/KitX.Core.Contract/Workflow/BlockScriptModels.cs deleted file mode 100644 index 860c8a2..0000000 --- a/KitX Core Contracts/KitX.Core.Contract/Workflow/BlockScriptModels.cs +++ /dev/null @@ -1,32 +0,0 @@ -namespace KitX.Core.Contract.Workflow; - -/// -/// Block type enumeration -/// -public enum BlockType -{ - /// - /// Constants block - variables are globally scoped and read-only - /// - ConstBlock, - - /// - /// Main block - entry point, local scope - /// - MainBlock, - - /// - /// Named block - local scope, can be called by name - /// - NamedBlock, - - /// - /// Public variable block - globally scoped and writable, but not exposed in UI editor - /// - PubVarBlock, - - /// - /// Loop block - auto-generated block containing a Loop statement - /// - LoopBlock -} \ No newline at end of file diff --git a/KitX Core Contracts/KitX.Core.Contract/Workflow/FlowControlType.cs b/KitX Core Contracts/KitX.Core.Contract/Workflow/FlowControlType.cs deleted file mode 100644 index 8cfdd0d..0000000 --- a/KitX Core Contracts/KitX.Core.Contract/Workflow/FlowControlType.cs +++ /dev/null @@ -1,32 +0,0 @@ -namespace KitX.Core.Contract.Workflow; - -/// -/// Flow control statement types -/// -public enum FlowControlType -{ - /// - /// Branch to another block based on condition - /// - Branch, - - /// - /// Loop while condition is true (Loop has three args: condition, trueBlock, falseBlock) - /// - Loop, - - /// - /// Return from script execution - /// - Return, - - /// - /// Break from current loop - /// - Break, - - /// - /// To loop condition - marks the end of a loop body and returns to loop condition - /// - ToLoopCond -} \ No newline at end of file diff --git a/KitX Core Contracts/KitX.Core.Contract/Workflow/IBlockScriptParser.cs b/KitX Core Contracts/KitX.Core.Contract/Workflow/IBlockScriptParser.cs deleted file mode 100644 index b911579..0000000 --- a/KitX Core Contracts/KitX.Core.Contract/Workflow/IBlockScriptParser.cs +++ /dev/null @@ -1,125 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace KitX.Core.Contract.Workflow; - -/// -/// Block script parser interface - parses C# scripts with block attributes -/// -public interface IBlockScriptParser -{ - /// - /// Parses a block-based script from source code - /// - /// The C# source code with block attributes - /// Parsed block script result - BlockScriptParseResult Parse(string sourceCode); - - /// - /// Parses a block-based script from source code asynchronously - /// - Task ParseAsync(string sourceCode); - - /// - /// Validates block script syntax and structure - /// - BlockScriptValidationResult Validate(string sourceCode); -} - -/// -/// Block script executor interface - executes parsed block scripts -/// -public interface IBlockScriptExecutor -{ - /// - /// Executes a block script - /// - /// The parsed block script - /// Input parameters - /// Cancellation token - /// Execution result - Task ExecuteAsync( - BlockScript script, - Dictionary? parameters = null, - CancellationToken cancellationToken = default); - - /// - /// Validates a block script - /// - BlockScriptValidationResult Validate(BlockScript script); - - /// - /// Sets an optional debug controller for interactive execution (breakpoints, step, slow). - /// Pass null to disable debug mode. - /// - void SetDebugger(IBlueprintDebugController? debugger); -} - -/// -/// Block scope manager interface - manages variable scoping -/// -public interface IBlockScopeManager -{ - /// - /// Gets the global (ConstBlock) scope - /// - IBlockScope GlobalScope { get; } - - /// - /// Resolves a variable name to its value (searches local then global) - /// - object? ResolveVariable(string name); - - /// - /// Sets a variable value in the appropriate scope - /// - void SetVariable(string name, object? value, bool global = false); - - /// - /// Checks if a variable exists in any scope - /// - bool HasVariable(string name); - - /// - /// Clears all local scopes (called between executions) - /// - void ClearLocalScopes(); -} - -/// -/// Variable scope interface -/// -public interface IBlockScope -{ - /// - /// Name of the block this scope belongs to - /// - string BlockName { get; } - - /// - /// Whether this is the global scope - /// - bool IsGlobal { get; } - - /// - /// Gets a variable value - /// - object? GetVariable(string name); - - /// - /// Sets a variable value - /// - void SetVariable(string name, object? value); - - /// - /// Checks if a variable exists in this scope - /// - bool HasVariable(string name); - - /// - /// Gets all variables in this scope - /// - Dictionary GetAllVariables(); -} diff --git a/KitX Core Contracts/KitX.Core.Contract/Workflow/IBlueprintConverter.cs b/KitX Core Contracts/KitX.Core.Contract/Workflow/IBlueprintConverter.cs index b7a46d0..9107a75 100644 --- a/KitX Core Contracts/KitX.Core.Contract/Workflow/IBlueprintConverter.cs +++ b/KitX Core Contracts/KitX.Core.Contract/Workflow/IBlueprintConverter.cs @@ -4,48 +4,12 @@ namespace KitX.Core.Contract.Workflow; /// -/// Interface for converting BlockScript to Blueprint -/// -public interface IBlockScriptToBlueprintConverter -{ - /// - /// Convert BlockScript source code to Blueprint - /// - /// BlockScript source code - /// Helper functions available - /// Converted Blueprint - Blueprint Convert(string sourceCode, List? helperFunctions = null); - - /// - /// Convert parsed BlockScript to Blueprint - /// - /// Parsed BlockScript - /// Converted Blueprint - Blueprint Convert(BlockScript script); -} - -/// -/// Interface for converting Blueprint to BlockScript -/// -public interface IBlueprintToBlockScriptConverter -{ - /// - /// Convert Blueprint to BlockScript source code - /// - /// Blueprint to convert - /// BlockScript source code - string Convert(Blueprint blueprint); - - /// - /// Convert Blueprint to parsed BlockScript - /// - /// Blueprint to convert - /// Parsed BlockScript - BlockScript ConvertToBlockScript(Blueprint blueprint); -} - -/// -/// Interface for Blueprint service +/// Interface for Blueprint service. +/// +/// Kept in the public Contract surface (Dashboard consumes it). The lower-level +/// converters (IBlockScriptToBlueprintConverter, +/// IBlueprintToBlockScriptConverter) are internal to the workflow pipeline +/// and live in the KitX.Workflow library. /// public interface IBlueprintService { diff --git a/KitX Core Contracts/KitX.Core.Contract/Workflow/ILayoutService.cs b/KitX Core Contracts/KitX.Core.Contract/Workflow/ILayoutService.cs deleted file mode 100644 index c146bbe..0000000 --- a/KitX Core Contracts/KitX.Core.Contract/Workflow/ILayoutService.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace KitX.Core.Contract.Workflow; - -/// -/// Interface for layout service -/// -public interface ILayoutService -{ - void LayoutNodes(Blueprint blueprint); -} diff --git a/KitX Core Contracts/KitX.Core.Contract/Workflow/INodeExportStrategy.cs b/KitX Core Contracts/KitX.Core.Contract/Workflow/INodeExportStrategy.cs deleted file mode 100644 index 918a998..0000000 --- a/KitX Core Contracts/KitX.Core.Contract/Workflow/INodeExportStrategy.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System.Collections.Generic; - -namespace KitX.Core.Contract.Workflow; - -/// -/// Helper service providing data resolution utilities for node export strategies. -/// Implemented by BlueprintToBlockScriptConverter. -/// -public interface INodeExportHelper -{ - /// -/// Resolves the input value for a pin by tracing data connections. -/// Returns ConstName for const references, PubVarName for pubvar references, -/// or the pin's default value. -/// - string GetInputValue(BlueprintNode node, string pinName); - - /// -/// Resolves all non-Exec input arguments for a node, returning them as a comma-separated string. -/// - string GetInputArgs(BlueprintNode node); - - /// - /// The blueprint being converted. - /// - Blueprint Blueprint { get; } - - /// - /// Returns the PubVar name assigned to the given output pin, or null if no data connection exists. - /// - string? GetOutputPubVar(BlueprintNode node, string pinName); - - /// - /// Returns true if the given output pin is consumed by at least one data connection. - /// - bool IsOutputConsumed(BlueprintNode node, string pinName); -} - -/// -/// Strategy for converting a specific node type to a BlockScript statement. -/// Each node type that participates in reverse conversion provides an implementation, -/// eliminating the need for switch-based dispatch in the converter. -/// -public interface INodeExportStrategy -{ - /// -/// The node type this strategy handles. -/// - BlueprintNodeType NodeType { get; } - - /// -/// Whether this node type represents a control flow construct (Branch, Loop, etc.). -/// Used by the converter to determine main flow termination and sub-graph processing. -/// - bool IsControlFlow { get; } - - /// -/// Converts the node to a BlockScript statement, or null if the node should be skipped. -/// - BlockStatement? ToStatement(BlueprintNode node, INodeExportHelper helper); - - /// -/// For control flow nodes: returns the output arm configuration. -/// Each arm defines an output pin name and whether it represents a loopback. -/// Non-control-flow strategies return an empty collection. -/// - IEnumerable GetOutputArms(BlueprintNode node); -} - -/// -/// Describes a single output arm of a control flow node (e.g., Branch's True/False, Loop's LoopBody/LoopEnd). -/// -public struct OutputArmDescriptor -{ - /// -/// The output pin name (e.g., Pins.True, Pins.False, Pins.LoopBody, Pins.LoopEnd) -/// - public string PinName { get; set; } - - /// -/// Whether this arm loops back to a parent node (LoopBody loops back to the Loop node) -/// - public bool IsLoopback { get; set; } -} diff --git a/KitX Core Contracts/KitX.Core.Contract/Workflow/IPluginManager.cs b/KitX Core Contracts/KitX.Core.Contract/Workflow/IPluginManager.cs deleted file mode 100644 index 9b4c62c..0000000 --- a/KitX Core Contracts/KitX.Core.Contract/Workflow/IPluginManager.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace KitX.Core.Contract.Workflow; - -/// -/// 插件管理器接口 - BlockScripting 使用此接口调用插件方法。 -/// Copy of Kscript.CSharp.Parser.Core.IPluginManager for BlockScripting use -/// without depending on the KCS parser assembly. -/// 实际实现由外部项目(RealPluginManager)提供。 -/// -public interface IPluginManager -{ - /// - /// 调用插件方法 - /// - /// 返回值类型 - /// 调用信息 - /// 插件方法的返回值 - T Call(PluginCallInfo callInfo); - - /// - /// 调用插件方法(无返回值) - /// - /// 调用信息 - void Call(PluginCallInfo callInfo); - - /// - /// 检查插件是否存在 - /// - /// 插件名称 - /// 插件是否存在 - bool IsPluginExists(string pluginName); - - /// - /// 检查插件方法是否存在 - /// - /// 插件名称 - /// 方法名称 - /// 方法是否存在 - bool IsMethodExists(string pluginName, string methodName); -} \ No newline at end of file diff --git a/KitX Core Contracts/KitX.Core.Contract/Workflow/IRealPluginManagerBridge.cs b/KitX Core Contracts/KitX.Core.Contract/Workflow/IRealPluginManagerBridge.cs new file mode 100644 index 0000000..1b2c90e --- /dev/null +++ b/KitX Core Contracts/KitX.Core.Contract/Workflow/IRealPluginManagerBridge.cs @@ -0,0 +1,17 @@ +namespace KitX.Core.Contract.Workflow; + +/// +/// Marker/bridge interface for the concrete plugin manager implementation +/// used by the workflow subsystem. +/// +/// Dashboard resolves this interface once at startup (via +/// GetRequiredService<IRealPluginManagerBridge>()) purely to force eager +/// singleton construction — the concrete RealPluginManager subscribes to plugin +/// message events in its constructor, so the instance must exist before plugins +/// connect. The interface itself carries no members; callers that need to +/// invoke plugin methods depend on the workflow library's own IPluginManager +/// contract instead. +/// +public interface IRealPluginManagerBridge +{ +} diff --git a/KitX Core Contracts/KitX.Core.Contract/Workflow/ITriggerManager.cs b/KitX Core Contracts/KitX.Core.Contract/Workflow/ITriggerManager.cs new file mode 100644 index 0000000..2431557 --- /dev/null +++ b/KitX Core Contracts/KitX.Core.Contract/Workflow/ITriggerManager.cs @@ -0,0 +1,34 @@ +namespace KitX.Core.Contract.Workflow; + +/// +/// Routes plugin trigger signals to the workflows that subscribed to them. +/// +/// A trigger is a pure signal (equivalent to pressing the "Run" button); it carries +/// no business payload. Plugins fire triggers via the TriggerFired command; the +/// matches the firing plugin/trigger against registered +/// subscriptions and runs each matching workflow. +/// +public interface ITriggerManager +{ + /// + /// Registers a workflow's trigger configuration so that matching + /// TriggerFired events from plugins will run the workflow. + /// Only PluginEvent triggers with a non-empty plugin name take effect. + /// + /// The workflow identifier. + /// The trigger configuration. + void RegisterWorkflowTrigger(string workflowId, TriggerConfig config); + + /// + /// Removes the trigger subscription for a workflow (e.g. on delete/rename). + /// + /// The workflow identifier. + void UnregisterWorkflowTrigger(string workflowId); + + /// + /// Scans persisted workflow files and re-subscribes all configured triggers. + /// Called once after DI initialization completes, before plugins connect, so + /// that TriggerFired events arriving early can still be routed. + /// + void InitializeFromPersistedWorkflows(); +} diff --git a/KitX Core Contracts/KitX.Core.Contract/Workflow/IWorkflowService.cs b/KitX Core Contracts/KitX.Core.Contract/Workflow/IWorkflowService.cs index 192b49b..9bfa7cb 100644 --- a/KitX Core Contracts/KitX.Core.Contract/Workflow/IWorkflowService.cs +++ b/KitX Core Contracts/KitX.Core.Contract/Workflow/IWorkflowService.cs @@ -75,20 +75,16 @@ public interface IWorkflowPluginService } /// -/// Block script service interface +/// Block script service interface — the public surface consumed by Dashboard. +/// +/// Only methods that take primitive/source parameters (string, List<HelperFunction>, ...) +/// or return Dashboard-visible result types are kept here. Pipeline-internal methods that +/// deal in the parsed BlockScript / BlockScriptParseResult models live on the +/// workflow library's internal IBlockScriptPipelineService instead, so that those +/// internal models need not be exposed through Contract. /// public interface IBlockScriptService { - /// - /// Parses a block script - /// - BlockScriptParseResult ParseBlockScript(string sourceCode); - - /// - /// Parses a block script asynchronously - /// - Task ParseBlockScriptAsync(string sourceCode); - /// /// Validates a block script /// @@ -100,14 +96,6 @@ public interface IBlockScriptService /// List ParseConstantsFromBlockScript(string sourceCode); - /// - /// Executes a block script - /// - Task ExecuteBlockScriptAsync( - BlockScript script, - Dictionary? parameters = null, - System.Threading.CancellationToken cancellationToken = default); - /// /// Executes a block script from source code /// @@ -134,14 +122,6 @@ Task ExecuteBlockScriptAsync( Dictionary? constantOverrides, System.Threading.CancellationToken cancellationToken = default); - /// - /// Compiles a BlockScript and persists the compiled assembly to disk. - /// - /// The parsed BlockScript to compile. - /// The workflow ID for assembly naming. - /// True if compilation and persistence succeeded. - Task CompileAndPersistAsync(BlockScript script, string workflowId); - /// /// Preloads all persisted compiled scripts for a workflow from disk. /// diff --git a/KitX Core Contracts/KitX.Core.Contract/Workflow/PluginCallInfo.cs b/KitX Core Contracts/KitX.Core.Contract/Workflow/PluginCallInfo.cs deleted file mode 100644 index 3f19863..0000000 --- a/KitX Core Contracts/KitX.Core.Contract/Workflow/PluginCallInfo.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; - -namespace KitX.Core.Contract.Workflow; - -/// -/// 插件调用信息,用于传递给 IPluginManager.Call 的参数。 -/// Copy of Kscript.CSharp.Parser.Models.PluginCallInfo for BlockScripting use -/// without depending on the KCS parser assembly. -/// -public class PluginCallInfo -{ - /// - /// 插件名称 - /// - public string PluginName { get; set; } = string.Empty; - - /// - /// 方法名称 - /// - public string MethodName { get; set; } = string.Empty; - - /// - /// 方法参数值数组 - /// - public object[] Parameters { get; set; } = Array.Empty(); - - /// - /// 参数类型数组 - /// - public Type[] ParameterTypes { get; set; } = Array.Empty(); - - /// - /// 参数名称数组 - /// - public string[] ParameterNames { get; set; } = Array.Empty(); - - /// - /// 目标设备名称(远程调用时使用)。如果为空或 null,则为本地调用。 - /// - public string? TargetDevice { get; set; } - - public PluginCallInfo() - { - } - - public PluginCallInfo(string pluginName, string methodName, object[] parameters, Type[] parameterTypes, string[] parameterNames) - { - PluginName = pluginName; - MethodName = methodName; - Parameters = parameters; - ParameterTypes = parameterTypes; - ParameterNames = parameterNames; - } - - public override string ToString() - { - return $"{PluginName}.{MethodName}({string.Join(", ", Parameters)})"; - } -} \ No newline at end of file diff --git a/KitX Core Contracts/KitX.Core.Contract/Workflow/Results/BlockExecutionResult.cs b/KitX Core Contracts/KitX.Core.Contract/Workflow/Results/BlockExecutionResult.cs deleted file mode 100644 index 056f78d..0000000 --- a/KitX Core Contracts/KitX.Core.Contract/Workflow/Results/BlockExecutionResult.cs +++ /dev/null @@ -1,48 +0,0 @@ -namespace KitX.Core.Contract.Workflow; - -/// -/// Result of executing a block - used by state machine for flow control -/// -public class BlockExecutionResult -{ - /// - /// Whether execution should continue to next block - /// - public bool ShouldContinue { get; set; } = true; - - /// - /// Name of the next block to execute (null means end of script) - /// - public string? NextBlockName { get; set; } - - /// - /// Whether this is a return (end of entire script) - /// - public bool IsReturn { get; set; } - - /// - /// Return value if IsReturn is true - /// - public object? ReturnValue { get; set; } - - /// - /// Create a result for continuing to next block - /// - public static BlockExecutionResult ContinueTo(string? nextBlockName) => new() - { - ShouldContinue = true, - NextBlockName = nextBlockName, - IsReturn = false - }; - - /// - /// Create a result for end of script - /// - public static BlockExecutionResult Return(object? value = null) => new() - { - ShouldContinue = false, - NextBlockName = null, - IsReturn = true, - ReturnValue = value - }; -} \ No newline at end of file diff --git a/KitX Core Contracts/KitX.Core.Contract/Workflow/Results/BlockScriptParseResult.cs b/KitX Core Contracts/KitX.Core.Contract/Workflow/Results/BlockScriptParseResult.cs deleted file mode 100644 index 594eee5..0000000 --- a/KitX Core Contracts/KitX.Core.Contract/Workflow/Results/BlockScriptParseResult.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace KitX.Core.Contract.Workflow; - -/// -/// Result of parsing operation -/// -public class BlockScriptParseResult -{ - /// - /// Whether parsing was successful - /// - public bool IsSuccess { get; set; } - - /// - /// Error message if parsing failed - /// - public string? ErrorMessage { get; set; } - - /// - /// Line number where error occurred - /// - public int ErrorLine { get; set; } - - /// - /// The parsed script if successful - /// - public BlockScript? Script { get; set; } -} \ No newline at end of file diff --git a/KitX Core Contracts/KitX.Core.Contract/Workflow/Statements/BlockStatement.cs b/KitX Core Contracts/KitX.Core.Contract/Workflow/Statements/BlockStatement.cs deleted file mode 100644 index 57c1e35..0000000 --- a/KitX Core Contracts/KitX.Core.Contract/Workflow/Statements/BlockStatement.cs +++ /dev/null @@ -1,24 +0,0 @@ -namespace KitX.Core.Contract.Workflow; - -/// -/// Base class for statements within a block -/// -public abstract class BlockStatement -{ - /// - /// Debug statement ID — preserved through BP⇄BS round-trip. - /// Set by CFG→BS conversion; consumed by BS→CFG conversion. - /// Empty means "unset; generate a new ID". - /// - public string StatementId { get; set; } = string.Empty; - - /// - /// Line number in source - /// - public int LineNumber { get; set; } - - /// - /// Original source code for this statement - /// - public string SourceCode { get; set; } = string.Empty; -} \ No newline at end of file diff --git a/KitX Core Contracts/KitX.Core.Contract/Workflow/Statements/ExpressionStatement.cs b/KitX Core Contracts/KitX.Core.Contract/Workflow/Statements/ExpressionStatement.cs deleted file mode 100644 index 2d32e60..0000000 --- a/KitX Core Contracts/KitX.Core.Contract/Workflow/Statements/ExpressionStatement.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace KitX.Core.Contract.Workflow; - -/// -/// Expression statement -/// -public class ExpressionStatement : BlockStatement -{ - /// - /// The expression to execute - /// - public string Expression { get; set; } = string.Empty; -} \ No newline at end of file diff --git a/KitX Core Contracts/KitX.Core.Contract/Workflow/Statements/FlowControlStatement.cs b/KitX Core Contracts/KitX.Core.Contract/Workflow/Statements/FlowControlStatement.cs deleted file mode 100644 index 728e0ca..0000000 --- a/KitX Core Contracts/KitX.Core.Contract/Workflow/Statements/FlowControlStatement.cs +++ /dev/null @@ -1,51 +0,0 @@ -namespace KitX.Core.Contract.Workflow; - -/// -/// Flow control statement -/// -public class FlowControlStatement : BlockStatement -{ - /// - /// Type of flow control - /// - public FlowControlType ControlType { get; set; } - - /// - /// Condition expression (for Branch/Loop) - /// - public string ConditionExpression { get; set; } = string.Empty; - - /// - /// Target block name when condition is true (for Branch/Loop) - /// - public string TrueBlockName { get; set; } = string.Empty; - - /// - /// Target block name when condition is false (for Branch/Loop) - /// For Loop: this is the loop exit block - /// - public string FalseBlockName { get; set; } = string.Empty; - - /// - /// For ToLoopCond: the block name containing the Loop statement to return to - /// - public string? ToLoopCondReturnTo { get; set; } - - /// - /// Regenerates SourceCode from current field values. - /// Call after updating TrueBlockName/FalseBlockName/etc. to keep SourceCode in sync. - /// - public void RegenerateSourceCode() - { - SourceCode = ControlType switch - { - FlowControlType.Branch => $"NextBlock = Branch({ConditionExpression}, \"{TrueBlockName}\", \"{FalseBlockName}\");", - FlowControlType.Loop => $"NextBlock = Loop({ConditionExpression}, \"{TrueBlockName}\", \"{FalseBlockName}\");", - FlowControlType.ToLoopCond => ToLoopCondReturnTo != null - ? $"NextBlock = ToLoopCond(\"{ToLoopCondReturnTo}\");" - : "ToLoopCond();", - FlowControlType.Break => "Break();", - _ => SourceCode - }; - } -} \ No newline at end of file diff --git a/KitX Core Contracts/KitX.Core.Contract/Workflow/Statements/VariableDeclarationStatement.cs b/KitX Core Contracts/KitX.Core.Contract/Workflow/Statements/VariableDeclarationStatement.cs deleted file mode 100644 index 4f6c4ef..0000000 --- a/KitX Core Contracts/KitX.Core.Contract/Workflow/Statements/VariableDeclarationStatement.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace KitX.Core.Contract.Workflow; - -/// -/// Variable declaration statement -/// -public class VariableDeclarationStatement : BlockStatement -{ - /// - /// The variable declaration - /// - public VariableDeclaration Declaration { get; set; } = new(); -} \ No newline at end of file diff --git a/KitX Core Contracts/KitX.Core.Contract/Workflow/VariableDeclaration.cs b/KitX Core Contracts/KitX.Core.Contract/Workflow/VariableDeclaration.cs deleted file mode 100644 index 492007a..0000000 --- a/KitX Core Contracts/KitX.Core.Contract/Workflow/VariableDeclaration.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace KitX.Core.Contract.Workflow; - -/// -/// Variable declaration -/// -public class VariableDeclaration -{ - /// - /// Variable name - /// - public string Name { get; set; } = string.Empty; - - /// - /// Variable type as string - /// - public string Type { get; set; } = "object"; - - /// - /// Initial value expression as string (for evaluation at parse time or execution time) - /// - public string? InitialValueExpression { get; set; } - - /// - /// Default value (pre-evaluated for const block) - /// - public object? DefaultValue { get; set; } -} \ No newline at end of file