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
77 changes: 77 additions & 0 deletions .github/workflows/zai-agents-init-example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Zai AGENTS.md Init (Example)

# Example workflow that runs on Mondays to initialize/update AGENTS.md files
# This demonstrates the scheduled tasks feature for AGENTS.md management

on:
schedule:
# Run every Monday at midnight UTC
- cron: "0 0 * * 1"

# Allow manual triggering
workflow_dispatch:

# Required permissions for creating branches and PRs
permissions:
contents: write
pull-requests: write

jobs:
agents-init:
name: Initialize/Update AGENTS.md
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
# Full history needed for branch operations
fetch-depth: 0

- name: Run zai-code-bot with scheduled task
uses: ./
with:
# REQUIRED: Your Z.ai API key
# Store this in repository secrets: Settings > Secrets > Actions > New repository secret
ZAI_API_KEY: ${{ secrets.ZAI_API_KEY }}

# Optional: Model to use (defaults to glm-5.2)
ZAI_MODEL: ${{ vars.ZAI_MODEL || 'glm-5.2' }}

# REQUIRED: URL to your Gist file with AGENTS.md content
# This is the "agents init command" - the gist contains the AGENTS.md template
# Can be set via:
# 1. secrets.ZAI_AGENTS_GIST_URL (recommended for production)
# 2. vars.ZAI_AGENTS_GIST_URL (for organization-wide)
# 3. In .zai-scheduled.yml configuration file
ZAI_AGENTS_GIST_URL: ${{ secrets.ZAI_AGENTS_GIST_URL }}

# Enable scheduled tasks processing
ZAI_SCHEDULED_ENABLED: "true"

# Path to scheduled config (defaults to .zai-scheduled.yml)
ZAI_SCHEDULED_CONFIG_PATH: ".zai-scheduled.yml"

# GitHub token is automatically provided by GitHub Actions
env:
GITHUB_TOKEN: ${{ github.token }}

# Optional job to verify the update worked
verify:
name: Verify AGENTS.md Update
runs-on: ubuntu-latest
needs: agents-init
if: success()

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check for changes
run: |
echo "AGENTS.md update workflow completed successfully"
# Add verification logic here if needed
# For example, check if files were modified:
# git diff --name-only HEAD~1 | grep -q "AGENTS.md" && echo "Files updated" || echo "No changes"
64 changes: 64 additions & 0 deletions .github/workflows/zai-agents-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Zai AGENTS.md Auto-Update

# This workflow runs every Monday to update AGENTS.md files from a Gist URL
# It uses the scheduled tasks feature of zai-code-bot

on:
schedule:
# Run “At 06:00.” UTC
- cron: "0 6 * * *"
workflow_dispatch:
# Allow manual triggering from GitHub UI
inputs:
dry-run:
description: "Dry run (no PR creation)"
required: false
default: "false"

permissions:
contents: write # Required to create branches and update files
pull-requests: write # Required to create PRs
issues: write # Required for comments

jobs:
update-agents:
name: Update AGENTS.md Files
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Required for full git history

- name: Run zai-code-bot scheduled tasks
uses: ./
with:
# Required: Z.ai API key (from repository secrets)
ZAI_API_KEY: ${{ secrets.ZAI_API_KEY }}

# Optional: Z.ai model to use
ZAI_MODEL: ${{ vars.ZAI_MODEL || 'glm-5.2' }}

# Required: URL to raw gist file containing AGENTS.md content
# This can also be configured in .zai-scheduled.yml
ZAI_AGENTS_GIST_URL: ${{ secrets.ZAI_AGENTS_GIST_URL || vars.ZAI_AGENTS_GIST_URL }}

# Enable scheduled tasks
ZAI_SCHEDULED_ENABLED: "true"

# Optional: Path to scheduled configuration file
ZAI_SCHEDULED_CONFIG_PATH: ".zai-scheduled.yml"
env:
# GitHub token for API access (automatically provided by GitHub Actions)
GITHUB_TOKEN: ${{ github.token }}

