AGENT SKILL

timesharing

Multiplexes one agent's attention across independent long-running external processes while preserving one reasoning context. Use for concurrent tests, builds, servers, watchers, REPLs, benchmarks, downloads, and other latency-bearing shell work; never use it to spawn or substitute subagents.

License 许可
MIT
所属仓库
roerohan/skills
最近更新
2026-09-04
Stars
★ 29
Forks
1

01 前言 Front Matter

name
timesharing
description
Multiplexes one agent's attention across independent long-running external processes while preserving one reasoning context. Use for concurrent tests, builds, servers, watchers, REPLs, benchmarks, downloads, and other latency-bearing shell work; never use it to spawn or substitute subagents.
compatibility
Prefers tmux; supports a non-interactive shell-background fallback on macOS and Linux.

02 资源文件 3

03 SKILL.md 正文

Timesharing

Timesharing lets one agent preserve one coherent reasoning context while opportunistically multiplexing its attention across independent external work.

The AI's reasoning stays serial. Only ordinary OS processes run concurrently. Never spawn a subagent, delegate interpretation, or create another AI context for this workflow.

Central Rule

Never block on an independent long-running process when useful independent work exists.

Treat yourself as a cooperative scheduler:

  1. Identify a command whose result is not immediately required.
  2. Start it asynchronously and record its purpose, provenance, dependency, and revisit point.
  3. Continue concrete independent work immediately.
  4. Revisit at a natural boundary, not through busy polling.
  5. Interpret the result in the same context that launched it.

Use a small number of jobs, usually 2-4. The goal is to hide external latency without losing cognitive coherence, not to maximize concurrency.

Decide

Timeshare when judgment says all of these are true:

  • The command may take meaningful time or must remain alive.
  • Its result is not required for the next reasoning step.
  • Useful independent work exists, or later interaction/incremental output matters.
  • Its inputs are stable enough that the run will remain useful.

Typical jobs include test suites, builds, installs, Docker builds, servers, watchers, long scripts, migrations, data/model processing, downloads, benchmarks, integration tests, REPLs, and debuggers.

Run trivial or immediately blocking commands normally: pwd, git status, small reads, quick searches, and commands whose answer determines the very next step. Use judgment, not a hard timing threshold.

Schedule

Before launch, form a tiny dependency graph. Only overlap genuinely independent work. Do not start a run whose inputs are likely to be invalidated immediately.

Maintain a lightweight in-context ledger:

JOB       PURPOSE             LOCATION                 STATE    DEPENDS/REVISIT
ts-tests  validate parser     tmux:ts-repo-tests-...   running  after serializer edit
ts-api    integration target  tmux:ts-repo-api-...     persistent before requests

Know for each job: what and why, location, state, expected result, dependents, revisit point, and code/input provenance. The helper persists operational metadata; the purpose and dependency graph remain in this agent's unified mental model.

Natural scheduling points include after an edit, before a dependent decision, after another job completes, when no independent work remains, before final response, or when input may be needed. Do not repeatedly check a job without useful work between checks. If nothing useful remains, bounded waiting or inspection is honest and appropriate.

Use The Interface

The bundled script prefers isolated tmux sessions and falls back to background processes when tmux is unavailable. Run it by absolute path when necessary:

timesharing/scripts/timeshare.sh start tests \
  --purpose 'validate parser fix' --dependency 'review after serializer edit' \
  --provenance 'parser change A' -- npm test
timesharing/scripts/timeshare.sh start api --persistent \
  --purpose 'serve integration target' -- npm run dev
timesharing/scripts/timeshare.sh list
timesharing/scripts/timeshare.sh status tests
timesharing/scripts/timeshare.sh inspect tests --lines 80
timesharing/scripts/timeshare.sh send repl --literal 'value.inspect' --enter
timesharing/scripts/timeshare.sh interrupt api
timesharing/scripts/timeshare.sh stop api
timesharing/scripts/timeshare.sh cleanup

Names become lowercase ts-* job IDs. The tmux session also includes a repository name and workspace hash, preventing cross-repository collisions. Existing live jobs are never silently replaced. Resolve and inspect exact registered IDs before sending input, interrupting, or stopping anything.

For detailed operations, states, fallback behavior, and failures, read references/operations.md. For scheduling examples, read references/examples.md. Load the lower-level tmux skill only when pane layout or tmux-specific mechanics beyond this interface are needed.

Interpret State And Output

The lifecycle is:

planned -> running -> completed | failed | waiting | persistent
        -> consumed -> cleaned up

The helper detects running, completed, failed, persistent, and unexpectedly terminated. For interactive jobs, infer waiting versus computing from the recent tail and prompt. Infer a stall only from elapsed time, unchanged output, expected behavior, and process state; do not guess from silence alone.

Inspect recent output first. Increase --lines only when the error needs earlier context. Never flood this context with whole logs by default. Treat a missing completion marker as unknown/unexpected termination, not success.

Before consuming a result, compare its launch provenance with current files/configuration. A run against state A does not validate later state B. Rerun relevant validation after material edits.

Interactive And Persistent Jobs

Mark servers/watchers with --persistent; continued execution is expected, not failure. Mark REPLs/debuggers with --interactive; tmux is required. Inspect the exact job before send, and send the least powerful input needed. Never send destructive keys to an uncertain target.

The shell fallback supports finite and persistent non-interactive commands, but not interactive input or durable terminal attachment. Report that limitation when fallback is used.

Finish

Before answering the user:

  • Inspect every important outstanding finite job.
  • Never claim success without a verified zero exit status.
  • Check that results still match the current code/input state.
  • State which requested services intentionally remain persistent.
  • Stop and clean disposable jobs you own; never kill uncertain or unrelated processes.
  • Preserve services the user explicitly asked to leave running.

Communicate only meaningful transitions: "Tests are running while I inspect the serializer" or "The build passed; integration tests are still running." Do not narrate every tmux command or status check.

Anti-Patterns

  • Subagent substitution: same agent launches a process; never spawn another AI to run or interpret it.
  • Fake concurrency: do useful work after launch; do not launch and immediately poll in a loop.
  • Context flooding: read a relevant tail, not 50,000 repeated log lines.
  • Excessive concurrency: prefer 2-4 purposeful jobs, not 14 vague experiments.
  • Stale validation: record what state ran and never apply an old result to newer changes.
  • Speculative overlap: do not run work whose inputs are still being rewritten.

04 同仓库更多 Skills