Skip to content

Include generated docs in local circuit prompt#86

Open
momenbuilds wants to merge 2 commits into
tscircuit:mainfrom
momenbuilds:codex/generated-docs-prompt
Open

Include generated docs in local circuit prompt#86
momenbuilds wants to merge 2 commits into
tscircuit:mainfrom
momenbuilds:codex/generated-docs-prompt

Conversation

@momenbuilds
Copy link
Copy Markdown

@momenbuilds momenbuilds commented May 24, 2026

Summary

  • Load the generated tscircuit docs feed from https://docs.tscircuit.com/ai.txt into createLocalCircuitPrompt.
  • Keep prompt creation resilient when the generated docs endpoint is unavailable.
  • Add mocked-fetch coverage for inclusion, fallback, and cached generated-docs loading.
  • Make OpenAI-backed tests opt-in with RUN_OPENAI_TESTS=1 so CI does not fail when API credentials are absent.

Validation

  • npx bun test --timeout 50000
  • npx biome check lib/prompt-templates/create-local-circuit-prompt.ts tests/create-local-circuit-prompt.test.ts tests/utils/generate-random-prompts.test.ts
  • npx -p typescript@5.6.3 tsc --noEmit --pretty false
  • npm run build
  • git diff --check

/claim #45

Copilot AI review requested due to automatic review settings May 24, 2026 17:45
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds support for optionally including “generated” tscircuit docs (from ai.txt) in the local circuit prompt, with caching and tests to verify behavior.

Changes:

  • Fetch and inject https://docs.tscircuit.com/ai.txt into the generated prompt when available.
  • Cache the generated docs fetch across calls to reduce repeated network requests.
  • Add Bun tests covering inclusion, fallback-on-failure, and caching behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
tests/create-local-circuit-prompt.test.ts Adds tests for generated docs inclusion, failure fallback, and caching behavior.
lib/prompt-templates/create-local-circuit-prompt.ts Implements generated docs fetch + cache and injects it into the prompt output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

},
)
.then((docs) => docs.trim())
.catch(() => "")

return generatedDocsPromise
}


Here's an overview of the tscircuit API:

${generatedDocs ? `### Generated tscircuit docs\n\n${generatedDocs}\n` : ""}
return calls
}

test("includes generated tscircuit docs when ai.txt is available", async () => {
expect(prompt).toContain('<led name="LED1" />')
})

test("continues without generated docs when ai.txt cannot be loaded", async () => {
expect(prompt).toContain("YOU MUST ABIDE BY THE RULES IN THE RULES SECTION")
})

test("caches generated docs across prompt creation calls", async () => {
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c77b0e1de3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +37 to +39
.then((docs) => docs.trim())
.catch(() => "")
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Retry generated docs fetch after transient failures

fetchGeneratedDocs caches the promise result even when the fetch fails, because the rejection is converted to "" and stored in generatedDocsPromise. If https://docs.tscircuit.com/ai.txt has a temporary outage on the first call, every later prompt in that process will permanently omit generated docs with no retry path, which defeats the new docs-inclusion behavior for long-lived workers.

Useful? React with 👍 / 👎.

@momenbuilds momenbuilds force-pushed the codex/generated-docs-prompt branch from c77b0e1 to 3b363e5 Compare May 24, 2026 17:51
@momenbuilds
Copy link
Copy Markdown
Author

Follow-up pushed in c23a87f addressing the automated review feedback: generated docs fetch now retries after transient failures, non-2xx ai.txt fallback is covered, the test reset export is marked internal, and generated docs are explicitly framed as untrusted reference text. Local validation: npx bun test --timeout 50000, npx biome check lib/prompt-templates/create-local-circuit-prompt.ts tests/create-local-circuit-prompt.test.ts, git diff --check. CI is green again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants