mirror-mind 0.33.4 → 0.34.0

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.
@@ -1,85 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Mirror Mind hook wrapper — GENERATED by scripts/generate_hook_wrappers.sh.
3
- # Edit the generator, never this file: every wrapper shares these bytes and
4
- # differs only in the hook name and in how it finds the Mirror entry
5
- # (CV22.DS10.TS5 decision D4; CV22.DS10.US3 decision D5).
6
- set -uo pipefail
7
- HOOK="codex:session-start"
8
-
9
- # Resolve the tree from THIS FILE, never from the cwd: a runtime spawns hooks
10
- # from whatever directory the session is in. The tree is a checkout or the
11
- # installed package; the wrapper's depth to its root is the same in both.
12
- HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
13
- REPO_ROOT="$(cd "$HERE/../.." && pwd -P)"
14
-
15
- # A hook never fails the user's turn, and never fails in silence: when it
16
- # cannot do its job it appends ONE line to <mirror home>/hooks.log and exits 0.
17
- # The home is found the way the core finds it -- MIRROR_HOME, else
18
- # MIRROR_USER -- from the environment when set there, else from the tree's
19
- # .env when the wrapper is in a tree, else from the user's config file
20
- # (~/.config/mirror/env), in the core's order (US3, D3). A GUI launch carries
21
- # neither variable, and the first wrappers then wrote to a home nobody reads.
22
- env_file_value() {
23
- [ -f "$2" ] || return 0
24
- sed -n -E "s/^[[:space:]]*(export[[:space:]]+)?$1[[:space:]]*=[[:space:]]*//p" "$2" \
25
- | tail -n 1 | tr -d "\"'\r"
26
- }
27
- env_value() {
28
- local value=""
29
- if [ -n "${!1+set}" ]; then printf '%s' "${!1}"; return; fi
30
- [ -z "$REPO_ROOT" ] || value="$(env_file_value "$1" "$REPO_ROOT/.env")"
31
- [ -n "$value" ] || value="$(env_file_value "$1" "${XDG_CONFIG_HOME:-$HOME/.config}/mirror/env")"
32
- printf '%s' "$value"
33
- }
34
- note() {
35
- local home user
36
- home="$(env_value MIRROR_HOME)"
37
- user="$(env_value MIRROR_USER)"
38
- if [ -n "$home" ]; then
39
- home="${home/#\~/$HOME}"
40
- elif [ -n "$user" ]; then
41
- home="$HOME/.mirror-minds/$user"
42
- [ -d "$home" ] || [ ! -d "$HOME/.mirror/$user" ] || home="$HOME/.mirror/$user"
43
- else
44
- return 0
45
- fi
46
- mkdir -p "$home" 2>/dev/null \
47
- && printf '%s %s: %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$HOOK" "$1" >> "$home/hooks.log" 2>/dev/null
48
- }
49
-
50
- ENTRY="$REPO_ROOT/bin/mirror-hook.js"
51
-
52
- # Find Node. /usr/bin/python3 exists on every macOS; node usually lives under
53
- # nvm or Homebrew and is NOT on the PATH of a GUI-launched runtime. The Python
54
- # hooks could end in `|| true` because they always found their interpreter;
55
- # the same silence here would hide a new failure — no logging, no inject, no
56
- # close tail — that a user would meet weeks later as "Mirror stopped
57
- # remembering". So an unresolvable Node is RECORDED, never swallowed. The
58
- # directory the entry was found in is searched first: an npm global bin holds
59
- # the `node` that installed the package beside `mirror-hook`, while a system
60
- # `/usr/local/bin/node` can be years older (CI's Ubuntu runner has one).
61
- NODE="${MIRROR_NODE:-}"
62
- if [ -z "$NODE" ] || [ ! -x "$NODE" ]; then
63
- NODE="$(command -v node 2>/dev/null || true)"
64
- fi
65
- for candidate in "$(dirname "$ENTRY")/node" "$HOME/.nvm/current/bin/node" /opt/homebrew/bin/node /usr/local/bin/node; do
66
- [ -n "$NODE" ] && break
67
- [ -x "$candidate" ] && NODE="$candidate"
68
- done
69
-
70
- if [ -z "$NODE" ]; then
71
- note "node not found on PATH; hook skipped. Set MIRROR_NODE."
72
- exit 0
73
- fi
74
-
75
- # Not `exec`: the entry exits 0 whatever happens inside it, so a non-zero exit
76
- # means Node itself could not run the hook -- too old for the loader shim, or
77
- # it crashed. That used to vanish into a stderr no runtime shows (TS5 handoff
78
- # review, finding N1). No flags: the entry reads configuration and silences
79
- # its own warnings (US3, D3).
80
- "$NODE" "$ENTRY" "$HOOK" "$@"
81
- status=$?
82
- if [ "$status" -ne 0 ]; then
83
- note "node exited $status before the hook finished ($NODE, $("$NODE" --version 2>/dev/null || echo 'version unknown')); Mirror needs Node 24 or later. Set MIRROR_NODE."
84
- fi
85
- exit 0
@@ -1,48 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Run Codex with Mirror Mind logging around it.
3
- #
4
- # Codex has no hook system, so this wraps the `codex` command: session start
5
- # before it, and after it the JSONL Codex wrote is imported, the session is
6
- # closed, and a silent backup is taken.
7
- #
8
- # Every Mirror call goes through a generated hook wrapper under
9
- # scripts/codex-hooks/, the way every other runtime's hooks do (CV22.DS10.TS5
10
- # handoff review, finding N3). The wrappers resolve Node explicitly, never fail
11
- # the session, and record anything they could not do in <mirror home>/hooks.log.
12
- # This script used to call the front door itself, as a command held in a string
13
- # that a checkout path with a space split in two -- silently.
14
- set -euo pipefail
15
-
16
- HOOKS="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)/codex-hooks"
17
-
18
- # The marker's mtime is how the session this run wrote is told from older ones.
19
- MARKER="$(mktemp)"
20
- trap 'rm -f "$MARKER"' EXIT
21
-
22
- cd "${CODEX_PROJECT_DIR:-$PWD}"
23
-
24
- # 1. Session start.
25
- bash "$HOOKS/session-start.sh" </dev/null >/dev/null 2>&1 || true
26
-
27
- # 2. Codex itself, until the user exits. `set -e` is off around it so the
28
- # wrap-up below still runs when Codex exits non-zero -- after an MCP startup
29
- # failure, for example -- and its exit code is still the script's.
30
- set +e
31
- codex "$@"
32
- EXIT_CODE=$?
33
- set -e
34
-
35
- # 3. The JSONL Codex wrote after the marker for this directory, if any:
36
- # ~/.codex/sessions/YYYY/MM/DD/rollout-<time>-<uuid>.jsonl.
37
- SESSION_JSONL="$(find ~/.codex/sessions -name "*.jsonl" -newer "$MARKER" \
38
- -exec grep -l "\"cwd\":\"$PWD\"" {} + 2>/dev/null | sort | tail -1 || true)"
39
- SESSION_ID=""
40
- if [[ -n "$SESSION_JSONL" ]]; then
41
- SESSION_ID="$(basename "$SESSION_JSONL" .jsonl \
42
- | grep -oE '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}' | tail -1 || true)"
43
- fi
44
-
45
- # 4. Import and close the session when there is one, then the silent backup.
46
- bash "$HOOKS/session-end.sh" "$SESSION_JSONL" "$SESSION_ID" </dev/null >/dev/null 2>&1 || true
47
-
48
- exit "$EXIT_CODE"
@@ -1,45 +0,0 @@
1
- // Codex hook entries (CV22.DS10.TS5 handoff review, finding N3).
2
- //
3
- // Codex has no hook system, so `scripts/codex-mirror.sh` wraps the `codex`
4
- // command itself and calls these through two generated wrappers under
5
- // `scripts/codex-hooks/`. Until the handoff review the script called the front
6
- // door directly: it found `node` on PATH alone, silenced every failure, and
7
- // built its command as a string that a checkout path with a space split in
8
- // two. Going through the wrappers gives it the same Node resolution and the
9
- // same hooks.log record as every other runtime.
10
- //
11
- // The payload comes as arguments, not stdin: the wrapper, not a runtime,
12
- // decides what to pass, and a path is safer as one quoted argument than
13
- // embedded in hand-written JSON.
14
-
15
- import { runFrontDoorQuietly } from "./runtime.ts";
16
-
17
- /** Wrapper start: make sure logging is on for this session. */
18
- export async function codexSessionStart(): Promise<number> {
19
- await runFrontDoorQuietly("codex:session-start", ["conversation-logger", "session-start"]);
20
- return 0;
21
- }
22
-
23
- /**
24
- * Wrapper exit: import the session Codex wrote, close it, then take the silent
25
- * backup. The transcript and its session id are both absent when Codex wrote
26
- * no session for this directory; the backup runs either way, as it always has.
27
- */
28
- export async function codexSessionEnd(transcriptPath: string, sessionId: string): Promise<number> {
29
- if (transcriptPath && sessionId) {
30
- await runFrontDoorQuietly("codex:session-end", [
31
- "conversation-logger",
32
- "backfill-codex-session",
33
- transcriptPath,
34
- "--interface",
35
- "codex",
36
- ]);
37
- await runFrontDoorQuietly("codex:session-end", [
38
- "conversation-logger",
39
- "session-end-pi",
40
- sessionId,
41
- ]);
42
- }
43
- await runFrontDoorQuietly("codex:session-end", ["backup", "--silent"]);
44
- return 0;
45
- }