MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / installWorkflowNotifications

Function installWorkflowNotifications

src/workflow/notifications.ts:41–69  ·  view source on GitHub ↗
(
  service: WorkflowService,
  notify: WorkflowNotifier = defaultNotifier,
)

Source from the content-addressed store, hash-verified

39}
40
41export function installWorkflowNotifications(
42 service: WorkflowService,
43 notify: WorkflowNotifier = defaultNotifier,
44): () => void {
45 const prevStatus = new Map<string, RunProgress['status'] | undefined>()
46
47 const unsubscribe = service.subscribe(() => {
48 const runs = service.listRuns()
49 for (const run of runs) {
50 const prev = prevStatus.get(run.runId)
51 // First time seeing this run: just record the current status without notifying
52 // (avoids treating existing historical runs as new notifications on install)
53 if (prev === undefined) {
54 prevStatus.set(run.runId, run.status)
55 continue
56 }
57 // Status changed + entered terminal state → emit notification
58 if (prev !== run.status && TERMINAL_STATUSES.has(run.status)) {
59 notify(buildMessage(run))
60 }
61 prevStatus.set(run.runId, run.status)
62 }
63 })
64
65 return () => {
66 unsubscribe()
67 prevStatus.clear()
68 }
69}
70
71function buildMessage(run: RunProgress): string {
72 const statusText =

Callers 2

getWorkflowServiceFunction · 0.85

Calls 7

buildMessageFunction · 0.85
setMethod · 0.80
getMethod · 0.65
notifyFunction · 0.50
subscribeMethod · 0.45
hasMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected