|
| bool | is_runtime_path (str|Path path) |
| list[Finding] | check_source (str|Path path, str text) |
| tuple[bool, str] | check_prompt_invariants (str|Path path, str text) |
| Iterator[Path] | iter_runtime_paths (Path root) |
| list[Finding] | check_paths (Iterable[Path] paths, *, Path root) |
| str | _normalize_repo_path (str|Path path) |
| tuple[str,...] | _path_parts (str|Path path) |
| ast.Module|None | _parse_source (str text) |
| Finding | _finding (str rule_id, str path, int line, int col, str message) |
| list[Finding] | _check_raw_tool_schema_dump (str path, ast.Module tree) |
| Iterator[ast.AST] | _iter_scopes (ast.Module tree) |
| Iterator[ast.AST] | _iter_scope_nodes (ast.AST scope) |
| Iterator[ast.AST] | _iter_scope_child_nodes (ast.AST node) |
| set[str] | _tool_schema_aliases (list[ast.AST] nodes) |
| list[str] | _assignment_target_names (ast.AST node) |
| str|None | _assignment_value_name (ast.AST node) |
| bool | _is_json_dumps (ast.AST func) |
| list[Finding] | _check_model_setter_chokepoint (str path, ast.Module tree) |
| bool | _is_model_write_target (ast.AST target) |
| list[Finding] | _check_literal_mode_branch (str path, ast.Module tree) |
| bool | _compare_has_mode_literal (ast.Compare node) |
| bool | _is_mode_expr (ast.AST node) |
| bool | _is_mode_literal (ast.AST node) |
| list[Finding] | _check_retired_composition_symbols (str path, str text, ast.Module|None tree) |
| set[tuple[int, int]] | _allowed_default_system_positions (str path, ast.Module|None tree) |
| list[Finding] | _check_cache_ctx_fields_distinct (str path, ast.Module tree) |
| bool | _is_show_turn_summary_call (ast.Call node) |
Purpose
-------
OC Chat prompt-invariant structural rules, lifted into the OCT linter from
``oc_chat/invariants/prompt_invariant_rules.py`` (Plan 140) at the Plan 151
monorepo migration. Provides local structural enforcement for the Plan 135
prompt invariants. The module exposes portable rule metadata, runtime path
scoping, and source checkers that the OCT strict profile hosts as the
``prompt_invariants`` rule (replacing the OC Chat pytest wrapper).
Responsibilities
----------------
- Define rule metadata and agent-legible remediation text.
- Keep runtime path scope centralized and repository-relative (scoped to
the OC Chat runtime source tree; a no-op for every other project).
- Check a single source string or a set of filesystem paths for invariant
violations.
- Keep detector logic independent of OC Chat runtime imports.
Diagnostics
-----------
Domain: OCT-LINTER
Levels:
L2 - lifecycle events
L3 - semantic details
L4 - deep tracing
Contracts
---------
- Public checkers accept repository-relative paths for matching.
- Absolute filesystem paths are normalized only through ``check_paths`` with
an explicit root.
- Detectors must not edit source or depend on live OC Chat runtime objects.
- Findings include remediation text from the rule registry.
Dependencies
------------
- ast (parses the source and walks it for the structural detectors)
- collections.abc (Iterable, Iterator, Mapping - type hints for paths and the rule table)
- dataclasses (dataclass - the frozen RuleMetadata and Finding records)
- io (StringIO - feeds the source text to tokenize)
- pathlib (Path - filesystem paths for the runtime scope walk)
- tokenize (NAME tokens for the retired composition symbol check)
- types (MappingProxyType - the read-only RULES table)
- oct.core.diagnostics (structured debug logging via _dbg)
| tuple[bool, str] oct.linter.prompt_invariant_rules.check_prompt_invariants |
( |
str | Path | path, |
|
|
str | text ) |
OCT linter adapter: collapse :func:`check_source` findings to the
``(passed, message)`` contract the per-file linter dispatch expects.
Returns ``(True, "")`` when the source is clean or out of the OC Chat
runtime scope (a no-op for every non-OC-Chat project), else
``(False, "<one line per finding>")`` naming each violated rule with its
location and remediation-bearing message.
Definition at line 202 of file prompt_invariant_rules.py.