@rbbtsn0w/adg 0.7.2-beta.2 → 0.8.0-beta.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.
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Pure decision model for "projection slots" — filesystem paths ADG owns a
3
+ * generated alias/exposure at (Antigravity's convention-field aliases and its
4
+ * external exposure symlink today; any future agent with the same
5
+ * symlink-or-copy-fallback shape can reuse this).
6
+ *
7
+ * This module makes no filesystem calls. It exists to separate *deciding*
8
+ * what to do at a path from *doing* it, because the two ad-hoc
9
+ * implementations that predate it (`removeProjectionTarget` in
10
+ * adapters/antigravity.ts, `rmIfSymlink`/`linkOrCopy` in
11
+ * agents/antigravity.ts) each re-derived "is this safe to touch?" via
12
+ * one-off lstat/existsSync checks, and every edge case that surfaced (a
13
+ * stale symlink, a broken link, a foreign directory, a copy-fallback left
14
+ * over where symlinks aren't available) got patched where it was found
15
+ * rather than modeled — see the fix(antigravity) commit history and
16
+ * https://github.com/RbBtSn0w/adg/issues/85 finding #1.
17
+ *
18
+ * `reconcileSlot` is the single place that decision lives now: a table over
19
+ * two small closed unions, exhaustively tested in
20
+ * test/projection-slot.test.ts. observeSlot/applySlotAction (the IO layer
21
+ * that calls this) land in a later phase; this phase is additive only —
22
+ * nothing in the codebase calls `reconcileSlot` yet.
23
+ */
24
+ /** Exported so tests assert against this exact string instead of duplicating it. */
25
+ export const FOREIGN_REASON = "a real, non-ADG-owned directory or file already exists at this path";
26
+ /**
27
+ * Only the variant's `kind` is included in the thrown message, never the
28
+ * full object: a `SlotObservation`/`SlotDesire`/`SlotAction` can carry a
29
+ * `target` (a filesystem path), and this path is meant to be unreachable —
30
+ * if it's ever hit anyway (a bug, or a caller bypassing the type checker),
31
+ * the error shouldn't be the thing that leaks a path into a log or an
32
+ * uncaught-exception report.
33
+ */
34
+ function assertNever(x) {
35
+ const kind = typeof x === "object" && x !== null && "kind" in x ? String(x.kind) : "unknown";
36
+ throw new Error(`unreachable projection state: ${kind}`);
37
+ }
38
+ export function reconcileSlot(desired, observed) {
39
+ if (desired.kind === "in-place")
40
+ return { kind: "noop" };
41
+ if (desired.kind === "absent") {
42
+ switch (observed.kind) {
43
+ case "absent": return { kind: "noop" };
44
+ case "symlink": return { kind: "remove-link" };
45
+ case "owned-dir": return { kind: "remove-link" };
46
+ case "foreign": return { kind: "skip-foreign", reason: FOREIGN_REASON }; // not ours; can't confirm "absent"
47
+ default: return assertNever(observed);
48
+ }
49
+ }
50
+ if (desired.kind === "linked") {
51
+ switch (observed.kind) {
52
+ case "absent": return { kind: "create-link", target: desired.target };
53
+ case "symlink":
54
+ if (observed.broken)
55
+ return { kind: "relink", target: desired.target };
56
+ return observed.target === desired.target
57
+ ? { kind: "noop" }
58
+ : { kind: "relink", target: desired.target };
59
+ case "owned-dir": return { kind: "relink", target: desired.target };
60
+ case "foreign": return { kind: "skip-foreign", reason: FOREIGN_REASON };
61
+ default: return assertNever(observed);
62
+ }
63
+ }
64
+ return assertNever(desired);
65
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbbtsn0w/adg",
3
- "version": "0.7.2-beta.2",
3
+ "version": "0.8.0-beta.1",
4
4
  "description": "Agent Directory Group (ADG) toolkit — two domains: plugins and skills.",
5
5
  "type": "module",
6
6
  "license": "MIT",