From d7855cd6ff5c78d1e39ef5abf42731747a10c286 Mon Sep 17 00:00:00 2001 From: davideast <4570265+davideast@users.noreply.github.com> Date: Tue, 10 Mar 2026 00:35:51 +0000 Subject: [PATCH] Fixes #236: Added GitHub Action AgentSkills Example Added an example demonstrating how to use the Jules SDK on a scheduled GitHub Action cron job to analyze a repository for Agent Skills. Included full Action config and updated READMEs. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- packages/core/README.md | 1 + .../github-action-agentskills/README.md | 55 ++++++++++++ .../github-action-agentskills/action.yml | 5 ++ .../github-action-agentskills/index.ts | 89 +++++++++++++++++++ .../github-action-agentskills/package.json | 18 ++++ .../github-action-agentskills/tsconfig.json | 13 +++ 6 files changed, 181 insertions(+) create mode 100644 packages/core/examples/github-action-agentskills/README.md create mode 100644 packages/core/examples/github-action-agentskills/action.yml create mode 100644 packages/core/examples/github-action-agentskills/index.ts create mode 100644 packages/core/examples/github-action-agentskills/package.json create mode 100644 packages/core/examples/github-action-agentskills/tsconfig.json diff --git a/packages/core/README.md b/packages/core/README.md index c3d32e7..9596ac9 100644 --- a/packages/core/README.md +++ b/packages/core/README.md @@ -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 diff --git a/packages/core/examples/github-action-agentskills/README.md b/packages/core/examples/github-action-agentskills/README.md new file mode 100644 index 0000000..06b8a66 --- /dev/null +++ b/packages/core/examples/github-action-agentskills/README.md @@ -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. diff --git a/packages/core/examples/github-action-agentskills/action.yml b/packages/core/examples/github-action-agentskills/action.yml new file mode 100644 index 0000000..a94e918 --- /dev/null +++ b/packages/core/examples/github-action-agentskills/action.yml @@ -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' diff --git a/packages/core/examples/github-action-agentskills/index.ts b/packages/core/examples/github-action-agentskills/index.ts new file mode 100644 index 0000000..a455ce0 --- /dev/null +++ b/packages/core/examples/github-action-agentskills/index.ts @@ -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(); diff --git a/packages/core/examples/github-action-agentskills/package.json b/packages/core/examples/github-action-agentskills/package.json new file mode 100644 index 0000000..395dea4 --- /dev/null +++ b/packages/core/examples/github-action-agentskills/package.json @@ -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" + } +} diff --git a/packages/core/examples/github-action-agentskills/tsconfig.json b/packages/core/examples/github-action-agentskills/tsconfig.json new file mode 100644 index 0000000..487a581 --- /dev/null +++ b/packages/core/examples/github-action-agentskills/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "CommonJS", + "moduleResolution": "node", + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "outDir": "./dist" + }, + "include": ["index.ts"] +}