Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"source": "git-subdir",
"url": "https://github.com/sendbird/sendbird-client-plugin.git",
"path": "plugins/sendbird-client",
"ref": "v0.1.47"
"ref": "v0.1.48"
},
"description": "Sendbird integration helper for Chat (incl. auth/session) and UIKit across iOS, Android, and JS. Includes hooks that run local shell scripts; see README \"What runs on your machine\"."
}
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,16 @@ This plugin runs inside Claude Code with your user account's permissions. Three
| Session start | `hooks/welcome.sh` | plugin files | adds the plugin's rules to the model's context | none |
| Before a file write or shell command | `hooks/credential-guard.sh` | the content or command about to run | blocks it if it contains a credential | none |
| Before a shell command | `hooks/destructive-command-guard.sh` | the command about to run | asks you to approve a Sendbird CLI `delete`, `revoke`, or `deactivate` run with `--yes`; in a `-p` run it is denied | none |
| Before a file write, or a shell command that writes a source file | `hooks/source-claim-guard.sh` | the content about to be written, local files it cites | blocks Sendbird API code without a verifiable source | fetches the cited page if it is on `sendbird.com/docs` or `github.com/sendbird` |
| Before a file write, or a shell command that writes a source file | `hooks/source-claim-guard.sh` | the content about to be written, local files it cites | blocks Sendbird API code without a verifiable source: a plugin file, an installed SDK file (`node_modules/@sendbird`, `Pods`, `.build`, Xcode `SourcePackages` or `DerivedData`, the Gradle cache), or a public page; a file the model wrote in your project does not count | fetches the cited page if it is on `sendbird.com/docs` or is a file in a `github.com/sendbird` repository (a `/blob/` or `/raw/` link); issues, discussions, and pull requests are not fetched |
| After an agent finishes | `hooks/unsourced-claim-warn.sh` | the agent's reply | adds a warning when an API claim has no source; in Codex, sends the agent back once to add sources | none |
| When the answer ends | `hooks/final-answer-gate.sh` | the final answer (passed by Claude Code; older versions: the session transcript after your last prompt) | asks the model to revise an unsourced answer | same as `source-claim-guard.sh` |
| When the answer ends, only when `SENDBIRD_NONINTERACTIVE` is set | `hooks/run-summary-gate.sh` | the final answer and the plugin's run summary schema | asks the model to fix a run summary that does not match the schema | none |
| When the answer ends, only when `SENDBIRD_NONINTERACTIVE` is `1`, `true`, or `yes` | `hooks/run-summary-gate.sh` | the final answer and the plugin's run summary schema | asks the model to fix a run summary that does not match the schema | none |
| Before and after an agent runs | `hooks/telemetry-start.sh`, `hooks/telemetry-end.sh` | agent name, duration, outcome | nothing; writes a local log only if you opted in | none |

The two fetching hooks send a plain request for the cited public page (8-second timeout); nothing from your project or conversation is sent.

The hooks read their input with `jq`. When `jq` is not on your `PATH`, the credential, source, and destructive-command guards cannot check a call, so instead of blocking or allowing it they ask you to approve every file write and shell command, and the session start says that `jq` is missing. The other hooks then do nothing. Install `jq` to turn the checks back on.

**Scripts the agent runs** through Claude Code's Bash tool, under your Claude Code permission settings: project detection (reads manifests such as `package.json`, `Podfile`, `Package.swift`, `build.gradle`) and the installed-SDK reader (reads `node_modules/@sendbird/*`, `Pods/`, `.build/`, this project's Xcode `DerivedData`, and the Gradle cache).

