Skip to content

rrrrrredy/research-toolkit / plugins/research-toolkit

research-toolkit

Flagged

Use for source-backed long-form research and writing in English or Chinese across fields, including revisions and continuation. Understand requirements, develop analysis through substantive research collaboration, and deliver a complete report after independent review, audit and acceptance.

FileKindSize
.codex-plugin/plugin.jsonconfig1.0 KB
.generated-files.jsonconfig6.3 KB
.mcp.jsonconfig158 B
LICENSEother1.0 KB
README.mdmarkdown3.4 KB
README.zh-CN.mdmarkdown3.0 KB
SKILL.mdskill md7.8 KB
SKILL.zh-CN.mdmarkdown6.5 KB
VERSIONother6 B
docs/compatibility.mdmarkdown3.8 KB
docs/compatibility.zh-CN.mdmarkdown3.2 KB
docs/delivery-verification.mdmarkdown19.2 KB
docs/delivery-verification.zh-CN.mdmarkdown16.3 KB
docs/review-completion.mdmarkdown18.0 KB
docs/review-completion.zh-CN.mdmarkdown14.7 KB
docs/usage-data.mdmarkdown15.4 KB
docs/usage-data.zh-CN.mdmarkdown13.9 KB
docs/usage-modes.mdmarkdown55.6 KB
docs/usage-modes.zh-CN.mdmarkdown48.6 KB
hooks/hooks.jsonconfig3.2 KB
mcp.jsonconfig253 B
plugin.jsonconfig1.1 KB
references/gotchas.mdmarkdown6.2 KB
references/gotchas.zh-CN.mdmarkdown3.6 KB
references/horizontal-vertical-analysis.mdmarkdown4.3 KB
references/horizontal-vertical-analysis.zh-CN.mdmarkdown3.2 KB
references/optional-analysis-lenses.mdmarkdown8.1 KB
references/optional-analysis-lenses.zh-CN.mdmarkdown6.1 KB
references/postmortem-lessons.mdmarkdown4.3 KB
references/postmortem-lessons.zh-CN.mdmarkdown3.5 KB
references/quality-gates.mdmarkdown5.7 KB
references/quality-gates.zh-CN.mdmarkdown4.5 KB
references/research-standard.mdmarkdown18.2 KB
references/research-standard.zh-CN.mdmarkdown13.7 KB
references/research-workflow.mdmarkdown25.5 KB
references/research-workflow.zh-CN.mdmarkdown19.9 KB
references/subagents-and-review-loop.mdmarkdown17.0 KB
references/subagents-and-review-loop.zh-CN.mdmarkdown13.4 KB
references/task-continuity.mdmarkdown6.9 KB
references/task-continuity.zh-CN.mdmarkdown5.3 KB
references/writing-style.mdmarkdown18.1 KB
references/writing-style.zh-CN.mdmarkdown14.9 KB
requirements-mcp.txtmarkdown11 B
scripts/agent_session.pyscript6.2 KB
scripts/check_delivery.pyscript44.6 KB
scripts/check_review_completion.pyscript28.5 KB
scripts/cli_agent_session.pyscript9.6 KB
scripts/codex_session.pyscript7.5 KB
scripts/extract_source_text.pyscript10.7 KB
scripts/host_review.pyscript78.4 KB
scripts/install_usage.pyscript9.7 KB
scripts/record_changes.pyscript13.7 KB
scripts/release_updates.pyscript9.8 KB
scripts/research_guidance.pyscript5.8 KB
scripts/research_host.pyscript52.4 KB
scripts/research_mcp.pyscript18.9 KB
scripts/research_records.pyscript28.5 KB
scripts/research_workflow.pyscript40.9 KB
scripts/review_process.pyscript5.2 KB
scripts/review_runner.pyscript20.2 KB
scripts/run_observation.pyscript7.7 KB
scripts/task_context.pyscript21.1 KB
scripts/task_lock.pyscript1.7 KB
scripts/task_reading.pyscript4.0 KB
scripts/task_storage.pyscript3.1 KB
scripts/usage_events.pyscript38.9 KB
scripts/usage_host.pyscript7.8 KB
scripts/usage_opencode.mjsscript3.1 KB

scripts/run_observation.py

View on GitHub
"""Small local observations, separate from research inputs and acceptance."""
from __future__ import annotations
from datetime import datetime, timezone
import json
import time


def now():
    return datetime.now(timezone.utc).isoformat()


def timed_capture(capture, started_at, started):
    if capture.get("import_only") is True:
        return {**capture, "import_started_at": started_at, "import_finished_at": now(),
                "import_elapsed_seconds": round(time.monotonic() - started, 6)}
    return {**capture, "started_at": started_at, "finished_at": now(),
            "elapsed_seconds": round(time.monotonic() - started, 6)}


