mirror of
https://github.com/Z3Prover/z3
synced 2025-04-12 04:03:39 +00:00
update gcm script
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
87f7a20e14
commit
114cae50a5
|
@ -1,6 +1,8 @@
|
||||||
/**
|
/**
|
||||||
* git commit flow with auto-generated commit message
|
* Script to automate the git commit process with AI-generated commit messages.
|
||||||
|
* It checks for staged changes, generates a commit message, and prompts the user to review or edit the message before committing.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
script({
|
script({
|
||||||
title: "git commit message",
|
title: "git commit message",
|
||||||
description: "Generate a commit message for all staged changes",
|
description: "Generate a commit message for all staged changes",
|
||||||
|
@ -9,40 +11,104 @@ script({
|
||||||
// Check for staged changes and stage all changes if none are staged
|
// Check for staged changes and stage all changes if none are staged
|
||||||
const diff = await git.diff({
|
const diff = await git.diff({
|
||||||
staged: true,
|
staged: true,
|
||||||
excludedPaths: "**/genaiscript.d.ts",
|
|
||||||
askStageOnEmpty: true,
|
askStageOnEmpty: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// If no staged changes are found, cancel the script with a message
|
||||||
if (!diff) cancel("no staged changes")
|
if (!diff) cancel("no staged changes")
|
||||||
|
|
||||||
// show diff in the console
|
// Display the diff of staged changes in the console
|
||||||
console.log(diff)
|
console.log(diff)
|
||||||
|
|
||||||
|
// chunk if case of massive diff
|
||||||
|
const chunks = await tokenizers.chunk(diff, { chunkSize: 10000 })
|
||||||
|
if (chunks.length > 1)
|
||||||
|
console.log(`staged changes chunked into ${chunks.length} parts`)
|
||||||
|
|
||||||
let choice
|
let choice
|
||||||
let message
|
let message
|
||||||
do {
|
do {
|
||||||
// Generate commit message
|
// Generate a conventional commit message based on the staged changes diff
|
||||||
const res = await runPrompt(
|
message = ""
|
||||||
(_) => {
|
for (const chunk of chunks) {
|
||||||
_.def("GIT_DIFF", diff, { maxTokens: 20000 })
|
const res = await runPrompt(
|
||||||
_.$`GIT_DIFF is a diff of all staged changes, coming from the command:
|
(_) => {
|
||||||
\`\`\`
|
_.def("GIT_DIFF", chunk, {
|
||||||
git diff --cached
|
maxTokens: 10000,
|
||||||
\`\`\`
|
language: "diff",
|
||||||
Please generate a concise, one-line commit message for these changes.
|
detectPromptInjection: "available",
|
||||||
- do NOT add quotes
|
})
|
||||||
` // TODO: add a better prompt
|
_.$`Generate a git conventional commit message that summarizes the changes in GIT_DIFF.
|
||||||
},
|
|
||||||
{ cache: false, temperature: 0.8 }
|
|
||||||
)
|
|
||||||
if (res.error) throw res.error
|
|
||||||
|
|
||||||
message = res.text
|
<type>: <description>
|
||||||
|
|
||||||
|
- <type> can be one of the following: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
|
||||||
|
- <description> is a short, imperative present-tense description of the change
|
||||||
|
- GIT_DIFF is generated by "git diff"
|
||||||
|
- do NOT use markdown syntax
|
||||||
|
- do NOT add quotes, single quote or code blocks
|
||||||
|
- keep it short, 1 line only, maximum 50 characters
|
||||||
|
- follow the conventional commit spec at https://www.conventionalcommits.org/en/v1.0.0/#specification
|
||||||
|
- do NOT confuse delete lines starting with '-' and add lines starting with '+'
|
||||||
|
`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
model: "large", // Specifies the LLM model to use for message generation
|
||||||
|
label: "generate commit message", // Label for the prompt task
|
||||||
|
system: [
|
||||||
|
"system.assistant",
|
||||||
|
"system.safety_jailbreak",
|
||||||
|
"system.safety_harmful_content",
|
||||||
|
"system.safety_validate_harmful_content",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if (res.error) throw res.error
|
||||||
|
message += res.text + "\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
// since we've concatenated the chunks, let's compress it back into a single sentence again
|
||||||
|
if (chunks.length > 1) {
|
||||||
|
const res =
|
||||||
|
await prompt`Generate a git conventional commit message that summarizes the COMMIT_MESSAGES.
|
||||||
|
|
||||||
|
<type>: <description>
|
||||||
|
|
||||||
|
- <type> can be one of the following: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
|
||||||
|
- <description> is a short, imperative present-tense description of the change
|
||||||
|
- do NOT use markdown syntax
|
||||||
|
- do NOT add quotes or code blocks
|
||||||
|
- keep it short, 1 line only, maximum 50 characters
|
||||||
|
- use gitmoji
|
||||||
|
- follow the conventional commit spec at https://www.conventionalcommits.org/en/v1.0.0/#specification
|
||||||
|
- do NOT confuse delete lines starting with '-' and add lines starting with '+'
|
||||||
|
- do NOT respond anything else than the commit message
|
||||||
|
|
||||||
|
COMMIT_MESSAGES:
|
||||||
|
${message}
|
||||||
|
`.options({
|
||||||
|
model: "large",
|
||||||
|
label: "summarize chunk commit messages",
|
||||||
|
system: [
|
||||||
|
"system.assistant",
|
||||||
|
"system.safety_jailbreak",
|
||||||
|
"system.safety_harmful_content",
|
||||||
|
"system.safety_validate_harmful_content",
|
||||||
|
],
|
||||||
|
})
|
||||||
|
if (res.error) throw res.error
|
||||||
|
message = res.text
|
||||||
|
}
|
||||||
|
|
||||||
|
message = message?.trim()
|
||||||
if (!message) {
|
if (!message) {
|
||||||
console.log("No message generated, did you configure the LLM model?")
|
console.log(
|
||||||
|
"No commit message generated, did you configure the LLM model?"
|
||||||
|
)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prompt user for commit message
|
// Prompt user to accept, edit, or regenerate the commit message
|
||||||
choice = await host.select(message, [
|
choice = await host.select(message, [
|
||||||
{
|
{
|
||||||
value: "commit",
|
value: "commit",
|
||||||
|
@ -58,14 +124,14 @@ Please generate a concise, one-line commit message for these changes.
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
// Handle user choice
|
// Handle user's choice for commit message
|
||||||
if (choice === "edit") {
|
if (choice === "edit") {
|
||||||
message = await host.input("Edit commit message", {
|
message = await host.input("Edit commit message", {
|
||||||
required: true,
|
required: true,
|
||||||
})
|
})
|
||||||
choice = "commit"
|
choice = "commit"
|
||||||
}
|
}
|
||||||
// Regenerate message
|
// If user chooses to commit, execute the git commit and optionally push changes
|
||||||
if (choice === "commit" && message) {
|
if (choice === "commit" && message) {
|
||||||
console.log(await git.exec(["commit", "-m", message]))
|
console.log(await git.exec(["commit", "-m", message]))
|
||||||
if (await host.confirm("Push changes?", { default: true }))
|
if (await host.confirm("Push changes?", { default: true }))
|
||||||
|
@ -73,3 +139,4 @@ Please generate a concise, one-line commit message for these changes.
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} while (choice !== "commit")
|
} while (choice !== "commit")
|
||||||
|
|
||||||
|
|
|
@ -669,8 +669,6 @@ namespace pb {
|
||||||
DEBUG_CODE(TRACE("sat_verbose", display(tout, m_A);););
|
DEBUG_CODE(TRACE("sat_verbose", display(tout, m_A);););
|
||||||
TRACE("pb", tout << "process consequent: " << consequent << " : "; s().display_justification(tout, js) << "\n";);
|
TRACE("pb", tout << "process consequent: " << consequent << " : "; s().display_justification(tout, js) << "\n";);
|
||||||
SASSERT(offset > 0);
|
SASSERT(offset > 0);
|
||||||
|
|
||||||
DEBUG_CODE(justification2pb(js, consequent, offset, m_B););
|
|
||||||
|
|
||||||
if (_debug_conflict) {
|
if (_debug_conflict) {
|
||||||
IF_VERBOSE(0,
|
IF_VERBOSE(0,
|
||||||
|
@ -713,12 +711,9 @@ namespace pb {
|
||||||
case sat::justification::EXT_JUSTIFICATION: {
|
case sat::justification::EXT_JUSTIFICATION: {
|
||||||
auto cindex = js.get_ext_justification_idx();
|
auto cindex = js.get_ext_justification_idx();
|
||||||
auto* ext = sat::constraint_base::to_extension(cindex);
|
auto* ext = sat::constraint_base::to_extension(cindex);
|
||||||
if (ext != this) {
|
if (ext != this)
|
||||||
m_lemma.reset();
|
return l_undef;
|
||||||
ext->get_antecedents(consequent, idx, m_lemma, false);
|
|
||||||
for (literal l : m_lemma) process_antecedent(~l, offset);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
constraint& cnstr = index2constraint(cindex);
|
constraint& cnstr = index2constraint(cindex);
|
||||||
++m_stats.m_num_resolves;
|
++m_stats.m_num_resolves;
|
||||||
switch (cnstr.tag()) {
|
switch (cnstr.tag()) {
|
||||||
|
@ -3442,39 +3437,6 @@ namespace pb {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void solver::justification2pb(sat::justification const& js, literal lit, unsigned offset, ineq& ineq) {
|
|
||||||
switch (js.get_kind()) {
|
|
||||||
case sat::justification::NONE:
|
|
||||||
SASSERT(lit != sat::null_literal);
|
|
||||||
ineq.reset(offset);
|
|
||||||
ineq.push(lit, offset);
|
|
||||||
break;
|
|
||||||
case sat::justification::BINARY:
|
|
||||||
SASSERT(lit != sat::null_literal);
|
|
||||||
ineq.reset(offset);
|
|
||||||
ineq.push(lit, offset);
|
|
||||||
ineq.push(js.get_literal(), offset);
|
|
||||||
break;
|
|
||||||
case sat::justification::CLAUSE: {
|
|
||||||
ineq.reset(offset);
|
|
||||||
sat::clause & c = s().get_clause(js);
|
|
||||||
for (literal l : c) ineq.push(l, offset);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case sat::justification::EXT_JUSTIFICATION: {
|
|
||||||
sat::ext_justification_idx index = js.get_ext_justification_idx();
|
|
||||||
VERIFY(this == sat::constraint_base::to_extension(index));
|
|
||||||
constraint& cnstr = index2constraint(index);
|
|
||||||
constraint2pb(cnstr, lit, offset, ineq);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
UNREACHABLE();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void solver::constraint2pb(constraint& cnstr, literal lit, unsigned offset, ineq& ineq) {
|
void solver::constraint2pb(constraint& cnstr, literal lit, unsigned offset, ineq& ineq) {
|
||||||
switch (cnstr.tag()) {
|
switch (cnstr.tag()) {
|
||||||
case pb::tag_t::card_t: {
|
case pb::tag_t::card_t: {
|
||||||
|
|
|
@ -332,7 +332,6 @@ namespace pb {
|
||||||
constraint* active2card();
|
constraint* active2card();
|
||||||
void active2wlits();
|
void active2wlits();
|
||||||
void active2wlits(svector<wliteral>& wlits);
|
void active2wlits(svector<wliteral>& wlits);
|
||||||
void justification2pb(sat::justification const& j, literal lit, unsigned offset, ineq& p);
|
|
||||||
void constraint2pb(constraint& cnstr, literal lit, unsigned offset, ineq& p);
|
void constraint2pb(constraint& cnstr, literal lit, unsigned offset, ineq& p);
|
||||||
bool validate_resolvent();
|
bool validate_resolvent();
|
||||||
unsigned get_coeff(ineq const& pb, literal lit);
|
unsigned get_coeff(ineq const& pb, literal lit);
|
||||||
|
|
Loading…
Reference in a new issue