Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality to diff GitHub Actions job logs and update related documentation and tool definitions #748

Merged
merged 5 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docs/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion docs/src/components/BuiltinTools.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
<LinkCard title="github_actions_workflows_list" description="List all workflows as a list of 'id: name' pair." href="/genaiscript/reference/scripts/system#systemgithub_actions" />
<LinkCard title="github_actions_runs_list" description="List all runs for a workflow. Use 'git_actions_list_workflows' to list workflows." href="/genaiscript/reference/scripts/system#systemgithub_actions" />
<LinkCard title="github_actions_jobs_list" description="List all jobs for a run." href="/genaiscript/reference/scripts/system#systemgithub_actions" />
<LinkCard title="github_actions_job_log" description="Download job log." href="/genaiscript/reference/scripts/system#systemgithub_actions" />
<LinkCard title="github_actions_job_logs_get" description="Download workflow job log." href="/genaiscript/reference/scripts/system#systemgithub_actions" />
<LinkCard title="github_actions_job_los_diff" description="Diffs two workflow job logs." href="/genaiscript/reference/scripts/system#systemgithub_actions" />

Check failure on line 24 in docs/src/components/BuiltinTools.mdx

View workflow job for this annotation

GitHub Actions / build

There seems to be a typo here. The correct tool name should be 'github_actions_job_logs_diff' instead of 'github_actions_job_los_diff'.
pelikhan marked this conversation as resolved.
Show resolved Hide resolved
<LinkCard title="github_files_get" description="Get a file from a repository." href="/genaiscript/reference/scripts/system#systemgithub_files" />
<LinkCard title="github_files_list" description="List all files in a repository." href="/genaiscript/reference/scripts/system#systemgithub_files" />
<LinkCard title="github_issues_list" description="List all issues in a repository." href="/genaiscript/reference/scripts/system#systemgithub_issues" />
Expand Down
39 changes: 36 additions & 3 deletions docs/src/content/docs/reference/scripts/system.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
type: "string",
description: "Query to answer",
},
required: ["query"],
},
async (args) => {
const { context, query } = args
Expand Down Expand Up @@ -146,6 +147,7 @@
"system.retrieval_fuzz_search",
"system.md_frontmatter",
],
label: "agent file system"
}
)
return res
Expand Down Expand Up @@ -178,6 +180,7 @@
type: "string",
description: "Query to answer",
},
required: ["query"],
},
async (args) => {
const { context, query } = args
Expand All @@ -202,6 +205,7 @@
"system.explanations",
"system.git",
],
label: "agent git"
}
)
return res
Expand Down Expand Up @@ -234,6 +238,7 @@
type: "string",
description: "Query to answer",
},
required: ["query"],
},
async (args) => {
const { context, query } = args
Expand All @@ -246,8 +251,12 @@

Analyze and answer QUERY.

## Constraints

- Assume that your answer will be analyzed by an LLM, not a human.
- If you cannot answer the query, return an empty string.
- Prefer diffing job logs rather downloading entire logs which can be very large.
pelikhan marked this conversation as resolved.
Show resolved Hide resolved

`
},
{
Expand All @@ -261,6 +270,7 @@
"system.github_issues",
"system.github_pulls",
],
label: "agent github",
}
)
return res
Expand Down Expand Up @@ -796,7 +806,8 @@
- tool `github_actions_workflows_list`: List all workflows as a list of 'id: name' pair.
- tool `github_actions_runs_list`: List all runs for a workflow. Use 'git_actions_list_workflows' to list workflows.
- tool `github_actions_jobs_list`: List all jobs for a run.
- tool `github_actions_job_log`: Download job log.
- tool `github_actions_job_logs_get`: Download workflow job log.
- tool `github_actions_job_los_diff`: Diffs two workflow job logs.

`````js wrap title="system.github_actions"
system({
Expand Down Expand Up @@ -881,8 +892,8 @@
)

defTool(
"github_actions_job_log",
"Download job log.",
"github_actions_job_logs_get",
"Download workflow job log.",
pelikhan marked this conversation as resolved.
Show resolved Hide resolved
{
job_id: {
type: "string",
Expand All @@ -900,6 +911,28 @@
}
)

defTool(
"github_actions_job_los_diff",
"Diffs two workflow job logs.",
{
job_id: {
type: "string",
description: "ID of the job to compare.",
},
other_job_id: {
type: "string",
description: "ID of the other job to compare.",
},
required: ["job_id", "other_job_id"],
},
async (args) => {
const { job_id, other_job_id, context } = args
context.log(`github action diff job logs ${job_id} ${other_job_id}`)
const log = await github.diffWorkflowJobLogs(job_id, other_job_id)
return log
}
)

Check failure on line 934 in docs/src/content/docs/reference/scripts/system.mdx

View workflow job for this annotation

GitHub Actions / build

The tool name 'github_actions_job_los_diff' is incorrect. It should be 'github_actions_job_logs_diff' as per the naming convention used for other tools.
pelikhan marked this conversation as resolved.
Show resolved Hide resolved
pelikhan marked this conversation as resolved.
Show resolved Hide resolved

`````


Expand Down
8 changes: 7 additions & 1 deletion genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion packages/auto/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/core/src/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@
cancellationToken,
} = options

stats.addUsage(req.model, resp.usage)
stats.addUsage(req, resp.usage)

Check failure on line 450 in packages/core/src/chat.ts

View workflow job for this annotation

GitHub Actions / build

The argument passed to `stats.addUsage` function has been changed from `req.model` to `req`. This might cause a type error if the function is expecting a string as an argument.
pelikhan marked this conversation as resolved.
Show resolved Hide resolved

if (resp.text)
messages.push({
Expand Down
8 changes: 7 additions & 1 deletion packages/core/src/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/core/src/genaisrc/system.agent_fs.genai.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ defTool(
"system.retrieval_fuzz_search",
"system.md_frontmatter",
],
label: "agent file system"
}
)
return res
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/genaisrc/system.agent_git.genai.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ defTool(
"system.explanations",
"system.git",
],
label: "agent git"
}
)
return res
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/genaisrc/system.agent_github.genai.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ defTool(

Analyze and answer QUERY.

## Constraints

- Assume that your answer will be analyzed by an LLM, not a human.
- If you cannot answer the query, return an empty string.
- Prefer diffing job logs rather downloading entire logs which can be very large.

`
},
{
Expand All @@ -40,6 +44,7 @@ defTool(
"system.github_issues",
"system.github_pulls",
],
label: "agent github",
}
)
return res
Expand Down
26 changes: 24 additions & 2 deletions packages/core/src/genaisrc/system.github_actions.genai.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ defTool(
)

defTool(
"github_actions_job_log",
"Download job log.",
"github_actions_job_logs_get",
"Download workflow job log.",
{
job_id: {
type: "string",
Expand All @@ -98,3 +98,25 @@ defTool(
return log
}
)

defTool(
"github_actions_job_los_diff",
"Diffs two workflow job logs.",
{
job_id: {
type: "string",
description: "ID of the job to compare.",
},
other_job_id: {
type: "string",
description: "ID of the other job to compare.",
},
required: ["job_id", "other_job_id"],
},
async (args) => {
const { job_id, other_job_id, context } = args
context.log(`github action diff job logs ${job_id} ${other_job_id}`)
const log = await github.diffWorkflowJobLogs(job_id, other_job_id)
return log
}
)
27 changes: 14 additions & 13 deletions packages/core/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ export class GitClient implements Git {
}
): Promise<WorkspaceFile[]> {
const { askStageOnEmpty } = options || {}
const paths = arrayify(options?.paths).filter((f) => !!f)
const excludedPaths = arrayify(options?.excludedPaths).filter(
(f) => !!f
)
const paths = arrayify(options?.paths, { filterEmpty: true })
const excludedPaths = arrayify(options?.excludedPaths, {
filterEmpty: true,
})

let filenames: string[]
if (scope === "modified-base" || scope === "staged") {
const args = ["diff", "--name-only", "--diff-filter=AM"]
Expand Down Expand Up @@ -177,10 +178,10 @@ export class GitClient implements Git {
excludedPaths?: ElementOrArray<string>
}): Promise<GitCommit[]> {
const { base, head, merges, excludedGrep } = options || {}
const paths = arrayify(options?.paths).filter((f) => !!f)
const excludedPaths = arrayify(options?.excludedPaths).filter(
(f) => !!f
)
const paths = arrayify(options?.paths, { filterEmpty: true })
const excludedPaths = arrayify(options?.excludedPaths, {
filterEmpty: true,
})

const args = ["log", "--pretty=oneline"]
if (!merges) args.push("--no-merges")
Expand All @@ -192,7 +193,7 @@ export class GitClient implements Git {
args.push(`--grep='${pattern}'`, "--invert-grep")
}
if (base && head) args.push(`${base}..${head}`)
GitClient.addFileFilters(arrayify(paths), arrayify(excludedPaths), args)
GitClient.addFileFilters(paths, excludedPaths, args)
const res = await this.exec(args)
const commits = res
.split("\n")
Expand Down Expand Up @@ -221,10 +222,10 @@ export class GitClient implements Git {
unified?: number
llmify?: boolean
}): Promise<string> {
const paths = arrayify(options?.paths).filter((f) => !!f)
const excludedPaths = arrayify(options?.excludedPaths).filter(
(f) => !!f
)
const paths = arrayify(options?.paths, { filterEmpty: true })
const excludedPaths = arrayify(options?.excludedPaths, {
filterEmpty: true,
})
const { staged, base, head, unified, askStageOnEmpty } = options || {}
const args = ["diff"]
if (staged) args.push("--staged")
Expand Down
26 changes: 26 additions & 0 deletions packages/core/src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import { isGlobMatch } from "./glob"
import { fetchText } from "./fetch"
import { concurrentLimit } from "./concurrency"
import { createDiff, llmifyDiff } from "./diff"

export interface GithubConnectionInfo {
token: string
Expand Down Expand Up @@ -706,6 +707,31 @@
return text
}

private async downladJob(job_id: number) {
pelikhan marked this conversation as resolved.
Show resolved Hide resolved
const { client, owner, repo } = await this.client()
const filename = `job-${job_id}.log`
const { url } = await client.rest.actions.downloadJobLogsForWorkflowRun(
{
owner,
repo,
job_id,
}
)
const { text: content } = await fetchText(url)
return { filename, url, content }
}

async diffWorkflowJobLogs(job_id: number, other_job_id: number) {
const job = await this.downladJob(job_id)
const other = await this.downladJob(other_job_id)

job.content = parseJobLog(job.content)
other.content = parseJobLog(other.content)

const diff = createDiff(job, other)
return llmifyDiff(diff)
pelikhan marked this conversation as resolved.
Show resolved Hide resolved
}

Check failure on line 733 in packages/core/src/github.ts

View workflow job for this annotation

GitHub Actions / build

The function `parseJobLog` is used but not defined in the provided diff. Make sure it is defined elsewhere in the codebase.
pelikhan marked this conversation as resolved.
Show resolved Hide resolved
pelikhan marked this conversation as resolved.
Show resolved Hide resolved
pelikhan marked this conversation as resolved.
Show resolved Hide resolved

async getFile(filename: string, ref: string): Promise<WorkspaceFile> {
const { client, owner, repo } = await this.client()
const { data: content } = await client.rest.repos.getContent({
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/types/prompt_template.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,11 @@ interface GitHub {
options?: { llmify?: boolean }
): Promise<string>

/**
* Diffs two GitHub Action workflow job logs
*/
diffWorkflowJobLogs(job_id: number, other_job_id: number): Promise<string>

/**
* Lists issues for a given repository
* @param options
Expand Down
Loading
Loading