Elffuss BraidHub

kikocis/continue public

main · 13.4 KiBRawPermalink
1---
2title: "Automating Documentation Updates with Continue CLI"
3sidebarTitle: "Automating Documentation Updates with Continue CLI"
4description: "Learn how to create automated documentation generation workflows using Continue CLI. Set up AI agents to analyze code changes and generate or update documentation automatically in GitHub workflows or local development."
5---
6# Automating Documentation Updates with Continue CLI
7
8This guide demonstrates how to create automated documentation generation based on code updates in a git branch using the Continue CLI, either as part of your local workflow or as part of a GitHub workflow.
9
10This process utilizes the **Continue CLI** (`cn`) in **headless mode** to analyze changes and generate the necessary documentation, and commit and push the changes. The goal is to keep the workflow as simple as possible by using straightforward shell commands, Continue CLI prompts, and basic git operations.
11
12## Why Use Continue CLI for Documentation?
13
14<CardGroup cols={2}>
15 <Card title="Intelligent Analysis" icon="brain">
16 AI agents understand your codebase and documentation patterns, analyzing git diffs to identify what needs documenting.
17 </Card>
18
19 <Card title="Automated Workflows" icon="robot">
20 Integrate seamlessly into CI/CD pipelines or local development workflows with minimal setup.
21 </Card>
22
23 <Card title="Contextual Understanding" icon="files">
24 Agents can read files, explore projects, and access Git history to generate accurate, relevant documentation.
25 </Card>
26
27 <Card title="Controlled Permissions" icon="shield">
28 Restrict agent actions to specific files and operations, ensuring safe automated documentation updates.
29 </Card>
30</CardGroup>
31
32## Prerequisites
33
34<CardGroup cols={1}>
35 <Card title="Node.js 18+" icon="node-js">
36 Continue CLI requires Node.js 18 or higher. Install globally with:
37 ```bash
38 npm i -g @continuedev/cli
39 ```
40 </Card>
41
42 <Card title="Continue API Key" icon="key">
43 Get your API key from [Continue Hub](https://hub.continue.dev/settings/api-keys) and set:
44 ```bash
45 export CONTINUE_API_KEY=your_key_here
46 ```
47 <Info>
48 You can use the Continue CLI in headless mode without interactive login by setting the `CONTINUE_API_KEY` environment variable.
49 </Info>
50 </Card>
51
52 <Card title="Git Repository" icon="code">
53 A project with code and documentation, or use an open-source project to experiment with the workflow.
54 </Card>
55</CardGroup>
56
57# Documentation Generation Workflow
58
59## Workflow Overview
60
61The documentation generation process follows these sequential steps:
62
63<Steps>
64 <Step title="Environment Setup">
65 Validate environment, install Continue CLI, and set up authentication with API keys.
66 </Step>
67
68 <Step title="Change Analysis">
69 Generate git diff context and analyze code changes between branches to identify new functionality.
70 </Step>
71
72 <Step title="Branch Creation">
73 Create a dedicated documentation branch following the pattern `{original-branch}-docs-update-{timestamp}`.
74 </Step>
75
76 <Step title="AI Documentation Generation">
77 Use Continue CLI with custom rules to analyze changes and generate or update documentation files.
78 <Tip>
79 Use an agent configuration with rules specific for documentation writing in your project and fine-tune it to work for your team's standards.
80 </Tip>
81 </Step>
82
83 <Step title="Review & Commit">
84 Review generated documentation, commit changes to the docs directory, and push to origin.
85 </Step>
86
87 <Step title="Cleanup">
88 Remove temporary files and output completion summary with branch information.
89 </Step>
90</Steps>
91
92
93
94## Implementation
95
96<Tabs>
97 <Tab title="GitHub Workflow">
98
99### GitHub Actions Implementation
100
101<Info>
102This example uses a manual workflow dispatch that requires two inputs: the repository name and the branch containing your code changes. This is helpful when you want to generate documentation for a feature branch before creating a pull request.
103</Info>
104
105**Required Inputs:**
106- **repository:** The repository you are operating on (format: `owner/repo`)
107- **branch_name:** The name of the branch you have code changes on and want to generate documentation for
108- **continue_config:** The Continue agent configuration to use
109 - Consider setting a default value if you have a default config your'd like to use
110- **continue_org:** The Continue org to use
111 - Consider setting a default value if you have a default org your'd like to use
112
113
114```yaml title=".github/workflows/generate-docs.yml"
115name: Generate Docs for Branch
116
117on:
118 workflow_dispatch:
119 inputs:
120 repository:
121 description: 'Repository (owner/repo)'
122 required: true
123 default: 'owner/repo'
124 branch_name:
125 description: 'Branch name to generate docs for'
126 required: true
127 continue_config:
128 description: 'Continue agent configuration to use'
129 required: true
130 # Set a default value if you have a default config your'd like to use
131 # default: 'agent-config-name'
132 continue_org:
133 description: 'Continue org to use'
134 required: true
135 # Set a default value if you have a default org your'd like to use
136 # default: 'your-org-name'
137
138jobs:
139 write-docs:
140 runs-on: ubuntu-latest
141 name: Write Documentation for Branch
142 env:
143 CONTINUE_API_KEY: ${{ secrets.CONTINUE_API_KEY }}
144 CONTINUE_ORG: ${{ github.event.inputs.continue_org }}
145 CONTINUE_CONFIG: ${{ github.event.inputs.continue_config }}
146
147 steps:
148
149 - name: Checkout fork repository
150 uses: actions/checkout@v4
151 with:
152 repository: ${{ github.event.inputs.repository || 'owner/repo' }}
153 token: ${{ secrets.GH_PAT }}
154 fetch-depth: 0 # Full history needed for sync
155
156 - name: Setup git configuration
157 run: |
158 git config user.name "github-actions[doc-writer-bot]"
159 git config user.email "yourname@email.com"
160
161 - name: Checkout target branch
162 run: |
163 git fetch origin ${{ github.event.inputs.branch_name }}
164 git checkout ${{ github.event.inputs.branch_name }}
165
166 - name: Setup Node.js
167 uses: actions/setup-node@v4
168 with:
169 node-version: '18'
170
171 - name: Install Continue CLI
172 run: |
173 echo "Installing Continue CLI..."
174 npm i -g @continuedev/cli
175
176 - name: Verify Continue CLI installation
177 run: |
178 echo "Checking Continue CLI version..."
179 cn --version || exit 1
180
181 - name: Set branch name
182 id: branch
183 run: |
184 BRANCH_NAME="${{ github.event.inputs.branch_name }}-docs-update-$(date +%Y-%m-%d-%H-%M-%S)"
185 echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
186 echo "Branch name: $BRANCH_NAME"
187
188 - name: Generate git diff context
189 run: |
190 echo "Git changes:" > context.txt
191 git diff origin/main..HEAD --stat >> context.txt
192 echo -e "\n\nFile list:" >> context.txt
193 git diff origin/main..HEAD >> context.txt
194 echo "Generated context file:"
195 cat context.txt
196
197 - name: Create documentation branch
198 run: |
199 echo "Creating branch: ${{ steps.branch.outputs.branch_name }}"
200 git checkout -b "${{ steps.branch.outputs.branch_name }}"
201
202 - name: Generate documentation with Continue CLI
203 run: |
204 echo "Running Continue agent to generate documentation..."
205 cn --config <continue-user>/<agent-config> \
206 --auto \
207 --allow Write \
208 -p \
209 --prompt ./context.txt \
210 "Analyze the provided git diff and identify any new functionality introduced. Summarise the new features in a few sentences. Then search the existing documentation in the site docs/ directory to determine whether these features are already documented in a way that enables users to use them. If documentation is missing or incomplete, create or modify Markdown files under the site diretory (without changing any code) to add clear explanations, usage instructions and examples for the new features in the same style and format as the existing documentation. Finally, print a brief summary of the documentation changes you made."
211
212 - name: Clean up temporary files
213 run: rm -f context.txt
214
215 - name: Commit and push documentation changes
216 run: |
217 echo "Review git status..."
218 git status
219
220 echo "Adding files edited in site directory to git..."
221 git add site/
222
223 echo "Committing changes..."
224 git commit -s -m "docs: update for new functionality from branch ${{ github.event.inputs.branch_name }}"
225
226 echo "Pushing changes to origin..."
227 git push --set-upstream origin "${{ steps.branch.outputs.branch_name }}"
228
229```
230
231 </Tab>
232 <Tab title="Local Development">
233
234### Local Development Implementation
235
236<Warning>
237Make sure to set your `CONTINUE_API_KEY` environment variable before running local scripts to enable headless mode.
238</Warning>
239
240When using the Continue CLI on your local machine, you can build workflows in various ways, one of which is by simply creating shell scripts that you can run, which call the CLI.
241
242The below shell script snippet shows the final part of a docs updating shell script that can be used to generate documentation for the code changes in a branch of a git repository.
243
244For the example snippet below to work you will need to set the following variables:
245- `CONTINUE_ORG`
246- `CONTINUE_CONFIG`
247- `BASE_BRANCH`
248- `COMPARE_BRANCH`
249- `DOCS_BRANCH_NAME`
250
251For example you can either set these as environment variables or as command line arguments to be used by the script.
252
253**Example shell script snippet for generating documentation**
254```bash title="generate-docs.sh"
255#!/bin/bash
256# The script below shows the final part of a docs updating shell script that can be used to generate documentation for the code changes in a branch of a git repository.
257
258# Generate git diff context
259echo "Generating git diff context..."
260echo "Git changes:" > context.txt
261git diff "$BASE_BRANCH..$COMPARE_BRANCH" --stat >> context.txt
262echo -e "\n\nFile list:" >> context.txt
263git diff "$BASE_BRANCH..$COMPARE_BRANCH" >> context.txt
264echo "Generated context file:"
265cat context.txt
266
267# Create documentation branch
268echo "Creating branch: $DOCS_BRANCH_NAME"
269git checkout -b "$DOCS_BRANCH_NAME"
270
271# Generate documentation with Continue CLI
272echo "Running Continue agent to generate documentation..."
273cn -config "$CONTINUE_ORG/$CONTINUE_CONFIG" \
274 --auto \
275 --allow Write \
276 -p \
277 --prompt ./context.txt \
278 "Analyze the provided git diff and identify any new functionality introduced. Summarise the new features in a few sentences. Then search the existing documentation in the site docs/ directory to determine whether these features are already documented in a way that enables users to use them. If documentation is missing or incomplete, create or modify Markdown files under the site diretory (without changing any code) to add clear explanations, usage instructions and examples for the new features in the same style and format as the existing documentation. Finally, print a brief summary of the documentation changes you made."
279
280# Clean up temporary files
281echo "Cleaning up temporary files..."
282rm -f context.txt
283
284# Commit and push documentation changes
285echo "Reviewing git status..."
286git status
287
288# Only adding files that have been added and modified in the site directory
289echo "Adding files edited in site directory to git..."
290git add site/
291
292if git diff --cached --quiet; then
293 echo "No documentation changes to commit"
294else
295 echo "Committing changes..."
296 git commit -s -m "docs: update for new functionality from branch $BRANCH_NAME"
297
298 echo "Pushing changes to origin..."
299 git push --set-upstream origin "$DOCS_BRANCH_NAME"
300
301 echo "Documentation branch created and pushed: $DOCS_BRANCH_NAME"
302fi
303```
304
305 </Tab>
306</Tabs>
307
308## Enhancement Ideas
309
310The workflow above is a basic example and can be enhanced in various ways to fit your needs. Here are some ideas:
311
312<CardGroup cols={2}>
313 <Card title="Change Analysis Agent" icon="magnifying-glass">
314 Define a specialized agent for analyzing changes and generating targeted prompts for documentation writers, improving output quality.
315 </Card>
316
317 <Card title="Auto-Documentation on Merge" icon="code-compare">
318 Create GitHub workflows that automatically generate documentation PRs when new features are merged to main.
319 </Card>
320
321 <Card title="Documentation Gap Analysis" icon="clipboard">
322 Build an agent that reviews older merged PRs to identify undocumented features and generates missing documentation.
323 </Card>
324
325 <Card title="Copy Editor Agent" icon="pencil">
326 Add a post-processing agent to enhance writing quality with rules like "use short sentences and simple words."
327 </Card>
328</CardGroup>
329
330## Next Steps
331
332Ready to implement automated documentation with Continue CLI? Here are some helpful resources to get you started:
333
334<CardGroup cols={2}>
335 <Card title="Continue CLI Guide" icon="terminal" href="/guides/cli">
336 Learn the fundamentals of using Continue CLI for automated coding tasks and headless workflows.
337 </Card>
338
339 <Card title="Understanding Agents" icon="robot" href="/guides/understanding-agents">
340 Discover how to configure and customize AI agents for your specific documentation needs.
341 </Card>
342
343 <Card title="Video: Leverage AI to help with your docs" icon="video" href="https://www.youtube.com/watch?v=rJ2taa8OLvY">
344 Checkout this video from Tetrate about using Continue Agents to help with writing your docs.
345 </Card>
346
347 <Card title="Continue Hub" icon="users" href="https://hub.continue.dev">
348 Browse pre-built agents and configurations from the Continue community.
349 </Card>
350</CardGroup>