Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
38c6a4f
Index TypeScript monorepos by member project, not the umbrella root
ZYZ666-RGB Nov 30, 2026
315c4d7
Fix TypeScript umbrella discovery and delta fallbacks
ZYZ666-RGB Nov 30, 2026
c0d7465
Isolate TypeScript member index runs and keep paths with spaces
ZYZ666-RGB Nov 30, 2026
7a6c9a2
Index a regular root TypeScript project as the workspace
ZYZ666-RGB Nov 30, 2026
11c0a52
Merge remote-tracking branch 'upstream/main' into fix-1678-ts-umbrell…
ZYZ666-RGB Nov 30, 2026
61465f5
Dedupe merged TypeScript indexes and keep hidden member paths
ZYZ666-RGB Nov 30, 2026
ff13773
Keep sibling tsconfig documents and reindex config-only windows
ZYZ666-RGB Dec 1, 2026
445d783
Merge remote-tracking branch 'upstream/main' into fix-1678-ts-umbrell…
ZYZ666-RGB Dec 1, 2026
b198ae2
Merge remote-tracking branch 'upstream/main' into fix-1678-ts-umbrell…
ZYZ666-RGB Dec 1, 2026
2c7d09a
Convert full member indexes on mixed TypeScript windows
ZYZ666-RGB Dec 1, 2026
2eade0f
Keep documents from root-level tsconfigs and rebuild on member config…
ZYZ666-RGB Dec 1, 2026
6e72312
Drop followed root-tsconfig docs and skip unowned config rebuilds
ZYZ666-RGB Dec 1, 2026
c24cf1d
Merge remote-tracking branch 'upstream/main' into fix-1678-ts-umbrell…
ZYZ666-RGB Dec 1, 2026
9dd7f42
Format the has-config guard the way shfmt expects
ZYZ666-RGB Dec 1, 2026
b123531
Merge remote-tracking branch 'upstream/main' into fix-1678-ts-umbrell…
ZYZ666-RGB Dec 1, 2026
53f1006
Keep merge docs when a generated tsconfig.scip.json matches a known dir
ZYZ666-RGB Dec 1, 2026
e8fbb33
Keep the most specific directory when sibling tsconfigs tie
ZYZ666-RGB Dec 1, 2026
d848bd1
Prefer a one-character member over a root tsconfig on a length tie
ZYZ666-RGB Dec 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/architecture/code-index-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,12 @@ applies it. Per touched file the apply upserts what the delta emits and tombston
file's `scip` rows it no longer emits; a deleted file is tombstoned whole. Re-applying a
delta gives the same live set.

| Producer | Language | Watermark | Workers | How it runs |
| ----------------- | ----------------------- | ---------------- | ------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------- |
| `scip-clang` | C++ | `scip_commit` | `code_scip_full`, `code_scip_delta`, `code_scip_apply` | Changed TUs (and TUs including changed headers, capped) via `run_delta.sh`; `code_scip_full` seeds the tier and re-indexes it weekly. |
| `scip-typescript` | TypeScript / JavaScript | `scip_commit_ts` | `code_scip_ts_delta` | Whole-workspace index per pass, bounded to the window's files by the converter. |
| `scip-go` | Go | `scip_commit_go` | `code_scip_go_delta` | One build per module (`run_go_monorepo_delta.sh`). |
| `scip-python` | Python | `scip_commit_py` | `code_scip_py_delta`, `code_scip_apply` | Per-merge delta (`run_python_delta.sh`); a first run indexes the tree. |
| Producer | Language | Watermark | Workers | How it runs |
| ----------------- | ----------------------- | ---------------- | ------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `scip-clang` | C++ | `scip_commit` | `code_scip_full`, `code_scip_delta`, `code_scip_apply` | Changed TUs (and TUs including changed headers, capped) via `run_delta.sh`; `code_scip_full` seeds the tier and re-indexes it weekly. |
| `scip-typescript` | TypeScript / JavaScript | `scip_commit_ts` | `code_scip_ts_delta` | Indexes named projects, or the members of an umbrella root tsconfig (including explicit tsconfig file references); a delta indexes only the projects that contain the window's files unless a shared config or lockfile changed, or a changed TypeScript path sits outside every member. The converter still bounds the output to the TypeScript window. |
| `scip-go` | Go | `scip_commit_go` | `code_scip_go_delta` | One build per module (`run_go_monorepo_delta.sh`). |
| `scip-python` | Python | `scip_commit_py` | `code_scip_py_delta`, `code_scip_apply` | Per-merge delta (`run_python_delta.sh`); a first run indexes the tree. |

