Skip to content

feat: use auto-generated docs in the system prompt (#45)#52

Open
SyedHannanMehdi wants to merge 30 commits into
tscircuit:mainfrom
SyedHannanMehdi:cashclaw/fix-45-use-the-new-auto-generat
Open

feat: use auto-generated docs in the system prompt (#45)#52
SyedHannanMehdi wants to merge 30 commits into
tscircuit:mainfrom
SyedHannanMehdi:cashclaw/fix-45-use-the-new-auto-generat

Conversation

@SyedHannanMehdi
Copy link
Copy Markdown

Summary

Closes #45

This PR integrates the auto-generated tscircuit component documentation into the system prompt used for AI benchmark evaluations.

What Changed

New files

File Purpose
lib/system-prompt.ts Main system prompt builder — reads cached auto-generated docs and appends them to the base prompt inside a <tscircuit_docs> block
lib/get-system-prompt-with-docs.ts Alternate helper that exposes getSystemPromptWithDocs() and getBaseSystemPrompt() separately
lib/get-system-prompt.ts Async variant that can fetch docs from the registry API if no local cache exists
scripts/update-docs.ts CLI script to refresh the cached docs: npx tsx scripts/update-docs.ts
evals/eval-with-docs.eval.ts Re-exports systemPrompt (with docs) for use in eval files
assets/.gitkeep Ensures the assets/ directory is tracked so the cached docs file can be committed

How it works

  1. Auto-generated docs are fetched from the tscircuit registry (or GitHub raw) and cached in assets/tscircuit-docs.md via scripts/update-docs.ts.
  2. lib/system-prompt.ts#getSystemPrompt() reads the cached file at runtime and appends it to the base prompt inside a clearly delimited <tscircuit_docs> XML block.
  3. If no cache file is present, the system prompt falls back gracefully to the base instructions only.

Why

The auto-generated docs give the AI model accurate, up-to-date API references for every tscircuit component and its props, reducing hallucinations and improving benchmark scores without requiring manual doc maintenance.

Copilot AI review requested due to automatic review settings March 29, 2026 19:54
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

Integrates auto-generated tscircuit component documentation into the system prompt building flow to improve AI benchmark accuracy by providing an up-to-date component/props reference.

Changes:

  • Adds a CLI script to fetch and cache auto-generated docs into assets/tscircuit-docs.md.
  • Introduces multiple system-prompt builder helpers that append cached (or fetched) docs to a base prompt.
  • Adds an eval helper module that re-exports a “prompt with docs” value for eval usage.

Reviewed changes

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

Show a summary per file
File Description
scripts/update-docs.ts Fetches docs from registry/GitHub and writes them into assets/tscircuit-docs.md.
lib/system-prompt.ts Builds a system prompt and (optionally) appends cached docs inside a <tscircuit_docs> block.
lib/get-system-prompt.ts Async system prompt builder that reads cache or fetches docs from registry.
lib/get-system-prompt-with-docs.ts Provides split helpers for base prompt vs base+cached-docs prompt.
evals/eval-with-docs.eval.ts Exposes a systemPrompt value for eval files (currently using the markdown-style docs append).
assets/.gitkeep Keeps assets/ tracked for committing cached docs.

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

Comment thread lib/system-prompt.ts Outdated
Comment on lines +21 to +25
* The main system prompt used in all tscircuit prompt benchmarks.
*
* Includes:
* 1. Core instructions for generating valid tscircuit code
* 2. Auto-generated component documentation for accurate API references
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

The docstring states this is "the main system prompt used in all tscircuit prompt benchmarks", but the benchmarks currently build the system prompt via createLocalCircuitPrompt() (see benchmarks/benchmark-local-circuit*.eval.ts) and nothing imports lib/system-prompt.ts. Please either wire this prompt builder into the benchmark flow or reword the comment to avoid misleading future readers.

Copilot uses AI. Check for mistakes.
Comment thread scripts/update-docs.ts Outdated
Comment on lines +8 to +9
import * as fs from "fs"
import * as path from "path"
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

Repository convention is to import Node built-ins via the node: specifier with default imports (e.g. import fs from "node:fs", import path from "node:path" as in scripts/threshold-test.ts:2-3). Please align these imports for consistency.

Suggested change
import * as fs from "fs"
import * as path from "path"
import fs from "node:fs"
import path from "node:path"

Copilot uses AI. Check for mistakes.
Comment thread evals/eval-with-docs.eval.ts Outdated
Comment on lines +1 to +2
import { getSystemPromptWithDocs } from "../lib/get-system-prompt-with-docs"

Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

PR description mentions appending cached docs inside a clearly delimited <tscircuit_docs> block, but this eval re-export uses getSystemPromptWithDocs() which appends docs under a markdown heading and does not include the <tscircuit_docs> delimiter. Please align the eval prompt output with the intended wrapper (either change the builder to wrap in <tscircuit_docs> or import the builder that already does so).

Copilot uses AI. Check for mistakes.
Comment thread lib/get-system-prompt-with-docs.ts Outdated
Comment on lines +25 to +29
export function getBaseSystemPrompt(): string {
return `You are an expert at generating tscircuit code. tscircuit is a TypeScript library for designing electronic circuits using a React-like JSX/TSX syntax.

## Rules
- Always import components from "tscircuit"
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

There are now multiple hard-coded base prompt variants across lib/system-prompt.ts, lib/get-system-prompt.ts, and this getBaseSystemPrompt() (different rules/examples and different docs wrapper formats). This duplication is likely to drift over time; consider extracting a single shared base prompt builder and having each variant only customize the docs-loading/wrapping strategy.

Copilot uses AI. Check for mistakes.
Comment thread lib/system-prompt.ts Outdated
Comment on lines +1 to +2
import * as fs from "fs"
import * as path from "path"
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

Repository convention is to import Node built-ins via the node: specifier with default imports (e.g. import fs from "node:fs", import path from "node:path" as in lib/utils/save-prompt.ts:1-2). Using import * as fs from "fs" / import * as path from "path" is inconsistent and can behave differently depending on TS/Bundler settings; please align these imports with the existing pattern.

Suggested change
import * as fs from "fs"
import * as path from "path"
import fs from "node:fs"
import path from "node:path"

Copilot uses AI. Check for mistakes.
Comment thread lib/get-system-prompt.ts Outdated
Comment on lines +36 to +40
* Builds the system prompt used for AI-based circuit generation benchmarks.
* Incorporates auto-generated tscircuit component documentation so the model
* has accurate, up-to-date API references.
*/
export async function getSystemPrompt(): Promise<string> {
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

This file exports an async getSystemPrompt(), but lib/system-prompt.ts also exports a sync getSystemPrompt() with different formatting/wrapping. Having two similarly-named public APIs for the same concept is confusing and can lead to importing the wrong one; consider consolidating to one implementation or renaming to reflect behavior (sync vs async / cached vs fetch) and standardizing the docs wrapper format.

Suggested change
* Builds the system prompt used for AI-based circuit generation benchmarks.
* Incorporates auto-generated tscircuit component documentation so the model
* has accurate, up-to-date API references.
*/
export async function getSystemPrompt(): Promise<string> {
* Builds the system prompt used for AI-based circuit generation benchmarks,
* including auto-generated tscircuit component documentation so the model
* has accurate, up-to-date API references.
*
* This async variant fetches the latest docs (from local cache or remote)
* and should be used when you need a prompt with embedded documentation.
*/
export async function getSystemPromptWithDocs(): Promise<string> {

Copilot uses AI. Check for mistakes.
Comment thread lib/get-system-prompt.ts Outdated
Comment on lines +1 to +2
import * as fs from "fs"
import * as path from "path"
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

Repository convention is to import Node built-ins via the node: specifier with default imports (e.g. import fs from "node:fs", import path from "node:path" as in lib/utils/save-prompt.ts:1-2). Please align these imports for consistency and to avoid ESM interop edge-cases.

Suggested change
import * as fs from "fs"
import * as path from "path"
import fs from "node:fs"
import path from "node:path"

Copilot uses AI. Check for mistakes.
Comment thread lib/get-system-prompt-with-docs.ts Outdated
Comment on lines +1 to +2
import * as fs from "fs"
import * as path from "path"
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

Repository convention is to import Node built-ins via the node: specifier with default imports (e.g. import fs from "node:fs", import path from "node:path" as in lib/utils/save-prompt.ts:1-2). Please align these imports for consistency.

Suggested change
import * as fs from "fs"
import * as path from "path"
import fs from "node:fs"
import path from "node:path"

Copilot uses AI. Check for mistakes.
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.

use the new auto generated docs in the system prompt

2 participants