Files
Vijay Janapa Reddi f1ffe5b6fa Rename interviews/ to staffml/ and drop the repeated prefix inside it
interviews/ held StaffML and nothing else, so the directory now carries the
product's name. Three names inside it repeated that prefix, and now line up
with vault/, vault-cli/, and paper/:

  interviews/staffml/               -> staffml/app/
  interviews/staffml-vault-worker/  -> staffml/vault-worker/
  interviews/staffml-vault-types/   -> staffml/vault-types/

Every repository path moved with it: workflow paths: triggers and variable
fallbacks, pre-commit hooks, .gitignore, contributor tooling, vault-cli path
joins, the app's tsconfig mapping to the shared types, and the docs.

Left alone on purpose:
- the published /interviews/ redirect to /staffml/ and the gh-pages subsite
  lists that protect it; those are URLs, not repository paths
- package and worker names (staffml-vault-worker, @staffml/vault-types) and
  the vitest job name, which branch protection may key on
- question YAMLs and generated track JSON, which are content-addressed.
  Three questions carry an older corruption, "recall @interviews/vault/
  questions/...", that predates this change
- the applied D1 migration 0001 and the vault CHANGELOG, which are history

codegen-hashes.txt is re-recorded; the three pinned artifacts changed only in
path strings. vault-cli: 97 passed, codegen --check clean.

interviewer.py's __main__ loader was one parent short and pointed at a
corpus.json that never existed; it now resolves staffml/app/src/data/
corpus.json. tools/validate_playbook.py and generate_interview_flashcard.py
still expect per-track directories that no longer exist; they point at the
new root but remain dead.

The GitHub repository variables STAFFML_ROOT, VAULT_DIR, and VAULT_CLI_DIR
still name the old paths and must change when this reaches origin.
2026-09-10 14:48:04 +02:00

68 lines
2.5 KiB
Python

#!/usr/bin/env python3
"""One-shot: normalize chain positions to contiguous [1..N] per chain.
The Phase-1 split preserved legacy ``chain_ids[0]`` as each question's chain
and took ``position + 1`` from the legacy 0-indexed value. Legacy corpus had
multi-chain membership: a single question could appear in up to 4 chains.
Our new single-chain schema kept only the first; the other chains are left
with gaps wherever their other members chose a different chain_ids[0].
This script re-numbers each chain's members to [1..N] sorted by their
current position, closing the gaps. Content-hash of affected questions
changes; re-run `vault build` afterward and update
``corpus-equivalence-hash.txt``.
Idempotent: running again with all chains already contiguous is a no-op.
"""
from __future__ import annotations
import sys
from collections import defaultdict
from pathlib import Path
_REPO = Path(__file__).resolve().parents[3]
sys.path.insert(0, str(_REPO / "staffml" / "vault-cli" / "src"))
from vault_cli.loader import load_all # noqa: E402
from vault_cli.yaml_io import dump_str, load_file # noqa: E402
def main() -> int:
vault_dir = _REPO / "staffml" / "vault"
loaded, errors = load_all(vault_dir)
if errors:
sys.stderr.write(f"warning: {len(errors)} load errors — skipping those files\n")
# Group by chain_id; each entry is (original_position, LoadedQuestion).
chains: dict[str, list[tuple[int, object]]] = defaultdict(list)
for lq in loaded:
if lq.question.chain is not None:
chains[lq.question.chain.id].append((lq.question.chain.position, lq))
rewritten = 0
for _chain_id, members in chains.items():
members.sort(key=lambda t: t[0])
positions = [m[0] for m in members]
expected = list(range(1, len(members) + 1))
if positions == expected:
continue
# Rewrite each member's chain.position to its new index.
for new_pos, (_old_pos, lq) in enumerate(members, start=1):
# Load raw YAML (preserves untouched fields) then update.
data = load_file(lq.path)
if "chain" in data and isinstance(data["chain"], dict):
if data["chain"].get("position") == new_pos:
continue
data["chain"]["position"] = new_pos
lq.path.write_text(dump_str(data), encoding="utf-8")
rewritten += 1
print(f"normalized: {rewritten} questions rewritten across {len(chains)} chains")
return 0
if __name__ == "__main__":
raise SystemExit(main())