pi-usereq 0.38.0 → 0.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  ---
2
2
  title: "PI-useReq Requirements"
3
3
  description: Software requirements specification
4
- version: "0.0.68"
5
- date: "2026-05-29"
4
+ version: "0.0.71"
5
+ date: "2026-07-10"
6
6
  author: "OpenAI Codex"
7
7
  scope:
8
8
  paths:
@@ -89,6 +89,7 @@ PI-useReq is a TypeScript pi extension plus companion Node CLI and standalone ex
89
89
  - **DES-010**: MUST centralize event-driven context snapshots, run-timing state, prompt-orchestration workflow state, and status-bar rendering through shared extension-status helpers.
90
90
  - **DES-011**: MUST implement `.github/workflows/release-npm.yml` as a two-job GitHub Actions pipeline where `check-branch` gates `build-release`, preserving changelog-driven GitHub Release creation while adding npm publication.
91
91
  - **DES-015**: MUST implement config-gated `debug-compress`, `debug-references`, `debug-static-check`, and `debug-tokens` slash-command wrappers in `src/index.ts` that reuse existing tool-runner execution paths.
92
+ - **DES-016**: MUST deliver rendered bundled-prompt content to the LLM through `sendMessage` as a `display:false` custom message with `triggerTurn:true` and MUST NOT use `sendUserMessage` when `sendMessage` is available.
92
93
 
93
94
  ### 3.2 Functions
94
95
  - **REQ-001**: MUST access bundled prompts, git execution instructions, templates, and guidelines from `<installation-path>/resources` without requiring user-home resource copies before prompt or tool execution.
@@ -157,6 +158,10 @@ PI-useReq is a TypeScript pi extension plus companion Node CLI and standalone ex
157
158
  - **REQ-066**: MUST omit `reset-context` and `context-reset` fields from persisted local and global configuration.
158
159
  - **REQ-067**: MUST send every bundled prompt-backed `req-<prompt>` payload into the current active session.
159
160
  - **REQ-068**: MUST use one prompt-delivery path that sends bundled prompt-backed `req-<prompt>` payloads through the forked execution session by using only the replacement-session context for post-switch session-bound operations.
161
+ - **REQ-334**: MUST NOT display rendered prompt content on screen when delivering bundled prompt-backed `req-<prompt>` commands and MUST deliver the full rendered content only to the LLM agent.
162
+ - **REQ-335**: MUST display a command invocation summary on screen for every bundled prompt-backed `req-<prompt>` command containing the command name, passed arguments, and active configuration.
163
+ - **REQ-336**: MUST render the command invocation summary with the command name without the `req-` prefix in uppercase and the user request arguments.
164
+ - **REQ-337**: MUST include `docs-dir`, `src-dir`, `tests-dir`, enabled context files, `AUTO_GIT_COMMIT`, effective `GIT_WORKTREE_ENABLED`, `GIT_WORKTREE_PREFIX`, enabled static-check languages, and `enabled-tools` in the command invocation summary.
160
165
  - **REQ-008**: MUST provide a `Language static code checkers` submenu that adds global Command entries by guided language flow, removes configured global checker entries, toggles local per-language enablement, and resets static-check configuration.
161
166
  - **REQ-160**: MUST hardcode `Command` as the only user-configurable static-check module and omit module-selection UI from static-check configuration menus.
162
167
  - **REQ-161**: MUST hide `Dummy` from user-configurable static-check menus while preserving existing-config parsing and debug-driver support for `Dummy` entries.
@@ -222,8 +227,8 @@ PI-useReq is a TypeScript pi extension plus companion Node CLI and standalone ex
222
227
  - **REQ-186**: MUST substitute `%%PROMT%%`, `%%BASE%%`, `%%TIME%%`, `%%ARGS%%`, and `%%RESULT%%` at runtime inside `Pushover title` and `Pushover text`.
223
228
  - **REQ-187**: MUST render `%%BASE%%` as static `base-path` relative to user home using `~/...` form and `%%TIME%%` as final elapsed `M:SS`.
224
229
  - **REQ-188**: MUST label notification-event rows as `Prompt completed`, `Prompt interrupted`, and `Prompt failed`.
225
- - **REQ-190**: MUST label top-level rows as `Document directory`, `Source-code directories`, `Unit tests directory`, `Auto git commit`, `Git worktree`, `Worktree prefix`, `Language static code checkers`, `Enable tools`, `Notifications`, `Debug`, `Show local configuration`, and `Show global configuration`.
226
- - **REQ-191**: MUST order top-level rows as `Document directory`, `Source-code directories`, `Unit tests directory`, `Auto git commit`, `Git worktree`, `Worktree prefix`, `Language static code checkers`, `Enable tools`, `Notifications`, and `Debug`.
230
+ - **REQ-190**: MUST label top-level rows as `Document directory`, `Source-code directories`, `Unit tests directory`, `Context Files`, `Auto git commit`, `Git worktree`, `Worktree prefix`, `Language static code checkers`, `Enable tools`, `Notifications`, `Debug`, `Show local configuration`, and `Show global configuration`.
231
+ - **REQ-191**: MUST order top-level rows as `Document directory`, `Source-code directories`, `Unit tests directory`, `Context Files`, `Auto git commit`, `Git worktree`, `Worktree prefix`, `Language static code checkers`, `Enable tools`, `Notifications`, and `Debug`.
227
232
  - **REQ-320**: MUST order `Show local configuration` after `Debug`, `Show global configuration` after `Show local configuration`, and `Reset defaults` last.
228
233
  - **REQ-192**: MUST preserve the selected settings-menu row after toggling or editing a setting value.
229
234
  - **REQ-193**: MUST append `Reset defaults` as a final row without right-aligned value text in every configuration menu and descendant selector menu, and MUST NOT render `Save and close`.
@@ -388,11 +393,19 @@ PI-useReq is a TypeScript pi extension plus companion Node CLI and standalone ex
388
393
  - **REQ-323**: MUST register `debug-compress`, `debug-references`, `debug-static-check`, `debug-summarize`, and `debug-tokens` only when `DEBUG_TOOL_COMMANDS_ENABLED=enable`.
