dsh-plugin-wsl-env 0.18.0 → 0.21.0

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 (123) hide show
  1. package/CHANGELOG.md +274 -0
  2. package/CONTRIBUTING.md +37 -5
  3. package/README.md +60 -5
  4. package/SUPPORT.md +3 -3
  5. package/agent/native/linux-aarch64/dsh-wsl-agent +0 -0
  6. package/agent/native/linux-x86_64/dsh-wsl-agent +0 -0
  7. package/agent/wsl-agent.sh +331 -11
  8. package/client.d.ts +5 -0
  9. package/client.js +98 -0
  10. package/cordis.patch.yml +66 -1
  11. package/docs/AGENT-PROTOCOL-V7.md +175 -0
  12. package/docs/API.md +25 -0
  13. package/docs/ARCHITECTURE.md +14 -1
  14. package/docs/CONFIGURATION.md +47 -6
  15. package/docs/CONFIGURATION.zh.md +20 -4
  16. package/docs/DIAGNOSTICS.md +83 -0
  17. package/docs/DIAGNOSTICS.zh.md +73 -0
  18. package/docs/LIMITATIONS.md +41 -4
  19. package/docs/LIMITATIONS.zh.md +27 -11
  20. package/docs/MIGRATION.md +4 -4
  21. package/docs/PEER-PARITY.md +50 -33
  22. package/docs/QUICKSTART.md +37 -4
  23. package/docs/QUICKSTART.zh.md +16 -1
  24. package/docs/README.zh.md +43 -4
  25. package/docs/RELEASING.md +4 -1
  26. package/docs/REQUIREMENTS.zh.md +3 -2
  27. package/docs/ROADMAP-1.0.md +75 -19
  28. package/docs/UPSTREAM-FILE-REFERENCE-SEAM.md +8 -1
  29. package/docs/UPSTREAM-OPEN-IN-APP.md +33 -0
  30. package/docs/UPSTREAM-SESSION-NOTICE.md +3 -1
  31. package/docs/UPSTREAM-TERMINAL-TITLE.md +3 -0
  32. package/docs/root-fs-routing.md +3 -3
  33. package/lib/agent-confined.js +4 -4
  34. package/lib/agent-errors.d.ts +1 -1
  35. package/lib/agent-errors.js +1 -1
  36. package/lib/agent-exec.d.ts +1 -1
  37. package/lib/agent-exec.js +1 -1
  38. package/lib/agent-protocol.d.ts +58 -8
  39. package/lib/agent-protocol.js +40 -7
  40. package/lib/agent-shared.d.ts +1 -1
  41. package/lib/agent-shared.js +1 -1
  42. package/lib/agent.d.ts +171 -1
  43. package/lib/agent.js +448 -288
  44. package/lib/auto-preset.d.ts +1 -1
  45. package/lib/auto-preset.js +1 -1
  46. package/lib/bwrap.d.ts +1 -1
  47. package/lib/bwrap.js +1 -1
  48. package/lib/client-host.d.ts +29 -0
  49. package/lib/client-host.js +29 -0
  50. package/lib/cwd-prompt-tool.d.ts +88 -0
  51. package/lib/cwd-prompt-tool.js +94 -0
  52. package/lib/cwd-prompt.d.ts +166 -0
  53. package/lib/cwd-prompt.js +203 -0
  54. package/lib/distro-route.d.ts +1 -1
  55. package/lib/distro-route.js +1 -1
  56. package/lib/doctor-live.d.ts +57 -0
  57. package/lib/doctor-live.js +38 -0
  58. package/lib/file-reference-wsl.d.ts +1 -1
  59. package/lib/file-reference-wsl.js +1 -1
  60. package/lib/fs-decisions.d.ts +1 -1
  61. package/lib/fs-decisions.js +1 -1
  62. package/lib/fs-routing.d.ts +1 -1
  63. package/lib/fs-routing.js +1 -1
  64. package/lib/fs-substrate.d.ts +90 -11
  65. package/lib/fs-substrate.js +202 -1
  66. package/lib/fs.d.ts +1 -1
  67. package/lib/fs.js +1 -1
  68. package/lib/fsio-agent.d.ts +128 -4
  69. package/lib/fsio-agent.js +224 -15
  70. package/lib/fsio-text.d.ts +1 -1
  71. package/lib/fsio-text.js +1 -1
  72. package/lib/git-exec.d.ts +1 -1
  73. package/lib/git-exec.js +1 -1
  74. package/lib/git-route.d.ts +1 -1
  75. package/lib/git-route.js +1 -1
  76. package/lib/index.d.ts +105 -30
  77. package/lib/index.js +272 -130
  78. package/lib/listing.d.ts +1 -1
  79. package/lib/listing.js +1 -1
  80. package/lib/messages.d.ts +157 -0
  81. package/lib/messages.js +199 -0
  82. package/lib/native-agent.d.ts +1 -1
  83. package/lib/native-agent.js +2 -2
  84. package/lib/paths.d.ts +6 -3
  85. package/lib/paths.js +4 -4
  86. package/lib/picker.d.ts +1 -1
  87. package/lib/picker.js +7 -7
  88. package/lib/ports.d.ts +1 -1
  89. package/lib/ports.js +1 -1
  90. package/lib/preflight.d.ts +25 -1
  91. package/lib/preflight.js +112 -12
  92. package/lib/sandbox-core.d.ts +1 -1
  93. package/lib/sandbox-core.js +9 -16
  94. package/lib/sandbox.d.ts +1 -1
  95. package/lib/sandbox.js +1 -1
  96. package/lib/search-exec.d.ts +1 -1
  97. package/lib/search-exec.js +1 -1
  98. package/lib/search-route.d.ts +1 -1
  99. package/lib/search-route.js +1 -1
  100. package/lib/session-runtime.d.ts +1 -1
  101. package/lib/session-runtime.js +2 -2
  102. package/lib/session-scope.d.ts +1 -1
  103. package/lib/session-scope.js +11 -6
  104. package/lib/shell-env.d.ts +26 -1
  105. package/lib/shell-env.js +57 -1
  106. package/lib/shell.d.ts +4 -2
  107. package/lib/shell.js +4 -2
  108. package/lib/subprocess.d.ts +1 -1
  109. package/lib/subprocess.js +2 -2
  110. package/lib/terminal-activity.d.ts +1 -1
  111. package/lib/terminal-activity.js +1 -1
  112. package/lib/terminal-route.d.ts +1 -1
  113. package/lib/terminal-route.js +1 -1
  114. package/lib/update-check.d.ts +197 -0
  115. package/lib/update-check.js +211 -0
  116. package/lib/watcher.d.ts +1 -1
  117. package/lib/watcher.js +1 -1
  118. package/lib/wsl-doctor-tool.d.ts +122 -0
  119. package/lib/wsl-doctor-tool.js +161 -0
  120. package/lib/wsl.d.ts +1 -31
  121. package/lib/wsl.js +1 -21
  122. package/package.json +55 -6
  123. package/scripts/doctor.mjs +1196 -166
