pi-tuck 1.1.1 → 1.1.3
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.
- package/CHANGELOG.md +35 -0
- package/README.md +7 -3
- package/dist/src/build-id.d.ts +1 -1
- package/dist/src/build-id.js +1 -1
- package/dist/src/compaction.d.ts +7 -0
- package/dist/src/compaction.js +131 -92
- package/dist/src/diagnostics.d.ts +1 -1
- package/dist/src/run.d.ts +14 -7
- package/dist/src/run.js +57 -2
- package/package.json +1 -1
- package/src/build-id.ts +1 -1
- package/src/compaction.ts +114 -78
- package/src/run.ts +48 -13
package/src/run.ts
CHANGED
|
@@ -75,18 +75,53 @@ export class StartingPrompt {
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
export
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
export type RunPhase = 'decided' | 'claimed' | 'expired' | 'starting' | 'admitted' | 'failed' | 'commit-failed';
|
|
79
|
+
/** Claim/expiry describe the input plan; a failed attempt cannot re-enter a live phase. */
|
|
80
|
+
export const RUN_TRANSITIONS: Readonly<Record<RunPhase, readonly RunPhase[]>> = {
|
|
81
|
+
decided: ['claimed', 'expired', 'starting', 'failed', 'commit-failed'],
|
|
82
|
+
claimed: ['claimed', 'starting', 'failed', 'commit-failed'],
|
|
83
|
+
expired: ['starting', 'failed', 'commit-failed'],
|
|
84
|
+
starting: ['admitted', 'failed', 'commit-failed'],
|
|
85
|
+
admitted: ['admitted', 'failed', 'commit-failed'],
|
|
86
|
+
failed: ['failed', 'commit-failed'],
|
|
87
|
+
'commit-failed': ['commit-failed'],
|
|
88
|
+
};
|
|
89
|
+
let reportedInvalidTransition = false;
|
|
90
|
+
type RunState = { phase: Exclude<RunPhase, 'failed' | 'commit-failed'> } | { phase: 'failed' | 'commit-failed'; error: Error };
|
|
91
|
+
|
|
92
|
+
export class Run {
|
|
93
|
+
private state: RunState;
|
|
94
|
+
// Input-plan provenance survives starting/admission: later native threshold
|
|
95
|
+
// checks still choose the live view when the original input plan expired.
|
|
96
|
+
private expiredPlan = false;
|
|
97
|
+
constructor(phase: Exclude<RunPhase, 'failed' | 'commit-failed'>) { this.state = { phase }; }
|
|
98
|
+
get phase() { return this.state.phase; }
|
|
99
|
+
get expired() { return this.expiredPlan; }
|
|
100
|
+
/** Failure data, only present in a failed phase. The phase alone decides admission. */
|
|
101
|
+
get error() { return 'error' in this.state ? this.state.error : undefined; }
|
|
102
|
+
transition(phase: RunPhase, ctx?: Pick<ExtensionContext, 'hasUI'>, error?: Error): boolean {
|
|
103
|
+
if (!RUN_TRANSITIONS[this.phase].includes(phase) || ((phase === 'failed' || phase === 'commit-failed') && !error)) {
|
|
104
|
+
const message = `pi-tuck: invalid run transition ${this.phase} -> ${phase}`;
|
|
105
|
+
if (process.env.NODE_ENV === 'test') throw new Error(message);
|
|
106
|
+
if (ctx?.hasUI === false && !reportedInvalidTransition) {
|
|
107
|
+
reportedInvalidTransition = true;
|
|
108
|
+
try { process.stderr.write(message + '\n'); } catch { /* ended */ }
|
|
109
|
+
}
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
this.state = phase === 'failed' || phase === 'commit-failed' ? { phase, error: error! } : { phase };
|
|
113
|
+
if (phase === 'expired') this.expiredPlan = true;
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
82
116
|
prompt?: StartingPrompt;
|
|
83
|
-
cut
|
|
84
|
-
clips
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
117
|
+
cut = new PendingCut();
|
|
118
|
+
clips = new Map<string, Clip>();
|
|
119
|
+
pendingBoundaryReceipts: string[] = [];
|
|
120
|
+
thinkingRetryPending = false;
|
|
121
|
+
refusalReceipted = false;
|
|
122
|
+
clear() {
|
|
123
|
+
this.prompt = undefined; this.cut.clear(); this.clips.clear(); this.pendingBoundaryReceipts = [];
|
|
124
|
+
this.thinkingRetryPending = false; this.refusalReceipted = false; this.expiredPlan = false;
|
|
125
|
+
}
|
|
90
126
|
}
|
|
91
|
-
export const createRun = (phase: Run[
|
|
92
|
-
cut: new PendingCut(), clips: new Map(), pendingBoundaryCommit: false, pendingBoundaryReceipts: [], thinkingRetryPending: false, refusalReceipted: false });
|
|
127
|
+
export const createRun = (phase: ConstructorParameters<typeof Run>[0]): Run => new Run(phase);
|