389
394
  - **REQ-324**: MUST make `debug-compress`, `debug-references`, `debug-static-check`, `debug-summarize`, and `debug-tokens` reuse the `compress`, `references`, `static-check`, `summarize`, and `tokens` runner outputs and write `content[0].text` to the editor.
390
395
  - **REQ-325**: MUST reject `debug-compress`, `debug-references`, `debug-static-check`, `debug-summarize`, and `debug-tokens` execution when `DEBUG_TOOL_COMMANDS_ENABLED=disable`.
396
+ - **REQ-326**: MUST add a top-level `Context Files` row to the `pi-usereq` menu between `Unit tests directory` and `Auto git commit`.
397
+ - **REQ-327**: MUST expose a `Context Files` submenu with separate enable toggles for `REQUIREMENTS.md`, `REFERENCES.md`, and `WORKFLOW.md` in that order.
398
+ - **REQ-328**: MUST persist `context-files-requirements`, `context-files-references`, and `context-files-workflow` as boolean flags in local configuration, each defaulting to enabled.
399
+ - **REQ-329**: MUST replace the `%%CONTEXT_FILES%%` prompt token with one markdown section per enabled context file in the order `REQUIREMENTS.md`, `REFERENCES.md`, `WORKFLOW.md`.
400
+ - **REQ-330**: MUST render each `%%CONTEXT_FILES%%` section as the file-name heading, an HTML `<file name="<docs-dir>/<filename>">` reference with `%%DOC_PATH%%` pre-substituted, and the raw file content inside four-backtick `markdown` fences.
401
+ - **REQ-331**: MUST omit the `%%CONTEXT_FILES%%` section for any disabled flag or missing context file without surfacing an error.
402
+ - **REQ-332**: MUST inject `%%CONTEXT_FILES%%` content verbatim after every other prompt replacement so literal `%%...%%` tokens inside context files are not substituted.
403
+ - **REQ-333**: MUST restore all three `Context Files` flags to enabled when the `Context Files` subtree `Reset defaults` is approved.
391
404
 
392
405
  ## 4. Test Requirements
393
406
  - **TST-001**: MUST verify extension activation registers every documented prompt command, agent tool, and configuration command while omitting tool-name slash commands, `test-static-check`, and the removed standalone config-viewer command.
394
407
  - **TST-002**: MUST verify installed bundled prompt, commit-instruction, template, and guideline resources remain readable from `installation-path`.
395
- - **TST-060**: MUST verify prompt rendering replaces `%%PROMPT%%` and expands `%%COMMIT%%` from rendered `git_commit.md` or `git_read-only.md` according to `AUTO_GIT_COMMIT`.
408
+ - **TST-060**: MUST verify prompt rendering replaces `%%PROMPT%%` and expands `%%COMMIT%%` from rendered `git_commit.md` or `git_read-only.md` according to `AUTO_GIT_COMMIT`, excluding the verbatim `%%CONTEXT_FILES%%` block from placeholder-absence assertions.
396
409
  - **TST-003**: MUST verify standalone `files-tokens` outputs match the Python oracle, `--test-static-check` dummy or command outputs match archived fixtures, and `files-summarize`, `files-compress`, plus `files-find` preserve leading source tabs.
397
410
  - **TST-004**: MUST verify project `tokens` outputs match the Python oracle, verify `files-static-check` plus `static-check` against archived fixtures, and verify `summarize`, `compress`, plus `find` preserve leading source tabs.
398
411
  - **TST-005**: MUST verify the configuration menu saves `docs-dir` locally and `AUTO_GIT_COMMIT`, `GIT_WORKTREE_ENABLED`, plus `GIT_WORKTREE_PREFIX` globally immediately after each change.
@@ -498,12 +511,17 @@ PI-useReq is a TypeScript pi extension plus companion Node CLI and standalone ex
498
511
  - **TST-065**: MUST verify default startup-tool enablement matches the documented enabled and disabled tool matrix.
499
512
  - **TST-110**: MUST verify `Enable tools` toggles, enable-all, disable-all, and reset-defaults persist only in global configuration.
500
513
  - **TST-066**: MUST verify `req-<prompt>` commands keep working when extension custom-tool registrations are removed from the runtime inventory.
514
+ - **TST-121**: MUST verify bundled prompt-backed `req-<prompt>` commands deliver the full rendered prompt content through the fallback `sendUserMessage` channel when the runtime does not expose `sendMessage`.
501
515
  - **TST-059**: MUST verify every agent-tool registration defines custom `renderResult` and that compact rendering shows essential invocation parameters while expanded rendering avoids fallback raw-content display.
502
516
  - **TST-086**: MUST verify bundled prompt-backed `req-<prompt>` commands abort before prompt dispatch when the persisted execution-session header cwd or `process.cwd()` differs from the expected execution path, and abort before merge when persisted execution-session header metadata or verified worktree artifacts diverge, while stale pre-switch context probes alone do not abort.
503
517
  - **TST-113**: MUST verify default local configuration persists `DEBUG_TOOL_COMMANDS_ENABLED=disable`, and the `Debug` submenu renders `Enable debug commands for tools` before `Log file`.
504
518
  - **TST-114**: MUST verify the `Debug` submenu persists `DEBUG_TOOL_COMMANDS_ENABLED` through immediate-save, reset, and focus-preserving re-render flows.
505
519
  - **TST-115**: MUST verify extension activation registers `debug-compress`, `debug-references`, `debug-static-check`, `debug-summarize`, and `debug-tokens` only when `DEBUG_TOOL_COMMANDS_ENABLED=enable`.
506
520
  - **TST-116**: MUST verify `debug-compress`, `debug-references`, `debug-static-check`, `debug-summarize`, and `debug-tokens` write the same `content[0].text` as `compress`, `references`, `static-check`, `summarize`, and `tokens`, and reject execution when disabled.
