instar 1.2.35 → 1.2.37
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/commands/server.d.ts.map +1 -1
- package/dist/commands/server.js +20 -67
- package/dist/commands/server.js.map +1 -1
- package/dist/core/AutoUpdater.d.ts.map +1 -1
- package/dist/core/AutoUpdater.js +25 -1
- package/dist/core/AutoUpdater.js.map +1 -1
- package/dist/core/PostUpdateMigrator.d.ts +1 -0
- package/dist/core/PostUpdateMigrator.d.ts.map +1 -1
- package/dist/core/PostUpdateMigrator.js +91 -0
- package/dist/core/PostUpdateMigrator.js.map +1 -1
- package/dist/core/version-skew.d.ts +77 -0
- package/dist/core/version-skew.d.ts.map +1 -0
- package/dist/core/version-skew.js +144 -0
- package/dist/core/version-skew.js.map +1 -0
- package/dist/lifeline/RestartOrchestrator.d.ts +1 -1
- package/dist/lifeline/RestartOrchestrator.d.ts.map +1 -1
- package/dist/lifeline/TelegramLifeline.d.ts +14 -0
- package/dist/lifeline/TelegramLifeline.d.ts.map +1 -1
- package/dist/lifeline/TelegramLifeline.js +60 -0
- package/dist/lifeline/TelegramLifeline.js.map +1 -1
- package/dist/lifeline/rateLimitState.d.ts +1 -1
- package/dist/lifeline/rateLimitState.d.ts.map +1 -1
- package/dist/lifeline/rateLimitState.js +16 -11
- package/dist/lifeline/rateLimitState.js.map +1 -1
- package/dist/server/routes.d.ts.map +1 -1
- package/dist/server/routes.js +20 -0
- package/dist/server/routes.js.map +1 -1
- package/dist/tunnel/TunnelManager.d.ts +99 -62
- package/dist/tunnel/TunnelManager.d.ts.map +1 -1
- package/dist/tunnel/TunnelManager.js +340 -395
- package/dist/tunnel/TunnelManager.js.map +1 -1
- package/package.json +1 -1
- package/scripts/instar-dev-precommit.js +128 -0
- package/src/data/builtin-manifest.json +64 -64
- package/src/templates/scripts/instar-watchdog.sh +80 -3
- package/upgrades/1.2.36.md +111 -0
- package/upgrades/1.2.37.md +53 -0
- package/upgrades/side-effects/auto-updater-lifeline-coordination.md +199 -0
- package/upgrades/side-effects/tunnel-manager-rewrite.md +129 -0
|
@@ -1,46 +1,68 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* TunnelManager — single owner of the tunnel lifecycle.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* ephemeral) and named tunnels (persistent, custom domain).
|
|
4
|
+
* Per spec specs/dev-infrastructure/tunnel-failure-resilience.md.
|
|
6
5
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Rewritten on top of the foundation modules:
|
|
7
|
+
* - TunnelProvider — backend abstraction; concrete providers under
|
|
8
|
+
* src/tunnel/Cloudflare*Provider.ts.
|
|
9
|
+
* - TunnelLifecycle — single-writer CAS-guarded state machine.
|
|
10
|
+
* - TunnelNotifier — two-channel routing (group / owner-DM) of
|
|
11
|
+
* transition events.
|
|
9
12
|
*
|
|
10
|
-
* The
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
13
|
+
* The manager is the SOLE owner of the detect → attempt → fall-back →
|
|
14
|
+
* notify → self-heal lifecycle. The previous server.ts startup-retry
|
|
15
|
+
* ladder + background-retry ladder + Lifeline failure message are
|
|
16
|
+
* retired in favor of routing all retry through here (one backoff
|
|
17
|
+
* engine, not two).
|
|
18
|
+
*
|
|
19
|
+
* Scope of this rewrite (PR 2 of the chain):
|
|
20
|
+
* - Tier-1 provider pool (Cloudflare named → quick) with internal
|
|
21
|
+
* backoff between retries within an episode.
|
|
22
|
+
* - Post-start reachability probe (HTTP /health through the public
|
|
23
|
+
* URL) before declaring `active` — prevents broadcasting a "back
|
|
24
|
+
* online" link that doesn't actually serve traffic.
|
|
25
|
+
* - Backward-compatible public API: start(), stop(), forceStop(),
|
|
26
|
+
* enableAutoReconnect(), disableAutoReconnect(), getExternalUrl(),
|
|
27
|
+
* url/isRunning/state. Plus the existing events.
|
|
28
|
+
* - Notifier sink optional; when telegram adapter is plumbed,
|
|
29
|
+
* transition events route to the group topic.
|
|
30
|
+
*
|
|
31
|
+
* Out of scope for THIS PR (future PRs in the chain):
|
|
32
|
+
* - Tier-2 consent flow + relay providers (PR 4).
|
|
33
|
+
* - Owner-DM channel + inline-button consent UX (PR 3).
|
|
34
|
+
* - authToken/PIN rotation + boot recovery (PR 5).
|
|
35
|
+
* - Self-heal probe with N-consecutive-success stability gate (PR 6).
|
|
36
|
+
* - The /tunnel route (PR 7).
|
|
37
|
+
*
|
|
38
|
+
* The lifecycle state machine already supports these states; the
|
|
39
|
+
* manager simply doesn't transition into them yet in PR 2.
|
|
16
40
|
*/
|
|
17
41
|
import { EventEmitter } from 'node:events';
|
|
42
|
+
import { type PersistedTunnelState } from './TunnelLifecycle.js';
|
|
43
|
+
import type { TunnelProvider, ProviderFailureReason } from './TunnelProvider.js';
|
|
44
|
+
import type { NotifierSink } from './TunnelNotifier.js';
|
|
18
45
|
export interface TunnelConfig {
|
|
19
|
-
/** Whether tunnel is enabled */
|
|
46
|
+
/** Whether tunnel is enabled. */
|
|
20
47
|
enabled: boolean;
|
|
21
|
-
/** Tunnel type: 'quick' (ephemeral, no account) or 'named' (persistent, requires token) */
|
|
48
|
+
/** Tunnel type: 'quick' (ephemeral, no account) or 'named' (persistent, requires token). */
|
|
22
49
|
type: 'quick' | 'named';
|
|
23
|
-
/** Cloudflare tunnel token (
|
|
50
|
+
/** Cloudflare tunnel token (named, token-auth). */
|
|
24
51
|
token?: string;
|
|
25
|
-
/** Config file path
|
|
52
|
+
/** Config file path (named, config-file-auth). */
|
|
26
53
|
configFile?: string;
|
|
27
|
-
/** Public hostname for named tunnels
|
|
54
|
+
/** Public hostname for named tunnels. */
|
|
28
55
|
hostname?: string;
|
|
29
|
-
/** Local port to tunnel to */
|
|
56
|
+
/** Local port to tunnel to. */
|
|
30
57
|
port: number;
|
|
31
|
-
/** State directory for persisting tunnel
|
|
58
|
+
/** State directory for persisting tunnel.json. */
|
|
32
59
|
stateDir: string;
|
|
33
60
|
}
|
|
34
61
|
export interface TunnelState {
|
|
35
|
-
/** Current tunnel URL (null if not connected) */
|
|
36
62
|
url: string | null;
|
|
37
|
-
/** Tunnel type */
|
|
38
63
|
type: 'quick' | 'named';
|
|
39
|
-
/** When the tunnel was started */
|
|
40
64
|
startedAt: string | null;
|
|
41
|
-
/** Connection info from cloudflared */
|
|
42
65
|
connectionId?: string;
|
|
43
|
-
/** Connection location */
|
|
44
66
|
connectionLocation?: string;
|
|
45
67
|
}
|
|
46
68
|
export interface TunnelEvents {
|
|
@@ -54,60 +76,75 @@ export interface TunnelEvents {
|
|
|
54
76
|
error: (error: Error) => void;
|
|
55
77
|
stopped: () => void;
|
|
56
78
|
}
|
|
79
|
+
/** Optional injections for testability. */
|
|
80
|
+
export interface TunnelManagerInjections {
|
|
81
|
+
providers?: TunnelProvider[];
|
|
82
|
+
notifierSink?: NotifierSink;
|
|
83
|
+
fetch?: typeof fetch;
|
|
84
|
+
}
|
|
57
85
|
export declare class TunnelManager extends EventEmitter {
|
|
58
|
-
private config;
|
|
59
|
-
private
|
|
60
|
-
private
|
|
61
|
-
private
|
|
62
|
-
private
|
|
86
|
+
private readonly config;
|
|
87
|
+
private readonly stateFile;
|
|
88
|
+
private readonly lifecycle;
|
|
89
|
+
private readonly providers;
|
|
90
|
+
private readonly notifier;
|
|
91
|
+
private readonly fetcher;
|
|
92
|
+
private currentHandle;
|
|
93
|
+
private currentProviderName;
|
|
94
|
+
private _legacyState;
|
|
63
95
|
private _autoReconnect;
|
|
64
|
-
private
|
|
65
|
-
private _reconnectAttempt;
|
|
96
|
+
private _stopped;
|
|
66
97
|
private _startPromise;
|
|
67
|
-
private
|
|
68
|
-
private
|
|
69
|
-
private
|
|
70
|
-
constructor(config: TunnelConfig);
|
|
71
|
-
/** Current tunnel URL, or null if not connected */
|
|
98
|
+
private _backoffAttempt;
|
|
99
|
+
private _backoffTimer;
|
|
100
|
+
private _postExhaustedTimer;
|
|
101
|
+
constructor(config: TunnelConfig, injections?: TunnelManagerInjections);
|
|
72
102
|
get url(): string | null;
|
|
73
|
-
/** Whether the tunnel is currently running */
|
|
74
103
|
get isRunning(): boolean;
|
|
75
|
-
/** Current tunnel state */
|
|
76
104
|
get state(): TunnelState;
|
|
105
|
+
/** Additive new accessor — lifecycle snapshot. */
|
|
106
|
+
get lifecycleState(): PersistedTunnelState;
|
|
77
107
|
/**
|
|
78
|
-
* Start the tunnel.
|
|
79
|
-
*
|
|
108
|
+
* Start the tunnel. Drives the full Tier-1 ladder internally — the
|
|
109
|
+
* caller does NOT wrap with its own retry loop (the old server.ts
|
|
110
|
+
* startup ladder is RETIRED).
|
|
111
|
+
*
|
|
112
|
+
* Resolves with the URL of the first provider that reaches `active`.
|
|
113
|
+
* Rejects when all Tier-1 providers fail and backoff is exhausted.
|
|
80
114
|
*/
|
|
81
115
|
start(): Promise<string>;
|
|
82
|
-
/**
|
|
83
|
-
* Stop the tunnel gracefully. Intentional stops disable auto-reconnect.
|
|
84
|
-
*/
|
|
85
116
|
stop(): Promise<void>;
|
|
86
|
-
/**
|
|
87
|
-
|
|
88
|
-
* SIGINT within `timeoutMs`, escalate to SIGKILL. Essential for sleep/wake
|
|
89
|
-
* recovery where cloudflared may be a zombie process.
|
|
90
|
-
*/
|
|
91
|
-
forceStop(timeoutMs?: number): Promise<void>;
|
|
92
|
-
/**
|
|
93
|
-
* Enable automatic reconnection when the tunnel disconnects unexpectedly.
|
|
94
|
-
* Uses exponential backoff: 5s, 10s, 20s, ... up to 5 minutes, max 10 attempts.
|
|
95
|
-
*/
|
|
117
|
+
/** Force-stop with escalation. Providers internally do SIGINT → SIGKILL. */
|
|
118
|
+
forceStop(_timeoutMs?: number): Promise<void>;
|
|
96
119
|
enableAutoReconnect(): void;
|
|
97
120
|
disableAutoReconnect(): void;
|
|
121
|
+
getExternalUrl(localPath: string): string | null;
|
|
122
|
+
private buildDefaultPool;
|
|
123
|
+
private doStart;
|
|
124
|
+
private driveTier1;
|
|
125
|
+
private exhaustedOrBackoff;
|
|
98
126
|
/**
|
|
99
|
-
*
|
|
127
|
+
* Background retry — runs the bounded exponential ladder off the
|
|
128
|
+
* start() promise so initial start() resolves/rejects fast. After
|
|
129
|
+
* the ladder exhausts, hands off to the indefinite post-exhausted
|
|
130
|
+
* placeholder (the PR 2 self-heal; PR 6 replaces with the spec's
|
|
131
|
+
* N-consecutive-success probe).
|
|
100
132
|
*/
|
|
101
|
-
private
|
|
133
|
+
private scheduleBackgroundRetry;
|
|
134
|
+
private clearBackoffTimer;
|
|
135
|
+
private clearPostExhaustedTimer;
|
|
102
136
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
137
|
+
* Minimum-viable post-exhausted retry (PR 2 self-heal placeholder).
|
|
138
|
+
* Schedules a single low-frequency probe; on completion (success or
|
|
139
|
+
* failure) it re-arms itself, so the agent keeps trying to recover
|
|
140
|
+
* even after the bounded startup-reconnect ladder gives up. PR 6
|
|
141
|
+
* replaces this with the spec's N-consecutive-success stability gate.
|
|
105
142
|
*/
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
private
|
|
109
|
-
private
|
|
110
|
-
private
|
|
111
|
-
private saveState;
|
|
143
|
+
private schedulePostExhaustedRetry;
|
|
144
|
+
/** HTTP probe through the public URL — confirms the link actually serves. */
|
|
145
|
+
private probeReachability;
|
|
146
|
+
private persist;
|
|
147
|
+
private restorePersisted;
|
|
112
148
|
}
|
|
149
|
+
export type { ProviderFailureReason };
|
|
113
150
|
//# sourceMappingURL=TunnelManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TunnelManager.d.ts","sourceRoot":"","sources":["../../src/tunnel/TunnelManager.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"TunnelManager.d.ts","sourceRoot":"","sources":["../../src/tunnel/TunnelManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH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