opencastle 1.12.7 → 1.12.9

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 (82) hide show
  1. package/dist/cli/convoy/crash-status.test.js +1 -1
  2. package/dist/cli/convoy/crash-status.test.js.map +1 -1
  3. package/dist/cli/convoy/engine.d.ts +3 -1
  4. package/dist/cli/convoy/engine.d.ts.map +1 -1
  5. package/dist/cli/convoy/engine.git.test.js +180 -3
  6. package/dist/cli/convoy/engine.git.test.js.map +1 -1
  7. package/dist/cli/convoy/engine.js +144 -16
  8. package/dist/cli/convoy/engine.js.map +1 -1
  9. package/dist/cli/convoy/engine.test.js +27 -1
  10. package/dist/cli/convoy/engine.test.js.map +1 -1
  11. package/dist/cli/convoy/event-schemas.d.ts.map +1 -1
  12. package/dist/cli/convoy/event-schemas.js +1 -0
  13. package/dist/cli/convoy/event-schemas.js.map +1 -1
  14. package/dist/cli/convoy/hangup.test.d.ts +2 -0
  15. package/dist/cli/convoy/hangup.test.d.ts.map +1 -0
  16. package/dist/cli/convoy/hangup.test.js +124 -0
  17. package/dist/cli/convoy/hangup.test.js.map +1 -0
  18. package/dist/cli/convoy/ledger-paths.test.js +1 -1
  19. package/dist/cli/convoy/ledger-paths.test.js.map +1 -1
  20. package/dist/cli/convoy/lock.d.ts.map +1 -1
  21. package/dist/cli/convoy/lock.js +28 -13
  22. package/dist/cli/convoy/lock.js.map +1 -1
  23. package/dist/cli/convoy/lock.test.js +44 -2
  24. package/dist/cli/convoy/lock.test.js.map +1 -1
  25. package/dist/cli/convoy/merge.d.ts +2 -0
  26. package/dist/cli/convoy/merge.d.ts.map +1 -1
  27. package/dist/cli/convoy/merge.js +4 -2
  28. package/dist/cli/convoy/merge.js.map +1 -1
  29. package/dist/cli/convoy/merge.test.js +14 -4
  30. package/dist/cli/convoy/merge.test.js.map +1 -1
  31. package/dist/cli/convoy/partition.d.ts +12 -6
  32. package/dist/cli/convoy/partition.d.ts.map +1 -1
  33. package/dist/cli/convoy/partition.js +76 -48
  34. package/dist/cli/convoy/partition.js.map +1 -1
  35. package/dist/cli/convoy/partition.symlinks.test.d.ts +2 -0
  36. package/dist/cli/convoy/partition.symlinks.test.d.ts.map +1 -0
  37. package/dist/cli/convoy/partition.symlinks.test.js +71 -0
  38. package/dist/cli/convoy/partition.symlinks.test.js.map +1 -0
  39. package/dist/cli/convoy/partition.test.js +2 -1
  40. package/dist/cli/convoy/partition.test.js.map +1 -1
  41. package/dist/cli/convoy/store.d.ts +1 -1
  42. package/dist/cli/convoy/store.d.ts.map +1 -1
  43. package/dist/cli/convoy/store.js +13 -2
  44. package/dist/cli/convoy/store.js.map +1 -1
  45. package/dist/cli/convoy/store.test.js +11 -11
  46. package/dist/cli/convoy/types.d.ts +9 -1
  47. package/dist/cli/convoy/types.d.ts.map +1 -1
  48. package/dist/cli/convoy/types.js.map +1 -1
  49. package/dist/cli/convoy/worktree.d.ts +2 -0
  50. package/dist/cli/convoy/worktree.d.ts.map +1 -1
  51. package/dist/cli/convoy/worktree.js +15 -3
  52. package/dist/cli/convoy/worktree.js.map +1 -1
  53. package/dist/cli/convoy/worktree.test.js +22 -1
  54. package/dist/cli/convoy/worktree.test.js.map +1 -1
  55. package/dist/cli/run/adapters/agent-process.d.ts.map +1 -1
  56. package/dist/cli/run/adapters/agent-process.js +58 -12
  57. package/dist/cli/run/adapters/agent-process.js.map +1 -1
  58. package/dist/cli/run/adapters/agent-process.test.js +59 -0
  59. package/dist/cli/run/adapters/agent-process.test.js.map +1 -1
  60. package/package.json +1 -1
  61. package/src/cli/convoy/TELEMETRY.md +3 -3
  62. package/src/cli/convoy/crash-status.test.ts +1 -1
  63. package/src/cli/convoy/engine.git.test.ts +197 -3
  64. package/src/cli/convoy/engine.test.ts +29 -1
  65. package/src/cli/convoy/engine.ts +146 -19
  66. package/src/cli/convoy/event-schemas.ts +1 -0
  67. package/src/cli/convoy/hangup.test.ts +126 -0
  68. package/src/cli/convoy/ledger-paths.test.ts +1 -1
  69. package/src/cli/convoy/lock.test.ts +63 -2
  70. package/src/cli/convoy/lock.ts +29 -13
  71. package/src/cli/convoy/merge.test.ts +17 -4
  72. package/src/cli/convoy/merge.ts +6 -2
  73. package/src/cli/convoy/partition.symlinks.test.ts +82 -0
  74. package/src/cli/convoy/partition.test.ts +2 -1
  75. package/src/cli/convoy/partition.ts +68 -55
  76. package/src/cli/convoy/store.test.ts +11 -11
  77. package/src/cli/convoy/store.ts +14 -3
  78. package/src/cli/convoy/types.ts +9 -1
  79. package/src/cli/convoy/worktree.test.ts +24 -1
  80. package/src/cli/convoy/worktree.ts +17 -3
  81. package/src/cli/run/adapters/agent-process.test.ts +59 -0
  82. package/src/cli/run/adapters/agent-process.ts +56 -10
