rhachet-roles-bhuild 0.1.3 → 0.4.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 (47) hide show
  1. package/dist/domain.operations/behavior/bind/flattenBranchName.cli.d.ts +2 -0
  2. package/dist/domain.operations/behavior/bind/flattenBranchName.cli.js +19 -0
  3. package/dist/domain.operations/behavior/bind/flattenBranchName.cli.js.map +1 -0
  4. package/dist/domain.operations/behavior/bind/flattenBranchName.d.ts +8 -0
  5. package/dist/domain.operations/behavior/bind/flattenBranchName.js +19 -0
  6. package/dist/domain.operations/behavior/bind/flattenBranchName.js.map +1 -0
  7. package/dist/domain.operations/behavior/bind/getBoundBehaviorByBranch.cli.d.ts +2 -0
  8. package/dist/domain.operations/behavior/bind/getBoundBehaviorByBranch.cli.js +18 -0
  9. package/dist/domain.operations/behavior/bind/getBoundBehaviorByBranch.cli.js.map +1 -0
  10. package/dist/domain.operations/behavior/bind/getBoundBehaviorByBranch.d.ts +11 -0
  11. package/dist/domain.operations/behavior/bind/getBoundBehaviorByBranch.js +51 -0
  12. package/dist/domain.operations/behavior/bind/getBoundBehaviorByBranch.js.map +1 -0
  13. package/dist/domain.operations/behavior/bind/getLatestBlueprintByBehavior.cli.d.ts +2 -0
  14. package/dist/domain.operations/behavior/bind/getLatestBlueprintByBehavior.cli.js +20 -0
  15. package/dist/domain.operations/behavior/bind/getLatestBlueprintByBehavior.cli.js.map +1 -0
  16. package/dist/domain.operations/behavior/bind/getLatestBlueprintByBehavior.d.ts +11 -0
  17. package/dist/domain.operations/behavior/bind/getLatestBlueprintByBehavior.js +51 -0
  18. package/dist/domain.operations/behavior/bind/getLatestBlueprintByBehavior.js.map +1 -0
  19. package/dist/domain.operations/behavior/bind/index.d.ts +3 -0
  20. package/dist/domain.operations/behavior/bind/index.js +10 -0
  21. package/dist/domain.operations/behavior/bind/index.js.map +1 -0
  22. package/dist/domain.roles/behaver/briefs/practices/behavior.blueprint/rule.require.criteria-satisfied.md +37 -0
  23. package/dist/domain.roles/behaver/briefs/practices/behavior.blueprint/rule.require.determinism-declared.md +44 -0
  24. package/dist/domain.roles/behaver/briefs/practices/behavior.blueprint/rule.require.test-coverage-specified.md +42 -0
  25. package/dist/domain.roles/behaver/briefs/practices/behavior.blueprint/rule.require.test-patterns-specified.md +43 -0
  26. package/dist/domain.roles/behaver/briefs/practices/behavior.criteria/rule.prefer.dependency-order.md +43 -0
  27. package/dist/domain.roles/behaver/briefs/practices/behavior.criteria/rule.prefer.depth-groups.md +44 -0
  28. package/dist/domain.roles/behaver/briefs/practices/behavior.criteria/rule.prefer.usecase-groups.md +41 -0
  29. package/dist/domain.roles/behaver/briefs/practices/behavior.criteria/rule.require.bdd-format.md +25 -0
  30. package/dist/domain.roles/behaver/briefs/practices/behavior.roadmap/rule.prefer.clear-deliverables.md +46 -0
  31. package/dist/domain.roles/behaver/briefs/practices/behavior.roadmap/rule.prefer.dependency-order.md +59 -0
  32. package/dist/domain.roles/behaver/briefs/practices/behavior.wish/rule.prefer.bounded-scope.md +29 -0
  33. package/dist/domain.roles/behaver/briefs/practices/behavior.wish/rule.prefer.clear-desires.md +31 -0
  34. package/dist/domain.roles/behaver/getBehaverRole.js +4 -0
  35. package/dist/domain.roles/behaver/getBehaverRole.js.map +1 -1
  36. package/dist/domain.roles/behaver/inits/claude.hooks/sessionstart.boot-behavior.sh +109 -0
  37. package/dist/domain.roles/behaver/inits/init.claude.hooks.findsert.sh +226 -0
  38. package/dist/domain.roles/behaver/inits/init.claude.hooks.sh +34 -0
  39. package/dist/domain.roles/behaver/skills/bind.behavior.sh +236 -0
  40. package/dist/domain.roles/behaver/skills/init.behavior.sh +51 -0
  41. package/dist/domain.roles/behaver/skills/review.behavior.sh +396 -0
  42. package/dist/domain.roles/behaver/skills/review.behavior.test.utils.d.ts +12 -0
  43. package/dist/domain.roles/behaver/skills/review.behavior.test.utils.js +63 -0
  44. package/dist/domain.roles/behaver/skills/review.behavior.test.utils.js.map +1 -0
  45. package/dist/domain.roles/behaver/skills/review.deliverable.sh +344 -0
  46. package/package.json +10 -8
  47. package/readme.md +34 -0
