codexspec 0.7.7__tar.gz → 0.7.8__tar.gz

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 (67) hide show
  1. {codexspec-0.7.7 → codexspec-0.7.8}/PKG-INFO +3 -2
  2. {codexspec-0.7.7 → codexspec-0.7.8}/README.md +1 -0
  3. {codexspec-0.7.7 → codexspec-0.7.8}/pyproject.toml +1 -1
  4. {codexspec-0.7.7 → codexspec-0.7.8}/src/codexspec/__init__.py +11 -1
  5. {codexspec-0.7.7 → codexspec-0.7.8}/src/codexspec/commands/installer.py +10 -3
  6. {codexspec-0.7.7 → codexspec-0.7.8}/src/codexspec/integrations/codex.py +5 -0
  7. codexspec-0.7.8/src/codexspec/profile.py +112 -0
  8. codexspec-0.7.8/templates/commands/debug.md +80 -0
  9. {codexspec-0.7.7 → codexspec-0.7.8}/templates/commands/distill.md +14 -13
  10. {codexspec-0.7.7 → codexspec-0.7.8}/templates/commands/implement-tasks.md +23 -1
  11. {codexspec-0.7.7 → codexspec-0.7.8}/templates/commands/specify.md +9 -0
  12. {codexspec-0.7.7 → codexspec-0.7.8}/.gitignore +0 -0
  13. {codexspec-0.7.7 → codexspec-0.7.8}/LICENSE +0 -0
  14. {codexspec-0.7.7 → codexspec-0.7.8}/codexspec-icon.svg +0 -0
  15. {codexspec-0.7.7 → codexspec-0.7.8}/codexspec-logo-dark.svg +0 -0
  16. {codexspec-0.7.7 → codexspec-0.7.8}/codexspec-logo-light.svg +0 -0
  17. {codexspec-0.7.7 → codexspec-0.7.8}/scripts/bash/check-i18n-completeness.sh +0 -0
  18. {codexspec-0.7.7 → codexspec-0.7.8}/scripts/bash/check-i18n-structure.sh +0 -0
  19. {codexspec-0.7.7 → codexspec-0.7.8}/scripts/bash/check-prerequisites.sh +0 -0
  20. {codexspec-0.7.7 → codexspec-0.7.8}/scripts/bash/common.sh +0 -0
  21. {codexspec-0.7.7 → codexspec-0.7.8}/scripts/bash/create-new-feature.sh +0 -0
  22. {codexspec-0.7.7 → codexspec-0.7.8}/scripts/bash/review-context.sh +0 -0
  23. {codexspec-0.7.7 → codexspec-0.7.8}/scripts/powershell/check-prerequisites.ps1 +0 -0
  24. {codexspec-0.7.7 → codexspec-0.7.8}/scripts/powershell/common.ps1 +0 -0
  25. {codexspec-0.7.7 → codexspec-0.7.8}/scripts/powershell/create-new-feature.ps1 +0 -0
  26. {codexspec-0.7.7 → codexspec-0.7.8}/scripts/powershell/review-context.ps1 +0 -0
  27. {codexspec-0.7.7 → codexspec-0.7.8}/src/codexspec/commands/__init__.py +0 -0
  28. {codexspec-0.7.7 → codexspec-0.7.8}/src/codexspec/i18n.py +0 -0
  29. {codexspec-0.7.7 → codexspec-0.7.8}/src/codexspec/idea.md +0 -0
  30. {codexspec-0.7.7 → codexspec-0.7.8}/src/codexspec/integrations/__init__.py +0 -0
  31. {codexspec-0.7.7 → codexspec-0.7.8}/src/codexspec/integrations/base.py +0 -0
  32. {codexspec-0.7.7 → codexspec-0.7.8}/src/codexspec/integrations/claude.py +0 -0
  33. {codexspec-0.7.7 → codexspec-0.7.8}/src/codexspec/translator.py +0 -0
  34. {codexspec-0.7.7 → codexspec-0.7.8}/templates/commands/analyze.md +0 -0
  35. {codexspec-0.7.7 → codexspec-0.7.8}/templates/commands/checklist.md +0 -0
  36. {codexspec-0.7.7 → codexspec-0.7.8}/templates/commands/clarify.md +0 -0
  37. {codexspec-0.7.7 → codexspec-0.7.8}/templates/commands/commit-staged.md +0 -0
  38. {codexspec-0.7.7 → codexspec-0.7.8}/templates/commands/config.md +0 -0
  39. {codexspec-0.7.7 → codexspec-0.7.8}/templates/commands/constitution.md +0 -0
  40. {codexspec-0.7.7 → codexspec-0.7.8}/templates/commands/evolve.md +0 -0
  41. {codexspec-0.7.7 → codexspec-0.7.8}/templates/commands/generate-spec.md +0 -0
  42. {codexspec-0.7.7 → codexspec-0.7.8}/templates/commands/plan-to-tasks.md +0 -0
  43. {codexspec-0.7.7 → codexspec-0.7.8}/templates/commands/pr.md +0 -0
  44. {codexspec-0.7.7 → codexspec-0.7.8}/templates/commands/quick.md +0 -0
  45. {codexspec-0.7.7 → codexspec-0.7.8}/templates/commands/review-code.md +0 -0
  46. {codexspec-0.7.7 → codexspec-0.7.8}/templates/commands/review-plan.md +0 -0
  47. {codexspec-0.7.7 → codexspec-0.7.8}/templates/commands/review-spec.md +0 -0
  48. {codexspec-0.7.7 → codexspec-0.7.8}/templates/commands/review-tasks.md +0 -0
  49. {codexspec-0.7.7 → codexspec-0.7.8}/templates/commands/spec-to-plan.md +0 -0
  50. {codexspec-0.7.7 → codexspec-0.7.8}/templates/commands/tasks-to-issues.md +0 -0
  51. {codexspec-0.7.7 → codexspec-0.7.8}/templates/docs/checklist-template.md +0 -0
  52. {codexspec-0.7.7 → codexspec-0.7.8}/templates/docs/constitution-template.md +0 -0
  53. {codexspec-0.7.7 → codexspec-0.7.8}/templates/docs/plan-template-detailed.md +0 -0
  54. {codexspec-0.7.7 → codexspec-0.7.8}/templates/docs/plan-template-simple.md +0 -0
  55. {codexspec-0.7.7 → codexspec-0.7.8}/templates/docs/requirements-template.md +0 -0
  56. {codexspec-0.7.7 → codexspec-0.7.8}/templates/docs/spec-template-detailed.md +0 -0
  57. {codexspec-0.7.7 → codexspec-0.7.8}/templates/docs/spec-template-simple.md +0 -0
  58. {codexspec-0.7.7 → codexspec-0.7.8}/templates/docs/tasks-template-detailed.md +0 -0
  59. {codexspec-0.7.7 → codexspec-0.7.8}/templates/docs/tasks-template-simple.md +0 -0
  60. {codexspec-0.7.7 → codexspec-0.7.8}/templates/translations/de.json +0 -0
  61. {codexspec-0.7.7 → codexspec-0.7.8}/templates/translations/en.json +0 -0
  62. {codexspec-0.7.7 → codexspec-0.7.8}/templates/translations/es.json +0 -0
  63. {codexspec-0.7.7 → codexspec-0.7.8}/templates/translations/fr.json +0 -0
  64. {codexspec-0.7.7 → codexspec-0.7.8}/templates/translations/ja.json +0 -0
  65. {codexspec-0.7.7 → codexspec-0.7.8}/templates/translations/ko.json +0 -0
  66. {codexspec-0.7.7 → codexspec-0.7.8}/templates/translations/pt-BR.json +0 -0
  67. {codexspec-0.7.7 → codexspec-0.7.8}/templates/translations/zh-CN.json +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: codexspec
