instinct-cli 0.3.6

Local memory for AI coding agents: an MCP server and CLI that gives Claude Code, Codex, Cursor and any MCP client the one lesson that fits. Lessons that keep failing go quiet.
# Artifact observation wire v1 — first implementation seam

Status: M2 contract, to be frozen before adapter code. Extends `check-observations.md`; pure M1 `check run` never gains ambient filesystem access.

## Platform behavior

Inventory observation is implemented on Unix. On macOS only, the fixed operating-system aliases `/var` → `/private/var`, `/tmp` → `/private/tmp`, and `/etc` → `/private/etc` are resolved when they occur **above** the explicitly named root and their actual link target matches the fixed mapping. The named root and all user-created symlinks remain rejected. This is not arbitrary ancestor canonicalization and does not change the quiescent-tree race assumption. Windows observation returns an explicit unsupported-platform abstention with no inventory; checked hits refuse with no recorded hit.

## Explicit command

```
instinct check observe --root /absolute/staging/root --input policy.json
```

Only this native CLI command grants read-only access to the exact root for this invocation. Validate the raw root spelling before filesystem path normalization: reject dot/dot-dot components, repeated separators and trailing separators on non-root paths. A filesystem root with no parent (such as `/`, `C:\`, or a Windows verbatim/UNC root) may retain its single final separator; doubled final separators remain invalid. This prevents trailing `/` or `/.` from resolving a final symlink before metadata inspection. `--root` is required and absolute; it is not read from JSON, environment, cwd, a lesson or pack. No observation MCP tool or implicit hook path is enabled in this increment. Existing `check validate|run|explain` syntax/semantics stay unchanged.

Policy envelope (only these keys):

```json
{
  "schema": "instinct.artifact-policy/v1",
  "assumptions": {"trusted_quiescent_staging": true},
  "allowed": ["docs", "docs/README", "release.bin"],
  "required": ["release.bin"],
  "scope": {"project": "release-lab"},
  "limits": {"max_entries": 10000, "max_depth": 64, "max_inventory_bytes": 1048576}
}
```

`schema` and `allowed` required; required defaults empty; scope defaults empty and uses M1 exact scope validation; limits defaults shown. `assumptions` has only boolean `trusted_quiescent_staging`; omitted or false yields incomplete/abstain before filesystem traversal. True is an explicit caller assumption, not observed proof of quiescence. It must be echoed in results under `assumptions` so receipts never conceal this premise. Reject duplicate/unknown fields and invalid numerics through the M1 strict parser. Allowed/required lists contain unique UTF-8 relative component paths: no empty, `.` or `..` components, leading/trailing slash, repeated separators, NUL, Unix absolute path, Windows drive/UNC syntax. Backslash is an ordinary Linux filename character unless part of a recognized absolute drive/UNC form; no normalization. Directory entries are included as names. `required` must be a subset of allowed: contradictory policy is an error, not an impossible check silently evaluated. This corrects the earlier contradictory phrase “need not” while retaining the originally specified contradictory-policy error.

Limits may only narrow implementation ceilings in v1. `max_entries` 0..10000 includes files+directories, root excluded. `max_depth` 0..64 is relative entry depth (root=0). `max_inventory_bytes` 0..1048576 charges UTF-8 relative path bytes plus 64 bytes per entry as a deterministic metadata-accounting allowance, independently per enumeration pass; it does not pretend to measure filesystem/kernel I/O or content bytes. No file contents are opened in inventory mode. Check counts before growing result buffers. Metadata/content fingerprints and receipt persistence are later M2 substeps, explicitly absent here.

## Observation result

`schema: instinct.artifact-observation/v1`, `adapter: artifact-inventory/v1`, `validity: observed_snapshot|incomplete`, `evidence_origin: adapter_observed`, `authorization: not_evaluated`, `reason`, `inventory` (sorted array of `{path,kind}`), `checks` (M1 results), `limits`, `visited_entries` (accepted first-pass entries, bounded by max_entries), and optionally `scan_visits` (actual entries examined across both passes, including the one entry that detects an over-limit condition). Each pass has its own entry/inventory-byte bound; aggregate metadata work is at most twice those limits plus boundary detection. These are logical accounting units, not allocator or kernel-memory measurements.

Complete observation runs two pure kernel checks over adapter-produced actual and caller-policy sets:
- actual subset allowed;
- required subset actual when required is nonempty.

Reuse `kernel::evaluate`; do not implement a second subset engine. Their embedded predicate inputs remain explicit facts; wrapper provenance attributes only the actual inventory to observation and policy to caller. Do not relabel allowed policy as observed authority. Both predicates share explicit scope. A check PASS is never labeled safe_to_release.

Incomplete observation (permission, unsupported entries, symlinks, nonUTF8 paths, detected race or budget) has empty inventory/checks, an abstention reason and no completeness claim. A sanitized relative witness may be provided for the offending entry, never a symlink target or absolute path outside root. Root validation errors may return structured check-error exit2. Incomplete/fail/pass observation exit0. All output <=65536bytes; exact data that does not fit returns bounded output-limit error.

## Race and root policy

Use `symlink_metadata`, reject symlink components from root through descendants, and never call read_link. Ordinary portable std path traversal is not a no-race security boundary. Walk names/kinds and relevant metadata twice; mismatch abstains. Provide an internal test seam between passes, not a public command that mutates files. Tests inject changes independently.

On Linux, descriptor-relative enumeration or an equivalent pinned-directory strategy is required before claiming that a hostile replacement cannot escape the root. This first adapter must either use an already-reviewed safe mechanism or restrict its documented grant to trusted, quiescent staging trees and abstain for untrusted/racing contexts. Do not imply double enumeration eliminates TOCTOU. Native Windows/macOS have separate platform tests; unsupported semantics abstain rather than silently use Unix assumptions.

## Deliberate partial scope

This seam establishes actual inventory→existing pure checks with no writes. Full M2 still includes grant/root fingerprints, content-dependent adapters, receipts, cryptographic identity and crash recovery. The acceptance data may contain future cases; mark those NOT IMPLEMENTED/SKIP, never green. No permanent API claims until independent adapter tests and review pass.