@@ -8,15 +8,22 @@
8
8
  # and speaks a line protocol over stdio. Fields are separated by `|`; binary
9
9
  # payloads (cwd, argv words, env values, captured output) travel as single-line
10
10
  # base64. The protocol deliberately avoids JSON: the agent must run under a
11
- # bare POSIX sh with no dependencies beyond coreutils' `base64`, because the
11
+ # bare POSIX sh. The tool floor is GNU coreutils' `base64`, GNU `find`
12
+ # (-printf), `realpath -e/-L`, `sync -f/-d` and `od` — the container suite
13
+ # exercises the BusyBox/apk family against exactly that floor, because the
12
14
  # one thing a distro is guaranteed to have is a shell.
13
15
  #
14
16
  # Handshake — the first line the agent writes:
15
- # HELLO|wsl-agent|<protocol version>|<sha256 of this script file>
17
+ # HELLO|wsl-agent|<protocol version>|<sha256 of this script file>|<pid>|<caps>
16
18
  # The digest lets the host verify that the script it is about to rely on is
17
19
  # byte-identical to the copy it shipped. The script is read in place — a
18
20
  # /mnt/c mirror in the deployed layout — so a stale or half-synced runtime
19
21
  # copy would otherwise pass the version handshake while drifting in behavior.
22
+ # Protocol 7 adds the sixth field, `caps`: a comma-separated capability token
23
+ # list (`conc` = FS ops may answer out of order, `batch` = the FSB frame is
24
+ # accepted). This agent advertises `batch` — its read loop is serial, so a
25
+ # batch (one worker, in-order answers) is safe while pipelined single FS
26
+ # frames are not. A v6 peer parser ignores the extra field.
20
27
  # Requests the agent accepts, one per line on stdin:
21
28
  # PING -> PONG
22
29
  # SHUTDOWN -> exits 0
@@ -48,14 +55,36 @@
48
55
  # ops: stat <path> · lstat <path> · list <dir> · realpath <path>
49
56
  # read <path> <offset> <maxbytes> · write <path> <mode|->
50
57
  # <replace|no-replace> <expected version|-> <content-b64>
58
+ # delete <path> <expected version|-> [protocol 7]
59
+ # move <src> <dst> <dst mode|-> <dst replace|no-replace|->
60
+ # <src expected version|-> <dst expected version|-> [7]
51
61
  # -> ACK|<id> at dequeue, then the same RES|<id>|<exit code>|<b64
52
62
  # stdout>|<b64 stderr> line as EXEC.