3
- Version: 0.7.7
3
+ Version: 0.7.8
4
4
  Summary: CodexSpec - A Requirements-First SDD toolkit for Claude Code
5
5
  Project-URL: Homepage, https://github.com/Zts0hg/codexspec
6
6
  Project-URL: Repository, https://github.com/Zts0hg/codexspec
@@ -589,6 +589,7 @@ Implementation follows **conditional TDD workflow**:
589
589
  | `/codexspec:analyze` | Cross-artifact consistency analysis (auto-remediating, severity-based) |
590
590
  | `/codexspec:checklist` | Generate requirements quality checklist |
591
591
  | `/codexspec:tasks-to-issues` | Convert tasks to GitHub Issues |
592
+ | `/codexspec:debug` | Systematic root-cause debugging (4 phases; standalone or escalated from implement-tasks) |
592
593
 
593
594
  #### Self-Evolution Commands
594
595
 
@@ -544,6 +544,7 @@ Implementation follows **conditional TDD workflow**:
544
544
  | `/codexspec:analyze` | Cross-artifact consistency analysis (auto-remediating, severity-based) |
545
545
  | `/codexspec:checklist` | Generate requirements quality checklist |
546
546
  | `/codexspec:tasks-to-issues` | Convert tasks to GitHub Issues |
