@db-lyon/flowkit 0.12.0 → 0.13.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/README.md +386 -375
- package/dist/.tsbuildinfo +1 -0
- package/dist/flow/references.d.ts +39 -0
- package/dist/flow/references.d.ts.map +1 -0
- package/dist/flow/references.js +102 -0
- package/dist/flow/references.js.map +1 -0
- package/dist/references.d.ts.map +1 -1
- package/dist/references.js +6 -0
- package/dist/references.js.map +1 -1
- package/dist/task/shell-task.d.ts +2 -0
- package/dist/task/shell-task.d.ts.map +1 -1
- package/dist/task/shell-task.js +186 -40
- package/dist/task/shell-task.js.map +1 -1
- package/dist/task/shell-termination.d.ts +34 -0
- package/dist/task/shell-termination.d.ts.map +1 -0
- package/dist/task/shell-termination.js +179 -0
- package/dist/task/shell-termination.js.map +1 -0
- package/docs/ai-agents.md +368 -368
- package/docs/api-reference.md +458 -430
- package/docs/configuration.md +347 -347
- package/docs/custom-tasks.md +258 -232
- package/package.json +53 -52
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
export const POSIX_SIGTERM_GRACE_MS = 250;
|
|
3
|
+
export const POSIX_TERMINATION_GRACE_MS = 1_000;
|
|
4
|
+
export const WINDOWS_TERMINATION_GRACE_MS = 3_000;
|
|
5
|
+
export function terminationGraceMs(platform) {
|
|
6
|
+
return platform === 'win32' ? WINDOWS_TERMINATION_GRACE_MS : POSIX_TERMINATION_GRACE_MS;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Start termination for one shell invocation.
|
|
10
|
+
*
|
|
11
|
+
* This module is deliberately internal. Passing the platform and process
|
|
12
|
+
* functions as dependencies makes the policy testable on every CI platform
|
|
13
|
+
* without changing ShellTask's public API or relying on global mutable state.
|
|
14
|
+
*/
|
|
15
|
+
export function beginShellTermination(child, dependencies = {}) {
|
|
16
|
+
const platform = dependencies.platform ?? process.platform;
|
|
17
|
+
const spawnProcess = dependencies.spawnProcess ?? spawn;
|
|
18
|
+
const killProcessGroup = dependencies.killProcessGroup ??
|
|
19
|
+
((pid, signal) => {
|
|
20
|
+
process.kill(pid, signal);
|
|
21
|
+
});
|
|
22
|
+
let active = true;
|
|
23
|
+
let escalated = false;
|
|
24
|
+
let rootForceRequested = false;
|
|
25
|
+
let treeKiller;
|
|
26
|
+
let treeKillerFinished = false;
|
|
27
|
+
let treeKillComplete = platform !== 'win32' || child.pid === undefined;
|
|
28
|
+
const treeKillListeners = new Set();
|
|
29
|
+
const markTreeKillComplete = () => {
|
|
30
|
+
if (treeKillComplete)
|
|
31
|
+
return;
|
|
32
|
+
treeKillComplete = true;
|
|
33
|
+
for (const listener of treeKillListeners)
|
|
34
|
+
listener();
|
|
35
|
+
treeKillListeners.clear();
|
|
36
|
+
};
|
|
37
|
+
const killRoot = (signal) => {
|
|
38
|
+
if (!active)
|
|
39
|
+
return;
|
|
40
|
+
if (signal === 'SIGKILL' && rootForceRequested)
|
|
41
|
+
return;
|
|
42
|
+
try {
|
|
43
|
+
const sent = child.kill(signal);
|
|
44
|
+
if (signal === 'SIGKILL' && sent)
|
|
45
|
+
rootForceRequested = true;
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// The shell may have closed between the terminal event and this call.
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const killGroup = (signal) => {
|
|
52
|
+
if (!active || child.pid === undefined) {
|
|
53
|
+
killRoot(signal);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
killProcessGroup(-child.pid, signal);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
// A missing process group or unsupported group signal falls back to the
|
|
61
|
+
// direct shell. This cannot promise termination of escaped descendants.
|
|
62
|
+
killRoot(signal);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const stopTreeKiller = () => {
|
|
66
|
+
if (!treeKiller || treeKillerFinished)
|
|
67
|
+
return;
|
|
68
|
+
// Retain an error handler because a forced helper close may race an error.
|
|
69
|
+
treeKiller.once('error', () => undefined);
|
|
70
|
+
try {
|
|
71
|
+
treeKiller.kill('SIGKILL');
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// The helper may already be exiting.
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
treeKiller.unref();
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
// Releasing the task result must not be defeated by an unref race.
|
|
81
|
+
}
|
|
82
|
+
treeKillerFinished = true;
|
|
83
|
+
};
|
|
84
|
+
if (platform === 'win32' && child.pid !== undefined) {
|
|
85
|
+
try {
|
|
86
|
+
treeKiller = spawnProcess('taskkill', ['/pid', String(child.pid), '/T', '/F'], { stdio: 'ignore', windowsHide: true });
|
|
87
|
+
const killOnError = () => {
|
|
88
|
+
if (!active)
|
|
89
|
+
return;
|
|
90
|
+
killRoot('SIGKILL');
|
|
91
|
+
markTreeKillComplete();
|
|
92
|
+
};
|
|
93
|
+
treeKiller.once('error', killOnError);
|
|
94
|
+
treeKiller.once('close', (code) => {
|
|
95
|
+
if (!active)
|
|
96
|
+
return;
|
|
97
|
+
treeKillerFinished = true;
|
|
98
|
+
if (code !== 0)
|
|
99
|
+
killRoot('SIGKILL');
|
|
100
|
+
markTreeKillComplete();
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
killRoot('SIGKILL');
|
|
105
|
+
markTreeKillComplete();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
// Cooperative first phase. ShellTask schedules the bounded SIGKILL
|
|
110
|
+
// escalation so normal commands can flush and clean up.
|
|
111
|
+
killGroup('SIGTERM');
|
|
112
|
+
}
|
|
113
|
+
const escalate = () => {
|
|
114
|
+
if (!active || escalated)
|
|
115
|
+
return;
|
|
116
|
+
escalated = true;
|
|
117
|
+
if (platform === 'win32') {
|
|
118
|
+
killRoot('SIGKILL');
|
|
119
|
+
stopTreeKiller();
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
killGroup('SIGKILL');
|
|
123
|
+
};
|
|
124
|
+
const dispose = () => {
|
|
125
|
+
if (!active)
|
|
126
|
+
return;
|
|
127
|
+
treeKillListeners.clear();
|
|
128
|
+
try {
|
|
129
|
+
stopTreeKiller();
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
active = false;
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
const release = () => {
|
|
136
|
+
if (!active)
|
|
137
|
+
return;
|
|
138
|
+
treeKillListeners.clear();
|
|
139
|
+
escalate();
|
|
140
|
+
try {
|
|
141
|
+
child.stdout?.destroy();
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
// The stream may have closed between escalation and release.
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
child.stderr?.destroy();
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
// The stream may have closed between escalation and release.
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
child.unref();
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
// A bounded result still settles if Node rejects an unref race.
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
stopTreeKiller();
|
|
160
|
+
}
|
|
161
|
+
finally {
|
|
162
|
+
active = false;
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
return {
|
|
166
|
+
platform,
|
|
167
|
+
isTreeKillComplete: () => treeKillComplete,
|
|
168
|
+
onTreeKillComplete: (listener) => {
|
|
169
|
+
if (treeKillComplete)
|
|
170
|
+
listener();
|
|
171
|
+
else
|
|
172
|
+
treeKillListeners.add(listener);
|
|
173
|
+
},
|
|
174
|
+
escalate,
|
|
175
|
+
release,
|
|
176
|
+
dispose,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=shell-termination.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell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