# Optional: Notify on failure
notify-failure:
name: Notify on Failure
runs-on: ubuntu-latest
needs: update-agents
if: failure() && needs.update-agents.result == 'failure'
steps:
- name: Send notification
run: echo "AGENTS.md update failed. Check workflow logs."
# Replace with actual notification (Slack, email, etc.)
66 changes: 66 additions & 0 deletions .zai-scheduled.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Zai Code Bot - Scheduled Tasks Configuration
# This file configures automated tasks that run on a schedule.
#
# For this repository (zai-code-bot), this configures:
# - Weekly AGENTS.md file updates by executing a command from a Gist URL
#
# IMPORTANT: The Gist URL must contain a command that generates/updates AGENTS.md files.
# The bot will:
# 1. Fetch the command text from the Gist
# 2. Execute the command to generate/update AGENTS.md files
# 3. The command MUST scan the repo and return JSON with all AGENTS.md files to create/update
#
# Gist URL Configuration (priority order):
# 1. ZAI_AGENTS_GIST_URL environment variable (secrets/vars)
# 2. gist_url in task config (below)
# 3. gist_url in defaults (below) - currently set to AndreiDrang's gist
#
# The Gist at the default URL should contain a prompt-command like:
# /init-agentsmd
# This command MUST autonomously scan the repo and return JSON with AGENTS.md tree

version: 1

# Default settings applied to all tasks unless overridden
defaults:
# Target branch for PRs created by scheduled tasks
branch: main

# Default cron schedule (if not specified per-task)
# Format: minute hour day-of-month month day-of-week
# "0 0 * * 1" = every Monday at midnight UTC
schedule: "0 0 * * 1"

# Default Gist URL containing the command to generate AGENTS.md files
# The command in this Gist will be executed to generate the content
# Can be overridden via ZAI_AGENTS_GIST_URL environment variable
gist_url: https://gist.githubusercontent.com/AndreiDrang/1580ae796fe56074b600cee6352a5f14/raw

# Individual scheduled tasks
tasks:
# Update AGENTS.md files weekly on Monday
- id: weekly-agents-update
name: "Weekly AGENTS.md Update"
enabled: true
schedule: "0 0 * * 1" # Every Monday at midnight UTC
command: update-agents
config:
# Branch to update - will create PR targeting this branch
branch: main

# PR configuration
pr_title: "chore: update AGENTS.md files"
pr_body: |
Automated weekly update of AGENTS.md files from Gist.

This PR was automatically generated by zai-code-bot scheduled task.
The command was fetched from the Gist URL configured in ZAI_AGENTS_GIST_URL
and executed to discover and update all AGENTS.md files in the repository.

The agent autonomously scanned the repository and generated updated AGENTS.md files.

To modify the Gist URL:
1. Go to Settings > Secrets > Actions
2. Update the ZAI_AGENTS_GIST_URL secret
3. Or update this configuration file
commit_message: "docs: update AGENTS.md from scheduled task"
148 changes: 148 additions & 0 deletions .zai-scheduled.yml.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# Zai Code Bot - Scheduled Tasks Configuration
#
# This file configures automated tasks that run on a schedule.
# Place this file in the root of your repository as .zai-scheduled.yml
#
# Documentation: https://github.com/AndreiDrang/zai-code-bot#scheduled-tasks
#
# ============================================================================
# CONFIGURATION EXAMPLE
# ============================================================================

version: 1

# Default settings applied to all tasks unless overridden
defaults:
# Target branch for PRs created by scheduled tasks
branch: main

# Default cron schedule (if not specified per-task)
# Format: minute hour day-of-month month day-of-week
# Example: "0 0 * * 0" = every Sunday at midnight UTC
# See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule
schedule: "0 0 * * 0"

# Default Gist URL for commands
# This is used by update-agents task to fetch content
# Can also be set via ZAI_AGENTS_GIST_URL environment variable
gist_url: https://gist.githubusercontent.com/AndreiDrang/1580ae796fe56074b600cee6352a5f14/raw

# Individual scheduled tasks
tasks:
# Update AGENTS.md files weekly
# The command will scan the repo and find all AGENTS.md files to create/update
- id: weekly-agents-update
name: "Weekly AGENTS.md Update"
enabled: true
schedule: "0 0 * * 0" # Weekly on Sunday at midnight UTC
command: update-agents
config:
# Branch to update (defaults to defaults.branch)
branch: main