53
- # A failed op writes `dsh-fs|<reason>|<b64 message>` as the FIRST line
54
- # of its stderr (reason: notfound notdir perm loop exists stale io),
55
- # which the host's adapter maps onto the FsError codes the tool layer
56
- # knows. A `replace` write carrying an expected version re-verifies it
57
- # against a fresh stat before the rename and refuses with `stale` on
58
- # a mismatch; a later concurrent write can still be overwritten.
63
+ # A failed op answers with the structured line
64
+ # FSERR|<id>|<reason>|<b64 message> instead of the RES (protocol 7;
65
+ # the host maps the reason directly), and ALSO writes
66
+ # `dsh-fs|<reason>|<b64 message>` as the FIRST line of its stderr
67
+ # (reason: notfound notdir perm loop exists stale io) — the
68
+ # convention older hosts parse. A `replace` write carrying an
69
+ # expected version re-verifies it against a fresh stat before the
70
+ # rename and refuses with `stale` on a mismatch; a later concurrent
71
+ # write can still be overwritten. A `delete` re-verifies the same
72
+ # way and refuses with `stale` on a mismatch or a vanished file. A
73
+ # `move` guards the source the same way, publishes the destination
74
+ # through the write machinery's staging (atomic rename, or a
75
+ # no-replace hard link for a guarded create), then removes the
76
+ # source; its stdout carries the destination's fresh stat record
77
+ # and — when the source survived — one SRCFAIL|<reason>|<b64 message>
78
+ # line (the peer's two-effect `FsMoveOutcome`, honestly preserved).
79
+ # FSB|<id>|<timeout seconds|0>|<n ops> [protocol 7]
80
+ # followed by <n ops> records, each an OP|<op>|<n args> line plus its
81
+ # base64 arguments. The ops run IN ORDER in one worker and the answer
82
+ # is ONE RES whose payload is the concatenated per-op records:
83
+ # OK <i>|<b64 payload>
84
+ # BAD <i>|<reason>|<b64 message>
85
+ # A failed op records BAD and the batch continues — a batch is a set of
86
+ # independent reads, not a transaction. One round trip for what costs
87
+ # four to six FS frames (the GUI preview's stat + list + read shape).
59
88
  #
60
89
  # Confinement is NOT this script's business: the host wraps argv in the bwrap
61
90
  # profile (lib/sandbox.js) before the frame is sent, so the agent executes
@@ -73,7 +102,7 @@ set -u
73
102
  # the child without it (NUL bytes — `check-ignore -z` separators — survive).
74
103
  # Every known consumer parses line-oriented stdin that tolerates a missing
75
104
  # final newline.
76
- PROTO_VERSION=6
105
+ PROTO_VERSION=7
77
106
  TMPDIR_AGENT=$(mktemp -d "${TMPDIR:-/tmp}/wsl-agent.XXXXXX")
78
107
  OUT_FILE="$TMPDIR_AGENT/out"
79
108
  ERR_FILE="$TMPDIR_AGENT/err"