def capture_usage(capture):
    """Use returned usage only; cached tokens are a subset, never added twice."""
    raw = []
    try:
        if capture.get("backend") == "generic":
            raw = [json.loads(capture["response"]).get("usage", {})]
        elif capture.get("format") == "codex-jsonl":
            raw = [e.get("usage", {}) for line in capture.get("stdout", "").split("\n") if line.strip()
                   for e in [json.loads(line)] if e.get("type") == "turn.completed"]
        elif capture.get("format") in {"json", "claude-json"}:
            raw = [json.loads(capture["stdout"]).get("usage", {})]
    except (ValueError, KeyError, TypeError, AttributeError):
        return None
    totals = {}
    for usage in raw:
        if not isinstance(usage, dict):
            continue
        values = {"input_tokens": usage.get("input_tokens", usage.get("prompt_tokens")),
                  "output_tokens": usage.get("output_tokens", usage.get("completion_tokens"))}
        cached = usage.get("cached_input_tokens")
        details = usage.get("prompt_tokens_details")
        if cached is None and isinstance(details, dict):
            cached = details.get("cached_tokens")
        values["cached_input_tokens"] = cached
        # Claude reports cache reads/writes separately from its input_tokens.
        if capture.get("format") == "claude-json":
            read, write = usage.get("cache_read_input_tokens"), usage.get("cache_creation_input_tokens")
            if all(type(v) is int and v >= 0 for v in (values["input_tokens"], read, write)):
                values["input_tokens"] += read + write
                values["cached_input_tokens"] = read
                values["cache_write_input_tokens"] = write
            else:
                values.pop("input_tokens")  # Do not report a partial total as complete.
        for key, value in values.items():
            if type(value) is int and value >= 0:
                totals[key] = totals.get(key, 0) + value
    return totals or None


def record_event(root, event):
    from task_storage import safe_path
    path = safe_path(root, "logs/activity.jsonl")
    path.parent.mkdir(parents=True, exist_ok=True)
    with path.open("a", encoding="utf-8") as stream:
        stream.write(json.dumps(event, ensure_ascii=False) + "\n")
    from usage_events import observe_record
    observe_record(root, event)


def _activity_summary(root):
    from task_storage import safe_path
    # safe_path resolves its result. Use the same base for relative paths,
    # including Windows short-name temp roots and equivalent paths with '..'.
    root = root.resolve()
    events, warnings = [], []
    path = safe_path(root, "logs/activity.jsonl")
    if path.exists():
        for line in path.read_text(encoding="utf-8").splitlines():
            try:
                row = json.loads(line)
                if isinstance(row, dict):
                    events.append(row)
            except ValueError:
                warnings.append("Unreadable activity row; original retained.")
    first = next((e for e in events if e.get("complete_draft") and e.get("outcome") == "saved"), None)
    start = next((e.get("started_at") for e in events if e.get("operation") == "start"), None)
    elapsed = None
    if first and start:
        try:
            elapsed = (datetime.fromisoformat(first["finished_at"]) - datetime.fromisoformat(start)).total_seconds()
        except (ValueError, KeyError, TypeError):
            warnings.append("Draft interval unavailable; original observations retained.")
    attempts, totals, self_submissions, imports = [], {}, 0, []
    imported_paths = set()
    # Only actual invocation captures; reusing a review creates no new capture.
    reviews = safe_path(root, "reviews")
    if reviews.exists():
        for path in sorted(reviews.rglob("execution.json")):
            try:
                path.resolve().relative_to(root.resolve())
                capture = json.loads(path.read_text(encoding="utf-8"))
                if capture.get("import_only") is True:
                    imported_paths.add(path.relative_to(root).as_posix())
                    imports.append({"path": path.relative_to(root).as_posix(),
                                    "import_elapsed_seconds": capture.get("import_elapsed_seconds", capture.get("elapsed_seconds")),
                                    "review_elapsed_seconds": None, "usage": None})
                    continue
                if capture.get("external_execution") is False:
                    self_submissions += 1
                    continue
                usage = capture_usage(capture)
                attempts.append({"path": path.relative_to(root).as_posix(),
                                 "elapsed_seconds": capture.get("elapsed_seconds"), "usage": usage})
                for key, value in (usage or {}).items():
                    totals[key] = totals.get(key, 0) + value
            except (ValueError, OSError, AttributeError):
                warnings.append("Unreadable invocation capture: " + str(path.relative_to(root)))
    retry_groups, failed = {}, 0
    history = safe_path(root, "logs/review.jsonl")
    if history.exists():
        for line in history.read_text(encoding="utf-8").splitlines():
            try:
                row = json.loads(line)
                if row.get("record_type") != "model_review" or row.get("reviewer") == "self":
                    continue
                if isinstance(row.get("execution"), dict) and row["execution"].get("path") in imported_paths:
                    continue
                key = (row.get("slot_id"), row.get("artifact_sha256"), json.dumps(row.get("input"), sort_keys=True))
                retry_groups.setdefault(key, set()).add(row.get("attempt_id"))
                failed += row.get("status") != "completed"
            except (ValueError, AttributeError, TypeError):
                warnings.append("Unreadable review activity row; original retained.")
    return {"task_started_at": start, "first_complete_draft": first, "seconds_to_first_complete_draft_observation": elapsed,
            "save_attempts": len([e for e in events if e.get("operation") == "save"]),
            "failed_saves": len([e for e in events if e.get("operation") == "save" and e.get("outcome") == "error"]),
            "review_invocations": attempts, "observed_review_usage": totals or None,
            "failed_review_attempts": failed, "review_retries": sum(max(0, len(ids) - 1) for ids in retry_groups.values()),
            "self_review_submissions": self_submissions,
            "imported_reviews": imports,
            "review_invocations_without_usage": sum(a["usage"] is None for a in attempts),
            "author_usage": None, "warnings": warnings,
            "scope": "Tool-observed draft saves and invocation captures; no agent tool author usage, billing or quality inference."}


def activity_summary(root):
    try:
        return _activity_summary(root)
    except (OSError, ValueError, TypeError):
        return {"warnings": ["Activity summary unavailable; research and delivery checks are unchanged."],
                "author_usage": None, "observed_review_usage": None}
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall