Skip to content
Back to search

legal-skills-open

Open library of legal AI skills (SKILL.md) for MCP-compatible agents — 39 jurisdictions, 200+ plugins, Apache-2.0.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today

Check it deeper on your machine

Its scripts were only partly scanned.

As a Claude Code plugin, install it and then ask Claude Code:

/plugin marketplace add keithmackay/mackayi/plugin install scanskillsafety@mackayiDo a deep scan of https://github.com/ThomasMoreAI/legal-skills-open with scanskillsafety

Or from a terminal, clone it and run it:

git clone https://github.com/keithmackay/scanskillsafety-skill ~/.claude/skills/scanskillsafetynode ~/.claude/skills/scanskillsafety/cli.cjs --deep 'https://github.com/ThomasMoreAI/legal-skills-open'

It checks the exact commit: every file, its packages against OSV (api.osv.dev), how it compares with this page's scan (findsafeskills.com receives the repository's address), and, if you agree, Claude reading every file with your own Claude subscription. It never runs the code.

Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/thomasmoreai--legal-skills-open/badge.svg)](/listings/thomasmoreai--legal-skills-open)

HTML

<a href="/listings/thomasmoreai--legal-skills-open"><img src="/api/listings/thomasmoreai--legal-skills-open/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 224 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # Legal Skills (Open)
  2. > **Open-source library of legal AI skills** in the Anthropic Skills
  3. > (`SKILL.md`) format, runnable by any MCP-compatible client — Claude Code,
  4. > Claude Cowork, Cursor, ChatGPT, the ThomasMore desktop app. **18,000+ skills
  5. > across 54 jurisdictions and 410+ practice plugins** — from filing-fee
  6. > calculators and case-law analysis to GDPR DPA review and US securities
  7. > disclosure. Apache-2.0, contribution-friendly, no lock-in.
  8. [![License: Apache-2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
  9. ![Skills](https://img.shields.io/badge/skills-18%2C000%2B-brightgreen)
  10. ![Jurisdictions](https://img.shields.io/badge/jurisdictions-54-blue)
  11. ![Plugins](https://img.shields.io/badge/plugins-410%2B-blueviolet)
  12. ![Format: Anthropic Skills](https://img.shields.io/badge/format-Anthropic_Skills-orange)
  13. ![Runtime: MCP](https://img.shields.io/badge/runtime-MCP-9cf)
  14. ---
  15. ## Table of contents
  16. - [What this repository is](#what-this-repository-is--an-open-source-legal-ai-skill-library)
  17. - [What a skill looks like (`SKILL.md` format)](#what-a-skill-looks-like-skillmd-format)
  18. - [Coverage by jurisdiction](#coverage-by-jurisdiction)
  19. - [Coverage by practice area](#coverage-by-practice-area)
  20. - [License](#license)
  21. - [FAQ](#faq)
  22. - [Related projects](#related-projects)
  23. ---
  24. ## What this repository is — an open-source legal AI skill library
  25. A **legal AI skill** is a single Markdown file (`SKILL.md`) that describes one
  26. applied legal task — *«calculate the German court fee under the GKG for a
  27. civil claim», «analyse this case under FRCP Rule 12(b)(6)», «check this DPA
  28. against GDPR Article 28»* — in a structured format an AI agent can execute
  29. deterministically.
  30. Skills follow the [Anthropic Skills convention](https://www.anthropic.com/news/skills):
  31. YAML frontmatter (machine-readable contract) + Markdown body (the algorithm).
  32. Every skill in this repository is grouped into a plugin by **jurisdiction**
  33. and **practice area**:
  34. ```
  35. {country}/{practice}/skills/{slug}/SKILL.md
  36. ```
  37. Allowed `{country}` values: any ISO 3166-1 alpha-2 code, plus `general`
  38. (jurisdiction-agnostic) and `cross-jurisdiction` (multi-country comparative).
  39. **There are two ways to use these skills:**
  40. 1. **Locally.** Since this repository is open source and every skill follows the
  41. Anthropic Skills/plugin format, you can clone it and use the skills locally
  42. (as Claude Code skills/plugins).
  43. 2. **Via the MCP server ThomasMore.** Connect any MCP-compatible
  44. client to the MCP server `mcp.thomasmoreai.com`; the orchestrator finds and
  45. runs the right skill via its `discover` and `invoke` tools. Follow
  46. [thomasmoreai.com](https://thomasmoreai.com/) for updates on the MCP server launch.
  47. ---
  48. ## What a skill looks like (`SKILL.md` format)
  49. Real example from [`eu/data-protection/skills/gdpr-expert/`](eu/data-protection/skills/gdpr-expert/):
  50. ```yaml
  51. ---
  52. name: gdpr-expert
  53. title: GDPR Expert
  54. description: GDPR expert for EU privacy compliance. Deep knowledge of General Data Protection Regulation including 99 articles, 7 principles, 6 lawful bases, data subject rights, DPO requirements, DPIA, breach notification, cross-border transfers, and enforcement.
  55. author: GRCEngClub
  56. author_url: https://github.com/GRCEngClub/claude-grc-engineering/tree/main/plugins/frameworks/gdpr/skills/gdpr-expert
  57. license: MIT
  58. version: 0.1.0
  59. execution_mode: open
  60. jurisdiction: eu
  61. practice: data-protection
  62. language: en
  63. ---
  64. # Skill title
  65. ## When to apply
  66. Triggers, example user prompts, what is out of scope.
  67. ## Algorithm
  68. Step-by-step instructions for the orchestrator.
  69. ## Output contract
  70. What the answer must contain — citations, disclaimer, structured fields.
  71. ```
  72. The canonical schema is in
  73. [`schemas/skill-frontmatter.schema.json`](schemas/skill-frontmatter.schema.json).
  74. See [CONTRIBUTING.md](CONTRIBUTING.md) for the full walkthrough.
  75. ---
  76. ## Coverage by jurisdiction
  77. 54 jurisdictions, sorted by plugin count. Click any code to browse plugins
  78. and skills for that jurisdiction.
  79. | Jurisdiction | Plugins | Jurisdiction | Plugins |
  80. |---|---:|---|---:|
  81. | 🇩🇪 [`de/`](de/) — Germany | 44 | 🇱🇺 [`lu/`](lu/) — Luxembourg | 3 |
  82. | 🇺🇸 [`us/`](us/) — United States | 44 | 🇦🇷 [`ar/`](ar/) — Argentina | 2 |
  83. | 🌐 [`general/`](general/) — jurisdiction-agnostic | 31 | 🇫🇮 [`fi/`](fi/) — Finland | 2 |
  84. | 🌍 [`cross-jurisdiction/`](cross-jurisdiction/) — comparative | 28 | 🇬🇷 [`gr/`](gr/) — Greece | 2 |
  85. | 🇪🇺 [`eu/`](eu/) — European Union | 26 | 🇱🇧 [`lb/`](lb/) — Lebanon | 2 |
  86. | 🇵🇱 [`pl/`](pl/) — Poland | 17 | 🇲🇽 [`mx/`](mx/) — Mexico | 2 |
  87. | 🇨🇳 [`cn/`](cn/) — China | 16 | 🇷🇺 [`ru/`](ru/) — Russia | 2 |
  88. | 🇦🇹 [`at/`](at/) — Austria | 15 | 🇹🇭 [`th/`](th/) — Thailand | 2 |
  89. | 🇧🇷 [`br/`](br/) — Brazil | 15 | 🇹🇼 [`tw/`](tw/) — Taiwan | 2 |
  90. | 🇫🇷 [`fr/`](fr/) — France | 14 | 🇻🇳 [`vn/`](vn/) — Vietnam | 2 |
  91. | 🇬🇧 [`gb/`](gb/) — United Kingdom | 14 | 🇦🇿 [`az/`](az/) — Azerbaijan | 1 |
  92. | 🇮🇱 [`il/`](il/) — Israel | 12 | 🇧🇦 [`ba/`](ba/) — Bosnia and Herzegovina | 1 |
  93. | 🇮🇳 [`in/`](in/) — India | 11 | 🇨🇲 [`cm/`](cm/) — Cameroon | 1 |
  94. | 🇮🇹 [`it/`](it/) — Italy | 10 | 🇨🇴 [`co/`](co/) — Colombia | 1 |
  95. | 🇳🇿 [`nz/`](nz/) — New Zealand | 10 | 🇩🇰 [`dk/`](dk/) — Denmark | 1 |
  96. | 🇪🇸 [`es/`](es/) — Spain | 9 | 🇩🇴 [`do/`](do/) — Dominican Republic | 1 |
  97. | 🇹🇷 [`tr/`](tr/) — Türkiye | 8 | 🇪🇬 [`eg/`](eg/) — Egypt | 1 |
  98. | 🇺🇦 [`ua/`](ua/) — Ukraine | 7 | 🇭🇰 [`hk/`](hk/) — Hong Kong SAR | 1 |
  99. | 🇨🇦 [`ca/`](ca/) — Canada | 6 | 🇭🇷 [`hr/`](hr/) — Croatia | 1 |
  100. | 🇨🇭 [`ch/`](ch/) — Switzerland | 6 | 🇮🇪 [`ie/`](ie/) — Ireland | 1 |
  101. | 🇰🇷 [`kr/`](kr/) — South Korea | 6 | 🇱🇹 [`lt/`](lt/) — Lithuania | 1 |
  102. | 🇦🇪 [`ae/`](ae/) — UAE | 5 | 🇱🇻 [`lv/`](lv/) — Latvia | 1 |
  103. | 🇩🇿 [`dz/`](dz/) — Algeria | 5 | 🇳🇬 [`ng/`](ng/) — Nigeria | 1 |
  104. | 🇸🇦 [`sa/`](sa/) — Saudi Arabia | 5 | 🇳🇴 [`no/`](no/) — Norway | 1 |
  105. | 🇸🇬 [`sg/`](sg/) — Singapore | 5 | 🇵🇪 [`pe/`](pe/) — Peru | 1 |
  106. | 🇦🇺 [`au/`](au/) — Australia | 4 | 🇷🇴 [`ro/`](ro/) — Romania | 1 |
  107. | 🇯🇵 [`jp/`](jp/) — Japan | 4 | 🇿🇦 [`za/`](za/) — South Africa | 1 |
  108. ---
  109. ## Coverage by practice area
  110. 48 practice areas covered across the 54 jurisdictions. Top areas by plugin count:
  111. | Practice area | Plugins | Typical skills |
  112. |---|---:|---|
  113. | Corporate | 27 | Cap-table analysis, corporate filings, governance |
  114. | Data protection | 27 | GDPR DPA review, ROPA generation, breach notification, transfer-impact assessments |
  115. | General | 27 | Cross-practice skills (legal drafting, citation discipline, statute lookup) |
  116. | Litigation | 23 | Case-law analysis, pleadings drafting, procedural calculators, discovery review |
  117. | Regulatory | 22 | Compliance checks, regulatory filings, AI governance reviews |
  118. | Employment | 18 | Employee-handbook review, termination checks, wage-and-hour |
  119. | Real estate | 18 | Lease review, title checks, zoning analysis |
  120. | Contracts | 17 | Clause review, redlines, template generation |
  121. | Tax | 15 | Tax classification, transfer-pricing review, withholding analysis |
  122. | Intellectual property | 13 | Trademark search, copyright analysis, patent landscaping |
  123. | Commercial | 12 | M&A diligence, commercial-contract review |
  124. | Criminal | 10 | Sentencing analysis, charge-mapping, plea evaluation |
  125. | Family | 10 | Divorce, custody and support, marital property, family-court filings |
  126. | White-collar & investigations | 10 | Internal investigations, AML/KYC and sanctions screening, corporate criminal liability |
  127. | Administrative | 9 | Administrative procedure, permits and appeals, public-service and civil-servant law |
  128. Other covered areas: **arbitration**, **consumer**, **cybersecurity**, **bankruptcy**, **immigration**, **personal-injury**, **trade**, **trusts-and-estates**, **antitrust**, **constitutional**, **insurance**, **social-security**, **construction**, **environmental**, **government-contracts**, **healthcare**, **tmt**, **aviation**, **employee-benefits**, **finance**, **life-sciences**, **sanctions**, **securities**, **sports**, **entertainment**, **investment-funds**, **military**, **transportation**, **capital-markets**, **energy**, **maritime**, **nonprofit**, **gaming**.
  129. ---
  130. ## License
  131. [Apache License 2.0](LICENSE). The repository and every contribution to it are
  132. Apache-2.0 by default. You can use, modify, distribute,
  133. and run these skills commercially — only attribution is required.
  134. ---
  135. ## FAQ
  136. ### Can I use these skills with Claude, Cursor, ChatGPT, or other clients?
  137. Yes. The skills are delivered over the **Model Context Protocol (MCP)**, which
  138. is supported by Claude Code, Claude Desktop, Cursor, ChatGPT (via MCP plugins),
  139. the ThomasMore desktop app, and any other MCP-compatible client. Point your
  140. client at `https://mcp.thomasmoreai.com/` and the orchestrator handles
  141. discovery and routing. Follow [thomasmoreai.com](https://thomasmoreai.com/) for
  142. updates on the MCP server launch.
  143. ### Are these skills production-ready?
  144. The repository is **community-curated**. Every skill carries an explicit
  145. `version`, `author`, and `license`, and is reviewed against the schema
  146. before merge. Output of every skill includes a built-in disclaimer that the
  147. answer is informational and does not replace qualified legal advice. Treat
  148. the library as a **second pair of eyes**, not as a substitute for a lawyer
  149. admitted in the relevant jurisdiction.
  150. ### Why not just write a prompt myself?
  151. Skills are versioned, testable, and citation-disciplined: each `SKILL.md`
  152. specifies which statutes, regulations, or cases it relies on (and which
  153. edition / date). Ad-hoc prompts drift, hallucinate citations, and aren't
  154. reproducible across team members. Skills make legal AI workflows
  155. **auditable** — important for compliance, conflicts checks, and post-mortems.
  156. ### How do I add a skill for my jurisdiction?
  157. If your country code (ISO 3166-1 alpha-2) is missing, just create the folder
  158. — e.g. `pt/contracts/skills/...` — and open a PR. See [CONTRIBUTING.md](CONTRIBUTING.md).
  159. ---
  160. ## Related projects
  161. - [Anthropic Skills](https://www.anthropic.com/news/skills) —
  162. the underlying `SKILL.md` format.
  163. - [Model Context Protocol](https://modelcontextprotocol.io/) — the open
  164. protocol every MCP-compatible client speaks.
  165. - [`anthropics/claude-for-legal`](https://github.com/anthropics/claude-for-legal) —
  166. Anthropic's official suite of legal plugins.
  167. - [`travisvn/awesome-claude-skills`](https://github.com/travisvn/awesome-claude-skills) —
  168. curated list of Claude Skills resources.
  169. - [`Vaquill-AI/awesome-legaltech`](https://github.com/Vaquill-AI/awesome-legaltech) —
  170. open-source legal-tech catalogue.
  171. - [`wong2/awesome-mcp-servers`](https://github.com/wong2/awesome-mcp-servers) —
  172. curated list of MCP servers.
  173. ---
  174. *Maintained by [ThomasMoreAI](https://github.com/ThomasMoreAI). Issues and
  175. pull requests welcome.*
br/data-protection/skills/lgpd-enterprise-auditor-brunolagoa/scripts/install.sh · Bundled script · 881 lines · 1 finding marked
  1. #!/usr/bin/env bash
  2. # LGPD Enterprise Auditor — instalador local, por projeto (macOS, Linux, Git Bash/WSL).
  3. # Compatível com bash 3.2 (padrão do macOS): sem arrays associativos, sem mapfile.
  4. set -euo pipefail
  5. REPO_DEFAULT="BrunoLagoa/lgpd-enterprise-auditor"
  6. SCHEMA_VERSION="1"
  7. FRAMEWORK_REL=".agents/lgpd-enterprise-auditor"
  8. STATE_REL="${FRAMEWORK_REL}/.install"
  9. SKILL_NAME="lgpd-enterprise-auditor"
  10. EXIT_NOT_FOUND=2
  11. SUPPORTED_TARGETS="claude cursor vscode opencode agents"
  12. ACTION="install"
  13. NON_INTERACTIVE=0
  14. TARGET=""
  15. WITH_SKILL=""
  16. VERSION=""
  17. PROJECT_DIR=""
  18. REPO="$REPO_DEFAULT"
  19. SOURCE_ROOT=""
  20. SOURCE_REF=""
  21. SOURCE_VERSION=""
  22. TMP_ROOT=""
  23. SCRIPT_FILE="${BASH_SOURCE[0]:-}"
  24. SCRIPT_DIR=""
  25. if [[ -n "$SCRIPT_FILE" && -f "$SCRIPT_FILE" ]]; then
  26. SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_FILE")" && pwd -P)"
  27. fi
  28. # ---------------------------------------------------------------------------
  29. # Saída e interação
  30. # ---------------------------------------------------------------------------
  31. color() {
  32. if [[ -t 1 ]]; then printf "\033[%sm" "$1"; fi
  33. }
  34. color_reset() {
  35. if [[ -t 1 ]]; then printf "\033[0m"; fi
  36. }
  37. log_info() { printf "%s[INFO]%s %s\n" "$(color 36)" "$(color_reset)" "$*"; }
  38. log_ok() { printf "%s[OK]%s %s\n" "$(color 32)" "$(color_reset)" "$*"; }
  39. log_warn() { printf "%s[WARN]%s %s\n" "$(color 33)" "$(color_reset)" "$*" >&2; }
  40. log_error() { printf "%s[ERROR]%s %s\n" "$(color 31)" "$(color_reset)" "$*" >&2; }
  41. die() {
  42. log_error "$*"
  43. exit 1
  44. }
  45. die_with_code() {
  46. local code="$1"
  47. shift
  48. log_error "$*"
  49. exit "$code"
  50. }
  51. # LGPD_AUDITOR_NO_TTY=1 força a leitura pelo stdin (usado nos testes).
  52. tty_available() {
  53. [[ "${LGPD_AUDITOR_NO_TTY:-0}" != "1" ]] && { : < /dev/tty; } 2>/dev/null
  54. }
  55. # Perguntas vão para o terminal (ou stderr) para não poluir capturas $(...).
  56. prompt_out() {
  57. if tty_available; then
  58. printf "%s" "$*" > /dev/tty
  59. else
  60. printf "%s" "$*" >&2
  61. fi
  62. }
  63. read_answer() {
  64. local __var="$1"
  65. local __reply=""
  66. if tty_available; then
  67. IFS= read -r __reply < /dev/tty || die "Entrada interativa indisponível. Use --non-interactive."
  68. else
  69. IFS= read -r __reply || die "Entrada interativa indisponível. Use --non-interactive."
  70. fi
  71. printf -v "$__var" "%s" "$__reply"
  72. }
  73. confirm() {
  74. local question="$1"
  75. local default_choice="${2:-y}"
  76. local suffix="[y/N]"
  77. local answer=""
  78. if [[ "$default_choice" == "y" ]]; then suffix="[Y/n]"; fi
  79. prompt_out "${question} ${suffix}: "
  80. read_answer answer
  81. answer="$(printf "%s" "${answer:-$default_choice}" | tr '[:upper:]' '[:lower:]')"
  82. [[ "$answer" == "y" || "$answer" == "yes" || "$answer" == "s" || "$answer" == "sim" ]]
  83. }
  84. # Imprime as opções e devolve (stdout) o número escolhido.
  85. choose_index() {
  86. local question="$1"
  87. shift
  88. local idx=1
  89. local answer=""
  90. local option
  91. prompt_out "${question}"$'\n'
  92. for option in "$@"; do
  93. prompt_out " ${idx}) ${option}"$'\n'
  94. idx=$((idx + 1))
  95. done
  96. while true; do
  97. prompt_out "Selecione uma opção [1-$#]: "
  98. read_answer answer
  99. if [[ "$answer" =~ ^[0-9]+$ ]] && (( answer >= 1 && answer <= $# )); then
  100. printf "%s" "$answer"
  101. return 0
  102. fi
  103. log_warn "Opção inválida. Tente novamente."
  104. done
  105. }
  106. print_banner() {
  107. cat <<'EOF'
  108. _ ____ ____ ____
  109. | | / ___| _ \| _ \
  110. | | | | _| |_) | | | |
  111. | |__| |_| | __/| |_| |
  112. |_____\____|_| |____/
  113. EOF
  114. printf "\nLGPD Enterprise Auditor %s\n\n" "$1"
  115. printf "Framework de auditoria de conformidade LGPD orientado a evidências, para usar com o seu\n"
  116. printf "assistente de IA (Claude Code, Cursor, VS Code + Copilot, OpenCode, Codex, Gemini CLI).\n"
  117. printf "A instalação é local: tudo fica dentro do projeto auditado.\n\n"
  118. }
  119. usage() {
  120. cat <<'EOF'
  121. LGPD Enterprise Auditor — instalador
  122. Uso:
  123. install.sh [install|update|uninstall|check] [opções]
  124. Ações:
  125. install Instala o framework e os comandos da ferramenta escolhida (padrão)
  126. update Reinstala as ferramentas já instaladas na versão escolhida
  127. uninstall Remove a instalação de uma ferramenta (ou de todas)
  128. check Verifica a instalação do projeto
  129. Opções:
  130. --target <claude|cursor|vscode|opencode|agents> Ferramenta (obrigatória com --non-interactive no install)
  131. --with-skill Instala também a skill
  132. --no-skill Não instala a skill (padrão)
  133. --project-dir <dir> Projeto de destino (padrão: raiz git do diretório atual)
  134. --version <ref|local> Tag, branch ou "local" (padrão: última tag publicada)
  135. --repo <owner/repo> Repositório GitHub (padrão: BrunoLagoa/lgpd-enterprise-auditor)
  136. --non-interactive Executa sem perguntas
  137. -h, --help Exibe esta ajuda
  138. Exemplos:
  139. curl -fsSL https://github.com/BrunoLagoa/lgpd-enterprise-auditor/releases/latest/download/install.sh | bash -s -- install
    • Note: Pipes a downloaded script directly into a shell (curl | sh / wget | bash)
    • Line 161 on GitHub
  140. ./scripts/install.sh install --target cursor --with-skill --project-dir ../meu-app
  141. ./scripts/install.sh update --non-interactive
  142. ./scripts/install.sh uninstall --target claude --non-interactive
  143. EOF
  144. }
  145. # ---------------------------------------------------------------------------
  146. # Argumentos e ambiente
  147. # ---------------------------------------------------------------------------
  148. require_value() {
  149. [[ $# -ge 2 && -n "$2" && "${2#--}" == "$2" ]] || die "A opção $1 exige um valor."
  150. }
  151. parse_args() {
  152. if [[ $# -gt 0 && "${1#-}" == "$1" ]]; then
  153. ACTION="$1"
  154. shift
  155. fi
  156. while [[ $# -gt 0 ]]; do
  157. case "$1" in
  158. --target) require_value "$@"; TARGET="$2"; shift 2 ;;
  159. --with-skill) WITH_SKILL=1; shift ;;
  160. --no-skill) WITH_SKILL=0; shift ;;
  161. --project-dir) require_value "$@"; PROJECT_DIR="$2"; shift 2 ;;
  162. --version) require_value "$@"; VERSION="$2"; shift 2 ;;
  163. --repo) require_value "$@"; REPO="$2"; shift 2 ;;
  164. --non-interactive) NON_INTERACTIVE=1; shift ;;
  165. -h|--help) usage; exit 0 ;;
  166. *) die "Argumento desconhecido: $1 (use --help)" ;;
  167. esac
  168. done
  169. case "$ACTION" in
  170. install|update|uninstall|check) ;;
  171. *) die "Ação inválida: $ACTION (use install, update, uninstall ou check)" ;;
  172. esac
  173. if [[ -n "$TARGET" ]] && ! is_supported_target "$TARGET"; then
  174. die "Ferramenta não suportada: $TARGET (use: ${SUPPORTED_TARGETS// /, })"
  175. fi
  176. [[ "$REPO" =~ ^[A-Za-z0-9._-]+/[A-Za-z0-9._-]+$ ]] || die "Repositório inválido: $REPO (use owner/repo)"
  177. }
  178. is_supported_target() {
  179. case "$1" in
  180. claude|cursor|vscode|opencode|agents) return 0 ;;
  181. *) return 1 ;;
  182. esac
  183. }
  184. detect_os() {
  185. case "$(uname -s | tr '[:upper:]' '[:lower:]')" in
  186. darwin*) printf "macos" ;;
  187. msys*|mingw*|cygwin*) printf "windows" ;;
  188. *) printf "linux" ;;
  189. esac
  190. }
  191. iso_timestamp() {
  192. date -u +"%Y-%m-%dT%H:%M:%SZ"
  193. }
  194. ensure_command() {
  195. command -v "$1" >/dev/null 2>&1 || die "Pré-requisito ausente: $1"
  196. }
  197. resolve_project_dir() {
  198. if [[ -n "$PROJECT_DIR" ]]; then
  199. [[ -d "$PROJECT_DIR" ]] || die "Diretório do projeto não encontrado: $PROJECT_DIR"
  200. PROJECT_DIR="$(cd "$PROJECT_DIR" && pwd -P)"
  201. else
  202. local current
  203. current="$(pwd -P)"
  204. PROJECT_DIR="$current"
  205. while [[ "$current" != "/" ]]; do
  206. if [[ -e "${current}/.git" ]]; then
  207. PROJECT_DIR="$current"
  208. break
  209. fi
  210. current="$(dirname "$current")"
  211. done
  212. fi
  213. if [[ "$PROJECT_DIR" == "/" || "$PROJECT_DIR" == "$(cd "$HOME" && pwd -P)" ]]; then
  214. die "Recusado instalar em ${PROJECT_DIR}. Rode na raiz do projeto ou use --project-dir."
  215. fi
  216. }
  217. # ---------------------------------------------------------------------------
  218. # Ferramentas (targets)
  219. # ---------------------------------------------------------------------------
  220. target_label() {
  221. case "$1" in
  222. claude) printf "claude (Claude Code)" ;;
  223. cursor) printf "cursor (Cursor)" ;;
  224. vscode) printf "vscode (VS Code + GitHub Copilot)" ;;
  225. opencode) printf "opencode (OpenCode)" ;;
  226. agents) printf "agents (outra ferramenta: Codex, Gemini CLI e similares)" ;;
  227. esac
  228. }
  229. target_commands_dir() {
  230. case "$1" in
  231. claude) printf ".claude/commands" ;;
  232. cursor) printf ".cursor/commands" ;;
  233. vscode) printf ".github/prompts" ;;
  234. opencode) printf ".opencode/commands" ;;
  235. agents) printf "" ;;
  236. esac
  237. }
  238. target_command_file() {
  239. local target="$1"
  240. local stem="$2"
  241. if [[ "$target" == "vscode" ]]; then
  242. printf "%s.prompt.md" "$stem"
  243. else
  244. printf "%s.md" "$stem"
  245. fi
  246. }
  247. target_skill_dir() {
  248. if [[ "$1" == "claude" ]]; then
  249. printf ".claude/skills/%s" "$SKILL_NAME"
  250. else
  251. printf ".agents/skills/%s" "$SKILL_NAME"
  252. fi
  253. }
  254. print_next_steps() {
  255. local target="$1"
  256. local skill="$2"
  257. printf "\nPróximos passos\n"
  258. case "$target" in
  259. claude) printf " Abra o Claude Code na raiz do projeto (claude) e rode /lgpd-saas, /lgpd-full-audit etc.\n" ;;
  260. cursor) printf " No chat do Cursor, digite /lgpd-saas, /lgpd-full-audit etc.\n" ;;
  261. vscode) printf " No Copilot Chat do VS Code, digite /lgpd-saas, /lgpd-full-audit etc.\n" ;;
  262. opencode) printf " Rode opencode na raiz do projeto e use /lgpd-saas, /lgpd-full-audit etc.\n" ;;
  263. agents) printf " Peça ao seu agente: \"faça uma auditoria LGPD deste projeto\" — ele carrega a skill %s.\n" "$SKILL_NAME" ;;
  264. esac
  265. if [[ "$skill" == "1" && "$target" != "agents" ]]; then
  266. printf " Com a skill instalada, você também pode pedir a auditoria em linguagem natural.\n"
  267. fi
  268. printf " Coloque política de privacidade, RIPD, contratos (DPA) e nomeação do DPO dentro do projeto\n"
  269. printf " (ex.: docs/lgpd/) para que contem como evidência documental.\n"
  270. }
  271. # Claude e OpenCode leem o frontmatter como está.
  272. # Cursor: remove o frontmatter e promove a description para a primeira linha.
  273. # VS Code: mantém só os campos aceitos em .prompt.md (name, description) e roda em modo agent.
  274. render_command() {
  275. local target="$1"
  276. local src="$2"
  277. local dest="$3"
  278. case "$target" in
  279. cursor)
  280. awk '
  281. NR == 1 && $0 == "---" { in_fm = 1; next }
  282. in_fm && $0 == "---" { in_fm = 0; if (desc != "") { print "> " desc; print "" }; skip_blank = 1; next }
  283. in_fm { if ($0 ~ /^description:/) { desc = $0; sub(/^description:[[:space:]]*/, "", desc); gsub(/^["\047]|["\047]$/, "", desc) }; next }
  284. skip_blank && $0 ~ /^[[:space:]]*$/ { next }
  285. { skip_blank = 0; print }
  286. ' "$src" > "$dest"
  287. ;;
  288. vscode)
  289. awk '
  290. NR == 1 && $0 == "---" { in_fm = 1; next }
  291. in_fm && $0 == "---" { in_fm = 0; print "---"; if (name != "") print name; if (desc != "") print desc; print "agent: agent"; print "---"; next }
  292. in_fm { if ($0 ~ /^name:/) name = $0; if ($0 ~ /^description:/) desc = $0; next }
  293. { print }
  294. ' "$src" > "$dest"
  295. ;;
  296. *)
  297. cp "$src" "$dest"
  298. ;;
  299. esac
  300. }
  301. # ---------------------------------------------------------------------------
  302. # Origem dos arquivos (local ou GitHub)
  303. # ---------------------------------------------------------------------------
  304. cleanup() {
  305. if [[ -n "$TMP_ROOT" && -d "$TMP_ROOT" ]]; then
  306. rm -rf "$TMP_ROOT"
  307. fi
  308. }
  309. local_source_root() {
  310. if [[ -z "$SCRIPT_DIR" ]]; then
  311. return 1
  312. fi
  313. local root
  314. root="$(cd "$SCRIPT_DIR/.." && pwd -P)"
  315. if [[ -d "${root}/${FRAMEWORK_REL}" && -f "${root}/SKILL.md" && -d "${root}/commands" ]]; then
  316. printf "%s" "$root"
  317. return 0
  318. fi
  319. return 1
  320. }
  321. skill_version() {
  322. sed -n 's/^[[:space:]]*version:[[:space:]]*"\{0,1\}\([^"]*\)"\{0,1\}[[:space:]]*$/\1/p' "$1" | head -n 1
  323. }
  324. # Imprime a última tag publicada. Retorno: 0 com a tag; 1 se o repositório não tem tag v*;
  325. # 2 se a consulta falhou (sem rede, limite da API do GitHub ou modo offline).
  326. fetch_latest_tag() {
  327. local response
  328. [[ "${LGPD_AUDITOR_OFFLINE:-0}" != "1" ]] || return 2
  329. command -v curl >/dev/null 2>&1 || return 2
  330. response="$(curl -fsSL --max-time 10 "https://api.github.com/repos/${REPO}/tags?per_page=100" 2>/dev/null)" || return 2
  331. printf "%s" "$response" \
  332. | grep -o '"name": *"v[0-9][^"]*"' \
  333. | sed 's/.*"\(v[^"]*\)"/\1/' \
  334. | sort -V \
  335. | tail -n 1
  336. }
  337. # Define SOURCE_REF antes de baixar (para exibir no banner e no resumo).
  338. resolve_ref() {
  339. if [[ -z "$VERSION" ]]; then
  340. if local_source_root >/dev/null; then
  341. VERSION="local"
  342. else
  343. local tag_status=0
  344. VERSION="$(fetch_latest_tag)" || tag_status=$?
  345. if [[ -z "$VERSION" ]]; then
  346. if [[ "$tag_status" -eq 2 ]]; then
  347. # Falha de consulta não é "sem versão publicada": a branch main pode ter mudanças não lançadas.
  348. log_warn "Não foi possível consultar a última versão publicada (sem rede ou limite da API do GitHub)."
  349. if [[ "$NON_INTERACTIVE" -eq 1 ]]; then
  350. die "Informe a versão com --version (ex.: --version vX.Y.Z) ou tente de novo mais tarde."
  351. fi
  352. confirm "Instalar a partir da branch main, que pode conter mudanças ainda não publicadas?" "n" \
  353. || die "Instalação cancelada. Informe a versão com --version (ex.: --version vX.Y.Z)."
  354. else
  355. log_warn "Nenhuma tag publicada encontrada; usando a branch main."
  356. fi
  357. VERSION="main"
  358. fi
  359. fi
  360. fi
  361. SOURCE_REF="$VERSION"
  362. if [[ "$SOURCE_REF" == "local" ]]; then
  363. SOURCE_ROOT="$(local_source_root)" || die "--version local exige rodar o script a partir de um clone do repositório."
  364. SOURCE_VERSION="$(skill_version "${SOURCE_ROOT}/SKILL.md")"
  365. fi
  366. }
  367. ref_label() {
  368. if [[ "$SOURCE_REF" == "local" ]]; then
  369. printf "v%s (cópia local em %s)" "$SOURCE_VERSION" "$SOURCE_ROOT"
  370. else
  371. printf "%s" "$SOURCE_REF"
  372. fi
  373. }
  374. fetch_source() {
  375. if [[ -n "$SOURCE_ROOT" ]]; then
  376. return 0
  377. fi
  378. ensure_command curl
  379. ensure_command tar
  380. local archive="${TMP_ROOT}/source.tar.gz"
  381. local url="https://codeload.github.com/${REPO}/tar.gz/${SOURCE_REF}"
  382. log_info "Baixando ${REPO}@${SOURCE_REF}..."
  383. curl -fsSL "$url" -o "$archive" || die "Falha ao baixar ${url}. Verifique a versão (--version) e a conexão."
  384. mkdir -p "${TMP_ROOT}/source"
  385. tar -xzf "$archive" -C "${TMP_ROOT}/source"
  386. local extracted
  387. extracted="$(find "${TMP_ROOT}/source" -mindepth 1 -maxdepth 1 -type d | head -n 1)"
  388. [[ -n "$extracted" && -d "${extracted}/${FRAMEWORK_REL}" && -f "${extracted}/SKILL.md" && -d "${extracted}/commands" ]] \
  389. || die "Conteúdo baixado inválido para ${SOURCE_REF}."
  390. SOURCE_ROOT="$extracted"
  391. SOURCE_VERSION="$(skill_version "${SOURCE_ROOT}/SKILL.md")"
  392. }
  393. guard_not_source_repo() {
  394. if [[ -n "$SOURCE_ROOT" && "$SOURCE_ROOT" == "$PROJECT_DIR" ]]; then
  395. die "O destino é o próprio repositório do framework. Use --project-dir para apontar o projeto a ser auditado."
  396. fi
  397. }
  398. # ---------------------------------------------------------------------------
  399. # Manifestos (um por ferramenta, em .agents/lgpd-enterprise-auditor/.install/)
  400. # ---------------------------------------------------------------------------
  401. manifest_path() {
  402. printf "%s/%s/%s.json" "$PROJECT_DIR" "$STATE_REL" "$1"
  403. }
  404. json_value() {
  405. sed -n "s/^[[:space:]]*\"$2\":[[:space:]]*\"\{0,1\}\([^\",]*\)\"\{0,1\},\{0,1\}[[:space:]]*$/\1/p" "$1" | head -n 1
  406. }
  407. manifest_files() {
  408. awk '
  409. /"files":[[:space:]]*\[/ { if ($0 !~ /\]/) in_files = 1; next }
  410. in_files && /\]/ { in_files = 0; next }
  411. in_files { gsub(/^[[:space:]]*"|",?[[:space:]]*$/, ""); if ($0 != "") print }
  412. ' "$1"
  413. }
  414. installed_targets() {
  415. local target
  416. for target in $SUPPORTED_TARGETS; do
  417. if [[ -f "$(manifest_path "$target")" ]]; then
  418. printf "%s\n" "$target"
  419. fi
  420. done
  421. }
  422. write_manifest() {
  423. local target="$1"
  424. local skill="$2"
  425. local files="$3"
  426. local skill_dir="$4"
  427. local manifest
  428. manifest="$(manifest_path "$target")"
  429. mkdir -p "$(dirname "$manifest")"
  430. local skill_json="false"
  431. if [[ "$skill" == "1" ]]; then skill_json="true"; fi
  432. {
  433. printf "{\n"
  434. printf " \"schemaVersion\": \"%s\",\n" "$SCHEMA_VERSION"
  435. printf " \"project\": \"lgpd-enterprise-auditor\",\n"
  436. printf " \"version\": \"%s\",\n" "$SOURCE_VERSION"
  437. printf " \"ref\": \"%s\",\n" "$SOURCE_REF"
  438. printf " \"repo\": \"%s\",\n" "$REPO"
  439. printf " \"target\": \"%s\",\n" "$target"
  440. printf " \"withSkill\": %s,\n" "$skill_json"
  441. printf " \"os\": \"%s\",\n" "$(detect_os)"
  442. printf " \"frameworkDir\": \"%s\",\n" "$FRAMEWORK_REL"
  443. printf " \"commandsDir\": \"%s\",\n" "$(target_commands_dir "$target")"
  444. printf " \"skillDir\": \"%s\",\n" "$skill_dir"
  445. printf " \"installedAt\": \"%s\",\n" "$(iso_timestamp)"
  446. printf " \"files\": ["
  447. local first=1
  448. local file
  449. while IFS= read -r file; do
  450. [[ -n "$file" ]] || continue
  451. if [[ "$first" -eq 1 ]]; then printf "\n"; first=0; else printf ",\n"; fi
  452. printf " \"%s\"" "$file"
  453. done <<< "$files"
  454. if [[ "$first" -eq 0 ]]; then printf "\n "; fi
  455. printf "]\n"
  456. printf "}\n"
  457. } > "$manifest"
  458. }
  459. # ---------------------------------------------------------------------------
  460. # Instalação e remoção
  461. # ---------------------------------------------------------------------------
  462. safe_rel_path() {
  463. [[ -n "$1" && "${1:0:1}" != "/" && "$1" != *".."* ]]
  464. }
  465. # Outra ferramenta (diferente de $1) usa a mesma pasta de skill?
  466. skill_dir_shared() {
  467. local target="$1"
  468. local skill_dir="$2"
  469. local other manifest
  470. for other in $(installed_targets); do
  471. [[ "$other" != "$target" ]] || continue
  472. manifest="$(manifest_path "$other")"
  473. if [[ "$(json_value "$manifest" withSkill)" == "true" && "$(json_value "$manifest" skillDir)" == "$skill_dir" ]]; then
  474. return 0
  475. fi
  476. done
  477. return 1
  478. }
  479. prune_empty_dirs() {
  480. local dir
  481. for dir in .claude/commands .claude/skills .claude .cursor/commands .cursor .github/prompts .github \
  482. .opencode/commands .opencode .agents/skills .agents; do
  483. rmdir "${PROJECT_DIR}/${dir}" 2>/dev/null || true
  484. done
  485. }
  486. remove_target_files() {
  487. local target="$1"
  488. local manifest
  489. manifest="$(manifest_path "$target")"
  490. [[ -f "$manifest" ]] || return 0
  491. local file
  492. while IFS= read -r file; do
  493. safe_rel_path "$file" || continue
  494. rm -f "${PROJECT_DIR}/${file}"
  495. done < <(manifest_files "$manifest")
  496. local skill_dir
  497. skill_dir="$(json_value "$manifest" skillDir)"
  498. if [[ "$(json_value "$manifest" withSkill)" == "true" ]] && safe_rel_path "$skill_dir" \
  499. && [[ "$skill_dir" == *"/${SKILL_NAME}" ]] && ! skill_dir_shared "$target" "$skill_dir"; then
  500. rm -rf "${PROJECT_DIR:?}/${skill_dir}"
  501. fi
  502. }
  503. backup_existing() {
  504. local target="$1"
  505. local backup_dir
  506. backup_dir="${PROJECT_DIR}/.lgpd-auditor-backup/$(date +%Y%m%d%H%M%S)"
  507. mkdir -p "$backup_dir"
  508. if [[ -d "${PROJECT_DIR}/${FRAMEWORK_REL}" ]]; then
  509. mkdir -p "${backup_dir}/$(dirname "$FRAMEWORK_REL")"
  510. cp -R "${PROJECT_DIR}/${FRAMEWORK_REL}" "${backup_dir}/${FRAMEWORK_REL}"
  511. fi
  512. local manifest file skill_dir
  513. manifest="$(manifest_path "$target")"
  514. if [[ -f "$manifest" ]]; then
  515. while IFS= read -r file; do
  516. safe_rel_path "$file" || continue
  517. if [[ -f "${PROJECT_DIR}/${file}" ]]; then
  518. mkdir -p "${backup_dir}/$(dirname "$file")"
  519. cp "${PROJECT_DIR}/${file}" "${backup_dir}/${file}"
  520. fi
  521. done < <(manifest_files "$manifest")
  522. skill_dir="$(json_value "$manifest" skillDir)"
  523. if safe_rel_path "$skill_dir" && [[ -d "${PROJECT_DIR}/${skill_dir}" ]]; then
  524. mkdir -p "${backup_dir}/$(dirname "$skill_dir")"
  525. cp -R "${PROJECT_DIR}/${skill_dir}" "${backup_dir}/${skill_dir}"
  526. fi
  527. fi
  528. log_info "Backup criado em ${backup_dir}"
  529. log_info "Dica: adicione .lgpd-auditor-backup/ ao .gitignore do projeto."
  530. }
  531. install_framework() {
  532. local framework_dir="${PROJECT_DIR}/${FRAMEWORK_REL}"
  533. local saved_state="${TMP_ROOT}/install-state"
  534. if [[ -d "${framework_dir}/.install" ]]; then
  535. rm -rf "$saved_state"
  536. mv "${framework_dir}/.install" "$saved_state"
  537. fi
  538. rm -rf "$framework_dir"
  539. mkdir -p "$(dirname "$framework_dir")"
  540. cp -R "${SOURCE_ROOT}/${FRAMEWORK_REL}" "$framework_dir"
  541. rm -rf "${framework_dir}/.install"
  542. find "$framework_dir" -name .DS_Store -type f -delete 2>/dev/null || true
  543. if [[ -d "$saved_state" ]]; then
  544. mv "$saved_state" "${framework_dir}/.install"
  545. fi
  546. }
  547. install_target() {
  548. local target="$1"
  549. local skill="$2"
  550. remove_target_files "$target"
  551. install_framework
  552. local files=""
  553. local commands_dir
  554. commands_dir="$(target_commands_dir "$target")"
  555. if [[ -n "$commands_dir" ]]; then
  556. mkdir -p "${PROJECT_DIR}/${commands_dir}"
  557. local src stem rel
  558. for src in "${SOURCE_ROOT}"/commands/*.md; do
  559. [[ -f "$src" ]] || continue
  560. stem="$(basename "$src" .md)"
  561. rel="${commands_dir}/$(target_command_file "$target" "$stem")"
  562. render_command "$target" "$src" "${PROJECT_DIR}/${rel}"
  563. files="${files}${rel}"$'\n'
  564. done
  565. [[ -n "$files" ]] || die "Nenhum comando encontrado em ${SOURCE_ROOT}/commands."
  566. fi
  567. local skill_dir=""
  568. if [[ "$skill" == "1" ]]; then
  569. skill_dir="$(target_skill_dir "$target")"
  570. mkdir -p "${PROJECT_DIR}/${skill_dir}"
  571. cp "${SOURCE_ROOT}/SKILL.md" "${PROJECT_DIR}/${skill_dir}/SKILL.md"
  572. fi
  573. write_manifest "$target" "$skill" "$files" "$skill_dir"
  574. prune_empty_dirs
  575. log_ok "$(target_label "$target") instalado (v${SOURCE_VERSION})."
  576. }
  577. warn_version_drift() {
  578. local target other installed_version
  579. target="$1"
  580. for other in $(installed_targets); do
  581. [[ "$other" != "$target" ]] || continue
  582. installed_version="$(json_value "$(manifest_path "$other")" version)"
  583. if [[ "$installed_version" != "$SOURCE_VERSION" ]]; then
  584. log_warn "Os comandos de ${other} estão na v${installed_version}, mas o framework agora está na v${SOURCE_VERSION}. Rode a ação update para alinhar."
  585. fi
  586. done
  587. }
  588. # ---------------------------------------------------------------------------
  589. # Ações
  590. # ---------------------------------------------------------------------------
  591. run_install() {
  592. resolve_ref
  593. guard_not_source_repo
  594. if [[ "$NON_INTERACTIVE" -eq 0 ]]; then
  595. print_banner "$(ref_label)"
  596. log_info "Sistema operacional: $(detect_os)"
  597. log_info "Projeto: ${PROJECT_DIR}"
  598. printf "\n"
  599. fi
  600. if [[ -z "$TARGET" ]]; then
  601. [[ "$NON_INTERACTIVE" -eq 0 ]] || die "Informe --target no modo --non-interactive."
  602. local choice
  603. choice="$(choose_index "1 - Selecione a ferramenta" \
  604. "$(target_label claude)" "$(target_label cursor)" "$(target_label vscode)" \
  605. "$(target_label opencode)" "$(target_label agents)")"
  606. TARGET="$(printf "%s" "$SUPPORTED_TARGETS" | cut -d' ' -f"$choice")"
  607. else
  608. [[ "$NON_INTERACTIVE" -eq 1 ]] || printf "1 - Ferramenta\n > %s\n" "$(target_label "$TARGET")"
  609. fi
  610. if [[ "$TARGET" == "agents" ]]; then
  611. [[ "$WITH_SKILL" != "0" ]] || die "A opção agents não tem slash commands: a skill é obrigatória (remova --no-skill)."
  612. WITH_SKILL=1
  613. [[ "$NON_INTERACTIVE" -eq 1 ]] || printf "2 - Skill\n > sim (obrigatória para agents: é a forma de acionar a auditoria)\n"
  614. elif [[ -z "$WITH_SKILL" ]]; then
  615. WITH_SKILL=0
  616. if [[ "$NON_INTERACTIVE" -eq 0 ]]; then
  617. prompt_out "2 - Instalar também a skill?"$'\n'
  618. prompt_out " Permite acionar a auditoria em linguagem natural, sem slash command."$'\n'
  619. if confirm " Instalar a skill?" "n"; then WITH_SKILL=1; fi
  620. fi
  621. fi
  622. local commands_dir skill_label
  623. commands_dir="$(target_commands_dir "$TARGET")"
  624. skill_label="não"
  625. if [[ "$WITH_SKILL" == "1" ]]; then skill_label="sim → ${PROJECT_DIR}/$(target_skill_dir "$TARGET")"; fi
  626. printf "\nResumo da instalação\n"
  627. printf " Ferramenta: %s\n" "$(target_label "$TARGET")"
  628. printf " Versão: %s\n" "$(ref_label)"
  629. printf " Framework: %s/%s\n" "$PROJECT_DIR" "$FRAMEWORK_REL"
  630. if [[ -n "$commands_dir" ]]; then
  631. printf " Comandos: %s/%s\n" "$PROJECT_DIR" "$commands_dir"
  632. fi
  633. printf " Skill: %s\n" "$skill_label"
  634. if [[ -f "$(manifest_path "$TARGET")" ]]; then
  635. printf " Atenção: já existe uma instalação para %s (v%s); ela será substituída.\n" \
  636. "$TARGET" "$(json_value "$(manifest_path "$TARGET")" version)"
  637. fi
  638. printf "\n"
  639. if [[ "$NON_INTERACTIVE" -eq 0 ]]; then
  640. confirm "Confirmar instalação?" "y" || { log_warn "Instalação cancelada."; exit 0; }
  641. if [[ -d "${PROJECT_DIR}/${FRAMEWORK_REL}" ]] && confirm "Instalação existente detectada. Criar backup antes de substituir?" "y"; then
  642. backup_existing "$TARGET"
  643. fi
  644. fi
  645. fetch_source
  646. guard_not_source_repo
  647. install_target "$TARGET" "$WITH_SKILL"
  648. warn_version_drift "$TARGET"
  649. print_next_steps "$TARGET" "$WITH_SKILL"
  650. }
  651. run_update() {
  652. local targets
  653. if [[ -n "$TARGET" ]]; then
  654. [[ -f "$(manifest_path "$TARGET")" ]] || die_with_code "$EXIT_NOT_FOUND" "Nenhuma instalação de ${TARGET} encontrada em ${PROJECT_DIR}."
  655. targets="$TARGET"
  656. else
  657. targets="$(installed_targets)"
  658. [[ -n "$targets" ]] || die_with_code "$EXIT_NOT_FOUND" "Nenhuma instalação encontrada em ${PROJECT_DIR}. Use a ação install."
  659. fi
  660. resolve_ref
  661. guard_not_source_repo
  662. printf "\nResumo da atualização\n"
  663. printf " Projeto: %s\n" "$PROJECT_DIR"
  664. printf " Versão: %s\n" "$(ref_label)"
  665. local target
  666. for target in $targets; do
  667. printf " - %s (atual: v%s)\n" "$(target_label "$target")" "$(json_value "$(manifest_path "$target")" version)"
  668. done
  669. printf "\n"
  670. if [[ "$NON_INTERACTIVE" -eq 0 ]]; then
  671. confirm "Confirmar atualização?" "y" || { log_warn "Atualização cancelada."; exit 0; }
  672. fi
  673. fetch_source
  674. guard_not_source_repo
  675. local skill
  676. for target in $targets; do
  677. skill=0
  678. if [[ "$(json_value "$(manifest_path "$target")" withSkill)" == "true" ]]; then skill=1; fi
  679. if [[ -n "$WITH_SKILL" && -n "$TARGET" && "$target" != "agents" ]]; then skill="$WITH_SKILL"; fi
  680. install_target "$target" "$skill"
  681. done
  682. }
  683. run_uninstall() {
  684. local installed
  685. installed="$(installed_targets)"
  686. [[ -n "$installed" ]] || die_with_code "$EXIT_NOT_FOUND" "Nenhuma instalação encontrada em ${PROJECT_DIR}."
  687. local targets=""
  688. if [[ -n "$TARGET" ]]; then
  689. [[ -f "$(manifest_path "$TARGET")" ]] || die_with_code "$EXIT_NOT_FOUND" "Nenhuma instalação de ${TARGET} encontrada em ${PROJECT_DIR}."
  690. targets="$TARGET"
  691. elif [[ "$NON_INTERACTIVE" -eq 1 || "$(printf "%s\n" "$installed" | wc -l | tr -d ' ')" -eq 1 ]]; then
  692. targets="$installed"
  693. else
  694. local options="" target choice count
  695. for target in $installed; do options="${options}${target} "; done
  696. # shellcheck disable=SC2086
  697. choice="$(choose_index "Qual instalação remover?" $options "todas")"
  698. count="$(printf "%s\n" "$installed" | wc -l | tr -d ' ')"
  699. if [[ "$choice" -gt "$count" ]]; then
  700. targets="$installed"
  701. else
  702. targets="$(printf "%s\n" "$installed" | sed -n "${choice}p")"
  703. fi
  704. fi
  705. printf "\nResumo da remoção\n"
  706. printf " Projeto: %s\n" "$PROJECT_DIR"
  707. local target
  708. for target in $targets; do
  709. printf " - %s\n" "$(target_label "$target")"
  710. done
  711. printf "\n"
  712. if [[ "$NON_INTERACTIVE" -eq 0 ]]; then
  713. confirm "Confirmar remoção?" "n" || { log_warn "Remoção cancelada."; exit 0; }
  714. fi
  715. for target in $targets; do
  716. remove_target_files "$target"
  717. rm -f "$(manifest_path "$target")"
  718. log_ok "$(target_label "$target") removido."
  719. done
  720. if [[ -z "$(installed_targets)" ]]; then
  721. rm -rf "${PROJECT_DIR:?}/${FRAMEWORK_REL}"
  722. log_ok "Framework removido de ${PROJECT_DIR}/${FRAMEWORK_REL}."
  723. fi
  724. prune_empty_dirs
  725. }
  726. run_check() {
  727. local installed
  728. installed="$(installed_targets)"
  729. [[ -n "$installed" ]] || die_with_code "$EXIT_NOT_FOUND" "Nenhuma instalação encontrada em ${PROJECT_DIR}."
  730. local broken=0
  731. if [[ ! -f "${PROJECT_DIR}/${FRAMEWORK_REL}/core/auditor-core.md" ]]; then
  732. log_error "Framework incompleto em ${PROJECT_DIR}/${FRAMEWORK_REL}."
  733. broken=1
  734. fi
  735. local target manifest file missing skill_dir version newest=""
  736. for target in $installed; do
  737. manifest="$(manifest_path "$target")"
  738. version="$(json_value "$manifest" version)"
  739. missing=0
  740. while IFS= read -r file; do
  741. [[ -f "${PROJECT_DIR}/${file}" ]] || { log_error "${target}: arquivo ausente ${file}"; missing=1; }
  742. done < <(manifest_files "$manifest")
  743. skill_dir="$(json_value "$manifest" skillDir)"
  744. if [[ "$(json_value "$manifest" withSkill)" == "true" && ! -f "${PROJECT_DIR}/${skill_dir}/SKILL.md" ]]; then
  745. log_error "${target}: skill ausente em ${skill_dir}"
  746. missing=1
  747. fi
  748. if [[ "$missing" -eq 0 ]]; then
  749. log_ok "$(target_label "$target") — v${version}, skill: $(json_value "$manifest" withSkill), instalado em $(json_value "$manifest" installedAt)"
  750. else
  751. broken=1
  752. fi
  753. done
  754. newest="$(fetch_latest_tag || true)"
  755. if [[ -n "$newest" && "v${version}" != "$newest" ]]; then
  756. log_info "Versão publicada mais recente: ${newest}. Rode a ação update para atualizar."
  757. fi
  758. if [[ "$broken" -eq 1 ]]; then
  759. log_error "Instalação com problemas. Rode a ação install novamente para corrigir."
  760. exit 1
  761. fi
  762. }
  763. main() {
  764. parse_args "$@"
  765. resolve_project_dir
  766. TMP_ROOT="$(mktemp -d)"
  767. trap cleanup EXIT
  768. case "$ACTION" in
  769. install) run_install ;;
  770. update) run_update ;;
  771. uninstall) run_uninstall ;;
  772. check) run_check ;;
  773. esac
  774. }
  775. main "$@"

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.