521
+ - **TST-117**: MUST verify the `pi-usereq` menu renders `Context Files` between `Unit tests directory` and `Auto git commit`.
522
+ - **TST-118**: MUST verify the `Context Files` submenu persists the three context-file flags in local configuration with immediate-save, reset, and focus-preserving re-render behavior.
523
+ - **TST-119**: MUST verify `%%CONTEXT_FILES%%` replacement emits one section per enabled existing file in the documented order and omits disabled or missing files.
524
+ - **TST-120**: MUST verify `%%CONTEXT_FILES%%` sections use the file-name heading, the pre-substituted HTML file reference, and four-backtick `markdown` fences around raw content.
507
525
 
508
526
  ## 5. Observed Component Model
509
527
 
@@ -573,11 +573,13 @@
573
573
  - `runCapture(...)`: run git add, commit, and status subprocesses [`src/core/req-references-command.ts`]
574
574
  - `listResidualGitStatusLines(...)`: confirm no residual git-status rows remain after commit [`src/core/req-references-command.ts`]
575
575
  - `buildIgnoredGitStatusPaths(...)`: ignore extension-owned debug-log artifacts during cleanliness verification [`src/core/req-references-command.ts`]
576
- - `renderPrompt(...)`: render prompt-command payloads with bundled commit-instruction expansion plus conditional pi.dev governance guidance [`src/core/prompts.ts`]
577
- - `deliverPromptCommand(...)`: dispatch prompt replay into the current recorded session [`src/index.ts`]
578
- - External boundaries: `RecordingExtensionAPI.sendUserMessage(...)` records the delivered prompt payload.
576
+ - `renderPrompt(...)`: render prompt-command payloads with bundled commit-instruction expansion, conditional pi.dev governance guidance, and `%%CONTEXT_FILES%%` context-file injection [`src/core/prompts.ts`]
577
+ - `buildContextFilesBlock(...)`: build the markdown block injected at `%%CONTEXT_FILES%%` from enabled context files in documented order with pre-substituted `%%DOC_PATH%%` file references and four-backtick fences [`src/core/prompts.ts`]
578
+ - `renderPromptCommandSummary(...)`: render the on-screen command invocation summary with command name, user request arguments, and active configuration fields [`src/core/prompts.ts`]
579
+ - `deliverPromptCommand(...)`: dispatch the rendered prompt as a hidden `display:false` custom message plus a `display:true` summary into the current recorded session, falling back to `sendUserMessage(...)` when `sendMessage(...)` is unavailable [`src/index.ts`]
580
+ - External boundaries: `RecordingExtensionAPI.sendMessage(...)` or fallback `RecordingExtensionAPI.sendUserMessage(...)` records the delivered prompt payload plus summary.
579
581
  - `configurePiUsereq(...)`: execute the interactive configuration menu [`src/index.ts`]
580
- - `buildPiUsereqMenuChoices(...)`: serialize top-level settings actions including effective worktree locking plus display-only local and global config-path rows [`src/index.ts`]
582
+ - `buildPiUsereqMenuChoices(...)`: serialize top-level settings actions including the `Context Files` injection toggle row, effective worktree locking, plus display-only local and global config-path rows [`src/index.ts`]
581
583
  - `formatLocalConfigPathForMenu(...)`: format the current local config path with the shared `~`-relative path formatter for menu display [`src/index.ts`]
582
584
  - `formatGlobalConfigPathForMenu(...)`: format the current global config path with the shared `~`-relative path formatter for menu display [`src/index.ts`]
583
585
  - `showPiUsereqSettingsMenu(...)`: render the shared settings-menu UI for top-level and submenu actions, keeping inline toggle rows open while rebuilding dependent rows in place [`src/core/settings-menu.ts`]
@@ -617,6 +619,9 @@
617
619
  - `resolvePiNotifyEventLabel(...)`: map one event-toggle key to the human-readable menu label [`src/index.ts`]
618
620
  - `togglePiNotifyFlag(...)`: toggle one persisted boolean notification setting [`src/index.ts`]
619
621
  - `togglePiNotifyFlag(...)`: toggle one persisted boolean notification setting [`src/index.ts`]
622
+ - `configureContextFilesMenu(...)`: interactive `Context Files` editor with inline `on|off` toggles for `REQUIREMENTS.md`, `REFERENCES.md`, and `WORKFLOW.md` plus subtree reset to all-enabled defaults [`src/index.ts`]
623
+ - `buildContextFilesMenuChoices(...)`: serialize the three context-file toggle rows plus the subtree reset terminal row [`src/index.ts`]
624
+ - `showPiUsereqSettingsMenu(...)`: render the shared settings-menu UI for inline context-file toggles and reset confirmation [`src/core/settings-menu.ts`]
620
625
  - `replayTool(...)`: replay a recorded tool execute handler and capture content/details [`scripts/lib/extension-debug-harness.ts`]
621
626
  - `registerExtensionOffline(...)`: rebuild the recorded extension registration surface [`scripts/lib/extension-debug-harness.ts`]
622
627
  - `RecordingCommandContext(...)`: initialize the recorded command-context UI adapter and deterministic theme-color encoding [`scripts/lib/recording-extension-api.ts`]
@@ -841,7 +846,7 @@
841
846
  - `cleanupPromptWorktreeCreation(...)`: rollback partial prompt-command worktree resources on verification or finalization failure [`src/core/prompt-command-runtime.ts`]
842
847
  - `promptWorktreeRegistered(...)`: test whether the sibling worktree remains registered [`src/core/prompt-command-runtime.ts`]
843
848
  - `createPromptExecutionSessionFile(...)`: fork the current persisted session into the worktree cwd when the origin session file already exists, or materialize an execution-session snapshot with header cwd=`worktree-path` plus the current in-memory branch when the origin session is not flushed yet [`src/core/prompt-command-runtime.ts`]
844
- - `renderPrompt(...)`: render prompt template with project substitutions, bundled commit-instruction expansion, extension-owned runtime guidance, and conditional pi.dev governance guidance [`src/core/prompts.ts`]
849
+ - `renderPrompt(...)`: render prompt template with project substitutions, bundled commit-instruction expansion, extension-owned runtime guidance, conditional pi.dev governance guidance, and `%%CONTEXT_FILES%%` context-file injection [`src/core/prompts.ts`]
845
850
  - `readBundledPrompt(...)`: read bundled prompt template [`src/core/resources.ts`]
