Skip to content

Commit 73c7589

Browse files
davidmatousekclaude
andcommitted
fix: auto-detect newest docs/security run directory in tachi commands
When invoked without an input/target directory argument, the four downstream tachi commands (tachi.risk-score, tachi.compensating-controls, tachi.infographic, tachi.security-report) defaulted to current working directory. Users running these from a project root with multiple timestamped runs in docs/security/ would silently miss their data. New behavior — applied consistently across all four commands: - If ./docs/security/ exists in cwd: glob docs/security/*/, sort directory names descending (ISO-like YYYY-MM-DDTHH-MM-SS timestamps sort correctly as strings), and select the newest directory containing the required artifact: * tachi.risk-score → threats.md or threats.sarif * tachi.compensating-controls → risk-scores.md or risk-scores.sarif * tachi.infographic → compensating-controls.md, risk-scores.md, or threats.md * tachi.security-report → threats.md (minimum required) - Display: "Auto-detected input/target: {path}" - Otherwise: fall back to cwd (existing default preserved) Backward compatible — explicit path argument continues to override. The tachi.infographic change also fixes a redundant "Set data_source_dir to current working directory" line that ran after the per-file path resolution. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 31e775a commit 73c7589

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

.claude/commands/tachi.compensating-controls.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ Consider user input before proceeding (if not empty).
2323
4. Default: `output_dir = null` (outputs written to same directory as input risk-scores)
2424

2525
5. Remaining `$ARGUMENTS` is treated as the risk-score input directory path.
26-
6. Default input directory: current working directory (`.`)
26+
6. If no input directory was provided in `$ARGUMENTS`:
27+
- If `./docs/security/` exists in cwd: glob `docs/security/*/`, sort directory names descending (ISO-like `YYYY-MM-DDTHH-MM-SS` timestamps sort correctly as strings), and select the newest directory that contains `risk-scores.md` or `risk-scores.sarif`. Set `input_dir` to that path and display: `Auto-detected input: {input_dir}`.
28+
- Otherwise, default to current working directory (`.`).
2729

2830
## Overview
2931

.claude/commands/tachi.infographic.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,15 @@ Single-command entry point for tachi threat infographic generation — the visua
8484
- Set `data_source_dir` to the directory containing the file
8585
8686
**If no explicit path** (auto-detect):
87-
- Scan current working directory for `compensating-controls.md`
88-
- If found: set `primary_file = compensating-controls.md`, type is `compensating-controls`
89-
- If `compensating-controls.md` not found, scan for `risk-scores.md`
90-
- If found: set `primary_file = risk-scores.md`, type is `risk-scores`
91-
- If `risk-scores.md` not found, scan for `threats.md`
92-
- If found: set `primary_file = threats.md`, type is `threats`
87+
- Determine scan directory:
88+
- If `./docs/security/` exists in cwd: glob `docs/security/*/`, sort directory names descending (ISO-like `YYYY-MM-DDTHH-MM-SS` timestamps sort correctly as strings), and select the newest directory that contains at least one of `compensating-controls.md`, `risk-scores.md`, or `threats.md`. Set `data_source_dir` to that path and display: `Auto-detected data source dir: {data_source_dir}`.
89+
- Otherwise, set `data_source_dir` to current working directory.
90+
- Scan `data_source_dir` for `compensating-controls.md`
91+
- If found: set `primary_file = {data_source_dir}/compensating-controls.md`, type is `compensating-controls`
92+
- If `compensating-controls.md` not found, scan `data_source_dir` for `risk-scores.md`
93+
- If found: set `primary_file = {data_source_dir}/risk-scores.md`, type is `risk-scores`
94+
- If `risk-scores.md` not found, scan `data_source_dir` for `threats.md`
95+
- If found: set `primary_file = {data_source_dir}/threats.md`, type is `threats`
9396
- If none found, display:
9497
```
9598
NO DATA SOURCE FILES FOUND
@@ -101,7 +104,6 @@ Single-command entry point for tachi threat infographic generation — the visua
101104
Then optionally: /risk-score → /compensating-controls for richer data.
102105
```
103106
- Halt if none found.
104-
- Set `data_source_dir` to current working directory
105107
106108
3. **Co-located threats.md check** (when type is `risk-scores` or `compensating-controls`):
107109
- Verify `threats.md` exists in `data_source_dir`

.claude/commands/tachi.risk-score.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ Consider user input before proceeding (if not empty).
1818
2. Default: `output_dir = null` (outputs written to same directory as input)
1919

2020
3. Remaining `$ARGUMENTS` is treated as the input directory path.
21-
4. Default input directory: current working directory (`.`)
21+
4. If no input directory was provided in `$ARGUMENTS`:
22+
- If `./docs/security/` exists in cwd: glob `docs/security/*/`, sort directory names descending (ISO-like `YYYY-MM-DDTHH-MM-SS` timestamps sort correctly as strings), and select the newest directory that contains `threats.md` or `threats.sarif`. Set `input_dir` to that path and display: `Auto-detected input: {input_dir}`.
23+
- Otherwise, default to current working directory (`.`).
2224

2325
## Overview
2426

.claude/commands/tachi.security-report.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ Consider user input before proceeding (if not empty).
2323
4. Default: `title_override = null` (auto-detected from `threats.md` frontmatter in agent)
2424

2525
5. Remaining `$ARGUMENTS` is treated as the target directory path.
26-
6. Default: `target_dir = current working directory`
26+
6. If no target directory was provided in `$ARGUMENTS`:
27+
- If `./docs/security/` exists in cwd: glob `docs/security/*/`, sort directory names descending (ISO-like `YYYY-MM-DDTHH-MM-SS` timestamps sort correctly as strings), and select the newest directory that contains `threats.md` (the minimum required artifact). Set `target_dir` to that path and display: `Auto-detected target: {target_dir}`.
28+
- Otherwise, default to current working directory (`.`).
2729

2830
## Overview
2931

0 commit comments

Comments
 (0)