Skip to main content

SDK Reference (Public SDK v1 — Stable)#

The programmatic SDK is the single supported import for embedding ACKit in Node.js (CLI, MCP, Action, dashboard, VS Code all converge on it).

Import path: @cynrath/agent-context-kit (ESM only).
Entry: src/index.ts is the ONLY public surface; src/core/** is internal and not exported via package.json exports.

Supported imports#

SymbolKindDescription
scanRepository(root, opts?)functionScans a repository, returns ScanResult (deterministic findings, diagnostics, filesScanned). Accepts opts.signal?: AbortSignal.
loadAckitConfig(rootPath, opts?)functionLoads and validates ackit.yml, merges configuration defaults and returns {ok, config} or {ok:false, errors}. rootPath is a directory string.
buildContextPack(root, opts?)functionBuilds a budgeted deterministic context pack (PackResult). opts.signal supported.
buildInstructionGraph(root, opts?)functionBuilds the instruction graph (InstructionGraph). opts.signal supported.
resolveEffectiveStack(graph, provider, forPath?)functionPure function resolving the effective instruction stack for a provider/path.
analyzeOptimize(root, opts?)functionOptimization findings + suggestions (pack/context waste analysis).
validateSkills(root)functionValidates .agents/skills/*/SKILL.md set, returns {skills, issues}.
evaluateRulePacks(effectivePacks, context)functionEvaluates loaded declarative rules against repository files/configuration (exported since v0.2.0).
loadRulePacks(root, rulePackPaths)functionLoads the explicit repository-relative rule-pack paths.
scoreRepository(inputs, opts?)functionScores collected graph/pack/scan/skills/policy/task inputs (exported since v0.2.0).
inspectRepository(root, opts?)async functionReturns the configured scan, active/suppressed/audit groups and the same Readiness projection as CLI. An unavailable assessment is null.
detectProfiles, loadBuiltInProfiles, resolveProfilefunctionsStack/profile detection and resolution.
ProfileSchemaconstantStack-profile zod schema.
READINESS_ENGINE_VERSIONconstantReadiness engine version marker.
AckitErrorclassTyped error extends Error { code: string; remediation?: string; cause?: unknown }. Never a raw string.
AckitErrorCodetypeUnion of stable codes (CONFIG-*, SCAN-*, FS-*, POLICY-*, GRAPH-*, PACK-*, UNKNOWN).
AckitConfigtypeMerged config (scan + context + policy + readiness (v0.2.0) + profile).
InstructionGraph, InstructionNode, ProviderId, BuildGraphOptionstypesInstruction model; BuildGraphOptions includes signal?, codexGlobalDir?, maxTokenEstimatePerFile?.
Finding, ScanResult, ScanDiagnostic, ScanRule, Severity, ScanCategorytypesScanner model (SARIF-compatible).
PackResult, PackManifestEntrytypesPack model (ackit.pack.v0).
SkillRecord, SkillIssuetypesSkills model.

Workflow expansion additions (feat/workflow-expansion):

SymbolKindDescription
TaskStore, TaskDoc, TaskMetaclass/typesDocs-first task store (create/list/find/start/complete/archive/doctor); additive reference fields (intentRef, specRefs, decisionRefs, planRef).
IntentStore, intentFingerprint, normalizeIntentclass/functionsIntent artifacts (docs/intent/, ackit.intent.v1); machine-path-independent fingerprints.
CheckpointStore, renderResumeContext, renderHandoffPackclass/functionsCheckpoints (ackit.checkpoint.v1) + deterministic resume/handoff renderers.
EvidenceStore, validateEvidenceclass/functionEvidence registry (ackit.evidence.v2) + completeness validation.
VerdictStore, buildVerificationBundleclass/functionAppend-only verdicts (stored ackit.verdict.v2, state-bound; legacy v1 readable) + deterministic state-bound verification bundles (ackit.verification-bundle.v2).
computeStateBinding, compareStoredBinding, isBoundVerdict, StateBindingErrorfunctions/classState-binding contract (ADR-0030): compute current binding, compare stored-vs-current freshness, narrow bound records.
detectWorkflowDriftfunctionDeterministic drift findings (eight frozen codes).
resolveAutonomy, resolveReviewfunctionsPolicy v2 risk-tiered autonomy + review resolution (deny wins).
listRoles, loadRolefunctionsPortable role contracts (ackit.role.v1).
WorkflowStore, BUILTIN_PROFILES, listWorkflowProfiles, requiredArtifactsclass/constantsWorkflow engine (ackit.workflow.v1); profiles are frozen catalogs.

v0.5 read-model additions (TASK-0080…0083, parity surfaces):

SymbolKindDescription
assessVerdictIndependence, verdictContentDigest, projectVerdictAuthoringfunctionsStructural independence assessment + replay content digest (no identity crypto).
buildHandoff, parseHandoffFile, validateHandoff, HandoffError, HANDOFF_SCHEMA_ID_V2functions/class/constantPortable verification-bound handoff (ackit.handoff.v2); import validates read-only.
buildStatusReport, renderStatusReport, STATUS_SCHEMA_IDfunctions/constantCanonical read-only status projection (ackit.status.v1, same snapshot as CLI/MCP).

Additions require ADR + contract test update; the allowlist test fails on accidental export.

Package contract#

  • package.json type: "module", sideEffects: false, engines.node >=22, exports: { ".": {...}, "./mcp": {...} } only.
  • Importing @cynrath/agent-context-kit has no side effects (no timers, servers, FS touches). sideEffects:false enables tree-shaking.
  • No process.exit is ever called from SDK code; CLI maps ScanResult/AckitError to EXIT_CODES and owns process.exit.
  • CJS consumers: use dynamic await import("@cynrath/agent-context-kit") (ESM-only, no CJS shim shipped).

Error model#

For scanning, packs, graphs, skills and rule-pack loading, root is a descriptor { canonicalPath: string }, not a path string. Resolve it with Node’s realpath:

scanRepository runs built-in rules plus opts.extraRules through the shared pipeline. It does not load ackit.yml or apply its external policy chain; configured CLI/MCP scans add that orchestration. Supply explicit limits and exclusions when embedding the lower-level SDK scanner.

Stable codes: CONFIG-UNKNOWN-KEY (did-you-mean hint in remediation), CONFIG-YAML-SYNTAX, SCAN-CONTRACT-ERROR, etc. Raw string throws never occur (grep-gated).

Cancellation (AbortSignal)#

The scanning, context-pack and instruction-graph entries accept { signal?: AbortSignal } and reject with DOMException { name:"AbortError" } within 200ms when signal.aborted is true before the call. Mid-flight cancellation is cooperative at scan batches, pack checkpoints and graph file boundaries; it is not a fixed wall-clock guarantee for arbitrary caller-supplied rules.

Pattern reused from buildContextPack checkpoints (6 checkpoints) and runScan batch loop.

Examples#

  • examples/sdk-consumer.mjs — minimal ESM import smoke (isolated tarball install validated).
  • Integration tests: tests/integration/sdk-cancellation.test.ts proves abort <200ms.

Compatibility#

Pre-1.0 policy: minor may add (not remove) symbols; additive fields have defaults. ackit.yml v1 files remain valid under v2 (defaults for readiness/profile/rulePacks).

MCP / Action / Dashboard / VS Code reuse#

All share this SDK; direct src/core imports from src/cli/src/mcp for scanner pipeline are considered internal implementation of the package (external consumers must not import src/core). The public boundary is src/index.ts.