diff --git a/README.md b/README.md index 8008017..154c8ad 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ > **Gitea Commit & Release Telemetry (`v2.17.1` • Namespace `urn:io:hyperstitionstud`)** > - **Repository Role & Public Route:** Shared PEP 420 Python core library (`hyperstitionstud_io.*`), MCP/REST server, `/quant/`, `/learn/`, `/engineering/`, `/math/`, & `/donate/` webroots → [`https://hyperstitionstud.io/`](https://hyperstitionstud.io/) -> - **Latest Commit Scope (`hyperstitionstudio-core`):** Synchronized v2.17.1 release state across 9 tracked module/artifact surface(s) -> - **Touched Files / Surfaces:** `site/quant/daily-brief-data.js`, `site/quant/daily-brief-latest.json`, `site/quant/daily-brief-state.json`, `site/quant/financial-aq-harvest-latest.json`, `site/quant/quant-timeseries-data.js`, `site/quant/quant-timeseries.json`, `site/quant/real-macro-indicators-data.js`, `site/quant/real-macro-indicators.json` (+1 more) +> - **Latest Commit Scope (`hyperstitionstudio-core`):** Synchronized v2.17.1 release state across 3 tracked module/artifact surface(s) +> - **Touched Files / Surfaces:** `docs/PLAN-SPECIFICATION-AND-GOVERNANCE-STANDARD.md`, `src/hyperstitionstud_io/ci/plan_validator.py`, `tests/test_core_suite.py` > - **Live Verified Ecosystem Metrics (`v2.17.1`):** `6` Repositories • `17` CLI Entrypoints • `20` MCP/REST Tools • `14` URN Resources • `63` Verified Web Routes • `388` KG Nodes / `1,282` Edges • `282` Glossary Entries • `4,943` Offline CMUdict Phonetics • `0` Synthetic Data diff --git a/docs/PLAN-SPECIFICATION-AND-GOVERNANCE-STANDARD.md b/docs/PLAN-SPECIFICATION-AND-GOVERNANCE-STANDARD.md new file mode 100644 index 0000000..8d788e7 --- /dev/null +++ b/docs/PLAN-SPECIFICATION-AND-GOVERNANCE-STANDARD.md @@ -0,0 +1,136 @@ +# Global Plan Specification, Operational Governance & Flexibility Standard + +**Document ID:** `PLAN-SPECIFICATION-AND-GOVERNANCE-STANDARD` +**Plan Reference:** `PLAN-QUANT-PRE-MARKET-OPEN-DAILY-BRIEF-AND-REGIME-CADENCE` (`Plan #72`) +**Scope:** Architectural planning, technical project management, release lifecycle governance, and operational execution across all 6 `hyperstitionstud.io` repositories. + +--- + +## 1. Purpose & Foundational Invariants + +This standard formalizes the operational and architectural planning methodology across the `hyperstitionstud.io` ecosystem to ensure that all project management deliverables are legible, understandable, and comprehensively sound. + +### Core Invariants +1. **Strict Planning vs. Implementation Boundary:** When asked to plan, the deliverable is strictly the architectural planning artifact (`.md` and compiled Dark-Mode ReportLab `.pdf` under `docs/plans/active/` or `docs/plans/piecewise/`, plus `references/roadmap-plan-ledger.md`), never unverified production code, partial stubs, or uncommitted working tree mutations. +2. **First-Resort Infrastructure Audit:** Existing automation infrastructure (systemd timers, cron rules, collector modules, cache tables) must be evaluated and prioritized before proposing net-new services or files. Creating new services or cron files is strictly a last resort. +3. **Comprehensive Lifecycle Scope:** Every plan must address end-to-end downstream impacts: data pipeline integrity, state archiving, single-layer (1x) compression, git repository commit cadence, and deployment script readiness (`DEPLOY-GATE-D01.MIRROR_PARITY` through `DEPLOY-GATE-D08.PRE_COMMIT_STAGE`). +4. **Disambiguated Prose & Comments:** All shorthand references in prose and comments must comply with `.` (e.g., `PANEL-P06.DAILY_BRIEF`, `REGIME-R01.BULL_RISK_ON`), while executable code remains globally exempt. +5. **Dual-Artifact Delivery:** Every active or piecewise plan is authored as version-controlled Markdown and immediately compiled to an offline-accessible Dark-Mode PDF via `hs-pdf-build`. + +--- + +## 2. Three-Tier Flexibility Protocol ("Strict by Default, Flexible on Demand") + +To provide institutional rigor without creating bureaucratic bottlenecks during rapid prototyping or ad-hoc analysis, planning follows a 3-tier flexibility protocol: + +``` +Planning Tier Selection Model ++----------------------------------------------------------------------------------------------------+ +| Tier 1: Standard Production Architectural Plan [DEFAULT] | +| Trigger: "plan to ...", "architect ...", or standard feature/release requests | +| Scope: Full 8-section specification, Dark-Mode PDF, ledger entry, VPS audit, gates, rollout | +| Target: docs/plans/active/PLAN-.{md,pdf} or docs/plans/piecewise/PLAN-.{md,pdf} | ++----------------------------------------------------------------------------------------------------+ + | + (If explicitly requested) + v ++----------------------------------------------------------------------------------------------------+ +| Tier 2: Lightweight Tactical Memo [EXPLICIT OVERRIDE] | +| Trigger: "lightweight plan", "brief plan", "memo: ...", "draft outline only" | +| Scope: Focused 1–2 page technical delta, core trade-offs, and verification commands | +| Skips: Full VPS infrastructure audit, compression analysis, PDF compilation (unless requested) | +| Target: docs/plans/active/PLAN-.md or inline CLI delivery | ++----------------------------------------------------------------------------------------------------+ + | + (If explicitly requested) + v ++----------------------------------------------------------------------------------------------------+ +| Tier 3: Exploratory Scratchpad / Spike [EXPLICIT OVERRIDE] | +| Trigger: "spike:", "scratchpad:", "throwaway spike:", "ad-hoc exploration:" | +| Scope: Unformatted notes, quick spikes, throwaway experiment scripts | +| Invariants: Written strictly to /workspace/untracked/; 0 ledger entries; 0 git commits | ++----------------------------------------------------------------------------------------------------+ +``` + +### Protocol Rules +- **Default Behavior:** The agent always operates at **Tier 1** unless an explicit prompt marker matches Tier 2 or Tier 3. +- **Override Handling:** When an override is requested, the agent acknowledges the lighter tier in a single line (e.g., `[Tier 2 Lightweight Memo requested; skipping PDF compilation and VPS scheduling audit]`) and proceeds immediately with the focused delta. + +--- + +## 3. Mandatory Sections for Tier 1 Production Architectural Plans + +Tier 1 Production Plans must contain the following standard sections: + +### 1. Document Metadata & Header +- Document ID: `PLAN-` +- Status: `ACTIVE (docs/plans/active/)` or `PIECEWISE (docs/plans/piecewise/)` +- Target Ecosystem Version: `vX.Y.Z` (with baseline) +- Target Repositories: Specific repository slugs +- Target Surfaces: Affected web routes, CLI tools, or background timers +- Web Route: Canonical public HTTPS URL for the compiled companion PDF +- Author & Date + +### 2. Operational Objective & Motivation +- Plain-statement summary of the deliverable. +- Domain motivation and measurable delta (e.g., information asymmetry advantage, memory reduction, latency bounds). + +### 3. Existing Infrastructure Audit & Scheduling Hierarchy +- Exhaustive audit of all existing automation surfaces (timers, cron, modules). +- Explicit 3-stage candidate hierarchy: + - **Strategy A (First Resort):** Maximally reuses existing units (e.g., multi-calendar systemd timer). + - **Strategy B (Second Resort):** Reuses existing files (e.g., cron multiplexing). + - **Strategy C (Strict Last Resort):** Dedicated net-new services/files, evaluated only if A and B are blocked. + +### 4. Data Pipeline Integrity & Transactional Rollback Safety +- End-to-end data flow: Harvesters -> Compilers -> Verification -> RAM Hydration -> Push. +- Zero-synthetic-data compliance (`PLAN-GATE-G01.EXTANT_DATA`). +- Transactional rollback on verification failure (`git checkout -- .` without touching tmpfs). + +### 5. Archiving & Historical Ledger Evolution +- Ledger format, storage path, and schema definition. +- Deduplication semantics and session-window discrimination (`session_window`). +- Retention window capacity and quiescent SQLite compaction (`sqlite_meta.py --compress-archive`). + +### 6. Compression Standards & Optimization Guarantees +- Single-Layer (1x) Compression Invariant (`PLAN-SINGLE-LAYER-COMPRESSION-ENFORCEMENT-AND-MULTI-COMPRESSED-FILE-REMEDIATION`). +- Webroot pre-compression (`.gz` via `gzip -9` and `.br` via `brotli -q 11`). +- Server-side bundle size caps (`--max-bundle-kb 256`). + +### 7. Git Repository Commit Cadence & Telemetry Reconciliation +- Automated commit frequency and commit message templates (`chore(telemetry): ...`). +- Gating: commits occur strictly when `git diff --cached` detects substantive changes. +- Lossless telemetry reconciliation (`DEPLOY-GATE-D04.LOSSLESS_TELEMETRY` via `--snapshot-telemetry` and `--reconcile-telemetry`). + +### 8. Stepwise Verification Gates & Acceptance Criteria +- Tabulated binary verification gates with explicit command-line invocations. + +### 9. Implementation Rollout Sequence +- Phased, non-breaking rollout steps. + +--- + +## 4. 5-Tier Plan Classification & Lifecycle Hierarchy + +Plans reside in designated filesystem locations under `encyclopedia-knowledge-graph/docs/plans/`: + +| Tier | Classification | Filesystem Directory | PDF Compilation Policy | +| :--- | :--- | :--- | :--- | +| **Tier 1** | Active Non-Piecewise | `docs/plans/active/` | Mandatory Dark-Mode `.pdf` | +| **Tier 2** | Fully Affirmed Piecewise | `docs/plans/piecewise/` | Mandatory Dark-Mode `.pdf` | +| **Tier 3** | Partially Affirmed Piecewise | `docs/plans/piecewise/` | Mandatory Dark-Mode `.pdf` | +| **Tier 4** | Pending Audit Piecewise | `docs/plans/piecewise/` | Mandatory Dark-Mode `.pdf` | +| **Tier 5.1** | Retained Inactive / Deferred | `docs/plans/inactive/` | Zero PDF compilation/recompilation | +| **Tier 5.2** | Cold-Archived Inactive | `docs/plans/inactive/inactive-plans-archive.tar.gz` | Zero PDF; manifests record SHA-256 | +| **Tier 5.3** | Cold-Archived Completed | `docs/archive/completed-plans-archive.tar.gz` | `.md`-only tarball; manifest records SHA-256 | + +--- + +## 5. Automated Plan Verification (`hs-plan-lint`) + +The plan specification validator (`hyperstitionstud_io.ci.plan_validator`) enforces: +1. Every `.md` in `docs/plans/active/` and `docs/plans/piecewise/` has a matching `.pdf` in the same directory. +2. Every active and piecewise plan has an entry in `references/roadmap-plan-ledger.md`. +3. All mandatory metadata fields (`Document ID:`, `Status:`, `Target Ecosystem Version:`, `Target Repositories:`) are present. +4. Shorthands comply with `hs-shorthand-lint`. +5. No bare container host paths are serialized. diff --git a/src/hyperstitionstud_io/ci/plan_validator.py b/src/hyperstitionstud_io/ci/plan_validator.py new file mode 100644 index 0000000..8d38072 --- /dev/null +++ b/src/hyperstitionstud_io/ci/plan_validator.py @@ -0,0 +1,125 @@ +#!/usr/bin/env python3 +""" +src/hyperstitionstud_io/ci/plan_validator.py +Plan Specification & Governance Validator (`hs-plan-lint`). +Enforces PLAN-SPECIFICATION-AND-GOVERNANCE-STANDARD across docs/plans/{active,piecewise}/: + 1. Mandatory companion ReportLab Dark-Mode PDF (.pdf) for every active/piecewise Markdown plan (.md). + 2. Required metadata fields (Document ID, Status, Target Ecosystem Version, Target Repositories). + 3. Registration in roadmap-plan-ledger.md. + 4. Zero container host path serialization. + 5. Shorthand disambiguation compliance (.). +""" + +from __future__ import annotations + +import argparse +import json +import re +import sys +from pathlib import Path +from typing import Any + +from hyperstitionstud_io.config import load_workspace_config + +REQUIRED_METADATA_KEYS = [ + "Document ID", + "Status", + "Target Ecosystem Version", + "Target Repositories", +] + +CONTAINER_HOST_PATH_PATTERNS = [ + re.compile(r"/home/[a-zA-Z0-9_-]+/\.hermes"), + re.compile(r"/var/lib/docker"), + re.compile(r"/tmp/docker"), +] + + +def verify_plan_specifications(workspace_root: str | Path | None = None) -> dict[str, Any]: + cfg = load_workspace_config(workspace_root=workspace_root) + plans_dir = cfg.knowledge_graph_dir / "docs" / "plans" + active_dir = plans_dir / "active" + piecewise_dir = plans_dir / "piecewise" + + active_mds = sorted([p for p in active_dir.glob("PLAN-*.md") if p.is_file()]) + piecewise_mds = sorted([p for p in piecewise_dir.glob("PLAN-*.md") if p.is_file()]) + all_target_mds = active_mds + piecewise_mds + + ledger_candidates = [ + Path.home() / ".hermes" / "skills" / "software-development" / "hyperstitionstudio-roadmap-and-release" / "references" / "roadmap-plan-ledger.md", + Path("/root/.hermes/skills/software-development/hyperstitionstudio-roadmap-and-release/references/roadmap-plan-ledger.md"), + ] + ledger_text = "" + for lc in ledger_candidates: + if lc.is_file(): + ledger_text = lc.read_text(encoding="utf-8") + break + + missing_pdfs: list[str] = [] + missing_ledger_entries: list[str] = [] + metadata_errors: list[dict[str, Any]] = [] + host_path_errors: list[dict[str, Any]] = [] + errors: list[str] = [] + + for md_p in all_target_mds: + rel_p = md_p.relative_to(cfg.workspace_root).as_posix() + pdf_p = md_p.with_suffix(".pdf") + if not pdf_p.is_file(): + missing_pdfs.append(rel_p) + + txt = md_p.read_text(encoding="utf-8") + + # Check metadata fields + missing_keys = [] + for key in REQUIRED_METADATA_KEYS: + if not re.search(rf"\*\*{re.escape(key)}:\*\*", txt): + missing_keys.append(key) + if missing_keys: + metadata_errors.append({"file": rel_p, "missing_keys": missing_keys}) + + # Check host path leakage + for pat in CONTAINER_HOST_PATH_PATTERNS: + m = pat.search(txt) + if m: + host_path_errors.append({"file": rel_p, "leakage": m.group(0)}) + + # Check ledger presence if ledger is found + if ledger_text: + plan_stem = md_p.stem + if plan_stem not in ledger_text: + missing_ledger_entries.append(plan_stem) + + if missing_pdfs: + errors.append(f"Missing companion Dark-Mode PDFs for: {', '.join(missing_pdfs)}") + if metadata_errors: + errors.append(f"Metadata errors: {metadata_errors}") + if host_path_errors: + errors.append(f"Host path leakage detected: {host_path_errors}") + if missing_ledger_entries: + errors.append(f"Plans missing from roadmap-plan-ledger.md: {missing_ledger_entries}") + + return { + "ok": len(errors) == 0, + "active_plans_checked": len(active_mds), + "piecewise_plans_checked": len(piecewise_mds), + "total_plans_checked": len(all_target_mds), + "missing_pdfs": missing_pdfs, + "missing_ledger_entries": missing_ledger_entries, + "metadata_errors": metadata_errors, + "host_path_errors": host_path_errors, + "errors": errors, + } + + +def main(argv: list[str] | None = None) -> int: + ap = argparse.ArgumentParser(prog="hs-plan-lint", description="Validate active/piecewise architectural plans against governance standard.") + ap.add_argument("--workspace-root", default=None, help="Root directory of hyperstitionstud.io workspace.") + args = ap.parse_args(argv) + + res = verify_plan_specifications(workspace_root=args.workspace_root) + print(json.dumps(res, indent=2)) + return 0 if res["ok"] else 1 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tests/test_core_suite.py b/tests/test_core_suite.py index 0ef44ef..b405cfd 100644 --- a/tests/test_core_suite.py +++ b/tests/test_core_suite.py @@ -1452,6 +1452,14 @@ def test_ipld_quant_and_mcp_server() -> None: assert erofs_res["verified"] is True assert erofs_res["mcp_tools_swept"] >= 15 + # Verify PLAN-SPECIFICATION-AND-GOVERNANCE-STANDARD (hs-plan-lint) + from hyperstitionstud_io.ci.plan_validator import verify_plan_specifications + + plan_audit = verify_plan_specifications(workspace_root=cfg.workspace_root) + assert plan_audit["ok"] is True, f"Plan specification audit failed: {plan_audit['errors']}" + assert plan_audit["total_plans_checked"] >= 8 + assert len(plan_audit["missing_pdfs"]) == 0 + # Write cached internal test baseline (.cache/internal-test-baseline-latest.json) for hs-public-smoke from hyperstitionstud_io.ci.public_regression import write_internal_test_baseline_cache