cli-usereq 0.68.0__py3-none-any.whl

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.
Files changed (37) hide show
  1. cli_usereq-0.68.0.dist-info/METADATA +1134 -0
  2. cli_usereq-0.68.0.dist-info/RECORD +37 -0
  3. cli_usereq-0.68.0.dist-info/WHEEL +5 -0
  4. cli_usereq-0.68.0.dist-info/entry_points.txt +4 -0
  5. cli_usereq-0.68.0.dist-info/licenses/LICENSE +674 -0
  6. cli_usereq-0.68.0.dist-info/top_level.txt +1 -0
  7. usereq/__init__.py +62 -0
  8. usereq/__main__.py +17 -0
  9. usereq/cli.py +4963 -0
  10. usereq/compress.py +393 -0
  11. usereq/compress_files.py +134 -0
  12. usereq/doxygen_parser.py +172 -0
  13. usereq/find_constructs.py +394 -0
  14. usereq/generate_markdown.py +158 -0
  15. usereq/resources/docs/Document_Source_Code_in_Doxygen_Style.md +130 -0
  16. usereq/resources/docs/HDT_Test_Authoring_Guide.md +318 -0
  17. usereq/resources/docs/Requirements_Template.md +78 -0
  18. usereq/resources/prompts/analyze.md +191 -0
  19. usereq/resources/prompts/change.md +279 -0
  20. usereq/resources/prompts/check.md +190 -0
  21. usereq/resources/prompts/cover.md +271 -0
  22. usereq/resources/prompts/create.md +134 -0
  23. usereq/resources/prompts/fix.md +273 -0
  24. usereq/resources/prompts/flowchart.md +272 -0
  25. usereq/resources/prompts/implement.md +194 -0
  26. usereq/resources/prompts/new.md +278 -0
  27. usereq/resources/prompts/readme.md +234 -0
  28. usereq/resources/prompts/recreate.md +265 -0
  29. usereq/resources/prompts/refactor.md +265 -0
  30. usereq/resources/prompts/references.md +131 -0
  31. usereq/resources/prompts/renumber.md +150 -0
  32. usereq/resources/prompts/workflow.md +254 -0
  33. usereq/resources/prompts/write.md +129 -0
  34. usereq/resources/prompts-version.txt +1 -0
  35. usereq/source_analyzer.py +2280 -0
  36. usereq/static_check.py +812 -0
  37. usereq/token_counter.py +123 -0
