feat(hooks): add cross-platform safety and status hooks
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
$data = ($input | Out-String) | ConvertFrom-Json
|
||||
$model = if ($data.model.display_name) { $data.model.display_name } else { '-' }
|
||||
$effort = if ($data.effort.level) { $data.effort.level } else { '-' }
|
||||
$directory = if ($data.workspace.current_dir) { $data.workspace.current_dir } else { $data.cwd }
|
||||
$repo = if ($data.workspace.repo.name) { $data.workspace.repo.name } elseif ($directory) { Split-Path $directory -Leaf } else { '-' }
|
||||
$branch = if ($directory -and (Get-Command git -ErrorAction SilentlyContinue)) { (& git -C $directory branch --show-current 2>$null | Select-Object -First 1) } else { $null }
|
||||
if (-not $branch) { $branch = '-' }
|
||||
$maxContext = if ($data.context_window.context_window_size) { [long]$data.context_window.context_window_size } else { 0 }
|
||||
$usedContext = if ($null -ne $data.context_window.used_percentage) { "$([math]::Round([double]$data.context_window.used_percentage, [MidpointRounding]::AwayFromZero))%" } else { '-' }
|
||||
$usedTokens = [long]$data.context_window.total_input_tokens + [long]$data.context_window.total_output_tokens
|
||||
Write-Output "Model: $model | Effort: $effort | Repo: $repo | Branch: $branch | Max Context: $maxContext | Used Context: $usedContext | Used Tokens: $usedTokens"
|
||||
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
command -v jq >/dev/null 2>&1 || exit 0
|
||||
input=
|
||||
while IFS= read -r line || [ -n "$line" ]; do input+="$line"; done
|
||||
IFS=$'\t' read -r model effort repo directory max_context used_context used_tokens < <(
|
||||
printf '%s' "$input" | jq -r '[
|
||||
(.model.display_name // "-"),
|
||||
(.effort.level // "-"),
|
||||
(.workspace.repo.name // "-"),
|
||||
(.workspace.current_dir // .cwd // "."),
|
||||
(.context_window.context_window_size // 0),
|
||||
(if .context_window.used_percentage == null then "-" else ((.context_window.used_percentage | round | tostring) + "%") end),
|
||||
((.context_window.total_input_tokens // 0) + (.context_window.total_output_tokens // 0))
|
||||
] | @tsv'
|
||||
)
|
||||
[ "$repo" != - ] || repo=$(basename -- "$directory")
|
||||
[ -n "$repo" ] || repo=-
|
||||
branch=$(git -C "$directory" branch --show-current 2>/dev/null || true)
|
||||
[ -n "$branch" ] || branch=-
|
||||
printf 'Model: %s | Effort: %s | Repo: %s | Branch: %s | Max Context: %s | Used Context: %s | Used Tokens: %s\n' "$model" "$effort" "$repo" "$branch" "$max_context" "$used_context" "$used_tokens"
|
||||
Reference in New Issue
Block a user