# Learnitive autonomous continuation handoff

## Objective
Maintain and deploy the completed independent Learnitive fork. The current next operational phase is the user-authorized direct production cutover at `https://www.learnitive.com` from a package extracted to `/var/www/learnitive.com`, using the guarded root `./run.sh` workflow.

## Absolute production-isolation rule
Interactive Shell production is read-only and forbidden to mutate. Never change, stop, restart, reload, migrate, prune, delete, overwrite or reuse its website, database, service, container, network, volume, path, port, certificate, vhost or deployment configuration. Any conflict must abort. For the operator-requested www cutover only, the package may install Learnitive-only vhost files and issue one guarded `apache2ctl graceful` after configtest and protected Apache-file before/after snapshots; it must never modify Interactive Shell Apache files, modules or certificates.

## Current completed product state
- Learnitive is learning/research/writing-first with Markdown default, LaTeX first-class, Code advanced/collapsed.
- Brand primary `#DA0B4E`; raw-red foreground is white.
- Supplied logo/favicon and Editor/Terminal/AI Builder homepage images are authoritative.
- Homepage: writer-first interactive hero → Explore Learnitive → Learnitive vs Overleaf → Free + $29 Lifetime Pro → FAQ → final CTA → footer.
- `/compare` and `/compare/overleaf` are curated public comparison surfaces; developer comparison/migration/software-catalog surfaces remain hidden at launch.
- BYOK is Pro; local AI/Ollama remain according to current entitlement policy.
- Legacy 10-character content-code activation remains transactional and checked before Payhip fallback.

## Completed staging/cutover implementation
- Approved staging origin: `https://edu.learnitive.com`.
- Staging application root: `/var/www/edu.learnitive.com/public_html`.
- Production origin/root: `https://www.learnitive.com`, `/var/www/learnitive.com/public_html`.
- Legacy `os.learnitive.com` recognition remains only as backward-compatible staging adoption logic.
- Edu vhost now mirrors production API/WebSocket/SSR routing and adds mandatory noindex protection.
- Staging noindex is enforced by HTTP header, server-rendered metadata, client hydration and `robots.txt: Disallow /`.
- Browser canonical/social metadata stays on edu during staging and on www in production.
- Staging env template is `deploy/config/learnitive-edu.env.example`; fresh staging keeps SaaS disabled and passwordless email off by default.
- GitHub OAuth callback follows the active edu/www profile.
- The production wrapper now activates the supplied edu→www redirect automatically only after the production application passes local acceptance; the root launcher performs the read-only ingress preflight first, and the old edu filesystem tree remains untouched.
- The core installer remains external-ingress-only. The operator-requested production wrapper performs only the guarded Learnitive vhost cutover after core acceptance; it does not run Certbot/a2ensite/a2dissite, does not change Apache modules, and uses `apache2ctl graceful` only after configtest/protected-file snapshots pass.
- New staging verifiers: `scripts/verify-edu-local-vhost.sh`, `scripts/verify-edu-staging.mjs`.
- Production verifiers updated: `scripts/verify-www-local-vhost.sh`, `scripts/verify-www-seo-cutover.mjs`.
- Detailed operator docs: `EDU_STAGING.md`, `WWW_CUTOVER.md`, `DIRECT_WWW_INSTALL.md`.
- Audit report: `STAGING_AUDIT_2026-09-15.md`.
- Packaged source artifact: `learnitive-v58-edu-staging-www-cutover-audited-final.zip` with root `run.sh` plus `public_html/`; use the external SHA-256 sidecar as authoritative.

## Verification
- Canonical dependency-light current release audit: **481/481 PASS**.
- Release-quality orchestration: **PASS**.
- Targeted staging/server tests: **79/79 PASS** before consolidation.
- Shell syntax: **23/23 PASS**.
- Changed JS/MJS `node --check`: PASS.
- Package JSON parse: PASS.
- Apache source template syntax: **7/7 Syntax OK** under an isolated non-mutating syntax fixture.
- Isolation, namespace, branding, SEO-hardening, public-assets, theme, writer-launch and autonomous-handoff gates: PASS.

