task

A set of project rules for GoTask, an asynchronous task framework for Go. It treats each operation as a task arranged in a parent-child hierarchy and managed through a shared event loop.

In plain words
What is it for?
Use it when implementing or reviewing GoTask code, especially task creation, parent-child execution, shutdown, disposal, and resource cleanup.
Why use it?
It helps keep task execution predictable and prevents unsafe concurrency, lifecycle, and cleanup patterns.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/langhuihui/gotask/task
Clone the repo
git clone --depth 1 https://github.com/langhuihui/gotask
Per session 2,425 This file is loaded in full into every session.
When invoked 2,425 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.02425 $0.02425
Opus 5 $0.01213 $0.01213
Sonnet 5 $0.00485 $0.00485
Haiku 4.5 $0.00243 $0.00243

Measured 2d ago against content hash 83b75fb8125e, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

task scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

ai_rules/.codebuddy/.rules/task.mdc · 387 lines

How it starts

The opening of the file, as written. The whole thing — 387 lines — stays where its author put it; the contents beside it link to each section on GitHub.

CodeBuddy (Tencent) Rules for GoTask Project

Project Context

GoTask is an asynchronous task management framework for Go that implements an "Everything is a Task" philosophy. It provides OS-like task manager capabilities with precise control over different granularity levels of system components.

Core Architectural Principles

1. Single Goroutine Event Loop (CRITICAL)

  • NEVER create goroutines directly in task implementations
  • All child tasks execute sequentially in the parent task's goroutine
  • This eliminates race conditions and ensures predictable execution
  • Use parent.AddTask(child) instead of go func()

2. Task Hierarchy and Lifecycle

  • Tasks form a tree structure with parent-child relationships
  • Each task has a unique ID for tracking and management
  • Use RootManager as the root task manager for signal handling
  • Implement proper Start(), Run(), and Dispose() methods

3. Resource Management Philosophy

  • Framework handles cascading disposal automatically
  • Use OnStop() and OnDispose() hooks for cleanup
  • Implement graceful shutdown patterns
  • Never call Start() directly - it must be called by the parent task

Task Type System

task.Task (Base Task)

  • Use for simple, single-purpose tasks
  • Basic task implementation with lifecycle methods

task.Job (Container Task)

  • Can contain child tasks
  • Ends when all child tasks complete
  • Use for task coordinators and containers

task.Work (Persistent Task)

  • Similar to Job but continues after children complete
  • Use for background workers and long-running services

task.TickTask (Periodic Task)

  • Executes at regular intervals
  • Implement GetTickInterval() time.Duration
  • Use for timers, heartbeats, cleanup tasks

task.ChannelTask (Event-Driven Task)

  • Custom signal-based tasks
  • Override GetSignal() method
  • Use for event-driven and reactive tasks

Implementation Patterns

Standard Task Template

type MyTask struct {
    task.Task  // Choose appropriate type
    // Task-specific fields
    Name        string
    Config      map[string]interface{}
    Resources   []Resource
}

func (t *MyTask) Start() error {
    // Resource initialization
    t.Info("Task starting", "name", t.Name, "taskId", t.GetID())
    
    // Add resource dependencies
    t.Using(t.Resources...)
    
    // OnStop: 用于关闭阻塞性资源(如端口监听、网络连接)
    t.OnStop(func() {
        // 关闭阻塞性资源,如 server.Close(), conn.Close()
        server.Close()
    })
    
    // OnDispose: 用于清理非阻塞性资源
    t.OnDispose(func() {
        // 清理其他资源,如缓存、文件句柄等
        cache.Flush()
    })
    
    return nil
}

func (t *MyTask) Run() error {
    // Main task logic (blocking)
    for !t.IsStopped() {
        // Do work
        if err := t.doWork(); err != nil {
            return err
        }
    }
    return t.StopReason()
}

func (t *MyTask) Dispose() {
    // Resource cleanup
    t.Info("Task disposing", "name", t.Name)
    for _, resource := range t.Resources {
        resource.Close()
    }
}

Read the full file on GitHub · 387 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 387 lines · 2,425 tokens per session scan A 83b75fb8125e

Subscribe to this mod's changes

task is a cursor rule published in the GitHub repository langhuihui/gotask (77 stars, last pushed 11d ago), licensed MIT. It adds 2,425 tokens to every session, about $0.0121 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.