`code/domain/index/compiler_tiers.py` (`TIERS`) is the one table of watermark, label
and workers per producer; status handlers and the dashboard read it. A delta worker
Expand Down
106 changes: 97 additions & 9 deletions scripts/scip_harness/run_typescript_delta.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
# DELTA_OUT DELTA_OUT=/path/delta.json run_typescript_delta.sh <checkout> <base|--full> <head>
# the in-server worker's mode: index, convert, write the JSON
# delta; no upload, no watermark read. Exits 0 with no file
# when no TypeScript file changed in the window.
# when no TypeScript file changed and no shared config or
# lockfile selected members to reindex.
#
# scip-typescript has no per-file mode — it indexes the workspace (langfuse:
# 4,603 files in ~4 min, a 384 MB index) — so both modes run the full index and
# let the converter's --changed-files bound the DELTA to the window's files.
# scip-typescript has no per-file mode, so a named or discovered project is
# indexed as a whole. A delta still bounds the converted output with
# --changed-files, and only the projects that contain those files are indexed
# unless a shared config or lockfile changed.
#
# Env: LOOM_API_KEY (writer; upload mode), SCIP_TYPESCRIPT (bin; `npm i -g
# @sourcegraph/scip-typescript@0.4.0`, node 22 or 24), PYTHON (venv python),
Expand Down Expand Up @@ -44,7 +46,16 @@ if [[ -n "${SCIP_TS_PROJECTS:-}" ]]; then
read -r -a PROJECTS <<<"$SCIP_TS_PROJECTS"
WORKSPACES="" # every target below has a tsconfig; inference would write one into the tree
SCIP_TS_PATHS=0 # the dist-export rewrite is for an unbuilt workspace, not named projects
elif discovered=$("$PYTHON" "$HARNESS_DIR/scip_ts_projects.py" discover "$CHECKOUT") && [[ -n "$discovered" ]]; then
# umbrella root tsconfig: index member projects instead of loading the root.
# One path per line (a member directory may contain a space).
mapfile -t PROJECTS <<<"$discovered"
WORKSPACES=""
SCIP_TS_PATHS=0
fi
# Ownership uses the full discovered set even when a delta indexes a subset,
# so a root-level tsconfig cannot keep documents a more specific member owns.
ALL_PROJECTS=("${PROJECTS[@]}")

