@proletariat/cli 0.3.105 → 0.3.109
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/agent/cleanup.js +13 -1
- package/dist/commands/agent/cleanup.js.map +1 -1
- package/dist/commands/claude/index.js +2 -2
- package/dist/commands/claude/index.js.map +1 -1
- package/dist/commands/feedback/list.js +4 -9
- package/dist/commands/feedback/list.js.map +1 -1
- package/dist/commands/feedback/submit.js +4 -9
- package/dist/commands/feedback/submit.js.map +1 -1
- package/dist/commands/feedback/view.js +4 -9
- package/dist/commands/feedback/view.js.map +1 -1
- package/dist/commands/gc.d.ts +1 -0
- package/dist/commands/gc.js +34 -1
- package/dist/commands/gc.js.map +1 -1
- package/dist/commands/notify/connect.d.ts +34 -0
- package/dist/commands/notify/connect.js +166 -0
- package/dist/commands/notify/connect.js.map +1 -0
- package/dist/commands/notify/disconnect.d.ts +16 -0
- package/dist/commands/notify/disconnect.js +45 -0
- package/dist/commands/notify/disconnect.js.map +1 -0
- package/dist/commands/notify/list.d.ts +15 -0
- package/dist/commands/notify/list.js +101 -0
- package/dist/commands/notify/list.js.map +1 -0
- package/dist/commands/notify/rules/add.d.ts +26 -0
- package/dist/commands/notify/rules/add.js +95 -0
- package/dist/commands/notify/rules/add.js.map +1 -0
- package/dist/commands/notify/rules/list.d.ts +14 -0
- package/dist/commands/notify/rules/list.js +82 -0
- package/dist/commands/notify/rules/list.js.map +1 -0
- package/dist/commands/notify/rules/remove.d.ts +16 -0
- package/dist/commands/notify/rules/remove.js +44 -0
- package/dist/commands/notify/rules/remove.js.map +1 -0
- package/dist/commands/notify/test.d.ts +16 -0
- package/dist/commands/notify/test.js +63 -0
- package/dist/commands/notify/test.js.map +1 -0
- package/dist/commands/orchestrate/index.js +11 -6
- package/dist/commands/orchestrate/index.js.map +1 -1
- package/dist/commands/orchestrate/machine.d.ts +29 -0
- package/dist/commands/orchestrate/machine.js +230 -0
- package/dist/commands/orchestrate/machine.js.map +1 -0
- package/dist/commands/pr/checks.js +4 -8
- package/dist/commands/pr/checks.js.map +1 -1
- package/dist/commands/pr/close.js +4 -8
- package/dist/commands/pr/close.js.map +1 -1
- package/dist/commands/pr/create.js +4 -8
- package/dist/commands/pr/create.js.map +1 -1
- package/dist/commands/pr/index.js +1 -1
- package/dist/commands/pr/index.js.map +1 -1
- package/dist/commands/pr/link.js +4 -8
- package/dist/commands/pr/link.js.map +1 -1
- package/dist/commands/pr/list.js +5 -9
- package/dist/commands/pr/list.js.map +1 -1
- package/dist/commands/pr/merge.d.ts +5 -0
- package/dist/commands/pr/merge.js +35 -11
- package/dist/commands/pr/merge.js.map +1 -1
- package/dist/commands/pr/status.js +5 -4
- package/dist/commands/pr/status.js.map +1 -1
- package/dist/commands/qa/index.js +2 -2
- package/dist/commands/qa/index.js.map +1 -1
- package/dist/commands/repo/create.js +4 -8
- package/dist/commands/repo/create.js.map +1 -1
- package/dist/commands/session/list.js +81 -41
- package/dist/commands/session/list.js.map +1 -1
- package/dist/commands/session/poke.d.ts +1 -11
- package/dist/commands/session/poke.js +20 -78
- package/dist/commands/session/poke.js.map +1 -1
- package/dist/commands/session/prune.js +3 -0
- package/dist/commands/session/prune.js.map +1 -1
- package/dist/commands/ticket/move.d.ts +12 -0
- package/dist/commands/ticket/move.js +75 -2
- package/dist/commands/ticket/move.js.map +1 -1
- package/dist/commands/work/drop.js +2 -2
- package/dist/commands/work/drop.js.map +1 -1
- package/dist/commands/work/ready.js +3 -3
- package/dist/commands/work/ready.js.map +1 -1
- package/dist/commands/work/rebase.js +4 -8
- package/dist/commands/work/rebase.js.map +1 -1
- package/dist/commands/work/run.d.ts +58 -0
- package/dist/commands/work/run.js +411 -0
- package/dist/commands/work/run.js.map +1 -0
- package/dist/commands/work/ship.d.ts +6 -0
- package/dist/commands/work/ship.js +93 -51
- package/dist/commands/work/ship.js.map +1 -1
- package/dist/commands/work/start.d.ts +1 -0
- package/dist/commands/work/start.js +126 -13
- package/dist/commands/work/start.js.map +1 -1
- package/dist/lib/agents/commands.d.ts +6 -0
- package/dist/lib/agents/commands.js +55 -2
- package/dist/lib/agents/commands.js.map +1 -1
- package/dist/lib/database/credential-store.js +2 -3
- package/dist/lib/database/credential-store.js.map +1 -1
- package/dist/lib/database/db-safety.d.ts +25 -0
- package/dist/lib/database/db-safety.js +35 -0
- package/dist/lib/database/db-safety.js.map +1 -1
- package/dist/lib/database/driver.js +6 -12
- package/dist/lib/database/driver.js.map +1 -1
- package/dist/lib/database/drizzle-schema.d.ts +3 -3
- package/dist/lib/database/drizzle.js +3 -3
- package/dist/lib/database/drizzle.js.map +1 -1
- package/dist/lib/database/index.d.ts +1 -1
- package/dist/lib/database/index.js +1 -1
- package/dist/lib/database/index.js.map +1 -1
- package/dist/lib/database/migrations/0021_notification_system.d.ts +2 -0
- package/dist/lib/database/migrations/0021_notification_system.js +39 -0
- package/dist/lib/database/migrations/0021_notification_system.js.map +1 -0
- package/dist/lib/database/migrations/0022_hook_mode_tiers.d.ts +11 -0
- package/dist/lib/database/migrations/0022_hook_mode_tiers.js +53 -0
- package/dist/lib/database/migrations/0022_hook_mode_tiers.js.map +1 -0
- package/dist/lib/database/migrations/index.js +4 -0
- package/dist/lib/database/migrations/index.js.map +1 -1
- package/dist/lib/database/pmo-bootstrap.js +6 -2
- package/dist/lib/database/pmo-bootstrap.js.map +1 -1
- package/dist/lib/database/workspace.js +5 -13
- package/dist/lib/database/workspace.js.map +1 -1
- package/dist/lib/events/emitting-runner.js +10 -0
- package/dist/lib/events/emitting-runner.js.map +1 -1
- package/dist/lib/execution/cc-version.d.ts +62 -0
- package/dist/lib/execution/cc-version.js +103 -0
- package/dist/lib/execution/cc-version.js.map +1 -0
- package/dist/lib/execution/devcontainer.js +2 -1
- package/dist/lib/execution/devcontainer.js.map +1 -1
- package/dist/lib/execution/runners/devcontainer.js +4 -1
- package/dist/lib/execution/runners/devcontainer.js.map +1 -1
- package/dist/lib/execution/runners/docker-management.js +10 -46
- package/dist/lib/execution/runners/docker-management.js.map +1 -1
- package/dist/lib/execution/runners/orchestrator.js +13 -39
- package/dist/lib/execution/runners/orchestrator.js.map +1 -1
- package/dist/lib/execution/session-utils.d.ts +88 -1
- package/dist/lib/execution/session-utils.js +120 -46
- package/dist/lib/execution/session-utils.js.map +1 -1
- package/dist/lib/execution/storage.js +20 -2
- package/dist/lib/execution/storage.js.map +1 -1
- package/dist/lib/flags/resolver.d.ts +8 -1
- package/dist/lib/flags/resolver.js +35 -2
- package/dist/lib/flags/resolver.js.map +1 -1
- package/dist/lib/gc/cascade.d.ts +99 -0
- package/dist/lib/gc/cascade.js +357 -0
- package/dist/lib/gc/cascade.js.map +1 -0
- package/dist/lib/gc/config.d.ts +69 -0
- package/dist/lib/gc/config.js +134 -0
- package/dist/lib/gc/config.js.map +1 -0
- package/dist/lib/gc/index.d.ts +36 -0
- package/dist/lib/gc/index.js +209 -1
- package/dist/lib/gc/index.js.map +1 -1
- package/dist/lib/init/index.js +10 -1
- package/dist/lib/init/index.js.map +1 -1
- package/dist/lib/machine-db.d.ts +144 -0
- package/dist/lib/machine-db.js +338 -0
- package/dist/lib/machine-db.js.map +1 -0
- package/dist/lib/machine-orchestrator.d.ts +35 -0
- package/dist/lib/machine-orchestrator.js +139 -0
- package/dist/lib/machine-orchestrator.js.map +1 -0
- package/dist/lib/notifications/dispatcher.d.ts +29 -0
- package/dist/lib/notifications/dispatcher.js +281 -0
- package/dist/lib/notifications/dispatcher.js.map +1 -0
- package/dist/lib/notifications/index.d.ts +13 -0
- package/dist/lib/notifications/index.js +18 -0
- package/dist/lib/notifications/index.js.map +1 -0
- package/dist/lib/notifications/manager.d.ts +46 -0
- package/dist/lib/notifications/manager.js +200 -0
- package/dist/lib/notifications/manager.js.map +1 -0
- package/dist/lib/notifications/storage.d.ts +60 -0
- package/dist/lib/notifications/storage.js +182 -0
- package/dist/lib/notifications/storage.js.map +1 -0
- package/dist/lib/notifications/types.d.ts +126 -0
- package/dist/lib/notifications/types.js +16 -0
- package/dist/lib/notifications/types.js.map +1 -0
- package/dist/lib/orchestrate/actions.js +182 -3
- package/dist/lib/orchestrate/actions.js.map +1 -1
- package/dist/lib/orchestrate/config-loader.js +9 -35
- package/dist/lib/orchestrate/config-loader.js.map +1 -1
- package/dist/lib/orchestrate/engine.d.ts +53 -1
- package/dist/lib/orchestrate/engine.js +74 -3
- package/dist/lib/orchestrate/engine.js.map +1 -1
- package/dist/lib/orchestrate/escalation.d.ts +87 -0
- package/dist/lib/orchestrate/escalation.js +63 -0
- package/dist/lib/orchestrate/escalation.js.map +1 -0
- package/dist/lib/orchestrate/index.d.ts +2 -0
- package/dist/lib/orchestrate/index.js +1 -0
- package/dist/lib/orchestrate/index.js.map +1 -1
- package/dist/lib/orchestrate/llm-agent.d.ts +101 -0
- package/dist/lib/orchestrate/llm-agent.js +295 -0
- package/dist/lib/orchestrate/llm-agent.js.map +1 -0
- package/dist/lib/orchestrate/presets.d.ts +4 -3
- package/dist/lib/orchestrate/presets.js +13 -8
- package/dist/lib/orchestrate/presets.js.map +1 -1
- package/dist/lib/orchestrate/types.d.ts +7 -1
- package/dist/lib/orchestrate/types.js +1 -0
- package/dist/lib/orchestrate/types.js.map +1 -1
- package/dist/lib/pmo/base-command.js +1 -1
- package/dist/lib/pmo/base-command.js.map +1 -1
- package/dist/lib/pmo/find-pmo.d.ts +8 -0
- package/dist/lib/pmo/find-pmo.js +63 -2
- package/dist/lib/pmo/find-pmo.js.map +1 -1
- package/dist/lib/pmo/index.d.ts +1 -1
- package/dist/lib/pmo/index.js +1 -1
- package/dist/lib/pmo/index.js.map +1 -1
- package/dist/lib/pmo/pmo-context.js +1 -1
- package/dist/lib/pmo/pmo-context.js.map +1 -1
- package/dist/lib/pmo/storage/index.js +2 -1
- package/dist/lib/pmo/storage/index.js.map +1 -1
- package/dist/lib/pr/index.d.ts +32 -0
- package/dist/lib/pr/index.js +45 -0
- package/dist/lib/pr/index.js.map +1 -1
- package/dist/lib/registry/index.js +0 -1
- package/dist/lib/registry/index.js.map +1 -1
- package/dist/lib/signal-handler.d.ts +8 -0
- package/dist/lib/signal-handler.js +33 -0
- package/dist/lib/signal-handler.js.map +1 -1
- package/dist/lib/themes.js +8 -1
- package/dist/lib/themes.js.map +1 -1
- package/dist/lib/work-lifecycle/container-cleanup-hook.d.ts +17 -7
- package/dist/lib/work-lifecycle/container-cleanup-hook.js +64 -11
- package/dist/lib/work-lifecycle/container-cleanup-hook.js.map +1 -1
- package/dist/lib/work-lifecycle/hooks/executor.d.ts +22 -2
- package/dist/lib/work-lifecycle/hooks/executor.js +46 -8
- package/dist/lib/work-lifecycle/hooks/executor.js.map +1 -1
- package/dist/lib/work-lifecycle/hooks/manager.d.ts +62 -3
- package/dist/lib/work-lifecycle/hooks/manager.js +285 -4
- package/dist/lib/work-lifecycle/hooks/manager.js.map +1 -1
- package/dist/lib/work-lifecycle/hooks/types.d.ts +36 -5
- package/dist/lib/work-lifecycle/hooks/types.js +1 -1
- package/dist/lib/work-lifecycle/hooks/types.js.map +1 -1
- package/dist/lib/workspace-resolution.d.ts +73 -0
- package/dist/lib/workspace-resolution.js +188 -0
- package/dist/lib/workspace-resolution.js.map +1 -0
- package/oclif.manifest.json +2830 -2142
- package/package.json +1 -1
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Machine Orchestrator — Prompt builder and state reader for machine-level orchestration.
|
|
3
|
+
*
|
|
4
|
+
* The machine orchestrator is the root-level supervisor. It reads machine.db
|
|
5
|
+
* to see ALL sessions across ALL repos on the machine, and can spawn, poke,
|
|
6
|
+
* kill, and ship agents in any repo.
|
|
7
|
+
*
|
|
8
|
+
* Unlike HQ-scoped orchestrators (which read workspace.db and see only one project),
|
|
9
|
+
* the machine orchestrator operates at the machine level — it's the `init` process
|
|
10
|
+
* for your development fleet.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Read the current machine state from machine.db.
|
|
14
|
+
*/
|
|
15
|
+
export function readMachineState(db) {
|
|
16
|
+
const activeExecutions = db.getActiveExecutions();
|
|
17
|
+
const persistentAgents = db.listPersistentAgents();
|
|
18
|
+
const diedPersistentAgents = db.getDiedPersistentAgents();
|
|
19
|
+
const recentCompleted = db.listExecutions({ status: 'completed', limit: 10 });
|
|
20
|
+
const activeRepos = [...new Set(activeExecutions.map(e => e.repoPath))];
|
|
21
|
+
return {
|
|
22
|
+
activeExecutions,
|
|
23
|
+
persistentAgents,
|
|
24
|
+
diedPersistentAgents,
|
|
25
|
+
recentCompleted,
|
|
26
|
+
activeRepos,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
// =============================================================================
|
|
30
|
+
// Prompt Builder
|
|
31
|
+
// =============================================================================
|
|
32
|
+
/**
|
|
33
|
+
* Build the system prompt for the machine-level orchestrator.
|
|
34
|
+
*
|
|
35
|
+
* This prompt gives the orchestrator visibility into all agents across all repos
|
|
36
|
+
* and the commands to manage them.
|
|
37
|
+
*/
|
|
38
|
+
export function buildMachineOrchestratorPrompt(state, actionPrompt) {
|
|
39
|
+
let prompt = '';
|
|
40
|
+
// ─── Identity ──────────────────────────────────────────────
|
|
41
|
+
prompt += `# Machine Orchestrator\n\n`;
|
|
42
|
+
prompt += `You are the **machine-level orchestrator** — the root supervisor for all AI agents across every repository on this machine.\n\n`;
|
|
43
|
+
prompt += `Unlike HQ-scoped orchestrators (which manage one project), you see and control **all agents, all repos, all sessions**. `;
|
|
44
|
+
prompt += `You are the \`init\` process for the development fleet.\n\n`;
|
|
45
|
+
// ��── Capabilities ──────────────────────────────────────────
|
|
46
|
+
prompt += `## Your Role\n\n`;
|
|
47
|
+
prompt += `- **Spawn** agents in any repo: \`prlt work run --dir /path/to/repo --prompt "task"\`\n`;
|
|
48
|
+
prompt += `- **Monitor** all sessions: \`prlt session list\` (reads machine.db, works from anywhere)\n`;
|
|
49
|
+
prompt += `- **Poke** running agents: \`prlt session poke <session-id> "message"\`\n`;
|
|
50
|
+
prompt += `- **Stop** agents: \`prlt work stop <execution-id>\`\n`;
|
|
51
|
+
prompt += `- **Restart** died persistent agents: \`prlt work run --name <name> --keep-alive --prompt "..."\`\n`;
|
|
52
|
+
prompt += `- **Ship** completed work: \`prlt work ship <ticket-id>\` (when inside an HQ)\n`;
|
|
53
|
+
prompt += `- **Spawn persistent agents**: \`prlt work run --name reviewer --keep-alive --prompt "..."\`\n\n`;
|
|
54
|
+
// ─── Current State ─────────────────────────────────────────
|
|
55
|
+
prompt += `## Current Machine State\n\n`;
|
|
56
|
+
if (state.activeExecutions.length === 0 && state.persistentAgents.length === 0) {
|
|
57
|
+
prompt += `No active agents. The machine is idle.\n\n`;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
// Active executions
|
|
61
|
+
if (state.activeExecutions.length > 0) {
|
|
62
|
+
prompt += `### Active Agents (${state.activeExecutions.length})\n\n`;
|
|
63
|
+
prompt += `| ID | Agent | Status | Repo | Prompt |\n`;
|
|
64
|
+
prompt += `|----|-------|--------|------|--------|\n`;
|
|
65
|
+
for (const exec of state.activeExecutions) {
|
|
66
|
+
const repoShort = exec.repoPath.split('/').slice(-2).join('/');
|
|
67
|
+
const promptShort = exec.prompt.substring(0, 40) + (exec.prompt.length > 40 ? '...' : '');
|
|
68
|
+
const persistent = exec.persistent ? ' (persistent)' : '';
|
|
69
|
+
prompt += `| ${exec.id} | ${exec.agentName}${persistent} | ${exec.status} | ${repoShort} | ${promptShort} |\n`;
|
|
70
|
+
}
|
|
71
|
+
prompt += `\n`;
|
|
72
|
+
}
|
|
73
|
+
// Persistent agents (all statuses)
|
|
74
|
+
const stoppedPersistent = state.persistentAgents.filter(a => a.status !== 'running' && a.status !== 'starting');
|
|
75
|
+
if (stoppedPersistent.length > 0) {
|
|
76
|
+
prompt += `### Stopped Persistent Agents (restart candidates)\n\n`;
|
|
77
|
+
for (const agent of stoppedPersistent) {
|
|
78
|
+
prompt += `- **${agent.agentName}** (${agent.id}): ${agent.status}`;
|
|
79
|
+
if (agent.errorMessage)
|
|
80
|
+
prompt += ` — ${agent.errorMessage}`;
|
|
81
|
+
prompt += `\n`;
|
|
82
|
+
}
|
|
83
|
+
prompt += `\n`;
|
|
84
|
+
}
|
|
85
|
+
// Died persistent agents
|
|
86
|
+
if (state.diedPersistentAgents.length > 0) {
|
|
87
|
+
prompt += `### Died Persistent Agents (need restart)\n\n`;
|
|
88
|
+
for (const agent of state.diedPersistentAgents) {
|
|
89
|
+
const repoShort = agent.repoPath.split('/').slice(-2).join('/');
|
|
90
|
+
prompt += `- **${agent.agentName}** in ${repoShort}: ${agent.errorMessage || 'died'}\n`;
|
|
91
|
+
prompt += ` Restart: \`prlt work run --name ${agent.agentName} --keep-alive --dir ${agent.repoPath} --prompt "${agent.prompt.substring(0, 60)}"\`\n`;
|
|
92
|
+
}
|
|
93
|
+
prompt += `\n`;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// Active repos
|
|
97
|
+
if (state.activeRepos.length > 0) {
|
|
98
|
+
prompt += `### Active Repos\n\n`;
|
|
99
|
+
for (const repo of state.activeRepos) {
|
|
100
|
+
const agentCount = state.activeExecutions.filter(e => e.repoPath === repo).length;
|
|
101
|
+
prompt += `- \`${repo}\` (${agentCount} agent${agentCount !== 1 ? 's' : ''})\n`;
|
|
102
|
+
}
|
|
103
|
+
prompt += `\n`;
|
|
104
|
+
}
|
|
105
|
+
// Recent history
|
|
106
|
+
if (state.recentCompleted.length > 0) {
|
|
107
|
+
prompt += `### Recent Completions\n\n`;
|
|
108
|
+
for (const exec of state.recentCompleted.slice(0, 5)) {
|
|
109
|
+
const repoShort = exec.repoPath.split('/').slice(-2).join('/');
|
|
110
|
+
const exitInfo = exec.exitCode !== undefined ? ` (exit ${exec.exitCode})` : '';
|
|
111
|
+
prompt += `- ${exec.agentName} in ${repoShort}: "${exec.prompt.substring(0, 50)}"${exitInfo}\n`;
|
|
112
|
+
}
|
|
113
|
+
prompt += `\n`;
|
|
114
|
+
}
|
|
115
|
+
// ─── Command Reference ─────────────────────────────────────
|
|
116
|
+
prompt += `## Command Reference\n\n`;
|
|
117
|
+
prompt += `### Agent Lifecycle\n`;
|
|
118
|
+
prompt += `| Command | Description |\n`;
|
|
119
|
+
prompt += `|---------|-------------|\n`;
|
|
120
|
+
prompt += `| \`prlt work run --prompt "..." --dir /repo\` | Spawn ephemeral agent in a repo |\n`;
|
|
121
|
+
prompt += `| \`prlt work run --name X --keep-alive --prompt "..."\` | Spawn persistent named agent |\n`;
|
|
122
|
+
prompt += `| \`prlt session list\` | List all sessions (machine-wide) |\n`;
|
|
123
|
+
prompt += `| \`prlt session attach <id>\` | Attach to agent session |\n`;
|
|
124
|
+
prompt += `| \`prlt session poke <id> "msg"\` | Send message to running agent |\n`;
|
|
125
|
+
prompt += `| \`prlt session peek <id>\` | View agent output without attaching |\n`;
|
|
126
|
+
prompt += `| \`prlt work stop <id>\` | Stop a running agent |\n`;
|
|
127
|
+
prompt += `| \`prlt session prune\` | Clean up stale sessions |\n\n`;
|
|
128
|
+
prompt += `### Anti-patterns\n\n`;
|
|
129
|
+
prompt += `- **NEVER** use \`docker exec\` or \`tmux send-keys\` directly — use \`prlt session poke\`\n`;
|
|
130
|
+
prompt += `- **NEVER** use \`gh pr create\` — use \`prlt work propose\` or \`prlt pr create\`\n`;
|
|
131
|
+
prompt += `- **NEVER** kill tmux sessions directly — use \`prlt work stop\`\n`;
|
|
132
|
+
prompt += `- **NEVER** write code yourself — you are a supervisor, delegate to agents\n\n`;
|
|
133
|
+
// ─── Action prompt ─────────────────────────────────────────
|
|
134
|
+
if (actionPrompt) {
|
|
135
|
+
prompt += `## Instructions\n\n${actionPrompt}\n`;
|
|
136
|
+
}
|
|
137
|
+
return prompt;
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=machine-orchestrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"machine-orchestrator.js","sourceRoot":"","sources":["../../src/lib/machine-orchestrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAqBH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AI,6FAA6F,CAAA;IACvG,MAAM,IAAI,gEAAgE,CAAA;IAC1E,MAAM,IAAI,8DAA8D,CAAA;IACxE,MAAM,IAAI,wEAAwE,CAAA;IAClF,MAAM,IAAI,wEAAwE,CAAA;IAClF,MAAM,IAAI,sDAAsD,CAAA;IAChE,MAAM,IAAI,0DAA0D,CAAA;IAEpE,MAAM,IAAI,uBAAuB,CAAA;IACjC,MAAM,IAAI,8FAA8F,CAAA;IACxG,MAAM,IAAI,sFAAsF,CAAA;IAChG,MAAM,IAAI,oEAAoE,CAAA;IAC9E,MAAM,IAAI,gFAAgF,CAAA;IAE1F,8DAA8D;IAC9D,IAAI,YAAY,EAAE,CAAC;QACjB,MAAM,IAAI,sBAAsB,YAAY,IAAI,CAAA;IAClD,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Notification Dispatcher
|
|
3
|
+
*
|
|
4
|
+
* Sends notifications through configured providers. Each provider type
|
|
5
|
+
* has a handler that formats and delivers the message.
|
|
6
|
+
*
|
|
7
|
+
* Handlers:
|
|
8
|
+
* - slack: POST to webhook URL
|
|
9
|
+
* - email: POST to SendGrid API
|
|
10
|
+
* - sms: POST to Twilio API
|
|
11
|
+
* - terminal: Write to stdout
|
|
12
|
+
* - browser_push: Placeholder (for prlt web dashboard)
|
|
13
|
+
*/
|
|
14
|
+
import type { NotificationProvider, NotificationContext, NotificationResult } from './types.js';
|
|
15
|
+
declare function buildMessage(context: NotificationContext): string;
|
|
16
|
+
/**
|
|
17
|
+
* Send a notification through a configured provider.
|
|
18
|
+
*/
|
|
19
|
+
export declare function dispatchNotification(provider: NotificationProvider, context: NotificationContext): Promise<NotificationResult>;
|
|
20
|
+
/**
|
|
21
|
+
* Send notifications through multiple providers.
|
|
22
|
+
* Returns results for all providers (does not short-circuit on failure).
|
|
23
|
+
*/
|
|
24
|
+
export declare function dispatchNotifications(providers: NotificationProvider[], context: NotificationContext): Promise<NotificationResult[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Build a human-readable notification message from context.
|
|
27
|
+
* Exported for testing and reuse.
|
|
28
|
+
*/
|
|
29
|
+
export { buildMessage };
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Notification Dispatcher
|
|
3
|
+
*
|
|
4
|
+
* Sends notifications through configured providers. Each provider type
|
|
5
|
+
* has a handler that formats and delivers the message.
|
|
6
|
+
*
|
|
7
|
+
* Handlers:
|
|
8
|
+
* - slack: POST to webhook URL
|
|
9
|
+
* - email: POST to SendGrid API
|
|
10
|
+
* - sms: POST to Twilio API
|
|
11
|
+
* - terminal: Write to stdout
|
|
12
|
+
* - browser_push: Placeholder (for prlt web dashboard)
|
|
13
|
+
*/
|
|
14
|
+
// =============================================================================
|
|
15
|
+
// Handlers
|
|
16
|
+
// =============================================================================
|
|
17
|
+
function buildMessage(context) {
|
|
18
|
+
const parts = [];
|
|
19
|
+
if (context.event)
|
|
20
|
+
parts.push(`[${context.event}]`);
|
|
21
|
+
if (context.ticket)
|
|
22
|
+
parts.push(`ticket=${context.ticket}`);
|
|
23
|
+
if (context.pr)
|
|
24
|
+
parts.push(`PR=#${context.pr}`);
|
|
25
|
+
if (context.agent)
|
|
26
|
+
parts.push(`agent=${context.agent}`);
|
|
27
|
+
if (context.branch)
|
|
28
|
+
parts.push(`branch=${context.branch}`);
|
|
29
|
+
if (context.message)
|
|
30
|
+
parts.push(context.message);
|
|
31
|
+
return parts.join(' ') || 'Notification';
|
|
32
|
+
}
|
|
33
|
+
const handleSlack = async (provider, context) => {
|
|
34
|
+
const start = Date.now();
|
|
35
|
+
const config = provider.config;
|
|
36
|
+
if (!config.webhook_url) {
|
|
37
|
+
return {
|
|
38
|
+
providerId: provider.id,
|
|
39
|
+
providerName: provider.name,
|
|
40
|
+
providerType: provider.type,
|
|
41
|
+
success: false,
|
|
42
|
+
error: 'No webhook_url configured',
|
|
43
|
+
durationMs: Date.now() - start,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
const message = buildMessage(context);
|
|
48
|
+
const payload = {
|
|
49
|
+
text: message,
|
|
50
|
+
...(config.channel ? { channel: config.channel } : {}),
|
|
51
|
+
...(config.username ? { username: config.username } : {}),
|
|
52
|
+
};
|
|
53
|
+
const response = await fetch(config.webhook_url, {
|
|
54
|
+
method: 'POST',
|
|
55
|
+
headers: { 'Content-Type': 'application/json' },
|
|
56
|
+
body: JSON.stringify(payload),
|
|
57
|
+
signal: AbortSignal.timeout(10_000),
|
|
58
|
+
});
|
|
59
|
+
if (!response.ok) {
|
|
60
|
+
return {
|
|
61
|
+
providerId: provider.id,
|
|
62
|
+
providerName: provider.name,
|
|
63
|
+
providerType: provider.type,
|
|
64
|
+
success: false,
|
|
65
|
+
error: `Slack webhook returned ${response.status}: ${await response.text()}`,
|
|
66
|
+
durationMs: Date.now() - start,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
providerId: provider.id,
|
|
71
|
+
providerName: provider.name,
|
|
72
|
+
providerType: provider.type,
|
|
73
|
+
success: true,
|
|
74
|
+
durationMs: Date.now() - start,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
return {
|
|
79
|
+
providerId: provider.id,
|
|
80
|
+
providerName: provider.name,
|
|
81
|
+
providerType: provider.type,
|
|
82
|
+
success: false,
|
|
83
|
+
error: err instanceof Error ? err.message : String(err),
|
|
84
|
+
durationMs: Date.now() - start,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const handleEmail = async (provider, context) => {
|
|
89
|
+
const start = Date.now();
|
|
90
|
+
const config = provider.config;
|
|
91
|
+
if (!config.api_key || !config.from || !config.to?.length) {
|
|
92
|
+
return {
|
|
93
|
+
providerId: provider.id,
|
|
94
|
+
providerName: provider.name,
|
|
95
|
+
providerType: provider.type,
|
|
96
|
+
success: false,
|
|
97
|
+
error: 'Email provider requires api_key, from, and to fields',
|
|
98
|
+
durationMs: Date.now() - start,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
const message = buildMessage(context);
|
|
103
|
+
const subject = `[prlt] ${context.event || 'Notification'}`;
|
|
104
|
+
if (config.provider === 'sendgrid') {
|
|
105
|
+
const payload = {
|
|
106
|
+
personalizations: [{ to: config.to.map(email => ({ email })) }],
|
|
107
|
+
from: { email: config.from },
|
|
108
|
+
subject,
|
|
109
|
+
content: [{ type: 'text/plain', value: message }],
|
|
110
|
+
};
|
|
111
|
+
const response = await fetch('https://api.sendgrid.com/v3/mail/send', {
|
|
112
|
+
method: 'POST',
|
|
113
|
+
headers: {
|
|
114
|
+
'Content-Type': 'application/json',
|
|
115
|
+
Authorization: `Bearer ${config.api_key}`,
|
|
116
|
+
},
|
|
117
|
+
body: JSON.stringify(payload),
|
|
118
|
+
signal: AbortSignal.timeout(10_000),
|
|
119
|
+
});
|
|
120
|
+
if (!response.ok) {
|
|
121
|
+
return {
|
|
122
|
+
providerId: provider.id,
|
|
123
|
+
providerName: provider.name,
|
|
124
|
+
providerType: provider.type,
|
|
125
|
+
success: false,
|
|
126
|
+
error: `SendGrid returned ${response.status}`,
|
|
127
|
+
durationMs: Date.now() - start,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
// SES — use AWS SDK-compatible HTTP call
|
|
133
|
+
// For now, log that SES requires aws-sdk and is not yet fully wired
|
|
134
|
+
return {
|
|
135
|
+
providerId: provider.id,
|
|
136
|
+
providerName: provider.name,
|
|
137
|
+
providerType: provider.type,
|
|
138
|
+
success: false,
|
|
139
|
+
error: 'SES provider requires AWS SDK — use SendGrid for now',
|
|
140
|
+
durationMs: Date.now() - start,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
providerId: provider.id,
|
|
145
|
+
providerName: provider.name,
|
|
146
|
+
providerType: provider.type,
|
|
147
|
+
success: true,
|
|
148
|
+
durationMs: Date.now() - start,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
catch (err) {
|
|
152
|
+
return {
|
|
153
|
+
providerId: provider.id,
|
|
154
|
+
providerName: provider.name,
|
|
155
|
+
providerType: provider.type,
|
|
156
|
+
success: false,
|
|
157
|
+
error: err instanceof Error ? err.message : String(err),
|
|
158
|
+
durationMs: Date.now() - start,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
const handleSms = async (provider, context) => {
|
|
163
|
+
const start = Date.now();
|
|
164
|
+
const config = provider.config;
|
|
165
|
+
if (!config.account_sid || !config.auth_token || !config.from || !config.to?.length) {
|
|
166
|
+
return {
|
|
167
|
+
providerId: provider.id,
|
|
168
|
+
providerName: provider.name,
|
|
169
|
+
providerType: provider.type,
|
|
170
|
+
success: false,
|
|
171
|
+
error: 'SMS provider requires account_sid, auth_token, from, and to fields',
|
|
172
|
+
durationMs: Date.now() - start,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
try {
|
|
176
|
+
const message = buildMessage(context);
|
|
177
|
+
const results = [];
|
|
178
|
+
for (const to of config.to) {
|
|
179
|
+
const body = new URLSearchParams({ Body: message, From: config.from, To: to });
|
|
180
|
+
const response = await fetch(`https://api.twilio.com/2010-04-01/Accounts/${config.account_sid}/Messages.json`, {
|
|
181
|
+
method: 'POST',
|
|
182
|
+
headers: {
|
|
183
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
184
|
+
Authorization: `Basic ${Buffer.from(`${config.account_sid}:${config.auth_token}`).toString('base64')}`,
|
|
185
|
+
},
|
|
186
|
+
body: body.toString(),
|
|
187
|
+
signal: AbortSignal.timeout(10_000),
|
|
188
|
+
});
|
|
189
|
+
results.push(response.ok);
|
|
190
|
+
}
|
|
191
|
+
const allOk = results.every(Boolean);
|
|
192
|
+
return {
|
|
193
|
+
providerId: provider.id,
|
|
194
|
+
providerName: provider.name,
|
|
195
|
+
providerType: provider.type,
|
|
196
|
+
success: allOk,
|
|
197
|
+
error: allOk ? undefined : `Some SMS messages failed to send`,
|
|
198
|
+
durationMs: Date.now() - start,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
catch (err) {
|
|
202
|
+
return {
|
|
203
|
+
providerId: provider.id,
|
|
204
|
+
providerName: provider.name,
|
|
205
|
+
providerType: provider.type,
|
|
206
|
+
success: false,
|
|
207
|
+
error: err instanceof Error ? err.message : String(err),
|
|
208
|
+
durationMs: Date.now() - start,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
const handleTerminal = async (provider, context) => {
|
|
213
|
+
const start = Date.now();
|
|
214
|
+
const config = provider.config;
|
|
215
|
+
const prefix = config.prefix || '[prlt:notify]';
|
|
216
|
+
const message = buildMessage(context);
|
|
217
|
+
// eslint-disable-next-line no-console
|
|
218
|
+
console.log(`${prefix} ${message}`);
|
|
219
|
+
return {
|
|
220
|
+
providerId: provider.id,
|
|
221
|
+
providerName: provider.name,
|
|
222
|
+
providerType: provider.type,
|
|
223
|
+
success: true,
|
|
224
|
+
durationMs: Date.now() - start,
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
const handleBrowserPush = async (provider, _context) => {
|
|
228
|
+
const start = Date.now();
|
|
229
|
+
// Browser push requires the prlt web dashboard to be running.
|
|
230
|
+
// This is a placeholder that succeeds silently when no endpoint is configured.
|
|
231
|
+
return {
|
|
232
|
+
providerId: provider.id,
|
|
233
|
+
providerName: provider.name,
|
|
234
|
+
providerType: provider.type,
|
|
235
|
+
success: true,
|
|
236
|
+
durationMs: Date.now() - start,
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
// =============================================================================
|
|
240
|
+
// Handler Registry
|
|
241
|
+
// =============================================================================
|
|
242
|
+
const HANDLERS = {
|
|
243
|
+
slack: handleSlack,
|
|
244
|
+
email: handleEmail,
|
|
245
|
+
sms: handleSms,
|
|
246
|
+
terminal: handleTerminal,
|
|
247
|
+
browser_push: handleBrowserPush,
|
|
248
|
+
};
|
|
249
|
+
// =============================================================================
|
|
250
|
+
// Dispatcher
|
|
251
|
+
// =============================================================================
|
|
252
|
+
/**
|
|
253
|
+
* Send a notification through a configured provider.
|
|
254
|
+
*/
|
|
255
|
+
export async function dispatchNotification(provider, context) {
|
|
256
|
+
const handler = HANDLERS[provider.type];
|
|
257
|
+
if (!handler) {
|
|
258
|
+
return {
|
|
259
|
+
providerId: provider.id,
|
|
260
|
+
providerName: provider.name,
|
|
261
|
+
providerType: provider.type,
|
|
262
|
+
success: false,
|
|
263
|
+
error: `Unknown provider type: ${provider.type}`,
|
|
264
|
+
durationMs: 0,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
return handler(provider, context);
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Send notifications through multiple providers.
|
|
271
|
+
* Returns results for all providers (does not short-circuit on failure).
|
|
272
|
+
*/
|
|
273
|
+
export async function dispatchNotifications(providers, context) {
|
|
274
|
+
return Promise.all(providers.map(p => dispatchNotification(p, context)));
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Build a human-readable notification message from context.
|
|
278
|
+
* Exported for testing and reuse.
|
|
279
|
+
*/
|
|
280
|
+
export { buildMessage };
|
|
281
|
+
//# sourceMappingURL=dispatcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatcher.js","sourceRoot":"","sources":["../../../src/lib/notifications/dispatcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAsBH,gFAAgF;AAChF,WAAW;AACX,gFAAgF;AAEhF,SAAS,YAAY,CAAC,OAA4B;IAChD,MAAM,KAAK,GAAa,EAAE,CAAA;IAC1B,IAAI,OAAO,CAAC,KAAK;QAAE,KAAK,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,KAAK,GAAG,CAAC,CAAA;IACnD,IAAI,OAAO,CAAC,MAAM;QAAE,K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AAE,cAAc;IACxB,YAAY,EAAE,iBAAiB;CAChC,CAAA;AAED,gFAAgF;AAChF,aAAa;AACb,gFAAgF;AAEhF;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,QAA8B,EAC9B,OAA4B;IAE5B,MAAM,OAAO,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IACvC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO;YACL,UAAU,EAAE,QAAQ,CAAC,EAAE;YACvB,YAAY,EAAE,QAAQ,CAAC,IAAI;YAC3B,YAAY,EAAE,QAAQ,CAAC,IAAI;YAC3B,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,0BAA0B,QAAQ,CAAC,IAAI,EAAE;YAChD,UAAU,EAAE,CAAC;SACd,CAAA;IACH,CAAC;IACD,OAAO,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;AACnC,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,SAAiC,EACjC,OAA4B;IAE5B,OAAO,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,oBAAoB,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;AAC1E,CAAC;AAED;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Notification Layer
|
|
3
|
+
*
|
|
4
|
+
* Outbound notification system for daemon events, hook actions, and escalations.
|
|
5
|
+
*
|
|
6
|
+
* Providers: Slack, Email (SendGrid/SES), SMS (Twilio), Terminal, Browser Push
|
|
7
|
+
* Escalation: Configurable timeout-based escalation chains
|
|
8
|
+
* Storage: Workspace DB (not YAML), shareable across machines
|
|
9
|
+
*/
|
|
10
|
+
export { type NotificationProviderType, type NotificationProvider, type NotificationRule, type NotificationContext, type NotificationResult, type ProviderConfig, type SlackProviderConfig, type EmailProviderConfig, type SmsProviderConfig, type TerminalProviderConfig, type BrowserPushProviderConfig, type NotificationEvent, type EscalationStep, type ActiveEscalation, NOTIFICATION_PROVIDER_TYPES, } from './types.js';
|
|
11
|
+
export { NotificationStorage } from './storage.js';
|
|
12
|
+
export { dispatchNotification, dispatchNotifications, buildMessage, } from './dispatcher.js';
|
|
13
|
+
export { NotificationManager, type NotificationManagerOptions, initNotificationManager, getNotificationManager, stopNotificationManager, } from './manager.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Notification Layer
|
|
3
|
+
*
|
|
4
|
+
* Outbound notification system for daemon events, hook actions, and escalations.
|
|
5
|
+
*
|
|
6
|
+
* Providers: Slack, Email (SendGrid/SES), SMS (Twilio), Terminal, Browser Push
|
|
7
|
+
* Escalation: Configurable timeout-based escalation chains
|
|
8
|
+
* Storage: Workspace DB (not YAML), shareable across machines
|
|
9
|
+
*/
|
|
10
|
+
// Types
|
|
11
|
+
export { NOTIFICATION_PROVIDER_TYPES, } from './types.js';
|
|
12
|
+
// Storage
|
|
13
|
+
export { NotificationStorage } from './storage.js';
|
|
14
|
+
// Dispatcher
|
|
15
|
+
export { dispatchNotification, dispatchNotifications, buildMessage, } from './dispatcher.js';
|
|
16
|
+
// Manager
|
|
17
|
+
export { NotificationManager, initNotificationManager, getNotificationManager, stopNotificationManager, } from './manager.js';
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/notifications/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,QAAQ;AACR,OAAO,EAeL,2BAA2B,GAC5B,MAAM,YAAY,CAAA;AAEnB,UAAU;AACV,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAElD,aAAa;AACb,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,YAAY,GACb,MAAM,iBAAiB,CAAA;AAExB,UAAU;AACV,OAAO,EACL,mBAAmB,EAEnB,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Notification Manager
|
|
3
|
+
*
|
|
4
|
+
* Integrates with the EventBus and hook system to dispatch notifications.
|
|
5
|
+
* Subscribes to hookable events, looks up notification rules, and dispatches
|
|
6
|
+
* through configured providers. Manages escalation chains with timeout-based
|
|
7
|
+
* escalation (e.g., Slack first, SMS after 10min, email after 30min).
|
|
8
|
+
*/
|
|
9
|
+
import type Database from 'better-sqlite3';
|
|
10
|
+
import type { NotificationContext, NotificationResult, ActiveEscalation } from './types.js';
|
|
11
|
+
export interface NotificationManagerOptions {
|
|
12
|
+
db: Database.Database;
|
|
13
|
+
log?: (msg: string) => void;
|
|
14
|
+
}
|
|
15
|
+
export declare class NotificationManager {
|
|
16
|
+
private storage;
|
|
17
|
+
private log;
|
|
18
|
+
private unsubscribers;
|
|
19
|
+
private activeEscalations;
|
|
20
|
+
constructor(options: NotificationManagerOptions);
|
|
21
|
+
/**
|
|
22
|
+
* Start listening to events on the EventBus.
|
|
23
|
+
* Dynamically imports event-bus to avoid circular dependency at module load.
|
|
24
|
+
*/
|
|
25
|
+
start(): Promise<void>;
|
|
26
|
+
/** Stop listening and clear all escalation timers. */
|
|
27
|
+
stop(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Manually fire a notification for an event.
|
|
30
|
+
* Returns results for all matched rules.
|
|
31
|
+
*/
|
|
32
|
+
fireEvent(event: string, context: NotificationContext): Promise<NotificationResult[]>;
|
|
33
|
+
/**
|
|
34
|
+
* Acknowledge an escalation chain (stops further escalation).
|
|
35
|
+
*/
|
|
36
|
+
acknowledgeEscalation(group: string): boolean;
|
|
37
|
+
/** Get active escalation chains. */
|
|
38
|
+
getActiveEscalations(): ActiveEscalation[];
|
|
39
|
+
private handleEvent;
|
|
40
|
+
private startEscalationChain;
|
|
41
|
+
private executeEscalationStep;
|
|
42
|
+
private normalizeContext;
|
|
43
|
+
}
|
|
44
|
+
export declare function initNotificationManager(options: NotificationManagerOptions): NotificationManager;
|
|
45
|
+
export declare function getNotificationManager(): NotificationManager | null;
|
|
46
|
+
export declare function stopNotificationManager(): void;
|