@easyops-cn/a2ui-react 0.0.0

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 (161) hide show
  1. package/.claude/commands/speckit.analyze.md +184 -0
  2. package/.claude/commands/speckit.checklist.md +294 -0
  3. package/.claude/commands/speckit.clarify.md +181 -0
  4. package/.claude/commands/speckit.constitution.md +82 -0
  5. package/.claude/commands/speckit.implement.md +135 -0
  6. package/.claude/commands/speckit.plan.md +89 -0
  7. package/.claude/commands/speckit.specify.md +256 -0
  8. package/.claude/commands/speckit.tasks.md +137 -0
  9. package/.claude/commands/speckit.taskstoissues.md +30 -0
  10. package/.github/workflows/deploy.yml +69 -0
  11. package/.husky/pre-commit +1 -0
  12. package/.prettierignore +4 -0
  13. package/.prettierrc +7 -0
  14. package/.specify/memory/constitution.md +73 -0
  15. package/.specify/scripts/bash/check-prerequisites.sh +166 -0
  16. package/.specify/scripts/bash/common.sh +156 -0
  17. package/.specify/scripts/bash/create-new-feature.sh +297 -0
  18. package/.specify/scripts/bash/setup-plan.sh +61 -0
  19. package/.specify/scripts/bash/update-agent-context.sh +799 -0
  20. package/.specify/templates/agent-file-template.md +28 -0
  21. package/.specify/templates/checklist-template.md +40 -0
  22. package/.specify/templates/plan-template.md +105 -0
  23. package/.specify/templates/spec-template.md +115 -0
  24. package/.specify/templates/tasks-template.md +250 -0
  25. package/CLAUDE.md +105 -0
  26. package/CONTRIBUTING.md +97 -0
  27. package/README.md +126 -0
  28. package/components.json +21 -0
  29. package/eslint.config.js +25 -0
  30. package/netlify.toml +50 -0
  31. package/package.json +94 -0
  32. package/playground/README.md +75 -0
  33. package/playground/index.html +22 -0
  34. package/playground/package.json +32 -0
  35. package/playground/public/favicon.svg +8 -0
  36. package/playground/src/App.css +256 -0
  37. package/playground/src/App.tsx +115 -0
  38. package/playground/src/assets/react.svg +1 -0
  39. package/playground/src/components/ErrorDisplay.tsx +13 -0
  40. package/playground/src/components/ExampleSelector.tsx +64 -0
  41. package/playground/src/components/Header.tsx +47 -0
  42. package/playground/src/components/JsonEditor.tsx +32 -0
  43. package/playground/src/components/Preview.tsx +78 -0
  44. package/playground/src/components/ThemeToggle.tsx +19 -0
  45. package/playground/src/data/examples.ts +1571 -0
  46. package/playground/src/hooks/useTheme.ts +55 -0
  47. package/playground/src/index.css +220 -0
  48. package/playground/src/main.tsx +10 -0
  49. package/playground/tsconfig.app.json +34 -0
  50. package/playground/tsconfig.json +13 -0
  51. package/playground/tsconfig.node.json +26 -0
  52. package/playground/vite.config.ts +31 -0
  53. package/specs/001-a2ui-renderer/checklists/requirements.md +41 -0
  54. package/specs/001-a2ui-renderer/data-model.md +140 -0
  55. package/specs/001-a2ui-renderer/plan.md +123 -0
  56. package/specs/001-a2ui-renderer/quickstart.md +141 -0
  57. package/specs/001-a2ui-renderer/research.md +140 -0
  58. package/specs/001-a2ui-renderer/spec.md +165 -0
  59. package/specs/001-a2ui-renderer/tasks.md +310 -0
  60. package/specs/002-playground/checklists/requirements.md +37 -0
  61. package/specs/002-playground/contracts/components.md +120 -0
  62. package/specs/002-playground/data-model.md +149 -0
  63. package/specs/002-playground/plan.md +73 -0
  64. package/specs/002-playground/quickstart.md +158 -0
  65. package/specs/002-playground/research.md +117 -0
  66. package/specs/002-playground/spec.md +109 -0
  67. package/specs/002-playground/tasks.md +224 -0
  68. package/src/0.8/A2UIRender.test.tsx +793 -0
  69. package/src/0.8/A2UIRender.tsx +142 -0
  70. package/src/0.8/components/ComponentRenderer.test.tsx +373 -0
  71. package/src/0.8/components/ComponentRenderer.tsx +163 -0
  72. package/src/0.8/components/UnknownComponent.tsx +49 -0
  73. package/src/0.8/components/display/AudioPlayerComponent.tsx +37 -0
  74. package/src/0.8/components/display/DividerComponent.tsx +23 -0
  75. package/src/0.8/components/display/IconComponent.tsx +137 -0
  76. package/src/0.8/components/display/ImageComponent.tsx +57 -0
  77. package/src/0.8/components/display/TextComponent.tsx +56 -0
  78. package/src/0.8/components/display/VideoComponent.tsx +31 -0
  79. package/src/0.8/components/display/display.test.tsx +660 -0
  80. package/src/0.8/components/display/index.ts +10 -0
  81. package/src/0.8/components/index.ts +14 -0
  82. package/src/0.8/components/interactive/ButtonComponent.tsx +44 -0
  83. package/src/0.8/components/interactive/CheckBoxComponent.tsx +45 -0
  84. package/src/0.8/components/interactive/DateTimeInputComponent.tsx +176 -0
  85. package/src/0.8/components/interactive/MultipleChoiceComponent.tsx +157 -0
  86. package/src/0.8/components/interactive/SliderComponent.tsx +53 -0
  87. package/src/0.8/components/interactive/TextFieldComponent.tsx +65 -0
  88. package/src/0.8/components/interactive/index.ts +10 -0
  89. package/src/0.8/components/interactive/interactive.test.tsx +618 -0
  90. package/src/0.8/components/layout/CardComponent.tsx +30 -0
  91. package/src/0.8/components/layout/ColumnComponent.tsx +93 -0
  92. package/src/0.8/components/layout/ListComponent.tsx +81 -0
  93. package/src/0.8/components/layout/ModalComponent.tsx +41 -0
  94. package/src/0.8/components/layout/RowComponent.tsx +94 -0
  95. package/src/0.8/components/layout/TabsComponent.tsx +59 -0
  96. package/src/0.8/components/layout/index.ts +10 -0
  97. package/src/0.8/components/layout/layout.test.tsx +558 -0
  98. package/src/0.8/contexts/A2UIProvider.test.tsx +226 -0
  99. package/src/0.8/contexts/A2UIProvider.tsx +54 -0
  100. package/src/0.8/contexts/ActionContext.test.tsx +242 -0
  101. package/src/0.8/contexts/ActionContext.tsx +105 -0
  102. package/src/0.8/contexts/ComponentsMapContext.tsx +125 -0
  103. package/src/0.8/contexts/DataModelContext.test.tsx +335 -0
  104. package/src/0.8/contexts/DataModelContext.tsx +184 -0
  105. package/src/0.8/contexts/SurfaceContext.test.tsx +339 -0
  106. package/src/0.8/contexts/SurfaceContext.tsx +197 -0
  107. package/src/0.8/hooks/useA2UIMessageHandler.test.tsx +399 -0
  108. package/src/0.8/hooks/useA2UIMessageHandler.ts +123 -0
  109. package/src/0.8/hooks/useComponent.test.tsx +148 -0
  110. package/src/0.8/hooks/useComponent.ts +39 -0
  111. package/src/0.8/hooks/useDataBinding.test.tsx +334 -0
  112. package/src/0.8/hooks/useDataBinding.ts +99 -0
  113. package/src/0.8/hooks/useDispatchAction.test.tsx +83 -0
  114. package/src/0.8/hooks/useDispatchAction.ts +35 -0
  115. package/src/0.8/hooks/useSurface.test.tsx +114 -0
  116. package/src/0.8/hooks/useSurface.ts +34 -0
  117. package/src/0.8/index.ts +38 -0
  118. package/src/0.8/schemas/client_to_server.json +50 -0
  119. package/src/0.8/schemas/server_to_client.json +148 -0
  120. package/src/0.8/schemas/standard_catalog_definition.json +661 -0
  121. package/src/0.8/types/index.ts +448 -0
  122. package/src/0.8/utils/dataBinding.test.ts +443 -0
  123. package/src/0.8/utils/dataBinding.ts +212 -0
  124. package/src/0.8/utils/pathUtils.test.ts +353 -0
  125. package/src/0.8/utils/pathUtils.ts +200 -0
  126. package/src/components/ui/button.tsx +62 -0
  127. package/src/components/ui/calendar.tsx +220 -0
  128. package/src/components/ui/card.tsx +92 -0
  129. package/src/components/ui/checkbox.tsx +30 -0
  130. package/src/components/ui/dialog.tsx +141 -0
  131. package/src/components/ui/input.tsx +21 -0
  132. package/src/components/ui/label.tsx +22 -0
  133. package/src/components/ui/native-select.tsx +53 -0
  134. package/src/components/ui/popover.tsx +46 -0
  135. package/src/components/ui/select.tsx +188 -0
  136. package/src/components/ui/separator.tsx +26 -0
  137. package/src/components/ui/slider.tsx +61 -0
  138. package/src/components/ui/tabs.tsx +64 -0
  139. package/src/components/ui/textarea.tsx +18 -0
  140. package/src/index.ts +1 -0
  141. package/src/lib/utils.ts +6 -0
  142. package/tsconfig.json +28 -0
  143. package/vite.config.ts +29 -0
  144. package/vitest.config.ts +22 -0
  145. package/vitest.setup.ts +8 -0
  146. package/website/README.md +4 -0
  147. package/website/assets/favicon.svg +8 -0
  148. package/website/content/.gitkeep +0 -0
  149. package/website/content/index.md +122 -0
  150. package/website/global.d.ts +9 -0
  151. package/website/package.json +17 -0
  152. package/website/plain.config.js +28 -0
  153. package/website/serve.json +6 -0
  154. package/website/src/client/color-mode-switch.css +47 -0
  155. package/website/src/client/index.js +61 -0
  156. package/website/src/client/moon.svg +1 -0
  157. package/website/src/client/sun.svg +1 -0
  158. package/website/src/components/Footer.jsx +9 -0
  159. package/website/src/components/Header.jsx +44 -0
  160. package/website/src/components/Page.jsx +28 -0
  161. package/website/src/global.css +423 -0