@@ -0,0 +1,272 @@
1
+ ---
2
+ description: "Write a FLOWCHART.md using the project's source code"
3
+ argument-hint: "No arguments utilized by the prompt logic"
4
+ usage: >
5
+ Use when the user asks to create, regenerate, or update FLOWCHART.md as a Mermaid diagram of the primary runtime flow derived from source under the project source directories. Change only that document and commit the update. Use /req-workflow for the textual execution model, /req-references for the source index, or /req-analyze for an explanation without file edits. Do not select to design an unimplemented flow or modify requirements, source code, tests, or other documents.
6
+ ---
7
+
8
+ # Write a FLOWCHART.md using the project's source code
9
+
10
+ ## Pre-Flight: Context Keyword Resolution
11
+ - **CRITICAL**: Complete this read-only gate before any path-dependent action or numbered Step. Immediate-start directives apply only after success; autonomous disambiguation MUST NOT guess `{{PRJ_BASE}}` or `{{GIT_BASE}}`.
12
+ - Runtime keywords: resolve exactly two LLM-resolved path keywords in fixed order: `{{PRJ_BASE}}` first, `{{GIT_BASE}}` second. Installation has already supplied the documentation, source, and test paths; use them as fixed relative suffixes, not values to discover or replace.
13
+ - Project base: `{{PRJ_BASE}}` is the absolute base directory of the unique target project containing its installation-supplied `%%DOC_PATH%%`, `%%SRC_PATHS%%`, and `%%TEST_PATH%%` directories.
14
+ - Git base: `{{GIT_BASE}}` is the absolute base directory of the git repository containing `{{PRJ_BASE}}`. One git repository can contain multiple projects; repository identity alone never identifies the project.
15
+ - Resolution order: identify `{{PRJ_BASE}}` first and uniquely from current invocation routing and explicit task scope; use uniquely corroborated project path metadata only for missing evidence. The current directory is a candidate, not a default. Conflicting bindings, multiple plausible projects, or stale cross-project values fail resolution. Source-free workflows inspect path metadata only. After `{{PRJ_BASE}}` is bound, derive `{{GIT_BASE}}` as the git repository root containing the bound project base.
16
+ - Binding: retain `{{PRJ_BASE}}`, `{{GIT_BASE}}`, active worktree root, project identity, evidence, directory existence states, and document provenance throughout this invocation. Start fresh for each invocation; replace the bindings only after a validated context transition.
17
+ - Paths: substitute the resolved base in each prefixed path. For an installation-supplied source list, apply the base separately to every entry; preserve order and explicit list boundaries, never split on spaces or commas. Treat paths as data and quote each resulting literal argument separately, with option termination where supported.
18
+ - Containment: validate the base and resulting paths inside the active worktree, including symlink targets and existing ancestors of prospective paths. Accept absent directories only for authorized creation or explicitly unused source/test scopes; absence is not an unresolved base. Create nothing during pre-flight.
19
+ - Document contract below: filenames are relative to the installation-supplied documentation path under `{{PRJ_BASE}}`. Required inputs MUST exist; creatable targets MAY be absent. Load exactly the listed existing documents in full before Steps, including existing targets; defer reads of absent creatable targets until generated. Unlisted canonical documents are not prerequisites.
20
+ - Required inputs: REQUIREMENTS.md, WORKFLOW.md, REFERENCES.md.
21
+ - Creatable targets: none.
22
+ - Load when present: REQUIREMENTS.md, WORKFLOW.md, REFERENCES.md.
23
+ - Context reuse: treat injected or previously read content as loaded only when repository, worktree, project-area, path, and revision provenance match this binding. Current runtime attestation or unchanged-file evidence can establish a match; a basename alone cannot. Refresh stale or unverified content from the resolved path; reuse matching content without re-reading. After an edit, retain the verified updated content and invalidate superseded evidence.
24
+ - Operation scope: run cwd-sensitive commands and configured tools from `{{PRJ_BASE}}` only when their effective scope matches the target project; otherwise use a documented explicit-path equivalent or fail resolution.
25
+ - Activity routing: reference all project-modification and requirements-modification activities exclusively to `{{PRJ_BASE}}`; reference only working-tree creation and git-management activities to `{{GIT_BASE}}`.
26
+ - Context transitions: after an authorized worktree change, rebase `{{PRJ_BASE}}` to the same project-relative location in the new worktree and rebase `{{GIT_BASE}}` to the new worktree's repository root. Revalidate containment and document provenance before project operations; discard old absolute paths. Reuse document contents only with verified unchanged-file evidence. A different target project requires a fresh invocation.
27
+ - **CRITICAL**: If `{{PRJ_BASE}}` or `{{GIT_BASE}}`, required document, containment check, or effective tool scope remains unresolved or conflicting, OUTPUT exactly "ERROR: Unable to resolve context keywords!". Before isolation, terminate without cleanup; after successful isolation, follow the context-resolution failure cleanup in the isolation Step before terminating.
28
+
29
+ ## Purpose
30
+ Maintain an LLM-oriented runtime flowchart (`{{PRJ_BASE}}/%%DOC_PATH%%/FLOWCHART.md`) derived from repository evidence so downstream LLM Agents can reason about primary execution flow, decision branches, and grouped internal operations during SRS-driven design/implementation.
31
+
32
+ ## Scope
33
+ In scope: static analysis of source under {{PRJ_BASE}}/%%SRC_PATHS%% to generate/overwrite only `{{PRJ_BASE}}/%%DOC_PATH%%/FLOWCHART.md` in English only, following the mandated Mermaid output contract, then commit that doc change. Out of scope: changes to requirements, workflow, references, source code, or tests.
34
+
35
+ ## Professional Personas
36
+ - **Act as a Prompt Engineer and LLM Optimization Specialist** whenever you design, write, modify, or analyze prompts, agents, skills, or documents whose target audience is an LLM Agent instead of a human reader.
37
+ - **Act as a Senior System Architect and Senior System Engineer** when analyzing source code; your primary goal is to trace the execution flow, decision points, and grouping boundaries across files and modules.
38
+ - **Act as a Business Analyst** when cross-referencing code findings with `{{PRJ_BASE}}/%%DOC_PATH%%/REQUIREMENTS.md` to ensure functional alignment.
39
+ - **Act as a Technical Writer and Expert Mermaid.js Developer** when producing the final flowchart, ensuring structurally valid Mermaid syntax and zero-hallucination mapping.
40
+ - **Act as a QA Auditor** when reporting facts, requiring concrete evidence as declaration file paths only (excluding line numbers and line ranges) for every finding.
41
+ - **Act as an Expert GitOps Engineer** when executing git workflows, especially when creating/removing/managing git worktrees to isolate changes safely.
42
+
43
+ ## Iteration and Context Economy
44
+ - **CRITICAL**: Plan every Step to complete in the minimum number of iterations; batch independent reads, searches, and edits into a single response and dispatch parallel tool calls whenever no dependency forces sequencing.
45
+ - **CRITICAL**: Reuse injected or previously read file evidence only when repository, worktree, project-area, path, and revision identity match the active binding; do not re-read matching content. Refresh stale or unverified evidence under the pre-flight context-reuse rules.
46
+ - **CRITICAL**: MUST NOT restate requirement text, prior tool output, or unchanged file contents into the context; cite them by file path, symbol, and line range, quoting only the minimal changed snippet.
47
+ - **CRITICAL**: MUST add only information required by the active Step, a requirement ID, or explicit user-request text; omit narration, filler, restatements, and speculative commentary.
48
+ - **CRITICAL**: MUST choose the most token-efficient evidence path in order: `{{PRJ_BASE}}/%%DOC_PATH%%/REQUIREMENTS.md`, `{{PRJ_BASE}}/%%DOC_PATH%%/WORKFLOW.md`, `{{PRJ_BASE}}/%%DOC_PATH%%/REFERENCES.md`, then `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --find`/`req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --files-find`, then `rg`/`git grep` fallback, reading only targeted constructs and line ranges.
49
+ - **CRITICAL**: MUST gather all evidence a Step needs before producing its output and MUST NOT split a single logical operation across multiple iterations when one suffices.
50
+ - **CRITICAL**: MUST pause and wait for a tool response only when a Step explicitly depends on it; otherwise proceed autonomously to the next Step without requesting confirmation.
51
+ - **CRITICAL**: These rules MUST govern how the agent organizes and sequences the work described in the `## Steps` section.
52
+
53
+ ## Pre-requisite: Execution Context
54
+ - **CRITICAL**: All information declared in this `Pre-requisite: Execution Context` section MUST remain continuously available in the active execution context for the entire workflow and MUST NEVER be dropped, forgotten, or overwritten.
55
+ - Generate <WORKTREE_NAME> with `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --git-wt-name`, retain the literal result for later steps, and use simple sequential execution with only linear shell commands compatible with restrictive filtering systems for all worktree operations in this workflow.
56
+
57
+ ## Absolute Rules, Non-Negotiable
58
+ - **CRITICAL**: When instructions generate shell commands, they MUST generate only linear shell commands compatible with restrictive filtering systems, MUST verify and apply correct quoting, escaping, or option termination for literal arguments that could be parsed as options or flags, MUST use explicit option termination for `rg` and `git grep` patterns beginning with `-` or `--`, MUST NOT rely on quoting or backslash escaping alone for those patterns, and MUST NOT use command substitution (`$()` or backticks), complex variable expansion, nested substitution, shell-derived helper composition, nested shell logic, or nested pipelines.
59
+ - **CRITICAL**: Every `req` invocation MUST carry the mandatory parameters `--prj-base={{PRJ_BASE}}` and `--git-base={{GIT_BASE}}` with the resolved values; the removed `--base` parameter MUST NOT be used.
60
+ - **CRITICAL**: NEVER write, modify, edit, or delete files outside of the active git worktree directory, except under `/tmp`, and except for worktree operations executed through `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --git-wt-create <WORKTREE_NAME>` and `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --git-wt-delete <WORKTREE_NAME>`.
61
+ - You can read, write, or edit `{{PRJ_BASE}}/%%DOC_PATH%%/FLOWCHART.md`.
62
+ - Treat static analysis as safe. Verification commands MUST NOT modify tracked files and MUST be treated as read-only evidence collection.
63
+ - **CRITICAL**: Do not modify any project files except creating/updating `{{PRJ_BASE}}/%%DOC_PATH%%/FLOWCHART.md`.
64
+ - **CRITICAL**: GIT operations and GIT rules:
65
+ - Do not run any shell/git commands and do not modify any files before starting Step 1 (including creating/modifying files, installing deps, formatting, etc.), except the read-only repository checks required by the `## Pre-Flight: Context Keyword Resolution` section: **CRITICAL**: Check GIT Status.
66
+ - Step 1 may run only the git commands `git rev-parse --is-inside-work-tree`, `git rev-parse --verify HEAD`, `git status --porcelain`, and `git symbolic-ref -q HEAD` (plus minimal shell built-ins to combine their outputs into a single cleanliness check).
67
+ - If the repository is NOT clean (modified files, staged changes, OR untracked files), exit immediately without changing anything.
68
+ - At the end you MUST commit only the intended changes with a unique identifier and change description in the commit message.
69
+ - Leave the working tree AND index clean (git `status --porcelain` must be empty).
70
+ - Do NOT “fix” a dirty repo by force (no `git reset --hard`, no `git clean -fd`, no stash) unless explicitly requested. If dirty: abort.
71
+ - **CRITICAL**: Formulate all source code information using a highly structured, machine-interpretable Markdown format with unambiguous, atomic syntax to ensure maximum reliability for downstream LLM agentic reasoning, avoiding any conversational filler or subjective adjectives; the **target audience** is other **LLM Agents** and Automated Parsers, NOT humans, use high semantic density, optimized to contextually enable an LLM to perform future refactoring or extension.
72
+
73
+ ## Behavior
74
+ - Write the `{{PRJ_BASE}}/%%DOC_PATH%%/FLOWCHART.md` document in English.
75
+ - Do not perform unrelated edits.
76
+ - Use the repository's existing language-specific environment/toolchain to execute code and tests; do NOT create new environments unless explicitly requested by the user. For Python, prefer Astral `uv` (`uv run`, `uvx`) when available, then fall back to the repository's existing `.venv` (if present). For other ecosystems (e.g., Node.js, Rust, C/C++), use the project's standard commands.
77
+ - Use filesystem/shell tools to read/write/delete files as needed (e.g., `cat`, `sed`, `perl -pi`, `printf > file`, `rm -f`, ...), but only to read project files and to write/update `{{PRJ_BASE}}/%%DOC_PATH%%/FLOWCHART.md`. Avoid in-place edits on any other path. Prefer read-only commands for analysis.
78
+
79
+ ## Canonical Terminology (MUST use these exact terms)
80
+ - **Process**: an OS process execution unit (MUST include the main process).
81
+ - **Thread**: an OS thread execution unit within a process.
82
+ - **Execution Unit**: a Process or a Thread.
83
+ - **Internal function**: a function/method defined in repository source under {{PRJ_BASE}}/%%SRC_PATHS%%.
84
+ - **External boundary**: any call/interaction whose target implementation is not defined under {{PRJ_BASE}}/%%SRC_PATHS%% (libraries/frameworks/OS/network/DB/etc.).
85
+ - **Communication Edge**: an explicit runtime interaction between two execution units.
86
+
87
+ ## FLOWCHART.md Output Contract
88
+ - The generated `{{PRJ_BASE}}/%%DOC_PATH%%/FLOWCHART.md` MUST be parser-stable and token-efficient: a single fenced Mermaid block, deterministic node labels, and zero narrative filler outside the fence.
89
+ - The generated `{{PRJ_BASE}}/%%DOC_PATH%%/FLOWCHART.md` MUST contain only a fenced `mermaid` block that starts with `graph TD`.
90
+ - The flowchart MUST represent the primary execution flow and MUST exclude tangential or secondary flows.
91
+ - The flowchart MUST group non-atomic internal functions into sequential alphabetical phases.
92
+ - Each phase node MUST list atomic operations as sequentially numbered parameterless function prototypes.
93
+ - Decision nodes MUST encode branching criteria in strict pseudo-code syntax.
94
+ - Visible graph text MUST NOT expose internal working tags such as temporary decision or join identifiers.
95
+
96
+ ## Source Code Analysis Toolkit
97
+ Four complementary pillars provide a complete, token-efficient source code analysis pipeline. Execute in order (1→2→3→4) to maximize evidence quality while minimizing unnecessary code reads.
98
+
99
+ ### 1. Runtime Model: `{{PRJ_BASE}}/%%DOC_PATH%%/WORKFLOW.md`
100
+ Compact document — read in full. Contains:
101
+ - **Execution Units Index**: all OS processes and threads with roles and entrypoints.
102
+ - **Execution Units**: per-unit internal call-trace trees showing function call order, defining file paths, and external boundaries.
103
+ - **Communication Edges**: inter-unit data flow (direction, mechanism, payload).
104
+
105
+ Use to: identify which execution units (processes/threads) are involved, trace call-order through internal functions, understand data flow between components. Build a runtime mental model before reading any code.
106
+
107
+ ### 2. Symbol Index: `{{PRJ_BASE}}/%%DOC_PATH%%/REFERENCES.md`
108
+ Structured index of all source-defined symbols (functions, classes, structs, objects, data structures) with file paths and line numbers. Per-symbol Doxygen-style fields may include:
109
+ - `@brief`: single-line technical description of the symbol's action.
110
+ - `@details`: high-density algorithmic summary (LLM-optimized, not prose).
111
+ - `@param` / `@param[out]`: input parameters with type constraints; mutated reference/pointer arguments.
112
+ - `@return` / `@retval`: output data structure or specific return values.
113
+ - `@exception` / `@throws`: error states and specific exception classes.
114
+ - `@satisfies`: linked requirement IDs (e.g., `@satisfies REQ-026, REQ-045`).
115
+ - `@pre` / `@post`: pre-conditions and post-conditions.
116
+ - `@warning`: critical usage hazards.
117
+ - `@note`: vital implementation details.
118
+ - `@see` / `@sa`: related symbols for context linkage.
119
+ - `@deprecated`: replacement API link.
120
+
121
+ Use to: identify candidate symbols by name, description, or `@satisfies` link; obtain exact file paths and line ranges; understand function signatures and contracts before extracting code. Cross-reference with WORKFLOW.md call-traces to narrow scope.
122
+
123
+ ### 3. Code Extraction: `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --find` / `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --files-find`
124
+ Extract actual source constructs as structured markdown with signatures, line ranges, and optional line-numbered code. Use after pillars 1-2 to extract only the targeted constructs identified during analysis.
125
+ #### What these commands do (and what they don't)
126
+ - Extract named constructs (e.g., CLASS, FUNCTION, STRUCT, INTERFACE, IMPORT, …) filtered by TAG and name-regex.
127
+ - Regex (PATTERN) matches construct name only (not body). For body-content search, use rg/git grep (pillar 4).
128
+ - Output per file: header `@@@ <filepath> | <language>`, per-construct blocks with:
129
+ - `### <TAG>: <name>` + optional Signature + `Lines: <start>-<end>`
130
+ - optional extracted Doxygen fields (if present in/around the construct)
131
+ - fenced code block with the complete construct slice (comments stripped, strings preserved)
132
+ #### Choose the right mode
133
+ - Project-wide scan: use --find (the mandatory `--prj-base`/`--git-base` prefix is required; `--base` is forbidden)
134
+ - Syntax: `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --find <TAG_FILTER> <NAME_REGEX>`
135
+ - Note: --find scans all files under configured source dirs; does not take a filename.
136
+ - Target specific files: use --files-find (standalone with the mandatory `--prj-base`/`--git-base` prefix)
137
+ - Syntax: `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --files-find <TAG_FILTER> <NAME_REGEX> <FILE1> [FILE2 ...]`
138
+ #### Enable line-numbered code for evidence citation
139
+ Add --enable-line-numbers (code lines prefixed as `<n>:`):
140
+ - `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --enable-line-numbers --find "<TAG_FILTER>" "<NAME_REGEX>"`
141
+ - `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --enable-line-numbers --files-find "<TAG_FILTER>" "<NAME_REGEX>" <FILE...>`
142
+ #### TAGs and filters
143
+ - TAG_FILTER: pipe-separated, case-insensitive (e.g., `CLASS|FUNCTION|IMPORT`).
144
+ - Tags are language-dependent; unsupported tags are ignored. Run `req -h` for supported TAGs per language.
145
+ - Broad cross-language TAG_FILTER: `CLASS|STRUCT|ENUM|INTERFACE|TRAIT|IMPL|FUNCTION|METHOD|MODULE|NAMESPACE|TYPE_ALIAS|TYPEDEF|IMPORT|CONSTANT|VARIABLE|MACRO|DECORATOR|COMPONENT|PROPERTY|PROTOCOL|EXTENSION|UNION`
146
+ #### Regex rules (NAME_REGEX)
147
+ - Regex matching follows `re.search()` semantics against construct names (tool behavior, independent of repository language).
148
+ - Prefer anchored patterns: exact `^Foo$`, prefix `^parse_`, suffix `Service$`. Use `.*` only when scope is already constrained by files/TAGs.
149
+ #### Failure modes you must handle
150
+ - "No constructs found": adjust TAGs (supported?), file paths, or NAME_REGEX (valid regex?).
151
+ - Regex-based extractor (not full AST): treat results as evidence pointers; confirm edge cases by opening referenced file/lines.
152
+
153
+ ### 4. Supplementary Search: `rg` / `git grep`
154
+ Use for: string/pattern searches inside code bodies, cross-file references, configuration values, error messages, or any content not captured by construct-name-based extraction.
155
+
156
+ ### Recommended Analysis Workflow
157
+ 1. **Read `{{PRJ_BASE}}/%%DOC_PATH%%/WORKFLOW.md`** (full read) → identify execution units, call-trace paths, and function names relevant to the task.
158
+ 2. **Read `{{PRJ_BASE}}/%%DOC_PATH%%/REFERENCES.md`** (full read or targeted search) → locate candidate symbols by name/description/`@satisfies`, obtain file paths and line ranges, understand function contracts.
159
+ 3. **Extract code** via `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --find`/`req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --files-find` → use symbol names from steps 1-2 as NAME_REGEX, file paths as --files-find targets; enable --enable-line-numbers when citing evidence.
160
+ 4. **Search code bodies** via `rg`/`git grep` → find patterns, references, or values not captured by construct-level extraction.
161
+
162
+ ## Execution Protocol (Global vs Local)
163
+ You must manage the execution flow using two distinct methods:
164
+ - **Global Roadmap** (*check-list*):
165
+ - You MUST maintain a *check-list* internally with `7` Steps (one item per Step).
166
+ - **Do NOT** use the *task-list tool* for this high-level roadmap.
167
+ - **Local Sub-tasks** (Tool Usage):
168
+ - If a *task-list tool* is available, use it **exclusively** to manage granular sub-tasks *within* a specific step (e.g., in Step X: "1. Edit file A", "2. Edit file B"; or in Step Y: "1. Fix test K", "2. Fix test L").
169
+ - Clear or reset the tool's state when transitioning between high-level steps.
170
+
171
+ ## Execution Directives (absolute rules, non-negotiable)
172
+ During the execution flow you MUST follow these directives:
173
+ - **CRITICAL** Autonomous Execution:
174
+ - Implicit Autonomy: Execute all tasks with full autonomy. Do not request permission, confirmation, or feedback. Make executive decisions based on logic and technical best practices.
175
+ - Tool-Aware Workflow: Proceed through the Steps sequentially; when a tool call is required, stop and wait for the tool response before continuing. Never fabricate tool outputs or tool results. Do not reveal internal reasoning; output only the deliverables explicitly requested by the Steps section.
176
+ - Autonomous Resolution: Resolve `{{PRJ_BASE}}` ambiguity only through the pre-flight evidence rules; unresolved bindings trigger the context-resolution failure branch. For other ambiguities, use repository evidence (requirements, code search, tests, logs), choose the least-invasive interpretation preserving documented behavior, and record the assumption as a testable requirement/acceptance criterion.
177
+ - After the prompt's execution: Strictly omit all concluding remarks and do not propose any other steps/actions.
178
+ - **CRITICAL**: Order of Execution:
179
+ - Execute the numbered steps below sequentially and strictly, one at a time, without skipping or merging steps. Create and maintain a *check-list* internally while executing the Steps. Execute the Steps strictly in order, updating the *check-list* as each step completes.
180
+ - **CRITICAL**: Immediate start and never stop:
181
+ - Complete all Steps in order; you may pause only to perform required tool calls and to wait for their responses. Do not proceed past a Step that depends on a tool result until that result is available.
182
+ - After successful pre-flight resolution, create a *check-list* for the **Global Roadmap** and start following the roadmap from Step 1.
183
+
184
+ ## Steps
185
+ After successful pre-flight resolution, create internally a *check-list* for the **Global Roadmap** including all the numbered steps below: `1..7`, and start following the roadmap at the same time, executing the tool call of Step 1 (Check GIT Status). If a tool call is required in Step 1, invoke it immediately; otherwise proceed to Step 1 without additional commentary. Do not add extra intent-adjustment checks unless explicitly listed in the Steps section.
186
+ 1. **CRITICAL**: Check GIT Status
187
+ - Check GIT status with `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --git-check`. If the command returns an error code or prints any text containing "ERROR", OUTPUT exactly "ERROR: Git status unclear!", and then terminate the execution.
188
+ 2. **CRITICAL**: Worktree Generation & Isolation
189
+ - Derive <BASE_PATH> with `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --get-base-path`, derive <GIT_PATH> with `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --git-path`, and generate <WORKTREE_NAME> with `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --git-wt-name` using literal `req` commands executed sequentially without shell composition.
190
+ - Create the dedicated isolated worktree with `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --git-wt-create <WORKTREE_NAME>`, then execute `cd <GIT_PATH>/../<WORKTREE_NAME>` before proceeding to the next step.
191
+ - If the command returns an error code or prints any text containing "ERROR", OUTPUT exactly "ERROR: Worktree generation failed!", and then terminate the execution.
192
+ - After successful worktree creation and directory change, apply the pre-flight context-transition rules before the next project operation. If rebinding fails, OUTPUT exactly "ERROR: Unable to resolve context keywords!", delete the isolated worktree and branch with `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --git-wt-delete <WORKTREE_NAME>`, and then terminate the execution. Apply this same failure cleanup to later context-resolution failures before merge-phase cleanup.
193
+
194
+ 3. Static analysis: build the runtime model from {{PRJ_BASE}}/%%SRC_PATHS%%
195
+ - Analyze only files under {{PRJ_BASE}}/%%SRC_PATHS%%; treat all files outside {{PRJ_BASE}}/%%SRC_PATHS%% as out of scope and never document them.
196
+ - Identify ALL execution units used at runtime:
197
+ - OS processes (MUST include the main process).
198
+ - OS threads (per process), including their entry functions/methods.
199
+ - If no explicit thread creation is present, record "no explicit threads detected" for that process.
200
+ - For EACH execution unit, derive entrypoint(s) and build a complete internal call-trace tree:
201
+ - Include ONLY internal functions as call-trace nodes (defined under {{PRJ_BASE}}/%%SRC_PATHS%%).
202
+ - Do NOT include external boundaries (system/library/framework calls) as nodes; annotate them only as external boundaries where relevant.
203
+ - No maximum depth: expand until an internal leaf function or an external boundary is reached.
204
+ - Identify ALL explicit communication edges between execution units and record for each edge:
205
+ - Direction (source -> destination), mechanism (IPC/thread communication), endpoint/channel (queue/topic/path/socket/etc.), and payload/data-shape references.
206
+
207
+ 4. Generate and overwrite `{{PRJ_BASE}}/%%DOC_PATH%%/FLOWCHART.md` document with a Mermaid flowchart representing the primary execution flow
208
+ - Isolate the core program functionality and disregard secondary or tangential flows.
209
+ - Group non-atomic functions into logical phases with sequential alphabetical labels.
210
+ - Inside each phase, extract atomic operations, label them with sequential integers, and document them using strictly parameterless function prototypes.
211
+ - Deduce actual control flow, branching, and joins from the code analyzed in Step 3.
212
+ - **Granularity consistency rule (CRITICAL):** maintain the same abstraction level across sibling branches that originate from the same decision node. If one branch exposes internal sub-operations of a composite internal function, then every sibling branch at that same decision depth MUST expose the equivalent internal sub-operations needed for semantic comparison; conversely, if one branch remains collapsed as a composite phase, sibling branches MUST NOT mix in a lower-level expansion unless that lower-level expansion is required in all sibling branches.
213
+ - **Comparability rule (CRITICAL):** the flowchart MUST make branch-to-branch equivalence explicit. Do not represent one branch as a wrapper function and another branch as the wrapper’s internal steps when both branches implement the same logical stage. Expand or collapse branches so that a downstream LLM Agent can compare them without inferring hidden steps.
214
+ - **Mandatory-entry vs optional-effect rule (CRITICAL):** explicitly distinguish between:
215
+ - mandatory stage entry: the caller always invokes the helper or stage wrapper;
216
+ - optional stage effect: the invoked helper may internally return the input unchanged, bypass its principal work, or otherwise behave as pass-through.
217
+ A helper that is always called MUST NOT be rendered as an unconditional application phase when its internal logic can disable the actual effect.
218
+ - **Decision-hoisting rule (CRITICAL):** when the first semantically relevant branch is internal to a composite helper, the flowchart MUST extract that branch outside the helper and render it as an explicit decision diamond using the real code condition expressed in strict pseudo-code.
219
+ - **Optional-wrapper detection heuristic (CRITICAL):** the agent MUST actively inspect composite helpers and wrappers for internal optional-work branches, including patterns such as:
220
+ - `if <mode> is None`
221
+ - `if not <enabled_flag>`
222
+ - enum or selector values such as `disable`
223
+ - early returns such as `return stage_input`, `return input_rgb`, or `return image_rgb_float`
224
+ - diagnostic messages indicating `disabled` or `pass-through`
225
+ - **Enable-state wrapper rule (CRITICAL):** if a composite helper contains enable-state validation and can bypass its principal work, the flowchart MUST render that condition as an explicit decision node even when the helper call itself is always executed. Wrappers with enable-state validation plus pass-through MUST NOT remain collapsed into a single phase node when the hidden decision changes the semantic meaning of the flow.
226
+ - **No hidden-step ambiguity rule (CRITICAL):** do not allow a phase node to visually imply that an internal operation is skipped when that operation is actually executed inside a composite helper, or to imply unconditional work when that helper can internally bypass the work. If a composite helper contains operations that are shown explicitly in an alternative branch, or contains the first relevant bypass condition for that logical stage, either:
227
+ - expand the composite helper to expose those operations and the bypass decision in the same decision region, or
228
+ - collapse the alternative branch to the same semantic level,
229
+ choosing the representation that maximizes branch readability and preserves the primary execution flow without hiding branch semantics.
230
+ - **Optional-stage representation rule (CRITICAL):** for a helper with mandatory stage entry and optional stage effect, the flowchart MUST show both semantic outcomes:
231
+ - disabled or bypass branch: render an explicit pass-through path to the next step;
232
+ - enabled branch: render either the phase node that actually applies the effect or a coherent expansion of its internal sub-steps.
233
+ - **Wrapper-function rule (CRITICAL):** a composite internal function MAY appear as a single visible phase only if its internal operations are not separately exposed elsewhere in parallel or sibling branches of the same logical decision region and it does not hide a decision that changes whether the stage effect is applied. If those operations are exposed elsewhere, or if such a decision exists, the composite function MUST be expanded enough to remove ambiguity.
234
+ - **Join readability rule (CRITICAL):** place joins only after branches have been normalized to a comparable semantic granularity and after enabled and disabled branches have actually reconverged. A join MUST NOT merge branches where one path still hides decision-relevant internal operations that are shown in another path.
235
+ - **Skipped-work rule (CRITICAL):** represent intentionally skipped work explicitly only when the source code emits or enforces a real skip condition. Do not create an apparent skip merely by collapsing one branch more aggressively than another. Real pass-through branches MUST be rendered as explicit bypasses.
236
+ - **Lexical signal check (CRITICAL):** before finalizing the flowchart, cross-check `{{PRJ_BASE}}/%%DOC_PATH%%/REQUIREMENTS.md` and `{{PRJ_BASE}}/%%DOC_PATH%%/WORKFLOW.md` for signal terms such as `optional`, `disabled`, `pass-through`, `enable-state validation`, `when omitted`, and `disable`; when those terms correspond to an analyzed stage or helper, ensure the flowchart reflects the same optionality semantics with visible decision and bypass structure.
237
+ - **Normative category example (CRITICAL):** "A helper always invoked by the caller but internally bypassed by an enable/disable selector MUST be rendered as a decision region, not as an unconditional application phase."
238
+ - Before writing the file, perform a strict internal audit cross-referencing the generated flowchart, the runtime model from Step 3, the original source code, and the lexical signals found in `{{PRJ_BASE}}/%%DOC_PATH%%/REQUIREMENTS.md` and `{{PRJ_BASE}}/%%DOC_PATH%%/WORKFLOW.md`.
239
+ - The internal audit MUST explicitly verify:
240
+ - every decision node has sibling branches rendered at comparable semantic granularity;
241
+ - every optional stage with mandatory stage entry has a visible decision node;
242
+ - every real pass-through is represented as an explicit bypass;
243
+ - no branch appears to omit an operation that is actually executed inside a composite helper;
244
+ - no composite helper hides a decision that changes the stage effect;
245
+ - every visible skip corresponds to a real code-level skip or bypass condition;
246
+ - no join occurs before enabled and disabled branches reconverge;
247
+ - every join occurs only after branch normalization.
248
+ - Mermaid generation rules:
249
+ - Write the final output strictly enclosed within ` ```mermaid ` and ` ``` ` fences.
250
+ - Use a vertical layout (`graph TD`).
251
+ - Flowchart nodes MUST represent phases and MUST contain the phase letter followed by the numbered list of atomic operations.
252
+ - Decision blocks MUST contain the decision criteria written in strict pseudo-code syntax.
253
+ - Use arrows and diamond nodes for branching, and do not output internal working tags in the final visible graph.
254
+ 5. **CRITICAL**: Stage & commit
255
+ - Show a summary of changes with `git diff` and `git diff --stat`.
256
+ - Stage changes explicitly (prefer targeted add; avoid `git add -A` if it may include unintended files): `git add <file...>` (ensure to include only `{{PRJ_BASE}}/%%DOC_PATH%%/FLOWCHART.md`).
257
+ - Ensure there is something to commit with: `git diff --cached --quiet && echo "Nothing to commit. Aborting."`. If command output contains "Aborting", OUTPUT exactly "No changes to commit.", and then delete the isolated worktree and branch with `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --git-wt-delete <WORKTREE_NAME>`, and then terminate the execution.
258
+ - Commit a structured commit message with: `git commit -m "docs(<COMPONENT>)<BREAKING>: <DESCRIPTION> [useReq]"`
259
+ - Set `<COMPONENT>` to the most specific component, module, or function affected. If multiple areas are touched, choose the primary one. If you cannot identify a unique component, use `core`.
260
+ - Set `<DESCRIPTION>` to a short, clear summary in **English language** of what changed, including (when applicable) updates to: requirements/specs, source code, tests. Use present tense, avoid vague wording, and keep it under ~80 characters if possible.
261
+ - Set `<BREAKING>` to `!` if a breaking change was implemented (a modification to an API, library, or system that breaks backward compatibility, causing dependent client applications or code to fail or behave incorrectly), set empty otherwise.
262
+ - Include main features added, requirements changes, or a bug-fix description adding a multi-line comment (maximum 10 lines).
263
+ - Do not include the 'Co-authored-by' trailer or any AI attribution. A GPG-signed commit is not required.
264
+ - Confirm the repo is clean with `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --git-check`. If the command returns an error code or prints any text containing "ERROR", override the final line with EXACTLY "WARNING: Flowchart request completed with unclean git repository!".
265
+ 6. **CRITICAL**: Merge Conflict Management
266
+ - Return to the original repository directory (the sibling directory of the worktree).
267
+ - Ensure you are on the original branch used before worktree creation by deriving `<BASE_PATH>` with `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --get-base-path` if needed and executing `cd <BASE_PATH>`.
268
+ - Merge the isolated branch into the original branch: `git merge <WORKTREE_NAME>`
269
+ - If the merge completes successfully, delete the isolated worktree and branch with `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --git-wt-delete <WORKTREE_NAME>`; if the command returns an error code or prints any text containing "ERROR", OUTPUT exactly "ERROR: Worktree cleanup verification failed!", and then terminate the execution.
270
+ - If the merge fails or results in conflicts, do NOT remove the worktree directory and override the final line with EXACTLY "WARNING: Flowchart request completed with merge conflicting!".
271
+ 7. Present results
272
+ - PRINT, in the response, the results for a human reader using clear, easily understandable sentences and readable Markdown formatting that highlight key findings, file paths, and concise evidence. Use the fixed report schema: ## **Outcome**, ## **Requirement Delta**, ## **Design Delta**, ## **Implementation Delta**, ## **Verification Delta**, ## **Evidence**, ## **Assumptions**, ## **Next Workflow**. Final line MUST be exactly: STATUS: OK or STATUS: ERROR.
@@ -0,0 +1,194 @@
1
+ ---
2
+ description: "Implement source code from requirements (from scratch)"
3
+ argument-hint: "No arguments utilized by the prompt logic"
4
+ usage: >
5
+ Use when the user asks to build an end-to-end implementation from authoritative REQUIREMENTS.md, including a from-scratch implementation or substantial missing functionality under the project source directories. Implement and verify required code and tests under the project test directory without changing the SRS. Use /req-cover for focused gaps in an existing implementation; /req-fix for a concrete defect; /req-new or /req-change when requirements must first evolve. Do not select for analysis or documentation-only work.
6
+ ---
7
+
8
+ # Implement source code from requirements from scratch
9
+
10
+ ## Pre-Flight: Context Keyword Resolution
11
+ - **CRITICAL**: Complete this read-only gate before any path-dependent action or numbered Step. Immediate-start directives apply only after success; autonomous disambiguation MUST NOT guess `{{PRJ_BASE}}` or `{{GIT_BASE}}`.
12
+ - Runtime keywords: resolve exactly two LLM-resolved path keywords in fixed order: `{{PRJ_BASE}}` first, `{{GIT_BASE}}` second. Installation has already supplied the documentation, source, and test paths; use them as fixed relative suffixes, not values to discover or replace.
13
+ - Project base: `{{PRJ_BASE}}` is the absolute base directory of the unique target project containing its installation-supplied `%%DOC_PATH%%`, `%%SRC_PATHS%%`, and `%%TEST_PATH%%` directories.
14
+ - Git base: `{{GIT_BASE}}` is the absolute base directory of the git repository containing `{{PRJ_BASE}}`. One git repository can contain multiple projects; repository identity alone never identifies the project.
15
+ - Resolution order: identify `{{PRJ_BASE}}` first and uniquely from current invocation routing and explicit task scope; use uniquely corroborated project path metadata only for missing evidence. The current directory is a candidate, not a default. Conflicting bindings, multiple plausible projects, or stale cross-project values fail resolution. Source-free workflows inspect path metadata only. After `{{PRJ_BASE}}` is bound, derive `{{GIT_BASE}}` as the git repository root containing the bound project base.
16
+ - Binding: retain `{{PRJ_BASE}}`, `{{GIT_BASE}}`, active worktree root, project identity, evidence, directory existence states, and document provenance throughout this invocation. Start fresh for each invocation; replace the bindings only after a validated context transition.
17
+ - Paths: substitute the resolved base in each prefixed path. For an installation-supplied source list, apply the base separately to every entry; preserve order and explicit list boundaries, never split on spaces or commas. Treat paths as data and quote each resulting literal argument separately, with option termination where supported.
18
+ - Containment: validate the base and resulting paths inside the active worktree, including symlink targets and existing ancestors of prospective paths. Accept absent directories only for authorized creation or explicitly unused source/test scopes; absence is not an unresolved base. Create nothing during pre-flight.
19
+ - Document contract below: filenames are relative to the installation-supplied documentation path under `{{PRJ_BASE}}`. Required inputs MUST exist; creatable targets MAY be absent. Load exactly the listed existing documents in full before Steps, including existing targets; defer reads of absent creatable targets until generated. Unlisted canonical documents are not prerequisites.
20
+ - Required inputs: REQUIREMENTS.md.
21
+ - Creatable targets: WORKFLOW.md, REFERENCES.md.
22
+ - Load when present: REQUIREMENTS.md, WORKFLOW.md, REFERENCES.md.
23
+ - Context reuse: treat injected or previously read content as loaded only when repository, worktree, project-area, path, and revision provenance match this binding. Current runtime attestation or unchanged-file evidence can establish a match; a basename alone cannot. Refresh stale or unverified content from the resolved path; reuse matching content without re-reading. After an edit, retain the verified updated content and invalidate superseded evidence.
24
+ - Operation scope: run cwd-sensitive commands and configured tools from `{{PRJ_BASE}}` only when their effective scope matches the target project; otherwise use a documented explicit-path equivalent or fail resolution.
25
+ - Activity routing: reference all project-modification and requirements-modification activities exclusively to `{{PRJ_BASE}}`; reference only working-tree creation and git-management activities to `{{GIT_BASE}}`.
26
+ - Context transitions: after an authorized worktree change, rebase `{{PRJ_BASE}}` to the same project-relative location in the new worktree and rebase `{{GIT_BASE}}` to the new worktree's repository root. Revalidate containment and document provenance before project operations; discard old absolute paths. Reuse document contents only with verified unchanged-file evidence. A different target project requires a fresh invocation.
27
+ - **CRITICAL**: If `{{PRJ_BASE}}` or `{{GIT_BASE}}`, required document, containment check, or effective tool scope remains unresolved or conflicting, OUTPUT exactly "ERROR: Unable to resolve context keywords!". Before isolation, terminate without cleanup; after successful isolation, follow the context-resolution failure cleanup in the isolation Step before terminating.
28
+
29
+ ## Purpose
30
+ Produce a working implementation from the normative SRS (`{{PRJ_BASE}}/%%DOC_PATH%%/REQUIREMENTS.md`) by building missing functionality end-to-end (including “from scratch” where needed), so the codebase becomes fully compliant with the documented requirement IDs without changing those requirements.
31
+
32
+ ## Scope
33
+ In scope: read `{{PRJ_BASE}}/%%DOC_PATH%%/REQUIREMENTS.md`, implement/introduce source under {{PRJ_BASE}}/%%SRC_PATHS%% (including new modules/files), add tests under {{PRJ_BASE}}/%%TEST_PATH%%, verify via static analysis (`req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --static-check`) and conditional execution of existing unit tests using language-specific test-suite priority policy, update `{{PRJ_BASE}}/%%DOC_PATH%%/WORKFLOW.md` and `{{PRJ_BASE}}/%%DOC_PATH%%/REFERENCES.md`, and commit. Out of scope: editing requirements or introducing features not present in the SRS (use `/req-change` or `/req-new` to evolve requirements first).
34
+
35
+
36
+ ## Professional Personas
37
+ - **Act as a Prompt Engineer and LLM Optimization Specialist** whenever you design, write, modify, or analyze prompts, agents, skills, or documents whose target audience is an LLM Agent instead of a human reader.
38
+ - **Act as a QA Automation Engineer** when identifying uncovered requirements: you must prove the lack of coverage through code analysis or static-analysis evidence gaps.
39
+ - **Act as a Business Analyst** when mapping requirement IDs from `{{PRJ_BASE}}/%%DOC_PATH%%/REQUIREMENTS.md` to observable behaviors.
40
+ - **Act as a Senior System Architect** when generating the **Implementation Delta** and planning the coverage strategy: ensure the new implementation integrates perfectly with the existing architecture without regressions.
41
+ - **Act as a Senior Software Developer** when implementing the missing logic: focus on satisfying the Requirement IDs previously marked as uncovered.
42
+ - **Act as a QA Engineer** during verification and testing Steps: verify compliance with zero leniency, using mandatory code evidence and strict fix loops based on static-analysis findings to ensure stability.
43
+ - **Act as an Expert GitOps Engineer** when executing git workflows, especially when creating/removing/managing git worktrees to isolate changes safely.
44
+
45
+
46
+ ## Iteration and Context Economy
47
+ - **CRITICAL**: Plan every Step to complete in the minimum number of iterations; batch independent reads, searches, and edits into a single response and dispatch parallel tool calls whenever no dependency forces sequencing.
48
+ - **CRITICAL**: Reuse injected or previously read file evidence only when repository, worktree, project-area, path, and revision identity match the active binding; do not re-read matching content. Refresh stale or unverified evidence under the pre-flight context-reuse rules.
49
+ - **CRITICAL**: MUST NOT restate requirement text, prior tool output, or unchanged file contents into the context; cite them by file path, symbol, and line range, quoting only the minimal changed snippet.
50
+ - **CRITICAL**: MUST add only information required by the active Step, a requirement ID, or explicit user-request text; omit narration, filler, restatements, and speculative commentary.
51
+ - **CRITICAL**: MUST choose the most token-efficient evidence path in order: `{{PRJ_BASE}}/%%DOC_PATH%%/REQUIREMENTS.md`, `{{PRJ_BASE}}/%%DOC_PATH%%/WORKFLOW.md`, `{{PRJ_BASE}}/%%DOC_PATH%%/REFERENCES.md`, then `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --find`/`req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --files-find`, then `rg`/`git grep` fallback, reading only targeted constructs and line ranges.
52
+ - **CRITICAL**: MUST gather all evidence a Step needs before producing its output and MUST NOT split a single logical operation across multiple iterations when one suffices.
53
+ - **CRITICAL**: MUST pause and wait for a tool response only when a Step explicitly depends on it; otherwise proceed autonomously to the next Step without requesting confirmation.
54
+ - **CRITICAL**: These rules MUST govern how the agent organizes and sequences the work described in the `## Steps` section.
55
+
56
+ ## Pre-requisite: Execution Context
57
+ - **CRITICAL**: All information declared in this `Pre-requisite: Execution Context` section MUST remain continuously available in the active execution context for the entire workflow and MUST NEVER be dropped, forgotten, or overwritten.
58
+ - Generate <WORKTREE_NAME> with `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --git-wt-name`, retain the literal result for later steps, and use simple sequential execution with only linear shell commands compatible with restrictive filtering systems for all worktree operations in this workflow.
59
+
60
+
61
+ ## Absolute Rules, Non-Negotiable
62
+ - **CRITICAL**: When instructions generate shell commands, they MUST generate only linear shell commands compatible with restrictive filtering systems, MUST verify and apply correct quoting, escaping, or option termination for literal arguments that could be parsed as options or flags, MUST use explicit option termination for `rg` and `git grep` patterns beginning with `-` or `--`, MUST NOT rely on quoting or backslash escaping alone for those patterns, and MUST NOT use command substitution (`$()` or backticks), complex variable expansion, nested substitution, shell-derived helper composition, nested shell logic, or nested pipelines.
63
+ - **CRITICAL**: Every `req` invocation MUST carry the mandatory parameters `--prj-base={{PRJ_BASE}}` and `--git-base={{GIT_BASE}}` with the resolved values; the removed `--base` parameter MUST NOT be used.
64
+ - **CRITICAL**: NEVER write, modify, edit, or delete files outside of the active git worktree directory, except under `/tmp`, and except for worktree operations executed through `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --git-wt-create <WORKTREE_NAME>` and `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --git-wt-delete <WORKTREE_NAME>`.
65
+ - You MUST read `{{PRJ_BASE}}/%%DOC_PATH%%/REQUIREMENTS.md`, but you MUST NOT modify it in this workflow.
66
+ - Treat static analysis as safe. Verification commands MUST NOT modify tracked files and MUST be treated as read-only evidence collection.
67
+ - **CRITICAL**: GIT operations and GIT rules:
68
+ - Do not run any shell/git commands and do not modify any files before starting Step 1 (including creating/modifying files, installing deps, formatting, etc.), except the read-only repository checks required by the `## Pre-Flight: Context Keyword Resolution` section: **CRITICAL**: Check GIT Status.
69
+ - Step 1 may run only the git commands `git rev-parse --is-inside-work-tree`, `git rev-parse --verify HEAD`, `git status --porcelain`, and `git symbolic-ref -q HEAD` (plus minimal shell built-ins to combine their outputs into a single cleanliness check).
70
+ - If the repository is NOT clean (modified files, staged changes, OR untracked files), exit immediately without changing anything.
71
+ - At the end you MUST commit only the intended changes with a unique identifier and change description in the commit message.
72
+ - Leave the working tree AND index clean (git `status --porcelain` must be empty).
73
+ - Do NOT “fix” a dirty repo by force (no `git reset --hard`, no `git clean -fd`, no stash) unless explicitly requested. If dirty: abort.
74
+ - **CRITICAL**: Generate, update, and maintain comprehensive **Doxygen-style documentation** for **ALL** code components (functions, classes, objects, structures, modules, variables, and new implementations), according to the **guidelines** in `.req/docs/Document_Source_Code_in_Doxygen_Style.md`. When writing documentation, adopt a "Parser-First" mindset. Your output is not prose; it is semantic metadata. Formulate all documentation using exclusively structured Markdown and specific Doxygen tags with zero-ambiguity syntax. Eliminate conversational filler ("This function...", "Basically..."). Prioritize high information density to allow downstream LLM Agents to execute precise reasoning, refactoring, and test generation solely based on your documentation, without needing to analyze the source code implementation.
75
+ - **CRITICAL**: Formulate all source code information using a highly structured, machine-interpretable Markdown format with unambiguous, atomic syntax to ensure maximum reliability for downstream LLM agentic reasoning, avoiding any conversational filler or subjective adjectives; the **target audience** is other **LLM Agents** and Automated Parsers, NOT humans, use high semantic density, optimized to contextually enable an LLM to perform future refactoring or extension.
76
+
77
+ ## Behavior
78
+ - Do not modify `{{PRJ_BASE}}/%%DOC_PATH%%/REQUIREMENTS.md`.
79
+ - Always strictly respect requirements.
80
+ - Use `{{PRJ_BASE}}/%%DOC_PATH%%/REQUIREMENTS.md`, `{{PRJ_BASE}}/%%DOC_PATH%%/WORKFLOW.md`, and `{{PRJ_BASE}}/%%DOC_PATH%%/REFERENCES.md` as the primary technical inputs; keep decisions traceable to requirements and repository evidence.
81
+ - All newly written or edited content MUST be in English. Do NOT translate existing text outside the minimal change surface required by this workflow; if you detect non-English text elsewhere, report it in **Evidence** instead of rewriting it.
82
+ - Prioritize backward compatibility. Do not introduce breaking changes; preserve existing interfaces, data formats, and features. If maintaining compatibility would require migrations/auto-upgrades conversion logic, report the conflict instead of implementing, and then terminate the execution.
83
+ - If `.venv/bin/python` exists in the project root, use it for Python executions (eg, `PYTHONPATH=src .venv/bin/python -m <program name>`).
84
+ - Non-Python tooling should use the project's standard commands.
85
+ - Use filesystem/shell tools to read/write/delete files as needed (e.g., `cat`, `sed`, `perl -pi`, `printf > file`, `rm -f`, ...). Prefer read-only commands for analysis.
86
+
87
+
88
+ ## Execution Protocol (Global vs Local)
89
+ You must manage the execution flow using two distinct methods:
90
+ - **Global Roadmap** (*check-list*):
91
+ - You MUST maintain a *check-list* internally with `10` Steps (one item per Step).
92
+ - **Do NOT** use the *task-list tool* for this high-level roadmap.
93
+ - **Local Sub-tasks** (Tool Usage):
94
+ - If a *task-list tool* is available, use it **exclusively** to manage granular sub-tasks *within* a specific step (e.g., in Step X: "1. Edit file A", "2. Edit file B"; or in Step Y: "1. Fix test K", "2. Fix test L").
95
+ - Clear or reset the tool's state when transitioning between high-level steps.
96
+
97
+ ## Execution Directives (absolute rules, non-negotiable)
98
+ During the execution flow you MUST follow these directives:
99
+ - **CRITICAL** Autonomous Execution:
100
+ - Implicit Autonomy: Execute all tasks with full autonomy. Do not request permission, confirmation, or feedback. Make executive decisions based on logic and technical best practices.
101
+ - Tool-Aware Workflow: Proceed through the Steps sequentially; when a tool call is required, stop and wait for the tool response before continuing. Never fabricate tool outputs or tool results. Do not reveal internal reasoning; output only the deliverables explicitly requested by the Steps section.
102
+ - Autonomous Resolution: Resolve `{{PRJ_BASE}}` ambiguity only through the pre-flight evidence rules; unresolved bindings trigger the context-resolution failure branch. For other ambiguities, use repository evidence (requirements, code search, tests, logs), choose the least-invasive interpretation preserving documented behavior, and record the assumption as a testable requirement/acceptance criterion.
103
+ - After the prompt's execution: Strictly omit all concluding remarks and do not propose any other steps/actions.
104
+ - **CRITICAL**: Order of Execution:
105
+ - Execute the numbered steps below sequentially and strictly, one at a time, without skipping or merging steps. Create and maintain a *check-list* internally while executing the Steps. Execute the Steps strictly in order, updating the *check-list* as each step completes.
106
+ - **CRITICAL**: Immediate start and never stop:
107
+ - Complete all Steps in order; you may pause only to perform required tool calls and to wait for their responses. Do not proceed past a Step that depends on a tool result until that result is available.
108
+ - After successful pre-flight resolution, create a *check-list* for the **Global Roadmap** and start following the roadmap from Step 1.
109
+
110
+
111
+ ## Steps
112
+ After successful pre-flight resolution, create internally a *check-list* for the **Global Roadmap** including all the numbered steps below: `1..10`, and start following the roadmap at the same time, executing the tool call of Step 1 (Check GIT Status). If a tool call is required in Step 1, invoke it immediately; otherwise proceed to Step 1 without additional commentary. Do not add extra intent-adjustment checks unless explicitly listed in the Steps section.
113
+ 1. **CRITICAL**: Check GIT Status
114
+ - Check GIT status with `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --git-check`. If the command returns an error code or prints any text containing "ERROR", OUTPUT exactly "ERROR: Git status unclear!", and then terminate the execution.
115
+ 2. **CRITICAL**: Worktree Generation & Isolation
116
+ - Derive <BASE_PATH> with `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --get-base-path`, derive <GIT_PATH> with `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --git-path`, and generate <WORKTREE_NAME> with `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --git-wt-name` using literal `req` commands executed sequentially without shell composition.
117
+ - Create the dedicated isolated worktree with `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --git-wt-create <WORKTREE_NAME>`, then execute `cd <GIT_PATH>/../<WORKTREE_NAME>` before proceeding to the next step.
118
+ - If the command returns an error code or prints any text containing "ERROR", OUTPUT exactly "ERROR: Worktree generation failed!", and then terminate the execution.
119
+ - After successful worktree creation and directory change, apply the pre-flight context-transition rules before the next project operation. If rebinding fails, OUTPUT exactly "ERROR: Unable to resolve context keywords!", delete the isolated worktree and branch with `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --git-wt-delete <WORKTREE_NAME>`, and then terminate the execution. Apply this same failure cleanup to later context-resolution failures before merge-phase cleanup.
120
+
121
+ 3. Read requirements, generate **Design Delta** and implement the **Implementation Delta** to cover all requirements
122
+ - Read `{{PRJ_BASE}}/%%DOC_PATH%%/REQUIREMENTS.md` and GENERATE a detailed **Implementation Delta** that covers all explicitly specified requirements, and explicitly list any requirement that cannot be implemented due to missing information or repository constraints. The **Implementation Delta** MUST be implementation-only: for each file, list exact developments (functions/classes created), and map each implementation to the requirement ID(s) it satisfies (no narrative summary).
123
+ - **ENFORCEMENT**: The definition of "valid code" strictly includes its documentation. You are mandatorily required to apply the Doxygen-LLM Standard defined in `.req/docs/Document_Source_Code_in_Doxygen_Style.md` to every single code component. Any code block generated without this specific documentation format is considered a compilation error and must be rejected/regenerated.
124
+ - Read %%GUIDELINES_FILES%% files and apply those **guidelines**; ensure the proposed code changes conform to those **guidelines**, and adjust the **Implementation Delta** if needed. Do not apply unrelated **guidelines**.
125
+ - Locate existing unit tests in {{PRJ_BASE}}/%%TEST_PATH%% that map to implemented requirement IDs; include in the **Implementation Delta** the language-specific priority order for verification runs, and record test execution as N/A when no relevant unit tests exist.
126
+ - **CRITICAL**: All tests MUST implement these instructions: `.req/docs/HDT_Test_Authoring_Guide.md`.
127
+ - Read %%GUIDELINES_FILES%% files and apply those **guidelines**; ensure the proposed code changes conform to those **guidelines**, and adjust the **Implementation Delta** if needed. Do not apply unrelated **guidelines**.
128
+ - IMPLEMENT the **Implementation Delta** in the source code (creating new files/directories if necessary) from scratch.
129
+ 4. Generate **Verification Delta** by verifying static-analysis results and implementing needed bug fixes
130
+ - Read ALL requirements from `{{PRJ_BASE}}/%%DOC_PATH%%/REQUIREMENTS.md`, analyze them one by one, and cross-reference them with the source code to check requirements. For each requirement, use tools (e.g., `git grep`, `find`, `ls`) to locate the relevant source code files used as evidence, read only the identified files to verify compliance, and do not assume compliance without locating the specific code implementation.
131
+ - For each requirement, report `OK` if satisfied or `FAIL` if not.
132
+ - Do not mark a requirement as `OK` without code evidence; for `OK` items provide only a compact pointer (file path + symbol + line range). For each requirement, provide a concise evidence pointer (file path + symbol + line range) excerpts only for `FAIL` requirements or when requirement is architectural, structural, or negative (e.g., "MUST NOT ..."). For such high-level requirements, cite the specific file paths or directory structures that prove compliance. Line ranges MUST be obtained from tooling output (e.g., `nl -ba` / `sed -n`) and MUST NOT be estimated. If evidence is missing, you MUST report `FAIL`. Do not assume implicit behavior.
133
+ - For every `FAIL`, provide evidence with a short explanation. Provide file path(s) and line numbers where possible.
134
+ - Perform a static analysis check by executing `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --static-check`.
135
+ - Review the produced output and fix every reported issue in source code.
136
+ - Re-run `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --static-check` until it produces no issues. If output is exactly `Error: no source files found in configured directories.`, treat it as successful no-source completion and continue without retries.
137
+ - If relevant unit tests already exist in the repository, run them during verification using language-specific test-suite priority policy: project-defined test command first, language-default unit-test command second; if no relevant tests exist, record test execution as N/A and continue.
138
+ - Verify that the implemented changes satisfy requirements evidence, static-analysis output, and unit-test outputs when tests are executed.
139
+ - If static analysis reports issues or executed unit tests fail, determine whether they are caused by source defects or requirement-implementation mismatch. Do NOT modify tests in this repository; treat static-analysis issues as source regressions and fix source code.
140
+ - Fix the source code to resolve valid verification findings autonomously without asking for user intervention. Execute a strict fix loop: 1) analyze static-check output and unit-test failures (when tests ran), 2) determine root cause from evidence, 3) fix code, 4) re-run `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --static-check` and re-run the selected unit-test suites when applicable. Repeat up to 2 times. If static analysis still reports issues after the second attempt, report the failure, OUTPUT exactly "ERROR: Implement request failed due to inability to complete static analysis!", delete the isolated worktree and branch with `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --git-wt-delete <WORKTREE_NAME>`, and then terminate the execution.
141
+ - Limitations: Do not introduce new features or change the architecture logic during this fix phase; if a fix requires substantial refactoring or requirements changes, report the failure, then OUTPUT exactly "ERROR: Implement request failed due to requirements incompatible with static-analysis constraints!", delete the isolated worktree and branch with `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --git-wt-delete <WORKTREE_NAME>`, and then terminate the execution.
142
+ - Do NOT create or modify tests in this repository.
143
+ 5. Static analysis: build the runtime model from {{PRJ_BASE}}/%%SRC_PATHS%%
144
+ - Analyze only files under {{PRJ_BASE}}/%%SRC_PATHS%%; treat all files outside {{PRJ_BASE}}/%%SRC_PATHS%% as out of scope and never document them.
145
+ - Identify ALL execution units used at runtime:
146
+ - OS processes (MUST include the main process).
147
+ - OS threads (per process), including their entry functions/methods.
148
+ - If no explicit thread creation is present, record "no explicit threads detected" for that process.
149
+ - For EACH execution unit, derive entrypoint(s) and build a complete internal call-trace tree:
150
+ - Include ONLY internal functions as call-trace nodes (defined under {{PRJ_BASE}}/%%SRC_PATHS%%).
151
+ - Do NOT include external boundaries (system/library/framework calls) as nodes; annotate them only as external boundaries where relevant.
152
+ - No maximum depth: expand until an internal leaf function or an external boundary is reached.
153
+ - Identify ALL explicit communication edges between execution units and record for each edge:
154
+ - Direction (source -> destination), mechanism (IPC/thread communication), endpoint/channel (queue/topic/path/socket/etc.), and payload/data-shape references.
155
+ 6. Generate and overwrite `{{PRJ_BASE}}/%%DOC_PATH%%/WORKFLOW.md` document using declaration file paths only, excluding line numbers, line ranges, and internal file-reference pointers
156
+ - Read any existing `{{PRJ_BASE}}/%%DOC_PATH%%/WORKFLOW.md` to preserve stable IDs and minimize unnecessary churn, then update it to strictly conform to the Output Contract above.
157
+ - Generate {{PRJ_BASE}}/%%DOC_PATH%%/WORKFLOW.md in English only using deterministic, machine-interpretable Markdown with the required schema and stable field order.
158
+ - During generation/update, include declaration file paths only; MUST NOT include line numbers, line ranges, or internal file-reference pointers.
159
+ - `## Execution Units Index` (stable IDs)
160
+ - Use stable IDs: `PROC:main`, `PROC:<name>` for processes; `THR:<proc_id>#<name>` for threads.
161
+ - For each execution unit: ID, type (process/thread), parent process (for threads), role, entrypoint symbol(s), and defining file(s).
162
+ - `## Execution Units`
163
+ - One subsection per execution unit ID including:
164
+ - Entrypoint(s)
165
+ - Lifecycle/trigger (how it starts, stops, and loops/blocks)
166
+ - Internal Call-Trace Tree (internal functions only; no maximum depth)
167
+ - External Boundaries (file I/O, network, DB, external APIs, OS interaction)
168
+ - `## Communication Edges`
169
+ - List ALL `Communication Edge` items with direction + mechanism + endpoint/channel + payload/data-shape reference + declaration file path references only.
170
+ - Call-trace node format (MUST be consistent):
171
+ - `symbol_name(...)`: `<single-line role>` [`<defining filepath>`]
172
+ - `<optional: brief invariants/external boundaries>`
173
+ - `<child internal calls as nested bullet list, in call order>`
174
+ 7. Update `{{PRJ_BASE}}/%%DOC_PATH%%/REFERENCES.md` references file
175
+ - Create/update the references file with `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --references >"{{PRJ_BASE}}/%%DOC_PATH%%/REFERENCES.md"`
176
+ 8. **CRITICAL**: Stage & commit
177
+ - Show a summary of changes with `git diff` and `git diff --stat`.
178
+ - Stage changes explicitly (prefer targeted add; avoid `git add -A` if it may include unintended files): `git add <file...>` (ensure to include all modified source code & test and WORKFLOW.md only if it was modified/created).
179
+ - Ensure there is something to commit with: `git diff --cached --quiet && echo "Nothing to commit. Aborting."`. If command output contains "Aborting", OUTPUT exactly "No changes to commit.", and then delete the isolated worktree and branch with `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --git-wt-delete <WORKTREE_NAME>`, and then terminate the execution.
180
+ - Commit a structured commit message with: `git commit -m "implement(<COMPONENT>)<BREAKING>: <DESCRIPTION> [useReq]"`
181
+ - Set `<COMPONENT>` to the most specific component, module, or function affected. If multiple areas are touched, choose the primary one. If you cannot identify a unique component, use `core`.
182
+ - Set `<DESCRIPTION>` to a short, clear summary in **English language** of what changed, including (when applicable) updates to: requirements/specs, source code, tests. Use present tense, avoid vague wording, and keep it under ~80 characters if possible.
183
+ - Set `<BREAKING>` to `!` if a breaking change was implemented (a modification to an API, library, or system that breaks backward compatibility, causing dependent client applications or code to fail or behave incorrectly), set empty otherwise.
184
+ - Include main features added, requirements changes, or a bug-fix description adding a multi-line comment (maximum 10 lines).
185
+ - Do not include the 'Co-authored-by' trailer or any AI attribution. A GPG-signed commit is not required.
186
+ - Confirm the repo is clean with `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --git-check`. If the command returns an error code or prints any text containing "ERROR", override the final line with EXACTLY "WARNING: Implement request completed with unclean git repository!".
187
+ 9. **CRITICAL**: Merge Conflict Management
188
+ - Return to the original repository directory (the sibling directory of the worktree).
189
+ - Ensure you are on the original branch used before worktree creation by deriving `<BASE_PATH>` with `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --get-base-path` if needed and executing `cd <BASE_PATH>`.
190
+ - Merge the isolated branch into the original branch: `git merge <WORKTREE_NAME>`
191
+ - If the merge completes successfully, delete the isolated worktree and branch with `req --prj-base={{PRJ_BASE}} --git-base={{GIT_BASE}} --git-wt-delete <WORKTREE_NAME>`; if the command returns an error code or prints any text containing "ERROR", OUTPUT exactly "ERROR: Worktree cleanup verification failed!", and then terminate the execution.
192
+ - If the merge fails or results in conflicts, do NOT remove the worktree directory and override the final line with EXACTLY "WARNING: Implement request completed with merge conflicting!".
193
+ 10. Present results
194
+ - PRINT, in the response, the results for a human reader using clear, easily understandable sentences and readable Markdown formatting that highlight key findings, file paths, and concise evidence. Use the fixed report schema: ## **Outcome**, ## **Requirement Delta**, ## **Design Delta**, ## **Implementation Delta**, ## **Verification Delta**, ## **Evidence**, ## **Assumptions**, ## **Next Workflow**. Final line MUST be exactly: STATUS: OK or STATUS: ERROR.