@@ -57,20 +57,65 @@ const onStop = new WeakMap<ChildProcess, () => void>()
57
57
  const stoppedProcs = new WeakSet<ChildProcess>()
58
58
  let exitHookInstalled = false
59
59
 
60
+ /**
61
+ * The signals whose default action ends this process. Closing the terminal
62
+ * sends SIGHUP, Ctrl+C sends SIGINT, and `kill` sends SIGTERM.
63
+ */
64
+ const ENDING_SIGNALS = ['SIGHUP', 'SIGINT', 'SIGTERM'] as const
65
+ /** The listeners `guardSignals` added, while any agent runs. */
66
+ const signalGuards = new Map<NodeJS.Signals, () => void>()
67
+
68
+ /** SIGKILL every agent still running. There is no later to escalate in. */
69
+ function killAllNow(): void {
70
+ for (const s of live.values()) for (const c of s) killTree(c.pid, 0)
71
+ }
72
+
73
+ /**
74
+ * No agent outlives this process.
75
+ *
76
+ * On POSIX each agent leads its own process group, so it gets neither the
77
+ * terminal's Ctrl+C nor its hangup. Anything still running when this process
78
+ * goes would be orphaned, still editing a worktree and spending tokens with
79
+ * nobody watching.
80
+ *
81
+ * The 'exit' hook covers `process.exit` and an uncaught throw. A signal's
82
+ * default action ends the process with no 'exit' event, so while an agent
83
+ * runs, each ending signal has a listener too. A command that handles the
84
+ * signal itself (the convoy engine stops gracefully on all three) has a
85
+ * listener of its own, and this one stands aside for it. With no other
86
+ * listener, the agents are killed and the signal is raised again, so the
87
+ * process still ends the way the signal would have ended it.
88
+ */
89
+ function guardSignals(): void {
90
+ if (!exitHookInstalled) {
91
+ exitHookInstalled = true
92
+ process.once('exit', killAllNow)
93
+ }
94
+ // On Windows the agents share this process's console and close with it.
95
+ if (process.platform === 'win32' || signalGuards.size > 0) return
96
+ for (const sig of ENDING_SIGNALS) {
97
+ const onSignal = (): void => {
98
+ if (process.listenerCount(sig) > 1) return
99
+ killAllNow()
100
+ unguardSignals()
101
+ process.kill(process.pid, sig)
102
+ }
103
+ signalGuards.set(sig, onSignal)
104
+ process.on(sig, onSignal)
105
+ }
106
+ }
107
+
108
+ /** Once no agent runs, a signal does what it would have done anyway. */
109
+ function unguardSignals(): void {
110
+ for (const [sig, onSignal] of signalGuards) process.removeListener(sig, onSignal)
111
+ signalGuards.clear()
112
+ }
113
+
60
114
  function track(taskId: string, child: ChildProcess): void {
61
115
  let set = live.get(taskId)
62
116
  if (!set) live.set(taskId, (set = new Set()))
63
117
  set.add(child)
64
- if (!exitHookInstalled) {
65
- exitHookInstalled = true
66
- // On POSIX each agent leads its own process group, so it does not get the
67
- // terminal's Ctrl+C. Anything still running when this process exits would
68
- // be orphaned, still editing a worktree nobody is watching. There is no
69
- // later to escalate in, so it is SIGKILL now.
70
- process.once('exit', () => {
71
- for (const s of live.values()) for (const c of s) killTree(c.pid, 0)
72
- })
73
- }
118
+ guardSignals()
74
119
  }
75
120
 
76
121
  function untrack(taskId: string, child: ChildProcess): void {
@@ -78,6 +123,7 @@ function untrack(taskId: string, child: ChildProcess): void {
78
123
  if (!set) return
79
124
  set.delete(child)
80
125
  if (set.size === 0) live.delete(taskId)
126
+ if (live.size === 0) unguardSignals()
81
127
  }
82
128
 
83
129
  function stop(child: ChildProcess): void {