Commit 61adc7d
committed
feat(status-line): surface hidden native non-zero exits as LastExit: N tag
PowerShell treats pipeline success as "$? on the last statement",
not "all natives exited 0". A pipeline like `cmd /c exit 7; "after"`
ends with $? True (the "after" string succeeded) even though cmd
returned 7. PowerShell.MCP previously rendered this as:
✓ Pipeline executed successfully | ... | Duration: 0.20s | Location ...
— the 7 was completely silent. An AI driving a CI-style pipeline
(`npm install; npm audit; npm test` and so on) would read the ✓,
assume clean, and move on while npm audit's non-zero exit carried
real information that just got dropped.
Port the gating pattern ripple uses for its OSC 633;L extension:
1. Snapshot $global:LASTEXITCODE BEFORE Invoke-Expression runs, so
we can later tell whether THIS pipeline wrote the value or
inherited it from an earlier native invocation in a prior call.
2. Capture $? and $global:LASTEXITCODE IMMEDIATELY after
Invoke-Expression returns — any statement between (including a
bare variable assignment) would reset $? to True.
3. Report only when all three gates fire:
$? True (pipeline overall succeeded → ✓ badge)
lecChanged (native wrote $LASTEXITCODE this pipeline)
lec non-zero (the value worth telling the AI about)
Any other combination is silent: failed pipelines already show
✗ + Errors count, and a stale $LASTEXITCODE from a prior
session would only add noise to current happy-path lines.
The new `LastExit: N` segment sits immediately after Duration in the
status line — next to the exit-code semantic domain, ahead of
Errors/Warnings/Info which describe PS streams (a separate axis).
Examples:
cmd /c exit 7; "after"
Before: ✓ ... | Duration: 0.20s | Location ...
After: ✓ ... | Duration: 0.20s | LastExit: 7 | Location ...
Get-Item /nope → ✗ ... | Errors: 1 | ...
(lecChanged false, $? false, LastExit gates all silent)
"plain string" → ✓ ... | Duration: 0.20s | ...
(no native ran, LastExit silent)
Session-state limitation inherited from ripple's implementation:
if the prior pipeline happened to leave $LASTEXITCODE at the same
value this pipeline's native produces (e.g. `cmd /c exit 7` twice
in a row), lecChanged is false and LastExit stays silent. The
underlying PS constraint (no runtime hook for "a native updated
LASTEXITCODE") makes a fully deterministic detection impossible.
Documented in docs/pwsh-mcp-vs-ripple-evaluation.md.
No API or wire-shape change. The `LastExitReport` field is only
added to the in-process StreamResults hashtable; existing callers
tolerate its presence, and the status-line rendering omits the tag
when the value is 0 (matches the zero-tag-omission discipline used
for Errors/Warnings/Info).1 parent e8596f7 commit 61adc7d
1 file changed
Lines changed: 63 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
105 | 114 | | |
106 | 115 | | |
107 | 116 | | |
108 | 117 | | |
109 | 118 | | |
110 | 119 | | |
111 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
112 | 128 | | |
113 | 129 | | |
114 | 130 | | |
| |||
126 | 142 | | |
127 | 143 | | |
128 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
129 | 163 | | |
130 | 164 | | |
131 | 165 | | |
132 | 166 | | |
133 | 167 | | |
134 | 168 | | |
| 169 | + | |
135 | 170 | | |
136 | 171 | | |
137 | 172 | | |
| |||
143 | 178 | | |
144 | 179 | | |
145 | 180 | | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
146 | 188 | | |
147 | 189 | | |
148 | 190 | | |
| |||
318 | 360 | | |
319 | 361 | | |
320 | 362 | | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
321 | 373 | | |
322 | 374 | | |
323 | 375 | | |
| |||
358 | 410 | | |
359 | 411 | | |
360 | 412 | | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
365 | 424 | | |
366 | 425 | | |
367 | 426 | | |
| |||
0 commit comments