Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .codesignal/run_solution.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
# BASE-TASK CONTENT: the base task's .codesignal/run_solution.sh. It is not run from this repository.
# Cosmo reads this script's STDOUT and nothing else: the report of the learner's workflow and runs.
#
# setup.sh keeps running (it serves the editor), so wait for its marker rather than for it to finish.
cd /usercode/FILESYSTEM/agentflow || exit 1
if [ ! -f /tmp/agentflow-release-ready ]; then
echo "AgentFlow is not ready: it is still starting, or its setup failed. Wait a few seconds and run again; if this repeats, reset the session."
exit 1
fi
PROJECT_ROOT=/usercode/FILESYSTEM/agentflow node apps/server/dist/report.cjs
55 changes: 55 additions & 0 deletions .codesignal/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/sh
# BASE-TASK CONTENT: the base task's .codesignal/setup.sh. It is not run from this repository.
#
# Downloads the release into agentflow/, adds the models (and the task's starting workflow, if
# any) from .codesignal/agentflow/, and serves the editor on port 3000.
#
# A task changes what the base task provides by shipping its own file at the same path:
# .codesignal/agentflow/config.json the models learners can pick (required)
# .codesignal/agentflow/default-workflow.json the starting canvas (optional)

WORKSPACE=/usercode/FILESYSTEM
APP_DIR="$WORKSPACE/agentflow"
SETTINGS_DIR="$WORKSPACE/.codesignal/agentflow"
READY_MARKER=/tmp/agentflow-release-ready
rm -f "$READY_MARKER"
mkdir -p "$APP_DIR" || exit 1
cd "$APP_DIR" || exit 1

# Production runs the latest release; staging runs the newest build.
RELEASE_URL="https://github.com/CodeSignal/learn_bespoke-agentflow/releases/latest/download/release.tar.gz"
if [ "${APP_ENVIRONMENT:-}" = "staging" ]; then
RELEASE_URL="https://github.com/CodeSignal/learn_bespoke-agentflow/releases/download/prerelease/release.tar.gz"
fi

# Stop on a failed download or unpack rather than start whatever an earlier session left here.
if ! wget -q "$RELEASE_URL" -O release.tar.gz; then
rm -f release.tar.gz
echo "Cannot start AgentFlow: the release could not be downloaded from $RELEASE_URL" >&2
exit 1
fi
if ! tar -xzf release.tar.gz; then
rm -f release.tar.gz
echo "Cannot start AgentFlow: the release could not be unpacked" >&2
exit 1
fi
rm release.tar.gz

# The release ships no models: they come from the base task or the task, every session.
mkdir -p .config
if ! cp "$SETTINGS_DIR/config.json" .config/config.json; then
echo "Cannot start AgentFlow: $SETTINGS_DIR/config.json is missing" >&2
exit 1
fi
if [ -f "$SETTINGS_DIR/default-workflow.json" ]; then
cp "$SETTINGS_DIR/default-workflow.json" .config/default-workflow.json
else
rm -f .config/default-workflow.json
fi
touch "$READY_MARKER"

# The learner's canvas and runs live in agentflow/data/ and survive a return visit.
# Keep the server in the foreground; the platform does not expect this script to return.
export PORT=3000
export PROJECT_ROOT="$APP_DIR"
exec npm run start:prod
94 changes: 94 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Publishes a pre-release for every merge to main.
#
# Each run builds release.tar.gz (npm run pack: bundled server and report, built
# editor, no node_modules), boots it like a session (npm run verify:release),
# publishes it as pre-release v<run number>, and moves the floating `prerelease`
# release to it.
#
# Staging: https://github.com/CodeSignal/learn_bespoke-agentflow/releases/download/prerelease/release.tar.gz
# Production: https://github.com/CodeSignal/learn_bespoke-agentflow/releases/latest/download/release.tar.gz
#
# Production only changes when a tested pre-release is promoted:
# gh release edit vN --prerelease=false --latest

name: Release

on:
push:
branches: [main]
workflow_dispatch:

permissions:
contents: write

# Never cancel: two merges in a row must both publish, in order.
concurrency:
group: release
cancel-in-progress: false

jobs:
release:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: actions/setup-node@v4
with:
node-version: 22.x
cache: npm

- name: Install dependencies
run: npm ci

- name: Test
run: |
npm run lint
npm run typecheck
npm test

- name: Build and pack
run: |
npm run build
npm run pack

- name: Verify the release like a session
run: npm run verify:release

