diff --git a/docs/superpowers/spikes/2026-12-05-direct-project-lifecycle-and-changelog-feed.md b/docs/superpowers/spikes/2026-12-05-direct-project-lifecycle-and-changelog-feed.md new file mode 100644 index 000000000..750bc65d3 --- /dev/null +++ b/docs/superpowers/spikes/2026-12-05-direct-project-lifecycle-and-changelog-feed.md @@ -0,0 +1,82 @@ +# Spike: direct project lifecycle, project listing paging and the changelog feed (#1229) + +**Date:** 2026-12-05 · **Profile:** `denon82` (Flow served `flow.google.com`) · **Base:** `develop` fa402f8e +· **Cost:** $0. One project was created, renamed and deleted; no generation was submitted. +· **Scripts:** [`scripts/dev/spike_direct_writes_1227.py`](../../../scripts/dev/spike_direct_writes_1227.py), +[`scripts/dev/spike_project_listing_paging.py`](../../../scripts/dev/spike_project_listing_paging.py), +[`scripts/dev/spike_changelog_feed.py`](../../../scripts/dev/spike_changelog_feed.py) +· **Depends on:** [direct project writes](2026-11-10-direct-project-writes.md), +[page-free reads](2026-11-09-page-free-reads.md) + +## Questions + +1. Do the direct project writes measured on 2026-11-10 (`jHPbke` create, `o8DA4` rename, + `QI2zvc` delete) still work on the build Flow serves today? +2. How does the project listing (`UpteDb`) page, and how many calls does reading every + project title cost? Project-title sync needs the answer. +3. Where do the entries of `https://flow.google.com/changelogs` come from, and can they be + read without a profile or a browser? A changelog watcher needs the answer. + +## Method + +All three use the profile's saved cookies and the shell's `at` token over `httpx`, as +`src/gflow_cli/api/flow_wire.py` does. The changelog question also loads the page in headless +Chromium: once in a fresh context with no cookies, and once on the profile. The scripts print +only shapes, counts, 8-character id prefixes and public page text, never a title, cookie or token. + +## Results + +### 1. Direct project lifecycle + +`spike_direct_writes_1227.py`, re-run unchanged, 25 days after the first run: + +| Call | Status | Read back | +|---|---|---| +| `jHPbke` create | 200 | the `ngNC2` title matches; the project is in the `UpteDb` listing | +| `o8DA4` rename | 200 | the reply title, the `ngNC2` title and the listing all match | +| `QI2zvc` delete | 200, `[]` | the project is gone from `ngNC2` and from the listing | + +The direct writes still hold on the current build. + +### 2. Listing paging + +`spike_project_listing_paging.py`, read only: + +- The `UpteDb` argument the app sends is `["projects/*", 21, null, null, null, null, [1]]`. The + reply frame is `[rows, next_token (28-character string), 26-character string]`. +- A page size of 100 is honoured and returns 100 rows. +- Sending the next token in slot 2 (the `null` after the page size) returns the next page with + no overlap with the first. +- `ngNC2` on one project returns `[project_id, [title]]`. + +Reading every project title costs one direct call per 100 projects. + +### 3. Changelog feed + +`spike_changelog_feed.py`: + +- **Cookieless context:** `/changelogs` redirects on the client to `/about?returnUrl=/changelogs` + and renders no entries. +- **Profile context:** the page renders 17 dated entries. The page also calls `o30O0e`, + `Yizz8d`, `NfrxTb`, `nzlxg`, `cPZSdc`, `KV2T2d`, `QLXvEd` and `RaYiHf`. +- **Carrier:** the marker is the text after the first entry's date. It appears in exactly one + response, a JavaScript bundle under `/_/mss/boq-labs-ai-sandbox/_/js/`. A cookieless + `httpx` GET of that bundle returns 200 and contains the marker. +- **Void first run:** the first run used "Google Flow" as its marker. That is page chrome found + in every bundle, so the run is recorded as void, and the marker was changed to the entry text. + +The changelog entries ship inside a public bundle. A watcher can read them without a profile, +the way `scripts/canary/rpc_drift.py` reads RPC ids from bundles, so it can run on hosted CI. + +## Consequences + +- A direct tier for project create, rename and delete is supported by current evidence. The + browser path stays as the fallback. +- Project-title sync can list titles directly, at one call per 100 projects. The reply shape + is pinned by the readings above. +- A changelog watcher needs no account. **Not measured:** whether the cookieless shell names + that bundle directly, as it names the `/_/js/` script `rpc_drift.py` reads, or whether the + page loads it later as a separate module. The bundle URL is versioned, so the watcher's plan + has to settle how it finds the URL on each run. +- **Not measured:** how many Flow reads a typical command makes. That number sets the size of + a read cache, and the cache's implementation plan measures it. diff --git a/scripts/dev/spike_changelog_feed.py b/scripts/dev/spike_changelog_feed.py new file mode 100644 index 000000000..9d690279f --- /dev/null +++ b/scripts/dev/spike_changelog_feed.py @@ -0,0 +1,154 @@ +"""Spike ($0): where do flow.google.com/changelogs entries come from, and can they be read +without a profile or a browser? + +Question: the wire observatory (#1229 Phase 2) wants to diff Flow's public changelog every +night. The page answers 200 with a 172 KB Angular shell whose HTML holds no entry text, so the +entries arrive some other way. Which request carries them, and does it need cookies? + +Method: bundled Chromium, headless, a fresh context (no profile, no cookies). Load +``https://flow.google.com/changelogs``, wait for the network to settle, then record: + +* every request: method, host, path, ``rpcids`` query value (batchexecute), status, content type; +* for each response body that is JSON, ``batchexecute`` or JS: whether it contains a marker + string taken from the RENDERED page (the first entry's heading), so the carrier is found by + content rather than guessed; +* the rendered entries: count of dated headings and the first three heading texts (public text). + +Then, without a browser, replay the carrier request with ``httpx`` and no cookies. + +Pre-registered readings (written before the run): + +* A batchexecute response carries the marker, and the cookieless httpx replay returns the same + marker -> "cookieless RPC feed": the observatory reads it with httpx (rpcid recorded). +* A JS bundle (``/_/js/``) carries the marker -> "entries ship in the bundle": the observatory + reads the bundle like ``scripts/canary/rpc_drift.py`` does. +* The marker appears only after login, or the page renders no entries in a cookieless context + -> "needs a session": the observatory reads it on the canary's profile instead. +* No captured body carries the marker -> "carrier not found": record the request list, nothing + is concluded about absence (a selector or marker miss is evidence about the method). + +Nothing private is printed: no cookies are present, and only public page text and request +paths are shown. + +Usage: + uv run python scripts/dev/spike_changelog_feed.py +""" + +from __future__ import annotations + +import asyncio +import contextlib +import re +from urllib.parse import parse_qs, urlparse + +import httpx +from playwright.async_api import async_playwright + +URL = "https://flow.google.com/changelogs" +_TEXTY = ("json", "javascript", "text/plain", "text/html", "x-protobuf") + + +async def main(profile: str | None) -> None: + records: list[dict[str, str]] = [] + bodies: dict[str, str] = {} + + from gflow_cli.config import get_settings # noqa: PLC0415 + from gflow_cli.profile_lease import ProfileLease # noqa: PLC0415 + + profile_dir = get_settings().profile_subdir(profile) if profile else None + # The profile arm holds the profile's lease, so a second session gets ProfileLockedError. + lease = ProfileLease(profile_dir) if profile_dir else contextlib.nullcontext() + async with lease, async_playwright() as pw: + if profile_dir: + # Profile arm: the session the canary would hold. Headless real Chrome on the + # gflow profile dir. + context = await pw.chromium.launch_persistent_context( + str(profile_dir), + channel="chrome", + headless=True, + locale="en-US", + ) + browser = None + else: + browser = await pw.chromium.launch(headless=True) + context = await browser.new_context(locale="en-US") + page = await context.new_page() + + async def on_response(resp) -> None: # noqa: ANN001 - playwright Response + url = resp.url + parsed = urlparse(url) + ctype = resp.headers.get("content-type", "") + rpc = parse_qs(parsed.query).get("rpcids", [""])[0] + rec = { + "method": resp.request.method, + "host": parsed.netloc, + "path": parsed.path[:90], + "rpcids": rpc, + "status": str(resp.status), + "ctype": ctype.split(";")[0], + } + records.append(rec) + if any(t in ctype for t in _TEXTY): + try: + bodies[url] = await resp.text() + except Exception: # noqa: BLE001 - redirects/evicted bodies are fine to skip + pass + + page.on("response", on_response) + await page.goto(URL, wait_until="networkidle", timeout=60_000) + await page.wait_for_timeout(3000) + final_url = page.url + headings = await page.eval_on_selector_all( + "h1, h2, h3, h4", + "els => els.map(e => e.innerText.trim()).filter(t => t.length > 0)", + ) + body_text = await page.inner_text("body") + await (browser.close() if browser else context.close()) + + dated = re.findall(r"\b\d{1,2}/\d{1,2}/20\d\d\b", body_text) + print(f"final_url={final_url}") + print(f"rendered headings={len(headings)} first={headings[:6]}") + print(f"dated tokens in rendered text={len(dated)} first={dated[:5]}") + + print("\n== requests (non-static)") + for r in records: + if any(r["path"].endswith(x) for x in (".woff2", ".png", ".svg", ".ico", ".css")): + continue + print( + f"{r['status']} {r['method']} {r['host']}{r['path']} " + f"rpcids={r['rpcids'] or '-'} {r['ctype']}" + ) + + # Marker: entry text next to a date, never page chrome ("Google Flow" matched every bundle + # on the first run and proved nothing). Take the 30 characters after the first date token. + marker = "" + if dated: + tail = body_text.split(dated[0], 1)[1].strip() + marker = tail.splitlines()[0][:30] if tail else "" + print(f"\nmarker={marker!r}") + carriers = [u for u, b in bodies.items() if marker and marker in b] + print(f"carriers containing marker={len(carriers)}") + for u in carriers: + p = urlparse(u) + rpc = parse_qs(p.query).get("rpcids", [""])[0] + print(f" {p.netloc}{p.path[:90]} rpcids={rpc or '-'} len={len(bodies[u])}") + + # Cookieless replay of GET carriers (a batchexecute POST needs its f.req; reported, not sent). + for u in carriers: + if "batchexecute" in u: + print(f" replay skipped (POST with f.req): {urlparse(u).path}") + continue + async with httpx.AsyncClient(follow_redirects=False, timeout=30) as client: + resp = await client.get(u) + print( + f" cookieless httpx GET {urlparse(u).path[:60]} -> {resp.status_code} " + f"marker_present={marker in resp.text}" + ) + + +if __name__ == "__main__": + import argparse + + ap = argparse.ArgumentParser() + ap.add_argument("--profile", default=None, help="gflow profile for the session arm") + asyncio.run(main(ap.parse_args().profile)) diff --git a/scripts/dev/spike_project_listing_paging.py b/scripts/dev/spike_project_listing_paging.py new file mode 100644 index 000000000..49164a8d5 --- /dev/null +++ b/scripts/dev/spike_project_listing_paging.py @@ -0,0 +1,149 @@ +"""Spike ($0, read-only): how does ``UpteDb`` page past 21 projects, and what does ``ngNC2`` +return for a title? Needed for project-title sync (#1229 Phase 2). + +No browser, no write: the same cookie + shell-token path as ``flow_wire`` (via the #1227 +spike's ``Wire`` helper). Only shapes, counts and 8-char id prefixes are printed, never a +title, cookie or token value. + +Arms: +1. ``UpteDb`` with the app's own argument ``["projects/*", 21, null, null, null, null, [1]]``: + print the frame's top-level shape (length and type of each slot) and the row count. +2. The same with a page size of 100: does the server honour a larger page? +3. If arm 1's frame carries a string slot other than the rows (a page token), resend with that + token in slot 2 (the null after the page size) and report the row count and overlap. +4. ``ngNC2`` on the first listed project: frame shape and whether slot [1][0] is a string. + +Pre-registered readings: +- arm 2 returns more than 21 rows -> a single larger page covers a sync (no paging needed up to N). +- arm 2 returns 21 and arm 1 has a string token that arm 3 accepts with new, non-overlapping + rows -> page with the token in slot 2. +- arm 1 returns fewer than 21 rows and no token -> the account has fewer projects than a page: + paging is unmeasured on this profile (no conclusion about paging). +- any error frame or non-200 -> refused; record it. + +Usage: + uv run python scripts/dev/spike_project_listing_paging.py --profile denon82 +""" + +from __future__ import annotations + +import argparse +import asyncio +import importlib.util +import json +from http.cookiejar import CookieJar, DefaultCookiePolicy +from pathlib import Path +from typing import Any + +import httpx + +from gflow_cli.api import flow_wire as fw +from gflow_cli.config import get_settings + +_SPEC = importlib.util.spec_from_file_location( + "spike1227", Path(__file__).with_name("spike_direct_writes_1227.py") +) +assert _SPEC and _SPEC.loader +spike1227 = importlib.util.module_from_spec(_SPEC) +_SPEC.loader.exec_module(spike1227) + + +def shape(value: Any) -> Any: + if isinstance(value, list): + return f"list[{len(value)}]" + if isinstance(value, str): + return f"str[{len(value)}]" + return type(value).__name__ + + +def rows_of(frame: Any) -> list[Any]: + if not isinstance(frame, list) or not frame or not isinstance(frame[0], list): + return [] + return [r for r in frame[0] if isinstance(r, list)] + + +async def main() -> None: + ap = argparse.ArgumentParser() + ap.add_argument("--profile", required=True) + a = ap.parse_args() + profile_dir = get_settings().profile_subdir(a.profile) + ua = fw._user_agent(profile_dir) # noqa: SLF001 + cookies = fw.read_cookies_for(profile_dir) + assert ua and cookies, "no UA or cookies for this profile" + headers = { + "user-agent": ua, + "accept-language": "en-US,en;q=0.9", + "cookie": "; ".join(f"{n}={v}" for n, v in cookies), + } + async with httpx.AsyncClient( + follow_redirects=False, + trust_env=False, + timeout=httpx.Timeout(60, connect=5), + cookies=CookieJar(policy=DefaultCookiePolicy(allowed_domains=[])), + ) as client: + tokens = await fw._shell_tokens(client, profile_dir, headers) # noqa: SLF001 + w = spike1227.Wire(client, tokens, headers) + + r1 = await w.call("UpteDb", ["projects/*", 21, None, None, None, None, [1]]) + f1 = r1["frame"] + rows1 = rows_of(f1) + print( + json.dumps( + { + "arm": 1, + "status": r1["status"], + "errors": r1["errors"], + "frame_slots": [shape(s) for s in (f1 or [])], + "rows": len(rows1), + "row0_slots": [shape(s) for s in (rows1[0] if rows1 else [])], + } + ) + ) + + r2 = await w.call("UpteDb", ["projects/*", 100, None, None, None, None, [1]]) + rows2 = rows_of(r2["frame"]) + print( + json.dumps( + {"arm": 2, "status": r2["status"], "errors": r2["errors"], "rows": len(rows2)} + ) + ) + + token = next((s for s in (f1 or [])[1:] if isinstance(s, str) and s), None) + if token: + r3 = await w.call("UpteDb", ["projects/*", 21, token, None, None, None, [1]]) + rows3 = rows_of(r3["frame"]) + ids1 = {r[0] for r in rows1} + overlap = sum(1 for r in rows3 if r[0] in ids1) + print( + json.dumps( + { + "arm": 3, + "status": r3["status"], + "errors": r3["errors"], + "rows": len(rows3), + "overlap_with_page1": overlap, + "token_len": len(token), + } + ) + ) + else: + print(json.dumps({"arm": 3, "skipped": "no string token slot in arm 1 frame"})) + + if rows1: + pid = rows1[0][0] + r4, title = await spike1227.title_of(w, pid) + print( + json.dumps( + { + "arm": 4, + "project": str(pid)[:8], + "status": r4["status"], + "frame_slots": [shape(s) for s in (r4["frame"] or [])], + "title_is_str": isinstance(title, str), + } + ) + ) + + +if __name__ == "__main__": + asyncio.run(main())