@crewhaus/harness-registry 0.5.2 → 0.5.4

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/dist/index.d.ts CHANGED
@@ -15,5 +15,5 @@
15
15
  * API.
16
16
  */
17
17
  export { HARNESS_ID_RE, REGISTRY_FILENAME } from "./doc.js";
18
- export { openHangarRegistry, registerHarnessHook, resolveRegistryRoot, type HangarRegistry, type ListOptions, type OpenHangarRegistryOptions, type RegisterHookFields, type RegisterHookResult, type UpsertFields, } from "./registry.js";
18
+ export { openHangarRegistry, registerHarnessHook, resolveRegistryRoot, sortGroupMembers, type HangarRegistry, type ListOptions, type OpenHangarRegistryOptions, type RegisterHookFields, type RegisterHookResult, type UpsertFields, } from "./registry.js";
19
19
  export type { GroupDef, HangarHarnessEntry, HangarRegistryDoc, HarnessKind, HarnessOrigin, ScanRoot, } from "./types.js";
package/dist/index.js CHANGED
@@ -15,4 +15,4 @@
15
15
  * API.
16
16
  */
17
17
  export { HARNESS_ID_RE, REGISTRY_FILENAME } from "./doc.js";
18
- export { openHangarRegistry, registerHarnessHook, resolveRegistryRoot, } from "./registry.js";
18
+ export { openHangarRegistry, registerHarnessHook, resolveRegistryRoot, sortGroupMembers, } from "./registry.js";
@@ -59,6 +59,16 @@ export type RegisterHookResult = {
59
59
  readonly id?: string;
60
60
  readonly error?: string;
61
61
  };
