claude-task-worker 0.135.0 → 0.137.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.
@@ -361,8 +361,11 @@ async function fetchPRChecks(prNumber) {
361
361
  if (!output) return [];
362
362
  return JSON.parse(output);
363
363
  }
364
+ function excludePrsByLabels(prs, excludeLabels) {
365
+ return prs.filter((pr) => !pr.labels.some((l) => excludeLabels.includes(l.name)));
366
+ }
367
+ var PR_LIST_FETCH_LIMIT = 50;
364
368
  async function listPullRequestsWithChecks(assignee, label, excludeLabels = [], limit = 5) {
365
- const search = ["sort:created-asc", ...excludeLabels.map((l) => `-label:"${l}"`)].join(" ");
366
369
  const args = [
367
370
  "pr",
368
371
  "list",
@@ -371,9 +374,9 @@ async function listPullRequestsWithChecks(assignee, label, excludeLabels = [], l
371
374
  "--json",
372
375
  "number,title,labels,headRefName",
373
376
  "--search",
374
- search,
377
+ "sort:created-asc",
375
378
  "--limit",
376
- String(limit)
379
+ String(PR_LIST_FETCH_LIMIT)
377
380
  ];
378
381
  if (assignee) {
379
382
  args.push("--assignee", assignee);
@@ -382,7 +385,7 @@ async function listPullRequestsWithChecks(assignee, label, excludeLabels = [], l
382
385
  args.push("--label", label);
383
386
  }
384
387
  const output = await execGh(args);
385
- const prs = JSON.parse(output);
388
+ const prs = excludePrsByLabels(JSON.parse(output), excludeLabels).slice(0, limit);
386
389
  const withChecks = await Promise.all(prs.map(async (pr) => ({ ...pr, checks: await fetchPRChecks(pr.number) })));
387
390
  return withChecks.filter((pr) => isCICompleted(pr.checks));
388
391
  }
@@ -1103,6 +1106,7 @@ import { mkdirSync, renameSync, writeFileSync as writeFileSync2 } from "node:fs"
1103
1106
  import os from "node:os";
1104
1107
  import path from "node:path";
1105
1108
  var CLOUD_REPORT_HEADING = "## claude-task-worker \u5B9F\u884C\u7D50\u679C";
1109
+ var ORPHANED_CLOUD_SESSION_HEADING = "## \u5B64\u7ACB\u30AF\u30E9\u30A6\u30C9\u30BB\u30C3\u30B7\u30E7\u30F3\u306E\u53EF\u80FD\u6027";
1106
1110
  var DISALLOWED_TOOLS = [
1107
1111
  // 遅延 / yield: 後続ウェイクアップ前提。print モードではウェイクアップが発火せず、
1108
1112
  // 呼ぶと処理未完のままプロセスが終了する。
@@ -1270,13 +1274,18 @@ function buildClaudeArgs({
1270
1274
  function buildCloudCreateArgs(commonArgs, prompt) {
1271
1275
  return ["--cloud", prompt, ...commonArgs];
1272
1276
  }
1273
- function appendCloudDoneInstruction(prompt, target, debug = false) {
1277
+ function appendCloudDoneInstruction(prompt, target, debug = false, startedAt) {
1274
1278
  const targetLabel = target.type === "issue" ? `Issue #${target.number}` : `PR #${target.number}`;
1275
1279
  const checkoutInstruction = buildCloudCheckoutInstruction(target);
1276
1280
  const worktreeInstruction = buildCloudWorktreeInstruction(prompt);
1277
1281
  const reportInstruction = debug ? `\`${CLOUD_DONE_LABEL}\` \u30E9\u30D9\u30EB\u3092\u4ED8\u3051\u308B\u76F4\u524D\u306B\u3001${targetLabel} \u3078 \`${CLOUD_REPORT_HEADING}\` \u3092\u898B\u51FA\u3057\u3068\u3059\u308B\u30B3\u30E1\u30F3\u30C8\u30921\u4EF6\u6295\u7A3F\u3057\u3001\u672C\u6587\u306B\u6700\u7D42\u5831\u544A\uFF08\u5B8C\u4E86\u30FB\u4E2D\u65AD\u306B\u304B\u304B\u308F\u3089\u305A\uFF09\u3092\u66F8\u304F\u3053\u3068\u3002GitHub MCP\uFF08\`add_issue_comment\`\uFF09\u3092\u512A\u5148\u3057\u3001\u5931\u6557\u3057\u305F\u5834\u5408\u306E\u307F \`gh ${target.type} comment ${target.number} --body-file -\` \u3078\u30D5\u30A9\u30FC\u30EB\u30D0\u30C3\u30AF\u3059\u308B\u3053\u3068\uFF08\u30D5\u30A9\u30FC\u30EB\u30D0\u30C3\u30AF\u306F1\u56DE\u307E\u3067\uFF09\u3002\u30EF\u30FC\u30AB\u30FC\u306F\u3053\u306E\u30B3\u30E1\u30F3\u30C8\u3092\u6700\u7D42\u30EC\u30DD\u30FC\u30C8\u3068\u3057\u3066\u56DE\u53CE\u3057 Slack \u901A\u77E5\u306B\u8F09\u305B\u308B\u3002` : "";
1278
1282
  const labelInstruction = `${debug ? "\u4E0A\u8A18\u30B3\u30E1\u30F3\u30C8\u306E\u6295\u7A3F\u5F8C\u3001" : ""}\u3053\u306E\u30BB\u30C3\u30B7\u30E7\u30F3\u306E\u6700\u5F8C\u306E\u64CD\u4F5C\u3068\u3057\u3066 ${targetLabel} \u306B \`${CLOUD_DONE_LABEL}\` \u30E9\u30D9\u30EB\u3092\u4ED8\u4E0E\u3059\u308B\u3053\u3068\u3002\u4ED8\u4E0E\u306F \`bash \${CLAUDE_PLUGIN_ROOT}/scripts/gh-compat.sh add-label ${target.number} ${CLOUD_DONE_LABEL}\` \u3067\u884C\u3044\u3001\u5931\u6557\u3057\u305F\u5834\u5408\u306E\u307F \`gh api -X POST repos/{owner}/{repo}/issues/${target.number}/labels -f "labels[]=${CLOUD_DONE_LABEL}"\` \u3078\u30D5\u30A9\u30FC\u30EB\u30D0\u30C3\u30AF\u3059\u308B\u3053\u3068\uFF08\u30D5\u30A9\u30FC\u30EB\u30D0\u30C3\u30AF\u306F1\u56DE\u307E\u3067\uFF09\u3002**GitHub MCP \u306E \`issue_write\` / \`pull_request_write\`\uFF08method: \`update\`\uFF09\u306F\u4F7F\u308F\u306A\u3044\u3053\u3068** \u2014 \u540C\u30C4\u30FC\u30EB\u306E \`labels\` \u306F\u5168\u7F6E\u63DB\u3067\u3001\`${CLOUD_DONE_LABEL}\` \u3092\u8DB3\u3059\u3064\u3082\u308A\u306E\u547C\u3073\u51FA\u3057\u304C\u65E2\u5B58\u30E9\u30D9\u30EB\uFF08\`cc-triage-scope\` / \`cc-in-progress\` \u7B49\uFF09\u3092\u5DFB\u304D\u6DFB\u3048\u3067\u6D88\u3057\u3001\u305D\u306E Issue/PR \u304C\u30EF\u30FC\u30AB\u30FC\u306E\u30DD\u30FC\u30EA\u30F3\u30B0\u5BFE\u8C61\u304B\u3089\u5916\u308C\u308B\u3002\u30EF\u30FC\u30AB\u30FC\u306F\u3053\u306E\u30E9\u30D9\u30EB\u3067\u30BF\u30B9\u30AF\u306E\u7D42\u4E86\u3092\u691C\u77E5\u3057\u3066\u304A\u308A\u3001\u4ED8\u4E0E\u3055\u308C\u306A\u3044\u3068\u30BF\u30A4\u30E0\u30A2\u30A6\u30C8\u307E\u3067\u5B8C\u4E86\u6271\u3044\u306B\u306A\u3089\u306A\u3044\u3002`;
1279
- return [prompt, checkoutInstruction, worktreeInstruction, reportInstruction, labelInstruction].filter((part) => part !== "").join("\n\n");
1283
+ const orphanInstruction = startedAt ? buildCloudOrphanCleanupInstruction(target, startedAt) : "";
1284
+ return [prompt, checkoutInstruction, worktreeInstruction, reportInstruction, orphanInstruction, labelInstruction].filter((part) => part !== "").join("\n\n");
1285
+ }
1286
+ function buildCloudOrphanCleanupInstruction(target, startedAt) {
1287
+ const targetLabel = target.type === "issue" ? `Issue #${target.number}` : `PR #${target.number}`;
1288
+ return `\`${CLOUD_DONE_LABEL}\` \u3092\u4ED8\u3051\u308B\u76F4\u524D\u306B\u3001${targetLabel} \u306B \`cc-need-human-check\` \u30E9\u30D9\u30EB\u304C\u4ED8\u3044\u3066\u3044\u308B\u304B\u3092\u78BA\u8A8D\u3059\u308B\u3053\u3068\u3002\u4ED8\u3044\u3066\u3044\u3066\u3001\u304B\u3064 ${startedAt.toISOString()} \u3088\u308A\u5F8C\u306B \`${ORPHANED_CLOUD_SESSION_HEADING}\` \u3092\u898B\u51FA\u3057\u3068\u3059\u308B\u30B3\u30E1\u30F3\u30C8\u304C\u6295\u7A3F\u3055\u308C\u3066\u3044\u308B\u5834\u5408\u306F\u3001\u30EF\u30FC\u30AB\u30FC\u304C\u3053\u306E\u30BB\u30C3\u30B7\u30E7\u30F3\u306E\u5B8C\u4E86\u3092\u5F85\u305F\u305A\u306B\u505C\u6B62\u3057\u305F\u3053\u3068\u3092\u793A\u3059\u306E\u3067\u3001\`bash \${CLAUDE_PLUGIN_ROOT}/scripts/gh-compat.sh remove-label ${target.number} cc-need-human-check\` \u3067\u5916\u3059\u3053\u3068\uFF08MCP \u306E \`issue_write\` / \`pull_request_write\` \u306F\u4F7F\u308F\u306A\u3044\uFF09\u3002\u305F\u3060\u3057\u3001\u3053\u306E\u30BB\u30C3\u30B7\u30E7\u30F3\u81EA\u8EAB\u304C\u30B9\u30AD\u30EB\u306E\u624B\u9806\u3068\u3057\u3066 \`cc-need-human-check\` \u3092\u4ED8\u3051\u305F\u5834\u5408\u3001\u304A\u3088\u3073\u30BF\u30B9\u30AF\u3092\u5B8C\u9042\u3067\u304D\u306A\u304B\u3063\u305F\u5834\u5408\u306F\u5916\u3055\u306A\u3044\u3053\u3068\u3002`;
1280
1289
  }
1281
1290
  var CLOUD_WORKTREE_EXEMPT_SKILLS = ["exec-issue", "fix-review-point", "create-ui-design"];
1282
1291
  function buildCloudWorktreeInstruction(prompt) {
@@ -1294,7 +1303,7 @@ function buildCloudGitHubAccessInstruction() {
1294
1303
  function buildCloudToolRestriction() {
1295
1304
  return `\u30AF\u30E9\u30A6\u30C9\u5B9F\u884C\u3067\u306F \`--disallowedTools\` \u30D5\u30E9\u30B0\u306B\u3088\u308B\u30C4\u30FC\u30EB\u5236\u9650\u304C\u53CD\u6620\u3055\u308C\u306A\u3044\u305F\u3081\u3001\u4EE5\u4E0B\u306E\u30C4\u30FC\u30EB\u3092\u4F7F\u308F\u306A\u3044\u3053\u3068: ${DISALLOWED_TOOLS.join(", ")}`;
1296
1305
  }
1297
- function buildCloudPrompt(prompt, model, target, debug = false) {
1306
+ function buildCloudPrompt(prompt, model, target, debug = false, startedAt) {
1298
1307
  const principles = `\u4EE5\u4E0B\u306F\u3053\u306E\u30BB\u30C3\u30B7\u30E7\u30F3\u306E\u5B9F\u884C\u539F\u5247\u3067\u3042\u308B\u3002\u30AF\u30E9\u30A6\u30C9\u5B9F\u884C\u3067\u306F\u30B7\u30B9\u30C6\u30E0\u30D7\u30ED\u30F3\u30D7\u30C8\u306B\u3088\u308B\u6CE8\u5165\u304C\u53CD\u6620\u3055\u308C\u306A\u3044\u305F\u3081\u3001\u30D7\u30ED\u30F3\u30D7\u30C8\u672C\u6587\u3068\u3057\u3066\u6E21\u3057\u3066\u3044\u308B\u3002
1299
1308
 
1300
1309
  ${systemPromptFor(model)}
@@ -1305,7 +1314,7 @@ ${buildCloudGitHubAccessInstruction()}`;
1305
1314
  const withPrinciples = `${prompt}
1306
1315
 
1307
1316
  ${principles}`;
1308
- return target ? appendCloudDoneInstruction(withPrinciples, target, debug) : withPrinciples;
1317
+ return target ? appendCloudDoneInstruction(withPrinciples, target, debug, startedAt) : withPrinciples;
1309
1318
  }
1310
1319
  function shellQuote(value) {
1311
1320
  return `'${value.replace(/'/g, "'\\''")}'`;
@@ -1590,24 +1599,31 @@ function ensureCloudPollLoop() {
1590
1599
  }
1591
1600
  })();
1592
1601
  }
1602
+ async function fetchCloudDoneNumbers() {
1603
+ const pendingTypes = /* @__PURE__ */ new Set();
1604
+ for (const waiter of cloudWaiters.values()) pendingTypes.add(waiter.type);
1605
+ const doneKeys = /* @__PURE__ */ new Map();
1606
+ for (const type of pendingTypes) {
1607
+ try {
1608
+ const numbers = await listNumbersWithLabel(type, CLOUD_DONE_LABEL);
1609
+ doneKeys.set(type, new Set(numbers));
1610
+ } catch (err) {
1611
+ console.error(`[worker] failed to poll ${CLOUD_DONE_LABEL} for ${type}: ${err}`);
1612
+ }
1613
+ }
1614
+ return doneKeys;
1615
+ }
1593
1616
  async function pollCloudWaiters() {
1594
1617
  while (cloudWaiters.size > 0) {
1595
1618
  if (herdrAbortSignal.aborted) {
1596
- for (const waiter of cloudWaiters.values()) waiter.settle("aborted");
1619
+ const doneKeys2 = await fetchCloudDoneNumbers();
1620
+ for (const waiter of cloudWaiters.values()) {
1621
+ waiter.settle(doneKeys2.get(waiter.type)?.has(waiter.number) ? "completed" : "aborted");
1622
+ }
1597
1623
  cloudWaiters.clear();
1598
1624
  break;
1599
1625
  }
1600
- const pendingTypes = /* @__PURE__ */ new Set();
1601
- for (const waiter of cloudWaiters.values()) pendingTypes.add(waiter.type);
1602
- const doneKeys = /* @__PURE__ */ new Map();
1603
- for (const type of pendingTypes) {
1604
- try {
1605
- const numbers = await listNumbersWithLabel(type, CLOUD_DONE_LABEL);
1606
- doneKeys.set(type, new Set(numbers));
1607
- } catch (err) {
1608
- console.error(`[worker] failed to poll ${CLOUD_DONE_LABEL} for ${type}: ${err}`);
1609
- }
1610
- }
1626
+ const doneKeys = await fetchCloudDoneNumbers();
1611
1627
  const now = Date.now();
1612
1628
  for (const [key, waiter] of [...cloudWaiters.entries()]) {
1613
1629
  const done = doneKeys.get(waiter.type);
@@ -1644,7 +1660,7 @@ async function flagOrphanedCloudSession(target, reason, cloudSessionId) {
1644
1660
  });
1645
1661
  const causeLine = reason === "session-id" ? "\u30BB\u30C3\u30B7\u30E7\u30F3ID\u306E\u62BD\u51FA\u306B\u5931\u6557\u3057\u3066\u5F85\u6A5F\u3092\u6253\u3061\u5207\u308A\u307E\u3057\u305F\u3002\u30D7\u30ED\u30F3\u30D7\u30C8\u306F\u6295\u5165\u6E08\u307F\u3067\u3001\u30AF\u30E9\u30A6\u30C9\u30BB\u30C3\u30B7\u30E7\u30F3\u306F\u72EC\u7ACB\u3057\u3066\u7A3C\u50CD\u3057\u3066\u3044\u308B\u53EF\u80FD\u6027\u304C\u3042\u308A\u307E\u3059\u3002" : "\u30EF\u30FC\u30AB\u30FC\u306E\u30B7\u30E3\u30C3\u30C8\u30C0\u30A6\u30F3\u3067\u5F85\u6A5F\u3092\u6253\u3061\u5207\u308A\u307E\u3057\u305F\u3002\u30AF\u30E9\u30A6\u30C9\u30BB\u30C3\u30B7\u30E7\u30F3\u306F\u7D99\u7D9A\u3057\u3066\u3044\u308B\u53EF\u80FD\u6027\u304C\u9AD8\u3044\u3067\u3059\u3002";
1646
1662
  const sessionLine = cloudSessionId ? `https://claude.ai/code/${cloudSessionId}` : "\u30BB\u30C3\u30B7\u30E7\u30F3URL\u4E0D\u660E\uFF08ID\u62BD\u51FA\u306B\u5931\u6557\uFF09";
1647
- const body = `## \u5B64\u7ACB\u30AF\u30E9\u30A6\u30C9\u30BB\u30C3\u30B7\u30E7\u30F3\u306E\u53EF\u80FD\u6027
1663
+ const body = `${ORPHANED_CLOUD_SESSION_HEADING}
1648
1664
 
1649
1665
  **\u539F\u56E0**: ${causeLine}
1650
1666
 
@@ -1706,7 +1722,7 @@ async function createCloudSession(args, initialPrompt, cwd, env) {
1706
1722
  async function runViaCloud(args, prompt, id, onComplete, cwd, env, cloudTarget, model) {
1707
1723
  herdrTasks.set(id, { paneId: "", tabId: "" });
1708
1724
  const debug = hasDebugFlag();
1709
- const initialPrompt = buildCloudPrompt(prompt, model ?? "", cloudTarget, debug);
1725
+ const initialPrompt = buildCloudPrompt(prompt, model ?? "", cloudTarget, debug, tasks.get(id)?.startedAt);
1710
1726
  let result;
1711
1727
  let cloudSessionId;
1712
1728
  try {
@@ -1,5 +1,6 @@
1
1
  import { type PermissionMode, type RunMode } from "./user-config";
2
2
  export declare const CLOUD_REPORT_HEADING = "## claude-task-worker \u5B9F\u884C\u7D50\u679C";
3
+ export declare const ORPHANED_CLOUD_SESSION_HEADING = "## \u5B64\u7ACB\u30AF\u30E9\u30A6\u30C9\u30BB\u30C3\u30B7\u30E7\u30F3\u306E\u53EF\u80FD\u6027";
3
4
  export declare const DISALLOWED_TOOLS: readonly ["Monitor", "ScheduleWakeup", "AskUserQuestion", "EnterPlanMode", "CronCreate", "CronDelete", "CronList", "RemoteTrigger", "EnterWorktree"];
4
5
  export declare const DISALLOWED_TOOLS_ARG: string;
5
6
  export declare const CLAUDE_SPAWN_ENV: {
@@ -34,12 +35,13 @@ export interface CloudPromptTarget {
34
35
  number: number;
35
36
  onBranch?: boolean;
36
37
  }
37
- export declare function appendCloudDoneInstruction(prompt: string, target: CloudPromptTarget, debug?: boolean): string;
38
+ export declare function appendCloudDoneInstruction(prompt: string, target: CloudPromptTarget, debug?: boolean, startedAt?: Date): string;
39
+ export declare function buildCloudOrphanCleanupInstruction(target: CloudPromptTarget, startedAt: Date): string;
38
40
  export declare function buildCloudWorktreeInstruction(prompt: string): string;
39
41
  export declare function buildCloudCheckoutInstruction(target: CloudPromptTarget): string;
40
42
  export declare function buildCloudGitHubAccessInstruction(): string;
41
43
  export declare function buildCloudToolRestriction(): string;
42
- export declare function buildCloudPrompt(prompt: string, model: string, target?: CloudPromptTarget, debug?: boolean): string;
44
+ export declare function buildCloudPrompt(prompt: string, model: string, target?: CloudPromptTarget, debug?: boolean, startedAt?: Date): string;
43
45
  export declare function shellQuote(value: string): string;
44
46
  export declare function buildScriptCommand(command: string, args: string[], platform?: string): {
45
47
  command: string;
package/dist/gh.d.ts CHANGED
@@ -85,6 +85,11 @@ export interface PullRequestWithChecks extends PullRequest {
85
85
  checks: PRCheck[];
86
86
  }
87
87
  export declare function isCICompleted(checks: PRCheck[]): boolean;
88
+ export declare function excludePrsByLabels<T extends {
89
+ labels: {
90
+ name: string;
91
+ }[];
92
+ }>(prs: T[], excludeLabels: string[]): T[];
88
93
  export declare function listPullRequestsWithChecks(assignee?: string, label?: string, excludeLabels?: string[], limit?: number): Promise<PullRequestWithChecks[]>;
89
94
  export declare function addLabel(type: "issue" | "pr", number: number, label: string): Promise<void>;
90
95
  export declare function addAssignee(type: "issue" | "pr", number: number, login: string): Promise<void>;
package/dist/index.js CHANGED
@@ -64,7 +64,7 @@ import {
64
64
  shutdown,
65
65
  waitForAllProcesses,
66
66
  writeLastRun
67
- } from "./chunk-5O66VYMR.js";
67
+ } from "./chunk-R4T3CDMO.js";
68
68
  import {
69
69
  UserConfigError,
70
70
  assertCloudCompatibleCommand,
package/dist/lib.js CHANGED
@@ -55,7 +55,7 @@ import {
55
55
  removeWorktreeByBranch,
56
56
  run,
57
57
  syncDefaultBranch
58
- } from "./chunk-5O66VYMR.js";
58
+ } from "./chunk-R4T3CDMO.js";
59
59
  import {
60
60
  getPermissionMode,
61
61
  getRunMode,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-task-worker",
3
- "version": "0.135.0",
3
+ "version": "0.137.0",
4
4
  "description": "CLI tool that polls GitHub Issues/PRs and delegates work to Claude CLI",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",