846
851
  - `ensureBundledResourcesAccessible(...)`: validate installation-owned bundled resources [`src/core/resources.ts`]
847
852
  - `getBundledResourceRoot(...)`: resolve installation-owned resource root [`src/core/resources.ts`]
@@ -867,6 +872,7 @@
867
872
  - `injectPiDevConformanceBlock(...)`: add conditional pi.dev governance guidance for read-only docs, interface-contract review, and pi client validation [`src/core/prompts.ts`]
868
873
  - `buildPiDevConformanceBlock(...)`: resolve manifest-gated pi.dev governance rules for read-only docs, interface contracts, and pi client validation [`src/core/prompts.ts`]
869
874
  - `adaptPromptForInternalTools(...)`: rewrite tool names for internal wrappers [`src/core/prompts.ts`]
875
+ - `buildContextFilesBlock(...)`: build the markdown block injected at `%%CONTEXT_FILES%%` from enabled context files in documented order with pre-substituted `%%DOC_PATH%%` file references and four-backtick fences [`src/core/prompts.ts`]
870
876
  - `activatePromptCommandExecution(...)`: switch to the verified execution session through replacement-session-aware `ctx.switchSession(sessionPath, { withSession })` handling, reuse the persisted replacement-session context when later lifecycle hooks omit `switchSession()`, carry forward the returned replacement-session context for later session-bound work, re-align `process.cwd()` to the execution path, confirm `process.cwd()` plus the persisted execution-session file header cwd when the file is already persisted (treating a not-yet-flushed session file as a non-fatal lazy-persistence state because pi writes session files on first assistant flush), and store the verified runtime path plus reusable command-context state used by later tool execution and prompt-end handling [`src/core/prompt-command-runtime.ts`]
871
877
  - `resolvePromptCommandSwitchContext(...)`: prefer the live command context or fall back to the persisted replacement-session context keyed by the execution-session file [`src/core/prompt-command-runtime.ts`]
872
878
  - `switchPromptCommandSession(...)`: perform the session switch, tolerate the documented stale-extension-context side effect from invalidating the old closure, and let later verification prove whether the target session actually became active [`src/core/prompt-command-runtime.ts`]
@@ -874,10 +880,11 @@
874
880
  - `writePersistedPromptCommandSessionContext(...)`: store the reusable command-capable replacement-session context for later closure handling [`src/core/prompt-command-state.ts`]
875
881
  - `clearPersistedPromptCommandSessionContext(...)`: drop reusable command-context persistence when worktree routing is inactive [`src/core/prompt-command-state.ts`]
876
882
  - `logPromptWorkflowEvent(...)`: append selected workflow-activation debug entries [`src/index.ts`]
877
- - `deliverPromptCommand(...)`: start dispatch of the rendered prompt into the current active session after execution-session activation is verified, preferring replacement-session `sendUserMessage(...)` when available, returning the delivery promise so the final `running` transition is recorded immediately after handoff begins instead of after the full prompt run completes, and suppressing the documented stale post-restore rejection once the prompt was already accepted [`src/index.ts`]
883
+ - `renderPromptCommandSummary(...)`: render the on-screen command invocation summary with command name without the `req-` prefix in uppercase, user request arguments, and active configuration fields [`src/core/prompts.ts`]
884
+ - `deliverPromptCommand(...)`: start dispatch of the rendered prompt as a hidden `display:false` custom message with `triggerTurn:true` plus a `display:true` command invocation summary into the current active session after execution-session activation is verified, preferring replacement-session `sendMessage(...)` when available, falling back to `sendUserMessage(...)` when `sendMessage(...)` is unavailable, returning the delivery promise so the final `running` transition is recorded immediately after handoff begins instead of after the full prompt run completes, and suppressing the documented stale post-restore rejection once the prompt was already accepted [`src/index.ts`]
878
885
  - `writePersistedPromptCommandRuntimeState(...)`: mirror the prepared prompt execution plan into process-scoped persistence before the worktree session switch returns control [`src/core/prompt-command-state.ts`]
879
- - `isStaleExtensionContextError(...)`: classify stale post-restore delivery rejections from replacement-session `sendUserMessage(...)` [`src/core/extension-status.ts`]
880
- - External boundaries: replacement-session `sendUserMessage(...)` or fallback `pi.sendUserMessage(...)` delivers the rendered prompt payload into the active `AgentSession`.
886
+ - `isStaleExtensionContextError(...)`: classify stale post-restore delivery rejections from replacement-session `sendMessage(...)` [`src/core/extension-status.ts`]
887
+ - External boundaries: replacement-session `sendMessage(...)` or `pi.sendMessage(...)` delivers the hidden rendered prompt payload plus the displayed summary into the active `AgentSession`; fallback replacement-session `sendUserMessage(...)` or `pi.sendUserMessage(...)` delivers the rendered prompt payload when `sendMessage(...)` is unavailable.
881
888
  - `abortPromptCommandExecution(...)`: restore the original session-backed base path and delete created worktree resources when command-side preflight or prompt handoff fails [`src/core/prompt-command-runtime.ts`]
882
889
  - `restorePromptCommandExecution(...)`: switch back to the original session through replacement-session-aware `ctx.switchSession(sessionPath, { withSession })` handling, reuse the persisted replacement-session context when lifecycle hooks omit `switchSession()`, carry forward the returned replacement-session context for later session-bound work, re-align `process.cwd()` to `base-path`, confirm `process.cwd()` plus the persisted original-session file header cwd when the file is already persisted, append optional workflow-restore debug entries, clear active worktree path facts, and best-effort realign the live `ctx.cwd` mirror when worktree routing was active without failing on stale or getter-only context mirrors [`src/core/prompt-command-runtime.ts`]
883
890
  - `resolvePromptCommandSwitchContext(...)`: prefer the live command context or fall back to the persisted replacement-session context keyed by the execution-session file [`src/core/prompt-command-runtime.ts`]
@@ -1116,7 +1123,7 @@
1116
1123
  - `formatPiNotifyBasePath(...)`: render `%%BASE%%` as `~`-relative when possible [`src/core/pi-notify.ts`]