@@ -225,6 +254,7 @@ timeout_watcher() {
225
254
  run_capture() {
226
255
  local req_id timeout_s maxout mode rc watcher_pid out_cut err_cut
227
256
  local out_fifo err_fifo out_reader err_reader spawn_out spawn_err killer_pid
257
+ local first_err rest_fs reason_fs msg_fs
228
258
  req_id=$1
229
259
  timeout_s=$2
230
260
  maxout=$3
@@ -331,6 +361,22 @@ run_capture() {
331
361
  # the protocol.
332
362
  out_cut=0
333
363
  err_cut=0
364
+ # Protocol 7 FS ops answer a failure with the structured FSERR line instead
365
+ # of a RES the host must sniff: the decision is the captured stderr's first
366
+ # line, which the handlers pin to the dsh-fs| convention.
367
+ if [ "$mode" = subshell ] && [ "$rc" -ne 0 ]; then
368
+ first_err=$(head -n 1 -- "$ERR_FILE" 2>/dev/null)
369
+ case $first_err in
370
+ dsh-fs\|*)
371
+ rest_fs=${first_err#dsh-fs|}
372
+ reason_fs=${rest_fs%%|*}
373
+ msg_fs=${rest_fs#*|}
374
+ printf 'FSERR|%s|%s|%s\n' "$req_id" "$reason_fs" "${msg_fs:-$(printf '' | base64 | tr -d '\n')}"
375
+ rm -f "$TMPDIR_AGENT/inflight"
376
+ return 0
377
+ ;;
378
+ esac
379
+ fi
334
380
  if [ "$maxout" -gt 0 ]; then
335
381
  [ "$(wc -c <"$OUT_FILE" 2>/dev/null || printf 0)" -gt "$maxout" ] && out_cut=1
336
382
  [ "$(wc -c <"$ERR_FILE" 2>/dev/null || printf 0)" -gt "$maxout" ] && err_cut=1
@@ -462,7 +508,11 @@ fs_read() {
462
508
  p=$(b64dec "$1")
463
509
  offset=$(b64dec "$2")
464
510
  max=$(b64dec "$3")
465
- [ "$max" -gt 0 ] || return 0
511
+ # A malformed window is a protocol-class failure, not an empty answer: the
512
+ # host always sends numerics, so anything else is a frame worth refusing.
513
+ case $offset in ''|*[!0-9]*) fs_fail protocol "fs read: offset is not a number";; esac
514
+ case $max in ''|*[!0-9]*) fs_fail protocol "fs read: max is not a number";; esac
515
+ [ "$max" -gt 0 ] || fs_fail protocol "fs read: max must be positive, got $max"
466
516
  : >"$ERR_FILE"
467
517
  tail -c +"$(( offset + 1 ))" -- "$p" 2>"$ERR_FILE" | head -c "$max" -- 2>/dev/null
468
518
  if [ -s "$ERR_FILE" ]; then
@@ -626,9 +676,221 @@ fs_write() {
626
676
  fs_fail "$(fs_classify "$err")" "$err"
627
677
  }
628
678
  fi
679
+ # The published name is only as durable as its directory entry: fsync the
680
+ # containing directory too, so a power loss cannot lose the rename that the
681
+ # file sync already made safe. Best effort — sync builds without -d and
682
+ # filesystems that refuse a directory fsync keep the peer's own promise.
683
+ sync -d -- "$(dirname -- "$path")" 2>/dev/null || :
629
684
  drop_staging
630
685
  }
631
686
 
687
+ fs_delete() {
688
+ # $1 = base64 path, $2 = base64 expected version (`-` for none). The peer's
689
+ # requireFile dialect: a vanished file is a stale guard, a non-regular
690
+ # target its own refusal, a version mismatch stale. One regular file comes
691
+ # off the disk; the host holds the diff basis it read beforehand.
692
+ local path expected version err
693
+ path=$(b64dec "$1")
694
+ expected=$(b64dec "$2")
695
+ LC_ALL=C
696
+ export LC_ALL=C
697
+ [ -n "$path" ] && [ "$path" != "/" ] || fs_fail notfound "empty file name"
698
+ if [ ! -e "$path" ] && [ ! -L "$path" ]; then
699
+ fs_fail stale "cannot delete \"$path\": file changed since it was read"
700
+ fi
701
+ if [ -d "$path" ] && [ ! -L "$path" ]; then
702
+ fs_fail notdir "cannot delete \"$path\": not a regular file"
703
+ fi
704
+ if [ "$expected" != "-" ]; then
705
+ version=$(fs_version "$path")
706
+ if [ "$version" != "$expected" ]; then
707
+ fs_fail stale "cannot delete \"$path\": file changed since it was read"
708
+ fi
709
+ fi
710
+ rm -f -- "$path" 2>"$ERR_FILE" || {
711
+ err=$(cat "$ERR_FILE")
712
+ fs_fail "$(fs_classify "$err")" "$err"
713
+ }
714
+ }
715
+
716
+ fs_move() {
717
+ # $1 = base64 source, $2 = base64 destination, $3 = base64 destination mode
718
+ # (`-` keeps the default), $4 = base64 destination publish (`no-replace`
719
+ # for a guarded create, anything else = `replace`), $5 = base64 source
720
+ # expected version (`-` for none), $6 = base64 destination expected version
721
+ # (`-` for none). The peer's moveFile shape: the source passes requireFile,
722
+ # the destination passes writeTarget, the bytes publish through the write
723
+ # machinery's staging (atomic rename, or the no-replace link for a guarded
724
+ # create), and the source is removed last. The stdout carries the
725
+ # destination's fresh stat record (the host turns it into the outcome's
726
+ # version) and — when the source survived — one
727
+ # SRCFAIL|<reason>|<b64 message> line: the two effects are separate, and
728
+ # the peer's `sourceDeleted=false` shape must stay observable.
729
+ local src dst mode guard sexp dexp ddir dbase staging tmp err version u src_err
730
+ src=$(b64dec "$1")
731
+ dst=$(b64dec "$2")
732
+ mode=$(b64dec "$3")
733
+ guard=$(b64dec "$4")
734
+ sexp=$(b64dec "$5")
735
+ dexp=$(b64dec "$6")
736
+ LC_ALL=C
737
+ export LC_ALL=C
738
+ ddir=$(dirname -- "$dst")
739
+ dbase=$(basename -- "$dst")
740
+ [ -n "$dbase" ] && [ "$dbase" != "/" ] || fs_fail notfound "empty file name"
741
+ # Source: requireFile's dialect.
742
+ if [ ! -e "$src" ] && [ ! -L "$src" ]; then
743
+ fs_fail stale "cannot move \"$src\": file changed since it was read"
744
+ fi
745
+ if [ -d "$src" ] && [ ! -L "$src" ]; then
746
+ fs_fail notdir "cannot move \"$src\": not a regular file"
747
+ fi
748
+ if [ "$sexp" != "-" ]; then
749
+ version=$(fs_version "$src")
750
+ if [ "$version" != "$sexp" ]; then
751
+ fs_fail stale "cannot move \"$src\": file changed since it was read"
752
+ fi
753
+ fi
754
+ # Destination: writeTarget's dialect, on whatever the disk holds now.
755
+ if [ -e "$dst" ] || [ -L "$dst" ]; then
756
+ if [ -d "$dst" ] && [ ! -L "$dst" ]; then
757
+ fs_fail notdir "cannot move \"$src\" to \"$dst\": not a regular file"
758
+ fi
759
+ if [ "$dexp" != "-" ]; then
760
+ version=$(fs_version "$dst")
761
+ if [ "$version" != "$dexp" ]; then
762
+ fs_fail stale "cannot move \"$src\" to \"$dst\": file changed since it was read"
763
+ fi
764
+ fi
765
+ else
766
+ if [ "$dexp" != "-" ]; then
767
+ fs_fail stale "cannot move \"$src\" to \"$dst\": file no longer exists"
768
+ fi
769
+ fi
770
+ sweep_staging "$ddir" "$dbase"
771
+ u=$(head -c 8 /dev/urandom 2>/dev/null | od -An -tx1 | tr -d ' \n')
772
+ staging="$ddir/.$dbase.$$.${u:-0}.tmpdir"
773
+ mkdir -- "$staging" 2>"$ERR_FILE" || {
774
+ err=$(cat "$ERR_FILE")
775
+ fs_fail "$(fs_classify "$err")" "$err"
776
+ }
777
+ CURRENT_STAGING=$staging
778
+ chmod 700 -- "$staging" 2>/dev/null
779
+ tmp="$staging/$dbase.tmp"
780
+ # The bytes travel kernel-side (cat to the staged temp) — no base64 round
781
+ # trip for a move's payload.
782
+ cat -- "$src" >"$tmp" 2>"$ERR_FILE" || {
783
+ err=$(cat "$ERR_FILE")
784
+ drop_staging
785
+ fs_fail io "$err"
786
+ }
787
+ chmod 600 -- "$tmp"
788
+ sync -f -- "$tmp" 2>/dev/null || :
789
+ if [ "$mode" != "-" ]; then
790
+ chmod "$mode" -- "$tmp" 2>"$ERR_FILE" || {
791
+ err=$(cat "$ERR_FILE")
792
+ drop_staging
793
+ fs_fail io "$err"
794
+ }
795
+ fi
796
+ if [ "$guard" = "no-replace" ]; then
797
+ if [ -e "$dst" ] || [ -L "$dst" ]; then
798
+ drop_staging
799
+ fs_fail exists "cannot move \"$src\" to \"$dst\": it already exists"
800
+ fi
801
+ ln -- "$tmp" "$dst" 2>"$ERR_FILE" || {
802
+ err=$(cat "$ERR_FILE")
803
+ drop_staging
804
+ fs_fail "$(fs_classify "$err")" "$err"
805
+ }
806
+ if ! [ "$tmp" -ef "$dst" ]; then
807
+ rm -f -- "$dst/$dbase.tmp"
808
+ drop_staging
809
+ fs_fail exists "cannot move \"$src\" to \"$dst\": it was created concurrently"
810
+ fi
811
+ else
812
+ mv -f -- "$tmp" "$dst" 2>"$ERR_FILE" || {
813
+ err=$(cat "$ERR_FILE")
814
+ drop_staging
815
+ fs_fail "$(fs_classify "$err")" "$err"
816
+ }
817
+ fi
818
+ # Same directory-entry durability as the write's publish above.
819
+ sync -d -- "$(dirname -- "$dst")" 2>/dev/null || :
820
+ drop_staging
821
+ # The destination's fresh identity, then the source's fate.
822
+ fs_stat -L "$(printf '%s' "$dst" | base64 | tr -d '\n')"
823
+ if rm -f -- "$src" 2>"$ERR_FILE"; then
824
+ :
825
+ else
826
+ src_err=$(cat "$ERR_FILE")
827
+ printf 'SRCFAIL|%s|%s\n' "$(fs_classify "$src_err")" "$(printf '%s' "$src_err" | base64 | tr -d '\n')"
828
+ fi
829
+ }
830
+
831
+ fs_batch_runner() {
832
+ # $1 = the flat batch record the FSB case assembled: op|nargs|arg…repeated.
833
+ # Every element is pipe-free (base64 alphabet, plain op names), so the
834
+ # walk below splits exactly. Each op runs in a subshell with its own
835
+ # capture files; the record stream lands on stdout (run_capture's OUT_FILE,
836
+ # which becomes the batch's single RES payload).
837
+ local batch op nargs rest arg n i first_err reason msg
838
+ batch=$1
839
+ LC_ALL=C
840
+ export LC_ALL=C
841
+ i=0
842
+ while [ -n "$batch" ]; do
843
+ i=$((i + 1))
844
+ op=${batch%%|*}
845
+ case $batch in
846
+ *\|*) rest=${batch#*|} ;;
847
+ *) rest= ;;
848
+ esac
849
+ nargs=${rest%%|*}
850
+ case $rest in
851
+ *\|*) rest=${rest#*|} ;;
852
+ *) rest= ;;
853
+ esac
854
+ case $nargs in
855
+ ''|*[!0-9]*) nargs=0 ;;
856
+ esac
857
+ set --
858
+ n=0
859
+ while [ "$n" -lt "$nargs" ]; do
860
+ arg=${rest%%|*}
861
+ case $rest in
862
+ *\|*) rest=${rest#*|} ;;
863
+ *) rest= ;;
864
+ esac
865
+ n=$((n + 1))
866
+ set -- "$@" "$arg"
867
+ done
868
+ # What remains belongs to the NEXT op record; keep it before the error
869
+ # parsing below reuses `rest`.
870
+ batch=$rest
871
+ opout="$TMPDIR_AGENT/b.$i.out"
872
+ operr="$TMPDIR_AGENT/b.$i.err"
873
+ if ( fs_dispatch "$op" "$@" ) >"$opout" 2>"$operr"; then
874
+ printf 'OK %s|%s\n' "$i" "$(b64enc_file "$opout")" >>"$TMPDIR_AGENT/b.res"
875
+ else
876
+ first_err=$(head -n 1 -- "$operr" 2>/dev/null)
877
+ case $first_err in
878
+ dsh-fs\|*)
879
+ rest=${first_err#dsh-fs|}
880
+ reason=${rest%%|*}
881
+ msg=${rest#*|}
882
+ printf 'BAD %s|%s|%s\n' "$i" "$reason" "${msg:-$(printf '' | base64 | tr -d '\n')}" >>"$TMPDIR_AGENT/b.res"
883
+ ;;
884
+ *)
885
+ printf 'BAD %s|io|%s\n' "$i" "$(printf '%s' "$first_err" | base64 | tr -d '\n')" >>"$TMPDIR_AGENT/b.res"
886
+ ;;
887
+ esac
888
+ fi
889
+ rm -f -- "$opout" "$operr"
890
+ done
891
+ cat -- "$TMPDIR_AGENT/b.res"
892
+ }
893
+
632
894
  fs_dispatch() {
633
895
  # $1 = op, $2.. = raw base64 arguments (handlers decode what they need to
634
896
  # treat as a path; write's content stays base64 until it hits the file).
@@ -644,13 +906,15 @@ fs_dispatch() {
644
906
  realpath) fs_realpath "$1" ;;
645
907
  read) fs_read "$1" "$2" "$3" ;;
