MCPcopy Create free account
hub / github.com/FSoft-AI4Code/CodeWiki / handle_get_processing_order

Function handle_get_processing_order

codewiki/mcp/tools/module_tree.py:109–146  ·  view source on GitHub ↗

Write the leaf-first processing order to a workspace file and return its path.

(
    arguments: Dict[str, Any],
    store: SessionStore,
)

Source from the content-addressed store, hash-verified

107 Returns ``(unmatched_ids, leftover_ids)``:
108 * ``unmatched_ids``: ids referenced by the tree that do not exist in the
109 index (typos / drift) -- they will be silently omitted from docs.
110 * ``leftover_ids``: clustering candidate ids (leaf nodes) that are not
111 assigned to any module -- a coverage gap for the current clustering.
112 Non-candidate components (excluded / non-essential) are intentionally
113 not reported as leftover.
114 """
115 assigned = _collect_component_ids(module_tree)
116 unmatched = sorted(assigned - known_ids)
117 leftover = sorted(candidate_ids - assigned)
118 return unmatched, leftover
119
120
121def handle_save_module_tree(
122 arguments: Dict[str, Any],
123 store: SessionStore,
124) -> str:
125 """Persist the IDE agent's clustering result as the module tree."""
126 session_id = arguments["session_id"]
127 session = store.get(session_id)
128 if session is None:
129 return json.dumps({"error": f"Session {session_id} not found or expired."})
130
131 module_tree = arguments["module_tree"]
132 output_dir = session.output_dir
133 known_ids = set(session.components.keys())
134 candidate_ids = set(session.leaf_nodes)
135
136 # Save both immutable snapshot and mutable working copy
137 first_path = os.path.join(output_dir, FIRST_MODULE_TREE_FILENAME)
138 working_path = os.path.join(output_dir, MODULE_TREE_FILENAME)
139
140 os.makedirs(output_dir, exist_ok=True)
141
142 with open(first_path, "w", encoding="utf-8") as f:
143 json.dump(module_tree, f, indent=2, ensure_ascii=False)
144 with open(working_path, "w", encoding="utf-8") as f:
145 json.dump(module_tree, f, indent=2, ensure_ascii=False)
146
147 # Cache in session
148 session.module_tree = module_tree
149

Callers

nothing calls this directly

Calls 4

_get_processing_orderFunction · 0.85
getMethod · 0.80
loadMethod · 0.80
write_jsonMethod · 0.80

Tested by

no test coverage detected