@0xmaxma/claude-gateway 1.3.25 → 1.3.32

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.
Files changed (72) hide show
  1. package/README.md +50 -2
  2. package/config.template.json +6 -2
  3. package/dist/agent/incident-store.d.ts +89 -0
  4. package/dist/agent/incident-store.d.ts.map +1 -0
  5. package/dist/agent/incident-store.js +299 -0
  6. package/dist/agent/incident-store.js.map +1 -0
  7. package/dist/agent/incident.d.ts +156 -0
  8. package/dist/agent/incident.d.ts.map +1 -0
  9. package/dist/agent/incident.js +177 -0
  10. package/dist/agent/incident.js.map +1 -0
  11. package/dist/agent/recovery-executor.d.ts +117 -0
  12. package/dist/agent/recovery-executor.d.ts.map +1 -0
  13. package/dist/agent/recovery-executor.js +168 -0
  14. package/dist/agent/recovery-executor.js.map +1 -0
  15. package/dist/agent/recovery-policy.d.ts +97 -0
  16. package/dist/agent/recovery-policy.d.ts.map +1 -0
  17. package/dist/agent/recovery-policy.js +164 -0
  18. package/dist/agent/recovery-policy.js.map +1 -0
  19. package/dist/agent/runner.d.ts +66 -6
  20. package/dist/agent/runner.d.ts.map +1 -1
  21. package/dist/agent/runner.js +332 -27
  22. package/dist/agent/runner.js.map +1 -1
  23. package/dist/agent/safe-mode.d.ts +61 -0
  24. package/dist/agent/safe-mode.d.ts.map +1 -0
  25. package/dist/agent/safe-mode.js +102 -0
  26. package/dist/agent/safe-mode.js.map +1 -0
  27. package/dist/agent/triage.d.ts +94 -0
  28. package/dist/agent/triage.d.ts.map +1 -0
  29. package/dist/agent/triage.js +209 -0
  30. package/dist/agent/triage.js.map +1 -0
  31. package/dist/agent/turn-trace.d.ts +120 -0
  32. package/dist/agent/turn-trace.d.ts.map +1 -0
  33. package/dist/agent/turn-trace.js +122 -0
  34. package/dist/agent/turn-trace.js.map +1 -0
  35. package/dist/api/gateway-router.d.ts +21 -0
  36. package/dist/api/gateway-router.d.ts.map +1 -1
  37. package/dist/api/gateway-router.js +58 -17
  38. package/dist/api/gateway-router.js.map +1 -1
  39. package/dist/api/router.d.ts.map +1 -1
  40. package/dist/api/router.js +104 -4
  41. package/dist/api/router.js.map +1 -1
  42. package/dist/config/migrator.d.ts +4 -0
  43. package/dist/config/migrator.d.ts.map +1 -1
  44. package/dist/config/migrator.js +60 -3
  45. package/dist/config/migrator.js.map +1 -1
  46. package/dist/history/db.d.ts +13 -1
  47. package/dist/history/db.d.ts.map +1 -1
  48. package/dist/history/db.js +67 -9
  49. package/dist/history/db.js.map +1 -1
  50. package/dist/history/types.d.ts +10 -0
  51. package/dist/history/types.d.ts.map +1 -1
  52. package/dist/index.js +3 -0
  53. package/dist/index.js.map +1 -1
  54. package/dist/session/process.d.ts +26 -0
  55. package/dist/session/process.d.ts.map +1 -1
  56. package/dist/session/process.js +77 -1
  57. package/dist/session/process.js.map +1 -1
  58. package/dist/shell/claude-pty-shell.js +59 -0
  59. package/dist/shell/claude-pty-shell.js.map +1 -1
  60. package/dist/shell/control-channel.d.ts +74 -0
  61. package/dist/shell/control-channel.d.ts.map +1 -0
  62. package/dist/shell/control-channel.js +114 -0
  63. package/dist/shell/control-channel.js.map +1 -0
  64. package/dist/types.d.ts +22 -0
  65. package/dist/types.d.ts.map +1 -1
  66. package/dist/ui/web-ui.d.ts.map +1 -1
  67. package/dist/ui/web-ui.js +103 -2
  68. package/dist/ui/web-ui.js.map +1 -1
  69. package/mcp/tools/skills/handlers.ts +4 -2
  70. package/mcp/tools/telegram/receiver-server.ts +163 -0
  71. package/mcp/tools/telegram/typing.ts +124 -0
  72. package/package.json +3 -1