547
+ | `/codexspec:debug` | Systematic root-cause debugging (4 phases; standalone or escalated from implement-tasks) |
547
548
 
548
549
  #### Self-Evolution Commands
549
550
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "codexspec"
3
- version = "0.7.7"
3
+ version = "0.7.8"
4
4
  description = "CodexSpec - A Requirements-First SDD toolkit for Claude Code"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -40,10 +40,11 @@ from .i18n import (
40
40
  update_language_field,
41
41
  )
42
42
  from .integrations import get_integrations
43
+ from .profile import ensure_profile_scaffold, inject_profile_block
43
44
  from .translator import SUPPORTED_LANGUAGES, translate
44
45
 
45
46
  # Version info
46
- __version__ = "0.7.7"
47
+ __version__ = "0.7.8"
47
48
  __author__ = "CodexSpec Team"
48
49
 
49
50
  # Constitution file path constants
@@ -706,6 +707,11 @@ def init(
706
707
  (codexspec_dir / "templates" / "docs").mkdir(exist_ok=True)
707
708
  (codexspec_dir / "scripts").mkdir(exist_ok=True)
708
709
 
710
+ # Ensure the profile scaffold unconditionally (independent of integrations),
711
+ # so knowledge distilled later is effective immediately with no re-init and
712
+ # no dangling reference. Non-destructive: existing profile files are kept.
713
+ ensure_profile_scaffold(target_dir)
714
+
709
715
  # Copy helper scripts based on platform
710
716
  scripts_source_dir = get_scripts_dir()
711
717
  if scripts_source_dir.exists():
@@ -884,6 +890,10 @@ def init(
884
890
  prepend_compliance_section(claude_md)
885
891
  console.print(f"[green]{translate('cli.init.compliance_added', normalized_lang)}[/green]")
886
892
 
893
+ # Inject the profile block AFTER creation/compliance so it never clobbers
894
+ # the compliance @import or the user's body (bounded, idempotent).
895
+ inject_profile_block(claude_md)
896
+
887
897
  # Initialize git if requested
888
898
  if not no_git and not (target_dir / ".git").exists():
889
899
  try:
@@ -47,8 +47,8 @@ def get_commands_metadata() -> list[CommandMetadata]:
47
47
 
48
48
  Returns:
49
49
  List of CommandMetadata dictionaries sorted by category priority:
50
- core (9) -> enhanced (6) -> git (2) -> review (1) -> utility (2)
51
- Total: 20 commands
50
+ core (9) -> enhanced (7) -> git (2) -> review (1) -> utility (2)
51
+ Total: 21 commands
52
52
  """
53
53
  return [
54
54
  # Core Commands (9)
@@ -115,7 +115,7 @@ def get_commands_metadata() -> list[CommandMetadata]:
115
115
  "category": "core",
116
116
  "file_name": "implement-tasks.md",
117
117
  },
118
- # Enhanced Commands (4)
118
+ # Enhanced Commands (7)
119
119
  {
120
120
  "name": "clarify",
121
121
  "display_name": "/codexspec:clarify",
@@ -158,6 +158,13 @@ def get_commands_metadata() -> list[CommandMetadata]:
158
158
  "category": "enhanced",
159
159
  "file_name": "evolve.md",
160
160
  },
161
+ {
162
+ "name": "debug",
163
+ "display_name": "/codexspec:debug",
164
+ "description": "系统化根因排查(四阶段:复现→定位根因→单一修复),可独立调用或由 implement-tasks 升级进入",
165
+ "category": "enhanced",
166
+ "file_name": "debug.md",
167
+ },
161
168
  # Git Workflow Commands (2)
162
169
  {
163
170
  "name": "commit-staged",
@@ -10,6 +10,7 @@ from typing import Any
10
10
  import yaml
11
11
 
12
12
  from codexspec.commands.installer import get_commands_metadata
13
+ from codexspec.profile import inject_profile_block
13
14
  from codexspec.translator import load_translation_cache, translate_template_frontmatter
14
15
 
15
16
  CODEXSPEC_CONTEXT_START = "<!-- CODEXSPEC START -->"
@@ -90,6 +91,10 @@ class CodexIntegration:
90
91
 
91
92
  context_path.write_text(updated, encoding="utf-8")
92
93
 
94
+ # Inject the profile block (pointers only, no @import) alongside the
95
+ # skills section, as its own bounded, idempotent managed block.
96
+ inject_profile_block(context_path)
97
+
93
98
  def render_skill(self, command_name: str, content: str, fallback_description: str = "") -> str:
94
99
  """Render one command template into a Codex SKILL.md."""
95
100
  frontmatter, body = _split_frontmatter(content)
@@ -0,0 +1,112 @@
1
+ """Project-profile consumption.
2
+
3
+ Wires a user project's ``.codexspec/profile/`` into the AI context files so that
4
+ knowledge distilled by ``/codexspec:distill`` is consulted in later work.
5
+
6
+ Store layout: **one record per file** under a per-category directory
7
+ (``constraints/`` ``conventions/`` ``pitfalls/`` ``decisions/``). Because parallel
8
+ feature branches each add differently-named record files, their distilled
9
+ knowledge merges without conflict.
10
+
11
+ Two concerns live here:
12
+
13
+ - ``ensure_profile_scaffold`` — create the four category directories (each kept
14
+ by a ``.gitkeep``) so every injected reference resolves, independent of whether
15
+ any knowledge has been distilled yet.
16
+ - ``render_profile_block`` / ``inject_profile_block`` — render a bounded,
17
+ channel-neutral managed block (pointers only, no ``@import``) and inject it
18
+ idempotently into a context file (CLAUDE.md or AGENTS.md) without disturbing any
19
+ other content.
20
+
21
+ See the feature record under
22
+ ``.codexspec/specs/2026-0812-14054p-profile-consumption/``.
23
+ """
24
+
25
+ import re
26
+ from pathlib import Path
27
+
28
+ # Ordered: constraints first (highest weight, honored first). Each is a directory
29
+ # holding one record per file.
30
+ PROFILE_CATEGORIES = ("constraints", "conventions", "pitfalls", "decisions")
31
+
32
+ PROFILE_BLOCK_START = "<!-- CODEXSPEC PROFILE START -->"
33
+ PROFILE_BLOCK_END = "<!-- CODEXSPEC PROFILE END -->"
34
+
35
+ # Channel-neutral: identical for CLAUDE.md and AGENTS.md. Constraints are a strong
36
+ # mandatory pointer (no @import), so the block depends on no tool-specific import
37
+ # mechanism and the store can be one-file-per-record directories. Assembled from
38
+ # short literals to keep each source line within the line-length limit.
39
+ _PROFILE_BLOCK = "".join(
40
+ [
41
+ f"{PROFILE_BLOCK_START}\n",
42
+ "## CodexSpec Project Profile\n\n",
43
+ "**Project constraints (highest priority — read these FIRST):** before any non-trivial work you MUST ",
44
+ "read every record under `.codexspec/profile/constraints/` — the project's hard prohibitions ",
45
+ "(严禁 / 仅允许). Honor them before anything else.\n\n",
46
+ "**Project profile — consult on demand when relevant to the task** ",
47
+ "(each directory holds one record per file):\n\n",
48
+ "- `.codexspec/profile/conventions/` — cross-feature conventions / steering; ",
49
+ "read before adopting a pattern, structure, or naming choice.\n",
50
+ "- `.codexspec/profile/pitfalls/` — known traps and their workarounds; ",
51
+ "read before implementing or debugging in an area that may have bitten before.\n",
52
+ "- `.codexspec/profile/decisions/` — past cross-feature / architectural decisions; ",
53
+ "read before deciding in the same area, to reuse prior rationale rather than re-litigate it.\n\n",
54
+ "Read the full record — each carries a `status` of `candidate` or `vetted`; ",
55
+ "weight `candidate` items with appropriate caution. A directory may be empty ",
56
+ "until `/codexspec:distill` has captured knowledge.\n",
57
+ f"{PROFILE_BLOCK_END}\n",
58
+ ]
59
+ )
60
+
61
+
62
+ def ensure_profile_scaffold(target_dir: Path) -> Path:
63
+ """Create ``.codexspec/profile/`` and its four category directories if absent.
64
+
65
+ Each category is a directory of one-record-per-file entries; a ``.gitkeep``
66
+ keeps an empty category tracked so every pointer resolves. Idempotent and
67
+ non-destructive: existing records and directories are never overwritten.
68
+ """
69
+ profile_dir = target_dir / ".codexspec" / "profile"
70
+ for category in PROFILE_CATEGORIES:
71
+ category_dir = profile_dir / category
72
+ category_dir.mkdir(parents=True, exist_ok=True)
73
+ keep = category_dir / ".gitkeep"
74
+ if not keep.exists():
75
+ keep.write_text("", encoding="utf-8")
76
+ return profile_dir
77
+
78
+
79
+ def render_profile_block() -> str:
80
+ """Render the bounded managed profile block.
81
+
82
+ Identical for CLAUDE.md and AGENTS.md: constraints and the three on-demand
83
+ categories are all delivered as pointers to their directories — no ``@import``
84
+ anywhere — so the block is channel-neutral and the store can be
85
+ one-file-per-record directories that merge without conflict.
86
+ """
87
+ return _PROFILE_BLOCK
88
+
89
+
90
+ def inject_profile_block(context_path: Path) -> None:
91
+ """Idempotently inject/update the profile block in ``context_path``.
92
+
93
+ Only the bounded ``<!-- CODEXSPEC PROFILE START/END -->`` region is written;
94
+ any other content in the file is preserved verbatim. Creates the file if it
95
+ does not exist.
96
+ """
97
+ block = render_profile_block().rstrip("\n")
98
+ existing = context_path.read_text(encoding="utf-8") if context_path.exists() else ""
99
+
100
+ pattern = re.compile(
101
+ re.escape(PROFILE_BLOCK_START) + r".*?" + re.escape(PROFILE_BLOCK_END),
102
+ re.DOTALL,
103
+ )
104
+ if pattern.search(existing):
105
+ # Function replacement avoids backslash/group interpretation in `block`.
106
+ updated = pattern.sub(lambda _match: block, existing)
107
+ elif existing.strip():
108
+ updated = existing.rstrip() + "\n\n" + block + "\n"
109
+ else:
110
+ updated = block + "\n"
111
+
112
+ context_path.write_text(updated, encoding="utf-8")
@@ -0,0 +1,80 @@
1
+ ---
2
+ description: Debug a failure to its root cause before proposing any fix
3
+ argument-hint: "[error text | failing test | file:line | plain-language symptom]"
4
+ allowed-tools: Read, Grep, Glob, Bash, Edit, Write
5
+ ---
6
+
7
+ # Systematic Debugger
8
+
9
+ ## Language Preference
10
+
11
+ Read `.codexspec/config.yml`. Two independent language controls apply (each falls back to `language.output`, then English):
12
+
13
+ - **Interaction language** (`language.interaction`): language for all conversation with the user — questions, explanations, status messages, and `codexspec` CLI terminal output.
14
+ - **Document language** (`language.document`): language for generated artifact files (requirements/spec/plan/tasks).
15
+
16
+ Converse in the interaction language and author artifacts in the document language. Apply the project's translation standard to both: translate by meaning (not word-for-word), keep English for terms with no good native equivalent, and write as if originally in that language.
17
+
18
+ ## User Input
19
+
20
+ `$ARGUMENTS`
21
+
22
+ ## Role and Iron Law
23
+
24
+ You debug a reported symptom to its **root cause** and apply exactly one verified fix.
25
+
26
+ **Iron Law: NO FIX BEFORE ROOT CAUSE.** You MUST NOT propose, apply, or even sketch a fix until Phase 1 has established what is actually wrong and why. Symptom patches — wrapping the error, silencing a failing assertion, retrying blindly — are failures, not fixes.
27
+
28
+ Red flags that mean STOP and return to Phase 1: "let me just try changing X", "add a try/except here", "it's probably the Y" — any edit attempted before the failure is reproduced and understood.
29
+
30
+ You leave **no persistent artifact**: no report file, no debug journal. Your output is the fix plus a concise root-cause explanation in the conversation. (Reusable, cross-feature lessons are captured separately by `/codexspec:distill`, never written here.)
31
+
32
+ ## Symptom Intake
33
+
34
+ Take the symptom from `$ARGUMENTS` when provided — an error or stack trace, a failing-test id, a `file:line`, or a plain-language description — otherwise from error output already visible in this session.
35
+
36
+ When the symptom is too thin to act on, **reproduce-or-ask** before doing anything else:
37
+
38
+ - First attempt to reproduce it yourself: run the failing test, exercise the path, read the log or stack trace.
39
+ - If you still cannot reproduce it reliably, ask the user for exactly what is missing — reproduction steps, the precise input that triggers it, expected-vs-actual behavior, the verbatim error, and when it started.
40
+ - Do NOT propose a fix for an unreproduced symptom.
41
+
42
+ ## Investigation Protocol
43
+
44
+ Work the phases in order. Phase 1 is a hard gate.
45
+
46
+ ### Phase 1 — Root-Cause Investigation (hard gate)
47
+
48
+ - Read the error/failure carefully and completely; do not skim.
49
+ - Reproduce it consistently. A flaky or order-dependent failure must be made reliably reproducible before you continue.
50
+ - Check what changed recently — the diff, recent commits, configuration.
51
+ - Trace the data and control flow **backward** from the symptom to where the wrong state originates. Inspect enough callers, callees, and inputs to locate the true origin; it is often not where the error surfaces.
52
+ - **Exit criterion**: you can state, in one sentence, WHAT is wrong and WHY. Until then, no fix.
53
+
54
+ ### Phase 2 — Pattern Analysis
55
+
56
+ - Find a working reference: a passing sibling test, an analogous code path, or an earlier good state.
57
+ - Compare the failing case against it and enumerate every material difference.
58
+ - Identify which difference actually explains the root cause.
59
+
60
+ ### Phase 3 — Hypothesis & Verification
61
+
62
+ - Write down a single, specific hypothesis about the root cause.
63
+ - Test it minimally — change one variable at a time, and predict the outcome before observing it.
64
+ - Confirm or reject. If rejected, reformulate; do not stack untested guesses.
65
+
66
+ ### Phase 4 — Fix
67
+
68
+ - Write a failing test first that captures the defect (a reproducing regression test) and observe it fail for the right reason. For a symptom with no natural unit test — a documentation or configuration defect, a production-log incident — construct the closest reproducing check instead.
69
+ - Apply a single, minimal fix that targets the root cause — not the symptom, and no "while I'm here" changes.
70
+ - Verify: the new test passes and no previously-passing test breaks.
71
+
72
+ ### Architecture Gate (≥3 failed fixes)
73
+
74
+ If three fixes for the same problem have failed, STOP. Do not attempt a fourth blind fix. Repeated failure is evidence that the model of the problem — or the architecture — is wrong. Surface it: state what was tried, why each attempt failed, and what architectural question must be answered before continuing.
75
+
76
+ ## Completion
77
+
78
+ - Report the root cause (one or two sentences), the fix applied, and the verification that shows it green.
79
+ - **When you were entered from another command** (for example, `implement-tasks` escalated into this discipline), do not end the session: hand control back and **resume that command** exactly where it left off, now with the defect resolved.
80
+ - If you could not reach a root cause, or you hit the Architecture Gate, say so plainly with the evidence. Never paper over it with a speculative fix.
@@ -42,17 +42,18 @@ Apply this boundary test to every candidate: **"Would a single feature's `requir
42
42
 
43
43
  ## The profile store: `.codexspec/profile/`
44
44
 
45
- Four markdown files, each holding **only current-effective** knowledge — dense, with no "retired" section (git history is the ledger). Create the directory and file on first write.
45
+ Four **category directories**, each holding **one record per file** (`<id>.md`) with **only current-effective** knowledge — dense, with no "retired" section (git history is the ledger). One-file-per-record is deliberate: parallel feature branches each add differently-named files, so distilled knowledge merges without conflict. Create the directory and record file on first write.
46
46
 
47
- - `constraints.md` — negative constraints (`严禁 / 仅允许`). These carry the **highest** weight and MUST be honored first.
48
- - `conventions.md` — positive cross-feature conventions / steering.
49
- - `pitfalls.md` — cross-feature traps and their workarounds.
50
- - `decisions.md` — cross-feature / architectural decisions only (ADR-lite). **Never** single-feature requirement rationale.
47
+ - `constraints/` — negative constraints (`严禁 / 仅允许`). These carry the **highest** weight and MUST be honored first.
48
+ - `conventions/` — positive cross-feature conventions / steering.
49
+ - `pitfalls/` — cross-feature traps and their workarounds.
50
+ - `decisions/` — cross-feature / architectural decisions only (ADR-lite). **Never** single-feature requirement rationale.
51
51
 
52
52
  ### Record format — `claim` and `evidence` physically separated
53
53
 
54
54
  Every record MUST separate the distilled claim from the evidence it rests on:
55
55
 
56
+ - `id` — **type letter + full source-feature id + local sequence**, e.g. `P-2026-0812-14054p-1` or `Con-2026-0812-14054p-1`. It is **both** the record's `### <id>: <title>` heading **and its filename** (`pitfalls/P-2026-0812-14054p-1.md`). The **source-feature id** is the distilling feature's full spec-dir id `{YYYY-MMDD-HHMM}{rr}` (e.g. `2026-0812-14054p`); it is globally unique by the timestamp+random scheme spec directories use, so records distilled on parallel feature branches never collide on id **or filename** (they merge with no conflict). Keep the **full** id (not a short tail) so the record is self-describing: the date supports recency/staleness reading, and the feature id ties the record to its originating change for decision context and scope. When distilling with no feature context, generate a fresh `{YYYY-MMDD-HHMM}{rr}` id now (same convention as create-new-feature). **Never** use a bare sequential id such as `P-001` — those collide across parallel branches.
56
57
  - `claim` — one-sentence reusable statement.
57
58
  - `type` — `convention` | `constraint` | `pitfall` | `decision` (`constraint` = highest priority).
58
59
  - `scope/when` — natural-language applicability condition (e.g. "when editing Python code"); omit for global. **No formal syntax.**
@@ -63,10 +64,10 @@ Every record MUST separate the distilled claim from the evidence it rests on:
63
64
 
64
65
  This separation is what makes a later error locatable as **misread** (facts wrong) vs **overreach** (claim over-generalized) vs **stale** (state no longer holds).
65
66
 
66
- Example entry:
67
+ Example entry — file `conventions/Con-2026-0809-2219gg-1.md`:
67
68
 
68
69
  ```markdown
69
- ### C-003: Prefer absolute imports
70
+ ### Con-2026-0809-2219gg-1: Prefer absolute imports
70
71
  - claim: Always use absolute imports in `src/`.
71
72
  - type: convention
72
73
  - scope/when: Python modules under `src/`
@@ -80,7 +81,7 @@ Example entry:
80
81
 
81
82
  Read the interaction segment and extract, per the dimensions above, only **verified** knowledge — prefer facts confirmed by outcomes over speculation; speculation MUST NOT become `vetted`.
82
83
 
83
- Before writing, **read the current profile** and skip anything already covered; update anything changed via `replace`. **This is how deduplication is done — by judgment, not an algorithm.**
84
+ Before writing, **read the current profile** (the record files under each category directory) and skip anything already covered; update anything changed via `replace`. **This is how deduplication is done — by judgment, not an algorithm.**
84
85
 
85
86
  ## Conflict adjudication
86
87
 
@@ -93,13 +94,13 @@ When a new item conflicts with an existing rule, resolve in this order:
93
94
 
94
95
  ## Mutation discipline
95
96
 
96
- Change the profile **only** through three conceptual operations (you edit the markdown directly — these are a discipline, **not** a tool API or matching algorithm):
97
+ Change the profile **only** through three conceptual operations (you edit the files directly — these are a discipline, **not** a tool API or matching algorithm):
97
98
 
98
- - `add` — append a new verified item.
99
- - `replace` — supersede an outdated/wrong item in place (keeps files dense).
100
- - `remove` — delete an item invalidated by a changed environment.
99
+ - `add` — create a new record file `<category>/<id>.md` for a verified item.
100
+ - `replace` — supersede an outdated/wrong item **in its own file** (keeps records dense).
101
+ - `remove` — delete the record's file when a changed environment invalidates it.
101
102
 
102
- git history is the audit ledger. Do **NOT** keep a retired section inside the files.
103
+ git history is the audit ledger. Do **NOT** keep a retired file or a retired section.
103
104
 
104
105
  ## Vetting candidates (manual, interactive)
105
106
 
@@ -90,6 +90,7 @@ For **each task**, determine the workflow based on task type:
90
90
  3. **Verify - Run Tests**
91
91
  - Execute all relevant tests
92
92
  - Ensure new tests pass and no existing tests break
93
+ - If a test stays red across several green attempts, a fix reddens a previously-passing test, or you catch yourself guessing: stop patching and follow **Systematic Debugging Escalation** (below)
93
94
 
94
95
  4. **Review & Refactor**
95
96
  - Check for bugs, edge cases, security issues
@@ -231,7 +232,9 @@ Apply only verified repairs:
231
232
 
232
233
  - For a functional defect, first add a reproducing regression test and observe
233
234
  the expected failure. Then use red-green-refactor until the defect is fixed
234
- while existing behavior remains green.
235
+ while existing behavior remains green. When such a repair is non-trivial — the
236
+ cause is not a mechanical local edit but must be traced across call chains,
237
+ state, or data flow — follow **Systematic Debugging Escalation** (below).
235
238
  - For documentation and non-code configuration defects, use the applicable
236
239
  deterministic checks before and after the repair. Do not manufacture a code
237
240
  test when the binding contract is non-code.
@@ -293,6 +296,25 @@ or a commit.
293
296
  a commit, create it only after the applicable checks are green; a commit must
294
297
  never alter, replace, or imply the review verdict.
295
298
 
299
+ ## Systematic Debugging Escalation
300
+
301
+ When a fix is not converging, escalate into the systematic root-cause discipline instead of continuing to patch. This is a reference, not a duplicate: the discipline lives once in `/codexspec:debug`.
302
+
303
+ **Trip conditions** (either one):
304
+
305
+ - **(a) During the TDD Verify/green loop (§3)**: the same test stays red after several green attempts, a fix reddens a previously-passing test, or you notice guess-and-check behavior.
306
+ - **(b) During a test-safe repair (§7.4)**: you are fixing a **functional/correctness (or robustness) defect** whose fix is **non-trivial** — it requires tracing across call chains, state, or data flow, not a mechanical local edit. This trip does NOT apply to idiomatic-clarity, architecture, constitution-alignment, style, or trivial mechanical fixes.
307
+
308
+ **Escalation**:
309
+
310
+ ```text
311
+ Invoke /codexspec:debug
312
+ ```
313
+
314
+ Apply its root-cause discipline to the failing test (trip a) or the defect under repair (trip b). The escalation is **non-gating and low-ceremony**: it produces no PASS/FAIL, emits no mandatory notice line, and does not interrupt the user.
315
+
316
+ **Resume**: once `debug` has reached the root cause and applied a verified fix, **return here and continue** the task or repair exactly where you left off — re-establish the green baseline and proceed. There is no runtime stack; resuming is your responsibility, not the engine's.
317
+
296
318
  ## Automatic Distillation
297
319
 
298
320
  Read `workflow.auto_distill` from `.codexspec/config.yml` (**default `true`** — enabled unless explicitly set to the literal `false`; absent or any non-`false` value means enabled).
@@ -50,6 +50,15 @@ When the argument identifies an existing feature:
50
50
  4. Load the existing `requirements.md`.
51
51
  5. Legacy feature: if only `spec.md` exists, extract candidate entries from it, mark them `open`, and require user confirmation before they become authoritative.
52
52
 
53
+ ## Consult Project Profile
54
+
55
+ Before discussing and finalizing requirements, read the project profile under `.codexspec/profile/` when it exists so the confirmed `requirements.md` is a synthesis that already accounts for accumulated project knowledge. Each category is a directory holding one record per file:
56
+
57
+ - `constraints/` first — the project's hard prohibitions (highest weight); requirements MUST NOT contradict them.
58
+ - `pitfalls/`, `conventions/`, `decisions/` — read the records relevant to this feature's area, to avoid re-hitting known traps, to follow established conventions, and to reuse past cross-feature/architectural decisions rather than re-litigating them.
59
+
60
+ Each record carries a `status` (`candidate` or `vetted`); weight `candidate` entries with appropriate caution. Fold what is relevant into the discussion and the resulting entries; cite a profile record as evidence when it materially shapes a decision. This is the single point where the profile enters the SDD pipeline — downstream stages keep `requirements.md` as authority and do not re-read the profile. Degrade silently when the profile is absent or empty (nothing to apply); never block on it.
61
+
53
62
  ## Discussion Rules
54
63
 
55
64
  - Ask one material question at a time.
File without changes
File without changes
File without changes