Skip to content

Commit ad47224

Browse files
authored
Preserve native tool identity in chat (#1078)
1 parent 90df4a4 commit ad47224

18 files changed

Lines changed: 3443 additions & 464 deletions

‎docs/ARCHITECTURE.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ These are the canonical homes. Do not reintroduce private copies elsewhere.
5959
| Presentation-layer DI composition root | `AppServiceRegistration` (root `ServiceProvider`, owned by `App`) | authoritative |
6060
| Settings snapshot read + batched save + non-echoing change notification | `ISettingsStore` | authoritative |
6161
| Settings page load/persist view logic | `SettingsPageViewModel` | authoritative |
62+
| Native tool identity, display arguments, payload extraction, and flattened-history projection | `NativeToolProjector` | authoritative |
6263
| Managed-local listener provenance and strong-credential authorization | `ManagedLocalGatewayPortProvenanceService` | authoritative |
6364
| Managed-local automatic repair eligibility and orchestration | `ManagedLocalGatewayAutoRepairMonitor` + `ManagedLocalGatewayRepairCoordinator` | authoritative |
6465
| Capability UI metadata | `NodeCapabilityUiCatalog` (planned) | planned |
@@ -72,7 +73,7 @@ These are the canonical homes. Do not reintroduce private copies elsewhere.
7273
| If you are editing… | Do not grow it. Extract toward… |
7374
| --- | --- |
7475
| `src/OpenClaw.Tray.WinUI/App.xaml.cs` | `IWindowManager`, `ITrayController`, `IActivationRouter`, `ISettingsChangeCoordinator`, `AppBootstrapper` |
75-
| `src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs` | `ChatSendQueue`, `ChatBridgeEventPump`, `ChatHistoryLoader`, `ChatSnapshotProjector`, `AttachmentMetadataStore` |
76+
| `src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs` | `ChatSendQueue`, `ChatBridgeEventPump`, `ChatHistoryLoader`, `ChatSnapshotProjector`, `AttachmentMetadataStore`; pure native tool projection stays in `NativeToolProjector` |
7677
| `src/OpenClaw.Tray.WinUI/Chat/OpenClawChatTimeline.cs` | `ReactorChatTimeline` (production `ItemsView` / `ItemContainer`), `ChatBubbleRenderer`, `ToolCallCardRenderer`, `PermissionRequestCard`, `AttachmentBubbleRenderer` |
7778
| `src/OpenClaw.Tray.WinUI/Chat/OpenClawComposer.cs` | `ComposerViewModel`, `SlashCommandPalette`, `AttachmentPreviewStrip`, `VoiceComposerController` |
7879
| `src/OpenClaw.Tray.WinUI/Pages/ConnectionPage.xaml.cs` | `ConnectionPagePlan` (pure), `ConnectionPageViewModel`, gateway row models |
@@ -125,6 +126,8 @@ leading and trailing pipe. Columns, in order:
125126
| app-window-manager | planned | src/OpenClaw.Tray.WinUI/App.xaml.cs | window creation/show/hide/shutdown | IWindowManager | composition/delegation only | startup/shutdown ordering deterministic; disposed once | none | review-only | extracted in Phase 3 |
126127
| app-tray-controller | planned | src/OpenClaw.Tray.WinUI/App.xaml.cs | tray icon/menu/action routing | ITrayController | composition/delegation only | tray actions route unchanged | none | review-only | extracted in Phase 3 |
127128
| app-activation-router | planned | src/OpenClaw.Tray.WinUI/App.xaml.cs | deep-link/toast/single-instance activation | IActivationRouter | composition/delegation only | activation routes land on the same UI/actions; current-user pipe security preserved | none | review-only | extracted in Phase 3 |
129+
| native-tool-projector | authoritative | src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs | pure native tool identity, allowlisted display arguments, payload extraction, and flattened-history detection/classification/summary | NativeToolProjector | provider calls the projector while retaining stateful live/history application and metadata cache behavior | unknown identities remain truthful Tool; title aliases are strict; display arguments are allowlisted, redacted, and bounded; live/history projection stays consistent | NativeToolProjectorTests.ExtractToolIdentity_TitleRequiresExactTrustedAlias | behavioral | - |
130+
| provider-native-tool-projection-closed | closed | src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs | private static copies of native tool identity, display argument, payload, and flattened-history projection | NativeToolProjector | provider owns run/session/legacy-generation correlation, metadata cache persistence/upsert/migration/matching, active run IDs, and timeline state | provider does not regain pure native tool projection or duplicate NativeToolProjector compatibility wrappers | review-only: the provider retains stateful orchestration and calls the focused projector directly | review-only | when OpenClawChatDataProvider no longer applies native tool events or history |
128131
| chat-send-queue | planned | src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs | send queue/admission/abort state | ChatSendQueue | - | queued send/abort/generation semantics preserved | none | review-only | extracted in Phase 4 |
129132
| gateway-pending-requests | planned | src/OpenClaw.Shared/OpenClawGatewayClient.cs | request-id -> method/completion tracking | PendingRequestRegistry | - | request ids never leak after disconnect; thread-safe | none | review-only | extracted in Phase 4 |
130133
| connect-envelope | planned | src/OpenClaw.Shared/OpenClawGatewayClient.cs + WindowsNodeClient.cs | connect message + auth precedence + signature version | ConnectEnvelopeBuilder | - | credential precedence never downgrades a device token; v3->v2 fallback preserved | none | review-only | extracted in Phase 4 |

‎src/OpenClaw.Chat/ChatModels.cs‎

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ public enum ChatToolCallStatus
8383
Interrupted
8484
}
8585