package/README.md CHANGED
@@ -230,6 +230,7 @@ Global default retention policy. Can be overridden per-agent with an `history` k
230
230
  "gateway": {
231
231
  "history": {
232
232
  "retentionDays": 90,
233
+ "maxHistoryMessages": 30,
233
234
  "cleanupHour": 3,
234
235
  "cleanupTimezone": "Asia/Bangkok"
235
236
  }
@@ -240,6 +241,7 @@ Global default retention policy. Can be overridden per-agent with an `history` k
240
241
  | Field | Default | Description |
241
242
  |-------|---------|-------------|
242
243
  | `retentionDays` | `null` (keep forever) | Delete messages older than N days on each cleanup cycle |
244
+ | `maxHistoryMessages` | `50` | Max history messages re-injected into a session at spawn. Lower it to shrink the context loaded at session start. `0` = inject no history |
243
245
  | `cleanupHour` | `3` | Hour of day to run cleanup (24h, in `cleanupTimezone`) |
244
246
  | `cleanupTimezone` | `"UTC"` | IANA timezone for the cleanup schedule |
245
247
 
@@ -249,7 +251,7 @@ Per-agent override example:
249
251
  "agents": [
250
252
  {
251
253
  "id": "alfred",
252
- "history": { "retentionDays": 30 }
254
+ "history": { "retentionDays": 30, "maxHistoryMessages": 30 }
253
255
  }
254
256
  ]
255
257
  }
@@ -293,6 +295,52 @@ Controls the Claude subprocess backend for all non-app agents.
293
295
 
294
296
  This setting is hot-reloadable — new sessions pick it up without a restart.
295
297
 
298
+ ### `gateway.selfHealing.autoRecover`
299
+
300
+ Opt-in self-healing for the turn-trace watchdog (Epic #195). When a turn stalls, the gateway always detects it, logs a scrubbed incident, and notifies the affected chat. This flag additionally controls whether the gateway may *act* on a stall.
301
+
302
+ | Value | Behaviour |
303
+ |-------|-----------|
304
+ | `false` *(default)* | Detection + incident logging + notification only — no automatic action |
305
+ | `true` | The watchdog may run a whitelisted recovery for a stalled turn: a keystroke into the TUI (esc / enter / arrow / menu selection), a session restart, a reversible safe-mode fallback to the headless backend, and — after a successful unblock — a guarded resend of the last message (only if the turn produced no output, so it is never double-submitted) |
306
+
307
+ Recovery actions are clamped to a per-stage whitelist and a per-turn budget, and any local triage treats the on-screen text as untrusted data validated against a closed schema. Safe-mode auto-fallback on a hard PTY failure is independent of this flag (it is always reversible and never presses keys). In-memory only — a gateway restart re-reads your real config.
308
+
309
+ ```json
310
+ {
311
+ "gateway": {
312
+ "selfHealing": {
313
+ "autoRecover": true
314
+ }
315
+ }
316
+ }
317
+ ```
318
+
319
+ ### `gateway.bind`
320
+
321
+ Network interface the HTTP/WebSocket server binds to. Defaults to `127.0.0.1` (localhost-only), so the dashboard and API are **not** exposed to the local network out of the box. Set to `0.0.0.0` to listen on all interfaces (for example when a containerized reverse proxy needs to reach the gateway). The `GATEWAY_BIND` environment variable, when set, takes precedence over this field.
322
+
323
+ ```json
324
+ {
325
+ "gateway": {
326
+ "bind": "127.0.0.1"
327
+ }
328
+ }
329
+ ```
330
+
331
+ > **⚠️ Upgrade note:** the default bind changed from `0.0.0.0` to `127.0.0.1` (configVersion 1.0.13). To avoid silently cutting off external access, the config migrator is **behavior-preserving**: whenever it upgrades a config that never set `gateway.bind`, it pins `bind` to `0.0.0.0` and logs a one-time warning, so a deployment that was reachable from another host stays reachable. This applies to *any* upgraded config with no `bind` key — including one already stamped `1.0.13` that never received a bind (an earlier version gated this on `< 1.0.13` and left such configs stuck on the `127.0.0.1` default). New installs (no prior config, so no migration runs) keep the secure `127.0.0.1` default. If you *want* localhost-only after upgrading, set `gateway.bind` to `127.0.0.1` explicitly (or the `GATEWAY_BIND` env var).
332
+
333
+ ### Terminal Viewer — interactive terminal mode
334
+
335
+ The dashboard's **Terminal Viewer** opens read-only (a live mirror of the PTY). A toggle in the top-right of the viewer switches it into an **interactive terminal**: keystrokes typed into the panel — printable characters, Enter, arrows, Ctrl-combos, Esc — are streamed into the live PTY, and the panel title changes to reflect the active mode. This is a per-browser client-side choice (Issue #201); there is no server config flag to enable it.
336
+
337
+ Because interactive mode turns a read-only view into a remote-write surface, access is protected upstream rather than by a feature flag:
338
+
339
+ - **Authentication** — the WebSocket requires a valid dashboard ticket or API key.
340
+ - **`gateway.bind`** — the gateway binds to `127.0.0.1` (localhost) by default, so the dashboard is not reachable from the network out of the box. Expose a non-loopback bind (`0.0.0.0`) **only** behind a trusted authenticating reverse proxy.
341
+
342
+ Inbound frames are always bounded (text-only, size-capped) and are dropped for headless sessions (no PTY).
343
+
296
344
  ### `gateway.api.keys`
297
345
 
298
346
  Each key has a `key` string (supports `${ENV_VAR}` interpolation), an optional `description`, and an `agents` field — either an array of agent IDs or `"*"` for full access. Keys support both `Authorization: Bearer` and `X-Api-Key` headers.
@@ -485,7 +533,7 @@ The gateway proxies `/app/:name/:portName/*` to the app containers. Two env vars
485
533
 
486
534
  | Env var | Default | Description |
487
535
  |---------|---------|-------------|
488
- | `GATEWAY_BIND` | `0.0.0.0` | Gateway HTTP listen address. Must be `0.0.0.0` (default) when a **containerized** reverse proxy (Caddy, nginx in Docker) needs to reach the gateway. Set to `127.0.0.1` only if using a **host-network** proxy (Traefik on host) loopback is not reachable across container boundaries. |
536
+ | `GATEWAY_BIND` | `127.0.0.1` | Gateway HTTP listen address. Overrides the `gateway.bind` config field when set. Defaults to localhost-only; set to `0.0.0.0` when a **containerized** reverse proxy (Caddy, nginx in Docker) needs to reach the gateway across container boundaries. A **host-network** proxy (Traefik on host) can keep the localhost default. |
489
537
  | `DOCKER_HOST` | _(system default)_ | Docker socket/TCP address. When set to `tcp://host:port` (e.g. DinD), the gateway automatically uses the host extracted from `DOCKER_HOST` to proxy to app containers instead of `127.0.0.1`. |
490
538
 
491
539
  Example Caddyfile for apps behind Caddy in Docker:
@@ -10,10 +10,11 @@
10
10
  "claude.dangerouslySkipPermissions"
11
11
  ]
12
12
  },
13
- "configVersion": "1.0.11",
13
+ "configVersion": "1.0.14",
14
14
  "gateway": {
15
15
  "logDir": "~/.claude-gateway/logs",
16
16
  "timezone": "Asia/Bangkok",
17
+ "bind": "127.0.0.1",
17
18
  "models": [
18
19
  { "id": "claude-fable-5[1m]", "label": "Fable 5 (1M)", "alias": "fable[1m]", "contextWindow": 1000000 },
19
20
  { "id": "claude-opus-4-8[1m]", "label": "Opus 4.8 (1M)", "alias": "opus[1m]", "contextWindow": 1000000 },
@@ -44,7 +45,10 @@
44
45
  "cleanupHour": 0,
45
46
  "cleanupTimezone": "UTC"
46
47
  },
47
- "headless": true
48
+ "headless": true,
49
+ "selfHealing": {
50
+ "autoRecover": false
51
+ }
48
52
  },
