entropy-machines 0.1.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.
Files changed (51) hide show
  1. package/LICENSE +93 -0
  2. package/README.md +68 -0
  3. package/agents/isolated-worker.md +128 -0
  4. package/agents/verifier.md +158 -0
  5. package/bin/dispatch +700 -0
  6. package/bin/doclint +460 -0
  7. package/bin/drain +507 -0
  8. package/bin/drain-pick.py +168 -0
  9. package/bin/drain-prompt.md +67 -0
  10. package/bin/drain-run.sh +342 -0
  11. package/bin/entropy-machines-init +285 -0
  12. package/bin/handoff +1151 -0
  13. package/bin/init +232 -0
  14. package/bin/post-fold-audit +377 -0
  15. package/bin/serve +724 -0
  16. package/bin/status +208 -0
  17. package/bin/tracker +153 -0
  18. package/docs/AGENT-QUICKSTART.md +86 -0
  19. package/docs/CONFIG.md +68 -0
  20. package/docs/NPM.md +91 -0
  21. package/docs/SERVE.md +74 -0
  22. package/docs/TRACKER-ADAPTER.md +66 -0
  23. package/doctrine/HANDOFF-PROMPT.md +63 -0
  24. package/doctrine/README.md +62 -0
  25. package/doctrine/ROLES.md +27 -0
  26. package/doctrine/WORKFLOW.md +87 -0
  27. package/hooks/commit-msg +24 -0
  28. package/hooks/post-checkout +354 -0
  29. package/hooks/pre-commit +33 -0
  30. package/lib/PRD-001-orientation.html +1180 -0
  31. package/lib/REPORT-TEMPLATE.html +413 -0
  32. package/lib/changelog-collate.mjs +328 -0
  33. package/lib/changelog-guard.sh +157 -0
  34. package/lib/changelog-new.mjs +70 -0
  35. package/lib/config.mjs +283 -0
  36. package/lib/config.py +317 -0
  37. package/lib/doc-template.html +807 -0
  38. package/lib/entropy-drain.plist.in +59 -0
  39. package/lib/entropy-drain.service.in +53 -0
  40. package/lib/entropy-drain.timer.in +36 -0
  41. package/lib/fail-first.mjs +901 -0
  42. package/lib/handoff-guard.sh +623 -0
  43. package/lib/install-hooks.sh +169 -0
  44. package/lib/notes.py +675 -0
  45. package/lib/preflight-tree.mjs +82 -0
  46. package/lib/roots.sh +212 -0
  47. package/lib/themes/daylight.css +84 -0
  48. package/lib/themes/high-contrast.css +36 -0
  49. package/lib/tracker-file +333 -0
  50. package/lib/tracker-view.py +784 -0
  51. package/package.json +38 -0
