Skip to content

refactor(think): make create-think standalone; think init augments existing projects#1699

Merged
threepointone merged 3 commits into
mainfrom
decouple-create-think
Jun 8, 2026
Merged

refactor(think): make create-think standalone; think init augments existing projects#1699
threepointone merged 3 commits into
mainfrom
decouple-create-think

Conversation

@threepointone
Copy link
Copy Markdown
Contributor

@threepointone threepointone commented Jun 8, 2026

Why

Installing create-think pulled in all of @cloudflare/think (codemode, shell, ai, agents, …) just to copy a starter template, making npm create think slow to start. This inverts the dependency so create-think is a lightweight, self-contained scaffolder.

create-think — now standalone

  • Owns the starter-template logic: init.ts + templates.ts moved here from @cloudflare/think, with the degit (tiged) fetcher now built in by default.
  • Drops the @cloudflare/think dependency entirely — depends only on tiged + yargs.
  • Adds a side-effect-free . export (initCommand + template registry) so the framework can reuse the exact same logic.

@cloudflare/thinkthink init gets two modes

  • New project (--template given, or run outside an existing npm project) → delegates to create-think to fetch a complete starter template.
  • Augment in place (inside an existing project, no --template) → adds Think framework files (agent, Vite/Wrangler config, generated types) and merges dependencies into the current project. This restores the pre-template think init behavior.

Also:

  • Depends on create-think (tiny: tiged + yargs) — no dependency cycle.
  • Removes the internal @cloudflare/think/cli export, its build entry, and src/cli.ts.
  • Restores the --route-prefix option (used by the augment path).

Tests

CLI init tests exercise the dispatcher (template path through create-think) and add coverage for augment mode, template-inside-an-existing-project, the Vite-config migration guard, and augment dry-run. 30 tests pass.

Checks

pnpm run check green (sherif + exports + format + lint + 102 projects typecheck); lockfile reflects the inverted dependency. Changeset added (both packages, patch).

Notes

  • create-think's scaffolding is covered through think init's dispatcher tests (same compiled initCommand); no separate vitest harness was added to create-think.

Open in Devin Review

…isting projects

Installing `create-think` previously pulled in all of `@cloudflare/think`
(codemode, shell, ai, agents, ...) just to copy a starter template, making
`npm create think` slow to start. Invert the dependency so `create-think` is a
lightweight, self-contained scaffolder.

create-think (standalone)
- Owns the starter-template logic: `init.ts` + `templates.ts` moved here from
  `@cloudflare/think`, with the degit (tiged) fetcher now built in by default.
- Drops the `@cloudflare/think` dependency entirely; depends only on `tiged`
  and `yargs`.
- Adds a side-effect-free `.` export (initCommand + template registry) so the
  framework can reuse it.

@cloudflare/think
- `think init` now dispatches between two modes:
  - New project (`--template` given, or run outside an existing npm project):
    delegates to `create-think` to fetch a complete starter template.
  - Augment in place (inside an existing project, no `--template`): adds Think
    framework files (agent, Vite/Wrangler config, generated types) and merges
    dependencies into the current project. Restores the pre-template behavior.
- Depends on `create-think` (tiny: tiged + yargs).
- Removes the internal `@cloudflare/think/cli` export, its build entry, and
  `src/cli.ts`; restores the `--route-prefix` option used by the augment path.

Tests
- CLI init tests exercise the dispatcher (template path via create-think) and
  add coverage for augment mode, template-inside-existing-project, the
  Vite-config migration guard, and augment dry-run (30 tests).

Adds a changeset (both packages, patch).
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 8, 2026

🦋 Changeset detected

Latest commit: 05a1e63

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@cloudflare/think Patch
create-think Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 potential issues.

View 2 additional findings in Devin Review.

Open in Devin Review

Comment thread packages/think/package.json
Comment thread packages/think/src/cli/init.ts
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jun 8, 2026

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@1699

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@1699

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@1699

create-think

npm i https://pkg.pr.new/create-think@1699

hono-agents

npm i https://pkg.pr.new/hono-agents@1699

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@1699

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@1699

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@1699

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@1699

commit: 05a1e63

- Augment no longer aborts when the project already has files Think wants to
  write (e.g. an existing tsconfig.json). Such files are kept as-is and listed
  in the output; only the migration guard (vite/wrangler) still blocks.
- Augment merge forces package.json `type: module` so Think + Vite work even
  when the existing project is CommonJS.
- create-think: in an empty starting folder the interactive prompt now defaults
  to `.` (scaffold in place); non-empty folders still default to a new
  subfolder, and `--yes` always uses a fresh subfolder.
- Dedupe: `looksLikeThinkApp` is exported from create-think and reused by
  @cloudflare/think instead of being copy-pasted.
- `think init` command description now mentions both modes (new app / augment).
- Add a direct create-think test suite (10 tests) covering template fetch,
  finalize, prompt defaults, --yes, guards, and dry-run. New @cloudflare/think
  tests cover the skip-existing-files and force-ESM augment behaviors.
The augment path previously pinned every dependency to `latest`, including
third-party packages (ai, vite, wrangler, typescript, workers-ai-provider,
@cloudflare/vite-plugin, @cloudflare/workers-types) that are not released in
tandem with this repo. A fresh `think init` could therefore pull an untested
major and produce a worse dependency set than the template path right beside it.

- In-repo packages (@cloudflare/think, agents) still float to `latest` — they
  release together via changesets.
- Third-party deps are now pinned to the exact ranges the starter templates are
  tested against (think-starters/basic/package.json), matching the template
  path's behavior.
- Prevent future drift: a test asserts the augment generator's third-party
  ranges equal the basic starter's, so bumping one without the other fails CI.
@threepointone threepointone merged commit b1b8268 into main Jun 8, 2026
4 checks passed
@threepointone threepointone deleted the decouple-create-think branch June 8, 2026 10:01
@github-actions github-actions Bot mentioned this pull request Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant