@ktpartners/dgs-platform 2.6.2
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.
- package/LICENSE +38 -0
- package/README.md +851 -0
- package/agents/dgs-codebase-cross-analyzer.md +183 -0
- package/agents/dgs-codebase-mapper.md +782 -0
- package/agents/dgs-codebase-synthesizer.md +156 -0
- package/agents/dgs-debugger.md +1256 -0
- package/agents/dgs-executor.md +550 -0
- package/agents/dgs-integration-checker.md +481 -0
- package/agents/dgs-nyquist-auditor.md +178 -0
- package/agents/dgs-phase-researcher.md +563 -0
- package/agents/dgs-phase-verifier.md +450 -0
- package/agents/dgs-plan-checker.md +708 -0
- package/agents/dgs-planner.md +1324 -0
- package/agents/dgs-project-researcher.md +631 -0
- package/agents/dgs-research-synthesizer.md +249 -0
- package/agents/dgs-roadmapper.md +652 -0
- package/agents/dgs-verifier.md +607 -0
- package/bin/install.js +2073 -0
- package/commands/dgs/add-doc.md +45 -0
- package/commands/dgs/add-idea.md +38 -0
- package/commands/dgs/add-phase.md +43 -0
- package/commands/dgs/add-repo.md +54 -0
- package/commands/dgs/add-tests.md +41 -0
- package/commands/dgs/add-todo.md +47 -0
- package/commands/dgs/approve-spec.md +38 -0
- package/commands/dgs/audit-milestone.md +36 -0
- package/commands/dgs/audit-phase.md +37 -0
- package/commands/dgs/cancel-job.md +23 -0
- package/commands/dgs/capture-principle.md +143 -0
- package/commands/dgs/check-todos.md +45 -0
- package/commands/dgs/cleanup.md +18 -0
- package/commands/dgs/complete-milestone.md +136 -0
- package/commands/dgs/complete-project.md +70 -0
- package/commands/dgs/consolidate-ideas.md +50 -0
- package/commands/dgs/create-milestone-job.md +37 -0
- package/commands/dgs/debug.md +164 -0
- package/commands/dgs/develop-idea.md +53 -0
- package/commands/dgs/discuss-idea.md +41 -0
- package/commands/dgs/discuss-phase.md +83 -0
- package/commands/dgs/execute-phase.md +41 -0
- package/commands/dgs/fast.md +38 -0
- package/commands/dgs/find-related-ideas.md +43 -0
- package/commands/dgs/health.md +28 -0
- package/commands/dgs/help.md +22 -0
- package/commands/dgs/import-spec.md +36 -0
- package/commands/dgs/init-product.md +28 -0
- package/commands/dgs/insert-phase.md +32 -0
- package/commands/dgs/join-discord.md +18 -0
- package/commands/dgs/list-docs.md +40 -0
- package/commands/dgs/list-ideas.md +42 -0
- package/commands/dgs/list-jobs.md +22 -0
- package/commands/dgs/list-phase-assumptions.md +46 -0
- package/commands/dgs/list-projects.md +57 -0
- package/commands/dgs/list-specs.md +40 -0
- package/commands/dgs/map-codebase.md +92 -0
- package/commands/dgs/new-milestone.md +44 -0
- package/commands/dgs/new-project.md +42 -0
- package/commands/dgs/node-repair.md +26 -0
- package/commands/dgs/overlap-check.md +20 -0
- package/commands/dgs/pause-work.md +38 -0
- package/commands/dgs/plan-milestone-gaps.md +34 -0
- package/commands/dgs/plan-phase.md +44 -0
- package/commands/dgs/progress.md +24 -0
- package/commands/dgs/quick.md +41 -0
- package/commands/dgs/reactivate-project.md +70 -0
- package/commands/dgs/reapply-patches.md +110 -0
- package/commands/dgs/refine-spec.md +38 -0
- package/commands/dgs/reject-idea.md +43 -0
- package/commands/dgs/remove-doc.md +44 -0
- package/commands/dgs/remove-phase.md +31 -0
- package/commands/dgs/remove-repo.md +69 -0
- package/commands/dgs/research-idea.md +43 -0
- package/commands/dgs/research-phase.md +189 -0
- package/commands/dgs/restore-idea.md +45 -0
- package/commands/dgs/resume-work.md +40 -0
- package/commands/dgs/rollback-job.md +24 -0
- package/commands/dgs/run-job.md +35 -0
- package/commands/dgs/search.md +40 -0
- package/commands/dgs/set-profile.md +34 -0
- package/commands/dgs/settings.md +38 -0
- package/commands/dgs/switch-project.md +58 -0
- package/commands/dgs/undo-consolidation.md +42 -0
- package/commands/dgs/update-idea.md +44 -0
- package/commands/dgs/update.md +37 -0
- package/commands/dgs/validate-phase.md +35 -0
- package/commands/dgs/verify-work.md +39 -0
- package/commands/dgs/write-spec.md +49 -0
- package/deliver-great-systems/.planning/phases/09-backend-wiring-and-error-handling/09-01-SUMMARY.md +84 -0
- package/deliver-great-systems/.planning/phases/09-backend-wiring-and-error-handling/09-02-SUMMARY.md +86 -0
- package/deliver-great-systems/.planning/phases/10-v1-to-v2-migration-flow/10-01-SUMMARY.md +85 -0
- package/deliver-great-systems/bin/dgs-tools.cjs +1444 -0
- package/deliver-great-systems/bin/lib/auto-test.cjs +1365 -0
- package/deliver-great-systems/bin/lib/commands.cjs +570 -0
- package/deliver-great-systems/bin/lib/config.cjs +417 -0
- package/deliver-great-systems/bin/lib/conflict-agent.cjs +1063 -0
- package/deliver-great-systems/bin/lib/conflict-agent.test.cjs +554 -0
- package/deliver-great-systems/bin/lib/context.cjs +929 -0
- package/deliver-great-systems/bin/lib/context.test.cjs +693 -0
- package/deliver-great-systems/bin/lib/core.cjs +744 -0
- package/deliver-great-systems/bin/lib/core.test.cjs +822 -0
- package/deliver-great-systems/bin/lib/docs.cjs +919 -0
- package/deliver-great-systems/bin/lib/docs.test.cjs +211 -0
- package/deliver-great-systems/bin/lib/execution.cjs +705 -0
- package/deliver-great-systems/bin/lib/execution.test.cjs +1472 -0
- package/deliver-great-systems/bin/lib/frontmatter.cjs +324 -0
- package/deliver-great-systems/bin/lib/ideas.cjs +1406 -0
- package/deliver-great-systems/bin/lib/ideas.test.cjs +1417 -0
- package/deliver-great-systems/bin/lib/identity.cjs +125 -0
- package/deliver-great-systems/bin/lib/init.cjs +1114 -0
- package/deliver-great-systems/bin/lib/init.test.cjs +1271 -0
- package/deliver-great-systems/bin/lib/jobs.cjs +2015 -0
- package/deliver-great-systems/bin/lib/jobs.test.cjs +2619 -0
- package/deliver-great-systems/bin/lib/merge-conflicts.cjs +654 -0
- package/deliver-great-systems/bin/lib/merge-conflicts.test.cjs +370 -0
- package/deliver-great-systems/bin/lib/migration.cjs +352 -0
- package/deliver-great-systems/bin/lib/migration.test.cjs +582 -0
- package/deliver-great-systems/bin/lib/milestone.cjs +243 -0
- package/deliver-great-systems/bin/lib/overlap.cjs +437 -0
- package/deliver-great-systems/bin/lib/overlap.test.cjs +747 -0
- package/deliver-great-systems/bin/lib/path-audit.test.cjs +384 -0
- package/deliver-great-systems/bin/lib/paths.cjs +144 -0
- package/deliver-great-systems/bin/lib/paths.test.cjs +486 -0
- package/deliver-great-systems/bin/lib/phase.cjs +910 -0
- package/deliver-great-systems/bin/lib/projects.cjs +691 -0
- package/deliver-great-systems/bin/lib/projects.test.cjs +871 -0
- package/deliver-great-systems/bin/lib/repos.cjs +1432 -0
- package/deliver-great-systems/bin/lib/repos.test.cjs +1882 -0
- package/deliver-great-systems/bin/lib/roadmap.cjs +305 -0
- package/deliver-great-systems/bin/lib/search.cjs +570 -0
- package/deliver-great-systems/bin/lib/specs.cjs +1303 -0
- package/deliver-great-systems/bin/lib/state.cjs +893 -0
- package/deliver-great-systems/bin/lib/template.cjs +228 -0
- package/deliver-great-systems/bin/lib/test-helpers.cjs +291 -0
- package/deliver-great-systems/bin/lib/verify.cjs +796 -0
- package/deliver-great-systems/references/checkpoints.md +776 -0
- package/deliver-great-systems/references/conflict-resolution.md +66 -0
- package/deliver-great-systems/references/context-tiers.md +166 -0
- package/deliver-great-systems/references/continuation-format.md +249 -0
- package/deliver-great-systems/references/decimal-phase-calculation.md +67 -0
- package/deliver-great-systems/references/git-integration.md +250 -0
- package/deliver-great-systems/references/git-planning-commit.md +40 -0
- package/deliver-great-systems/references/model-profile-resolution.md +36 -0
- package/deliver-great-systems/references/model-profiles.md +95 -0
- package/deliver-great-systems/references/phase-argument-parsing.md +61 -0
- package/deliver-great-systems/references/planning-config.md +224 -0
- package/deliver-great-systems/references/questioning.md +162 -0
- package/deliver-great-systems/references/spec-review-loop.md +177 -0
- package/deliver-great-systems/references/tdd.md +265 -0
- package/deliver-great-systems/references/ui-brand.md +160 -0
- package/deliver-great-systems/references/verification-patterns.md +612 -0
- package/deliver-great-systems/templates/DEBUG.md +166 -0
- package/deliver-great-systems/templates/UAT.md +251 -0
- package/deliver-great-systems/templates/VALIDATION.md +95 -0
- package/deliver-great-systems/templates/claude-md.md +74 -0
- package/deliver-great-systems/templates/codebase/architecture.md +257 -0
- package/deliver-great-systems/templates/codebase/concerns.md +312 -0
- package/deliver-great-systems/templates/codebase/conventions.md +309 -0
- package/deliver-great-systems/templates/codebase/integrations.md +282 -0
- package/deliver-great-systems/templates/codebase/stack.md +188 -0
- package/deliver-great-systems/templates/codebase/structure.md +287 -0
- package/deliver-great-systems/templates/codebase/testing.md +482 -0
- package/deliver-great-systems/templates/config.json +38 -0
- package/deliver-great-systems/templates/context.md +354 -0
- package/deliver-great-systems/templates/continue-here.md +80 -0
- package/deliver-great-systems/templates/debug-subagent-prompt.md +93 -0
- package/deliver-great-systems/templates/discovery.md +148 -0
- package/deliver-great-systems/templates/milestone-archive.md +125 -0
- package/deliver-great-systems/templates/milestone.md +117 -0
- package/deliver-great-systems/templates/phase-prompt.md +615 -0
- package/deliver-great-systems/templates/planner-subagent-prompt.md +119 -0
- package/deliver-great-systems/templates/project.md +186 -0
- package/deliver-great-systems/templates/requirements.md +233 -0
- package/deliver-great-systems/templates/research-project/ARCHITECTURE.md +206 -0
- package/deliver-great-systems/templates/research-project/FEATURES.md +149 -0
- package/deliver-great-systems/templates/research-project/PITFALLS.md +202 -0
- package/deliver-great-systems/templates/research-project/STACK.md +122 -0
- package/deliver-great-systems/templates/research-project/SUMMARY.md +172 -0
- package/deliver-great-systems/templates/research.md +554 -0
- package/deliver-great-systems/templates/retrospective.md +54 -0
- package/deliver-great-systems/templates/roadmap.md +204 -0
- package/deliver-great-systems/templates/state.md +178 -0
- package/deliver-great-systems/templates/summary-complex.md +59 -0
- package/deliver-great-systems/templates/summary-minimal.md +41 -0
- package/deliver-great-systems/templates/summary-standard.md +48 -0
- package/deliver-great-systems/templates/summary.md +253 -0
- package/deliver-great-systems/templates/user-setup.md +313 -0
- package/deliver-great-systems/templates/verification-report.md +324 -0
- package/deliver-great-systems/workflows/add-doc.md +151 -0
- package/deliver-great-systems/workflows/add-idea.md +96 -0
- package/deliver-great-systems/workflows/add-phase.md +120 -0
- package/deliver-great-systems/workflows/add-tests.md +359 -0
- package/deliver-great-systems/workflows/add-todo.md +162 -0
- package/deliver-great-systems/workflows/approve-spec.md +194 -0
- package/deliver-great-systems/workflows/audit-milestone.md +364 -0
- package/deliver-great-systems/workflows/audit-phase.md +462 -0
- package/deliver-great-systems/workflows/cancel-job.md +108 -0
- package/deliver-great-systems/workflows/check-todos.md +181 -0
- package/deliver-great-systems/workflows/cleanup.md +247 -0
- package/deliver-great-systems/workflows/codereview.md +526 -0
- package/deliver-great-systems/workflows/complete-milestone.md +1298 -0
- package/deliver-great-systems/workflows/consolidate-ideas.md +365 -0
- package/deliver-great-systems/workflows/create-milestone-job.md +177 -0
- package/deliver-great-systems/workflows/develop-idea.md +544 -0
- package/deliver-great-systems/workflows/diagnose-issues.md +231 -0
- package/deliver-great-systems/workflows/discovery-phase.md +301 -0
- package/deliver-great-systems/workflows/discuss-idea.md +263 -0
- package/deliver-great-systems/workflows/discuss-phase.md +733 -0
- package/deliver-great-systems/workflows/execute-phase.md +571 -0
- package/deliver-great-systems/workflows/execute-plan.md +592 -0
- package/deliver-great-systems/workflows/find-related-ideas.md +271 -0
- package/deliver-great-systems/workflows/health.md +173 -0
- package/deliver-great-systems/workflows/help.md +997 -0
- package/deliver-great-systems/workflows/import-spec.md +381 -0
- package/deliver-great-systems/workflows/init-product.md +767 -0
- package/deliver-great-systems/workflows/insert-phase.md +138 -0
- package/deliver-great-systems/workflows/list-docs.md +119 -0
- package/deliver-great-systems/workflows/list-ideas.md +154 -0
- package/deliver-great-systems/workflows/list-jobs.md +89 -0
- package/deliver-great-systems/workflows/list-phase-assumptions.md +192 -0
- package/deliver-great-systems/workflows/list-specs.md +101 -0
- package/deliver-great-systems/workflows/map-codebase.md +621 -0
- package/deliver-great-systems/workflows/new-milestone.md +591 -0
- package/deliver-great-systems/workflows/new-project.md +1113 -0
- package/deliver-great-systems/workflows/node-repair.md +94 -0
- package/deliver-great-systems/workflows/overlap-check.md +86 -0
- package/deliver-great-systems/workflows/pause-work.md +134 -0
- package/deliver-great-systems/workflows/plan-milestone-gaps.md +306 -0
- package/deliver-great-systems/workflows/plan-phase.md +698 -0
- package/deliver-great-systems/workflows/progress.md +386 -0
- package/deliver-great-systems/workflows/quick.md +845 -0
- package/deliver-great-systems/workflows/refine-spec.md +275 -0
- package/deliver-great-systems/workflows/reject-idea.md +109 -0
- package/deliver-great-systems/workflows/remove-doc.md +117 -0
- package/deliver-great-systems/workflows/remove-phase.md +163 -0
- package/deliver-great-systems/workflows/research-idea.md +325 -0
- package/deliver-great-systems/workflows/research-phase.md +81 -0
- package/deliver-great-systems/workflows/restore-idea.md +101 -0
- package/deliver-great-systems/workflows/resume-project.md +311 -0
- package/deliver-great-systems/workflows/rollback-job.md +130 -0
- package/deliver-great-systems/workflows/run-job.md +498 -0
- package/deliver-great-systems/workflows/search.md +130 -0
- package/deliver-great-systems/workflows/set-profile.md +83 -0
- package/deliver-great-systems/workflows/settings.md +470 -0
- package/deliver-great-systems/workflows/transition.md +563 -0
- package/deliver-great-systems/workflows/undo-consolidation.md +155 -0
- package/deliver-great-systems/workflows/update-idea.md +157 -0
- package/deliver-great-systems/workflows/update.md +242 -0
- package/deliver-great-systems/workflows/validate-phase.md +177 -0
- package/deliver-great-systems/workflows/verify-phase.md +253 -0
- package/deliver-great-systems/workflows/verify-work.md +671 -0
- package/deliver-great-systems/workflows/write-spec.md +450 -0
- package/hooks/dist/dgs-check-update.js +62 -0
- package/hooks/dist/dgs-context-monitor.js +141 -0
- package/hooks/dist/dgs-statusline.js +115 -0
- package/package.json +60 -0
- package/scripts/build-hooks.js +43 -0
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
<purpose>
|
|
2
|
+
Draft a structured PRD spec from pending ideas, send through cross-LLM review, and finalize. Supports interactive mode (collaborative drafting with user) and auto mode (idea IDs required, no interaction). Covers the full spec lifecycle: idea selection, PRD generation, review loop, and finalization.
|
|
3
|
+
</purpose>
|
|
4
|
+
|
|
5
|
+
<context_tier>planning</context_tier>
|
|
6
|
+
|
|
7
|
+
<required_reading>
|
|
8
|
+
Read all files referenced by the invoking prompt's execution_context before starting.
|
|
9
|
+
</required_reading>
|
|
10
|
+
|
|
11
|
+
<process>
|
|
12
|
+
|
|
13
|
+
<step name="initialize" priority="first">
|
|
14
|
+
Load planning context:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
INIT=$(node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs init milestone-op)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Extract: `project_root` as needed by the workflow.
|
|
21
|
+
|
|
22
|
+
Load planning-tier context files:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
TIER_FILES=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" context load-tier planning --raw 2>/dev/null)
|
|
26
|
+
```
|
|
27
|
+
</step>
|
|
28
|
+
|
|
29
|
+
<step name="parse_arguments">
|
|
30
|
+
Check `$ARGUMENTS` for flags and positional arguments.
|
|
31
|
+
|
|
32
|
+
- If `--auto` detected: set `mode = auto`
|
|
33
|
+
- Otherwise: set `mode = interactive`
|
|
34
|
+
- Extract positional numbers as `selected_ids` (e.g., `1 3 5` from `/dgs:write-spec 1 3 5 --auto`)
|
|
35
|
+
|
|
36
|
+
Examples:
|
|
37
|
+
- `/dgs:write-spec` -> interactive mode, no pre-selected ideas
|
|
38
|
+
- `/dgs:write-spec 1 3` -> interactive mode, ideas 1 and 3 pre-selected
|
|
39
|
+
- `/dgs:write-spec 1 3 --auto` -> auto mode, ideas 1 and 3
|
|
40
|
+
</step>
|
|
41
|
+
|
|
42
|
+
<step name="load_ideas">
|
|
43
|
+
Fetch pending ideas:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs ideas list --state pending --orphan-check
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Parse JSON result for `ideas` array and `counts`.
|
|
50
|
+
|
|
51
|
+
If no pending ideas exist:
|
|
52
|
+
```
|
|
53
|
+
No pending ideas found. Run /dgs:add-idea to capture ideas first.
|
|
54
|
+
```
|
|
55
|
+
Stop execution.
|
|
56
|
+
</step>
|
|
57
|
+
|
|
58
|
+
<step name="select_ideas">
|
|
59
|
+
**If `selected_ids` provided from args:**
|
|
60
|
+
- Filter the loaded ideas to those matching the provided IDs.
|
|
61
|
+
- Validate each ID exists and is in pending state. Error if any ID not found.
|
|
62
|
+
|
|
63
|
+
**If `mode = interactive` and no IDs provided:**
|
|
64
|
+
- Display pending ideas in a numbered list:
|
|
65
|
+
```
|
|
66
|
+
## Pending Ideas
|
|
67
|
+
|
|
68
|
+
| # | ID | Title | Tags |
|
|
69
|
+
|---|-----|-------|------|
|
|
70
|
+
| 1 | 001 | Auto review reminders | automation, reviews |
|
|
71
|
+
| 2 | 003 | Dashboard analytics | analytics, ui |
|
|
72
|
+
```
|
|
73
|
+
- Use AskUserQuestion: "Which ideas should this spec cover? (enter numbers, comma-separated, e.g. 1,3,5)"
|
|
74
|
+
- Parse response into selected idea IDs.
|
|
75
|
+
|
|
76
|
+
**If `mode = auto` and no IDs provided:**
|
|
77
|
+
- Error: "Auto mode requires idea IDs as arguments. Usage: /dgs:write-spec 1 3 --auto"
|
|
78
|
+
- Stop execution.
|
|
79
|
+
|
|
80
|
+
**Bundle size warning (interactive mode only):**
|
|
81
|
+
If more than 5 ideas selected, warn:
|
|
82
|
+
```
|
|
83
|
+
You selected N ideas. Specs with more than 5 source ideas tend to be too broad. Continue? (yes/no)
|
|
84
|
+
```
|
|
85
|
+
Use AskUserQuestion. If "no", return to selection.
|
|
86
|
+
|
|
87
|
+
**Read full content** of each selected idea file for use in PRD generation.
|
|
88
|
+
|
|
89
|
+
**Load enrichment context** for each selected idea:
|
|
90
|
+
|
|
91
|
+
For each selected idea, after reading its full content:
|
|
92
|
+
a. Check if the idea file contains a `## Discussion Log` section. If so, extract that section content as discussion context. Count the number of `### ` entries within it as `discussion_session_count`.
|
|
93
|
+
b. Check if the idea file contains a `## Research Log` section. If so, extract that section content as research context. Count the number of `### ` entries within it as `research_run_count`. Also look for `**Document:**` references in the Research Log entries.
|
|
94
|
+
c. For each `**Document:**` path found (the value after the `**Document:**` label), use the Read tool to load the full research document. The detailed comparison tables and feasibility analysis in research documents produce a richer PRD. If the research document does not exist on disk, skip it gracefully (no error).
|
|
95
|
+
d. Store the enrichment context (discussion content, research content, research documents) per idea for use in the `clarify_and_draft` step.
|
|
96
|
+
|
|
97
|
+
If none of the selected ideas have a Discussion Log or Research Log section, display:
|
|
98
|
+
```
|
|
99
|
+
Tip: Run /dgs:develop-idea first to discuss and research ideas for a richer spec.
|
|
100
|
+
```
|
|
101
|
+
Then proceed normally. Only show this tip when ALL selected ideas lack enrichment. If at least one idea has enrichment, skip the tip.
|
|
102
|
+
|
|
103
|
+
**Load supporting documents** from each selected idea's `docs/` directory:
|
|
104
|
+
|
|
105
|
+
For each selected idea:
|
|
106
|
+
a. Derive the idea's docs path: `${project_root}/ideas/pending/{idea_slug}/docs/` where `idea_slug` is derived from the idea filename (strip numeric prefix and .md suffix, e.g., `005-retry-logic.md` -> `retry-logic`).
|
|
107
|
+
Alternative path: check if ideas use a flat structure where docs are at `${project_root}/docs/ideas/pending/{slug}-*.md`.
|
|
108
|
+
b. If the docs/ directory exists, list all files in it:
|
|
109
|
+
```bash
|
|
110
|
+
ls "${IDEA_DOCS_DIR}/" 2>/dev/null
|
|
111
|
+
```
|
|
112
|
+
c. For each file found:
|
|
113
|
+
- **Text files** (.md, .txt, .json, .yaml, .yml): Read using the Read tool and store as idea doc context.
|
|
114
|
+
- **Image files** (.png, .jpg, .jpeg, .gif, .svg, .webp): Read using the Read tool directly -- Claude can process these as multimodal input. Cap at 5 images per idea to manage context size.
|
|
115
|
+
- **PDF files** (.pdf): Check for a `.txt` sidecar first (e.g., `report.pdf` -> `report.txt`). If sidecar exists, read the sidecar. If no sidecar, read up to 5 pages of the PDF directly using the Read tool with pages parameter.
|
|
116
|
+
- **Other files**: Skip silently.
|
|
117
|
+
d. If docs/ directory does not exist: silent skip -- no docs is normal.
|
|
118
|
+
e. If any file in docs/ is unreadable: skip silently.
|
|
119
|
+
|
|
120
|
+
Store the loaded doc content per idea. In the `clarify_and_draft` step, use idea docs as additional source material: idea docs are loaded first (source material), then spec docs (refinements).
|
|
121
|
+
|
|
122
|
+
**Check for already-covered ideas:**
|
|
123
|
+
|
|
124
|
+
For each selected idea, check if it appears as a source idea in any approved (final-status) spec:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
APPROVED_SPECS=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" specs list --status final --raw 2>/dev/null || echo '{"specs":[]}')
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
For each approved spec in the JSON result, check its `source_ideas` array. If any selected idea's filename matches a source_idea in an approved spec:
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
Note: The following selected ideas are already covered by approved specs:
|
|
134
|
+
- Idea #{id} "{title}" is a source for spec "{spec_title}" ({spec_filename})
|
|
135
|
+
|
|
136
|
+
These ideas may already be addressed. Proceeding with spec creation.
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Detection uses exact idea ID/filename match only -- only warn if the same idea ID appears as a source in an approved spec. No fuzzy matching.
|
|
140
|
+
|
|
141
|
+
This is a warning only -- do not block spec creation. Proceed normally after displaying the warning.
|
|
142
|
+
</step>
|
|
143
|
+
|
|
144
|
+
<step name="load_codebase_context">
|
|
145
|
+
Read all codebase analysis documents:
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
ls ${project_root}/codebase/*.md 2>/dev/null
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
For each `.md` file found in the codebase directory, read it using the Read tool. This replaces the previous 3-file hardcoded list and ensures all codebase docs (including CONCERNS.md, TESTING.md, INTEGRATIONS.md, CONVENTIONS.md, etc.) are loaded when they exist.
|
|
152
|
+
|
|
153
|
+
If the codebase directory does not exist or contains no `.md` files, proceed without codebase context.
|
|
154
|
+
|
|
155
|
+
These provide context for the Technical Considerations section of the spec.
|
|
156
|
+
|
|
157
|
+
Additionally, load all markdown files from `${project_root}/docs/product/` (if the directory exists) to inform the spec with product-level context such as target architecture and product summary:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
ls ${project_root}/docs/product/*.md 2>/dev/null
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Read each markdown file found. These provide product-level context (target architecture, product summary, design guidelines, etc.) that should inform Problem, Goals, Requirements, and Technical Considerations sections of the spec. If the directory does not exist or contains no markdown files, proceed without it.
|
|
164
|
+
</step>
|
|
165
|
+
|
|
166
|
+
<step name="clarify_and_draft">
|
|
167
|
+
Generate the PRD spec using selected idea content and codebase context.
|
|
168
|
+
|
|
169
|
+
**Interactive mode:**
|
|
170
|
+
Before writing each major section, Claude may ask the user clarifying questions via AskUserQuestion to fill gaps in the idea descriptions. For example:
|
|
171
|
+
- "The idea mentions 'auto-review' -- should this cover only automated code reviews or also manual review reminders?"
|
|
172
|
+
- "Any specific metrics you care about for Success Metrics?"
|
|
173
|
+
|
|
174
|
+
Use judgment on which sections need clarification vs. can be inferred from the idea text.
|
|
175
|
+
|
|
176
|
+
**Auto mode:**
|
|
177
|
+
Generate all sections without asking clarifying questions. Infer missing details from the idea text and codebase context.
|
|
178
|
+
|
|
179
|
+
**The spec body MUST include all these sections in order:**
|
|
180
|
+
|
|
181
|
+
1. `## Problem` -- synthesized from idea problem statements
|
|
182
|
+
2. `## Goals` -- concrete goals derived from ideas
|
|
183
|
+
3. `## Non-Goals` -- explicit boundaries (important for review auto-rejection)
|
|
184
|
+
4. `## User Stories` -- "As a [user], I want [X] so that [Y]" format
|
|
185
|
+
5. `## Requirements` with subsections:
|
|
186
|
+
- `### P0 (Must Have)`
|
|
187
|
+
- `### P1 (Should Have)`
|
|
188
|
+
- `### P2 (Nice to Have)`
|
|
189
|
+
6. `## Success Metrics` -- measurable outcomes
|
|
190
|
+
7. `## Open Questions` -- unknowns to resolve
|
|
191
|
+
8. `## Technical Considerations` -- informed by codebase analysis
|
|
192
|
+
9. `## Review History` -- empty initially, populated by review loop
|
|
193
|
+
|
|
194
|
+
**Enrichment Context (when available):**
|
|
195
|
+
|
|
196
|
+
If selected ideas have Discussion Log and/or Research Log content:
|
|
197
|
+
- Weave discussion insights naturally into Problem, Goals, and Requirements sections
|
|
198
|
+
- Use research findings to inform Technical Considerations and identify implementation approaches
|
|
199
|
+
- Discussion decisions should be reflected as requirements (P0 or P1) unless there's good reason to diverge
|
|
200
|
+
- Research recommendations inform Technical Considerations but are not automatically locked decisions
|
|
201
|
+
- If discussion and research findings contradict each other, flag the conflict explicitly in Open Questions and note both positions
|
|
202
|
+
- Add a metadata line at the bottom of the PRD body: `Informed by: Discussion (N sessions), Research (N runs)` with actual counts from the enrichment data. Omit this line entirely if no enrichment was available
|
|
203
|
+
|
|
204
|
+
Generate a title for the spec that captures the overall scope of the selected ideas.
|
|
205
|
+
|
|
206
|
+
Set `title`, `body` (the full PRD markdown), and `source_ideas` (list of idea filenames like "001-slug.md").
|
|
207
|
+
</step>
|
|
208
|
+
|
|
209
|
+
<step name="save_draft">
|
|
210
|
+
Save the draft spec via dgs-tools:
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs specs create --title "$title" --body "$body" --source-ideas "$source_ideas_comma_separated"
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Parse JSON result to get `id`, `filename`, `path`.
|
|
217
|
+
|
|
218
|
+
Add the initial Refinement Log entry:
|
|
219
|
+
```bash
|
|
220
|
+
node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs specs add-log-entry --id "$id" --date "$(date +%Y-%m-%d)" --version "1.0" --action Created --summary "Drafted from ideas $idea_ids via /dgs:write-spec"
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
Commit the draft:
|
|
224
|
+
```bash
|
|
225
|
+
node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs commit "specs: draft $id from ideas $idea_ids" --files ${project_root}/specs/$filename
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Store `SPEC_ID` and `FILENAME` for subsequent steps.
|
|
229
|
+
</step>
|
|
230
|
+
|
|
231
|
+
<step name="auto_search">
|
|
232
|
+
After the draft is saved, run an automatic search to surface related content.
|
|
233
|
+
|
|
234
|
+
**1. Build search query:**
|
|
235
|
+
Use Claude's judgment to extract the best search signal from the spec. Good sources: spec title, key terms from the Problem section, or P0 requirement keywords. Construct a concise search query (2-4 words) that captures the core topic.
|
|
236
|
+
|
|
237
|
+
**2. Run search with tight result cap:**
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs search "QUERY" --max-per-type 3 --include-rejected --raw
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Note: Use `--include-rejected` for auto-search so rejected ideas with similar topics are surfaced (they may have been rejected for good reason -- useful context).
|
|
244
|
+
|
|
245
|
+
**3. Check for matches:**
|
|
246
|
+
Parse JSON result. If `total_matches === 0`: skip display entirely (no empty block). Proceed to review_draft step.
|
|
247
|
+
|
|
248
|
+
**4. Check for duplicate specs:**
|
|
249
|
+
In the specs results, compare each spec title against the current spec title. If a spec with very similar title or overlapping content exists (and it is not the spec just created), flag it:
|
|
250
|
+
```
|
|
251
|
+
Warning: This may overlap with existing spec: "{spec_title}" ({spec_path})
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
**5. Display related content block (only if matches found):**
|
|
255
|
+
|
|
256
|
+
```
|
|
257
|
+
## Related Content Found
|
|
258
|
+
|
|
259
|
+
The following existing content may be relevant to this spec:
|
|
260
|
+
|
|
261
|
+
### Ideas
|
|
262
|
+
- **{title}** -- {one-line snippet}
|
|
263
|
+
|
|
264
|
+
### Specs
|
|
265
|
+
- **{title}** ({status}) -- {one-line snippet}
|
|
266
|
+
|
|
267
|
+
### Documents
|
|
268
|
+
- **{title}** -- {one-line snippet}
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
Only show type sections that have results. No counts header -- go straight to grouped results. Showing top 3 per type.
|
|
272
|
+
|
|
273
|
+
**6. User action (interactive mode only):**
|
|
274
|
+
Use AskUserQuestion: "Review the related content above. Type **continue** to proceed as-is, or **revise** to update the spec based on these findings."
|
|
275
|
+
|
|
276
|
+
If **revise**: Claude applies user-directed changes to the spec, rewrites the file, commits, then returns to this step to re-run search with updated content.
|
|
277
|
+
If **continue** (or auto mode): proceed to review_draft step.
|
|
278
|
+
</step>
|
|
279
|
+
|
|
280
|
+
<step name="review_draft" condition="mode = interactive">
|
|
281
|
+
**Skipped in auto mode.**
|
|
282
|
+
|
|
283
|
+
Display the draft spec content to the user for review.
|
|
284
|
+
|
|
285
|
+
Use AskUserQuestion: "Review the draft spec above. Type **approve** to send to reviewers, or describe changes you'd like."
|
|
286
|
+
|
|
287
|
+
- If **approved**: proceed to Step 9 (run_review_loop).
|
|
288
|
+
- If **changes requested**: Claude applies the requested edits to the spec body, rewrites the file on disk, re-displays the updated spec, and asks for approval again. Loop until approved.
|
|
289
|
+
|
|
290
|
+
After approval, commit any changes:
|
|
291
|
+
```bash
|
|
292
|
+
node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs commit "specs: revise draft $SPEC_ID" --files ${project_root}/specs/$FILENAME
|
|
293
|
+
```
|
|
294
|
+
</step>
|
|
295
|
+
|
|
296
|
+
<step name="run_review_loop">
|
|
297
|
+
Load the review loop reference for detailed mechanics:
|
|
298
|
+
@~/.claude/deliver-great-systems/references/spec-review-loop.md
|
|
299
|
+
|
|
300
|
+
**1. Load review config:**
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs review-config
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
Parse JSON result. If `has_any_key = false`: warn "No review API keys configured. Edit review-keys.json in your planning root to add OpenAI or Gemini keys. Skipping review." and proceed to finalization step.
|
|
307
|
+
|
|
308
|
+
**2. Update spec status to review:**
|
|
309
|
+
|
|
310
|
+
```bash
|
|
311
|
+
node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs specs update-status --id "$SPEC_ID" --status review
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
**3. Initialize tracking:**
|
|
315
|
+
|
|
316
|
+
- `round = 0`
|
|
317
|
+
- `total_tokens = { openai: { prompt: 0, completion: 0 }, gemini: { prompt: 0, completion: 0 } }`
|
|
318
|
+
- `rejected_items_history = []` (for convergence detection across rounds)
|
|
319
|
+
|
|
320
|
+
**4. Loop** (while round < max_rounds):
|
|
321
|
+
|
|
322
|
+
a. Increment round.
|
|
323
|
+
b. Read current spec content from disk (it may have changed from prior round edits).
|
|
324
|
+
c. Send to available reviewers in parallel using the API call patterns from the reference doc. Issue both curl commands via parallel Bash tool calls.
|
|
325
|
+
d. Handle failures per reference doc error handling rules (retry once, then mark failed).
|
|
326
|
+
e. Parse feedback items from each reviewer's response. Each item: section, severity, feedback text, reviewer name.
|
|
327
|
+
f. **Auto-reject Non-Goal contradictions:** read the `## Non-Goals` section, reject any feedback that suggests adding something explicitly listed as a Non-Goal. Disposition: `rejected-non-goal`.
|
|
328
|
+
g. **Check convergence:** compare rejected items against `rejected_items_history`. If an item (or substantially similar item) was rejected in the previous round too, move the concern to `## Open Questions` tagged as "From review: [concern]". Disposition: `moved-to-open-questions`.
|
|
329
|
+
h. **Apply accepted feedback:** Claude reads each remaining item and decides whether to apply it by modifying the spec body. Disposition: `accepted` (with change description) or `no-action` (with reason).
|
|
330
|
+
i. Build round history entry with all dispositions in the review history table format.
|
|
331
|
+
j. Append review history to spec:
|
|
332
|
+
```bash
|
|
333
|
+
node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs specs append-review --id "$SPEC_ID" --entry "$HISTORY_MD"
|
|
334
|
+
```
|
|
335
|
+
k. Update token totals from response usage metadata.
|
|
336
|
+
l. **Check exit conditions:**
|
|
337
|
+
- No changes applied (all items rejected, no-action, or moved-to-open-questions) -> EXIT
|
|
338
|
+
- Green-only (all reviewers responded "LGTM" or no actionable feedback) -> EXIT
|
|
339
|
+
- Max rounds reached -> EXIT
|
|
340
|
+
If none met: continue to next round.
|
|
341
|
+
|
|
342
|
+
**5. Display token/cost summary:**
|
|
343
|
+
|
|
344
|
+
```
|
|
345
|
+
Review complete (N rounds).
|
|
346
|
+
Tokens: OpenAI [X prompt + Y completion] | Gemini [X prompt + Y completion]
|
|
347
|
+
Estimated cost: ~$X.XX
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
**6. Commit updated spec:**
|
|
351
|
+
|
|
352
|
+
```bash
|
|
353
|
+
node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs commit "specs: review $SPEC_ID (N rounds)" --files ${project_root}/specs/$FILENAME
|
|
354
|
+
```
|
|
355
|
+
</step>
|
|
356
|
+
|
|
357
|
+
<step name="finalize">
|
|
358
|
+
|
|
359
|
+
### User Approval (interactive mode only)
|
|
360
|
+
|
|
361
|
+
If `mode = interactive`:
|
|
362
|
+
|
|
363
|
+
1. Display the final spec content to the user (after review loop has completed).
|
|
364
|
+
2. Use AskUserQuestion: "The spec is ready for finalization. Review above and choose:\n- **approve** -- finalize the spec\n- **reject** -- send back for another review round"
|
|
365
|
+
3. If **reject**: go back to Step 9 (run_review_loop) for one more round, then return here.
|
|
366
|
+
4. If **approve**: proceed to finalization.
|
|
367
|
+
|
|
368
|
+
If `mode = auto`: skip approval, proceed directly to finalization.
|
|
369
|
+
|
|
370
|
+
### Execute Finalization
|
|
371
|
+
|
|
372
|
+
1. Finalize the spec via dgs-tools:
|
|
373
|
+
|
|
374
|
+
```bash
|
|
375
|
+
node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs specs finalize --id "$SPEC_ID"
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
Parse JSON result: `{ id, filename, status, ideas_moved, ideas_failed, research_docs_moved }`.
|
|
379
|
+
|
|
380
|
+
2. If any `ideas_failed`: warn user "Note: Some source ideas could not be moved to done: [list]. They may already be in done state or were deleted."
|
|
381
|
+
|
|
382
|
+
3. If any `research_docs_moved`: mention it in the summary: "Research documents moved to done: [list]"
|
|
383
|
+
|
|
384
|
+
4. The finalize command auto-commits. No separate commit needed.
|
|
385
|
+
|
|
386
|
+
### Post-Finalization Routing
|
|
387
|
+
|
|
388
|
+
Display a summary and routing options:
|
|
389
|
+
|
|
390
|
+
```
|
|
391
|
+
Spec finalized: $TITLE
|
|
392
|
+
Status: final
|
|
393
|
+
Source ideas moved to done: $IDEAS_MOVED
|
|
394
|
+
Research documents moved to done: $RESEARCH_DOCS_MOVED (if any)
|
|
395
|
+
|
|
396
|
+
What would you like to do next?
|
|
397
|
+
1. Create a new project from this spec -> /dgs:new-project
|
|
398
|
+
2. Add a milestone to an existing project -> /dgs:new-milestone
|
|
399
|
+
3. Nothing for now -- the spec is saved and ready when you are
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
In interactive mode, use AskUserQuestion: "Choose 1, 2, or 3 (or just press enter to defer):"
|
|
403
|
+
|
|
404
|
+
- If **1**: Tell user "Run `/dgs:new-project` and reference spec `$FILENAME` during project creation."
|
|
405
|
+
- If **2**: Tell user "Run `/dgs:new-milestone` and reference spec `$FILENAME` during milestone creation."
|
|
406
|
+
- If **3** or empty/enter: Output "Spec saved. You can find it at `${project_root}/specs/$FILENAME`."
|
|
407
|
+
|
|
408
|
+
In `--auto` mode: skip the routing question, just output the summary with the three options listed for reference.
|
|
409
|
+
</step>
|
|
410
|
+
|
|
411
|
+
</process>
|
|
412
|
+
|
|
413
|
+
<auto_mode_summary>
|
|
414
|
+
## Auto Mode Flow (`--auto`)
|
|
415
|
+
|
|
416
|
+
When invoked with `--auto` and idea IDs (e.g., `/dgs:write-spec 1 3 --auto`):
|
|
417
|
+
|
|
418
|
+
1. Ideas selected from args (no interactive selection)
|
|
419
|
+
2. PRD drafted without clarifying questions
|
|
420
|
+
3. Draft saved without user review
|
|
421
|
+
4. Auto-search runs and displays related content (no user prompt)
|
|
422
|
+
5. Review loop runs normally (same as interactive)
|
|
423
|
+
6. Spec finalized without user approval
|
|
424
|
+
7. Summary displayed with routing options (no interactive prompt)
|
|
425
|
+
|
|
426
|
+
Auto mode still runs the full review loop -- only user interaction steps are skipped.
|
|
427
|
+
</auto_mode_summary>
|
|
428
|
+
|
|
429
|
+
<success_criteria>
|
|
430
|
+
- [ ] Arguments parsed correctly (idea IDs, --auto flag)
|
|
431
|
+
- [ ] Pending ideas loaded and validated
|
|
432
|
+
- [ ] Idea selection works in both interactive and auto modes
|
|
433
|
+
- [ ] Bundle size warning shown for >5 ideas (interactive only)
|
|
434
|
+
- [ ] Codebase context loaded for Technical Considerations
|
|
435
|
+
- [ ] PRD includes all 9 required sections in order
|
|
436
|
+
- [ ] Draft saved via specs create with correct source_ideas
|
|
437
|
+
- [ ] Draft committed to git
|
|
438
|
+
- [ ] Auto-search surfaces related content after draft save
|
|
439
|
+
- [ ] Auto-search only displays when matches found (no empty block)
|
|
440
|
+
- [ ] Auto-search flags potential duplicate specs
|
|
441
|
+
- [ ] Draft review loop works in interactive mode (approve/edit cycle)
|
|
442
|
+
- [ ] Review loop sends to configured reviewers and processes feedback
|
|
443
|
+
- [ ] Enrichment context loaded from Discussion Log, Research Log, and linked research documents
|
|
444
|
+
- [ ] Enrichment tip shown only when all selected ideas lack enrichment
|
|
445
|
+
- [ ] PRD metadata line shows enrichment source counts when available
|
|
446
|
+
- [ ] Finalization sets status to final
|
|
447
|
+
- [ ] Source ideas moved to done
|
|
448
|
+
- [ ] Research documents moved to done alongside ideas
|
|
449
|
+
- [ ] Post-finalization routing options presented
|
|
450
|
+
</success_criteria>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Check for DGS updates in background, write result to cache
|
|
3
|
+
// Called by SessionStart hook - runs once per session
|
|
4
|
+
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const os = require('os');
|
|
8
|
+
const { spawn } = require('child_process');
|
|
9
|
+
|
|
10
|
+
const homeDir = os.homedir();
|
|
11
|
+
const cwd = process.cwd();
|
|
12
|
+
const cacheDir = path.join(homeDir, '.claude', 'cache');
|
|
13
|
+
const cacheFile = path.join(cacheDir, 'dgs-update-check.json');
|
|
14
|
+
|
|
15
|
+
// VERSION file locations (check project first, then global)
|
|
16
|
+
const projectVersionFile = path.join(cwd, '.claude', 'deliver-great-systems', 'VERSION');
|
|
17
|
+
const globalVersionFile = path.join(homeDir, '.claude', 'deliver-great-systems', 'VERSION');
|
|
18
|
+
|
|
19
|
+
// Ensure cache directory exists
|
|
20
|
+
if (!fs.existsSync(cacheDir)) {
|
|
21
|
+
fs.mkdirSync(cacheDir, { recursive: true });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Run check in background (spawn background process, windowsHide prevents console flash)
|
|
25
|
+
const child = spawn(process.execPath, ['-e', `
|
|
26
|
+
const fs = require('fs');
|
|
27
|
+
const { execSync } = require('child_process');
|
|
28
|
+
|
|
29
|
+
const cacheFile = ${JSON.stringify(cacheFile)};
|
|
30
|
+
const projectVersionFile = ${JSON.stringify(projectVersionFile)};
|
|
31
|
+
const globalVersionFile = ${JSON.stringify(globalVersionFile)};
|
|
32
|
+
|
|
33
|
+
// Check project directory first (local install), then global
|
|
34
|
+
let installed = '0.0.0';
|
|
35
|
+
try {
|
|
36
|
+
if (fs.existsSync(projectVersionFile)) {
|
|
37
|
+
installed = fs.readFileSync(projectVersionFile, 'utf8').trim();
|
|
38
|
+
} else if (fs.existsSync(globalVersionFile)) {
|
|
39
|
+
installed = fs.readFileSync(globalVersionFile, 'utf8').trim();
|
|
40
|
+
}
|
|
41
|
+
} catch (e) {}
|
|
42
|
+
|
|
43
|
+
let latest = null;
|
|
44
|
+
try {
|
|
45
|
+
latest = execSync('npm view @ktpartners/dgs-platform version', { encoding: 'utf8', timeout: 10000, windowsHide: true }).trim();
|
|
46
|
+
} catch (e) {}
|
|
47
|
+
|
|
48
|
+
const result = {
|
|
49
|
+
update_available: latest && installed !== latest,
|
|
50
|
+
installed,
|
|
51
|
+
latest: latest || 'unknown',
|
|
52
|
+
checked: Math.floor(Date.now() / 1000)
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
fs.writeFileSync(cacheFile, JSON.stringify(result));
|
|
56
|
+
`], {
|
|
57
|
+
stdio: 'ignore',
|
|
58
|
+
windowsHide: true,
|
|
59
|
+
detached: true // Required on Windows for proper process detachment
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
child.unref();
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Context Monitor - PostToolUse/AfterTool hook (Gemini uses AfterTool)
|
|
3
|
+
// Reads context metrics from the statusline bridge file and injects
|
|
4
|
+
// warnings when context usage is high. This makes the AGENT aware of
|
|
5
|
+
// context limits (the statusline only shows the user).
|
|
6
|
+
//
|
|
7
|
+
// How it works:
|
|
8
|
+
// 1. The statusline hook writes metrics to /tmp/claude-ctx-{session_id}.json
|
|
9
|
+
// 2. This hook reads those metrics after each tool use
|
|
10
|
+
// 3. When remaining context drops below thresholds, it injects a warning
|
|
11
|
+
// as additionalContext, which the agent sees in its conversation
|
|
12
|
+
//
|
|
13
|
+
// Thresholds:
|
|
14
|
+
// WARNING (remaining <= 35%): Agent should wrap up current task
|
|
15
|
+
// CRITICAL (remaining <= 25%): Agent should stop immediately and save state
|
|
16
|
+
//
|
|
17
|
+
// Debounce: 5 tool uses between warnings to avoid spam
|
|
18
|
+
// Severity escalation bypasses debounce (WARNING -> CRITICAL fires immediately)
|
|
19
|
+
|
|
20
|
+
const fs = require('fs');
|
|
21
|
+
const os = require('os');
|
|
22
|
+
const path = require('path');
|
|
23
|
+
|
|
24
|
+
const WARNING_THRESHOLD = 35; // remaining_percentage <= 35%
|
|
25
|
+
const CRITICAL_THRESHOLD = 25; // remaining_percentage <= 25%
|
|
26
|
+
const STALE_SECONDS = 60; // ignore metrics older than 60s
|
|
27
|
+
const DEBOUNCE_CALLS = 5; // min tool uses between warnings
|
|
28
|
+
|
|
29
|
+
let input = '';
|
|
30
|
+
// Timeout guard: if stdin doesn't close within 3s (e.g. pipe issues on
|
|
31
|
+
// Windows/Git Bash), exit silently instead of hanging until Claude Code
|
|
32
|
+
// kills the process and reports "hook error". See #775.
|
|
33
|
+
const stdinTimeout = setTimeout(() => process.exit(0), 3000);
|
|
34
|
+
process.stdin.setEncoding('utf8');
|
|
35
|
+
process.stdin.on('data', chunk => input += chunk);
|
|
36
|
+
process.stdin.on('end', () => {
|
|
37
|
+
clearTimeout(stdinTimeout);
|
|
38
|
+
try {
|
|
39
|
+
const data = JSON.parse(input);
|
|
40
|
+
const sessionId = data.session_id;
|
|
41
|
+
|
|
42
|
+
if (!sessionId) {
|
|
43
|
+
process.exit(0);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const tmpDir = os.tmpdir();
|
|
47
|
+
const metricsPath = path.join(tmpDir, `claude-ctx-${sessionId}.json`);
|
|
48
|
+
|
|
49
|
+
// If no metrics file, this is a subagent or fresh session -- exit silently
|
|
50
|
+
if (!fs.existsSync(metricsPath)) {
|
|
51
|
+
process.exit(0);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const metrics = JSON.parse(fs.readFileSync(metricsPath, 'utf8'));
|
|
55
|
+
const now = Math.floor(Date.now() / 1000);
|
|
56
|
+
|
|
57
|
+
// Ignore stale metrics
|
|
58
|
+
if (metrics.timestamp && (now - metrics.timestamp) > STALE_SECONDS) {
|
|
59
|
+
process.exit(0);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const remaining = metrics.remaining_percentage;
|
|
63
|
+
const usedPct = metrics.used_pct;
|
|
64
|
+
|
|
65
|
+
// No warning needed
|
|
66
|
+
if (remaining > WARNING_THRESHOLD) {
|
|
67
|
+
process.exit(0);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Debounce: check if we warned recently
|
|
71
|
+
const warnPath = path.join(tmpDir, `claude-ctx-${sessionId}-warned.json`);
|
|
72
|
+
let warnData = { callsSinceWarn: 0, lastLevel: null };
|
|
73
|
+
let firstWarn = true;
|
|
74
|
+
|
|
75
|
+
if (fs.existsSync(warnPath)) {
|
|
76
|
+
try {
|
|
77
|
+
warnData = JSON.parse(fs.readFileSync(warnPath, 'utf8'));
|
|
78
|
+
firstWarn = false;
|
|
79
|
+
} catch (e) {
|
|
80
|
+
// Corrupted file, reset
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
warnData.callsSinceWarn = (warnData.callsSinceWarn || 0) + 1;
|
|
85
|
+
|
|
86
|
+
const isCritical = remaining <= CRITICAL_THRESHOLD;
|
|
87
|
+
const currentLevel = isCritical ? 'critical' : 'warning';
|
|
88
|
+
|
|
89
|
+
// Emit immediately on first warning, then debounce subsequent ones
|
|
90
|
+
// Severity escalation (WARNING -> CRITICAL) bypasses debounce
|
|
91
|
+
const severityEscalated = currentLevel === 'critical' && warnData.lastLevel === 'warning';
|
|
92
|
+
if (!firstWarn && warnData.callsSinceWarn < DEBOUNCE_CALLS && !severityEscalated) {
|
|
93
|
+
// Update counter and exit without warning
|
|
94
|
+
fs.writeFileSync(warnPath, JSON.stringify(warnData));
|
|
95
|
+
process.exit(0);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Reset debounce counter
|
|
99
|
+
warnData.callsSinceWarn = 0;
|
|
100
|
+
warnData.lastLevel = currentLevel;
|
|
101
|
+
fs.writeFileSync(warnPath, JSON.stringify(warnData));
|
|
102
|
+
|
|
103
|
+
// Detect if DGS is active (has .planning/STATE.md in working directory)
|
|
104
|
+
const cwd = data.cwd || process.cwd();
|
|
105
|
+
const isDgsActive = fs.existsSync(path.join(cwd, '.planning', 'STATE.md'));
|
|
106
|
+
|
|
107
|
+
// Build advisory warning message (never use imperative commands that
|
|
108
|
+
// override user preferences — see #884)
|
|
109
|
+
let message;
|
|
110
|
+
if (isCritical) {
|
|
111
|
+
message = isDgsActive
|
|
112
|
+
? `CONTEXT CRITICAL: Usage at ${usedPct}%. Remaining: ${remaining}%. ` +
|
|
113
|
+
'Context is nearly exhausted. Do NOT start new complex work or write handoff files — ' +
|
|
114
|
+
'DGS state is already tracked in STATE.md. Inform the user so they can run ' +
|
|
115
|
+
'/dgs:pause-work at the next natural stopping point.'
|
|
116
|
+
: `CONTEXT CRITICAL: Usage at ${usedPct}%. Remaining: ${remaining}%. ` +
|
|
117
|
+
'Context is nearly exhausted. Inform the user that context is low and ask how they ' +
|
|
118
|
+
'want to proceed. Do NOT autonomously save state or write handoff files unless the user asks.';
|
|
119
|
+
} else {
|
|
120
|
+
message = isDgsActive
|
|
121
|
+
? `CONTEXT WARNING: Usage at ${usedPct}%. Remaining: ${remaining}%. ` +
|
|
122
|
+
'Context is getting limited. Avoid starting new complex work. If not between ' +
|
|
123
|
+
'defined plan steps, inform the user so they can prepare to pause.'
|
|
124
|
+
: `CONTEXT WARNING: Usage at ${usedPct}%. Remaining: ${remaining}%. ` +
|
|
125
|
+
'Be aware that context is getting limited. Avoid unnecessary exploration or ' +
|
|
126
|
+
'starting new complex work.';
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const output = {
|
|
130
|
+
hookSpecificOutput: {
|
|
131
|
+
hookEventName: process.env.GEMINI_API_KEY ? "AfterTool" : "PostToolUse",
|
|
132
|
+
additionalContext: message
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
process.stdout.write(JSON.stringify(output));
|
|
137
|
+
} catch (e) {
|
|
138
|
+
// Silent fail -- never block tool execution
|
|
139
|
+
process.exit(0);
|
|
140
|
+
}
|
|
141
|
+
});
|