-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathCommandClassifier.cs
More file actions
89 lines (80 loc) · 3.23 KB
/
CommandClassifier.cs
File metadata and controls
89 lines (80 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using Newtonsoft.Json.Linq;
namespace MCPForUnity.Editor.Tools
{
/// <summary>
/// Refines a tool's ExecutionTier based on action-level parameters.
/// Tools declare a base tier via [McpForUnityTool(Tier=...)]; this classifier
/// can promote or demote based on specific action strings or param values.
/// </summary>
public static class CommandClassifier
{
/// <summary>
/// Classify a single command. Returns the effective tier after action-level overrides.
/// </summary>
public static ExecutionTier Classify(string toolName, ExecutionTier attributeTier, JObject @params)
{
if (@params == null) return attributeTier;
string action = @params.Value<string>("action");
return toolName switch
{
"manage_scene" => ClassifyManageScene(action, attributeTier),
"refresh_unity" => ClassifyRefreshUnity(@params, attributeTier),
"manage_editor" => ClassifyManageEditor(action, attributeTier),
_ => attributeTier
};
}
/// <summary>
/// Classify a batch of commands. Returns the highest (most restrictive) tier.
/// </summary>
public static ExecutionTier ClassifyBatch(
(string toolName, ExecutionTier attributeTier, JObject @params)[] commands)
{
var max = ExecutionTier.Instant;
foreach (var (toolName, attributeTier, @params) in commands)
{
var tier = Classify(toolName, attributeTier, @params);
if (tier > max) max = tier;
}
return max;
}
/// <summary>
/// Returns true if the given command would trigger a domain reload (compilation or play mode entry).
/// </summary>
public static bool CausesDomainReload(string toolName, JObject @params)
{
if (@params == null) return false;
return toolName switch
{
"refresh_unity" => @params.Value<string>("compile") != "none",
"manage_editor" => @params.Value<string>("action") == "play",
_ => false
};
}
static ExecutionTier ClassifyManageScene(string action, ExecutionTier fallback)
{
return action switch
{
"get_hierarchy" or "get_active" or "get_build_settings" or "screenshot"
=> ExecutionTier.Instant,
"create" or "load" or "save"
=> ExecutionTier.Heavy,
_ => fallback
};
}
static ExecutionTier ClassifyRefreshUnity(JObject @params, ExecutionTier fallback)
{
string compile = @params.Value<string>("compile");
if (compile == "none") return ExecutionTier.Smooth;
return fallback; // Heavy by default
}
static ExecutionTier ClassifyManageEditor(string action, ExecutionTier fallback)
{
return action switch
{
"telemetry_status" or "telemetry_ping" => ExecutionTier.Instant,
"play" or "pause" or "stop" => ExecutionTier.Heavy,
_ => fallback
};
}
}
}