1117
1124
  - `formatPiNotifyDuration(...)`: render `%%TIME%%` as `M:SS` [`src/core/pi-notify.ts`]
1118
1125
  - `formatPiNotifyResult(...)`: map prompt-end outcomes to `successed|aborted|failed` [`src/core/pi-notify.ts`]
1119
- - `configurePiUsereq(...)`: interactive configuration menu runtime root for directories, `Auto git commit`, locked-or-editable worktree rows, tools, notifications, and debug settings [`src/index.ts`]
1126
+ - `configurePiUsereq(...)`: interactive configuration menu runtime root for directories, `Context Files` injection toggles, `Auto git commit`, locked-or-editable worktree rows, tools, notifications, and debug settings [`src/index.ts`]
1120
1127
  - `loadProjectConfig(...)`: load config and normalize persisted directory paths for command context [`src/index.ts`]
1121
1128
  - `getProjectBase(...)`: resolve project base from command context cwd [`src/index.ts`]
1122
1129
  - `loadConfig(...)`: load config or defaults [`src/core/config.ts`]
@@ -1128,7 +1135,7 @@
1128
1135
  - `resolveGitRoot(...)`: resolve repository root [`src/core/tool-runner.ts`]
1129
1136
  - `runCapture(...)`: run git subprocess [`src/core/tool-runner.ts`]
1130
1137
  - `getProjectBase(...)`: resolve project base from command context cwd [`src/index.ts`]
1131
- - `buildPiUsereqMenuChoices(...)`: serialize top-level settings actions including effective worktree locking, notification and debug summaries, display-only local and global config-path rows, and reset-only terminal rows [`src/index.ts`]
1138
+ - `buildPiUsereqMenuChoices(...)`: serialize top-level settings actions including the `Context Files` injection toggle row, effective worktree locking, notification and debug summaries, display-only local and global config-path rows, and reset-only terminal rows [`src/index.ts`]
1132
1139
  - `formatDebugMenuSummary(...)`: summarize global debug mode plus selected tool and prompt counts [`src/index.ts`]
1133
1140
  - `formatLocalConfigPathForMenu(...)`: format the current local config path with the shared `~`-relative path formatter for menu display [`src/index.ts`]
1134
1141
  - `formatGlobalConfigPathForMenu(...)`: format the current global config path with the shared `~`-relative path formatter for menu display [`src/index.ts`]
@@ -1230,6 +1237,10 @@
1230
1237
  - `selectPiNotifyPushoverPriority(...)`: present the `Normal|High` priority selector with the subtree-local reset action [`src/index.ts`]
1231
1238
  - `buildTerminalSettingsMenuChoices(...)`: append the canonical value-less `Reset defaults` row to the selector menu [`src/index.ts`]
1232
1239
  - `resetPiNotifyConfigToDefaults(...)`: restore notification settings to documented defaults [`src/index.ts`]
1240
+ - `configureContextFilesMenu(...)`: interactive `Context Files` editor with inline `on|off` toggles for `REQUIREMENTS.md`, `REFERENCES.md`, and `WORKFLOW.md` plus subtree reset to all-enabled defaults [`src/index.ts`]
1241
+ - `buildContextFilesMenuChoices(...)`: serialize the three context-file toggle rows plus the subtree reset terminal row [`src/index.ts`]
1242
+ - `showPiUsereqSettingsMenu(...)`: render the shared settings-menu UI for inline context-file toggles and reset confirmation [`src/core/settings-menu.ts`]
1243
+ - `confirmResetChanges(...)`: require explicit approval before applying the Context Files subtree reset [`src/index.ts`]
1233
1244
  - `getDefaultConfig(...)`: restore default config on reset and subtree-local selector resets [`src/core/config.ts`]
1234
1245
  - `normalizeEnabledPiUsereqTools(...)`: canonicalize configurable active tools [`src/core/pi-usereq-tools.ts`]
1235
1246
  - `applyConfiguredPiUsereqTools(...)`: re-apply active tools after reset [`src/index.ts`]
@@ -84,6 +84,9 @@ export interface UseReqConfig {
84
84
  "docs-dir": string;
85
85
  "tests-dir": string;
86
86
  "src-dir": string[];
87
+ "context-files-requirements": boolean;
88
+ "context-files-references": boolean;
89
+ "context-files-workflow": boolean;
87
90
  "static-check": Record<string, StaticCheckLanguageConfig>;
88
91
  "enabled-tools": string[];
89
92
  AUTO_GIT_COMMIT: "enable" | "disable";
@@ -145,6 +148,9 @@ interface UseReqLocalConfig {
145
148
  "docs-dir": string;
146
149
  "tests-dir": string;
147
150
  "src-dir": string[];
151
+ "context-files-requirements": boolean;
152
+ "context-files-references": boolean;
153
+ "context-files-workflow": boolean;
148
154
  "static-check": Record<string, LocalStaticCheckLanguageConfig>;
149
155
  DEBUG_ENABLED: "enable" | "disable";
150
156
  DEBUG_LOG_FILE: string;
@@ -206,6 +212,23 @@ export const DEFAULT_TESTS_DIR = "tests";
206
212
  * @details The array seeds newly created configs and repairs invalid persisted source selections. Access complexity is O(1).
207
213
  */
208
214
  export const DEFAULT_SRC_DIRS = ["src"];
215
+ /**
216
+ * @brief Defines the default value for every persisted context-file injection flag.
217
+ * @details Each `%%CONTEXT_FILES%%` injection toggle defaults to enabled so the bundled canonical documents remain part of the prompt context unless the user explicitly disables one. Lookup complexity is O(1).
218
+ * @satisfies REQ-328
219
+ */
220
+ export const DEFAULT_CONTEXT_FILES_FLAG = true;
221
+
222
+ /**
223
+ * @brief Normalizes one persisted context-file injection flag.
224
+ * @details Returns the documented default (`true`) for missing or non-boolean values and preserves only explicit boolean input, so any malformed persisted entry keeps context-file injection enabled. Runtime is O(1). No external state is mutated.
225
+ * @param[in] value {unknown} Candidate persisted context-file flag.
226
+ * @return {boolean} Normalized context-file injection flag.
227
+ * @satisfies REQ-328
228
+ */
229
+ export function normalizeContextFilesFlag(value: unknown): boolean {
230
+ return typeof value === "boolean" ? value : DEFAULT_CONTEXT_FILES_FLAG;
231
+ }
209
232
  /**
210
233
  * @brief Defines the canonical supported static-check language order used by default config serialization.
211
234
  * @details The array lists every supported user-configurable language exactly once so default config builders and config serializers can emit deterministic per-language records. Access complexity is O(1).
@@ -555,7 +578,7 @@ export function getGlobalConfigPath(): string {
555
578
  * @details Populates canonical docs/test/source directories, derives local static-check enable defaults from the supplied global checker definitions, and seeds documented debug defaults including tool-wrapper command registration without any cross-project fields. Runtime is O(l). No filesystem side effects occur.
556
579
  * @param[in] globalStaticCheckConfig {Record<string, GlobalStaticCheckLanguageConfig>} Global checker definitions used to derive local enable defaults.
557
580
  * @return {UseReqLocalConfig} Fresh default local configuration object.
558
- * @satisfies CTN-019
581
+ * @satisfies CTN-019, REQ-328
559
582
  */
560
583
  function getDefaultLocalConfig(
561
584
  globalStaticCheckConfig: Record<string, GlobalStaticCheckLanguageConfig>,
@@ -564,6 +587,9 @@ function getDefaultLocalConfig(
564
587
  "docs-dir": DEFAULT_DOCS_DIR,
565
588
  "tests-dir": DEFAULT_TESTS_DIR,
566
589
  "src-dir": [...DEFAULT_SRC_DIRS],
590
+ "context-files-requirements": DEFAULT_CONTEXT_FILES_FLAG,
591
+ "context-files-references": DEFAULT_CONTEXT_FILES_FLAG,
592
+ "context-files-workflow": DEFAULT_CONTEXT_FILES_FLAG,
567
593
  "static-check": getDefaultLocalStaticCheckConfig(globalStaticCheckConfig),
568
594
  DEBUG_ENABLED: DEFAULT_DEBUG_ENABLED,
569
595
  DEBUG_LOG_FILE: DEFAULT_DEBUG_LOG_FILE,
@@ -619,6 +645,7 @@ function getDefaultGlobalConfig(): UseReqGlobalConfig {
619
645
  * @param[in] localConfig {UseReqLocalConfig} Persisted local configuration.
620
646
  * @param[in] globalConfig {UseReqGlobalConfig} Persisted global configuration.
621
647
  * @return {UseReqConfig} Effective merged configuration.
648
+ * @satisfies REQ-328
622
649
  */
623
650
  function mergeConfigScopes(
624
651
  localConfig: UseReqLocalConfig,
@@ -645,6 +672,9 @@ function mergeConfigScopes(
645
672
  "docs-dir": docsDir,
646
673
  "tests-dir": testsDir,
647
674
  "src-dir": srcDir.length > 0 ? srcDir : [...DEFAULT_SRC_DIRS],
675
+ "context-files-requirements": localConfig["context-files-requirements"],
676
+ "context-files-references": localConfig["context-files-references"],
677
+ "context-files-workflow": localConfig["context-files-workflow"],
648
678
  "static-check": mergeStaticCheckConfig(localConfig["static-check"], globalConfig["static-check"]),
649
679
  "enabled-tools": normalizeEnabledPiUsereqTools(globalConfig["enabled-tools"]),
650
680
  AUTO_GIT_COMMIT: autoGitCommit,
@@ -823,7 +853,7 @@ function normalizeGlobalStaticCheckConfig(
823
853
  * @param[in] projectBase {string} Absolute project root path.
824
854
  * @param[in] defaultStaticCheckConfig {Record<string, LocalStaticCheckLanguageConfig>} Local static-check enable defaults derived from the current global checker map.
825
855
  * @return {UseReqLocalConfig} Sanitized local configuration.
826
- * @satisfies CTN-019
856
+ * @satisfies CTN-019, REQ-328
827
857
  */
828
858
  function loadLocalConfig(
829
859
  projectBase: string,
@@ -836,6 +866,9 @@ function loadLocalConfig(
836
866
  "docs-dir": DEFAULT_DOCS_DIR,
837
867
  "tests-dir": DEFAULT_TESTS_DIR,
838
868
  "src-dir": [...DEFAULT_SRC_DIRS],
869
+ "context-files-requirements": DEFAULT_CONTEXT_FILES_FLAG,
870
+ "context-files-references": DEFAULT_CONTEXT_FILES_FLAG,
871
+ "context-files-workflow": DEFAULT_CONTEXT_FILES_FLAG,
839
872
  "static-check": normalizeLocalStaticCheckConfig(undefined, defaultStaticCheckConfig),
840
873
  DEBUG_ENABLED: DEFAULT_DEBUG_ENABLED,
841
874
  DEBUG_LOG_FILE: DEFAULT_DEBUG_LOG_FILE,
@@ -863,6 +896,9 @@ function loadLocalConfig(
863
896
  "docs-dir": docsDirCandidate || DEFAULT_DOCS_DIR,
864
897
  "tests-dir": testsDirCandidate || DEFAULT_TESTS_DIR,
865
898
  "src-dir": srcDirCandidate.length > 0 ? srcDirCandidate : [...DEFAULT_SRC_DIRS],
899
+ "context-files-requirements": normalizeContextFilesFlag(data["context-files-requirements"]),
900
+ "context-files-references": normalizeContextFilesFlag(data["context-files-references"]),
901
+ "context-files-workflow": normalizeContextFilesFlag(data["context-files-workflow"]),
866
902
  "static-check": normalizeLocalStaticCheckConfig(data["static-check"], defaultStaticCheckConfig),
867
903
  DEBUG_ENABLED: normalizeDebugEnabled(data.DEBUG_ENABLED),
868
904
  DEBUG_LOG_FILE: normalizeDebugLogFile(data.DEBUG_LOG_FILE),
@@ -945,7 +981,7 @@ export function loadConfig(projectBase: string): UseReqConfig {
945
981
  * @details Copies only project-scoped keys into a fresh object so runtime-derived metadata plus global checker, tool, git, and notification fields never reach `.pi-usereq.json`, while preserving the debug tool-wrapper command flag beside other local debug settings. Runtime is O(n) in config size. No external state is mutated.
946
982
  * @param[in] config {UseReqConfig} Effective configuration object.
947
983
  * @return {UseReqLocalConfig} Persistable local configuration payload.
948
- * @satisfies CTN-012, CTN-013, CTN-019, REQ-104, REQ-146, REQ-249, REQ-316, REQ-277
984
+ * @satisfies CTN-012, CTN-013, CTN-019, REQ-104, REQ-146, REQ-249, REQ-316, REQ-277, REQ-328
949
985
  */
950
986
  function buildPersistedLocalConfig(config: UseReqConfig): UseReqLocalConfig {
951
987
  const normalizedSrcDir = config["src-dir"]
@@ -955,6 +991,9 @@ function buildPersistedLocalConfig(config: UseReqConfig): UseReqLocalConfig {
955
991
  "docs-dir": normalizeRelativeDirContract(config["docs-dir"]) || DEFAULT_DOCS_DIR,
956
992
  "tests-dir": normalizeRelativeDirContract(config["tests-dir"]) || DEFAULT_TESTS_DIR,
957
993
  "src-dir": normalizedSrcDir.length > 0 ? normalizedSrcDir : [...DEFAULT_SRC_DIRS],
994
+ "context-files-requirements": normalizeContextFilesFlag(config["context-files-requirements"]),
995
+ "context-files-references": normalizeContextFilesFlag(config["context-files-references"]),
996
+ "context-files-workflow": normalizeContextFilesFlag(config["context-files-workflow"]),
958
997
  "static-check": Object.fromEntries(
959
998
  Object.entries(config["static-check"]).map(([language, languageConfig]) => [
960
999
  language,
@@ -6,8 +6,18 @@
6
6
 
7
7
  import fs from "node:fs";
8
8
  import path from "node:path";
9
- import { buildPromptReplacementPaths, type UseReqConfig } from "./config.js";
10
- import { formatRuntimePathForDisplay } from "./path-context.js";
9
+ import {
10
+ buildPromptReplacementPaths,
11
+ DEFAULT_DOCS_DIR,
12
+ DEFAULT_STATIC_CHECK_LANGUAGES,
13
+ resolveEffectiveGitWorktreeEnabled,
14
+ type UseReqConfig,
15
+ } from "./config.js";
16
+ import {
17
+ comparePiUsereqStartupToolNames,
18
+ type PiUsereqStartupToolName,
19
+ } from "./pi-usereq-tools.js";
20
+ import { formatRuntimePathForDisplay, normalizeRelativeDirContract } from "./path-context.js";
11
21
  import type {
12
22
  PromptCommandExecutionPlan,
13
23
  PromptCommandName,
@@ -135,6 +145,44 @@ function injectPiDevConformanceBlock(text: string, promptName: string, projectBa
135
145
  return text.replace(behaviorHeading, `${behaviorHeading}${block}\n`);
136
146
  }
137
147
 
148
+ /**
149
+ * @brief Defines the ordered context-file injection descriptors used by `%%CONTEXT_FILES%%`.
150
+ * @details Each entry binds the configured flag key to its canonical document file name so the renderer can iterate the documented `REQUIREMENTS.md`, `REFERENCES.md`, `WORKFLOW.md` order in one stable vector. Lookup complexity is O(1).
151
+ * @satisfies REQ-329
152
+ */
153
+ const CONTEXT_FILE_DESCRIPTORS: ReadonlyArray<{ flagKey: "context-files-requirements" | "context-files-references" | "context-files-workflow"; fileName: string }> = [
154
+ { flagKey: "context-files-requirements", fileName: "REQUIREMENTS.md" },
155
+ { flagKey: "context-files-references", fileName: "REFERENCES.md" },
156
+ { flagKey: "context-files-workflow", fileName: "WORKFLOW.md" },
157
+ ];
158
+
159
+ /**
160
+ * @brief Builds the markdown block that replaces the `%%CONTEXT_FILES%%` prompt token.
161
+ * @details Iterates the documented `REQUIREMENTS.md`, `REFERENCES.md`, `WORKFLOW.md` order, skips disabled flags and missing files without error, and renders each remaining file as a file-name heading, an HTML `<file name="<docs-dir>/<filename>">` reference with `%%DOC_PATH%%` pre-substituted, and the raw file content inside four-backtick `markdown` fences. Runtime is O(n) in aggregate context-file size. Side effects are limited to filesystem reads.
162
+ * @param[in] projectBase {string} Absolute project root used to resolve the configured docs directory.
163
+ * @param[in] config {UseReqConfig} Effective project configuration supplying the docs directory and context-file flags.
164
+ * @return {string} Rendered markdown block, or the empty string when no enabled context file exists.
165
+ * @satisfies REQ-329, REQ-330, REQ-331, REQ-332
166
+ */
167
+ function buildContextFilesBlock(projectBase: string, config: UseReqConfig): string {
168
+ const normalizedDocsDir = normalizeRelativeDirContract(config["docs-dir"]) || DEFAULT_DOCS_DIR;
169
+ const sections: string[] = [];
170
+ for (const { flagKey, fileName } of CONTEXT_FILE_DESCRIPTORS) {
171
+ if (!config[flagKey]) {
172
+ continue;
173
+ }
174
+ const filePath = path.join(projectBase, normalizedDocsDir, fileName);
175
+ if (!fs.existsSync(filePath) || !fs.statSync(filePath).isFile()) {
176
+ continue;
177
+ }
178
+ const content = fs.readFileSync(filePath, "utf8");
179
+ sections.push(
180
+ `### ${fileName}\n\n<file name="${normalizedDocsDir}/${fileName}">\n\`\`\`\`markdown\n${content}\n\`\`\`\``,
181
+ );
182
+ }
183
+ return sections.join("\n\n");
184
+ }
185
+
138
186
  /**
139
187
  * @brief Rewrites bundled prompt tool references from legacy `req --...` syntax to internal tool names.
140
188
  * @details Applies deterministic global regex replacements so prompt text matches the extension-registered tool surface instead of the standalone CLI spelling. Time complexity O(p*r) where p is pattern count and r is prompt length.
@@ -278,7 +326,7 @@ function renderBundledCommitInstruction(
278
326
  * @param[in] config {UseReqConfig} Effective project configuration used for path substitutions.
279
327
  * @param[in] executionPlan {PromptCommandExecutionPlan | undefined} Optional prompt-command execution plan used for injected runtime guidance.
280
328
  * @return {string} Fully rendered prompt markdown ready for `pi.sendUserMessage(...)`.
281
- * @satisfies REQ-002, REQ-003, REQ-032, REQ-033, REQ-034, REQ-108, REQ-200, REQ-201, REQ-202, REQ-206, REQ-207, REQ-208, REQ-209, REQ-211, REQ-213, REQ-214, REQ-273, REQ-274, REQ-275
329
+ * @satisfies REQ-002, REQ-003, REQ-032, REQ-033, REQ-034, REQ-108, REQ-200, REQ-201, REQ-202, REQ-206, REQ-207, REQ-208, REQ-209, REQ-211, REQ-213, REQ-214, REQ-273, REQ-274, REQ-275, REQ-329, REQ-330, REQ-331, REQ-332
282
330
  */
283
331
  export function renderPrompt(
284
332
  promptName: string,
@@ -310,5 +358,68 @@ export function renderPrompt(
310
358
  promptName,
311
359
  projectBase,
312
360
  );
313
- return adaptPromptForInternalTools(withPiDevConformance);
361
+ const adapted = adaptPromptForInternalTools(withPiDevConformance);
362
+ const contextFilesBlock = buildContextFilesBlock(projectBase, config);
363
+ if (contextFilesBlock) {
364
+ return adapted.split("%%CONTEXT_FILES%%").join(contextFilesBlock);
365
+ }
366
+ return adapted.split("%%CONTEXT_FILES%%").join("");
367
+ }
368
+
369
+ /**
370
+ * @brief Defines the custom-message type used for pi-usereq prompt-command screen summaries and hidden LLM prompt delivery.
371
+ * @details The constant is reused as the `customType` for both the `display:true` command invocation summary and the `display:false` hidden rendered prompt so the TUI renders only the summary while the full prompt reaches the LLM agent through the same custom-message channel. Access complexity is O(1).
372
+ * @satisfies DES-016, REQ-334
373
+ */
374
+ export const PROMPT_COMMAND_SUMMARY_CUSTOM_TYPE = "pi-usereq-prompt-command";
375
+
376
+ /**
377
+ * @brief Builds the on-screen command invocation summary for one bundled prompt-backed `req-<prompt>` command.
378
+ * @details Renders the command name without the `req-` prefix in uppercase, the user request arguments, and the active configuration fields (`docs-dir`, `src-dir`, `tests-dir`, enabled context files, `AUTO_GIT_COMMIT`, effective `GIT_WORKTREE_ENABLED`, `GIT_WORKTREE_PREFIX`, enabled static-check languages, and `enabled-tools`) so the TUI shows only a compact summary while the full rendered prompt is delivered hidden to the LLM agent. Static-check languages are emitted in canonical `DEFAULT_STATIC_CHECK_LANGUAGES` order; enabled tools are emitted in documented menu order via `comparePiUsereqStartupToolNames`. Runtime is O(l + t log t) where l is language count and t is enabled-tool count. No external state is mutated.
379
+ * @param[in] promptName {string} Bundled prompt name without the `req-` prefix.
380
+ * @param[in] args {string} User request arguments passed to the slash command.
381
+ * @param[in] config {UseReqConfig} Effective project configuration supplying directory, git, static-check, and tool fields.
382
+ * @return {string} Multi-line command invocation summary text.
383
+ * @satisfies REQ-335, REQ-336, REQ-337
384
+ */
385
+ export function renderPromptCommandSummary(
386
+ promptName: string,
387
+ args: string,
388
+ config: UseReqConfig,
389
+ ): string {
390
+ const contextFiles = CONTEXT_FILE_DESCRIPTORS
391
+ .filter((descriptor) => config[descriptor.flagKey])
392
+ .map((descriptor) => descriptor.fileName.replace(/\.md$/, "").toLowerCase())
393
+ .join(", ");
394
+ const enabledLanguages = DEFAULT_STATIC_CHECK_LANGUAGES
395
+ .filter((language) => config["static-check"][language]?.enabled === "enable")
396
+ .join(", ");
397
+ const enabledTools = [...config["enabled-tools"]]
398
+ .sort((left, right) =>
399
+ comparePiUsereqStartupToolNames(
400
+ left as PiUsereqStartupToolName,
401
+ right as PiUsereqStartupToolName,
402
+ ))
403
+ .join(", ");
404
+ const effectiveWorktree = resolveEffectiveGitWorktreeEnabled(
405
+ config.AUTO_GIT_COMMIT,
406
+ config.GIT_WORKTREE_ENABLED,
407
+ );
408
+ const lines: string[] = [
409
+ `Command: ${promptName.toUpperCase()}`,
410
+ "",
411
+ `User's Request: ${args}`,
412
+ "",
413
+ "Configuration:",
414
+ `- document dir: ${config["docs-dir"]}`,
415
+ `- source-code dirs: ${config["src-dir"].join(", ")}`,
416
+ `- unit tests dir: ${config["tests-dir"]}`,
417
+ `- context files: ${contextFiles}`,
418
+ `- auto git commit: ${config.AUTO_GIT_COMMIT}`,
419
+ `- git worktree: ${effectiveWorktree}`,
420
+ `- worktree prefix: ${config.GIT_WORKTREE_PREFIX}`,
421
+ `- static code checks: ${enabledLanguages}`,
422
+ `- enabled tools: ${enabledTools}`,
423
+ ];
424
+ return lines.join("\n");
314
425
  }