feat(filesystem): add PageIndex FileSystem and PIFS CLI#302
Conversation
274af6c to
d7d3cb8
Compare
Remove the synchronous=OFF pragma from PIFS catalog inserts so SQLite remains the durable source of truth.
Route default semantic search to the summary projection when summary is the only populated semantic channel.
Only use the fresh event loop fallback for missing running-loop detection, so RuntimeError from a threaded agent run is not retried.
Return nested PageIndex structure JSON from cat --structure and keep content reads page-based only. Remove the cat --node command surface, related limits, prompts, and structure-text fallback.
* feat(filesystem): add pifs semantic folder build * fix(filesystem): preserve semantic folder command paths * fix(filesystem): retry semantic folder planning * fix(filesystem): balance semantic folder planner guidance
KylinMountain
left a comment
There was a problem hiding this comment.
Automated deep-review summary (recall-oriented)
Machine-assisted review (multi-agent finder + adversarial verification passes) of the PIFS change, optimized for recall of real defects. Each inline finding was independently verified against the PR-head code. Severity tags: High = breaks normal usage / crashes / silent wrong results; Med = real bug with a narrower trigger.
Positioning question first (see the requirements.txt comment)
PIFS introduces sqlite-vec + an OpenAI embedding pipeline, and pifs browse performs vector similarity search, which sits in tension with the README's "Vectorless / No Vector DB" positioning (L14 / L16 / L65 / L67). Flagging for an explicit product + docs decision, not as a code bug.
Highest-impact correctness issues (inlined below)
- Malformed command (
find /docs --where) → uncaughtIndexErrorcrashes the agent turn / CLI. - Read-only commands (
ls/cat/find...) require an embedding key once content is indexed. - Stopword-only query (
--name "the") silently returns[]. - One ambiguous title aborts the whole
browse. - Metadata filters: numeric
$eqint/float mismatch,$gt/$ltexcludes text-stored numerics, large-int float precision loss — three distinct holes in the same area.
Investigated but NOT flagged (verified safe)
SQLiteSession thread / shared-history concerns (SDK uses check_same_thread=False + per-instance in-memory DB); decode_vector dimension (index-level search/upsert already validate); __init__.py only swallows ModuleNotFoundError for the 4 optional deps with a re-raise guard; add_file readiness guards not reused on register (intentional deferred-metadata design); the folder-vs-file depth -1 asymmetry (actually correct — a file is one tree level below its folder).
Lower-severity (not inlined, for completeness)
cat --range past EOF → nonsensical start>end empty result; the pagination "next" command can point past document EOF; SQLiteVecSemanticIndex.reset() uses auto-committing executescript with no rollback (recoverable — rebuildable index); with self.connect() commits but never closes the connection (bounded by CPython GC); entity/relation channels are declared & plumbed but never populated (dormant — hidden from capabilities & rejected up front, only over-advertised in static help). The default-model change to gpt-5.4 looks intentional (retrieve_model was already gpt-5.4).
There are also several cleanup/DRY opportunities (OpenAI-client construction duplicated 3x; normalize_path / JSON-coercion / textwrap.shorten reimplemented; MetadataGenerator lazy-init copy-pasted 3x; per-file LLM/embedding calls that could batch) — happy to file separately if useful.
Generated with assistance; treat as input, not gospel — verify before acting.
* cleanup(pifs): align bashlike command surface * fix(pifs): finish core alignment cleanup * chore(pifs): keep alignment docs local * cleanup(pifs): simplify summary projection surface * chore(pifs): keep local uv files out of repo * fix(pifs): return cli error status for failed commands
* refactor(pifs): simplify metadata handling * fix(pifs): keep summary out of metadata search
* feat(filesystem): add metadata scope paths Add one shared PIFS query-scope resolver for physical folders plus @field/value metadata suffixes. Wire tree, browse, and stat through it with metadata axis discovery, value pagination, semantic scope errors, and agent guidance updates. * fix(filesystem): preserve scoped child paths Keep metadata-filtered tree child paths copyable by reattaching the active metadata suffix to emitted folder nodes, and resolve query scope before folder validation in browse_semantic_files. * fix(filesystem): recurse metadata scope in core browse Make browse_semantic_files treat metadata-scoped paths as recursive even when recursive=False, matching the command wrapper, and cover the descendant case in the direct core test. * fix(filesystem): prefer in-scope browse membership Make browse_semantic_files choose the physical membership under query_scope.folder_path for metadata-scoped direct calls, and cover the dual-membership regression in the scope-path tests.
027382c to
9a57804
Compare
Read PIFS embedding model, dimensions, provider, and timeout from the persisted PIFS config when constructing CLI workspaces. Also print ask final output when streaming tool events.
* fix(pifs): load embedding runtime config Read embedding base URL and API key from PIFS config and pass them directly through the filesystem to the embedding client, avoiding PIFS_* shell exports or env bridging. * fix(pifs): require direct embedding config * fix(pifs): keep config file override
* fix(filesystem): round-trip scope-qualified file locators * chore(filesystem): keep local docs out of PR * fix(filesystem): stabilize scoped file locator lookup * fix(filesystem): encode scoped file locator leaves * fix(filesystem): avoid scoped locator suffix collisions
* refactor(filesystem): simplify PIFS core surface Align the CLI, public Python API, SQLite schemas, and summary projection with the locally approved PR VectifyAI#302 simplification spec. Add fail-first behavior coverage and real migration compatibility fixtures. * fix(filesystem): enforce exact PIFS schema validation Fail closed on pseudo-v2 catalog and projection databases, validate projection topology before any workspace mutation, and keep migration subprocess coverage outside the PageIndex test suite. * fix(filesystem): close PIFS migration validation gaps Require an exact catalog whenever projection databases exist, validate canonical vec0 and persisted embedding identities, and align the external migration's staged and idempotent checks with the runtime schema contract. * fix(filesystem): validate workspace consistency Fail closed before mutating an existing catalog and reject projection rows that do not reference active catalog files. Validate the canonical root and cross-database references at workspace open. Refs #47 * fix(filesystem): reject broken projection symlinks Treat existing symlink entries as projection paths even when their targets are missing. Share the same presence rule between core preflight and topology validation so damaged projections fail closed without workspace mutation. Refs #47 * fix(filesystem): preserve actionable file locators Derive setmeta output from the updated document instead of echoing its input target. Reuse the tree scope collision mapping for physical browse and stable locators so duplicate display names remain ranked and resolvable. Refs #47 * fix(filesystem): complete projections for registrations Open or create the Summary Projection for Python registrations, require ready status before returning, and roll back fresh batches when projection completion fails. Clean partial fresh projection databases when schema creation aborts. * fix(filesystem): restore registration rollback baseline Track only folders, metadata fields, and embedding cache keys introduced by a failed registration batch, then remove them without disturbing preexisting workspace state. Generalize Summary Projection lifecycle readiness messages for add and registration. * fix(filesystem): restore PageIndex registration artifacts Capture PageIndex document IDs before registration preparation and remove only IDs introduced by a failed batch. Prepare records inside the rollback boundary so PageIndex after-write failures also restore the logical workspace baseline. * fix(filesystem): preserve registration rollback state Validate copied caller metadata before PageIndex and artifact preparation. Capture exact registration-owned artifact baselines so prepare-stage failures restore existing bytes and remove only newly created paths. * fix(filesystem): preflight registration mutations Validate every batch metadata payload before PageIndex work begins. Reuse one canonical raw-artifact policy for both success-path writes and rollback baseline capture. * fix(filesystem): require complete workspace projection Validate active catalog and Summary Projection references in both directions. Existing catalogs with active files now fail closed when the projection pair is absent, while fresh and deleted-only catalog listing remains lazy. * fix(filesystem): close PIFS consistency gaps Restore the canonical metadata-axis paths, load embedding credentials from the configured precedence, and validate projection rows on open. Make add and registration failures restore catalog, projection, cache, PageIndex, and owned artifact state exactly, including updates to existing records. Refs #47 * fix(filesystem): encode metadata dot segments Percent-encode dot-only metadata values so tree locators survive path normalization and remain actionable through tree, browse, and stat. Refs #47
Summary
This PR adds PageIndex FileSystem (PIFS): a filesystem-like interaction system for agents working inside a PageIndex workspace, plus a
pifsCLI and anask/chatloop built on the same command surface.The core purpose is to help an agent quickly locate the right file in a workspace, then combine that filesystem context with PageIndex structure, metadata, and projection indexes to retrieve precise file evidence.
Goal
PIFS gives agents a stable filesystem-like interface to PageIndex workspaces:
browseis part of the file-location step. It ranks file candidates within a folder scope when folder names and exact filters are not enough. Evidence still comes from boundedcat,grep, and PageIndex structural reads.What Changed
pifs, a shell-style CLI for workspace navigation, file discovery, metadata filtering, source reads, imports, and agent execution.pifs addfor atomic local imports into workspace-owned artifacts.pifs askandpifs chat, where the agent uses the same read-only filesystem commands available to users.pifs semantic-folder build [source_scope]materializes a generated<source_scope>/semantictree from canonicalizeddomain/topicmetadata.grep -R, path ambiguity, projection dimension mismatches, atomic import cleanup, and semantic-folder rebuild safety.Command Surface
--workspace,--env-file,--jsonpifs set workspace <path>pifs ls,pifs tree,pifs find,pifs statpifs browse [-R] <folder> "<query>" [--space summary|entity|relation] [--where JSON] [--page N]pifs cat <path> --structure|--page|--range|--all,pifs grep [-R] <pattern> <path>pifs add <physical_path> <virtual_path>,pifs semantic-folder build [source_scope]pifs ask "<question>",pifs chatThe agent command surface intentionally exposes only read/navigation commands:
ls,tree,find,browse,grep,cat, andstat. It can use an existing semantic folder like any other tree, but it cannot build one.Key Files
pageindex/filesystem/core.py: high-level PIFS API, registration flow, metadata generation, projection wiring, semantic-folder build orchestration, and browse behavior.pageindex/filesystem/store.py: SQLite workspace catalog for folders, files, metadata, generated memberships, and PageIndex/projection state.pageindex/filesystem/commands.py: command parser, executor, shell rendering, capabilities, and guardrail messages.pageindex/filesystem/agent.py:ask/chatpolicy and streaming loop over the PIFS command surface.pageindex/filesystem/semantic_folder.py: Semantic Folder planner contract, OpenAI planner, plan schema, and validation rules.pageindex/filesystem/semantic_projection.pyandsemantic_index.py: summary projection indexing and vector search adapter used bybrowse.pageindex/filesystem/metadata.pyandmetadata_generation.py: metadata schema, policy, status, and generated metadata helpers.pageindex/filesystem/cli.pyandpifs: CLI entrypoints.examples/pifs_demo.py: local end-to-end demo over example documents.Verification
uv run pytest tests/test_filesystem_store.py tests/test_import_surface.py tests/test_metadata_generation.py tests/test_pageindex_filesystem_scope.py tests/test_pageindex_structural_read.py tests/test_pifs_add_command.py tests/test_pifs_agent_stream.py tests/test_pifs_cli.py tests/test_pifs_find_maxdepth.py tests/test_pifs_like_escape.py tests/test_pifs_path_resolution.py tests/test_pifs_register_side_effects.py tests/test_pifs_semantic_folder.py tests/test_semantic_index.py/SEC_Filings_LTM/semanticbuilt astopic/domainwith 82 files, 82 memberships, and 0 skipped files./33capital/semanticbuilt astopic/domainwith 18 files, 18 memberships, and 0 skipped files.