## Deployment model
This release intentionally uses a sequential promotion model. Edu staging and www production reuse the Learnitive service/config identities during promotion; they are not designed to run permanently side by side. If edu must remain a long-lived staging environment after www launch, first give staging independent config/service names, ports, Redis/container/queue namespace, database/user and preview origin.

## Environment limitation
The source-audit workspace does not have the project PNPM dependency installation needed to claim full dependency-backed build/lint/Playwright. Those gates must run on CI or the prepared staging host before production cutover.

## Exact next operational phase
1. Extract/publish the verified release under `/var/www/edu.learnitive.com/public_html`.
2. Configure staging-safe credentials only where required.
3. Run staging installer with `LEARNITIVE_DEPLOYMENT_PROFILE=staging`.
4. Provision edu DNS/TLS on the independent Learnitive ingress and run its config syntax test before activation.
5. Run `bash scripts/verify-edu-local-vhost.sh` on the host.
6. Run `node scripts/verify-edu-staging.mjs` against public edu.
7. Run `pnpm lint:ci`, `pnpm test:ci`, `pnpm build`, `pnpm local-ci-check`, relevant Playwright suites and manual smoke tests (auth, Markdown/LaTeX, PDF, AI, Learn/course playback, collaboration, terminal/WebSocket, persistence, mobile, pricing/licensing, noindex).
8. Freeze the exact accepted release.
9. Promote the same release to `/var/www/learnitive.com/public_html` with the production root launcher/profile.
10. Activate independent www/apex ingress and DNS.
11. Run `bash scripts/verify-www-local-vhost.sh` and `node scripts/verify-www-seo-cutover.mjs`.
12. Only after www acceptance, optionally retire edu or activate the supplied edu→www one-hop redirect templates.
13. Repeat the read-only Interactive Shell before/after non-interference audit.

## Recommendations / cautions
- Public noindex staging is not private; use Cloudflare Access or equivalent if confidentiality is required.
- If staging SaaS uses `learnitive_os`, staging relational data is production-bound unless cleaned. For destructive QA/long-lived staging use a dedicated staging DB.
- Use staging-specific OAuth, SMTP, Turnstile, analytics and licence-provider credentials.
- Never solve a port/service/ingress/database conflict by changing Interactive Shell.

## Autonomous execution rules
Identify current state, start at the first incomplete phase, execute all remaining phases sequentially, verify each phase, diagnose/fix/retest failures, do not ask for confirmation between routine phases, preserve existing decisions, and only stop for genuinely unknowable information, required credentials/permission, irreversible high-impact actions requiring approval, or substantial risk of pursuing the wrong objective.

## Quality-control loop
Execute → Verify → Identify problems → Fix → Verify again → Continue.

## Context handoff rule
If the chat approaches its practical context limit, finish the current safe subtask if possible; record completed phases, exact current phase/status, remaining phases, decisions, assumptions, requirements, dependencies, tests, failures/fixes, artifacts and risks; then produce a complete self-contained continuation prompt preserving these rules and this handoff rule.

Continue autonomously from this exact state. Do not restart completed phases. Do not ask for confirmation. Execute all remaining phases sequentially, verify each phase, fix problems, and continue until the project is complete. If this chat again approaches its context limit, generate another complete continuation prompt for the next chat before stopping.

