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.
- package/package.json +1 -1
- package/template/.claude/hooks/forge-release-fold.sh +9 -1
- package/template/.claude/skills/jarvis/SKILL.md +204 -0
- package/template/.forge/checks/forge-board-render.sh +11 -5
- package/template/.forge/checks/forge-jarvis-answer.sh +79 -0
- package/template/.forge/checks/forge-jarvis-awareness.sh +128 -0
- package/template/.forge/checks/forge-jarvis-bridge-clean.sh +130 -0
- package/template/.forge/checks/forge-jarvis-dispatch.sh +176 -0
- package/template/.forge/checks/forge-jarvis-instruments.sh +146 -0
- package/template/.forge/checks/forge-jarvis-notify-logonly.sh +40 -0
- package/template/.forge/checks/forge-jarvis-promote.sh +103 -0
- package/template/.forge/checks/forge-jarvis-prwatch.sh +92 -0
- package/template/.forge/checks/forge-jarvis-relay.sh +215 -0
- package/template/.forge/checks/forge-jarvis.sh +160 -0
- package/template/.forge/checks/tests/forge-jarvis-answer.test.sh +75 -0
- package/template/.forge/checks/tests/forge-jarvis-bridge-clean.test.sh +94 -0
- package/template/.forge/checks/tests/forge-jarvis-dispatch.test.sh +162 -0
- package/template/.forge/checks/tests/forge-jarvis-instruments.test.sh +64 -0
- package/template/.forge/checks/tests/forge-jarvis-promote.test.sh +102 -0
- package/template/.forge/checks/tests/forge-jarvis-prwatch.test.sh +66 -0
- package/template/.forge/checks/tests/forge-jarvis-relay.test.sh +135 -0
- package/template/.forge/checks/tests/forge-jarvis.test.sh +122 -0
- package/template/.forge/templates/project.yml +11 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
#!/usr/bin/env sh
|
|
2
|
+
# forge-jarvis-relay.sh — the callback-relay CORE (m-37, Brief-R2 step 4 B4(a/b/c/e);
|
|
3
|
+
# contract handoff-step4-jarvis.md REV2). Turns one notify-log line into a relay
|
|
4
|
+
# decision: HOST-TRUTH recompute → typed relay text → at-most-once offset marker.
|
|
5
|
+
#
|
|
6
|
+
# The runner writes every §8 ping to a slice's notify.log (tab-separated
|
|
7
|
+
# `timestamp<TAB>type<TAB>payload`; forge-slice-notify.sh / -notify-logonly.sh). Under a
|
|
8
|
+
# live Jarvis, that log IS the event bus: the skill arms a Monitor `tail -F` on it and pipes
|
|
9
|
+
# each new line through THIS helper, then fires PushNotification with the returned text.
|
|
10
|
+
#
|
|
11
|
+
# THE LOAD-BEARING RULE (operator ruling 5): every relayed STATE claim (merged / landed /
|
|
12
|
+
# validated) is recomputed from HOST truth (the fold / gh / board) BEFORE relay — NEVER taken
|
|
13
|
+
# from the payload. A payload that claims what the host does not show relays the DISCREPANCY,
|
|
14
|
+
# loudly. A question (ambiguity) is relayed verbatim — it is a question, not a state claim.
|
|
15
|
+
#
|
|
16
|
+
# OWNED STATE (the ONE admitted class, NFR-036): durable marker files keyed by the log-line
|
|
17
|
+
# OFFSET (1-based line number — stable in an append-only log; the runner's internal ping-dedup
|
|
18
|
+
# keys never reach the log, F10). Marker present → already relayed → never re-buzz (at-most-once).
|
|
19
|
+
# Everything else Jarvis "knows" is recomputed; kill Jarvis and only the live connection + armed
|
|
20
|
+
# watches are lost — the markers on disk survive and re-drive the while-you-were-away catch-up.
|
|
21
|
+
#
|
|
22
|
+
# MODES
|
|
23
|
+
# --one "<tsv-line>" [--milestone m-N] pure text-builder: print the relay text for ONE
|
|
24
|
+
# line; NO marker, NO side effects (the unit tests hit).
|
|
25
|
+
# --scan <logfile> [--marker-dir <dir>] [--milestone m-N] [--mode live|catchup]
|
|
26
|
+
# stateful driver: relay every UNMARKED line, write
|
|
27
|
+
# its marker. live → one text line per new ping;
|
|
28
|
+
# catchup → ONE "while you were away" summary. Both
|
|
29
|
+
# write markers, so a line is relayed at-most-once.
|
|
30
|
+
# --audit-sources <?logfile> self-grep: fail if any state claim is sourced from
|
|
31
|
+
# the payload rather than fold/gh/board (acceptance #3).
|
|
32
|
+
#
|
|
33
|
+
# HOST-TRUTH COMMANDS (env-overridable so tests inject stubs, and so degradation is explicit):
|
|
34
|
+
# FORGE_JARVIS_FOLD default .claude/hooks/forge-release-fold.sh (release_state recompute)
|
|
35
|
+
# FORGE_JARVIS_GH default `gh` (PR/check facts — plan-02 leans on it)
|
|
36
|
+
# FORGE_JARVIS_BOARD default .forge/checks/forge-board-render.sh (rollup recompute)
|
|
37
|
+
#
|
|
38
|
+
# BEST-EFFORT: a fold/gh/board that is absent or errors degrades to release_state=unknown and
|
|
39
|
+
# says so — never a silent success, never a hard fail of the relay path.
|
|
40
|
+
set -u
|
|
41
|
+
|
|
42
|
+
SELF_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
43
|
+
REPO_ROOT="$(cd "$SELF_DIR/../.." && pwd)" # .forge/checks → repo root
|
|
44
|
+
FOLD="${FORGE_JARVIS_FOLD:-$REPO_ROOT/.claude/hooks/forge-release-fold.sh}"
|
|
45
|
+
|
|
46
|
+
# ── host truth: the slice's release_state, recomputed from the fold (never the payload) ───────
|
|
47
|
+
host_release_state() { # host_release_state <milestone-id> → prints unmerged|merged|validated|unknown
|
|
48
|
+
_mid="${1:-}"
|
|
49
|
+
[ -n "$_mid" ] || { printf 'unknown'; return 0; }
|
|
50
|
+
_out="$("$FOLD" "$_mid" 2>/dev/null)" || { printf 'unknown'; return 0; }
|
|
51
|
+
_rs="$(printf '%s\n' "$_out" | grep -m1 'release_state=' | sed 's/.*release_state=//; s/[[:space:]].*//')"
|
|
52
|
+
[ -n "$_rs" ] && printf '%s' "$_rs" || printf 'unknown'
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
# Does the payload TEXT assert a landing/merge/promotion? (only then can it contradict the host)
|
|
56
|
+
payload_claims_landed() { # payload_claims_landed <payload>
|
|
57
|
+
printf '%s' "${1:-}" | grep -qiE 'merged|landed|validated|promoted|on main|is live|shipped|deployed'
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
# ── build the relay text for ONE parsed ping (the pure host-truth text-builder) ───────────────
|
|
61
|
+
# Reads: $2=type $3=payload ; $MILESTONE (optional, for fold). Prints one line to stdout.
|
|
62
|
+
build_relay_text() { # build_relay_text <type> <payload>
|
|
63
|
+
_type="${1:-note}"; _payload="${2:-}"
|
|
64
|
+
case "$_type" in
|
|
65
|
+
ambiguity)
|
|
66
|
+
# A QUESTION — relay verbatim, named. Legal: it is not a state claim (acceptance #2).
|
|
67
|
+
printf '❓ Needs you (ambiguity): %s' "$_payload" ;;
|
|
68
|
+
fork)
|
|
69
|
+
# payload is a PATH to a sketch the operator LOOKS AT (§8) — name it.
|
|
70
|
+
printf '🎨 Design fork — review the sketch: %s' "$_payload" ;;
|
|
71
|
+
irreversible)
|
|
72
|
+
# a gate on an irreversible act — your call; relay verbatim, named.
|
|
73
|
+
printf '⚠️ Irreversible action — your call: %s' "$_payload" ;;
|
|
74
|
+
budget)
|
|
75
|
+
# the runner's OWN spend tally — no host source to recompute against; relay verbatim, named.
|
|
76
|
+
printf '💸 Budget cap reached: %s' "$_payload" ;;
|
|
77
|
+
done|halt)
|
|
78
|
+
# STATE-CLAIM territory. Recompute host truth FIRST; build the claim from it, not the payload.
|
|
79
|
+
_rs="$(host_release_state "${MILESTONE:-}")"
|
|
80
|
+
if [ "$_type" = done ]; then _base='✅ Slice done'; else _base='🛑 Slice HALTED'; fi
|
|
81
|
+
if payload_claims_landed "$_payload"; then
|
|
82
|
+
if [ "$_rs" = unmerged ]; then
|
|
83
|
+
# The standing lesson: payload says merged, host says not. Relay the host, loudly.
|
|
84
|
+
printf '⚠️ DISCREPANCY — payload claims landed/merged, but host shows release_state=unmerged. %s (host truth wins). Payload said: %s' "$_base" "$_payload"
|
|
85
|
+
elif [ "$_rs" = unknown ]; then
|
|
86
|
+
printf '⚠️ %s — payload claims landed/merged but the host could NOT be verified (release_state=unknown). Payload said: %s' "$_base" "$_payload"
|
|
87
|
+
else
|
|
88
|
+
# payload claims landed AND host agrees (merged/validated) — no discrepancy.
|
|
89
|
+
printf '%s — host confirms: release_state=%s. %s' "$_base" "$_rs" "$_payload"
|
|
90
|
+
fi
|
|
91
|
+
else
|
|
92
|
+
printf '%s — host: release_state=%s. %s' "$_base" "$_rs" "$_payload"
|
|
93
|
+
fi ;;
|
|
94
|
+
*)
|
|
95
|
+
# unknown type — relay raw, named (never silently drop).
|
|
96
|
+
printf '(%s): %s' "$_type" "$_payload" ;;
|
|
97
|
+
esac
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
# Parse a TSV log line (ts<TAB>type<TAB>payload) then build text. Prints one line.
|
|
101
|
+
relay_one_line() { # relay_one_line <tsv-line>
|
|
102
|
+
_line="$1"
|
|
103
|
+
_type="$(printf '%s' "$_line" | cut -f2)"
|
|
104
|
+
_payload="$(printf '%s' "$_line" | cut -f3-)"
|
|
105
|
+
# A malformed line with no tabs → cut returns the whole line for f2/f3; treat as a raw note.
|
|
106
|
+
case "$_line" in
|
|
107
|
+
*" "*) : ;; # has a tab — well-formed
|
|
108
|
+
*) _type='note'; _payload="$_line" ;;
|
|
109
|
+
esac
|
|
110
|
+
build_relay_text "$_type" "$_payload"
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
# ── mode dispatch ─────────────────────────────────────────────────────────────────────────────
|
|
114
|
+
MILESTONE=""
|
|
115
|
+
MODE_LIVE="live"
|
|
116
|
+
MARKER_DIR=""
|
|
117
|
+
|
|
118
|
+
case "${1:-}" in
|
|
119
|
+
--one)
|
|
120
|
+
shift
|
|
121
|
+
LINE="${1:-}"; shift 2>/dev/null || true
|
|
122
|
+
while [ $# -gt 0 ]; do case "$1" in --milestone) MILESTONE="${2:-}"; shift 2 ;; *) shift ;; esac; done
|
|
123
|
+
relay_one_line "$LINE"; printf '\n'
|
|
124
|
+
exit 0 ;;
|
|
125
|
+
|
|
126
|
+
--list-logs)
|
|
127
|
+
# The watch set the skill arms `tail -F` on — recomputed from a DISK GLOB on EVERY call,
|
|
128
|
+
# never held in memory (Amendment 2: kill Jarvis and the armed watches re-derive from disk).
|
|
129
|
+
# Live slices are worktrees on a forge/m-* branch; each runner writes to
|
|
130
|
+
# <worktree>/.forge/runner-work/notify.log (the dispatch's FORGE_SLICE_NOTIFY_LOG). Emit the
|
|
131
|
+
# EXPECTED path even when the log does not exist yet — `tail -F` (capital F) is chosen exactly
|
|
132
|
+
# so a not-yet-created log is picked up when the first ping lands (F8).
|
|
133
|
+
shift
|
|
134
|
+
WT_ROOT=""
|
|
135
|
+
while [ $# -gt 0 ]; do case "$1" in --worktree-root) WT_ROOT="${2:-}"; shift 2 ;; *) shift ;; esac; done
|
|
136
|
+
if [ -n "$WT_ROOT" ]; then
|
|
137
|
+
# override path (tests): disk-glob the given root for slice worktrees.
|
|
138
|
+
for _wt in "$WT_ROOT"/*/; do
|
|
139
|
+
[ -d "$_wt" ] || continue
|
|
140
|
+
printf '%s.forge/runner-work/notify.log\n' "$_wt"
|
|
141
|
+
done
|
|
142
|
+
else
|
|
143
|
+
# live path: `git worktree list` is the on-disk registry of worktrees; glob it to the
|
|
144
|
+
# forge/m-* slice branches and emit each slice's notify-log path.
|
|
145
|
+
git worktree list --porcelain 2>/dev/null | awk '
|
|
146
|
+
/^worktree / { p=$2 }
|
|
147
|
+
/^branch / { if ($2 ~ /refs\/heads\/forge\/m-/) print p "/.forge/runner-work/notify.log" }
|
|
148
|
+
'
|
|
149
|
+
fi
|
|
150
|
+
exit 0 ;;
|
|
151
|
+
|
|
152
|
+
--audit-sources)
|
|
153
|
+
# Static guard: the done/halt (state-claim) branch must recompute from the fold, and the
|
|
154
|
+
# authoritative release-state var must NEVER be assigned from the payload. Catches a future
|
|
155
|
+
# rewrite that sources a merge verdict from the session's own payload rather than host truth.
|
|
156
|
+
# The guard's own two grep lines carry a #@audit tag and are excluded from the scan so their
|
|
157
|
+
# literal patterns cannot self-match the file they scan.
|
|
158
|
+
_body="$(grep -vE '#@audit' "$0")"
|
|
159
|
+
if ! printf '%s\n' "$_body" | grep -qE 'host_release_state|FORGE_JARVIS_FOLD|forge-release-fold'; then #@audit
|
|
160
|
+
printf 'forge-jarvis-relay: AUDIT FAIL — no host-truth (fold) recompute in the relay path\n' >&2
|
|
161
|
+
exit 3
|
|
162
|
+
fi
|
|
163
|
+
if printf '%s\n' "$_body" | grep -qE '_rs=["'\''$]*_payload'; then #@audit
|
|
164
|
+
printf 'forge-jarvis-relay: AUDIT FAIL — a state claim is sourced from the payload, not the host\n' >&2
|
|
165
|
+
exit 3
|
|
166
|
+
fi
|
|
167
|
+
printf 'relay speaks host truth only\n'
|
|
168
|
+
exit 0 ;;
|
|
169
|
+
|
|
170
|
+
--scan)
|
|
171
|
+
shift
|
|
172
|
+
LOG="${1:-}"; shift 2>/dev/null || true
|
|
173
|
+
while [ $# -gt 0 ]; do
|
|
174
|
+
case "$1" in
|
|
175
|
+
--marker-dir) MARKER_DIR="${2:-}"; shift 2 ;;
|
|
176
|
+
--milestone) MILESTONE="${2:-}"; shift 2 ;;
|
|
177
|
+
--mode) MODE_LIVE="${2:-live}"; shift 2 ;;
|
|
178
|
+
*) shift ;;
|
|
179
|
+
esac
|
|
180
|
+
done
|
|
181
|
+
[ -n "$LOG" ] && [ -f "$LOG" ] || { printf 'forge-jarvis-relay: --scan needs an existing logfile\n' >&2; exit 2; }
|
|
182
|
+
[ -n "$MARKER_DIR" ] || MARKER_DIR="$(dirname "$LOG")/relay-markers"
|
|
183
|
+
mkdir -p "$MARKER_DIR" 2>/dev/null || true
|
|
184
|
+
|
|
185
|
+
_n=0; _fresh=0; _summary=""
|
|
186
|
+
# Read every line; relay only those whose offset (line number) has no marker yet.
|
|
187
|
+
while IFS= read -r _l || [ -n "$_l" ]; do
|
|
188
|
+
_n=$((_n + 1))
|
|
189
|
+
_marker="$MARKER_DIR/$_n.relayed"
|
|
190
|
+
[ -f "$_marker" ] && continue # at-most-once: already relayed, never re-buzz
|
|
191
|
+
_text="$(relay_one_line "$_l")"
|
|
192
|
+
# Write the marker BEFORE emitting — a crash after emit must not double-buzz; a crash
|
|
193
|
+
# before emit leaves it unmarked and it re-surfaces as while-you-were-away (no silent loss).
|
|
194
|
+
printf '%s\toffset=%s\t%s\n' "$(date -u '+%Y-%m-%dT%H:%M:%SZ' 2>/dev/null || echo now)" "$_n" "$_text" > "$_marker" 2>/dev/null || true
|
|
195
|
+
_fresh=$((_fresh + 1))
|
|
196
|
+
if [ "$MODE_LIVE" = catchup ]; then
|
|
197
|
+
_summary="${_summary}${_summary:+ | }$_text"
|
|
198
|
+
else
|
|
199
|
+
printf '%s\n' "$_text" # live: one relay text per new ping → one buzz
|
|
200
|
+
fi
|
|
201
|
+
done < "$LOG"
|
|
202
|
+
|
|
203
|
+
if [ "$MODE_LIVE" = catchup ] && [ "$_fresh" -gt 0 ]; then
|
|
204
|
+
printf '📨 While you were away — %s ping(s): %s\n' "$_fresh" "$_summary"
|
|
205
|
+
fi
|
|
206
|
+
# exit 0 whether or not anything was fresh (a no-op scan is success, not failure).
|
|
207
|
+
exit 0 ;;
|
|
208
|
+
|
|
209
|
+
*)
|
|
210
|
+
printf 'usage: forge-jarvis-relay.sh --one "<tsv-line>" [--milestone m-N]\n' >&2
|
|
211
|
+
printf ' forge-jarvis-relay.sh --scan <logfile> [--marker-dir <dir>] [--milestone m-N] [--mode live|catchup]\n' >&2
|
|
212
|
+
printf ' forge-jarvis-relay.sh --list-logs [--worktree-root <dir>]\n' >&2
|
|
213
|
+
printf ' forge-jarvis-relay.sh --audit-sources\n' >&2
|
|
214
|
+
exit 2 ;;
|
|
215
|
+
esac
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
#!/usr/bin/env sh
|
|
2
|
+
# forge-jarvis.sh — the Jarvis launcher (m-37, Brief-R2 step 4 B2; contract handoff-step4-jarvis.md REV2).
|
|
3
|
+
#
|
|
4
|
+
# Starts the repo's ONE standing front door: a named `claude remote-control` server whose
|
|
5
|
+
# PRE-CREATED session is Jarvis — intake, dispatch, callback relay, awareness (B3-B5 attach
|
|
6
|
+
# to the session this launcher creates; this script is only the presence). Operator-started
|
|
7
|
+
# when he sits down (presence ops v1-minimal, operator-ruled 2026-07-20): no login items,
|
|
8
|
+
# no watchdogs, no daemon. The launcher is STATELESS — killing the server loses only the
|
|
9
|
+
# live connection and armed watches; everything re-establishes at restart from files
|
|
10
|
+
# (Amendment 2; B1 probe viii: dispatched work survives Jarvis's death via nohup-&).
|
|
11
|
+
#
|
|
12
|
+
# RESOLVED COMMAND SHAPE (operator ruling 6, 2026-07-21):
|
|
13
|
+
# caffeinate -s claude remote-control --name <sticky-name> --spawn worktree --capacity <N>
|
|
14
|
+
#
|
|
15
|
+
# caffeinate -s B1 probe (iii): sleep suspends local COMPUTE (dispatches, Monitor-
|
|
16
|
+
# triggered autonomous turns, sandbox allocation) while the RC
|
|
17
|
+
# connection persists — "present but asleep". -s keeps the machine
|
|
18
|
+
# awake on AC POWER ONLY; on battery, normal sleep + queue-until-wake
|
|
19
|
+
# apply. One word in the launch command, not nursing machinery.
|
|
20
|
+
# (caffeinate absent on PATH → warn + launch unwrapped, portably.)
|
|
21
|
+
# --name B1 probe (ii): the phone lists sessions by their first typed message;
|
|
22
|
+
# the pre-created session's --name is the ONLY sticky, recognizable
|
|
23
|
+
# discoverability anchor. Default: jarvis-<repo-basename>; a per-machine
|
|
24
|
+
# suffix names each machine on multi-machine repos (forge:
|
|
25
|
+
# jarvis-forge-personal / jarvis-forge-work).
|
|
26
|
+
# --spawn worktree on-demand sessions get isolated worktrees (step 0, platform-enforced).
|
|
27
|
+
# NOTE (probe ii finding): spawned bridge worktrees live under
|
|
28
|
+
# .claude/worktrees/ and do NOT auto-clean — B5 presence-ops owns that.
|
|
29
|
+
# --capacity sane for one operator; default 4.
|
|
30
|
+
#
|
|
31
|
+
# AUTH — NO TOKEN EXPORT (B1 probe iv): headless `claude -p` dispatches authenticate via
|
|
32
|
+
# the machine's KEYCHAIN credential with CLAUDE_CODE_OAUTH_TOKEN unset. This launcher must
|
|
33
|
+
# never export a token; if a thinner env ever surfaces the need, `claude setup-token` is
|
|
34
|
+
# the operator's minting path — never committed, never set here.
|
|
35
|
+
#
|
|
36
|
+
# PERMISSIONS — NO FLAGS NEEDED FOR THE PRE-CREATED SESSION (B1 probe vii): typed Bash,
|
|
37
|
+
# Monitor-arm, and PushNotification all run prompt-free in the pre-created session as-is;
|
|
38
|
+
# `--permission-mode` governs only SPAWNED sessions. Nothing to provision here. (Probe vii
|
|
39
|
+
# still owes an explicit check for any OTHER tool a later phase uses unattended.)
|
|
40
|
+
#
|
|
41
|
+
# CONFIG — optional `jarvis:` block in .forge/project.yml (board-block precedent):
|
|
42
|
+
# jarvis:
|
|
43
|
+
# enabled: true # explicit false = this launcher refuses (door switched off)
|
|
44
|
+
# name_suffix: "" # appended: jarvis-<repo>-<suffix>; env FORGE_JARVIS_NAME_SUFFIX
|
|
45
|
+
# # overrides per machine (the multi-machine seam)
|
|
46
|
+
# capacity: 4 # RC server session capacity
|
|
47
|
+
# NO block → sensible defaults (the launcher is operator-invoked, not ambient — unlike
|
|
48
|
+
# the board, absence does not mean inert).
|
|
49
|
+
#
|
|
50
|
+
# USAGE:
|
|
51
|
+
# .forge/checks/forge-jarvis.sh [--dry-run] [--name <full-name>] [--capacity <N>]
|
|
52
|
+
# --dry-run print the fully resolved command on stdout and exit 0 — never executes.
|
|
53
|
+
# --name full sticky-name override (skips derivation entirely).
|
|
54
|
+
# --capacity override config/default capacity.
|
|
55
|
+
#
|
|
56
|
+
# BOUNDARIES (contract "Not this step"): no routing, no approval surface, no new
|
|
57
|
+
# notification infrastructure, no Jarvis-owned state. This script keeps none.
|
|
58
|
+
set -u
|
|
59
|
+
|
|
60
|
+
# --- args -------------------------------------------------------------------
|
|
61
|
+
DRY_RUN=0
|
|
62
|
+
NAME_OVERRIDE=""
|
|
63
|
+
CAP_OVERRIDE=""
|
|
64
|
+
while [ $# -gt 0 ]; do
|
|
65
|
+
case "$1" in
|
|
66
|
+
--dry-run) DRY_RUN=1; shift ;;
|
|
67
|
+
--name) shift; NAME_OVERRIDE="${1:-}"; [ $# -gt 0 ] && shift || true ;;
|
|
68
|
+
--name=*) NAME_OVERRIDE="${1#*=}"; shift ;;
|
|
69
|
+
--capacity) shift; CAP_OVERRIDE="${1:-}"; [ $# -gt 0 ] && shift || true ;;
|
|
70
|
+
--capacity=*) CAP_OVERRIDE="${1#*=}"; shift ;;
|
|
71
|
+
*) printf 'forge-jarvis: unknown argument: %s\n' "$1" >&2; exit 2 ;;
|
|
72
|
+
esac
|
|
73
|
+
done
|
|
74
|
+
|
|
75
|
+
# --- repo (refusal, not fallback: --spawn worktree needs a real git repo) ----
|
|
76
|
+
ROOT="$(git rev-parse --show-toplevel 2>/dev/null)" || {
|
|
77
|
+
printf 'forge-jarvis: not inside a git repo — `claude remote-control --spawn worktree` needs one.\n' >&2
|
|
78
|
+
exit 2
|
|
79
|
+
}
|
|
80
|
+
PROJECT="$ROOT/.forge/project.yml"
|
|
81
|
+
# Repo identity for the sticky name: the git COMMON dir's parent, not the checkout's
|
|
82
|
+
# toplevel — stable across worktrees (a worktree basename like m-37 must never leak
|
|
83
|
+
# into the phone-visible name). The presence itself belongs on the MAIN checkout
|
|
84
|
+
# (the shape: Jarvis runs on the repo's main checkout in a real terminal).
|
|
85
|
+
COMMON="$(git rev-parse --git-common-dir)"
|
|
86
|
+
REPO_BASE="$(basename "$(cd "$(dirname "$COMMON")" && pwd)")"
|
|
87
|
+
|
|
88
|
+
# --- config: read a scalar under the top-level `jarvis:` block ---------------
|
|
89
|
+
jarvis_cfg() { # $1 = key under jarvis:
|
|
90
|
+
[ -f "$PROJECT" ] || return 0
|
|
91
|
+
awk -v k="$1" '
|
|
92
|
+
/^jarvis:/ { inb=1; next }
|
|
93
|
+
inb && /^[A-Za-z]/ { inb=0 }
|
|
94
|
+
inb && $0 ~ "^[[:space:]]+"k":" {
|
|
95
|
+
sub(/^[[:space:]]*[^:]+:[[:space:]]*/, "")
|
|
96
|
+
sub(/[[:space:]]*#.*/, "")
|
|
97
|
+
gsub(/^["'"'"']|["'"'"']$/, "")
|
|
98
|
+
print; exit
|
|
99
|
+
}
|
|
100
|
+
' "$PROJECT"
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
# --- enabled gate (explicit false refuses; absent block = defaults) ----------
|
|
104
|
+
if [ "$(jarvis_cfg enabled)" = "false" ]; then
|
|
105
|
+
printf 'forge-jarvis: jarvis.enabled is false in .forge/project.yml — the door is switched off.\n' >&2
|
|
106
|
+
exit 2
|
|
107
|
+
fi
|
|
108
|
+
|
|
109
|
+
# --- sticky name (probe ii: the only discoverability anchor) -----------------
|
|
110
|
+
if [ -n "$NAME_OVERRIDE" ]; then
|
|
111
|
+
NAME="$NAME_OVERRIDE"
|
|
112
|
+
else
|
|
113
|
+
NAME="jarvis-$REPO_BASE"
|
|
114
|
+
# per-machine seam: env overrides config (multi-machine repos name each machine)
|
|
115
|
+
SUFFIX="${FORGE_JARVIS_NAME_SUFFIX:-$(jarvis_cfg name_suffix)}"
|
|
116
|
+
[ -n "$SUFFIX" ] && NAME="$NAME-$SUFFIX"
|
|
117
|
+
fi
|
|
118
|
+
|
|
119
|
+
# --- capacity ----------------------------------------------------------------
|
|
120
|
+
CAP="${CAP_OVERRIDE:-$(jarvis_cfg capacity)}"
|
|
121
|
+
CAP="${CAP:-4}"
|
|
122
|
+
case "$CAP" in
|
|
123
|
+
*[!0-9]*|'') printf 'forge-jarvis: capacity must be a positive integer, got: %s\n' "$CAP" >&2; exit 2 ;;
|
|
124
|
+
esac
|
|
125
|
+
|
|
126
|
+
# --- resolve -----------------------------------------------------------------
|
|
127
|
+
# Printed exactly as executed (modulo the caffeinate degradation below).
|
|
128
|
+
RESOLVED="caffeinate -s claude remote-control --name $NAME --spawn worktree --capacity $CAP"
|
|
129
|
+
|
|
130
|
+
if [ "$DRY_RUN" = "1" ]; then
|
|
131
|
+
printf '%s\n' "$RESOLVED"
|
|
132
|
+
exit 0
|
|
133
|
+
fi
|
|
134
|
+
|
|
135
|
+
# ============================================================================
|
|
136
|
+
# B4 SEAM — DO NOT REMOVE (contract B4(a)).
|
|
137
|
+
# At boot Jarvis arms a Monitor tail (`tail -F` — capital F) on each active
|
|
138
|
+
# slice's notify log, the watch list recomputed by globbing live slice
|
|
139
|
+
# worktrees, never from memory (Amendment 2). That boot arming act attaches
|
|
140
|
+
# HERE — as the launcher's instruction to the pre-created session — once the
|
|
141
|
+
# relay (B4) exists. Deliberately a no-op today: B2 ships the presence only,
|
|
142
|
+
# and building any relay glue ahead of B4 is out of this phase's scope.
|
|
143
|
+
# ============================================================================
|
|
144
|
+
jarvis_boot_arm() { :; }
|
|
145
|
+
jarvis_boot_arm
|
|
146
|
+
|
|
147
|
+
# --- launch ------------------------------------------------------------------
|
|
148
|
+
command -v claude >/dev/null 2>&1 || {
|
|
149
|
+
printf 'forge-jarvis: `claude` not found on PATH.\n' >&2
|
|
150
|
+
exit 2
|
|
151
|
+
}
|
|
152
|
+
printf 'forge-jarvis: starting %s (capacity %s) in %s\n' "$NAME" "$CAP" "$ROOT" >&2
|
|
153
|
+
cd "$ROOT" || exit 2
|
|
154
|
+
if command -v caffeinate >/dev/null 2>&1; then
|
|
155
|
+
exec caffeinate -s claude remote-control --name "$NAME" --spawn worktree --capacity "$CAP"
|
|
156
|
+
else
|
|
157
|
+
# non-macOS: no caffeinate — launch unwrapped; sleep then queues-until-wake (probe iii).
|
|
158
|
+
printf 'forge-jarvis: caffeinate not found — launching without keep-awake (lid-closed autonomy degrades to queue-until-wake).\n' >&2
|
|
159
|
+
exec claude remote-control --name "$NAME" --spawn worktree --capacity "$CAP"
|
|
160
|
+
fi
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/usr/bin/env sh
|
|
2
|
+
# Fixture test suite for .forge/checks/forge-jarvis-answer.sh (m-37, step 4 B4(d); plan 68-02).
|
|
3
|
+
#
|
|
4
|
+
# Contract under test (handoff-step4-jarvis.md REV2 B4(d); NFR-037; acceptance #2):
|
|
5
|
+
# - the answer lands at the EXACT m-35 path: <work-dir>/phase-<N>/answer.md, with the reply text.
|
|
6
|
+
# - after writing, the slice is re-dispatched via forge-jarvis-dispatch.sh (stubbed here).
|
|
7
|
+
# - NEG-CONTROL: no answer content → nothing written, nothing re-dispatched (slice stays parked).
|
|
8
|
+
# - the reply may arrive via --answer or via stdin.
|
|
9
|
+
#
|
|
10
|
+
# The dispatch is stubbed via FORGE_JARVIS_DISPATCH (records that it was called) so no real runner
|
|
11
|
+
# spawns. Each assertion prints WHY. RED-friendly: a missing script fails every case.
|
|
12
|
+
set -u
|
|
13
|
+
|
|
14
|
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
15
|
+
ANSWER="$SCRIPT_DIR/../forge-jarvis-answer.sh"
|
|
16
|
+
[ -f "$ANSWER" ] || printf 'NOTE: %s missing — RED phase, every case should FAIL\n' "$ANSWER" >&2
|
|
17
|
+
|
|
18
|
+
ROOT="$(mktemp -d)"
|
|
19
|
+
trap 'rm -rf "$ROOT"' EXIT INT TERM
|
|
20
|
+
PASSED=0; FAILED=0
|
|
21
|
+
ok() { PASSED=$((PASSED+1)); printf ' ok %s\n' "$1"; }
|
|
22
|
+
bad() { FAILED=$((FAILED+1)); printf ' FAIL %s\n %s\n' "$1" "$2"; }
|
|
23
|
+
|
|
24
|
+
# stub dispatch: record the call so we can assert re-dispatch happened (no real runner spawns)
|
|
25
|
+
STUBD="$ROOT/dispatch-stub.sh"
|
|
26
|
+
CALLED="$ROOT/dispatch.called"
|
|
27
|
+
printf '#!/usr/bin/env sh\nprintf "%%s\\n" "$*" > "%s"\n' "$CALLED" > "$STUBD"
|
|
28
|
+
chmod +x "$STUBD"
|
|
29
|
+
SLICE="$ROOT/slice"; mkdir -p "$SLICE"
|
|
30
|
+
|
|
31
|
+
# 1. answer via --answer → lands at the EXACT m-35 path with the reply text
|
|
32
|
+
WD="$ROOT/w1"; rm -f "$CALLED"
|
|
33
|
+
FORGE_JARVIS_DISPATCH="$STUBD" sh "$ANSWER" --work-dir "$WD" --phase 3 --slice "$SLICE" --answer "Use JWT." >/dev/null 2>&1
|
|
34
|
+
if [ -f "$WD/phase-3/answer.md" ] && grep -q 'Use JWT.' "$WD/phase-3/answer.md"; then
|
|
35
|
+
ok "answer lands at the EXACT m-35 path <work-dir>/phase-3/answer.md with the reply text"
|
|
36
|
+
else
|
|
37
|
+
bad "m-35 answer path" "missing or wrong content at $WD/phase-3/answer.md"
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
# 2. re-dispatch invoked (the stub recorded the call, carrying --slice + --work-dir)
|
|
41
|
+
if [ -f "$CALLED" ] && grep -q -- "--slice $SLICE" "$CALLED" && grep -q -- "--work-dir $WD" "$CALLED"; then
|
|
42
|
+
ok "slice re-dispatched after the answer landed (forge-jarvis-dispatch called with --slice/--work-dir)"
|
|
43
|
+
else
|
|
44
|
+
bad "re-dispatch" "dispatch not called or missing args: $(cat "$CALLED" 2>/dev/null)"
|
|
45
|
+
fi
|
|
46
|
+
|
|
47
|
+
# 3. NEG-CONTROL: no answer (empty stdin) → nothing written, NO re-dispatch, non-zero exit
|
|
48
|
+
WD2="$ROOT/w2"; rm -f "$CALLED"
|
|
49
|
+
FORGE_JARVIS_DISPATCH="$STUBD" sh "$ANSWER" --work-dir "$WD2" --phase 3 --slice "$SLICE" </dev/null >/dev/null 2>&1; rc=$?
|
|
50
|
+
if [ "$rc" != 0 ] && [ ! -f "$WD2/phase-3/answer.md" ] && [ ! -f "$CALLED" ]; then
|
|
51
|
+
ok "neg-control: no answer → nothing written, no re-dispatch (slice stays parked), non-zero exit"
|
|
52
|
+
else
|
|
53
|
+
bad "neg-control no-answer" "rc=$rc wrote=$([ -f "$WD2/phase-3/answer.md" ] && echo yes) dispatched=$([ -f "$CALLED" ] && echo yes)"
|
|
54
|
+
fi
|
|
55
|
+
|
|
56
|
+
# 4. answer via stdin also works (phone/typed reply piped in)
|
|
57
|
+
WD3="$ROOT/w3"; rm -f "$CALLED"
|
|
58
|
+
printf 'sessions, not JWT' | FORGE_JARVIS_DISPATCH="$STUBD" sh "$ANSWER" --work-dir "$WD3" --phase 7 --slice "$SLICE" >/dev/null 2>&1
|
|
59
|
+
if [ -f "$WD3/phase-7/answer.md" ] && grep -q 'sessions, not JWT' "$WD3/phase-7/answer.md" && [ -f "$CALLED" ]; then
|
|
60
|
+
ok "answer via stdin lands at phase-7/answer.md and re-dispatches"
|
|
61
|
+
else
|
|
62
|
+
bad "stdin answer" "missing write or dispatch for stdin path"
|
|
63
|
+
fi
|
|
64
|
+
|
|
65
|
+
# 5. --dry-run: nothing written, nothing dispatched
|
|
66
|
+
WD4="$ROOT/w4"; rm -f "$CALLED"
|
|
67
|
+
FORGE_JARVIS_DISPATCH="$STUBD" sh "$ANSWER" --work-dir "$WD4" --phase 2 --slice "$SLICE" --answer "x" --dry-run >/dev/null 2>&1
|
|
68
|
+
if [ ! -f "$WD4/phase-2/answer.md" ] && [ ! -f "$CALLED" ]; then
|
|
69
|
+
ok "--dry-run writes nothing and dispatches nothing"
|
|
70
|
+
else
|
|
71
|
+
bad "dry-run side effects" "dry-run wrote or dispatched"
|
|
72
|
+
fi
|
|
73
|
+
|
|
74
|
+
printf '\n%s: %d passed, %d failed\n' "$(basename "$0")" "$PASSED" "$FAILED"
|
|
75
|
+
[ "$FAILED" = 0 ]
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#!/usr/bin/env sh
|
|
2
|
+
# Fixture test for .forge/checks/forge-jarvis-bridge-clean.sh (m-37 B5; FR-206; B1 probe ii).
|
|
3
|
+
#
|
|
4
|
+
# Builds a REAL throwaway repo with two REAL bridge worktrees (one "live", one orphaned), then
|
|
5
|
+
# asserts the orphan is reaped from disk AND git's registry while the live one is untouched — and
|
|
6
|
+
# that --dry-run removes nothing and never flags the live one. Liveness is pinned deterministically
|
|
7
|
+
# via FORGE_JARVIS_BRIDGE_LIVECHECK so the test never depends on wall-clock mtime.
|
|
8
|
+
set -u
|
|
9
|
+
|
|
10
|
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
11
|
+
CLEAN="$SCRIPT_DIR/../forge-jarvis-bridge-clean.sh"
|
|
12
|
+
[ -f "$CLEAN" ] || printf 'NOTE: %s missing — RED phase, every case should FAIL\n' "$CLEAN" >&2
|
|
13
|
+
|
|
14
|
+
ROOT="$(mktemp -d)"
|
|
15
|
+
trap 'rm -rf "$ROOT"' EXIT INT TERM
|
|
16
|
+
|
|
17
|
+
PASSED=0; FAILED=0
|
|
18
|
+
ok() { PASSED=$((PASSED+1)); printf ' ok %s\n' "$1"; }
|
|
19
|
+
bad() { FAILED=$((FAILED+1)); printf ' FAIL %s\n %s\n' "$1" "$2"; }
|
|
20
|
+
|
|
21
|
+
# --- a real repo with two real bridge worktrees ------------------------------------------------
|
|
22
|
+
REPO="$ROOT/repo"; mkdir -p "$REPO"
|
|
23
|
+
git -C "$REPO" init -q
|
|
24
|
+
git -C "$REPO" config user.email t@t.test
|
|
25
|
+
git -C "$REPO" config user.name tester
|
|
26
|
+
printf 'seed\n' > "$REPO/f"; git -C "$REPO" add f; git -C "$REPO" commit -qm init
|
|
27
|
+
|
|
28
|
+
WTR="$REPO/.claude/worktrees"; mkdir -p "$WTR"
|
|
29
|
+
git -C "$REPO" worktree add -q "$WTR/bridge-alive" 2>/dev/null || bad "setup" "could not add bridge-alive worktree"
|
|
30
|
+
git -C "$REPO" worktree add -q "$WTR/bridge-dead" 2>/dev/null || bad "setup" "could not add bridge-dead worktree"
|
|
31
|
+
|
|
32
|
+
# livecheck stub: ONLY bridge-alive is live.
|
|
33
|
+
LIVE="$ROOT/livecheck.sh"
|
|
34
|
+
printf '#!/usr/bin/env sh\ncase "$1" in *bridge-alive*) exit 0 ;; *) exit 1 ;; esac\n' > "$LIVE"
|
|
35
|
+
chmod +x "$LIVE"
|
|
36
|
+
|
|
37
|
+
run() { FORGE_JARVIS_BRIDGE_LIVECHECK="$LIVE" sh "$CLEAN" --worktrees-root "$WTR" "$@" 2>/dev/null; }
|
|
38
|
+
|
|
39
|
+
# 1. dry-run flags the orphan, removes nothing
|
|
40
|
+
out="$(run --dry-run)"
|
|
41
|
+
case "$out" in *bridge-dead*candidate*) ok "dry-run flags bridge-dead as an orphan candidate" ;; *) bad "dry-run candidate" "$out" ;; esac
|
|
42
|
+
[ -d "$WTR/bridge-dead" ] && ok "dry-run removed nothing (bridge-dead still on disk)" || bad "dry-run non-removal" "bridge-dead gone after dry-run"
|
|
43
|
+
|
|
44
|
+
# 2. dry-run never flags the live one (line-scoped: the bridge-alive line must not say "candidate")
|
|
45
|
+
if printf '%s\n' "$out" | grep 'bridge-alive' | grep -q 'candidate'; then
|
|
46
|
+
bad "dry-run live safety" "flagged the live worktree: $out"
|
|
47
|
+
else
|
|
48
|
+
ok "dry-run keeps the live worktree out of candidates"
|
|
49
|
+
fi
|
|
50
|
+
|
|
51
|
+
# 3. real run reaps the orphan, keeps the live one
|
|
52
|
+
out="$(run)"
|
|
53
|
+
[ ! -d "$WTR/bridge-dead" ] && ok "orphan bridge-dead reaped (removed from disk)" || bad "orphan removal" "bridge-dead still present: $out"
|
|
54
|
+
[ -d "$WTR/bridge-alive" ] && ok "live bridge-alive untouched" || bad "live safety" "live worktree was removed"
|
|
55
|
+
|
|
56
|
+
# 4. reaped from git's worktree registry too (not just the directory)
|
|
57
|
+
if git -C "$REPO" worktree list --porcelain 2>/dev/null | grep -q 'bridge-dead'; then
|
|
58
|
+
bad "registry" "bridge-dead still in git worktree list"
|
|
59
|
+
else
|
|
60
|
+
ok "bridge-dead gone from git's worktree registry too"
|
|
61
|
+
fi
|
|
62
|
+
|
|
63
|
+
# 5. re-run is a clean no-op (only the live one remains, and it is kept)
|
|
64
|
+
out="$(run)"
|
|
65
|
+
case "$out" in *'0 reaped'*) ok "re-run reaps nothing (idempotent — only the live worktree left)" ;; *) bad "idempotent" "$out" ;; esac
|
|
66
|
+
|
|
67
|
+
# --- 6+7. LOCK-AWARE liveness — the REAL RC substrate: bridges are git-LOCKED under the server pid.
|
|
68
|
+
# No injected livecheck here, so this exercises default_livecheck's lock-pid path AND unlock-on-reap
|
|
69
|
+
# (the fixtures 1-5 used unlocked worktrees + a stubbed livecheck, which masked both — the gap the
|
|
70
|
+
# FR-207 human-verification walk surfaced against a live RC server).
|
|
71
|
+
REPO2="$ROOT/repo2"; mkdir -p "$REPO2"
|
|
72
|
+
git -C "$REPO2" init -q
|
|
73
|
+
git -C "$REPO2" config user.email t@t.test
|
|
74
|
+
git -C "$REPO2" config user.name tester
|
|
75
|
+
printf 'seed\n' > "$REPO2/f"; git -C "$REPO2" add f; git -C "$REPO2" commit -qm init
|
|
76
|
+
WTR2="$REPO2/.claude/worktrees"; mkdir -p "$WTR2"
|
|
77
|
+
git -C "$REPO2" worktree add -q "$WTR2/bridge-livepid" 2>/dev/null || bad "setup2" "add bridge-livepid"
|
|
78
|
+
git -C "$REPO2" worktree add -q "$WTR2/bridge-deadpid" 2>/dev/null || bad "setup2" "add bridge-deadpid"
|
|
79
|
+
|
|
80
|
+
# a definitely-DEAD pid (background a no-op, reap it, reuse its pid); a definitely-LIVE pid (this shell)
|
|
81
|
+
( : ) & DEADPID=$!; wait "$DEADPID" 2>/dev/null
|
|
82
|
+
LIVEPID=$$
|
|
83
|
+
git -C "$REPO2" worktree lock --reason "claude agent bridge-livepid (pid $LIVEPID start now)" "$WTR2/bridge-livepid" 2>/dev/null || bad "setup2" "lock bridge-livepid"
|
|
84
|
+
git -C "$REPO2" worktree lock --reason "claude agent bridge-deadpid (pid $DEADPID start now)" "$WTR2/bridge-deadpid" 2>/dev/null || bad "setup2" "lock bridge-deadpid"
|
|
85
|
+
|
|
86
|
+
# Both are FRESH (mtime ~now): under the OLD mtime rule both would be "live". The fix classifies by
|
|
87
|
+
# the lock pid, so the dead-pid one must reap (despite fresh mtime) and the live-pid one must stay —
|
|
88
|
+
# AND the reap must succeed against a LOCKED worktree (unlock-before-remove).
|
|
89
|
+
out2="$(sh "$CLEAN" --worktrees-root "$WTR2" 2>/dev/null)"
|
|
90
|
+
[ ! -d "$WTR2/bridge-deadpid" ] && ok "dead-pid lock reaped despite fresh mtime (lock beats mtime; unlock-then-remove worked)" || bad "lock-pid orphan" "bridge-deadpid still present: $out2"
|
|
91
|
+
[ -d "$WTR2/bridge-livepid" ] && ok "live-pid lock kept (the server still owns it)" || bad "lock-pid live" "live-pid worktree was removed: $out2"
|
|
92
|
+
|
|
93
|
+
printf '\n%s: %d passed, %d failed\n' "$(basename "$0")" "$PASSED" "$FAILED"
|
|
94
|
+
[ "$FAILED" = 0 ]
|