solidworks_mcp.agents.soc_rewind¶
solidworks_mcp.agents.soc_rewind ¶
SolidWorks-as-Code rewind: roll back to a named checkpoint.
Two complementary operations:
- Model rewind — open the .sldprt saved at a checkpoint in SolidWorks.
- Script rewind — truncate a generated script to the checkpoint boundary, returning only the lines up to (and including) the checkpoint comment block.
The combination gives you a clean slate: the model is at checkpoint state and the script reflects exactly what produced it. Continue building from there by appending new tool calls.
Usage::
from solidworks_mcp.agents.soc_rewind import rewind_to_checkpoint, truncate_script_at
# Open the model and get the truncated script
script_so_far = await rewind_to_checkpoint(
adapter,
session_id="my-session",
label="base-extrude",
)
CLI (model rewind only — prints truncated script to stdout)::
python -m solidworks_mcp.agents.soc_rewind <session_id> <label>
Attributes¶
_CP_LABEL_RE
module-attribute
¶
_CP_OPEN_RE
module-attribute
¶
Functions:¶
_cli ¶
Source code in src/solidworks_mcp/agents/soc_rewind.py
list_checkpoints ¶
List all SoCCheckpoints for a session (DB query).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The SoC session ID. |
required |
db_path
|
Path | None
|
Override default SQLite DB path. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
Ordered list of checkpoint dicts with keys: id, label, file_path, |
list[dict[str, Any]]
|
first_record_id, last_record_id, snapshot_id, created_at. |
Source code in src/solidworks_mcp/agents/soc_rewind.py
parse_script_checkpoints ¶
Parse all checkpoint comment blocks from a generated SoC script.
Returns a list of dicts with keys: label, file, line_start, line_end. line_start and line_end are 0-based indices into script_text.splitlines().
Source code in src/solidworks_mcp/agents/soc_rewind.py
rewind_to_checkpoint
async
¶
rewind_to_checkpoint(adapter: Any, session_id: str, label: str, *, db_path: Path | None = None, script_text: str | None = None) -> str | None
Open the checkpoint model in SolidWorks and return the truncated script.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
Connected SolidWorks adapter (CircuitBreakerAdapter or equivalent). |
required |
session_id
|
str
|
The SoC session ID. |
required |
label
|
str
|
Checkpoint label to rewind to. |
required |
db_path
|
Path | None
|
Override default SQLite DB path. |
None
|
script_text
|
str | None
|
If provided, also truncate this script text at the checkpoint. Pass the output of export_session() to get the truncated version back. |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
Truncated script text if script_text was provided, else None. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the checkpoint is not found in the DB or the file cannot be opened. |
Source code in src/solidworks_mcp/agents/soc_rewind.py
truncate_script_at ¶
Return the script truncated to (and including) the named checkpoint block.
Everything after the checkpoint comment is removed. The result is a valid script that can be run to reproduce the model state up to that label.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
script_text
|
str
|
Full generated script text. |
required |
label
|
str
|
Checkpoint label to truncate at (e.g. "base-extrude"). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Truncated script text, or the full script if label not found. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If no checkpoint with that label exists in the script. |