## Latest implemented state — writer AI homepage + office (2026-09-15)
- Base release includes the edu staging service-ownership and Docker-network-owner hotfixes.
- Create Project opens Markdown by default; selecting Code chooses Python and removes Markdown/LaTeX selection, while later explicit code choices remain user-controlled.
- Homepage H1 is `Privacy First Research` / `Writing Platform` with reduced responsive sizing.
- Functional homepage AI writing composer is mounted immediately after the hero and before Explore Learnitive. It reuses canonical auth, Pro gate, global AI Settings/provider readiness, single-use pending handoff, CreateWorkspaceDialog and agent workflow.
- Writer starters: Research Paper, Essay, Study Notes, Literature Review, LaTeX, Report, Article; More includes Thesis, Dissertation, Book Chapter, Proposal, Lab Report, Case Study, Meeting Notes, Summary, Study Guide, Flashcards and Markdown.
- General writing defaults to Markdown; explicit LaTeX stays LaTeX; explicit code/software prompts still route to advanced code starters.
- About first image is `/learnitive-office.webp`; do not describe it as a factual headquarters/location.
- Current verification: canonical release audit **490/490 PASS**; release-quality orchestration PASS; shell **23/23**; strict JSON **177/177**; JS/MJS/CJS **382/382**; TS/TSX parse **1076/1076**.
- Dependency-backed pnpm/build/browser gates remain staging-host/CI work because project dependencies are not installed in this audit workspace.


Continue autonomously from this exact state. Do not restart completed phases. Do not ask for confirmation. Execute all remaining phases sequentially, verify each phase, fix problems, and continue until the project is complete. If this chat again approaches its context limit, generate another complete continuation prompt for the next chat before stopping.

## Latest implemented state — LaTeX hero, prompt actions, source-backed reviews and social assets (2026-09-15)
- Homepage hero H1 retains `Privacy First Research` / `Writing Platform` with the smaller authoritative responsive sizing.
- Hero workspace is now a Learnitive LaTeX research editor using `main.tex`, references, figures, analysis and notes, with interactive Source/Visual reveal, Compile state and synchronized PDF preview. Toolbar/status cues include Navigator, TikZ, Terminal, AI Review, Review, Tools and TexLab; no TeXise namespace is introduced.
- `What will you write today?` now has a separate icon-labelled `Try a prompt` action row. Prompt actions fill the composer without auto-submit and preserve manually edited text.
- Icon-labelled project starters remain separate under `Start with a project`: Research Paper, Essay, Study Notes, Literature Review, LaTeX, Report, Article, More.
- Homepage reviews now use source-backed identities only: Han Lee / Trustpilot, Amit Jaiswal / DealMirror, plus the existing named first-party Learnitive testimonials. No G2 review, unsupported review count, invented aggregate rating or third-party verification badge is presented.
- Review cards use a two-direction desktop marquee with accessibility-safe duplicate cards and a reduced-motion/mobile snap layout.
- About value icons are white on raw Learnitive red.
- About bottom carousel uses `/learnitive-team3.webp` and `/learnitive-office3.webp`; existing carousel accessibility and motion rules remain.
- `/learnitive-og.webp` is the default browser + SSR OG/Twitter image at 1731×909. Team/office assets are 1672×941.
- Canonical public-assets audit requires all three supplied WebP files.
- Verification: targeted bundle **68/68 PASS**; canonical current release audit **501/501 PASS**; release-quality orchestration PASS; isolation guard **398 files**; namespace audit **1483 active text files**; public-assets **16 required assets**; brand/SEO/theme/writer-launch/autonomous-handoff gates PASS.
- Packaging workspace still lacks installed project dependencies, so dependency-backed pnpm/build and browser Playwright execution must run on staging/CI before production promotion.
- Candidate artifact: `learnitive-v58-writer-latex-prompts-real-reviews-final.zip`; use its external SHA-256 and verification report after packaging as authoritative.

Continue from this exact state under the AUTO quality loop. Preserve strict Interactive Shell production isolation. Do not revert the LaTeX hero, icon-labelled prompt/project controls, source-backed reviews, supplied social/team/office assets or the writer-first launch positioning.

## Latest implemented state — homepage pricing + AI format refinement (2026-09-15)
- Home pricing heading, supporting copy, auth/collaboration note, purchased-license action and Compare plans action are explicitly centered; plan-card internals remain left aligned.
- Desktop customer-review marquee has dedicated responsive top/bottom padding while retaining source-backed Trustpilot/DealMirror links, opposing directions and reduced-motion/mobile behavior.
- Simulated LaTeX source/code panes are explicitly left aligned and line numbers remain right aligned.
- Homepage `Privacy First Research` / `Writing Platform` title is reduced again to the new authoritative desktop/mobile scale.
- `What will you write today?` now has a dedicated icon-labelled Output format selector with Markdown and LaTeX. Markdown is default; selecting the LaTeX project starter switches to LaTeX; other writer starters switch back to Markdown; the user may override afterward.
- Output format is part of `PendingHomeAiIntent`, survives login/sessionStorage handoff, and is honored by the canonical CreateWorkspaceDialog. Legacy/explicit advanced code intents still take precedence over document format.
- Missing Agent-capable AI no longer jumps straight into settings. Eligible users first see `Set up AI to continue` with Not now / Set up AI actions; Set up AI opens the existing global AI Settings and successful configuration resumes the single pending creation once.
- The old passive `AI creation requires Pro, sign-in and a configured AI provider.` footer note is removed. Login, Pro entitlement and provider requirements are handled contextually.
- Added source-level Playwright coverage for Markdown/LaTeX selection and anonymous handoff persistence, plus focused dependency-light regression coverage for pricing alignment, review padding, LaTeX alignment, output-format persistence and AI setup prompting.
- Current dependency-light canonical audit after these changes: **506/506 PASS**.
- No live server, Interactive Shell resource, shared ingress, database, service, container, network or firewall was modified.
- Dependency-backed pnpm/build/Playwright execution remains staging/CI acceptance work because this packaging workspace has no local project dependencies installed.

Continue autonomously from this exact state. Do not restart completed phases. Do not ask for confirmation. Execute all remaining phases sequentially, verify each phase, fix problems, and continue until the project is complete. If this chat again approaches its context limit, generate another complete continuation prompt for the next chat before stopping.

## Latest implemented state — home AI simplification + dynamic Interactive Shell sandbox isolation hotfix (2026-09-16)
- The previous edu staging run built and activated Learnitive successfully but the final read-only Interactive Shell baseline produced a false positive because normal production traffic created/destroyed `interactive-shell-guest-*` sandboxes during the deployment window.
- Host evidence showed permanent Interactive Shell containers/networks retained their IDs and restart counts; the changing objects were expected guest runtime sandboxes.
- `scripts/learnitive-protected-production-baseline.mjs` now excludes only expected `interactive-shell-guest-*` and `interactive-shell-dev-u*` runtime containers from immutable container identity while continuing to compare protected networks and all other matching infrastructure containers.
- Genuine Docker infrastructure differences now name the exact added/removed/changed container or network and write a retained `.after.json` snapshot for forensics.
- `deploy/learnitive/install-staging.sh` retains failed before/after baseline files and avoids duplicate EXIT verification after an explicit final baseline failure.
- Homepage AI no longer renders the redundant `Start with a project` section or the LaTeX/More homepage cards.
- The AI writer is now a focused flow: `Describe your project`, clearer research/writing placeholder, labelled `Add context`, shortcut hint, `Create project`, icon-labelled `Popular writing tasks`, then explicit Markdown/LaTeX output format.
- Markdown stays default; LaTeX remains first-class and persists through login and AI setup. Prompt suggestions populate without auto-submit or overwriting manually edited copy.
- Current verification: focused bundle 21/21 PASS; canonical current-release audit 509/509 PASS; release-quality orchestration PASS; writer-launch/isolation/namespace/brand/SEO/assets/theme/AUTO gates PASS.
- Next step is edu staging deployment of the new packaged hotfix and a full `./run.sh` rerun. The parent staging build/runtime/template/queue/LaTeX checks already passed before the old false-positive baseline stopped acceptance.

