MCPcopy
hub / github.com/HKUDS/OpenHarness / get_bundle

Method get_bundle

ohmo/gateway/runtime.py:146–210  ·  view source on GitHub ↗

Return an existing bundle or create a new one.

(
        self,
        session_key: str,
        latest_user_prompt: str | None = None,
        cwd: str | Path | None = None,
    )

Source from the content-addressed store, hash-verified

144 return result
145
146 async def get_bundle(
147 self,
148 session_key: str,
149 latest_user_prompt: str | None = None,
150 cwd: str | Path | None = None,
151 ) -> RuntimeBundle:
152 """Return an existing bundle or create a new one."""
153 session_cwd = str(Path(cwd or self._cwd).expanduser().resolve())
154 bundle = self._bundles.get(session_key)
155 if bundle is not None:
156 bundle_cwd = str(Path(getattr(bundle, "cwd", self._cwd)).resolve())
157 if bundle_cwd != session_cwd:
158 logger.info(
159 "ohmo runtime recreating session for cwd change session_key=%s old_cwd=%s new_cwd=%s",
160 session_key,
161 bundle_cwd,
162 session_cwd,
163 )
164 await close_runtime(bundle)
165 self._bundles.pop(session_key, None)
166 else:
167 logger.info(
168 "ohmo runtime reusing session session_key=%s session_id=%s prompt=%r",
169 session_key,
170 bundle.session_id,
171 _content_snippet(latest_user_prompt or ""),
172 )
173 bundle.engine.set_system_prompt(self._runtime_system_prompt(bundle, latest_user_prompt))
174 return bundle
175
176 snapshot = self._session_backend.load_latest_for_session_key(session_key)
177 logger.info(
178 "ohmo runtime creating session session_key=%s restored=%s prompt=%r",
179 session_key,
180 bool(snapshot),
181 _content_snippet(latest_user_prompt or ""),
182 )
183 bundle = await build_runtime(
184 cwd=session_cwd,
185 model=self._model,
186 max_turns=self._max_turns,
187 system_prompt=build_ohmo_system_prompt(session_cwd, workspace=self._workspace, extra_prompt=None),
188 active_profile=self._provider_profile,
189 session_backend=self._session_backend,
190 enforce_max_turns=self._max_turns is not None,
191 restore_messages=_sanitize_snapshot_messages(snapshot.get("messages") if snapshot else None),
192 restore_tool_metadata=_sanitize_group_command_metadata(snapshot.get("tool_metadata") if snapshot else None),
193 extra_skill_dirs=(str(get_skills_dir(self._workspace)),),
194 extra_plugin_roots=(str(get_plugins_dir(self._workspace)),),
195 memory_backend=create_memory_command_backend(self._workspace),
196 include_project_memory=False,
197 )
198 if snapshot and snapshot.get("session_id"):
199 bundle.session_id = str(snapshot["session_id"])
200 self._register_gateway_tools(bundle)
201 await start_runtime(bundle)
202 bundle.engine.set_system_prompt(self._runtime_system_prompt(bundle, latest_user_prompt))
203 logger.info(

Calls 15

close_runtimeFunction · 0.90
build_runtimeFunction · 0.90
build_ohmo_system_promptFunction · 0.90
get_skills_dirFunction · 0.90
get_plugins_dirFunction · 0.90
start_runtimeFunction · 0.90