AGENT SKILL
harn-language
Use for Harn language syntax, typechecking, modules, imports, and idiomatic script authoring.
- License 许可
- Apache-2.0
- 所属仓库
- burin-labs/harn
- 最近更新
- 2026-11-15
- Stars
- ★ 31
- Forks
- 6
01 前言 Front Matter
- name
- harn-language
- short
- Harn syntax, modules, types, diagnostics, and script structure.
- description
- Use for Harn language syntax, typechecking, modules, imports, and idiomatic script authoring.
- when_to_use
- Use when writing, reviewing, or explaining Harn source code and language-level behavior.
03 SKILL.md 正文
Harn language
Use this skill when writing, reviewing, or explaining .harn source code.
Pair it with [[harn-testing]] for fixtures and [[harn-diagnostics]] for user-facing errors.
Start here
- Read
docs/llm/harn-quickref.mdbefore editing.harnfiles. - In a Harn worktree, run
make setuponce and useHARN_BIN_NO_BUILD=1 ./scripts/harn_bin.sh -- <command>for narrow CLI checks. This resolves the lane-local binary without starting a hidden Cargo build. Outside the repository, use the installed, pinnedharnexecutable. - Use
docs/llm/harn-triggers-quickref.mdwhen trigger manifests are involved. - Read
spec/HARN_SPEC.mdas the assembled language reference. - Default new script entrypoints to
fn main(harness: Harness) { ... }and route side effects throughharness.*. - Use
harness.fs.mkdtemp_in_workspace(prefix?)for scratch files that must be visible under sandbox policy; avoid composing.harn/tmppaths by hand. - Use typed
std/fsconditional replacement for shared state or artifacts that must not overwrite a newer observation; branch on the closed receipt. - Use bounded
std/jsonlpages for file-backed logs and transcripts. Apply aSchemaContract<T>when consumers need typed records and named rules. - For connector credentials, read canonical ids such as
provider/access-tokenthroughharness.secretsfrom a package script; the runner scopes the default provider from the nearestharn.toml. - Edit the authoritative chapters under
spec/chapters/*.mdfor spec changes; never hand-edit the generatedspec/HARN_SPEC.mdordocs/src/language-spec.mdprojections. - Regenerate and verify every spec projection with
make sync-language-spec. - Check user-visible behavior with conformance fixtures under
conformance/tests/. - Keep examples small enough for agents to copy without hidden setup.
- Prefer existing syntax and stdlib helpers over new host-side shortcuts.
- Put platform spellings, policy rows, and other closed configuration in one typed data-only module. Import that value into the evaluator and mechanically project it downstream instead of duplicating lists or host branches.
Syntax checklist
- Imports go first.
pipelineis the usual entry-point construct.fnis for reusable pure or host-backed logic.constbinds a value that never changes;letbinds one that may.- Builtin methods have one name each (
len,contains,lower,upper,windows,chunks,map_keys,merge). Mutating methods (push,pop,insert,extend,sort,reverse, setadd/remove, dictremove) change aletbinding in place;sorted(),reversed(), andxs + [v]return new values. - Use explicit type annotations at boundaries.
- Use
matchfor variant-sensitive behavior. - Use
forfor straightforward iteration. - Use
parallel eachfor bounded fan-out work. - Use
parallel settlewhen collecting settled outcomes matters. - Use
settle_with_abortfromstd/abortwhen outcomes matter and branches poll or wait, so one branch's doomed verdict can stop the rest. - Always set
max_concurrenton broad parallel work. - Use triple-quoted strings for long prompts in Harn source.
- Heredoc syntax is for LLM tool-call argument JSON, not general strings.
- Keep comments factual and close to non-obvious logic.
Decode at the boundary
Untyped data (JSON text, a GraphQL response, a dict from another API) gets
decoded once where it enters. After that, read typed fields with ..
type WorkflowRun = {headBranch: string, conclusion: string?, url: string}
type WorkflowRuns = list<WorkflowRun>
const runs = json_decode(child.stdout, schema_of(WorkflowRuns))? // text
const pr = schema_parse(payload, schema_of(Snapshot))? // a value
json_decodeandschema_parsereturnResult<T, {message, errors, issues}>.matchor postfix?keepsT;unwrapreturns a dynamic value. Useschema_expectto throw instead.- Unknown fields pass.
name: T?may benull;name?: Tmay be absent. - Declare a GraphQL response type next to its query and decode
payload.datawith it. command_run,harness.process.exec/shell, and bufferedharness.netrequests already return typed, never-nil records: writeresult.stdout, notresult?.stdout ?? "". Keep the type when you wrap them; a wrapper that returnsdicterases it.- A
?.chain over an untyped value (HARN-LNT-080) orto_string(x ?? "")on a field means a decode is missing.
Types and boundaries
- Treat
unknownas the type for untrusted inputs. - Use
SchemaContract<T>for deterministic cross-field rules after structural validation. Capture typed context in the rule closure; do not replace it with an open dictionary. - Use
ArtifactDescriptor<T>when a producer and consumer share a durable JSON artifact. Bind its relative name andSchemaContract<T>once, then reuse the descriptor for reads and writes. - Narrow
unknownwithtype_of,schema_is, or validated helpers. - Use
anyonly as an explicit escape hatch. - Do not erase types merely to silence the typechecker.
- Keep struct and enum names stable when they are user-facing.
- Add conformance coverage before changing type inference behavior.
- Preserve diagnostic codes and spans when refactoring typechecker logic.
- Keep imported callable declarations aligned with module graph behavior.
- Watch for strict-types behavior when changing boundary APIs.
- Update examples when public type syntax changes.
Typed decisions
- Use
harness.llm.evaluate(site_id, state, questions, policy)for bounded boolean, choice, or score questions over one shared, closed serializable state. Import the builders fromstd/predicate; declare question ids and choice labels as literals so the checker can type every answer and record the site in the predicate manifest. - Use
evaluate_predicateonly for its single-boolean projection. Neither entry point returns a bare boolean: match the closed outcome and handle uncertainty, refusal, and budget limits explicitly. Anansweredbatch contains every declared question, or the evaluator refuses it. - Name a catalog route that declares the
decisionoperation in a constant policy. Keep deterministic authorization rules outside the model decision, and do not treat a reported confidence as measured accuracy. - See
docs/src/predicates.mdfor the builders, outcome arms, and admission contract. Pair with [[harn-testing]] for hermetic fixtures and quality reads.
Portable execution
- Treat portable execution as a deployment contract, not a second Harn language. Source must use the canonical parser, typechecker, and compiler.
- Passing
harn checkis necessary but does not prove Portable Kernel v1 support. Compile the intended entry through the portable interface so unsupported opcodes, builtins, and capability methods fail explicitly. - Keep entry inputs and terminal values JSON-shaped: null, booleans, signed integers, finite or tagged floats, strings, bytes, lists, and named records.
- Preserve explicit type annotations at the entry and reusable function
boundaries. The portable kernel enforces declared call contracts rather than
treating browser JSON as
any. - Route privileged operations through typed
harnesscapabilities. Do not add target-specific browser builtins or read ambient file, network, process, clock, random, or model authority. - Keep DOM, canvas, and presentation state in the browser host. Run CPU-heavy portable behavior in a Web Worker and exchange typed values.
- Do not add a parser, evaluator, opcode table, builtin registry, or keyword list to an adapter. Generate projections or test parity against the owning language/runtime registry.
- Use
harn bench portablefor compiler, artifact decode, and dispatch measurements. Usestd/timingonly for hostful application spans.
Modules and imports
- Keep import paths explicit and readable.
- Prefer
import * as alias from "module"when a module publishes short member names under a collision-safe alias; do not invent receiver-method APIs for that case. - When callers use a namespace alias, export
eventrather than repeating the module name inui_event; the call site already readsui.event. pub import * as alias from "module"re-exports the alias namespace object, not the target's flattened members (contrastpub import "module").- Avoid relying on the current working directory in examples.
- When touching module resolution, inspect
crates/harn-modules. - Cross-file checks should use the same module graph as the CLI.
- Public symbols should remain discoverable by editor tooling.
- Use curated
pub importfacades for stable package surfaces; package checks and API docs follow re-exports to the original declaration. - Avoid duplicate import spellings for the same file.
- Prefer canonical relative paths in fixtures.
- Add a cycle regression when changing import traversal.
- Keep generated docs and tree-sitter grammar in sync after syntax changes.
- Use [[harn-orchestration]] when module behavior affects workflows.
Prompt templates
- The template engine lives in
crates/harn-vm/src/stdlib/template.rs. - Do not add a second prompt-template parser.
- Keep host-call and script-call rendering behavior identical.
- Preserve pre-v2
{{name}}missing-identifier passthrough. - New template constructs should fail with useful parse diagnostics.
- Update
docs/src/prompt-templating.mdfor template syntax changes. - Update
docs/llm/harn-quickref.mdwhen agents need the new syntax. - Update VS Code grammar when
.harn.promptsyntax changes. - Add conformance fixtures under
conformance/tests/template_*. - Use [[harn-diagnostics]] for template parse and lint diagnostics.
Simpler first
- Can this be ordinary Harn instead of Rust?
- Can a stdlib helper express this without a new language form?
- Can the typechecker infer it without a new annotation?
- Can a conformance fixture capture the behavior without a large harness?
- Can docs describe the rule in one sentence?
- Can the formatter preserve the style without special cases?
- Can the linter derive the rule from existing AST structure?
- Can the tree-sitter grammar remain a direct mirror of parser syntax?
- Can existing examples be updated mechanically?
- Can user-visible behavior stay backward compatible?
Verify
- Narrow script check:
HARN_BIN_NO_BUILD=1 ./scripts/harn_bin.sh -- check <path>. - Narrow lint check:
HARN_BIN_NO_BUILD=1 ./scripts/harn_bin.sh -- lint <path>. - Narrow format check:
HARN_BIN_NO_BUILD=1 ./scripts/harn_bin.sh -- fmt --check <path>(fmt, neverformat). - Narrow conformance case:
HARN_BIN_NO_BUILD=1 ./scripts/harn_bin.sh -- test conformance --filter <name>. - Parser changes:
make test ARGS='-p harn-parser <filter>'. - Formatter changes:
make test ARGS='-p harn-fmt <filter>'. - Linter changes:
make test ARGS='-p harn-lint <filter>'. - Syntax or keyword changes:
make conformance. - Harn fixture changes:
make lint-harnandmake fmt-harn. - Tree-sitter changes:
(cd tree-sitter-harn && npm test).
04 同仓库更多 Skills
stream-fan-in
Stream trigger example for routing or grouping event batches.
★ 31
github-stale-pr-nudger
Cron recipe for scanning repositories and nudging old pull requests.
★ 31
webhook-generic-hmac
Generic webhook recipe with signed inbound requests.
★ 31
slack-thread-summarizer
Slack webhook recipe with a local summarize predicate.
★ 31
slack-reaction-action
Slack Events API recipe for reaction_added workflows.
★ 31
slack-keyword-router
Slack webhook recipe for routing messages by keyword.
★ 31