dandelion-memory 1.0.0rc15__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- benchmarks/__init__.py +3 -0
- benchmarks/adapters/__init__.py +29 -0
- benchmarks/adapters/ablations.py +406 -0
- benchmarks/adapters/base.py +72 -0
- benchmarks/adapters/controlled/__init__.py +13 -0
- benchmarks/adapters/controlled/core_archival.py +115 -0
- benchmarks/adapters/controlled/extract_resolve.py +130 -0
- benchmarks/adapters/controlled/hybrid_rag.py +120 -0
- benchmarks/adapters/controlled/no_late_binding.py +113 -0
- benchmarks/adapters/dandelion.py +94 -0
- benchmarks/adapters/native/__init__.py +31 -0
- benchmarks/adapters/native/base.py +45 -0
- benchmarks/adapters/native/dandelion_native.py +164 -0
- benchmarks/adapters/native/dandelion_native_b0.py +165 -0
- benchmarks/adapters/native/dandelion_native_b1.py +170 -0
- benchmarks/adapters/native/dandelion_native_b2.py +169 -0
- benchmarks/adapters/native/dandelion_native_b3.py +171 -0
- benchmarks/adapters/native/dandelion_native_c4.py +261 -0
- benchmarks/adapters/native/dandelion_native_c4_1.py +281 -0
- benchmarks/adapters/native/dandelion_native_c4_2.py +435 -0
- benchmarks/adapters/native/event_evidence_b2.py +616 -0
- benchmarks/adapters/native/evidence_b2.py +609 -0
- benchmarks/adapters/native/letta_native.py +253 -0
- benchmarks/adapters/native/mem0_native.py +219 -0
- benchmarks/adapters/native/store_vector_b0.py +792 -0
- benchmarks/adapters/native/store_vector_b2.py +808 -0
- benchmarks/agent_adapter_stdio_acceptance.py +86 -0
- benchmarks/bootstrap_cross_stack.py +218 -0
- benchmarks/canonical_profile_instrumentation.py +167 -0
- benchmarks/canonical_public_baseline.py +288 -0
- benchmarks/cli.py +525 -0
- benchmarks/collector_public30_offline.py +1653 -0
- benchmarks/datasets/__init__.py +45 -0
- benchmarks/datasets/conversational_generator.py +238 -0
- benchmarks/datasets/generator.py +283 -0
- benchmarks/datasets/holdout_topology_generator.py +290 -0
- benchmarks/datasets/holdout_topology_generator_v2.py +294 -0
- benchmarks/datasets/multi_world.py +1643 -0
- benchmarks/datasets/scale_generator.py +289 -0
- benchmarks/datasets/schema.py +57 -0
- benchmarks/deep_collision_stress.py +199 -0
- benchmarks/evaluators/__init__.py +12 -0
- benchmarks/evaluators/manifest.py +142 -0
- benchmarks/evaluators/metrics.py +277 -0
- benchmarks/evaluators/runner.py +258 -0
- benchmarks/f1_step0/build_dev_measurement_manifest_v1.py +127 -0
- benchmarks/f1_step0/build_dev_measurement_manifest_v2.py +127 -0
- benchmarks/f1_step0/build_dev_measurement_manifest_v3.py +146 -0
- benchmarks/f1_step0/build_ledger.py +143 -0
- benchmarks/f1_step0/build_ledger_v2.py +296 -0
- benchmarks/f1_step0/compare_dev52_readiness_v1.py +106 -0
- benchmarks/f1_step0/locator_public_smoke.py +172 -0
- benchmarks/f1_step0/prepare_dev52_owner_v1.py +133 -0
- benchmarks/f1_step0/prepare_dev52_owner_v2.py +133 -0
- benchmarks/f1_step0/public_identity_probe.py +191 -0
- benchmarks/f1_step0/public_response_mapper.py +101 -0
- benchmarks/f1_step0/real_source_public_preflight.py +244 -0
- benchmarks/f1_step0/run_exact_fusion_dev_experiment_v1.py +83 -0
- benchmarks/f1_step0/scorer.py +110 -0
- benchmarks/f1_step0/source_aware_dev_measurement_v1.py +627 -0
- benchmarks/f1_step0/source_aware_dev_measurement_v2.py +659 -0
- benchmarks/f1_step0/source_aware_dev_measurement_v3.py +776 -0
- benchmarks/f1_step0/test_public_response_mapper.py +110 -0
- benchmarks/f1_step0/test_real_source_public_preflight.py +25 -0
- benchmarks/f1_step0/test_scorer.py +158 -0
- benchmarks/f1_step0/test_source_aware_dev_measurement.py +189 -0
- benchmarks/f1_step0/test_source_aware_dev_measurement_v2.py +263 -0
- benchmarks/f1_step0/test_source_aware_dev_measurement_v3.py +334 -0
- benchmarks/f1_step0/typed_readback_public_smoke.py +181 -0
- benchmarks/forensic_c4_1_dev.py +258 -0
- benchmarks/forensic_c4_dev.py +255 -0
- benchmarks/forensic_deep25_c4_1.py +478 -0
- benchmarks/legacy_migration_acceptance.py +29 -0
- benchmarks/longmemeval_actor.py +497 -0
- benchmarks/longmemeval_agent_judge.py +593 -0
- benchmarks/longmemeval_budget.py +139 -0
- benchmarks/longmemeval_full.py +410 -0
- benchmarks/longmemeval_judge.py +327 -0
- benchmarks/longmemeval_pilot.py +316 -0
- benchmarks/longmemeval_s.py +318 -0
- benchmarks/memory_bench.py +248 -0
- benchmarks/memory_formation/__init__.py +1 -0
- benchmarks/memory_formation/audit.py +801 -0
- benchmarks/memory_formation/real_audit.py +688 -0
- benchmarks/memory_session_acceptance.py +279 -0
- benchmarks/native_codex_host.py +513 -0
- benchmarks/owner_dense_acceptance.py +126 -0
- benchmarks/pilot_seeker_vault.py +266 -0
- benchmarks/prepare_public30_ripgrep_range_owner.py +115 -0
- benchmarks/profile_canonical.py +373 -0
- benchmarks/profile_canonical_lanes.py +405 -0
- benchmarks/profile_search_chunks.py +351 -0
- benchmarks/public_ranges_faq_proof.py +121 -0
- benchmarks/public_repos/build_history_scope_v3.py +330 -0
- benchmarks/public_repos/build_oracle.py +108 -0
- benchmarks/public_repos/build_oracle_v2.py +169 -0
- benchmarks/public_repos/build_oracle_v3.py +176 -0
- benchmarks/public_repos/map_public_v2.py +296 -0
- benchmarks/public_repos/project_prompts_v2.py +31 -0
- benchmarks/public_repos/project_prompts_v3.py +29 -0
- benchmarks/public_repos/ready_admin_v2.py +214 -0
- benchmarks/public_repos/score_public_v2.py +258 -0
- benchmarks/public_repos/test_map_public_v2.py +171 -0
- benchmarks/public_repos/test_public_repo_v2.py +44 -0
- benchmarks/public_repos/test_public_repo_v3.py +46 -0
- benchmarks/public_repos/test_ready_admin_v2.py +117 -0
- benchmarks/public_repos/test_score_public_v2.py +163 -0
- benchmarks/public_repos/test_wire_v2.py +292 -0
- benchmarks/public_repos/wire_v2.py +603 -0
- benchmarks/real_blocker_fix_acceptance.py +155 -0
- benchmarks/real_scan_rescan_acceptance.py +41 -0
- benchmarks/recall_v2_20k_smoke.py +112 -0
- benchmarks/recall_v2_e1_retrieve.py +70 -0
- benchmarks/recall_v2_e1_score.py +271 -0
- benchmarks/recall_v2_e2_prepare.py +69 -0
- benchmarks/recall_v2_e2_public_score.py +91 -0
- benchmarks/recall_v2_e2_score.py +108 -0
- benchmarks/recall_v2_navigation_mcp_replay.py +308 -0
- benchmarks/recall_v2_reader_capture.py +118 -0
- benchmarks/recall_v2_reader_replay.py +136 -0
- benchmarks/run_blind_h10_holdout.py +284 -0
- benchmarks/run_blind_h9_holdout.py +275 -0
- benchmarks/run_c4_2_nightly_scale.py +446 -0
- benchmarks/run_context_scale_simulation.py +189 -0
- benchmarks/run_conversational_bench.py +170 -0
- benchmarks/run_h11_evaluation.py +316 -0
- benchmarks/run_h11_v2_evaluation.py +431 -0
- benchmarks/run_native_fixed12.py +469 -0
- benchmarks/run_native_preflight.py +280 -0
- benchmarks/run_scale_stress.py +225 -0
- benchmarks/solanazation_brownfield_01/build_oracle.py +970 -0
- benchmarks/solanazation_brownfield_01/check_level_a.py +78 -0
- benchmarks/solanazation_brownfield_01/debug_scope.py +13 -0
- benchmarks/solanazation_brownfield_01/evaluate_bootstrap_02.py +570 -0
- benchmarks/solanazation_brownfield_01/evaluate_first_pass.py +306 -0
- benchmarks/solanazation_brownfield_01/generate_dryrun_report.py +222 -0
- benchmarks/solanazation_brownfield_01/generate_manifests.py +146 -0
- benchmarks/solanazation_brownfield_01/inspect_misses.py +29 -0
- benchmarks/solanazation_brownfield_01/run_miss_forensic.py +206 -0
- benchmarks/solanazation_brownfield_01/test_facts.py +15 -0
- benchmarks/statistics/__init__.py +15 -0
- benchmarks/statistics/significance.py +326 -0
- benchmarks/test_native_mcp_preflight.py +229 -0
- benchmarks/test_prepare_public30_range_owner.py +35 -0
- benchmarks/test_public30_source_reference.py +698 -0
- benchmarks/test_recall_v2_e1_reader_input.py +89 -0
- benchmarks/test_recall_v2_navigation_mcp_replay.py +155 -0
- benchmarks/test_recall_v2_reader_replay.py +41 -0
- dandelion/__init__.py +3 -0
- dandelion/__main__.py +11 -0
- dandelion/agent_adapter.py +2369 -0
- dandelion/bootstrap/__init__.py +872 -0
- dandelion/bootstrap/alias_policy.py +50 -0
- dandelion/bootstrap/authority.py +225 -0
- dandelion/bootstrap/canonical_history.py +412 -0
- dandelion/bootstrap/classifier.py +403 -0
- dandelion/bootstrap/component_graph.py +280 -0
- dandelion/bootstrap/discovery.py +279 -0
- dandelion/bootstrap/domain_induction.py +180 -0
- dandelion/bootstrap/domain_topology.py +673 -0
- dandelion/bootstrap/evidence_envelope.py +132 -0
- dandelion/bootstrap/extractors/base.py +171 -0
- dandelion/bootstrap/extractors/exact.py +1234 -0
- dandelion/bootstrap/extractors/generic.py +100 -0
- dandelion/bootstrap/extractors/git_temporal.py +111 -0
- dandelion/bootstrap/extractors/registry.py +345 -0
- dandelion/bootstrap/extractors/relations.py +89 -0
- dandelion/bootstrap/extractors/semantic.py +424 -0
- dandelion/bootstrap/extractors/status.py +218 -0
- dandelion/bootstrap/git_sweeper.py +135 -0
- dandelion/bootstrap/manifest.py +246 -0
- dandelion/bootstrap/quarantine.py +264 -0
- dandelion/bootstrap/report.py +259 -0
- dandelion/bootstrap/root_resolver.py +221 -0
- dandelion/bootstrap/tech_profiler.py +125 -0
- dandelion/bootstrap/topology.py +75 -0
- dandelion/bootstrap/topology_index.py +110 -0
- dandelion/bootstrap/transaction.py +315 -0
- dandelion/canonical_bootstrap.py +257 -0
- dandelion/canonical_memory.py +4130 -0
- dandelion/captured_input.py +295 -0
- dandelion/cli.py +767 -0
- dandelion/config.py +40 -0
- dandelion/derived_index.py +745 -0
- dandelion/domains.py +706 -0
- dandelion/embedder.py +229 -0
- dandelion/event_evidence.py +571 -0
- dandelion/evidence.py +812 -0
- dandelion/evidence_response.py +453 -0
- dandelion/evidence_workspace.py +2360 -0
- dandelion/exact_context.py +129 -0
- dandelion/hydrator.py +124 -0
- dandelion/inspector.py +442 -0
- dandelion/inspector_assets/dandelion-mark.svg +33 -0
- dandelion/inspector_assets/dandelion_graph.js +361 -0
- dandelion/inspector_assets/inspector.css +223 -0
- dandelion/inspector_assets/inspector.html +135 -0
- dandelion/inspector_assets/inspector.js +1059 -0
- dandelion/legacy_import.py +431 -0
- dandelion/live_source_grants.py +133 -0
- dandelion/local_owner.py +114 -0
- dandelion/memory_client.py +252 -0
- dandelion/memory_contract.py +107 -0
- dandelion/memory_owner.py +560 -0
- dandelion/reader_providers.py +118 -0
- dandelion/recall_v2.py +767 -0
- dandelion/reconciler.py +219 -0
- dandelion/request_budget.py +125 -0
- dandelion/retained_basis.py +223 -0
- dandelion/retrieval.py +485 -0
- dandelion/router.py +405 -0
- dandelion/search_terms.py +53 -0
- dandelion/security.py +124 -0
- dandelion/server.py +810 -0
- dandelion/source_content_fts.py +219 -0
- dandelion/source_delivery.py +89 -0
- dandelion/source_history.py +241 -0
- dandelion/source_identity.py +88 -0
- dandelion/source_navigator.py +5 -0
- dandelion/source_reader.py +444 -0
- dandelion/source_references.py +379 -0
- dandelion/source_sections.py +265 -0
- dandelion/store_kv.py +684 -0
- dandelion/store_vector.py +1289 -0
- dandelion/studio.py +325 -0
- dandelion/wal.py +227 -0
- dandelion_memory-1.0.0rc15.dist-info/METADATA +48 -0
- dandelion_memory-1.0.0rc15.dist-info/RECORD +232 -0
- dandelion_memory-1.0.0rc15.dist-info/WHEEL +5 -0
- dandelion_memory-1.0.0rc15.dist-info/entry_points.txt +5 -0
- dandelion_memory-1.0.0rc15.dist-info/licenses/LICENSE +21 -0
- dandelion_memory-1.0.0rc15.dist-info/top_level.txt +2 -0
dandelion/cli.py
ADDED
|
@@ -0,0 +1,767 @@
|
|
|
1
|
+
"""Dandelion Command-Line Interface (CLI).
|
|
2
|
+
|
|
3
|
+
Subcommands:
|
|
4
|
+
init Initialize .dandelion configuration directory
|
|
5
|
+
bootstrap Bootstrap memory from codebase (BOOTSTRAP-02)
|
|
6
|
+
topology Display project hierarchical topology
|
|
7
|
+
inspect Introspect project structure, unknown formats, and conflicts
|
|
8
|
+
get Query exact fact by key from deterministic KV store
|
|
9
|
+
recall Query episodic memories with late-binding hydration
|
|
10
|
+
serve Run MCP server over stdio
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import argparse
|
|
16
|
+
import json
|
|
17
|
+
import os
|
|
18
|
+
import sys
|
|
19
|
+
import time
|
|
20
|
+
from functools import wraps
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
from typing import Optional
|
|
23
|
+
|
|
24
|
+
from dandelion.config import (
|
|
25
|
+
COLLECTION_NAME,
|
|
26
|
+
DANDELION_DIR,
|
|
27
|
+
FACTS_FILE,
|
|
28
|
+
QDRANT_DIR,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _owner_backend_selected(workspace: Path) -> bool:
|
|
33
|
+
try:
|
|
34
|
+
marker = workspace / ".dandelion" / "backend.json"
|
|
35
|
+
selected = json.loads(marker.read_text(encoding="utf-8")).get("mode") == "owner"
|
|
36
|
+
except (FileNotFoundError, OSError, json.JSONDecodeError):
|
|
37
|
+
return False
|
|
38
|
+
if not selected:
|
|
39
|
+
return False
|
|
40
|
+
from dandelion.memory_client import MemoryClient
|
|
41
|
+
status = MemoryClient.for_workspace(workspace).call("backend_status")
|
|
42
|
+
if status.get("status") != "ACTIVE":
|
|
43
|
+
raise RuntimeError("Canonical backend marker is invalid; refusing legacy fallback")
|
|
44
|
+
return True
|
|
45
|
+
from dandelion.bootstrap import (
|
|
46
|
+
bootstrap_project,
|
|
47
|
+
init_project,
|
|
48
|
+
BootstrapResult,
|
|
49
|
+
)
|
|
50
|
+
from dandelion.bootstrap.discovery import discover_project
|
|
51
|
+
from dandelion.bootstrap.topology import build_project_topology
|
|
52
|
+
from dandelion.bootstrap.quarantine import EpistemicQuarantine
|
|
53
|
+
from dandelion.bootstrap.transaction import BootstrapTransactionStore
|
|
54
|
+
from dandelion.domains import (
|
|
55
|
+
DomainRegistry,
|
|
56
|
+
PartitionDescriptor,
|
|
57
|
+
get_global_domain_registry,
|
|
58
|
+
resolve_wildcard,
|
|
59
|
+
)
|
|
60
|
+
from dandelion.hydrator import hydrate_template, is_sensitive_key
|
|
61
|
+
from dandelion.security import public_egress
|
|
62
|
+
from dandelion.store_kv import KVStore
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def __getattr__(name: str):
|
|
66
|
+
if name == "VectorStore":
|
|
67
|
+
from dandelion.store_vector import VectorStore
|
|
68
|
+
globals()[name] = VectorStore
|
|
69
|
+
return VectorStore
|
|
70
|
+
raise AttributeError(name)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _configure_stdout_utf8() -> None:
|
|
74
|
+
"""Make redirected Windows CLI output UTF-8 before emitting JSON/text.
|
|
75
|
+
|
|
76
|
+
``TextIOWrapper.reconfigure`` is unavailable on a few test and embedding
|
|
77
|
+
streams, where the existing in-memory stream is already Unicode-safe.
|
|
78
|
+
"""
|
|
79
|
+
reconfigure = getattr(sys.stdout, "reconfigure", None)
|
|
80
|
+
if callable(reconfigure):
|
|
81
|
+
try:
|
|
82
|
+
reconfigure(encoding="utf-8", errors="strict")
|
|
83
|
+
except (OSError, ValueError):
|
|
84
|
+
pass
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _consistent_read(command):
|
|
88
|
+
"""Acquire the bootstrap shared lease before a CLI command opens stores."""
|
|
89
|
+
@wraps(command)
|
|
90
|
+
def wrapped(args: argparse.Namespace) -> int:
|
|
91
|
+
target_dir = Path(args.path).resolve()
|
|
92
|
+
with BootstrapTransactionStore(target_dir / ".dandelion").read_lock():
|
|
93
|
+
return command(args)
|
|
94
|
+
|
|
95
|
+
return wrapped
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def load_topology(topology_file: Path) -> list[PartitionDescriptor]:
|
|
99
|
+
"""Load cached partition descriptors from JSON file."""
|
|
100
|
+
with open(topology_file, "r", encoding="utf-8") as f:
|
|
101
|
+
data = json.load(f)
|
|
102
|
+
return [PartitionDescriptor.from_dict(p) for p in data.get("partitions", [])]
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def cmd_init(args: argparse.Namespace) -> int:
|
|
106
|
+
"""Handle 'dandelion init' command."""
|
|
107
|
+
target_dir = Path(args.path).resolve()
|
|
108
|
+
res = init_project(target_dir)
|
|
109
|
+
print(f"Initialized Dandelion memory in {res['dandelion_dir']}")
|
|
110
|
+
print(f"Config: {res['config_file']}")
|
|
111
|
+
return 0
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def cmd_bootstrap(args: argparse.Namespace) -> int:
|
|
115
|
+
"""Handle 'dandelion bootstrap' command (BOOTSTRAP-02)."""
|
|
116
|
+
target_dir = Path(args.path).resolve()
|
|
117
|
+
if _owner_backend_selected(target_dir):
|
|
118
|
+
print("Error: owner backend forbids legacy bootstrap writes; migrate a frozen bootstrap copy through the owner.")
|
|
119
|
+
return 2
|
|
120
|
+
mode_str = "DRY RUN" if args.dry_run else "APPLYING"
|
|
121
|
+
print(f"Bootstrapping Dandelion memory for {target_dir} ({mode_str})...")
|
|
122
|
+
|
|
123
|
+
res = bootstrap_project(
|
|
124
|
+
target_dir,
|
|
125
|
+
dry_run=args.dry_run,
|
|
126
|
+
deep_history=args.deep_history,
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
if res.report_summary:
|
|
130
|
+
print("\n" + res.report_summary)
|
|
131
|
+
else:
|
|
132
|
+
d = res.to_dict()
|
|
133
|
+
print("\n" + "=" * 55)
|
|
134
|
+
print(f"Dandelion Project Assimilation Summary ({mode_str})")
|
|
135
|
+
print("=" * 55)
|
|
136
|
+
print(f" Project Root: {d['project_root']}")
|
|
137
|
+
print(f" Facts Inserted: {d['facts_inserted']}")
|
|
138
|
+
print(f" Memories Inserted: {d['memories_inserted']}")
|
|
139
|
+
print(f" Partitions Created: {d['partitions_created']}")
|
|
140
|
+
print(f" Topology Revision: {d['topology_revision']} ({d['topology_changes']} changes)")
|
|
141
|
+
print(f" Duration: {d['duration_sec']}s")
|
|
142
|
+
print("=" * 55)
|
|
143
|
+
return 0
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
@_consistent_read
|
|
147
|
+
def cmd_topology(args: argparse.Namespace) -> int:
|
|
148
|
+
"""Handle 'dandelion topology' command."""
|
|
149
|
+
target_dir = Path(args.path).resolve()
|
|
150
|
+
top_file = target_dir / ".dandelion" / "topology.json"
|
|
151
|
+
quar_file = target_dir / ".dandelion" / "quarantine.json"
|
|
152
|
+
|
|
153
|
+
if top_file.exists():
|
|
154
|
+
partitions = load_topology(top_file)
|
|
155
|
+
source_note = "from .dandelion/topology.json"
|
|
156
|
+
else:
|
|
157
|
+
report = discover_project(target_dir)
|
|
158
|
+
partitions = build_project_topology(report)
|
|
159
|
+
source_note = "discovered dynamically"
|
|
160
|
+
|
|
161
|
+
print(f"Dandelion Topology for '{target_dir.name}' ({source_note}):")
|
|
162
|
+
print(f"Total Partitions: {len(partitions)}\n")
|
|
163
|
+
|
|
164
|
+
for p in partitions:
|
|
165
|
+
print(f" [{p.canonical_id}]")
|
|
166
|
+
print(f" Title: {p.title}")
|
|
167
|
+
print(f" Role: {p.service_role}")
|
|
168
|
+
if p.description:
|
|
169
|
+
print(f" Desc: {p.description}")
|
|
170
|
+
if p.keywords:
|
|
171
|
+
print(f" Keys: {', '.join(p.keywords)}")
|
|
172
|
+
print()
|
|
173
|
+
|
|
174
|
+
if quar_file.exists():
|
|
175
|
+
quar = EpistemicQuarantine(quar_file)
|
|
176
|
+
items = quar.list_items()
|
|
177
|
+
if items:
|
|
178
|
+
print(f"Quarantine Ledger ({len(items)} items pending human review):")
|
|
179
|
+
for item in items:
|
|
180
|
+
print(f" - [{item.item_id}] key='{item.key}' reason='{item.reason}' ({item.status.value})")
|
|
181
|
+
print()
|
|
182
|
+
|
|
183
|
+
return 0
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
@_consistent_read
|
|
187
|
+
def cmd_inspect(args: argparse.Namespace) -> int:
|
|
188
|
+
"""Handle 'dandelion inspect' subcommands (Section 52)."""
|
|
189
|
+
target_dir = Path(args.path).resolve()
|
|
190
|
+
dand_dir = target_dir / ".dandelion"
|
|
191
|
+
aspect = args.aspect.lower()
|
|
192
|
+
|
|
193
|
+
if aspect == "project":
|
|
194
|
+
rep_file = dand_dir / "assimilation_report.json"
|
|
195
|
+
tech_file = dand_dir / "technology_profile.json"
|
|
196
|
+
if rep_file.exists():
|
|
197
|
+
data = json.loads(rep_file.read_text(encoding="utf-8"))
|
|
198
|
+
print(f"Project Identity: {data.get('project_name')} ({data.get('workspace_type')})")
|
|
199
|
+
print(f"Files Examined: {data.get('total_files_examined')}")
|
|
200
|
+
print(f"Major Components: {data.get('major_components_count')}")
|
|
201
|
+
print(f"Technologies: {', '.join(data.get('technologies', []))}")
|
|
202
|
+
if tech_file.exists():
|
|
203
|
+
tdata = json.loads(tech_file.read_text(encoding="utf-8"))
|
|
204
|
+
print(f"Languages: {', '.join(f'{k}:{v}' for k, v in tdata.get('languages', {}).items())}")
|
|
205
|
+
print(f"Build Tools: {', '.join(tdata.get('build_tools', []))}")
|
|
206
|
+
print(f"Frameworks: {', '.join(tdata.get('frameworks', []))}")
|
|
207
|
+
|
|
208
|
+
elif aspect == "topology":
|
|
209
|
+
from dandelion.bootstrap.domain_topology import DomainTopologyStore
|
|
210
|
+
|
|
211
|
+
committed = DomainTopologyStore(dand_dir).load_current()
|
|
212
|
+
if committed is not None:
|
|
213
|
+
tdata = committed.to_dict()
|
|
214
|
+
nodes = list(tdata["nodes"].values())
|
|
215
|
+
print(
|
|
216
|
+
f"Topology Revision: {tdata.get('revision')} "
|
|
217
|
+
f"({tdata.get('snapshot_id')})"
|
|
218
|
+
)
|
|
219
|
+
print(f"Stable Domains: {len(nodes)}\n")
|
|
220
|
+
for node in sorted(nodes, key=lambda item: (item.get("path", ""), item.get("domain_id", ""))):
|
|
221
|
+
path = node.get("path") or "<root>"
|
|
222
|
+
print(
|
|
223
|
+
f" [{node.get('lifecycle', 'OBSERVED'):12s}] "
|
|
224
|
+
f"{path} -> {node.get('domain_id')}"
|
|
225
|
+
)
|
|
226
|
+
else:
|
|
227
|
+
topo_file = dand_dir / "domain_topology.json"
|
|
228
|
+
if topo_file.exists():
|
|
229
|
+
tdata = json.loads(topo_file.read_text(encoding="utf-8"))
|
|
230
|
+
print(f"Total Partitions: {tdata.get('partitions_count')}\n")
|
|
231
|
+
for p in tdata.get("partitions", []):
|
|
232
|
+
print(f" [{p.get('structural_role', 'NODE'):15s}] {p.get('canonical_id')} (imp={p.get('importance_score')})")
|
|
233
|
+
print(f" evidence: {', '.join(p.get('evidence', []))}")
|
|
234
|
+
|
|
235
|
+
elif aspect == "unknown":
|
|
236
|
+
inv_file = dand_dir / "bootstrap_inventory.json"
|
|
237
|
+
if inv_file.exists():
|
|
238
|
+
idata = json.loads(inv_file.read_text(encoding="utf-8"))
|
|
239
|
+
unknowns = [f for f in idata.get("files", []) if "unknown" in f.get("role", "")]
|
|
240
|
+
print(f"Total Unknown Formats: {len(unknowns)} (Gracefully Indexed)\n")
|
|
241
|
+
for u in unknowns[:30]:
|
|
242
|
+
print(f" {u.get('rel_path')} [{u.get('format')}] -> {u.get('role')} (signals: {u.get('signals')})")
|
|
243
|
+
|
|
244
|
+
elif aspect == "conflicts":
|
|
245
|
+
quar_file = dand_dir / "quarantine.json"
|
|
246
|
+
if quar_file.exists():
|
|
247
|
+
quar = EpistemicQuarantine(quar_file)
|
|
248
|
+
items = quar.list_items()
|
|
249
|
+
print(f"Quarantined Conflicts: {len(items)}\n")
|
|
250
|
+
for item in items:
|
|
251
|
+
print(f" - [{item.item_id}] key='{item.key}' reason='{item.reason}'")
|
|
252
|
+
else:
|
|
253
|
+
print("No quarantine ledger found.")
|
|
254
|
+
|
|
255
|
+
elif aspect == "sources":
|
|
256
|
+
inv_file = dand_dir / "bootstrap_inventory.json"
|
|
257
|
+
if inv_file.exists():
|
|
258
|
+
idata = json.loads(inv_file.read_text(encoding="utf-8"))
|
|
259
|
+
domain_filter = args.domain or ""
|
|
260
|
+
matching = [f for f in idata.get("files", []) if domain_filter.lower() in f.get("rel_path", "").lower()]
|
|
261
|
+
print(f"Found {len(matching)} sources matching '{domain_filter}':\n")
|
|
262
|
+
for m in matching[:25]:
|
|
263
|
+
print(f" {m.get('rel_path')} -> role={m.get('role')} auth={m.get('authority')}")
|
|
264
|
+
|
|
265
|
+
return 0
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
@_consistent_read
|
|
269
|
+
def cmd_get(args: argparse.Namespace) -> int:
|
|
270
|
+
"""Handle 'dandelion get' command."""
|
|
271
|
+
target_dir = Path(args.path).resolve()
|
|
272
|
+
if _owner_backend_selected(target_dir):
|
|
273
|
+
from dandelion.memory_client import MemoryClient
|
|
274
|
+
result = MemoryClient.for_workspace(target_dir).call("get_fact", {
|
|
275
|
+
"key": args.key, "revision": args.revision,
|
|
276
|
+
})
|
|
277
|
+
if result.get("status") == "UNKNOWN":
|
|
278
|
+
print(f"Fact '{args.key}' not found."); return 1
|
|
279
|
+
print(public_egress(f"{args.key} = {result.get('value')} (rev {result.get('revision')}, source: {result.get('source')})"))
|
|
280
|
+
return 0
|
|
281
|
+
facts_file = target_dir / ".dandelion" / "facts.json"
|
|
282
|
+
|
|
283
|
+
if not facts_file.is_file():
|
|
284
|
+
if FACTS_FILE.is_file() and target_dir == Path.cwd().resolve():
|
|
285
|
+
facts_file = FACTS_FILE
|
|
286
|
+
else:
|
|
287
|
+
print(f"Error: Facts store not found at {facts_file}. Run 'dandelion bootstrap' first.")
|
|
288
|
+
return 1
|
|
289
|
+
|
|
290
|
+
kv = KVStore(path=facts_file)
|
|
291
|
+
lookup_key = args.key
|
|
292
|
+
if args.revision is not None:
|
|
293
|
+
lookup_key = f"{args.key}@rev:{args.revision}"
|
|
294
|
+
|
|
295
|
+
canonical_key = args.key.split("@")[0]
|
|
296
|
+
if not args.allow_secrets and is_sensitive_key(canonical_key):
|
|
297
|
+
print(f"{lookup_key} = [SECRET — access denied by server policy]")
|
|
298
|
+
return 0
|
|
299
|
+
|
|
300
|
+
val = kv.resolve_ref(lookup_key)
|
|
301
|
+
if val is None:
|
|
302
|
+
print(f"Fact '{lookup_key}' not found.")
|
|
303
|
+
return 1
|
|
304
|
+
|
|
305
|
+
meta = kv.get_fact_metadata(canonical_key)
|
|
306
|
+
rev_str = f" (rev {meta.get('revision')}, source: {meta.get('source')})" if meta else ""
|
|
307
|
+
print(public_egress(f"{lookup_key} = {val}{rev_str}"))
|
|
308
|
+
return 0
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
@_consistent_read
|
|
312
|
+
def cmd_recall(args: argparse.Namespace) -> int:
|
|
313
|
+
"""Handle 'dandelion recall' command."""
|
|
314
|
+
target_dir = Path(args.path).resolve()
|
|
315
|
+
if _owner_backend_selected(target_dir):
|
|
316
|
+
from dandelion.memory_client import MemoryClient
|
|
317
|
+
result = MemoryClient.for_workspace(target_dir).call("recall", {
|
|
318
|
+
"query": args.query, "domain": args.partition, "limit": args.limit,
|
|
319
|
+
})
|
|
320
|
+
if not result.get("results"):
|
|
321
|
+
print(f"No memories found matching '{args.query}'."); return 0
|
|
322
|
+
for idx, item in enumerate(result["results"], start=1):
|
|
323
|
+
print(f"[{idx}] ID: {item['memory_id'][:8]} | Partition: {item['domain']} | Source: {item.get('source','unknown')}")
|
|
324
|
+
print(public_egress(f" {item['text']}"))
|
|
325
|
+
return 0
|
|
326
|
+
dandelion_dir = target_dir / ".dandelion"
|
|
327
|
+
facts_file = dandelion_dir / "facts.json"
|
|
328
|
+
qdrant_dir = dandelion_dir / "qdrant"
|
|
329
|
+
|
|
330
|
+
if not facts_file.is_file() or not qdrant_dir.is_dir():
|
|
331
|
+
if FACTS_FILE.is_file() and QDRANT_DIR.is_dir() and target_dir == Path.cwd().resolve():
|
|
332
|
+
facts_file = FACTS_FILE
|
|
333
|
+
qdrant_dir = QDRANT_DIR
|
|
334
|
+
else:
|
|
335
|
+
print(f"Error: No Dandelion stores found at {dandelion_dir}. Run 'dandelion bootstrap' first.")
|
|
336
|
+
return 1
|
|
337
|
+
|
|
338
|
+
kv = KVStore(path=facts_file)
|
|
339
|
+
vector_type = globals().get("VectorStore") or __getattr__("VectorStore")
|
|
340
|
+
vec = vector_type(path=qdrant_dir)
|
|
341
|
+
|
|
342
|
+
try:
|
|
343
|
+
domains = None
|
|
344
|
+
if args.partition:
|
|
345
|
+
if args.partition.endswith(".*"):
|
|
346
|
+
domains = resolve_wildcard(args.partition, kv.get_domains())
|
|
347
|
+
if not domains:
|
|
348
|
+
print(f"No partitions match pattern '{args.partition}'.")
|
|
349
|
+
return 0
|
|
350
|
+
else:
|
|
351
|
+
domains = [args.partition]
|
|
352
|
+
|
|
353
|
+
results = vec.search_chunks(
|
|
354
|
+
query=args.query,
|
|
355
|
+
domains=domains,
|
|
356
|
+
limit=args.limit,
|
|
357
|
+
kv_store=kv,
|
|
358
|
+
)
|
|
359
|
+
if not results:
|
|
360
|
+
msg = f"No memories found matching '{args.query}'"
|
|
361
|
+
if args.partition:
|
|
362
|
+
msg += f" in partition '{args.partition}'"
|
|
363
|
+
print(msg + ".")
|
|
364
|
+
return 0
|
|
365
|
+
|
|
366
|
+
print(f"Recalled {len(results)} memory record(s) for query: \"{args.query}\"\n")
|
|
367
|
+
for idx, r in enumerate(results, start=1):
|
|
368
|
+
hydrated = hydrate_template(
|
|
369
|
+
text=r["template"],
|
|
370
|
+
kv_resolver=kv.resolve_ref,
|
|
371
|
+
chunk_domain=r["domain"],
|
|
372
|
+
allow_secrets=args.allow_secrets,
|
|
373
|
+
)
|
|
374
|
+
score_val = r.get("score", 0.0)
|
|
375
|
+
source_val = r.get("source", "unknown")
|
|
376
|
+
cid = r.get("id", "")
|
|
377
|
+
short_id = cid[:8] if isinstance(cid, str) else str(cid)
|
|
378
|
+
print(f"[{idx}] ID: {short_id} | Partition: {r['domain']} | Score: {score_val:.4f} | Source: {source_val}")
|
|
379
|
+
print(public_egress(f" {hydrated}"))
|
|
380
|
+
fact_refs = r.get("referenced_facts")
|
|
381
|
+
if fact_refs:
|
|
382
|
+
print(f" Fact Refs: {', '.join(fact_refs)}")
|
|
383
|
+
print()
|
|
384
|
+
return 0
|
|
385
|
+
finally:
|
|
386
|
+
vec.close()
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
def cmd_serve(args: argparse.Namespace) -> int:
|
|
390
|
+
"""Handle 'dandelion serve' command (FastMCP stdio server)."""
|
|
391
|
+
from dandelion.server import main as server_main
|
|
392
|
+
server_main()
|
|
393
|
+
return 0
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
def cmd_memory_owner(args: argparse.Namespace) -> int:
|
|
397
|
+
"""Manage the additive single-owner canonical-memory service."""
|
|
398
|
+
from dandelion.memory_client import OwnerRejected, OwnerUnavailable
|
|
399
|
+
from dandelion.memory_owner import OwnerAlreadyRunning, OwnerDescriptorError
|
|
400
|
+
|
|
401
|
+
try:
|
|
402
|
+
return _cmd_memory_owner(args)
|
|
403
|
+
except OwnerUnavailable:
|
|
404
|
+
message = ("OWNER_UNAVAILABLE: owner unreachable or request timed out. Check the workspace and "
|
|
405
|
+
"host process. A timeout does not prove that a submitted operation failed.")
|
|
406
|
+
except OwnerDescriptorError:
|
|
407
|
+
message = ("OWNER_DESCRIPTOR_INVALID: owner endpoint is missing or invalid. Check the configured "
|
|
408
|
+
"workspace and its normal owner connection; do not create a replacement database.")
|
|
409
|
+
except OwnerAlreadyRunning:
|
|
410
|
+
message = ("OWNER_ALREADY_RUNNING: this workspace is already owned. Use memory-owner status; "
|
|
411
|
+
"do not start a second owner.")
|
|
412
|
+
except OwnerRejected:
|
|
413
|
+
message = "OWNER_REJECTED: the owner rejected the request. Check authentication and operation requirements."
|
|
414
|
+
except Exception:
|
|
415
|
+
message = "Memory owner operation failed; existing database and validated snapshots are preserved."
|
|
416
|
+
print(message, file=sys.stderr)
|
|
417
|
+
return 1
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
def _cmd_memory_owner(args: argparse.Namespace) -> int:
|
|
421
|
+
from dandelion.memory_client import MemoryClient
|
|
422
|
+
workspace = Path(args.path).resolve()
|
|
423
|
+
if args.action == "status":
|
|
424
|
+
print(json.dumps(MemoryClient.for_workspace(workspace).status(), indent=2, ensure_ascii=False))
|
|
425
|
+
return 0
|
|
426
|
+
if args.action == "stop":
|
|
427
|
+
print(json.dumps(MemoryClient.for_workspace(workspace).stop(), indent=2, ensure_ascii=False))
|
|
428
|
+
return 0
|
|
429
|
+
from dandelion.canonical_memory import CanonicalMemory
|
|
430
|
+
from dandelion.memory_owner import MemoryOwner
|
|
431
|
+
if args.action == "backup":
|
|
432
|
+
if not args.output:
|
|
433
|
+
raise ValueError("Backup requires --output")
|
|
434
|
+
result = MemoryClient.for_workspace(workspace).call("owner.backup", {
|
|
435
|
+
"output": str(Path(args.output).resolve()), "timeout_seconds": 4.0,
|
|
436
|
+
})
|
|
437
|
+
print(json.dumps(result, indent=2, ensure_ascii=False))
|
|
438
|
+
return 0
|
|
439
|
+
if args.action == "restore":
|
|
440
|
+
if not args.backup or workspace.exists():
|
|
441
|
+
raise ValueError("Restore requires a backup and a new workspace")
|
|
442
|
+
source = Path(args.backup).resolve()
|
|
443
|
+
CanonicalMemory.inspect_database(source)
|
|
444
|
+
workspace.mkdir(parents=True, exist_ok=False)
|
|
445
|
+
owner = MemoryOwner(workspace, None)
|
|
446
|
+
try:
|
|
447
|
+
owner.acquire_guard()
|
|
448
|
+
result = CanonicalMemory.copy_snapshot(source, workspace / ".dandelion" / "memory.sqlite3")
|
|
449
|
+
finally:
|
|
450
|
+
owner.abort_start()
|
|
451
|
+
print(json.dumps(result, indent=2, ensure_ascii=False))
|
|
452
|
+
return 0
|
|
453
|
+
from dandelion.derived_index import CanonicalDerivedService, DerivedIndex
|
|
454
|
+
owner = MemoryOwner(workspace, None)
|
|
455
|
+
try:
|
|
456
|
+
owner.acquire_guard()
|
|
457
|
+
canonical = CanonicalMemory(workspace, lifecycle_v1_enabled=args.lifecycle_v1,
|
|
458
|
+
source_policy=args.source_policy,
|
|
459
|
+
source_content_fts5=args.source_content_fts5,
|
|
460
|
+
access_mode=args.access_mode)
|
|
461
|
+
derived = None
|
|
462
|
+
if args.profile == "dense":
|
|
463
|
+
from dandelion.embedder import Embedder
|
|
464
|
+
derived = DerivedIndex(canonical, Embedder.get())
|
|
465
|
+
owner.service = CanonicalDerivedService(canonical, derived)
|
|
466
|
+
descriptor = owner.start()
|
|
467
|
+
except Exception:
|
|
468
|
+
owner.abort_start()
|
|
469
|
+
raise
|
|
470
|
+
print(json.dumps({**descriptor.public_status(), "profile": args.profile,
|
|
471
|
+
"lexical_readiness": "READY", "dense_enabled": args.profile == "dense"},
|
|
472
|
+
indent=2, ensure_ascii=False), flush=True)
|
|
473
|
+
try:
|
|
474
|
+
while owner.is_running:
|
|
475
|
+
owner.wait_stopped(timeout=0.5)
|
|
476
|
+
except KeyboardInterrupt:
|
|
477
|
+
owner.stop()
|
|
478
|
+
return 0
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
def cmd_memory(args: argparse.Namespace) -> int:
|
|
482
|
+
"""Call canonical memory through the workspace owner (never direct SQLite)."""
|
|
483
|
+
from dandelion.memory_client import MemoryClient
|
|
484
|
+
client = MemoryClient.for_workspace(Path(args.path).resolve())
|
|
485
|
+
payload = json.loads(args.data) if args.data else {}
|
|
486
|
+
operation = args.operation.replace("-", "_")
|
|
487
|
+
if operation in {"scan_bootstrap_submit", "scan_bootstrap_status", "scan_bootstrap_wait"}:
|
|
488
|
+
if not isinstance(payload, dict):
|
|
489
|
+
raise ValueError(f"{args.operation} data must be a JSON object")
|
|
490
|
+
if operation == "scan_bootstrap_submit":
|
|
491
|
+
if set(payload) != {"source_workspace", "idempotency_key"}:
|
|
492
|
+
raise ValueError("scan-bootstrap-submit requires source_workspace and idempotency_key")
|
|
493
|
+
result = client.submit_scan_bootstrap(
|
|
494
|
+
payload["source_workspace"], payload["idempotency_key"],
|
|
495
|
+
)
|
|
496
|
+
elif operation == "scan_bootstrap_status":
|
|
497
|
+
if set(payload) != {"operation_id"}:
|
|
498
|
+
raise ValueError("scan-bootstrap-status requires operation_id")
|
|
499
|
+
result = client.scan_bootstrap_status(payload["operation_id"])
|
|
500
|
+
else:
|
|
501
|
+
if set(payload) - {"operation_id", "timeout_seconds", "poll_interval"}:
|
|
502
|
+
raise ValueError("scan-bootstrap-wait accepts operation_id, timeout_seconds, and poll_interval")
|
|
503
|
+
operation_id = payload.get("operation_id")
|
|
504
|
+
if not isinstance(operation_id, str) or not operation_id.strip():
|
|
505
|
+
raise ValueError("scan-bootstrap-wait requires a non-empty operation_id")
|
|
506
|
+
timeout = payload.get("timeout_seconds")
|
|
507
|
+
poll_interval = payload.get("poll_interval", 0.05)
|
|
508
|
+
result = client.wait_for_scan_bootstrap(
|
|
509
|
+
operation_id, timeout_seconds=timeout,
|
|
510
|
+
poll_interval=poll_interval,
|
|
511
|
+
)
|
|
512
|
+
else:
|
|
513
|
+
result = client.call(operation, payload)
|
|
514
|
+
# MemoryClient is authenticated to the local owner, which has already
|
|
515
|
+
# enforced the configured access mode and strict source-evidence boundary.
|
|
516
|
+
# A second public-egress pass here would erase trusted-local memory output.
|
|
517
|
+
print(json.dumps(result, indent=2, ensure_ascii=False))
|
|
518
|
+
return 0
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
def _memory_session_examples(workspace: Path, source_root: Path) -> list[dict[str, object]]:
|
|
522
|
+
"""Return copy/pasteable, value-free owner invocations for a workspace."""
|
|
523
|
+
prefix = [str(Path(sys.executable).resolve()), "-m", "dandelion.cli", "memory"]
|
|
524
|
+
|
|
525
|
+
def example(name: str, operation: str, payload: dict[str, object], payload_schema: dict[str, object]) -> dict[str, object]:
|
|
526
|
+
argv = [*prefix, operation.replace("_", "-"), "--path", str(workspace),
|
|
527
|
+
"--data", json.dumps(payload, ensure_ascii=False, separators=(",", ":"))]
|
|
528
|
+
# ``argv`` is the authoritative, parser-safe form. The display string
|
|
529
|
+
# deliberately quotes the absolute launcher, workspace, and JSON.
|
|
530
|
+
shell = " ".join(f'"{part}"' for part in argv)
|
|
531
|
+
return {"name": name, "operation": operation, "argv": argv, "shell": shell,
|
|
532
|
+
"working_directory": str(source_root), "payload": payload,
|
|
533
|
+
"payload_schema": payload_schema}
|
|
534
|
+
|
|
535
|
+
return [
|
|
536
|
+
example("status", "status", {}, {"type": "object", "properties": {}, "additionalProperties": False}),
|
|
537
|
+
example("get_current", "get_fact", {"key": "<fact-key>"}, {
|
|
538
|
+
"type": "object", "required": ["key"], "properties": {"key": "string"}, "additionalProperties": False}),
|
|
539
|
+
example("get_revision", "get_fact", {"key": "<fact-key>", "revision": 1}, {
|
|
540
|
+
"type": "object", "required": ["key", "revision"],
|
|
541
|
+
"properties": {"key": "string", "revision": "integer|null"}, "additionalProperties": False}),
|
|
542
|
+
example("search", "search", {"query": "<query>", "domain": "<optional-domain>", "limit": 5}, {
|
|
543
|
+
"type": "object", "required": ["query"],
|
|
544
|
+
"properties": {"query": "string", "domain": "string", "limit": "integer", "exact_key": "string"}, "additionalProperties": False}),
|
|
545
|
+
example("recall_diagnostic", "recall", {"query": "<query>", "domain": "<optional-domain>", "limit": 5}, {
|
|
546
|
+
"type": "object", "required": ["query"],
|
|
547
|
+
"properties": {"query": "string", "domain": "string", "limit": "integer"}, "additionalProperties": False}),
|
|
548
|
+
example("recover_decision", "recover", {"topic": "<exact-topic>", "intent": "decision", "limit": 5}, {
|
|
549
|
+
"type": "object", "required": ["topic"],
|
|
550
|
+
"properties": {"query": "string", "topic": "string", "intent": "decision|recommendation", "domain": "string", "limit": "integer"}, "additionalProperties": False}),
|
|
551
|
+
example("recover_recommendation", "recover", {"query": "<query>", "intent": "recommendation", "limit": 5}, {
|
|
552
|
+
"type": "object", "required": ["query", "intent"],
|
|
553
|
+
"properties": {"query": "string", "topic": "string", "intent": "decision|recommendation", "domain": "string", "limit": "integer"}, "additionalProperties": False}),
|
|
554
|
+
example("dense_recall", "dense_recall", {"query": "<query>", "domain": "<optional-domain>", "limit": 5}, {
|
|
555
|
+
"type": "object", "required": ["query"],
|
|
556
|
+
"properties": {"query": "string", "domain": "string", "limit": "integer", "allow_restricted": "boolean"}, "additionalProperties": False}),
|
|
557
|
+
]
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
def _memory_session_manifest(workspace: Path, owner_status: dict[str, object], dense_status: dict[str, object]) -> dict[str, object]:
|
|
561
|
+
"""Describe the public read API without returning canonical data."""
|
|
562
|
+
return {
|
|
563
|
+
"kind": "dandelion.memory_session",
|
|
564
|
+
"version": 1,
|
|
565
|
+
"workspace": str(workspace),
|
|
566
|
+
"status": "READY",
|
|
567
|
+
"read_only": True,
|
|
568
|
+
"default_operation": "search",
|
|
569
|
+
"owner": {
|
|
570
|
+
"available": True,
|
|
571
|
+
"authenticated": True,
|
|
572
|
+
"check": "owner.status",
|
|
573
|
+
"protocol_version": owner_status.get("version"),
|
|
574
|
+
},
|
|
575
|
+
"indexes": {
|
|
576
|
+
"lexical": {"available": True, "operation": "recall"},
|
|
577
|
+
"unified": {"available": True, "operation": "search", "default": True},
|
|
578
|
+
"dense": {
|
|
579
|
+
"operation": "dense_recall",
|
|
580
|
+
"readiness": dense_status.get("readiness"),
|
|
581
|
+
"pending": dense_status.get("pending"),
|
|
582
|
+
"failed": dense_status.get("failed"),
|
|
583
|
+
"available": dense_status.get("readiness") not in {None, "UNKNOWN", "DISABLED"},
|
|
584
|
+
"availability": "independent of lexical/current/history reads",
|
|
585
|
+
},
|
|
586
|
+
},
|
|
587
|
+
"invocation": {
|
|
588
|
+
"interpreter": str(Path(sys.executable).resolve()),
|
|
589
|
+
"module": "dandelion.cli",
|
|
590
|
+
"working_directory": str(Path(__file__).resolve().parents[1]),
|
|
591
|
+
"note": "Run argv with this working_directory so it resolves this checkout, not a stale installed launcher.",
|
|
592
|
+
},
|
|
593
|
+
"operations": _memory_session_examples(workspace, Path(__file__).resolve().parents[1]),
|
|
594
|
+
"history": {
|
|
595
|
+
"current": "get_current omits revision and resolves the current revision.",
|
|
596
|
+
"pinned": "get_revision supplies revision and resolves that immutable revision.",
|
|
597
|
+
"memory_refs": "Recall results may hydrate live refs at the current revision; pinned {{ref:key@rev:N}} refs remain pinned.",
|
|
598
|
+
},
|
|
599
|
+
"typed_memory": {
|
|
600
|
+
"operation": "recover",
|
|
601
|
+
"accepted_meaning": "ACCEPTED is a recorded producer assertion with explicit provenance, not authority or user endorsement.",
|
|
602
|
+
"scope": "Use an exact topic for canonical accepted-decision coverage. Topic-less recovery is bounded and never claims global absence.",
|
|
603
|
+
"routing": "Use recover for previously recorded proposals or decisions; use search for general project information.",
|
|
604
|
+
},
|
|
605
|
+
"source": "Read responses identify canonical provenance through source, authority, and reason fields; this manifest contains none of those records.",
|
|
606
|
+
"security": {
|
|
607
|
+
"policy": "The owner enforces the host secret policy. Client payloads cannot elevate it.",
|
|
608
|
+
"denial": "Restricted facts or memories return status DENIED with a redacted placeholder; the manifest never returns memory content or fact values.",
|
|
609
|
+
},
|
|
610
|
+
"limits": "Search is the default discovery operation. Dense readiness is reported separately: PENDING or DEGRADED dense indexing does not disable exact/current/history lookup or lexical matches.",
|
|
611
|
+
"warnings": (
|
|
612
|
+
(["Dense index readiness is unavailable; use lexical recall or retry dense discovery."]
|
|
613
|
+
if dense_status.get("readiness") == "UNKNOWN" else [])
|
|
614
|
+
),
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
def cmd_memory_session(args: argparse.Namespace) -> int:
|
|
619
|
+
"""Publish a read-only, authenticated public session manifest."""
|
|
620
|
+
from dandelion.memory_client import MemoryClient, MemoryClientError, OwnerDescriptorError
|
|
621
|
+
|
|
622
|
+
workspace = Path(args.path).resolve()
|
|
623
|
+
try:
|
|
624
|
+
# ``for_workspace`` reads an existing descriptor only; it never creates
|
|
625
|
+
# the workspace, SQLite database, owner, or derived index.
|
|
626
|
+
client = MemoryClient.for_workspace(workspace)
|
|
627
|
+
owner_status = dict(client.status())
|
|
628
|
+
except (MemoryClientError, OwnerDescriptorError):
|
|
629
|
+
print(json.dumps({
|
|
630
|
+
"kind": "dandelion.memory_session", "version": 1,
|
|
631
|
+
"workspace": str(workspace), "status": "FAILED", "read_only": True,
|
|
632
|
+
"error": {"code": "OWNER_UNAVAILABLE", "message": "An authenticated memory owner is not available."},
|
|
633
|
+
}, ensure_ascii=False))
|
|
634
|
+
return 2
|
|
635
|
+
try:
|
|
636
|
+
dense_status = dict(client.call("index_status", {}))
|
|
637
|
+
except MemoryClientError:
|
|
638
|
+
# Owner authentication succeeded, so do not conflate an unavailable
|
|
639
|
+
# dense projection with unavailable canonical/lexical reads.
|
|
640
|
+
dense_status = {"readiness": "UNKNOWN", "pending": None, "failed": None}
|
|
641
|
+
print(json.dumps(_memory_session_manifest(workspace, owner_status, dense_status), indent=2, ensure_ascii=False))
|
|
642
|
+
return 0
|
|
643
|
+
|
|
644
|
+
|
|
645
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
646
|
+
parser = argparse.ArgumentParser(
|
|
647
|
+
prog="dandelion",
|
|
648
|
+
description="Dandelion: Minimalist Federated Memory Engine with Hierarchical Routing",
|
|
649
|
+
)
|
|
650
|
+
subparsers = parser.add_subparsers(dest="command", help="Available subcommands")
|
|
651
|
+
|
|
652
|
+
# init
|
|
653
|
+
p_init = subparsers.add_parser("init", help="Initialize .dandelion configuration")
|
|
654
|
+
p_init.add_argument("path", nargs="?", default=".", help="Project directory (default: .)")
|
|
655
|
+
p_init.set_defaults(func=cmd_init)
|
|
656
|
+
|
|
657
|
+
# bootstrap
|
|
658
|
+
p_boot = subparsers.add_parser("bootstrap", help="Bootstrap memory from codebase (BOOTSTRAP-02)")
|
|
659
|
+
p_boot.add_argument("path", nargs="?", default=".", help="Project directory (default: .)")
|
|
660
|
+
p_boot.add_argument("--deep-history", action="store_true", help="Perform full Git history sweep")
|
|
661
|
+
p_boot.add_argument("--dry-run", action="store_true", help="Analyze without writing to stores")
|
|
662
|
+
p_boot.set_defaults(func=cmd_bootstrap)
|
|
663
|
+
|
|
664
|
+
# topology
|
|
665
|
+
p_top = subparsers.add_parser("topology", help="Display project hierarchical topology")
|
|
666
|
+
p_top.add_argument("path", nargs="?", default=".", help="Project directory (default: .)")
|
|
667
|
+
p_top.set_defaults(func=cmd_topology)
|
|
668
|
+
|
|
669
|
+
# inspect
|
|
670
|
+
p_insp = subparsers.add_parser("inspect", help="Introspect project structure, unknown formats, and conflicts")
|
|
671
|
+
p_insp.add_argument("aspect", choices=["project", "topology", "unknown", "conflicts", "sources"], help="Aspect to inspect")
|
|
672
|
+
p_insp.add_argument("domain", nargs="?", default="", help="Optional domain or path filter for sources")
|
|
673
|
+
p_insp.add_argument("--path", "-p", default=".", help="Project directory (default: .)")
|
|
674
|
+
p_insp.set_defaults(func=cmd_inspect)
|
|
675
|
+
|
|
676
|
+
# get
|
|
677
|
+
p_get = subparsers.add_parser("get", help="Get exact fact value by key")
|
|
678
|
+
p_get.add_argument("key", help="Fact key (e.g. backend.db.port)")
|
|
679
|
+
p_get.add_argument("--revision", "-r", type=int, default=None, help="Historical revision number")
|
|
680
|
+
p_get.add_argument("--path", "-p", default=".", help="Project directory (default: .)")
|
|
681
|
+
p_get.add_argument(
|
|
682
|
+
"--allow-secrets", action="store_true",
|
|
683
|
+
help=("Legacy compatibility flag for internal hydration only; public stdout remains "
|
|
684
|
+
"credential-redacted and never reveals raw secret values"),
|
|
685
|
+
)
|
|
686
|
+
p_get.set_defaults(func=cmd_get)
|
|
687
|
+
|
|
688
|
+
# recall
|
|
689
|
+
p_recall = subparsers.add_parser("recall", help="Recall episodic memories with late-binding hydration")
|
|
690
|
+
p_recall.add_argument("query", help="Search query (natural language, code symbol, error code)")
|
|
691
|
+
p_recall.add_argument("--partition", "--domain", "-d", default="", help="Partition / domain scope filter")
|
|
692
|
+
p_recall.add_argument("--limit", "-k", type=int, default=5, help="Maximum results to return (default: 5)")
|
|
693
|
+
p_recall.add_argument("--path", "-p", default=".", help="Project directory (default: .)")
|
|
694
|
+
p_recall.add_argument(
|
|
695
|
+
"--allow-secrets", action="store_true",
|
|
696
|
+
help=("Legacy compatibility flag for internal hydration only; public stdout remains "
|
|
697
|
+
"credential-redacted and never reveals raw secret values"),
|
|
698
|
+
)
|
|
699
|
+
p_recall.set_defaults(func=cmd_recall)
|
|
700
|
+
|
|
701
|
+
# serve
|
|
702
|
+
p_serve = subparsers.add_parser("serve", help="Run MCP server over stdio")
|
|
703
|
+
p_serve.set_defaults(func=cmd_serve)
|
|
704
|
+
|
|
705
|
+
# Additive single-owner architecture slice. Existing commands keep their
|
|
706
|
+
# legacy backend until the documented migration/cutover is completed.
|
|
707
|
+
p_owner = subparsers.add_parser("memory-owner", help="Manage canonical memory owner")
|
|
708
|
+
p_owner.add_argument("action", choices=["start", "status", "stop", "backup", "restore"])
|
|
709
|
+
p_owner.add_argument("--path", "-p", default=".")
|
|
710
|
+
p_owner.add_argument("--lifecycle-v1", action="store_true",
|
|
711
|
+
help="Enable the explicit lifecycle-v1 mutation capability for this owner")
|
|
712
|
+
p_owner.add_argument("--source-policy", choices=["PUBLIC_RANGES_V1"],
|
|
713
|
+
help="Opt in to public source ranges in a new isolated owner")
|
|
714
|
+
p_owner.add_argument("--source-content-fts5", action="store_true",
|
|
715
|
+
help="Opt in to the current-source FTS5 projection during explicit bootstrap refresh")
|
|
716
|
+
p_owner.add_argument("--profile", choices=["dense", "lexical"], default="dense",
|
|
717
|
+
help="Opt-in lexical startup disables dense/model runtime; default retains dense compatibility")
|
|
718
|
+
p_owner.add_argument("--access-mode", choices=["strict", "trusted-local"], default="strict",
|
|
719
|
+
help="Host-selected canonical-memory confidentiality policy; source grants are unchanged")
|
|
720
|
+
p_owner.add_argument("--output", help="New SQLite snapshot file for authenticated backup")
|
|
721
|
+
p_owner.add_argument("--backup", help="Validated SQLite snapshot for restore into a new workspace")
|
|
722
|
+
p_owner.set_defaults(func=cmd_memory_owner)
|
|
723
|
+
|
|
724
|
+
p_memory = subparsers.add_parser("memory", help="Call canonical owner memory API")
|
|
725
|
+
p_memory.add_argument("operation", choices=[
|
|
726
|
+
"set-fact", "get-fact", "remember", "recall", "search", "put-claim",
|
|
727
|
+
"query-claim", "rebuild-index", "status", "import-legacy",
|
|
728
|
+
"migrate-legacy", "activate-backend", "backend-status", "delete-fact", "forget",
|
|
729
|
+
"scan-bootstrap", "scan-bootstrap-submit", "scan-bootstrap-status", "scan-bootstrap-wait",
|
|
730
|
+
"consume-dense", "rebuild-dense", "dense-recall", "index-status",
|
|
731
|
+
"recover", "transition-semantics", "source-content-search",
|
|
732
|
+
"correct-fact", "supersede-decision", "revoke-memory", "soft-forget",
|
|
733
|
+
"restore-fact", "lifecycle-history", "withdraw-source-grant",
|
|
734
|
+
"domain-map", "list-memories", "define-domain",
|
|
735
|
+
])
|
|
736
|
+
p_memory.add_argument("--data", default="{}", help="JSON operation payload")
|
|
737
|
+
p_memory.add_argument("--path", "-p", default=".")
|
|
738
|
+
p_memory.set_defaults(func=cmd_memory)
|
|
739
|
+
|
|
740
|
+
p_session = subparsers.add_parser(
|
|
741
|
+
"memory-session",
|
|
742
|
+
help="Print a read-only authenticated canonical-memory session manifest",
|
|
743
|
+
)
|
|
744
|
+
p_session.add_argument("--path", "-p", required=True, help="Existing workspace with a running memory owner")
|
|
745
|
+
p_session.set_defaults(func=cmd_memory_session)
|
|
746
|
+
|
|
747
|
+
return parser
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+
def main() -> int:
|
|
751
|
+
_configure_stdout_utf8()
|
|
752
|
+
parser = build_parser()
|
|
753
|
+
if len(sys.argv) == 1:
|
|
754
|
+
from dandelion.server import main as server_main
|
|
755
|
+
server_main()
|
|
756
|
+
return 0
|
|
757
|
+
|
|
758
|
+
args = parser.parse_args()
|
|
759
|
+
if hasattr(args, "func"):
|
|
760
|
+
return args.func(args)
|
|
761
|
+
else:
|
|
762
|
+
parser.print_help()
|
|
763
|
+
return 0
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
if __name__ == "__main__":
|
|
767
|
+
sys.exit(main())
|