49
53
  "agents": [
50
54
  {
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Incident store (Epic #195, Phase 2).
3
+ *
4
+ * Persists turn-trace stall incidents as on-disk bundles under
5
+ * `<dir>/<id>/`, deduplicates repeats by fingerprint within a rolling window,
6
+ * escalates according to the pure rules in incident.ts, and prunes old bundles.
7
+ *
8
+ * All IO is funnelled through an injected `fs` and `now()` so the store is
9
+ * fully unit-testable against an in-memory filesystem (no real disk, no real
10
+ * clock). The pure decision logic (fingerprint, escalation, scrub, digest)
11
+ * lives in incident.ts; this file only orchestrates it and touches disk.
12
+ *
13
+ * A bundle is captured BEFORE any recovery mutates state (Phase 3 recovery runs
14
+ * after record() returns), so evidence reflects the wedged turn, not its
15
+ * aftermath. Every text artifact is scrubbed on the way in.
16
+ */
17
+ import type { TurnIncident, TurnIncidentEvidence } from './turn-trace';
18
+ import { type EscalationConfig, type EscalationDecision, type EscalationLevel, type IncidentManifest, type DigestSummary, type RecoveryOutcome } from './incident';
19
+ /** Minimal filesystem surface the store needs. Node's `fs` satisfies it. */
20
+ export interface IncidentFsApi {
21
+ mkdirSync(path: string, opts: {
22
+ recursive: boolean;
23
+ }): void;
24
+ writeFileSync(path: string, data: string): void;
25
+ readFileSync(path: string, enc: 'utf8'): string;
26
+ existsSync(path: string): boolean;
27
+ readdirSync(path: string): string[];
28
+ rmSync(path: string, opts: {
29
+ recursive: boolean;
30
+ force: boolean;
31
+ }): void;
32
+ }
33
+ export interface IncidentStoreDeps {
34
+ /** Base directory for incident bundles (e.g. ~/.claude-gateway/incidents). */
35
+ dir: string;
36
+ fs: IncidentFsApi;
37
+ /** Clock injection — epoch ms. */
38
+ now: () => number;
39
+ /** Transport name recorded on each incident ('telegram' | 'discord' | ...). */
40
+ channel: string;
41
+ /** Gateway version, recorded for context (not part of the fingerprint). */
42
+ gatewayVersion: string;
43
+ /** Lazily resolves the Claude CLI version (part of the fingerprint). */
44
+ getCliVersion: () => string;
45
+ /** Retention: bundles whose lastAt is older than this are pruned (ms). */
46
+ retentionMs?: number;
47
+ /** Retention: hard cap on bundle count (oldest pruned first). */
48
+ maxIncidents?: number;
49
+ /** Escalation thresholds. */
50
+ escalation?: EscalationConfig;
51
+ /** Max occurrence samples retained per incident. */
52
+ maxSamples?: number;
53
+ }
54
+ /** Outcome of recording one stall occurrence. */
55
+ export interface RecordResult {
56
+ id: string;
57
+ fingerprint: string;
58
+ occurrences: number;
59
+ escalation: EscalationDecision;
60
+ /** True when this created a fresh bundle (vs. folding into an existing one). */
61
+ isNew: boolean;
62
+ manifest: IncidentManifest;
63
+ }
64
+ export interface IncidentStore {
65
+ record(incident: TurnIncident, evidence?: TurnIncidentEvidence): RecordResult;
66
+ /** Load a manifest by id, or null if absent/corrupt. */
67
+ get(id: string): IncidentManifest | null;
68
+ /** Record that the user was notified at a level (dedupes re-notifying). */
69
+ markNotified(id: string, level: EscalationLevel, at?: number): void;
70
+ /**
71
+ * Append a recovery outcome to an incident bundle (Phase 3b). The runner
72
+ * executes recovery and returns the outcome; the receiver persists it here so
73
+ * the bundle records what was attempted and whether it worked. Capped like
74
+ * samples so a flapping stall cannot grow the manifest unbounded.
75
+ */
76
+ appendRecovery(id: string, outcome: RecoveryOutcome): void;
77
+ /** Link a filed GitHub issue to an incident fingerprint. */
78
+ linkIssue(id: string, issueNumber: number): void;
79
+ /** Mark an incident resolved (stops it folding new occurrences). */
80
+ resolve(id: string): void;
81
+ /** Prune bundles past retention / over the count cap. Returns pruned ids. */
82
+ prune(): string[];
83
+ /** Digest summary over the last `sinceMs`. */
84
+ digest(sinceMs: number): DigestSummary;
85
+ /** All manifests currently on disk (unsorted). */
86
+ list(): IncidentManifest[];
87
+ }
88
+ export declare function createIncidentStore(deps: IncidentStoreDeps): IncidentStore;
89
+ //# sourceMappingURL=incident-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"incident-store.d.ts","sourceRoot":"","sources":["../../src/agent/incident-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,oBAAo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icates repeats by fingerprint within a rolling window,
7
+ * escalates according to the pure rules in incident.ts, and prunes old bundles.
8
+ *
9
+ * All IO is funnelled through an injected `fs` and `now()` so the store is
10
+ * fully unit-testable against an in-memory filesystem (no real disk, no real
11
+ * clock). The pure decision logic (fingerprint, escalation, scrub, digest)
12
+ * lives in incident.ts; this file only orchestrates it and touches disk.
13
+ *
14
+ * A bundle is captured BEFORE any recovery mutates state (Phase 3 recovery runs
15
+ * after record() returns), so evidence reflects the wedged turn, not its
16
+ * aftermath. Every text artifact is scrubbed on the way in.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.createIncidentStore = createIncidentStore;
20
+ const incident_1 = require("./incident");
21
+ const DEFAULT_RETENTION_MS = 30 * 24 * 60 * 60 * 1000; // 30 days
22
+ const DEFAULT_MAX_INCIDENTS = 500;
23
+ const DEFAULT_MAX_SAMPLES = 20;
24
+ const MANIFEST = 'manifest.json';
25
+ function createIncidentStore(deps) {
26
+ const { dir, fs, now, channel, gatewayVersion, getCliVersion, retentionMs = DEFAULT_RETENTION_MS, maxIncidents = DEFAULT_MAX_INCIDENTS, escalation = incident_1.DEFAULT_ESCALATION, maxSamples = DEFAULT_MAX_SAMPLES, } = deps;
27
+ // In-memory index of currently-open incidents by fingerprint, so dedup does
28
+ // not rescan every bundle on each stall. Rebuilt from disk on construction so
29
+ // dedup survives a process restart.
30
+ const openByFingerprint = new Map(); // fingerprint → id
31
+ function bundleDir(id) {
32
+ return join(dir, id);
33
+ }
34
+ function manifestPath(id) {
35
+ return join(bundleDir(id), MANIFEST);
36
+ }
37
+ function ensureBaseDir() {
38
+ try {
39
+ fs.mkdirSync(dir, { recursive: true });
40
+ }
41
+ catch {
42
+ // Best-effort; a subsequent write will surface a real failure.
43
+ }
44
+ }
45
+ function readManifest(id) {
46
+ try {
47
+ const raw = fs.readFileSync(manifestPath(id), 'utf8');
48
+ const m = JSON.parse(raw);
49
+ // Defensive: a manifest missing its id is treated as corrupt.
50
+ if (!m || typeof m.id !== 'string' || typeof m.fingerprint !== 'string') {
51
+ return null;
52
+ }
53
+ return m;
54
+ }
55
+ catch {
56
+ return null;
57
+ }
58
+ }
59
+ function writeManifest(m) {
60
+ fs.mkdirSync(bundleDir(m.id), { recursive: true });
61
+ fs.writeFileSync(manifestPath(m.id), JSON.stringify(m, null, 2));
62
+ }
63
+ function listIds() {
64
+ try {
65
+ return fs.readdirSync(dir).filter((name) => {
66
+ // Only directories that contain a manifest count as bundles.
67
+ return fs.existsSync(manifestPath(name));
68
+ });
69
+ }
70
+ catch {
71
+ return [];
72
+ }
73
+ }
74
+ // ── Rebuild the open-fingerprint index from disk on construction. ──────────
75
+ ensureBaseDir();
76
+ for (const id of listIds()) {
77
+ const m = readManifest(id);
78
+ if (m && m.status === 'open') {
79
+ // If two open bundles share a fingerprint (shouldn't happen), keep the
80
+ // most recent so folding continues on the freshest episode.
81
+ const existing = openByFingerprint.get(m.fingerprint);
82
+ if (!existing) {
83
+ openByFingerprint.set(m.fingerprint, m.id);
84
+ }
85
+ else {
86
+ const prev = readManifest(existing);
87
+ if (!prev || m.lastAt >= prev.lastAt) {
88
+ openByFingerprint.set(m.fingerprint, m.id);
89
+ }
90
+ }
91
+ }
92
+ }
93
+ function scrubEvidence(evidence, redactions) {
94
+ const files = {};
95
+ if (!evidence)
96
+ return files;
97
+ if (evidence.artifacts && evidence.artifacts.length > 0) {
98
+ files['typing-artifacts.txt'] = (0, incident_1.scrubText)(evidence.artifacts.join('\n'), redactions);
99
+ }
100
+ if (evidence.statusText) {
101
+ files['status.txt'] = (0, incident_1.scrubText)(evidence.statusText, redactions);
102
+ }
103
+ if (evidence.errorText) {
104
+ files['error.txt'] = (0, incident_1.scrubText)(evidence.errorText, redactions);
105
+ }
106
+ return files;
107
+ }
108
+ function record(incident, evidence) {
109
+ const at = incident.at || now();
110
+ const cliVersion = safe(getCliVersion) || 'unknown';
111
+ const fingerprint = (0, incident_1.computeFingerprint)({
112
+ stage: incident.stage,
113
+ failureClass: incident.failureClass,
114
+ cliVersion,
115
+ });
116
+ const sample = {
117
+ at,
118
+ sinceMs: incident.sinceMs,
119
+ budgetMs: incident.budgetMs,
120
+ midTurn: incident.midTurn,
121
+ };
122
+ // Try to fold into an existing open incident within the dedup window.
123
+ const existingId = openByFingerprint.get(fingerprint);
124
+ if (existingId) {
125
+ const existing = readManifest(existingId);
126
+ if (existing &&
127
+ existing.status === 'open' &&
128
+ at - existing.lastAt <= escalation.windowMs) {
129
+ existing.occurrences += 1;
130
+ existing.lastAt = at;
131
+ existing.samples = pushCapped(existing.samples, sample, maxSamples);
132
+ const escalated = (0, incident_1.decideEscalation)(existing.occurrences, existing.notifiedLevel === 'investigate', escalation);
133
+ existing.escalationLevel = (0, incident_1.maxEscalationLevel)(existing.escalationLevel, escalated.level);
134
+ writeManifest(existing);
135
+ return {
136
+ id: existing.id,
137
+ fingerprint,
138
+ occurrences: existing.occurrences,
139
+ escalation: escalated,
140
+ isNew: false,
141
+ manifest: existing,
142
+ };
143
+ }
144
+ // Stale or resolved → drop the stale index entry and fall through to new.
145
+ openByFingerprint.delete(fingerprint);
146
+ }
147
+ // Fresh incident bundle.
148
+ const id = `${(0, incident_1.fingerprintHash)(fingerprint)}-${at}`;
149
+ const escalated = (0, incident_1.decideEscalation)(1, false, escalation);
150
+ const manifest = {
151
+ id,
152
+ fingerprint,
153
+ stage: incident.stage,
154
+ failureClass: incident.failureClass,
155
+ cliVersion,
156
+ gatewayVersion,
157
+ channel,
158
+ firstAt: at,
159
+ lastAt: at,
160
+ occurrences: 1,
161
+ escalationLevel: escalated.level,
162
+ status: 'open',
163
+ notifiedAt: null,
164
+ notifiedLevel: null,
165
+ githubIssue: null,
166
+ recovery: [],
167
+ samples: [sample],
168
+ };
169
+ // Redact the chat id and any known handle from all exported text.
170
+ const redactions = [incident.chatId];
171
+ writeManifest(manifest);
172
+ const files = scrubEvidence(evidence, redactions);
173
+ for (const [name, content] of Object.entries(files)) {
174
+ try {
175
+ fs.writeFileSync(join(bundleDir(id), name), content);
176
+ }
177
+ catch {
178
+ // A failed artifact write must not lose the incident itself.
179
+ }
180
+ }
181
+ openByFingerprint.set(fingerprint, id);
182
+ // Enforce the count cap opportunistically on creation.
183
+ prune();
184
+ return { id, fingerprint, occurrences: 1, escalation: escalated, isNew: true, manifest };
185
+ }
186
+ function get(id) {
187
+ return readManifest(id);
188
+ }
189
+ function markNotified(id, level, atArg) {
190
+ const m = readManifest(id);
191
+ if (!m)
192
+ return;
193
+ m.notifiedAt = atArg ?? now();
194
+ m.notifiedLevel = m.notifiedLevel
195
+ ? (0, incident_1.maxEscalationLevel)(m.notifiedLevel, level)
196
+ : level;
197
+ writeManifest(m);
198
+ }
199
+ function appendRecovery(id, outcome) {
200
+ const m = readManifest(id);
201
+ if (!m)
202
+ return;
203
+ m.recovery = pushCapped(m.recovery ?? [], outcome, maxSamples);
204
+ writeManifest(m);
205
+ }
206
+ function linkIssue(id, issueNumber) {
207
+ const m = readManifest(id);
208
+ if (!m)
209
+ return;
210
+ m.githubIssue = issueNumber;
211
+ writeManifest(m);
212
+ }
213
+ function resolve(id) {
214
+ const m = readManifest(id);
215
+ if (!m)
216
+ return;
217
+ m.status = 'resolved';
218
+ writeManifest(m);
219
+ if (openByFingerprint.get(m.fingerprint) === id) {
220
+ openByFingerprint.delete(m.fingerprint);
221
+ }
222
+ }
223
+ function list() {
224
+ const out = [];
225
+ for (const id of listIds()) {
226
+ const m = readManifest(id);
227
+ if (m)
228
+ out.push(m);
229
+ }
230
+ return out;
231
+ }
232
+ function prune() {
233
+ const manifests = list();
234
+ const cutoff = now() - retentionMs;
235
+ const pruned = [];
236
+ // Age-based prune.
237
+ const survivors = [];
238
+ for (const m of manifests) {
239
+ if (m.lastAt < cutoff) {
240
+ removeBundle(m.id);
241
+ pruned.push(m.id);
242
+ }
243
+ else {
244
+ survivors.push(m);
245
+ }
246
+ }
247
+ // Count-cap prune: drop oldest (by lastAt) beyond the cap.
248
+ if (survivors.length > maxIncidents) {
249
+ survivors.sort((a, b) => a.lastAt - b.lastAt); // oldest first
250
+ const overflow = survivors.length - maxIncidents;
251
+ for (let i = 0; i < overflow; i++) {
252
+ removeBundle(survivors[i].id);
253
+ pruned.push(survivors[i].id);
254
+ }
255
+ }
256
+ // Keep the open-fingerprint index consistent with what remains.
257
+ for (const id of pruned) {
258
+ for (const [fp, mapped] of openByFingerprint) {
259
+ if (mapped === id)
260
+ openByFingerprint.delete(fp);
261
+ }
262
+ }
263
+ return pruned;
264
+ }
265
+ function removeBundle(id) {
266
+ try {
267
+ fs.rmSync(bundleDir(id), { recursive: true, force: true });
268
+ }
269
+ catch {
270
+ // Best-effort.
271
+ }
272
+ }
273
+ function digest(sinceMs) {
274
+ return (0, incident_1.summarizeIncidents)(list(), sinceMs, now());
275
+ }
276
+ return { record, get, markNotified, appendRecovery, linkIssue, resolve, prune, digest, list };
277
+ }
278
+ /** Path join without importing `path` (keeps the module dependency-light). */
279
+ function join(...parts) {
280
+ return parts
281
+ .map((p, i) => (i === 0 ? p.replace(/\/+$/, '') : p.replace(/^\/+|\/+$/g, '')))
282
+ .filter((p) => p.length > 0)
283
+ .join('/');
284
+ }
285
+ /** Push onto a capped ring, dropping the oldest when full. */
286
+ function pushCapped(arr, item, cap) {
287
+ const next = [...arr, item];
288
+ return next.length > cap ? next.slice(next.length - cap) : next;
289
+ }
290
+ /** Call a provider defensively; any throw collapses to ''. */
291
+ function safe(fn) {
292
+ try {
293
+ return fn();
294
+ }
295
+ catch {
296
+ return '';
297
+ }
298
+ }
299
+ //# sourceMappingURL=incident-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"incident-store.js","sourceRoot":"","sources":["../../src/agent/incident-store.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;AA6FH,kDAsSC;AAhYD,yCAemB;AA6CnB,MAAM,oBAAoB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA,CAAC,UAAU;AAChE,MAA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