- name: Publish pre-release v${{ github.run_number }}
uses: ncipollo/release-action@v1
with:
tag: v${{ github.run_number }}
commit: ${{ github.sha }}
name: v${{ github.run_number }}
body: Build of ${{ github.sha }}. Promote it with `gh release edit v${{ github.run_number }} --prerelease=false --latest` after a staging test.
artifacts: release.tar.gz
artifactErrorsFailBuild: true
prerelease: true
makeLatest: false

- name: Move the prerelease channel to this build
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: v${{ github.run_number }}
run: |
set -euo pipefail
# Skip if a newer build was published while this run waited in the queue.
newest="$(gh api "repos/${GITHUB_REPOSITORY}/releases" \
--jq '[.[] | select(.draft == false and (.tag_name | test("^v[0-9]+$")))] | map(.tag_name | ltrimstr("v") | tonumber) | max')"
if [ "${newest}" != "${{ github.run_number }}" ]; then
echo "v${newest} is newer than ${TAG}; leaving the prerelease channel alone."
exit 0
fi
git tag -f prerelease "${GITHUB_SHA}"
git push --no-verify -f origin refs/tags/prerelease
notes="Floating channel for staging sessions. Currently ${TAG} (${GITHUB_SHA})."
if gh release view prerelease >/dev/null 2>&1; then
gh release edit prerelease --prerelease --title "Latest pre-release" --notes "${notes}"
gh release upload prerelease release.tar.gz --clobber
else
gh release create prerelease release.tar.gz --prerelease --latest=false \
--title "Latest pre-release" --notes "${notes}"
fi
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ yarn-error.log*

# Scripts
setup.sh
!.codesignal/setup.sh

# Release packing (npm run pack)
release/
release.tar.gz

# Local config
.config/default-workflow.json
Expand Down
3 changes: 3 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Server routes:
- `npm run build`: Build server and web app.
- `npm run build:packages`: Build shared packages.
- `npm run report`: Print the workflow and run report (build the server first).
- `npm run release:local`: Build, pack `release.tar.gz` and boot it like a session (`docs/releases.md`).
- `npm run lint`: Run ESLint.
- `npm run typecheck`: Typecheck every workspace.
- `npm test`: Build shared packages, then run Vitest in the engine, server and web workspaces.
Expand All @@ -52,6 +53,8 @@ Server routes:
## Testing Guidelines

- CI checks in `.github/workflows/pr.yml`: `lint`, `build:packages`, `typecheck`, `test`, `build`.
- `.github/workflows/release.yml` publishes every merge to `main` as pre-release `vN` and moves the `prerelease` channel; promote a tested build to `latest` by hand.
- `.codesignal/` mirrors the session scripts of the CodeSignal base task; it is not run from the repository.
- Every workspace with logic uses Vitest (`npm --workspace <path> run test`). The engine and server suites use a stub LLM; the server's SDK suite runs the real Agents SDK against a scripted model, so no API key is needed.
- Server and package sources are ES modules compiled with `NodeNext`: relative imports need a `.js` extension.
- Prefer targeted `*.test.ts` files near changed behavior.
Expand Down
2 changes: 2 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ npm run lint
npm run typecheck
npm test
npm run report # after npm run build:server
npm run release:local # build, pack release.tar.gz, boot it like a session

npm --workspace apps/web run test
npm --workspace apps/server run test
Expand Down Expand Up @@ -112,6 +113,7 @@ git submodule update --init --recursive
- `docs/workflow-semantics.md`
- `docs/run-persistence.md`
- `docs/report.md`
- `docs/releases.md`
- `docs/configuration.md`
- `docs/troubleshooting.md`
- `apps/web/docs/run-readiness.md`
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ npm run dev
| `npm run build` | Build server and web app. |
| `npm run build:packages` | Build `packages/types`, `packages/workflow-graph` and `packages/workflow-engine`. |
| `npm run report` | Print the workflow and run report (after `npm run build:server`; see [Report](./docs/report.md)). |
| `npm run release:local` | Build, pack `release.tar.gz` and boot it like a session (see [Releases and Sessions](./docs/releases.md)). |
| `npm run typecheck` | Typecheck every workspace. |
| `npm run lint` | ESLint across repo TypeScript files. |
| `npm test` | Build shared packages, then run the Vitest suites of the engine, server and web app. |
Expand All @@ -70,6 +71,7 @@ npm run dev
- [Workflow Semantics](./docs/workflow-semantics.md)
- [Run Persistence and Recovery](./docs/run-persistence.md)
- [Report](./docs/report.md)
- [Releases and Sessions](./docs/releases.md)
- [Configuration](./docs/configuration.md)
- [Troubleshooting](./docs/troubleshooting.md)
- [Web Run Readiness Rules](./apps/web/docs/run-readiness.md)
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [Workflow Semantics](./workflow-semantics.md)
- [Run Persistence and Recovery](./run-persistence.md)
- [Report](./report.md)
- [Releases and Sessions](./releases.md)
- [Configuration](./configuration.md)
- [Troubleshooting](./troubleshooting.md)
- [Web Run Readiness](../apps/web/docs/run-readiness.md)
51 changes: 51 additions & 0 deletions docs/releases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Releases and Sessions