if [[ -z "${WORKSPACES+x}" ]]; then
if [[ -f "$CHECKOUT/pnpm-workspace.yaml" ]]; then
Expand Down Expand Up @@ -104,6 +115,11 @@ index_workspace() {
fi
for proj in "${PROJECTS[@]}"; do
proj=${proj%/}
# An umbrella reference may name a tsconfig file (e.g. tsconfig.build.json).
if [[ -f "$proj" ]]; then
targets+=("$proj")
continue
fi
[[ -d "$proj" ]] || {
echo ">> project $proj is not in the tree — skipped" >&2
continue
Expand All @@ -127,27 +143,99 @@ JSONEOF
done
local ws=()
[[ -n "$WORKSPACES" ]] && ws=("$WORKSPACES")
NODE_OPTIONS="--max-old-space-size=$NODE_HEAP_MB" \
"$SCIP_TYPESCRIPT" index "${ws[@]}" "${targets[@]}" --output "$WORK/index.scip" >&2
# One indexer process per member: scip-typescript walks every target in a
# single process and shares its source-file cache across them, so passing
# the whole umbrella as arguments keeps the same heap growth the root
# pass already hits. Isolated runs drop that cache between members.
local parts=() target part i=0
if [[ ${#targets[@]} -eq 0 ]]; then
# No member list: a regular root tsconfig (or a pnpm/yarn workspace)
# is indexed by invoking scip-typescript on the checkout with only the
# workspace flags. An umbrella whose members were all skipped still
# writes an empty index.
if [[ ${#PROJECTS[@]} -eq 0 ]]; then
NODE_OPTIONS="--max-old-space-size=$NODE_HEAP_MB" \
"$SCIP_TYPESCRIPT" index "${ws[@]}" --output "$WORK/index.scip" >&2
else
: >"$WORK/index.scip"
fi
return
fi
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
for target in "${targets[@]}"; do
part="$WORK/index.part.$i.scip"
NODE_OPTIONS="--max-old-space-size=$NODE_HEAP_MB" \
"$SCIP_TYPESCRIPT" index "${ws[@]}" "$target" --output "$part" >&2
parts+=("$part")
i=$((i + 1))
done
# Always merge so a single member that followed project references
# also drops documents it does not own.
local merge_args=() t
for t in "${targets[@]}"; do
merge_args+=(--project "$t")
done
for t in "${ALL_PROJECTS[@]}"; do
merge_args+=(--known-project "$t")
done
"$PYTHON" "$HARNESS_DIR/scip_merge_indexes.py" --output "$WORK/index.scip" \
"${merge_args[@]}" "${parts[@]}"
}

cd "$CHECKOUT"
CONVERT_ARGS=(--index "$WORK/index.scip" --commit "$HEAD_SHA")
CONFIG_ONLY_REBUILD=0
if [[ "$BASE" != "--full" ]]; then
require_base "$BASE"
window_files "$WORK" "$BASE" "$HEAD_SHA" "${TS_GLOBS[@]}"
if [[ ! -s "$WORK/changed.txt" && ! -s "$WORK/deleted.txt" ]]; then
if [[ ${#PROJECTS[@]} -gt 0 ]]; then
# The convert window is TypeScript-only; the project filter also needs
# shared configs and lockfiles so a mixed window falls back to every member.
mkdir -p "$WORK/project-window"
window_files "$WORK/project-window" "$BASE" "$HEAD_SHA"
filter_args=()
[[ -s "$WORK/project-window/changed.txt" ]] && filter_args+=(--changed-file-list "$WORK/project-window/changed.txt")
[[ -s "$WORK/project-window/deleted.txt" ]] && filter_args+=(--deleted-file-list "$WORK/project-window/deleted.txt")
filtered=$("$PYTHON" "$HARNESS_DIR/scip_ts_projects.py" filter "${filter_args[@]}" -- "${PROJECTS[@]}")
Comment thread
zlareb1 marked this conversation as resolved.
Resolved
if [[ -n "$filtered" ]]; then
mapfile -t PROJECTS <<<"$filtered"
else
# An empty filter is a real empty selection (e.g. an unowned
# package.json). Do not keep the full member set.
PROJECTS=()
fi
# A package manifest, lockfile, or tsconfig in a selected member (or a
# shared root config) can change resolution. Convert the full selected
# indexes; keep TypeScript deletions so removed files still drop out
# of the compiler rows. An unowned config does not rebuild anyone.
if [[ ${#PROJECTS[@]} -gt 0 ]] \
&& "$PYTHON" "$HARNESS_DIR/scip_ts_projects.py" has-config "${filter_args[@]}"; then
CONFIG_ONLY_REBUILD=1
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
fi
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
fi
if [[ ! -s "$WORK/changed.txt" && ! -s "$WORK/deleted.txt" && "$CONFIG_ONLY_REBUILD" != "1" ]]; then
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
echo ">> no TypeScript changes in $BASE..$HEAD_SHA"
if [[ -n "${DELTA_OUT:-}" ]]; then exit 0; fi # the worker advances the watermark itself
echo ">> advancing watermark via empty delta"
fi
CONVERT_ARGS+=(--base "$BASE" --changed-files "$WORK/changed.txt" --deleted-files "$WORK/deleted.txt")
if [[ "$CONFIG_ONLY_REBUILD" == "1" ]]; then
if [[ -s "$WORK/changed.txt" || -s "$WORK/deleted.txt" ]]; then
echo ">> mixed window with a config change — converting full member indexes"
else
echo ">> config-only window — reindexing selected members"
fi
CONVERT_ARGS+=(--base "$BASE")
if [[ -s "$WORK/deleted.txt" ]]; then
CONVERT_ARGS+=(--deleted-files "$WORK/deleted.txt")
fi
else
CONVERT_ARGS+=(--base "$BASE" --changed-files "$WORK/changed.txt" --deleted-files "$WORK/deleted.txt")
fi
else
echo ">> no scip_commit_ts watermark — full TypeScript backfill"
CONVERT_ARGS+=(--full)
fi

if [[ "$BASE" != "--full" && ! -s "$WORK/changed.txt" ]]; then
if [[ "$BASE" != "--full" && ! -s "$WORK/changed.txt" && "$CONFIG_ONLY_REBUILD" != "1" ]]; then
# nothing to read from an index: a zero-byte file is an empty Index, and
# the delta carries only the window's deletions
: >"$WORK/index.scip"
Expand Down
158 changes: 158 additions & 0 deletions scripts/scip_harness/scip_merge_indexes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
#!/usr/bin/env python3
"""Merge SCIP Index files into one index.

Each input is a complete Index (scip-typescript --output). Documents are
keyed by relative_path so a file emitted by more than one isolated run
appears once. When --project is given for each input, a document is taken
from the member that uniquely owns it (the longest matching project
scope); that drops copies a dependent emitted by following TypeScript
project references. Sibling tsconfigs in the same directory share a
scope, so each keeps the documents it emitted and a path present in more
than one of those indexes keeps the last copy. Metadata is taken from
the first non-empty input. External
symbols are concatenated. An all-empty input list, or only empty files,
writes a zero-byte output so the converter treats it as an empty index.
"""

from __future__ import annotations

import argparse
import importlib.util
import sys
from pathlib import Path
from typing import Any

_HARNESS = Path(__file__).resolve().parent
_VENDOR = _HARNESS / "vendor"


def _load_ts_projects() -> Any:
spec = importlib.util.spec_from_file_location(
"scip_ts_projects", _HARNESS / "scip_ts_projects.py"
)
if spec is None or spec.loader is None:
raise SystemExit(f"cannot load {_HARNESS / 'scip_ts_projects.py'}")
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod


_ts_projects = _load_ts_projects()
project_owns = _ts_projects.project_owns
project_scope = _ts_projects.project_scope


def _ensure_scip_pb2() -> Any:
if str(_VENDOR) not in sys.path:
sys.path.insert(0, str(_VENDOR))
try:
import scip_pb2
except Exception as e: # ImportError, or protobuf VersionError
raise SystemExit(
f"cannot load vendor/scip_pb2.py ({e}): merging indexes needs protobuf>=7.35.1"
) from e
return scip_pb2


def _scope_specificity(project: str) -> int:
"""Longer directory scopes win. The root scope '.' has length 1, which
would otherwise tie a one-character member directory such as 'a'."""
scope = project_scope(project)
if scope in (".", ""):
return 0
return len(scope)


def _preferred_owner(projects: list[str], relpath: str) -> str | None:
owners = [project for project in projects if project_owns(project, relpath)]
if not owners:
return None
best_scope = max(_scope_specificity(project) for project in owners)
tied = [project for project in owners if _scope_specificity(project) == best_scope]
# Sibling explicit tsconfigs share a directory scope. Returning one of
# them still lets each sibling keep its documents (scopes match) while
# a shorter ancestor, such as a root tsconfig, is dropped.
return tied[0]
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved


def merge_indexes(
paths: list[Path],
output: Path,
projects: list[str] | None = None,
known_projects: list[str] | None = None,
) -> None:
if projects is not None and len(projects) != len(paths):
raise SystemExit("--project count must match the number of indexes")
scip_pb2 = _ensure_scip_pb2()
merged = scip_pb2.Index()
documents: dict[str, object] = {}
has_payload = False
for i, path in enumerate(paths):
data = path.read_bytes() if path.is_file() else b""
if not data:
continue
idx = scip_pb2.Index()
idx.ParseFromString(data)
if not has_payload and idx.HasField("metadata"):
merged.metadata.CopyFrom(idx.metadata)
project = projects[i] if projects is not None else None
for doc in idx.documents:
rel = doc.relative_path
if projects is not None and project is not None:
# Keep documents this member owns. Documents followed through
# TypeScript project references into another package are
# dropped even when that package is not in this merge, so a
# subset rebuild cannot overwrite the other package's rows.
# known_projects is the full discovered set: a root-level
# tsconfig owns every path, so ownership still prefers a
# longer member that was not indexed in this run.
if not project_owns(project, rel):
continue
owners = known_projects if known_projects is not None else projects
owner = _preferred_owner(owners, rel)
# Compare scopes, not raw project strings: a generated
# member target is dir/tsconfig.scip.json, while
# --known-project still names dir.
if owner is not None and project_scope(owner) != project_scope(project):
Comment thread
zlareb1 marked this conversation as resolved.
Resolved
continue
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
copied = scip_pb2.Document()
copied.CopyFrom(doc)
documents[rel] = copied
merged.external_symbols.extend(idx.external_symbols)
has_payload = True
if not has_payload:
output.write_bytes(b"")
return
for doc in documents.values():
merged.documents.append(doc)
output.write_bytes(merged.SerializeToString())
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved


def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--output", required=True, type=Path)
parser.add_argument(
"--project",
action="append",
default=[],
help="member path for the corresponding index (same order); "
"documents are kept from the owning member",
)
parser.add_argument(
"--known-project",
action="append",
default=[],
help="full discovered member set used for ownership; a document is "
"dropped when a more specific member owns it, even if that member "
"was not indexed in this run",
)
parser.add_argument("indexes", nargs="+", type=Path)
args = parser.parse_args(argv)
projects = args.project or None
known = args.known_project or None
merge_indexes(args.indexes, args.output, projects, known)
return 0


if __name__ == "__main__":
raise SystemExit(main())
Loading
Loading