codexspec 0.7.21__tar.gz → 0.7.23__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 (108) hide show
  1. {codexspec-0.7.21 → codexspec-0.7.23}/PKG-INFO +1 -1
  2. {codexspec-0.7.21 → codexspec-0.7.23}/pyproject.toml +1 -1
  3. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/__init__.py +68 -39
  4. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/commit_guidance.py +10 -3
  5. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/integrations/codex.py +2 -0
  6. codexspec-0.7.23/src/codexspec/specs_context.py +86 -0
  7. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/analyze.md +16 -0
  8. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/blueprint.md +16 -0
  9. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/debug.md +16 -0
  10. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/design-to-plan.md +16 -0
  11. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/generate-spec.md +16 -0
  12. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/implement-tasks.md +16 -0
  13. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/plan-to-tasks.md +16 -0
  14. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/quick.md +16 -0
  15. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/review-code.md +16 -0
  16. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/review-design.md +16 -0
  17. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/review-plan.md +16 -0
  18. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/review-spec.md +16 -0
  19. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/review-tasks.md +16 -0
  20. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/spec-to-design.md +16 -0
  21. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/specify.md +16 -0
  22. {codexspec-0.7.21 → codexspec-0.7.23}/.gitignore +0 -0
  23. {codexspec-0.7.21 → codexspec-0.7.23}/LICENSE +0 -0
  24. {codexspec-0.7.21 → codexspec-0.7.23}/README.md +0 -0
  25. {codexspec-0.7.21 → codexspec-0.7.23}/codexspec-icon.svg +0 -0
  26. {codexspec-0.7.21 → codexspec-0.7.23}/codexspec-logo-dark.svg +0 -0
  27. {codexspec-0.7.21 → codexspec-0.7.23}/codexspec-logo-light.svg +0 -0
  28. {codexspec-0.7.21 → codexspec-0.7.23}/scripts/bash/check-i18n-completeness.sh +0 -0
  29. {codexspec-0.7.21 → codexspec-0.7.23}/scripts/bash/check-i18n-structure.sh +0 -0
  30. {codexspec-0.7.21 → codexspec-0.7.23}/scripts/bash/check-prerequisites.sh +0 -0
  31. {codexspec-0.7.21 → codexspec-0.7.23}/scripts/bash/common.sh +0 -0
  32. {codexspec-0.7.21 → codexspec-0.7.23}/scripts/bash/create-new-feature.sh +0 -0
  33. {codexspec-0.7.21 → codexspec-0.7.23}/scripts/bash/review-context.sh +0 -0
  34. {codexspec-0.7.21 → codexspec-0.7.23}/scripts/powershell/check-prerequisites.ps1 +0 -0
  35. {codexspec-0.7.21 → codexspec-0.7.23}/scripts/powershell/common.ps1 +0 -0
  36. {codexspec-0.7.21 → codexspec-0.7.23}/scripts/powershell/create-new-feature.ps1 +0 -0
  37. {codexspec-0.7.21 → codexspec-0.7.23}/scripts/powershell/review-context.ps1 +0 -0
  38. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/automation.py +0 -0
  39. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/blueprint.py +0 -0
  40. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/commands/__init__.py +0 -0
  41. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/commands/installer.py +0 -0
  42. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/commit_runtime.py +0 -0
  43. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/distill_review/__init__.py +0 -0
  44. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/distill_review/assets/app.js +0 -0
  45. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/distill_review/assets/i18n/ar.json +0 -0
  46. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/distill_review/assets/i18n/de.json +0 -0
  47. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/distill_review/assets/i18n/en.json +0 -0
  48. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/distill_review/assets/i18n/es.json +0 -0
  49. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/distill_review/assets/i18n/fr.json +0 -0
  50. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/distill_review/assets/i18n/hi.json +0 -0
  51. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/distill_review/assets/i18n/it.json +0 -0
  52. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/distill_review/assets/i18n/ja.json +0 -0
  53. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/distill_review/assets/i18n/ko.json +0 -0
  54. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/distill_review/assets/i18n/pt.json +0 -0
  55. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/distill_review/assets/i18n/ru.json +0 -0
  56. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/distill_review/assets/i18n/zh-CN.json +0 -0
  57. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/distill_review/assets/i18n/zh-TW.json +0 -0
  58. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/distill_review/assets/index.html +0 -0
  59. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/distill_review/assets/styles.css +0 -0
  60. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/distill_review/domain.py +0 -0
  61. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/distill_review/lease.py +0 -0
  62. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/distill_review/models.py +0 -0
  63. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/distill_review/records.py +0 -0
  64. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/distill_review/server.py +0 -0
  65. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/distill_review/session.py +0 -0
  66. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/distill_review/terminal.py +0 -0
  67. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/distill_review/transaction.py +0 -0
  68. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/i18n.py +0 -0
  69. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/idea.md +0 -0
  70. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/integrations/__init__.py +0 -0
  71. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/integrations/base.py +0 -0
  72. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/integrations/claude.py +0 -0
  73. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/merge_commits.py +0 -0
  74. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/profile.py +0 -0
  75. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/staged_commits.py +0 -0
  76. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/translator.py +0 -0
  77. {codexspec-0.7.21 → codexspec-0.7.23}/src/codexspec/worktrees.py +0 -0
  78. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/auto-dev.md +0 -0
  79. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/checklist.md +0 -0
  80. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/clarify.md +0 -0
  81. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/commit-staged.md +0 -0
  82. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/config.md +0 -0
  83. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/constitution.md +0 -0
  84. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/distill.md +0 -0
  85. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/evolve.md +0 -0
  86. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/onboard.md +0 -0
  87. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/pr.md +0 -0
  88. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/release-notes.md +0 -0
  89. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/reverse-spec.md +0 -0
  90. {codexspec-0.7.21 → codexspec-0.7.23}/templates/commands/tasks-to-issues.md +0 -0
  91. {codexspec-0.7.21 → codexspec-0.7.23}/templates/docs/checklist-template.md +0 -0
  92. {codexspec-0.7.21 → codexspec-0.7.23}/templates/docs/constitution-template.md +0 -0
  93. {codexspec-0.7.21 → codexspec-0.7.23}/templates/docs/design-template.md +0 -0
  94. {codexspec-0.7.21 → codexspec-0.7.23}/templates/docs/plan-template-detailed.md +0 -0
  95. {codexspec-0.7.21 → codexspec-0.7.23}/templates/docs/plan-template-simple.md +0 -0
  96. {codexspec-0.7.21 → codexspec-0.7.23}/templates/docs/requirements-template.md +0 -0
  97. {codexspec-0.7.21 → codexspec-0.7.23}/templates/docs/spec-template-detailed.md +0 -0
  98. {codexspec-0.7.21 → codexspec-0.7.23}/templates/docs/spec-template-simple.md +0 -0
  99. {codexspec-0.7.21 → codexspec-0.7.23}/templates/docs/tasks-template-detailed.md +0 -0
  100. {codexspec-0.7.21 → codexspec-0.7.23}/templates/docs/tasks-template-simple.md +0 -0
  101. {codexspec-0.7.21 → codexspec-0.7.23}/templates/translations/de.json +0 -0
  102. {codexspec-0.7.21 → codexspec-0.7.23}/templates/translations/en.json +0 -0
  103. {codexspec-0.7.21 → codexspec-0.7.23}/templates/translations/es.json +0 -0
  104. {codexspec-0.7.21 → codexspec-0.7.23}/templates/translations/fr.json +0 -0
  105. {codexspec-0.7.21 → codexspec-0.7.23}/templates/translations/ja.json +0 -0
  106. {codexspec-0.7.21 → codexspec-0.7.23}/templates/translations/ko.json +0 -0
  107. {codexspec-0.7.21 → codexspec-0.7.23}/templates/translations/pt-BR.json +0 -0
  108. {codexspec-0.7.21 → codexspec-0.7.23}/templates/translations/zh-CN.json +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: codexspec
