MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / build_tool_detail

Function build_tool_detail

atomic-agent/src/provenance/accumulator/helpers.rs:96–268  ·  view source on GitHub ↗

Build the `detail` JSON for a tool-derived node.

(
    kind: NodeKind,
    tool_name: &str,
    tool_input: Option<&serde_json::Value>,
    tool_output: Option<&str>,
    status: Option<&str>,
)

Source from the content-addressed store, hash-verified

94
95/// Build the `detail` JSON for a tool-derived node.
96pub(crate) fn build_tool_detail(
97 kind: NodeKind,
98 tool_name: &str,
99 tool_input: Option<&serde_json::Value>,
100 tool_output: Option<&str>,
101 status: Option<&str>,
102) -> Option<serde_json::Value> {
103 match kind {
104 NodeKind::Exploration => {
105 let path = tool_input
106 .and_then(|v| {
107 v.get("path")
108 .or_else(|| v.get("file"))
109 .or_else(|| v.get("glob"))
110 .or_else(|| v.get("regex"))
111 })
112 .and_then(|v| v.as_str());
113 path.map(|p| serde_json::json!({"tool": tool_name, "target": p}))
114 }
115
116 NodeKind::Commitment => {
117 // Extract file path from tool_input — OpenCode uses "filePath" (camelCase)
118 // while other agents may use "path", "file", or "file_path" (snake_case).
119 // Also check the top-level "file_path" field added by the enriched plugin.
120 let path = tool_input
121 .and_then(|v| {
122 v.get("filePath")
123 .or_else(|| v.get("path"))
124 .or_else(|| v.get("file"))
125 .or_else(|| v.get("file_path"))
126 })
127 .and_then(|v| v.as_str());
128
129 let mut detail = serde_json::json!({"tool": tool_name});
130
131 if let Some(p) = path {
132 // Store both the full path and a shortened display path
133 detail["file_path"] = serde_json::Value::String(p.to_string());
134 // Shorten: take last 2-3 path components for display
135 let short = shorten_path(p);
136 detail["file"] = serde_json::Value::String(short);
137 }
138
139 // Determine operation: create vs edit
140 // "write" tool = create (new file), "edit"/"multiedit"/"patch" = edit
141 let operation = match tool_name.to_lowercase().as_str() {
142 "write" | "write_file" | "create" | "create_file" => "create",
143 "delete_file" | "remove_file" => "delete",
144 _ => "edit",
145 };
146 detail["operation"] = serde_json::Value::String(operation.to_string());
147
148 // Pull in filediff from the enriched after-tool payload if present.
149 // The plugin sends: { filediff: { file, before, after, additions, deletions } }
150 if let Some(filediff) = tool_input.and_then(|v| v.get("filediff")).cloned() {
151 detail["filediff"] = filediff;
152 }
153

Callers 2

enrich_opencode_turnMethod · 0.85
append_tool_callMethod · 0.85

Calls 5

shorten_pathFunction · 0.85
getMethod · 0.65
as_strMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected