claude-task-worker 0.81.0 → 0.82.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +62 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1525,6 +1525,15 @@ async function commentOnPR(prNumber, body) {
|
|
|
1525
1525
|
async function commentOnIssue(issueNumber, body) {
|
|
1526
1526
|
await execGh(["issue", "comment", String(issueNumber), "--body", body]);
|
|
1527
1527
|
}
|
|
1528
|
+
async function createPullRequest(base, head, title, body) {
|
|
1529
|
+
const url = await execGh(["pr", "create", "--base", base, "--head", head, "--title", title, "--body", body]);
|
|
1530
|
+
const matched = url.match(/\/pull\/(\d+)/);
|
|
1531
|
+
if (!matched) throw new Error(`gh pr create returned an unexpected output: ${url}`);
|
|
1532
|
+
return Number(matched[1]);
|
|
1533
|
+
}
|
|
1534
|
+
async function mergePullRequest(prNumber) {
|
|
1535
|
+
await execGh(["pr", "merge", String(prNumber), "--merge", "--delete-branch"]);
|
|
1536
|
+
}
|
|
1528
1537
|
async function createLabel(name, color, force) {
|
|
1529
1538
|
try {
|
|
1530
1539
|
const args = ["label", "create", name];
|
|
@@ -3897,6 +3906,56 @@ var applyUiDesignWorker = async (opts = {}) => {
|
|
|
3897
3906
|
})();
|
|
3898
3907
|
};
|
|
3899
3908
|
|
|
3909
|
+
// src/last-run-pr.ts
|
|
3910
|
+
import { execFile as execFile3 } from "node:child_process";
|
|
3911
|
+
import { promisify as promisify4 } from "node:util";
|
|
3912
|
+
var execFileAsync3 = promisify4(execFile3);
|
|
3913
|
+
var CONFIG_FILE = "claude-task-worker.json";
|
|
3914
|
+
function lastRunBranchName(workerName) {
|
|
3915
|
+
return `ctw-last-run-${workerName}`;
|
|
3916
|
+
}
|
|
3917
|
+
function hasLastRunChange(porcelain) {
|
|
3918
|
+
return porcelain.trim().length > 0;
|
|
3919
|
+
}
|
|
3920
|
+
function lastRunPrTitle(workerName) {
|
|
3921
|
+
return `chore: ${workerName} \u306E\u5B9F\u884C\u8A18\u9332\u3092\u66F4\u65B0`;
|
|
3922
|
+
}
|
|
3923
|
+
function lastRunPrBody(workerName, at) {
|
|
3924
|
+
return [
|
|
3925
|
+
`\`claude-task-worker\` \u306E \`${workerName}\` \u30EF\u30FC\u30AB\u30FC\u304C\u3001\u5B9A\u671F\u5B9F\u884C\u306E\u8A18\u9332\uFF08\`lastRun.${workerName}\`\uFF09\u3092\u66F4\u65B0\u3057\u307E\u3057\u305F\u3002`,
|
|
3926
|
+
"",
|
|
3927
|
+
`- \u5B9F\u884C\u6642\u523B: ${at.toISOString()}`,
|
|
3928
|
+
"",
|
|
3929
|
+
`\u3053\u306EPR\u306F\u5B9F\u884C\u8A18\u9332\u306E\u307F\u3092\u66F4\u65B0\u3057\u307E\u3059\uFF08\u6210\u679C\u7269\u306E\u5909\u66F4\u306F\u540C\u30EF\u30FC\u30AB\u30FC\u304C\u8D77\u52D5\u3057\u305F\u30B9\u30AD\u30EB\u304C\u5225PR\u3067\u51FA\u3057\u307E\u3059\uFF09\u3002`,
|
|
3930
|
+
`\u30EC\u30D3\u30E5\u30FC\u5BFE\u8C61\u3067\u306F\u306A\u3044\u305F\u3081\u3001\u30EF\u30FC\u30AB\u30FC\u304C\u305D\u306E\u307E\u307E\u30DE\u30FC\u30B8\u3057\u307E\u3059\u3002`
|
|
3931
|
+
].join("\n");
|
|
3932
|
+
}
|
|
3933
|
+
async function git(cwd, args) {
|
|
3934
|
+
const { stdout } = await execFileAsync3("git", ["-C", cwd, ...args]);
|
|
3935
|
+
return stdout;
|
|
3936
|
+
}
|
|
3937
|
+
async function publishLastRunPr(workerName, defaultBranch, at) {
|
|
3938
|
+
const branch = lastRunBranchName(workerName);
|
|
3939
|
+
const cwd = getWorktreePath(branch);
|
|
3940
|
+
try {
|
|
3941
|
+
await createWorktreeFromBranch(branch, defaultBranch);
|
|
3942
|
+
writeLastRun(cwd, workerName, at);
|
|
3943
|
+
if (!hasLastRunChange(await git(cwd, ["status", "--porcelain", CONFIG_FILE]))) {
|
|
3944
|
+
console.log(`[${workerName}] lastRun unchanged, skipping PR`);
|
|
3945
|
+
return;
|
|
3946
|
+
}
|
|
3947
|
+
await git(cwd, ["add", CONFIG_FILE]);
|
|
3948
|
+
await git(cwd, ["commit", "-m", lastRunPrTitle(workerName)]);
|
|
3949
|
+
await git(cwd, ["push", "--force", "origin", `HEAD:refs/heads/${branch}`]);
|
|
3950
|
+
const existing = await findOpenPrNumberByHeadRef(branch);
|
|
3951
|
+
const prNumber = existing ?? await createPullRequest(defaultBranch, branch, lastRunPrTitle(workerName), lastRunPrBody(workerName, at));
|
|
3952
|
+
await mergePullRequest(prNumber);
|
|
3953
|
+
console.log(`[${workerName}] merged lastRun PR #${prNumber}`);
|
|
3954
|
+
} finally {
|
|
3955
|
+
await removeWorktree(branch).catch((err) => console.error(`[${workerName}] removeWorktree failed: ${err}`));
|
|
3956
|
+
}
|
|
3957
|
+
}
|
|
3958
|
+
|
|
3900
3959
|
// src/workers/scheduled-worker.ts
|
|
3901
3960
|
var SCHEDULE_INTERVAL_HOURS = 24;
|
|
3902
3961
|
var SCHEDULE_INTERVAL_MS = SCHEDULE_INTERVAL_HOURS * 60 * 60 * 1e3;
|
|
@@ -3931,9 +3990,11 @@ function createScheduledWorker(config) {
|
|
|
3931
3990
|
advisorModel: isAdvisorEnabled() ? advisorModel : "",
|
|
3932
3991
|
permissionMode: getPermissionMode()
|
|
3933
3992
|
});
|
|
3993
|
+
await publishLastRunPr(config.name, defaultBranch, new Date(now)).catch(
|
|
3994
|
+
(err) => console.error(`[${config.name}] publishLastRunPr failed: ${err}`)
|
|
3995
|
+
);
|
|
3934
3996
|
await createWorktreeFromBranch(worktreeId, defaultBranch);
|
|
3935
3997
|
const cwd = getWorktreePath(worktreeId);
|
|
3936
|
-
writeLastRun(cwd, config.name, new Date(now));
|
|
3937
3998
|
console.log(`[${config.name}] created worktree ${worktreeId} from ${defaultBranch}`);
|
|
3938
3999
|
const repoUrl = `https://github.com/${owner}/${repoName}`;
|
|
3939
4000
|
run(
|