646
908
  write) fs_write "$1" "$2" "$3" "$4" "$5" ;;
909
+ delete) fs_delete "$1" "$2" ;;
910
+ move) fs_move "$1" "$2" "$3" "$4" "$5" "$6" ;;
647
911
  # A host/agent contract breach is an I/O-class failure, not a file that
648
912
  # was not found: the mapped reason reads FS_IO_ERROR host-side.
649
913
  *) fs_fail protocol "unknown fs op" ;;
650
914
  esac
651
915
  }
652
916
 
653
- printf 'HELLO|wsl-agent|%s|%s|%s\n' "$PROTO_VERSION" "$AGENT_DIGEST" "$$"
917
+ printf 'HELLO|wsl-agent|%s|%s|%s|%s\n' "$PROTO_VERSION" "$AGENT_DIGEST" "$$" batch
654
918
 
655
919
  while IFS= read -r line; do
656
920
  case $line in
@@ -695,6 +959,12 @@ while IFS= read -r line; do
695
959
  nargs=${rest%%|*}
696
960
  rest=${rest#*|}
697
961
  maxout=${rest%%|*}
962
+ case $timeout_s in
963
+ ''|*[!0-9]*) timeout_s=0 ;;
964
+ esac
965
+ case $nargs in
966
+ ''|*[!0-9]*) nargs=0 ;;
967
+ esac
698
968
  # Protocol v6: an optional seventh field flags one stdin payload line