@@ -0,0 +1,169 @@
1
+ #!/usr/bin/env bash
2
+ # install-hooks — put a shim in the repo's hooks directory that runs the
3
+ # harness's checked-in hooks in hooks/.
4
+ #
5
+ # lib/install-hooks.sh (run with cwd anywhere inside the repo)
6
+ #
7
+ # ONE ROOT. The harness is vendored as plain tracked files inside the repo it
8
+ # works on, so the hook bodies and the .git being written into are in the SAME
9
+ # repository. There is no second repo to reconcile. Two paths still matter and
10
+ # they are not the same directory:
11
+ #
12
+ # ENTROPY_MACHINES_HOME where hooks/ and lib/ actually are — the harness directory,
13
+ # which may be the repo root or a subdirectory of it. Resolved
14
+ # from this script's OWN path.
15
+ # ENTROPY_MACHINES_ROOT the repo's MAIN checkout, resolved via --git-common-dir so
16
+ # it is right even when this is run from a linked worktree
17
+ # (see lib/roots.sh).
18
+ #
19
+ # It does NOT set core.hooksPath. A repo may already have it set, that setting
20
+ # is shared by every worktree, and rewriting it from a script would change hook
21
+ # resolution for whatever else is running in a sibling worktree at the time.
22
+ # Instead we write into whatever directory git currently resolves — `git
23
+ # rev-parse --git-path hooks` honours core.hooksPath if it is set and falls
24
+ # back to the common .git/hooks if it is not.
25
+ #
26
+ # THE SHIM CARRIES ONE PATH BAKED IN, ABSOLUTE, AT INSTALL TIME: ENTROPY_MACHINES_HOME.
27
+ # An installed shim lives inside .git/hooks and can no longer assume a hooks/
28
+ # directory sits beside it, so it cannot find the harness relatively. It does
29
+ # NOT bake the root: git guarantees a hook's cwd is a working tree of this
30
+ # repo, so lib/roots.sh resolves the root correctly at hook time and a baked
31
+ # copy could only ever go stale. The shim delegates to the WORKING-TREE copy of
32
+ # the hook body (not a frozen copy of its contents), so it never needs
33
+ # reinstalling when a hook's body changes — only when the harness MOVES.
34
+ #
35
+ # It VERIFIES afterwards, and says so. A setting that is quietly ignored is a
36
+ # failure this project has already paid for once. An installer that prints
37
+ # "installed" without checking is the same bug in a different costume. That is
38
+ # also why it checks that the shim's BAKED-IN path actually resolves: a shim
39
+ # that installs cleanly and points at a harness directory that does not exist
40
+ # is "installed, verified, dead".
41
+
42
+ set -euo pipefail
43
+
44
+ . "$(dirname "$0")/roots.sh"
45
+
46
+ ENTROPY_MACHINES_HOME=$(entropy_machines_home "$0")
47
+ entropy_machines_require_root install-hooks # sets+exports ENTROPY_MACHINES_ROOT or exits 2
48
+
49
+ # cd to the main checkout so `git rev-parse --git-path hooks` below resolves
50
+ # unambiguously no matter which subdirectory (or worktree) this was run from.
51
+ cd "$ENTROPY_MACHINES_ROOT"
52
+
53
+ HOOK_DIR="$(git rev-parse --git-path hooks)"
54
+ case "$HOOK_DIR" in
55
+ /*) ;;
56
+ *) HOOK_DIR="$ENTROPY_MACHINES_ROOT/$HOOK_DIR" ;;
57
+ esac
58
+
59
+ mkdir -p "$HOOK_DIR"
60
+
61
+ installed=0
62
+ for src in "$ENTROPY_MACHINES_HOME"/hooks/*; do
63
+ [ -f "$src" ] || continue
64
+ name="$(basename "$src")"
65
+ dest="$HOOK_DIR/$name"
66
+ # Deliberately UNQUOTED heredoc delimiter: $ENTROPY_MACHINES_HOME must expand NOW,
67
+ # baked into the generated file. $0, $@ and the nested $(basename ...) are
68
+ # backslash-escaped so they survive into the shim literally and are
69
+ # evaluated at THAT script's run time, against the real hook path git
70
+ # passes it.
71
+ cat > "$dest" <<SHIM
72
+ #!/usr/bin/env bash
73
+ # Generated by lib/install-hooks.sh — do not edit.
74
+ #
75
+ # ENTROPY_MACHINES_HOME is baked in below, ABSOLUTE, because this file lives inside
76
+ # .git/hooks and cannot assume a hooks/ or lib/ directory sits beside it (the
77
+ # harness may be vendored in a subdirectory). Re-run lib/install-hooks.sh if
78
+ # the harness moves. The repo root is NOT baked in — git guarantees a hook's
79
+ # cwd is a working tree of this repo, so lib/roots.sh resolves it live.
80
+ #
81
+ # It delegates to the WORKING-TREE copy of hooks/$name in the harness, so
82
+ # editing that file's body never requires reinstalling this shim.
83
+ export ENTROPY_MACHINES_HOME="$ENTROPY_MACHINES_HOME"
84
+ set -euo pipefail
85
+ HOOK="\$ENTROPY_MACHINES_HOME/hooks/\$(basename "\$0")"
86
+ [ -x "\$HOOK" ] || exit 0
87
+ exec "\$HOOK" "\$@"
88
+ SHIM
89
+ chmod +x "$dest"
90
+ installed=$((installed + 1))
91
+ done
92
+
93
+ echo "install-hooks: wrote $installed shim(s) to $HOOK_DIR"
94
+ echo "install-hooks: harness (ENTROPY_MACHINES_HOME) = $ENTROPY_MACHINES_HOME"
95
+ echo "install-hooks: repo (ENTROPY_MACHINES_ROOT) = $ENTROPY_MACHINES_ROOT"
96
+
97
+ # --- verify, don't assume ---------------------------------------------------
98
+ fail=0
99
+ for src in "$ENTROPY_MACHINES_HOME"/hooks/*; do
100
+ [ -f "$src" ] || continue
101
+ name="$(basename "$src")"
102
+ if [ ! -x "$src" ]; then
103
+ echo "install-hooks: FAIL $ENTROPY_MACHINES_HOME/hooks/$name is not executable (chmod +x it and commit the mode)." >&2
104
+ fail=1
105
+ fi
106
+ if [ ! -x "$HOOK_DIR/$name" ]; then
107
+ echo "install-hooks: FAIL $HOOK_DIR/$name is missing or not executable." >&2
108
+ fail=1
109
+ fi
110
+
111
+ # Prove the INSTALLED FILE'S OWN baked-in path resolves, by reading it back
112
+ # off disk rather than trusting the variables still in memory from the write
113
+ # above. This catches a shim that installs cleanly, passes both checks
114
+ # above, and still points at a harness directory that does not exist (a
115
+ # stale install after the harness moved, or a shim copied between machines).
116
+ baked="$(sed -n 's/^export ENTROPY_MACHINES_HOME="\(.*\)"$/\1/p' "$HOOK_DIR/$name" 2>/dev/null | head -1)"
117
+ if [ -z "$baked" ]; then
118
+ echo "install-hooks: FAIL $HOOK_DIR/$name has no baked-in ENTROPY_MACHINES_HOME — cannot verify it resolves." >&2
119
+ fail=1
120
+ elif [ ! -x "$baked/hooks/$name" ]; then
121
+ echo "install-hooks: FAIL $HOOK_DIR/$name points at $baked/hooks/$name, which is missing or not executable." >&2
122
+ fail=1
123
+ fi
124
+ done
125
+
126
+ if [ "$fail" -ne 0 ]; then
127
+ exit 1
128
+ fi
129
+
130
+ echo "install-hooks: verified. Hooks resolve to $HOOK_DIR and each shim's"
131
+ echo " baked-in harness path resolves to an executable hook."
132
+
133
+ # --- post-checkout needs a SHARED hooks dir, so check it is one -------------
134
+ #
135
+ # The checks above prove the shim exists, is executable, and its baked-in
136
+ # harness path resolves. For post-checkout that is not enough to prove it will
137
+ # ever RUN, because it has to fire inside a worktree that does not exist yet.
138
+ #
139
+ # git resolves hooks from core.hooksPath when it is set, and from
140
+ # $GIT_COMMON_DIR/hooks when it is not. Both are shared by every worktree — but
141
+ # only if core.hooksPath is ABSOLUTE. Set to a relative path, git resolves it
142
+ # against each working tree's own root, so a brand-new worktree would look in
143
+ # its own empty directory and post-checkout would silently never fire. The
144
+ # install would still print "verified": installed, checked, dead.
145
+ #
146
+ # Not a hard failure: commit-msg and pre-commit install correctly in that
147
+ # setup, and refusing the whole install to complain about one hook would be
148
+ # worse than saying so loudly.
149
+ if [ -f "$ENTROPY_MACHINES_HOME/hooks/post-checkout" ]; then
150
+ configured="$(git config --get core.hooksPath || true)"
151
+ if [ -n "$configured" ]; then
152
+ case "$configured" in
153
+ /*) ;;
154
+ *)
155
+ echo "install-hooks: WARNING — core.hooksPath is set to a RELATIVE path" >&2
156
+ echo " ('$configured'). git resolves that against each working" >&2
157
+ echo " tree's own root, so a new worktree will look in its own" >&2
158
+ echo " empty directory and the post-checkout hook will NOT fire" >&2
159
+ echo " for 'git worktree add'. worktree.linkPaths" >&2
160
+ echo " will not be linked. Fix: set it to an absolute path," >&2
161
+ echo " or unset it so hooks come from the shared .git/hooks." >&2
162
+ ;;
163
+ esac
164
+ fi
165
+ fi
166
+
167
+ echo "install-hooks: note — hooks are per-clone and per-worktree. Anyone who"
168
+ echo " never runs this has no hook; a CI job is the enforcement"
169
+ echo " that lives in the repo."