instar 1.2.33 → 1.2.35
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/dist/core/MessagingToneGate.d.ts.map +1 -1
- package/dist/core/MessagingToneGate.js +30 -1
- package/dist/core/MessagingToneGate.js.map +1 -1
- package/dist/tunnel/CloudflareNamedProvider.d.ts +51 -0
- package/dist/tunnel/CloudflareNamedProvider.d.ts.map +1 -0
- package/dist/tunnel/CloudflareNamedProvider.js +258 -0
- package/dist/tunnel/CloudflareNamedProvider.js.map +1 -0
- package/dist/tunnel/CloudflareQuickProvider.d.ts +48 -0
- package/dist/tunnel/CloudflareQuickProvider.d.ts.map +1 -0
- package/dist/tunnel/CloudflareQuickProvider.js +201 -0
- package/dist/tunnel/CloudflareQuickProvider.js.map +1 -0
- package/dist/tunnel/TunnelLifecycle.d.ts +190 -0
- package/dist/tunnel/TunnelLifecycle.d.ts.map +1 -0
- package/dist/tunnel/TunnelLifecycle.js +222 -0
- package/dist/tunnel/TunnelLifecycle.js.map +1 -0
- package/dist/tunnel/TunnelNotifier.d.ts +110 -0
- package/dist/tunnel/TunnelNotifier.d.ts.map +1 -0
- package/dist/tunnel/TunnelNotifier.js +268 -0
- package/dist/tunnel/TunnelNotifier.js.map +1 -0
- package/dist/tunnel/TunnelProvider.d.ts +80 -0
- package/dist/tunnel/TunnelProvider.d.ts.map +1 -0
- package/dist/tunnel/TunnelProvider.js +28 -0
- package/dist/tunnel/TunnelProvider.js.map +1 -0
- package/package.json +1 -1
- package/src/data/builtin-manifest.json +2 -2
- package/upgrades/1.2.34.md +84 -0
- package/upgrades/1.2.35.md +96 -0
- package/upgrades/side-effects/context-death-stop-hook.md +100 -0
- package/upgrades/side-effects/tunnel-failure-resilience.md +118 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TunnelNotifier — two-channel routing of tunnel lifecycle events to
|
|
3
|
+
* the user.
|
|
4
|
+
*
|
|
5
|
+
* Per spec specs/dev-infrastructure/tunnel-failure-resilience.md Part 3.
|
|
6
|
+
*
|
|
7
|
+
* Strict channel separation (the GPT external review's CRITICAL finding):
|
|
8
|
+
* - GROUP topic (Dashboard / Lifeline fallback / General fallback):
|
|
9
|
+
* status text only. NEVER the URL, NEVER the PIN, NEVER a signed
|
|
10
|
+
* view link. Anyone in the group can read those, which would defeat
|
|
11
|
+
* the owner-only consent gate.
|
|
12
|
+
* - OWNER DM (private bot chat with the owner principal): the actual
|
|
13
|
+
* URL + PIN + signed view links. The only credential-bearing channel.
|
|
14
|
+
*
|
|
15
|
+
* Class-based throttling (verification finding V2 + GPT finding #5):
|
|
16
|
+
* - action-required: NEVER throttled within an episode. Cross-episode
|
|
17
|
+
* cooldown applies (consent prompts) but the lifecycle decides that,
|
|
18
|
+
* not the notifier.
|
|
19
|
+
* - state-change: light — at most one per (episode, state) pair, and
|
|
20
|
+
* at most one per 15 minutes within an episode on re-entry of the
|
|
21
|
+
* same state.
|
|
22
|
+
* - noise: heavy — flapping episodes collapse into one "tunnel
|
|
23
|
+
* unstable" message, suppressed for the rest of the episode.
|
|
24
|
+
*
|
|
25
|
+
* Dedup by transition epoch (the lifecycle's monotonic counter): the
|
|
26
|
+
* notifier never emits twice for the same epoch, even if the same
|
|
27
|
+
* event fires through multiple listeners.
|
|
28
|
+
*/
|
|
29
|
+
import type { TransitionEvent } from './TunnelLifecycle.js';
|
|
30
|
+
import type { ProviderName } from './TunnelProvider.js';
|
|
31
|
+
/** Message class — drives throttling policy. */
|
|
32
|
+
export type NotificationClass = 'action-required' | 'state-change' | 'noise';
|
|
33
|
+
/** Channel — drives credential-handling policy. */
|
|
34
|
+
export type NotificationChannel = 'group' | 'owner-dm';
|
|
35
|
+
export interface NotifierMessage {
|
|
36
|
+
channel: NotificationChannel;
|
|
37
|
+
class: NotificationClass;
|
|
38
|
+
text: string;
|
|
39
|
+
/** Episode this message belongs to (for cross-episode dedup). */
|
|
40
|
+
episodeId: string | null;
|
|
41
|
+
/** Transition epoch — never emit twice for the same epoch. */
|
|
42
|
+
epoch: number;
|
|
43
|
+
}
|
|
44
|
+
export interface NotifierSink {
|
|
45
|
+
/** Send a status-text message to the group topic (Dashboard preferred, Lifeline/General fallback). */
|
|
46
|
+
sendGroup(text: string): Promise<void>;
|
|
47
|
+
/** Send a credential-bearing message to the owner's private bot DM. */
|
|
48
|
+
sendOwnerDM(text: string): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
export interface NotifierClock {
|
|
51
|
+
now(): number;
|
|
52
|
+
}
|
|
53
|
+
export interface TunnelNotifierOptions {
|
|
54
|
+
sink: NotifierSink;
|
|
55
|
+
clock?: NotifierClock;
|
|
56
|
+
/** Within-episode same-state re-entry throttle (default 15 min). */
|
|
57
|
+
stateChangeMinIntervalMs?: number;
|
|
58
|
+
/** Flap threshold — N connect/drop cycles within an episode → noise-collapse. */
|
|
59
|
+
flapThreshold?: number;
|
|
60
|
+
}
|
|
61
|
+
export declare class TunnelNotifier {
|
|
62
|
+
private readonly sink;
|
|
63
|
+
private readonly clock;
|
|
64
|
+
private readonly stateChangeMinIntervalMs;
|
|
65
|
+
private readonly flapThreshold;
|
|
66
|
+
private lastEmittedEpoch;
|
|
67
|
+
private currentEpisodeId;
|
|
68
|
+
/** Last-emitted timestamps keyed by `<state>::<channel>` so the group
|
|
69
|
+
* pointer and the owner-DM credential delivery are throttled
|
|
70
|
+
* independently — otherwise the DM gets swallowed after the group
|
|
71
|
+
* pointer fires for the same state-change. */
|
|
72
|
+
private lastEmittedAt;
|
|
73
|
+
/** Track noise-collapse emission per episode. Once emitted, further
|
|
74
|
+
* noise messages in the same episode are suppressed. */
|
|
75
|
+
private noiseEmittedThisEpisode;
|
|
76
|
+
private flapCycles;
|
|
77
|
+
private flapCollapsed;
|
|
78
|
+
constructor(opts: TunnelNotifierOptions);
|
|
79
|
+
/**
|
|
80
|
+
* Drive the notifier from a lifecycle transition. Idempotent on the
|
|
81
|
+
* transition epoch — repeated calls with the same epoch are no-ops.
|
|
82
|
+
*/
|
|
83
|
+
onTransition(e: TransitionEvent): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Compose the user-facing messages for a transition. May return zero,
|
|
86
|
+
* one, or two messages (some transitions emit to BOTH channels, e.g.
|
|
87
|
+
* "back online — link in your DM" + DM with the URL).
|
|
88
|
+
*
|
|
89
|
+
* The DM credential payload is filled in by the manager via a callback
|
|
90
|
+
* (the notifier itself doesn't know URLs/PINs); for now the DM strings
|
|
91
|
+
* are placeholders that the manager substitutes before send. Future:
|
|
92
|
+
* extend onTransition signature to accept the credential payload.
|
|
93
|
+
*/
|
|
94
|
+
private composeMessages;
|
|
95
|
+
/**
|
|
96
|
+
* Throttle decision per spec Part 3:
|
|
97
|
+
* - action-required: NEVER throttled within an episode.
|
|
98
|
+
* - state-change: at most one per (episode, state, channel) combo
|
|
99
|
+
* within `stateChangeMinIntervalMs`. The channel scoping is
|
|
100
|
+
* load-bearing: the group pointer and the owner-DM credential
|
|
101
|
+
* delivery are TWO messages for the same state-change; they must
|
|
102
|
+
* both emit, not throttle each other out.
|
|
103
|
+
* - noise: emits at most once per episode. The flap-collapse
|
|
104
|
+
* message goes out the first time the threshold is crossed; all
|
|
105
|
+
* subsequent noise in the same episode is suppressed.
|
|
106
|
+
*/
|
|
107
|
+
private allow;
|
|
108
|
+
}
|
|
109
|
+
export type { ProviderName };
|
|
110
|
+
//# sourceMappingURL=TunnelNotifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TunnelNotifier.d.ts","sourceRoot":"","sources":["../../src/tunnel/TunnelNotifier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAwB,MAAM,sBAAsB,CAAC;AAClF,OAAO,KAAK,EAAE,YAAY,EAAyB,MAAM,qBAAqB,CAAC;AAE/E,gDAAgD;AAChD,MAAM,MAAM,iBAAiB,GAAG,iBAA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EAAE,qBAAqB;IAOvC;;;OAGG;IACG,YAAY,CAAC,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAyCrD;;;;;;;;;OASG;IACH,OAAO,CAAC,eAAe;IA6HvB;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,KAAK;CAWd;AAmBD,YAAY,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TunnelNotifier — two-channel routing of tunnel lifecycle events to
|
|
3
|
+
* the user.
|
|
4
|
+
*
|
|
5
|
+
* Per spec specs/dev-infrastructure/tunnel-failure-resilience.md Part 3.
|
|
6
|
+
*
|
|
7
|
+
* Strict channel separation (the GPT external review's CRITICAL finding):
|
|
8
|
+
* - GROUP topic (Dashboard / Lifeline fallback / General fallback):
|
|
9
|
+
* status text only. NEVER the URL, NEVER the PIN, NEVER a signed
|
|
10
|
+
* view link. Anyone in the group can read those, which would defeat
|
|
11
|
+
* the owner-only consent gate.
|
|
12
|
+
* - OWNER DM (private bot chat with the owner principal): the actual
|
|
13
|
+
* URL + PIN + signed view links. The only credential-bearing channel.
|
|
14
|
+
*
|
|
15
|
+
* Class-based throttling (verification finding V2 + GPT finding #5):
|
|
16
|
+
* - action-required: NEVER throttled within an episode. Cross-episode
|
|
17
|
+
* cooldown applies (consent prompts) but the lifecycle decides that,
|
|
18
|
+
* not the notifier.
|
|
19
|
+
* - state-change: light — at most one per (episode, state) pair, and
|
|
20
|
+
* at most one per 15 minutes within an episode on re-entry of the
|
|
21
|
+
* same state.
|
|
22
|
+
* - noise: heavy — flapping episodes collapse into one "tunnel
|
|
23
|
+
* unstable" message, suppressed for the rest of the episode.
|
|
24
|
+
*
|
|
25
|
+
* Dedup by transition epoch (the lifecycle's monotonic counter): the
|
|
26
|
+
* notifier never emits twice for the same epoch, even if the same
|
|
27
|
+
* event fires through multiple listeners.
|
|
28
|
+
*/
|
|
29
|
+
export class TunnelNotifier {
|
|
30
|
+
sink;
|
|
31
|
+
clock;
|
|
32
|
+
stateChangeMinIntervalMs;
|
|
33
|
+
flapThreshold;
|
|
34
|
+
// Dedup state. The lifecycle's epoch is monotonic per manager instance,
|
|
35
|
+
// so once we've emitted for epoch N we never re-emit for N.
|
|
36
|
+
lastEmittedEpoch = -1;
|
|
37
|
+
// Per-episode bookkeeping.
|
|
38
|
+
currentEpisodeId = null;
|
|
39
|
+
/** Last-emitted timestamps keyed by `<state>::<channel>` so the group
|
|
40
|
+
* pointer and the owner-DM credential delivery are throttled
|
|
41
|
+
* independently — otherwise the DM gets swallowed after the group
|
|
42
|
+
* pointer fires for the same state-change. */
|
|
43
|
+
lastEmittedAt = new Map();
|
|
44
|
+
/** Track noise-collapse emission per episode. Once emitted, further
|
|
45
|
+
* noise messages in the same episode are suppressed. */
|
|
46
|
+
noiseEmittedThisEpisode = false;
|
|
47
|
+
flapCycles = 0;
|
|
48
|
+
flapCollapsed = false;
|
|
49
|
+
constructor(opts) {
|
|
50
|
+
this.sink = opts.sink;
|
|
51
|
+
this.clock = opts.clock ?? { now: () => Date.now() };
|
|
52
|
+
this.stateChangeMinIntervalMs = opts.stateChangeMinIntervalMs ?? 15 * 60_000;
|
|
53
|
+
this.flapThreshold = opts.flapThreshold ?? 3;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Drive the notifier from a lifecycle transition. Idempotent on the
|
|
57
|
+
* transition epoch — repeated calls with the same epoch are no-ops.
|
|
58
|
+
*/
|
|
59
|
+
async onTransition(e) {
|
|
60
|
+
// Dedup on epoch FIRST: never emit twice for the same epoch even if
|
|
61
|
+
// the listener fires multiple times.
|
|
62
|
+
if (e.epoch <= this.lastEmittedEpoch)
|
|
63
|
+
return;
|
|
64
|
+
this.lastEmittedEpoch = e.epoch;
|
|
65
|
+
// Reset per-episode bookkeeping when the episode id changes.
|
|
66
|
+
const newEpisodeId = e.episode?.episodeId ?? null;
|
|
67
|
+
if (newEpisodeId !== this.currentEpisodeId) {
|
|
68
|
+
this.currentEpisodeId = newEpisodeId;
|
|
69
|
+
this.lastEmittedAt = new Map();
|
|
70
|
+
this.noiseEmittedThisEpisode = false;
|
|
71
|
+
this.flapCycles = 0;
|
|
72
|
+
this.flapCollapsed = false;
|
|
73
|
+
}
|
|
74
|
+
// Build the message for THIS transition (if any).
|
|
75
|
+
const messages = this.composeMessages(e);
|
|
76
|
+
for (const m of messages) {
|
|
77
|
+
const allowed = this.allow(m, e.to);
|
|
78
|
+
if (!allowed)
|
|
79
|
+
continue;
|
|
80
|
+
try {
|
|
81
|
+
if (m.channel === 'group') {
|
|
82
|
+
await this.sink.sendGroup(m.text);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
await this.sink.sendOwnerDM(m.text);
|
|
86
|
+
}
|
|
87
|
+
// Update bookkeeping AFTER successful send (cheap-best-effort).
|
|
88
|
+
const key = throttleKey(e.to, m.channel);
|
|
89
|
+
this.lastEmittedAt.set(key, this.clock.now());
|
|
90
|
+
if (m.class === 'noise') {
|
|
91
|
+
this.noiseEmittedThisEpisode = true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
// Never throw into the tunnel path — preserves existing
|
|
96
|
+
// .catch(() => {}) semantics from server.ts.
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Compose the user-facing messages for a transition. May return zero,
|
|
102
|
+
* one, or two messages (some transitions emit to BOTH channels, e.g.
|
|
103
|
+
* "back online — link in your DM" + DM with the URL).
|
|
104
|
+
*
|
|
105
|
+
* The DM credential payload is filled in by the manager via a callback
|
|
106
|
+
* (the notifier itself doesn't know URLs/PINs); for now the DM strings
|
|
107
|
+
* are placeholders that the manager substitutes before send. Future:
|
|
108
|
+
* extend onTransition signature to accept the credential payload.
|
|
109
|
+
*/
|
|
110
|
+
composeMessages(e) {
|
|
111
|
+
const ep = e.episode?.episodeId ?? null;
|
|
112
|
+
const reason = e.lastFailureReason;
|
|
113
|
+
const messages = [];
|
|
114
|
+
switch (e.to) {
|
|
115
|
+
case 'retrying':
|
|
116
|
+
// First Tier-1 failure — describe the cause, no DM.
|
|
117
|
+
messages.push({
|
|
118
|
+
channel: 'group',
|
|
119
|
+
class: 'state-change',
|
|
120
|
+
text: `Couldn't reach the usual Cloudflare tunnel${reasonSuffix(reason)}; still retrying.`,
|
|
121
|
+
episodeId: ep,
|
|
122
|
+
epoch: e.epoch,
|
|
123
|
+
});
|
|
124
|
+
// Track for flap detection.
|
|
125
|
+
this.flapCycles += 1;
|
|
126
|
+
if (this.flapCycles >= this.flapThreshold && !this.flapCollapsed) {
|
|
127
|
+
this.flapCollapsed = true;
|
|
128
|
+
messages.push({
|
|
129
|
+
channel: 'group',
|
|
130
|
+
class: 'noise',
|
|
131
|
+
text: `Tunnel is unstable right now — still working on it. I'll stop re-pinging this until something changes.`,
|
|
132
|
+
episodeId: ep,
|
|
133
|
+
epoch: e.epoch,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
break;
|
|
137
|
+
case 'active':
|
|
138
|
+
if (e.from === 'self-healing' || e.from === 'relay-active') {
|
|
139
|
+
// Self-healed back to Tier 1.
|
|
140
|
+
messages.push({
|
|
141
|
+
channel: 'group',
|
|
142
|
+
class: 'state-change',
|
|
143
|
+
text: `Your permanent link is back. New link in your DM.`,
|
|
144
|
+
episodeId: ep,
|
|
145
|
+
epoch: e.epoch,
|
|
146
|
+
});
|
|
147
|
+
messages.push({
|
|
148
|
+
channel: 'owner-dm',
|
|
149
|
+
class: 'state-change',
|
|
150
|
+
text: `__OWNER_DM_RESTORED_URL_PLACEHOLDER__`,
|
|
151
|
+
episodeId: ep,
|
|
152
|
+
epoch: e.epoch,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
else if (e.from === 'retrying') {
|
|
156
|
+
// Cloudflare came back during retry.
|
|
157
|
+
messages.push({
|
|
158
|
+
channel: 'group',
|
|
159
|
+
class: 'state-change',
|
|
160
|
+
text: `Back online. Link in your DM.`,
|
|
161
|
+
episodeId: ep,
|
|
162
|
+
epoch: e.epoch,
|
|
163
|
+
});
|
|
164
|
+
messages.push({
|
|
165
|
+
channel: 'owner-dm',
|
|
166
|
+
class: 'state-change',
|
|
167
|
+
text: `__OWNER_DM_RECOVERED_URL_PLACEHOLDER__`,
|
|
168
|
+
episodeId: ep,
|
|
169
|
+
epoch: e.epoch,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
// Other 'active' arrivals (initial startup) are non-events from the user's perspective.
|
|
173
|
+
break;
|
|
174
|
+
case 'awaiting-consent':
|
|
175
|
+
// Consent prompt: owner DM only, brief group pointer.
|
|
176
|
+
messages.push({
|
|
177
|
+
channel: 'group',
|
|
178
|
+
class: 'state-change',
|
|
179
|
+
text: `Cloudflare is down. I've messaged you in DM about a possible backup.`,
|
|
180
|
+
episodeId: ep,
|
|
181
|
+
epoch: e.epoch,
|
|
182
|
+
});
|
|
183
|
+
messages.push({
|
|
184
|
+
channel: 'owner-dm',
|
|
185
|
+
class: 'action-required',
|
|
186
|
+
text: `__OWNER_DM_CONSENT_PROMPT_PLACEHOLDER__`,
|
|
187
|
+
episodeId: ep,
|
|
188
|
+
epoch: e.epoch,
|
|
189
|
+
});
|
|
190
|
+
break;
|
|
191
|
+
case 'relay-active':
|
|
192
|
+
// A Tier-2 relay is up: group pointer + DM with URL + rotated PIN.
|
|
193
|
+
messages.push({
|
|
194
|
+
channel: 'group',
|
|
195
|
+
class: 'state-change',
|
|
196
|
+
text: `Backup tunnel is up. New link in your DM.`,
|
|
197
|
+
episodeId: ep,
|
|
198
|
+
epoch: e.epoch,
|
|
199
|
+
});
|
|
200
|
+
messages.push({
|
|
201
|
+
channel: 'owner-dm',
|
|
202
|
+
class: 'state-change',
|
|
203
|
+
text: `__OWNER_DM_RELAY_URL_PLACEHOLDER__`,
|
|
204
|
+
episodeId: ep,
|
|
205
|
+
epoch: e.epoch,
|
|
206
|
+
});
|
|
207
|
+
break;
|
|
208
|
+
case 'exhausted':
|
|
209
|
+
messages.push({
|
|
210
|
+
channel: 'group',
|
|
211
|
+
class: 'state-change',
|
|
212
|
+
text: `All tunnel options are unavailable right now. I'll keep retrying Cloudflare in the background and switch back the moment it recovers — no restart needed.`,
|
|
213
|
+
episodeId: ep,
|
|
214
|
+
epoch: e.epoch,
|
|
215
|
+
});
|
|
216
|
+
break;
|
|
217
|
+
case 'self-healing':
|
|
218
|
+
// No user-visible message at entry. The "permanent link is back"
|
|
219
|
+
// emits on self-healing → active (above).
|
|
220
|
+
break;
|
|
221
|
+
// No notification on idle / starting transitions.
|
|
222
|
+
case 'idle':
|
|
223
|
+
case 'starting':
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
return messages;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Throttle decision per spec Part 3:
|
|
230
|
+
* - action-required: NEVER throttled within an episode.
|
|
231
|
+
* - state-change: at most one per (episode, state, channel) combo
|
|
232
|
+
* within `stateChangeMinIntervalMs`. The channel scoping is
|
|
233
|
+
* load-bearing: the group pointer and the owner-DM credential
|
|
234
|
+
* delivery are TWO messages for the same state-change; they must
|
|
235
|
+
* both emit, not throttle each other out.
|
|
236
|
+
* - noise: emits at most once per episode. The flap-collapse
|
|
237
|
+
* message goes out the first time the threshold is crossed; all
|
|
238
|
+
* subsequent noise in the same episode is suppressed.
|
|
239
|
+
*/
|
|
240
|
+
allow(m, toState) {
|
|
241
|
+
if (m.class === 'action-required')
|
|
242
|
+
return true;
|
|
243
|
+
if (m.class === 'noise') {
|
|
244
|
+
return !this.noiseEmittedThisEpisode;
|
|
245
|
+
}
|
|
246
|
+
// state-change: keyed per (state, channel).
|
|
247
|
+
const key = throttleKey(toState, m.channel);
|
|
248
|
+
const lastAt = this.lastEmittedAt.get(key);
|
|
249
|
+
if (lastAt === undefined)
|
|
250
|
+
return true;
|
|
251
|
+
return this.clock.now() - lastAt >= this.stateChangeMinIntervalMs;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
function throttleKey(state, channel) {
|
|
255
|
+
return `${state}::${channel}`;
|
|
256
|
+
}
|
|
257
|
+
function reasonSuffix(reason) {
|
|
258
|
+
switch (reason) {
|
|
259
|
+
case 'rate-limited': return ' (Cloudflare is rate-limiting us)';
|
|
260
|
+
case 'binary-missing': return ' (the tunnel software is missing)';
|
|
261
|
+
case 'network': return ' (network is unreachable)';
|
|
262
|
+
case 'timeout': return ' (it timed out connecting)';
|
|
263
|
+
case 'process-exit': return ' (the tunnel process exited)';
|
|
264
|
+
case 'reachability-failed': return ' (the link did not respond)';
|
|
265
|
+
default: return '';
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
//# sourceMappingURL=TunnelNotifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TunnelNotifier.js","sourceRoot":"","sources":["../../src/tunnel/TunnelNotifier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAyCH,MAAM,OAAO,cAAc;IACR,IAAI,CAAe;IACnB,KAAK,CAAgB;IACrB,wBAAwB,CAAS;IACjC,aAAa,CAAS;IAEvC,wEAAwE;IACxE,4DAA4D;IACpD,gBAAgB,GAAG,CAAC,CAAC,CAAC;IAE9B,2BAA2B;IACnB,gBAAgB,GAAkB,IAAI,CAAC;IAC/C;;;kDAG8C;IACtC,aAAa,GAAwB,IAAI,GAAG,EAAE,CAAC;IACvD;4DACwD;IAChD,uBAAuB,GAAG,KAAK,CAAC;IAChC,UAAU,GAAG,CAAC,CAAC;IACf,aAAa,GAAG,KAAK,CAAC;IAE9B,YAAY,IAA2B;QACrC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;QACrD,IAAI,CAAC,wBAAw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AAI,CAAC,CAAC,KAAK,KAAK,iBAAiB;YAAE,OAAO,IAAI,CAAC;QAC/C,IAAI,CAAC,CAAC,KAAK,KAAK,OAAO,EAAE,CAAC;YACxB,OAAO,CAAC,IAAI,CAAC,uBAAuB,CAAC;QACvC,CAAC;QACD,4CAA4C;QAC5C,MAAM,GAAG,GAAG,WAAW,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;QAC5C,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC3C,IAAI,MAAM,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC;QACtC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,MAAM,IAAI,IAAI,CAAC,wBAAwB,CAAC;IACpE,CAAC;CACF;AAED,SAAS,WAAW,CAAC,KAA2B,EAAE,OAA4B;IAC5E,OAAO,GAAG,KAAK,KAAK,OAAO,EAAE,CAAC;AAChC,CAAC;AAED,SAAS,YAAY,CAAC,MAAoC;IACxD,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,cAAc,CAAC,CAAC,OAAO,mCAAmC,CAAC;QAChE,KAAK,gBAAgB,CAAC,CAAC,OAAO,mCAAmC,CAAC;QAClE,KAAK,SAAS,CAAC,CAAC,OAAO,2BAA2B,CAAC;QACnD,KAAK,SAAS,CAAC,CAAC,OAAO,4BAA4B,CAAC;QACpD,KAAK,cAAc,CAAC,CAAC,OAAO,8BAA8B,CAAC;QAC3D,KAAK,qBAAqB,CAAC,CAAC,OAAO,6BAA6B,CAAC;QACjE,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC;IACrB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TunnelProvider — abstraction over the underlying tunnel implementation.
|
|
3
|
+
*
|
|
4
|
+
* Per spec specs/dev-infrastructure/tunnel-failure-resilience.md Part 1:
|
|
5
|
+
* the TunnelManager is the single owner of the lifecycle state machine,
|
|
6
|
+
* and each backend (cloudflared quick, cloudflared named, localtunnel,
|
|
7
|
+
* bore) implements this interface. The manager treats providers as
|
|
8
|
+
* interchangeable units; trust-tier ordering (Tier 1 vs Tier 2) and the
|
|
9
|
+
* consent gate live in the manager, NOT in the providers themselves.
|
|
10
|
+
*
|
|
11
|
+
* Two tiers:
|
|
12
|
+
* - Tier 1: automatic, secure. Cloudflare providers. Tried silently.
|
|
13
|
+
* - Tier 2: consent-gated relays. localtunnel, bore. Never activated
|
|
14
|
+
* without explicit owner approval recorded against the episode.
|
|
15
|
+
*
|
|
16
|
+
* Every provider's `start()` MUST resolve only after the URL has passed
|
|
17
|
+
* a post-start reachability probe (verified by the manager via the
|
|
18
|
+
* /health endpoint through the public URL). A URL that emits from
|
|
19
|
+
* cloudflared but doesn't actually serve (e.g. localtunnel interstitial,
|
|
20
|
+
* bore.pub down) is NOT counted as `active` — that prevents a false
|
|
21
|
+
* "back online" broadcast for a dead link.
|
|
22
|
+
*
|
|
23
|
+
* The provider does NOT decide retry, fallback, or notification — those
|
|
24
|
+
* are the manager's responsibility. Provider responsibilities are
|
|
25
|
+
* narrowly: spawn the backend, surface the URL, surface a stop handle.
|
|
26
|
+
*/
|
|
27
|
+
/** Trust tier — Tier 1 is automatic/secure, Tier 2 is consent-gated. */
|
|
28
|
+
export type ProviderTier = 1 | 2;
|
|
29
|
+
/** Stable identifier the manager uses to route episode/consent records. */
|
|
30
|
+
export type ProviderName = 'cloudflare-named' | 'cloudflare-quick' | 'localtunnel' | 'bore';
|
|
31
|
+
export interface TunnelProviderHandle {
|
|
32
|
+
/** The public URL the provider exposes. */
|
|
33
|
+
readonly url: string;
|
|
34
|
+
/**
|
|
35
|
+
* Stop the provider. MUST escalate SIGINT → SIGKILL with PID
|
|
36
|
+
* verification (mirror the existing `forceStop()` pattern) so the
|
|
37
|
+
* manager can guarantee no relay child lingers across a self-heal
|
|
38
|
+
* switch-back. Tunnel teardown is security-load-bearing for Tier 2.
|
|
39
|
+
*/
|
|
40
|
+
stop(): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
export interface TunnelProvider {
|
|
43
|
+
/** Stable name routed through episode/consent records and audit logs. */
|
|
44
|
+
readonly name: ProviderName;
|
|
45
|
+
/** Trust tier — manager uses this to decide whether the consent gate applies. */
|
|
46
|
+
readonly tier: ProviderTier;
|
|
47
|
+
/**
|
|
48
|
+
* True if the provider can be started in this environment without further
|
|
49
|
+
* user setup. Used by the manager to filter the provider pool BEFORE
|
|
50
|
+
* declaring `exhausted`. Reasons for `false`: required binary missing,
|
|
51
|
+
* required token/credentials not configured, OS unsupported, etc.
|
|
52
|
+
*
|
|
53
|
+
* The manager calls this once per episode (cheap signal), not per attempt.
|
|
54
|
+
*/
|
|
55
|
+
isAvailable(): Promise<boolean>;
|
|
56
|
+
/**
|
|
57
|
+
* Start the provider against the given local port. Resolves with the
|
|
58
|
+
* URL + a stop handle when the URL is emitted by the backend. The
|
|
59
|
+
* manager performs the reachability probe AFTER resolution and before
|
|
60
|
+
* transitioning to `active`; providers MUST NOT do their own probing
|
|
61
|
+
* here (the manager owns post-start verification per spec Part 1).
|
|
62
|
+
*
|
|
63
|
+
* Implementations should reject with a structured Error whose `message`
|
|
64
|
+
* carries the classification the manager will surface to the notifier
|
|
65
|
+
* (e.g. "rate-limited (HTTP 429 / Cloudflare 1015)", "binary missing",
|
|
66
|
+
* "network unreachable", "process exited code 1"). The manager parses
|
|
67
|
+
* these strings into ProviderFailureReason classifications.
|
|
68
|
+
*/
|
|
69
|
+
start(localPort: number): Promise<TunnelProviderHandle>;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Classification the manager applies to a provider failure for the
|
|
73
|
+
* notifier and for deciding whether to advance to the next provider.
|
|
74
|
+
*
|
|
75
|
+
* The classification is owned by the manager (not the provider) per the
|
|
76
|
+
* signal-vs-authority discipline: providers raise errors with reason
|
|
77
|
+
* strings; the manager classifies into this enum and routes accordingly.
|
|
78
|
+
*/
|
|
79
|
+
export type ProviderFailureReason = 'rate-limited' | 'binary-missing' | 'network' | 'process-exit' | 'timeout' | 'reachability-failed' | 'unknown';
|
|
80
|
+
//# sourceMappingURL=TunnelProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TunnelProvider.d.ts","sourceRoot":"","sources":["../../src/tunnel/TunnelProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,wEAAwE;AACxE,MAAM,MAAM,YAAY,GAAG,CAAC,GAAG,CAAC,CAAC;AAEjC,2EAA2E;AAC3E,MAAM,MAAM,YAAY,GACpB,kBAAkB,GAClB,kBAAkB,GAClB,aAAa,GACb,MAAM,CAAC;AAEX,MAAM,WAAW,oBAAoB;IACnC,2CAA2C;IAC3C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB;;;;;OAKG;IACH,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB;AAED,MAAM,WAAW,cAAc;IAC7B,yEAAyE;IACzE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAE5B,iFAAiF;IACjF,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAE5B;;;;;;;OAOG;IACH,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAEhC;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;CACzD;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,qBAAqB,GAC7B,cAAc,GACd,gBAAgB,GAChB,SAAS,GACT,cAAc,GACd,SAAS,GACT,qBAAqB,GACrB,SAAS,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TunnelProvider — abstraction over the underlying tunnel implementation.
|
|
3
|
+
*
|
|
4
|
+
* Per spec specs/dev-infrastructure/tunnel-failure-resilience.md Part 1:
|
|
5
|
+
* the TunnelManager is the single owner of the lifecycle state machine,
|
|
6
|
+
* and each backend (cloudflared quick, cloudflared named, localtunnel,
|
|
7
|
+
* bore) implements this interface. The manager treats providers as
|
|
8
|
+
* interchangeable units; trust-tier ordering (Tier 1 vs Tier 2) and the
|
|
9
|
+
* consent gate live in the manager, NOT in the providers themselves.
|
|
10
|
+
*
|
|
11
|
+
* Two tiers:
|
|
12
|
+
* - Tier 1: automatic, secure. Cloudflare providers. Tried silently.
|
|
13
|
+
* - Tier 2: consent-gated relays. localtunnel, bore. Never activated
|
|
14
|
+
* without explicit owner approval recorded against the episode.
|
|
15
|
+
*
|
|
16
|
+
* Every provider's `start()` MUST resolve only after the URL has passed
|
|
17
|
+
* a post-start reachability probe (verified by the manager via the
|
|
18
|
+
* /health endpoint through the public URL). A URL that emits from
|
|
19
|
+
* cloudflared but doesn't actually serve (e.g. localtunnel interstitial,
|
|
20
|
+
* bore.pub down) is NOT counted as `active` — that prevents a false
|
|
21
|
+
* "back online" broadcast for a dead link.
|
|
22
|
+
*
|
|
23
|
+
* The provider does NOT decide retry, fallback, or notification — those
|
|
24
|
+
* are the manager's responsibility. Provider responsibilities are
|
|
25
|
+
* narrowly: spawn the backend, surface the URL, surface a stop handle.
|
|
26
|
+
*/
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=TunnelProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TunnelProvider.js","sourceRoot":"","sources":["../../src/tunnel/TunnelProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "./builtin-manifest.schema.json",
|
|
3
3
|
"schemaVersion": 1,
|
|
4
|
-
"generatedAt": "2026-05-
|
|
5
|
-
"instarVersion": "1.2.
|
|
4
|
+
"generatedAt": "2026-05-22T22:17:56.523Z",
|
|
5
|
+
"instarVersion": "1.2.35",
|
|
6
6
|
"entryCount": 191,
|
|
7
7
|
"entries": {
|
|
8
8
|
"hook:session-start": {
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Upgrade Guide — vNEXT
|
|
2
|
+
|
|
3
|
+
<!-- bump: patch -->
|
|
4
|
+
<!-- patch = behavior fix, no new capability, no breaking change -->
|
|
5
|
+
|
|
6
|
+
## What Changed
|
|
7
|
+
|
|
8
|
+
**feat(tone-gate): add B15_CONTEXT_DEATH_STOP — block outbound "fresh-
|
|
9
|
+
session / hand-off" framing on in-flight work.**
|
|
10
|
+
|
|
11
|
+
instar's `MessagingToneGate` already runs on every outbound user
|
|
12
|
+
message and blocks fourteen classes of leakage (B1–B14 — CLI commands,
|
|
13
|
+
file paths, jargon dumps, health-alert internals, style mismatch,
|
|
14
|
+
etc.). This adds a fifteenth rule, **B15_CONTEXT_DEATH_STOP**, that
|
|
15
|
+
catches a specific failure mode of the agent: proposing to pause, stop,
|
|
16
|
+
or hand off the current in-flight work for a context-window /
|
|
17
|
+
fresh-session / end-of-session reason rather than a legitimate stop
|
|
18
|
+
reason.
|
|
19
|
+
|
|
20
|
+
The pattern is documented in the CLAUDE.md "Context-Death Self-Stop"
|
|
21
|
+
anti-pattern section, and reinforced by multiple memory entries
|
|
22
|
+
(`feedback_scope_hook_is_grounding_not_termination`,
|
|
23
|
+
`feedback_no_deferrals`, `feedback_finish_means_merge`, etc.). Despite
|
|
24
|
+
the documentation, the slip kept recurring. Per instar's foundational
|
|
25
|
+
"Structure beats willpower" principle, this needs a structural guard
|
|
26
|
+
that catches the language at send-time.
|
|
27
|
+
|
|
28
|
+
B15 is an LLM-gate rule (the existing tone-gate authority). It lists
|
|
29
|
+
literal pattern markers ("fresh session," "next session," "tail of
|
|
30
|
+
this session," "hand off cleanly," "pick this up later," etc.) AND
|
|
31
|
+
legitimate-stop carve-outs that pass unblocked (real design question
|
|
32
|
+
only the operator can answer, real blocker, real error, completion
|
|
33
|
+
report on user-requested scope). The LLM combines the markers with
|
|
34
|
+
conversational context and the carve-outs to make the block/pass call.
|
|
35
|
+
|
|
36
|
+
When B15 fires, the standard tone-gate UX applies: the candidate is
|
|
37
|
+
rejected with rule id B15, an issue summary, and a suggestion. The
|
|
38
|
+
agent has to either delete the handoff framing and continue working
|
|
39
|
+
or supply an explicit legitimate-stop reason.
|
|
40
|
+
|
|
41
|
+
## Evidence
|
|
42
|
+
|
|
43
|
+
The change is one entry added to `VALID_RULES`, one new section in
|
|
44
|
+
the gate's prompt, and one line updated in the response-format note
|
|
45
|
+
listing valid rule ids. Nine unit tests in
|
|
46
|
+
`tests/unit/messaging-tone-gate-b15.test.ts` verify:
|
|
47
|
+
|
|
48
|
+
1. The prompt always carries the B15 rule definition for every review.
|
|
49
|
+
2. The prompt carries the literal pattern markers (fresh session, next
|
|
50
|
+
session, tail of this session, hand off cleanly, pick this up later).
|
|
51
|
+
3. The prompt documents the legitimate-stop carve-outs (completion
|
|
52
|
+
report, genuine error / blocker).
|
|
53
|
+
4. The response-format rule list includes B15.
|
|
54
|
+
5. An LLM response citing B15 is accepted as a valid block (not
|
|
55
|
+
fail-opened as `invalidRule`).
|
|
56
|
+
6. A completion-report message passes through unchanged when the LLM
|
|
57
|
+
returns pass.
|
|
58
|
+
7. A genuine-blocker message passes through unchanged.
|
|
59
|
+
8. A topic-split / continuation message passes through unchanged.
|
|
60
|
+
9. The drift-detection still rejects unknown rule ids (no widening
|
|
61
|
+
of the gate to arbitrary ids).
|
|
62
|
+
|
|
63
|
+
All 27 existing `MessagingToneGate.test.ts` tests still pass; all 8
|
|
64
|
+
existing `messaging-tone-gate-health-alerts.test.ts` tests still pass.
|
|
65
|
+
The TypeScript build is clean; lint is clean.
|
|
66
|
+
|
|
67
|
+
## What to Tell Your User
|
|
68
|
+
|
|
69
|
+
Your agent now has one more safety net on the messages it sends you.
|
|
70
|
+
The new check looks for moments where the agent is about to write some
|
|
71
|
+
version of "let me pick this up in a fresh session" or "I'll hand this
|
|
72
|
+
off cleanly" while the work you asked for isn't actually done yet — and
|
|
73
|
+
quietly blocks that message before it reaches you. The agent has to
|
|
74
|
+
either delete the bail-out framing and keep working, or cite a real
|
|
75
|
+
reason for stopping. You should notice the agent doing less of that
|
|
76
|
+
pattern. Nothing changes about messages where the agent has a real
|
|
77
|
+
question, a real blocker, a real error, or actually finished the work.
|
|
78
|
+
|
|
79
|
+
## Summary of New Capabilities
|
|
80
|
+
|
|
81
|
+
| Capability | How to Use |
|
|
82
|
+
|-----------|-----------|
|
|
83
|
+
| B15 tone-gate rule catches outbound context-death stop framing | Automatic — runs on every outbound user message via MessagingToneGate |
|
|
84
|
+
| B15 has explicit legitimate-stop carve-outs | Automatic — real question / real blocker / real error / completion report pass unblocked |
|