Commit a6ffe85
feat(busy-route): auto-execute pipeline on a fresh console at the source's cwd
Pre-fix: when invoke_expression's chosen pipe was busy (a user command
typed in the visible terminal between FindReadyPipeAsync and the
proxy's request arrival, or another mcp_command racing), the proxy
spawned a brand-new console at \$HOME, returned `Pipeline NOT executed
- verify location and re-execute` plus the full get_current_location
JSON (system info + every PSDrive), and the AI had to re-send the same
invoke_expression with whatever cwd they wanted. Two MCP round-trips
and a manual Set-Location for every busy race — observed as the
single biggest token-waster in side-by-side comparisons against
ripple, which auto-routes to a same-family standby with the source's
cwd preserved.
Now: the busy response carries the source console's process-level
cwd (DLL: NamedPipeServer.cs adds `cwd` from
Directory.GetCurrentDirectory in three places — get_status/busy,
mcp_command, user_command branches; reading the property does NOT
touch the runspace, so it stays non-blocking). The proxy reads
jsonResponse.Cwd, starts the new console at that path (falls back to
\$HOME when the field is null on older DLLs — fully backward-compatible),
and recursively calls InvokeExpression on the same agent. The new
console is now the active standby, so FindReadyPipeAsync on the
recursive call lands on it and the pipeline runs cleanly. The
recursion is bounded in practice: a back-to-back race against another
user-typed command in the freshly-spawned console would require
sub-millisecond timing at AI tool-call cadence; if it ever happens,
the recursion spawns one more console and runs there — no infinite
loop, just an extra console.
The bulky get_current_location JSON drops out of the response in
this path: the AI no longer needs the OS / PSDrive listing to verify
cwd because the auto-route already preserved it, and the recursive
call's response carries the actual pipeline output the AI was
waiting for. Proxy still surfaces the busy status line ("⧗ Pipeline
is running ...") and a one-line auto-route notice
("ℹ️ Auto-routed to NEW at CWD ... Pipeline executed automatically
— no re-send needed") so the AI sees what happened, but the verbose
JSON is gone. Closed-console messages from the outer call are
prepended too (the recursive call's FindReadyPipeAsync runs fresh
and won't re-report them).
The other two `Pipeline NOT executed` paths (no-pipe auto-start and
consoleSwitched on a claimed unowned console) are left alone for
now: they don't have a source-console cwd to preserve, and forcing
auto-execution there would risk landing the AI's pipeline in an
unrelated cwd. Trim of the bulky JSON in those paths is a separate
concern.
Existing 19 PowerShellTools unit tests still pass — none cover the
busy auto-respawn path (StartConsoleInternal calls a static
PowerShellProcessManager so spawn-mock isn't possible without a
process-manager-injection refactor first; deferred). The change is
safe to ship because the wire format is strictly additive (DLL emits
a new optional field; older proxies ignore it; older DLLs still hit
the null-cwd → \$HOME fallback path = pre-fix behavior).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 61adc7d commit a6ffe85
3 files changed
Lines changed: 109 additions & 32 deletions
File tree
- PowerShell.MCP.Proxy
- Models
- Tools
- PowerShell.MCP/Services
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
79 | 91 | | |
80 | 92 | | |
81 | 93 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
344 | 344 | | |
345 | 345 | | |
346 | 346 | | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
351 | 368 | | |
352 | | - | |
| 369 | + | |
353 | 370 | | |
354 | 371 | | |
355 | 372 | | |
| |||
359 | 376 | | |
360 | 377 | | |
361 | 378 | | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
367 | 406 | | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
| 407 | + | |
379 | 408 | | |
| 409 | + | |
380 | 410 | | |
381 | | - | |
382 | | - | |
383 | 411 | | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
384 | 416 | | |
385 | 417 | | |
386 | 418 | | |
| |||
536 | 568 | | |
537 | 569 | | |
538 | 570 | | |
539 | | - | |
540 | | - | |
541 | | - | |
| 571 | + | |
| 572 | + | |
542 | 573 | | |
543 | 574 | | |
544 | 575 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
417 | 417 | | |
418 | 418 | | |
419 | 419 | | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
420 | 435 | | |
421 | 436 | | |
422 | 437 | | |
| |||
435 | 450 | | |
436 | 451 | | |
437 | 452 | | |
438 | | - | |
| 453 | + | |
| 454 | + | |
439 | 455 | | |
440 | 456 | | |
441 | 457 | | |
| |||
448 | 464 | | |
449 | 465 | | |
450 | 466 | | |
451 | | - | |
| 467 | + | |
| 468 | + | |
452 | 469 | | |
453 | 470 | | |
454 | 471 | | |
| |||
457 | 474 | | |
458 | 475 | | |
459 | 476 | | |
460 | | - | |
| 477 | + | |
461 | 478 | | |
462 | 479 | | |
463 | 480 | | |
| |||
470 | 487 | | |
471 | 488 | | |
472 | 489 | | |
473 | | - | |
| 490 | + | |
| 491 | + | |
474 | 492 | | |
475 | 493 | | |
476 | 494 | | |
| |||
571 | 589 | | |
572 | 590 | | |
573 | 591 | | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
574 | 600 | | |
575 | 601 | | |
576 | 602 | | |
577 | 603 | | |
578 | 604 | | |
579 | 605 | | |
580 | | - | |
| 606 | + | |
| 607 | + | |
581 | 608 | | |
582 | 609 | | |
583 | 610 | | |
| |||
598 | 625 | | |
599 | 626 | | |
600 | 627 | | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
601 | 634 | | |
602 | 635 | | |
603 | 636 | | |
604 | 637 | | |
605 | 638 | | |
606 | 639 | | |
607 | | - | |
| 640 | + | |
| 641 | + | |
608 | 642 | | |
609 | 643 | | |
610 | 644 | | |
| |||
0 commit comments