@dyyz1993/pi-coding-agent 0.74.41 → 0.74.43
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.
|
@@ -161,6 +161,19 @@ export default function (pi: ExtensionAPI) {
|
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
pi.on("session_start", async () => {
|
|
164
|
+
// Kill all managed processes from previous session before clearing references.
|
|
165
|
+
// Without this, background processes become orphans when the session switches.
|
|
166
|
+
for (const m of managed.values()) {
|
|
167
|
+
if (!m.resolved && m.proc.pid) {
|
|
168
|
+
try {
|
|
169
|
+
killProcessTree(m.proc.pid);
|
|
170
|
+
} catch {
|
|
171
|
+
// Process may have already exited — ignore
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (m.logStream) m.logStream.end();
|
|
175
|
+
}
|
|
176
|
+
|
|
164
177
|
const rawChannel = pi.registerChannel(BASH_CHANNEL_NAME);
|
|
165
178
|
channel = createTypedChannel<BashChannelContract>(rawChannel).server;
|
|
166
179
|
managed.clear();
|
|
@@ -852,17 +865,40 @@ export default function (pi: ExtensionAPI) {
|
|
|
852
865
|
const { proc, isLive } = result;
|
|
853
866
|
const durationMs = (proc.endedAt ?? Date.now()) - proc.startedAt;
|
|
854
867
|
|
|
855
|
-
|
|
868
|
+
const rawOutput = proc.output || "(no output yet)";
|
|
869
|
+
const allLines = rawOutput.split("\n");
|
|
870
|
+
const totalLines = allLines.length;
|
|
871
|
+
|
|
872
|
+
let displayLines: string[];
|
|
873
|
+
let startLine: number;
|
|
874
|
+
let endLine: number;
|
|
856
875
|
|
|
857
876
|
if (grepPattern) {
|
|
858
|
-
|
|
877
|
+
// Grep mode: filter matching lines, keep line numbers
|
|
878
|
+
const matched = allLines
|
|
879
|
+
.map((line, i) => ({ line, num: i + 1 }))
|
|
880
|
+
.filter((e) => e.line.toLowerCase().includes(grepPattern.toLowerCase()));
|
|
881
|
+
if (matched.length === 0) {
|
|
882
|
+
displayLines = [`(no lines matching "${grepPattern}")`];
|
|
883
|
+
startLine = 0;
|
|
884
|
+
endLine = 0;
|
|
885
|
+
} else {
|
|
886
|
+
// Apply lastLines to grep results if specified
|
|
887
|
+
const sliced = lastLines && lastLines > 0 ? matched.slice(-lastLines) : matched;
|
|
888
|
+
displayLines = sliced.map((e) => `L${e.num}: ${e.line}`);
|
|
889
|
+
startLine = sliced[0].num;
|
|
890
|
+
endLine = sliced[sliced.length - 1].num;
|
|
891
|
+
}
|
|
892
|
+
} else {
|
|
893
|
+
// Normal mode: take last N lines with line numbers
|
|
894
|
+
const n = lastLines && lastLines > 0 ? lastLines : 50;
|
|
895
|
+
startLine = Math.max(1, totalLines - n + 1);
|
|
896
|
+
endLine = totalLines;
|
|
897
|
+
const selected = allLines.slice(-n);
|
|
898
|
+
displayLines = selected.map((line, i) => `L${startLine + i}: ${line}`);
|
|
859
899
|
}
|
|
860
900
|
|
|
861
|
-
|
|
862
|
-
output = takeLastLines(output, lastLines);
|
|
863
|
-
} else if (!grepPattern) {
|
|
864
|
-
output = takeLastLines(output, 50);
|
|
865
|
-
}
|
|
901
|
+
const output = displayLines.join("\n");
|
|
866
902
|
|
|
867
903
|
const header = [
|
|
868
904
|
`Process: ${proc.command}`,
|
|
@@ -873,6 +909,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
873
909
|
proc.exitCode !== undefined ? `Exit code: ${proc.exitCode}` : null,
|
|
874
910
|
proc.logPath ? `Log: ${proc.logPath}` : null,
|
|
875
911
|
proc.error ? `Error: ${proc.error}` : null,
|
|
912
|
+
totalLines > 0 ? `Lines: ${startLine}-${endLine} of ${totalLines} total` : null,
|
|
876
913
|
grepPattern ? `Filtered by: "${grepPattern}"` : null,
|
|
877
914
|
"",
|
|
878
915
|
isLive ? "Output so far:" : "Output:",
|