# URL to fetch content from
gist_url: https://gist.githubusercontent.com/AndreiDrang/1580ae796fe56074b600cee6352a5f14/raw

# PR configuration
pr_title: "chore: update AGENTS.md files"
pr_body: |
Automated weekly update of AGENTS.md files from gist.

The agent autonomously scanned the repository and updated all AGENTS.md files.
Generated by zai-code-bot scheduled task.
commit_message: "docs: update AGENTS.md from scheduled task"

# Example: Additional task (disabled by default)
# Uncomment and configure to enable
# - id: daily-docs-sync
# name: "Daily Documentation Sync"
# enabled: false
# schedule: "0 12 * * *" # Daily at noon UTC
# command: sync-docs
# config:
# source_repo: my-org/docs-repo
# target_path: docs/
# pr_title: "docs: sync documentation"
# pr_body: "Automated daily documentation sync"
# commit_message: "docs: sync from upstream"

# ============================================================================
# WORKFLOW EXAMPLE
# ============================================================================
#
# Create a file at: .github/workflows/zai-scheduled.yml
#
# name: Zai Scheduled Tasks
#
# on:
# schedule:
# - cron: "0 0 * * 0" # Weekly on Sunday
# workflow_dispatch: # Allow manual triggering
#
# permissions:
# contents: write # Required to create branches and PRs
# pull-requests: write
#
# jobs:
# zai-scheduled:
# name: Run Scheduled Tasks
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# with:
# fetch-depth: 0 # Required for git history
#
# - name: Run scheduled tasks
# uses: AndreiDrang/zai-code-bot@main
# with:
# ZAI_API_KEY: ${{ secrets.ZAI_API_KEY }}
# ZAI_MODEL: ${{ vars.ZAI_MODEL }}
# ZAI_SCHEDULED_ENABLED: "true"
# ZAI_AGENTS_GIST_URL: ${{ vars.ZAI_AGENTS_GIST_URL }} # Or use secrets.ZAI_AGENTS_GIST_URL
#
# ============================================================================
# AVAILABLE COMMANDS
# ============================================================================
#
# update-agents: Fetches and executes a command from a Gist URL to update files
# Gist URL can be configured via: gist_url (config) or ZAI_AGENTS_GIST_URL (env var)
#
# The command in the Gist MUST return a JSON response with file updates.
# The command scans the repo and determines which AGENTS.md files to create/update.
#
# Required config: branch (optional, defaults to main)
# Optional config: gist_url, pr_title, pr_body, commit_message
#
# Example command for auto-discovery mode (should be in Gist):
# /init-agentsmd
# This command must return JSON like:
# {
# "summary": "Updated 3 AGENTS.md files",
# "files": [
# {"path": "AGENTS.md", "content": "...", "action": "updated"},
# {"path": "src/lib/AGENTS.md", "content": "...", "action": "created"}
# ]
# }
#
# ============================================================================
# CRON SCHEDULE REFERENCE
# ============================================================================
#
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
# │ │ │ │ │
# │ │ │ │ │
# * * * * *
#
# Examples:
# "0 0 * * *" - Every day at midnight UTC
# "0 0 * * 0" - Every Sunday at midnight UTC
# "0 9 * * 1-5" - Every weekday at 9 AM UTC
# "0 */6 * * *" - Every 6 hours
#
# Note: GitHub Actions uses UTC timezone
# See: https://crontab.guru/ for help with cron expressions
12 changes: 12 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ inputs:
description: "Maximum diff characters per file chunk before splitting a large patch across review parts"
required: false
default: "18000"
ZAI_SCHEDULED_ENABLED:
description: "Enable scheduled tasks execution"
required: false
default: "true"
ZAI_SCHEDULED_CONFIG_PATH:
description: "Path to scheduled tasks configuration file"
required: false
default: ".zai-scheduled.yml"
ZAI_AGENTS_GIST_URL:
description: "URL to raw gist file for AGENTS.md updates"
required: false
default: ""
runs:
using: "node20"
main: "dist/index.js"
Loading
Loading