Skip to content

Commit 114cae5

Browse files
update gcm script
Signed-off-by: Nikolaj Bjorner <[email protected]>
1 parent 87f7a20 commit 114cae5

File tree

3 files changed

+93
-65
lines changed

3 files changed

+93
-65
lines changed

genaisrc/gcm.genai.mts

Lines changed: 90 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/**
2-
* git commit flow with auto-generated commit message
2+
* Script to automate the git commit process with AI-generated commit messages.
3+
* It checks for staged changes, generates a commit message, and prompts the user to review or edit the message before committing.
34
*/
5+
46
script({
57
title: "git commit message",
68
description: "Generate a commit message for all staged changes",
@@ -9,40 +11,104 @@ script({
911
// Check for staged changes and stage all changes if none are staged
1012
const diff = await git.diff({
1113
staged: true,
12-
excludedPaths: "**/genaiscript.d.ts",
1314
askStageOnEmpty: true,
1415
})
16+
17+
// If no staged changes are found, cancel the script with a message
1518
if (!diff) cancel("no staged changes")
1619

17-
// show diff in the console
20+
// Display the diff of staged changes in the console
1821
console.log(diff)
1922

23+
// chunk if case of massive diff
24+
const chunks = await tokenizers.chunk(diff, { chunkSize: 10000 })
25+
if (chunks.length > 1)
26+
console.log(`staged changes chunked into ${chunks.length} parts`)
27+
2028
let choice
2129
let message
2230
do {
23-
// Generate commit message
24-
const res = await runPrompt(
25-
(_) => {
26-
_.def("GIT_DIFF", diff, { maxTokens: 20000 })
27-
_.$`GIT_DIFF is a diff of all staged changes, coming from the command:
28-
\`\`\`
29-
git diff --cached
30-
\`\`\`
31-
Please generate a concise, one-line commit message for these changes.
32-
- do NOT add quotes
33-
` // TODO: add a better prompt
34-
},
35-
{ cache: false, temperature: 0.8 }
36-
)
37-
if (res.error) throw res.error
31+
// Generate a conventional commit message based on the staged changes diff
32+
message = ""
33+
for (const chunk of chunks) {
34+
const res = await runPrompt(
35+
(_) => {
36+
_.def("GIT_DIFF", chunk, {
37+
maxTokens: 10000,
38+
language: "diff",
39+
detectPromptInjection: "available",
40+
})
41+
_.$`Generate a git conventional commit message that summarizes the changes in GIT_DIFF.
42+
43+
<type>: <description>
44+
45+
- <type> can be one of the following: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
46+
- <description> is a short, imperative present-tense description of the change
47+
- GIT_DIFF is generated by "git diff"
48+
- do NOT use markdown syntax
49+
- do NOT add quotes, single quote or code blocks
50+
- keep it short, 1 line only, maximum 50 characters
51+
- follow the conventional commit spec at https://www.conventionalcommits.org/en/v1.0.0/#specification
52+
- do NOT confuse delete lines starting with '-' and add lines starting with '+'
53+
`
54+
},
55+
{
56+
model: "large", // Specifies the LLM model to use for message generation
57+
label: "generate commit message", // Label for the prompt task
58+
system: [
59+
"system.assistant",
60+
"system.safety_jailbreak",
61+
"system.safety_harmful_content",
62+
"system.safety_validate_harmful_content",
63+
],
64+
}
65+
)
66+
if (res.error) throw res.error
67+
message += res.text + "\n"
68+
}
3869

39-
message = res.text
70+
// since we've concatenated the chunks, let's compress it back into a single sentence again
71+
if (chunks.length > 1) {
72+
const res =
73+
await prompt`Generate a git conventional commit message that summarizes the COMMIT_MESSAGES.
74+
75+
<type>: <description>
76+
77+
- <type> can be one of the following: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
78+
- <description> is a short, imperative present-tense description of the change
79+
- do NOT use markdown syntax
80+
- do NOT add quotes or code blocks
81+
- keep it short, 1 line only, maximum 50 characters
82+
- use gitmoji
83+
- follow the conventional commit spec at https://www.conventionalcommits.org/en/v1.0.0/#specification
84+
- do NOT confuse delete lines starting with '-' and add lines starting with '+'
85+
- do NOT respond anything else than the commit message
86+
87+
COMMIT_MESSAGES:
88+
${message}
89+
`.options({
90+
model: "large",
91+
label: "summarize chunk commit messages",
92+
system: [
93+
"system.assistant",
94+
"system.safety_jailbreak",
95+
"system.safety_harmful_content",
96+
"system.safety_validate_harmful_content",
97+
],
98+
})
99+
if (res.error) throw res.error
100+
message = res.text
101+
}
102+
103+
message = message?.trim()
40104
if (!message) {
41-
console.log("No message generated, did you configure the LLM model?")
105+
console.log(
106+
"No commit message generated, did you configure the LLM model?"
107+
)
42108
break
43109
}
44110

45-
// Prompt user for commit message
111+
// Prompt user to accept, edit, or regenerate the commit message
46112
choice = await host.select(message, [
47113
{
48114
value: "commit",
@@ -58,18 +124,19 @@ Please generate a concise, one-line commit message for these changes.
58124
},
59125
])
60126

61-
// Handle user choice
127+
// Handle user's choice for commit message
62128
if (choice === "edit") {
63129
message = await host.input("Edit commit message", {
64130
required: true,
65131
})
66132
choice = "commit"
67133
}
68-
// Regenerate message
134+
// If user chooses to commit, execute the git commit and optionally push changes
69135
if (choice === "commit" && message) {
70136
console.log(await git.exec(["commit", "-m", message]))
71137
if (await host.confirm("Push changes?", { default: true }))
72138
console.log(await git.exec("push"))
73139
break
74140
}
75141
} while (choice !== "commit")
142+

src/sat/smt/pb_solver.cpp

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,6 @@ namespace pb {
669669
DEBUG_CODE(TRACE("sat_verbose", display(tout, m_A);););
670670
TRACE("pb", tout << "process consequent: " << consequent << " : "; s().display_justification(tout, js) << "\n";);
671671
SASSERT(offset > 0);
672-
673-
DEBUG_CODE(justification2pb(js, consequent, offset, m_B););
674672

675673
if (_debug_conflict) {
676674
IF_VERBOSE(0,
@@ -713,12 +711,9 @@ namespace pb {
713711
case sat::justification::EXT_JUSTIFICATION: {
714712
auto cindex = js.get_ext_justification_idx();
715713
auto* ext = sat::constraint_base::to_extension(cindex);
716-
if (ext != this) {
717-
m_lemma.reset();
718-
ext->get_antecedents(consequent, idx, m_lemma, false);
719-
for (literal l : m_lemma) process_antecedent(~l, offset);
720-
break;
721-
}
714+
if (ext != this)
715+
return l_undef;
716+
722717
constraint& cnstr = index2constraint(cindex);
723718
++m_stats.m_num_resolves;
724719
switch (cnstr.tag()) {
@@ -3442,39 +3437,6 @@ namespace pb {
34423437
return c;
34433438
}
34443439

3445-
3446-
void solver::justification2pb(sat::justification const& js, literal lit, unsigned offset, ineq& ineq) {
3447-
switch (js.get_kind()) {
3448-
case sat::justification::NONE:
3449-
SASSERT(lit != sat::null_literal);
3450-
ineq.reset(offset);
3451-
ineq.push(lit, offset);
3452-
break;
3453-
case sat::justification::BINARY:
3454-
SASSERT(lit != sat::null_literal);
3455-
ineq.reset(offset);
3456-
ineq.push(lit, offset);
3457-
ineq.push(js.get_literal(), offset);
3458-
break;
3459-
case sat::justification::CLAUSE: {
3460-
ineq.reset(offset);
3461-
sat::clause & c = s().get_clause(js);
3462-
for (literal l : c) ineq.push(l, offset);
3463-
break;
3464-
}
3465-
case sat::justification::EXT_JUSTIFICATION: {
3466-
sat::ext_justification_idx index = js.get_ext_justification_idx();
3467-
VERIFY(this == sat::constraint_base::to_extension(index));
3468-
constraint& cnstr = index2constraint(index);
3469-
constraint2pb(cnstr, lit, offset, ineq);
3470-
break;
3471-
}
3472-
default:
3473-
UNREACHABLE();
3474-
break;
3475-
}
3476-
}
3477-
34783440
void solver::constraint2pb(constraint& cnstr, literal lit, unsigned offset, ineq& ineq) {
34793441
switch (cnstr.tag()) {
34803442
case pb::tag_t::card_t: {

src/sat/smt/pb_solver.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ namespace pb {
332332
constraint* active2card();
333333
void active2wlits();
334334
void active2wlits(svector<wliteral>& wlits);
335-
void justification2pb(sat::justification const& j, literal lit, unsigned offset, ineq& p);
336335
void constraint2pb(constraint& cnstr, literal lit, unsigned offset, ineq& p);
337336
bool validate_resolvent();
338337
unsigned get_coeff(ineq const& pb, literal lit);

0 commit comments

Comments
 (0)