feat: Embedded baseline MCP config and global tools
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import os
|
||||
from typing import List, Literal, Optional
|
||||
|
||||
def run(
|
||||
string: str,
|
||||
string_enum: Literal["foo", "bar"],
|
||||
boolean: bool,
|
||||
integer: int,
|
||||
number: float,
|
||||
array: List[str],
|
||||
string_optional: Optional[str] = None,
|
||||
array_optional: Optional[List[str]] = None,
|
||||
):
|
||||
"""Demonstrates how to create a tool using Python and how to use comments.
|
||||
Args:
|
||||
string: Define a required string property
|
||||
string_enum: Define a required string property with enum
|
||||
boolean: Define a required boolean property
|
||||
integer: Define a required integer property
|
||||
number: Define a required number property
|
||||
array: Define a required string array property
|
||||
string_optional: Define an optional string property
|
||||
array_optional: Define an optional string array property
|
||||
"""
|
||||
output = f"""string: {string}
|
||||
string_enum: {string_enum}
|
||||
string_optional: {string_optional}
|
||||
boolean: {boolean}
|
||||
integer: {integer}
|
||||
number: {number}
|
||||
array: {array}
|
||||
array_optional: {array_optional}"""
|
||||
|
||||
for key, value in os.environ.items():
|
||||
if key.startswith("LLM_"):
|
||||
output = f"{output}\n{key}: {value}"
|
||||
|
||||
return output
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Demonstrate how to create a tool using Bash and how to use comment tags.
|
||||
# @option --string! Define a required string property
|
||||
# @option --string-enum![foo|bar] Define a required string property with enum
|
||||
# @option --string-optional Define a optional string property
|
||||
# @flag --boolean Define a boolean property
|
||||
# @option --integer! <INT> Define a required integer property
|
||||
# @option --number! <NUM> Define a required number property
|
||||
# @option --array+ <VALUE> Define a required string array property
|
||||
# @option --array-optional* Define a optional string array property
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
cat <<EOF >> "$LLM_OUTPUT"
|
||||
string: ${argc_string}
|
||||
string_enum: ${argc_string_enum}
|
||||
string_optional: ${argc_string_optional}
|
||||
boolean: ${argc_boolean}
|
||||
integer: ${argc_integer}
|
||||
number: ${argc_number}
|
||||
array: ${argc_array[@]}
|
||||
array_optional: ${argc_array_optional[@]}
|
||||
$(printenv | grep '^LLM_')
|
||||
EOF
|
||||
}
|
||||
Executable
+204
@@ -0,0 +1,204 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Execute the shell command.
|
||||
# @option --command! The command to execute.
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
PROMPT_UTILS="${LLM_ROOT_DIR:-$(dirname "${BASH_SOURCE[0]}")/..}/utils/prompt-utils.sh"
|
||||
# shellcheck disable=SC1090
|
||||
source "$PROMPT_UTILS"
|
||||
|
||||
main() {
|
||||
guard_operation
|
||||
# shellcheck disable=SC2154
|
||||
eval "$argc_command" >> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
# ARGC-BUILD {
|
||||
# This block was generated by argc (https://github.com/sigoden/argc).
|
||||
# Modifying it manually is not recommended
|
||||
|
||||
_argc_run() {
|
||||
if [[ "${1:-}" == "___internal___" ]]; then
|
||||
_argc_die "error: unsupported ___internal___ command"
|
||||
fi
|
||||
if [[ "${OS:-}" == "Windows_NT" ]] && [[ -n "${MSYSTEM:-}" ]]; then
|
||||
set -o igncr
|
||||
fi
|
||||
argc__args=("$(basename "$0" .sh)" "$@")
|
||||
argc__positionals=()
|
||||
_argc_index=1
|
||||
_argc_len="${#argc__args[@]}"
|
||||
_argc_tools=()
|
||||
_argc_parse
|
||||
if [ -n "${argc__fn:-}" ]; then
|
||||
$argc__fn "${argc__positionals[@]}"
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_usage() {
|
||||
cat <<-'EOF'
|
||||
Execute the shell command.
|
||||
|
||||
USAGE: --command <COMMAND>
|
||||
|
||||
OPTIONS:
|
||||
--command <COMMAND> The command to execute.
|
||||
-h, --help Print help
|
||||
-V, --version Print version
|
||||
|
||||
ENVIRONMENTS:
|
||||
LLM_OUTPUT The output path [default: /dev/stdout]
|
||||
EOF
|
||||
exit
|
||||
}
|
||||
|
||||
_argc_version() {
|
||||
echo 0.0.0
|
||||
exit
|
||||
}
|
||||
|
||||
_argc_parse() {
|
||||
local _argc_key _argc_action
|
||||
local _argc_subcmds=""
|
||||
while [[ $_argc_index -lt $_argc_len ]]; do
|
||||
_argc_item="${argc__args[_argc_index]}"
|
||||
_argc_key="${_argc_item%%=*}"
|
||||
case "$_argc_key" in
|
||||
--help | -help | -h)
|
||||
_argc_usage
|
||||
;;
|
||||
--version | -version | -V)
|
||||
_argc_version
|
||||
;;
|
||||
--)
|
||||
_argc_dash="${#argc__positionals[@]}"
|
||||
argc__positionals+=("${argc__args[@]:$((_argc_index + 1))}")
|
||||
_argc_index=$_argc_len
|
||||
break
|
||||
;;
|
||||
--command)
|
||||
_argc_take_args "--command <COMMAND>" 1 1 "-" ""
|
||||
_argc_index=$((_argc_index + _argc_take_args_len + 1))
|
||||
if [[ -z "${argc_command:-}" ]]; then
|
||||
argc_command="${_argc_take_args_values[0]:-}"
|
||||
else
|
||||
_argc_die "error: the argument \`--command\` cannot be used multiple times"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
if _argc_maybe_flag_option "-" "$_argc_item"; then
|
||||
_argc_die "error: unexpected argument \`$_argc_key\` found"
|
||||
fi
|
||||
argc__positionals+=("$_argc_item")
|
||||
_argc_index=$((_argc_index + 1))
|
||||
;;
|
||||
esac
|
||||
done
|
||||
_argc_require_params "error: the following required arguments were not provided:" \
|
||||
'argc_command:--command <COMMAND>'
|
||||
if [[ -n "${_argc_action:-}" ]]; then
|
||||
$_argc_action
|
||||
else
|
||||
argc__fn=main
|
||||
if [[ "${argc__positionals[0]:-}" == "help" ]] && [[ "${#argc__positionals[@]}" -eq 1 ]]; then
|
||||
_argc_usage
|
||||
fi
|
||||
if [[ -z "${LLM_OUTPUT:-}" ]]; then
|
||||
export LLM_OUTPUT=/dev/stdout
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_take_args() {
|
||||
_argc_take_args_values=()
|
||||
_argc_take_args_len=0
|
||||
local param="$1" min="$2" max="$3" signs="$4" delimiter="$5"
|
||||
if [[ "$min" -eq 0 ]] && [[ "$max" -eq 0 ]]; then
|
||||
return
|
||||
fi
|
||||
local _argc_take_index=$((_argc_index + 1)) _argc_take_value
|
||||
if [[ "$_argc_item" == *=* ]]; then
|
||||
_argc_take_args_values=("${_argc_item##*=}")
|
||||
else
|
||||
while [[ $_argc_take_index -lt $_argc_len ]]; do
|
||||
_argc_take_value="${argc__args[_argc_take_index]}"
|
||||
if _argc_maybe_flag_option "$signs" "$_argc_take_value"; then
|
||||
if [[ "${#_argc_take_value}" -gt 1 ]]; then
|
||||
break
|
||||
fi
|
||||
fi
|
||||
_argc_take_args_values+=("$_argc_take_value")
|
||||
_argc_take_args_len=$((_argc_take_args_len + 1))
|
||||
if [[ "$_argc_take_args_len" -ge "$max" ]]; then
|
||||
break
|
||||
fi
|
||||
_argc_take_index=$((_argc_take_index + 1))
|
||||
done
|
||||
fi
|
||||
if [[ "${#_argc_take_args_values[@]}" -lt "$min" ]]; then
|
||||
_argc_die "error: incorrect number of values for \`$param\`"
|
||||
fi
|
||||
if [[ -n "$delimiter" ]] && [[ "${#_argc_take_args_values[@]}" -gt 0 ]]; then
|
||||
local item values arr=()
|
||||
for item in "${_argc_take_args_values[@]}"; do
|
||||
IFS="$delimiter" read -r -a values <<<"$item"
|
||||
arr+=("${values[@]}")
|
||||
done
|
||||
_argc_take_args_values=("${arr[@]}")
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_require_params() {
|
||||
local message="$1" missed_envs="" item name render_name
|
||||
for item in "${@:2}"; do
|
||||
name="${item%%:*}"
|
||||
render_name="${item##*:}"
|
||||
if [[ -z "${!name:-}" ]]; then
|
||||
missed_envs="$missed_envs"$'\n'" $render_name"
|
||||
fi
|
||||
done
|
||||
if [[ -n "${missed_envs}" ]]; then
|
||||
_argc_die "$message$missed_envs"
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_maybe_flag_option() {
|
||||
local signs="$1" arg="$2"
|
||||
if [[ -z "$signs" ]]; then
|
||||
return 1
|
||||
fi
|
||||
local cond=false
|
||||
if [[ "$signs" == *"+"* ]]; then
|
||||
if [[ "$arg" =~ ^\+[^+].* ]]; then
|
||||
cond=true
|
||||
fi
|
||||
elif [[ "$arg" == -* ]]; then
|
||||
if (( ${#arg} < 3 )) || [[ ! "$arg" =~ ^---.* ]]; then
|
||||
cond=true
|
||||
fi
|
||||
fi
|
||||
if [[ "$cond" == "false" ]]; then
|
||||
return 1
|
||||
fi
|
||||
local value="${arg%%=*}"
|
||||
if [[ "$value" =~ [[:space:]] ]]; then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
_argc_die() {
|
||||
if [[ $# -eq 0 ]]; then
|
||||
cat
|
||||
else
|
||||
echo "$*" >&2
|
||||
fi
|
||||
exit 1
|
||||
}
|
||||
|
||||
_argc_run "$@"
|
||||
|
||||
# ARGC-BUILD }
|
||||
@@ -0,0 +1,33 @@
|
||||
import ast
|
||||
import io
|
||||
from contextlib import redirect_stdout
|
||||
|
||||
|
||||
def run(code: str):
|
||||
"""Execute the python code.
|
||||
Args:
|
||||
code: Python code to execute, such as `print("hello world")`
|
||||
"""
|
||||
output = io.StringIO()
|
||||
with redirect_stdout(output):
|
||||
value = exec_with_return(code, {}, {})
|
||||
|
||||
if value is not None:
|
||||
output.write(str(value))
|
||||
|
||||
return output.getvalue()
|
||||
|
||||
|
||||
def exec_with_return(code: str, globals: dict, locals: dict):
|
||||
a = ast.parse(code)
|
||||
last_expression = None
|
||||
if a.body:
|
||||
if isinstance(a_last := a.body[-1], ast.Expr):
|
||||
last_expression = ast.unparse(a.body.pop())
|
||||
elif isinstance(a_last, ast.Assign):
|
||||
last_expression = ast.unparse(a_last.targets[0])
|
||||
elif isinstance(a_last, (ast.AnnAssign, ast.AugAssign)):
|
||||
last_expression = ast.unparse(a_last.target)
|
||||
exec(ast.unparse(a), globals, locals)
|
||||
if last_expression:
|
||||
return eval(last_expression, globals, locals)
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Execute sql code.
|
||||
# @option --code! The code to execute.
|
||||
|
||||
# @meta require-tools usql
|
||||
|
||||
# @env USQL_DSN! The database connection url. e.g. pgsql://user:pass@host:port
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
PROMPT_UTILS="${LLM_ROOT_DIR:-$(dirname "${BASH_SOURCE[0]}")/..}/utils/prompt-utils.sh"
|
||||
# shellcheck disable=SC1090
|
||||
source "$PROMPT_UTILS"
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
if ! grep -qi '^select' <<<"$argc_code"; then
|
||||
guard_operation ""
|
||||
fi
|
||||
usql -c "$argc_code" "$USQL_DSN" >> "$LLM_OUTPUT"
|
||||
}
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Extract the content from a given URL.
|
||||
# @option --url! The URL to scrape.
|
||||
|
||||
# @meta require-tools pandoc
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
# span and div tags are dropped from the HTML https://pandoc.org/MANUAL.html#raw-htmltex and sed removes any inline SVG images in image tags from the Markdown content.
|
||||
curl -fsSL "$argc_url" | \
|
||||
pandoc -f html-native_divs-native_spans -t gfm-raw_html --wrap=none | \
|
||||
sed -E 's/!\[[^]]*\]\([^)]*\)//g' \
|
||||
>> "$LLM_OUTPUT"
|
||||
}
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Extract the content from a given URL.
|
||||
# @option --url! The URL to scrape.
|
||||
|
||||
# @env JINA_API_KEY Your Jina API key
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
curl_args=()
|
||||
if [[ -n "$JINA_API_KEY" ]]; then
|
||||
curl_args+=("-H" "Authorization: Bearer $JINA_API_KEY")
|
||||
fi
|
||||
curl -fsSL "${curl_args[@]}" "https://r.jina.ai/$argc_url" >> "$LLM_OUTPUT"
|
||||
}
|
||||
Executable
+202
@@ -0,0 +1,202 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Read the contents of a file at the specified path.
|
||||
# Use this when you need to examine the contents of an existing file.
|
||||
|
||||
# @option --path! The path of the file to read
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
main() {
|
||||
# shellcheck disable=SC2154
|
||||
cat "$argc_path" >> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
# ARGC-BUILD {
|
||||
# This block was generated by argc (https://github.com/sigoden/argc).
|
||||
# Modifying it manually is not recommended
|
||||
|
||||
_argc_run() {
|
||||
if [[ "${1:-}" == "___internal___" ]]; then
|
||||
_argc_die "error: unsupported ___internal___ command"
|
||||
fi
|
||||
if [[ "${OS:-}" == "Windows_NT" ]] && [[ -n "${MSYSTEM:-}" ]]; then
|
||||
set -o igncr
|
||||
fi
|
||||
argc__args=("$(basename "$0" .sh)" "$@")
|
||||
argc__positionals=()
|
||||
_argc_index=1
|
||||
_argc_len="${#argc__args[@]}"
|
||||
_argc_tools=()
|
||||
_argc_parse
|
||||
if [ -n "${argc__fn:-}" ]; then
|
||||
$argc__fn "${argc__positionals[@]}"
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_usage() {
|
||||
cat <<-'EOF'
|
||||
Read the contents of a file at the specified path.
|
||||
Use this when you need to examine the contents of an existing file.
|
||||
|
||||
USAGE: --path <PATH>
|
||||
|
||||
OPTIONS:
|
||||
--path <PATH> The path of the file to read
|
||||
-h, --help Print help
|
||||
-V, --version Print version
|
||||
|
||||
ENVIRONMENTS:
|
||||
LLM_OUTPUT The output path [default: /dev/stdout]
|
||||
EOF
|
||||
exit
|
||||
}
|
||||
|
||||
_argc_version() {
|
||||
echo 0.0.0
|
||||
exit
|
||||
}
|
||||
|
||||
_argc_parse() {
|
||||
local _argc_key _argc_action
|
||||
local _argc_subcmds=""
|
||||
while [[ $_argc_index -lt $_argc_len ]]; do
|
||||
_argc_item="${argc__args[_argc_index]}"
|
||||
_argc_key="${_argc_item%%=*}"
|
||||
case "$_argc_key" in
|
||||
--help | -help | -h)
|
||||
_argc_usage
|
||||
;;
|
||||
--version | -version | -V)
|
||||
_argc_version
|
||||
;;
|
||||
--)
|
||||
_argc_dash="${#argc__positionals[@]}"
|
||||
argc__positionals+=("${argc__args[@]:$((_argc_index + 1))}")
|
||||
_argc_index=$_argc_len
|
||||
break
|
||||
;;
|
||||
--path)
|
||||
_argc_take_args "--path <PATH>" 1 1 "-" ""
|
||||
_argc_index=$((_argc_index + _argc_take_args_len + 1))
|
||||
if [[ -z "${argc_path:-}" ]]; then
|
||||
argc_path="${_argc_take_args_values[0]:-}"
|
||||
else
|
||||
_argc_die "error: the argument \`--path\` cannot be used multiple times"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
if _argc_maybe_flag_option "-" "$_argc_item"; then
|
||||
_argc_die "error: unexpected argument \`$_argc_key\` found"
|
||||
fi
|
||||
argc__positionals+=("$_argc_item")
|
||||
_argc_index=$((_argc_index + 1))
|
||||
;;
|
||||
esac
|
||||
done
|
||||
_argc_require_params "error: the following required arguments were not provided:" \
|
||||
'argc_path:--path <PATH>'
|
||||
if [[ -n "${_argc_action:-}" ]]; then
|
||||
$_argc_action
|
||||
else
|
||||
argc__fn=main
|
||||
if [[ "${argc__positionals[0]:-}" == "help" ]] && [[ "${#argc__positionals[@]}" -eq 1 ]]; then
|
||||
_argc_usage
|
||||
fi
|
||||
if [[ -z "${LLM_OUTPUT:-}" ]]; then
|
||||
export LLM_OUTPUT=/dev/stdout
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_take_args() {
|
||||
_argc_take_args_values=()
|
||||
_argc_take_args_len=0
|
||||
local param="$1" min="$2" max="$3" signs="$4" delimiter="$5"
|
||||
if [[ "$min" -eq 0 ]] && [[ "$max" -eq 0 ]]; then
|
||||
return
|
||||
fi
|
||||
local _argc_take_index=$((_argc_index + 1)) _argc_take_value
|
||||
if [[ "$_argc_item" == *=* ]]; then
|
||||
_argc_take_args_values=("${_argc_item##*=}")
|
||||
else
|
||||
while [[ $_argc_take_index -lt $_argc_len ]]; do
|
||||
_argc_take_value="${argc__args[_argc_take_index]}"
|
||||
if _argc_maybe_flag_option "$signs" "$_argc_take_value"; then
|
||||
if [[ "${#_argc_take_value}" -gt 1 ]]; then
|
||||
break
|
||||
fi
|
||||
fi
|
||||
_argc_take_args_values+=("$_argc_take_value")
|
||||
_argc_take_args_len=$((_argc_take_args_len + 1))
|
||||
if [[ "$_argc_take_args_len" -ge "$max" ]]; then
|
||||
break
|
||||
fi
|
||||
_argc_take_index=$((_argc_take_index + 1))
|
||||
done
|
||||
fi
|
||||
if [[ "${#_argc_take_args_values[@]}" -lt "$min" ]]; then
|
||||
_argc_die "error: incorrect number of values for \`$param\`"
|
||||
fi
|
||||
if [[ -n "$delimiter" ]] && [[ "${#_argc_take_args_values[@]}" -gt 0 ]]; then
|
||||
local item values arr=()
|
||||
for item in "${_argc_take_args_values[@]}"; do
|
||||
IFS="$delimiter" read -r -a values <<<"$item"
|
||||
arr+=("${values[@]}")
|
||||
done
|
||||
_argc_take_args_values=("${arr[@]}")
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_require_params() {
|
||||
local message="$1" missed_envs="" item name render_name
|
||||
for item in "${@:2}"; do
|
||||
name="${item%%:*}"
|
||||
render_name="${item##*:}"
|
||||
if [[ -z "${!name:-}" ]]; then
|
||||
missed_envs="$missed_envs"$'\n'" $render_name"
|
||||
fi
|
||||
done
|
||||
if [[ -n "${missed_envs}" ]]; then
|
||||
_argc_die "$message$missed_envs"
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_maybe_flag_option() {
|
||||
local signs="$1" arg="$2"
|
||||
if [[ -z "$signs" ]]; then
|
||||
return 1
|
||||
fi
|
||||
local cond=false
|
||||
if [[ "$signs" == *"+"* ]]; then
|
||||
if [[ "$arg" =~ ^\+[^+].* ]]; then
|
||||
cond=true
|
||||
fi
|
||||
elif [[ "$arg" == -* ]]; then
|
||||
if (( ${#arg} < 3 )) || [[ ! "$arg" =~ ^---.* ]]; then
|
||||
cond=true
|
||||
fi
|
||||
fi
|
||||
if [[ "$cond" == "false" ]]; then
|
||||
return 1
|
||||
fi
|
||||
local value="${arg%%=*}"
|
||||
if [[ "$value" =~ [[:space:]] ]]; then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
_argc_die() {
|
||||
if [[ $# -eq 0 ]]; then
|
||||
cat
|
||||
else
|
||||
echo "$*" >&2
|
||||
fi
|
||||
exit 1
|
||||
}
|
||||
|
||||
_argc_run "$@"
|
||||
|
||||
# ARGC-BUILD }
|
||||
Executable
+200
@@ -0,0 +1,200 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe List all files and directories at the specified path.
|
||||
|
||||
# @option --path! The path of the directory to list
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
main() {
|
||||
# shellcheck disable=SC2154
|
||||
ls -1 "$argc_path" >> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
# ARGC-BUILD {
|
||||
# This block was generated by argc (https://github.com/sigoden/argc).
|
||||
# Modifying it manually is not recommended
|
||||
|
||||
_argc_run() {
|
||||
if [[ "${1:-}" == "___internal___" ]]; then
|
||||
_argc_die "error: unsupported ___internal___ command"
|
||||
fi
|
||||
if [[ "${OS:-}" == "Windows_NT" ]] && [[ -n "${MSYSTEM:-}" ]]; then
|
||||
set -o igncr
|
||||
fi
|
||||
argc__args=("$(basename "$0" .sh)" "$@")
|
||||
argc__positionals=()
|
||||
_argc_index=1
|
||||
_argc_len="${#argc__args[@]}"
|
||||
_argc_tools=()
|
||||
_argc_parse
|
||||
if [ -n "${argc__fn:-}" ]; then
|
||||
$argc__fn "${argc__positionals[@]}"
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_usage() {
|
||||
cat <<-'EOF'
|
||||
List all files and directories at the specified path.
|
||||
|
||||
USAGE: --path <PATH>
|
||||
|
||||
OPTIONS:
|
||||
--path <PATH> The path of the directory to list
|
||||
-h, --help Print help
|
||||
-V, --version Print version
|
||||
|
||||
ENVIRONMENTS:
|
||||
LLM_OUTPUT The output path [default: /dev/stdout]
|
||||
EOF
|
||||
exit
|
||||
}
|
||||
|
||||
_argc_version() {
|
||||
echo 0.0.0
|
||||
exit
|
||||
}
|
||||
|
||||
_argc_parse() {
|
||||
local _argc_key _argc_action
|
||||
local _argc_subcmds=""
|
||||
while [[ $_argc_index -lt $_argc_len ]]; do
|
||||
_argc_item="${argc__args[_argc_index]}"
|
||||
_argc_key="${_argc_item%%=*}"
|
||||
case "$_argc_key" in
|
||||
--help | -help | -h)
|
||||
_argc_usage
|
||||
;;
|
||||
--version | -version | -V)
|
||||
_argc_version
|
||||
;;
|
||||
--)
|
||||
_argc_dash="${#argc__positionals[@]}"
|
||||
argc__positionals+=("${argc__args[@]:$((_argc_index + 1))}")
|
||||
_argc_index=$_argc_len
|
||||
break
|
||||
;;
|
||||
--path)
|
||||
_argc_take_args "--path <PATH>" 1 1 "-" ""
|
||||
_argc_index=$((_argc_index + _argc_take_args_len + 1))
|
||||
if [[ -z "${argc_path:-}" ]]; then
|
||||
argc_path="${_argc_take_args_values[0]:-}"
|
||||
else
|
||||
_argc_die "error: the argument \`--path\` cannot be used multiple times"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
if _argc_maybe_flag_option "-" "$_argc_item"; then
|
||||
_argc_die "error: unexpected argument \`$_argc_key\` found"
|
||||
fi
|
||||
argc__positionals+=("$_argc_item")
|
||||
_argc_index=$((_argc_index + 1))
|
||||
;;
|
||||
esac
|
||||
done
|
||||
_argc_require_params "error: the following required arguments were not provided:" \
|
||||
'argc_path:--path <PATH>'
|
||||
if [[ -n "${_argc_action:-}" ]]; then
|
||||
$_argc_action
|
||||
else
|
||||
argc__fn=main
|
||||
if [[ "${argc__positionals[0]:-}" == "help" ]] && [[ "${#argc__positionals[@]}" -eq 1 ]]; then
|
||||
_argc_usage
|
||||
fi
|
||||
if [[ -z "${LLM_OUTPUT:-}" ]]; then
|
||||
export LLM_OUTPUT=/dev/stdout
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_take_args() {
|
||||
_argc_take_args_values=()
|
||||
_argc_take_args_len=0
|
||||
local param="$1" min="$2" max="$3" signs="$4" delimiter="$5"
|
||||
if [[ "$min" -eq 0 ]] && [[ "$max" -eq 0 ]]; then
|
||||
return
|
||||
fi
|
||||
local _argc_take_index=$((_argc_index + 1)) _argc_take_value
|
||||
if [[ "$_argc_item" == *=* ]]; then
|
||||
_argc_take_args_values=("${_argc_item##*=}")
|
||||
else
|
||||
while [[ $_argc_take_index -lt $_argc_len ]]; do
|
||||
_argc_take_value="${argc__args[_argc_take_index]}"
|
||||
if _argc_maybe_flag_option "$signs" "$_argc_take_value"; then
|
||||
if [[ "${#_argc_take_value}" -gt 1 ]]; then
|
||||
break
|
||||
fi
|
||||
fi
|
||||
_argc_take_args_values+=("$_argc_take_value")
|
||||
_argc_take_args_len=$((_argc_take_args_len + 1))
|
||||
if [[ "$_argc_take_args_len" -ge "$max" ]]; then
|
||||
break
|
||||
fi
|
||||
_argc_take_index=$((_argc_take_index + 1))
|
||||
done
|
||||
fi
|
||||
if [[ "${#_argc_take_args_values[@]}" -lt "$min" ]]; then
|
||||
_argc_die "error: incorrect number of values for \`$param\`"
|
||||
fi
|
||||
if [[ -n "$delimiter" ]] && [[ "${#_argc_take_args_values[@]}" -gt 0 ]]; then
|
||||
local item values arr=()
|
||||
for item in "${_argc_take_args_values[@]}"; do
|
||||
IFS="$delimiter" read -r -a values <<<"$item"
|
||||
arr+=("${values[@]}")
|
||||
done
|
||||
_argc_take_args_values=("${arr[@]}")
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_require_params() {
|
||||
local message="$1" missed_envs="" item name render_name
|
||||
for item in "${@:2}"; do
|
||||
name="${item%%:*}"
|
||||
render_name="${item##*:}"
|
||||
if [[ -z "${!name:-}" ]]; then
|
||||
missed_envs="$missed_envs"$'\n'" $render_name"
|
||||
fi
|
||||
done
|
||||
if [[ -n "${missed_envs}" ]]; then
|
||||
_argc_die "$message$missed_envs"
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_maybe_flag_option() {
|
||||
local signs="$1" arg="$2"
|
||||
if [[ -z "$signs" ]]; then
|
||||
return 1
|
||||
fi
|
||||
local cond=false
|
||||
if [[ "$signs" == *"+"* ]]; then
|
||||
if [[ "$arg" =~ ^\+[^+].* ]]; then
|
||||
cond=true
|
||||
fi
|
||||
elif [[ "$arg" == -* ]]; then
|
||||
if (( ${#arg} < 3 )) || [[ ! "$arg" =~ ^---.* ]]; then
|
||||
cond=true
|
||||
fi
|
||||
fi
|
||||
if [[ "$cond" == "false" ]]; then
|
||||
return 1
|
||||
fi
|
||||
local value="${arg%%=*}"
|
||||
if [[ "$value" =~ [[:space:]] ]]; then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
_argc_die() {
|
||||
if [[ $# -eq 0 ]]; then
|
||||
cat
|
||||
else
|
||||
echo "$*" >&2
|
||||
fi
|
||||
exit 1
|
||||
}
|
||||
|
||||
_argc_run "$@"
|
||||
|
||||
# ARGC-BUILD }
|
||||
Executable
+201
@@ -0,0 +1,201 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Create a new directory at the specified path.
|
||||
|
||||
# @option --path! The path of the directory to create
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
main() {
|
||||
# shellcheck disable=SC2154
|
||||
mkdir -p "$argc_path"
|
||||
echo "Directory created: $argc_path" >> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
# ARGC-BUILD {
|
||||
# This block was generated by argc (https://github.com/sigoden/argc).
|
||||
# Modifying it manually is not recommended
|
||||
|
||||
_argc_run() {
|
||||
if [[ "${1:-}" == "___internal___" ]]; then
|
||||
_argc_die "error: unsupported ___internal___ command"
|
||||
fi
|
||||
if [[ "${OS:-}" == "Windows_NT" ]] && [[ -n "${MSYSTEM:-}" ]]; then
|
||||
set -o igncr
|
||||
fi
|
||||
argc__args=("$(basename "$0" .sh)" "$@")
|
||||
argc__positionals=()
|
||||
_argc_index=1
|
||||
_argc_len="${#argc__args[@]}"
|
||||
_argc_tools=()
|
||||
_argc_parse
|
||||
if [ -n "${argc__fn:-}" ]; then
|
||||
$argc__fn "${argc__positionals[@]}"
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_usage() {
|
||||
cat <<-'EOF'
|
||||
Create a new directory at the specified path.
|
||||
|
||||
USAGE: --path <PATH>
|
||||
|
||||
OPTIONS:
|
||||
--path <PATH> The path of the directory to create
|
||||
-h, --help Print help
|
||||
-V, --version Print version
|
||||
|
||||
ENVIRONMENTS:
|
||||
LLM_OUTPUT The output path [default: /dev/stdout]
|
||||
EOF
|
||||
exit
|
||||
}
|
||||
|
||||
_argc_version() {
|
||||
echo 0.0.0
|
||||
exit
|
||||
}
|
||||
|
||||
_argc_parse() {
|
||||
local _argc_key _argc_action
|
||||
local _argc_subcmds=""
|
||||
while [[ $_argc_index -lt $_argc_len ]]; do
|
||||
_argc_item="${argc__args[_argc_index]}"
|
||||
_argc_key="${_argc_item%%=*}"
|
||||
case "$_argc_key" in
|
||||
--help | -help | -h)
|
||||
_argc_usage
|
||||
;;
|
||||
--version | -version | -V)
|
||||
_argc_version
|
||||
;;
|
||||
--)
|
||||
_argc_dash="${#argc__positionals[@]}"
|
||||
argc__positionals+=("${argc__args[@]:$((_argc_index + 1))}")
|
||||
_argc_index=$_argc_len
|
||||
break
|
||||
;;
|
||||
--path)
|
||||
_argc_take_args "--path <PATH>" 1 1 "-" ""
|
||||
_argc_index=$((_argc_index + _argc_take_args_len + 1))
|
||||
if [[ -z "${argc_path:-}" ]]; then
|
||||
argc_path="${_argc_take_args_values[0]:-}"
|
||||
else
|
||||
_argc_die "error: the argument \`--path\` cannot be used multiple times"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
if _argc_maybe_flag_option "-" "$_argc_item"; then
|
||||
_argc_die "error: unexpected argument \`$_argc_key\` found"
|
||||
fi
|
||||
argc__positionals+=("$_argc_item")
|
||||
_argc_index=$((_argc_index + 1))
|
||||
;;
|
||||
esac
|
||||
done
|
||||
_argc_require_params "error: the following required arguments were not provided:" \
|
||||
'argc_path:--path <PATH>'
|
||||
if [[ -n "${_argc_action:-}" ]]; then
|
||||
$_argc_action
|
||||
else
|
||||
argc__fn=main
|
||||
if [[ "${argc__positionals[0]:-}" == "help" ]] && [[ "${#argc__positionals[@]}" -eq 1 ]]; then
|
||||
_argc_usage
|
||||
fi
|
||||
if [[ -z "${LLM_OUTPUT:-}" ]]; then
|
||||
export LLM_OUTPUT=/dev/stdout
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_take_args() {
|
||||
_argc_take_args_values=()
|
||||
_argc_take_args_len=0
|
||||
local param="$1" min="$2" max="$3" signs="$4" delimiter="$5"
|
||||
if [[ "$min" -eq 0 ]] && [[ "$max" -eq 0 ]]; then
|
||||
return
|
||||
fi
|
||||
local _argc_take_index=$((_argc_index + 1)) _argc_take_value
|
||||
if [[ "$_argc_item" == *=* ]]; then
|
||||
_argc_take_args_values=("${_argc_item##*=}")
|
||||
else
|
||||
while [[ $_argc_take_index -lt $_argc_len ]]; do
|
||||
_argc_take_value="${argc__args[_argc_take_index]}"
|
||||
if _argc_maybe_flag_option "$signs" "$_argc_take_value"; then
|
||||
if [[ "${#_argc_take_value}" -gt 1 ]]; then
|
||||
break
|
||||
fi
|
||||
fi
|
||||
_argc_take_args_values+=("$_argc_take_value")
|
||||
_argc_take_args_len=$((_argc_take_args_len + 1))
|
||||
if [[ "$_argc_take_args_len" -ge "$max" ]]; then
|
||||
break
|
||||
fi
|
||||
_argc_take_index=$((_argc_take_index + 1))
|
||||
done
|
||||
fi
|
||||
if [[ "${#_argc_take_args_values[@]}" -lt "$min" ]]; then
|
||||
_argc_die "error: incorrect number of values for \`$param\`"
|
||||
fi
|
||||
if [[ -n "$delimiter" ]] && [[ "${#_argc_take_args_values[@]}" -gt 0 ]]; then
|
||||
local item values arr=()
|
||||
for item in "${_argc_take_args_values[@]}"; do
|
||||
IFS="$delimiter" read -r -a values <<<"$item"
|
||||
arr+=("${values[@]}")
|
||||
done
|
||||
_argc_take_args_values=("${arr[@]}")
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_require_params() {
|
||||
local message="$1" missed_envs="" item name render_name
|
||||
for item in "${@:2}"; do
|
||||
name="${item%%:*}"
|
||||
render_name="${item##*:}"
|
||||
if [[ -z "${!name:-}" ]]; then
|
||||
missed_envs="$missed_envs"$'\n'" $render_name"
|
||||
fi
|
||||
done
|
||||
if [[ -n "${missed_envs}" ]]; then
|
||||
_argc_die "$message$missed_envs"
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_maybe_flag_option() {
|
||||
local signs="$1" arg="$2"
|
||||
if [[ -z "$signs" ]]; then
|
||||
return 1
|
||||
fi
|
||||
local cond=false
|
||||
if [[ "$signs" == *"+"* ]]; then
|
||||
if [[ "$arg" =~ ^\+[^+].* ]]; then
|
||||
cond=true
|
||||
fi
|
||||
elif [[ "$arg" == -* ]]; then
|
||||
if (( ${#arg} < 3 )) || [[ ! "$arg" =~ ^---.* ]]; then
|
||||
cond=true
|
||||
fi
|
||||
fi
|
||||
if [[ "$cond" == "false" ]]; then
|
||||
return 1
|
||||
fi
|
||||
local value="${arg%%=*}"
|
||||
if [[ "$value" =~ [[:space:]] ]]; then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
_argc_die() {
|
||||
if [[ $# -eq 0 ]]; then
|
||||
cat
|
||||
else
|
||||
echo "$*" >&2
|
||||
fi
|
||||
exit 1
|
||||
}
|
||||
|
||||
_argc_run "$@"
|
||||
|
||||
# ARGC-BUILD }
|
||||
Executable
+229
@@ -0,0 +1,229 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Apply a patch to a file at the specified path.
|
||||
# This can be used to edit the file without having to rewrite the whole file.
|
||||
|
||||
# @option --path! The path of the file to apply the patch to
|
||||
# @option --contents! The patch to apply to the file
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
PROMPT_UTILS="${LLM_ROOT_DIR:-$(dirname "${BASH_SOURCE[0]}")/..}/utils/prompt-utils.sh"
|
||||
# shellcheck disable=SC1090
|
||||
source "$PROMPT_UTILS"
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
if [[ ! -f "$argc_path" ]]; then
|
||||
error "Unable to find the specified file: $argc_path"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
new_contents="$(patch_file "$argc_path" <(printf "%s" "$argc_contents"))"
|
||||
printf "%s" "$new_contents" | git diff --no-index "$argc_path" - || true
|
||||
|
||||
guard_operation "Apply changes?"
|
||||
|
||||
printf "%s" "$new_contents" > "$argc_path"
|
||||
|
||||
info "Applied the patch to: $argc_path" >> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
# ARGC-BUILD {
|
||||
# This block was generated by argc (https://github.com/sigoden/argc).
|
||||
# Modifying it manually is not recommended
|
||||
|
||||
_argc_run() {
|
||||
if [[ "${1:-}" == "___internal___" ]]; then
|
||||
_argc_die "error: unsupported ___internal___ command"
|
||||
fi
|
||||
if [[ "${OS:-}" == "Windows_NT" ]] && [[ -n "${MSYSTEM:-}" ]]; then
|
||||
set -o igncr
|
||||
fi
|
||||
argc__args=("$(basename "$0" .sh)" "$@")
|
||||
argc__positionals=()
|
||||
_argc_index=1
|
||||
_argc_len="${#argc__args[@]}"
|
||||
_argc_tools=()
|
||||
_argc_parse
|
||||
if [ -n "${argc__fn:-}" ]; then
|
||||
$argc__fn "${argc__positionals[@]}"
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_usage() {
|
||||
cat <<-'EOF'
|
||||
Apply a patch to a file at the specified path.
|
||||
This can be used to edit the file without having to rewrite the whole file.
|
||||
|
||||
USAGE: --path <PATH> --contents <CONTENTS>
|
||||
|
||||
OPTIONS:
|
||||
--path <PATH> The path of the file to apply the patch to
|
||||
--contents <CONTENTS> The patch to apply to the file
|
||||
-h, --help Print help
|
||||
-V, --version Print version
|
||||
|
||||
ENVIRONMENTS:
|
||||
LLM_OUTPUT The output path [default: /dev/stdout]
|
||||
EOF
|
||||
exit
|
||||
}
|
||||
|
||||
_argc_version() {
|
||||
echo 0.0.0
|
||||
exit
|
||||
}
|
||||
|
||||
_argc_parse() {
|
||||
local _argc_key _argc_action
|
||||
local _argc_subcmds=""
|
||||
while [[ $_argc_index -lt $_argc_len ]]; do
|
||||
_argc_item="${argc__args[_argc_index]}"
|
||||
_argc_key="${_argc_item%%=*}"
|
||||
case "$_argc_key" in
|
||||
--help | -help | -h)
|
||||
_argc_usage
|
||||
;;
|
||||
--version | -version | -V)
|
||||
_argc_version
|
||||
;;
|
||||
--)
|
||||
_argc_dash="${#argc__positionals[@]}"
|
||||
argc__positionals+=("${argc__args[@]:$((_argc_index + 1))}")
|
||||
_argc_index=$_argc_len
|
||||
break
|
||||
;;
|
||||
--path)
|
||||
_argc_take_args "--path <PATH>" 1 1 "-" ""
|
||||
_argc_index=$((_argc_index + _argc_take_args_len + 1))
|
||||
if [[ -z "${argc_path:-}" ]]; then
|
||||
argc_path="${_argc_take_args_values[0]:-}"
|
||||
else
|
||||
_argc_die "error: the argument \`--path\` cannot be used multiple times"
|
||||
fi
|
||||
;;
|
||||
--contents)
|
||||
_argc_take_args "--contents <CONTENTS>" 1 1 "-" ""
|
||||
_argc_index=$((_argc_index + _argc_take_args_len + 1))
|
||||
if [[ -z "${argc_contents:-}" ]]; then
|
||||
argc_contents="${_argc_take_args_values[0]:-}"
|
||||
else
|
||||
_argc_die "error: the argument \`--contents\` cannot be used multiple times"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
if _argc_maybe_flag_option "-" "$_argc_item"; then
|
||||
_argc_die "error: unexpected argument \`$_argc_key\` found"
|
||||
fi
|
||||
argc__positionals+=("$_argc_item")
|
||||
_argc_index=$((_argc_index + 1))
|
||||
;;
|
||||
esac
|
||||
done
|
||||
_argc_require_params "error: the following required arguments were not provided:" \
|
||||
'argc_path:--path <PATH>' 'argc_contents:--contents <CONTENTS>'
|
||||
if [[ -n "${_argc_action:-}" ]]; then
|
||||
$_argc_action
|
||||
else
|
||||
argc__fn=main
|
||||
if [[ "${argc__positionals[0]:-}" == "help" ]] && [[ "${#argc__positionals[@]}" -eq 1 ]]; then
|
||||
_argc_usage
|
||||
fi
|
||||
if [[ -z "${LLM_OUTPUT:-}" ]]; then
|
||||
export LLM_OUTPUT=/dev/stdout
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_take_args() {
|
||||
_argc_take_args_values=()
|
||||
_argc_take_args_len=0
|
||||
local param="$1" min="$2" max="$3" signs="$4" delimiter="$5"
|
||||
if [[ "$min" -eq 0 ]] && [[ "$max" -eq 0 ]]; then
|
||||
return
|
||||
fi
|
||||
local _argc_take_index=$((_argc_index + 1)) _argc_take_value
|
||||
if [[ "$_argc_item" == *=* ]]; then
|
||||
_argc_take_args_values=("${_argc_item##*=}")
|
||||
else
|
||||
while [[ $_argc_take_index -lt $_argc_len ]]; do
|
||||
_argc_take_value="${argc__args[_argc_take_index]}"
|
||||
if _argc_maybe_flag_option "$signs" "$_argc_take_value"; then
|
||||
if [[ "${#_argc_take_value}" -gt 1 ]]; then
|
||||
break
|
||||
fi
|
||||
fi
|
||||
_argc_take_args_values+=("$_argc_take_value")
|
||||
_argc_take_args_len=$((_argc_take_args_len + 1))
|
||||
if [[ "$_argc_take_args_len" -ge "$max" ]]; then
|
||||
break
|
||||
fi
|
||||
_argc_take_index=$((_argc_take_index + 1))
|
||||
done
|
||||
fi
|
||||
if [[ "${#_argc_take_args_values[@]}" -lt "$min" ]]; then
|
||||
_argc_die "error: incorrect number of values for \`$param\`"
|
||||
fi
|
||||
if [[ -n "$delimiter" ]] && [[ "${#_argc_take_args_values[@]}" -gt 0 ]]; then
|
||||
local item values arr=()
|
||||
for item in "${_argc_take_args_values[@]}"; do
|
||||
IFS="$delimiter" read -r -a values <<<"$item"
|
||||
arr+=("${values[@]}")
|
||||
done
|
||||
_argc_take_args_values=("${arr[@]}")
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_require_params() {
|
||||
local message="$1" missed_envs="" item name render_name
|
||||
for item in "${@:2}"; do
|
||||
name="${item%%:*}"
|
||||
render_name="${item##*:}"
|
||||
if [[ -z "${!name:-}" ]]; then
|
||||
missed_envs="$missed_envs"$'\n'" $render_name"
|
||||
fi
|
||||
done
|
||||
if [[ -n "${missed_envs}" ]]; then
|
||||
_argc_die "$message$missed_envs"
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_maybe_flag_option() {
|
||||
local signs="$1" arg="$2"
|
||||
if [[ -z "$signs" ]]; then
|
||||
return 1
|
||||
fi
|
||||
local cond=false
|
||||
if [[ "$signs" == *"+"* ]]; then
|
||||
if [[ "$arg" =~ ^\+[^+].* ]]; then
|
||||
cond=true
|
||||
fi
|
||||
elif [[ "$arg" == -* ]]; then
|
||||
if (( ${#arg} < 3 )) || [[ ! "$arg" =~ ^---.* ]]; then
|
||||
cond=true
|
||||
fi
|
||||
fi
|
||||
if [[ "$cond" == "false" ]]; then
|
||||
return 1
|
||||
fi
|
||||
local value="${arg%%=*}"
|
||||
if [[ "$value" =~ [[:space:]] ]]; then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
_argc_die() {
|
||||
if [[ $# -eq 0 ]]; then
|
||||
cat
|
||||
else
|
||||
echo "$*" >&2
|
||||
fi
|
||||
exit 1
|
||||
}
|
||||
|
||||
_argc_run "$@"
|
||||
|
||||
# ARGC-BUILD }
|
||||
Executable
+210
@@ -0,0 +1,210 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Remove the file or directory at the specified path.
|
||||
|
||||
# @option --path! The path of the file or directory to remove
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
PROMPT_UTILS="${LLM_ROOT_DIR:-$(dirname "${BASH_SOURCE[0]}")/..}/utils/prompt-utils.sh"
|
||||
# shellcheck disable=SC1090
|
||||
source "$PROMPT_UTILS"
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
if [[ -f "$argc_path" ]]; then
|
||||
guard_path "$argc_path" "Remove '$argc_path'?"
|
||||
rm -rf "$argc_path"
|
||||
fi
|
||||
|
||||
echo "Path removed: $argc_path" >> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
|
||||
# ARGC-BUILD {
|
||||
# This block was generated by argc (https://github.com/sigoden/argc).
|
||||
# Modifying it manually is not recommended
|
||||
|
||||
_argc_run() {
|
||||
if [[ "${1:-}" == "___internal___" ]]; then
|
||||
_argc_die "error: unsupported ___internal___ command"
|
||||
fi
|
||||
if [[ "${OS:-}" == "Windows_NT" ]] && [[ -n "${MSYSTEM:-}" ]]; then
|
||||
set -o igncr
|
||||
fi
|
||||
argc__args=("$(basename "$0" .sh)" "$@")
|
||||
argc__positionals=()
|
||||
_argc_index=1
|
||||
_argc_len="${#argc__args[@]}"
|
||||
_argc_tools=()
|
||||
_argc_parse
|
||||
if [ -n "${argc__fn:-}" ]; then
|
||||
$argc__fn "${argc__positionals[@]}"
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_usage() {
|
||||
cat <<-'EOF'
|
||||
Remove the file or directory at the specified path.
|
||||
|
||||
USAGE: --path <PATH>
|
||||
|
||||
OPTIONS:
|
||||
--path <PATH> The path of the file or directory to remove
|
||||
-h, --help Print help
|
||||
-V, --version Print version
|
||||
|
||||
ENVIRONMENTS:
|
||||
LLM_OUTPUT The output path [default: /dev/stdout]
|
||||
EOF
|
||||
exit
|
||||
}
|
||||
|
||||
_argc_version() {
|
||||
echo 0.0.0
|
||||
exit
|
||||
}
|
||||
|
||||
_argc_parse() {
|
||||
local _argc_key _argc_action
|
||||
local _argc_subcmds=""
|
||||
while [[ $_argc_index -lt $_argc_len ]]; do
|
||||
_argc_item="${argc__args[_argc_index]}"
|
||||
_argc_key="${_argc_item%%=*}"
|
||||
case "$_argc_key" in
|
||||
--help | -help | -h)
|
||||
_argc_usage
|
||||
;;
|
||||
--version | -version | -V)
|
||||
_argc_version
|
||||
;;
|
||||
--)
|
||||
_argc_dash="${#argc__positionals[@]}"
|
||||
argc__positionals+=("${argc__args[@]:$((_argc_index + 1))}")
|
||||
_argc_index=$_argc_len
|
||||
break
|
||||
;;
|
||||
--path)
|
||||
_argc_take_args "--path <PATH>" 1 1 "-" ""
|
||||
_argc_index=$((_argc_index + _argc_take_args_len + 1))
|
||||
if [[ -z "${argc_path:-}" ]]; then
|
||||
argc_path="${_argc_take_args_values[0]:-}"
|
||||
else
|
||||
_argc_die "error: the argument \`--path\` cannot be used multiple times"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
if _argc_maybe_flag_option "-" "$_argc_item"; then
|
||||
_argc_die "error: unexpected argument \`$_argc_key\` found"
|
||||
fi
|
||||
argc__positionals+=("$_argc_item")
|
||||
_argc_index=$((_argc_index + 1))
|
||||
;;
|
||||
esac
|
||||
done
|
||||
_argc_require_params "error: the following required arguments were not provided:" \
|
||||
'argc_path:--path <PATH>'
|
||||
if [[ -n "${_argc_action:-}" ]]; then
|
||||
$_argc_action
|
||||
else
|
||||
argc__fn=main
|
||||
if [[ "${argc__positionals[0]:-}" == "help" ]] && [[ "${#argc__positionals[@]}" -eq 1 ]]; then
|
||||
_argc_usage
|
||||
fi
|
||||
if [[ -z "${LLM_OUTPUT:-}" ]]; then
|
||||
export LLM_OUTPUT=/dev/stdout
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_take_args() {
|
||||
_argc_take_args_values=()
|
||||
_argc_take_args_len=0
|
||||
local param="$1" min="$2" max="$3" signs="$4" delimiter="$5"
|
||||
if [[ "$min" -eq 0 ]] && [[ "$max" -eq 0 ]]; then
|
||||
return
|
||||
fi
|
||||
local _argc_take_index=$((_argc_index + 1)) _argc_take_value
|
||||
if [[ "$_argc_item" == *=* ]]; then
|
||||
_argc_take_args_values=("${_argc_item##*=}")
|
||||
else
|
||||
while [[ $_argc_take_index -lt $_argc_len ]]; do
|
||||
_argc_take_value="${argc__args[_argc_take_index]}"
|
||||
if _argc_maybe_flag_option "$signs" "$_argc_take_value"; then
|
||||
if [[ "${#_argc_take_value}" -gt 1 ]]; then
|
||||
break
|
||||
fi
|
||||
fi
|
||||
_argc_take_args_values+=("$_argc_take_value")
|
||||
_argc_take_args_len=$((_argc_take_args_len + 1))
|
||||
if [[ "$_argc_take_args_len" -ge "$max" ]]; then
|
||||
break
|
||||
fi
|
||||
_argc_take_index=$((_argc_take_index + 1))
|
||||
done
|
||||
fi
|
||||
if [[ "${#_argc_take_args_values[@]}" -lt "$min" ]]; then
|
||||
_argc_die "error: incorrect number of values for \`$param\`"
|
||||
fi
|
||||
if [[ -n "$delimiter" ]] && [[ "${#_argc_take_args_values[@]}" -gt 0 ]]; then
|
||||
local item values arr=()
|
||||
for item in "${_argc_take_args_values[@]}"; do
|
||||
IFS="$delimiter" read -r -a values <<<"$item"
|
||||
arr+=("${values[@]}")
|
||||
done
|
||||
_argc_take_args_values=("${arr[@]}")
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_require_params() {
|
||||
local message="$1" missed_envs="" item name render_name
|
||||
for item in "${@:2}"; do
|
||||
name="${item%%:*}"
|
||||
render_name="${item##*:}"
|
||||
if [[ -z "${!name:-}" ]]; then
|
||||
missed_envs="$missed_envs"$'\n'" $render_name"
|
||||
fi
|
||||
done
|
||||
if [[ -n "${missed_envs}" ]]; then
|
||||
_argc_die "$message$missed_envs"
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_maybe_flag_option() {
|
||||
local signs="$1" arg="$2"
|
||||
if [[ -z "$signs" ]]; then
|
||||
return 1
|
||||
fi
|
||||
local cond=false
|
||||
if [[ "$signs" == *"+"* ]]; then
|
||||
if [[ "$arg" =~ ^\+[^+].* ]]; then
|
||||
cond=true
|
||||
fi
|
||||
elif [[ "$arg" == -* ]]; then
|
||||
if (( ${#arg} < 3 )) || [[ ! "$arg" =~ ^---.* ]]; then
|
||||
cond=true
|
||||
fi
|
||||
fi
|
||||
if [[ "$cond" == "false" ]]; then
|
||||
return 1
|
||||
fi
|
||||
local value="${arg%%=*}"
|
||||
if [[ "$value" =~ [[:space:]] ]]; then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
_argc_die() {
|
||||
if [[ $# -eq 0 ]]; then
|
||||
cat
|
||||
else
|
||||
echo "$*" >&2
|
||||
fi
|
||||
exit 1
|
||||
}
|
||||
|
||||
_argc_run "$@"
|
||||
|
||||
# ARGC-BUILD }
|
||||
Executable
+224
@@ -0,0 +1,224 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Write the full file contents to a file at the specified path.
|
||||
|
||||
# @option --path! The path of the file to write to
|
||||
# @option --contents! The full contents to write to the file
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
PROMPT_UTILS="${LLM_ROOT_DIR:-$(dirname "${BASH_SOURCE[0]}")/..}/utils/prompt-utils.sh"
|
||||
# shellcheck disable=SC1090
|
||||
source "$PROMPT_UTILS"
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
if [[ -f "$argc_path" ]]; then
|
||||
printf "%s" "$argc_contents" | git diff --no-index "$argc_path" - || true
|
||||
guard_operation "Apply changes?"
|
||||
else
|
||||
guard_path "$argc_path" "Write '$argc_path'?"
|
||||
mkdir -p "$(dirname "$argc_path")"
|
||||
fi
|
||||
|
||||
printf "%s" "$argc_contents" > "$argc_path"
|
||||
echo "The File contents were written to: $argc_path" >> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
# ARGC-BUILD {
|
||||
# This block was generated by argc (https://github.com/sigoden/argc).
|
||||
# Modifying it manually is not recommended
|
||||
|
||||
_argc_run() {
|
||||
if [[ "${1:-}" == "___internal___" ]]; then
|
||||
_argc_die "error: unsupported ___internal___ command"
|
||||
fi
|
||||
if [[ "${OS:-}" == "Windows_NT" ]] && [[ -n "${MSYSTEM:-}" ]]; then
|
||||
set -o igncr
|
||||
fi
|
||||
argc__args=("$(basename "$0" .sh)" "$@")
|
||||
argc__positionals=()
|
||||
_argc_index=1
|
||||
_argc_len="${#argc__args[@]}"
|
||||
_argc_tools=()
|
||||
_argc_parse
|
||||
if [ -n "${argc__fn:-}" ]; then
|
||||
$argc__fn "${argc__positionals[@]}"
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_usage() {
|
||||
cat <<-'EOF'
|
||||
Write the full file contents to a file at the specified path.
|
||||
|
||||
USAGE: --path <PATH> --contents <CONTENTS>
|
||||
|
||||
OPTIONS:
|
||||
--path <PATH> The path of the file to write to
|
||||
--contents <CONTENTS> The full contents to write to the file
|
||||
-h, --help Print help
|
||||
-V, --version Print version
|
||||
|
||||
ENVIRONMENTS:
|
||||
LLM_OUTPUT The output path [default: /dev/stdout]
|
||||
EOF
|
||||
exit
|
||||
}
|
||||
|
||||
_argc_version() {
|
||||
echo 0.0.0
|
||||
exit
|
||||
}
|
||||
|
||||
_argc_parse() {
|
||||
local _argc_key _argc_action
|
||||
local _argc_subcmds=""
|
||||
while [[ $_argc_index -lt $_argc_len ]]; do
|
||||
_argc_item="${argc__args[_argc_index]}"
|
||||
_argc_key="${_argc_item%%=*}"
|
||||
case "$_argc_key" in
|
||||
--help | -help | -h)
|
||||
_argc_usage
|
||||
;;
|
||||
--version | -version | -V)
|
||||
_argc_version
|
||||
;;
|
||||
--)
|
||||
_argc_dash="${#argc__positionals[@]}"
|
||||
argc__positionals+=("${argc__args[@]:$((_argc_index + 1))}")
|
||||
_argc_index=$_argc_len
|
||||
break
|
||||
;;
|
||||
--path)
|
||||
_argc_take_args "--path <PATH>" 1 1 "-" ""
|
||||
_argc_index=$((_argc_index + _argc_take_args_len + 1))
|
||||
if [[ -z "${argc_path:-}" ]]; then
|
||||
argc_path="${_argc_take_args_values[0]:-}"
|
||||
else
|
||||
_argc_die "error: the argument \`--path\` cannot be used multiple times"
|
||||
fi
|
||||
;;
|
||||
--contents)
|
||||
_argc_take_args "--contents <CONTENTS>" 1 1 "-" ""
|
||||
_argc_index=$((_argc_index + _argc_take_args_len + 1))
|
||||
if [[ -z "${argc_contents:-}" ]]; then
|
||||
argc_contents="${_argc_take_args_values[0]:-}"
|
||||
else
|
||||
_argc_die "error: the argument \`--contents\` cannot be used multiple times"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
if _argc_maybe_flag_option "-" "$_argc_item"; then
|
||||
_argc_die "error: unexpected argument \`$_argc_key\` found"
|
||||
fi
|
||||
argc__positionals+=("$_argc_item")
|
||||
_argc_index=$((_argc_index + 1))
|
||||
;;
|
||||
esac
|
||||
done
|
||||
_argc_require_params "error: the following required arguments were not provided:" \
|
||||
'argc_path:--path <PATH>' 'argc_contents:--contents <CONTENTS>'
|
||||
if [[ -n "${_argc_action:-}" ]]; then
|
||||
$_argc_action
|
||||
else
|
||||
argc__fn=main
|
||||
if [[ "${argc__positionals[0]:-}" == "help" ]] && [[ "${#argc__positionals[@]}" -eq 1 ]]; then
|
||||
_argc_usage
|
||||
fi
|
||||
if [[ -z "${LLM_OUTPUT:-}" ]]; then
|
||||
export LLM_OUTPUT=/dev/stdout
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_take_args() {
|
||||
_argc_take_args_values=()
|
||||
_argc_take_args_len=0
|
||||
local param="$1" min="$2" max="$3" signs="$4" delimiter="$5"
|
||||
if [[ "$min" -eq 0 ]] && [[ "$max" -eq 0 ]]; then
|
||||
return
|
||||
fi
|
||||
local _argc_take_index=$((_argc_index + 1)) _argc_take_value
|
||||
if [[ "$_argc_item" == *=* ]]; then
|
||||
_argc_take_args_values=("${_argc_item##*=}")
|
||||
else
|
||||
while [[ $_argc_take_index -lt $_argc_len ]]; do
|
||||
_argc_take_value="${argc__args[_argc_take_index]}"
|
||||
if _argc_maybe_flag_option "$signs" "$_argc_take_value"; then
|
||||
if [[ "${#_argc_take_value}" -gt 1 ]]; then
|
||||
break
|
||||
fi
|
||||
fi
|
||||
_argc_take_args_values+=("$_argc_take_value")
|
||||
_argc_take_args_len=$((_argc_take_args_len + 1))
|
||||
if [[ "$_argc_take_args_len" -ge "$max" ]]; then
|
||||
break
|
||||
fi
|
||||
_argc_take_index=$((_argc_take_index + 1))
|
||||
done
|
||||
fi
|
||||
if [[ "${#_argc_take_args_values[@]}" -lt "$min" ]]; then
|
||||
_argc_die "error: incorrect number of values for \`$param\`"
|
||||
fi
|
||||
if [[ -n "$delimiter" ]] && [[ "${#_argc_take_args_values[@]}" -gt 0 ]]; then
|
||||
local item values arr=()
|
||||
for item in "${_argc_take_args_values[@]}"; do
|
||||
IFS="$delimiter" read -r -a values <<<"$item"
|
||||
arr+=("${values[@]}")
|
||||
done
|
||||
_argc_take_args_values=("${arr[@]}")
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_require_params() {
|
||||
local message="$1" missed_envs="" item name render_name
|
||||
for item in "${@:2}"; do
|
||||
name="${item%%:*}"
|
||||
render_name="${item##*:}"
|
||||
if [[ -z "${!name:-}" ]]; then
|
||||
missed_envs="$missed_envs"$'\n'" $render_name"
|
||||
fi
|
||||
done
|
||||
if [[ -n "${missed_envs}" ]]; then
|
||||
_argc_die "$message$missed_envs"
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_maybe_flag_option() {
|
||||
local signs="$1" arg="$2"
|
||||
if [[ -z "$signs" ]]; then
|
||||
return 1
|
||||
fi
|
||||
local cond=false
|
||||
if [[ "$signs" == *"+"* ]]; then
|
||||
if [[ "$arg" =~ ^\+[^+].* ]]; then
|
||||
cond=true
|
||||
fi
|
||||
elif [[ "$arg" == -* ]]; then
|
||||
if (( ${#arg} < 3 )) || [[ ! "$arg" =~ ^---.* ]]; then
|
||||
cond=true
|
||||
fi
|
||||
fi
|
||||
if [[ "$cond" == "false" ]]; then
|
||||
return 1
|
||||
fi
|
||||
local value="${arg%%=*}"
|
||||
if [[ "$value" =~ [[:space:]] ]]; then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
_argc_die() {
|
||||
if [[ $# -eq 0 ]]; then
|
||||
cat
|
||||
else
|
||||
echo "$*" >&2
|
||||
fi
|
||||
exit 1
|
||||
}
|
||||
|
||||
_argc_run "$@"
|
||||
|
||||
# ARGC-BUILD }
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Get the current time.
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
main() {
|
||||
date >> "$LLM_OUTPUT"
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
from urllib.parse import quote_plus
|
||||
from urllib.request import urlopen
|
||||
|
||||
|
||||
def run(
|
||||
location: str,
|
||||
llm_output: Optional[str] = None,
|
||||
) -> str:
|
||||
"""Get the current weather in a given location
|
||||
|
||||
Args:
|
||||
location (str): The city and optionally the state or country (e.g., "London", "San Francisco, CA").
|
||||
|
||||
Returns:
|
||||
str: A single-line formatted weather string from wttr.in (``format=4`` with metric units).
|
||||
"""
|
||||
url = f"https://wttr.in/{quote_plus(location)}?format=4&M"
|
||||
|
||||
with urlopen(url, timeout=10) as resp:
|
||||
weather = resp.read().decode("utf-8", errors="replace")
|
||||
|
||||
dest = llm_output if llm_output is not None else os.environ.get("LLM_OUTPUT", "/dev/stdout")
|
||||
|
||||
if dest not in {"-", "/dev/stdout"}:
|
||||
path = Path(dest)
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with path.open("a", encoding="utf-8") as fh:
|
||||
fh.write(weather)
|
||||
else:
|
||||
pass
|
||||
|
||||
return weather
|
||||
+199
@@ -0,0 +1,199 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Get the current weather in a given location.
|
||||
# @option --location! The city and optionally the state or country, e.g., "London", "San Francisco, CA".
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
main() {
|
||||
curl -fsSL "https://wttr.in/$(echo "$argc_location" | sed 's/ /+/g')?format=4&M" \
|
||||
>> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
# ARGC-BUILD {
|
||||
# This block was generated by argc (https://github.com/sigoden/argc).
|
||||
# Modifying it manually is not recommended
|
||||
|
||||
_argc_run() {
|
||||
if [[ "${1:-}" == "___internal___" ]]; then
|
||||
_argc_die "error: unsupported ___internal___ command"
|
||||
fi
|
||||
if [[ "${OS:-}" == "Windows_NT" ]] && [[ -n "${MSYSTEM:-}" ]]; then
|
||||
set -o igncr
|
||||
fi
|
||||
argc__args=("$(basename "$0" .sh)" "$@")
|
||||
argc__positionals=()
|
||||
_argc_index=1
|
||||
_argc_len="${#argc__args[@]}"
|
||||
_argc_tools=()
|
||||
_argc_parse
|
||||
if [ -n "${argc__fn:-}" ]; then
|
||||
$argc__fn "${argc__positionals[@]}"
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_usage() {
|
||||
cat <<-'EOF'
|
||||
Get the current weather in a given location.
|
||||
|
||||
USAGE: --location <LOCATION>
|
||||
|
||||
OPTIONS:
|
||||
--location <LOCATION> The city and optionally the state or country, e.g., "London", "San Francisco, CA".
|
||||
-h, --help Print help
|
||||
-V, --version Print version
|
||||
|
||||
ENVIRONMENTS:
|
||||
LLM_OUTPUT The output path [default: /dev/stdout]
|
||||
EOF
|
||||
exit
|
||||
}
|
||||
|
||||
_argc_version() {
|
||||
echo 0.0.0
|
||||
exit
|
||||
}
|
||||
|
||||
_argc_parse() {
|
||||
local _argc_key _argc_action
|
||||
local _argc_subcmds=""
|
||||
while [[ $_argc_index -lt $_argc_len ]]; do
|
||||
_argc_item="${argc__args[_argc_index]}"
|
||||
_argc_key="${_argc_item%%=*}"
|
||||
case "$_argc_key" in
|
||||
--help | -help | -h)
|
||||
_argc_usage
|
||||
;;
|
||||
--version | -version | -V)
|
||||
_argc_version
|
||||
;;
|
||||
--)
|
||||
_argc_dash="${#argc__positionals[@]}"
|
||||
argc__positionals+=("${argc__args[@]:$((_argc_index + 1))}")
|
||||
_argc_index=$_argc_len
|
||||
break
|
||||
;;
|
||||
--location)
|
||||
_argc_take_args "--location <LOCATION>" 1 1 "-" ""
|
||||
_argc_index=$((_argc_index + _argc_take_args_len + 1))
|
||||
if [[ -z "${argc_location:-}" ]]; then
|
||||
argc_location="${_argc_take_args_values[0]:-}"
|
||||
else
|
||||
_argc_die "error: the argument \`--location\` cannot be used multiple times"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
if _argc_maybe_flag_option "-" "$_argc_item"; then
|
||||
_argc_die "error: unexpected argument \`$_argc_key\` found"
|
||||
fi
|
||||
argc__positionals+=("$_argc_item")
|
||||
_argc_index=$((_argc_index + 1))
|
||||
;;
|
||||
esac
|
||||
done
|
||||
_argc_require_params "error: the following required arguments were not provided:" \
|
||||
'argc_location:--location <LOCATION>'
|
||||
if [[ -n "${_argc_action:-}" ]]; then
|
||||
$_argc_action
|
||||
else
|
||||
argc__fn=main
|
||||
if [[ "${argc__positionals[0]:-}" == "help" ]] && [[ "${#argc__positionals[@]}" -eq 1 ]]; then
|
||||
_argc_usage
|
||||
fi
|
||||
if [[ -z "${LLM_OUTPUT:-}" ]]; then
|
||||
export LLM_OUTPUT=/dev/stdout
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_take_args() {
|
||||
_argc_take_args_values=()
|
||||
_argc_take_args_len=0
|
||||
local param="$1" min="$2" max="$3" signs="$4" delimiter="$5"
|
||||
if [[ "$min" -eq 0 ]] && [[ "$max" -eq 0 ]]; then
|
||||
return
|
||||
fi
|
||||
local _argc_take_index=$((_argc_index + 1)) _argc_take_value
|
||||
if [[ "$_argc_item" == *=* ]]; then
|
||||
_argc_take_args_values=("${_argc_item##*=}")
|
||||
else
|
||||
while [[ $_argc_take_index -lt $_argc_len ]]; do
|
||||
_argc_take_value="${argc__args[_argc_take_index]}"
|
||||
if _argc_maybe_flag_option "$signs" "$_argc_take_value"; then
|
||||
if [[ "${#_argc_take_value}" -gt 1 ]]; then
|
||||
break
|
||||
fi
|
||||
fi
|
||||
_argc_take_args_values+=("$_argc_take_value")
|
||||
_argc_take_args_len=$((_argc_take_args_len + 1))
|
||||
if [[ "$_argc_take_args_len" -ge "$max" ]]; then
|
||||
break
|
||||
fi
|
||||
_argc_take_index=$((_argc_take_index + 1))
|
||||
done
|
||||
fi
|
||||
if [[ "${#_argc_take_args_values[@]}" -lt "$min" ]]; then
|
||||
_argc_die "error: incorrect number of values for \`$param\`"
|
||||
fi
|
||||
if [[ -n "$delimiter" ]] && [[ "${#_argc_take_args_values[@]}" -gt 0 ]]; then
|
||||
local item values arr=()
|
||||
for item in "${_argc_take_args_values[@]}"; do
|
||||
IFS="$delimiter" read -r -a values <<<"$item"
|
||||
arr+=("${values[@]}")
|
||||
done
|
||||
_argc_take_args_values=("${arr[@]}")
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_require_params() {
|
||||
local message="$1" missed_envs="" item name render_name
|
||||
for item in "${@:2}"; do
|
||||
name="${item%%:*}"
|
||||
render_name="${item##*:}"
|
||||
if [[ -z "${!name:-}" ]]; then
|
||||
missed_envs="$missed_envs"$'\n'" $render_name"
|
||||
fi
|
||||
done
|
||||
if [[ -n "${missed_envs}" ]]; then
|
||||
_argc_die "$message$missed_envs"
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_maybe_flag_option() {
|
||||
local signs="$1" arg="$2"
|
||||
if [[ -z "$signs" ]]; then
|
||||
return 1
|
||||
fi
|
||||
local cond=false
|
||||
if [[ "$signs" == *"+"* ]]; then
|
||||
if [[ "$arg" =~ ^\+[^+].* ]]; then
|
||||
cond=true
|
||||
fi
|
||||
elif [[ "$arg" == -* ]]; then
|
||||
if (( ${#arg} < 3 )) || [[ ! "$arg" =~ ^---.* ]]; then
|
||||
cond=true
|
||||
fi
|
||||
fi
|
||||
if [[ "$cond" == "false" ]]; then
|
||||
return 1
|
||||
fi
|
||||
local value="${arg%%=*}"
|
||||
if [[ "$value" =~ [[:space:]] ]]; then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
_argc_die() {
|
||||
if [[ $# -eq 0 ]]; then
|
||||
cat
|
||||
else
|
||||
echo "$*" >&2
|
||||
fi
|
||||
exit 1
|
||||
}
|
||||
|
||||
_argc_run "$@"
|
||||
|
||||
# ARGC-BUILD }
|
||||
Executable
+198
@@ -0,0 +1,198 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @meta require-tools jira
|
||||
# @describe Query for jira issues using a Jira Query Language (JQL) query
|
||||
# @option --jql-query! The Jira Query Language query to execute
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
main() {
|
||||
jira issue ls -q "$argc_jql_query" --plain >> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
# ARGC-BUILD {
|
||||
# This block was generated by argc (https://github.com/sigoden/argc).
|
||||
# Modifying it manually is not recommended
|
||||
|
||||
_argc_run() {
|
||||
if [[ "${1:-}" == "___internal___" ]]; then
|
||||
_argc_die "error: unsupported ___internal___ command"
|
||||
fi
|
||||
if [[ "${OS:-}" == "Windows_NT" ]] && [[ -n "${MSYSTEM:-}" ]]; then
|
||||
set -o igncr
|
||||
fi
|
||||
argc__args=("$(basename "$0" .sh)" "$@")
|
||||
argc__positionals=()
|
||||
_argc_index=1
|
||||
_argc_len="${#argc__args[@]}"
|
||||
_argc_tools=()
|
||||
_argc_parse
|
||||
if [ -n "${argc__fn:-}" ]; then
|
||||
$argc__fn "${argc__positionals[@]}"
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_usage() {
|
||||
cat <<-'EOF'
|
||||
Query for jira issues using a Jira Query Language (JQL) query
|
||||
|
||||
USAGE: --jql-query <JQL-QUERY>
|
||||
|
||||
OPTIONS:
|
||||
--jql-query <JQL-QUERY> The Jira Query Language query to execute
|
||||
-h, --help Print help
|
||||
-V, --version Print version
|
||||
|
||||
ENVIRONMENTS:
|
||||
LLM_OUTPUT The output path [default: /dev/stdout]
|
||||
EOF
|
||||
exit
|
||||
}
|
||||
|
||||
_argc_version() {
|
||||
echo 0.0.0
|
||||
exit
|
||||
}
|
||||
|
||||
_argc_parse() {
|
||||
local _argc_key _argc_action
|
||||
local _argc_subcmds=""
|
||||
while [[ $_argc_index -lt $_argc_len ]]; do
|
||||
_argc_item="${argc__args[_argc_index]}"
|
||||
_argc_key="${_argc_item%%=*}"
|
||||
case "$_argc_key" in
|
||||
--help | -help | -h)
|
||||
_argc_usage
|
||||
;;
|
||||
--version | -version | -V)
|
||||
_argc_version
|
||||
;;
|
||||
--)
|
||||
_argc_dash="${#argc__positionals[@]}"
|
||||
argc__positionals+=("${argc__args[@]:$((_argc_index + 1))}")
|
||||
_argc_index=$_argc_len
|
||||
break
|
||||
;;
|
||||
--jql-query)
|
||||
_argc_take_args "--jql-query <JQL-QUERY>" 1 1 "-" ""
|
||||
_argc_index=$((_argc_index + _argc_take_args_len + 1))
|
||||
if [[ -z "${argc_jql_query:-}" ]]; then
|
||||
argc_jql_query="${_argc_take_args_values[0]:-}"
|
||||
else
|
||||
_argc_die "error: the argument \`--jql-query\` cannot be used multiple times"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
if _argc_maybe_flag_option "-" "$_argc_item"; then
|
||||
_argc_die "error: unexpected argument \`$_argc_key\` found"
|
||||
fi
|
||||
argc__positionals+=("$_argc_item")
|
||||
_argc_index=$((_argc_index + 1))
|
||||
;;
|
||||
esac
|
||||
done
|
||||
_argc_require_params "error: the following required arguments were not provided:" \
|
||||
'argc_jql_query:--jql-query <JQL-QUERY>'
|
||||
if [[ -n "${_argc_action:-}" ]]; then
|
||||
$_argc_action
|
||||
else
|
||||
argc__fn=main
|
||||
if [[ "${argc__positionals[0]:-}" == "help" ]] && [[ "${#argc__positionals[@]}" -eq 1 ]]; then
|
||||
_argc_usage
|
||||
fi
|
||||
if [[ -z "${LLM_OUTPUT:-}" ]]; then
|
||||
export LLM_OUTPUT=/dev/stdout
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_take_args() {
|
||||
_argc_take_args_values=()
|
||||
_argc_take_args_len=0
|
||||
local param="$1" min="$2" max="$3" signs="$4" delimiter="$5"
|
||||
if [[ "$min" -eq 0 ]] && [[ "$max" -eq 0 ]]; then
|
||||
return
|
||||
fi
|
||||
local _argc_take_index=$((_argc_index + 1)) _argc_take_value
|
||||
if [[ "$_argc_item" == *=* ]]; then
|
||||
_argc_take_args_values=("${_argc_item##*=}")
|
||||
else
|
||||
while [[ $_argc_take_index -lt $_argc_len ]]; do
|
||||
_argc_take_value="${argc__args[_argc_take_index]}"
|
||||
if _argc_maybe_flag_option "$signs" "$_argc_take_value"; then
|
||||
if [[ "${#_argc_take_value}" -gt 1 ]]; then
|
||||
break
|
||||
fi
|
||||
fi
|
||||
_argc_take_args_values+=("$_argc_take_value")
|
||||
_argc_take_args_len=$((_argc_take_args_len + 1))
|
||||
if [[ "$_argc_take_args_len" -ge "$max" ]]; then
|
||||
break
|
||||
fi
|
||||
_argc_take_index=$((_argc_take_index + 1))
|
||||
done
|
||||
fi
|
||||
if [[ "${#_argc_take_args_values[@]}" -lt "$min" ]]; then
|
||||
_argc_die "error: incorrect number of values for \`$param\`"
|
||||
fi
|
||||
if [[ -n "$delimiter" ]] && [[ "${#_argc_take_args_values[@]}" -gt 0 ]]; then
|
||||
local item values arr=()
|
||||
for item in "${_argc_take_args_values[@]}"; do
|
||||
IFS="$delimiter" read -r -a values <<<"$item"
|
||||
arr+=("${values[@]}")
|
||||
done
|
||||
_argc_take_args_values=("${arr[@]}")
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_require_params() {
|
||||
local message="$1" missed_envs="" item name render_name
|
||||
for item in "${@:2}"; do
|
||||
name="${item%%:*}"
|
||||
render_name="${item##*:}"
|
||||
if [[ -z "${!name:-}" ]]; then
|
||||
missed_envs="$missed_envs"$'\n'" $render_name"
|
||||
fi
|
||||
done
|
||||
if [[ -n "${missed_envs}" ]]; then
|
||||
_argc_die "$message$missed_envs"
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_maybe_flag_option() {
|
||||
local signs="$1" arg="$2"
|
||||
if [[ -z "$signs" ]]; then
|
||||
return 1
|
||||
fi
|
||||
local cond=false
|
||||
if [[ "$signs" == *"+"* ]]; then
|
||||
if [[ "$arg" =~ ^\+[^+].* ]]; then
|
||||
cond=true
|
||||
fi
|
||||
elif [[ "$arg" == -* ]]; then
|
||||
if (( ${#arg} < 3 )) || [[ ! "$arg" =~ ^---.* ]]; then
|
||||
cond=true
|
||||
fi
|
||||
fi
|
||||
if [[ "$cond" == "false" ]]; then
|
||||
return 1
|
||||
fi
|
||||
local value="${arg%%=*}"
|
||||
if [[ "$value" =~ [[:space:]] ]]; then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
_argc_die() {
|
||||
if [[ $# -eq 0 ]]; then
|
||||
cat
|
||||
else
|
||||
echo "$*" >&2
|
||||
fi
|
||||
exit 1
|
||||
}
|
||||
|
||||
_argc_run "$@"
|
||||
|
||||
# ARGC-BUILD }
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Search arXiv using the given search query and return the top papers.
|
||||
|
||||
# @option --query! The search query.
|
||||
|
||||
# @env ARXIV_MAX_RESULTS=3 The max results to return.
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
main() {
|
||||
# shellcheck disable=SC2154
|
||||
encoded_query="$(jq -nr --arg q "$argc_query" '$q|@uri')"
|
||||
url="http://export.arxiv.org/api/query?search_query=all:$encoded_query&max_results=$ARXIV_MAX_RESULTS"
|
||||
curl -fsSL "$url" >> "$LLM_OUTPUT"
|
||||
}
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Search Wikipedia using the given search query.
|
||||
# Use it to get detailed information about a public figure, interpretation of a complex scientific concept or in-depth connectivity of a significant historical event, etc.
|
||||
|
||||
# @option --query! The search query.
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
encoded_query="$(jq -nr --arg q "$argc_query" '$q|@uri')"
|
||||
base_url="https://en.wikipedia.org/w/api.php"
|
||||
url="$base_url?action=query&list=search&srprop=&srlimit=1&limit=1&srsearch=$encoded_query&srinfo=suggestion&format=json"
|
||||
json="$(curl -fsSL "$url")"
|
||||
# suggestion="$(echo "$json" | jq -r '.query.searchinfo.suggestion // empty')"
|
||||
title="$(echo "$json" | jq -r '.query.search[0].title // empty')"
|
||||
pageid="$(echo "$json" | jq -r '.query.search[0].pageid // empty')"
|
||||
|
||||
if [[ -z "$title" || -z "$pageid" ]]; then
|
||||
echo "error: no results for '$argc_query'" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
title="$(echo "$title" | tr ' ' '_')"
|
||||
url="$base_url?action=query&prop=extracts&explaintext=&titles=$title&exintro=&format=json"
|
||||
curl -fsSL "$url" | jq -r '.query.pages["'"$pageid"'"].extract' >> "$LLM_OUTPUT"
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Get an answer to a question using Wolfram Alpha. The input query should be in English.
|
||||
# Use it to answer user questions that require computation, detailed facts, data analysis, or complex queries.
|
||||
|
||||
# @option --query! The search/computation query to pass to Wolfram Alpha
|
||||
|
||||
# @env WOLFRAM_API_ID! Your Wolfram Alpha API ID
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
encoded_query="$(jq -nr --arg q "$argc_query" '$q|@uri')"
|
||||
url="https://api.wolframalpha.com/v2/query?appid=${WOLFRAM_API_ID}&input=$encoded_query&output=json&format=plaintext"
|
||||
|
||||
curl -fsSL "$url" | jq '[.queryresult | .pods[] | {title:.title, values:[.subpods[].plaintext | select(. != "")]}]' \
|
||||
>> "$LLM_OUTPUT"
|
||||
}
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Send an email.
|
||||
# @option --recipient! The recipient of the email.
|
||||
# @option --subject! The subject of the email.
|
||||
# @option --body! The body of the email.
|
||||
|
||||
# @env EMAIL_SMTP_ADDR! The SMTP Address, e.g. smtps://smtp.gmail.com:465
|
||||
# @env EMAIL_SMTP_USER! The SMTP User, e.g. alice@gmail.com
|
||||
# @env EMAIL_SMTP_PASS! The SMTP Password
|
||||
# @env EMAIL_SENDER_NAME The sender's name
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
sender_name="${EMAIL_SENDER_NAME:-$(echo "$EMAIL_SMTP_USER" | awk -F'@' '{print $1}')}"
|
||||
printf "%s\n" "From: $sender_name <$EMAIL_SMTP_USER>
|
||||
To: $argc_recipient
|
||||
Subject: $argc_subject
|
||||
|
||||
$argc_body" | \
|
||||
curl -fsS --ssl-reqd \
|
||||
--url "$EMAIL_SMTP_ADDR" \
|
||||
--user "$EMAIL_SMTP_USER:$EMAIL_SMTP_PASS" \
|
||||
--mail-from "$EMAIL_SMTP_USER" \
|
||||
--mail-rcpt "$argc_recipient" \
|
||||
--upload-file -
|
||||
echo "Email sent successfully" >> "$LLM_OUTPUT"
|
||||
}
|
||||
Executable
+50
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Send SMS or Twilio Messaging Channels messages using the Twilio API.
|
||||
# @option --to-number! The recipient's phone number. Prefix it with 'whatsapp:' for WhatsApp messages, e.g. whatsapp:+1234567890
|
||||
# @option --message! The content of the message to be sent
|
||||
|
||||
# @env TWILIO_ACCOUNT_SID! The twilio account sid
|
||||
# @env TWILIO_AUTH_TOKEN! The twilio auth token
|
||||
# @env TWILIO_FROM_NUMBER! The twilio from number
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
from_number="$TWILIO_FROM_NUMBER"
|
||||
to_number="$argc_to_number"
|
||||
|
||||
if [[ "$to_number" == 'whatsapp:'* ]]; then
|
||||
from_number="whatsapp:$from_number"
|
||||
fi
|
||||
|
||||
if [[ "$to_number" != 'whatsapp:'* && "$to_number" != '+'* ]]; then
|
||||
to_number="+$to_number"
|
||||
fi
|
||||
|
||||
res="$(curl -s -X POST "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages.json" \
|
||||
-u "$TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN" \
|
||||
-w "\n%{http_code}" \
|
||||
--data-urlencode "From=$from_number" \
|
||||
--data-urlencode "To=$to_number" \
|
||||
--data-urlencode "Body=$argc_message")"
|
||||
status="$(echo "$res" | tail -n 1)"
|
||||
body="$(echo "$res" | head -n -1)"
|
||||
|
||||
if [[ "$status" -ge 200 && "$status" -lt 300 ]]; then
|
||||
if [[ "$(echo "$body" | jq -r 'has("sid")')" == "true" ]]; then
|
||||
echo "Message sent successfully" >> "$LLM_OUTPUT"
|
||||
else
|
||||
_die "error: $body"
|
||||
fi
|
||||
else
|
||||
_die "error: $body"
|
||||
fi
|
||||
}
|
||||
|
||||
_die() {
|
||||
echo "$*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
Executable
+254
@@ -0,0 +1,254 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Perform a web search to get up-to-date information or additional context.
|
||||
# Use this when you need current information or feel a search could provide a better answer.
|
||||
|
||||
# @option --query! The search query.
|
||||
|
||||
# @meta require-tools loki
|
||||
|
||||
# @env WEB_SEARCH_MODEL=gemini:gemini-2.5-flash The model for web-searching.
|
||||
#
|
||||
# supported loki models:
|
||||
# - gemini:gemini-2.0-*
|
||||
# - vertexai:gemini-*
|
||||
# - perplexity:*
|
||||
# - ernie:*
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
client="${WEB_SEARCH_MODEL%%:*}"
|
||||
|
||||
if [[ "$client" == "gemini" ]]; then
|
||||
export LOKI_PATCH_GEMINI_CHAT_COMPLETIONS='{".*":{"body":{"tools":[{"google_search":{}}]}}}'
|
||||
elif [[ "$client" == "vertexai" ]]; then
|
||||
export LOKI_PATCH_VERTEXAI_CHAT_COMPLETIONS='{
|
||||
"gemini-1.5-.*":{"body":{"tools":[{"googleSearchRetrieval":{}}]}},
|
||||
"gemini-2.0-.*":{"body":{"tools":[{"google_search":{}}]}}
|
||||
}'
|
||||
elif [[ "$client" == "ernie" ]]; then
|
||||
export LOKI_PATCH_ERNIE_CHAT_COMPLETIONS='{".*":{"body":{"web_search":{"enable":true}}}}'
|
||||
fi
|
||||
|
||||
loki -m "$WEB_SEARCH_MODEL" "$argc_query" >> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
|
||||
# ARGC-BUILD {
|
||||
# This block was generated by argc (https://github.com/sigoden/argc).
|
||||
# Modifying it manually is not recommended
|
||||
|
||||
_argc_run() {
|
||||
if [[ "${1:-}" == "___internal___" ]]; then
|
||||
_argc_die "error: unsupported ___internal___ command"
|
||||
fi
|
||||
if [[ "${OS:-}" == "Windows_NT" ]] && [[ -n "${MSYSTEM:-}" ]]; then
|
||||
set -o igncr
|
||||
fi
|
||||
argc__args=("$(basename "$0" .sh)" "$@")
|
||||
argc__positionals=()
|
||||
_argc_index=1
|
||||
_argc_len="${#argc__args[@]}"
|
||||
_argc_tools=()
|
||||
_argc_parse
|
||||
_argc_require_tools "${_argc_tools[@]}"
|
||||
if [ -n "${argc__fn:-}" ]; then
|
||||
$argc__fn "${argc__positionals[@]}"
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_usage() {
|
||||
cat <<-'EOF'
|
||||
Perform a web search to get up-to-date information or additional context.
|
||||
Use this when you need current information or feel a search could provide a better answer.
|
||||
|
||||
USAGE: --query <QUERY>
|
||||
|
||||
OPTIONS:
|
||||
--query <QUERY> The query to search for.
|
||||
-h, --help Print help
|
||||
-V, --version Print version
|
||||
|
||||
ENVIRONMENTS:
|
||||
WEB_SEARCH_MODEL
|
||||
The model for web-searching.
|
||||
|
||||
supported loki models:
|
||||
- gemini:gemini-2.0-*
|
||||
- vertexai:gemini-*
|
||||
- perplexity:*
|
||||
- ernie:*
|
||||
[default: gemini:gemini-2.5-flash]
|
||||
|
||||
LLM_OUTPUT
|
||||
The output path [default: /dev/stdout]
|
||||
EOF
|
||||
exit
|
||||
}
|
||||
|
||||
_argc_version() {
|
||||
echo 0.0.0
|
||||
exit
|
||||
}
|
||||
|
||||
_argc_parse() {
|
||||
local _argc_key _argc_action
|
||||
local _argc_subcmds=""
|
||||
while [[ $_argc_index -lt $_argc_len ]]; do
|
||||
_argc_item="${argc__args[_argc_index]}"
|
||||
_argc_key="${_argc_item%%=*}"
|
||||
case "$_argc_key" in
|
||||
--help | -help | -h)
|
||||
_argc_usage
|
||||
;;
|
||||
--version | -version | -V)
|
||||
_argc_version
|
||||
;;
|
||||
--)
|
||||
_argc_dash="${#argc__positionals[@]}"
|
||||
argc__positionals+=("${argc__args[@]:$((_argc_index + 1))}")
|
||||
_argc_index=$_argc_len
|
||||
break
|
||||
;;
|
||||
--query)
|
||||
_argc_take_args "--query <QUERY>" 1 1 "-" ""
|
||||
_argc_index=$((_argc_index + _argc_take_args_len + 1))
|
||||
if [[ -z "${argc_query:-}" ]]; then
|
||||
argc_query="${_argc_take_args_values[0]:-}"
|
||||
else
|
||||
_argc_die "error: the argument \`--query\` cannot be used multiple times"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
if _argc_maybe_flag_option "-" "$_argc_item"; then
|
||||
_argc_die "error: unexpected argument \`$_argc_key\` found"
|
||||
fi
|
||||
argc__positionals+=("$_argc_item")
|
||||
_argc_index=$((_argc_index + 1))
|
||||
;;
|
||||
esac
|
||||
done
|
||||
_argc_require_params "error: the following required arguments were not provided:" \
|
||||
'argc_query:--query <QUERY>'
|
||||
_argc_tools=(loki)
|
||||
if [[ -n "${_argc_action:-}" ]]; then
|
||||
$_argc_action
|
||||
else
|
||||
argc__fn=main
|
||||
if [[ "${argc__positionals[0]:-}" == "help" ]] && [[ "${#argc__positionals[@]}" -eq 1 ]]; then
|
||||
_argc_usage
|
||||
fi
|
||||
if [[ -z "${WEB_SEARCH_MODEL:-}" ]]; then
|
||||
export WEB_SEARCH_MODEL=gemini:gemini-2.5-flash
|
||||
fi
|
||||
if [[ -z "${LLM_OUTPUT:-}" ]]; then
|
||||
export LLM_OUTPUT=/dev/stdout
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_take_args() {
|
||||
_argc_take_args_values=()
|
||||
_argc_take_args_len=0
|
||||
local param="$1" min="$2" max="$3" signs="$4" delimiter="$5"
|
||||
if [[ "$min" -eq 0 ]] && [[ "$max" -eq 0 ]]; then
|
||||
return
|
||||
fi
|
||||
local _argc_take_index=$((_argc_index + 1)) _argc_take_value
|
||||
if [[ "$_argc_item" == *=* ]]; then
|
||||
_argc_take_args_values=("${_argc_item##*=}")
|
||||
else
|
||||
while [[ $_argc_take_index -lt $_argc_len ]]; do
|
||||
_argc_take_value="${argc__args[_argc_take_index]}"
|
||||
if _argc_maybe_flag_option "$signs" "$_argc_take_value"; then
|
||||
if [[ "${#_argc_take_value}" -gt 1 ]]; then
|
||||
break
|
||||
fi
|
||||
fi
|
||||
_argc_take_args_values+=("$_argc_take_value")
|
||||
_argc_take_args_len=$((_argc_take_args_len + 1))
|
||||
if [[ "$_argc_take_args_len" -ge "$max" ]]; then
|
||||
break
|
||||
fi
|
||||
_argc_take_index=$((_argc_take_index + 1))
|
||||
done
|
||||
fi
|
||||
if [[ "${#_argc_take_args_values[@]}" -lt "$min" ]]; then
|
||||
_argc_die "error: incorrect number of values for \`$param\`"
|
||||
fi
|
||||
if [[ -n "$delimiter" ]] && [[ "${#_argc_take_args_values[@]}" -gt 0 ]]; then
|
||||
local item values arr=()
|
||||
for item in "${_argc_take_args_values[@]}"; do
|
||||
IFS="$delimiter" read -r -a values <<<"$item"
|
||||
arr+=("${values[@]}")
|
||||
done
|
||||
_argc_take_args_values=("${arr[@]}")
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_require_params() {
|
||||
local message="$1" missed_envs="" item name render_name
|
||||
for item in "${@:2}"; do
|
||||
name="${item%%:*}"
|
||||
render_name="${item##*:}"
|
||||
if [[ -z "${!name:-}" ]]; then
|
||||
missed_envs="$missed_envs"$'\n'" $render_name"
|
||||
fi
|
||||
done
|
||||
if [[ -n "${missed_envs}" ]]; then
|
||||
_argc_die "$message$missed_envs"
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_maybe_flag_option() {
|
||||
local signs="$1" arg="$2"
|
||||
if [[ -z "$signs" ]]; then
|
||||
return 1
|
||||
fi
|
||||
local cond=false
|
||||
if [[ "$signs" == *"+"* ]]; then
|
||||
if [[ "$arg" =~ ^\+[^+].* ]]; then
|
||||
cond=true
|
||||
fi
|
||||
elif [[ "$arg" == -* ]]; then
|
||||
if (( ${#arg} < 3 )) || [[ ! "$arg" =~ ^---.* ]]; then
|
||||
cond=true
|
||||
fi
|
||||
fi
|
||||
if [[ "$cond" == "false" ]]; then
|
||||
return 1
|
||||
fi
|
||||
local value="${arg%%=*}"
|
||||
if [[ "$value" =~ [[:space:]] ]]; then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
_argc_require_tools() {
|
||||
local tool missing_tools=()
|
||||
for tool in "$@"; do
|
||||
if ! command -v "$tool" >/dev/null 2>&1; then
|
||||
missing_tools+=("$tool")
|
||||
fi
|
||||
done
|
||||
if [[ "${#missing_tools[@]}" -gt 0 ]]; then
|
||||
echo "error: missing tools: ${missing_tools[*]}" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_die() {
|
||||
if [[ $# -eq 0 ]]; then
|
||||
cat
|
||||
else
|
||||
echo "$*" >&2
|
||||
fi
|
||||
exit 1
|
||||
}
|
||||
|
||||
_argc_run "$@"
|
||||
|
||||
# ARGC-BUILD }
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Perform a web search using the Perplexity API to get up-to-date information or additional context.
|
||||
# Use this when you need current information or feel a search could provide a better answer.
|
||||
|
||||
# @option --query! The search query.
|
||||
|
||||
# @env PERPLEXITY_API_KEY! Your Perplexity API key
|
||||
# @env PERPLEXITY_WEB_SEARCH_MODEL=llama-3.1-sonar-small-128k-online The LLM model to use for the search
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
curl -fsS -X POST https://api.perplexity.ai/chat/completions \
|
||||
-H "authorization: Bearer $PERPLEXITY_API_KEY" \
|
||||
-H "accept: application/json" \
|
||||
-H "content-type: application/json" \
|
||||
--data '
|
||||
{
|
||||
"model": "'"$PERPLEXITY_WEB_SEARCH_MODEL"'",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "'"$argc_query"'"
|
||||
}
|
||||
]
|
||||
}
|
||||
' | \
|
||||
jq -r '.choices[0].message.content' \
|
||||
>> "$LLM_OUTPUT"
|
||||
}
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Perform a web search using the Tavily API to get up-to-date information or additional context.
|
||||
# Use this when you need current information or feel a search could provide a better answer.
|
||||
|
||||
# @option --query! The search query.
|
||||
|
||||
# @env TAVILY_API_KEY! Your Tavile API key
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path The output path
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
curl -fsSL -X POST https://api.tavily.com/search \
|
||||
-H "content-type: application/json" \
|
||||
-d '
|
||||
{
|
||||
"api_key": "'"$TAVILY_API_KEY"'",
|
||||
"query": "'"$argc_query"'",
|
||||
"include_answer": true
|
||||
}' | \
|
||||
jq -r '.answer' >> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user