api-layer

67 beliefs (53 IN, 14 OUT)

The api-layer topic covers the design and behavioral contracts of the two outermost layers in the reasons system: the functional API in api.py and the CLI in cli.py. These layers mediate all access to the underlying TMS engine and persistence, so their contracts determine what callers can rely on — JSON-serializability of returns, atomicity of mutations, error semantics, and search resilience. The three-layer architecture belief (three-layer-architecture) establishes the overall structure: data model, TMS engine, and persistence at the bottom, with the API providing context-managed operations and the CLI acting as a thin formatting wrapper on top.

The API layer enforces several interlocking safety properties. Every mutation runs inside a context manager that guarantees atomic load-operate-save semantics (api-uses-with-network-context-manager, api-layer-ensures-atomic-isolated-mutations), and mutating operations use before/after truth-value diffing to report structured change sets (api-mutating-ops-use-before-after-diffing). Public functions return dicts rather than live objects (api-functions-return-dicts), preventing callers from holding references that could bypass the persistence boundary. At the access control boundary, single-node lookups raise PermissionError on forbidden nodes while collection endpoints silently filter (direct-access-raises-list-access-filters, single-node-api-raises-permissionerror). Input validation catches duplicates via ValueError (duplicate-node-id-raises-valueerror) and requires at least one justification type on add_justification (api-add-justification-requires-justification-arg). Search is notably resilient: it tries FTS5 first, falls back to substring matching, and caps progressive relaxation at 50 queries to prevent combinatorial blowup (search-uses-fts5-with-substring-fallback, search-relaxation-capped-at-50-queries, api-fts-search-bounds-query-calls). Both layers use lazy imports to keep startup fast (api-uses-lazy-imports, cli-uses-lazy-imports-for-heavy-modules).

The CLI layer is characterized as a pure formatter: every cmd_* handler delegates to an api.* function and only formats the returned dict for terminal display (cli-is-pure-formatter). Dispatch is a flat dictionary lookup with no plugin system (cli-dispatch-is-flat-dict-lookup), exit codes are strictly binary — 0 or 1 (cli-exit-code-contract-is-binary), and output streams are cleanly separated with diagnostics on stderr and results on stdout (cli-errors-use-stderr-success-uses-stdout). Several commands follow a plan-review-apply workflow where proposals are written to a file for human review before being applied (cli-plan-review-apply-pattern). A notable subset of commands — those requiring filesystem access, LLM calls, or bulk load-modify-save semantics — are SQLite-only and will refuse to run against PostgreSQL (cli-sqlite-only-commands-exist, sqlite-only-commands-are-filesystem-llm-or-bulk). Testing is black-box integration: every test creates an isolated database and exercises the full argv-parsing pipeline (cli-tests-are-black-box-integration, each-cli-test-creates-isolated-db).

Several beliefs are retracted (OUT), and these mostly represent higher-order synthesis claims that were superseded or found to overreach. For example, api-enforces-typed-preconditions, cli-is-pure-delegation-layer, and cli-is-verified-pure-delegation were retracted, likely because their sweeping characterizations conflicted with specific exceptions like cmd_propagate bypassing the API (cmd-propagate-bypasses-api, itself now also OUT). Similarly, a cluster of derived beliefs about mutation pipeline properties (mutation-pipeline-is-atomic-snapshot, mutation-pipeline-produces-consistent-state, mutations-are-atomic-and-safely-propagated, mutation-safety-spans-all-dimensions) are all OUT, suggesting that these broad unifying claims were retracted in favor of more precise, individually scoped beliefs like mutations-are-atomic-audited-and-index-consistent and mutations-are-observable-audited-and-index-consistent which remain IN. The pattern of retraction indicates an epistemic tightening — replacing ambitious synthesized claims with narrower, directly verifiable ones.