@h1r-ai/croche 0.6.0 → 0.6.1

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.
@@ -512,7 +512,7 @@ var Agent = class {
512
512
  // package.json
513
513
  var package_default = {
514
514
  name: "@h1r-ai/croche",
515
- version: "0.6.0",
515
+ version: "0.6.1",
516
516
  private: true,
517
517
  publishConfig: {
518
518
  access: "public"
@@ -14,20 +14,23 @@ export type LockRecord = {
14
14
  start?: string;
15
15
  };
16
16
  export type Incarnation = {
17
- os: 'linux' | 'darwin';
17
+ os: 'linux' | 'darwin' | 'win32';
18
18
  boot: string;
19
19
  pidns: string;
20
20
  start?: string;
21
21
  };
22
22
  /** The PID namespace macOS records name: it has none, so every process shares this one. */
23
23
  export declare const DARWIN_PIDNS = "darwin";
24
- /** This process's scope and incarnation, or null where the OS cannot say (Windows, or anything
25
- * here failing): then no held record is taken over.
24
+ /** Windows's scope: one PID space per host, and no boot id. The host is checked in `keeps`. */
25
+ export declare const WIN32_SCOPE = "win32";
26
+ /** This process's scope and incarnation, or null where the OS cannot say (anything here
27
+ * failing): then no held record is taken over.
26
28
  * - Linux (/proc): the boot id (/proc/sys/kernel/random/boot_id), the PID namespace (the inode in
27
29
  * readlink /proc/self/ns/pid, `pid:[N]`), and the start in clock ticks since boot
28
30
  * (/proc/self/stat field 22).
29
31
  * - macOS: kern.bootsessionuuid (sysctl), and the one PID namespace. No start: the one the OS
30
32
  * gives is wall-clock text in the reader's time zone, so the same pid is always this process.
33
+ * - Windows: the fixed WIN32_SCOPE for boot and PID space, and no start, as on macOS.
31
34
  * None moves with the wall clock, and every thread of the process reads the same values. */
32
35
  export declare function incarnation(): Incarnation | null;
33
36
  /** The generations of `path` present now, highest first. */
@@ -36,7 +36,11 @@ import { randomUUID } from 'node:crypto';
36
36
  // UUID per boot, and there are no PID namespaces. The host is not part of it there: a Mac's
37
37
  // hostname follows the network it is on, and equal per-boot UUIDs already name one machine.
38
38
  // A record names its OS, and a Linux record and a macOS record are never in one scope (a
39
- // directory shared with a container). Windows has no scope: nothing held is taken over.
39
+ // directory shared with a container).
40
+ // - Windows has a scope too: the host, and the one PID space. There is no boot id to read without
41
+ // a clock, so a pid reused after a reboot reads as alive and keeps the lock (the safe
42
+ // direction), and a dead pid is taken over as on Linux. Without it, every Ctrl+C or crash left
43
+ // the store `held` until the records were removed by hand (Keel, 0.6.1 Windows audit).
40
44
  /** Lock records this module holds, by lock path: the generation and its nonce. */
41
45
  const held = new Map();
42
46
  let exitHook = false;
@@ -44,18 +48,22 @@ let exitHook = false;
44
48
  const ATTEMPTS = 5;
45
49
  /** The PID namespace macOS records name: it has none, so every process shares this one. */
46
50
  export const DARWIN_PIDNS = 'darwin';
47
- /** This process's scope and incarnation, or null where the OS cannot say (Windows, or anything
48
- * here failing): then no held record is taken over.
51
+ /** Windows's scope: one PID space per host, and no boot id. The host is checked in `keeps`. */
52
+ export const WIN32_SCOPE = 'win32';
53
+ /** This process's scope and incarnation, or null where the OS cannot say (anything here
54
+ * failing): then no held record is taken over.
49
55
  * - Linux (/proc): the boot id (/proc/sys/kernel/random/boot_id), the PID namespace (the inode in
50
56
  * readlink /proc/self/ns/pid, `pid:[N]`), and the start in clock ticks since boot
51
57
  * (/proc/self/stat field 22).
52
58
  * - macOS: kern.bootsessionuuid (sysctl), and the one PID namespace. No start: the one the OS
53
59
  * gives is wall-clock text in the reader's time zone, so the same pid is always this process.
60
+ * - Windows: the fixed WIN32_SCOPE for boot and PID space, and no start, as on macOS.
54
61
  * None moves with the wall clock, and every thread of the process reads the same values. */
55
62
  export function incarnation() {
56
63
  if (cached !== undefined)
57
64
  return cached;
58
- cached = process.platform === 'darwin' ? darwin() : process.platform === 'linux' ? linux() : null;
65
+ cached = process.platform === 'darwin' ? darwin() : process.platform === 'linux' ? linux()
66
+ : process.platform === 'win32' ? { os: 'win32', boot: WIN32_SCOPE, pidns: WIN32_SCOPE } : null;
59
67
  return cached;
60
68
  }
61
69
  let cached;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h1r-ai/croche",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },