MCPcopy Create free account
hub / github.com/1jehuang/jcode / create_session

Function create_session

scripts/profile_single_spawn.py:42–66  ·  view source on GitHub ↗
(debug_sock: Path, cwd: str)

Source from the content-addressed store, hash-verified

40
41
42def create_session(debug_sock: Path, cwd: str) -> str:
43 sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
44 sock.connect(str(debug_sock))
45 req = {"type": "debug_command", "id": 1, "command": f"create_session:{cwd}"}
46 sock.sendall((json.dumps(req) + "\n").encode())
47 buf = b""
48 while True:
49 chunk = sock.recv(65536)
50 if not chunk:
51 break
52 buf += chunk
53 while b"\n" in buf:
54 line, buf = buf.split(b"\n", 1)
55 resp = json.loads(line.decode())
56 if resp.get("type") == "ack":
57 continue
58 if resp.get("type") == "error":
59 raise RuntimeError(resp.get("message") or resp)
60 if resp.get("type") != "debug_response":
61 continue
62 if not resp.get("ok", True):
63 raise RuntimeError(resp.get("output") or resp)
64 output = json.loads(resp["output"])
65 return output["session_id"]
66 raise RuntimeError("missing debug response")
67
68
69def reply_queries(master_fd: int, buffer: bytes) -> bytes:

Callers 1

profile_single_spawnFunction · 0.70

Calls 6

encodeMethod · 0.80
recvMethod · 0.80
decodeMethod · 0.80
connectMethod · 0.45
splitMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected