fix(acms): keep context add output compatible
This commit is contained in:
committed by
Forgejo
parent
980ec56b54
commit
34c24f48ad
@@ -14,7 +14,6 @@ from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
from collections.abc import Callable, Generator, Iterator
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime
|
||||
from enum import StrEnum
|
||||
from fnmatch import fnmatch
|
||||
@@ -22,7 +21,7 @@ from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import structlog
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import BaseModel, Field, model_validator
|
||||
|
||||
logger = structlog.get_logger(__name__)
|
||||
|
||||
@@ -449,8 +448,7 @@ DEFAULT_IGNORE_PATTERNS: frozenset[str] = frozenset(
|
||||
DEFAULT_CHUNK_SIZE: int = 50
|
||||
|
||||
|
||||
@dataclass
|
||||
class AcmsIndexEntry:
|
||||
class AcmsIndexEntry(BaseModel):
|
||||
"""A single entry in the ACMS index.
|
||||
|
||||
Represents a file that has been indexed into the ACMS system with
|
||||
@@ -471,17 +469,19 @@ class AcmsIndexEntry:
|
||||
content: str
|
||||
content_hash: str
|
||||
size_bytes: int
|
||||
tags: list[str] = field(default_factory=list)
|
||||
tags: list[str] = Field(default_factory=list)
|
||||
policy: str | None = None
|
||||
metadata: dict[str, Any] = field(default_factory=dict)
|
||||
metadata: dict[str, Any] = Field(default_factory=dict)
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
@model_validator(mode="after")
|
||||
def _validate_entry(self) -> AcmsIndexEntry:
|
||||
if not self.path.is_absolute():
|
||||
raise ValueError(f"AcmsIndexEntry.path must be absolute, got {self.path!r}")
|
||||
if self.size_bytes < 0:
|
||||
raise ValueError(
|
||||
f"AcmsIndexEntry.size_bytes must be non-negative, got {self.size_bytes}"
|
||||
)
|
||||
return self
|
||||
|
||||
|
||||
class ChunkedFileTraverser:
|
||||
|
||||
@@ -273,9 +273,9 @@ def context_add(
|
||||
typer.Option("--format", help="Output format: table or json"),
|
||||
] = OutputFormat.TABLE.value,
|
||||
) -> None:
|
||||
"""Add files or directories to the ACMS index.
|
||||
"""Add files or directories to the current plan's context.
|
||||
|
||||
Indexes files into the ACMS context store so that the AI can retrieve
|
||||
Indexes files into the ACMS index so that the AI can retrieve
|
||||
relevant context during plan execution. Uses ``ChunkedFileTraverser``
|
||||
for directory traversal with chunked progress output.
|
||||
|
||||
@@ -313,6 +313,7 @@ def context_add(
|
||||
|
||||
# Build progress callback for large directory indexing
|
||||
_progress_state: dict[str, int] = {"last_reported": 0}
|
||||
show_progress = output_format != "json"
|
||||
|
||||
def _on_progress(done: int, total: int) -> None:
|
||||
console.print(
|
||||
@@ -323,7 +324,7 @@ def context_add(
|
||||
|
||||
# Create traverser with tags, policy, and progress callback
|
||||
traverser = ChunkedFileTraverser(
|
||||
on_progress=_on_progress,
|
||||
on_progress=_on_progress if show_progress else None,
|
||||
tags=list(tag),
|
||||
policy=policy,
|
||||
)
|
||||
@@ -348,7 +349,8 @@ def context_add(
|
||||
# Consume traverser to trigger progress callbacks
|
||||
list(traverser.traverse(path, recursive=recursive))
|
||||
# Clear progress line before final summary
|
||||
console.print(" " * 60, end="\r")
|
||||
if show_progress:
|
||||
console.print(" " * 60, end="\r")
|
||||
else:
|
||||
# Single file - traverser validates and attaches metadata
|
||||
list(traverser.traverse(path, recursive=False))
|
||||
|
||||
Reference in New Issue
Block a user