699
969
  # after the argv words. Absent (a stale peer) or 0 keeps the v5 shape —
700
970
  # the child reads an empty stdin and immediate EOF.
@@ -756,6 +1026,12 @@ while IFS= read -r line; do
756
1026
  rest=${rest#*|}
757
1027
  timeout_s=${rest%%|*}
758
1028
  nargs=${rest#*|}
1029
+ case $timeout_s in
1030
+ ''|*[!0-9]*) timeout_s=0 ;;
1031
+ esac
1032
+ case $nargs in
1033
+ ''|*[!0-9]*) nargs=0 ;;
1034
+ esac
759
1035
  # Arguments stay base64 (write's content must never become a shell
760
1036
  # variable of raw bytes); handlers decode what they treat as a path.
761
1037
  # A frame that ends before its declared argument count must never run
@@ -772,6 +1048,50 @@ while IFS= read -r line; do
772
1048
  # by the protocol.
773
1049
  run_capture "$req_id" "$timeout_s" 0 subshell fs_dispatch "$op" "$@"
774
1050
  ;;
1051
+ FSB\|*)
1052
+ # Protocol 7's batched FS frame: op records are read into one flat
1053
+ # pipe-free record string and handed to a single worker, whose record
1054
+ # stream becomes the one RES payload. The batch file starts empty so a
1055
+ # previous batch's records can never leak into this answer.
1056
+ header=${line#FSB|}
1057
+ req_id=${header%%|*}
1058
+ rest=${header#*|}
1059
+ timeout_s=${rest%%|*}
1060
+ nops=${rest#*|}
1061
+ case $nops in
1062
+ ''|*[!0-9]*) nops=0 ;;
1063
+ esac
1064
+ batch=
1065
+ n=0
1066
+ while [ "$n" -lt "$nops" ]; do
1067
+ IFS= read -r specline || exit 0
1068
+ specline=${specline#OP|}
1069
+ op=${specline%%|*}
1070
+ case $specline in
1071
+ *\|*) rest=${specline#*|} ;;
1072
+ *) rest= ;;
1073
+ esac
1074
+ nargs=${rest%%|*}
1075
+ case $rest in
1076
+ *\|*) rest=${rest#*|} ;;
1077
+ *) rest= ;;
1078
+ esac
1079
+ case $nargs in
1080
+ ''|*[!0-9]*) nargs=0 ;;
1081
+ esac
1082
+ n=$((n + 1))
1083
+ batch="${batch:+$batch|}$op|$nargs"
1084
+ k=0
1085
+ while [ "$k" -lt "$nargs" ]; do
1086
+ IFS= read -r arg_b64 || exit 0
1087
+ k=$((k + 1))
1088
+ batch="$batch|$arg_b64"
1089
+ done
1090
+ done
1091
+ : >"$TMPDIR_AGENT/b.res"
1092
+ run_capture "$req_id" "$timeout_s" 0 subshell fs_batch_runner "$batch"
1093
+ rm -f -- "$TMPDIR_AGENT/b.res"
1094
+ ;;
775
1095
  *)
