Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .githooks/post-commit
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ cd "$(git rev-parse --show-toplevel)" || exit 0
if command -v uv >/dev/null 2>&1; then RUN="uv run"; else RUN="./.venv/bin/python"; fi
$RUN scripts/snapshot_code.py 2>&1 || echo "code-sensor sync failed (non-blocking; next sync heals)"
$RUN scripts/sense_self.py 2>&1 || echo "self-sensor sync failed (non-blocking; next sync heals)"
# The code instance (dn-palace-lite), when it has landed once: as .githooks/post-merge keeps it.
[ -f config/instances/code.toml ] && { MIND_PALACE_OVERLAY=config/instances/code.toml \
$RUN scripts/palace.py repo-sync --if-landed 2>&1 \
|| echo "code instance sync failed (non-blocking; next sync heals)"; }
exit 0
17 changes: 17 additions & 0 deletions .githooks/post-merge
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh
# A pull or merge that moves main keeps the code instance current (docs/design-notes/
# dn-palace-lite.md): its repositories' files land by the writer, a changed file a new version, a
# file gone retired, no vector computed. NEVER blocks the merge: a failed sync prints a warning and
# exits 0; the sync is idempotent catch-up, so the next one (any merge or commit on main, or
# `palace repo-sync` by hand) heals the gap. Only an instance already landed once is kept current
# here (`--if-landed`); its first sync is the operator's.
#
# main is the ingestion branch (CONVENTIONS §Commits): exit silently on any other branch or
# detached HEAD.
[ "$(git symbolic-ref --short -q HEAD)" = "main" ] || exit 0
cd "$(git rev-parse --show-toplevel)" || exit 0
[ -f config/instances/code.toml ] || exit 0
if command -v uv >/dev/null 2>&1; then RUN="uv run"; else RUN="./.venv/bin/python"; fi
MIND_PALACE_OVERLAY=config/instances/code.toml $RUN scripts/palace.py repo-sync --if-landed 2>&1 \
|| echo "code instance sync failed (non-blocking; next sync heals)"
exit 0
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![sorry](https://img.shields.io/badge/sorry-0-brightgreen)](formal/sorry-budget)
[![kernels](https://img.shields.io/badge/kernel_replay-6_checkers-6f42c1)](formal/check.sh)
[![attacks](https://img.shields.io/badge/attacks-227_with_controls-blue)](formal/PalaceTest)
[![tests](https://img.shields.io/badge/tests-3633-brightgreen)](docs/runbook.md)
[![tests](https://img.shields.io/badge/tests-3651-brightgreen)](docs/runbook.md)
[![coverage](https://img.shields.io/badge/coverage-77%25-green)](pyproject.toml)
[![mypy](https://img.shields.io/badge/mypy-0_errors_in_core-brightgreen)](pyproject.toml)
[![sealed core](https://img.shields.io/badge/sealed_core-zero_egress-6f42c1)](scripts/check_imports.py)
Expand Down Expand Up @@ -161,7 +161,7 @@ Utility is a side effect and is treated as one. What the project optimizes for i

The base build is complete and the live instance runs always-on under launchd with a gated deployment path. "Complete" is not "wired": this repo distinguishes built, deployed and wired, and its own audit found the summaries were the least honest surface, so this one names the gaps.

Wired and live: ingestion (notes within seconds, code per commit), dreaming on a six-hour cadence, the provenance firewall, the attestation chain, the strict-typed core, CI on every push, deploy-gated releases, the research airlock, the curated literature store, and the query language with its one MCP command, the CLI, the query log as a sensor, and a battery run read-only against the live stores. Built but deliberately dormant, each waiting on its design gate: retrieval demotion for superseded content, the supersession certification layer, effectors (the "hands", flag-off at every tier), recursive dreaming. Open in the language, and stated in every answer: version moves at the note grain are empty (the chains are per note), and there is no snapshot of the notes at a past cut. The causal moves are wired: a transcript turn to the files it produced, and back. So is the ingress: ingestion is written in a generic language, and each path, from the vault sync to a capture, is a script of it (`ingress/`). A surface speaks a request, `do sync_vault` or a script inline, typed under the speaker's grant; the daemon evaluates it under a budget of measured work into a plan and lands the plan as the one writer, under the palace's rules, and the answer is a receipt. The Ambassador's write tools are requests, and its inbox lands the owner's messages through a script of its own, under a role that writes nothing else. Landing is two-phase where an instance asks for it (`[embedding] lazy`): an item lands complete without its vector, with its bytes, label, edges and a lexical index, and the `embed` drain derives the vectors afterwards, idempotently; a query that needs a vector not yet derived reports the item pending instead of guessing (ING-19 to ING-21). The default instance keeps synchronous embedding. Left for later: research, a paper's manifest, and one commit's or one session's backfill as scripts, and the parallel dispatcher, whose laws are proved (DO-6).
Wired and live: ingestion (notes within seconds, code per commit), dreaming on a six-hour cadence, the provenance firewall, the attestation chain, the strict-typed core, CI on every push, deploy-gated releases, the research airlock, the curated literature store, and the query language with its one MCP command, the CLI, the query log as a sensor, and a battery run read-only against the live stores. Built but deliberately dormant, each waiting on its design gate: retrieval demotion for superseded content, the supersession certification layer, effectors (the "hands", flag-off at every tier), recursive dreaming. Open in the language, and stated in every answer: version moves at the note grain are empty (the chains are per note), and there is no snapshot of the notes at a past cut. The causal moves are wired: a transcript turn to the files it produced, and back. So is the ingress: ingestion is written in a generic language, and each path, from the vault sync to a capture, is a script of it (`ingress/`). A surface speaks a request, `do sync_vault` or a script inline, typed under the speaker's grant; the daemon evaluates it under a budget of measured work into a plan and lands the plan as the one writer, under the palace's rules, and the answer is a receipt. The Ambassador's write tools are requests, and its inbox lands the owner's messages through a script of its own, under a role that writes nothing else. Landing is two-phase where an instance asks for it (`[embedding] lazy`): an item lands complete without its vector, with its bytes, label, edges and a lexical index, and the `embed` drain derives the vectors afterwards, idempotently; a query that needs a vector not yet derived reports the item pending instead of guessing (ING-19 to ING-21). The default instance keeps synchronous embedding. An instance may also embed nothing (`[embedding] enabled = false`), and a source may keep no vectors (`[ingestion.code] embed = false`): its items land with their lexical units and no vector, and `near` ranks them by the lexical index and says so. The code instance (`config/instances/code.toml`) lands this repository's files that way, read through git at `main`, for a coding agent to query over MCP. Left for later: research, a paper's manifest, and one commit's or one session's backfill as scripts, and the parallel dispatcher, whose laws are proved (DO-6).

The current frontier is the query algebra as the system's interface, the mathematics pushed to where its claims close or break, and the trace as the language's debugger. Behind it, drafted: the palace's memory of itself, the graph as it stood at any past cut, and the conversations that design the system becoming a stratum it can study.

Expand All @@ -177,7 +177,7 @@ The build's own history is a dataset. Every commit's structure is snapshotted in

```sh
uv sync --extra dev
uv run pytest -q -m 'not live and not podman and not needs_vault and not needs_restic' # the deterministic tier: 3,633 tests
uv run pytest -q -m 'not live and not podman and not needs_vault and not needs_restic' # the deterministic tier: 3,651 tests
uv run mypy # strict core: 0 errors (the 67 in tests/ are pinned)
uv run python scripts/check_imports.py # the sealed core names no network module
uv run python -m ops.type_gate # every core-reaching package is type-checked
Expand Down
36 changes: 34 additions & 2 deletions agents/ambassador/mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,22 @@ def overview(self) -> dict[str, Any]:
}
for s in AMBASSADOR.scopes
]
return {
out: dict[str, Any] = {
"catalog_by_provenance": dict(catalog),
"vector_rows": self.engine._get("vectors").count(),
"relation_edges": dict(edges),
"versions": self.engine._get("versions").count(),
"your_grant": planes,
}
if not cfg.embedding.enabled: # the lite profile: say so, and what ranks instead
out["embedding"] = "off: this instance embeds nothing; near ranks by the lexical index"
lexical = self.engine._get("lexical")
if lexical is not None:
out["lexical_units"] = lexical.count()
code = code_sources(cfg)
if code:
out["code"] = code
return out

# writes and on-demand work -----------------------------------------------------------------
def _run(self, fn: Callable[[], int]) -> dict[str, Any]:
Expand Down Expand Up @@ -169,7 +178,9 @@ def status(self) -> dict[str, Any]:
"models": {
"chat": model_state(cfg.runtime.port_for("routine") or 8080,
key=chat_key(policy)),
"embedder": model_state(cfg.runtime.port_for("embedding") or 8081),
# an instance that embeds nothing has no embedder to ask (dn-palace-lite)
"embedder": (model_state(cfg.runtime.port_for("embedding") or 8081)
if cfg.embedding.enabled else "off"),
},
"heartbeat": last_tick(cfg.paths.data_dir, interval_s=policy.interval_s),
"services": _launch_agents(),
Expand Down Expand Up @@ -224,6 +235,27 @@ def _ledger(self, op: Callable[[Any], dict[str, Any]]) -> dict[str, Any]:
return {**out, "now": now_local().isoformat(timespec="minutes")}


def code_sources(cfg: Any) -> list[dict[str, Any]]:
"""Each repository of the lexical code source (dn-palace-lite): the commit whose files it
last landed whole, when, and how many commits its ref has moved past that since, so a reader
knows how current the code stratum is before trusting an answer from it."""
from core.ingest.readers import read_mark
from core.ingest.repository import behind
from core.ingest.table import repository_mark
from core.kernel.config.loader import lexical_code

if not lexical_code(cfg):
return []
out = []
for repo in cfg.ingestion.code.repositories:
mark = read_mark(repository_mark(cfg, repo.name))
landed = str(mark["commit"]) if mark else ""
out.append({"repository": repo.name, "ref": repo.ref, "landed": landed[:12] or None,
"at": mark.get("at") if mark else None,
"behind": behind(Path(repo.path), landed, repo.ref) if landed else None})
return out


def _launch_agents() -> list[dict[str, str]]:
"""The stack's LaunchAgents: running (pid) or idle, and the last exit status."""
import subprocess
Expand Down
63 changes: 63 additions & 0 deletions config/instances/code.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# The CODE instance: source repositories for a coding agent to query, with no embedder and no
# language model (docs/design-notes/dn-palace-lite.md).
#
# Selected by `MIND_PALACE_OVERLAY=config/instances/code.toml`. A named overlay replaces the whole
# per-machine chain, so nothing of Ouroboros's `ouroboros.toml` or `levers.toml` reaches this
# instance (DI-2). Its state lives under its own root, outside every checkout and worktree, so it
# outlives the one a process happens to run from; it declares no vault, no transcripts and no
# dialogue, so it reads none of the default instance's sources.
#
# The repositories below are read through git's object store at their ref, never their working
# tree. `palace repo-sync` lands each one's files as items of the reference stratum, a changed file
# a new version and a file gone from the ref retired, with their lexical units and no vector; a
# second run after no commit lands nothing. No daemon runs for this instance: it embeds nothing,
# and nothing in it wakes a model.
#
# MIND_PALACE_OVERLAY=config/instances/code.toml uv run scripts/palace.py repo-sync
# MIND_PALACE_OVERLAY=config/instances/code.toml uv run scripts/palace.py query 'near "x" over reference'
# MIND_PALACE_OVERLAY=config/instances/code.toml uv run python scripts/palace_mcp.py

[instance]
id = "code"
root = "~/.mind-palace/instances/code"

# No embedder: no plane is opened, no drain runs, and `near` ranks by the lexical index, saying so.
[embedding]
enabled = false

[dreaming]
scheduled = false # no language model: nothing dreams, relates or curates

[ingestion.vault]
enabled = false
[ingestion.transcripts]
enabled = false

[ingestion.code]
enabled = true
embed = false

# One table per repository; add another to read more. An item is `code/<name>/<path>`.
[[ingestion.code.repositories]]
name = "mind-palace"
path = "~/mind-palace"
ref = "main"

[integrate]
enabled = false

[backup]
enabled = false

[secrets]
enabled = false

[attestation]
enabled = false

[selfmod]
enabled = false
unattended_enabled = false

[effectors]
enabled = false
14 changes: 10 additions & 4 deletions core/ingest/derive.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
Provenance.CURATED.value: CURATED_READ,
}

# The classes whose items the lexical index holds: the plane's, and the code's, which lands with
# lexical units and no vector (dn-palace-lite), so it is in no plane class and the vector drain
# never sees it. The lexical backfill re-derives all of them after a tokenizer change.
LEXICAL_CLASSES: frozenset[str] = frozenset(HOLDS) | {Provenance.CODE.value}


@dataclass(frozen=True)
class DrainReport:
Expand Down Expand Up @@ -268,10 +273,11 @@ def __str__(self) -> str:

def lexical_missing(catalog: Any, lexical: Any, *,
classes: Iterable[Provenance] | None = None) -> list[CatalogEntry]:
"""The active entries of the plane's classes (of `classes` when given) whose current version
the lexical index has no record of: items landed before the index was opened, by an earlier
writer or while the instance embedded synchronously."""
wanted = {p.value for p in classes} if classes is not None else set(HOLDS)
"""The active entries of the classes the lexical index holds (`LEXICAL_CLASSES`; of `classes`
when given) whose current version the index has no record of: items landed before the index
was opened, by an earlier writer or while the instance embedded synchronously, and every item
after a tokenizer change reset the index, the code's included."""
wanted = {p.value for p in classes} if classes is not None else set(LEXICAL_CLASSES)
have = lexical.landed_versions()
return [e for e in catalog.active_entries()
if str(e.provenance) in wanted and (e.source_path, e.digest) not in have]
Expand Down
4 changes: 4 additions & 0 deletions core/ingest/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ def build_embedder(config: Config | None = None) -> Embedder:
from core.models.inference import build_inference_client

cfg = config or get_config()
if not cfg.embedding.enabled: # the lite profile: no embedder exists (dn-palace-lite)
from core.stores.noplane import refuse

raise refuse("building the embedder")
# The embedding ROLE picks its own backend (`[runtime] embedding_backend`), independently of
# the chat tiers — that is what makes the embedder cutover a real, separately reversible step
# (dn-local-model-runtime §2.6 P4). Default is `ollama`, so this returns exactly what it
Expand Down
29 changes: 21 additions & 8 deletions core/ingest/ingress.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,23 +625,35 @@ def prune(cfg: Config, *, now: float | None = None, max_age_s: float = PRUNE_AFT

def build_stores(cfg: Config, enqueue: Callable[..., int] | None = None) -> Any:
"""The stores the writer lands into, opened by the daemon, the one writer. The lexical index
is opened under `[embedding] lazy` alone (dn-two-phase-ingestion D6), so an instance that
embeds synchronously writes nothing it did not write before."""
is opened when the instance lands lazily, embeds nothing, or has a source that keeps no
vectors (`needs_lexical`; dn-two-phase-ingestion D6, dn-palace-lite), so an instance that
embeds every item synchronously writes nothing it did not write before. An instance that
embeds nothing builds no embedder and opens no plane: the writer is handed `NoPlane`."""
from core.attestation import build_attestor
from core.ingest.embed import build_embedder
from core.ingest.writer import Stores
from core.kernel.config.loader import needs_lexical
from core.kernel.stores.rawstore import RawStore
from core.stores.catalog import VaultCatalog
from core.stores.edges import open_edge_store
from core.stores.lexical import open_lexical_store
from core.stores.vectorstore import open_vector_store
from core.stores.versions import open_version_store

return Stores(raw=RawStore(cfg.paths.raw_store), plane=open_vector_store(cfg),
embedder=build_embedder(cfg), catalog=VaultCatalog(cfg.paths.vault_catalog),
plane: Any = None
embedder: Any = None
if cfg.embedding.enabled:
from core.ingest.embed import build_embedder
from core.stores.vectorstore import open_vector_store

plane, embedder = open_vector_store(cfg), build_embedder(cfg)
else:
from core.stores.noplane import NoPlane

plane = NoPlane()
return Stores(raw=RawStore(cfg.paths.raw_store), plane=plane,
embedder=embedder, catalog=VaultCatalog(cfg.paths.vault_catalog),
versions=open_version_store(cfg), attestor=build_attestor(cfg),
edges=open_edge_store(cfg), enqueue=enqueue,
lexical=open_lexical_store(cfg) if cfg.embedding.lazy else None)
lexical=open_lexical_store(cfg) if needs_lexical(cfg) else None)


def reader(cfg: Config, role: str) -> Callable[[str], list[Any]]:
Expand Down Expand Up @@ -724,7 +736,8 @@ def perform(do: ast.Do, cfg: Config, role: str, *, stores: Any,
plan = Evaluator(v, role, meter, library=library or load).run(script, args, kwargs, name=name)
reads = frozenset().union(*(classes_of(s.sigma.strata) for s in grant_for(role).scopes))
writer = Writer(table, role, stores, has=v.has, meter=meter, request=request, reads=reads,
batch=batch, lazy=bool(cfg.embedding.lazy) if lazy is None else lazy)
batch=batch, lazy=bool(cfg.embedding.lazy) if lazy is None else lazy,
embedding=bool(cfg.embedding.enabled))
cut_before = getattr(stores.embedder, "cut", None)
outcomes = writer.land(plan)
if hasattr(v, "landed"):
Expand Down
Loading
Loading