Skip to content

feat: add lifecycle-aware compact re-entry for llmdoc - #31

Merged
Disdjj merged 1 commit into
mainfrom
dev_compact_message
Jul 28, 2026
Merged

feat: add lifecycle-aware compact re-entry for llmdoc#31
Disdjj merged 1 commit into
mainfrom
dev_compact_message

Conversation

@wh1teAlter

Copy link
Copy Markdown
Collaborator

PR Description:

Summary

This PR makes llmdoc context loading lifecycle-aware and prevents Codex compaction from repeatedly replaying the entire startup package.

It introduces separate cold-start, resume, and compact re-entry paths, adds a compact LLMDOC_STATE contract, and keeps startup context
bounded for monolith repositories.

Motivation

Previously, the SessionStart hook matched startup, resume, clear, and compact through the same path.

Because Codex runs SessionStart(source=compact) after manual and automatic compaction, every compaction instructed the model to reload:

  • the llmdoc skill
  • llmdoc/index.md
  • llmdoc/startup.md
  • all listed MUST documents
  • related task documentation

In large repositories, this repeatedly consumed the restored context window and could trigger additional compactions.

What Changed

Lifecycle-aware context loading

Lifecycle source Behavior
━━━━━━━━━━━━━━━━━━
startup, clear Perform one cold-start read of the skill and startup package
──────────────────
resume Reuse a valid LLMDOC_STATE; fall back to one cold start when unavailable or stale
──────────────────
compact Continue from the compact summary without replaying previously loaded llmdoc content

Compact re-entry now refreshes documentation only when:

  • the startup fingerprint changed
  • a relevant document changed
  • the task enters a new subsystem
  • the preserved state is insufficient
  • validation or evidence conflicts

Bounded startup context

  • Defines the startup package as index.md + startup.md + must/
  • Adds a default 24 KiB startup-package budget
  • Generates a stable fingerprint from file digests, sizes, and relative paths
  • Treats the root index as an L0 router
  • Recommends L1 subsystem indexes for monolith repositories
  • Avoids loading a repository-wide leaf-document catalog

Codex integration

  • Adds a bundled lifecycle-aware hooks/hooks.json
  • Splits SessionStart into dedicated cold, resume, and compact matchers
  • Produces no compact-hook output for repositories without llmdoc
  • Adds an optional compact prompt template for preserving structured LLMDOC_STATE
  • Keeps the more opinionated Stop hook opt-in
  • Updates Stop output to the supported systemMessage shape

Validation and documentation

  • Adds verify-lifecycle-hooks.sh to prevent matcher and no-reload regressions
  • Documents the context lifecycle architecture and hook maintenance workflow
  • Updates the core skill, init/update contracts, recorder guidance, examples, and public READMEs
  • Synchronizes the Claude and Codex plugin versions to 2.3.0
  • Adds a reflection capturing the original lifecycle design gap

Compatibility and Rollout

There are no breaking command or API changes.

Plugin users should note:

  • Codex will require the bundled hook to be reviewed and trusted
  • bundled and repo-local copies of the same hook should not be enabled together
  • the compact prompt override remains optional and is not enabled automatically
  • existing installations must reinstall or upgrade the plugin and start a new thread to load the new lifecycle behavior

Validation

  • Lifecycle matcher and compact no-reload verification passed
  • Cold-start and compact fingerprints match for the same repository state
  • Non-llmdoc compact hook produces no output
  • Bash syntax validation passed
  • Hook and plugin JSON validation passed
  • Codex plugin validation passed
  • llmdoc, llmdoc-init, and llmdoc-update skill validation passed
  • Startup package is 6696 bytes, below the 24576 byte budget
  • English and Chinese documentation updated
  • Stable llmdoc architecture, guide, routing, and reflection documents synchronized

- Introduced a clear distinction between cold start and compact re-entry for llmdoc, ensuring the startup pack is only loaded once at cold start.
- Updated documentation to reflect the new lifecycle rules, including the handling of LLMDOC_STATE during context compaction.
- Improved routing and indexing strategies to maintain a bounded startup context, with a default size limit of 24 KiB for startup-related documents.
- Added new guides and references for lifecycle hooks and context management, ensuring better alignment with Codex integration.
- Updated plugin metadata to reflect changes in functionality and improved user guidance.

This commit aims to streamline the llmdoc workflow, enhance performance, and ensure clarity in the lifecycle processes.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@Disdjj
Disdjj merged commit 1ad676f into main Jul 28, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants