Feature: File Statistics Toggle & File Size fix
Hi, I've looking for a way to turn off the file statistics section in the generated documents, and thought to contribute this when I saw that there was none.
This PR adds a showFileStats boolean flag (default: true) that controls whether the auto-generated File Statistics section is appended to compiled documents. Can be set per-document or globally via settings.showFileStats. The per-document value always takes precedence.
Additionally, a discrepancy was fixed where file statistics were silently omitted on the first ctx generate' run because addFileStatistics() attempted to read stats from the output file before witing it to disk. This also had the effect to always count the previous file size, not the size of the new file being written. Stats are now computed directly from the in-memory content, making them accurate on every run.
Hi @butschster, I checked the CI error and it is unrelated to my changes. I had my agent look at the issue, here's a summary explaining what's going on - hoping it helps.
Issue Report for ctx/mcp-server — PromptConfigFactory::parseRole() silently accepts missing role
Package: ctx/mcp-server v1.7.2
File: src/Prompt/PromptConfigFactory.php
Method: parseRole()
What changed
In v1.7.2 the parseMessage() logic was refactored to extract a dedicated parseRole() helper. In that refactor the behaviour for a missing role key changed:
Before (correct behaviour, previously in the consuming project's local override):
if (!isset($messageConfig['role']) || !\is_string($messageConfig['role'])) {
throw new PromptParsingException('Message must have a valid role');
}
After (current v1.7.2 behaviour):
private function parseRole(array $messageConfig): Role
{
if (!isset($messageConfig['role'])) {
return Role::User; // ← silently defaults instead of rejecting
}
// ...
}
The docblock even documents this as intentional ("defaults to Role::User if not specified"), but it breaks the expected contract.
Why this is a problem
When role is missing, the factory should reject the message so the error bubbles up through PromptParserPlugin to ConfigParser, which catches it and omits the entire prompt from the registry. Silently defaulting to Role::User instead hides a configuration mistake and registers a prompt the user did not properly define.
The inconsistency is also asymmetric: a non-string role already throws (!\is_string check), and an invalid string role also throws (Role::tryFrom(...) ?? throw). Only a missing role is silently swallowed — which is the most common typo/omission.
Ideal fix
In parseRole(), treat a missing role the same as an invalid one:
/**
* @param array<string, mixed> $messageConfig The message configuration.
* @return Role The parsed role.
*
* @throws PromptParsingException If the role is missing or invalid.
*/
private function parseRole(array $messageConfig): Role
{
if (!isset($messageConfig['role']) || !\is_string($messageConfig['role'])) {
throw new PromptParsingException('Message must have a valid role');
}
return Role::tryFrom($messageConfig['role'])
?? throw new PromptParsingException(
\sprintf('Invalid role "%s"', $messageConfig['role']),
);
}
This restores the original behaviour: any message without an explicit role causes the containing prompt to be silently dropped from the registry (with a logged warning), rather than being registered with an assumed role the user never specified.