feat(deploy): cloudflare-worker agent directories gain sub-agents, schedules, channels, memory and projectInstructions - #392
Merged
Conversation
… schedules, channels, memory and projectInstructions (#298) The cloudflare-worker target rejected an agent directory with subagents/, schedules/, channels/, memory/ or a projectInstructions config. The build now embeds all of them: - subagents/<name>/ directories are embedded recursively in the generated agent.module.ts and resolved with resolveAgentDir()'s rules (description required, model inherited from the parent); the parent gets a delegate_to_<name> tool. - schedules/ files are evaluated at scaffold time (evalModule bundles them with the Worker SDK plugin) so their cron expressions reach wrangler.toml's [triggers] crons, and the generated worker exports scheduled() only when schedules exist. Cloudflare's UTC / five-field / day-name rules apply. - channels/ are mounted under /channels through mountFetchChannels(), a Fetch-native sibling of mountChannels() sharing the new channelCore(). - memory/ slots can use kvMemory(): a provider bound per request to the AGENT_CHECKPOINTS KV namespace (memory/<scopeKey> keys), exported from the package root and the /kv subpath. - projectInstructions reads AGENTS.md/CLAUDE.md at build time and embeds the text instead of reading a file the Worker has no access to. Closes #298
LinuxDevil
force-pushed
the
fix/lou-s5-wdir
branch
from
October 4, 2026 10:11
658e72b to
494173e
Compare
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.
What was missing
lousho build --target=cloudflare-workerrejected an agent directory containingsubagents/,schedules/,channels/,memory/or a config withprojectInstructions, pointing users atnode-server/dockerinstead (#298).What changed
The scaffold (
src/deploy/adapters/cloudflare-dir.ts) now embeds all of it into the generatedagent.module.ts, and the Worker runtime (src/deploy/runtime.worker.ts,src/deploy/workerAgentDir.ts) serves it:subagents/<name>/directories are embedded recursively with the same layout rules and resolved withresolveAgentDir()'s semantics (adescriptionis required, the parent's model is inherited). The parent gets adelegate_to_<name>tool (workerAgentDir.ts,runtime.worker.ts:workerDelegateTool).src/deploy/evalModule.ts(esbuild + the Worker SDK plugin) so their cron expressions reachwrangler.toml's[triggers] crons(workerDirCrons()incloudflare.tsapplies the same UTC / five-field / day-name rules as spec triggers). The generatedworker.tsexportsscheduled()only when schedules exist, routed throughhandleWorkerAgentDirScheduled./channelsby the newmountFetchChannels()(src/channels/fetchChannels.ts), a Fetch-native sibling ofmountChannels(); the channel logic itself moved intosrc/channels/channelCore.ts, shared by both mounts. Early-acknowledged turns keep running underctx.waitUntil.kvMemory()provider (src/deploy/workerMemory.ts), bound per request to theAGENT_CHECKPOINTSKV namespace undermemory/<scopeKey>keys (custombindingname supported; in-memory fallback when unbound, same asworkerStore()). Exported from the package root, the/kvsubpath and the Worker SDK.projectInstructions: truereadsAGENTS.md/CLAUDE.mdat build time and embeds the text; a JSON/YAML options object is honoured too. An options object hidden in anagent.tsconfig is refused at Worker start with a clear error.A JSON/YAML config is now validated at scaffold time for the whole directory tree (sub-agents without a
descriptionfail the build, not the first request);agent.tsconfigs are still checked at Worker start. The Worker SDK subset (workerSdk.ts/workerSdkExports.ts) grew the directory-facing names (defineSchedule,defineChannel, the channel factories,defineMemory,inMemoryMemory,kvMemory), and the missing-export hint lists them.Tests
src/deploy/adapters/cloudflare.dir.test.ts— real scaffold + tsup build of a newworker-agent-dir-fullfixture (sub-agent, schedule, channel,kvMemory()memory,AGENTS.md), then the built bundle'sfetch()/scheduled()driven in-process; plus scaffold refusals (bad schedule export, timezone cron, sub-agent without description).src/deploy/workerAgentDir.test.ts— resolution and runtime coverage for every new folder.src/channels/fetchChannels.test.ts— the Fetch router's routes, earlyrespond+waitUntil, error mapping.src/deploy/workerMemory.test.ts—kvMemory()binding semantics.npm run build,npm run docs:llms(llms-full.txtregenerated); fullvitest runsuite green (4260+ tests; the only failures seen were a missingpackages/create-lousho-agentdist build and a flaky 5s shell timeout, both passing after a rebuild/retry).Closes #298