62
+ /**
63
+ * A group's members in BOOT order.
64
+ *
65
+ * Two tiers, because a fleet is rarely fully ordered: everything with a
66
+ * declared `groupOrder[group]` first, ascending, then everything without
67
+ * one. Inside a tier the sort is by spec name — an arbitrary but STABLE
68
+ * choice, so the same fleet walks the same way on every machine and a
69
+ * `--group` start is reproducible rather than registry-insertion-ordered.
70
+ */
71
+ export declare function sortGroupMembers(group: string, entries: readonly HangarHarnessEntry[]): HangarHarnessEntry[];
62
72
  export type HangarRegistry = {
63
73
  /** Absolute path of the registry file. */
64
74
  readonly path: string;
@@ -83,6 +93,14 @@ export type HangarRegistry = {
83
93
  * Throws if `newDir` is already registered to a different entry. */
84
94
  relocate(id: string, newDir: string): HangarHarnessEntry | undefined;
85
95
  setGroups(dirOrId: string, groups: readonly string[]): HangarHarnessEntry | undefined;
96
+ /** Set (or, with `undefined`, clear) this member's boot order INSIDE one
97
+ * group. Independent of membership: an order for a group the entry does
98
+ * not belong to is simply never consulted. */
99
+ setGroupOrder(dirOrId: string, group: string, order: number | undefined): HangarHarnessEntry | undefined;
100
+ /** The members of a group in BOOT order: declared orders ascending first,
101
+ * then the undeclared ones, each tier by spec name so the walk is stable
102
+ * across machines. `stop` is this list reversed. */
103
+ groupMembers(group: string, opts?: ListOptions): HangarHarnessEntry[];
86
104
  setTags(dirOrId: string, tags: readonly string[]): HangarHarnessEntry | undefined;
87
105
  setPinned(dirOrId: string, pinned: boolean): HangarHarnessEntry | undefined;
88
106
  setNotes(dirOrId: string, notes: string): HangarHarnessEntry | undefined;
package/dist/registry.js CHANGED
@@ -34,6 +34,31 @@ import { homedir } from "node:os";
34
34
  import { basename, join, resolve } from "node:path";
35
35
  import { openHarnessRegistry as openWatchmeRegistry } from "@crewhaus/watchme-store";
36
36
  import { EMPTY_DOC, HARNESS_ID_RE, REGISTRY_FILENAME, fingerprintPath, mintHarnessId, normalizeDoc, sleepSync, sortDoc, } from "./doc.js";
37
+ /**
38
+ * A group's members in BOOT order.
39
+ *
40
+ * Two tiers, because a fleet is rarely fully ordered: everything with a
41
+ * declared `groupOrder[group]` first, ascending, then everything without
42
+ * one. Inside a tier the sort is by spec name — an arbitrary but STABLE
43
+ * choice, so the same fleet walks the same way on every machine and a
44
+ * `--group` start is reproducible rather than registry-insertion-ordered.
45
+ */
46
+ export function sortGroupMembers(group, entries) {
47
+ return entries
48
+ .filter((e) => e.groups.includes(group))
49
+ .sort((a, b) => {
50
+ const ao = a.groupOrder?.[group];
51
+ const bo = b.groupOrder?.[group];
52
+ if (ao !== bo) {
53
+ if (ao === undefined)
54
+ return 1;
55
+ if (bo === undefined)
56
+ return -1;
57
+ return ao - bo;
58
+ }
59
+ return a.specName.localeCompare(b.specName) || a.dir.localeCompare(b.dir);
60
+ });
61
+ }
37
62
  /** Resolve the registry ROOT directory (the one containing
38
63
  * `harnesses.json`): `CREWHAUS_REGISTRY_ROOT` or `~/.crewhaus`. */
39
64
  export function resolveRegistryRoot(env = process.env) {
@@ -563,6 +588,22 @@ export function openHangarRegistry(opts = {}) {
563
588
  remove,
564
589
  relocate,
565
590
  setGroups: (dirOrId, groups) => patchEntry(dirOrId, (e) => ({ ...e, groups: [...groups] })),
591
+ setGroupOrder: (dirOrId, group, order) => patchEntry(dirOrId, (e) => {
592
+ const next = { ...(e.groupOrder ?? {}) };
593
+ // An absent key, not a key holding undefined: this object is written
594
+ // to JSON, where the two are the same thing on read and different on
595
+ // write.
596
+ if (order === undefined)
597
+ delete next[group];
598
+ else
599
+ next[group] = order;
600
+ if (Object.keys(next).length === 0) {
601
+ const { groupOrder: _dropped, ...rest } = e;
602
+ return rest;
603
+ }
604
+ return { ...e, groupOrder: next };
605
+ }),
606
+ groupMembers: (group, opts) => sortGroupMembers(group, list(opts)),
566
607
  setTags: (dirOrId, tags) => patchEntry(dirOrId, (e) => ({ ...e, tags: [...tags] })),
567
608
  setPinned: (dirOrId, pinned) => patchEntry(dirOrId, (e) => ({ ...e, pinned })),
568
609
  setNotes: (dirOrId, notes) => patchEntry(dirOrId, (e) => ({ ...e, notes })),
package/dist/types.d.ts CHANGED
@@ -37,6 +37,22 @@ export type HangarHarnessEntry = {
37
37
  readonly lastSeen: string;
38
38
  /** User-managed; never clobbered by an upsert refresh. */
39
39
  readonly groups: readonly string[];
40
+ /**
41
+ * Per-group boot order for this member, keyed by group name (1-based,
42
+ * lower boots first). Absent for a member with no declared order, which
43
+ * sorts after every ordered one.
44
+ *
45
+ * This is a MEMBER's order INSIDE a group, distinct from `GroupDef.order`
46
+ * (the groups' order relative to each other). A fleet has dependency
47
+ * order — a secretary whose A2A door every other spec mounts has to be up
48
+ * before them, and the chief that supervises the rest comes last — and
49
+ * that order lives per member, not per group.
50
+ *
51
+ * Keyed by name rather than held as a list on the group so that renaming
52
+ * a group (which rewrites `groups` on every entry) and removing a member
53
+ * cannot leave a dangling ordering behind.
54
+ */
55
+ readonly groupOrder?: Readonly<Record<string, number>>;
40
56
  /** User-managed; never clobbered by an upsert refresh. */
41
57
  readonly tags: readonly string[];
42
58
  /** User-managed; pinned entries survive prune prompts. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crewhaus/harness-registry",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "type": "module",
5
5
  "description": "Machine-wide harness registry (harnesses.json v2) — stable hrn_ ids, groups/tags/pins, scan roots, missing-dir stamping, and watchme registry interop behind the harness manager",
6
6
  "main": "dist/index.js",
@@ -15,7 +15,7 @@
15
15
  "test": "bun test src"
16
16
  },
17
17
  "dependencies": {
18
- "@crewhaus/watchme-store": "0.5.2"
18
+ "@crewhaus/watchme-store": "0.5.4"
19
19
  },
20
20
  "license": "Apache-2.0",
21
21
  "author": {