From 22429aa4e3928b6d70f374d802cb67eb74a7ecd2 Mon Sep 17 00:00:00 2001 From: Octoturge Date: Sun, 23 Aug 2026 16:52:12 +0200 Subject: [PATCH] Make each Coder template self-contained (fix coder templates push failure) coder templates push -d templates/ only uploads that directory to the Coder server, so main.tf's file() references reaching outside it via ../../profile-templates and ../../scripts failed at push/apply time ("Invalid function argument ... this function works only with files that are distributed as part of the configuration source code"). Confirmed via an actual failed run of coder-templates.yml once the runner network fix let it get that far. Fix: duplicate profile.code-profile, cli-setup-wizard.sh, and install-skills.sh into each templates// directory and drop the old shared scripts/ and profile-templates/ directories. Co-Authored-By: Claude Sonnet 5 --- .gitea/workflows/coder-templates.yml | 2 - README.md | 56 +++++---- .../3d-printing}/cli-setup-wizard.sh | 0 .../3d-printing}/install-skills.sh | 0 templates/3d-printing/main.tf | 10 +- .../3d-printing/profile.code-profile | 0 templates/cobol/cli-setup-wizard.sh | 107 ++++++++++++++++++ templates/cobol/install-skills.sh | 68 +++++++++++ templates/cobol/main.tf | 10 +- .../cobol/profile.code-profile | 0 templates/default/cli-setup-wizard.sh | 107 ++++++++++++++++++ templates/default/install-skills.sh | 68 +++++++++++ templates/default/main.tf | 10 +- .../default/profile.code-profile | 0 templates/python/cli-setup-wizard.sh | 107 ++++++++++++++++++ templates/python/install-skills.sh | 68 +++++++++++ templates/python/main.tf | 10 +- .../python/profile.code-profile | 0 templates/ttrpg/cli-setup-wizard.sh | 107 ++++++++++++++++++ templates/ttrpg/install-skills.sh | 68 +++++++++++ templates/ttrpg/main.tf | 10 +- .../ttrpg/profile.code-profile | 0 templates/web/cli-setup-wizard.sh | 107 ++++++++++++++++++ templates/web/install-skills.sh | 68 +++++++++++ templates/web/main.tf | 10 +- .../web/profile.code-profile | 0 26 files changed, 938 insertions(+), 55 deletions(-) rename {scripts => templates/3d-printing}/cli-setup-wizard.sh (100%) rename {scripts => templates/3d-printing}/install-skills.sh (100%) rename profile-templates/3D.code-profile => templates/3d-printing/profile.code-profile (100%) create mode 100644 templates/cobol/cli-setup-wizard.sh create mode 100644 templates/cobol/install-skills.sh rename profile-templates/COBOL.code-profile => templates/cobol/profile.code-profile (100%) create mode 100644 templates/default/cli-setup-wizard.sh create mode 100644 templates/default/install-skills.sh rename profile-templates/Default.code-profile => templates/default/profile.code-profile (100%) create mode 100644 templates/python/cli-setup-wizard.sh create mode 100644 templates/python/install-skills.sh rename profile-templates/Python.code-profile => templates/python/profile.code-profile (100%) create mode 100644 templates/ttrpg/cli-setup-wizard.sh create mode 100644 templates/ttrpg/install-skills.sh rename profile-templates/TTRPG.code-profile => templates/ttrpg/profile.code-profile (100%) create mode 100644 templates/web/cli-setup-wizard.sh create mode 100644 templates/web/install-skills.sh rename profile-templates/Web.code-profile => templates/web/profile.code-profile (100%) diff --git a/.gitea/workflows/coder-templates.yml b/.gitea/workflows/coder-templates.yml index 49b177d..5765e37 100644 --- a/.gitea/workflows/coder-templates.yml +++ b/.gitea/workflows/coder-templates.yml @@ -19,8 +19,6 @@ on: branches: [main] paths: - "templates/**" - - "scripts/**" - - "profile-templates/**" - ".gitea/workflows/coder-templates.yml" workflow_dispatch: {} diff --git a/README.md b/README.md index 6c04b87..a7fe89d 100644 --- a/README.md +++ b/README.md @@ -9,25 +9,34 @@ do and which didn't actually work. ``` templates/ - default/main.tf # Standard Default Dev - 3d-printing/main.tf # 3D Printing & Engineering - cobol/main.tf # COBOL Modern Mainframe - python/main.tf # Python Engineering - ttrpg/main.tf # TTRPG & Lore Building - web/main.tf # Web Applications -scripts/ - cli-setup-wizard.sh # shared first-run wizard, see below - install-skills.sh # shared Agent Skills installer, see below -profile-templates/ # VS Code .code-profile exports, one per env + default/ + main.tf # Standard Default Dev + profile.code-profile # VS Code .code-profile export for this env + cli-setup-wizard.sh # first-run wizard, see below + install-skills.sh # Agent Skills installer, see below + 3d-printing/ (same 4 files) # 3D Printing & Engineering + cobol/ (same 4 files) # COBOL Modern Mainframe + python/ (same 4 files) # Python Engineering + ttrpg/ (same 4 files) # TTRPG & Lore Building + web/ (same 4 files) # Web Applications extensions/ # Agent Skills bundles, installed per env (see below) ``` -Each `templates//main.tf` is a complete, independent Coder template -(agent, docker container, code-server, JetBrains). They're deliberately not -built from a shared Terraform module - only their `locals` block differs -(which profile file to read). The naming convention is `profiles-` -(matches what `.gitea/workflows/coder-templates.yml` does automatically - -see below). To push by hand: +Each `templates//` is a complete, independent Coder template (agent, +docker container, code-server, JetBrains) with its own copy of everything +`main.tf` needs. They're deliberately not built from a shared Terraform +module or shared files elsewhere in the repo: `coder templates push -d +templates/` only uploads that one directory to the Coder server, so any +`file()` reference reaching outside it (e.g. the old shared +`scripts/`/`profile-templates/` layout) fails at push/apply time with +`Invalid function argument: ... this function works only with files that +are distributed as part of the configuration source code` - discovered the +hard way once `coder-templates.yml` actually ran end-to-end. `main.tf`, +`profile.code-profile`, `cli-setup-wizard.sh`, and `install-skills.sh` are +duplicated per template rather than shared for this reason; only their +`locals` block and profile file differ meaningfully. The naming convention +is `profiles-` (matches what `.gitea/workflows/coder-templates.yml` +does automatically - see below). To push by hand: ```sh coder templates push profiles-default -d templates/default @@ -40,7 +49,7 @@ coder templates push profiles-web -d templates/web ### How the VS Code profile gets applied -`profile-templates/*.code-profile` is a real VS Code Profile export: a JSON +`templates//profile.code-profile` is a real VS Code Profile export: a JSON file whose `settings` and `extensions` fields are themselves JSON-encoded strings (double/triple-nested). Each template's `main.tf` reads and decodes its matching file **at `terraform apply`/push time** (via `file()` + @@ -71,7 +80,8 @@ installs. ### CLI setup wizard -`scripts/cli-setup-wizard.sh` is dropped onto every workspace and hooked +`templates//cli-setup-wizard.sh` (identical across envs) is dropped +onto every workspace and hooked into `~/.bashrc`. It runs in every new interactive terminal - until the user finishes it - and offers to install + log into: @@ -92,7 +102,7 @@ root `main.tf` copied this folder straight into code-server's VS Code extensions directory, which never worked since these aren't VS Code extension packages. -Each template now runs `scripts/install-skills.sh` (via a `coder_script`, +Each template now runs its own copy of `install-skills.sh` (via a `coder_script`, pulling a fresh zip of this repo from Gitea rather than embedding ~2.5MB into Terraform state) to install skills into all three AI CLIs' personal skills directories: @@ -117,13 +127,13 @@ the `SPECIALTY_SKILLS` env var passed to the script from each template's ### Auto-provisioning (Gitea Actions) `.gitea/workflows/coder-templates.yml` keeps Coder in sync with this repo on -every push to `main` that touches `templates/**`, `scripts/**`, or -`profile-templates/**`: +every push to `main` that touches `templates/**`: - **Add** a new `templates//` directory -> next push creates a new Coder template `profiles-` automatically. No workflow edits needed. -- **Edit** an existing `templates//main.tf` (or a shared script/profile - it references) -> next push updates that template with a new version. +- **Edit** an existing `templates//main.tf` (or its `profile.code-profile`, + `cli-setup-wizard.sh`, or `install-skills.sh`) -> next push updates that + template with a new version. - **Remove** a `templates//` directory -> next push deletes `profiles-` from Coder. `coder templates delete` refuses if the template still has active workspaces, so this fails loudly instead of diff --git a/scripts/cli-setup-wizard.sh b/templates/3d-printing/cli-setup-wizard.sh similarity index 100% rename from scripts/cli-setup-wizard.sh rename to templates/3d-printing/cli-setup-wizard.sh diff --git a/scripts/install-skills.sh b/templates/3d-printing/install-skills.sh similarity index 100% rename from scripts/install-skills.sh rename to templates/3d-printing/install-skills.sh diff --git a/templates/3d-printing/main.tf b/templates/3d-printing/main.tf index ea74af2..1950c41 100644 --- a/templates/3d-printing/main.tf +++ b/templates/3d-printing/main.tf @@ -11,7 +11,7 @@ terraform { locals { env_name = "3D Printing & Engineering" - profile = jsondecode(file("${path.module}/../../profile-templates/3D.code-profile")) + profile = jsondecode(file("${path.module}/profile.code-profile")) settings_raw = jsondecode(local.profile.settings).settings extensions = [for e in jsondecode(local.profile.extensions) : e.identifier.id] } @@ -243,7 +243,7 @@ resource "coder_script" "apply_settings" { # Drops the shared CLI setup wizard onto the workspace and hooks it into # every new interactive shell (via .bashrc) until the user completes it. -# See ../../scripts/cli-setup-wizard.sh for what it actually asks. +# See ./cli-setup-wizard.sh for what it actually asks. resource "coder_script" "cli_setup_wizard" { agent_id = coder_agent.main.id display_name = "Install CLI Setup Wizard" @@ -252,7 +252,7 @@ resource "coder_script" "cli_setup_wizard" { #!/bin/bash set -e mkdir -p /opt/coder - echo '${base64encode(file("${path.module}/../../scripts/cli-setup-wizard.sh"))}' | base64 -d > /opt/coder/cli-setup-wizard.sh + echo '${base64encode(file("${path.module}/cli-setup-wizard.sh"))}' | base64 -d > /opt/coder/cli-setup-wizard.sh chmod +x /opt/coder/cli-setup-wizard.sh MARKER="# >>> coder cli setup wizard >>>" @@ -298,7 +298,7 @@ resource "coder_script" "install_bun" { # Installs this repo's Agent Skills into Claude Code, GitHub Copilot CLI, and # Antigravity CLI's skills directories, plus the openscad-parametric skill -# from extensions/custom-specialty-plugin. See ../../scripts/install-skills.sh. +# from extensions/custom-specialty-plugin. See ./install-skills.sh. resource "coder_script" "install_skills" { agent_id = coder_agent.main.id display_name = "Install Agent Skills" @@ -307,7 +307,7 @@ resource "coder_script" "install_skills" { #!/bin/bash set -e mkdir -p /opt/coder - echo '${base64encode(file("${path.module}/../../scripts/install-skills.sh"))}' | base64 -d > /opt/coder/install-skills.sh + echo '${base64encode(file("${path.module}/install-skills.sh"))}' | base64 -d > /opt/coder/install-skills.sh chmod +x /opt/coder/install-skills.sh SPECIALTY_SKILLS="openscad-parametric" /opt/coder/install-skills.sh EOT diff --git a/profile-templates/3D.code-profile b/templates/3d-printing/profile.code-profile similarity index 100% rename from profile-templates/3D.code-profile rename to templates/3d-printing/profile.code-profile diff --git a/templates/cobol/cli-setup-wizard.sh b/templates/cobol/cli-setup-wizard.sh new file mode 100644 index 0000000..20fc6ef --- /dev/null +++ b/templates/cobol/cli-setup-wizard.sh @@ -0,0 +1,107 @@ +#!/usr/bin/env bash +# Coder workspace first-run CLI setup wizard. +# +# Meant to be `source`d from a new interactive shell (e.g. via .bashrc). It asks, +# once per user per workspace, whether to install and log into a few optional +# AI coding CLIs. It re-runs on every new terminal until the user lets it finish +# (or explicitly skips it for good), then gets out of the way. +# +# VS Code / code-server extensions are intentionally NOT asked about here - +# they're installed declaratively by the Coder template itself (the +# `code-server` module's `extensions` input, populated from the matching +# profile-templates/*.code-profile file at template-push time). +# +# Manual re-run: bash /opt/coder/cli-setup-wizard.sh --force + +set -u + +WIZARD_DONE_FILE="${HOME}/.cache/coder-cli-wizard/done" +FORCE=0 +[ "${1:-}" = "--force" ] && FORCE=1 + +export BUN_INSTALL="${HOME}/.bun" +export PATH="${BUN_INSTALL}/bin:${HOME}/.local/bin:${PATH}" + +# Only bother interactive shells with a real terminal attached, and only until +# the user marks the wizard as done. +if [ "$FORCE" -ne 1 ]; then + case "$-" in + *i*) : ;; + *) return 0 2>/dev/null || exit 0 ;; + esac + [ -t 0 ] || { return 0 2>/dev/null || exit 0; } + [ -f "$WIZARD_DONE_FILE" ] && { return 0 2>/dev/null || exit 0; } +fi + +mkdir -p "$(dirname "$WIZARD_DONE_FILE")" + +ask_yes_no() { + local prompt="$1" reply + read -r -p "$prompt [y/N] " reply + case "$reply" in + [Yy]*) return 0 ;; + *) return 1 ;; + esac +} + +echo "" +echo "===================================================================" +echo " Coder workspace setup wizard" +echo " Runs once per new terminal until you finish it. Ctrl+C any time" +echo " to skip for now - it'll ask again next terminal." +echo "===================================================================" + +# --- GitHub Copilot CLI --- +if command -v copilot >/dev/null 2>&1; then + echo "GitHub Copilot CLI already installed, skipping." +elif command -v bun >/dev/null 2>&1; then + if ask_yes_no "Install GitHub Copilot CLI and log in?"; then + if bun install -g @github/copilot; then + copilot login || echo "Install succeeded but login didn't complete. Retry any time with: copilot login" + else + echo "Copilot CLI install failed. Retry later with: bun install -g @github/copilot && copilot login" + fi + fi +else + echo "Skipping GitHub Copilot CLI: bun not found on this workspace image." +fi + +# --- Google Antigravity CLI (agy) --- +if command -v agy >/dev/null 2>&1; then + echo "Antigravity CLI already installed, skipping." +else + if ask_yes_no "Install Google Antigravity CLI (agy) and log in?"; then + if curl -fsSL https://antigravity.google/cli/install.sh | bash; then + echo "Launching 'agy' once to complete sign-in (exit with /logout or Ctrl+D when done)..." + agy || echo "Sign-in didn't complete. Retry any time by running: agy" + else + echo "Antigravity CLI install failed. Retry later with: curl -fsSL https://antigravity.google/cli/install.sh | bash" + fi + fi +fi + +# --- Claude Code CLI --- +if command -v claude >/dev/null 2>&1; then + echo "Claude Code CLI already installed, skipping." +elif command -v bun >/dev/null 2>&1; then + if ask_yes_no "Install Claude Code CLI and log in?"; then + if bun install -g @anthropic-ai/claude-code; then + echo "Launching 'claude' once to complete sign-in (use /login if not prompted; Ctrl+C to exit when done)..." + claude || echo "Sign-in didn't complete. Retry any time by running: claude" + else + echo "Claude Code CLI install failed. Retry later with: bun install -g @anthropic-ai/claude-code" + fi + fi +else + echo "Skipping Claude Code CLI: bun not found on this workspace image." +fi + +echo "" +if ask_yes_no "Mark setup wizard as complete so it stops asking on new terminals?"; then + touch "$WIZARD_DONE_FILE" + echo "Done. Re-run any time with: bash /opt/coder/cli-setup-wizard.sh --force" +else + echo "OK, this'll ask again next time you open a terminal." +fi + +return 0 2>/dev/null || exit 0 diff --git a/templates/cobol/install-skills.sh b/templates/cobol/install-skills.sh new file mode 100644 index 0000000..f7d82cd --- /dev/null +++ b/templates/cobol/install-skills.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash +# Installs this repo's Agent Skills (extensions/{awesome-skills-plugin, +# custom-specialty-plugin}/skills/*, each a SKILL.md-based skill directory) +# into every AI CLI's personal skills directory: +# +# Claude Code CLI -> ~/.claude/skills// +# GitHub Copilot CLI -> ~/.copilot/skills// +# Antigravity CLI -> ~/.gemini/config/skills// (per antigravity.google/docs/skills; +# worth a spot-check if agy doesn't pick these up, some third-party +# docs disagree on the exact path) +# +# Run once at workspace startup via coder_script. Pulls this repo fresh from +# Gitea rather than embedding ~2.5MB of skill files into Terraform state. +# +# Env vars: +# SPECIALTY_SKILLS - optional space-separated skill names from +# extensions/custom-specialty-plugin/skills/ to install in addition to +# the common awesome-skills-plugin bundle (every env gets that one). + +set -e + +REPO_ZIP_URL="https://git.octoturge.com/octoturge/Profiles-for-Coder/archive/main.zip" +ZIP_PATH="/tmp/coder-skills-src.zip" +WORK_DIR="/tmp/coder-skills-src" + +rm -rf "$WORK_DIR" "$ZIP_PATH" +curl -fsSL "$REPO_ZIP_URL" -o "$ZIP_PATH" +mkdir -p "$WORK_DIR" +unzip -q -o "$ZIP_PATH" -d "$WORK_DIR" + +INNER_DIR=$(find "$WORK_DIR" -mindepth 1 -maxdepth 1 -type d | head -n1) +if [ -z "$INNER_DIR" ]; then + echo "install-skills: couldn't find extracted repo contents, skipping." >&2 + rm -rf "$WORK_DIR" "$ZIP_PATH" + exit 0 +fi + +TARGET_DIRS=("$HOME/.claude/skills" "$HOME/.copilot/skills" "$HOME/.gemini/config/skills") +for dir in "${TARGET_DIRS[@]}"; do + mkdir -p "$dir" +done + +# Common skill bundle, installed for every environment. +COMMON_SKILLS_SRC="$INNER_DIR/extensions/awesome-skills-plugin/skills" +if [ -d "$COMMON_SKILLS_SRC" ]; then + for dir in "${TARGET_DIRS[@]}"; do + cp -r "$COMMON_SKILLS_SRC/." "$dir/" + done + echo "install-skills: installed common skill bundle into ${TARGET_DIRS[*]}" +else + echo "install-skills: common skill bundle not found at $COMMON_SKILLS_SRC, skipping." >&2 +fi + +# Environment-specific specialty skills, if any were requested. +for skill in ${SPECIALTY_SKILLS:-}; do + SRC="$INNER_DIR/extensions/custom-specialty-plugin/skills/$skill" + if [ -d "$SRC" ]; then + for dir in "${TARGET_DIRS[@]}"; do + cp -r "$SRC" "$dir/$skill" + done + echo "install-skills: installed specialty skill '$skill'" + else + echo "install-skills: specialty skill '$skill' not found at $SRC, skipping." >&2 + fi +done + +rm -rf "$WORK_DIR" "$ZIP_PATH" +echo "install-skills: done." diff --git a/templates/cobol/main.tf b/templates/cobol/main.tf index f9ee846..53a5753 100644 --- a/templates/cobol/main.tf +++ b/templates/cobol/main.tf @@ -11,7 +11,7 @@ terraform { locals { env_name = "COBOL Modern Mainframe" - profile = jsondecode(file("${path.module}/../../profile-templates/COBOL.code-profile")) + profile = jsondecode(file("${path.module}/profile.code-profile")) settings_raw = jsondecode(local.profile.settings).settings extensions = [for e in jsondecode(local.profile.extensions) : e.identifier.id] } @@ -243,7 +243,7 @@ resource "coder_script" "apply_settings" { # Drops the shared CLI setup wizard onto the workspace and hooks it into # every new interactive shell (via .bashrc) until the user completes it. -# See ../../scripts/cli-setup-wizard.sh for what it actually asks. +# See ./cli-setup-wizard.sh for what it actually asks. resource "coder_script" "cli_setup_wizard" { agent_id = coder_agent.main.id display_name = "Install CLI Setup Wizard" @@ -252,7 +252,7 @@ resource "coder_script" "cli_setup_wizard" { #!/bin/bash set -e mkdir -p /opt/coder - echo '${base64encode(file("${path.module}/../../scripts/cli-setup-wizard.sh"))}' | base64 -d > /opt/coder/cli-setup-wizard.sh + echo '${base64encode(file("${path.module}/cli-setup-wizard.sh"))}' | base64 -d > /opt/coder/cli-setup-wizard.sh chmod +x /opt/coder/cli-setup-wizard.sh MARKER="# >>> coder cli setup wizard >>>" @@ -298,7 +298,7 @@ resource "coder_script" "install_bun" { # Installs this repo's Agent Skills into Claude Code, GitHub Copilot CLI, and # Antigravity CLI's skills directories, plus the cobol-teacher skill from -# extensions/custom-specialty-plugin. See ../../scripts/install-skills.sh. +# extensions/custom-specialty-plugin. See ./install-skills.sh. resource "coder_script" "install_skills" { agent_id = coder_agent.main.id display_name = "Install Agent Skills" @@ -307,7 +307,7 @@ resource "coder_script" "install_skills" { #!/bin/bash set -e mkdir -p /opt/coder - echo '${base64encode(file("${path.module}/../../scripts/install-skills.sh"))}' | base64 -d > /opt/coder/install-skills.sh + echo '${base64encode(file("${path.module}/install-skills.sh"))}' | base64 -d > /opt/coder/install-skills.sh chmod +x /opt/coder/install-skills.sh SPECIALTY_SKILLS="cobol-teacher" /opt/coder/install-skills.sh EOT diff --git a/profile-templates/COBOL.code-profile b/templates/cobol/profile.code-profile similarity index 100% rename from profile-templates/COBOL.code-profile rename to templates/cobol/profile.code-profile diff --git a/templates/default/cli-setup-wizard.sh b/templates/default/cli-setup-wizard.sh new file mode 100644 index 0000000..20fc6ef --- /dev/null +++ b/templates/default/cli-setup-wizard.sh @@ -0,0 +1,107 @@ +#!/usr/bin/env bash +# Coder workspace first-run CLI setup wizard. +# +# Meant to be `source`d from a new interactive shell (e.g. via .bashrc). It asks, +# once per user per workspace, whether to install and log into a few optional +# AI coding CLIs. It re-runs on every new terminal until the user lets it finish +# (or explicitly skips it for good), then gets out of the way. +# +# VS Code / code-server extensions are intentionally NOT asked about here - +# they're installed declaratively by the Coder template itself (the +# `code-server` module's `extensions` input, populated from the matching +# profile-templates/*.code-profile file at template-push time). +# +# Manual re-run: bash /opt/coder/cli-setup-wizard.sh --force + +set -u + +WIZARD_DONE_FILE="${HOME}/.cache/coder-cli-wizard/done" +FORCE=0 +[ "${1:-}" = "--force" ] && FORCE=1 + +export BUN_INSTALL="${HOME}/.bun" +export PATH="${BUN_INSTALL}/bin:${HOME}/.local/bin:${PATH}" + +# Only bother interactive shells with a real terminal attached, and only until +# the user marks the wizard as done. +if [ "$FORCE" -ne 1 ]; then + case "$-" in + *i*) : ;; + *) return 0 2>/dev/null || exit 0 ;; + esac + [ -t 0 ] || { return 0 2>/dev/null || exit 0; } + [ -f "$WIZARD_DONE_FILE" ] && { return 0 2>/dev/null || exit 0; } +fi + +mkdir -p "$(dirname "$WIZARD_DONE_FILE")" + +ask_yes_no() { + local prompt="$1" reply + read -r -p "$prompt [y/N] " reply + case "$reply" in + [Yy]*) return 0 ;; + *) return 1 ;; + esac +} + +echo "" +echo "===================================================================" +echo " Coder workspace setup wizard" +echo " Runs once per new terminal until you finish it. Ctrl+C any time" +echo " to skip for now - it'll ask again next terminal." +echo "===================================================================" + +# --- GitHub Copilot CLI --- +if command -v copilot >/dev/null 2>&1; then + echo "GitHub Copilot CLI already installed, skipping." +elif command -v bun >/dev/null 2>&1; then + if ask_yes_no "Install GitHub Copilot CLI and log in?"; then + if bun install -g @github/copilot; then + copilot login || echo "Install succeeded but login didn't complete. Retry any time with: copilot login" + else + echo "Copilot CLI install failed. Retry later with: bun install -g @github/copilot && copilot login" + fi + fi +else + echo "Skipping GitHub Copilot CLI: bun not found on this workspace image." +fi + +# --- Google Antigravity CLI (agy) --- +if command -v agy >/dev/null 2>&1; then + echo "Antigravity CLI already installed, skipping." +else + if ask_yes_no "Install Google Antigravity CLI (agy) and log in?"; then + if curl -fsSL https://antigravity.google/cli/install.sh | bash; then + echo "Launching 'agy' once to complete sign-in (exit with /logout or Ctrl+D when done)..." + agy || echo "Sign-in didn't complete. Retry any time by running: agy" + else + echo "Antigravity CLI install failed. Retry later with: curl -fsSL https://antigravity.google/cli/install.sh | bash" + fi + fi +fi + +# --- Claude Code CLI --- +if command -v claude >/dev/null 2>&1; then + echo "Claude Code CLI already installed, skipping." +elif command -v bun >/dev/null 2>&1; then + if ask_yes_no "Install Claude Code CLI and log in?"; then + if bun install -g @anthropic-ai/claude-code; then + echo "Launching 'claude' once to complete sign-in (use /login if not prompted; Ctrl+C to exit when done)..." + claude || echo "Sign-in didn't complete. Retry any time by running: claude" + else + echo "Claude Code CLI install failed. Retry later with: bun install -g @anthropic-ai/claude-code" + fi + fi +else + echo "Skipping Claude Code CLI: bun not found on this workspace image." +fi + +echo "" +if ask_yes_no "Mark setup wizard as complete so it stops asking on new terminals?"; then + touch "$WIZARD_DONE_FILE" + echo "Done. Re-run any time with: bash /opt/coder/cli-setup-wizard.sh --force" +else + echo "OK, this'll ask again next time you open a terminal." +fi + +return 0 2>/dev/null || exit 0 diff --git a/templates/default/install-skills.sh b/templates/default/install-skills.sh new file mode 100644 index 0000000..f7d82cd --- /dev/null +++ b/templates/default/install-skills.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash +# Installs this repo's Agent Skills (extensions/{awesome-skills-plugin, +# custom-specialty-plugin}/skills/*, each a SKILL.md-based skill directory) +# into every AI CLI's personal skills directory: +# +# Claude Code CLI -> ~/.claude/skills// +# GitHub Copilot CLI -> ~/.copilot/skills// +# Antigravity CLI -> ~/.gemini/config/skills// (per antigravity.google/docs/skills; +# worth a spot-check if agy doesn't pick these up, some third-party +# docs disagree on the exact path) +# +# Run once at workspace startup via coder_script. Pulls this repo fresh from +# Gitea rather than embedding ~2.5MB of skill files into Terraform state. +# +# Env vars: +# SPECIALTY_SKILLS - optional space-separated skill names from +# extensions/custom-specialty-plugin/skills/ to install in addition to +# the common awesome-skills-plugin bundle (every env gets that one). + +set -e + +REPO_ZIP_URL="https://git.octoturge.com/octoturge/Profiles-for-Coder/archive/main.zip" +ZIP_PATH="/tmp/coder-skills-src.zip" +WORK_DIR="/tmp/coder-skills-src" + +rm -rf "$WORK_DIR" "$ZIP_PATH" +curl -fsSL "$REPO_ZIP_URL" -o "$ZIP_PATH" +mkdir -p "$WORK_DIR" +unzip -q -o "$ZIP_PATH" -d "$WORK_DIR" + +INNER_DIR=$(find "$WORK_DIR" -mindepth 1 -maxdepth 1 -type d | head -n1) +if [ -z "$INNER_DIR" ]; then + echo "install-skills: couldn't find extracted repo contents, skipping." >&2 + rm -rf "$WORK_DIR" "$ZIP_PATH" + exit 0 +fi + +TARGET_DIRS=("$HOME/.claude/skills" "$HOME/.copilot/skills" "$HOME/.gemini/config/skills") +for dir in "${TARGET_DIRS[@]}"; do + mkdir -p "$dir" +done + +# Common skill bundle, installed for every environment. +COMMON_SKILLS_SRC="$INNER_DIR/extensions/awesome-skills-plugin/skills" +if [ -d "$COMMON_SKILLS_SRC" ]; then + for dir in "${TARGET_DIRS[@]}"; do + cp -r "$COMMON_SKILLS_SRC/." "$dir/" + done + echo "install-skills: installed common skill bundle into ${TARGET_DIRS[*]}" +else + echo "install-skills: common skill bundle not found at $COMMON_SKILLS_SRC, skipping." >&2 +fi + +# Environment-specific specialty skills, if any were requested. +for skill in ${SPECIALTY_SKILLS:-}; do + SRC="$INNER_DIR/extensions/custom-specialty-plugin/skills/$skill" + if [ -d "$SRC" ]; then + for dir in "${TARGET_DIRS[@]}"; do + cp -r "$SRC" "$dir/$skill" + done + echo "install-skills: installed specialty skill '$skill'" + else + echo "install-skills: specialty skill '$skill' not found at $SRC, skipping." >&2 + fi +done + +rm -rf "$WORK_DIR" "$ZIP_PATH" +echo "install-skills: done." diff --git a/templates/default/main.tf b/templates/default/main.tf index 5fe56ae..fff0329 100644 --- a/templates/default/main.tf +++ b/templates/default/main.tf @@ -11,7 +11,7 @@ terraform { locals { env_name = "Default" - profile = jsondecode(file("${path.module}/../../profile-templates/Default.code-profile")) + profile = jsondecode(file("${path.module}/profile.code-profile")) settings_raw = jsondecode(local.profile.settings).settings extensions = [for e in jsondecode(local.profile.extensions) : e.identifier.id] } @@ -243,7 +243,7 @@ resource "coder_script" "apply_settings" { # Drops the shared CLI setup wizard onto the workspace and hooks it into # every new interactive shell (via .bashrc) until the user completes it. -# See ../../scripts/cli-setup-wizard.sh for what it actually asks. +# See ./cli-setup-wizard.sh for what it actually asks. resource "coder_script" "cli_setup_wizard" { agent_id = coder_agent.main.id display_name = "Install CLI Setup Wizard" @@ -252,7 +252,7 @@ resource "coder_script" "cli_setup_wizard" { #!/bin/bash set -e mkdir -p /opt/coder - echo '${base64encode(file("${path.module}/../../scripts/cli-setup-wizard.sh"))}' | base64 -d > /opt/coder/cli-setup-wizard.sh + echo '${base64encode(file("${path.module}/cli-setup-wizard.sh"))}' | base64 -d > /opt/coder/cli-setup-wizard.sh chmod +x /opt/coder/cli-setup-wizard.sh MARKER="# >>> coder cli setup wizard >>>" @@ -297,7 +297,7 @@ resource "coder_script" "install_bun" { } # Installs this repo's Agent Skills into Claude Code, GitHub Copilot CLI, and -# Antigravity CLI's skills directories. See ../../scripts/install-skills.sh. +# Antigravity CLI's skills directories. See ./install-skills.sh. # Default has no matching entry in extensions/custom-specialty-plugin/skills, # so it only gets the common awesome-skills-plugin bundle. resource "coder_script" "install_skills" { @@ -308,7 +308,7 @@ resource "coder_script" "install_skills" { #!/bin/bash set -e mkdir -p /opt/coder - echo '${base64encode(file("${path.module}/../../scripts/install-skills.sh"))}' | base64 -d > /opt/coder/install-skills.sh + echo '${base64encode(file("${path.module}/install-skills.sh"))}' | base64 -d > /opt/coder/install-skills.sh chmod +x /opt/coder/install-skills.sh SPECIALTY_SKILLS="" /opt/coder/install-skills.sh EOT diff --git a/profile-templates/Default.code-profile b/templates/default/profile.code-profile similarity index 100% rename from profile-templates/Default.code-profile rename to templates/default/profile.code-profile diff --git a/templates/python/cli-setup-wizard.sh b/templates/python/cli-setup-wizard.sh new file mode 100644 index 0000000..20fc6ef --- /dev/null +++ b/templates/python/cli-setup-wizard.sh @@ -0,0 +1,107 @@ +#!/usr/bin/env bash +# Coder workspace first-run CLI setup wizard. +# +# Meant to be `source`d from a new interactive shell (e.g. via .bashrc). It asks, +# once per user per workspace, whether to install and log into a few optional +# AI coding CLIs. It re-runs on every new terminal until the user lets it finish +# (or explicitly skips it for good), then gets out of the way. +# +# VS Code / code-server extensions are intentionally NOT asked about here - +# they're installed declaratively by the Coder template itself (the +# `code-server` module's `extensions` input, populated from the matching +# profile-templates/*.code-profile file at template-push time). +# +# Manual re-run: bash /opt/coder/cli-setup-wizard.sh --force + +set -u + +WIZARD_DONE_FILE="${HOME}/.cache/coder-cli-wizard/done" +FORCE=0 +[ "${1:-}" = "--force" ] && FORCE=1 + +export BUN_INSTALL="${HOME}/.bun" +export PATH="${BUN_INSTALL}/bin:${HOME}/.local/bin:${PATH}" + +# Only bother interactive shells with a real terminal attached, and only until +# the user marks the wizard as done. +if [ "$FORCE" -ne 1 ]; then + case "$-" in + *i*) : ;; + *) return 0 2>/dev/null || exit 0 ;; + esac + [ -t 0 ] || { return 0 2>/dev/null || exit 0; } + [ -f "$WIZARD_DONE_FILE" ] && { return 0 2>/dev/null || exit 0; } +fi + +mkdir -p "$(dirname "$WIZARD_DONE_FILE")" + +ask_yes_no() { + local prompt="$1" reply + read -r -p "$prompt [y/N] " reply + case "$reply" in + [Yy]*) return 0 ;; + *) return 1 ;; + esac +} + +echo "" +echo "===================================================================" +echo " Coder workspace setup wizard" +echo " Runs once per new terminal until you finish it. Ctrl+C any time" +echo " to skip for now - it'll ask again next terminal." +echo "===================================================================" + +# --- GitHub Copilot CLI --- +if command -v copilot >/dev/null 2>&1; then + echo "GitHub Copilot CLI already installed, skipping." +elif command -v bun >/dev/null 2>&1; then + if ask_yes_no "Install GitHub Copilot CLI and log in?"; then + if bun install -g @github/copilot; then + copilot login || echo "Install succeeded but login didn't complete. Retry any time with: copilot login" + else + echo "Copilot CLI install failed. Retry later with: bun install -g @github/copilot && copilot login" + fi + fi +else + echo "Skipping GitHub Copilot CLI: bun not found on this workspace image." +fi + +# --- Google Antigravity CLI (agy) --- +if command -v agy >/dev/null 2>&1; then + echo "Antigravity CLI already installed, skipping." +else + if ask_yes_no "Install Google Antigravity CLI (agy) and log in?"; then + if curl -fsSL https://antigravity.google/cli/install.sh | bash; then + echo "Launching 'agy' once to complete sign-in (exit with /logout or Ctrl+D when done)..." + agy || echo "Sign-in didn't complete. Retry any time by running: agy" + else + echo "Antigravity CLI install failed. Retry later with: curl -fsSL https://antigravity.google/cli/install.sh | bash" + fi + fi +fi + +# --- Claude Code CLI --- +if command -v claude >/dev/null 2>&1; then + echo "Claude Code CLI already installed, skipping." +elif command -v bun >/dev/null 2>&1; then + if ask_yes_no "Install Claude Code CLI and log in?"; then + if bun install -g @anthropic-ai/claude-code; then + echo "Launching 'claude' once to complete sign-in (use /login if not prompted; Ctrl+C to exit when done)..." + claude || echo "Sign-in didn't complete. Retry any time by running: claude" + else + echo "Claude Code CLI install failed. Retry later with: bun install -g @anthropic-ai/claude-code" + fi + fi +else + echo "Skipping Claude Code CLI: bun not found on this workspace image." +fi + +echo "" +if ask_yes_no "Mark setup wizard as complete so it stops asking on new terminals?"; then + touch "$WIZARD_DONE_FILE" + echo "Done. Re-run any time with: bash /opt/coder/cli-setup-wizard.sh --force" +else + echo "OK, this'll ask again next time you open a terminal." +fi + +return 0 2>/dev/null || exit 0 diff --git a/templates/python/install-skills.sh b/templates/python/install-skills.sh new file mode 100644 index 0000000..f7d82cd --- /dev/null +++ b/templates/python/install-skills.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash +# Installs this repo's Agent Skills (extensions/{awesome-skills-plugin, +# custom-specialty-plugin}/skills/*, each a SKILL.md-based skill directory) +# into every AI CLI's personal skills directory: +# +# Claude Code CLI -> ~/.claude/skills// +# GitHub Copilot CLI -> ~/.copilot/skills// +# Antigravity CLI -> ~/.gemini/config/skills// (per antigravity.google/docs/skills; +# worth a spot-check if agy doesn't pick these up, some third-party +# docs disagree on the exact path) +# +# Run once at workspace startup via coder_script. Pulls this repo fresh from +# Gitea rather than embedding ~2.5MB of skill files into Terraform state. +# +# Env vars: +# SPECIALTY_SKILLS - optional space-separated skill names from +# extensions/custom-specialty-plugin/skills/ to install in addition to +# the common awesome-skills-plugin bundle (every env gets that one). + +set -e + +REPO_ZIP_URL="https://git.octoturge.com/octoturge/Profiles-for-Coder/archive/main.zip" +ZIP_PATH="/tmp/coder-skills-src.zip" +WORK_DIR="/tmp/coder-skills-src" + +rm -rf "$WORK_DIR" "$ZIP_PATH" +curl -fsSL "$REPO_ZIP_URL" -o "$ZIP_PATH" +mkdir -p "$WORK_DIR" +unzip -q -o "$ZIP_PATH" -d "$WORK_DIR" + +INNER_DIR=$(find "$WORK_DIR" -mindepth 1 -maxdepth 1 -type d | head -n1) +if [ -z "$INNER_DIR" ]; then + echo "install-skills: couldn't find extracted repo contents, skipping." >&2 + rm -rf "$WORK_DIR" "$ZIP_PATH" + exit 0 +fi + +TARGET_DIRS=("$HOME/.claude/skills" "$HOME/.copilot/skills" "$HOME/.gemini/config/skills") +for dir in "${TARGET_DIRS[@]}"; do + mkdir -p "$dir" +done + +# Common skill bundle, installed for every environment. +COMMON_SKILLS_SRC="$INNER_DIR/extensions/awesome-skills-plugin/skills" +if [ -d "$COMMON_SKILLS_SRC" ]; then + for dir in "${TARGET_DIRS[@]}"; do + cp -r "$COMMON_SKILLS_SRC/." "$dir/" + done + echo "install-skills: installed common skill bundle into ${TARGET_DIRS[*]}" +else + echo "install-skills: common skill bundle not found at $COMMON_SKILLS_SRC, skipping." >&2 +fi + +# Environment-specific specialty skills, if any were requested. +for skill in ${SPECIALTY_SKILLS:-}; do + SRC="$INNER_DIR/extensions/custom-specialty-plugin/skills/$skill" + if [ -d "$SRC" ]; then + for dir in "${TARGET_DIRS[@]}"; do + cp -r "$SRC" "$dir/$skill" + done + echo "install-skills: installed specialty skill '$skill'" + else + echo "install-skills: specialty skill '$skill' not found at $SRC, skipping." >&2 + fi +done + +rm -rf "$WORK_DIR" "$ZIP_PATH" +echo "install-skills: done." diff --git a/templates/python/main.tf b/templates/python/main.tf index 6caf374..7b2e302 100644 --- a/templates/python/main.tf +++ b/templates/python/main.tf @@ -11,7 +11,7 @@ terraform { locals { env_name = "Python Engineering" - profile = jsondecode(file("${path.module}/../../profile-templates/Python.code-profile")) + profile = jsondecode(file("${path.module}/profile.code-profile")) settings_raw = jsondecode(local.profile.settings).settings extensions = [for e in jsondecode(local.profile.extensions) : e.identifier.id] } @@ -243,7 +243,7 @@ resource "coder_script" "apply_settings" { # Drops the shared CLI setup wizard onto the workspace and hooks it into # every new interactive shell (via .bashrc) until the user completes it. -# See ../../scripts/cli-setup-wizard.sh for what it actually asks. +# See ./cli-setup-wizard.sh for what it actually asks. resource "coder_script" "cli_setup_wizard" { agent_id = coder_agent.main.id display_name = "Install CLI Setup Wizard" @@ -252,7 +252,7 @@ resource "coder_script" "cli_setup_wizard" { #!/bin/bash set -e mkdir -p /opt/coder - echo '${base64encode(file("${path.module}/../../scripts/cli-setup-wizard.sh"))}' | base64 -d > /opt/coder/cli-setup-wizard.sh + echo '${base64encode(file("${path.module}/cli-setup-wizard.sh"))}' | base64 -d > /opt/coder/cli-setup-wizard.sh chmod +x /opt/coder/cli-setup-wizard.sh MARKER="# >>> coder cli setup wizard >>>" @@ -297,7 +297,7 @@ resource "coder_script" "install_bun" { } # Installs this repo's Agent Skills into Claude Code, GitHub Copilot CLI, and -# Antigravity CLI's skills directories. See ../../scripts/install-skills.sh. +# Antigravity CLI's skills directories. See ./install-skills.sh. # Python has no matching entry in extensions/custom-specialty-plugin/skills, # so it only gets the common awesome-skills-plugin bundle. resource "coder_script" "install_skills" { @@ -308,7 +308,7 @@ resource "coder_script" "install_skills" { #!/bin/bash set -e mkdir -p /opt/coder - echo '${base64encode(file("${path.module}/../../scripts/install-skills.sh"))}' | base64 -d > /opt/coder/install-skills.sh + echo '${base64encode(file("${path.module}/install-skills.sh"))}' | base64 -d > /opt/coder/install-skills.sh chmod +x /opt/coder/install-skills.sh SPECIALTY_SKILLS="" /opt/coder/install-skills.sh EOT diff --git a/profile-templates/Python.code-profile b/templates/python/profile.code-profile similarity index 100% rename from profile-templates/Python.code-profile rename to templates/python/profile.code-profile diff --git a/templates/ttrpg/cli-setup-wizard.sh b/templates/ttrpg/cli-setup-wizard.sh new file mode 100644 index 0000000..20fc6ef --- /dev/null +++ b/templates/ttrpg/cli-setup-wizard.sh @@ -0,0 +1,107 @@ +#!/usr/bin/env bash +# Coder workspace first-run CLI setup wizard. +# +# Meant to be `source`d from a new interactive shell (e.g. via .bashrc). It asks, +# once per user per workspace, whether to install and log into a few optional +# AI coding CLIs. It re-runs on every new terminal until the user lets it finish +# (or explicitly skips it for good), then gets out of the way. +# +# VS Code / code-server extensions are intentionally NOT asked about here - +# they're installed declaratively by the Coder template itself (the +# `code-server` module's `extensions` input, populated from the matching +# profile-templates/*.code-profile file at template-push time). +# +# Manual re-run: bash /opt/coder/cli-setup-wizard.sh --force + +set -u + +WIZARD_DONE_FILE="${HOME}/.cache/coder-cli-wizard/done" +FORCE=0 +[ "${1:-}" = "--force" ] && FORCE=1 + +export BUN_INSTALL="${HOME}/.bun" +export PATH="${BUN_INSTALL}/bin:${HOME}/.local/bin:${PATH}" + +# Only bother interactive shells with a real terminal attached, and only until +# the user marks the wizard as done. +if [ "$FORCE" -ne 1 ]; then + case "$-" in + *i*) : ;; + *) return 0 2>/dev/null || exit 0 ;; + esac + [ -t 0 ] || { return 0 2>/dev/null || exit 0; } + [ -f "$WIZARD_DONE_FILE" ] && { return 0 2>/dev/null || exit 0; } +fi + +mkdir -p "$(dirname "$WIZARD_DONE_FILE")" + +ask_yes_no() { + local prompt="$1" reply + read -r -p "$prompt [y/N] " reply + case "$reply" in + [Yy]*) return 0 ;; + *) return 1 ;; + esac +} + +echo "" +echo "===================================================================" +echo " Coder workspace setup wizard" +echo " Runs once per new terminal until you finish it. Ctrl+C any time" +echo " to skip for now - it'll ask again next terminal." +echo "===================================================================" + +# --- GitHub Copilot CLI --- +if command -v copilot >/dev/null 2>&1; then + echo "GitHub Copilot CLI already installed, skipping." +elif command -v bun >/dev/null 2>&1; then + if ask_yes_no "Install GitHub Copilot CLI and log in?"; then + if bun install -g @github/copilot; then + copilot login || echo "Install succeeded but login didn't complete. Retry any time with: copilot login" + else + echo "Copilot CLI install failed. Retry later with: bun install -g @github/copilot && copilot login" + fi + fi +else + echo "Skipping GitHub Copilot CLI: bun not found on this workspace image." +fi + +# --- Google Antigravity CLI (agy) --- +if command -v agy >/dev/null 2>&1; then + echo "Antigravity CLI already installed, skipping." +else + if ask_yes_no "Install Google Antigravity CLI (agy) and log in?"; then + if curl -fsSL https://antigravity.google/cli/install.sh | bash; then + echo "Launching 'agy' once to complete sign-in (exit with /logout or Ctrl+D when done)..." + agy || echo "Sign-in didn't complete. Retry any time by running: agy" + else + echo "Antigravity CLI install failed. Retry later with: curl -fsSL https://antigravity.google/cli/install.sh | bash" + fi + fi +fi + +# --- Claude Code CLI --- +if command -v claude >/dev/null 2>&1; then + echo "Claude Code CLI already installed, skipping." +elif command -v bun >/dev/null 2>&1; then + if ask_yes_no "Install Claude Code CLI and log in?"; then + if bun install -g @anthropic-ai/claude-code; then + echo "Launching 'claude' once to complete sign-in (use /login if not prompted; Ctrl+C to exit when done)..." + claude || echo "Sign-in didn't complete. Retry any time by running: claude" + else + echo "Claude Code CLI install failed. Retry later with: bun install -g @anthropic-ai/claude-code" + fi + fi +else + echo "Skipping Claude Code CLI: bun not found on this workspace image." +fi + +echo "" +if ask_yes_no "Mark setup wizard as complete so it stops asking on new terminals?"; then + touch "$WIZARD_DONE_FILE" + echo "Done. Re-run any time with: bash /opt/coder/cli-setup-wizard.sh --force" +else + echo "OK, this'll ask again next time you open a terminal." +fi + +return 0 2>/dev/null || exit 0 diff --git a/templates/ttrpg/install-skills.sh b/templates/ttrpg/install-skills.sh new file mode 100644 index 0000000..f7d82cd --- /dev/null +++ b/templates/ttrpg/install-skills.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash +# Installs this repo's Agent Skills (extensions/{awesome-skills-plugin, +# custom-specialty-plugin}/skills/*, each a SKILL.md-based skill directory) +# into every AI CLI's personal skills directory: +# +# Claude Code CLI -> ~/.claude/skills// +# GitHub Copilot CLI -> ~/.copilot/skills// +# Antigravity CLI -> ~/.gemini/config/skills// (per antigravity.google/docs/skills; +# worth a spot-check if agy doesn't pick these up, some third-party +# docs disagree on the exact path) +# +# Run once at workspace startup via coder_script. Pulls this repo fresh from +# Gitea rather than embedding ~2.5MB of skill files into Terraform state. +# +# Env vars: +# SPECIALTY_SKILLS - optional space-separated skill names from +# extensions/custom-specialty-plugin/skills/ to install in addition to +# the common awesome-skills-plugin bundle (every env gets that one). + +set -e + +REPO_ZIP_URL="https://git.octoturge.com/octoturge/Profiles-for-Coder/archive/main.zip" +ZIP_PATH="/tmp/coder-skills-src.zip" +WORK_DIR="/tmp/coder-skills-src" + +rm -rf "$WORK_DIR" "$ZIP_PATH" +curl -fsSL "$REPO_ZIP_URL" -o "$ZIP_PATH" +mkdir -p "$WORK_DIR" +unzip -q -o "$ZIP_PATH" -d "$WORK_DIR" + +INNER_DIR=$(find "$WORK_DIR" -mindepth 1 -maxdepth 1 -type d | head -n1) +if [ -z "$INNER_DIR" ]; then + echo "install-skills: couldn't find extracted repo contents, skipping." >&2 + rm -rf "$WORK_DIR" "$ZIP_PATH" + exit 0 +fi + +TARGET_DIRS=("$HOME/.claude/skills" "$HOME/.copilot/skills" "$HOME/.gemini/config/skills") +for dir in "${TARGET_DIRS[@]}"; do + mkdir -p "$dir" +done + +# Common skill bundle, installed for every environment. +COMMON_SKILLS_SRC="$INNER_DIR/extensions/awesome-skills-plugin/skills" +if [ -d "$COMMON_SKILLS_SRC" ]; then + for dir in "${TARGET_DIRS[@]}"; do + cp -r "$COMMON_SKILLS_SRC/." "$dir/" + done + echo "install-skills: installed common skill bundle into ${TARGET_DIRS[*]}" +else + echo "install-skills: common skill bundle not found at $COMMON_SKILLS_SRC, skipping." >&2 +fi + +# Environment-specific specialty skills, if any were requested. +for skill in ${SPECIALTY_SKILLS:-}; do + SRC="$INNER_DIR/extensions/custom-specialty-plugin/skills/$skill" + if [ -d "$SRC" ]; then + for dir in "${TARGET_DIRS[@]}"; do + cp -r "$SRC" "$dir/$skill" + done + echo "install-skills: installed specialty skill '$skill'" + else + echo "install-skills: specialty skill '$skill' not found at $SRC, skipping." >&2 + fi +done + +rm -rf "$WORK_DIR" "$ZIP_PATH" +echo "install-skills: done." diff --git a/templates/ttrpg/main.tf b/templates/ttrpg/main.tf index b8fac8b..7fe16e5 100644 --- a/templates/ttrpg/main.tf +++ b/templates/ttrpg/main.tf @@ -11,7 +11,7 @@ terraform { locals { env_name = "TTRPG & Lore Building" - profile = jsondecode(file("${path.module}/../../profile-templates/TTRPG.code-profile")) + profile = jsondecode(file("${path.module}/profile.code-profile")) settings_raw = jsondecode(local.profile.settings).settings extensions = [for e in jsondecode(local.profile.extensions) : e.identifier.id] } @@ -243,7 +243,7 @@ resource "coder_script" "apply_settings" { # Drops the shared CLI setup wizard onto the workspace and hooks it into # every new interactive shell (via .bashrc) until the user completes it. -# See ../../scripts/cli-setup-wizard.sh for what it actually asks. +# See ./cli-setup-wizard.sh for what it actually asks. resource "coder_script" "cli_setup_wizard" { agent_id = coder_agent.main.id display_name = "Install CLI Setup Wizard" @@ -252,7 +252,7 @@ resource "coder_script" "cli_setup_wizard" { #!/bin/bash set -e mkdir -p /opt/coder - echo '${base64encode(file("${path.module}/../../scripts/cli-setup-wizard.sh"))}' | base64 -d > /opt/coder/cli-setup-wizard.sh + echo '${base64encode(file("${path.module}/cli-setup-wizard.sh"))}' | base64 -d > /opt/coder/cli-setup-wizard.sh chmod +x /opt/coder/cli-setup-wizard.sh MARKER="# >>> coder cli setup wizard >>>" @@ -299,7 +299,7 @@ resource "coder_script" "install_bun" { # Installs this repo's Agent Skills into Claude Code, GitHub Copilot CLI, and # Antigravity CLI's skills directories, plus the foundryvtt-modding and # ttrpg-lore-weaver skills from extensions/custom-specialty-plugin. -# See ../../scripts/install-skills.sh. +# See ./install-skills.sh. resource "coder_script" "install_skills" { agent_id = coder_agent.main.id display_name = "Install Agent Skills" @@ -308,7 +308,7 @@ resource "coder_script" "install_skills" { #!/bin/bash set -e mkdir -p /opt/coder - echo '${base64encode(file("${path.module}/../../scripts/install-skills.sh"))}' | base64 -d > /opt/coder/install-skills.sh + echo '${base64encode(file("${path.module}/install-skills.sh"))}' | base64 -d > /opt/coder/install-skills.sh chmod +x /opt/coder/install-skills.sh SPECIALTY_SKILLS="foundryvtt-modding ttrpg-lore-weaver" /opt/coder/install-skills.sh EOT diff --git a/profile-templates/TTRPG.code-profile b/templates/ttrpg/profile.code-profile similarity index 100% rename from profile-templates/TTRPG.code-profile rename to templates/ttrpg/profile.code-profile diff --git a/templates/web/cli-setup-wizard.sh b/templates/web/cli-setup-wizard.sh new file mode 100644 index 0000000..20fc6ef --- /dev/null +++ b/templates/web/cli-setup-wizard.sh @@ -0,0 +1,107 @@ +#!/usr/bin/env bash +# Coder workspace first-run CLI setup wizard. +# +# Meant to be `source`d from a new interactive shell (e.g. via .bashrc). It asks, +# once per user per workspace, whether to install and log into a few optional +# AI coding CLIs. It re-runs on every new terminal until the user lets it finish +# (or explicitly skips it for good), then gets out of the way. +# +# VS Code / code-server extensions are intentionally NOT asked about here - +# they're installed declaratively by the Coder template itself (the +# `code-server` module's `extensions` input, populated from the matching +# profile-templates/*.code-profile file at template-push time). +# +# Manual re-run: bash /opt/coder/cli-setup-wizard.sh --force + +set -u + +WIZARD_DONE_FILE="${HOME}/.cache/coder-cli-wizard/done" +FORCE=0 +[ "${1:-}" = "--force" ] && FORCE=1 + +export BUN_INSTALL="${HOME}/.bun" +export PATH="${BUN_INSTALL}/bin:${HOME}/.local/bin:${PATH}" + +# Only bother interactive shells with a real terminal attached, and only until +# the user marks the wizard as done. +if [ "$FORCE" -ne 1 ]; then + case "$-" in + *i*) : ;; + *) return 0 2>/dev/null || exit 0 ;; + esac + [ -t 0 ] || { return 0 2>/dev/null || exit 0; } + [ -f "$WIZARD_DONE_FILE" ] && { return 0 2>/dev/null || exit 0; } +fi + +mkdir -p "$(dirname "$WIZARD_DONE_FILE")" + +ask_yes_no() { + local prompt="$1" reply + read -r -p "$prompt [y/N] " reply + case "$reply" in + [Yy]*) return 0 ;; + *) return 1 ;; + esac +} + +echo "" +echo "===================================================================" +echo " Coder workspace setup wizard" +echo " Runs once per new terminal until you finish it. Ctrl+C any time" +echo " to skip for now - it'll ask again next terminal." +echo "===================================================================" + +# --- GitHub Copilot CLI --- +if command -v copilot >/dev/null 2>&1; then + echo "GitHub Copilot CLI already installed, skipping." +elif command -v bun >/dev/null 2>&1; then + if ask_yes_no "Install GitHub Copilot CLI and log in?"; then + if bun install -g @github/copilot; then + copilot login || echo "Install succeeded but login didn't complete. Retry any time with: copilot login" + else + echo "Copilot CLI install failed. Retry later with: bun install -g @github/copilot && copilot login" + fi + fi +else + echo "Skipping GitHub Copilot CLI: bun not found on this workspace image." +fi + +# --- Google Antigravity CLI (agy) --- +if command -v agy >/dev/null 2>&1; then + echo "Antigravity CLI already installed, skipping." +else + if ask_yes_no "Install Google Antigravity CLI (agy) and log in?"; then + if curl -fsSL https://antigravity.google/cli/install.sh | bash; then + echo "Launching 'agy' once to complete sign-in (exit with /logout or Ctrl+D when done)..." + agy || echo "Sign-in didn't complete. Retry any time by running: agy" + else + echo "Antigravity CLI install failed. Retry later with: curl -fsSL https://antigravity.google/cli/install.sh | bash" + fi + fi +fi + +# --- Claude Code CLI --- +if command -v claude >/dev/null 2>&1; then + echo "Claude Code CLI already installed, skipping." +elif command -v bun >/dev/null 2>&1; then + if ask_yes_no "Install Claude Code CLI and log in?"; then + if bun install -g @anthropic-ai/claude-code; then + echo "Launching 'claude' once to complete sign-in (use /login if not prompted; Ctrl+C to exit when done)..." + claude || echo "Sign-in didn't complete. Retry any time by running: claude" + else + echo "Claude Code CLI install failed. Retry later with: bun install -g @anthropic-ai/claude-code" + fi + fi +else + echo "Skipping Claude Code CLI: bun not found on this workspace image." +fi + +echo "" +if ask_yes_no "Mark setup wizard as complete so it stops asking on new terminals?"; then + touch "$WIZARD_DONE_FILE" + echo "Done. Re-run any time with: bash /opt/coder/cli-setup-wizard.sh --force" +else + echo "OK, this'll ask again next time you open a terminal." +fi + +return 0 2>/dev/null || exit 0 diff --git a/templates/web/install-skills.sh b/templates/web/install-skills.sh new file mode 100644 index 0000000..f7d82cd --- /dev/null +++ b/templates/web/install-skills.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash +# Installs this repo's Agent Skills (extensions/{awesome-skills-plugin, +# custom-specialty-plugin}/skills/*, each a SKILL.md-based skill directory) +# into every AI CLI's personal skills directory: +# +# Claude Code CLI -> ~/.claude/skills// +# GitHub Copilot CLI -> ~/.copilot/skills// +# Antigravity CLI -> ~/.gemini/config/skills// (per antigravity.google/docs/skills; +# worth a spot-check if agy doesn't pick these up, some third-party +# docs disagree on the exact path) +# +# Run once at workspace startup via coder_script. Pulls this repo fresh from +# Gitea rather than embedding ~2.5MB of skill files into Terraform state. +# +# Env vars: +# SPECIALTY_SKILLS - optional space-separated skill names from +# extensions/custom-specialty-plugin/skills/ to install in addition to +# the common awesome-skills-plugin bundle (every env gets that one). + +set -e + +REPO_ZIP_URL="https://git.octoturge.com/octoturge/Profiles-for-Coder/archive/main.zip" +ZIP_PATH="/tmp/coder-skills-src.zip" +WORK_DIR="/tmp/coder-skills-src" + +rm -rf "$WORK_DIR" "$ZIP_PATH" +curl -fsSL "$REPO_ZIP_URL" -o "$ZIP_PATH" +mkdir -p "$WORK_DIR" +unzip -q -o "$ZIP_PATH" -d "$WORK_DIR" + +INNER_DIR=$(find "$WORK_DIR" -mindepth 1 -maxdepth 1 -type d | head -n1) +if [ -z "$INNER_DIR" ]; then + echo "install-skills: couldn't find extracted repo contents, skipping." >&2 + rm -rf "$WORK_DIR" "$ZIP_PATH" + exit 0 +fi + +TARGET_DIRS=("$HOME/.claude/skills" "$HOME/.copilot/skills" "$HOME/.gemini/config/skills") +for dir in "${TARGET_DIRS[@]}"; do + mkdir -p "$dir" +done + +# Common skill bundle, installed for every environment. +COMMON_SKILLS_SRC="$INNER_DIR/extensions/awesome-skills-plugin/skills" +if [ -d "$COMMON_SKILLS_SRC" ]; then + for dir in "${TARGET_DIRS[@]}"; do + cp -r "$COMMON_SKILLS_SRC/." "$dir/" + done + echo "install-skills: installed common skill bundle into ${TARGET_DIRS[*]}" +else + echo "install-skills: common skill bundle not found at $COMMON_SKILLS_SRC, skipping." >&2 +fi + +# Environment-specific specialty skills, if any were requested. +for skill in ${SPECIALTY_SKILLS:-}; do + SRC="$INNER_DIR/extensions/custom-specialty-plugin/skills/$skill" + if [ -d "$SRC" ]; then + for dir in "${TARGET_DIRS[@]}"; do + cp -r "$SRC" "$dir/$skill" + done + echo "install-skills: installed specialty skill '$skill'" + else + echo "install-skills: specialty skill '$skill' not found at $SRC, skipping." >&2 + fi +done + +rm -rf "$WORK_DIR" "$ZIP_PATH" +echo "install-skills: done." diff --git a/templates/web/main.tf b/templates/web/main.tf index 991cd99..855438d 100644 --- a/templates/web/main.tf +++ b/templates/web/main.tf @@ -11,7 +11,7 @@ terraform { locals { env_name = "Web Applications" - profile = jsondecode(file("${path.module}/../../profile-templates/Web.code-profile")) + profile = jsondecode(file("${path.module}/profile.code-profile")) settings_raw = jsondecode(local.profile.settings).settings extensions = [for e in jsondecode(local.profile.extensions) : e.identifier.id] } @@ -243,7 +243,7 @@ resource "coder_script" "apply_settings" { # Drops the shared CLI setup wizard onto the workspace and hooks it into # every new interactive shell (via .bashrc) until the user completes it. -# See ../../scripts/cli-setup-wizard.sh for what it actually asks. +# See ./cli-setup-wizard.sh for what it actually asks. resource "coder_script" "cli_setup_wizard" { agent_id = coder_agent.main.id display_name = "Install CLI Setup Wizard" @@ -252,7 +252,7 @@ resource "coder_script" "cli_setup_wizard" { #!/bin/bash set -e mkdir -p /opt/coder - echo '${base64encode(file("${path.module}/../../scripts/cli-setup-wizard.sh"))}' | base64 -d > /opt/coder/cli-setup-wizard.sh + echo '${base64encode(file("${path.module}/cli-setup-wizard.sh"))}' | base64 -d > /opt/coder/cli-setup-wizard.sh chmod +x /opt/coder/cli-setup-wizard.sh MARKER="# >>> coder cli setup wizard >>>" @@ -297,7 +297,7 @@ resource "coder_script" "install_bun" { } # Installs this repo's Agent Skills into Claude Code, GitHub Copilot CLI, and -# Antigravity CLI's skills directories. See ../../scripts/install-skills.sh. +# Antigravity CLI's skills directories. See ./install-skills.sh. # Web has no matching entry in extensions/custom-specialty-plugin/skills, # so it only gets the common awesome-skills-plugin bundle. resource "coder_script" "install_skills" { @@ -308,7 +308,7 @@ resource "coder_script" "install_skills" { #!/bin/bash set -e mkdir -p /opt/coder - echo '${base64encode(file("${path.module}/../../scripts/install-skills.sh"))}' | base64 -d > /opt/coder/install-skills.sh + echo '${base64encode(file("${path.module}/install-skills.sh"))}' | base64 -d > /opt/coder/install-skills.sh chmod +x /opt/coder/install-skills.sh SPECIALTY_SKILLS="" /opt/coder/install-skills.sh EOT diff --git a/profile-templates/Web.code-profile b/templates/web/profile.code-profile similarity index 100% rename from profile-templates/Web.code-profile rename to templates/web/profile.code-profile