pi-tuck 1.1.0 → 1.1.2
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 +42 -0
- package/README.md +10 -3
- package/dist/index.js +2 -0
- package/dist/src/build-id.d.ts +1 -1
- package/dist/src/build-id.js +1 -1
- package/dist/src/compaction.d.ts +21 -1
- package/dist/src/compaction.js +203 -106
- package/dist/src/diagnostics.d.ts +1 -1
- package/dist/src/run.d.ts +14 -7
- package/dist/src/run.js +57 -2
- package/dist/src/semantic-recall.d.ts +2 -0
- package/dist/src/semantic-recall.js +53 -6
- package/dist/src/status.d.ts +1 -0
- package/dist/src/status.js +2 -0
- package/index.ts +1 -0
- package/package.json +1 -1
- package/src/build-id.ts +1 -1
- package/src/compaction.ts +163 -86
- package/src/run.ts +48 -13
- package/src/semantic-recall.ts +28 -3
- package/src/status.ts +2 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type RecallPolicy } from './recall.js';
|
|
2
2
|
import type { SessionEntry } from '@earendil-works/pi-coding-agent';
|
|
3
|
-
export declare const DIAGNOSTIC_BUILD = "
|
|
3
|
+
export declare const DIAGNOSTIC_BUILD = "e36f2c823c0d56405dab4cda3f16894a034bdb082d322c30587474d15b332b70";
|
|
4
4
|
export interface Receipt {
|
|
5
5
|
id: string;
|
|
6
6
|
build: string;
|
package/dist/src/run.d.ts
CHANGED
|
@@ -36,18 +36,25 @@ export declare class StartingPrompt {
|
|
|
36
36
|
id(branch: readonly SessionEntry[]): string | undefined;
|
|
37
37
|
text(branch: readonly SessionEntry[]): string;
|
|
38
38
|
}
|
|
39
|
-
export
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
export type RunPhase = 'decided' | 'claimed' | 'expired' | 'starting' | 'admitted' | 'failed' | 'commit-failed';
|
|
40
|
+
/** Claim/expiry describe the input plan; a failed attempt cannot re-enter a live phase. */
|
|
41
|
+
export declare const RUN_TRANSITIONS: Readonly<Record<RunPhase, readonly RunPhase[]>>;
|
|
42
|
+
export declare class Run {
|
|
43
|
+
private state;
|
|
44
|
+
private expiredPlan;
|
|
45
|
+
constructor(phase: Exclude<RunPhase, 'failed' | 'commit-failed'>);
|
|
46
|
+
get phase(): "starting" | "failed" | "decided" | "claimed" | "expired" | "admitted" | "commit-failed";
|
|
47
|
+
get expired(): boolean;
|
|
48
|
+
/** Failure data, only present in a failed phase. The phase alone decides admission. */
|
|
49
|
+
get error(): Error | undefined;
|
|
50
|
+
transition(phase: RunPhase, ctx?: Pick<ExtensionContext, 'hasUI'>, error?: Error): boolean;
|
|
43
51
|
prompt?: StartingPrompt;
|
|
44
52
|
cut: PendingCut;
|
|
45
53
|
clips: Map<string, Clip>;
|
|
46
|
-
pendingBoundaryCommit: boolean;
|
|
47
54
|
pendingBoundaryReceipts: string[];
|
|
48
55
|
thinkingRetryPending: boolean;
|
|
49
|
-
failure?: Error;
|
|
50
56
|
refusalReceipted: boolean;
|
|
57
|
+
clear(): void;
|
|
51
58
|
}
|
|
52
|
-
export declare const createRun: (phase: Run[
|
|
59
|
+
export declare const createRun: (phase: ConstructorParameters<typeof Run>[0]) => Run;
|
|
53
60
|
export {};
|
package/dist/src/run.js
CHANGED
|
@@ -85,5 +85,60 @@ export class StartingPrompt {
|
|
|
85
85
|
throw new Error('The starting prompt entry is no longer on this branch');
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
/** Claim/expiry describe the input plan; a failed attempt cannot re-enter a live phase. */
|
|
89
|
+
export const RUN_TRANSITIONS = {
|
|
90
|
+
decided: ['claimed', 'expired', 'starting', 'failed', 'commit-failed'],
|
|
91
|
+
claimed: ['claimed', 'starting', 'failed', 'commit-failed'],
|
|
92
|
+
expired: ['starting', 'failed', 'commit-failed'],
|
|
93
|
+
starting: ['admitted', 'failed', 'commit-failed'],
|
|
94
|
+
admitted: ['admitted', 'failed', 'commit-failed'],
|
|
95
|
+
failed: ['failed', 'commit-failed'],
|
|
96
|
+
'commit-failed': ['commit-failed'],
|
|
97
|
+
};
|
|
98
|
+
let reportedInvalidTransition = false;
|
|
99
|
+
export class Run {
|
|
100
|
+
state;
|
|
101
|
+
// Input-plan provenance survives starting/admission: later native threshold
|
|
102
|
+
// checks still choose the live view when the original input plan expired.
|
|
103
|
+
expiredPlan = false;
|
|
104
|
+
constructor(phase) { this.state = { phase }; }
|
|
105
|
+
get phase() { return this.state.phase; }
|
|
106
|
+
get expired() { return this.expiredPlan; }
|
|
107
|
+
/** Failure data, only present in a failed phase. The phase alone decides admission. */
|
|
108
|
+
get error() { return 'error' in this.state ? this.state.error : undefined; }
|
|
109
|
+
transition(phase, ctx, error) {
|
|
110
|
+
if (!RUN_TRANSITIONS[this.phase].includes(phase) || ((phase === 'failed' || phase === 'commit-failed') && !error)) {
|
|
111
|
+
const message = `pi-tuck: invalid run transition ${this.phase} -> ${phase}`;
|
|
112
|
+
if (process.env.NODE_ENV === 'test')
|
|
113
|
+
throw new Error(message);
|
|
114
|
+
if (ctx?.hasUI === false && !reportedInvalidTransition) {
|
|
115
|
+
reportedInvalidTransition = true;
|
|
116
|
+
try {
|
|
117
|
+
process.stderr.write(message + '\n');
|
|
118
|
+
}
|
|
119
|
+
catch { /* ended */ }
|
|
120
|
+
}
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
this.state = phase === 'failed' || phase === 'commit-failed' ? { phase, error: error } : { phase };
|
|
124
|
+
if (phase === 'expired')
|
|
125
|
+
this.expiredPlan = true;
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
prompt;
|
|
129
|
+
cut = new PendingCut();
|
|
130
|
+
clips = new Map();
|
|
131
|
+
pendingBoundaryReceipts = [];
|
|
132
|
+
thinkingRetryPending = false;
|
|
133
|
+
refusalReceipted = false;
|
|
134
|
+
clear() {
|
|
135
|
+
this.prompt = undefined;
|
|
136
|
+
this.cut.clear();
|
|
137
|
+
this.clips.clear();
|
|
138
|
+
this.pendingBoundaryReceipts = [];
|
|
139
|
+
this.thinkingRetryPending = false;
|
|
140
|
+
this.refusalReceipted = false;
|
|
141
|
+
this.expiredPlan = false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
export const createRun = (phase) => new Run(phase);
|
|
@@ -133,6 +133,8 @@ export declare const MAX_INDEX_UNITS = 8000;
|
|
|
133
133
|
export declare function healDelayMs(attempts: number, integrity: boolean, delays?: readonly number[], steady?: number): number;
|
|
134
134
|
export type SemanticState = 'disabled' | 'unavailable' | 'preparing' | 'ready' | 'waiting';
|
|
135
135
|
export type SemanticSetup = 'off-settings' | 'off-user' | 'not-installed' | 'off-platform' | 'off-project' | 'starting' | 'failed' | 'ready';
|
|
136
|
+
/** Host policy is re-evaluated at session start; only a start may publish ready. */
|
|
137
|
+
export declare const SEMANTIC_SETUP_TRANSITIONS: Readonly<Record<SemanticSetup, readonly SemanticSetup[]>>;
|
|
136
138
|
interface SetupDetail {
|
|
137
139
|
installed?: boolean;
|
|
138
140
|
reason?: string;
|
|
@@ -222,6 +222,18 @@ const SCORE_CHUNK = 1024;
|
|
|
222
222
|
export function healDelayMs(attempts, integrity, delays = HEAL_DELAYS_MS, steady = HEAL_STEADY_MS) { return integrity ? steady : delays[attempts] ?? steady; }
|
|
223
223
|
/** Errors that mean "the history moved or a slice ended; try again", not that the runtime failed. They do not make the state `unavailable`. */
|
|
224
224
|
const CHURN = /indexing incomplete|history changed|source changed before|branch or source changed|cancelled/i;
|
|
225
|
+
const OFF_SETUP = ['off-settings', 'off-user', 'off-platform', 'off-project'];
|
|
226
|
+
/** Host policy is re-evaluated at session start; only a start may publish ready. */
|
|
227
|
+
export const SEMANTIC_SETUP_TRANSITIONS = {
|
|
228
|
+
'off-settings': OFF_SETUP,
|
|
229
|
+
'off-user': [...OFF_SETUP, 'not-installed', 'starting', 'failed'],
|
|
230
|
+
'off-platform': [...OFF_SETUP, 'not-installed', 'starting'],
|
|
231
|
+
'off-project': [...OFF_SETUP, 'not-installed', 'starting'],
|
|
232
|
+
'not-installed': [...OFF_SETUP, 'not-installed', 'starting', 'failed'],
|
|
233
|
+
starting: [...OFF_SETUP, 'not-installed', 'starting', 'failed', 'ready'],
|
|
234
|
+
failed: [...OFF_SETUP, 'not-installed', 'starting', 'failed'],
|
|
235
|
+
ready: [...OFF_SETUP, 'not-installed', 'starting', 'failed', 'ready'],
|
|
236
|
+
};
|
|
225
237
|
/** Setup and operator wording have one owner; runtime indexing state remains separate. */
|
|
226
238
|
export function semanticSetupMessage(setup, detail = {}) {
|
|
227
239
|
switch (setup) {
|
|
@@ -597,7 +609,14 @@ export class SemanticRecallController {
|
|
|
597
609
|
_timer;
|
|
598
610
|
_error = null;
|
|
599
611
|
get enabled() { return this._enabled; }
|
|
600
|
-
set enabled(value) {
|
|
612
|
+
set enabled(value) {
|
|
613
|
+
this._enabled = value;
|
|
614
|
+
if (!value && this.setup === 'ready') {
|
|
615
|
+
const reason = this.error ?? this.cleanupError;
|
|
616
|
+
this.setSetup(reason ? 'failed' : 'off-user', reason ? { stage: 'start', reason } : {});
|
|
617
|
+
}
|
|
618
|
+
this.touch();
|
|
619
|
+
}
|
|
601
620
|
get current() { return this._current; }
|
|
602
621
|
set current(value) { this._current = value; this.touch(); }
|
|
603
622
|
get task() { return this._task; }
|
|
@@ -644,7 +663,14 @@ export class SemanticRecallController {
|
|
|
644
663
|
}
|
|
645
664
|
catch { } }); }
|
|
646
665
|
/** A host that could not configure the runtime records why a requested start failed. The controller stays disabled and `lastError` carries the reason until the next `enable`. */
|
|
647
|
-
setSetup(setup, detail = {}) {
|
|
666
|
+
setSetup(setup, detail = {}) {
|
|
667
|
+
if (!SEMANTIC_SETUP_TRANSITIONS[this.setup].includes(setup))
|
|
668
|
+
return;
|
|
669
|
+
const announced = setup === 'ready' && this.setupDetail.announced;
|
|
670
|
+
this.setup = setup;
|
|
671
|
+
this.setupDetail = announced ? { ...detail, announced: true } : detail;
|
|
672
|
+
this.touch();
|
|
673
|
+
}
|
|
648
674
|
/** Compatibility for hosts that already record an external start failure. */
|
|
649
675
|
refuse(reason) { this.setSetup('failed', { stage: 'start', reason }); }
|
|
650
676
|
setupNotice() { return semanticSetupNotice(this.setup, this.setupDetail); }
|
|
@@ -669,10 +695,31 @@ export class SemanticRecallController {
|
|
|
669
695
|
const text = await readFile(path, 'utf8').catch((error) => { throw error.code === 'ENOENT' ? new Error('Semantic recall is not set up yet: pi-tuck sets it up when a session starts, unless pi-tuck.json turns it off') : error; });
|
|
670
696
|
this.configure({ ...JSON.parse(text), ...(runtime?.nativeOwnerHelperPath === undefined ? {} : { nativeOwnerHelperPath: runtime.nativeOwnerHelperPath }) });
|
|
671
697
|
}
|
|
672
|
-
enable() {
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
698
|
+
enable() {
|
|
699
|
+
// Explicit opt-in can end off-user; project, platform and settings policy belongs to the host.
|
|
700
|
+
if (['off-user', 'not-installed', 'failed'].includes(this.setup))
|
|
701
|
+
this.setSetup('starting');
|
|
702
|
+
if (!SEMANTIC_SETUP_TRANSITIONS[this.setup].includes('ready'))
|
|
703
|
+
return;
|
|
704
|
+
try {
|
|
705
|
+
if (this.closing || this.joiningSearches || this.cleanupError)
|
|
706
|
+
throw new Error('Semantic cleanup is unresolved; retry close before enable');
|
|
707
|
+
if (!this.config)
|
|
708
|
+
throw new Error('Optional local semantic runtime is not configured');
|
|
709
|
+
this.setSetup('ready');
|
|
710
|
+
this.enabled = true;
|
|
711
|
+
this.error = null;
|
|
712
|
+
this.healReason = null;
|
|
713
|
+
this.healAttempts = 0;
|
|
714
|
+
this.cancelHeal();
|
|
715
|
+
if (this.provider && this.active)
|
|
716
|
+
this.schedule(this.provider);
|
|
717
|
+
}
|
|
718
|
+
catch (error) {
|
|
719
|
+
this.setSetup('failed', { stage: 'start', reason: error instanceof Error ? error.message : String(error) });
|
|
720
|
+
throw error;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
676
723
|
status() { return { setup: this.setup, setupMessage: semanticSetupMessage(this.setup, this.setupDetail), enabled: this.enabled, configured: Boolean(this.config), cleanupError: this.cleanupError, state: (!this.enabled ? 'disabled' : this.healReason !== null || (this.error !== null && !CHURN.test(this.error)) ? 'unavailable' : this.task || this.timer ? 'preparing' : this.current?.complete ? 'ready' : 'waiting'), snapshotId: this.current?.id ?? null, throughEntryId: this.current?.throughEntryId ?? null, eligibleSources: this.current?.sources.length ?? 0, totalUnits: this.current?.units.length ?? 0, coveredUnits: this.current?.indexed.size ?? 0, indexingComplete: Boolean(this.current?.complete), lastError: this.error ?? this.healReason ?? semanticSetupMessage(this.setup, this.setupDetail), window: this.current ? windowCoverage(this.current) : null, recovery: this.healReason === null ? null : { attempts: this.healAttempts, integrity: this.healIntegrity, retryAt: this.healRetryAt === null ? null : new Date(this.healRetryAt).toISOString() }, operations: { ...this.operations }, limits: { keyword: 16000, broad: 20000 } }; }
|
|
677
724
|
/** The existing model-facing coverage contract: setup metadata belongs to operator status, not the request. */
|
|
678
725
|
requestCoverage() { const { setup, setupMessage, ...coverage } = this.status(); return coverage; }
|
package/dist/src/status.d.ts
CHANGED
package/dist/src/status.js
CHANGED
|
@@ -15,6 +15,8 @@ export const LOADED_VERSION = (() => {
|
|
|
15
15
|
export function statusText(input) {
|
|
16
16
|
if (!input.active)
|
|
17
17
|
return `pi-tuck ${input.version} is loaded but inactive in this host; Pi's own compaction runs.`;
|
|
18
|
+
if (input.compaction?.kind === 'standingDown')
|
|
19
|
+
return `pi-tuck ${input.version}: standing down: ${input.compaction.reason}; Pi's own compaction runs.`;
|
|
18
20
|
const cuts = input.branch.filter(e => e.type === "compaction"), ours = cuts.filter(e => e.details?.compactor === "pi-tuck");
|
|
19
21
|
const last = ours.at(-1), before = last?.tokensBefore, after = last?.details?.tokensAfter;
|
|
20
22
|
const count = (n) => n.toLocaleString("en-US");
|
package/index.ts
CHANGED
|
@@ -72,6 +72,7 @@ export default async function (pi: ExtensionAPI) {
|
|
|
72
72
|
pi.on("session_start", (_event, ctx) => {
|
|
73
73
|
const current = ++session;
|
|
74
74
|
stderrSaid.clear();
|
|
75
|
+
if (handle.state?.(ctx).kind === "standingDown") return;
|
|
75
76
|
if (settings.error) once(ctx, `pi-tuck: ${settings.error}; using the defaults.`, "warning");
|
|
76
77
|
if (!appleSilicon)
|
|
77
78
|
return announce(ctx, "off-platform");
|
package/package.json
CHANGED
package/src/build-id.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const BUILD_ID = "
|
|
1
|
+
export const BUILD_ID = "e36f2c823c0d56405dab4cda3f16894a034bdb082d322c30587474d15b332b70";
|