A CodeSignal session never clones this repository or runs `npm install`. It downloads a release, adds the task's models, and starts the server on port 3000.

## The release

`npm run pack` (after `npm run build`) writes `release.tar.gz`:

| Path | What it is |
| --- | --- |
| `package.json` | `start:prod` (the server) and `report` scripts |
| `apps/server/dist/index.cjs` | the server, bundled with its dependencies by esbuild |
| `apps/server/dist/report.cjs` | the report for the grader (`npm run report`), bundled |
| `apps/web/dist/` | the built editor, with the design system |

It holds no `node_modules` and no `.config/`: the models and the starting workflow come from the session, so unpacking a release never overwrites them.

`npm run verify:release` boots the tarball the way a session does: it unpacks it into an empty directory, adds `.config/config.json`, starts the server without API keys, saves a canvas, runs a Start → Approval workflow (which needs no model) and checks the report. `npm run release:local` builds, packs and verifies in one go.

## Channels

`.github/workflows/release.yml` runs on every merge to `main`: lint, typecheck, tests, build, pack, verify, then it publishes pre-release `v<run number>` and moves the floating `prerelease` release to it.

| Channel | URL |
| --- | --- |
| Staging | `https://github.com/CodeSignal/learn_bespoke-agentflow/releases/download/prerelease/release.tar.gz` |
| Production | `https://github.com/CodeSignal/learn_bespoke-agentflow/releases/latest/download/release.tar.gz` |

Production only changes when a pre-release has passed a staging test and is promoted:

```bash
gh release edit vN -R CodeSignal/learn_bespoke-agentflow --prerelease=false --latest
```

## Session scripts

The scripts the session runs belong to the base task; copies are kept in [`.codesignal/`](../.codesignal) so a change to the release layout and to the scripts land together.

| Base-task file | Runs on | Job |
| --- | --- | --- |
| `.codesignal/setup.sh` | session start | download the release into `agentflow/` (`prerelease` when `APP_ENVIRONMENT=staging`, else `latest`), copy the models and starting workflow, serve on port 3000 |
| `.codesignal/run_solution.sh` | Run | print the report to STDOUT for the grader |
| `main.sh` | Run | `bash .codesignal/run_solution.sh` |
| `.codesignal/agentflow/config.json` | session start | the models learners can pick ([Configuration](./configuration.md)) |
| `.codesignal/agentflow/default-workflow.json` | session start | optional starting canvas |

A task overrides the base task's models or starting workflow by shipping its own file at the same path. `setup.sh` copies them into `agentflow/.config/` on every start, so a changed file applies from the next session.

The learner's canvas and runs are written to `agentflow/data/`, which the session saves, so they survive a return visit. Run records count toward the session's save budget; retention keeps the newest 20.

Every model in `config.json` must also be allowed by the LLM proxy the session uses, and the proxy must provide a key for each provider in the file (`OPENAI_API_KEY` and `OPENAI_BASE_URL` for OpenAI, `ANTHROPIC_API_KEY` and `ANTHROPIC_BASE_URL` for Anthropic). The SDKs read the base URLs from the environment when the provider sets no `baseUrl`.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"build:packages": "npm --workspace packages/types run build && npm --workspace packages/workflow-graph run build && npm --workspace packages/workflow-engine run build",
"build:server": "npm run build:packages && npm --workspace apps/server run build",
"build:web": "npm --workspace apps/web run build",
"pack": "node scripts/pack-release.mjs",
"verify:release": "node scripts/verify-release.mjs",
"release:local": "npm run build && npm run pack && npm run verify:release",
"test": "npm run build:packages && npm run test --workspaces --if-present",
"clean": "npm run clean --workspaces",
"lint": "eslint .",
Expand All @@ -26,6 +29,7 @@
"@types/node": "^26.6.6",
"@typescript-eslint/eslint-plugin": "^8.73.0",
"@typescript-eslint/parser": "^8.73.0",
"esbuild": "^0.28.2",
"eslint": "^10.15.0",
"tsx": "^4.23.15",
"typescript": "^6.0.3",
Expand Down
Loading
Loading