Skip to content

Commit adad91a

Browse files
saravmajesticclaude
andcommitted
fix: team rules hook — start nothing outside linked repositories
- Session start runs the CLI only where workspace rules state exists, or where the workspace link cache names the repository or a folder inside it. Elsewhere the hook costs nothing. - The per-turn hooks share the same state check. The CLI still runs from the host's directory: a link can be for a folder inside the repository. - README: direct "remember" needs "team rule" wording. `/altimate-code:rules`: a here-doc delimiter note. - Hook test covers the pre-filter and a link for a folder inside the repository. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 3f97ab6 commit adad91a

4 files changed

Lines changed: 22 additions & 5 deletions

File tree

‎plugins/altimate-code/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ With learning on (the workspace's "Learn from sessions", or `altimate-code learn
4646

4747
- **At session start** the plugin gives Codex the team rules for this repository, tells it how many proposed rules are waiting for you, and reports the owner's reviews of your proposals since your last session (approved, or rejected with the reason).
4848
- **When you correct Codex** ("no, we never use FLOAT for money") the correction is recorded locally. When you correct it on the same topic in two sessions, or correct a team rule it was given, altimate-code words a proposed rule after the turn, in the background.
49-
- **"Remember this as a team rule: …"**, said to Codex or in a task handed to altimate-code, waits as a proposal the same way.
49+
- **"Remember this as a team rule: …"**, said to Codex or in a task handed to altimate-code, waits as a proposal the same way. It needs the words "team rule" (or "as a rule"): "remember to run the tests" is just part of the conversation.
5050
- **`/altimate-code:rules`** shows the proposals waiting for you, the team rules, and the status of the rules you proposed. For each proposal you choose: send it to the workspace owner's review (or approve it, if you are the owner), edit the wording, save it as a memory, or "Not a rule". Nothing reaches teammates until the owner approves it.
5151

5252
Rule drafting uses altimate-code's own model (sign in to the Altimate LLM Gateway, or set a provider in altimate-code): if it has none it can use, the next session start says the check failed. The same commands work in a terminal: `altimate-code learn proposals`, `altimate-code learn proposals reply <id> --send`. This needs an altimate-code release with workspace rules.

‎plugins/altimate-code/commands/rules.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Workflow (follow in order):
4949
)"
5050
"$ALTIMATE_BIN" learn proposals reply "$PROPOSAL_ID" --json --edit="$WORDING" < /dev/null
5151
```
52-
Keep `--edit="$WORDING"` in one argument (a wording that starts with `-` is otherwise read as a flag), and start the closing `ALTIMATE_RULE` line at the beginning of its line. For any other choice, run the same command with that flag instead of `--edit="$WORDING"` (and without the here-doc).
52+
Keep `--edit="$WORDING"` in one argument (a wording that starts with `-` is otherwise read as a flag), and start the closing `ALTIMATE_RULE` line at the beginning of its line. If the wording itself has a line that is exactly `ALTIMATE_RULE`, use another delimiter. For any other choice, run the same command with that flag instead of `--edit="$WORDING"` (and without the here-doc).
5353
5454
The JSON answer is `{"ok": true, "message": …, "closed": …}` or `{"ok": false, "code": …, "error": …}`. Show the `message` or `error` to the user as it is. Then:
5555
- `closed: false` after an edit: the proposal is still open with the new wording; ask about it again.

‎plugins/altimate-code/hooks/altimate-code-workspace-rules.sh‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,28 @@ for ALTIMATE_NAME in altimate-code altimate; do
2626
done
2727
[ -n "$ALTIMATE_BIN" ] || exit 0
2828

29+
# Run from the host's directory, not the repository root: a workspace link can be for a folder inside the repository
30+
# (a dbt project), and the CLI finds the root itself.
31+
ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
32+
STATE="$ROOT/.altimate-code/learn/workspace-rules/rules.json"
33+
2934
case "$EVENT" in
3035
session-start)
36+
# Only a repository with workspace rules state, or one the workspace link cache names (the repository or a folder
37+
# inside it), can have team rules: elsewhere the CLI is not started at all.
38+
if [ ! -f "$STATE" ]; then
39+
CACHE="${XDG_STATE_HOME:-$HOME/.local/state}/altimate-code/altimate-workspace-bindings.json"
40+
REAL="$(cd "$ROOT" 2>/dev/null && pwd -P)"
41+
[ -n "$REAL" ] && grep -qF "\"$REAL" "$CACHE" 2>/dev/null || exit 0
42+
fi
3143
OUTPUT="$(printf '%s' "$INPUT" | "$ALTIMATE_BIN" learn hook session-start --host "$HOST" 2>/dev/null)"
3244
# Only the hook's JSON: an altimate-code without `learn hook` prints its help instead.
3345
case "$OUTPUT" in
3446
'{'*) printf '%s\n' "$OUTPUT" ;;
3547
esac
3648
;;
3749
user-prompt-submit|stop)
38-
ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
39-
[ -f "$ROOT/.altimate-code/learn/workspace-rules/rules.json" ] || exit 0
50+
[ -f "$STATE" ] || exit 0
4051
( printf '%s' "$INPUT" | nohup "$ALTIMATE_BIN" learn hook "$EVENT" --host "$HOST" & ) >/dev/null 2>&1 </dev/null
4152
;;
4253
esac

‎tests/workspace-rules-hook.sh‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ chmod +x "$BIN/altimate-code"
3535
# hook <dir> <event> <PATH> [STUB_MODE] → prints "exit|stdout"
3636
hook() {
3737
local out rc
38-
out="$(cd "$1" && printf '{"session_id":"s1","prompt":"no, that is wrong"}' | env PATH="$3" STUB_MODE="${4:-ok}" bash "$HOOK" "$2" 2>&1)"
38+
out="$(cd "$1" && printf '{"session_id":"s1","prompt":"no, that is wrong"}' | env PATH="$3" STUB_MODE="${4:-ok}" XDG_STATE_HOME="$WORK/xdg" bash "$HOOK" "$2" 2>&1)"
3939
rc=$?
4040
printf '%s|%s' "$rc" "$out"
4141
}
@@ -44,6 +44,12 @@ SYS="/usr/bin:/bin"
4444
await_log() { for _ in $(seq 50); do grep -q "$1" "$LOG" 2>/dev/null && return 0; sleep 0.1; done; return 1; }
4545

4646
: > "$LOG"
47+
# Neither workspace rules state nor a workspace link: the CLI is not started at session start.
48+
[ "$(hook "$WORK/project" session-start "$BIN:$SYS")" = "0|" ] || fail "session start printed output in a project with no link"
49+
[ ! -s "$LOG" ] || fail "session start ran the CLI in a project with no link: $(cat "$LOG")"
50+
# A link for a folder inside the repository (a dbt project), started from the repository root: the CLI runs.
51+
mkdir -p "$WORK/xdg/altimate-code" "$WORK/project/dbt"
52+
printf '{"bindings":{"%s/dbt":{"datamateId":1}}}' "$(cd "$WORK/project" && pwd -P)" > "$WORK/xdg/altimate-code/altimate-workspace-bindings.json"
4753
[ "$(hook "$WORK/project" session-start "$BIN:$SYS")" = '0|{"hookSpecificOutput":{"hookEventName":"SessionStart","additionalContext":"rules"}}' ] \
4854
|| fail "session start does not print the CLI's hook JSON"
4955
grep -qx "learn hook session-start --host $HOST|{\"session_id\":\"s1\",\"prompt\":\"no, that is wrong\"}" "$LOG" \

0 commit comments

Comments
 (0)