[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6CF6KBMFVEWB3MAE68EWZWG":3,"skill-same:01M6CF6KBMFVEWB3MAE68EWZWG":99},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":36,"linkOnly":37,"markdownContent":38,"markdownBody":39,"frontMatter":40,"refName":50,"commitSha":51,"skillDirectory":52,"forksCount":53,"repositoryHtmlUrl":54,"repositoryHomepageUrl":6,"ownerHtmlUrl":55,"ownerBlogUrl":6,"ownerDescription":56,"updatedAt":57,"install":58,"resources":71},"01M6CF6KBMFVEWB3MAE68EWZWG","ocaml",null,"Write native OCaml for cnos. Use when building the runtime\u002Fkernel, package tooling, command dispatch, contract\u002Frendering logic, transport support, or other low-level infrastructure in OCaml.","usurobor\u002Fcnos","usurobor","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F182342826?v=4","01M6CEXJCRMYD8HB2315FGB1Q8","Peter Lisovin","01M6CEXJH2RW04GQ2SNXY40F5S",9,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fusurobor\u002Fcnos\u002Fblob\u002Fmain\u002Fsrc\u002Fpackages\u002Fcnos.eng\u002Fskills\u002Feng\u002Focaml\u002FSKILL.md",[],[5,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35],"command","fallback","tooling","embedded","dispatch","use","orchestrator","write","kernel","model","how","discovery","package","code","debugging","infrastructure","support","2026-11-10 10:12:30",false,"---\nname: ocaml\ndescription: Write native OCaml for cnos. Use when building the runtime\u002Fkernel, package tooling, command dispatch, contract\u002Frendering logic, transport support, or other low-level infrastructure in OCaml.\nartifact_class: skill\nkata_surface: embedded\ngoverning_question: How do we write OCaml that keeps cnos explicit, pure where possible, and hostile to silent fallback?\ntriggers:\n  - implementing cnos runtime\u002Fkernel code in OCaml\n  - extracting pure model logic out of command handlers\n  - building package\u002Fcommand\u002Forchestrator infrastructure in OCaml\n  - reviewing OCaml code for purity leaks or silent fallback\n  - debugging type ambiguity, fallback drift, or resource discovery bugs\nscope: task-local\n---\n\n# OCaml\n\n## Core Principle\n\n**Write OCaml so the compiler carries the burden early and the runtime makes degraded behavior visible.**\n\nUse types to remove ambiguity at definition time, modules to enforce purity boundaries, Result for expected failure, and explicit fallback policy for every degraded path. Prefer a small number of clear representations over cleverness that moves ambiguity downstream.\n\n## Algorithm\n\n1. **Define** — name the domain model, the purity boundary, the fallback policy, and the build\u002Ftest contract.\n2. **Unfold** — design types, modules, result\u002Ferror flow, resource discovery, determinism, and tests together.\n3. **Rules** — keep the code type-first, purity-aware, explicit about fallback, and hostile to fabricated empty state.\n4. **Verify** — build, run expect tests, and audit the same failure class across sibling surfaces.\n\n---\n\n## 1. Define\n\n### 1.0. Classify the artifact first\n\nUse this skill for OCaml code that belongs in the cnos runtime\u002Fkernel layer:\n\n- package management\n- command dispatch\n- runtime contract emission\n- activation\u002Fregistry logic\n- transport\u002Fprotocol support\n- orchestrator\u002Fworkflow runtime\n- file\u002Fgit\u002Fprocess\u002Fhttp adapters\n- contract\u002Frendering logic\n\nDo **not** use this skill for:\n\n- prose-only documentation\n- package-authored Markdown skills\n- shell one-offs that should stay shell one-offs\n- workflow judgment better expressed as package skills\n\n### 1.1. Identify the parts\n\nA coherent OCaml subsystem has:\n\n- **Types** — the primary safety mechanism\n- **Modules** — the primary purity and ownership boundary\n- **Results** — the normal channel for expected failure\n- **Fallback policy** — the explicit rule for degraded behavior\n- **Resource discovery** — path\u002Fbinary\u002Fconfig\u002Fpackage lookup with visible outcomes\n- **Determinism** — stable ordering, stable rendering, stable hashing inputs\n- **Observability** — logs\u002Freceipts\u002Fstructured state for degraded paths\n- **Tests** — expect tests and focused pure-logic checks\n- **Build** — dune build, dune runtest, native binary discipline\n\n- ❌ Start with helpers and exceptions, then discover the model later\n- ✅ Name the types and module boundaries first, then implement behavior\n\n### 1.2. Articulate how they fit\n\nTypes define the domain. Modules isolate purity and ownership. Result carries expected failure. Fallbacks are policy decisions, not convenience. Resource discovery validates reality before work depends on it. Deterministic rendering and stable ordering keep reports\u002Fcontracts comparable. Tests lock behavior to visible output.\n\n- ❌ Put I\u002FO in a pure parsing module\n- ✅ Parse returns `Result`; caller performs I\u002FO\n\n### 1.3. Name the failure mode\n\nOCaml code fails through:\n\n- **type ambiguity** — overlapping record fields create annotation debt everywhere\n- **purity leaks** — Unix\u002FSys\u002FIO code drifts into model\u002Fparse modules\n- **silent fallback** — missing, malformed, or unreadable becomes `[]`, `None`, or `\"\"`\n- **exception abuse** — expected failures become implicit jumps\n- **resource discovery drift** — paths\u002Fbinaries are constructed but not validated\n- **nondeterministic output** — unstable ordering leaks into contracts, reports, hashes\n- **invisible degraded paths** — fallback happened but no log\u002Freceipt\u002Fstate makes it inspectable\n\n- ❌ `with _ -> []`\n- ✅ `Error \"resource not found: ...\"` or explicit logged fallback by policy\n\n---\n\n## 2. Unfold\n\n### 2.1. Type design\n\nDisambiguate at definition, not at use. When two record types in the same module share a field name, every access site pays the annotation cost. Avoid that by naming the fields differently at the type definition.\n\n```ocaml\n(* ❌ recurring disambiguation burden *)\ntype extension_op = { kind : string; op_class : string }\ntype backend = { kind : string; command : string list }\n\n(* ✅ ambiguity removed at definition *)\ntype extension_op = { op_kind : string; op_class : string }\ntype backend = { backend_kind : string; command : string list }\n```\n\n- ❌ Rely on incremental type annotations every time the compiler complains\n- ✅ Fix the representation once so the whole module gets simpler\n\nPrefer:\n\n- concrete algebraic data types\n- records with semantically specific field names\n- variants for explicit state\n- small helper constructors only when invariants need them\n\n### 2.2. Module structure\n\nUse modules to enforce purity and ownership. Prefer a split like:\n\n- `lib\u002F` — pure types, parsing, validation, rendering\n- `protocol\u002F` — pure FSMs \u002F protocol state\n- `ffi\u002F` — system bindings \u002F side-effectful primitives\n- `cmd\u002F` — business logic wiring pure and impure pieces\n- `transport\u002F` — adapters for git\u002Fmail\u002Fnetwork\n- `cli\u002F` — thin entrypoint\u002Fdispatch only\n\n- ❌ One module owns parsing, I\u002FO, rendering, and policy\n- ✅ Pure modules decide; impure modules execute\n\n### 2.3. Results, exceptions, and fallback\n\nUse `Result` for expected failure. Expected failures include:\n\n- malformed manifests\n- missing config\n- checksum mismatch\n- unsupported target\n- absent resource by policy\n\nReserve exceptions for:\n\n- impossible internal invariants\n- programmer errors\n- truly exceptional system conditions\n\n```ocaml\nlet parse s : (value, string) result = ...\n```\n\n- ❌ `raise Parse_error`\n- ✅ `Error \"expected package version\"`\n\nEvery fallback must be:\n\n- intentional\n- visible\n- justified\n\n### 2.4. Resource discovery\n\nAny function that resolves binaries, files, package contents, transport roots, or thread stores must validate existence or return a visible failure.\n\n- ❌ `let resolve name = Filename.concat dir name`\n- ✅ `if Sys.file_exists p then Ok p else Error (Printf.sprintf \"not found: %s\" p)`\n\nDo not defer discovery of missing resources to a later opaque exec\u002FIO failure.\n\n### 2.5. Compatibility and fallback discipline\n\nEvery compatibility path must be explicitly classified:\n\n- **remove** — delete it\n- **convert** — log + fallback\n- **keep** — justify it, make it fail-closed or operator-visible, and give it an expiry\u002Ffollow-up where appropriate\n\n- ❌ \"Keep for safety\"\n- ✅ \"Keep until all peers use packet refs; reject loudly on ambiguity\"\n\nIf \"empty\u002Fskip\" is the safe semantic outcome, fallback may be tolerated, but it must still be:\n\n- logged or surfaced\n- bounded\n- auditable\n\n### 2.6. Determinism and reproducibility\n\nFor anything that is:\n\n- hashed\n- diffed in tests\n- emitted in reports\n- stored in runtime contracts\n- compared across runs\n\nensure:\n\n- sorted ordering\n- canonical rendering\n- stable traversal\n- no hidden timestamps unless deliberate\n\n- ❌ Use `Sys.readdir` order directly in a contract\u002Freport\n- ✅ `Sys.readdir dir |> Array.to_list |> List.sort String.compare`\n\n### 2.7. Idempotence, retry, and receipts\n\nAssume package restore, update, sync, and workflow steps may be retried. For state-changing operations, define:\n\n- interruption behavior\n- cleanup behavior\n- whether the operation is idempotent\n- what receipt\u002Flog\u002Fstate proves what happened\n\nPatterns to prefer:\n\n- temp + validate + atomic move\n- lock or exclusive create where needed\n- receipt\u002Flog\u002Fstate update on degraded path\n\n- ❌ Write directly into final state and hope the process completes\n- ✅ Write to temp, verify, then atomically install\n\n### 2.8. Side-effect boundaries\n\nKeep parsing\u002Fvalidation\u002Fplanning separate from:\n\n- filesystem\n- git\n- HTTP\n- subprocesses\n- archive extraction\n- env access\n\n- ❌ Parse a package manifest inside the fetcher or subprocess wrapper\n- ✅ Fetch bytes \u002F run process in the adapter; parse\u002Fvalidate in the domain module\n\n### 2.9. Patterns\n\nPrefer:\n\n```ocaml\n(* Pipeline style *)\ninput |> parse |> validate |> output\n\n(* Result-based parsing *)\nlet parse s : (value, string) result = ...\n\n(* Pattern matching over partial stdlib access *)\nmatch xs with\n| x :: _ -> x\n| [] -> default\n\n(* filter_map — filter + map in one pass *)\nList.filter_map extract items\n\n(* Localized mutable state hidden behind a pure API *)\ntype state = { src : string; mutable pos : int }\n\n(* RAII cleanup *)\nFun.protect ~finally:(fun () -> close_in_noerr ic) (fun () -> ...)\n\n(* argv-based subprocess, not shell concatenation *)\nlet code, output = exec_args ~prog:\"curl\"\n  ~args:[\"--config\"; \"-\"] ~stdin_data:config ()\n```\n\nAvoid:\n\n- partial functions (`List.hd`, `Option.get`)\n- `with _ ->`\n- exceptions for expected domain failure\n- mutable state escaping module-local scope\n- shell interpolation for subprocesses\n\n### 2.10. Testing\n\nUse:\n\n- `ppx_expect` \u002F inline expect tests for behavior contracts\n- pure logic tests close to the module\n- degraded-path tests for fallback\u002Fcompatibility\u002Fresource discovery\n\nTest both:\n\n- positive path\n- missing\u002Fmalformed\u002Fdegraded path\n\n- ❌ Only test the happy path\n- ✅ Test success and the explicit failure\u002Ffallback behavior\n\n### 2.11. Build and shipping\n\nKeep the build boring:\n\n- `dune build`\n- `dune runtest`\n- native binary path\n- minimal toolchain assumptions\n\nRun before push:\n\n```\ndune build\ndune runtest\n```\n\nIf the toolchain is unavailable in the current environment, do a class-wide audit of the touched failure pattern instead of relying on CI to discover all sibling cases.\n\n---\n\n## 3. Rules\n\n3.1. **Type safety rule**\nDisambiguate record fields at the type definition. If overlapping names are unavoidable, annotate all access sites in one pass.\n\n3.2. **Purity boundary rule**\n`lib\u002F` and `protocol\u002F` stay pure. I\u002FO, Unix, Sys, subprocesses, HTTP, and filesystem access stay in `ffi\u002F`, `transport\u002F`, or other adapters.\n\n3.3. **Error rule**\nUse `Result` for expected failures. Do not use exceptions for normal domain errors. Never `with _ ->` without explicit classification and justification.\n\n3.4. **Fallback rule**\nEvery fallback is a policy decision. If a degraded path exists, it must be:\n- intentional\n- visible\n- justified\n- testable\n\n3.5. **Resource discovery rule**\nAny function that resolves external resources must validate existence or return explicit failure. Do not return speculative paths and let later I\u002FO fail opaquely.\n\n3.6. **Determinism rule**\nIf output is compared, hashed, or rendered for later use, sort and render canonically.\n\n3.7. **Idempotence and receipt rule**\nFor restore\u002Fupdate\u002Fsync\u002Fworkflow logic:\n- be safe to retry or fail explicitly if not\n- leave visible receipts\u002Flogs\u002Fstate on degraded paths\n- make partial-state cleanup explicit\n\n3.8. **Preserve cnos boundaries**\nKeep these concepts distinct:\n- skills choose\n- commands dispatch\n- orchestrators execute\n- extensions provide capability\n\nDo not let one module smear these ideas together.\n\n3.9. **Shell and archive safety**\nUse argv-based subprocesses. Reject path traversal on extraction. Do not log secrets. Keep destructive operations explicit.\n\n3.10. **Smell list**\nTreat these as review smells:\n- `with _ -> []`\n- `with _ -> None`\n- `with _ -> \"\"`\n- swallowing `Sys_error`\n- fabricated empty state\n- compatibility aliases with no reason or expiry\n- returning unvalidated external paths\n- partial stdlib functions in core\u002Fruntime logic\n- resource lookup deferred to opaque later failure\n\n3.11. **Build-before-push rule**\nRun `dune build` and `dune runtest` before push. If not possible locally, audit the whole failure class, not just the edited line.\n\n---\n\n## 4. Verify\n\n4.1. **File-level check**\n- Is the type model explicit?\n- Is the purity boundary clear?\n- Is fallback policy named?\n\n4.2. **Boundary check**\n- Is I\u002FO at the edge?\n- Are parsing\u002Fvalidation\u002Frendering kept pure?\n\n4.3. **Error\u002Ffallback check**\n- Any swallowed errors?\n- Any fabricated empty state?\n- Any degraded path that is invisible?\n\n4.4. **Determinism\u002Freceipt check**\n- Are sorted\u002Fcanonical outputs enforced where needed?\n- Does retry\u002Fpartial failure leave visible evidence?\n\n4.5. **Build\u002Ftest check**\n- `dune build`\n- `dune runtest`\n- degraded-path tests present\n\n---\n\n## 5. Kata\n\n### 5.1. Kata A — package restore path\n\n**Scenario:** Implement or modify first-party package restore from an artifact index and tarball.\n\n**Task:** Write OCaml code that:\n- resolves name + version\n- downloads artifact + checksum\n- verifies SHA-256\n- extracts into vendor\n- validates `cn.package.json`\n- fails visibly on malformed\u002Fmissing cases\n\n**Governing skills:** ocaml, design, test\n\n**Inputs:**\n- valid package index fixture\n- malformed index fixture\n- missing package fixture\n- checksum mismatch fixture\n- tarball extraction path fixture\n\n**Expected artifacts:**\n- concrete package types\n- pure parse\u002Fvalidate modules\n- explicit fallback policy\n- no fabricated empty state\n- expect tests for success and degraded cases\n\n**Verification:**\n- no `with _ ->` swallowing parse\u002FIO failure\n- restore path is explicit and retry-safe\n- `dune build` and `dune runtest` pass\n\n**Common failures:**\n- parse logic inside fetch\u002Fprocess code\n- fallback to `[]` \u002F `None`\n- unchecked path construction\n- missing degraded-path tests\n\n**Reflection:**\n- Did the compiler reduce ambiguity early?\n- Did every fallback become visible and justified?\n\n### 5.2. Kata B — runtime contract extraction\n\n**Scenario:** Move runtime-contract model\u002Frendering out of a large command-side module into a purer library surface.\n\n**Task:** Extract:\n- record types\n- validation helpers\n- rendering helpers\n\ninto a reusable pure module, leaving only runtime wiring in the command layer.\n\n**Governing skills:** ocaml, design, write\n\n**Inputs:**\n- one mixed command-side contract builder\n- one expected JSON contract output\n- one expected markdown\u002Ftext output\n\n**Expected artifacts:**\n- pure contract types\u002Frendering\n- explicit wiring in the command layer\n- tests for JSON and text rendering\n- no I\u002FO inside the contract model\n\n**Verification:**\n- no system-truth logic stranded in the command module\n- no cyclic dependencies introduced\n- output remains stable under tests\n\n**Common failures:**\n- moving side effects into the pure module\n- leaving rendering behavior untested\n- preserving hidden fallback behavior\n\n**Reflection:**\n- Did the extraction reduce command-layer ownership of system truth?\n- Did the new module make degraded behavior easier to audit?\n","# OCaml\n\n## Core Principle\n\n**Write OCaml so the compiler carries the burden early and the runtime makes degraded behavior visible.**\n\nUse types to remove ambiguity at definition time, modules to enforce purity boundaries, Result for expected failure, and explicit fallback policy for every degraded path. Prefer a small number of clear representations over cleverness that moves ambiguity downstream.\n\n## Algorithm\n\n1. **Define** — name the domain model, the purity boundary, the fallback policy, and the build\u002Ftest contract.\n2. **Unfold** — design types, modules, result\u002Ferror flow, resource discovery, determinism, and tests together.\n3. **Rules** — keep the code type-first, purity-aware, explicit about fallback, and hostile to fabricated empty state.\n4. **Verify** — build, run expect tests, and audit the same failure class across sibling surfaces.\n\n---\n\n## 1. Define\n\n### 1.0. Classify the artifact first\n\nUse this skill for OCaml code that belongs in the cnos runtime\u002Fkernel layer:\n\n- package management\n- command dispatch\n- runtime contract emission\n- activation\u002Fregistry logic\n- transport\u002Fprotocol support\n- orchestrator\u002Fworkflow runtime\n- file\u002Fgit\u002Fprocess\u002Fhttp adapters\n- contract\u002Frendering logic\n\nDo **not** use this skill for:\n\n- prose-only documentation\n- package-authored Markdown skills\n- shell one-offs that should stay shell one-offs\n- workflow judgment better expressed as package skills\n\n### 1.1. Identify the parts\n\nA coherent OCaml subsystem has:\n\n- **Types** — the primary safety mechanism\n- **Modules** — the primary purity and ownership boundary\n- **Results** — the normal channel for expected failure\n- **Fallback policy** — the explicit rule for degraded behavior\n- **Resource discovery** — path\u002Fbinary\u002Fconfig\u002Fpackage lookup with visible outcomes\n- **Determinism** — stable ordering, stable rendering, stable hashing inputs\n- **Observability** — logs\u002Freceipts\u002Fstructured state for degraded paths\n- **Tests** — expect tests and focused pure-logic checks\n- **Build** — dune build, dune runtest, native binary discipline\n\n- ❌ Start with helpers and exceptions, then discover the model later\n- ✅ Name the types and module boundaries first, then implement behavior\n\n### 1.2. Articulate how they fit\n\nTypes define the domain. Modules isolate purity and ownership. Result carries expected failure. Fallbacks are policy decisions, not convenience. Resource discovery validates reality before work depends on it. Deterministic rendering and stable ordering keep reports\u002Fcontracts comparable. Tests lock behavior to visible output.\n\n- ❌ Put I\u002FO in a pure parsing module\n- ✅ Parse returns `Result`; caller performs I\u002FO\n\n### 1.3. Name the failure mode\n\nOCaml code fails through:\n\n- **type ambiguity** — overlapping record fields create annotation debt everywhere\n- **purity leaks** — Unix\u002FSys\u002FIO code drifts into model\u002Fparse modules\n- **silent fallback** — missing, malformed, or unreadable becomes `[]`, `None`, or `\"\"`\n- **exception abuse** — expected failures become implicit jumps\n- **resource discovery drift** — paths\u002Fbinaries are constructed but not validated\n- **nondeterministic output** — unstable ordering leaks into contracts, reports, hashes\n- **invisible degraded paths** — fallback happened but no log\u002Freceipt\u002Fstate makes it inspectable\n\n- ❌ `with _ -> []`\n- ✅ `Error \"resource not found: ...\"` or explicit logged fallback by policy\n\n---\n\n## 2. Unfold\n\n### 2.1. Type design\n\nDisambiguate at definition, not at use. When two record types in the same module share a field name, every access site pays the annotation cost. Avoid that by naming the fields differently at the type definition.\n\n```ocaml\n(* ❌ recurring disambiguation burden *)\ntype extension_op = { kind : string; op_class : string }\ntype backend = { kind : string; command : string list }\n\n(* ✅ ambiguity removed at definition *)\ntype extension_op = { op_kind : string; op_class : string }\ntype backend = { backend_kind : string; command : string list }\n```\n\n- ❌ Rely on incremental type annotations every time the compiler complains\n- ✅ Fix the representation once so the whole module gets simpler\n\nPrefer:\n\n- concrete algebraic data types\n- records with semantically specific field names\n- variants for explicit state\n- small helper constructors only when invariants need them\n\n### 2.2. Module structure\n\nUse modules to enforce purity and ownership. Prefer a split like:\n\n- `lib\u002F` — pure types, parsing, validation, rendering\n- `protocol\u002F` — pure FSMs \u002F protocol state\n- `ffi\u002F` — system bindings \u002F side-effectful primitives\n- `cmd\u002F` — business logic wiring pure and impure pieces\n- `transport\u002F` — adapters for git\u002Fmail\u002Fnetwork\n- `cli\u002F` — thin entrypoint\u002Fdispatch only\n\n- ❌ One module owns parsing, I\u002FO, rendering, and policy\n- ✅ Pure modules decide; impure modules execute\n\n### 2.3. Results, exceptions, and fallback\n\nUse `Result` for expected failure. Expected failures include:\n\n- malformed manifests\n- missing config\n- checksum mismatch\n- unsupported target\n- absent resource by policy\n\nReserve exceptions for:\n\n- impossible internal invariants\n- programmer errors\n- truly exceptional system conditions\n\n```ocaml\nlet parse s : (value, string) result = ...\n```\n\n- ❌ `raise Parse_error`\n- ✅ `Error \"expected package version\"`\n\nEvery fallback must be:\n\n- intentional\n- visible\n- justified\n\n### 2.4. Resource discovery\n\nAny function that resolves binaries, files, package contents, transport roots, or thread stores must validate existence or return a visible failure.\n\n- ❌ `let resolve name = Filename.concat dir name`\n- ✅ `if Sys.file_exists p then Ok p else Error (Printf.sprintf \"not found: %s\" p)`\n\nDo not defer discovery of missing resources to a later opaque exec\u002FIO failure.\n\n### 2.5. Compatibility and fallback discipline\n\nEvery compatibility path must be explicitly classified:\n\n- **remove** — delete it\n- **convert** — log + fallback\n- **keep** — justify it, make it fail-closed or operator-visible, and give it an expiry\u002Ffollow-up where appropriate\n\n- ❌ \"Keep for safety\"\n- ✅ \"Keep until all peers use packet refs; reject loudly on ambiguity\"\n\nIf \"empty\u002Fskip\" is the safe semantic outcome, fallback may be tolerated, but it must still be:\n\n- logged or surfaced\n- bounded\n- auditable\n\n### 2.6. Determinism and reproducibility\n\nFor anything that is:\n\n- hashed\n- diffed in tests\n- emitted in reports\n- stored in runtime contracts\n- compared across runs\n\nensure:\n\n- sorted ordering\n- canonical rendering\n- stable traversal\n- no hidden timestamps unless deliberate\n\n- ❌ Use `Sys.readdir` order directly in a contract\u002Freport\n- ✅ `Sys.readdir dir |> Array.to_list |> List.sort String.compare`\n\n### 2.7. Idempotence, retry, and receipts\n\nAssume package restore, update, sync, and workflow steps may be retried. For state-changing operations, define:\n\n- interruption behavior\n- cleanup behavior\n- whether the operation is idempotent\n- what receipt\u002Flog\u002Fstate proves what happened\n\nPatterns to prefer:\n\n- temp + validate + atomic move\n- lock or exclusive create where needed\n- receipt\u002Flog\u002Fstate update on degraded path\n\n- ❌ Write directly into final state and hope the process completes\n- ✅ Write to temp, verify, then atomically install\n\n### 2.8. Side-effect boundaries\n\nKeep parsing\u002Fvalidation\u002Fplanning separate from:\n\n- filesystem\n- git\n- HTTP\n- subprocesses\n- archive extraction\n- env access\n\n- ❌ Parse a package manifest inside the fetcher or subprocess wrapper\n- ✅ Fetch bytes \u002F run process in the adapter; parse\u002Fvalidate in the domain module\n\n### 2.9. Patterns\n\nPrefer:\n\n```ocaml\n(* Pipeline style *)\ninput |> parse |> validate |> output\n\n(* Result-based parsing *)\nlet parse s : (value, string) result = ...\n\n(* Pattern matching over partial stdlib access *)\nmatch xs with\n| x :: _ -> x\n| [] -> default\n\n(* filter_map — filter + map in one pass *)\nList.filter_map extract items\n\n(* Localized mutable state hidden behind a pure API *)\ntype state = { src : string; mutable pos : int }\n\n(* RAII cleanup *)\nFun.protect ~finally:(fun () -> close_in_noerr ic) (fun () -> ...)\n\n(* argv-based subprocess, not shell concatenation *)\nlet code, output = exec_args ~prog:\"curl\"\n  ~args:[\"--config\"; \"-\"] ~stdin_data:config ()\n```\n\nAvoid:\n\n- partial functions (`List.hd`, `Option.get`)\n- `with _ ->`\n- exceptions for expected domain failure\n- mutable state escaping module-local scope\n- shell interpolation for subprocesses\n\n### 2.10. Testing\n\nUse:\n\n- `ppx_expect` \u002F inline expect tests for behavior contracts\n- pure logic tests close to the module\n- degraded-path tests for fallback\u002Fcompatibility\u002Fresource discovery\n\nTest both:\n\n- positive path\n- missing\u002Fmalformed\u002Fdegraded path\n\n- ❌ Only test the happy path\n- ✅ Test success and the explicit failure\u002Ffallback behavior\n\n### 2.11. Build and shipping\n\nKeep the build boring:\n\n- `dune build`\n- `dune runtest`\n- native binary path\n- minimal toolchain assumptions\n\nRun before push:\n\n```\ndune build\ndune runtest\n```\n\nIf the toolchain is unavailable in the current environment, do a class-wide audit of the touched failure pattern instead of relying on CI to discover all sibling cases.\n\n---\n\n## 3. Rules\n\n3.1. **Type safety rule**\nDisambiguate record fields at the type definition. If overlapping names are unavoidable, annotate all access sites in one pass.\n\n3.2. **Purity boundary rule**\n`lib\u002F` and `protocol\u002F` stay pure. I\u002FO, Unix, Sys, subprocesses, HTTP, and filesystem access stay in `ffi\u002F`, `transport\u002F`, or other adapters.\n\n3.3. **Error rule**\nUse `Result` for expected failures. Do not use exceptions for normal domain errors. Never `with _ ->` without explicit classification and justification.\n\n3.4. **Fallback rule**\nEvery fallback is a policy decision. If a degraded path exists, it must be:\n- intentional\n- visible\n- justified\n- testable\n\n3.5. **Resource discovery rule**\nAny function that resolves external resources must validate existence or return explicit failure. Do not return speculative paths and let later I\u002FO fail opaquely.\n\n3.6. **Determinism rule**\nIf output is compared, hashed, or rendered for later use, sort and render canonically.\n\n3.7. **Idempotence and receipt rule**\nFor restore\u002Fupdate\u002Fsync\u002Fworkflow logic:\n- be safe to retry or fail explicitly if not\n- leave visible receipts\u002Flogs\u002Fstate on degraded paths\n- make partial-state cleanup explicit\n\n3.8. **Preserve cnos boundaries**\nKeep these concepts distinct:\n- skills choose\n- commands dispatch\n- orchestrators execute\n- extensions provide capability\n\nDo not let one module smear these ideas together.\n\n3.9. **Shell and archive safety**\nUse argv-based subprocesses. Reject path traversal on extraction. Do not log secrets. Keep destructive operations explicit.\n\n3.10. **Smell list**\nTreat these as review smells:\n- `with _ -> []`\n- `with _ -> None`\n- `with _ -> \"\"`\n- swallowing `Sys_error`\n- fabricated empty state\n- compatibility aliases with no reason or expiry\n- returning unvalidated external paths\n- partial stdlib functions in core\u002Fruntime logic\n- resource lookup deferred to opaque later failure\n\n3.11. **Build-before-push rule**\nRun `dune build` and `dune runtest` before push. If not possible locally, audit the whole failure class, not just the edited line.\n\n---\n\n## 4. Verify\n\n4.1. **File-level check**\n- Is the type model explicit?\n- Is the purity boundary clear?\n- Is fallback policy named?\n\n4.2. **Boundary check**\n- Is I\u002FO at the edge?\n- Are parsing\u002Fvalidation\u002Frendering kept pure?\n\n4.3. **Error\u002Ffallback check**\n- Any swallowed errors?\n- Any fabricated empty state?\n- Any degraded path that is invisible?\n\n4.4. **Determinism\u002Freceipt check**\n- Are sorted\u002Fcanonical outputs enforced where needed?\n- Does retry\u002Fpartial failure leave visible evidence?\n\n4.5. **Build\u002Ftest check**\n- `dune build`\n- `dune runtest`\n- degraded-path tests present\n\n---\n\n## 5. Kata\n\n### 5.1. Kata A — package restore path\n\n**Scenario:** Implement or modify first-party package restore from an artifact index and tarball.\n\n**Task:** Write OCaml code that:\n- resolves name + version\n- downloads artifact + checksum\n- verifies SHA-256\n- extracts into vendor\n- validates `cn.package.json`\n- fails visibly on malformed\u002Fmissing cases\n\n**Governing skills:** ocaml, design, test\n\n**Inputs:**\n- valid package index fixture\n- malformed index fixture\n- missing package fixture\n- checksum mismatch fixture\n- tarball extraction path fixture\n\n**Expected artifacts:**\n- concrete package types\n- pure parse\u002Fvalidate modules\n- explicit fallback policy\n- no fabricated empty state\n- expect tests for success and degraded cases\n\n**Verification:**\n- no `with _ ->` swallowing parse\u002FIO failure\n- restore path is explicit and retry-safe\n- `dune build` and `dune runtest` pass\n\n**Common failures:**\n- parse logic inside fetch\u002Fprocess code\n- fallback to `[]` \u002F `None`\n- unchecked path construction\n- missing degraded-path tests\n\n**Reflection:**\n- Did the compiler reduce ambiguity early?\n- Did every fallback become visible and justified?\n\n### 5.2. Kata B — runtime contract extraction\n\n**Scenario:** Move runtime-contract model\u002Frendering out of a large command-side module into a purer library surface.\n\n**Task:** Extract:\n- record types\n- validation helpers\n- rendering helpers\n\ninto a reusable pure module, leaving only runtime wiring in the command layer.\n\n**Governing skills:** ocaml, design, write\n\n**Inputs:**\n- one mixed command-side contract builder\n- one expected JSON contract output\n- one expected markdown\u002Ftext output\n\n**Expected artifacts:**\n- pure contract types\u002Frendering\n- explicit wiring in the command layer\n- tests for JSON and text rendering\n- no I\u002FO inside the contract model\n\n**Verification:**\n- no system-truth logic stranded in the command module\n- no cyclic dependencies introduced\n- output remains stable under tests\n\n**Common failures:**\n- moving side effects into the pure module\n- leaving rendering behavior untested\n- preserving hidden fallback behavior\n\n**Reflection:**\n- Did the extraction reduce command-layer ownership of system truth?\n- Did the new module make degraded behavior easier to audit?\n",{"name":5,"scope":41,"triggers":42,"description":7,"kata_surface":22,"artifact_class":48,"governing_question":49},"task-local",[43,44,45,46,47],"implementing cnos runtime\u002Fkernel code in OCaml","extracting pure model logic out of command handlers","building package\u002Fcommand\u002Forchestrator infrastructure in OCaml","reviewing OCaml code for purity leaks or silent fallback","debugging type ambiguity, fallback drift, or resource discovery bugs","skill","How do we write OCaml that keeps cnos explicit, pure where possible, and hostile to silent fallback?","main","fb527e6c4bfb75c71fa75d6471b3aa3da32106d4","src\u002Fpackages\u002Fcnos.eng\u002Fskills\u002Feng\u002Focaml",0,"https:\u002F\u002Fgithub.com\u002Fusurobor\u002Fcnos","https:\u002F\u002Fgithub.com\u002Fusurobor","Coherence engineer. Building git-CN.","2026-11-07 14:25:44",{"source":8,"skillName":5,"commands":59,"prompt":69,"zipAvailable":70},[60,63,66],{"tool":61,"command":62},"npx","npx skills add usurobor\u002Fcnos --skill ocaml",{"tool":64,"command":65},"bunx","bunx skills add usurobor\u002Fcnos --skill ocaml",{"tool":67,"command":68},"pnpm","pnpm dlx skills add usurobor\u002Fcnos --skill ocaml","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fusurobor\u002Fcnos\u002Fblob\u002Fmain\u002Fsrc\u002Fpackages\u002Fcnos.eng\u002Fskills\u002Feng\u002Focaml\u002FSKILL.md",true,[72,78,83,87,91,95],{"path":73,"resourceType":74,"resourceTypeDesc":75,"sizeBytes":76,"sourceHtmlUrl":77},"CHANGELOG.md","REFERENCE","参考文档",41,"https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fexchanges\u002Fkucoin-official-earn\u002FCHANGELOG.md",{"path":79,"resourceType":79,"resourceTypeDesc":80,"sizeBytes":81,"sourceHtmlUrl":82},"LICENSE","许可证",1072,"https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fexchanges\u002Fkucoin-official-earn\u002FLICENSE",{"path":84,"resourceType":79,"resourceTypeDesc":80,"sizeBytes":85,"sourceHtmlUrl":86},"LICENSE.md",1063,"https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fexchanges\u002Fkucoin-official-earn\u002FLICENSE.md",{"path":88,"resourceType":74,"resourceTypeDesc":75,"sizeBytes":89,"sourceHtmlUrl":90},"references\u002Fauthentication.md",3443,"https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fexchanges\u002Fkucoin-official-earn\u002Freferences\u002Fauthentication.md",{"path":92,"resourceType":74,"resourceTypeDesc":75,"sizeBytes":93,"sourceHtmlUrl":94},"SOURCE.md",169,"https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fexchanges\u002Fkucoin-official-earn\u002FSOURCE.md",{"path":96,"resourceType":74,"resourceTypeDesc":75,"sizeBytes":97,"sourceHtmlUrl":98},"TRUST.auto.yaml",2232,"https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fexchanges\u002Fkucoin-official-earn\u002FTRUST.auto.yaml",[100,128,148,166,181,201],{"skillNo":101,"name":102,"nameZh":103,"description":104,"descriptionZh":105,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":106,"categories":107,"keywords":118,"publishedAt":36},"01M6CF8RWQPM0VXZG06XMR0FFX","issues\u002Ftriage","Issue 分诊与判定","Issue triage doctrine pointer. Use when classifying a new issue, deciding dispatch eligibility, or deciding whether to close\u002Fsupersede\u002Fdefer.","Issue 分诊规则指引。在对新 issue 进行分类、判定其是否符合派发条件，或决定将其关闭\u002F取代\u002F延后时使用。","https:\u002F\u002Fgithub.com\u002Fusurobor\u002Fcnos\u002Fblob\u002Fmain\u002Fsrc\u002Fpackages\u002Fcnos.issues\u002Fskills\u002Ftriage\u002FSKILL.md",[108,113],{"categoryNo":109,"categoryName":110,"taxonomyType":111,"taxonomyTypeDesc":112},"01M8BQ6TQZN6R52WBJ9H8NRMQM","软件开发工程师","PROFESSION","适用职业",{"categoryNo":114,"categoryName":115,"taxonomyType":116,"taxonomyTypeDesc":117},"01M8C2MZSDTE56BDKER3VPW2JM","工单与问题跟踪管理","SCENARIO","使用场景",[119,120,121,122,123,29,124,125,24,23,126,127],"triage","issues","issues triage","issue triage","SET","decision","public","issue","doctrine",{"skillNo":129,"name":130,"nameZh":131,"description":132,"descriptionZh":133,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":134,"categories":135,"keywords":138,"publishedAt":36},"01M6CF8PJ812DD4APZ3WE8X67B","issues\u002Ftaxonomy","Issue 标签分类体系","Issue label taxonomy pointer. Use when classifying an issue's kind\u002Farea\u002Fpriority\u002Feffort\u002Fstatus\u002Fprotocol\u002Fdispatch labels, or when the board needs to interpret them.","Issue 标签分类体系指引。在对 issue 的 kind\u002Farea\u002Fpriority\u002Feffort\u002Fstatus\u002Fprotocol\u002Fdispatch 标签进行分类，或看板需要解读这些标签时使用。","https:\u002F\u002Fgithub.com\u002Fusurobor\u002Fcnos\u002Fblob\u002Fmain\u002Fsrc\u002Fpackages\u002Fcnos.issues\u002Fskills\u002Ftaxonomy\u002FSKILL.md",[136,137],{"categoryNo":109,"categoryName":110,"taxonomyType":111,"taxonomyTypeDesc":112},{"categoryNo":114,"categoryName":115,"taxonomyType":116,"taxonomyTypeDesc":117},[120,139,140,141,142,143,123,144,125,145,24,23,146,126,147],"taxonomy","issues taxonomy","github","status","protocol","open","board","github issue","issue labels",{"skillNo":149,"name":150,"nameZh":6,"description":151,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":152,"categories":153,"keywords":154,"publishedAt":36},"01M6CF8KBMZ4D0CDJQ3PF1YVTP","issues\u002Fmap","Issue-board (Issue Pivot) generation domain. Use when reasoning about `cn issues map`'s fetch, taxonomy-parse, effort-computation, and render pipeline, or about the board's JSON\u002FHTML output contract.","https:\u002F\u002Fgithub.com\u002Fusurobor\u002Fcnos\u002Fblob\u002Fmain\u002Fsrc\u002Fpackages\u002Fcnos.issues\u002Fskills\u002Fmap\u002FSKILL.md",[],[120,155,141,156,157,158,123,159,139,144,29,160,161,145,162,163,164,165,24,126],"issues map","reasoning","data","pipeline","api","json","README","edit","interactive","fetch","generated",{"skillNo":167,"name":120,"nameZh":6,"description":168,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":169,"categories":170,"keywords":171,"publishedAt":36},"01M6CF8CZQH7G7B7RZPANQWR4G","cnos.issues package entrypoint. Use when reasoning about issue taxonomy, the Issue Pivot \u002F issue-board (`cn issues map`), the read-only CDS issue-state evaluator (`cn issues fsm evaluate`), or the current command-dispatch disposition of issue tooling.","https:\u002F\u002Fgithub.com\u002Fusurobor\u002Fcnos\u002Fblob\u002Fmain\u002Fsrc\u002Fpackages\u002Fcnos.issues\u002FSKILL.md",[],[120,141,172,173,174,175,176,31,177,139,144,29,124,178,161,19,24,179,23,180],"pr","current state","run","artifacts","state","boundary","branch","only","cds",{"skillNo":182,"name":183,"nameZh":6,"description":184,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":185,"categories":186,"keywords":187,"publishedAt":36},"01M6CF896XKSRQVB1CSHY8GSXB","receipt-stream","Cross-cycle receipt-stream doctrine for protocol-iteration. Use when γ closes a cycle and writes the per-cycle iteration artifact (`cdd-iteration.md`), when γ updates the cross-cycle aggregator at `.cdd\u002Fiterations\u002FINDEX.md`, when ε reads the receipt stream across cycles to surface protocol-gap patterns, when a finding's disposition lands a cross-repo patch and the cross-repo trace bundle attaches, or when a courtesy empty-findings stub is written for a `protocol_gap_count == 0` cycle.","https:\u002F\u002Fgithub.com\u002Fusurobor\u002Fcnos\u002Fblob\u002Fmain\u002Fsrc\u002Fpackages\u002Fcnos.handoff\u002Fskills\u002Fhandoff\u002Freceipt-stream\u002FSKILL.md",[],[188,189,175,143,190,29,191,192,193,125,194,195,196,197,24,22,198,199,200,127],"receipt stream","handoff","index","learning","format","trace","repo","closeout","read","channel","patch","shape","cdd",{"skillNo":202,"name":203,"nameZh":6,"description":204,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":205,"categories":206,"keywords":207,"publishedAt":36},"01M6CF84VCBME6RK8V6HAVDM8Z","mid-flight","Mid-flight γ→in-flight-α rescue channel. Use when γ needs to change a load-bearing fact (pinned axis, scope, AC, blocker) after α has begun coding, when γ edits the cycle's GitHub issue body mid-cycle, or when a spec change lands on origin\u002Fmain while α\u002Fβ polling sessions are in-flight.","https:\u002F\u002Fgithub.com\u002Fusurobor\u002Fcnos\u002Fblob\u002Fmain\u002Fsrc\u002Fpackages\u002Fcnos.handoff\u002Fskills\u002Fhandoff\u002Fmid-flight\u002FSKILL.md",[],[208,141,209,210,211,212,29,213,214,178,194,196,24,179,23,215,146,216,217,218],"mid flight","change","sessions","file","cache","pin","coordination","up","Legacy","gamma","artifact channel"]