fix(init): make the scaffolded starter find the runtime and explain when it can't - #217
Merged
Conversation
The starter `af-stack init <name>` writes assumed the runtime was at
localhost:8080 and, on any failure, printed "Could not reach the
backend" plus a raw response body. Two things made that wrong in
practice: `af-stack dev` moves the API off :8080 whenever the port is
busy (the reporter's :8080 was an AgentField control plane, whose 404
body the starter dumped verbatim), and `npm start` ran plain `node
src/index.mjs`, which never read .env — so the documented `cp
.env.example .env` and "set AF_STACK_URL" did nothing.
The starter now loads .env itself (no dependency; real env wins),
tolerates a pasted ".../api/v1" suffix, and probes /health before the
first call so it can tell the three cases apart: nothing listening,
something listening that is not a BackAI runtime, and an auth
rejection — each with the fix, including where the real URL comes from
("API runtime" in af-stack dev's output). The scaffold's next steps,
README, and .env.example say the same. Tests drive the real file with
node against fake backends for each case.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Abir Abbas <abirabbas1998@gmail.com>
Both "what runs where" banners list the API as ".../api/v1", which is not what an app's AF_STACK_URL wants, and neither said which line to copy when preflight had moved the port. Add "Your apps AF_STACK_URL=http://localhost:<port>" to both. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Signed-off-by: Abir Abbas <abirabbas1998@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #216, from the next thing the reporter hit.
af-stack init my-ai-productthennpm startprinted "Could not reach the backend" followed by a raw AgentField 404 body. Two causes, both in the scaffolded starter:localhost:8080, and could not tell "nothing there" from "something else there".af-stack devdeliberately moves the API off 8080 whenever the port is busy (on the reporter's machine 8080 is an AgentField control plane), but the starter never said where the real URL comes from.npm startnever read.env. It ran plainnode src/index.mjs, so the documentedcp .env.example .envand "setAF_STACK_URL" had no effect at all.Changes
.envitself with no dependency (real environment wins), tolerates a pasted…/api/v1suffix, and probes/healthbefore its first call. It now distinguishes three failures and gives the fix for each: nothing listening, something listening that is not a BackAI runtime, and an auth rejection. Each points at the "API runtime" line ofaf-stack dev's output as the source of the URL..env.examplesay the same thing.af-stack devbanners printYour apps AF_STACK_URL=http://localhost:<port>, the exact line to copy, since the "API runtime" line ends in/api/v1and is not what an app wants.Verification
src/index.mjswith Node against fake backends: a BackAI runtime (lists agents, exit 0),.envhonoured,/api/v1suffix tolerated, a foreign server on the port (exit 1, names the cause and the fix), nothing listening (exit 1), and a 401 (namesAF_STACK_API_KEY). They skip whennodeis absent.af-stack dev/AF_STACK_URLinstructions.go build,go vet,go test ./...pass; golangci-lint v2.13.1 in CI's new-issues mode reports 0 new issues.🤖 Generated with Claude Code