Skip to content

Commit eb8266a

Browse files
cursoragent4ian
andcommitted
Rework summary handling and include AI output in PR bodies
- automated_updates_data.json: format empty array with newline for cleaner diffs when entries are added - improve-docs.js: AI now edits automated_updates_data.json directly (adds to last_improved_things) instead of writing improvement_summary.txt; script reads back the new entry and writes summary to /tmp/ai_summary.txt - update-docs-from-commits.js: prompt now asks for a brief summary; script writes AI output to /tmp/ai_summary.txt and commit log to /tmp/commit_log.txt; uses writeDataFile helper for consistent formatting - improve-docs.yml: reads AI summary as step output and includes it in the PR body ('The AI agent summary is:') - update-docs-from-commits.yml: reads AI summary + commit log as step outputs and includes both in the PR body - .gitignore: remove unused improvement_summary.txt entry Co-authored-by: Florian Rival <4ian@users.noreply.github.com>
1 parent 2128eeb commit eb8266a

6 files changed

Lines changed: 141 additions & 41 deletions

File tree

.github/workflows/improve-docs.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,22 @@ jobs:
5252

5353
# ── Run the improvement script ────────────────────────────────────
5454
- name: Improve documentation
55+
id: improve
5556
env:
5657
AI_PROVIDER: "claude" # Change to "codex" to use Codex
5758
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
5859
# OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
59-
run: node scripts/improve-docs.js
60+
run: |
61+
node scripts/improve-docs.js
62+
63+
# Pass the AI summary to subsequent steps
64+
if [ -f /tmp/ai_summary.txt ]; then
65+
{
66+
echo "summary<<SUMMARY_EOF"
67+
cat /tmp/ai_summary.txt
68+
echo "SUMMARY_EOF"
69+
} >> "$GITHUB_OUTPUT"
70+
fi
6071
6172
# ── Create Pull Request ───────────────────────────────────────────
6273
- name: Create Pull Request
@@ -71,6 +82,9 @@ jobs:
7182
An AI coding agent inspected the [GDevelop](https://github.com/4ian/GDevelop) codebase
7283
and the existing documentation, then chose an aspect to improve.
7384
85+
The AI agent summary is:
86+
> ${{ steps.improve.outputs.summary }}
87+
7488
The updated `automated_updates_data.json` tracks what was improved so future
7589
runs will pick a different area.
7690

.github/workflows/update-docs-from-commits.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,29 @@ jobs:
5252

5353
# ── Run the update script ─────────────────────────────────────────
5454
- name: Update documentation from recent commits
55+
id: update
5556
env:
5657
AI_PROVIDER: "claude" # Change to "codex" to use Codex
5758
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
5859
# OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
59-
run: node scripts/update-docs-from-commits.js
60+
run: |
61+
node scripts/update-docs-from-commits.js
62+
63+
# Pass the AI summary and commit log to subsequent steps
64+
if [ -f /tmp/ai_summary.txt ]; then
65+
{
66+
echo "summary<<SUMMARY_EOF"
67+
cat /tmp/ai_summary.txt
68+
echo "SUMMARY_EOF"
69+
} >> "$GITHUB_OUTPUT"
70+
fi
71+
if [ -f /tmp/commit_log.txt ]; then
72+
{
73+
echo "commits<<COMMITS_EOF"
74+
cat /tmp/commit_log.txt
75+
echo "COMMITS_EOF"
76+
} >> "$GITHUB_OUTPUT"
77+
fi
6078
6179
# ── Create Pull Request ───────────────────────────────────────────
6280
- name: Create Pull Request
@@ -71,6 +89,14 @@ jobs:
7189
An AI coding agent analysed recent commits in [4ian/GDevelop](https://github.com/4ian/GDevelop)
7290
and updated the documentation to reflect user-facing changes.
7391
92+
### GDevelop commits covered
93+
```
94+
${{ steps.update.outputs.commits }}
95+
```
96+
97+
### The AI agent summary is:
98+
${{ steps.update.outputs.summary }}
99+
74100
**Please review the changes carefully before merging.**
75101
base: main
76102
branch: auto/update-docs-from-commits

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
dokuwiki2wikijs/__pycache__
22
.DS_Store
33
site
4-
scripts/node_modules/
5-
improvement_summary.txt
4+
scripts/node_modules/

automated_updates_data.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
22
"last_automated_updates_commit": null,
3-
"last_improved_things": []
3+
"last_improved_things": [
4+
5+
]
46
}

scripts/improve-docs.js

Lines changed: 64 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
* DIFFERENT aspect of the documentation (its own choice of scope — a folder,
1010
* feature, topic, etc.).
1111
*
12-
* After the AI finishes, the script updates automated_updates_data.json so
13-
* future runs don't repeat the same improvements.
12+
* The AI agent directly adds a new entry to the "last_improved_things" array
13+
* inside automated_updates_data.json, so the change is tracked in the same
14+
* commit as the documentation edits.
1415
*/
1516

1617
const { execSync } = require("child_process");
@@ -24,7 +25,7 @@ const GDEVELOP_REPO = "https://github.com/4ian/GDevelop.git";
2425
const GDEVELOP_DIR = process.env.GDEVELOP_DIR || "/tmp/GDevelop";
2526
const REPO_ROOT = path.resolve(__dirname, "..");
2627
const DATA_FILE = path.join(REPO_ROOT, "automated_updates_data.json");
27-
const SUMMARY_FILE = path.join(REPO_ROOT, "improvement_summary.txt");
28+
const SUMMARY_OUT = "/tmp/ai_summary.txt";
2829

2930
// AI provider — switch by changing this value (or set AI_PROVIDER env var).
3031
// Supported values: "claude" | "codex"
@@ -37,6 +38,14 @@ function run(cmd, opts = {}) {
3738
return execSync(cmd, { encoding: "utf8", ...opts }).trim();
3839
}
3940

41+
function writeDataFile(data) {
42+
let json = JSON.stringify(data, null, 2);
43+
// Keep empty arrays on separate lines so future additions produce clean diffs
44+
json = json.replace(/"last_improved_things": \[\s*\]/g,
45+
'"last_improved_things": [\n\n ]');
46+
fs.writeFileSync(DATA_FILE, json + "\n");
47+
}
48+
4049
// ---------------------------------------------------------------------------
4150
// Main
4251
// ---------------------------------------------------------------------------
@@ -48,6 +57,7 @@ function main() {
4857
}
4958

5059
const alreadyImproved = data.last_improved_things || [];
60+
const previousCount = alreadyImproved.length;
5161

5262
// 2. Clone / update GDevelop
5363
if (!fs.existsSync(path.join(GDEVELOP_DIR, ".git"))) {
@@ -71,35 +81,50 @@ function main() {
7181
{ cwd: REPO_ROOT }
7282
);
7383

74-
// 4. Clean up any leftover summary file
75-
if (fs.existsSync(SUMMARY_FILE)) fs.unlinkSync(SUMMARY_FILE);
76-
77-
// 5. Build prompt
84+
// 4. Build prompt
7885
const prompt = buildPrompt(alreadyImproved, docTree);
7986

8087
const promptFile = "/tmp/doc_improve_prompt.txt";
8188
fs.writeFileSync(promptFile, prompt);
8289
console.log(`Prompt written to ${promptFile} (${prompt.length} chars)`);
8390

84-
// 6. Invoke AI agent
91+
// 5. Invoke AI agent
8592
console.log(`\nInvoking AI agent (${AI_PROVIDER})…\n`);
86-
invokeAI(promptFile, REPO_ROOT);
87-
88-
// 7. Read back the improvement summary the AI wrote
89-
let summary = "(no summary provided)";
90-
if (fs.existsSync(SUMMARY_FILE)) {
91-
summary = fs.readFileSync(SUMMARY_FILE, "utf8").trim();
92-
// Clean up temp file — we don't want it committed
93-
fs.unlinkSync(SUMMARY_FILE);
93+
const aiOutput = invokeAI(promptFile, REPO_ROOT);
94+
95+
// 6. Read back the data file to find what the AI added
96+
let updatedData = data;
97+
try {
98+
updatedData = JSON.parse(fs.readFileSync(DATA_FILE, "utf8"));
99+
} catch (err) {
100+
console.error("Warning: could not re-read automated_updates_data.json:", err.message);
101+
}
102+
103+
const updatedList = updatedData.last_improved_things || [];
104+
let summary;
105+
106+
if (updatedList.length > previousCount) {
107+
// The AI added one or more entries — take the last one
108+
const newEntry = updatedList[updatedList.length - 1];
109+
summary = newEntry.summary || "(no summary in new entry)";
110+
console.log(`\nAI added improvement entry: [${newEntry.date}] ${summary}`);
111+
} else {
112+
// AI didn't update the file — add a fallback entry ourselves
113+
summary = aiOutput
114+
? aiOutput.split("\n").filter(Boolean).slice(0, 3).join(" ").substring(0, 200)
115+
: "(no summary provided)";
116+
updatedData.last_improved_things = updatedList;
117+
updatedData.last_improved_things.push({
118+
date: new Date().toISOString().split("T")[0],
119+
summary,
120+
});
121+
writeDataFile(updatedData);
122+
console.log(`\nFallback: script added improvement entry: ${summary}`);
94123
}
95124

96-
// 8. Update tracking data
97-
data.last_improved_things.push({
98-
date: new Date().toISOString().split("T")[0],
99-
summary,
100-
});
101-
fs.writeFileSync(DATA_FILE, JSON.stringify(data, null, 2) + "\n");
102-
console.log(`\nImprovement recorded: ${summary}`);
125+
// 7. Write summary for the workflow to pick up
126+
fs.writeFileSync(SUMMARY_OUT, summary);
127+
console.log(`Summary written to ${SUMMARY_OUT}`);
103128
}
104129

105130
// ---------------------------------------------------------------------------
@@ -111,6 +136,8 @@ function buildPrompt(alreadyImproved, docTree) {
111136
? alreadyImproved.map((e) => ` • [${e.date}] ${e.summary}`).join("\n")
112137
: " (none yet — this is the first run)";
113138

139+
const today = new Date().toISOString().split("T")[0];
140+
114141
return `You are an expert technical writer improving GDevelop's documentation.
115142
116143
DOCUMENTATION LOCATION
@@ -147,14 +174,23 @@ IMPORTANT CONSTRAINTS
147174
– Every "reference.md" file under docs/gdevelop5/all-features/*/reference.md
148175
– docs/gdevelop5/all-features/expressions-reference.md
149176
• NEVER create new files unless absolutely necessary.
150-
• NEVER edit files outside docs/gdevelop5/.
177+
• NEVER edit files outside docs/gdevelop5/ (except automated_updates_data.json as described below).
151178
• Do NOT touch images or binary files.
152179
153180
WHEN YOU ARE DONE
154181
-----------------
155-
Create a file called "improvement_summary.txt" in ${REPO_ROOT}/ containing
156-
a single line that describes what you improved.
157-
Example: "Improved getting_started/index.md — added clearer first-project walkthrough steps"
182+
Edit the file "automated_updates_data.json" in ${REPO_ROOT}/ and add a new
183+
entry at the END of the "last_improved_things" array with this format:
184+
185+
{ "date": "${today}", "summary": "<one-line description of what you improved>" }
186+
187+
For example, the file might look like:
188+
{
189+
"last_automated_updates_commit": null,
190+
"last_improved_things": [
191+
{ "date": "${today}", "summary": "Improved objects/sprite/index.md — clarified animation looping behaviour" }
192+
]
193+
}
158194
159195
Make your changes now.`;
160196
}
@@ -178,11 +214,11 @@ function invokeAI(promptFile, cwd) {
178214
throw new Error(`Unknown AI_PROVIDER: "${AI_PROVIDER}". Use "claude" or "codex".`);
179215
}
180216

181-
// Run with stdout/stderr piped so we can capture and log the full output.
182217
const output = execSync(cmd, { ...opts, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] });
183218
console.log("── AI agent output ─────────────────────────────────────────");
184219
console.log(output);
185220
console.log("── End of AI agent output ──────────────────────────────────");
221+
return output;
186222
}
187223

188224
// ---------------------------------------------------------------------------

scripts/update-docs-from-commits.js

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const REPO_ROOT = path.resolve(__dirname, "..");
2424
const DATA_FILE = path.join(REPO_ROOT, "automated_updates_data.json");
2525
const DEFAULT_COMMIT_COUNT = 5;
2626
const MAX_DIFF_BYTES = 80000; // Truncate diffs to keep prompt manageable
27+
const SUMMARY_OUT = "/tmp/ai_summary.txt";
28+
const COMMITS_OUT = "/tmp/commit_log.txt";
2729

2830
// AI provider — switch by changing this value (or set AI_PROVIDER env var).
2931
// Supported values: "claude" | "codex"
@@ -44,6 +46,14 @@ function runSafe(cmd, opts = {}) {
4446
}
4547
}
4648

49+
function writeDataFile(data) {
50+
let json = JSON.stringify(data, null, 2);
51+
// Keep empty arrays on separate lines so future additions produce clean diffs
52+
json = json.replace(/"last_improved_things": \[\s*\]/g,
53+
'"last_improved_things": [\n\n ]');
54+
fs.writeFileSync(DATA_FILE, json + "\n");
55+
}
56+
4757
// ---------------------------------------------------------------------------
4858
// Main
4959
// ---------------------------------------------------------------------------
@@ -61,7 +71,6 @@ function main() {
6171
`git clone --filter=blob:none --no-checkout ${GDEVELOP_REPO} ${GDEVELOP_DIR}`,
6272
{ stdio: "inherit" }
6373
);
64-
// Only checkout the history (we need commits, not a full working tree initially)
6574
execSync("git checkout", { cwd: GDEVELOP_DIR, stdio: "inherit" });
6675
} else {
6776
console.log("Updating existing GDevelop clone…");
@@ -76,7 +85,6 @@ function main() {
7685
let commitRange = null;
7786

7887
if (lastCommit) {
79-
// Verify the commit exists in our (possibly shallow) clone
8088
const commitExists = (() => {
8189
try {
8290
execSync(`git cat-file -e ${lastCommit}`, {
@@ -106,19 +114,19 @@ function main() {
106114

107115
if (!commitLog) {
108116
console.log("No new commits found. Nothing to do.");
109-
// Still update the pointer so we don't re-scan next time
110117
data.last_automated_updates_commit = run("git rev-parse HEAD", {
111118
cwd: GDEVELOP_DIR,
112119
});
113-
fs.writeFileSync(DATA_FILE, JSON.stringify(data, null, 2) + "\n");
120+
writeDataFile(data);
121+
fs.writeFileSync(SUMMARY_OUT, "(no new commits to process)");
122+
fs.writeFileSync(COMMITS_OUT, "(none)");
114123
return;
115124
}
116125

117126
const diffStat = runSafe(`git diff ${commitRange} --stat`, {
118127
cwd: GDEVELOP_DIR,
119128
});
120129

121-
// Get meaningful code diffs (skip binary, tests, and overly large files)
122130
const diffContent = runSafe(
123131
`git diff ${commitRange} -- '*.js' '*.jsx' '*.ts' '*.tsx' '*.json' '*.md' `
124132
+ `':!*/__tests__/*' ':!*/node_modules/*' ':!*/fixtures/*' `
@@ -141,12 +149,21 @@ function main() {
141149

142150
// 7. Invoke AI agent
143151
console.log(`\nInvoking AI agent (${AI_PROVIDER})…\n`);
144-
invokeAI(promptFile, REPO_ROOT);
152+
const aiOutput = invokeAI(promptFile, REPO_ROOT);
145153

146154
// 8. Update tracking data
147155
data.last_automated_updates_commit = latestCommit;
148-
fs.writeFileSync(DATA_FILE, JSON.stringify(data, null, 2) + "\n");
156+
writeDataFile(data);
149157
console.log(`\nTracking data updated — latest commit: ${latestCommit}`);
158+
159+
// 9. Write summary + commit log for the workflow to pick up
160+
const summary = aiOutput
161+
? aiOutput.trim()
162+
: "(AI agent produced no output)";
163+
fs.writeFileSync(SUMMARY_OUT, summary);
164+
fs.writeFileSync(COMMITS_OUT, commitLog);
165+
console.log(`Summary written to ${SUMMARY_OUT}`);
166+
console.log(`Commit log written to ${COMMITS_OUT}`);
150167
}
151168

152169
// ---------------------------------------------------------------------------
@@ -194,6 +211,12 @@ IMPORTANT CONSTRAINTS
194211
• Do NOT touch images or binary files.
195212
• If no documentation updates are needed, do nothing.
196213
214+
WHEN YOU ARE DONE
215+
-----------------
216+
Output a brief summary (2-3 lines) of the documentation changes you made,
217+
or state that no changes were needed. This summary will be included in the
218+
pull request description.
219+
197220
Make your changes now.`;
198221
}
199222

@@ -216,11 +239,11 @@ function invokeAI(promptFile, cwd) {
216239
throw new Error(`Unknown AI_PROVIDER: "${AI_PROVIDER}". Use "claude" or "codex".`);
217240
}
218241

219-
// Run with stdout/stderr piped so we can capture and log the full output.
220242
const output = execSync(cmd, { ...opts, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] });
221243
console.log("── AI agent output ─────────────────────────────────────────");
222244
console.log(output);
223245
console.log("── End of AI agent output ──────────────────────────────────");
246+
return output;
224247
}
225248

226249
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)