@srobroek/pi-worktrunk-merge-policy 1.0.1 → 1.0.2

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/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## worktrunk [1.0.2](https://github.com/srobroek/harness-plugins/compare/worktrunk--v1.0.1...worktrunk--v1.0.2) (2026-12-05)
2
+
3
+ ### Bug Fixes
4
+
5
+ * **lib:** settle a subprocess whose pipe a descendant holds, and verify cut-off mutations ([#342](https://github.com/srobroek/harness-plugins/issues/342)) ([8fd6bd8](https://github.com/srobroek/harness-plugins/commit/8fd6bd8df1c19fab2618a0965c620093aa1444c6))
6
+
1
7
  ## worktrunk [1.0.1](https://github.com/srobroek/harness-plugins/compare/worktrunk--v1.0.0...worktrunk--v1.0.1) (2026-12-04)
2
8
 
3
9
  ### Bug Fixes
@@ -1791,6 +1791,8 @@ var INTERPRETERS = new Set(["bash", "sh", "zsh", "dash", "ksh"]);
1791
1791
  import { constants } from "os";
1792
1792
  var EXIT_GRACE_MS = 2000;
1793
1793
  var EXIT_POLL_MS = 100;
1794
+ var PIPE_DRAIN_MS = 2000;
1795
+ var DRAIN_EXTRA_TURNS = 2;
1794
1796
  function goneWatch(graceMs, pollMs) {
1795
1797
  const polls = Math.max(1, Math.ceil(graceMs / Math.max(1, pollMs)));
1796
1798
  let since = null;
@@ -1857,6 +1859,7 @@ function capture(stream) {
1857
1859
  }
1858
1860
  function supervise(child, options = {}) {
1859
1861
  const grace = Math.max(0, options.graceMs ?? EXIT_GRACE_MS);
1862
+ const drainMs = Math.max(0, options.drainMs ?? PIPE_DRAIN_MS);
1860
1863
  const pollMs = Math.max(1, options.pollMs ?? EXIT_POLL_MS);
1861
1864
  const alive = options.alive ?? processAlive;
1862
1865
  const group = options.group ?? false;
@@ -1870,6 +1873,7 @@ function supervise(child, options = {}) {
1870
1873
  const gone = goneWatch(grace, pollMs);
1871
1874
  let deadline;
1872
1875
  let graceTimer;
1876
+ let drainTimer;
1873
1877
  const settle = (run) => {
1874
1878
  if (settled)
1875
1879
  return;
@@ -1877,6 +1881,7 @@ function supervise(child, options = {}) {
1877
1881
  clearTimeout(deadline);
1878
1882
  clearTimeout(graceTimer);
1879
1883
  clearInterval(poller);
1884
+ clearTimeout(drainTimer);
1880
1885
  signal?.removeEventListener("abort", onAbort);
1881
1886
  resolve(run);
1882
1887
  };
@@ -1900,7 +1905,8 @@ function supervise(child, options = {}) {
1900
1905
  end("lost");
1901
1906
  }, pollMs);
1902
1907
  unref(poller);
1903
- if (timeoutMs !== undefined && timeoutMs > 0 && Number.isFinite(timeoutMs)) {
1908
+ const bounded = timeoutMs !== undefined && timeoutMs > 0 && Number.isFinite(timeoutMs);
1909
+ if (bounded) {
1904
1910
  deadline = setTimeout(() => end("timeout"), timeoutMs);
1905
1911
  if (options.unref)
1906
1912
  unref(deadline);
@@ -1908,8 +1914,28 @@ function supervise(child, options = {}) {
1908
1914
  signal?.addEventListener("abort", onAbort, { once: true });
1909
1915
  if (signal?.aborted)
1910
1916
  onAbort();
1911
- child.exited.then(() => {
1917
+ child.exited.then((exitCode) => {
1912
1918
  exitSeen = true;
1919
+ if (bounded || ended !== null || settled)
1920
+ return;
1921
+ let turns = 0;
1922
+ const drain = () => {
1923
+ if (ended !== null || settled)
1924
+ return;
1925
+ if (turns++ < DRAIN_EXTRA_TURNS) {
1926
+ drainTimer = setTimeout(drain, 0);
1927
+ if (options.unref)
1928
+ unref(drainTimer);
1929
+ return;
1930
+ }
1931
+ out.cancel();
1932
+ err.cancel();
1933
+ const signalCode = signalName(child.signalCode);
1934
+ settle({ kind: "incomplete", exitCode, signalCode, stdout: out.snapshot(), stderr: err.snapshot() });
1935
+ };
1936
+ drainTimer = setTimeout(drain, drainMs);
1937
+ if (options.unref)
1938
+ unref(drainTimer);
1913
1939
  }, () => {
1914
1940
  return;
1915
1941
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@srobroek/pi-worktrunk-merge-policy",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Worktrunk (wt) skills: work in linked worktrees and run deterministic preflight checks before an agent run or merge.",
5
5
  "keywords": [
6
6
  "pi-package"