@@ -0,0 +1,137 @@
1
+ ---
2
+ description: Generate an actionable, dependency-ordered tasks.md for the feature based on available design artifacts.
3
+ handoffs:
4
+ - label: Analyze For Consistency
5
+ agent: speckit.analyze
6
+ prompt: Run a project analysis for consistency
7
+ send: true
8
+ - label: Implement Project
9
+ agent: speckit.implement
10
+ prompt: Start the implementation in phases
11
+ send: true
12
+ ---
13
+
14
+ ## User Input
15
+
16
+ ```text
17
+ $ARGUMENTS
18
+ ```
19
+
20
+ You **MUST** consider the user input before proceeding (if not empty).
21
+
22
+ ## Outline
23
+
24
+ 1. **Setup**: Run `.specify/scripts/bash/check-prerequisites.sh --json` from repo root and parse FEATURE_DIR and AVAILABLE_DOCS list. All paths must be absolute. For single quotes in args like "I'm Groot", use escape syntax: e.g 'I'\''m Groot' (or double-quote if possible: "I'm Groot").
25
+
26
+ 2. **Load design documents**: Read from FEATURE_DIR:
27
+ - **Required**: plan.md (tech stack, libraries, structure), spec.md (user stories with priorities)
28
+ - **Optional**: data-model.md (entities), contracts/ (API endpoints), research.md (decisions), quickstart.md (test scenarios)
29
+ - Note: Not all projects have all documents. Generate tasks based on what's available.
30
+
31
+ 3. **Execute task generation workflow**:
32
+ - Load plan.md and extract tech stack, libraries, project structure
33
+ - Load spec.md and extract user stories with their priorities (P1, P2, P3, etc.)
34
+ - If data-model.md exists: Extract entities and map to user stories
35
+ - If contracts/ exists: Map endpoints to user stories
36
+ - If research.md exists: Extract decisions for setup tasks
37
+ - Generate tasks organized by user story (see Task Generation Rules below)
38
+ - Generate dependency graph showing user story completion order
39
+ - Create parallel execution examples per user story
40
+ - Validate task completeness (each user story has all needed tasks, independently testable)
41
+
42
+ 4. **Generate tasks.md**: Use `.specify/templates/tasks-template.md` as structure, fill with:
43
+ - Correct feature name from plan.md
44
+ - Phase 1: Setup tasks (project initialization)
45
+ - Phase 2: Foundational tasks (blocking prerequisites for all user stories)
46
+ - Phase 3+: One phase per user story (in priority order from spec.md)
47
+ - Each phase includes: story goal, independent test criteria, tests (if requested), implementation tasks
48
+ - Final Phase: Polish & cross-cutting concerns
49
+ - All tasks must follow the strict checklist format (see Task Generation Rules below)
50
+ - Clear file paths for each task
51
+ - Dependencies section showing story completion order
52
+ - Parallel execution examples per story
53
+ - Implementation strategy section (MVP first, incremental delivery)
54
+
55
+ 5. **Report**: Output path to generated tasks.md and summary:
56
+ - Total task count
57
+ - Task count per user story
58
+ - Parallel opportunities identified
59
+ - Independent test criteria for each story
60
+ - Suggested MVP scope (typically just User Story 1)
61
+ - Format validation: Confirm ALL tasks follow the checklist format (checkbox, ID, labels, file paths)
62
+
63
+ Context for task generation: $ARGUMENTS
64
+
65
+ The tasks.md should be immediately executable - each task must be specific enough that an LLM can complete it without additional context.
66
+
67
+ ## Task Generation Rules
68
+
69
+ **CRITICAL**: Tasks MUST be organized by user story to enable independent implementation and testing.
70
+
71
+ **Tests are OPTIONAL**: Only generate test tasks if explicitly requested in the feature specification or if user requests TDD approach.
72
+
73
+ ### Checklist Format (REQUIRED)
74
+
75
+ Every task MUST strictly follow this format:
76
+
77
+ ```text
78
+ - [ ] [TaskID] [P?] [Story?] Description with file path
79
+ ```
80
+
81
+ **Format Components**:
82
+
83
+ 1. **Checkbox**: ALWAYS start with `- [ ]` (markdown checkbox)
84
+ 2. **Task ID**: Sequential number (T001, T002, T003...) in execution order
85
+ 3. **[P] marker**: Include ONLY if task is parallelizable (different files, no dependencies on incomplete tasks)
86
+ 4. **[Story] label**: REQUIRED for user story phase tasks only
87
+ - Format: [US1], [US2], [US3], etc. (maps to user stories from spec.md)
88
+ - Setup phase: NO story label
89
+ - Foundational phase: NO story label
90
+ - User Story phases: MUST have story label
91
+ - Polish phase: NO story label
92
+ 5. **Description**: Clear action with exact file path
93
+
94
+ **Examples**:
95
+
96
+ - ✅ CORRECT: `- [ ] T001 Create project structure per implementation plan`
97
+ - ✅ CORRECT: `- [ ] T005 [P] Implement authentication middleware in src/middleware/auth.py`
98
+ - ✅ CORRECT: `- [ ] T012 [P] [US1] Create User model in src/models/user.py`
99
+ - ✅ CORRECT: `- [ ] T014 [US1] Implement UserService in src/services/user_service.py`
100
+ - ❌ WRONG: `- [ ] Create User model` (missing ID and Story label)
101
+ - ❌ WRONG: `T001 [US1] Create model` (missing checkbox)
102
+ - ❌ WRONG: `- [ ] [US1] Create User model` (missing Task ID)
103
+ - ❌ WRONG: `- [ ] T001 [US1] Create model` (missing file path)
104
+
105
+ ### Task Organization
106
+
107
+ 1. **From User Stories (spec.md)** - PRIMARY ORGANIZATION:
108
+ - Each user story (P1, P2, P3...) gets its own phase
109
+ - Map all related components to their story:
110
+ - Models needed for that story
111
+ - Services needed for that story
112
+ - Endpoints/UI needed for that story
113
+ - If tests requested: Tests specific to that story
114
+ - Mark story dependencies (most stories should be independent)
115
+
116
+ 2. **From Contracts**:
117
+ - Map each contract/endpoint → to the user story it serves
118
+ - If tests requested: Each contract → contract test task [P] before implementation in that story's phase
119
+
120
+ 3. **From Data Model**:
121
+ - Map each entity to the user story(ies) that need it
122
+ - If entity serves multiple stories: Put in earliest story or Setup phase
123
+ - Relationships → service layer tasks in appropriate story phase
124
+
125
+ 4. **From Setup/Infrastructure**:
126
+ - Shared infrastructure → Setup phase (Phase 1)
127
+ - Foundational/blocking tasks → Foundational phase (Phase 2)
128
+ - Story-specific setup → within that story's phase
129
+
130
+ ### Phase Structure
131
+
132
+ - **Phase 1**: Setup (project initialization)
133
+ - **Phase 2**: Foundational (blocking prerequisites - MUST complete before user stories)
134
+ - **Phase 3+**: User Stories in priority order (P1, P2, P3...)
135
+ - Within each story: Tests (if requested) → Models → Services → Endpoints → Integration
136
+ - Each phase should be a complete, independently testable increment
137
+ - **Final Phase**: Polish & Cross-Cutting Concerns
@@ -0,0 +1,30 @@
1
+ ---
2
+ description: Convert existing tasks into actionable, dependency-ordered GitHub issues for the feature based on available design artifacts.
3
+ tools: ['github/github-mcp-server/issue_write']
4
+ ---
5
+
6
+ ## User Input
7
+
8
+ ```text
9
+ $ARGUMENTS
10
+ ```
11
+
12
+ You **MUST** consider the user input before proceeding (if not empty).
13
+
14
+ ## Outline
15
+
16
+ 1. Run `.specify/scripts/bash/check-prerequisites.sh --json --require-tasks --include-tasks` from repo root and parse FEATURE_DIR and AVAILABLE_DOCS list. All paths must be absolute. For single quotes in args like "I'm Groot", use escape syntax: e.g 'I'\''m Groot' (or double-quote if possible: "I'm Groot").
17
+ 1. From the executed script, extract the path to **tasks**.
18
+ 1. Get the Git remote by running:
19
+
20
+ ```bash
21
+ git config --get remote.origin.url
22
+ ```
23
+
24
+ > [!CAUTION]
25
+ > ONLY PROCEED TO NEXT STEPS IF THE REMOTE IS A GITHUB URL
26
+
27
+ 1. For each task in the list, use the GitHub MCP server to create a new issue in the repository that is representative of the Git remote.
28
+
29
+ > [!CAUTION]
30
+ > UNDER NO CIRCUMSTANCES EVER CREATE ISSUES IN REPOSITORIES THAT DO NOT MATCH THE REMOTE URL
@@ -0,0 +1,69 @@
1
+ name: Deploy to GitHub Pages
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+ branches:
9
+ - main
10
+ workflow_dispatch:
11
+
12
+ jobs:
13
+ build-and-deploy:
14
+ runs-on: ubuntu-latest
15
+
16
+ steps:
17
+ - name: Checkout
18
+ uses: actions/checkout@v4
19
+
20
+ - name: Setup Node.js
21
+ uses: actions/setup-node@v4
22
+ with:
23
+ node-version: '22'
24
+ cache: 'npm'
25
+ registry-url: 'https://registry.npmjs.org'
26
+
27
+ - name: Install dependencies
28
+ run: npm ci
29
+
30
+ - name: Build @easyops-cn/a2ui-react
31
+ run: npm run build
32
+
33
+ - name: Publish to npm
34
+ run: npm publish --access public
35
+ env:
36
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
37
+ if: github.event_name == 'push' && github.ref == 'refs/heads/main'
38
+
39
+ - name: Build playground
40
+ run: npm run build -w playground
41
+
42
+ - name: Build website
43
+ run: npm run build -w website
44
+
45
+ - name: Copy website dist to build/a2ui-react, and playground dist to build/a2ui-react/playground
46
+ run: mkdir -p build && cp -r website/dist build/a2ui-react && cp -r playground/dist build/a2ui-react/playground
47
+
48
+ - name: Deploy to Netlify (pull request)
49
+ id: netlify-deploy
50
+ uses: nwtgck/actions-netlify@v3.0
51
+ with:
52
+ publish-dir: ./build
53
+ production-branch: main
54
+ github-token: ${{ secrets.GITHUB_TOKEN }}
55
+ deploy-message: "${{ github.event.pull_request.title }}"
56
+ netlify-config-path: ./netlify.toml
57
+ env:
58
+ NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
59
+ NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
60
+ timeout-minutes: 2
61
+ if: github.event_name == 'pull_request'
62
+
63
+ - name: Deploy to GitHub Pages
64
+ uses: peaceiris/actions-gh-pages@v4
65
+ with:
66
+ personal_token: ${{ secrets.GH_TOKEN_EVE }}
67
+ publish_dir: ./build/a2ui-react
68
+ force_orphan: true
69
+ if: github.event_name == 'push' && github.ref == 'refs/heads/main'
@@ -0,0 +1 @@
1
+ npx lint-staged
@@ -0,0 +1,4 @@
1
+ dist
2
+ node_modules
3
+ coverage
4
+ *.log
package/.prettierrc ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "semi": false,
3
+ "singleQuote": true,
4
+ "tabWidth": 2,
5
+ "trailingComma": "es5",
6
+ "printWidth": 80
7
+ }
@@ -0,0 +1,73 @@
1
+ # [PROJECT_NAME] Constitution
2
+
3
+ <!-- Example: Spec Constitution, TaskFlow Constitution, etc. -->
4
+
5
+ ## Core Principles
6
+
7
+ ### [PRINCIPLE_1_NAME]
8
+
9
+ <!-- Example: I. Library-First -->
10
+
11
+ [PRINCIPLE_1_DESCRIPTION]
12
+
13
+ <!-- Example: Every feature starts as a standalone library; Libraries must be self-contained, independently testable, documented; Clear purpose required - no organizational-only libraries -->
14
+
15
+ ### [PRINCIPLE_2_NAME]
16
+
17
+ <!-- Example: II. CLI Interface -->
18
+
19
+ [PRINCIPLE_2_DESCRIPTION]
20
+
21
+ <!-- Example: Every library exposes functionality via CLI; Text in/out protocol: stdin/args → stdout, errors → stderr; Support JSON + human-readable formats -->
22
+
23
+ ### [PRINCIPLE_3_NAME]
24
+
25
+ <!-- Example: III. Test-First (NON-NEGOTIABLE) -->
26
+
27
+ [PRINCIPLE_3_DESCRIPTION]
28
+
29
+ <!-- Example: TDD mandatory: Tests written → User approved → Tests fail → Then implement; Red-Green-Refactor cycle strictly enforced -->
30
+
31
+ ### [PRINCIPLE_4_NAME]
32
+
33
+ <!-- Example: IV. Integration Testing -->
34
+
35
+ [PRINCIPLE_4_DESCRIPTION]
36
+
37
+ <!-- Example: Focus areas requiring integration tests: New library contract tests, Contract changes, Inter-service communication, Shared schemas -->
38
+
39
+ ### [PRINCIPLE_5_NAME]
40
+
41
+ <!-- Example: V. Observability, VI. Versioning & Breaking Changes, VII. Simplicity -->
42
+
43
+ [PRINCIPLE_5_DESCRIPTION]
44
+
45
+ <!-- Example: Text I/O ensures debuggability; Structured logging required; Or: MAJOR.MINOR.BUILD format; Or: Start simple, YAGNI principles -->
46
+
47
+ ## [SECTION_2_NAME]
48
+
49
+ <!-- Example: Additional Constraints, Security Requirements, Performance Standards, etc. -->
50
+
51
+ [SECTION_2_CONTENT]
52
+
53
+ <!-- Example: Technology stack requirements, compliance standards, deployment policies, etc. -->
54
+
55
+ ## [SECTION_3_NAME]
56
+
57
+ <!-- Example: Development Workflow, Review Process, Quality Gates, etc. -->
58
+
59
+ [SECTION_3_CONTENT]
60
+
61
+ <!-- Example: Code review requirements, testing gates, deployment approval process, etc. -->
62
+
63
+ ## Governance
64
+
65
+ <!-- Example: Constitution supersedes all other practices; Amendments require documentation, approval, migration plan -->
66
+
67
+ [GOVERNANCE_RULES]
68
+
69
+ <!-- Example: All PRs/reviews must verify compliance; Complexity must be justified; Use [GUIDANCE_FILE] for runtime development guidance -->
70
+
71
+ **Version**: [CONSTITUTION_VERSION] | **Ratified**: [RATIFICATION_DATE] | **Last Amended**: [LAST_AMENDED_DATE]
72
+
73
+ <!-- Example: Version: 2.1.1 | Ratified: 2025-06-13 | Last Amended: 2025-07-16 -->
@@ -0,0 +1,166 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Consolidated prerequisite checking script
4
+ #
5
+ # This script provides unified prerequisite checking for Spec-Driven Development workflow.
6
+ # It replaces the functionality previously spread across multiple scripts.
7
+ #
8
+ # Usage: ./check-prerequisites.sh [OPTIONS]
9
+ #
10
+ # OPTIONS:
11
+ # --json Output in JSON format
12
+ # --require-tasks Require tasks.md to exist (for implementation phase)
13
+ # --include-tasks Include tasks.md in AVAILABLE_DOCS list
14
+ # --paths-only Only output path variables (no validation)
15
+ # --help, -h Show help message
16
+ #
17
+ # OUTPUTS:
18
+ # JSON mode: {"FEATURE_DIR":"...", "AVAILABLE_DOCS":["..."]}
19
+ # Text mode: FEATURE_DIR:... \n AVAILABLE_DOCS: \n ✓/✗ file.md
20
+ # Paths only: REPO_ROOT: ... \n BRANCH: ... \n FEATURE_DIR: ... etc.
21
+
22
+ set -e
23
+
24
+ # Parse command line arguments
25
+ JSON_MODE=false
26
+ REQUIRE_TASKS=false
27
+ INCLUDE_TASKS=false
28
+ PATHS_ONLY=false
29
+
30
+ for arg in "$@"; do
31
+ case "$arg" in
32
+ --json)
33
+ JSON_MODE=true
34
+ ;;
35
+ --require-tasks)
36
+ REQUIRE_TASKS=true
37
+ ;;
38
+ --include-tasks)
39
+ INCLUDE_TASKS=true
40
+ ;;
41
+ --paths-only)
42
+ PATHS_ONLY=true
43
+ ;;
44
+ --help|-h)
45
+ cat << 'EOF'
46
+ Usage: check-prerequisites.sh [OPTIONS]
47
+
48
+ Consolidated prerequisite checking for Spec-Driven Development workflow.
49
+
50
+ OPTIONS:
51
+ --json Output in JSON format
52
+ --require-tasks Require tasks.md to exist (for implementation phase)
53
+ --include-tasks Include tasks.md in AVAILABLE_DOCS list
54
+ --paths-only Only output path variables (no prerequisite validation)
55
+ --help, -h Show this help message
56
+
57
+ EXAMPLES:
58
+ # Check task prerequisites (plan.md required)
59
+ ./check-prerequisites.sh --json
60
+
61
+ # Check implementation prerequisites (plan.md + tasks.md required)
62
+ ./check-prerequisites.sh --json --require-tasks --include-tasks
63
+
64
+ # Get feature paths only (no validation)
65
+ ./check-prerequisites.sh --paths-only
66
+
67
+ EOF
68
+ exit 0
69
+ ;;
70
+ *)
71
+ echo "ERROR: Unknown option '$arg'. Use --help for usage information." >&2
72
+ exit 1
73
+ ;;
74
+ esac
75
+ done
76
+
77
+ # Source common functions
78
+ SCRIPT_DIR="$(CDPATH="" cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
79
+ source "$SCRIPT_DIR/common.sh"
80
+
81
+ # Get feature paths and validate branch
82
+ eval $(get_feature_paths)
83
+ check_feature_branch "$CURRENT_BRANCH" "$HAS_GIT" || exit 1
84
+
85
+ # If paths-only mode, output paths and exit (support JSON + paths-only combined)
86
+ if $PATHS_ONLY; then
87
+ if $JSON_MODE; then
88
+ # Minimal JSON paths payload (no validation performed)
89
+ printf '{"REPO_ROOT":"%s","BRANCH":"%s","FEATURE_DIR":"%s","FEATURE_SPEC":"%s","IMPL_PLAN":"%s","TASKS":"%s"}\n' \
90
+ "$REPO_ROOT" "$CURRENT_BRANCH" "$FEATURE_DIR" "$FEATURE_SPEC" "$IMPL_PLAN" "$TASKS"
91
+ else
92
+ echo "REPO_ROOT: $REPO_ROOT"
93
+ echo "BRANCH: $CURRENT_BRANCH"
94
+ echo "FEATURE_DIR: $FEATURE_DIR"
95
+ echo "FEATURE_SPEC: $FEATURE_SPEC"
96
+ echo "IMPL_PLAN: $IMPL_PLAN"
97
+ echo "TASKS: $TASKS"
98
+ fi
99
+ exit 0
100
+ fi
101
+
102
+ # Validate required directories and files
103
+ if [[ ! -d "$FEATURE_DIR" ]]; then
104
+ echo "ERROR: Feature directory not found: $FEATURE_DIR" >&2
105
+ echo "Run /speckit.specify first to create the feature structure." >&2
106
+ exit 1
107
+ fi
108
+
109
+ if [[ ! -f "$IMPL_PLAN" ]]; then
110
+ echo "ERROR: plan.md not found in $FEATURE_DIR" >&2
111
+ echo "Run /speckit.plan first to create the implementation plan." >&2
112
+ exit 1
113
+ fi
114
+
115
+ # Check for tasks.md if required
116
+ if $REQUIRE_TASKS && [[ ! -f "$TASKS" ]]; then
117
+ echo "ERROR: tasks.md not found in $FEATURE_DIR" >&2
118
+ echo "Run /speckit.tasks first to create the task list." >&2
119
+ exit 1
120
+ fi
121
+
122
+ # Build list of available documents
123
+ docs=()
124
+
125
+ # Always check these optional docs
126
+ [[ -f "$RESEARCH" ]] && docs+=("research.md")
127
+ [[ -f "$DATA_MODEL" ]] && docs+=("data-model.md")
128
+
129
+ # Check contracts directory (only if it exists and has files)
130
+ if [[ -d "$CONTRACTS_DIR" ]] && [[ -n "$(ls -A "$CONTRACTS_DIR" 2>/dev/null)" ]]; then
131
+ docs+=("contracts/")
132
+ fi
133
+
134
+ [[ -f "$QUICKSTART" ]] && docs+=("quickstart.md")
135
+
136
+ # Include tasks.md if requested and it exists
137
+ if $INCLUDE_TASKS && [[ -f "$TASKS" ]]; then
138
+ docs+=("tasks.md")
139
+ fi
140
+
141
+ # Output results
142
+ if $JSON_MODE; then
143
+ # Build JSON array of documents
144
+ if [[ ${#docs[@]} -eq 0 ]]; then
145
+ json_docs="[]"
146
+ else
147
+ json_docs=$(printf '"%s",' "${docs[@]}")
148
+ json_docs="[${json_docs%,}]"
149
+ fi
150
+
151
+ printf '{"FEATURE_DIR":"%s","AVAILABLE_DOCS":%s}\n' "$FEATURE_DIR" "$json_docs"
152
+ else
153
+ # Text output
154
+ echo "FEATURE_DIR:$FEATURE_DIR"
155
+ echo "AVAILABLE_DOCS:"
156
+
157
+ # Show status of each potential document
158
+ check_file "$RESEARCH" "research.md"
159
+ check_file "$DATA_MODEL" "data-model.md"
160
+ check_dir "$CONTRACTS_DIR" "contracts/"
161
+ check_file "$QUICKSTART" "quickstart.md"
162
+
163
+ if $INCLUDE_TASKS; then
164
+ check_file "$TASKS" "tasks.md"
165
+ fi
166
+ fi
@@ -0,0 +1,156 @@
1
+ #!/usr/bin/env bash
2
+ # Common functions and variables for all scripts
3
+
4
+ # Get repository root, with fallback for non-git repositories
5
+ get_repo_root() {
6
+ if git rev-parse --show-toplevel >/dev/null 2>&1; then
7
+ git rev-parse --show-toplevel
8
+ else
9
+ # Fall back to script location for non-git repos
10
+ local script_dir="$(CDPATH="" cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
11
+ (cd "$script_dir/../../.." && pwd)
12
+ fi
13
+ }
14
+
15
+ # Get current branch, with fallback for non-git repositories
16
+ get_current_branch() {
17
+ # First check if SPECIFY_FEATURE environment variable is set
18
+ if [[ -n "${SPECIFY_FEATURE:-}" ]]; then
19
+ echo "$SPECIFY_FEATURE"
20
+ return
21
+ fi
22
+
23
+ # Then check git if available
24
+ if git rev-parse --abbrev-ref HEAD >/dev/null 2>&1; then
25
+ git rev-parse --abbrev-ref HEAD
26
+ return
27
+ fi
28
+
29
+ # For non-git repos, try to find the latest feature directory
30
+ local repo_root=$(get_repo_root)
31
+ local specs_dir="$repo_root/specs"
32
+
33
+ if [[ -d "$specs_dir" ]]; then
34
+ local latest_feature=""
35
+ local highest=0
36
+
37
+ for dir in "$specs_dir"/*; do
38
+ if [[ -d "$dir" ]]; then
39
+ local dirname=$(basename "$dir")
40
+ if [[ "$dirname" =~ ^([0-9]{3})- ]]; then
41
+ local number=${BASH_REMATCH[1]}
42
+ number=$((10#$number))
43
+ if [[ "$number" -gt "$highest" ]]; then
44
+ highest=$number
45
+ latest_feature=$dirname
46
+ fi
47
+ fi
48
+ fi
49
+ done
50
+
51
+ if [[ -n "$latest_feature" ]]; then
52
+ echo "$latest_feature"
53
+ return
54
+ fi
55
+ fi
56
+
57
+ echo "main" # Final fallback
58
+ }
59
+
60
+ # Check if we have git available
61
+ has_git() {
62
+ git rev-parse --show-toplevel >/dev/null 2>&1
63
+ }
64
+
65
+ check_feature_branch() {
66
+ local branch="$1"
67
+ local has_git_repo="$2"
68
+
69
+ # For non-git repos, we can't enforce branch naming but still provide output
70
+ if [[ "$has_git_repo" != "true" ]]; then
71
+ echo "[specify] Warning: Git repository not detected; skipped branch validation" >&2
72
+ return 0
73
+ fi
74
+
75
+ if [[ ! "$branch" =~ ^[0-9]{3}- ]]; then
76
+ echo "ERROR: Not on a feature branch. Current branch: $branch" >&2
77
+ echo "Feature branches should be named like: 001-feature-name" >&2
78
+ return 1
79
+ fi
80
+
81
+ return 0
82
+ }
83
+
84
+ get_feature_dir() { echo "$1/specs/$2"; }
85
+
86
+ # Find feature directory by numeric prefix instead of exact branch match
87
+ # This allows multiple branches to work on the same spec (e.g., 004-fix-bug, 004-add-feature)
88
+ find_feature_dir_by_prefix() {
89
+ local repo_root="$1"
90
+ local branch_name="$2"
91
+ local specs_dir="$repo_root/specs"
92
+
93
+ # Extract numeric prefix from branch (e.g., "004" from "004-whatever")
94
+ if [[ ! "$branch_name" =~ ^([0-9]{3})- ]]; then
95
+ # If branch doesn't have numeric prefix, fall back to exact match
96
+ echo "$specs_dir/$branch_name"
97
+ return
98
+ fi
99
+
100
+ local prefix="${BASH_REMATCH[1]}"
101
+
102
+ # Search for directories in specs/ that start with this prefix
103
+ local matches=()
104
+ if [[ -d "$specs_dir" ]]; then
105
+ for dir in "$specs_dir"/"$prefix"-*; do
106
+ if [[ -d "$dir" ]]; then
107
+ matches+=("$(basename "$dir")")
108
+ fi
109
+ done
110
+ fi
111
+
112
+ # Handle results
113
+ if [[ ${#matches[@]} -eq 0 ]]; then
114
+ # No match found - return the branch name path (will fail later with clear error)
115
+ echo "$specs_dir/$branch_name"
116
+ elif [[ ${#matches[@]} -eq 1 ]]; then
117
+ # Exactly one match - perfect!
118
+ echo "$specs_dir/${matches[0]}"
119
+ else
120
+ # Multiple matches - this shouldn't happen with proper naming convention
121
+ echo "ERROR: Multiple spec directories found with prefix '$prefix': ${matches[*]}" >&2
122
+ echo "Please ensure only one spec directory exists per numeric prefix." >&2
123
+ echo "$specs_dir/$branch_name" # Return something to avoid breaking the script
124
+ fi
125
+ }
126
+
127
+ get_feature_paths() {
128
+ local repo_root=$(get_repo_root)
129
+ local current_branch=$(get_current_branch)
130
+ local has_git_repo="false"
131
+
132
+ if has_git; then
133
+ has_git_repo="true"
134
+ fi
135
+
136
+ # Use prefix-based lookup to support multiple branches per spec
137
+ local feature_dir=$(find_feature_dir_by_prefix "$repo_root" "$current_branch")
138
+
139
+ cat <<EOF
140
+ REPO_ROOT='$repo_root'
141
+ CURRENT_BRANCH='$current_branch'
142
+ HAS_GIT='$has_git_repo'
143
+ FEATURE_DIR='$feature_dir'
144
+ FEATURE_SPEC='$feature_dir/spec.md'
145
+ IMPL_PLAN='$feature_dir/plan.md'
146
+ TASKS='$feature_dir/tasks.md'
147
+ RESEARCH='$feature_dir/research.md'
148
+ DATA_MODEL='$feature_dir/data-model.md'
149
+ QUICKSTART='$feature_dir/quickstart.md'
150
+ CONTRACTS_DIR='$feature_dir/contracts'
151
+ EOF
152
+ }
153
+
154
+ check_file() { [[ -f "$1" ]] && echo " ✓ $2" || echo " ✗ $2"; }
155
+ check_dir() { [[ -d "$1" && -n $(ls -A "$1" 2>/dev/null) ]] && echo " ✓ $2" || echo " ✗ $2"; }
156
+