microsoft/TypeAgent

Public

mirrored from https://github.com/microsoft/TypeAgentAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
agents/azure-cli-json-output-format

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

.devcontainer/scripts/post-create.sh

155lines · modecode

1#!/bin/bash
2# Copyright (c) Microsoft Corporation.
3# Licensed under the MIT License.
4
5#
6# TypeAgent DevContainer Post-Create Script
7# Runs once when the container is first created
8#
9
10echo "╔══════════════════════════════════════════════════════════════╗"
11echo "║ TypeAgent DevContainer Setup ║"
12echo "╚══════════════════════════════════════════════════════════════╝"
13echo ""
14
15# Detect environment
16detect_env() {
17 if [[ "$CODESPACES" == "true" ]]; then
18 echo "codespaces"
19 elif [[ -n "$WSL_DISTRO_NAME" ]] || grep -qi "wsl" /proc/version 2>/dev/null; then
20 if [[ -n "$WAYLAND_DISPLAY" ]] || [[ -n "$DISPLAY" ]]; then
21 echo "wsl2-gui"
22 else
23 echo "wsl2"
24 fi
25 else
26 echo "standard"
27 fi
28}
29
30ENV=$(detect_env)
31echo "Environment: $ENV"
32echo ""
33
34# Navigate to TypeScript workspace
35echo "Looking for TypeScript workspace..."
36if [[ -d "/workspaces/TypeAgent/ts" ]]; then
37 cd /workspaces/TypeAgent/ts
38 echo "Found: /workspaces/TypeAgent/ts"
39else
40 # Try glob pattern
41 TS_DIR=$(find /workspaces -maxdepth 2 -type d -name "ts" 2>/dev/null | head -1)
42 if [[ -n "$TS_DIR" ]]; then
43 cd "$TS_DIR"
44 echo "Found: $TS_DIR"
45 else
46 echo "Warning: Could not find ts directory in /workspaces"
47 echo "Listing /workspaces contents:"
48 ls -la /workspaces/ 2>/dev/null || echo " /workspaces not accessible"
49 echo ""
50 echo "Skipping dependency installation. Run manually after container starts:"
51 echo " cd ts && pnpm install"
52 exit 0
53 fi
54fi
55
56# Enable pnpm
57echo ""
58echo "Enabling corepack and pnpm..."
59if command -v corepack &> /dev/null; then
60 corepack enable || echo "Warning: corepack enable failed"
61 corepack prepare pnpm@latest --activate || echo "Warning: corepack prepare failed"
62else
63 echo "Warning: corepack not found, checking for pnpm..."
64 if ! command -v pnpm &> /dev/null; then
65 echo "Installing pnpm via npm..."
66 npm install -g pnpm || { echo "Failed to install pnpm"; exit 1; }
67 fi
68fi
69
70# Verify pnpm is available
71if ! command -v pnpm &> /dev/null; then
72 echo "Error: pnpm is not available after setup"
73 exit 1
74fi
75
76echo "pnpm version: $(pnpm --version)"
77
78# Install dependencies
79echo ""
80echo "Installing pnpm dependencies..."
81echo "This may take a few minutes on first run..."
82pnpm install || {
83 echo ""
84 echo "Warning: pnpm install failed. You may need to run it manually."
85 echo "This is often due to network issues or missing system dependencies."
86}
87
88# Set up git hooks for lock file sync (non-critical)
89echo ""
90echo "Setting up git hooks for dependency synchronization..."
91
92HOOKS_DIR="../.git/hooks"
93if [[ -d "$HOOKS_DIR" ]]; then
94 # Post-checkout hook
95 cat > "$HOOKS_DIR/post-checkout" << 'EOF'
96#!/bin/bash
97PREV_HEAD=$1
98NEW_HEAD=$2
99BRANCH_CHECKOUT=$3
100
101if [ "$BRANCH_CHECKOUT" != "1" ]; then exit 0; fi
102
103LOCKFILE_CHANGED=$(git diff "$PREV_HEAD" "$NEW_HEAD" --name-only 2>/dev/null | grep -c "pnpm-lock.yaml" || true)
104
105if [ "$LOCKFILE_CHANGED" -gt 0 ]; then
106 echo "pnpm-lock.yaml changed. Running pnpm install..."
107 cd ts && pnpm install --frozen-lockfile
108 echo "Dependencies synchronized"
109fi
110EOF
111 chmod +x "$HOOKS_DIR/post-checkout"
112
113 # Post-merge hook
114 cat > "$HOOKS_DIR/post-merge" << 'EOF'
115#!/bin/bash
116LOCKFILE_CHANGED=$(git diff HEAD@{1} HEAD --name-only | grep -c "pnpm-lock.yaml" || true)
117
118if [ "$LOCKFILE_CHANGED" -gt 0 ]; then
119 echo "pnpm-lock.yaml changed after merge. Running pnpm install..."
120 cd ts && pnpm install --frozen-lockfile
121 echo "Dependencies synchronized"
122fi
123EOF
124 chmod +x "$HOOKS_DIR/post-merge"
125
126 echo "Git hooks installed for automatic dependency sync"
127else
128 echo "Note: .git/hooks directory not found, skipping git hooks setup"
129fi
130
131echo ""
132echo "╔══════════════════════════════════════════════════════════════╗"
133echo "║ Setup Complete! ║"
134echo "╚══════════════════════════════════════════════════════════════╝"
135echo ""
136echo "Next steps:"
137echo " cd ts"
138echo " pnpm run build"
139echo ""
140
141case $ENV in
142 wsl2-gui)
143 echo "GUI Support: WSLg detected - 'pnpm run shell' will work!"
144 ;;
145 codespaces)
146 echo "GUI Support: Use VNC at http://localhost:6080"
147 ;;
148 *)
149 echo "GUI Support: For Electron, use hybrid approach:"
150 echo " Container: pnpm run server"
151 echo " Host: pnpm run shell"
152 ;;
153esac
154
155echo ""
156