deliberaide-cli 0.1.5__tar.gz → 0.1.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.7}/PKG-INFO +1 -1
  2. {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.7}/deliberaide_cli/__init__.py +1 -1
  3. {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.7}/deliberaide_cli/copilot_chat.py +158 -29
  4. {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.7}/deliberaide_cli.egg-info/PKG-INFO +1 -1
  5. {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.7}/setup.py +1 -1
  6. {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.7}/deliberaide_cli/README.md +0 -0
  7. {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.7}/deliberaide_cli/__main__.py +0 -0
  8. {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.7}/deliberaide_cli/core/__init__.py +0 -0
  9. {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.7}/deliberaide_cli/core/manifest.py +0 -0
  10. {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.7}/deliberaide_cli/core/session.py +0 -0
  11. {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.7}/deliberaide_cli/deliberaide_cli.py +0 -0
  12. {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.7}/deliberaide_cli/route_manifest.json +0 -0
  13. {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.7}/deliberaide_cli/utils/__init__.py +0 -0
  14. {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.7}/deliberaide_cli/utils/api_backend.py +0 -0
  15. {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.7}/deliberaide_cli/utils/formatting.py +0 -0
  16. {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.7}/deliberaide_cli/utils/repl_skin.py +0 -0
  17. {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.7}/deliberaide_cli.egg-info/SOURCES.txt +0 -0
  18. {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.7}/deliberaide_cli.egg-info/dependency_links.txt +0 -0
  19. {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.7}/deliberaide_cli.egg-info/entry_points.txt +0 -0
  20. {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.7}/deliberaide_cli.egg-info/requires.txt +0 -0
  21. {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.7}/deliberaide_cli.egg-info/top_level.txt +0 -0
  22. {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.7}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: deliberaide-cli
3
- Version: 0.1.5
3
+ Version: 0.1.7
4
4
  Summary: Stateful, agent-native CLI for the deliberAIde v2 API
5
5
  Home-page: https://deliberaide.com
6
6
  Author: deliberAIde
@@ -1,3 +1,3 @@
1
1
  __all__ = ["__version__"]
2
2
 
3
- __version__ = "0.1.4"
3
+ __version__ = "0.1.7"
@@ -122,12 +122,19 @@ class ChatResult:
122
122
  frame_counts: dict[str, int] = field(default_factory=dict)
123
123
  duration_seconds: float = 0.0
124
124
  timed_out: bool = False
125
+ over_budget: bool = False # the printing budget passed; the turn may still have finished during the hold
125
126
 
126
127
  @property
127
128
  def ok(self) -> bool:
128
129
  return self.final is not None and self.error is None and not self.timed_out
129
130
 
130
131
 
