This file is the single-file agent harness for AutoTriage. It is intentionally short enough to stay useful in context while still giving agents the map, constraints, and feedback loops needed to make reliable changes.
The design follows OpenAI's harness engineering guidance: agent effectiveness comes from repository-local knowledge, legible systems, enforceable invariants, and tight validation loops rather than a large instruction manual. Keep this file as the table of contents and operating contract for now; promote repeated rules into scripts, tests, or CI when they become stable.
Source: https://openai.com/index/harness-engineering/
AutoTriage is a GitHub Action for AI-assisted issue and pull request triage. It uses repository context, issue or pull request history, and a configurable prompt to plan and apply authorized GitHub operations.
Preserve these invariants:
- Runtime compatibility: Node.js 24 or newer.
- Action entry point:
dist/index.js. - Source of truth: TypeScript under
src/. - Generated bundle:
dist/is committed, but never edited manually. - Default runtime prompt: with no
.github/AutoTriage.promptconfigured, the built-in label-only prompt (src/prompts.ts) is used. Theexamples/AutoTriage.promptfile is a copy-paste starting point, not bundled. - Unit tests must not require real GitHub or model API credentials, or any network beyond localhost.
- Public action behavior must stay aligned across
action.yml,README.md, tests, and generateddist/. - A run fails the job only for a configuration error or a bug in AutoTriage. Model failures, deferred items and GitHub's own failures, such as outages and rate limits, only warn through annotations and the job summary.
Start with the smallest useful context:
src/index.ts- action entry point.src/config.tsandsrc/env.ts- action inputs and environment handling.src/runner.tsandsrc/issueProcessor.ts- orchestration and per-item work.src/failures.ts- decides whether a failure fails the job or only warns.src/summary.ts- the job summary and the warning annotations.src/github.ts- GitHub API boundary.src/llm/- the model API boundary, with no SDK.endpoint.tspicks the endpoint and key for a model input.chat.tsis the one client every provider goes through, with its retries, per-call deadline, error classification, and undici fetch. It speaks Chat Completions to every host exceptapi.anthropic.com, which gets Claude's own Messages API so that effort can be set (xhigh), since Claude's Chat Completions layer ignoresreasoning_effort. danielchalmers/Nuntia copiessrc/llm/andtests/llm/verbatim, so change them here first and copy them over in a paired PR.src/analysis.tsandsrc/triage.ts- response schema and operation planning.src/prompts.ts- the built-in policy and prompt assembly. A bot's earlier comments reach the prompt without the hidden explanation block that the action ends its comments with, andsrc/triage.tsholds the one pattern for that block.src/storage.tsandsrc/stats.ts- persisted triage data and run metrics.src/util.ts- shared error-detail and timestamp helpers.errorMessageis imported straight fromsrc/llm/chat.ts.tests/- Vitest coverage and examples of expected behavior.action.yml- public GitHub Action metadata.examples/AutoTriage.prompt- example starting-point prompt to copy into a repo (not bundled)..github/AutoTriage.prompt- this repo's own policy: the example prompt plus the MOCK fixture rules that this repo's workflows and CI rely on.tests/examples.test.tsfails when the two drift apart, so carry every example edit over to it.examples/workflows/- example workflows. They and this repo's triage workflows queue in one job-levelqueue: maxgroup, only the backlog sweep saves the DB cache, andtests/examples.test.tschecks both sets..github/workflows/- CI expectations.ci.ymlrunsnpm run verifyon every pull request, whatever its base branch, and on every push to main, then dry-runs the action on the pull request. A newer push to a pull request cancels that pull request's older CI run.dist/- generated action bundle.
Read the relevant source and nearby tests before editing. Prefer repository-local evidence over assumptions from memory.
For any change:
- Inspect the current implementation, tests, and public contract.
- Make the smallest coherent change.
- Add or update focused tests when behavior changes.
- Run the narrowest useful verification first.
- Run required verification before finishing.
- Rebuild
dist/when source, bundled assets, dependencies, or action metadata affect runtime output. - Summarize what changed, what was verified, and any remaining risk.
If something fails, do not guess. Treat the failure as a missing capability, broken invariant, stale test, or real regression. Fix the specific cause.
Default verification:
npm run typecheck
npm run typecheck:test
npm testWhen runtime output may change, also run:
npm run build
git status --porcelain
git diff --exit-code --name-onlyDocs-only changes usually do not require npm run build. Changes to src/,
package.json, package-lock.json, action.yml, or bundling behavior require
build verification and updated dist/ output when the bundle changes.
npm run verify runs the default verification, then the build, then npm run check:dist, which fails when the build left dist/ different from what is committed.
CI runs the same script before its dry run of the action.
npm ci- install dependencies frompackage-lock.json.npm run typecheck- type-check runtime TypeScript.npm run typecheck:test- type-check tests.npm test- run Vitest once.npm run test:watch- run Vitest in watch mode.npm run dev- run TypeScript in watch mode.npm run build- type-check, cleandist/, and bundle withesbuildinto a single minifieddist/index.js(third-party license notices appended at the end; no source map or code-split chunks).npm run clean- removedist/.npm run check:dist- fail whendist/has uncommitted changes.npm run verify- typecheck, typecheck tests, run the tests, build, then checkdist/.
- Keep TypeScript strictness intact.
- Validate or narrow untrusted shapes at boundaries, especially GitHub event payloads, action inputs, API responses, stored JSON, and model output.
- Keep external service access isolated behind modules that tests can mock.
- Avoid broad refactors unless they directly reduce risk for the requested change.
When changing inputs, defaults, permissions, or runtime behavior:
- Update
action.yml. - Update
README.mdwhen user-facing behavior changes. - Add or update tests for parsing, defaults, and failure behavior.
- Run
npm run buildand inspect generateddist/changes.
When changing prompt loading or the built-in fallback:
- Test custom prompt path behavior.
- Test built-in label-only fallback behavior.
- Test missing or invalid prompt behavior when applicable.
Before adding a dependency, check whether the existing stack already solves the
problem. New dependencies must be compatible with Node.js 24 and GitHub Actions,
committed in package-lock.json, covered by relevant tests, and included in the
rebuilt bundle when used at runtime.
For triage behavior, cover:
- Normal issue or pull request processing.
- Missing, malformed, or partial inputs.
- Model or GitHub API failure paths.
- Dry-run behavior.
- Storage, artifact, or stats changes when touched.
For GitHub integration boundaries, prefer mocked clients and representative
payload fixtures over live network calls. Local development against real GitHub
and a model API requires GITHUB_TOKEN and one of GEMINI_API_KEY,
ANTHROPIC_API_KEY, or OPENAI_API_KEY (optionally with OPENAI_BASE_URL), but
unit tests must not depend on any of them. Model client tests use an injected
fetch or a localhost server.
tests/setup.ts clears every GITHUB_*, INPUT_* and RUNNER_* variable before each test file loads and again before each test, so a test sets what it needs with vi.stubEnv in beforeEach or in the test itself.
Only failing tests print their console output, so spy on console only to assert a log line.
@actions/core commands such as group and warning write straight to stdout, which that setting can't hide, so mock them in tests that reach them.
npm cifails: check Node/npm version and lockfile consistency.- Typecheck fails: fix types rather than weakening strictness.
- Tests fail: determine whether the failure is a regression, stale expectation, missing mock, or environment issue.
- Build fails: inspect the first compiler or bundler error before retrying.
dist/changes unexpectedly: inspect the generated diff before finishing.- Credentials are missing: do not invent them; report the blocked verification.
Before opening or updating a PR:
- Verification has passed, or blocked checks are named with reasons.
- Runtime-impacting changes have rebuilt
dist/. - Public behavior changes are reflected in docs and tests.
- Unrelated files are not modified.
- The PR body explains the why, the what, verification, and residual risk.
These are good follow-up investments because OpenAI's harness engineering post argues that durable agent leverage comes from legible repository systems, mechanical checks, and feedback loops rather than repeated manual guidance.
- Add representative GitHub issue, pull request, and comment fixtures for behavior tests.
- Add model-response fixtures for planning edge cases.
- Add a periodic documentation freshness check once the project has more repository-local design notes.