86+
public enum ChatToolIdentityStrength
87+
{
88+
Fallback,
89+
Heuristic,
90+
Specific,
91+
Explicit
92+
}
93+
8694
public enum ChatTone
8795
{
8896
Info,
@@ -137,7 +145,17 @@ public record ChatTimelineItem(
137145
string? ToolCallId = null,
138146
string? PermissionRequestId = null,
139147
ChatPermissionDecision PermissionDecision = ChatPermissionDecision.Pending,
140-
IReadOnlyList<string>? PermissionActions = null);
148+
IReadOnlyList<string>? PermissionActions = null,
149+
ChatToolIdentityStrength ToolIdentityStrength = ChatToolIdentityStrength.Fallback,
150+
System.Collections.Immutable.ImmutableHashSet<string>? ToolCorrelationIds = null,
151+
long ToolOutcomeSequence = 0,
152+
string? ToolRunId = null,
153+
long ToolLegacyTurn = 0);
154+
155+
public readonly record struct ChatToolCorrelationKey(
156+
string? RunId,
157+
long LegacyTurn,
158+
string ToolCallId);
141159

142160
public record ChatPermissionRequest(string RequestId, string PermissionKind, string ToolName, string Detail, IReadOnlyList<string>? Actions = null);
143161

@@ -150,17 +168,38 @@ public record ChatTimelineState(
150168
string? ActiveToolCallId,
151169
string? CurrentIntent,
152170
System.Collections.Immutable.ImmutableHashSet<string> LocalNonces,
153-
System.Collections.Immutable.ImmutableDictionary<string, string> ActiveToolCalls,
171+
System.Collections.Immutable.ImmutableDictionary<ChatToolCorrelationKey, string> ActiveToolCalls,
154172
bool HistoryLoaded = false,
155-
ChatPermissionRequest? PendingPermission = null)
173+
ChatPermissionRequest? PendingPermission = null,
174+
System.Collections.Immutable.ImmutableDictionary<ChatToolCorrelationKey, ChatPendingToolPresentation>? PendingToolPresentations = null,
175+
System.Collections.Immutable.ImmutableDictionary<ChatToolCorrelationKey, ChatPendingToolOutcome>? PendingToolOutcomes = null,
176+
System.Collections.Immutable.ImmutableDictionary<ChatToolCorrelationKey, long>? TerminalToolCorrelations = null,
177+
long NextToolOutcomeSequence = 1,
178+
long NextToolCorrelationSequence = 1,
179+
long ToolLegacyTurn = 1)
156180
{
157181
public static ChatTimelineState Initial() => new(
158182
System.Collections.Immutable.ImmutableList<ChatTimelineItem>.Empty,
159183
false, 1, null, null, null, null,
160184
System.Collections.Immutable.ImmutableHashSet<string>.Empty,
161-
System.Collections.Immutable.ImmutableDictionary<string, string>.Empty);
185+
System.Collections.Immutable.ImmutableDictionary<ChatToolCorrelationKey, string>.Empty,
186+
PendingToolPresentations: System.Collections.Immutable.ImmutableDictionary<ChatToolCorrelationKey, ChatPendingToolPresentation>.Empty,
187+
PendingToolOutcomes: System.Collections.Immutable.ImmutableDictionary<ChatToolCorrelationKey, ChatPendingToolOutcome>.Empty,
188+
TerminalToolCorrelations: System.Collections.Immutable.ImmutableDictionary<ChatToolCorrelationKey, long>.Empty);
162189
}
163190

