@agent-deck/backend 1.11.8 → 2.0.0
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/.tsbuildinfo +1 -1
- package/dist/audit/store.d.ts +43 -0
- package/dist/audit/store.d.ts.map +1 -0
- package/dist/audit/store.js +128 -0
- package/dist/audit/store.js.map +1 -0
- package/dist/auth/client-grants.d.ts +109 -0
- package/dist/auth/client-grants.d.ts.map +1 -0
- package/dist/auth/client-grants.js +260 -0
- package/dist/auth/client-grants.js.map +1 -0
- package/dist/auth/hosted-mode.d.ts +16 -0
- package/dist/auth/hosted-mode.d.ts.map +1 -0
- package/dist/auth/hosted-mode.js +136 -0
- package/dist/auth/hosted-mode.js.map +1 -0
- package/dist/auth/owner-auth.d.ts +24 -0
- package/dist/auth/owner-auth.d.ts.map +1 -0
- package/dist/auth/owner-auth.js +68 -0
- package/dist/auth/owner-auth.js.map +1 -0
- package/dist/auth/request-limiter.d.ts +17 -0
- package/dist/auth/request-limiter.d.ts.map +1 -0
- package/dist/auth/request-limiter.js +47 -0
- package/dist/auth/request-limiter.js.map +1 -0
- package/dist/cli-runtime.d.ts +2 -2
- package/dist/container-entrypoint.d.ts +2 -0
- package/dist/container-entrypoint.d.ts.map +1 -0
- package/dist/container-entrypoint.js +52 -0
- package/dist/container-entrypoint.js.map +1 -0
- package/dist/export-import/export-bundle.d.ts +2 -2
- package/dist/export-import/export-bundle.d.ts.map +1 -1
- package/dist/export-import/export-bundle.js +4 -2
- package/dist/export-import/export-bundle.js.map +1 -1
- package/dist/export-import/import-bundle.d.ts.map +1 -1
- package/dist/export-import/import-bundle.js +15 -3
- package/dist/export-import/import-bundle.js.map +1 -1
- package/dist/index.js +18 -15
- package/dist/index.js.map +1 -1
- package/dist/lib/destination-guard.d.ts +32 -0
- package/dist/lib/destination-guard.d.ts.map +1 -0
- package/dist/lib/destination-guard.js +238 -0
- package/dist/lib/destination-guard.js.map +1 -0
- package/dist/lib/fatal.d.ts +4 -4
- package/dist/lib/fatal.d.ts.map +1 -1
- package/dist/lib/fatal.js +36 -16
- package/dist/lib/fatal.js.map +1 -1
- package/dist/lib/graceful-shutdown.d.ts +26 -0
- package/dist/lib/graceful-shutdown.d.ts.map +1 -0
- package/dist/lib/graceful-shutdown.js +92 -0
- package/dist/lib/graceful-shutdown.js.map +1 -0
- package/dist/lib/mcp-oauth-discovery.d.ts.map +1 -1
- package/dist/lib/mcp-oauth-discovery.js +9 -4
- package/dist/lib/mcp-oauth-discovery.js.map +1 -1
- package/dist/lib/structured-console.d.ts +3 -0
- package/dist/lib/structured-console.d.ts.map +1 -0
- package/dist/lib/structured-console.js +29 -0
- package/dist/lib/structured-console.js.map +1 -0
- package/dist/mcp-index.js +2 -14
- package/dist/mcp-index.js.map +1 -1
- package/dist/mcp-server.d.ts +145 -2
- package/dist/mcp-server.d.ts.map +1 -1
- package/dist/mcp-server.js +524 -16
- package/dist/mcp-server.js.map +1 -1
- package/dist/mcp-session-binding.d.ts +54 -0
- package/dist/mcp-session-binding.d.ts.map +1 -1
- package/dist/mcp-session-binding.js +81 -0
- package/dist/mcp-session-binding.js.map +1 -1
- package/dist/mcp-tools/elicitation.d.ts +13 -4
- package/dist/mcp-tools/elicitation.d.ts.map +1 -1
- package/dist/mcp-tools/elicitation.js +34 -14
- package/dist/mcp-tools/elicitation.js.map +1 -1
- package/dist/mcp-tools/register.d.ts.map +1 -1
- package/dist/mcp-tools/register.js +105 -5
- package/dist/mcp-tools/register.js.map +1 -1
- package/dist/models/database.d.ts +12 -8
- package/dist/models/database.d.ts.map +1 -1
- package/dist/models/database.js +67 -51
- package/dist/models/database.js.map +1 -1
- package/dist/routes/agent-grants.d.ts +9 -0
- package/dist/routes/agent-grants.d.ts.map +1 -0
- package/dist/routes/agent-grants.js +97 -0
- package/dist/routes/agent-grants.js.map +1 -0
- package/dist/routes/audit.d.ts +5 -0
- package/dist/routes/audit.d.ts.map +1 -0
- package/dist/routes/audit.js +33 -0
- package/dist/routes/audit.js.map +1 -0
- package/dist/routes/decks.d.ts.map +1 -1
- package/dist/routes/decks.js +27 -0
- package/dist/routes/decks.js.map +1 -1
- package/dist/routes/mcp.d.ts.map +1 -1
- package/dist/routes/mcp.js +5 -4
- package/dist/routes/mcp.js.map +1 -1
- package/dist/routes/playbooks.d.ts.map +1 -1
- package/dist/routes/playbooks.js +9 -10
- package/dist/routes/playbooks.js.map +1 -1
- package/dist/routes/scope.d.ts.map +1 -1
- package/dist/routes/scope.js +4 -2
- package/dist/routes/scope.js.map +1 -1
- package/dist/routes/services.d.ts.map +1 -1
- package/dist/routes/services.js +6 -0
- package/dist/routes/services.js.map +1 -1
- package/dist/routes/trusted-session.d.ts +2 -0
- package/dist/routes/trusted-session.d.ts.map +1 -1
- package/dist/routes/trusted-session.js +194 -1
- package/dist/routes/trusted-session.js.map +1 -1
- package/dist/routes/usage.d.ts +3 -1
- package/dist/routes/usage.d.ts.map +1 -1
- package/dist/routes/usage.js +20 -1
- package/dist/routes/usage.js.map +1 -1
- package/dist/scope/live-display-registry.d.ts +56 -1
- package/dist/scope/live-display-registry.d.ts.map +1 -1
- package/dist/scope/live-display-registry.js +115 -2
- package/dist/scope/live-display-registry.js.map +1 -1
- package/dist/server/cors-origins.d.ts +6 -0
- package/dist/server/cors-origins.d.ts.map +1 -0
- package/dist/server/cors-origins.js +122 -0
- package/dist/server/cors-origins.js.map +1 -0
- package/dist/server/degraded.d.ts +15 -0
- package/dist/server/degraded.d.ts.map +1 -0
- package/dist/server/degraded.js +55 -0
- package/dist/server/degraded.js.map +1 -0
- package/dist/server/graceful-shutdown.fixture.d.ts +2 -0
- package/dist/server/graceful-shutdown.fixture.d.ts.map +1 -0
- package/dist/server/graceful-shutdown.fixture.js +52 -0
- package/dist/server/graceful-shutdown.fixture.js.map +1 -0
- package/dist/server/health.d.ts +21 -0
- package/dist/server/health.d.ts.map +1 -0
- package/dist/server/health.js +65 -0
- package/dist/server/health.js.map +1 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +60 -26
- package/dist/server/index.js.map +1 -1
- package/dist/services/icon-resolver.d.ts.map +1 -1
- package/dist/services/icon-resolver.js +2 -1
- package/dist/services/icon-resolver.js.map +1 -1
- package/dist/services/mcp-client-manager.d.ts.map +1 -1
- package/dist/services/mcp-client-manager.js +3 -0
- package/dist/services/mcp-client-manager.js.map +1 -1
- package/dist/services/mcp-discovery-service.d.ts.map +1 -1
- package/dist/services/mcp-discovery-service.js +2 -1
- package/dist/services/mcp-discovery-service.js.map +1 -1
- package/dist/services/oauth-manager.d.ts.map +1 -1
- package/dist/services/oauth-manager.js +12 -7
- package/dist/services/oauth-manager.js.map +1 -1
- package/dist/services/service-manager.d.ts.map +1 -1
- package/dist/services/service-manager.js +15 -4
- package/dist/services/service-manager.js.map +1 -1
- package/dist/store/atomic-write.d.ts.map +1 -1
- package/dist/store/atomic-write.js +44 -3
- package/dist/store/atomic-write.js.map +1 -1
- package/dist/store/deck-codec.d.ts +9 -0
- package/dist/store/deck-codec.d.ts.map +1 -1
- package/dist/store/deck-codec.js +64 -1
- package/dist/store/deck-codec.js.map +1 -1
- package/dist/store/deck-file.d.ts +3 -3
- package/dist/store/deck-file.d.ts.map +1 -1
- package/dist/store/deck-file.js +4 -3
- package/dist/store/deck-file.js.map +1 -1
- package/dist/store/index.d.ts +1 -0
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +1 -0
- package/dist/store/index.js.map +1 -1
- package/dist/store/migrate-v1-to-v2.d.ts +22 -0
- package/dist/store/migrate-v1-to-v2.d.ts.map +1 -0
- package/dist/store/migrate-v1-to-v2.js +167 -0
- package/dist/store/migrate-v1-to-v2.js.map +1 -0
- package/dist/store/migrate.js +2 -2
- package/dist/store/migrate.js.map +1 -1
- package/dist/store/reindex.d.ts.map +1 -1
- package/dist/store/reindex.js +16 -6
- package/dist/store/reindex.js.map +1 -1
- package/dist/store/startup.d.ts.map +1 -1
- package/dist/store/startup.js +13 -0
- package/dist/store/startup.js.map +1 -1
- package/dist/store/writer.d.ts.map +1 -1
- package/dist/store/writer.js +7 -3
- package/dist/store/writer.js.map +1 -1
- package/dist/trusted-session/route-policy-registry.d.ts.map +1 -1
- package/dist/trusted-session/route-policy-registry.js +12 -1
- package/dist/trusted-session/route-policy-registry.js.map +1 -1
- package/dist/trusted-session/store.d.ts +37 -2
- package/dist/trusted-session/store.d.ts.map +1 -1
- package/dist/trusted-session/store.js +75 -20
- package/dist/trusted-session/store.js.map +1 -1
- package/dist/vault/encrypted-file-secret-store.d.ts +61 -0
- package/dist/vault/encrypted-file-secret-store.d.ts.map +1 -0
- package/dist/vault/encrypted-file-secret-store.js +211 -0
- package/dist/vault/encrypted-file-secret-store.js.map +1 -0
- package/dist/vault/index.d.ts +1 -0
- package/dist/vault/index.d.ts.map +1 -1
- package/dist/vault/index.js +1 -0
- package/dist/vault/index.js.map +1 -1
- package/dist/vault/secret-store.d.ts +8 -0
- package/dist/vault/secret-store.d.ts.map +1 -1
- package/dist/vault/secret-store.js +31 -2
- package/dist/vault/secret-store.js.map +1 -1
- package/package.json +2 -2
- package/static-ui/assets/index-ClYpYc1K.js +251 -0
- package/static-ui/assets/index-DMqzTrRe.css +1 -0
- package/static-ui/index.html +2 -2
- package/static-ui/assets/index-CQf3Vouc.css +0 -1
- package/static-ui/assets/index-DCImqPRz.js +0 -235
|
@@ -13,6 +13,29 @@ export type LiveDisplayEntry = {
|
|
|
13
13
|
lastActivityAt: string;
|
|
14
14
|
};
|
|
15
15
|
export type LiveDisplayUpsert = Omit<LiveDisplayEntry, 'badge' | 'lastActivityAt'>;
|
|
16
|
+
/**
|
|
17
|
+
* NOT-309: staleness bound for live-display entries. A session that dies
|
|
18
|
+
* without a clean MCP disconnect (killed terminal, SIGKILL, crashed host)
|
|
19
|
+
* never fires `transport.onclose`, so its entry would otherwise linger
|
|
20
|
+
* forever and keep the workspace status line on `multiple session decks`.
|
|
21
|
+
* Entries older than this bound are ignored by `resolveWorkspaceSessions`
|
|
22
|
+
* and removed by the sweep. `0` disables expiry.
|
|
23
|
+
*/
|
|
24
|
+
export declare const DEFAULT_LIVE_DISPLAY_STALE_MS: number;
|
|
25
|
+
export declare const LIVE_DISPLAY_STALE_ENV_VAR = "LIVE_DISPLAY_STALE_MS";
|
|
26
|
+
/** Cadence of the registry-owned periodic sweep (wired up in server/index). */
|
|
27
|
+
export declare const LIVE_DISPLAY_SWEEP_INTERVAL_MS = 60000;
|
|
28
|
+
/**
|
|
29
|
+
* NOT-309: parse the staleness bound. Missing/blank/invalid/negative values
|
|
30
|
+
* fall back to the default; `0` disables expiry.
|
|
31
|
+
*/
|
|
32
|
+
export declare function resolveLiveDisplayStaleMs(raw: string | undefined): number;
|
|
33
|
+
export type LiveDisplayRegistryOptions = {
|
|
34
|
+
/** Clock for staleness checks (tests inject a fake clock). Defaults to Date.now. */
|
|
35
|
+
nowMs?: () => number;
|
|
36
|
+
/** Staleness bound in ms. Defaults to LIVE_DISPLAY_STALE_MS env parsing. */
|
|
37
|
+
staleMs?: number;
|
|
38
|
+
};
|
|
16
39
|
/**
|
|
17
40
|
* NOT-296: explicit ambiguity-aware workspace match. `single` keeps the one
|
|
18
41
|
* live session's exact display; `multiple` carries every match in
|
|
@@ -32,10 +55,42 @@ export type WorkspaceSessionMatch = {
|
|
|
32
55
|
/** In-memory registry of live MCP session binds (status line reads reality only). */
|
|
33
56
|
export declare class LiveDisplayRegistry {
|
|
34
57
|
private bySessionId;
|
|
58
|
+
private readonly nowMs;
|
|
59
|
+
private readonly staleMs;
|
|
60
|
+
private sweepTimer;
|
|
61
|
+
constructor(options?: LiveDisplayRegistryOptions);
|
|
62
|
+
/** Effective staleness bound in ms (`0` disables expiry). */
|
|
63
|
+
getStaleMs(): number;
|
|
64
|
+
/**
|
|
65
|
+
* NOT-309: staleness probe. An unparseable `lastActivityAt` counts as stale
|
|
66
|
+
* (no writer ever emits one, so there is no liveness to prove).
|
|
67
|
+
*/
|
|
68
|
+
isStale(entry: Pick<LiveDisplayEntry, 'lastActivityAt'>, now?: number): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* NOT-309: drop every entry older than the bound. Returns the removed count.
|
|
71
|
+
* Runs periodically via `startStaleSweep` and lazily on every read, so a
|
|
72
|
+
* killed session stops counting within the bound even if the timer never
|
|
73
|
+
* fires in a test or short-lived process.
|
|
74
|
+
*/
|
|
75
|
+
sweepStale(now?: number): number;
|
|
76
|
+
/**
|
|
77
|
+
* NOT-309: registry-owned periodic sweep. Returns a stop function; the
|
|
78
|
+
* timer is unref'd so it never holds the backend process open.
|
|
79
|
+
*/
|
|
80
|
+
startStaleSweep(intervalMs?: number): () => void;
|
|
81
|
+
stopStaleSweep(): void;
|
|
35
82
|
upsert(input: LiveDisplayUpsert): LiveDisplayEntry;
|
|
36
83
|
get(mcpSessionId: string): LiveDisplayEntry | undefined;
|
|
37
84
|
remove(mcpSessionId: string): void;
|
|
38
|
-
|
|
85
|
+
/**
|
|
86
|
+
* NOT-309 repair round 2: report whether the session was known. A live
|
|
87
|
+
* session swept during a host sleep (or a status-line read on wake) is
|
|
88
|
+
* still connected, so a `false` here tells the MCP side to re-register
|
|
89
|
+
* instead of staying silently off the status line until reconnect/rebind.
|
|
90
|
+
* Returns `true` when the entry exists (bumping `lastActivityAt` when `at`
|
|
91
|
+
* is newer), `false` for an unknown — including already-swept — id.
|
|
92
|
+
*/
|
|
93
|
+
touch(mcpSessionId: string, at: string): boolean;
|
|
39
94
|
list(): LiveDisplayEntry[];
|
|
40
95
|
/**
|
|
41
96
|
* NOT-296: ambiguity-aware workspace lookup. Returns every live session
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"live-display-registry.d.ts","sourceRoot":"","sources":["../../src/scope/live-display-registry.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EACd,iBAAiB,EAElB,MAAM,oBAAoB,CAAC;AAG5B,MAAM,MAAM,gBAAgB,GAAG;IAC7B,YAAY,EAAE,MAAM,CA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B,EAAE,gBAAgB,CAAC,EAAE,GAAG,GAAE,MAAqB,GAAG,OAAO;IAW7F;;;;;OAKG;IACH,UAAU,CAAC,GAAG,GAAE,MAAqB,GAAG,MAAM;IAc9C;;;OAGG;IACH,eAAe,CAAC,UAAU,GAAE,MAAuC,GAAG,MAAM,IAAI;IAUhF,cAAc,IAAI,IAAI;IAOtB,MAAM,CAAC,KAAK,EAAE,iBAAiB,GAAG,gBAAgB;IAkBlD,GAAG,CAAC,YAAY,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS;IAKvD,MAAM,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;IAIlC;;;;;;;OAOG;IACH,KAAK,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO;IAWhD,IAAI,IAAI,gBAAgB,EAAE;IAS1B;;;;;;OAMG;IACH,wBAAwB,CAAC,aAAa,EAAE,MAAM,GAAG,qBAAqB;CA8BvE"}
|
|
@@ -3,13 +3,108 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.LiveDisplayRegistry = void 0;
|
|
6
|
+
exports.LiveDisplayRegistry = exports.LIVE_DISPLAY_SWEEP_INTERVAL_MS = exports.LIVE_DISPLAY_STALE_ENV_VAR = exports.DEFAULT_LIVE_DISPLAY_STALE_MS = void 0;
|
|
7
|
+
exports.resolveLiveDisplayStaleMs = resolveLiveDisplayStaleMs;
|
|
7
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
9
|
const shared_1 = require("@agent-deck/shared");
|
|
9
10
|
const badge_1 = require("./badge");
|
|
11
|
+
/**
|
|
12
|
+
* NOT-309: staleness bound for live-display entries. A session that dies
|
|
13
|
+
* without a clean MCP disconnect (killed terminal, SIGKILL, crashed host)
|
|
14
|
+
* never fires `transport.onclose`, so its entry would otherwise linger
|
|
15
|
+
* forever and keep the workspace status line on `multiple session decks`.
|
|
16
|
+
* Entries older than this bound are ignored by `resolveWorkspaceSessions`
|
|
17
|
+
* and removed by the sweep. `0` disables expiry.
|
|
18
|
+
*/
|
|
19
|
+
exports.DEFAULT_LIVE_DISPLAY_STALE_MS = 30 * 60 * 1_000;
|
|
20
|
+
exports.LIVE_DISPLAY_STALE_ENV_VAR = 'LIVE_DISPLAY_STALE_MS';
|
|
21
|
+
/** Cadence of the registry-owned periodic sweep (wired up in server/index). */
|
|
22
|
+
exports.LIVE_DISPLAY_SWEEP_INTERVAL_MS = 60_000;
|
|
23
|
+
/**
|
|
24
|
+
* NOT-309: parse the staleness bound. Missing/blank/invalid/negative values
|
|
25
|
+
* fall back to the default; `0` disables expiry.
|
|
26
|
+
*/
|
|
27
|
+
function resolveLiveDisplayStaleMs(raw) {
|
|
28
|
+
if (raw === undefined) {
|
|
29
|
+
return exports.DEFAULT_LIVE_DISPLAY_STALE_MS;
|
|
30
|
+
}
|
|
31
|
+
const trimmed = raw.trim();
|
|
32
|
+
if (trimmed === '') {
|
|
33
|
+
return exports.DEFAULT_LIVE_DISPLAY_STALE_MS;
|
|
34
|
+
}
|
|
35
|
+
const parsed = Number(trimmed);
|
|
36
|
+
if (!Number.isFinite(parsed) || parsed < 0) {
|
|
37
|
+
return exports.DEFAULT_LIVE_DISPLAY_STALE_MS;
|
|
38
|
+
}
|
|
39
|
+
return Math.floor(parsed);
|
|
40
|
+
}
|
|
10
41
|
/** In-memory registry of live MCP session binds (status line reads reality only). */
|
|
11
42
|
class LiveDisplayRegistry {
|
|
12
43
|
bySessionId = new Map();
|
|
44
|
+
nowMs;
|
|
45
|
+
staleMs;
|
|
46
|
+
sweepTimer = null;
|
|
47
|
+
constructor(options = {}) {
|
|
48
|
+
this.nowMs = options.nowMs ?? Date.now;
|
|
49
|
+
this.staleMs =
|
|
50
|
+
options.staleMs ?? resolveLiveDisplayStaleMs(process.env[exports.LIVE_DISPLAY_STALE_ENV_VAR]);
|
|
51
|
+
}
|
|
52
|
+
/** Effective staleness bound in ms (`0` disables expiry). */
|
|
53
|
+
getStaleMs() {
|
|
54
|
+
return this.staleMs;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* NOT-309: staleness probe. An unparseable `lastActivityAt` counts as stale
|
|
58
|
+
* (no writer ever emits one, so there is no liveness to prove).
|
|
59
|
+
*/
|
|
60
|
+
isStale(entry, now = this.nowMs()) {
|
|
61
|
+
if (this.staleMs === 0) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
const activity = Date.parse(entry.lastActivityAt);
|
|
65
|
+
if (!Number.isFinite(activity)) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
return now - activity > this.staleMs;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* NOT-309: drop every entry older than the bound. Returns the removed count.
|
|
72
|
+
* Runs periodically via `startStaleSweep` and lazily on every read, so a
|
|
73
|
+
* killed session stops counting within the bound even if the timer never
|
|
74
|
+
* fires in a test or short-lived process.
|
|
75
|
+
*/
|
|
76
|
+
sweepStale(now = this.nowMs()) {
|
|
77
|
+
if (this.staleMs === 0) {
|
|
78
|
+
return 0;
|
|
79
|
+
}
|
|
80
|
+
let removed = 0;
|
|
81
|
+
for (const [sessionId, entry] of this.bySessionId) {
|
|
82
|
+
if (this.isStale(entry, now)) {
|
|
83
|
+
this.bySessionId.delete(sessionId);
|
|
84
|
+
removed += 1;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return removed;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* NOT-309: registry-owned periodic sweep. Returns a stop function; the
|
|
91
|
+
* timer is unref'd so it never holds the backend process open.
|
|
92
|
+
*/
|
|
93
|
+
startStaleSweep(intervalMs = exports.LIVE_DISPLAY_SWEEP_INTERVAL_MS) {
|
|
94
|
+
this.stopStaleSweep();
|
|
95
|
+
const timer = setInterval(() => {
|
|
96
|
+
this.sweepStale();
|
|
97
|
+
}, intervalMs);
|
|
98
|
+
timer.unref?.();
|
|
99
|
+
this.sweepTimer = timer;
|
|
100
|
+
return () => this.stopStaleSweep();
|
|
101
|
+
}
|
|
102
|
+
stopStaleSweep() {
|
|
103
|
+
if (this.sweepTimer) {
|
|
104
|
+
clearInterval(this.sweepTimer);
|
|
105
|
+
this.sweepTimer = null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
13
108
|
upsert(input) {
|
|
14
109
|
const existing = this.bySessionId.get(input.mcpSessionId);
|
|
15
110
|
const badge = existing?.badge ??
|
|
@@ -27,18 +122,34 @@ class LiveDisplayRegistry {
|
|
|
27
122
|
return entry;
|
|
28
123
|
}
|
|
29
124
|
get(mcpSessionId) {
|
|
125
|
+
this.sweepStale();
|
|
30
126
|
return this.bySessionId.get(mcpSessionId);
|
|
31
127
|
}
|
|
32
128
|
remove(mcpSessionId) {
|
|
33
129
|
this.bySessionId.delete(mcpSessionId);
|
|
34
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* NOT-309 repair round 2: report whether the session was known. A live
|
|
133
|
+
* session swept during a host sleep (or a status-line read on wake) is
|
|
134
|
+
* still connected, so a `false` here tells the MCP side to re-register
|
|
135
|
+
* instead of staying silently off the status line until reconnect/rebind.
|
|
136
|
+
* Returns `true` when the entry exists (bumping `lastActivityAt` when `at`
|
|
137
|
+
* is newer), `false` for an unknown — including already-swept — id.
|
|
138
|
+
*/
|
|
35
139
|
touch(mcpSessionId, at) {
|
|
36
140
|
const entry = this.bySessionId.get(mcpSessionId);
|
|
37
|
-
if (entry
|
|
141
|
+
if (!entry) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
if (at > entry.lastActivityAt) {
|
|
38
145
|
entry.lastActivityAt = at;
|
|
39
146
|
}
|
|
147
|
+
return true;
|
|
40
148
|
}
|
|
41
149
|
list() {
|
|
150
|
+
// NOT-309: GET /api/scope/bindings reads through here, so expired entries
|
|
151
|
+
// are omitted from that route (never marked `stale: true`).
|
|
152
|
+
this.sweepStale();
|
|
42
153
|
return [...this.bySessionId.values()].sort((a, b) => a.lastActivityAt < b.lastActivityAt ? 1 : a.lastActivityAt > b.lastActivityAt ? -1 : 0);
|
|
43
154
|
}
|
|
44
155
|
/**
|
|
@@ -49,6 +160,8 @@ class LiveDisplayRegistry {
|
|
|
49
160
|
* was updated last.
|
|
50
161
|
*/
|
|
51
162
|
resolveWorkspaceSessions(workspaceRoot) {
|
|
163
|
+
// NOT-309: killed sessions stop counting within the bound.
|
|
164
|
+
this.sweepStale();
|
|
52
165
|
let current = (0, shared_1.normalizeWorkspaceRoot)(workspaceRoot);
|
|
53
166
|
while (true) {
|
|
54
167
|
const matches = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"live-display-registry.js","sourceRoot":"","sources":["../../src/scope/live-display-registry.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"live-display-registry.js","sourceRoot":"","sources":["../../src/scope/live-display-registry.ts"],"names":[],"mappings":";;;;;;AAyCA,8DAaC;AAtDD,0DAA6B;AAC7B,+CAI4B;AAC5B,mCAAsC;AAkBtC;;;;;;;GAOG;AACU,QAAA,6BAA6B,GAAG,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC;AAChD,QAAA,0BAA0B,GAAG,uBAAuB,CAAC;AAClE,+EAA+E;AAClE,QAAA,8BAA8B,GAAG,MAAM,CAAC;AAErD;;;GAGG;AACH,SAAgB,yBAAyB,CAAC,GAAuB;IAC/D,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,OAAO,qCAA6B,CAAC;IACvC,CAAC;IACD,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;IAC3B,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC;QACnB,OAAO,qCAA6B,CAAC;IACvC,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAC/B,IAAI,CAAC,MAAM,CAAC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AM,MAAM,GAAG,mBAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACrC,IAAI,MAAM,KAAK,OAAO,EAAE,CAAC;gBACvB,MAAM;YACR,CAAC;YACD,OAAO,GAAG,MAAM,CAAC;QACnB,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACvC,CAAC;CACF;AArKD,kDAqKC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { FastifyInstance } from 'fastify';
|
|
2
|
+
export declare const DEFAULT_CORS_PORT_FALLBACK = 8000;
|
|
3
|
+
export declare const DEFAULT_ALLOWED_ORIGINS: string[];
|
|
4
|
+
export declare function resolveAllowedOrigins(env: NodeJS.ProcessEnv): string[];
|
|
5
|
+
export declare function registerCors(fastify: FastifyInstance, env?: NodeJS.ProcessEnv): Promise<void>;
|
|
6
|
+
//# sourceMappingURL=cors-origins.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cors-origins.d.ts","sourceRoot":"","sources":["../../src/server/cors-origins.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAG/C,eAAO,MAAM,0BAA0B,OAAO,CAAC;AAE/C,eAAO,MAAM,uBAAuB,UAKnC,CAAC;AA8CF,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,MAAM,EAAE,CA+CtE;AAED,wBAAsB,YAAY,CAChC,OAAO,EAAE,eAAe,EACxB,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,OAAO,CAAC,IAAI,CAAC,CAef"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DEFAULT_ALLOWED_ORIGINS = exports.DEFAULT_CORS_PORT_FALLBACK = void 0;
|
|
7
|
+
exports.resolveAllowedOrigins = resolveAllowedOrigins;
|
|
8
|
+
exports.registerCors = registerCors;
|
|
9
|
+
const cors_1 = __importDefault(require("@fastify/cors"));
|
|
10
|
+
exports.DEFAULT_CORS_PORT_FALLBACK = 8000;
|
|
11
|
+
exports.DEFAULT_ALLOWED_ORIGINS = [
|
|
12
|
+
'http://127.0.0.1:1111',
|
|
13
|
+
'http://localhost:1111',
|
|
14
|
+
'http://127.0.0.1:3000',
|
|
15
|
+
'http://localhost:3000',
|
|
16
|
+
];
|
|
17
|
+
function resolvePort(env) {
|
|
18
|
+
const raw = env.PORT?.trim();
|
|
19
|
+
if (raw !== undefined && raw !== '') {
|
|
20
|
+
// Mirror the listener in packages/backend/src/index.ts, which parses
|
|
21
|
+
// with parseInt(process.env.PORT), so CORS derives from the same port
|
|
22
|
+
// the backend actually binds (e.g. '2111abc' listens on 2111).
|
|
23
|
+
const parsed = parseInt(raw, 10);
|
|
24
|
+
if (Number.isInteger(parsed) && parsed >= 1 && parsed <= 65535) {
|
|
25
|
+
return parsed;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return exports.DEFAULT_CORS_PORT_FALLBACK;
|
|
29
|
+
}
|
|
30
|
+
// Validate an AGENT_DECK_DASHBOARD_ORIGIN entry and return its normalized
|
|
31
|
+
// origin, or undefined when it must be ignored. Only bare http/https
|
|
32
|
+
// origins (no path, query, fragment, or wildcard) are kept.
|
|
33
|
+
function normalizeExtraOrigin(entry) {
|
|
34
|
+
if (entry === '' || entry.includes('*')) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
let url;
|
|
38
|
+
try {
|
|
39
|
+
url = new URL(entry);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
// No path, query, fragment, or wildcard: entry must be a bare origin.
|
|
48
|
+
const afterScheme = entry.slice(entry.indexOf('://') + 3);
|
|
49
|
+
if (afterScheme === '' || /[/?#]/.test(afterScheme)) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
if (url.pathname !== '/' || url.search !== '' || url.hash !== '') {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
// Store the normalized origin: browsers send url.origin, so a typed entry
|
|
56
|
+
// like 'HTTP://A.example' or 'http://a.example:80' would otherwise never
|
|
57
|
+
// match the incoming Origin header.
|
|
58
|
+
return url.origin;
|
|
59
|
+
}
|
|
60
|
+
function resolveAllowedOrigins(env) {
|
|
61
|
+
if (env.AGENT_DECK_HOSTED_MODE === '1') {
|
|
62
|
+
const hostedOrigins = new Set();
|
|
63
|
+
for (const raw of [env.AGENT_DECK_PUBLIC_URL, env.AGENT_DECK_DASHBOARD_URL]) {
|
|
64
|
+
const value = raw?.trim();
|
|
65
|
+
if (!value)
|
|
66
|
+
continue;
|
|
67
|
+
try {
|
|
68
|
+
const url = new URL(value);
|
|
69
|
+
if (url.protocol === 'http:' || url.protocol === 'https:') {
|
|
70
|
+
hostedOrigins.add(url.origin);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// Hosted-mode configuration validation reports invalid public URLs.
|
|
75
|
+
// CORS still fails closed if called independently.
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return [...hostedOrigins];
|
|
79
|
+
}
|
|
80
|
+
const port = resolvePort(env);
|
|
81
|
+
const seen = new Set();
|
|
82
|
+
const result = [];
|
|
83
|
+
const push = (origin) => {
|
|
84
|
+
if (!seen.has(origin)) {
|
|
85
|
+
seen.add(origin);
|
|
86
|
+
result.push(origin);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
push(`http://127.0.0.1:${port}`);
|
|
90
|
+
push(`http://localhost:${port}`);
|
|
91
|
+
for (const origin of exports.DEFAULT_ALLOWED_ORIGINS) {
|
|
92
|
+
push(origin);
|
|
93
|
+
}
|
|
94
|
+
const rawExtra = env.AGENT_DECK_DASHBOARD_ORIGIN;
|
|
95
|
+
if (rawExtra !== undefined && rawExtra !== '') {
|
|
96
|
+
for (const part of rawExtra.split(',')) {
|
|
97
|
+
const normalized = normalizeExtraOrigin(part.trim());
|
|
98
|
+
if (normalized === undefined || seen.has(normalized)) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
push(normalized);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
async function registerCors(fastify, env = process.env) {
|
|
107
|
+
const allowedOrigins = resolveAllowedOrigins(env);
|
|
108
|
+
await fastify.register(cors_1.default, {
|
|
109
|
+
origin: (origin, cb) => {
|
|
110
|
+
if (!origin) {
|
|
111
|
+
// Non-browser clients (curl, CLI) — allow.
|
|
112
|
+
return cb(null, true);
|
|
113
|
+
}
|
|
114
|
+
if (allowedOrigins.includes(origin)) {
|
|
115
|
+
return cb(null, true);
|
|
116
|
+
}
|
|
117
|
+
cb(new Error('Origin not allowed by CORS'), false);
|
|
118
|
+
},
|
|
119
|
+
credentials: true,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=cors-origins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cors-origins.js","sourceRoot":"","sources":["../../src/server/cors-origins.ts"],"names":[],"mappings":";;;;;;AAwDA,sDA+CC;AAED,oCAkBC;AA1HD,yDAAiC;AAEpB,QAAA,0BAA0B,GAAG,IAAI,CAAC;AAElC,QAAA,uBAAuB,GAAG;IACrC,uBAAuB;IACvB,uBAAuB;IACvB,uBAAuB;IACvB,uBAAuB;CACxB,CAAC;AAEF,SAAS,WAAW,CAAC,GAAsB;IACzC,MAAM,GAAG,GAAG,GAAG,CAAC,IAAI,EAAE,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C,CAAC;QACrD,CAAC;QACD,WAAW,EAAE,IAAI;KAClB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare function isStorageStartupError(error: unknown): boolean;
|
|
2
|
+
/** Hosted deployments stay live for probes; local CLI launches must fail fast. */
|
|
3
|
+
export declare function shouldServeStorageFailure(error: unknown, env?: NodeJS.ProcessEnv): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* If persistent state cannot initialize, retain only the two probe endpoints.
|
|
6
|
+
* This keeps liveness truthful while readiness reports the operator-fixable
|
|
7
|
+
* storage reason; no product API is exposed with half-initialized state.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createStorageFailureServer(startupError: unknown, options?: {
|
|
10
|
+
env?: NodeJS.ProcessEnv;
|
|
11
|
+
dataPath?: string;
|
|
12
|
+
}): import("fastify").FastifyInstance<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault> & PromiseLike<import("fastify").FastifyInstance<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>> & {
|
|
13
|
+
__linterBrands: "SafePromiseLike";
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=degraded.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"degraded.d.ts","sourceRoot":"","sources":["../../src/server/degraded.ts"],"names":[],"mappings":"AAiBA,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAK7D;AAED,kFAAkF;AAClF,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,OAAO,EACd,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,OAAO,CAET;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CACxC,YAAY,EAAE,OAAO,EACrB,OAAO,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAO;;EAgB7D"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isStorageStartupError = isStorageStartupError;
|
|
7
|
+
exports.shouldServeStorageFailure = shouldServeStorageFailure;
|
|
8
|
+
exports.createStorageFailureServer = createStorageFailureServer;
|
|
9
|
+
const fastify_1 = __importDefault(require("fastify"));
|
|
10
|
+
const paths_1 = require("../lib/paths");
|
|
11
|
+
const health_1 = require("./health");
|
|
12
|
+
const STORAGE_ERROR_CODES = new Set([
|
|
13
|
+
'EACCES',
|
|
14
|
+
'EPERM',
|
|
15
|
+
'EROFS',
|
|
16
|
+
'ENOTDIR',
|
|
17
|
+
'SQLITE_CANTOPEN',
|
|
18
|
+
'SQLITE_CORRUPT',
|
|
19
|
+
'SQLITE_IOERR',
|
|
20
|
+
'SQLITE_NOTADB',
|
|
21
|
+
'SQLITE_READONLY',
|
|
22
|
+
]);
|
|
23
|
+
function isStorageStartupError(error) {
|
|
24
|
+
const code = error?.code;
|
|
25
|
+
if (code && (STORAGE_ERROR_CODES.has(code) || code.startsWith('SQLITE_')))
|
|
26
|
+
return true;
|
|
27
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
28
|
+
return /sqlite|database (?:is|could not be) (?:opened|open)|readonly database/i.test(message);
|
|
29
|
+
}
|
|
30
|
+
/** Hosted deployments stay live for probes; local CLI launches must fail fast. */
|
|
31
|
+
function shouldServeStorageFailure(error, env = process.env) {
|
|
32
|
+
return env.AGENT_DECK_HOSTED_MODE === '1' && isStorageStartupError(error);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* If persistent state cannot initialize, retain only the two probe endpoints.
|
|
36
|
+
* This keeps liveness truthful while readiness reports the operator-fixable
|
|
37
|
+
* storage reason; no product API is exposed with half-initialized state.
|
|
38
|
+
*/
|
|
39
|
+
function createStorageFailureServer(startupError, options = {}) {
|
|
40
|
+
const fastify = (0, fastify_1.default)({
|
|
41
|
+
logger: { level: 'info' },
|
|
42
|
+
// Fastify's default ('idle') also drops a connection whose handler has not
|
|
43
|
+
// written a byte yet; graceful shutdown must let that request finish.
|
|
44
|
+
// Node's server.close() already closes truly idle keep-alive sockets.
|
|
45
|
+
forceCloseConnections: false,
|
|
46
|
+
});
|
|
47
|
+
fastify.log.error({ err: startupError }, 'persistent state unavailable; serving probes only');
|
|
48
|
+
(0, health_1.registerHealthRoutes)(fastify, {
|
|
49
|
+
env: options.env,
|
|
50
|
+
dataPath: options.dataPath ?? (0, paths_1.resolveAgentDeckHome)(),
|
|
51
|
+
sqliteProbe: () => { throw startupError; },
|
|
52
|
+
});
|
|
53
|
+
return fastify;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=degraded.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"degraded.js","sourceRoot":"","sources":["../../src/server/degraded.ts"],"names":[],"mappings":";;;;;AAiBA,sDAKC;AAGD,8DAKC;AAOD,gEAkBC;AAvDD,sDAA8B;AAE9B,wCAAoD;AACpD,qCAAgD;AAEhD,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC;IAClC,QAAQ;IACR,OAAO;IACP,OAAO;IACP,SAAS;IACT,iBAAiB;IACjB,gBAAgB;IAChB,cAAc;IACd,eAAe;IACf,iBAAiB;CAClB,CAAC,CAAC;AAEH,SAAgB,qBAAqB,CAAC,KAAc;IAClD,MAAM,IAAI,GAAI,KAA2C,EAAE,IAAI,CAAC;IAChE,IAAI,IAAI,IAAI,CAAC,mBAAmB,CAAC,GAAG,CA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|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fastify_1 = __importDefault(require("fastify"));
|
|
7
|
+
const graceful_shutdown_1 = require("../lib/graceful-shutdown");
|
|
8
|
+
async function run() {
|
|
9
|
+
// Bare Fastify instance on purpose: the full createServer() boots the
|
|
10
|
+
// entire backend (SQLite, seeding, icon backfill with outbound fetches,
|
|
11
|
+
// every route plugin and hook), which made this timing-sensitive test
|
|
12
|
+
// flaky in CI. The mechanism under test is installGracefulShutdown plus
|
|
13
|
+
// the production close call — createTrackedClose, the same function
|
|
14
|
+
// src/index.ts passes — draining a real in-flight HTTP connection. This
|
|
15
|
+
// fixture keeps all of that and drops only the unrelated app stack.
|
|
16
|
+
const server = (0, fastify_1.default)({ logger: false, forceCloseConnections: false });
|
|
17
|
+
// No local drain counter here: the close below is the production
|
|
18
|
+
// createTrackedClose from src/index.ts, so the SIGTERM test proves what
|
|
19
|
+
// production does. The outer shutdown deadline in
|
|
20
|
+
// installGracefulShutdown still bounds the wait.
|
|
21
|
+
server.get('/slow', async () => {
|
|
22
|
+
process.send?.({ type: 'request-started' });
|
|
23
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
24
|
+
return { completed: true };
|
|
25
|
+
});
|
|
26
|
+
// Bind a real TCP listener so SIGTERM exercises the real drain path:
|
|
27
|
+
// installGracefulShutdown calls server.close(), which must wait for the
|
|
28
|
+
// live socket to finish.
|
|
29
|
+
//
|
|
30
|
+
// The HTTP client lives in the parent test process (not here): the
|
|
31
|
+
// fixture used to request itself, so process.exit(0) after close()
|
|
32
|
+
// could kill the same-process client before it reported completion —
|
|
33
|
+
// a race CI lost. An out-of-process client is also the production
|
|
34
|
+
// shape: external clients are unaffected by our exit.
|
|
35
|
+
// Hooks must be registered before listen(); Fastify rejects addHook after.
|
|
36
|
+
const close = (0, graceful_shutdown_1.createTrackedClose)(server);
|
|
37
|
+
await server.listen({ port: 0, host: '127.0.0.1' });
|
|
38
|
+
const bound = server.server.address();
|
|
39
|
+
const port = typeof bound === 'object' && bound ? bound.port : 0;
|
|
40
|
+
if (!port)
|
|
41
|
+
throw new Error('shutdown fixture listener did not report a port');
|
|
42
|
+
// Production close, the same createTrackedClose src/index.ts uses.
|
|
43
|
+
(0, graceful_shutdown_1.installGracefulShutdown)({ label: 'backend', close });
|
|
44
|
+
process.send?.({ type: 'ready', port });
|
|
45
|
+
}
|
|
46
|
+
void run().catch((error) => {
|
|
47
|
+
// Surface startup failures (for example the listener bind) to the parent
|
|
48
|
+
// test instead of dying silent before the first IPC message.
|
|
49
|
+
process.send?.({ type: 'startup-failed', error: String(error) });
|
|
50
|
+
process.exitCode = 1;
|
|
51
|
+
});
|
|
52
|
+
//# sourceMappingURL=graceful-shutdown.fixture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graceful-shutdown.fixture.js","sourceRoot":"","sources":["../../src/server/graceful-shutdown.fixture.ts"],"names":[],"mappings":";;;;;AAAA,sDAA8B;AAE9B,gEAAuF;AAEvF,KAAK,UAAU,GAAG;IAChB,sEAAsE;IACtE,wEAAwE;IACxE,sEAAsE;IACtE,wEAAwE;IACxE,oEAAoE;IACpE,wEAAwE;IACxE,oEAAoE;IACpE,MAAM,MAAM,GAAG,IAAA,iBAAO,EAAC,EAAE,MAAM,EAAE,KAAK,EAAE,qBAAqB,EAAE,KAAK,EAAE,CAAC,CAAC;IAExE,iEAAiE;IACjE,wEAAwE;IACxE,kDAAkD;IAClD,iDAAiD;IAEjD,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,IAAI,EAAE;QAC7B,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC,CAAC;QAC5C,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,E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
import type { FastifyInstance } from 'fastify';
|
|
2
|
+
export type ReadinessReason = 'vault_key_missing' | 'vault_key_invalid' | 'data_not_writable' | 'sqlite_unavailable';
|
|
3
|
+
export type ReadinessResult = {
|
|
4
|
+
ready: true;
|
|
5
|
+
} | {
|
|
6
|
+
ready: false;
|
|
7
|
+
reason: ReadinessReason;
|
|
8
|
+
};
|
|
9
|
+
export type ReadinessProbeOptions = {
|
|
10
|
+
env?: NodeJS.ProcessEnv;
|
|
11
|
+
dataPath: string;
|
|
12
|
+
sqliteProbe: () => void | Promise<void>;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Probe only operator-controlled dependencies. Responses intentionally expose
|
|
16
|
+
* stable codes rather than exception text, paths, key material, or SQLite
|
|
17
|
+
* diagnostics.
|
|
18
|
+
*/
|
|
19
|
+
export declare function assessReadiness(options: ReadinessProbeOptions): Promise<ReadinessResult>;
|
|
20
|
+
export declare function registerHealthRoutes(fastify: FastifyInstance, options: ReadinessProbeOptions): void;
|
|
21
|
+
//# sourceMappingURL=health.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/server/health.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAI/C,MAAM,MAAM,eAAe,GACvB,mBAAmB,GACnB,mBAAmB,GACnB,mBAAmB,GACnB,oBAAoB,CAAC;AAEzB,MAAM,MAAM,eAAe,GACvB;IAAE,KAAK,EAAE,IAAI,CAAA;CAAE,GACf;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,eAAe,CAAA;CAAE,CAAC;AAE9C,MAAM,MAAM,qBAAqB,GAAG;IAClC,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzC,CAAC;AAeF;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC,CA0B9F;AAED,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,qBAAqB,GAC7B,IAAI,CASN"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.assessReadiness = assessReadiness;
|
|
7
|
+
exports.registerHealthRoutes = registerHealthRoutes;
|
|
8
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const encrypted_file_secret_store_1 = require("../vault/encrypted-file-secret-store");
|
|
11
|
+
async function dataPathIsWritable(dataPath) {
|
|
12
|
+
const probePath = node_path_1.default.join(dataPath, `.agent-deck-ready-${process.pid}-${Date.now()}`);
|
|
13
|
+
try {
|
|
14
|
+
await promises_1.default.mkdir(dataPath, { recursive: true });
|
|
15
|
+
await promises_1.default.writeFile(probePath, '', { flag: 'wx', mode: 0o600 });
|
|
16
|
+
await promises_1.default.unlink(probePath);
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
await promises_1.default.unlink(probePath).catch(() => undefined);
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Probe only operator-controlled dependencies. Responses intentionally expose
|
|
26
|
+
* stable codes rather than exception text, paths, key material, or SQLite
|
|
27
|
+
* diagnostics.
|
|
28
|
+
*/
|
|
29
|
+
async function assessReadiness(options) {
|
|
30
|
+
const env = options.env ?? process.env;
|
|
31
|
+
const rawVaultKey = env[encrypted_file_secret_store_1.VAULT_KEY_ENV_VAR];
|
|
32
|
+
if (!rawVaultKey?.trim()) {
|
|
33
|
+
return { ready: false, reason: 'vault_key_missing' };
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
(0, encrypted_file_secret_store_1.parseVaultKey)(rawVaultKey);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (error instanceof encrypted_file_secret_store_1.VaultKeyError) {
|
|
40
|
+
return { ready: false, reason: 'vault_key_invalid' };
|
|
41
|
+
}
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
if (!(await dataPathIsWritable(options.dataPath))) {
|
|
45
|
+
return { ready: false, reason: 'data_not_writable' };
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
await options.sqliteProbe();
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return { ready: false, reason: 'sqlite_unavailable' };
|
|
52
|
+
}
|
|
53
|
+
return { ready: true };
|
|
54
|
+
}
|
|
55
|
+
function registerHealthRoutes(fastify, options) {
|
|
56
|
+
fastify.get('/healthz', async () => ({ status: 'ok' }));
|
|
57
|
+
fastify.get('/readyz', async (_request, reply) => {
|
|
58
|
+
const result = await assessReadiness(options);
|
|
59
|
+
if (!result.ready) {
|
|
60
|
+
return reply.status(503).send({ status: 'not_ready', reason: result.reason });
|
|
61
|
+
}
|
|
62
|
+
return { status: 'ready' };
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=health.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.js","sourceRoot":"","sources":["../../src/server/health.ts"],"names":[],"mappings":";;;;;AAwCA,0CA0BC;AAED,oDAYC;AAhFD,gEAAkC;AAClC,0DAA6B;AAG7B,sFAAuG;AAkBvG,KAAK,UAAU,kBAAkB,CAAC,QAAgB;IAChD,MAAM,SAAS,GAAG,mBAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,qBAAqB,OAAO,CAAC,GAAG,IAAI,IAA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