**Instructions** — skills and agents that tell Claude how to work. They change what Claude does in your session.
Expand Down
2 changes: 1 addition & 1 deletion plugins/sendbird-client/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sendbird-client",
"displayName": "Sendbird Client",
"version": "0.1.47",
"version": "0.1.48",
"description": "Sendbird integration helper for Chat (incl. auth/session) and UIKit across iOS, Android, and JS",
"author": {
"name": "Sendbird",
Expand Down
2 changes: 1 addition & 1 deletion plugins/sendbird-client/.codex-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sendbird-client",
"version": "0.1.47",
"version": "0.1.48",
"description": "Sendbird integration helper for Chat (incl. auth/session) and UIKit across iOS, Android, and JS",
"author": {
"name": "Sendbird",
Expand Down
2 changes: 1 addition & 1 deletion plugins/sendbird-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
> Generated by `tools/editions/build.sh` from the repository root. Do not edit this folder;
> change the root and rerun the build.

`sendbird-client` v0.1.47 — Sendbird integration helper for Chat (incl. auth/session) and UIKit across iOS, Android, and JS.
`sendbird-client` v0.1.48 — Sendbird integration helper for Chat (incl. auth/session) and UIKit across iOS, Android, and JS.

## Products

Expand Down
2 changes: 1 addition & 1 deletion plugins/sendbird-client/config/plugin-config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"schemaVersion": "0.1.47",
"schemaVersion": "0.1.48",
"knowledge": {
"mode": "runtime-fetch",
"_modes": [
Expand Down
2 changes: 1 addition & 1 deletion plugins/sendbird-client/docs/AGENT_CONTRACT.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Return:

## 7. Non-interactive runs

When `SENDBIRD_NONINTERACTIVE` is set (for example `SENDBIRD_NONINTERACTIVE=1 claude -p ...` in CI or a script), nobody can answer a question during the run.
When `SENDBIRD_NONINTERACTIVE` is `1`, `true`, or `yes` in any case (for example `SENDBIRD_NONINTERACTIVE=1 claude -p ...` in CI or a script), nobody can answer a question during the run. Any other value, including an empty one, `0`, `false`, or `no`, keeps the run interactive.

- Never ask the user a question, and never end the answer with one.
- For a value you would otherwise ask for, use the environment (`SENDBIRD_APP_ID`, `SENDBIRD_PRODUCTS`, `SENDBIRD_REGION`, `SENDBIRD_PLAN`) or the project's `profile.json` when they have it.
Expand Down
2 changes: 1 addition & 1 deletion plugins/sendbird-client/hooks/credential-guard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
set -uo pipefail
HERE="$(cd "$(dirname "$0")" && pwd)"
source "$HERE/lib/hook-helpers.sh"
read_stdin_json
read_stdin_json guard

tool="$(jget .tool_name)"
case "$tool" in
Expand Down
11 changes: 8 additions & 3 deletions plugins/sendbird-client/hooks/destructive-command-guard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,26 @@ set -uo pipefail
HERE="$(cd "$(dirname "$0")" && pwd)"
# shellcheck source=lib/hook-helpers.sh
source "$HERE/lib/hook-helpers.sh"
read_stdin_json
read_stdin_json guard

[ "$(jget .tool_name)" = "Bash" ] || exit 0
cmd="$(jget .tool_input.command)"
[ -n "$cmd" ] || exit 0

# Look at each simple command (split on ; && || | and newlines) on its own.
# Normalize before matching: quotes, backticks, and command substitution become spaces, so a
# command wrapped as bash -c "sendbird ...", sh -c'...', zsh -c, eval "...", $(...), or with a
# quoted program name reads as plain words. Then look at each simple command (split on
# ; && || | and newlines) on its own. An env or sudo prefix needs nothing: the CLI name is
# matched anywhere after a space.
norm="$(printf '%s\n' "$cmd" | tr "\"'\`()" ' ')"
hit=""
while IFS= read -r part; do
# the CLI: sendbird, sendbird-cli, or npx/pnpm dlx/bunx @sendbird/cli
printf '%s' "$part" | grep -Eq '(^|[[:space:]/])(sendbird|sendbird-cli|@sendbird/cli(@[^[:space:]]*)?)([[:space:]]|$)' || continue
printf '%s' "$part" | grep -Eq '(^|[[:space:]])(delete|revoke|deactivate)([[:space:]]|$)' || continue
printf '%s' "$part" | grep -Eq '(^|[[:space:]])(--yes|-y)([[:space:]=]|$)' || continue
hit="$part"; break
done < <(printf '%s\n' "$cmd" | sed -E 's/(&&|\|\||;|\|)/\n/g')
done < <(printf '%s\n' "$norm" | sed -E 's/(&&|\|\||;|\|)/\n/g')
[ -n "$hit" ] || exit 0

jq -n --arg c "$(printf '%s' "$hit" | sed -E 's/^[[:space:]]+//' | cut -c1-200)" '{
Expand Down
63 changes: 15 additions & 48 deletions plugins/sendbird-client/hooks/final-answer-gate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Stop hook: citation gate for the FINAL answer of a turn (closes the gap where the
# main loop names Sendbird APIs without any skill/agent involved — dogfood round 2).
#
# Behavior: if the final answer contains Sendbird-specific API identifiers AND code,
# Behavior: if the final answer contains Sendbird-specific API identifiers AND code (or, in
# prose, a Sendbird error code or a dotted Sendbird symbol),
# but no citation marker, block ONCE with a reason (Claude continues and adds sources
# or corrects). The documented `stop_hook_active` guard makes the second pass exit 0,
# so this can never loop or trap the session. Fail-open on any parsing problem.
Expand All @@ -22,9 +23,15 @@ text="$(final_answer_text)"
# line; otherwise PR numbers, dates and IDs would gate unrelated answers.
code_ctx='(error|Error|ERROR|code|Code|에러|오류|코드)[^0-9]{0,24}[0-9]{6}([^0-9]|$)'

# Only gate Sendbird-flavored answers that include code-shaped content.
# A Sendbird type followed by a member (GroupChannel.createChannel) names an API even in prose.
dotted_symbol='(SendbirdChat|SendBirdCall|SendbirdCalls|AIAgentMessenger|SendbirdUIKit|SendbirdLive|SendbirdDesk|SendBirdDesk|MessengerLauncher|GroupChannel|BaseMessage|SBU[A-Z][A-Za-z0-9_]*|SBA[A-Z][A-Za-z0-9_]*|SBDSK[A-Za-z0-9_]*)\.[A-Za-z_]'

# Gate Sendbird-flavored answers that include code-shaped content, and prose answers that name
# a Sendbird error code or a dotted Sendbird symbol ("Error code 400302 means ..." has no code
# block but states a fact that needs a source). A bare type name in prose is not checked.
printf '%s' "$text" | grep -Eq "SendbirdChat|SendBirdCall|SendbirdCalls|AIAgentMessenger|SendbirdUIKit|SendbirdLive|SendbirdDesk|SendBirdDesk|MessengerLauncher|GroupChannel|BaseMessage|@sendbird/|\bSBU[A-Z]|\bSBA[A-Z]|\bSBDSK|$code_ctx" || exit 0
printf '%s' "$text" | grep -Eq '```|[A-Za-z]\([A-Za-z]*:' || exit 0
printf '%s' "$text" | grep -Eq '```|[A-Za-z]\([A-Za-z]*:' \
|| printf '%s' "$text" | grep -Eq "$code_ctx|$dotted_symbol" || exit 0

# Pass only when a concrete source marker resolves to a shipped local file or an
# allowed public URL. Vague words such as "verified" are not citations.
Expand All @@ -35,51 +42,11 @@ error_codes="$(printf '%s' "$text" | grep -Eo "$code_ctx" | grep -Eo '[0-9]{6}'
symbols="$(printf '%s\n%s\n%s\n' "$symbols" "$instance_methods" "$error_codes" | sed '/^$/d' | sort -u)"
# Nothing checkable (for example a bare package name in prose): let it pass.
[ -n "$symbols" ] || exit 0
source_supports_symbol() {
local file="$1" symbol="$2" method
[ -s "$file" ] || return 1
grep -Fq -- "$symbol" "$file" && return 0
method="${symbol#*.}"
grep -Eq -- "(^|[^A-Za-z0-9_])${method}([^A-Za-z0-9_]|$)" "$file"
}
cwd="$(jget '.cwd')"
resolved_sources=()
tmp_sources=()
while IFS= read -r source; do
[ -n "$source" ] || continue
case "$source" in
https://sendbird.com/docs/*|https://github.com/sendbird/*)
tmp_source="$(mktemp)"
if curl -fsSL --max-time 8 "$source" -o "$tmp_source" 2>/dev/null; then
resolved_sources+=("$tmp_source")
tmp_sources+=("$tmp_source")
else
rm -f "$tmp_source"
fi
;;
knowledge/curated/*)
root="${CLAUDE_PLUGIN_ROOT:-.}"
resolved_sources+=("$root/$source")
;;
.sendbird-client/cache/*)
project_root="${cwd:-$(pwd)}"
resolved_sources+=("$project_root/$source")
;;
*.swiftinterface|*.d.ts) resolved_sources+=("$source") ;;
esac
done <<< "$sources"

valid=1
while IFS= read -r symbol; do
supported=0
for source_file in ${resolved_sources[@]+"${resolved_sources[@]}"}; do
if source_supports_symbol "$source_file" "$symbol"; then supported=1; break; fi
done
[ "$supported" -eq 1 ] || { valid=0; break; }
done <<< "$symbols"
for tmp_source in ${tmp_sources[@]+"${tmp_sources[@]}"}; do rm -f "$tmp_source"; done
[ "$valid" -eq 1 ] && exit 0
# Plugin files, the plugin's SDK cache, installed SDK interfaces, and public Sendbird pages
# (hooks/lib/hook-helpers.sh resolve_cited_sources); a file the model wrote in the app does not count.
resolve_cited_sources "$(jget '.cwd')" <<< "$sources"
all_symbols_sourced "$symbols" && exit 0

jq -n '{decision: "block",
reason: "Final-answer citation gate (Sendbird plugin): this answer names Sendbird APIs/code but cites no source. Re-emit it citing a verifiable source per symbol — knowledge/curated/<platform>/... , the customer-local SDK surface, a public sendbird/* repo, or a version-matched sendbird.com/docs page — or state: I do not know, and list what you checked. Do not invent symbols."}'
reason: "Final-answer citation gate (Sendbird plugin): this answer names Sendbird APIs/code but cites no source. Re-emit it citing a verifiable source per symbol — knowledge/curated/<platform>/... , the customer-local SDK surface or installed SDK files, a file in a public sendbird/* repo (a /blob/ or /raw/ link, not an issue or discussion), or a version-matched sendbird.com/docs page — or state: I do not know, and list what you checked. Do not invent symbols."}'
exit 0
114 changes: 113 additions & 1 deletion plugins/sendbird-client/hooks/lib/hook-helpers.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
#!/usr/bin/env bash
# Shared helpers for hook scripts. Source this file. Reads stdin JSON once.

# read_stdin_json : caches the stdin payload into $HOOK_JSON (empty if none/not json)
# JQ_MISSING_REASON : what a guard tells the user when jq is missing (welcome.sh says it too)
JQ_MISSING_REASON='The Sendbird plugin safety checks (credential, source citation, and destructive-command guards) need jq, which is not on PATH, so this call was not checked. Approve it only if you trust it, and install jq to turn the checks back on.'

# ask_without_jq : the PreToolUse "ask" decision, built with printf because jq is absent
ask_without_jq() {
printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"ask","permissionDecisionReason":"%s"}}\n' "$JQ_MISSING_REASON"
}

# read_stdin_json [guard] : caches the stdin payload into $HOOK_JSON (empty if none/not json).
# Every hook reads its input with jq. Without jq on PATH no check can run, so the hook stops
# here instead of reading '{}' and letting everything through: a PreToolUse guard (called with
# "guard") asks the user to approve the call, and any other hook exits 0 without blocking.
read_stdin_json() {
if ! command -v jq >/dev/null 2>&1; then
cat >/dev/null 2>&1 || true
[ "${1:-}" = guard ] && ask_without_jq
exit 0
fi
HOOK_JSON="$(cat 2>/dev/null || true)"
if ! printf '%s' "$HOOK_JSON" | jq -e . >/dev/null 2>&1; then HOOK_JSON='{}'; fi
}

# is_noninteractive : 0 when SENDBIRD_NONINTERACTIVE turns on a non-interactive run (1, true, or
# yes in any case). Empty, 0, false, no, and any other value keep the run interactive. welcome.sh
# and run-summary-gate.sh both use this, so the model is told about the run summary exactly when
# the gate checks it. (tr, not ${v,,}: stock macOS bash 3.2.)
is_noninteractive() {
case "$(printf '%s' "${SENDBIRD_NONINTERACTIVE:-}" | tr '[:upper:]' '[:lower:]')" in
1|true|yes) return 0 ;;
*) return 1 ;;
esac
}

# jget <jq-path> : echo a string field from $HOOK_JSON ('' if absent)
jget() { printf '%s' "$HOOK_JSON" | jq -r "$1 // empty" 2>/dev/null; }

Expand Down Expand Up @@ -34,6 +61,91 @@ final_answer_text() {
printf '%s' "$text"
}

# --- Cited sources (source-claim-guard.sh, final-answer-gate.sh) ---------------------------
# A cited source counts only when the model cannot have written it in this session.

# public_source_url <url> : 0 for a page Sendbird controls: sendbird.com/docs, or a file at a
# ref in a sendbird GitHub repository (/blob/ or /raw/, or raw.githubusercontent.com). Issues,
# discussions, pull requests, and other GitHub pages are written by anyone, so they do not count.
public_source_url() {
printf '%s' "$1" | grep -Eq '^https://sendbird\.com/docs/|^https://github\.com/sendbird/[A-Za-z0-9._-]+/(blob|raw)/[^[:space:]]+|^https://raw\.githubusercontent\.com/sendbird/[A-Za-z0-9._-]+/[^[:space:]]+'
}

# sdk_source_path <path> <cwd> : prints the real path of a local .d.ts or .swiftinterface when it
# is inside an installed SDK (node_modules/@sendbird or node_modules/sendbird-*, Pods, .build,
# SourcePackages, DerivedData, the Gradle cache) or the plugin's own knowledge/ or templates/;
# prints nothing for any other file, such as one the model just wrote in the app's folders.
# A relative path resolves from <cwd>; ".." is resolved before the check.
sdk_source_path() {
local p="$1" cwd="$2" d real root
case "$p" in /*) ;; *) p="${cwd:-$(pwd)}/$p" ;; esac
[ -f "$p" ] || return 0
d="$(cd "$(dirname "$p")" 2>/dev/null && pwd -P)" || return 0
real="$d/$(basename "$p")"
root="$(cd "${CLAUDE_PLUGIN_ROOT:-$(dirname "${BASH_SOURCE[0]}")/../..}" 2>/dev/null && pwd -P)"
case "$real" in
"$root"/knowledge/*|"$root"/templates/*) printf '%s' "$real" ;;
*/node_modules/@sendbird/*|*/node_modules/sendbird-*|*/Pods/*|*/.build/*|*/SourcePackages/*|*/DerivedData/*|*/.gradle/caches/*)
printf '%s' "$real" ;;
esac
}

# resolve_cited_sources <cwd> : reads cited source tokens on stdin, one per line, and fills
# RESOLVED_SOURCES with the files to search for a symbol: plugin files (knowledge/, templates/),
# the plugin's cache of the customer's installed SDK, installed SDK interfaces, and fetched
# copies of public pages. Fetched copies are also in TMP_SOURCES; remove them when done.
resolve_cited_sources() {
local cwd="$1" source tmp_source local_path root="${CLAUDE_PLUGIN_ROOT:-.}"
RESOLVED_SOURCES=(); TMP_SOURCES=()
while IFS= read -r source; do
[ -n "$source" ] || continue
case "$source" in *..*) continue ;; esac
case "$source" in
knowledge/*|templates/*)
RESOLVED_SOURCES+=("$root/$source") ;;
.sendbird-client/cache/*)
RESOLVED_SOURCES+=("${cwd:-$(pwd)}/$source") ;;
*.swiftinterface|*.d.ts)
local_path="$(sdk_source_path "$source" "$cwd")"
[ -z "$local_path" ] || RESOLVED_SOURCES+=("$local_path") ;;
https://*)
public_source_url "$source" || continue
tmp_source="$(mktemp)"
if curl -fsSL --max-time 8 "$source" -o "$tmp_source" 2>/dev/null; then
RESOLVED_SOURCES+=("$tmp_source"); TMP_SOURCES+=("$tmp_source")
else
rm -f "$tmp_source"
fi ;;
esac
done
}

# source_supports_symbol <file> <symbol> : 0 when the file names the symbol, or for Type.member
# the member as a whole word
source_supports_symbol() {
local file="$1" symbol="$2" method
[ -s "$file" ] || return 1
grep -Fq -- "$symbol" "$file" && return 0
method="${symbol#*.}"
grep -Eq -- "(^|[^A-Za-z0-9_])${method}([^A-Za-z0-9_]|$)" "$file"
}

# all_symbols_sourced <symbols> : 0 when every symbol (one per line) is in one of
# RESOLVED_SOURCES. Removes the fetched copies either way.
all_symbols_sourced() {
local symbol supported source_file valid=1
while IFS= read -r symbol; do
[ -n "$symbol" ] || continue
supported=0
for source_file in ${RESOLVED_SOURCES[@]+"${RESOLVED_SOURCES[@]}"}; do
if source_supports_symbol "$source_file" "$symbol"; then supported=1; break; fi
done
[ "$supported" -eq 1 ] || { valid=0; break; }
done <<< "$1"
for source_file in ${TMP_SOURCES[@]+"${TMP_SOURCES[@]}"}; do rm -f "$source_file"; done
[ "$valid" -eq 1 ]
}

# emit_warning <text> : warn-only output (exit 0 in caller). Never blocks.
emit_warning() { jq -n --arg m "$1" '{systemMessage: $m}'; }

Expand Down
4 changes: 2 additions & 2 deletions plugins/sendbird-client/hooks/run-summary-gate.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# Stop hook for non-interactive runs (SENDBIRD_NONINTERACTIVE set): the caller, a CLI or a
# Stop hook for non-interactive runs (SENDBIRD_NONINTERACTIVE=1, true, or yes): the caller, a CLI or a
# script, decides what to do next from the run summary the answer ends with, so its shape is
# checked before the run ends. A follow-up request sent with --resume does not get the
# session-start instructions again, and such a run once ended with "status": "ok" and no
Expand All @@ -12,7 +12,7 @@ HERE="$(cd "$(dirname "$0")" && pwd)"
source "$HERE/lib/hook-helpers.sh"
read_stdin_json

[ -n "${SENDBIRD_NONINTERACTIVE:-}" ] || exit 0
is_noninteractive || exit 0
[ "$(jget '.stop_hook_active')" = "true" ] && exit 0
SCHEMA="${CLAUDE_PLUGIN_ROOT:-$HERE/..}/core/schemas/run-summary.schema.json"
[ -r "$SCHEMA" ] || exit 0
Expand Down
Loading
Loading