3
- Version: 0.7.21
3
+ Version: 0.7.23
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
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "codexspec"
3
- version = "0.7.21"
3
+ version = "0.7.23"
4
4
  description = "CodexSpec - A Requirements-First SDD toolkit for Claude Code"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -30,7 +30,6 @@ from .automation import (
30
30
  AutomationError,
31
31
  BlueprintStore,
32
32
  OwnershipError,
33
- WorkspaceContext,
34
33
  ensure_dedicated_workspace,
35
34
  locate_dedicated_workspace,
36
35
  locate_repository,
@@ -65,6 +64,7 @@ from .i18n import (
65
64
  )
66
65
  from .integrations import get_integrations
67
66
  from .profile import ensure_profile_scaffold, inject_profile_block
67
+ from .specs_context import inject_specs_context
68
68
  from .translator import SUPPORTED_LANGUAGES, translate
69
69
  from .worktrees import (
70
70
  MAINTENANCE_NAME,
@@ -78,7 +78,7 @@ from .worktrees import (
78
78
  )
79
79
 
80
80
  # Version info
81
- __version__ = "0.7.21"
81
+ __version__ = "0.7.23"
82
82
  __author__ = "CodexSpec Team"
83
83
 
84
84
  # Constitution file path constants
@@ -476,22 +476,64 @@ def blueprint_helper(
476
476
  _automation_failure(exc)
477
477
 
478
478
 
479
+ def _validate_auto_dev_request(action: str, body: dict[str, Any]) -> None:
480
+ """Reject malformed requests before ownership or workspace mutations."""
481
+ if action == "acquire":
482
+ if body:
483
+ raise AutomationError("unexpected_fields")
484
+ return
485
+ token_only = {"renew", "assert-owner", "release", "sync-default", "abort-sync"}
486
+ if action not in token_only | {
487
+ "prepare-sync-verification",
488
+ "continue-sync",
489
+ "prepare-feature",
490
+ "commit-feature",
491
+ "discard-feature",
492
+ }:
493
+ raise AutomationError("unsupported_auto_dev_helper_action", action)
494
+ if not isinstance(body.get("token"), str):
495
+ raise AutomationError("missing_token")
496
+ if action in token_only:
497
+ if set(body) != {"token"}:
498
+ raise AutomationError("unexpected_fields")
499
+ elif action == "prepare-sync-verification":
500
+ if (
501
+ set(body) != {"token", "resolved_paths"}
502
+ or not isinstance(body["resolved_paths"], list)
503
+ or not body["resolved_paths"]
504
+ or not all(isinstance(path, str) for path in body["resolved_paths"])
505
+ ):
506
+ raise AutomationError("invalid_prepare_sync_request")
507
+ elif action == "continue-sync":
508
+ if set(body) not in (
509
+ {"token", "checks_passed"},
510
+ {"token", "checks_passed", "analysis", "message"},
511
+ ) or not isinstance(body.get("checks_passed"), bool):
512
+ raise AutomationError("invalid_continue_sync_request")
513
+ elif action == "prepare-feature":
514
+ if (
515
+ set(body) != {"token", "feature_id", "paths"}
516
+ or not isinstance(body["feature_id"], str)
517
+ or not isinstance(body["paths"], list)
518
+ or not all(isinstance(path, str) for path in body["paths"])
519
+ ):
520
+ raise AutomationError("invalid_prepare_feature_request")
521
+ elif action == "commit-feature":
522
+ _analysis_request(body, token=True)
523
+ elif action == "discard-feature":
524
+ if set(body) != {"token", "preparation_id"} or not isinstance(body["preparation_id"], str):
525
+ raise AutomationError("invalid_preparation")
526
+
527
+
479
528
  @app.command("_auto-dev-helper", hidden=True)
480
529
  def auto_dev_helper(action: str = typer.Argument(..., help="Internal helper action")) -> None:
481
530
  """Internal machine interface for auto-dev ownership and Git writes."""
482
531
  try:
483
532
  body = _stdin_json()
533
+ _validate_auto_dev_request(action, body)
484
534
  context = locate_repository(Path.cwd())
485
535
  ownership = AutoDevOwnership(context)
486
- workspace: WorkspaceContext | None = None
487
- service: AutoDevGit | None = None
488
- if action != "acquire":
489
- # Every non-acquire action legitimately waits behind the active run.
490
- workspace = ensure_dedicated_workspace(context)
491
- service = AutoDevGit(workspace, ownership)
492
536
  if action == "acquire":
493
- if body:
494
- raise AutomationError("unexpected_fields")
495
537
  token = ownership.acquire()
496
538
  try:
497
539
  workspace = ensure_dedicated_workspace(context)
@@ -514,56 +556,42 @@ def auto_dev_helper(action: str = typer.Argument(..., help="Internal helper acti
514
556
  }
515
557
  )
516
558
  return
517
- if set(body) < {"token"} or not isinstance(body.get("token"), str):
518
- raise AutomationError("missing_token")
519
559
  token = body["token"]
520
- if action in {"renew", "assert-owner", "release", "sync-default", "abort-sync"} and set(body) != {"token"}:
521
- raise AutomationError("unexpected_fields")
560
+ # Ownership operations must remain usable even if the worktree is missing.
522
561
  if action == "renew":
523
562
  ownership.renew(token)
524
- result = {"state": "renewed"}
525
- elif action == "assert-owner":
563
+ _machine_json({"state": "renewed"})
564
+ return
565
+ if action == "assert-owner":
526
566
  ownership.assert_owner(token)
527
- result = {"state": "owner"}
528
- elif action == "release":
567
+ _machine_json({"state": "owner"})
568
+ return
569
+ if action == "release":
529
570
  ownership.release(token)
530
- result = {"state": "released"}
531
- elif action == "sync-default":
571
+ _machine_json({"state": "released"})
572
+ return
573
+
574
+ # Only acquire may initialize a workspace; follow-up actions must not repair
575
+ # missing state or fetch/merge history before their operation is validated.
576
+ workspace = locate_dedicated_workspace(context)
577
+ service = AutoDevGit(workspace, ownership)
578
+ if action == "sync-default":
532
579
  result = service.sync_default(token)
533
580
  elif action == "prepare-sync-verification":
534
- if set(body) != {"token", "resolved_paths"} or not isinstance(body["resolved_paths"], list):
535
- raise AutomationError("invalid_prepare_sync_request")
536
- if not body["resolved_paths"] or not all(isinstance(path, str) for path in body["resolved_paths"]):
537
- raise AutomationError("invalid_prepare_sync_request")
538
581
  result = service.prepare_sync_verification(token, body["resolved_paths"])
539
582
  elif action == "abort-sync":
540
583
  result = service.abort_sync(token)
541
584
  elif action == "continue-sync":
542
- if set(body) not in (
543
- {"token", "checks_passed"},
544
- {"token", "checks_passed", "analysis", "message"},
545
- ) or not isinstance(body.get("checks_passed"), bool):
546
- raise AutomationError("invalid_continue_sync_request")
547
585
  result = service.continue_sync(
548
586
  token, checks_passed=body["checks_passed"], analysis=body.get("analysis"), message=body.get("message")
549
587
  )
550
588
  elif action == "prepare-feature":
551
- if (
552
- set(body) != {"token", "feature_id", "paths"}
553
- or not isinstance(body["feature_id"], str)
554
- or not isinstance(body["paths"], list)
555
- or not all(isinstance(path, str) for path in body["paths"])
556
- ):
557
- raise AutomationError("invalid_prepare_feature_request")
558
589
  result = service.prepare_feature(token, body["feature_id"], body["paths"])
559
590
  elif action == "commit-feature":
560
- _analysis_request(body, token=True)
561
591
  result = service.commit_feature(token, body["preparation_id"], body["analyzed_tree"], body["message"])
562
592
  elif action == "discard-feature":
563
593
  from .staged_commits import PreparedCommits
564
594
 
565
- if set(body) != {"token", "preparation_id"} or not isinstance(body["preparation_id"], str):
566
- raise AutomationError("invalid_preparation")
567
595
  ownership.assert_owner(token)
568
596
  PreparedCommits(workspace).discard(body["preparation_id"], kind="feature", token=token)
569
597
  result = {"state": "discarded"}
@@ -1436,6 +1464,7 @@ def init(
1436
1464
  # the compliance @import or the user's body (bounded, idempotent).
1437
1465
  inject_profile_block(claude_md)
1438
1466
  inject_commit_guidance(claude_md, "/codexspec:commit-staged")
1467
+ inject_specs_context(claude_md)
1439
1468
 
1440
1469
  # Initialize git if requested
1441
1470
  if not no_git and not (target_dir / ".git").exists():
@@ -1,10 +1,12 @@
1
- """Managed context instructions for staged commit analysis."""
1
+ """Managed commit instructions and shared plugin startup guidance."""
2
2
 
3
3
  import json
4
4
  import re
5
5
  import shlex
6
6
  from pathlib import Path
7
7
 
8
+ from .specs_context import render_specs_context
9
+
8
10
  START = "<!-- CODEXSPEC COMMITS START -->"
9
11
  END = "<!-- CODEXSPEC COMMITS END -->"
10
12
 
@@ -44,8 +46,13 @@ def inject_commit_guidance(path: Path, invocation: str) -> None:
44
46
  path.write_text(updated, encoding="utf-8", newline="\n")
45
47
 
46
48
 
49
+ def render_plugin_guidance() -> str:
50
+ """Compose startup rules without duplicating either policy's source."""
51
+ return render_commit_guidance("/codexspec:commit-staged") + "\n\n" + render_specs_context()
52
+
53
+
47
54
  def install_plugin_commit_guidance(plugin: Path) -> Path:
48
- """Install SessionStart context without needing the CLI or project init.
55
+ """Install commit and specs context without needing the CLI or project init.
49
56
 
50
57
  Git is already required for commits. Its shell alias provides printf on all
51
58
  Git platforms; exec-form hooks pass this static command without host-shell
@@ -59,7 +66,7 @@ def install_plugin_commit_guidance(plugin: Path) -> Path:
59
66
  raise AutomationError("linked_commit_guidance", str(part))
60
67
  if destination.exists() and (not destination.is_file() or destination.stat().st_nlink != 1):
61
68
  raise AutomationError("shared_commit_guidance", str(destination))
62
- guidance = render_commit_guidance("/codexspec:commit-staged")
69
+ guidance = render_plugin_guidance()
63
70
  hook = {
64
71
  "type": "command",
65
72
  "command": "git",
@@ -17,6 +17,7 @@ from codexspec.commands.installer import (
17
17
  )
18
18
  from codexspec.commit_guidance import inject_commit_guidance
19
19
  from codexspec.profile import inject_profile_block
20
+ from codexspec.specs_context import inject_specs_context
20
21
  from codexspec.translator import load_translation_cache, translate_template_frontmatter
21
22
 
22
23
  CODEXSPEC_CONTEXT_START = "<!-- CODEXSPEC START -->"
@@ -114,6 +115,7 @@ class CodexIntegration:
114
115
  # skills section, as its own bounded, idempotent managed block.
115
116
  inject_profile_block(context_path)
116
117
  inject_commit_guidance(context_path, self.invocation_for("commit-staged"))
118
+ inject_specs_context(context_path)
117
119
 
118
120
  def render_skill(self, command_name: str, content: str, fallback_description: str = "") -> str:
119
121
  """Render one command template into a Codex SKILL.md."""
@@ -0,0 +1,86 @@
1
+ """Task-dependent historical-spec recall instructions for both agent integrations."""
2
+
3
+ import re
4
+ from pathlib import Path
5
+
6
+ START = "<!-- CODEXSPEC SPECS START -->"
7
+ END = "<!-- CODEXSPEC SPECS END -->"
8
+
9
+
10
+ _GUIDANCE = """## CodexSpec Historical Specs
11
+
12
+ Before substantive requirements, behavior, design, implementation, debugging, or
13
+ review judgments, actively recall relevant history under `.codexspec/specs/`.
14
+ This applies in ordinary conversation and SDD workflows. Prepare background before
15
+ questioning the user. Purely mechanical edits, such as spelling or formatting
16
+ with no substantive judgment, may omit recall.
17
+
18
+ Select related features by the task's capabilities, affected modules, interfaces,
19
+ and terminology; use directory names, artifact headings, and targeted text search
20
+ to find candidates. Read relevant requirements and follow earlier and later
21
+ additions, changes, and references. Do not stop at the first matching document or
22
+ load every historical artifact. Use feature-directory timestamps to reconstruct
23
+ the iteration timeline, together with explicit confirmation and replacement
24
+ records, including later revisions inside an older feature directory.
25
+
26
+ Confirmed content in each `requirements.md` is an authoritative user decision
27
+ record. Older unchanged requirements remain applicable; an unrelated later feature
28
+ does not replace them. Combine later additions with earlier requirements. A later
29
+ explicit change updates the same matter while retaining the earlier rationale
30
+ and unrelated requirements. Open proposals are not confirmed decisions. When a
31
+ relationship is unclear, explain the specific difference and ask a concise
32
+ question; do not assume an earlier requirement expired.
33
+
34
+ The user's latest explicit decision in the current interaction takes precedence
35
+ over historical specs: history must never override or replace it. Explain relevant
36
+ changes and implications. Do not ask again about the same explicit decision merely
37
+ because history differs. Use the owning requirements workflow to reflect changed
38
+ requirements before downstream artifacts rely on them, without repeating an
39
+ already answered question. Historical background must not silently rewrite current
40
+ requirements or broaden the selected target, permissions, or staged-only inputs.
41
+
42
+ Read to the depth needed for the scenario:
43
+
44
+ - Requirements discussion (including specify, quick, blueprint): reconstruct the
45
+ requirements timeline; read design rationale when needed to explain a trade-off.
46
+ Prepare known background, applicable requirements, and differences to confirm.
47
+ - Design and planning: use confirmed requirements plus relevant historical designs,
48
+ alternatives, and trade-offs; consult plans when implementation experience matters.
49
+ - Implementation and debugging: establish expected behavior and its successive
50
+ changes, then examine relevant design, code and tests; plans alone do not prove implementation.
51
+ - Code review: trace concrete changes and concerns to relevant requirements and
52
+ designs, checking current requirements, compatibility, and repeated problems.
53
+
54
+ Reuse applicable established information instead of asking the user to reconstruct
55
+ it. If continued applicability needs confirmation, present the known background
56
+ and a short targeted question. If history is missing or incomplete, distinguish
57
+ what is known from what remains uncertain; never invent decisions or confirmation.
58
+ For legacy artifacts without requirements, use available evidence and disclose
59
+ that original user confirmation cannot be established from those artifacts alone.
60
+
61
+ Stop expanding retrieval when relevant requirements, decision evolution, and
62
+ applicability support the current judgment. Do not expand into unrelated history;
63
+ ask about any remaining material ambiguity instead of silently choosing an answer.
64
+ Reuse prepared background across workflow stages and duplicate entry points.
65
+ Supplement retrieval when scope changes, new evidence appears, or the background
66
+ is insufficient for the judgment required. Reuse never makes incomplete evidence
67
+ sufficient. Keep relevant source paths and decision relationships with the prepared
68
+ background so later stages can reuse it without reconstructing the entire history."""
69
+
70
+
71
+ def render_specs_context() -> str:
72
+ """Return constant-size guidance; historical artifacts are read by the agent on demand."""
73
+ return "\n".join((START, _GUIDANCE, END))
74
+
75
+
76
+ def inject_specs_context(path: Path) -> None:
77
+ """Update only the bounded block, retaining surrounding UTF-8 text verbatim."""
78
+ block = render_specs_context()
79
+ existing = path.read_bytes().decode("utf-8") if path.exists() else ""
80
+ pattern = re.compile(re.escape(START) + r".*?" + re.escape(END), re.DOTALL)
81
+ if pattern.search(existing):
82
+ updated = pattern.sub(lambda _match: block, existing)
83
+ else:
84
+ separator = "" if not existing else "\n" if existing.endswith("\n") else "\n\n"
85
+ updated = existing + separator + block + "\n"
86
+ path.write_bytes(updated.encode("utf-8"))
@@ -112,6 +112,22 @@ override or imply immediate changes to main's effective value. Completion retain
112
112
  does not automatically merge to main or delete them. Any occupied path, invalid identity, failed
113
113
  creation, or unusable baseline is an explicit stop, never permission to fall back to main writes.
114
114
 
115
+ ## Historical Specs Before Decisions
116
+
117
+ Use the CodexSpec Historical Specs guidance to prepare relevant background from
118
+ `.codexspec/specs/` before substantive judgments or questions. Select related
119
+ features and trace earlier and later confirmed decisions; read requirements first,
120
+ then design, plans, or implementation evidence as the current scenario needs.
121
+ Reuse sufficient background; supplement it when scope, evidence, or judgment needs
122
+ change. Explain specific unresolved differences in concise questions instead of
123
+ asking the user to reconstruct known history.
124
+
125
+ The latest explicit user decision takes precedence over historical specs. History
126
+ does not silently change current requirements, broaden the selected target, or
127
+ override this command's write permissions or staged-only input restrictions.
128
+ When a confirmed decision changes current requirements, use the owning requirements
129
+ workflow to record it without asking the user to decide the same matter again.
130
+
115
131
  ## User Input
116
132
 
117
133
  `$ARGUMENTS`
@@ -114,6 +114,22 @@ override or imply immediate changes to main's effective value. Completion retain
114
114
  does not automatically merge to main or delete them. Any occupied path, invalid identity, failed
115
115
  creation, or unusable baseline is an explicit stop, never permission to fall back to main writes.
116
116
 
117
+ ## Historical Specs Before Decisions
118
+
119
+ Use the CodexSpec Historical Specs guidance to prepare relevant background from
120
+ `.codexspec/specs/` before substantive judgments or questions. Select related
121
+ features and trace earlier and later confirmed decisions; read requirements first,
122
+ then design, plans, or implementation evidence as the current scenario needs.
123
+ Reuse sufficient background; supplement it when scope, evidence, or judgment needs
124
+ change. Explain specific unresolved differences in concise questions instead of
125
+ asking the user to reconstruct known history.
126
+
127
+ The latest explicit user decision takes precedence over historical specs. History
128
+ does not silently change current requirements, broaden the selected target, or
129
+ override this command's write permissions or staged-only input restrictions.
130
+ When a confirmed decision changes current requirements, use the owning requirements
131
+ workflow to record it without asking the user to decide the same matter again.
132
+
117
133
  ## User Input
118
134
 
119
135
  `$ARGUMENTS`
@@ -113,6 +113,22 @@ override or imply immediate changes to main's effective value. Completion retain
113
113
  does not automatically merge to main or delete them. Any occupied path, invalid identity, failed
114
114
  creation, or unusable baseline is an explicit stop, never permission to fall back to main writes.
115
115
 
116
+ ## Historical Specs Before Decisions
117
+
118
+ Use the CodexSpec Historical Specs guidance to prepare relevant background from
119
+ `.codexspec/specs/` before substantive judgments or questions. Select related
120
+ features and trace earlier and later confirmed decisions; read requirements first,
121
+ then design, plans, or implementation evidence as the current scenario needs.
122
+ Reuse sufficient background; supplement it when scope, evidence, or judgment needs
123
+ change. Explain specific unresolved differences in concise questions instead of
124
+ asking the user to reconstruct known history.
125
+
126
+ The latest explicit user decision takes precedence over historical specs. History
127
+ does not silently change current requirements, broaden the selected target, or
128
+ override this command's write permissions or staged-only input restrictions.
129
+ When a confirmed decision changes current requirements, use the owning requirements
130
+ workflow to record it without asking the user to decide the same matter again.
131
+
116
132
  ## User Input
117
133
 
118
134
  `$ARGUMENTS`
@@ -115,6 +115,22 @@ override or imply immediate changes to main's effective value. Completion retain
115
115
  does not automatically merge to main or delete them. Any occupied path, invalid identity, failed
116
116
  creation, or unusable baseline is an explicit stop, never permission to fall back to main writes.
117
117
 
118
+ ## Historical Specs Before Decisions
119
+
120
+ Use the CodexSpec Historical Specs guidance to prepare relevant background from
121
+ `.codexspec/specs/` before substantive judgments or questions. Select related
122
+ features and trace earlier and later confirmed decisions; read requirements first,
123
+ then design, plans, or implementation evidence as the current scenario needs.
124
+ Reuse sufficient background; supplement it when scope, evidence, or judgment needs
125
+ change. Explain specific unresolved differences in concise questions instead of
126
+ asking the user to reconstruct known history.
127
+
128
+ The latest explicit user decision takes precedence over historical specs. History
129
+ does not silently change current requirements, broaden the selected target, or
130
+ override this command's write permissions or staged-only input restrictions.
131
+ When a confirmed decision changes current requirements, use the owning requirements
132
+ workflow to record it without asking the user to decide the same matter again.
133
+
118
134
  ## User Input
119
135
 
120
136
  `$ARGUMENTS`
@@ -115,6 +115,22 @@ override or imply immediate changes to main's effective value. Completion retain
115
115
  does not automatically merge to main or delete them. Any occupied path, invalid identity, failed
116
116
  creation, or unusable baseline is an explicit stop, never permission to fall back to main writes.
117
117
 
118
+ ## Historical Specs Before Decisions
119
+
120
+ Use the CodexSpec Historical Specs guidance to prepare relevant background from
121
+ `.codexspec/specs/` before substantive judgments or questions. Select related
122
+ features and trace earlier and later confirmed decisions; read requirements first,
123
+ then design, plans, or implementation evidence as the current scenario needs.
124
+ Reuse sufficient background; supplement it when scope, evidence, or judgment needs
125
+ change. Explain specific unresolved differences in concise questions instead of
126
+ asking the user to reconstruct known history.
127
+
128
+ The latest explicit user decision takes precedence over historical specs. History
129
+ does not silently change current requirements, broaden the selected target, or
130
+ override this command's write permissions or staged-only input restrictions.
131
+ When a confirmed decision changes current requirements, use the owning requirements
132
+ workflow to record it without asking the user to decide the same matter again.
133
+
118
134
  ## User Input
119
135
 
120
136
  `$ARGUMENTS`
@@ -115,6 +115,22 @@ override or imply immediate changes to main's effective value. Completion retain
115
115
  does not automatically merge to main or delete them. Any occupied path, invalid identity, failed
116
116
  creation, or unusable baseline is an explicit stop, never permission to fall back to main writes.
117
117
 
118
+ ## Historical Specs Before Decisions
119
+
120
+ Use the CodexSpec Historical Specs guidance to prepare relevant background from
121
+ `.codexspec/specs/` before substantive judgments or questions. Select related
122
+ features and trace earlier and later confirmed decisions; read requirements first,
123
+ then design, plans, or implementation evidence as the current scenario needs.
124
+ Reuse sufficient background; supplement it when scope, evidence, or judgment needs
125
+ change. Explain specific unresolved differences in concise questions instead of
126
+ asking the user to reconstruct known history.
127
+
128
+ The latest explicit user decision takes precedence over historical specs. History
129
+ does not silently change current requirements, broaden the selected target, or
130
+ override this command's write permissions or staged-only input restrictions.
131
+ When a confirmed decision changes current requirements, use the owning requirements
132
+ workflow to record it without asking the user to decide the same matter again.
133
+
118
134
  ## Feature Resolution
119
135
 
120
136
  Resolve the feature in this order:
@@ -115,6 +115,22 @@ override or imply immediate changes to main's effective value. Completion retain
115
115
  does not automatically merge to main or delete them. Any occupied path, invalid identity, failed
116
116
  creation, or unusable baseline is an explicit stop, never permission to fall back to main writes.
117
117
 
118
+ ## Historical Specs Before Decisions
119
+
120
+ Use the CodexSpec Historical Specs guidance to prepare relevant background from
121
+ `.codexspec/specs/` before substantive judgments or questions. Select related
122
+ features and trace earlier and later confirmed decisions; read requirements first,
123
+ then design, plans, or implementation evidence as the current scenario needs.
124
+ Reuse sufficient background; supplement it when scope, evidence, or judgment needs
125
+ change. Explain specific unresolved differences in concise questions instead of
126
+ asking the user to reconstruct known history.
127
+
128
+ The latest explicit user decision takes precedence over historical specs. History
129
+ does not silently change current requirements, broaden the selected target, or
130
+ override this command's write permissions or staged-only input restrictions.
131
+ When a confirmed decision changes current requirements, use the owning requirements
132
+ workflow to record it without asking the user to decide the same matter again.
133
+
118
134
  ## User Input
119
135
 
120
136
  `$ARGUMENTS`
@@ -112,6 +112,22 @@ override or imply immediate changes to main's effective value. Completion retain
112
112
  does not automatically merge to main or delete them. Any occupied path, invalid identity, failed
113
113
  creation, or unusable baseline is an explicit stop, never permission to fall back to main writes.
114
114
 
115
+ ## Historical Specs Before Decisions
116
+
117
+ Use the CodexSpec Historical Specs guidance to prepare relevant background from
118
+ `.codexspec/specs/` before substantive judgments or questions. Select related
119
+ features and trace earlier and later confirmed decisions; read requirements first,
120
+ then design, plans, or implementation evidence as the current scenario needs.
121
+ Reuse sufficient background; supplement it when scope, evidence, or judgment needs
122
+ change. Explain specific unresolved differences in concise questions instead of
123
+ asking the user to reconstruct known history.
124
+
125
+ The latest explicit user decision takes precedence over historical specs. History
126
+ does not silently change current requirements, broaden the selected target, or
127
+ override this command's write permissions or staged-only input restrictions.
128
+ When a confirmed decision changes current requirements, use the owning requirements
129
+ workflow to record it without asking the user to decide the same matter again.
130
+
115
131
  ## User Input
116
132
 
117
133
  `$ARGUMENTS`
@@ -145,6 +145,22 @@ override or imply immediate changes to main's effective value. Completion retain
145
145
  does not automatically merge to main or delete them. Any occupied path, invalid identity, failed
146
146
  creation, or unusable baseline is an explicit stop, never permission to fall back to main writes.
147
147
 
148
+ ## Historical Specs Before Decisions
149
+
150
+ Use the CodexSpec Historical Specs guidance to prepare relevant background from
151
+ `.codexspec/specs/` before substantive judgments or questions. Select related
152
+ features and trace earlier and later confirmed decisions; read requirements first,
153
+ then design, plans, or implementation evidence as the current scenario needs.
154
+ Reuse sufficient background; supplement it when scope, evidence, or judgment needs
155
+ change. Explain specific unresolved differences in concise questions instead of
156
+ asking the user to reconstruct known history.
157
+
158
+ The latest explicit user decision takes precedence over historical specs. History
159
+ does not silently change current requirements, broaden the selected target, or
160
+ override this command's write permissions or staged-only input restrictions.
161
+ When a confirmed decision changes current requirements, use the owning requirements
162
+ workflow to record it without asking the user to decide the same matter again.
163
+
148
164
  ## User Input
149
165
 
150
166
  ```text
@@ -115,6 +115,22 @@ override or imply immediate changes to main's effective value. Completion retain
115
115
  does not automatically merge to main or delete them. Any occupied path, invalid identity, failed
116
116
  creation, or unusable baseline is an explicit stop, never permission to fall back to main writes.
117
117
 
118
+ ## Historical Specs Before Decisions
119
+
120
+ Use the CodexSpec Historical Specs guidance to prepare relevant background from
121
+ `.codexspec/specs/` before substantive judgments or questions. Select related
122
+ features and trace earlier and later confirmed decisions; read requirements first,
123
+ then design, plans, or implementation evidence as the current scenario needs.
124
+ Reuse sufficient background; supplement it when scope, evidence, or judgment needs
125
+ change. Explain specific unresolved differences in concise questions instead of
126
+ asking the user to reconstruct known history.
127
+
128
+ The latest explicit user decision takes precedence over historical specs. History
129
+ does not silently change current requirements, broaden the selected target, or
130
+ override this command's write permissions or staged-only input restrictions.
131
+ When a confirmed decision changes current requirements, use the owning requirements
132
+ workflow to record it without asking the user to decide the same matter again.
133
+
118
134
  ## User Input
119
135
 
120
136
  `$ARGUMENTS`
@@ -115,6 +115,22 @@ override or imply immediate changes to main's effective value. Completion retain
115
115
  does not automatically merge to main or delete them. Any occupied path, invalid identity, failed
116
116
  creation, or unusable baseline is an explicit stop, never permission to fall back to main writes.
117
117
 
118
+ ## Historical Specs Before Decisions
119
+
120
+ Use the CodexSpec Historical Specs guidance to prepare relevant background from
121
+ `.codexspec/specs/` before substantive judgments or questions. Select related
122
+ features and trace earlier and later confirmed decisions; read requirements first,
123
+ then design, plans, or implementation evidence as the current scenario needs.
124
+ Reuse sufficient background; supplement it when scope, evidence, or judgment needs
125
+ change. Explain specific unresolved differences in concise questions instead of
126
+ asking the user to reconstruct known history.
127
+
128
+ The latest explicit user decision takes precedence over historical specs. History
129
+ does not silently change current requirements, broaden the selected target, or
130
+ override this command's write permissions or staged-only input restrictions.
131
+ When a confirmed decision changes current requirements, use the owning requirements
132
+ workflow to record it without asking the user to decide the same matter again.
133
+
118
134
  ## User Input
119
135
 
120
136
  `$ARGUMENTS`
@@ -115,6 +115,22 @@ override or imply immediate changes to main's effective value. Completion retain
115
115
  does not automatically merge to main or delete them. Any occupied path, invalid identity, failed
116
116
  creation, or unusable baseline is an explicit stop, never permission to fall back to main writes.
117
117
 
118
+ ## Historical Specs Before Decisions
119
+
120
+ Use the CodexSpec Historical Specs guidance to prepare relevant background from
121
+ `.codexspec/specs/` before substantive judgments or questions. Select related
122
+ features and trace earlier and later confirmed decisions; read requirements first,
123
+ then design, plans, or implementation evidence as the current scenario needs.
124
+ Reuse sufficient background; supplement it when scope, evidence, or judgment needs
125
+ change. Explain specific unresolved differences in concise questions instead of
126
+ asking the user to reconstruct known history.
127
+
128
+ The latest explicit user decision takes precedence over historical specs. History
129
+ does not silently change current requirements, broaden the selected target, or
130
+ override this command's write permissions or staged-only input restrictions.
131
+ When a confirmed decision changes current requirements, use the owning requirements
132
+ workflow to record it without asking the user to decide the same matter again.
133
+
118
134
  ## User Input
119
135
 
120
136
  `$ARGUMENTS`
@@ -115,6 +115,22 @@ override or imply immediate changes to main's effective value. Completion retain
115
115
  does not automatically merge to main or delete them. Any occupied path, invalid identity, failed
116
116
  creation, or unusable baseline is an explicit stop, never permission to fall back to main writes.
117
117
 
118
+ ## Historical Specs Before Decisions
119
+
120
+ Use the CodexSpec Historical Specs guidance to prepare relevant background from
121
+ `.codexspec/specs/` before substantive judgments or questions. Select related
122
+ features and trace earlier and later confirmed decisions; read requirements first,
123
+ then design, plans, or implementation evidence as the current scenario needs.
124
+ Reuse sufficient background; supplement it when scope, evidence, or judgment needs
125
+ change. Explain specific unresolved differences in concise questions instead of
126
+ asking the user to reconstruct known history.
127
+
128
+ The latest explicit user decision takes precedence over historical specs. History
129
+ does not silently change current requirements, broaden the selected target, or
130
+ override this command's write permissions or staged-only input restrictions.
131
+ When a confirmed decision changes current requirements, use the owning requirements
132
+ workflow to record it without asking the user to decide the same matter again.
133
+
118
134
  ## User Input
119
135
 
120
136
  `$ARGUMENTS`
@@ -115,6 +115,22 @@ override or imply immediate changes to main's effective value. Completion retain
115
115
  does not automatically merge to main or delete them. Any occupied path, invalid identity, failed
116
116
  creation, or unusable baseline is an explicit stop, never permission to fall back to main writes.
117
117
 
118
+ ## Historical Specs Before Decisions
119
+
120
+ Use the CodexSpec Historical Specs guidance to prepare relevant background from
121
+ `.codexspec/specs/` before substantive judgments or questions. Select related
122
+ features and trace earlier and later confirmed decisions; read requirements first,
123
+ then design, plans, or implementation evidence as the current scenario needs.
124
+ Reuse sufficient background; supplement it when scope, evidence, or judgment needs
125
+ change. Explain specific unresolved differences in concise questions instead of
126
+ asking the user to reconstruct known history.
127
+
128
+ The latest explicit user decision takes precedence over historical specs. History
129
+ does not silently change current requirements, broaden the selected target, or
130
+ override this command's write permissions or staged-only input restrictions.
131
+ When a confirmed decision changes current requirements, use the owning requirements
132
+ workflow to record it without asking the user to decide the same matter again.
133
+
118
134
  ## User Input
119
135
 
120
136
  `$ARGUMENTS`
@@ -115,6 +115,22 @@ override or imply immediate changes to main's effective value. Completion retain
115
115
  does not automatically merge to main or delete them. Any occupied path, invalid identity, failed
116
116
  creation, or unusable baseline is an explicit stop, never permission to fall back to main writes.
117
117
 
118
+ ## Historical Specs Before Decisions
119
+
120
+ Use the CodexSpec Historical Specs guidance to prepare relevant background from
121
+ `.codexspec/specs/` before substantive judgments or questions. Select related
122
+ features and trace earlier and later confirmed decisions; read requirements first,
123
+ then design, plans, or implementation evidence as the current scenario needs.
124
+ Reuse sufficient background; supplement it when scope, evidence, or judgment needs
125
+ change. Explain specific unresolved differences in concise questions instead of
126
+ asking the user to reconstruct known history.
127
+
128
+ The latest explicit user decision takes precedence over historical specs. History
129
+ does not silently change current requirements, broaden the selected target, or
130
+ override this command's write permissions or staged-only input restrictions.
131
+ When a confirmed decision changes current requirements, use the owning requirements
132
+ workflow to record it without asking the user to decide the same matter again.
133
+
118
134
  ## User Input
119
135
 
120
136
  `$ARGUMENTS`
File without changes
File without changes
File without changes