191+
public record ChatPendingToolPresentation(
192+
string ToolName,
193+
ChatToolIdentityStrength IdentityStrength,
194+
JsonObject? ToolArgs,
195+
System.Collections.Immutable.ImmutableHashSet<string> CorrelationIds,
196+
long Sequence = 0);
197+
198+
public record ChatPendingToolOutcome(
199+
string Text,
200+
ChatToolCallStatus Status,
201+
long Sequence);
202+
164203
public enum ChatQueuedMessageSendState
165204
{
166205
Queued,
@@ -194,9 +233,30 @@ public record ChatMessageEvent(string Text, string? ReasoningText = null, bool R
194233
public record ChatMessageDeltaEvent(string Text) : ChatEvent;
195234
public record ChatTurnEndEvent() : ChatEvent;
196235
public record ChatIntentEvent(string Intent) : ChatEvent;
197-
public record ChatToolStartEvent(string Text, string ToolName, JsonObject? ToolArgs = null, string? ToolCallId = null) : ChatEvent;
198-
public record ChatToolOutputEvent(string Text, string? ToolCallId = null) : ChatEvent;
199-
public record ChatToolErrorEvent(string Text, string? ToolCallId = null) : ChatEvent;
236+
public record ChatToolStartEvent(
237+
string Text,
238+
string ToolName,
239+
JsonObject? ToolArgs = null,
240+
string? ToolCallId = null,
241+
ChatToolIdentityStrength IdentityStrength = ChatToolIdentityStrength.Explicit,
242+
string? RunId = null) : ChatEvent;
243+
public record ChatToolPresentationEvent(
244+
string ParentToolCallId,
245+
string ToolName,
246+
ChatToolIdentityStrength IdentityStrength,
247+
JsonObject? ToolArgs = null,
248+
string? ChildToolCallId = null,
249+
bool ActivatesTurn = true,
250+
string? RunId = null) : ChatEvent;
251+
public record ChatToolOutputEvent(
252+
string Text,
253+
string? ToolCallId = null,
254+
string? RunId = null) : ChatEvent;
255+
public record ChatToolErrorEvent(
256+
string Text,
257+
string? ToolCallId = null,
258+
string? RunId = null) : ChatEvent;
259+
public record ChatToolReplayResetEvent : ChatEvent;
200260
public record ChatContextChangedEvent(string? Cwd, string? GitBranch) : ChatEvent;
201261
public record ChatStatusEvent(string Text, ChatTone Tone) : ChatEvent;
202262
public record ChatErrorEvent(string Text) : ChatEvent;

0 commit comments

Comments
 (0)