forge-orkes 0.63.0 → 0.64.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.
Files changed (23) hide show
  1. package/package.json +1 -1
  2. package/template/.claude/hooks/forge-release-fold.sh +9 -1
  3. package/template/.claude/skills/jarvis/SKILL.md +204 -0
  4. package/template/.forge/checks/forge-board-render.sh +11 -5
  5. package/template/.forge/checks/forge-jarvis-answer.sh +79 -0
  6. package/template/.forge/checks/forge-jarvis-awareness.sh +128 -0
  7. package/template/.forge/checks/forge-jarvis-bridge-clean.sh +130 -0
  8. package/template/.forge/checks/forge-jarvis-dispatch.sh +176 -0
  9. package/template/.forge/checks/forge-jarvis-instruments.sh +146 -0
  10. package/template/.forge/checks/forge-jarvis-notify-logonly.sh +40 -0
  11. package/template/.forge/checks/forge-jarvis-promote.sh +103 -0
  12. package/template/.forge/checks/forge-jarvis-prwatch.sh +92 -0
  13. package/template/.forge/checks/forge-jarvis-relay.sh +215 -0
  14. package/template/.forge/checks/forge-jarvis.sh +160 -0
  15. package/template/.forge/checks/tests/forge-jarvis-answer.test.sh +75 -0
  16. package/template/.forge/checks/tests/forge-jarvis-bridge-clean.test.sh +94 -0
  17. package/template/.forge/checks/tests/forge-jarvis-dispatch.test.sh +162 -0
  18. package/template/.forge/checks/tests/forge-jarvis-instruments.test.sh +64 -0
  19. package/template/.forge/checks/tests/forge-jarvis-promote.test.sh +102 -0
  20. package/template/.forge/checks/tests/forge-jarvis-prwatch.test.sh +66 -0
  21. package/template/.forge/checks/tests/forge-jarvis-relay.test.sh +135 -0
  22. package/template/.forge/checks/tests/forge-jarvis.test.sh +122 -0
  23. package/template/.forge/templates/project.yml +11 -0
