-
Notifications
You must be signed in to change notification settings - Fork 126
feat(coder-labs/modules/copilot): agentapi state persistence and maintenance #799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c61c6fd
45d3d8e
b5e7968
d6b490e
496c29d
236c1cc
9e827d5
2d8699b
c709541
70f4d62
90fe6a5
f73c20a
aa6c429
88ddf34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,9 @@ | ||
| #!/bin/bash | ||
|
|
||
| if [ -f "$HOME/.bashrc" ]; then | ||
| source "$HOME"/.bashrc | ||
| fi | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| export PATH="$HOME/.local/bin:$PATH" | ||
|
|
||
| command_exists() { | ||
| command -v "$1" > /dev/null 2>&1 | ||
| } | ||
|
|
@@ -19,34 +17,13 @@ ARG_EXTERNAL_AUTH_ID=${ARG_EXTERNAL_AUTH_ID:-github} | |
| ARG_COPILOT_VERSION=${ARG_COPILOT_VERSION:-0.0.334} | ||
| ARG_COPILOT_MODEL=${ARG_COPILOT_MODEL:-claude-sonnet-4.5} | ||
|
|
||
| validate_prerequisites() { | ||
| if ! command_exists node; then | ||
| echo "ERROR: Node.js not found. Copilot requires Node.js v22+." | ||
| echo "Install with: curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash - && sudo apt-get install -y nodejs" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if ! command_exists npm; then | ||
| echo "ERROR: npm not found. Copilot requires npm v10+." | ||
| exit 1 | ||
| fi | ||
|
|
||
| node_version=$(node --version | sed 's/v//' | cut -d. -f1) | ||
| if [ "$node_version" -lt 22 ]; then | ||
| echo "WARNING: Node.js v$node_version detected. Copilot requires v22+." | ||
| fi | ||
| } | ||
|
|
||
| install_copilot() { | ||
| if ! command_exists copilot; then | ||
| echo "Installing GitHub Copilot CLI (version: ${ARG_COPILOT_VERSION})..." | ||
| if [ "$ARG_COPILOT_VERSION" = "latest" ]; then | ||
| npm install -g @github/copilot | ||
| else | ||
| npm install -g "@github/copilot@${ARG_COPILOT_VERSION}" | ||
| fi | ||
| curl -fsSL https://gh.io/copilot-install | VERSION="${ARG_COPILOT_VERSION}" bash | ||
|
|
||
| if ! command_exists copilot; then | ||
| echo "PATH after installation: $PATH" | ||
| echo "ERROR: Failed to install Copilot" | ||
| exit 1 | ||
| fi | ||
|
|
@@ -95,7 +72,7 @@ setup_copilot_configurations() { | |
| } | ||
|
|
||
| setup_copilot_config() { | ||
| export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}" | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DevelopmentCats I changed the paths here, any reason why we'd want to keep it as $HOME/.config ?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, we have had a lot of modules that store their configuration, and logs in random places like the home root, or /tmp. There has been a push to normalize this across all modules. so you are probably fine to just leave as is and I will take care of it in another PR |
||
| export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME}" | ||
| local copilot_config_dir="$XDG_CONFIG_HOME/.copilot" | ||
| local copilot_config_file="$copilot_config_dir/config.json" | ||
| local mcp_config_file="$copilot_config_dir/mcp-config.json" | ||
|
|
@@ -190,27 +167,15 @@ add_custom_mcp_servers() { | |
| local updated_config | ||
| updated_config=$(jq --argjson custom "$custom_servers" '.mcpServers += $custom' "$mcp_config_file") | ||
| echo "$updated_config" > "$mcp_config_file" | ||
| elif command_exists node; then | ||
| node -e " | ||
| const fs = require('fs'); | ||
| const existing = JSON.parse(fs.readFileSync('$mcp_config_file', 'utf8')); | ||
| const input = JSON.parse(\`$ARG_MCP_CONFIG\`); | ||
| const custom = input.mcpServers || {}; | ||
| existing.mcpServers = {...existing.mcpServers, ...custom}; | ||
| fs.writeFileSync('$mcp_config_file', JSON.stringify(existing, null, 2)); | ||
| " | ||
| else | ||
| echo "WARNING: jq and node not available, cannot merge custom MCP servers" | ||
| echo "WARNING: jq not available, cannot merge custom MCP servers" | ||
| fi | ||
| } | ||
|
|
||
| configure_copilot_model() { | ||
| if [ -n "$ARG_COPILOT_MODEL" ] && [ "$ARG_COPILOT_MODEL" != "claude-sonnet-4.5" ]; then | ||
| echo "Setting Copilot model to: $ARG_COPILOT_MODEL" | ||
| copilot config model "$ARG_COPILOT_MODEL" || { | ||
| echo "WARNING: Failed to set model via copilot config, will use environment variable fallback" | ||
| export COPILOT_MODEL="$ARG_COPILOT_MODEL" | ||
| } | ||
| if [[ -n "${ARG_COPILOT_MODEL}" ]]; then | ||
| echo "Setting Copilot model to: ${ARG_COPILOT_MODEL}" | ||
| export COPILOT_MODEL="${ARG_COPILOT_MODEL}" | ||
| fi | ||
| } | ||
|
|
||
|
|
@@ -227,7 +192,6 @@ configure_coder_integration() { | |
| fi | ||
| } | ||
|
|
||
| validate_prerequisites | ||
| install_copilot | ||
| check_github_authentication | ||
| setup_copilot_configurations | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we not check if it exists before prepending the $PATH?