@computesdk/cli 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/bootstrap.sh +164 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +1281 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 computesdk
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/bootstrap.sh
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
#
|
|
3
|
+
# Bootstrap script for compute workspace
|
|
4
|
+
# Runs inside sandbox to set up git, gh CLI, and worktree
|
|
5
|
+
#
|
|
6
|
+
# Usage: ./bootstrap.sh <repo> <branch> [optional: github_token]
|
|
7
|
+
#
|
|
8
|
+
# Example: ./bootstrap.sh lodash/lodash fix-auth
|
|
9
|
+
|
|
10
|
+
set -e
|
|
11
|
+
|
|
12
|
+
REPO="${1:-}"
|
|
13
|
+
BRANCH="${2:-}"
|
|
14
|
+
GITHUB_TOKEN="${3:-${GITHUB_TOKEN:-}}"
|
|
15
|
+
REPO_NAME=$(basename "$REPO")
|
|
16
|
+
WORKTREE_DIR="/workspaces/${REPO_NAME}-${BRANCH}"
|
|
17
|
+
REPO_DIR="/workspaces/${REPO_NAME}"
|
|
18
|
+
|
|
19
|
+
# Colors for output
|
|
20
|
+
RED='\033[0;31m'
|
|
21
|
+
GREEN='\033[0;32m'
|
|
22
|
+
YELLOW='\033[1;33m'
|
|
23
|
+
NC='\033[0m' # No Color
|
|
24
|
+
|
|
25
|
+
log() {
|
|
26
|
+
echo -e "${GREEN}[bootstrap]${NC} $1"
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
warn() {
|
|
30
|
+
echo -e "${YELLOW}[bootstrap]${NC} $1"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
error() {
|
|
34
|
+
echo -e "${RED}[bootstrap]${NC} $1" >&2
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
# Validate inputs
|
|
38
|
+
if [ -z "$REPO" ] || [ -z "$BRANCH" ]; then
|
|
39
|
+
error "Usage: $0 <owner/repo> <branch>"
|
|
40
|
+
exit 1
|
|
41
|
+
fi
|
|
42
|
+
|
|
43
|
+
# Ensure /workspaces exists
|
|
44
|
+
mkdir -p /workspaces
|
|
45
|
+
|
|
46
|
+
# Install gh CLI if not present
|
|
47
|
+
if ! command -v gh &> /dev/null; then
|
|
48
|
+
log "Installing GitHub CLI..."
|
|
49
|
+
|
|
50
|
+
# Detect architecture
|
|
51
|
+
ARCH=$(uname -m)
|
|
52
|
+
case $ARCH in
|
|
53
|
+
x86_64) GH_ARCH="amd64" ;;
|
|
54
|
+
aarch64|arm64) GH_ARCH="arm64" ;;
|
|
55
|
+
*) error "Unsupported architecture: $ARCH"; exit 1 ;;
|
|
56
|
+
esac
|
|
57
|
+
|
|
58
|
+
# Download and install
|
|
59
|
+
GH_VERSION=$(curl -s https://api.github.com/repos/cli/cli/releases/latest | grep '"tag_name"' | cut -d'"' -f4)
|
|
60
|
+
GH_VERSION=${GH_VERSION#v} # Remove 'v' prefix
|
|
61
|
+
|
|
62
|
+
curl -fsSL "https://github.com/cli/cli/releases/download/v${GH_VERSION}/gh_${GH_VERSION}_linux_${GH_ARCH}.tar.gz" | tar -xz -C /tmp
|
|
63
|
+
sudo mv /tmp/gh_${GH_VERSION}_linux_${GH_ARCH}/bin/gh /usr/local/bin/
|
|
64
|
+
sudo chmod +x /usr/local/bin/gh
|
|
65
|
+
rm -rf /tmp/gh_${GH_VERSION}_linux_${GH_ARCH}
|
|
66
|
+
|
|
67
|
+
log "GitHub CLI installed: $(gh --version | head -1)"
|
|
68
|
+
fi
|
|
69
|
+
|
|
70
|
+
# Handle GitHub authentication
|
|
71
|
+
if [ -n "$GITHUB_TOKEN" ]; then
|
|
72
|
+
# Use provided token
|
|
73
|
+
log "Using provided GitHub token..."
|
|
74
|
+
echo "$GITHUB_TOKEN" | gh auth login --with-token
|
|
75
|
+
elif ! gh auth status &> /dev/null; then
|
|
76
|
+
# No token, no existing auth - use device flow
|
|
77
|
+
warn "No GitHub credentials found"
|
|
78
|
+
echo ""
|
|
79
|
+
echo "╔════════════════════════════════════════════════════════════╗"
|
|
80
|
+
echo "║ Please authenticate with GitHub ║"
|
|
81
|
+
echo "╚════════════════════════════════════════════════════════════╝"
|
|
82
|
+
echo ""
|
|
83
|
+
|
|
84
|
+
# Start device flow in background and capture output
|
|
85
|
+
TMPFILE=$(mktemp)
|
|
86
|
+
gh auth login --scopes repo,workflow --method device 2>&1 | tee "$TMPFILE" &
|
|
87
|
+
AUTH_PID=$!
|
|
88
|
+
|
|
89
|
+
# Monitor for device code
|
|
90
|
+
for i in {1..60}; do
|
|
91
|
+
if grep -q "First copy your one-time code" "$TMPFILE" 2>/dev/null; then
|
|
92
|
+
CODE=$(grep -o '[A-Z0-9]\{4\}-[A-Z0-9]\{4\}' "$TMPFILE" | head -1)
|
|
93
|
+
if [ -n "$CODE" ]; then
|
|
94
|
+
echo ""
|
|
95
|
+
echo "Your one-time code: ${YELLOW}${CODE}${NC}"
|
|
96
|
+
echo "Visit: https://github.com/device"
|
|
97
|
+
echo ""
|
|
98
|
+
break
|
|
99
|
+
fi
|
|
100
|
+
fi
|
|
101
|
+
sleep 1
|
|
102
|
+
done
|
|
103
|
+
|
|
104
|
+
# Wait for auth to complete
|
|
105
|
+
wait $AUTH_PID || true
|
|
106
|
+
rm -f "$TMPFILE"
|
|
107
|
+
|
|
108
|
+
if ! gh auth status &> /dev/null; then
|
|
109
|
+
error "GitHub authentication failed or timed out"
|
|
110
|
+
exit 1
|
|
111
|
+
fi
|
|
112
|
+
|
|
113
|
+
USER=$(gh api user -q .login 2>/dev/null || echo "unknown")
|
|
114
|
+
log "Authenticated as @${USER}"
|
|
115
|
+
else
|
|
116
|
+
USER=$(gh api user -q .login 2>/dev/null || echo "unknown")
|
|
117
|
+
log "Using existing GitHub auth (@${USER})"
|
|
118
|
+
fi
|
|
119
|
+
|
|
120
|
+
# Clone repo if not exists
|
|
121
|
+
if [ ! -d "$REPO_DIR/.git" ]; then
|
|
122
|
+
log "Cloning ${REPO}..."
|
|
123
|
+
gh repo clone "$REPO" "$REPO_DIR"
|
|
124
|
+
log "Cloned to ${REPO_DIR}"
|
|
125
|
+
else
|
|
126
|
+
log "Repo already cloned at ${REPO_DIR}, fetching updates..."
|
|
127
|
+
cd "$REPO_DIR"
|
|
128
|
+
git fetch origin
|
|
129
|
+
fi
|
|
130
|
+
|
|
131
|
+
# Create worktree
|
|
132
|
+
cd "$REPO_DIR"
|
|
133
|
+
|
|
134
|
+
if git worktree list | grep -q "$WORKTREE_DIR"; then
|
|
135
|
+
warn "Worktree for ${BRANCH} already exists at ${WORKTREE_DIR}"
|
|
136
|
+
else
|
|
137
|
+
# Check if branch exists locally or remotely
|
|
138
|
+
if git show-ref --verify --quiet "refs/heads/${BRANCH}"; then
|
|
139
|
+
log "Creating worktree for existing branch: ${BRANCH}"
|
|
140
|
+
git worktree add "$WORKTREE_DIR" "$BRANCH"
|
|
141
|
+
elif git ls-remote --exit-code origin "$BRANCH" &> /dev/null; then
|
|
142
|
+
log "Creating worktree for remote branch: ${BRANCH}"
|
|
143
|
+
git worktree add --track -b "$BRANCH" "$WORKTREE_DIR" "origin/${BRANCH}"
|
|
144
|
+
else
|
|
145
|
+
log "Creating new branch and worktree: ${BRANCH}"
|
|
146
|
+
git worktree add -b "$BRANCH" "$WORKTREE_DIR"
|
|
147
|
+
fi
|
|
148
|
+
|
|
149
|
+
log "Worktree created: ${WORKTREE_DIR}"
|
|
150
|
+
fi
|
|
151
|
+
|
|
152
|
+
# Output workspace info for the CLI to parse
|
|
153
|
+
echo ""
|
|
154
|
+
echo "{"
|
|
155
|
+
echo ' "status": "ready",'
|
|
156
|
+
echo " \"repo\": \"${REPO}\","
|
|
157
|
+
echo " \"branch\": \"${BRANCH}\","
|
|
158
|
+
echo " \"worktree_path\": \"${WORKTREE_DIR}\","
|
|
159
|
+
echo " \"repo_path\": \"${REPO_DIR}\","
|
|
160
|
+
echo " \"user\": \"$(gh api user -q .login 2>/dev/null || echo '')\""
|
|
161
|
+
echo "}"
|
|
162
|
+
|
|
163
|
+
log "Bootstrap complete!"
|
|
164
|
+
exit 0
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @computesdk/cli
|
|
3
|
+
*
|
|
4
|
+
* ComputeSDK CLI - Cloud-native workspace management.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* compute # interactive workspace creation
|
|
8
|
+
* compute owner/repo # create workspace for repo
|
|
9
|
+
* compute --repo owner/repo --branch fix-auth
|
|
10
|
+
* compute workspace # manage existing workspaces
|
|
11
|
+
* compute exec <id> <cmd...> # run command in sandbox
|
|
12
|
+
* compute connect <id> # interactive shell
|
|
13
|
+
* compute destroy <id...> # destroy sandboxes
|
|
14
|
+
* compute run -- <cmd...> # create + exec + optional destroy
|
|
15
|
+
* compute providers # list configured providers
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
declare function shellEscape(arg: string): string;
|
|
19
|
+
|
|
20
|
+
export { shellEscape };
|