132
+ # The server keeps a turn alive for this long after its client disconnects; a client that
133
+ # reconnects within the window re-attaches (see synthesis/cli_briefing_reattach_2026-09-08.md).
134
+ SERVER_DISCONNECT_GRACE_SECONDS = 45.0
135
+ DEFAULT_HOLD_SECONDS = 900.0
136
+
137
+
131
138
  def copilot_message_frame(
132
139
  *,
133
140
  text: str,
@@ -161,22 +168,40 @@ def run_chat_turn(
161
168
  timeout_seconds: float,
162
169
  ping_interval: float,
163
170
  on_frame: Callable[[dict[str, Any]], None] | None = None,
171
+ hold_seconds: float = 0.0,
172
+ on_budget: Callable[[ChatResult], None] | None = None,
164
173
  ) -> ChatResult:
165
174
  """Send one frame and consume server frames until the turn ends.
166
175
 
167
176
  ``websocket`` needs ``send(str)`` and ``recv(timeout=float)`` (websockets.sync); a
168
177
  ``TimeoutError`` from ``recv`` means silence, which is answered with a ``ping`` like
169
178
  the web client's heartbeat. The turn ends on ``copilot_done``, ``error``,
170
- ``quota_exceeded``, connection close, or the overall deadline.
179
+ ``quota_exceeded`` or connection close.
180
+
181
+ ``timeout_seconds`` is the printing budget. When it passes and ``hold_seconds`` is
182
+ positive, the socket stays open quietly (no ``on_frame`` calls) for up to
183
+ ``hold_seconds`` more, because the server discards a turn whose client goes away;
184
+ ``on_budget`` is called once at that moment. With ``hold_seconds`` 0 the call returns
185
+ at the budget with ``timed_out`` set, as it did before.
171
186
  """
172
187
  started = time.monotonic()
173
188
  deadline = started + timeout_seconds
189
+ hard_deadline = deadline + max(hold_seconds, 0.0)
174
190
  result = ChatResult(conversation_id=conversation_id)
175
191
  websocket.send(json_dumps(frame, compact=True))
192
+ quiet = False
176
193
 
177
194
  while True:
178
- remaining = deadline - time.monotonic()
195
+ now = time.monotonic()
196
+ remaining = (hard_deadline if quiet else deadline) - now
179
197
  if remaining <= 0:
198
+ if not quiet and hold_seconds > 0:
199
+ quiet = True
200
+ result.over_budget = True
201
+ if on_budget is not None:
202
+ on_budget(result)
203
+ continue
204
+ result.over_budget = True
180
205
  result.timed_out = True
181
206
  break
182
207
  try:
@@ -199,7 +224,7 @@ def run_chat_turn(
199
224
  data = event.get("data") if isinstance(event.get("data"), dict) else {}
200
225
  result.frames += 1
201
226
  result.frame_counts[frame_type] = result.frame_counts.get(frame_type, 0) + 1
202
- if on_frame is not None:
227
+ if on_frame is not None and not quiet:
203
228
  on_frame(event)
204
229
 
205
230
  if frame_type == "copilot_conversation_created" and data.get("conversation_id"):
@@ -218,6 +243,34 @@ def run_chat_turn(
218
243
  return result
219
244
 
220
245
 
246
+ def keep_socket_alive(websocket: Any, seconds: float, *, ping_interval: float = 30.0) -> str:
247
+ """Hold a bare Co-Pilot socket for ``seconds`` so a detached turn stays re-attached.
248
+
249
+ Answers silence with pings like ``run_chat_turn``. Returns ``"terminal"`` as soon as a
250
+ ``copilot_done``/``copilot_response_final``/``error`` frame arrives (the caller should
251
+ poll the messages endpoint right away), ``"closed"`` if the server closed the socket,
252
+ otherwise ``"elapsed"``.
253
+ """
254
+ end = time.monotonic() + max(seconds, 0.0)
255
+ while True:
256
+ remaining = end - time.monotonic()
257
+ if remaining <= 0:
258
+ return "elapsed"
259
+ try:
260
+ raw = websocket.recv(timeout=min(ping_interval, remaining))
261
+ except TimeoutError:
262
+ websocket.send(json_dumps({"type": "ping", "data": {}}, compact=True))
263
+ continue
264
+ except ConnectionClosed:
265
+ return "closed"
266
+ try:
267
+ event = json.loads(raw)
268
+ except (TypeError, ValueError):
269
+ continue
270
+ if isinstance(event, dict) and str(event.get("type") or "") in ("copilot_done", "copilot_response_final", "error", "quota_exceeded"):
271
+ return "terminal"
272
+
273
+
221
274
  # ------------------------------------------------------------------ wait (HTTP)
222
275
 
223
276
 
@@ -327,7 +380,10 @@ def install_copilot_commands(root: click.Group) -> None:
327
380
  root.add_command(group)
328
381
 
329
382
  @click.command("chat")
330
- @click.option("--text", required=True, help="The message to send.")
383
+ @click.option("--text", default=None, help="The message to send. Alternatively --text-file.")
384
+ @click.option("--text-file", type=click.Path(exists=True, dir_okay=False), default=None,
385
+ help="Read the message from a UTF-8 file instead of --text; use this for long or "
386
+ "quote-heavy messages, which shells (PowerShell especially) mangle as arguments.")
331
387
  @click.option("--conversation-id", default=None, help="Existing conversation; omit to let the server create one.")
332
388
  @click.option("--discussion-id", "discussion_ids", multiple=True, help="Discussion scope; repeat for several. Defaults to the conversation's scope.")
333
389
  @click.option("--project-id", default=None)
@@ -339,14 +395,22 @@ def install_copilot_commands(root: click.Group) -> None:
339
395
  @click.option("--web-search/--no-web-search", default=None, help="web_search_enabled; omitted unless given.")
340
396
  @click.option("--hide-from-chat", is_flag=True, help="Run the turn without a visible user message (show_in_chat=false).")
341
397
  @click.option("--x-organisation-id", default=None, help="Organisation header; falls back to the profile default.")
342
- @click.option("--timeout-seconds", type=float, default=900.0, show_default=True, help="Overall budget for the turn.")
398
+ @click.option("--timeout-seconds", type=float, default=900.0, show_default=True,
399
+ help="Budget for streaming the turn. After it the connection is held quietly (see --hold-seconds) "
400
+ "because the server drops a turn whose client goes away.")
401
+ @click.option("--hold-seconds", type=float, default=DEFAULT_HOLD_SECONDS, show_default=True,
402
+ help="How long to keep the connection open after the budget so the server can finish; 0 returns at the budget.")
403
+ @click.option("--detach", is_flag=True,
404
+ help=f"Return at the budget and leave the turn on the server; run `copilot wait --conversation-id <id>` "
405
+ f"within {SERVER_DISCONNECT_GRACE_SECONDS:.0f} s or the server cancels it. Same as --hold-seconds 0.")
343
406
  @click.option("--ping-interval", type=float, default=30.0, show_default=True, help="Heartbeat while the server is silent.")
344
407
  @click.option("--stream/--no-stream", default=True, show_default=True, help="Print server frames as they arrive (NDJSON in --json mode).")
345
408
  @click.option("--dry-run", is_flag=True, help="Print the frame that would be sent and exit.")
346
409
  @click.pass_obj
347
410
  def copilot_chat(
348
411
  runtime: Any,
349
- text: str,
412
+ text: str | None,
413
+ text_file: str | None,
350
414
  conversation_id: str | None,
351
415
  discussion_ids: tuple[str, ...],
352
416
  project_id: str | None,
@@ -358,11 +422,22 @@ def install_copilot_commands(root: click.Group) -> None:
358
422
  hide_from_chat: bool,
359
423
  x_organisation_id: str | None,
360
424
  timeout_seconds: float,
425
+ hold_seconds: float,
426
+ detach: bool,
361
427
  ping_interval: float,
362
428
  stream: bool,
363
429
  dry_run: bool,
364
430
  ) -> None:
365
431
  """Send one Co-Pilot message over the WebSocket, exactly like the web app, and stream the turn."""
432
+ if (text is None) == (text_file is None):
433
+ raise click.UsageError("Give exactly one of --text or --text-file.")
434
+ if text_file is not None:
435
+ from pathlib import Path
436
+ text = Path(text_file).read_text(encoding="utf-8").strip()
437
+ if not text:
438
+ raise click.UsageError(f"--text-file {text_file} is empty.")
439
+ if detach:
440
+ hold_seconds = 0.0
366
441
  org_headers = _org_header(runtime, x_organisation_id)
367
442
  scope: dict[str, Any] = {"discussion_ids": list(discussion_ids), "discussion_id": None, "project_id": project_id,
368
443
  "selected_workflow": None, "workspace_state": {}}
@@ -405,6 +480,22 @@ def install_copilot_commands(root: click.Group) -> None:
405
480
  else:
406
481
  _human_frame_printer(click.echo)(event)
407
482
 
483
+ def on_budget(partial: ChatResult) -> None:
484
+ notice = {
485
+ "notice": "budget_reached",
486
+ "conversation_id": partial.conversation_id,
487
+ "still_running": True,
488
+ "holding_seconds": hold_seconds,
489
+ }
490
+ if runtime.json_output:
491
+ click.echo(json_dumps(notice, compact=True))
492
+ click.echo(
493
+ f"Budget of {timeout_seconds:.0f} s reached; the turn is still running on the server. "
494
+ f"Holding the connection quietly for up to {hold_seconds:.0f} s (frames are no longer printed).",
495
+ err=True,
496
+ )
497
+ click.echo(f"conversation id: {partial.conversation_id or '?'}", err=True)
498
+
408
499
  with websocket_connect(url, additional_headers=headers, open_timeout=runtime.profile.timeout_seconds) as websocket:
409
500
  result = run_chat_turn(
410
501
  websocket,
@@ -413,6 +504,8 @@ def install_copilot_commands(root: click.Group) -> None:
413
504
  timeout_seconds=timeout_seconds,
414
505
  ping_interval=ping_interval,
415
506
  on_frame=on_frame,
507
+ hold_seconds=hold_seconds,
508
+ on_budget=on_budget,
416
509
  )
417
510
 
418
511
  envelope = {
@@ -424,6 +517,8 @@ def install_copilot_commands(root: click.Group) -> None:
424
517
  "message": result.final,
425
518
  "error": result.error,
426
519
  "timed_out": result.timed_out,
520
+ "over_budget": result.over_budget,
521
+ "still_running": result.timed_out and result.error is None,
427
522
  "frames": result.frames,
428
523
  "frame_counts": result.frame_counts,
429
524
  "duration_seconds": result.duration_seconds,
@@ -434,9 +529,16 @@ def install_copilot_commands(root: click.Group) -> None:
434
529
  elif not stream:
435
530
  click.echo(str((result.final or {}).get("content") or ""))
436
531
  if not result.ok:
437
- if not runtime.json_output:
438
- reason = "timed out" if result.timed_out else json_dumps(result.error or {}, compact=True)
439
- click.echo(f"Co-Pilot turn did not finish: {reason}", err=True)
532
+ if result.timed_out and result.error is None:
533
+ click.echo(
534
+ f"Co-Pilot turn did not finish within the budget; it is still running on the server, which cancels it "
535
+ f"{SERVER_DISCONNECT_GRACE_SECONDS:.0f} s after the last client goes away. Run now:",
536
+ err=True,
537
+ )
538
+ click.echo(f" deliberaide-cli --profile {runtime.profile.name} copilot wait --conversation-id {result.conversation_id or '<id>'}", err=True)
539
+ click.echo(str(result.conversation_id or ""), err=True)
540
+ elif not runtime.json_output:
541
+ click.echo(f"Co-Pilot turn did not finish: {json_dumps(result.error or {}, compact=True)}", err=True)
440
542
  raise SystemExit(1)
441
543
 
442
544
  @click.command("wait")
@@ -445,6 +547,9 @@ def install_copilot_commands(root: click.Group) -> None:
445
547
  @click.option("--x-organisation-id", default=None)
446
548
  @click.option("--timeout-seconds", type=float, default=900.0, show_default=True)
447
549
  @click.option("--interval", type=float, default=15.0, show_default=True)
550
+ @click.option("--socket/--no-socket", default=True, show_default=True,
551
+ help="Open a bare Co-Pilot WebSocket first and hold it while polling, so a turn whose `chat` client "
552
+ "went away is re-attached instead of cancelled (must start within 45 s of the disconnect).")
448
553
  @click.pass_obj
449
554
  def copilot_wait(
450
555
  runtime: Any,
@@ -453,30 +558,54 @@ def install_copilot_commands(root: click.Group) -> None:
453
558
  x_organisation_id: str | None,
454
559
  timeout_seconds: float,
455
560
  interval: float,
561
+ socket: bool,
456
562
  ) -> None:
457
- """Poll a conversation until a non-interim assistant message arrives (for turns started over HTTP)."""
563
+ """Wait for a turn's final answer: re-attach to the server over the WebSocket and poll the persisted messages."""
458
564
  headers = _org_header(runtime, x_organisation_id)
565
+ websocket = None
566
+ if socket:
567
+ ws_headers = {**_cookie_header(runtime), **headers}
568
+ if "Cookie" not in ws_headers:
569
+ raise click.ClickException("No session cookies for this profile. Run `deliberaide-cli auth login` first.")
570
+ url = runtime.backend.build_websocket_url(WS_PATH)
571
+ try:
572
+ websocket = websocket_connect(url, additional_headers=ws_headers, open_timeout=runtime.profile.timeout_seconds)
573
+ except Exception as exc: # noqa: BLE001 - polling still works without the re-attach
574
+ click.echo(f"could not open the Co-Pilot socket ({exc}); polling without re-attaching", err=True)
459
575
  deadline = time.monotonic() + timeout_seconds
460
- while True:
461
- response = runtime.backend.request(
462
- "GET", f"/api/v1/copilot/conversations/{conversation_id}/messages", params={"limit": 200}, headers=headers
463
- )
464
- if not response.is_success:
465
- raise click.ClickException(f"GET messages failed: HTTP {response.status_code} {response.text[:200]}")
466
- body = response.json()
467
- messages = body if isinstance(body, list) else (body.get("items") or body.get("messages") or [])
468
- message = select_terminal_message(messages, after=after)
469
- if message is not None:
470
- envelope = {"ok": True, "operation": "copilot.wait", "response": {"conversation_id": conversation_id, "message": message}}
471
- click.echo(json_dumps(envelope, compact=True) if runtime.json_output else str(message.get("content") or ""))
472
- return
473
- if time.monotonic() >= deadline:
474
- if runtime.json_output:
475
- click.echo(json_dumps({"ok": False, "operation": "copilot.wait", "response": {"conversation_id": conversation_id, "message": None, "timed_out": True}}, compact=True))
576
+ try:
577
+ while True:
578
+ response = runtime.backend.request(
579
+ "GET", f"/api/v1/copilot/conversations/{conversation_id}/messages", params={"limit": 200}, headers=headers
580
+ )
581
+ if not response.is_success:
582
+ raise click.ClickException(f"GET messages failed: HTTP {response.status_code} {response.text[:200]}")
583
+ body = response.json()
584
+ messages = body if isinstance(body, list) else (body.get("items") or body.get("messages") or [])
585
+ message = select_terminal_message(messages, after=after)
586
+ if message is not None:
587
+ envelope = {"ok": True, "operation": "copilot.wait", "response": {"conversation_id": conversation_id, "message": message}}
588
+ click.echo(json_dumps(envelope, compact=True) if runtime.json_output else str(message.get("content") or ""))
589
+ return
590
+ if time.monotonic() >= deadline:
591
+ if runtime.json_output:
592
+ click.echo(json_dumps({"ok": False, "operation": "copilot.wait", "response": {"conversation_id": conversation_id, "message": None, "timed_out": True}}, compact=True))
593
+ else:
594
+ click.echo("No terminal assistant message yet.", err=True)
595
+ raise SystemExit(1)
596
+ if websocket is not None:
597
+ outcome = keep_socket_alive(websocket, interval)
598
+ if outcome == "closed":
599
+ click.echo("Co-Pilot socket closed by the server; polling continues without it", err=True)
600
+ websocket = None
476
601
  else:
477
- click.echo("No terminal assistant message yet.", err=True)
478
- raise SystemExit(1)
479
- time.sleep(interval)
602
+ time.sleep(interval)
603
+ finally:
604
+ if websocket is not None:
605
+ try:
606
+ websocket.close()
607
+ except Exception: # noqa: BLE001
608
+ pass
480
609
 
481
610
  group.add_command(copilot_chat)
482
611
  group.add_command(copilot_wait)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: deliberaide-cli
3
- Version: 0.1.5
3
+ Version: 0.1.7
4
4
  Summary: Stateful, agent-native CLI for the deliberAIde v2 API
5
5
  Home-page: https://deliberaide.com
6
6
  Author: deliberAIde
@@ -7,7 +7,7 @@ LONG_DESCRIPTION = (Path(__file__).parent / "deliberaide_cli" / "README.md").rea
7
7
 
8
8
  setup(
9
9
  name="deliberaide-cli",
10
- version="0.1.5",
10
+ version="0.1.7",
11
11
  description="Stateful, agent-native CLI for the deliberAIde v2 API",
12
12
  long_description=LONG_DESCRIPTION,
13
13
  long_description_content_type="text/markdown",