diff --git a/.devcontainer/.env.example b/.devcontainer/.env.example new file mode 100644 index 000000000..d14211604 --- /dev/null +++ b/.devcontainer/.env.example @@ -0,0 +1,8 @@ +# Copy to .env and fill in your tokens. +# .env is gitignored — secrets stay local. +# +# GITHUB_TOKEN=ghp_... +# GITLAB_TOKEN=glpat-... +# BITBUCKET_TOKEN=... +# BITBUCKET_USERNAME=... +# SKILLSHARE_GIT_TOKEN=... diff --git a/.devcontainer/bin/credential-helper b/.devcontainer/bin/credential-helper new file mode 100755 index 000000000..43b066d65 --- /dev/null +++ b/.devcontainer/bin/credential-helper @@ -0,0 +1,119 @@ +#!/usr/bin/env bash +set -euo pipefail + +BACKUP_FILE="/tmp/.git-credential-helper-backup" +TOKEN_BACKUP="/tmp/.git-token-env-backup" +TOKEN_VARS=(GITHUB_TOKEN GITLAB_TOKEN BITBUCKET_TOKEN BITBUCKET_USERNAME SKILLSHARE_GIT_TOKEN) + +# When called with --eval, output shell commands for the caller to eval. +# Usage: eval "$(credential-helper off)" / eval "$(credential-helper on)" +EVAL_MODE=false +if [ "${1:-}" = "--eval" ]; then + EVAL_MODE=true + shift +fi + +emit() { + if $EVAL_MODE; then + echo "$1" + fi +} + +case "${1:-}" in + off) + # Save current credential helper + current="$(git config --global credential.helper 2>/dev/null || true)" + if [ -n "$current" ] && [ "$current" != "''" ]; then + echo "$current" > "$BACKUP_FILE" + echo "Saved credential.helper: $current" >&2 + fi + git config --global credential.helper '' + echo "credential.helper disabled" >&2 + + # Save and unset token env vars + : > "$TOKEN_BACKUP" + for var in "${TOKEN_VARS[@]}"; do + val="${!var:-}" + if [ -n "$val" ]; then + echo "$var=$val" >> "$TOKEN_BACKUP" + emit "unset $var;" + echo " unset $var" >&2 + fi + done + + if ! $EVAL_MODE; then + # Check if any tokens were active but couldn't be unset + has_tokens=false + for var in "${TOKEN_VARS[@]}"; do + if [ -n "${!var:-}" ]; then has_tokens=true; break; fi + done + if $has_tokens; then + echo "" >&2 + echo "Token env vars detected but cannot be unset from a script." >&2 + echo "Run with eval to also clear tokens:" >&2 + echo " eval \"\$(credential-helper --eval off)\"" >&2 + fi + fi + ;; + on) + # Restore credential helper + if [ -f "$BACKUP_FILE" ]; then + saved="$(cat "$BACKUP_FILE")" + git config --global credential.helper "$saved" + echo "credential.helper restored: $saved" >&2 + else + git config --global --unset credential.helper 2>/dev/null || true + echo "credential.helper unset (system default)" >&2 + fi + + # Restore token env vars + if [ -f "$TOKEN_BACKUP" ]; then + while IFS='=' read -r key val; do + [ -z "$key" ] && continue + emit "export $key='$val';" + echo " restored $key" >&2 + done < "$TOKEN_BACKUP" + rm -f "$TOKEN_BACKUP" + fi + + if ! $EVAL_MODE; then + if [ -f "$TOKEN_BACKUP" ] 2>/dev/null; then + echo "" >&2 + echo "Token backup found. Run with eval to restore tokens:" >&2 + echo " eval \"\$(credential-helper --eval on)\"" >&2 + fi + fi + ;; + status) + current="$(git config --global credential.helper 2>/dev/null || true)" + if [ -z "$current" ]; then + echo "credential.helper: (not set, using system default)" + elif [ "$current" = "''" ]; then + echo "credential.helper: DISABLED" + else + echo "credential.helper: $current" + fi + echo "" + for var in "${TOKEN_VARS[@]}"; do + val="${!var:-}" + if [ -n "$val" ]; then + # Show first 4 chars + mask + masked="${val:0:4}****" + echo "$var: $masked" + else + echo "$var: (not set)" + fi + done + ;; + *) + echo "Usage: eval \"\$(credential-helper --eval )\"" >&2 + echo " credential-helper " >&2 + echo "" >&2 + echo " off Disable all git auth (credential helper + token env vars)" >&2 + echo " on Restore credential helper and token env vars" >&2 + echo " status Show current auth state" >&2 + echo "" >&2 + echo "Use --eval to also unset/restore token env vars in your shell." >&2 + exit 1 + ;; +esac diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 1c400d2dd..9dd8ebece 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -17,7 +17,12 @@ }, "remoteEnv": { "PATH": "/workspace/.devcontainer/bin:/workspace/bin:${containerEnv:PATH}", - "SKILLSHARE_UI_HOST": "0.0.0.0" + "SKILLSHARE_UI_HOST": "0.0.0.0", + "GITHUB_TOKEN": "${localEnv:GITHUB_TOKEN}", + "GITLAB_TOKEN": "${localEnv:GITLAB_TOKEN}", + "BITBUCKET_TOKEN": "${localEnv:BITBUCKET_TOKEN}", + "BITBUCKET_USERNAME": "${localEnv:BITBUCKET_USERNAME}", + "SKILLSHARE_GIT_TOKEN": "${localEnv:SKILLSHARE_GIT_TOKEN}" }, "postCreateCommand": ".devcontainer/setup.sh", "postStartCommand": ".devcontainer/start-dev.sh", diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index 14143910d..6e774670a 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -7,6 +7,9 @@ services: dockerfile: docker/sandbox/Dockerfile working_dir: /workspace command: sleep infinity + env_file: + - path: .env + required: false environment: HOME: /tmp GOCACHE: /go/build-cache diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh index c23721d6c..1bc6f7739 100755 --- a/.devcontainer/setup.sh +++ b/.devcontainer/setup.sh @@ -60,6 +60,11 @@ echo " ui stop # stop dashboard" echo " docs # documentation site → :3000" echo " docs stop # stop docs" echo "" +echo "Private repos:" +echo " credential-helper status # check auth state" +echo " eval \"\$(credential-helper --eval off)\" # disable all auth" +echo " eval \"\$(credential-helper --eval on)\" # restore all auth" +echo "" echo "Audit playground:" echo " ss audit # scan all skills, see findings" echo " cd ~/demo-project && ss audit # project-level scan" diff --git a/.devcontainer/start-dev.sh b/.devcontainer/start-dev.sh index 9e2d2b98c..ae2b54106 100755 --- a/.devcontainer/start-dev.sh +++ b/.devcontainer/start-dev.sh @@ -1,7 +1,17 @@ #!/usr/bin/env bash -# Print available commands on container start. +# Resolve GITHUB_TOKEN and print available commands on container start. set -euo pipefail +# Auto-detect GITHUB_TOKEN from gh CLI if not already set +# (via .env, remoteEnv, or manual export). +if [ -z "${GITHUB_TOKEN:-}" ] && command -v gh &>/dev/null; then + token="$(gh auth token 2>/dev/null || true)" + if [ -n "$token" ]; then + export GITHUB_TOKEN="$token" + echo "GITHUB_TOKEN auto-detected from gh CLI" + fi +fi + echo "Dev servers ready:" echo " ui # global-mode dashboard → :5173" echo " ui -p # project-mode dashboard → :5173" diff --git a/.gitignore b/.gitignore index 3e6d9ba50..f6e1b3a59 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,9 @@ docs/plans/ video/node_modules/ +# Devcontainer secrets +.devcontainer/.env + # Web UI ui/node_modules/ ui/dist/ diff --git a/website/docs/commands/install.md b/website/docs/commands/install.md index dd39a8de7..7ef41e02c 100644 --- a/website/docs/commands/install.md +++ b/website/docs/commands/install.md @@ -317,7 +317,7 @@ skillshare install https://github.com/org/private-skills.git --track |----------|---------|------------| | GitHub | `GITHUB_TOKEN` | Personal access token (`repo` scope) | | GitLab | `GITLAB_TOKEN` | Personal access or CI job token | -| Bitbucket | `BITBUCKET_TOKEN` | Repository token, or app password (with `BITBUCKET_USERNAME` or `https://@...`) | +| Bitbucket | `BITBUCKET_TOKEN` | Repository token, or app password (with `BITBUCKET_USERNAME`) | | Any host | `SKILLSHARE_GIT_TOKEN` | Generic fallback | Platform-specific variables take priority over `SKILLSHARE_GIT_TOKEN`. @@ -364,6 +364,7 @@ install-skills: script: - skillshare install https://bitbucket.org/team/skills.git --track env: + BITBUCKET_USERNAME: $BITBUCKET_USERNAME # for app passwords BITBUCKET_TOKEN: $BITBUCKET_TOKEN ``` diff --git a/website/docs/guides/docker-sandbox.md b/website/docs/guides/docker-sandbox.md index 0b80c2116..142010025 100644 --- a/website/docs/guides/docker-sandbox.md +++ b/website/docs/guides/docker-sandbox.md @@ -326,6 +326,38 @@ docs stop # stop Docusaurus `ui` starts both the Go API backend (port 19420, background) and Vite dev server (port 5173, HMR). Switching between `ui` and `ui -p` automatically restarts the API in the new mode. VS Code auto-forwards ports to your host browser. +### Token configuration + +Tokens for private repo access (`GITHUB_TOKEN`, `GITLAB_TOKEN`, etc.) can come from multiple sources. They are checked in this order: + +| Priority | Source | Setup | +|----------|--------|-------| +| 1 | `.devcontainer/.env` | Copy `.env.example` → `.env`, fill in values (gitignored) | +| 2 | Host env vars | Set in `~/.zshrc` — forwarded via `remoteEnv` in `devcontainer.json` | +| 3 | `gh auth login` | `GITHUB_TOKEN` auto-detected on container start (GitHub only) | + +All sources are optional. You can also use `export` manually inside the container at any time. + +Check current state: + +```bash +credential-helper status +``` + +### Private repo testing + +VS Code Dev Containers automatically forwards your host git credentials into the container. This means `git clone` of private repos may succeed even without explicit token env vars — the forwarded credential helper handles auth silently. + +To disable **all** authentication (credential helper + token env vars) for testing: + +```bash +eval "$(credential-helper --eval off)" # disable everything +eval "$(credential-helper --eval on)" # restore everything +credential-helper status # check current state +``` + +Without `--eval`, only the git credential helper is toggled (token env vars remain active). + ### Running tests ```bash