@@ -0,0 +1,176 @@
1
+ #!/usr/bin/env sh
2
+ # forge-jarvis-dispatch.sh --slice <worktree> [runner args...] [--dry-run]
3
+ # (m-37, Brief-R2 step 4 B3; contract handoff-step4-jarvis.md REV2)
4
+ #
5
+ # On the operator's "go", Jarvis dispatches the slice runner DETACHED so the build
6
+ # survives Jarvis's death (B1 probe viii: nohup-&). This helper owns ONLY the caller-side
7
+ # environment — the runner loop is UNTOUCHED (the "no runner changes" boundary; the runner's
8
+ # swappable seams are used exactly as designed).
9
+ #
10
+ # WHAT IT SETS (and nothing else):
11
+ # FORGE_SLICE_NOTIFY_LOG → INTO the slice worktree (<worktree>/.forge/runner-work/notify.log),
12
+ # never the invoker's cwd. The default would land the log in the
13
+ # MAIN checkout (one shared file, invisible to the worktree glob,
14
+ # dirtying step 0's clean-main invariant). This is the path the B4
15
+ # relay derives per slice from its worktree glob. (acceptance #5)
16
+ # FORGE_SLICE_NOTIFY → the LOG-ONLY channel (forge-jarvis-notify-logonly.sh), so the
17
+ # default channel's per-ping headless `claude -p` push stays quiet
18
+ # — under a live relay, delivery is the relay's job; a live default
19
+ # channel would risk a double-buzz (B1 probe x). Explicit + portable
20
+ # (FR-197): true regardless of the ambient auth shape.
21
+ #
22
+ # MODEL MAP — PASSED THROUGH UNTOUCHED (FR-198, boundary "No routing"): the runner reads
23
+ # config.model_by_phase_type from its CONFIG (the step-5 seam — read, not routed). This helper
24
+ # forwards every runner arg (incl. --config) VERBATIM and carries NO model-selection logic. If
25
+ # this dispatch ever starts choosing models, STOP — routing is step 5.
26
+ #
27
+ # All non-flag args are forwarded to the runner unchanged (--slice <worktree>, and optionally
28
+ # --work-dir / --config / --schema / --report-template — whatever the runner accepts). The only
29
+ # arg this helper consumes for itself is --dry-run.
30
+ #
31
+ # --dry-run print the exact `nohup env ... runner ...` command + env on stdout and exit 0;
32
+ # never dispatches. Use it to show the operator what "go" will run.
33
+ #
34
+ # WORK-ORDER MATERIALIZATION (FR-197; walk run 4, 2026-07-22). The runner's contract
35
+ # (consumed, never edited) is <worktree>/slice.yml listing phase names, each resolving to
36
+ # <worktree>/phases/<name>/plan.md — but the Forge intake act writes plans under
37
+ # .forge/phases/milestone-{id}/{phase}-{name}/plan-NN.md, and nothing bridged the two: the
38
+ # observed failure was a clean dispatch whose runner refused instantly ('no slice.yml'), the
39
+ # refusal visible only in dispatch.out — the operator's phone stayed silent. So before the
40
+ # detach this helper MATERIALIZES the work order from the milestone's locked plans (slice.yml
41
+ # in phase order + phases/<name>/plan.md concatenated from that phase's plan-NN.md files), and
42
+ # REFUSES LOUDLY AND SYNCHRONOUSLY when it cannot — the failure surface is this exit code, not
43
+ # a silent phone. An existing slice.yml is honored untouched (a hand-authored work order wins).
44
+ # --materialize-only materialize (or refuse) and exit — no dispatch. Test hook + operator tool.
45
+ set -u
46
+
47
+ SELF_DIR="$(cd "$(dirname "$0")" && pwd)"
48
+ REPO_ROOT="$(cd "$SELF_DIR/../.." && pwd)" # .forge/checks → repo root
49
+ RUNNER="$REPO_ROOT/.claude/hooks/forge-slice-runner.sh" # the slice runner (consumed, never edited)
50
+ CHANNEL="$SELF_DIR/forge-jarvis-notify-logonly.sh" # the log-only channel (sibling)
51
+
52
+ # --- parse args: consume --dry-run; extract --slice; forward everything else verbatim -------
53
+ # POSIX count-guard idiom: shift originals off the front, re-append forwarded args to the back;
54
+ # when the original count hits 0, "$@" holds exactly the forwarded runner args (spaces safe).
55
+ DRY_RUN=0
56
+ MAT_ONLY=0
57
+ WORKTREE=""
58
+ argc=$#
59
+ while [ "$argc" -gt 0 ]; do
60
+ arg="$1"; shift; argc=$((argc - 1))
61
+ case "$arg" in
62
+ --dry-run)
63
+ DRY_RUN=1 ;; # ours — not forwarded
64
+ --materialize-only)
65
+ MAT_ONLY=1 ;; # ours — not forwarded
66
+ --slice)
67
+ WORKTREE="${1:-}"; shift; argc=$((argc - 1))
68
+ set -- "$@" --slice "$WORKTREE" ;; # forward it too (runner needs it)
69
+ *)
70
+ set -- "$@" "$arg" ;; # forward verbatim
71
+ esac
72
+ done
73
+
74
+ [ -n "$WORKTREE" ] || { printf 'forge-jarvis-dispatch: --slice <worktree> is required\n' >&2; exit 2; }
75
+ [ -d "$WORKTREE" ] || { printf 'forge-jarvis-dispatch: slice worktree not found: %s\n' "$WORKTREE" >&2; exit 2; }
76
+ WORKTREE="$(cd "$WORKTREE" && pwd)" # absolutize — the log path must be stable
77
+
78
+ [ -f "$RUNNER" ] || { printf 'forge-jarvis-dispatch: runner not found: %s\n' "$RUNNER" >&2; exit 2; }
79
+ [ -f "$CHANNEL" ] || { printf 'forge-jarvis-dispatch: log-only channel not found: %s\n' "$CHANNEL" >&2; exit 2; }
80
+
81
+ # --- materialize the work order from the milestone's locked plans (FR-197) -------------------
82
+ # slice.yml present → honored untouched. Absent → build it from the single
83
+ # .forge/phases/milestone-*/ dir: one phases/<name>/plan.md per phase subdir (plan-NN.md
84
+ # concatenated in order), slice.yml listing the names numerically. Cannot → REFUSE, exit 2,
85
+ # BEFORE the detach — the caller sees it synchronously and must relay it to the operator.
86
+ materialize_work_order() {
87
+ if [ -f "$WORKTREE/slice.yml" ]; then
88
+ printf 'forge-jarvis-dispatch: slice.yml present — using it as-is\n' >&2
89
+ return 0
90
+ fi
91
+ # Prefer the worktree's OWN milestone — .forge/phases/ carries the repo's whole milestone
92
+ # history (32 dirs on the forge repo), so "the only milestone dir" is a fixture-world
93
+ # assumption. The Worktree Convention names the branch forge/{anchor} with anchor =
94
+ # {milestone-id}[-{session}]; derive the id and pick that milestone's dir.
95
+ _mdir=""
96
+ _branch="$(git -C "$WORKTREE" branch --show-current 2>/dev/null)"
97
+ case "$_branch" in
98
+ forge/m-*)
99
+ _anchor="${_branch#forge/m-}" # 40 | 40-a1b2c3d4 | R61-002
100
+ [ -d "$WORKTREE/.forge/phases/milestone-$_anchor" ] && _mdir="$WORKTREE/.forge/phases/milestone-$_anchor"
101
+ if [ -z "$_mdir" ]; then
102
+ _short="${_anchor%-*}" # strip one trailing -token (session suffix)
103
+ [ "$_short" != "$_anchor" ] && [ -d "$WORKTREE/.forge/phases/milestone-$_short" ] && _mdir="$WORKTREE/.forge/phases/milestone-$_short"
104
+ fi ;;
105
+ esac
106
+ # Fallback (non-git fixture dirs / unconventional branches): a SINGLE milestone dir is
107
+ # unambiguous; several without a branch-derived pick is a refusal, never a guess.
108
+ if [ -z "$_mdir" ]; then
109
+ _mdirs=0
110
+ for _d in "$WORKTREE"/.forge/phases/milestone-*; do
111
+ [ -d "$_d" ] || continue
112
+ _mdirs=$((_mdirs + 1)); _mdir="$_d"
113
+ done
114
+ if [ "$_mdirs" -eq 0 ]; then
115
+ printf 'forge-jarvis-dispatch: REFUSED — no slice.yml and no .forge/phases/milestone-*/ plans in %s; nothing to dispatch. Plan the slice first. RELAY this refusal to the operator.\n' "$WORKTREE" >&2
116
+ return 2
117
+ fi
118
+ if [ "$_mdirs" -gt 1 ]; then
119
+ printf 'forge-jarvis-dispatch: REFUSED — %s milestone plan dirs in %s and no forge/m-* branch to pick by; ambiguous work order. Write slice.yml explicitly. RELAY this refusal to the operator.\n' "$_mdirs" "$WORKTREE" >&2
120
+ return 2
121
+ fi
122
+ fi
123
+ _tmp="$WORKTREE/slice.yml.tmp"
124
+ printf '# Materialized by forge-jarvis-dispatch from %s (delete to re-materialize)\nphases:\n' "${_mdir#"$WORKTREE"/}" > "$_tmp"
125
+ _count=0
126
+ for _p in $(ls "$_mdir" 2>/dev/null | sort -n); do
127
+ [ -d "$_mdir/$_p" ] || continue
128
+ _plans="$(ls "$_mdir/$_p"/plan-*.md 2>/dev/null | sort)"
129
+ [ -n "$_plans" ] || continue
130
+ mkdir -p "$WORKTREE/phases/$_p"
131
+ # shellcheck disable=SC2086
132
+ cat $_plans > "$WORKTREE/phases/$_p/plan.md"
133
+ printf ' - %s\n' "$_p" >> "$_tmp"
134
+ _count=$((_count + 1))
135
+ done
136
+ if [ "$_count" -eq 0 ]; then
137
+ rm -f "$_tmp"
138
+ printf 'forge-jarvis-dispatch: REFUSED — %s has no phase plans (plan-*.md); nothing to dispatch. RELAY this refusal to the operator.\n' "$_mdir" >&2
139
+ return 2
140
+ fi
141
+ mv "$_tmp" "$WORKTREE/slice.yml"
142
+ printf 'forge-jarvis-dispatch: materialized slice.yml (%s phase(s)) from %s\n' "$_count" "${_mdir#"$WORKTREE"/}" >&2
143
+ return 0
144
+ }
145
+
146
+ # --- caller-side env (the two seams; nothing else) ------------------------------------------
147
+ LOG="$WORKTREE/.forge/runner-work/notify.log" # INTO the slice worktree (B4 derives this)
148
+
149
+ if [ "$DRY_RUN" = "1" ]; then
150
+ # Side-effect-free: report work-order state to stderr, print the command to stdout.
151
+ if [ -f "$WORKTREE/slice.yml" ]; then
152
+ printf 'forge-jarvis-dispatch: (dry-run) slice.yml present — will be used as-is\n' >&2
153
+ else
154
+ printf 'forge-jarvis-dispatch: (dry-run) no slice.yml — a real dispatch materializes it from .forge/phases/milestone-*/\n' >&2
155
+ fi
156
+ # Print exactly what would run — greppable: worktree-scoped log, log-only channel, nohup, forwarded args.
157
+ printf 'nohup env FORGE_SLICE_NOTIFY_LOG=%s FORGE_SLICE_NOTIFY=%s %s' "$LOG" "$CHANNEL" "$RUNNER"
158
+ for a in "$@"; do printf ' %s' "$a"; done
159
+ printf ' >%s 2>&1 &\n' "$WORKTREE/.forge/runner-work/dispatch.out"
160
+ exit 0
161
+ fi
162
+
163
+ if [ "$MAT_ONLY" = "1" ]; then
164
+ materialize_work_order; exit $?
165
+ fi
166
+
167
+ materialize_work_order || exit 2
168
+
169
+ # --- dispatch DETACHED (nohup-& — survives Jarvis's death, B1 probe viii) --------------------
170
+ mkdir -p "$WORKTREE/.forge/runner-work" 2>/dev/null || true
171
+ printf 'forge-jarvis-dispatch: dispatching runner for %s (detached)\n' "$WORKTREE" >&2
172
+ nohup env FORGE_SLICE_NOTIFY_LOG="$LOG" FORGE_SLICE_NOTIFY="$CHANNEL" \
173
+ "$RUNNER" "$@" >"$WORKTREE/.forge/runner-work/dispatch.out" 2>&1 &
174
+
175
+ printf 'forge-jarvis-dispatch: dispatched (pid %s); notify log → %s\n' "$!" "$LOG" >&2
176
+ exit 0
@@ -0,0 +1,146 @@
1
+ #!/usr/bin/env sh
2
+ # forge-jarvis-instruments.sh — the week's DIRECTION-TEST numbers, derived from what B4 already
3
+ # wrote: the notify logs + relay markers. NO new store (m-37 B5 instruments; FR-205; NFR-036).
4
+ #
5
+ # Risk 1 (contract): did the front door REDUCE operator touches, or just RELOCATE them? These four
6
+ # numbers are how we would tell, measured from existing artifacts ONLY (no instrumentation added):
7
+ # 1. PINGS RELAYED BY TYPE — how many buzzes, of what kind (ambiguity / fork / irreversible /
8
+ # budget / done / halt). Only RELAYED pings count (a marker exists).
9
+ # 2. RELAY LATENCY — log-line emit-time → marker relay-time, per ping (mean + max secs).
10
+ # 3. DISCREPANCY COUNT — how often B4(c) host-verification caught a payload's state claim
11
+ # disagreeing with the host (the standing lesson, counted).
12
+ # 4. PRESENCE PROXY — pings relayed LIVE vs pings that landed while the relay was down
13
+ # (relayed late, on catch-up). Uptime here is a PROXY derived from
14
+ # relay latency, NOT an uptime store: a ping whose relay lagged past
15
+ # --live-window seconds is counted "landed while away". Labelled a
16
+ # proxy in the output so it is never read as a measured SLA.
17
+ #
18
+ # SOURCES (read-only): each slice's <worktree>/.forge/runner-work/notify.log (TSV
19
+ # emit-ts<TAB>type<TAB>payload) and its sibling relay-markers/<offset>.relayed
20
+ # (relay-ts<TAB>offset=N<TAB>relay-text). A marker's offset (line number) joins it to its log line.
21
+ # Nothing is written; the numbers are a pure function of the existing markers + logs.
22
+ #
23
+ # forge-jarvis-instruments.sh [--log <notify.log> ...] [--marker-dir <dir>] \
24
+ # [--live-window <sec>] [--since <ISO-Z>] [--worktree-root <dir>] [--dry-run]
25
+ # (no --log) disk-glob live slice worktrees (git worktree list, forge/m-*) for their logs.
26
+ # --marker-dir override the marker dir (default: sibling relay-markers/ of each log).
27
+ # --live-window seconds under which a relay counts LIVE (default 120).
28
+ # --since only count pings emitted at/after this ISO-Z timestamp (default: all).
29
+ # --worktree-root glob this dir for slice worktrees instead of `git worktree list` (tests).
30
+ # --dry-run print the resolved logs/markers and exit (plumbing check).
31
+ # Portable date (BSD then GNU) so latency math works on macOS and Linux.
32
+ set -u
33
+
34
+ SELF_DIR="$(cd "$(dirname "$0")" && pwd)"
35
+ REPO_ROOT="$(cd "$SELF_DIR/../.." && pwd)"
36
+
37
+ LOGS=""
38
+ MARKER_DIR_OVERRIDE=""
39
+ LIVE_WINDOW=120
40
+ SINCE=""
41
+ WT_ROOT=""
42
+ DRY_RUN=0
43
+ while [ $# -gt 0 ]; do
44
+ case "$1" in
45
+ --log) LOGS="${LOGS}${LOGS:+
46
+ }${2:-}"; shift 2 ;;
47
+ --marker-dir) MARKER_DIR_OVERRIDE="${2:-}"; shift 2 ;;
48
+ --live-window) LIVE_WINDOW="${2:-120}"; shift 2 ;;
49
+ --since) SINCE="${2:-}"; shift 2 ;;
50
+ --worktree-root) WT_ROOT="${2:-}"; shift 2 ;;
51
+ --dry-run) DRY_RUN=1; shift ;;
52
+ *) shift ;;
53
+ esac
54
+ done
55
+
56
+ # ISO-8601 Z → epoch seconds; empty on failure (GNU `date -d` then BSD `date -j -f`).
57
+ to_epoch() { # to_epoch <iso-z>
58
+ _t="${1:-}"; [ -n "$_t" ] || return 1
59
+ date -u -d "$_t" +%s 2>/dev/null || date -u -j -f '%Y-%m-%dT%H:%M:%SZ' "$_t" +%s 2>/dev/null
60
+ }
61
+
62
+ # ── resolve the log set: explicit --log wins; else disk-glob live slice worktrees ────────────────
63
+ if [ -z "$LOGS" ]; then
64
+ if [ -n "$WT_ROOT" ]; then
65
+ for _wt in "$WT_ROOT"/*/; do
66
+ [ -d "$_wt" ] || continue
67
+ _l="${_wt}.forge/runner-work/notify.log"
68
+ [ -f "$_l" ] && LOGS="${LOGS}${LOGS:+
69
+ }$_l"
70
+ done
71
+ else
72
+ _globbed="$(git -C "$REPO_ROOT" worktree list --porcelain 2>/dev/null | awk '
73
+ /^worktree / { p = $2 }
74
+ /^branch / { if ($2 ~ /refs\/heads\/forge\/m-/) print p "/.forge/runner-work/notify.log" }')"
75
+ for _l in $_globbed; do
76
+ [ -f "$_l" ] && LOGS="${LOGS}${LOGS:+
77
+ }$_l"
78
+ done
79
+ fi
80
+ fi
81
+
82
+ if [ "$DRY_RUN" -eq 1 ]; then
83
+ printf 'forge-jarvis-instruments (--dry-run): resolved logs:\n'
84
+ if [ -n "$LOGS" ]; then printf '%s\n' "$LOGS" | sed 's/^/ /'; else printf ' (none)\n'; fi
85
+ exit 0
86
+ fi
87
+
88
+ # ── build one record per RELAYED ping: type, latency_sec, live(1/0), discrepancy(1/0) ────────────
89
+ TMP="$(mktemp)"; trap 'rm -f "$TMP"' EXIT INT TERM
90
+ _since_epoch=""; [ -n "$SINCE" ] && _since_epoch="$(to_epoch "$SINCE")"
91
+
92
+ printf '%s\n' "$LOGS" | while IFS= read -r LOG; do
93
+ [ -n "$LOG" ] && [ -f "$LOG" ] || continue
94
+ MK="$MARKER_DIR_OVERRIDE"; [ -n "$MK" ] || MK="$(dirname "$LOG")/relay-markers"
95
+ _n=0
96
+ while IFS= read -r _line || [ -n "$_line" ]; do
97
+ _n=$((_n + 1))
98
+ _emit="$(printf '%s' "$_line" | cut -f1)"
99
+ _type="$(printf '%s' "$_line" | cut -f2)"
100
+ if [ -n "$_since_epoch" ]; then
101
+ _e="$(to_epoch "$_emit")"
102
+ { [ -n "$_e" ] && [ "$_e" -lt "$_since_epoch" ]; } && continue
103
+ fi
104
+ _marker="$MK/$_n.relayed"
105
+ [ -f "$_marker" ] || continue # only RELAYED pings carry instruments data
106
+ _relayts="$(cut -f1 "$_marker" 2>/dev/null)"
107
+ _text="$(cut -f3- "$_marker" 2>/dev/null)"
108
+ _ee="$(to_epoch "$_emit")"; _re="$(to_epoch "$_relayts")"
109
+ if [ -n "$_ee" ] && [ -n "$_re" ]; then _lat=$((_re - _ee)); else _lat=-1; fi
110
+ if [ "$_lat" -ge 0 ] && [ "$_lat" -le "$LIVE_WINDOW" ]; then _live=1; else _live=0; fi
111
+ case "$_text" in
112
+ *DISCREPANCY*|*"could NOT be verified"*) _disc=1 ;;
113
+ *) _disc=0 ;;
114
+ esac
115
+ printf '%s\t%s\t%s\t%s\n' "$_type" "$_lat" "$_live" "$_disc" >> "$TMP"
116
+ done < "$LOG"
117
+ done
118
+
119
+ # ── emit the four numbers ────────────────────────────────────────────────────────────────────────
120
+ _total="$(wc -l < "$TMP" 2>/dev/null | tr -d ' ')"; [ -n "$_total" ] || _total=0
121
+
122
+ printf '── Jarvis week-zero instruments (from relay markers + notify logs) ──\n\n'
123
+
124
+ printf '1. Pings relayed by type (%s total):\n' "$_total"
125
+ if [ "$_total" -gt 0 ]; then
126
+ cut -f1 "$TMP" | sort | uniq -c | while read -r _c _t; do
127
+ printf ' %-14s %s\n' "$_t" "$_c"
128
+ done
129
+ else
130
+ printf ' (no relayed pings in range)\n'
131
+ fi
132
+
133
+ awk -F'\t' -v total="$_total" -v win="$LIVE_WINDOW" '
134
+ { if ($2 + 0 >= 0) { s += $2; n++; if ($2 + 0 > mx) mx = $2 }
135
+ live += $3; disc += $4 }
136
+ END {
137
+ mean = (n > 0) ? s / n : 0
138
+ printf "2. Relay latency: mean %.1fs, max %ds (over %d timed ping(s); live window %ds)\n", mean, mx + 0, n + 0, win + 0
139
+ printf "3. Discrepancies caught (host-verification): %d\n", disc + 0
140
+ away = total - live
141
+ up = (total > 0) ? (live * 100.0 / total) : 0
142
+ printf "4. Presence proxy: %d/%d relayed live (%.0f%%); %d landed while away", live + 0, total + 0, up, away + 0
143
+ printf " (proxy — derived from relay latency, not an uptime store)\n"
144
+ }' "$TMP"
145
+
146
+ exit 0
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env sh
2
+ # forge-jarvis-notify-logonly.sh <type> <payload> — a LOG-ONLY notify channel for
3
+ # Jarvis-dispatched slices (m-37, Brief-R2 step 4 B3; contract handoff-step4-jarvis.md REV2).
4
+ #
5
+ # The default runner channel (.claude/hooks/forge-slice-notify.sh) does TWO things per
6
+ # ping: (1) append it to the durable log, and (2) a best-effort headless `claude -p`
7
+ # PushNotification micro-call. Under a live Jarvis relay (B4), delivery to the phone is the
8
+ # RELAY's job — the Monitor `tail -F` on this log IS the delivery path. Running the default
9
+ # channel's own push in parallel risks a double-buzz (B1 probe x). So a Jarvis dispatch
10
+ # points FORGE_SLICE_NOTIFY at THIS channel, which does step (1) ONLY.
11
+ #
12
+ # Why an EXPLICIT channel and not just "the keychain box has no exported token so the
13
+ # default is already quiet": that quiet is ambient (it depends on CLAUDE_CODE_OAUTH_TOKEN /
14
+ # ANTHROPIC_API_KEY being unset). On a box where a token IS exported, the default WOULD
15
+ # push and double-buzz. Pointing at this channel makes log-only EXPLICIT and PORTABLE
16
+ # (FR-197) — the relay is the one delivery path regardless of the ambient auth shape.
17
+ #
18
+ # This is the runner's swappable channel seam used exactly as designed: the runner is
19
+ # UNTOUCHED; the caller (forge-jarvis-dispatch.sh) owns the env. The log FORMAT is identical
20
+ # to the default channel (same tab-separated timestamp/type/payload) so the log is uniform
21
+ # whichever channel wrote a line — the relay parses one format.
22
+ #
23
+ # BEST-EFFORT by contract (same as the default channel): exit 0 even if the log write
24
+ # fails — the runner treats a non-zero exit as a best-effort miss, never a slice failure.
25
+ #
26
+ # type/payload: the runner calls `$FORGE_SLICE_NOTIFY <type> <payload>`; the type is one of
27
+ # the §8 surface (ambiguity | irreversible | fork | budget | done) plus `halt`.
28
+ set -u
29
+
30
+ TYPE="${1:-note}"
31
+ PAYLOAD="${2:-}"
32
+
33
+ # Durable local record — the ONLY thing this channel does. Default location travels with
34
+ # the slice (FORGE_SLICE_WORK_DIR), but a Jarvis dispatch always sets FORGE_SLICE_NOTIFY_LOG
35
+ # explicitly INTO the slice worktree.
36
+ LOG="${FORGE_SLICE_NOTIFY_LOG:-${FORGE_SLICE_WORK_DIR:-.}/notify.log}"
37
+ mkdir -p "$(dirname "$LOG")" 2>/dev/null || true
38
+ printf '%s\t%s\t%s\n' "$(date -u '+%Y-%m-%dT%H:%M:%SZ' 2>/dev/null || echo now)" "$TYPE" "$PAYLOAD" >> "$LOG" 2>/dev/null || true
39
+
40
+ exit 0
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env sh
2
+ # forge-jarvis-promote.sh — the promotion VOICE (m-37, Brief-R2 step 4 B6; contract
3
+ # handoff-step4-jarvis.md REV2; FR-208; NFR-038; operator ruling 3 "trigger-not-approve").
4
+ #
5
+ # The operator says "promote <sha>". Jarvis does exactly two things, in order:
6
+ # 1. SHOW what that SHA carries — recomputed from HOST truth (the board projection + the
7
+ # fold), never a session's word. The merged-but-not-yet-validated units are the ones a
8
+ # promotion covers, by CONTAINMENT: a unit becomes validated when its landed SHA is an
9
+ # ancestor of the signed promotion tag's commit (ADR-024) — verified offline, host-side.
10
+ # 2. TRIGGER the step-2 seam: gh workflow run promote.yml -f sha=<full-sha>
11
+ #
12
+ # That is ALL it does. It NEVER approves, waives, or lowers anything: the flow STOPS at
13
+ # GitHub's Environment gates (both taps: deploy + mint) until the operator presses there.
14
+ # Triggering is not approving — the approval is not Jarvis's to give (operator ruling 3).
15
+ # There is deliberately NO Environment-approval call anywhere in this file; the neg-control in
16
+ # the test suite greps this file to prove it (an approval path would fail the acceptance test).
17
+ #
18
+ # forge-jarvis-promote.sh <full-sha> [--dry-run]
19
+ # <full-sha> the full 40-hex deploy SHA. The promotion tag is promotion/<full-sha>
20
+ # (FROZEN with the operator); a short sha is refused — containment needs the
21
+ # full one, and Jarvis never invents or truncates a sha.
22
+ # --dry-run SHOW host state, then PRINT the trigger command without running it.
23
+ #
24
+ # HOST-TRUTH commands (env-overridable so tests inject stubs and degradation is explicit):
25
+ # FORGE_JARVIS_BOARD default .forge/checks/forge-board-render.sh (the rollup projection)
26
+ # FORGE_JARVIS_FOLD default .claude/hooks/forge-release-fold.sh (per-unit release_state)
27
+ # FORGE_JARVIS_GH default `gh` (the trigger — never an approval)
28
+ # BEST-EFFORT: a missing board/fold degrades to a stated '(unavailable)' — the show still
29
+ # renders; a missing gh in a real (non-dry-run) trigger is a clear error, never a silent success.
30
+ set -u
31
+
32
+ SELF_DIR="$(cd "$(dirname "$0")" && pwd)"
33
+ REPO_ROOT="$(cd "$SELF_DIR/../.." && pwd)" # .forge/checks → repo root
34
+ BOARD="${FORGE_JARVIS_BOARD:-$REPO_ROOT/.forge/checks/forge-board-render.sh}"
35
+ FOLD="${FORGE_JARVIS_FOLD:-$REPO_ROOT/.claude/hooks/forge-release-fold.sh}"
36
+ GH="${FORGE_JARVIS_GH:-gh}"
37
+ WORKFLOW="promote.yml"
38
+
39
+ SHA=""
40
+ DRY_RUN=0
41
+ while [ $# -gt 0 ]; do
42
+ case "$1" in
43
+ --dry-run) DRY_RUN=1; shift ;;
44
+ --*) shift ;; # tolerate/ignore unknown flags
45
+ *) [ -z "$SHA" ] && SHA="$1"; shift ;;
46
+ esac
47
+ done
48
+
49
+ # ── refuse a missing or non-full sha (Jarvis never invents/truncates a sha) ─────────────────────
50
+ case "$SHA" in
51
+ "") printf 'forge-jarvis-promote: need a full deploy SHA — usage: forge-jarvis-promote.sh <full-sha> [--dry-run]\n' >&2; exit 2 ;;
52
+ esac
53
+ if ! printf '%s' "$SHA" | grep -qE '^[0-9a-f]{40}$'; then
54
+ printf 'forge-jarvis-promote: %s is not a full 40-hex SHA. Promotion validates by containment against promotion/<full-sha> — pass the full deploy SHA, not a short one.\n' "$SHA" >&2
55
+ exit 2
56
+ fi
57
+
58
+ # ── 1. SHOW what this SHA carries — host truth, recomputed now (never a session's claim) ─────────
59
+ printf '── Promote %s ────────────────────────────────────\n' "$SHA"
60
+ printf '\n> What this promotion covers (board projection — merged units validate by containment):\n'
61
+ if [ -f "$BOARD" ]; then
62
+ _emit="$(sh "$BOARD" --emit 2>/dev/null)"
63
+ if [ -n "$_emit" ]; then
64
+ # release-relevant units: merged (candidate -> validated) + validated (already covered).
65
+ # line-oriented JSON -> grep/sed, no jq (Article X native-first) — same parse as awareness.
66
+ _rel="$(printf '%s\n' "$_emit" | grep '"forge_id"' | grep -E '"release_state":[[:space:]]*"(merged|validated)"')"
67
+ if [ -n "$_rel" ]; then
68
+ printf '%s\n' "$_rel" \
69
+ | sed -E 's/.*"forge_id":[[:space:]]*"([^"]+)".*"release_state":[[:space:]]*"([^"]+)".*/ \1 release_state=\2/' \
70
+ | head -60
71
+ else
72
+ printf ' (no merged units in the board projection — nothing waiting on a promotion)\n'
73
+ fi
74
+ else
75
+ printf ' (board projection unavailable — degraded, not fatal)\n'
76
+ fi
77
+ else
78
+ printf ' (forge-board-render.sh not found — projection unavailable)\n'
79
+ fi
80
+ printf '\n Validation is by CONTAINMENT: each merged unit becomes validated when its landed SHA is an\n'
81
+ printf ' ancestor of the signed promotion/%s tag commit (ADR-024) — host-verified offline, not a claim.\n' "$SHA"
82
+
83
+ # ── 2. TRIGGER the step-2 seam — and STOP. Jarvis triggers; the operator presses the gates. ──────
84
+ CMD="$GH workflow run $WORKFLOW -f sha=$SHA"
85
+ printf '\n> Trigger (step-2 seam — Jarvis triggers; the operator presses GitHub Environment gates):\n'
86
+ if [ "$DRY_RUN" -eq 1 ]; then
87
+ printf ' [--dry-run] would run: %s\n' "$CMD"
88
+ exit 0
89
+ fi
90
+ if ! command -v "$GH" >/dev/null 2>&1; then
91
+ printf ' gh not found — cannot trigger the promotion. Run it from a host that has gh: %s\n' "$CMD" >&2
92
+ exit 3
93
+ fi
94
+ printf ' %s\n' "$CMD"
95
+ # gh workflow run promote.yml -f sha=<full-sha> — the trigger, never an approval call.
96
+ "$GH" workflow run "$WORKFLOW" -f sha="$SHA"
97
+ _rc=$?
98
+ if [ "$_rc" -eq 0 ]; then
99
+ printf '\n[ok] Triggered promote.yml for %s. It now STOPS at GitHub Environment gates — press them there; Jarvis does not.\n' "$SHA"
100
+ else
101
+ printf '\n[!] gh workflow run exited %s — the promotion was NOT triggered. Check the workflow name / host auth.\n' "$_rc" >&2
102
+ fi
103
+ exit "$_rc"
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env sh
2
+ # forge-jarvis-prwatch.sh — the bounded "merged, on staging — come try" watch
3
+ # (m-37, Brief-R2 step 4 B4(c); contract handoff-step4-jarvis.md REV2).
4
+ #
5
+ # The runner's `done` ping fires at PR-open; step-2 auto-merge + the staging deploy land minutes
6
+ # LATER, so that flagship "come try it" moment never appears in the notify log. This watch is the
7
+ # SECOND bounded source for it: on a `done`, poll `gh` for the PR's merge + staging-deploy state
8
+ # with a HARD bound and, on merge+deploy, emit the come-try text once.
9
+ #
10
+ # STRICTLY BOUNDED + self-terminating (NFR-036 / Fork 3): it stops on merge+deploy, on a closed
11
+ # PR, or when the iteration/wall bound is hit — it NEVER becomes a standing daemon and owns no
12
+ # durable state beyond the at-most-once come-try marker (keyed by PR number).
13
+ #
14
+ # HOST TRUTH ONLY: merge + deploy state come from `gh`, never from a build session's words
15
+ # (operator ruling 5). The gh binary is env-overridable (FORGE_JARVIS_GH) so fixtures drive tests.
16
+ #
17
+ # --pr <num> the PR to watch (required)
18
+ # --repo <owner/repo> default: the current repo (gh resolves it)
19
+ # --staging-env <name> deployment environment that means "on staging" (default: staging)
20
+ # --max-iterations <N> hard poll bound (default 30)
21
+ # --interval <seconds> sleep between polls (default 20; 0 = no sleep, for fixtures)
22
+ # --marker-dir <dir> where the at-most-once come-try marker lives (default: cwd/.relay-markers)
23
+ # --dry-run print the resolved plan (pr, repo, env, bound) and exit; no polling
24
+ set -u
25
+
26
+ PR=""; REPO=""; ENV_STAGING="staging"; MAX_ITER=30; INTERVAL=20; MARKER_DIR=""
27
+ GH="${FORGE_JARVIS_GH:-gh}"
28
+ DRY=0
29
+ while [ $# -gt 0 ]; do
30
+ case "$1" in
31
+ --pr) PR="${2:-}"; shift 2 ;;
32
+ --repo) REPO="${2:-}"; shift 2 ;;
33
+ --staging-env) ENV_STAGING="${2:-staging}"; shift 2 ;;
34
+ --max-iterations) MAX_ITER="${2:-30}"; shift 2 ;;
35
+ --interval) INTERVAL="${2:-20}"; shift 2 ;;
36
+ --marker-dir) MARKER_DIR="${2:-}"; shift 2 ;;
37
+ --dry-run) DRY=1; shift ;;
38
+ *) shift ;;
39
+ esac
40
+ done
41
+ [ -n "$PR" ] || { printf 'forge-jarvis-prwatch: --pr <num> is required\n' >&2; exit 2; }
42
+ [ -n "$MARKER_DIR" ] || MARKER_DIR="./.relay-markers"
43
+ REPO_ARG=""; [ -n "$REPO" ] && REPO_ARG="--repo $REPO"
44
+
45
+ if [ "$DRY" = 1 ]; then
46
+ printf 'prwatch plan: pr=%s repo=%s env=%s bound=%s×%ss marker-dir=%s\n' \
47
+ "$PR" "${REPO:-<current>}" "$ENV_STAGING" "$MAX_ITER" "$INTERVAL" "$MARKER_DIR"
48
+ exit 0
49
+ fi
50
+
51
+ # --- host-truth probes (gh only) -------------------------------------------------------------
52
+ # The two probes are literal gh queries (env-overridable via $GH for fixtures):
53
+ # merge state → `gh pr view <num> --json state --jq .state`
54
+ # staging deploy → `gh api repos/{owner}/{repo}/deployments?environment=<env>` + its statuses
55
+ # Both read host truth; neither consults anything a build session emitted.
56
+ pr_merge_state() { # → MERGED | CLOSED | OPEN (empty on gh error → treated as OPEN, keep polling)
57
+ # shellcheck disable=SC2086
58
+ "$GH" pr view "$PR" $REPO_ARG --json state --jq '.state' 2>/dev/null
59
+ }
60
+ deploy_succeeded() { # → exit 0 iff the latest staging deployment is in a success state
61
+ # shellcheck disable=SC2086
62
+ _st="$("$GH" api "repos/{owner}/{repo}/deployments?environment=$ENV_STAGING&per_page=1" \
63
+ --jq '.[0].statuses_url' 2>/dev/null)"
64
+ [ -n "$_st" ] || return 1
65
+ _s="$("$GH" api "$_st?per_page=1" --jq '.[0].state' 2>/dev/null)"
66
+ [ "$_s" = success ]
67
+ }
68
+
69
+ fire_come_try() { # at-most-once, keyed by PR (the ONE owned state class)
70
+ mkdir -p "$MARKER_DIR" 2>/dev/null || true
71
+ _mk="$MARKER_DIR/pr-$PR-cometry.relayed"
72
+ [ -f "$_mk" ] && return 0 # already fired — never re-buzz
73
+ _text="🚀 Merged, on staging — come try: PR #$PR is live on $ENV_STAGING."
74
+ printf '%s\toffset=pr-%s\t%s\n' "$(date -u '+%Y-%m-%dT%H:%M:%SZ' 2>/dev/null || echo now)" "$PR" "$_text" > "$_mk" 2>/dev/null || true
75
+ printf '%s\n' "$_text" # the skill fires PushNotification with this
76
+ }
77
+
78
+ # --- the bounded poll loop -------------------------------------------------------------------
79
+ i=0
80
+ while [ "$i" -lt "$MAX_ITER" ]; do
81
+ case "$(pr_merge_state)" in
82
+ MERGED)
83
+ if deploy_succeeded; then fire_come_try; exit 0; fi ;; # the come-try moment — fire + stop
84
+ CLOSED)
85
+ exit 0 ;; # closed without a live deploy — stop, no fire
86
+ *) : ;; # OPEN (or gh hiccup) — keep polling
87
+ esac
88
+ i=$((i + 1))
89
+ [ "$i" -lt "$MAX_ITER" ] && [ "$INTERVAL" -gt 0 ] && sleep "$INTERVAL"
90
+ done
91
+ # bound reached without a merge+deploy — self-terminate cleanly, no fire (never a daemon).
92
+ exit 0