-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.dev.sh
More file actions
executable file
·61 lines (56 loc) · 2.29 KB
/
Copy pathentrypoint.dev.sh
File metadata and controls
executable file
·61 lines (56 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/sh
# Entrypoint for the dev service: coding-agent server + Next.js dev server
# behind Caddy. The two node processes restart automatically if they exit —
# a broken hot reload should degrade, not kill the container.
set -u
cd /workspace
# Git repo backing the run/publish history shown in the admin console. On the
# very first deploy there is no .git in the build context, so a baseline repo
# is created here. On every publish after that, the workspace (including
# .git) IS the build context, so the accumulated history — one commit per
# successful agent run, one per publish — survives self-redeploys. Done at
# runtime (not build time) so it also works when the source is bind-mounted
# for local development.
if [ ! -d .git ]; then
git init -q -b main
git add -A
git -c user.name="coding-agent" -c user.email="agent@self-improving.local" \
commit -qm "baseline: as deployed"
else
echo "existing git history: $(git rev-list --count HEAD 2>/dev/null || echo 0) commit(s) at $(git rev-parse --short HEAD 2>/dev/null || echo '?')"
fi
# Isolated worktree for the coding agent. It edits and typechecks here; a
# successful run is fast-forwarded into this live tree (see agent/src/git.ts),
# so the Next.js dev server — which watches /workspace/todo-app — never serves a
# half-applied edit. Kept outside /workspace so it stays out of the served tree
# and the publish build context. `prune` first drops the stale registration that
# rides along in .git across a self-redeploy (its directory won't exist in the
# fresh container).
AGENT_WT="${AGENT_WORKTREE_DIR:-/agent-worktree}"
git worktree prune
if [ ! -e "$AGENT_WT/.git" ]; then
rm -rf "$AGENT_WT"
git worktree add -q --detach "$AGENT_WT" HEAD
fi
# tsc in the worktree needs the app's dependencies; share the image's install
# rather than duplicating it (node_modules is gitignored, so it never commits).
if [ ! -e "$AGENT_WT/todo-app/node_modules" ]; then
ln -s /workspace/todo-app/node_modules "$AGENT_WT/todo-app/node_modules"
fi
(
cd agent
while true; do
npm start
echo "agent server exited; restarting in 2s" >&2
sleep 2
done
) &
(
cd todo-app
while true; do
npm run dev -- --port 3001
echo "next dev exited; restarting in 2s" >&2
sleep 2
done
) &
exec caddy run --config /workspace/Caddyfile --adapter caddyfile