@davideasden/pi-undo 0.2.29 → 0.2.30
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.
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
package/src/controller.ts
CHANGED
|
@@ -18,6 +18,8 @@ import type {
|
|
|
18
18
|
} from "./model.ts";
|
|
19
19
|
import type { RestorePlan, RestoreResult } from "./restore-engine.ts";
|
|
20
20
|
|
|
21
|
+
const INPUT_CAPTURE_RETRY_DELAY_MS = 250;
|
|
22
|
+
|
|
21
23
|
/** 控制器所需的最小运行时适配层;Pi 绑定在 extension 中完成。 */
|
|
22
24
|
export interface ControllerDependencies {
|
|
23
25
|
readonly workspaceIdentity: string;
|
|
@@ -483,9 +485,18 @@ export class UndoControllerImpl implements UndoController {
|
|
|
483
485
|
if (warmUp !== undefined) await warmUp;
|
|
484
486
|
const warmUpManifest = this.warmUpManifest;
|
|
485
487
|
this.warmUpManifest = undefined;
|
|
486
|
-
|
|
488
|
+
const capture = (): Promise<SnapshotManifest> => warmUpManifest !== undefined && this.dependencies.captureBaseline !== undefined
|
|
487
489
|
? this.captureBaselineWithWorkspaceLock(warmUpManifest)
|
|
488
490
|
: this.captureWithWorkspaceLock();
|
|
491
|
+
try {
|
|
492
|
+
return await capture();
|
|
493
|
+
} catch (error) {
|
|
494
|
+
// 输入前捕获也可能撞上短暂的工作区竞态;重试一次后仍失败才放弃本轮历史。
|
|
495
|
+
if (!isTransientCaptureFailure(error)) throw error;
|
|
496
|
+
await sleep(INPUT_CAPTURE_RETRY_DELAY_MS);
|
|
497
|
+
checkOperation();
|
|
498
|
+
return capture();
|
|
499
|
+
}
|
|
489
500
|
}
|
|
490
501
|
|
|
491
502
|
private async captureInputForToken(text: string, token: symbol): Promise<void> {
|
package/src/git-runner.ts
CHANGED
|
@@ -67,7 +67,7 @@ export class GitRunner {
|
|
|
67
67
|
let outcome = "failed";
|
|
68
68
|
let exitCode: number | null = null;
|
|
69
69
|
try {
|
|
70
|
-
const result = await this.runCommand(args, options);
|
|
70
|
+
const result = await this.runCommand(args, options, command);
|
|
71
71
|
outcome = result.timedOut ? "timeout" : result.aborted ? "cancelled" : "exit";
|
|
72
72
|
exitCode = result.code;
|
|
73
73
|
return result;
|
|
@@ -82,7 +82,7 @@ export class GitRunner {
|
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
private async runCommand(args: readonly string[], options: GitRunOptions): Promise<GitRunResult> {
|
|
85
|
+
private async runCommand(args: readonly string[], options: GitRunOptions, command: string): Promise<GitRunResult> {
|
|
86
86
|
const stderrLimit = options.stderrLimit ?? DEFAULT_STDERR_LIMIT;
|
|
87
87
|
if (!Number.isInteger(stderrLimit) || stderrLimit < 0) {
|
|
88
88
|
throw new RangeError("stderrLimit 必须是非负整数");
|
|
@@ -212,7 +212,11 @@ export class GitRunner {
|
|
|
212
212
|
return;
|
|
213
213
|
}
|
|
214
214
|
if (!killed && exit.code !== 0) {
|
|
215
|
-
reject(new GitRunError(
|
|
215
|
+
reject(new GitRunError(
|
|
216
|
+
"git_failed",
|
|
217
|
+
formatGitFailure(command, exit.code, result.stderr),
|
|
218
|
+
result,
|
|
219
|
+
));
|
|
216
220
|
return;
|
|
217
221
|
}
|
|
218
222
|
resolve(result);
|
|
@@ -610,6 +614,15 @@ function mergeEnvironment(overrides: Readonly<Record<string, string | undefined>
|
|
|
610
614
|
return environment;
|
|
611
615
|
}
|
|
612
616
|
|
|
617
|
+
function formatGitFailure(command: string, code: number | null, stderr: string): string {
|
|
618
|
+
const detail = stderr
|
|
619
|
+
.replace(/[\u0000-\u001F\u007F]+/g, " ")
|
|
620
|
+
.replace(/\s+/g, " ")
|
|
621
|
+
.trim()
|
|
622
|
+
.slice(0, 512);
|
|
623
|
+
return `${command} 退出码为 ${String(code)}${detail.length === 0 ? "" : `: ${detail}`}`;
|
|
624
|
+
}
|
|
625
|
+
|
|
613
626
|
function errorMessage(error: unknown): string {
|
|
614
627
|
return error instanceof Error ? error.message : String(error);
|
|
615
628
|
}
|