@ravshansbox/pi-github 1.2.0 → 1.3.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/README.md +1 -0
- package/dist/handler.js +5 -3
- package/dist/pi-agent.js +9 -1
- package/dist/progress.js +8 -0
- package/dist/watch.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,6 +7,7 @@ Watches open issues in a GitHub repo and answers new issues and comments with [p
|
|
|
7
7
|
- Polls the repo of the current directory for new issues and comments every 30 seconds. Pull requests are ignored.
|
|
8
8
|
- Only handles issues and comments created after the first start. After a restart it picks up where it stopped, including runs a crash cut off. A crash right after posting a reply can lead to that reply being posted twice.
|
|
9
9
|
- Each issue gets its own git worktree in `.worktrees/issue-<number>` on branch `issue-<number>`, and its own pi session that continues across comments.
|
|
10
|
+
- The terminal shows each issue's progress: every tool call the agent makes, failed tool calls, and when a branch is pushed or a pull request opened.
|
|
10
11
|
- New issues and comments get an 👀 reaction as soon as they are picked up, then 🚀 once answered or 😕 if the run failed.
|
|
11
12
|
- Issues are handled in parallel, up to 3 at once. Comments on the same issue are handled one after another.
|
|
12
13
|
- The agent's final message is posted as a comment that starts with `agent:`. Comments that start with `agent:` are ignored, so it does not answer itself.
|
package/dist/handler.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { branchFor, ensureWorktree, hasUnpushedCommits, pushBranch } from "./git.js";
|
|
2
2
|
import { agentPrefix } from "./poller.js";
|
|
3
|
-
export async function handleTrigger(trigger, { github, agent, repoRoot }) {
|
|
3
|
+
export async function handleTrigger(trigger, { github, agent, repoRoot, log = () => { }, }) {
|
|
4
4
|
const base = await github.getDefaultBranch();
|
|
5
5
|
const worktree = await ensureWorktree(repoRoot, trigger.issueNumber, base);
|
|
6
|
-
const answer = await agent.run(trigger, { cwd: worktree });
|
|
6
|
+
const answer = await agent.run(trigger, { cwd: worktree, progress: log });
|
|
7
7
|
if (await hasUnpushedCommits(worktree, base)) {
|
|
8
|
-
await pushBranch(worktree);
|
|
9
8
|
const branch = branchFor(trigger.issueNumber);
|
|
9
|
+
await pushBranch(worktree);
|
|
10
|
+
log(`pushed ${branch}`);
|
|
10
11
|
if (!(await github.hasOpenPullRequest(branch))) {
|
|
11
12
|
const issue = await github.getIssue(trigger.issueNumber);
|
|
12
13
|
await github.createPullRequest({
|
|
@@ -15,6 +16,7 @@ export async function handleTrigger(trigger, { github, agent, repoRoot }) {
|
|
|
15
16
|
title: issue.title,
|
|
16
17
|
body: `${agentPrefix} Closes #${trigger.issueNumber}`,
|
|
17
18
|
});
|
|
19
|
+
log("opened a pull request");
|
|
18
20
|
}
|
|
19
21
|
}
|
|
20
22
|
await github.postComment(trigger.issueNumber, `${agentPrefix} ${answer}`);
|
package/dist/pi-agent.js
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import { createAgentSession, SessionManager } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import { describeToolCall } from "./progress.js";
|
|
3
4
|
import { buildPrompt } from "./prompt.js";
|
|
4
5
|
export function createPiAgent({ github, repo, sessionsDir }) {
|
|
5
6
|
return {
|
|
6
|
-
async run(trigger, { cwd }) {
|
|
7
|
+
async run(trigger, { cwd, progress }) {
|
|
7
8
|
const sessionManager = SessionManager.continueRecent(cwd, join(sessionsDir, `issue-${trigger.issueNumber}`));
|
|
8
9
|
const { session } = await createAgentSession({ cwd, sessionManager });
|
|
10
|
+
const unsubscribe = session.subscribe((event) => {
|
|
11
|
+
if (event.type === "tool_execution_start" && !event.parentToolCallId)
|
|
12
|
+
progress(describeToolCall(event.toolName, event.args));
|
|
13
|
+
if (event.type === "tool_execution_end" && event.isError && !event.parentToolCallId)
|
|
14
|
+
progress(`${event.toolName} failed`);
|
|
15
|
+
});
|
|
9
16
|
try {
|
|
10
17
|
const issue = await github.getIssue(trigger.issueNumber);
|
|
11
18
|
const firstInSession = session.messages.length === 0;
|
|
@@ -13,6 +20,7 @@ export function createPiAgent({ github, repo, sessionsDir }) {
|
|
|
13
20
|
return session.getLastAssistantText() ?? "";
|
|
14
21
|
}
|
|
15
22
|
finally {
|
|
23
|
+
unsubscribe();
|
|
16
24
|
session.dispose();
|
|
17
25
|
}
|
|
18
26
|
},
|
package/dist/progress.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const maximumLength = 100;
|
|
2
|
+
export function describeToolCall(toolName, args) {
|
|
3
|
+
const values = args !== null && typeof args === "object" ? args : {};
|
|
4
|
+
const detail = ["command", "path", "pattern", "query"].map((key) => values[key]).find((value) => typeof value === "string") ??
|
|
5
|
+
JSON.stringify(args ?? {});
|
|
6
|
+
const line = detail.split("\n")[0] ?? "";
|
|
7
|
+
return `${toolName}: ${line.length > maximumLength ? `${line.slice(0, maximumLength - 1)}…` : line}`;
|
|
8
|
+
}
|
package/dist/watch.js
CHANGED
|
@@ -37,7 +37,7 @@ export async function watch({ github, agent, repoRoot, stateFile, intervalMs, co
|
|
|
37
37
|
concurrency,
|
|
38
38
|
handle: async (trigger) => {
|
|
39
39
|
try {
|
|
40
|
-
await handleTrigger(trigger, { github, agent, repoRoot });
|
|
40
|
+
await handleTrigger(trigger, { github, agent, repoRoot, log: (message) => log(`#${trigger.issueNumber}: ${message}`) });
|
|
41
41
|
log(`#${trigger.issueNumber}: answered @${trigger.author}`);
|
|
42
42
|
await react(trigger, "rocket");
|
|
43
43
|
}
|