## Latest implemented state — direct www production package + top-nav Learn removal (2026-09-16)
- Shared `PUBLIC_PRIMARY_NAV` no longer contains `Learn`, so desktop/mobile public headers and `/projects` omit that top-menu link. `/learn` routes and Learn product content remain available.
- Production package root remains `run.sh` + complete `public_html/` and is intended to be extracted directly into `/var/www/learnitive.com/`.
- Root `./run.sh` performs a read-only Apache/TLS preflight before stopping Learnitive services, promotes filesystem-backed state from edu when present, runs the production profile, normalizes active paths, then activates the Learnitive vhosts.
- Production vhost activation serves `www.learnitive.com`, redirects apex to www, redirects edu to www, preserves path/query, and leaves `legacy.learnitive.com`/`preview.learnitive.com` untouched.
- Existing enabled vhost owners are auto-migrated only if every declared hostname is one of www/apex/edu; mixed-domain files fail closed.
- TLS is discovered from existing `/etc/letsencrypt/live` certificates or explicit host-specific overrides. Certbot is never run.
- Previous Learnitive Apache site state is backed up under `/var/backups/learnitive/apache-vhosts/`; activation failure restores it and clears the www release-success marker.
- Protected Interactive Shell Apache files are snapshotted before/after; only Learnitive site files are written. Apache modules are not changed. Activation uses configtest then one guarded `apache2ctl graceful`.
- Current dependency-light verification: focused cutover/navigation suite **28/28 PASS**; canonical current release audit **511/511 PASS**; release-quality orchestration PASS including namespace/brand/SEO/assets/theme/writer-launch/AUTO/isolation/lock/dependency/barrel gates.
- Target-host prerequisites still matter: existing valid TLS for www/apex/edu and DNS/edge pointing to the host. The package checks TLS locally before service mutation but cannot change external DNS.

Continue from this exact production-ready state. On the target host, extract into `/var/www/learnitive.com`, run `./run.sh` as root, capture any preflight failure verbatim, and do not bypass certificate/vhost/protected-product safeguards.

Continue autonomously from this exact state. Do not restart completed phases. Do not ask for confirmation. Execute all remaining phases sequentially, verify each phase, fix problems, and continue until the project is complete. If this chat again approaches its context limit, generate another complete continuation prompt for the next chat before stopping.

## Latest implemented state — production Cloud Terminal WSS cutover-order hotfix (2026-09-16)
- Target-host production run passed 521/521 release audit, dependency install/build, SaaS schema 64 preflight, Redis, secret helper, Universal Runner, Packages + Git proxy, Console Gateway and main app readiness.
- It failed at the terminal acceptance smoke with `Unexpected server response: 404` on the public www WebSocket route.
- Console Gateway logs showed the smoke guest sandbox was created and destroyed correctly, so the private gateway/Docker path was functioning.
- Root cause is deployment ordering: the core application installer runs before root `run.sh` activates the new Learnitive-only www/apex/edu Apache vhosts. The old smoke required `wss://www.learnitive.com/console-gateway/...` before the vhost that defines `/console-gateway/ -> 127.0.0.1:9887` was active.
- Fix: for the `www` profile, `deploy/learnitive/install-staging.sh` certifies loopback WebSocket -> Console Gateway -> Docker -> PTY before cutover. Staging retains the public HTTPS WebSocket smoke because staging ingress already exists.
- `scripts/verify-www-local-vhost.sh` now certifies the real public `wss://www.learnitive.com/console-gateway/...` path after Apache cutover by running the same authenticated terminal smoke with www forced to 127.0.0.1. Failure causes the existing vhost activator rollback path to restore the previous Learnitive Apache state.
- No protected Interactive Shell resource is touched and no Learnitive Docker network is relabelled/recreated/deleted.
- Verification: focused installer/www suite 17/17 PASS; shell syntax PASS; canonical current-release audit 521/521 PASS; release-quality orchestration PASS.
- Candidate artifact: `learnitive-v58-www-production-wss-cutover-order-hotfix-final.zip` plus SHA-256 and verification report.