@@ -0,0 +1,236 @@
1
+ #!/usr/bin/env bash
2
+ ######################################################################
3
+ # .what = bind, unbind, or query branch-to-behavior binding
4
+ #
5
+ # .why = explicit user control over which behavior applies to current branch
6
+ #
7
+ # usage:
8
+ # bind.behavior.sh --set --behavior <name> # bind current branch
9
+ # bind.behavior.sh --del # unbind current branch
10
+ # bind.behavior.sh --get # query current binding
11
+ #
12
+ # guarantee:
13
+ # - fail-fast if behavior not found or ambiguous
14
+ # - fail-fast if --set to different behavior (suggest --del or worktree)
15
+ # - idempotent: --set to same behavior succeeds, --del when unbound succeeds
16
+ ######################################################################
17
+
18
+ set -euo pipefail
19
+
20
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
21
+ REPO_ROOT="$(cd "$SCRIPT_DIR/../../../.." && pwd)"
22
+
23
+ # ────────────────────────────────────────────────────────────────────
24
+ # argument parsing
25
+ # ────────────────────────────────────────────────────────────────────
26
+
27
+ ACTION=""
28
+ BEHAVIOR_NAME=""
29
+
30
+ while [[ $# -gt 0 ]]; do
31
+ case $1 in
32
+ --set)
33
+ ACTION="set"
34
+ shift
35
+ ;;
36
+ --del)
37
+ ACTION="del"
38
+ shift
39
+ ;;
40
+ --get)
41
+ ACTION="get"
42
+ shift
43
+ ;;
44
+ --behavior)
45
+ BEHAVIOR_NAME="$2"
46
+ shift 2
47
+ ;;
48
+ --skill|--repo|--role|-s)
49
+ # ignore rhachet passthrough args
50
+ shift 2
51
+ ;;
52
+ *)
53
+ echo "error: unknown argument '$1'"
54
+ echo "usage: bind.behavior.sh --set --behavior <name> | --del | --get"
55
+ exit 1
56
+ ;;
57
+ esac
58
+ done
59
+
60
+ # validate action
61
+ if [[ -z "$ACTION" ]]; then
62
+ echo "error: no action specified"
63
+ echo "usage: bind.behavior.sh --set --behavior <name> | --del | --get"
64
+ exit 1
65
+ fi
66
+
67
+ # ────────────────────────────────────────────────────────────────────
68
+ # helpers
69
+ # ────────────────────────────────────────────────────────────────────
70
+
71
+ get_current_branch() {
72
+ git rev-parse --abbrev-ref HEAD
73
+ }
74
+
75
+ flatten_branch_name() {
76
+ local branch="$1"
77
+ npx tsx "$REPO_ROOT/src/domain.operations/behavior/bind/flattenBranchName.cli.ts" "$branch"
78
+ }
79
+
80
+ get_bound_behavior() {
81
+ npx tsx "$REPO_ROOT/src/domain.operations/behavior/bind/getBoundBehaviorByBranch.cli.ts" "$1"
82
+ }
83
+
84
+ resolve_behavior_dir() {
85
+ local name="$1"
86
+ local behavior_root="$PWD/.behavior"
87
+
88
+ if [[ ! -d "$behavior_root" ]]; then
89
+ echo ""
90
+ return
91
+ fi
92
+
93
+ # find matching behavior directories
94
+ local matches=()
95
+ while IFS= read -r -d '' dir; do
96
+ matches+=("$dir")
97
+ done < <(find "$behavior_root" -maxdepth 1 -type d -name "*${name}*" -print0 2>/dev/null)
98
+
99
+ if [[ ${#matches[@]} -eq 0 ]]; then
100
+ echo "error: no behavior found matching '$name'" >&2
101
+ echo "available behaviors:" >&2
102
+ ls -1 "$behavior_root" 2>/dev/null | sed 's/^/ /' >&2
103
+ exit 1
104
+ fi
105
+
106
+ if [[ ${#matches[@]} -gt 1 ]]; then
107
+ echo "error: multiple behaviors match '$name'" >&2
108
+ echo "matches:" >&2
109
+ printf ' %s\n' "${matches[@]}" >&2
110
+ exit 1
111
+ fi
112
+
113
+ echo "${matches[0]}"
114
+ }
115
+
116
+ # ────────────────────────────────────────────────────────────────────
117
+ # actions
118
+ # ────────────────────────────────────────────────────────────────────
119
+
120
+ action_get() {
121
+ local branch
122
+ branch=$(get_current_branch)
123
+ local result
124
+ result=$(get_bound_behavior "$branch")
125
+
126
+ local behavior_dir
127
+ behavior_dir=$(echo "$result" | jq -r '.behaviorDir // empty')
128
+
129
+ if [[ -z "$behavior_dir" || "$behavior_dir" == "null" ]]; then
130
+ echo "not bound"
131
+ else
132
+ # extract just the behavior name from the path
133
+ local behavior_name
134
+ behavior_name=$(basename "$behavior_dir")
135
+ echo "bound to: $behavior_name"
136
+ fi
137
+ }
138
+
139
+ action_set() {
140
+ if [[ -z "$BEHAVIOR_NAME" ]]; then
141
+ echo "error: --behavior is required with --set"
142
+ exit 1
143
+ fi
144
+
145
+ local branch
146
+ branch=$(get_current_branch)
147
+ local flat_branch
148
+ flat_branch=$(flatten_branch_name "$branch")
149
+
150
+ # resolve the behavior directory
151
+ local behavior_dir
152
+ behavior_dir=$(resolve_behavior_dir "$BEHAVIOR_NAME")
153
+
154
+ if [[ -z "$behavior_dir" ]]; then
155
+ echo "error: .behavior/ directory not found"
156
+ exit 1
157
+ fi
158
+
159
+ # check if already bound
160
+ local result
161
+ result=$(get_bound_behavior "$branch")
162
+ local current_binding
163
+ current_binding=$(echo "$result" | jq -r '.behaviorDir // empty')
164
+
165
+ if [[ -n "$current_binding" && "$current_binding" != "null" ]]; then
166
+ if [[ "$current_binding" == "$behavior_dir" ]]; then
167
+ echo "✓ already bound to: $(basename "$behavior_dir")"
168
+ return 0
169
+ else
170
+ echo "error: branch already bound to different behavior: $(basename "$current_binding")"
171
+ echo ""
172
+ echo "to rebind, first unbind with:"
173
+ echo " bind.behavior.sh --del"
174
+ echo ""
175
+ echo "or use a new worktree for the new behavior:"
176
+ echo " git worktree add ../<new-branch> -b <new-branch>"
177
+ exit 1
178
+ fi
179
+ fi
180
+
181
+ # create bind directory if needed
182
+ local bind_dir="$behavior_dir/.bind"
183
+ mkdir -p "$bind_dir"
184
+
185
+ # create bind flag with metadata
186
+ local flag_path="$bind_dir/${flat_branch}.flag"
187
+ cat > "$flag_path" <<EOF
188
+ branch: $branch
189
+ bound_at: $(date -u +"%Y-%m-%dT%H:%M:%SZ")
190
+ bound_by: bind.behavior skill
191
+ EOF
192
+
193
+ echo "✓ bound branch '$branch' to: $(basename "$behavior_dir")"
194
+ }
195
+
196
+ action_del() {
197
+ local branch
198
+ branch=$(get_current_branch)
199
+ local flat_branch
200
+ flat_branch=$(flatten_branch_name "$branch")
201
+
202
+ # check if bound
203
+ local result
204
+ result=$(get_bound_behavior "$branch")
205
+ local current_binding
206
+ current_binding=$(echo "$result" | jq -r '.behaviorDir // empty')
207
+
208
+ if [[ -z "$current_binding" || "$current_binding" == "null" ]]; then
209
+ echo "✓ no binding existed"
210
+ return 0
211
+ fi
212
+
213
+ # remove the bind flag
214
+ local flag_path="$current_binding/.bind/${flat_branch}.flag"
215
+ if [[ -f "$flag_path" ]]; then
216
+ rm "$flag_path"
217
+ fi
218
+
219
+ echo "✓ unbound branch '$branch' from: $(basename "$current_binding")"
220
+ }
221
+
222
+ # ────────────────────────────────────────────────────────────────────
223
+ # main
224
+ # ────────────────────────────────────────────────────────────────────
225
+
226
+ case "$ACTION" in
227
+ get)
228
+ action_get
229
+ ;;
230
+ set)
231
+ action_set
232
+ ;;
233
+ del)
234
+ action_del
235
+ ;;
236
+ esac
@@ -33,6 +33,9 @@ set -euo pipefail
33
33
  # fail loud: print what failed
34
34
  trap 'echo "❌ init.bhuild.sh failed at line $LINENO" >&2' ERR
35
35
 
36
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
37
+ REPO_ROOT="$(cd "$SCRIPT_DIR/../../../.." && pwd)"
38
+
36
39
  # parse arguments
37
40
  BEHAVIOR_NAME=""
38
41
  TARGET_DIR="$PWD"
@@ -65,6 +68,37 @@ if [[ -z "$BEHAVIOR_NAME" ]]; then
65
68
  exit 1
66
69
  fi
67
70
 
71
+ # ────────────────────────────────────────────────────────────────────
72
+ # binding check: fail fast if branch already bound to a behavior
73
+ # ────────────────────────────────────────────────────────────────────
74
+
75
+ get_bound_behavior() {
76
+ npx tsx "$REPO_ROOT/src/domain.operations/behavior/bind/getBoundBehaviorByBranch.cli.ts" "$1" 2>/dev/null || echo '{"behaviorDir":null,"bindings":[]}'
77
+ }
78
+
79
+ flatten_branch_name() {
80
+ local branch="$1"
81
+ npx tsx "$REPO_ROOT/src/domain.operations/behavior/bind/flattenBranchName.cli.ts" "$branch"
82
+ }
83
+
84
+ CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
85
+ BINDING_RESULT=$(get_bound_behavior "$CURRENT_BRANCH")
86
+ EXISTING_BEHAVIOR=$(echo "$BINDING_RESULT" | jq -r '.behaviorDir // empty')
87
+
88
+ if [[ -n "$EXISTING_BEHAVIOR" && "$EXISTING_BEHAVIOR" != "null" ]]; then
89
+ echo "error: branch '$CURRENT_BRANCH' is already bound to: $(basename "$EXISTING_BEHAVIOR")"
90
+ echo ""
91
+ echo "to create a new behavior, use a new worktree:"
92
+ echo " git worktree add ../<new-dir> -b <new-branch>"
93
+ echo " cd ../<new-dir>"
94
+ echo " init.behavior.sh --name <new-behavior>"
95
+ exit 1
96
+ fi
97
+
98
+ # ────────────────────────────────────────────────────────────────────
99
+ # behavior directory setup
100
+ # ────────────────────────────────────────────────────────────────────
101
+
68
102
  # generate isodate in format YYYY_MM_DD
69
103
  ISO_DATE=$(date +%Y_%m_%d)
70
104
 
@@ -310,6 +344,23 @@ npx rhachet roles boot --repo ehmpathy --role mechanic
310
344
  # blocker.3
311
345
  EOF
312
346
 
347
+ # ────────────────────────────────────────────────────────────────────
348
+ # auto-bind: bind current branch to newly created behavior
349
+ # ────────────────────────────────────────────────────────────────────
350
+
351
+ FLAT_BRANCH=$(flatten_branch_name "$CURRENT_BRANCH")
352
+ BIND_DIR="$BEHAVIOR_DIR/.bind"
353
+ mkdir -p "$BIND_DIR"
354
+
355
+ FLAG_PATH="$BIND_DIR/${FLAT_BRANCH}.flag"
356
+ cat > "$FLAG_PATH" <<BIND_EOF
357
+ branch: $CURRENT_BRANCH
358
+ bound_at: $(date -u +"%Y-%m-%dT%H:%M:%SZ")
359
+ bound_by: init.behavior skill
360
+ BIND_EOF
361
+
313
362
  echo ""
314
363
  echo "behavior thoughtroute initialized!"
315
364
  echo " $BEHAVIOR_DIR"
365
+ echo ""
366
+ echo "branch '$CURRENT_BRANCH' bound to: v${ISO_DATE}.${BEHAVIOR_NAME}"
@@ -0,0 +1,396 @@
1
+ #!/usr/bin/env bash
2
+ ######################################################################
3
+ # .what = review behavior artifacts against best practice rules
4
+ #
5
+ # .why = enables automated review of behavior artifacts (wish, criteria,
6
+ # blueprint, roadmap) against established rule briefs, producing
7
+ # structured feedback via bhrain review skill
8
+ #
9
+ # .how = 1. resolve behavior directory from --of argument
10
+ # 2. determine artifacts to review from --against (default: all)
11
+ # 3. invoke bhrain review for each artifact type
12
+ # 4. aggregate feedback into summary output
13
+ #
14
+ # usage:
15
+ # review.behavior.sh --of <behavior-name> [--against <targets>] [--interactive]
16
+ #
17
+ # examples:
18
+ # review.behavior.sh --of say-hello
19
+ # review.behavior.sh --of say-hello --against criteria,blueprint
20
+ # review.behavior.sh --of say-hello --interactive
21
+ #
22
+ # guarantee:
23
+ # - fail-fast if behavior not found or ambiguous
24
+ # - fail-fast if artifact file is absent
25
+ # - idempotent: safe to rerun
26
+ ######################################################################
27
+
28
+ set -euo pipefail
29
+
30
+ trap 'echo "review.behavior.sh failed at line $LINENO"' ERR
31
+
32
+ # ────────────────────────────────────────────────────────────────────
33
+ # script location resolution
34
+ # ────────────────────────────────────────────────────────────────────
35
+
36
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
37
+ BRIEFS_DIR="$SCRIPT_DIR/../briefs/practices"
38
+
39
+ # resolve claude binary (prefer global, fallback to local node_modules)
40
+ CLAUDE_BIN=""
41
+ if command -v claude >/dev/null 2>&1; then
42
+ CLAUDE_BIN="claude"
43
+ else
44
+ NPM_BIN_DIR="$(cd "$SCRIPT_DIR" && npm bin 2>/dev/null || echo "")"
45
+ if [[ -n "$NPM_BIN_DIR" && -x "$NPM_BIN_DIR/claude" ]]; then
46
+ CLAUDE_BIN="$NPM_BIN_DIR/claude"
47
+ else
48
+ echo "error: claude binary not found (install @anthropic-ai/claude-code or ensure claude is in PATH)"
49
+ exit 1
50
+ fi
51
+ fi
52
+
53
+ # ────────────────────────────────────────────────────────────────────
54
+ # argument parsing
55
+ # ────────────────────────────────────────────────────────────────────
56
+
57
+ BEHAVIOR_NAME=""
58
+ AGAINST="wish,criteria,blueprint,roadmap"
59
+ INTERACTIVE=false
60
+ TARGET_DIR="$PWD"
61
+
62
+ while [[ $# -gt 0 ]]; do
63
+ case $1 in
64
+ --of)
65
+ BEHAVIOR_NAME="$2"
66
+ shift 2
67
+ ;;
68
+ --against)
69
+ AGAINST="$2"
70
+ shift 2
71
+ ;;
72
+ --interactive)
73
+ INTERACTIVE=true
74
+ shift
75
+ ;;
76
+ --dir)
77
+ TARGET_DIR="$2"
78
+ shift 2
79
+ ;;
80
+ --skill|--repo|--role|-s)
81
+ # ignore rhachet passthrough args
82
+ shift 2
83
+ ;;
84
+ --help|-h)
85
+ echo "usage: review.behavior.sh --of <behavior-name> [--against <targets>] [--interactive]"
86
+ echo ""
87
+ echo "options:"
88
+ echo " --of <name> behavior name to review (required)"
89
+ echo " --against <list> comma-separated targets: wish,criteria,blueprint,roadmap (default: all)"
90
+ echo " --interactive run in interactive mode"
91
+ echo " --dir <path> target directory (default: current directory)"
92
+ exit 0
93
+ ;;
94
+ *)
95
+ echo "error: unknown argument '$1'"
96
+ echo "usage: review.behavior.sh --of <behavior-name> [--against <targets>] [--interactive]"
97
+ exit 1
98
+ ;;
99
+ esac
100
+ done
101
+
102
+ # validate required arguments
103
+ if [[ -z "$BEHAVIOR_NAME" ]]; then
104
+ echo "error: --of is required"
105
+ exit 1
106
+ fi
107
+
108
+ # ────────────────────────────────────────────────────────────────────
109
+ # behavior directory resolution
110
+ # ────────────────────────────────────────────────────────────────────
111
+
112
+ BEHAVIOR_ROOT="$TARGET_DIR/.behavior"
113
+ if [[ ! -d "$BEHAVIOR_ROOT" ]]; then
114
+ echo "error: .behavior/ directory not found in $TARGET_DIR"
115
+ exit 1
116
+ fi
117
+
118
+ # find matching behavior directories
119
+ MATCHES=()
120
+ while IFS= read -r -d '' dir; do
121
+ MATCHES+=("$dir")
122
+ done < <(find "$BEHAVIOR_ROOT" -maxdepth 1 -type d -name "*${BEHAVIOR_NAME}*" -print0 2>/dev/null)
123
+
124
+ if [[ ${#MATCHES[@]} -eq 0 ]]; then
125
+ echo "error: no behavior found matching '$BEHAVIOR_NAME'"
126
+ echo "available behaviors:"
127
+ ls -1 "$BEHAVIOR_ROOT" 2>/dev/null | sed 's/^/ /'
128
+ exit 1
129
+ fi
130
+
131
+ if [[ ${#MATCHES[@]} -gt 1 ]]; then
132
+ echo "error: multiple behaviors match '$BEHAVIOR_NAME'"
133
+ echo "matches:"
134
+ printf ' %s\n' "${MATCHES[@]}"
135
+ echo "please provide a more specific name"
136
+ exit 1
137
+ fi
138
+
139
+ BEHAVIOR_DIR="${MATCHES[0]}"
140
+ BEHAVIOR_DIR_REL=$(realpath --relative-to="$PWD" "$BEHAVIOR_DIR")
141
+
142
+ # ────────────────────────────────────────────────────────────────────
143
+ # artifact file resolution
144
+ # ────────────────────────────────────────────────────────────────────
145
+
146
+ # map target to filename pattern and rules path
147
+ get_artifact_info() {
148
+ local target="$1"
149
+ local behavior_dir="$2"
150
+ local found_file
151
+ local rules_dir
152
+
153
+ case "$target" in
154
+ wish)
155
+ found_file=$(find "$behavior_dir" -maxdepth 1 -name "*.wish.md" -print0 2>/dev/null \
156
+ | head -z -n1 \
157
+ | tr -d '\0')
158
+ rules_dir="$BRIEFS_DIR/behavior.wish"
159
+ ;;
160
+ criteria)
161
+ found_file=$(find "$behavior_dir" -maxdepth 1 -name "*.criteria.md" -print0 2>/dev/null \
162
+ | head -z -n1 \
163
+ | tr -d '\0')
164
+ rules_dir="$BRIEFS_DIR/behavior.criteria"
165
+ ;;
166
+ blueprint)
167
+ # find latest version: *.blueprint.vN.iM.md
168
+ found_file=$(find "$behavior_dir" -maxdepth 1 -name "*.blueprint.v*.i*.md" -print0 2>/dev/null \
169
+ | sort -zV -t'v' -k2 \
170
+ | tail -z -n1 \
171
+ | tr -d '\0')
172
+ rules_dir="$BRIEFS_DIR/behavior.blueprint"
173
+ ;;
174
+ roadmap)
175
+ # find latest version: *.roadmap.vN.iM.md
176
+ found_file=$(find "$behavior_dir" -maxdepth 1 -name "*.roadmap.v*.i*.md" -print0 2>/dev/null \
177
+ | sort -zV -t'v' -k2 \
178
+ | tail -z -n1 \
179
+ | tr -d '\0')
180
+ rules_dir="$BRIEFS_DIR/behavior.roadmap"
181
+ ;;
182
+ *)
183
+ echo ""
184
+ return
185
+ ;;
186
+ esac
187
+
188
+ echo "${found_file:-}|${rules_dir:-}"
189
+ }
190
+
191
+ # ────────────────────────────────────────────────────────────────────
192
+ # log setup
193
+ # ────────────────────────────────────────────────────────────────────
194
+
195
+ TIMESTAMP=$(date +%Y%m%d_%H%M%S)
196
+ LOG_DIR="$TARGET_DIR/.log/bhuild/review.behavior/$TIMESTAMP"
197
+ mkdir -p "$LOG_DIR"
198
+ LOG_DIR_REL=$(realpath --relative-to="$PWD" "$LOG_DIR")
199
+
200
+ # emit input args
201
+ cat > "$LOG_DIR/input.args.json" <<ARGS_EOF
202
+ {
203
+ "behavior_name": "$BEHAVIOR_NAME",
204
+ "against": "$AGAINST",
205
+ "interactive": $INTERACTIVE,
206
+ "target_dir": "$TARGET_DIR",
207
+ "behavior_dir": "$BEHAVIOR_DIR"
208
+ }
209
+ ARGS_EOF
210
+
211
+ # ────────────────────────────────────────────────────────────────────
212
+ # review invocation
213
+ # ────────────────────────────────────────────────────────────────────
214
+
215
+ # show tree-structured status
216
+ echo ""
217
+ echo "🔭 review.behavior"
218
+ echo "├── behavior: $BEHAVIOR_DIR_REL"
219
+ echo "├── against: $AGAINST"
220
+ echo "└── log: $LOG_DIR_REL"
221
+ echo ""
222
+
223
+ # parse targets
224
+ IFS=',' read -ra TARGETS <<< "$AGAINST"
225
+ BLOCKERS=()
226
+ NITPICKS=()
227
+ REVIEWED_COUNT=0
228
+ SKIPPED_COUNT=0
229
+
230
+ for target in "${TARGETS[@]}"; do
231
+ target=$(echo "$target" | tr -d ' ') # trim whitespace
232
+
233
+ # get artifact info
234
+ artifact_info=$(get_artifact_info "$target" "$BEHAVIOR_DIR")
235
+ artifact_file=$(echo "$artifact_info" | cut -d'|' -f1)
236
+ rules_dir=$(echo "$artifact_info" | cut -d'|' -f2)
237
+
238
+ if [[ -z "$rules_dir" ]]; then
239
+ echo "⚠️ unknown target '$target', skipping"
240
+ SKIPPED_COUNT=$((SKIPPED_COUNT + 1))
241
+ continue
242
+ fi
243
+
244
+ if [[ ! -d "$rules_dir" ]]; then
245
+ echo "⚠️ rules directory not found for '$target': $rules_dir"
246
+ SKIPPED_COUNT=$((SKIPPED_COUNT + 1))
247
+ continue
248
+ fi
249
+
250
+ if [[ -z "$artifact_file" || ! -f "$artifact_file" ]]; then
251
+ echo "error: artifact not found for '$target' in $BEHAVIOR_DIR"
252
+ exit 1
253
+ fi
254
+
255
+ artifact_file_rel=$(realpath --relative-to="$TARGET_DIR" "$artifact_file")
256
+
257
+ # output file path
258
+ artifact_basename=$(basename "$artifact_file" .md)
259
+ output_file="$BEHAVIOR_DIR/${artifact_basename}.[feedback].[given].by_robot.v${TIMESTAMP}.md"
260
+ output_file_rel=$(realpath --relative-to="$TARGET_DIR" "$output_file")
261
+
262
+ # get relative path for display
263
+ rules_dir_rel=$(realpath --relative-to="$TARGET_DIR" "$rules_dir")
264
+
265
+ echo "├── reviewing $target..."
266
+ echo "│ ├── artifact: $artifact_file_rel"
267
+ echo "│ ├── rules: $rules_dir_rel/rule.*.md"
268
+ echo "│ └── output: $output_file_rel"
269
+
270
+ # collect rule files and their content
271
+ RULE_FILES=$(find "$rules_dir" -name "rule.*.md" -type f | sort)
272
+ RULES_CONTENT=""
273
+ while IFS= read -r rule_file; do
274
+ rule_name=$(basename "$rule_file")
275
+ rule_content=$(cat "$rule_file")
276
+ RULES_CONTENT="${RULES_CONTENT}### ${rule_name}\n\n${rule_content}\n\n"
277
+ done <<< "$RULE_FILES"
278
+
279
+ # build prompt for bhrain review (with inlined rule content)
280
+ PROMPT=$(cat <<EOF
281
+ # review.behavior: $target
282
+
283
+ you are reviewing a behavior artifact against best practice rules.
284
+
285
+ ## artifact to review
286
+ - $artifact_file_rel
287
+
288
+ ## rules to apply
289
+
290
+ $(echo -e "$RULES_CONTENT")
291
+
292
+ ## instructions
293
+
294
+ 1. read the artifact file
295
+ 2. evaluate the artifact against each rule shown above
296
+ 3. identify BLOCKERs (must fix) and NITPICKs (suggestions)
297
+
298
+ ## output format
299
+
300
+ output your review feedback directly to stdout.
301
+
302
+ start with:
303
+ # review: $target
304
+
305
+ then list findings as:
306
+ - # blocker.N = description
307
+ - # nitpick.N = description
308
+
309
+ with clear explanations referencing the specific rules.
310
+
311
+ ## begin review
312
+
313
+ read the artifact file now and output review to stdout only.
314
+ EOF
315
+ )
316
+
317
+ # save prompt to log
318
+ echo "$PROMPT" > "$LOG_DIR/prompt.$target.md"
319
+
320
+ if [[ "$INTERACTIVE" == "true" ]]; then
321
+ # interactive mode: run claude and show output
322
+ (cd "$TARGET_DIR" && "$CLAUDE_BIN" --print "$PROMPT") | tee "$output_file"
323
+ else
324
+ # non-interactive: run with spinner
325
+ echo -n "│ ⏳ "
326
+ (cd "$TARGET_DIR" && echo "$PROMPT" | "$CLAUDE_BIN" --print 2>&1) > "$LOG_DIR/output.$target.md" &
327
+ CLAUDE_PID=$!
328
+
329
+ # spinner animation
330
+ SPINNER="⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏"
331
+ ELAPSED=0
332
+ while kill -0 $CLAUDE_PID 2>/dev/null; do
333
+ for (( i=0; i<${#SPINNER}; i++ )); do
334
+ if ! kill -0 $CLAUDE_PID 2>/dev/null; then break; fi
335
+ echo -ne "\r│ ⏳ ${SPINNER:$i:1} ${ELAPSED}s"
336
+ sleep 0.1
337
+ done
338
+ ELAPSED=$((ELAPSED + 1))
339
+ done
340
+
341
+ wait $CLAUDE_PID
342
+ CLAUDE_EXIT=$?
343
+
344
+ echo -e "\r│ ✓ complete (${ELAPSED}s) "
345
+
346
+ if [[ $CLAUDE_EXIT -eq 0 ]]; then
347
+ # copy output to feedback file
348
+ cp "$LOG_DIR/output.$target.md" "$output_file"
349
+
350
+ # extract blockers and nitpicks
351
+ while IFS= read -r line; do
352
+ BLOCKERS+=("[$target] $line")
353
+ done < <(grep -i "^# blocker" "$output_file" 2>/dev/null || true)
354
+
355
+ while IFS= read -r line; do
356
+ NITPICKS+=("[$target] $line")
357
+ done < <(grep -i "^# nitpick" "$output_file" 2>/dev/null || true)
358
+ else
359
+ echo "│ ⛈️ review failed (exit code: $CLAUDE_EXIT)"
360
+ fi
361
+ fi
362
+
363
+ REVIEWED_COUNT=$((REVIEWED_COUNT + 1))
364
+ done
365
+
366
+ # ────────────────────────────────────────────────────────────────────
367
+ # summary output
368
+ # ────────────────────────────────────────────────────────────────────
369
+
370
+ echo ""
371
+ echo "────────────────────────────────────────"
372
+ echo "🌿 summary"
373
+ echo "├── reviewed: $REVIEWED_COUNT"
374
+ echo "├── skipped: $SKIPPED_COUNT"
375
+ echo "├── blockers: ${#BLOCKERS[@]}"
376
+ echo "└── nitpicks: ${#NITPICKS[@]}"
377
+
378
+ if [[ ${#BLOCKERS[@]} -gt 0 ]]; then
379
+ echo ""
380
+ echo "⛈️ blockers:"
381
+ for b in "${BLOCKERS[@]}"; do
382
+ echo " - $b"
383
+ done
384
+ fi
385
+
386
+ if [[ ${#NITPICKS[@]} -gt 0 ]]; then
387
+ echo ""
388
+ echo "🌊 nitpicks:"
389
+ for n in "${NITPICKS[@]}"; do
390
+ echo " - $n"
391
+ done
392
+ fi
393
+
394
+ echo ""
395
+ echo "✨ review.behavior complete"
396
+ echo "└── log: $LOG_DIR_REL"