776
1096
  printf 'ERR||protocol|%s\n' "$(printf '%s' "unrecognized request" | base64 | tr -d '\n')"
777
1097
  ;;
package/client.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Type declaration for the web client half (`client.js`): a plain
3
+ * `window.__ModuleLoader__` registration with no importable surface.
4
+ */
5
+ export {}
package/client.js ADDED
@@ -0,0 +1,98 @@
1
+ /**
2
+ * The doctor's GUI button: a pill in the conversation composer dock that drops
3
+ * `/wsl-doctor` into the current session's input and submits it.
4
+ *
5
+ * The composer dock's slot components receive the harness's standard props —
6
+ * `inputActions` among them. Sending is `setDraft(text)` (replace the whole
7
+ * draft with plain text) followed by `submit()` (send the current draft — the
8
+ * published face has no submit-with-text verb). When those verbs are missing
9
+ * the button degrades to a draft prefill, never to a broken control.
10
+ *
11
+ * Loaded by the harness's web client loader through the `dsh.client`
12
+ * declaration in package.json; the composition's bare-name row
13
+ * (`wsl-env-client-host`, mounting the no-op root export) is what puts this
14
+ * package on the web bundle list.
15
+ */
16
+ window.__ModuleLoader__.load({
17
+ id: "dsh-plugin-wsl-env",
18
+ factory(require) {
19
+ const React = require("react");
20
+ const h = React.createElement;
21
+
22
+ const COMMAND =
23
+ "请用 wsl_doctor 工具对当前会话的发行版运行环境诊断:先给 verdict," +
24
+ "blocked 时逐条列出失败项与 remedy,不代改文件、不代装软件包。";
25
+
26
+ function DoctorButton(props) {
27
+ const trigger = () => {
28
+ const actions = props && props.inputActions;
29
+ // The published InputActions face has no submit(text): submit() sends
30
+ // the CURRENT draft, and insertText needs a captureInsertion() span.
31
+ // setDraft replaces the whole draft with plain text, then submit()
32
+ // sends it — one click, no span bookkeeping.
33
+ if (actions && typeof actions.setDraft === "function" && typeof actions.submit === "function") {
34
+ try {
35
+ actions.setDraft(COMMAND);
36
+ actions.submit();
37
+ return;
38
+ } catch (error) {
39
+ // Fall through to the draft prefill below; the command text is the
40
+ // same either way.
41
+ }
42
+ }
43
+ if (actions && typeof actions.setDraft === "function") {
44
+ try {
45
+ actions.setDraft(COMMAND);
46
+ return;
47
+ } catch (error) {
48
+ // Ignored: the draft stays untouched rather than half-filled.
49
+ }
50
+ }
51
+ };
52
+ return h(
53
+ "button",
54
+ {
55
+ type: "button",
56
+ onClick: trigger,
57
+ title: "运行 WSL 环境诊断(doctor)",
58
+ style: {
59
+ display: "flex",
60
+ alignItems: "center",
61
+ gap: 5,
62
+ // The dock is a centered flex row; an auto left margin overrides
63
+ // the group centering for this item alone and pins the pill to
64
+ // the dock's right edge.
65
+ marginLeft: "auto",
66
+ padding: "2px 10px",
67
+ borderRadius: 999,
68
+ fontSize: 12,
69
+ border: "none",
70
+ outline: "none",
71
+ background: "transparent",
72
+ color: "inherit",
73
+ opacity: 0.75,
74
+ cursor: "pointer",
75
+ userSelect: "none",
76
+ },
77
+ },
78
+ "WSL 诊断"
79
+ );
80
+ }
81
+
82
+ return {
83
+ inject: ["slots"],
84
+ apply(ctx) {
85
+ ctx.slots.inject("conversation.composer.dock", function* () {
86
+ yield ctx.slots.register(
87
+ {
88
+ name: "conversation.composer.dock",
89
+ id: "wsl-doctor-button",
90
+ order: 9,
91
+ },
92
+ DoctorButton
93
+ );
94
+ });
95
+ },
96
+ };
97
+ },
98
+ });
package/cordis.patch.yml CHANGED
@@ -139,7 +139,30 @@
139
139
  - id: fs-sandbox
140
140
  disabled: true
141
141
 
142
+ # The shipped `working_directory` tool prints the host-canonical UNC spelling
143
+ # (`fs.processPath()`), which the distro shell cannot resolve — the same
144
+ # failure mode the cwd rewrite below removes. Disable the shipped row by id
145
+ # (a top-level entry: a disable inside an insert list is duplicate-id data,
146
+ # see the comment above), then mount the replacement in the insert list.
147
+ - id: tool-working-directory
148
+ disabled: true
149
+
142
150
  - insert:
151
+ # ═════════════════════════════════════════════════════════════════════════════
152
+ # The web client host half.
153
+ #
154
+ # The web app's client-modules roster only scans Loader rows whose name is
155
+ # an exact package name, and this package's service rows are all subpath
156
+ # mounts — so without this row the browser half declared under `dsh.client`
157
+ # (the doctor composer button) would never load. `.` is the no-op client
158
+ # host half (lib/client-host.js), safe at the composition root; the shell
159
+ # executor that used to own `.` lives at `dsh-plugin-wsl-env/shell` since
160
+ # 0.20.0 and is mounted inside the preset below. The bare specifier is
161
+ # load-bearing: do not "simplify" it to a subpath.
162
+ # ═════════════════════════════════════════════════════════════════════════════
163
+ - id: wsl-env-client-host
164
+ name: 'dsh-plugin-wsl-env'
165
+
143
166
  - id: fs-routing
144
167
  name: 'dsh-plugin-wsl-env/fs-routing'
145
168
  config:
@@ -172,6 +195,40 @@
172
195
  - id: wsl-preflight
173
196
  name: 'dsh-plugin-wsl-env/preflight'
174
197
 
198
+ # Distro-native working directory in the runtime context: rewrite the
199
+ # `working-directory:current` entry so a distro session reads its cwd as
200
+ # the POSIX path its own commands use (`/home/...`) instead of the host
201
+ # UNC spelling (`\\wsl.localhost\<distro>\...`). Display only: it touches
202
+ # one prompt entry, leaves drive paths and every other context alone, and
203
+ # degrades to a no-op on a harness without the assemble waterfall.
204
+ - id: wsl-cwd-prompt
205
+ name: 'dsh-plugin-wsl-env/cwd-prompt'
206
+ config:
207
+ enabled: true
208
+
209
+ # Distro-native `working_directory` tool: the third surface the cwd reaches
210
+ # the model through. Same tool name, parameters, and `cd` semantics (the
211
+ # harness's `workingDirectory` service still owns all directory state);
212
+ # the returned path is rewritten to the distro's POSIX form. Non-WSL paths
213
+ # pass through byte for byte. Pairs with the top-level disable of
214
+ # `tool-working-directory` above.
215
+ - id: wsl-cwd-prompt-tool
216
+ name: 'dsh-plugin-wsl-env/cwd-prompt-tool'
217
+
218
+ # Update check: on a slow timer (first check 2-10 minutes after boot, then
219
+ # once a day) ask the host's plugin-manager whether a newer stable release
220
+ # of this package exists, and publish one fact the shell-env row serves as
221
+ # DSH_WSL_PLUGIN_UPDATE. Advisory only: it never installs, never fetches on
222
+ # its own (the host's plugin-manager does the registry work), and a host
223
+ # without the service — or a bundle loaded from a linked checkout — skips
224
+ # the check quietly. Upgrading stays manual; the harness has no HMR, so a
225
+ # fresh version needs a restart to take effect.
226
+ - id: wsl-update-check
227
+ name: 'dsh-plugin-wsl-env/update-check'
228
+ config:
229
+ enabled: true
230
+ intervalMs: 86400000
231
+
175
232
  - insert:
176
233
  # ═════════════════════════════════════════════════════════════════════════════
177
234
  # preset-wsl — the WSL environment, scoped to agents that select this preset.
@@ -239,7 +296,7 @@
239
296
  # per-command shape. Bubblewrap is still required for the mount
240
297
  # profile; without it the providers fail closed.
241
298
  - id: wsl-shell
242
- name: 'dsh-plugin-wsl-env'
299
+ name: 'dsh-plugin-wsl-env/shell'
243
300
  config:
244
301
  # auto: follow the request workdir's UNC distro; "default"
245
302
  # forces WSL's default, and a name pins. Empty is auto.
@@ -300,6 +357,14 @@
300
357
  sampleOverCapGlobResults: false
301
358
  - id: tool-jobs
302
359
  name: '@deepseek-ai/dsh-tool-jobs'
360
+
361
+ # The model runs the environment doctor itself: the verdict
362
+ # lands in the transcript (ready, or blocked with per-failure
363
+ # copy-paste remedies). In-process via doctorReport(), so the
364
+ # live resident's state merges in; mounts inside this preset
365
+ # because a host-preset agent has no distro to examine.
366
+ - id: wsl-doctor-tool
367
+ name: 'dsh-plugin-wsl-env/wsl-doctor-tool'
303
368
  - id: tool-schedule
304
369
  name: '@deepseek-ai/dsh-tool-schedule'
305
370
  - id: skill-filesystem