Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Orchestrate complex, long-running coding tasks to an ephemeral cloud environment
- [Agent Workflow](./examples/agent/README.md)
- [Webhook Integration](./examples/webhook/README.md)
- [GitHub Actions](./examples/github-actions/README.md)
- [Github Action Agentskills](./examples/github-action-agentskills/README.md)

## Send work to a Cloud based session

Expand Down
55 changes: 55 additions & 0 deletions packages/core/examples/github-action-agentskills/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# GitHub Action Agent Skills Example

This example demonstrates how to use the Jules SDK on a scheduled GitHub Action cron job to analyze a repository and generate suggestions for Agent Skills that improve automation.

## Overview

The action reads the Agent Skills specification from [https://agentskills.io/specification.md](https://agentskills.io/specification.md) and instructs the Jules agent to:
1. Review the repository structure and workflows.
2. Identify areas where an Agent Skill could be beneficial.
3. Create corresponding Agent Skills configuration files.
4. Generate a pull request with the suggested changes.

## Files

- `index.ts`: The main action logic using the Jules SDK.
- `package.json`: Dependencies for the action (`@actions/core`, `@actions/github`, `@google/jules-sdk`).

## Usage

You can use this action in your own GitHub workflows by referencing its path or publishing it.

Here is an example workflow file (`.github/workflows/jules-agentskills.yml`) that triggers the agent on a weekly schedule:

```yaml
name: Jules Agent Skills Generator

on:
schedule:
# Run at 00:00 every Monday
- cron: '0 0 * * 1'

jobs:
run-jules-agentskills:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Run Jules Agent Skills Analyzer
uses: ./packages/core/examples/github-action-agentskills
env:
JULES_API_KEY: ${{ secrets.JULES_API_KEY }}
```

## Running the Example Locally

To compile the TypeScript action:

```bash
cd packages/core/examples/github-action-agentskills
npm install
npm run build
```

The compiled JavaScript will be placed in `dist/index.js`, which is what GitHub Actions will execute.
5 changes: 5 additions & 0 deletions packages/core/examples/github-action-agentskills/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: 'Jules Agent Skills Generator'
description: 'Analyze repository for Agent Skills using a scheduled GitHub Action cron job'
runs:
using: 'node20'
main: 'dist/index.js'
89 changes: 89 additions & 0 deletions packages/core/examples/github-action-agentskills/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import * as core from '@actions/core';
import * as github from '@actions/github';
import { jules } from '@google/jules-sdk';

async function run() {
try {
if (!process.env.JULES_API_KEY) {
throw new Error('JULES_API_KEY environment variable is missing.');
}

// 1. Get context about the current repository from the GitHub Action payload
const context = github.context;
// In a cron job, context.repo will still point to the repository where the workflow is running
const owner = context.repo.owner || process.env.GITHUB_REPOSITORY?.split('/')[0] || 'unknown';
const repo = context.repo.repo || process.env.GITHUB_REPOSITORY?.split('/')[1] || 'unknown';
const ref = context.ref || process.env.GITHUB_REF || 'refs/heads/main';

let baseBranch = 'main';
if (ref.startsWith('refs/heads/')) {
baseBranch = ref.replace('refs/heads/', '');
}

core.info(`Starting Jules session for ${owner}/${repo} on branch ${baseBranch}`);

// 2. Construct the prompt for generating Agent Skills
const prompt = `Analyze this repository and suggest Agent Skills to improve automation of common or complex tasks.

Use the Agent Skills specification located at https://agentskills.io/specification.md as a reference for formatting and structuring the skills.

Tasks:
1. Review the repository structure, code, and existing workflows.
2. Identify 1 to 3 areas where an Agent Skill could be beneficial (e.g., code review, automated testing, boilerplate generation, or specific formatting rules).
3. Create the corresponding Agent Skills configuration files (e.g., in a \`.jules/skills\` directory or similar, as per the specification).
4. Provide a brief explanation of what each skill does and why it is useful for this repository.`;

core.info(`Prompt: ${prompt}`);

// 3. Create a new Jules session
const session = await jules.session({
prompt: prompt,
source: {
github: `${owner}/${repo}`,
baseBranch: baseBranch,
},
// Automatically create a PR when the session is complete
autoPr: true,
});

core.info(`Session created successfully. ID: ${session.id}`);

// 4. Monitor the progress
for await (const activity of session.stream()) {
switch (activity.type) {
case 'planGenerated':
core.info(`[Plan Generated] ${activity.plan.steps.length} steps.`);
break;
case 'progressUpdated':
core.info(`[Progress Updated] ${activity.title}`);
break;
case 'sessionCompleted':
core.info(`[Session Completed]`);
break;
}
}

// 5. Wait for the final outcome
const outcome = await session.result();

if (outcome.state === 'failed') {
core.setFailed(`Session failed.`);
return;
}

core.info(`Session finished successfully.`);

if (outcome.pullRequest) {
core.info(`Pull Request created: ${outcome.pullRequest.url}`);
core.setOutput('pr-url', outcome.pullRequest.url);
}
} catch (error) {
if (error instanceof Error) {
core.setFailed(`Action failed with error: ${error.message}`);
} else {
core.setFailed(`Action failed with an unknown error.`);
}
}
}

run();
18 changes: 18 additions & 0 deletions packages/core/examples/github-action-agentskills/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "jules-github-action-agentskills-example",
"version": "1.0.0",
"description": "Analyze repository for Agent Skills using a scheduled GitHub Action cron job",
"main": "dist/index.js",
"scripts": {
"build": "tsc"
},
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/github": "^6.0.0",
"@google/jules-sdk": "workspace:*"
},
"devDependencies": {
"@types/node": "^20.0.0",
"typescript": "^5.0.0"
}
}
13 changes: 13 additions & 0 deletions packages/core/examples/github-action-agentskills/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "CommonJS",
"moduleResolution": "node",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"outDir": "./dist"
},
"include": ["index.ts"]
}
Loading