Continue from this exact state. Deploy the new package into `/var/www/learnitive.com` and rerun `./run.sh`. Expected sequence is private terminal PTY smoke -> remaining installer acceptance -> installer success -> guarded Learnitive-only Apache activation -> post-cutover public www WSS + PTY certification -> local www/apex/edu verification -> final production completion. Do not bypass rollback/protected-product safeguards or manually relabel/remove Docker networks.

Continue autonomously from this exact state. Do not restart completed phases. Do not ask for confirmation. Execute all remaining phases sequentially, verify each phase, fix problems, and continue until the project is complete. If this chat again approaches its context limit, generate another complete continuation prompt for the next chat before stopping.


## Latest implemented state — production root-launcher contract hotfix (2026-09-16)
- Host run proved the WSS-order fix: private loopback terminal smoke, templates, queue, LaTeX and full production installer all passed.
- Apache still served the old Learnitive vhost and www returned 404. The root launcher never printed its post-installer `Installing and verifying ... cutover vhosts` line.
- The release's root `run.sh` does contain that activation step, so the host was running a stale/custom root launcher while `public_html` was current.
- Root `run.sh` now exports `LEARNITIVE_WWW_ROOT_LAUNCHER_CONTRACT=www-vhost-cutover-v4`. `deploy/learnitive/install-production-www.sh` requires the exact value and aborts immediately if the root launcher was not replaced.
- Core installer remains external-ingress-only; the dedicated production wrapper calls `install-www-vhosts.sh --activate` before it returns, while root `run.sh` owns the preflight and v4 launch contract.
- Immediate recovery on the already-accepted host is safe through the existing guarded helper: `public_html/deploy/learnitive/install-www-vhosts.sh --preflight` then `--activate`, which snapshots/changes only Learnitive vhosts, configtests, gracefully reloads, runs local www/apex/edu + public WSS/PTy verification, and rolls back on failure.

Continue from this state. Ensure the complete release replaces both root `run.sh` and `public_html`. Never bypass the new launcher contract, and never modify Interactive Shell resources.

Continue autonomously from this exact state. Do not restart completed phases. Do not ask for confirmation. Execute all remaining phases sequentially, verify each phase, fix problems, and continue until the project is complete. If this chat again approaches its context limit, generate another complete continuation prompt for the next chat before stopping.


## 2026-09-16 — production Apache commit ownership hotfix

- A second target-host run proved the v3 contract alone was insufficient: the full child installer returned success, but no post-child root-launcher cutover log appeared and Apache still served the old Learnitive vhost (public www returned 404).
- Root `run.sh` now exports `LEARNITIVE_WWW_ROOT_LAUNCHER_CONTRACT=www-vhost-cutover-v4` and performs the read-only vhost/TLS preflight before any application mutation.
- `deploy/learnitive/install-production-www.sh` no longer `exec`s the core installer. It runs the core installer as a child, normalizes any remaining Learnitive staging-root config references, then invokes the existing guarded `install-www-vhosts.sh --activate` itself before returning success.
- Therefore public www activation no longer depends on root `run.sh` resuming after the child process. If Apache activation or public WSS/PTy verification fails, the vhost helper rolls back and the production wrapper clears the www successful-release marker.
- The core `install-staging.sh` remains Apache/external-ingress agnostic and now logs clearly that www Apache cutover is the next mandatory wrapper step.
- The old `/etc/apache2/sites-available/learnitive.com*.conf` files are intentionally left untouched as rollback/source history; successful activation is visible in `/etc/apache2/sites-enabled/`, `apache2ctl -S`, and the canonical `www.learnitive.com-*.conf` files.

Continue autonomously from this exact state. Do not restart completed phases. Do not ask for confirmation. Execute all remaining phases sequentially, verify each phase, fix problems, and continue until the project is complete. If this chat again approaches its context limit, generate another complete continuation prompt for the next chat before stopping.
