safeword 0.2.3 → 0.2.4
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/.claude/commands/arch-review.md +32 -0
- package/.claude/commands/lint.md +6 -0
- package/.claude/commands/quality-review.md +13 -0
- package/.claude/commands/setup-linting.md +6 -0
- package/.claude/hooks/auto-lint.sh +6 -0
- package/.claude/hooks/auto-quality-review.sh +170 -0
- package/.claude/hooks/check-linting-sync.sh +17 -0
- package/.claude/hooks/inject-timestamp.sh +6 -0
- package/.claude/hooks/question-protocol.sh +12 -0
- package/.claude/hooks/run-linters.sh +8 -0
- package/.claude/hooks/run-quality-review.sh +76 -0
- package/.claude/hooks/version-check.sh +10 -0
- package/.claude/mcp/README.md +96 -0
- package/.claude/mcp/arcade.sample.json +9 -0
- package/.claude/mcp/context7.sample.json +7 -0
- package/.claude/mcp/playwright.sample.json +7 -0
- package/.claude/settings.json +62 -0
- package/.claude/skills/quality-reviewer/SKILL.md +190 -0
- package/.claude/skills/safeword-quality-reviewer/SKILL.md +13 -0
- package/.env.arcade.example +4 -0
- package/.env.example +11 -0
- package/.gitmodules +4 -0
- package/.safeword/SAFEWORD.md +33 -0
- package/.safeword/eslint/eslint-base.mjs +101 -0
- package/.safeword/guides/architecture-guide.md +404 -0
- package/.safeword/guides/code-philosophy.md +174 -0
- package/.safeword/guides/context-files-guide.md +405 -0
- package/.safeword/guides/data-architecture-guide.md +183 -0
- package/.safeword/guides/design-doc-guide.md +165 -0
- package/.safeword/guides/learning-extraction.md +515 -0
- package/.safeword/guides/llm-instruction-design.md +239 -0
- package/.safeword/guides/llm-prompting.md +95 -0
- package/.safeword/guides/tdd-best-practices.md +570 -0
- package/.safeword/guides/test-definitions-guide.md +243 -0
- package/.safeword/guides/testing-methodology.md +573 -0
- package/.safeword/guides/user-story-guide.md +237 -0
- package/.safeword/guides/zombie-process-cleanup.md +214 -0
- package/{templates → .safeword}/hooks/agents-md-check.sh +0 -0
- package/{templates → .safeword}/hooks/post-tool.sh +0 -0
- package/{templates → .safeword}/hooks/pre-commit.sh +0 -0
- package/.safeword/planning/002-user-story-quality-evaluation.md +1840 -0
- package/.safeword/planning/003-langsmith-eval-setup-prompt.md +363 -0
- package/.safeword/planning/004-llm-eval-test-cases.md +3226 -0
- package/.safeword/planning/005-architecture-enforcement-system.md +169 -0
- package/.safeword/planning/006-reactive-fix-prevention-research.md +135 -0
- package/.safeword/planning/011-cli-ux-vision.md +330 -0
- package/.safeword/planning/012-project-structure-cleanup.md +154 -0
- package/.safeword/planning/README.md +39 -0
- package/.safeword/planning/automation-plan-v2.md +1225 -0
- package/.safeword/planning/automation-plan-v3.md +1291 -0
- package/.safeword/planning/automation-plan.md +3058 -0
- package/.safeword/planning/design/005-cli-implementation.md +343 -0
- package/.safeword/planning/design/013-cli-self-contained-templates.md +596 -0
- package/.safeword/planning/design/013a-eslint-plugin-suite.md +256 -0
- package/.safeword/planning/design/013b-implementation-snippets.md +385 -0
- package/.safeword/planning/design/013c-config-isolation-strategy.md +242 -0
- package/.safeword/planning/design/code-philosophy-improvements.md +60 -0
- package/.safeword/planning/mcp-analysis.md +545 -0
- package/.safeword/planning/phase2-subagents-vs-skills-analysis.md +451 -0
- package/.safeword/planning/settings-improvements.md +970 -0
- package/.safeword/planning/test-definitions/005-cli-implementation.md +1301 -0
- package/.safeword/planning/test-definitions/cli-self-contained-templates.md +205 -0
- package/.safeword/planning/user-stories/001-guides-review-user-stories.md +1381 -0
- package/.safeword/planning/user-stories/003-reactive-fix-prevention.md +132 -0
- package/.safeword/planning/user-stories/004-technical-constraints.md +86 -0
- package/.safeword/planning/user-stories/005-cli-implementation.md +311 -0
- package/.safeword/planning/user-stories/cli-self-contained-templates.md +172 -0
- package/.safeword/planning/versioned-distribution.md +740 -0
- package/.safeword/prompts/arch-review.md +43 -0
- package/.safeword/prompts/quality-review.md +11 -0
- package/.safeword/scripts/arch-review.sh +235 -0
- package/.safeword/scripts/check-linting-sync.sh +58 -0
- package/.safeword/scripts/setup-linting.sh +559 -0
- package/.safeword/templates/architecture-template.md +136 -0
- package/.safeword/templates/ci/architecture-check.yml +79 -0
- package/.safeword/templates/design-doc-template.md +127 -0
- package/.safeword/templates/test-definitions-feature.md +100 -0
- package/.safeword/templates/ticket-template.md +74 -0
- package/.safeword/templates/user-stories-template.md +82 -0
- package/.safeword/tickets/001-guides-review-user-stories.md +83 -0
- package/.safeword/tickets/002-architecture-enforcement.md +211 -0
- package/.safeword/tickets/003-reactive-fix-prevention.md +57 -0
- package/.safeword/tickets/004-technical-constraints-in-user-stories.md +39 -0
- package/.safeword/tickets/005-cli-implementation.md +248 -0
- package/.safeword/tickets/006-flesh-out-skills.md +43 -0
- package/.safeword/tickets/007-flesh-out-questioning.md +44 -0
- package/.safeword/tickets/008-upgrade-questioning.md +58 -0
- package/.safeword/tickets/009-naming-conventions.md +41 -0
- package/.safeword/tickets/010-safeword-md-cleanup.md +34 -0
- package/.safeword/tickets/011-cursor-setup.md +86 -0
- package/.safeword/tickets/README.md +73 -0
- package/.safeword/version +1 -0
- package/AGENTS.md +59 -0
- package/CLAUDE.md +12 -0
- package/README.md +347 -0
- package/docs/001-cli-implementation-plan.md +856 -0
- package/docs/elite-dx-implementation-plan.md +1034 -0
- package/framework/README.md +131 -0
- package/framework/mcp/README.md +96 -0
- package/framework/mcp/arcade.sample.json +8 -0
- package/framework/mcp/context7.sample.json +6 -0
- package/framework/mcp/playwright.sample.json +6 -0
- package/framework/scripts/arch-review.sh +235 -0
- package/framework/scripts/check-linting-sync.sh +58 -0
- package/framework/scripts/load-env.sh +49 -0
- package/framework/scripts/setup-claude.sh +223 -0
- package/framework/scripts/setup-linting.sh +559 -0
- package/framework/scripts/setup-quality.sh +477 -0
- package/framework/scripts/setup-safeword.sh +550 -0
- package/framework/templates/ci/architecture-check.yml +78 -0
- package/learnings/ai-sdk-v5-breaking-changes.md +178 -0
- package/learnings/e2e-test-zombie-processes.md +231 -0
- package/learnings/milkdown-crepe-editor-property.md +96 -0
- package/learnings/prosemirror-fragment-traversal.md +119 -0
- package/package.json +19 -43
- package/packages/cli/AGENTS.md +1 -0
- package/packages/cli/ARCHITECTURE.md +279 -0
- package/packages/cli/package.json +51 -0
- package/packages/cli/src/cli.ts +63 -0
- package/packages/cli/src/commands/check.ts +166 -0
- package/packages/cli/src/commands/diff.ts +209 -0
- package/packages/cli/src/commands/reset.ts +190 -0
- package/packages/cli/src/commands/setup.ts +325 -0
- package/packages/cli/src/commands/upgrade.ts +163 -0
- package/packages/cli/src/index.ts +3 -0
- package/packages/cli/src/templates/config.ts +58 -0
- package/packages/cli/src/templates/content.ts +18 -0
- package/packages/cli/src/templates/index.ts +12 -0
- package/packages/cli/src/utils/agents-md.ts +66 -0
- package/packages/cli/src/utils/fs.ts +179 -0
- package/packages/cli/src/utils/git.ts +124 -0
- package/packages/cli/src/utils/hooks.ts +29 -0
- package/packages/cli/src/utils/output.ts +60 -0
- package/packages/cli/src/utils/project-detector.test.ts +185 -0
- package/packages/cli/src/utils/project-detector.ts +44 -0
- package/packages/cli/src/utils/version.ts +28 -0
- package/packages/cli/src/version.ts +6 -0
- package/packages/cli/templates/SAFEWORD.md +776 -0
- package/packages/cli/templates/doc-templates/architecture-template.md +136 -0
- package/packages/cli/templates/doc-templates/design-doc-template.md +134 -0
- package/packages/cli/templates/doc-templates/test-definitions-feature.md +131 -0
- package/packages/cli/templates/doc-templates/ticket-template.md +82 -0
- package/packages/cli/templates/doc-templates/user-stories-template.md +92 -0
- package/packages/cli/templates/guides/architecture-guide.md +423 -0
- package/packages/cli/templates/guides/code-philosophy.md +195 -0
- package/packages/cli/templates/guides/context-files-guide.md +457 -0
- package/packages/cli/templates/guides/data-architecture-guide.md +200 -0
- package/packages/cli/templates/guides/design-doc-guide.md +171 -0
- package/packages/cli/templates/guides/learning-extraction.md +552 -0
- package/packages/cli/templates/guides/llm-instruction-design.md +248 -0
- package/packages/cli/templates/guides/llm-prompting.md +102 -0
- package/packages/cli/templates/guides/tdd-best-practices.md +615 -0
- package/packages/cli/templates/guides/test-definitions-guide.md +334 -0
- package/packages/cli/templates/guides/testing-methodology.md +618 -0
- package/packages/cli/templates/guides/user-story-guide.md +256 -0
- package/packages/cli/templates/guides/zombie-process-cleanup.md +219 -0
- package/packages/cli/templates/hooks/agents-md-check.sh +27 -0
- package/packages/cli/templates/hooks/post-tool.sh +4 -0
- package/packages/cli/templates/hooks/pre-commit.sh +10 -0
- package/packages/cli/templates/prompts/arch-review.md +43 -0
- package/packages/cli/templates/prompts/quality-review.md +10 -0
- package/packages/cli/templates/skills/safeword-quality-reviewer/SKILL.md +207 -0
- package/packages/cli/tests/commands/check.test.ts +129 -0
- package/packages/cli/tests/commands/cli.test.ts +89 -0
- package/packages/cli/tests/commands/diff.test.ts +115 -0
- package/packages/cli/tests/commands/reset.test.ts +310 -0
- package/packages/cli/tests/commands/self-healing.test.ts +170 -0
- package/packages/cli/tests/commands/setup-blocking.test.ts +71 -0
- package/packages/cli/tests/commands/setup-core.test.ts +135 -0
- package/packages/cli/tests/commands/setup-git.test.ts +139 -0
- package/packages/cli/tests/commands/setup-hooks.test.ts +334 -0
- package/packages/cli/tests/commands/setup-linting.test.ts +189 -0
- package/packages/cli/tests/commands/setup-noninteractive.test.ts +80 -0
- package/packages/cli/tests/commands/setup-templates.test.ts +181 -0
- package/packages/cli/tests/commands/upgrade.test.ts +215 -0
- package/packages/cli/tests/helpers.ts +243 -0
- package/packages/cli/tests/npm-package.test.ts +83 -0
- package/packages/cli/tests/technical-constraints.test.ts +96 -0
- package/packages/cli/tsconfig.json +25 -0
- package/packages/cli/tsup.config.ts +11 -0
- package/packages/cli/vitest.config.ts +23 -0
- package/promptfoo.yaml +3270 -0
- package/dist/check-3NGQ4NR5.js +0 -129
- package/dist/check-3NGQ4NR5.js.map +0 -1
- package/dist/chunk-2XWIUEQK.js +0 -190
- package/dist/chunk-2XWIUEQK.js.map +0 -1
- package/dist/chunk-GZRQL3SX.js +0 -146
- package/dist/chunk-GZRQL3SX.js.map +0 -1
- package/dist/chunk-ORQHKDT2.js +0 -10
- package/dist/chunk-ORQHKDT2.js.map +0 -1
- package/dist/chunk-W66Z3C5H.js +0 -21
- package/dist/chunk-W66Z3C5H.js.map +0 -1
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +0 -34
- package/dist/cli.js.map +0 -1
- package/dist/diff-Y6QTAW4O.js +0 -166
- package/dist/diff-Y6QTAW4O.js.map +0 -1
- package/dist/index.d.ts +0 -11
- package/dist/index.js +0 -7
- package/dist/index.js.map +0 -1
- package/dist/reset-3ACTIYYE.js +0 -143
- package/dist/reset-3ACTIYYE.js.map +0 -1
- package/dist/setup-RR4M334C.js +0 -266
- package/dist/setup-RR4M334C.js.map +0 -1
- package/dist/upgrade-6AR3DHUV.js +0 -134
- package/dist/upgrade-6AR3DHUV.js.map +0 -1
- /package/{templates → framework}/SAFEWORD.md +0 -0
- /package/{templates → framework}/guides/architecture-guide.md +0 -0
- /package/{templates → framework}/guides/code-philosophy.md +0 -0
- /package/{templates → framework}/guides/context-files-guide.md +0 -0
- /package/{templates → framework}/guides/data-architecture-guide.md +0 -0
- /package/{templates → framework}/guides/design-doc-guide.md +0 -0
- /package/{templates → framework}/guides/learning-extraction.md +0 -0
- /package/{templates → framework}/guides/llm-instruction-design.md +0 -0
- /package/{templates → framework}/guides/llm-prompting.md +0 -0
- /package/{templates → framework}/guides/tdd-best-practices.md +0 -0
- /package/{templates → framework}/guides/test-definitions-guide.md +0 -0
- /package/{templates → framework}/guides/testing-methodology.md +0 -0
- /package/{templates → framework}/guides/user-story-guide.md +0 -0
- /package/{templates → framework}/guides/zombie-process-cleanup.md +0 -0
- /package/{templates → framework}/prompts/arch-review.md +0 -0
- /package/{templates → framework}/prompts/quality-review.md +0 -0
- /package/{templates/skills/safeword-quality-reviewer → framework/skills/quality-reviewer}/SKILL.md +0 -0
- /package/{templates/doc-templates → framework/templates}/architecture-template.md +0 -0
- /package/{templates/doc-templates → framework/templates}/design-doc-template.md +0 -0
- /package/{templates/doc-templates → framework/templates}/test-definitions-feature.md +0 -0
- /package/{templates/doc-templates → framework/templates}/ticket-template.md +0 -0
- /package/{templates/doc-templates → framework/templates}/user-stories-template.md +0 -0
- /package/{templates → packages/cli/templates}/commands/arch-review.md +0 -0
- /package/{templates → packages/cli/templates}/commands/lint.md +0 -0
- /package/{templates → packages/cli/templates}/commands/quality-review.md +0 -0
- /package/{templates → packages/cli/templates}/hooks/inject-timestamp.sh +0 -0
- /package/{templates → packages/cli/templates}/lib/common.sh +0 -0
- /package/{templates → packages/cli/templates}/lib/jq-fallback.sh +0 -0
- /package/{templates → packages/cli/templates}/markdownlint.jsonc +0 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# Plan: Architecture Enforcement for SAFEWORD
|
|
2
|
+
|
|
3
|
+
**Created:** 2025-11-27
|
|
4
|
+
**Status:** Draft
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Problem
|
|
9
|
+
|
|
10
|
+
AI agents write code without respecting architectural boundaries → circular dependencies, god modules (>10 dependents or >500 lines), unsafe refactoring.
|
|
11
|
+
|
|
12
|
+
## Solution
|
|
13
|
+
|
|
14
|
+
Codify layers + boundaries in `ARCHITECTURE.md`, enforce via static analysis tools and LLM prompts.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Deliverables
|
|
19
|
+
|
|
20
|
+
### Phase 1: Documentation
|
|
21
|
+
|
|
22
|
+
| Deliverable | Description |
|
|
23
|
+
| ------------------------------------ | ------------------------------------------- |
|
|
24
|
+
| `templates/architecture-template.md` | Layers/boundaries section template |
|
|
25
|
+
| Update `architecture-guide.md` | Add layers/boundaries guidance + edge cases |
|
|
26
|
+
|
|
27
|
+
**Layers Template (sample):**
|
|
28
|
+
|
|
29
|
+
```markdown
|
|
30
|
+
## Layers & Boundaries
|
|
31
|
+
|
|
32
|
+
### Layer Definitions
|
|
33
|
+
|
|
34
|
+
| Layer | Directory | Responsibility |
|
|
35
|
+
| ------ | ------------- | --------------------------- |
|
|
36
|
+
| app | `src/app/` | UI, routing, composition |
|
|
37
|
+
| domain | `src/domain/` | Business rules, pure logic |
|
|
38
|
+
| infra | `src/infra/` | IO, APIs, DB, external SDKs |
|
|
39
|
+
|
|
40
|
+
### Allowed Dependencies
|
|
41
|
+
|
|
42
|
+
| From | To | Allowed | Rationale |
|
|
43
|
+
| ------ | ------ | ------- | --------------------------------- |
|
|
44
|
+
| app | domain | ✅ | UI composes business logic |
|
|
45
|
+
| app | infra | ✅ | UI triggers side effects |
|
|
46
|
+
| domain | app | ❌ | Domain must be framework-agnostic |
|
|
47
|
+
| domain | infra | ❌ | Domain contains pure logic only |
|
|
48
|
+
| infra | domain | ✅ | Adapters may use domain types |
|
|
49
|
+
|
|
50
|
+
Note: This template allows direct app→infra. Alternative: force app→domain→infra for stricter separation (hexagonal/ports-adapters pattern).
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**Edge Cases (must document):**
|
|
54
|
+
|
|
55
|
+
- Project doesn't fit 3-layer model → Document actual layers, same boundary rules apply
|
|
56
|
+
- Feature module needs another feature → Import via public API (`index.ts`) only
|
|
57
|
+
- Shared utilities → Create `shared/` layer, all layers may import
|
|
58
|
+
- Brownfield adoption → Start with warnings-only mode, fix violations incrementally, then enforce
|
|
59
|
+
|
|
60
|
+
### Phase 2: Boundary Enforcement (ESLint)
|
|
61
|
+
|
|
62
|
+
| Deliverable | Description |
|
|
63
|
+
| ------------------------------ | ----------------------------------------------------- |
|
|
64
|
+
| Add `eslint-plugin-boundaries` | To all ESLint modes in `setup-linting.sh` |
|
|
65
|
+
| Remove `--biome` mode | ESLint is the only supported linter (breaking change) |
|
|
66
|
+
| Update `architecture-guide.md` | Boundary rule setup instructions |
|
|
67
|
+
|
|
68
|
+
**Why ESLint-only:**
|
|
69
|
+
|
|
70
|
+
- IDE integration (errors show in editor immediately)
|
|
71
|
+
- Single config file (no separate tool)
|
|
72
|
+
- Most TypeScript projects use ESLint anyway
|
|
73
|
+
- Simpler maintenance (one path)
|
|
74
|
+
|
|
75
|
+
**User flow:**
|
|
76
|
+
|
|
77
|
+
1. Run `setup-linting.sh` → gets ESLint + boundary rules
|
|
78
|
+
2. Create `ARCHITECTURE.md` → define layers
|
|
79
|
+
3. Configure boundary rules in `eslint.config.mjs`
|
|
80
|
+
4. Errors appear in IDE + CI automatically
|
|
81
|
+
|
|
82
|
+
### Phase 3: LLM Prompts + Pre-commit Hook
|
|
83
|
+
|
|
84
|
+
| Deliverable | Description |
|
|
85
|
+
| --------------------------- | ---------------------------------------------------------- |
|
|
86
|
+
| `framework/prompts/` folder | New folder for LLM inputs (copied to `.safeword/prompts/`) |
|
|
87
|
+
| `prompts/quality-review.md` | Extract existing prompt from `setup-quality.sh` |
|
|
88
|
+
| `prompts/arch-review.md` | Semantic architecture review prompt |
|
|
89
|
+
| `scripts/arch-review.sh` | Shell script calling Haiku API for arch review |
|
|
90
|
+
| Update `setup-safeword.sh` | Copy `prompts/` folder + add pre-commit hook |
|
|
91
|
+
| Update `setup-quality.sh` | Reference `.safeword/prompts/quality-review.md` |
|
|
92
|
+
|
|
93
|
+
**`prompts/arch-review.md`:**
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
Review for architectural issues:
|
|
97
|
+
|
|
98
|
+
1. **Misplaced logic** - Business rules in wrong layer?
|
|
99
|
+
2. **God module** - Too many responsibilities?
|
|
100
|
+
3. **Leaky abstraction** - Implementation details exposed?
|
|
101
|
+
4. **Tight coupling** - Changes cascade unnecessarily?
|
|
102
|
+
|
|
103
|
+
Return JSON:
|
|
104
|
+
{
|
|
105
|
+
"issues": [{ "type": string, "location": string, "fix": string }],
|
|
106
|
+
"verdict": "clean" | "minor" | "refactor_needed"
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**`scripts/arch-review.sh`:**
|
|
111
|
+
|
|
112
|
+
- Sends changed files + ARCHITECTURE.md + prompt
|
|
113
|
+
- Returns JSON verdict
|
|
114
|
+
- Requires `ANTHROPIC_API_KEY` env var
|
|
115
|
+
|
|
116
|
+
**Pre-commit hook integration:**
|
|
117
|
+
|
|
118
|
+
- Git pre-commit hook runs:
|
|
119
|
+
1. `eslint` on staged files (fast, free, deterministic)
|
|
120
|
+
2. `arch-review.sh` on staged files (semantic review)
|
|
121
|
+
- Lint errors → blocks commit
|
|
122
|
+
- Arch verdict `refactor_needed` → blocks commit
|
|
123
|
+
- Arch verdict `minor` → warns, allows commit
|
|
124
|
+
|
|
125
|
+
### Phase 4: CI Integration
|
|
126
|
+
|
|
127
|
+
| Deliverable | Description |
|
|
128
|
+
| ------------------------------------- | -------------------------------- |
|
|
129
|
+
| `templates/ci/architecture-check.yml` | GitHub Actions workflow template |
|
|
130
|
+
|
|
131
|
+
**CI Steps (in order):**
|
|
132
|
+
|
|
133
|
+
1. `tsc --noEmit` - Type check
|
|
134
|
+
2. `eslint` - Includes boundary rules via eslint-plugin-boundaries
|
|
135
|
+
3. LLM review (optional, non-blocking initially)
|
|
136
|
+
|
|
137
|
+
### Phase 5: Drift Detection
|
|
138
|
+
|
|
139
|
+
Deferred. Revisit after Phase 4 validated in production use.
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Dependencies
|
|
144
|
+
|
|
145
|
+
| Phase | Depends On | Can Parallelize With |
|
|
146
|
+
| ---------------- | ---------- | -------------------- |
|
|
147
|
+
| Phase 1: Docs | None | Phase 2, 3 |
|
|
148
|
+
| Phase 2: Tooling | None | Phase 1, 3 |
|
|
149
|
+
| Phase 3: Prompts | None | Phase 1, 2 |
|
|
150
|
+
| Phase 4: CI | Phase 2 | — |
|
|
151
|
+
| Phase 5: Drift | Phase 4 | — |
|
|
152
|
+
|
|
153
|
+
**Recommended start:** Phase 1 + Phase 2 + Phase 3 in parallel, then Phase 4.
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## Open Questions
|
|
158
|
+
|
|
159
|
+
1. **Scope:** TypeScript-only, or Python support in Phase 6?
|
|
160
|
+
2. **CI LLM review:** Blocking or advisory-only initially?
|
|
161
|
+
3. **Template flexibility:** Ship opinionated 3-layer, or configurable?
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## Next Steps
|
|
166
|
+
|
|
167
|
+
1. ✅ Ticket created: `.safeword/tickets/002-architecture-enforcement.md`
|
|
168
|
+
2. Write user stories for Phase 1
|
|
169
|
+
3. Prototype boundary rules in a test project
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# Research: Reactive Fix Prevention
|
|
2
|
+
|
|
3
|
+
**Created:** 2025-11-27
|
|
4
|
+
**Status:** Complete
|
|
5
|
+
**Ticket:** 003-reactive-fix-prevention
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Problem Statement
|
|
10
|
+
|
|
11
|
+
AI coding agents fall into "error-fix-error" loops:
|
|
12
|
+
|
|
13
|
+
1. See error → attempt fix
|
|
14
|
+
2. Fix creates new error → attempt another fix
|
|
15
|
+
3. Repeat until codebase is tangled
|
|
16
|
+
|
|
17
|
+
This pattern ignores:
|
|
18
|
+
|
|
19
|
+
- Root cause analysis
|
|
20
|
+
- Architectural boundaries
|
|
21
|
+
- Broader system implications
|
|
22
|
+
|
|
23
|
+
## Research Sources
|
|
24
|
+
|
|
25
|
+
### 1. MASAI Framework (arxiv.org/abs/2406.11638)
|
|
26
|
+
|
|
27
|
+
**Key finding:** Modular sub-agents with well-defined objectives outperform monolithic agents.
|
|
28
|
+
|
|
29
|
+
**Relevance:** Instead of one agent that does everything, specialized agents (planner, implementer, reviewer) prevent reactive thrashing.
|
|
30
|
+
|
|
31
|
+
**Application:** Force planning phase before implementation phase.
|
|
32
|
+
|
|
33
|
+
### 2. ProSEA Framework (arxiv.org/abs/2510.07423)
|
|
34
|
+
|
|
35
|
+
**Key finding:** Manager Agent orchestrates Expert Agents. Failed attempts report back with "structured feedback" including constraints discovered.
|
|
36
|
+
|
|
37
|
+
**Relevance:** When a fix fails, the agent should learn WHY and carry that constraint forward—not just try another random fix.
|
|
38
|
+
|
|
39
|
+
**Application:** After any fix attempt, agent must document what was learned before retrying.
|
|
40
|
+
|
|
41
|
+
### 3. Factored Agents (arxiv.org/abs/2503.22931)
|
|
42
|
+
|
|
43
|
+
**Key finding:** Separating in-context learning (planning) from memorization (execution) improves accuracy.
|
|
44
|
+
|
|
45
|
+
**Relevance:** Agents that plan separately from executing make better architectural decisions.
|
|
46
|
+
|
|
47
|
+
**Application:** Explicit "planning mode" before "execution mode."
|
|
48
|
+
|
|
49
|
+
### 4. DEV.to Article (vuong_ngo)
|
|
50
|
+
|
|
51
|
+
**Key finding:** "AI Keeps Breaking Your Architectural Patterns. Documentation Won't Fix It."
|
|
52
|
+
|
|
53
|
+
**Relevance:** Long AGENTS.md files are insufficient. Agents need:
|
|
54
|
+
|
|
55
|
+
- Active validation mechanisms
|
|
56
|
+
- Enforcement gates
|
|
57
|
+
- Context retrieval at decision points
|
|
58
|
+
|
|
59
|
+
**Application:** Pre-commit hooks, session-level triggers, mandatory context loading.
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Synthesis
|
|
64
|
+
|
|
65
|
+
| Problem | Root Cause | Solution |
|
|
66
|
+
| --------------------- | ---------------------------- | ------------------------------------------------------- |
|
|
67
|
+
| Reactive fixing | No planning phase | Mandatory "understand first" before any fix |
|
|
68
|
+
| Ignoring architecture | Docs loaded once, forgotten | Force ARCHITECTURE.md reload at decision points |
|
|
69
|
+
| Cascading fixes | No threshold/circuit breaker | "3+ fixes = STOP" rule (exists in systematic-debugging) |
|
|
70
|
+
| Multi-file changes | No blast radius awareness | Approval gate for >3 file changes |
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Recommended Additions to SAFEWORD
|
|
75
|
+
|
|
76
|
+
### 1. Before ANY Error Fix (Mandatory)
|
|
77
|
+
|
|
78
|
+
```markdown
|
|
79
|
+
## Before ANY Error Fix (CRITICAL)
|
|
80
|
+
|
|
81
|
+
BEFORE attempting to fix any error:
|
|
82
|
+
|
|
83
|
+
1. **Load Context** - Read relevant ARCHITECTURE.md sections
|
|
84
|
+
2. **Ask "Why Here?"** - Is this error a symptom of a deeper issue?
|
|
85
|
+
3. **Check Pattern** - Does the fix match existing patterns, or introduce a new one?
|
|
86
|
+
4. **Consider Blast Radius** - What else touches this code?
|
|
87
|
+
|
|
88
|
+
If you've made 2+ fix attempts → STOP. Use systematic-debugging skill.
|
|
89
|
+
If fix would change >3 files → STOP. Get approval first.
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### 2. Red Flags (Stop and Think)
|
|
93
|
+
|
|
94
|
+
```markdown
|
|
95
|
+
## Red Flags (Stop and Think)
|
|
96
|
+
|
|
97
|
+
If you catch yourself:
|
|
98
|
+
|
|
99
|
+
- Fixing an error you just created
|
|
100
|
+
- Changing the same file 3+ times in one session
|
|
101
|
+
- Adding workarounds instead of understanding root cause
|
|
102
|
+
- "Just trying" something without hypothesis
|
|
103
|
+
- Fixing in multiple layers for "one" issue
|
|
104
|
+
|
|
105
|
+
→ STOP. Read ARCHITECTURE.md. Use systematic-debugging.
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### 3. Validation Triggers
|
|
109
|
+
|
|
110
|
+
| Trigger | Action |
|
|
111
|
+
| ----------------------- | ------------------------------ |
|
|
112
|
+
| 2+ fix attempts | Stop, use systematic-debugging |
|
|
113
|
+
| 3+ changes to same file | Stop, investigate root cause |
|
|
114
|
+
| 5+ files changed | Run architecture review |
|
|
115
|
+
| Fix touches 3+ layers | Get explicit approval |
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Integration Points
|
|
120
|
+
|
|
121
|
+
| Existing Asset | How to Integrate |
|
|
122
|
+
| --------------------------- | ------------------------------------- |
|
|
123
|
+
| SAFEWORD.md | Add "Before ANY Error Fix" section |
|
|
124
|
+
| code-philosophy.md | Add "Reactive Fix Prevention" section |
|
|
125
|
+
| systematic-debugging skill | Add architecture context loading step |
|
|
126
|
+
| arch-review.sh (ticket 002) | Use as validation gate |
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## Next Steps
|
|
131
|
+
|
|
132
|
+
1. ✅ User stories created (`.safeword/planning/user-stories/003-reactive-fix-prevention.md`)
|
|
133
|
+
2. Draft SAFEWORD.md additions (Stories 1-4)
|
|
134
|
+
3. Update systematic-debugging skill with architecture context loading
|
|
135
|
+
4. Session-level change counting (deferred—out of scope for ticket 003)
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
# CLI UX Vision: Safeword
|
|
2
|
+
|
|
3
|
+
**Status:** 🟢 Complete
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Philosophy
|
|
8
|
+
|
|
9
|
+
- **Natural language** — Commands read like sentences
|
|
10
|
+
- **Progressive discovery** — Capabilities via `--help`
|
|
11
|
+
- **No modes** — Stateless commands
|
|
12
|
+
- **npx-first** — Always latest
|
|
13
|
+
- **Dual-audience** — Human + LLM readable
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Decisions
|
|
18
|
+
|
|
19
|
+
| Decision | Choice |
|
|
20
|
+
| -------------------- | ---------------------------------------------- |
|
|
21
|
+
| Package | `safeword` |
|
|
22
|
+
| Setup cmd | `setup` (not `init`) |
|
|
23
|
+
| Bare cmd | Show help |
|
|
24
|
+
| Errors | Medium verbosity |
|
|
25
|
+
| Versions | Coupled (project = CLI) |
|
|
26
|
+
| Downgrade | Refuse |
|
|
27
|
+
| Hooks | `$CLAUDE_PROJECT_DIR/.safeword/hooks/` |
|
|
28
|
+
| Skills | Copy to `.claude/skills/safeword-*/` |
|
|
29
|
+
| Git hooks | Marker-based append/remove |
|
|
30
|
+
| Linting | Full install + configure |
|
|
31
|
+
| Linting failure | Core failure, exit 1 |
|
|
32
|
+
| Existing config | Error: "Run `safeword upgrade`" |
|
|
33
|
+
| Root file | AGENTS.md only, **prepend** link |
|
|
34
|
+
| AGENTS.md check | SessionStart hook verifies, re-adds if missing |
|
|
35
|
+
| Offline check | Graceful degradation |
|
|
36
|
+
| Non-git | Prompt (auto-skip with `--yes`) |
|
|
37
|
+
| Monorepo | Root only |
|
|
38
|
+
| User edits | Overwritten on upgrade |
|
|
39
|
+
| Same-version upgrade | Force reinstall |
|
|
40
|
+
| Partial fail | Exit 0 + warnings |
|
|
41
|
+
| Non-interactive | Auto-TTY + `--yes` |
|
|
42
|
+
| Skill conflict | Overwrite silently |
|
|
43
|
+
| Diff output | Summary + `--verbose` |
|
|
44
|
+
| Reset AGENTS.md | Search exact string, remove |
|
|
45
|
+
| Reset confirm | Prompt (auto-confirm with `--yes`) |
|
|
46
|
+
| package.json | Add lint/format scripts |
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Commands (v1)
|
|
51
|
+
|
|
52
|
+
| Command | Purpose |
|
|
53
|
+
| ------------------ | ------------------------------------ |
|
|
54
|
+
| `safeword` | Show help |
|
|
55
|
+
| `safeword setup` | Initialize (full setup with linting) |
|
|
56
|
+
| `safeword check` | Health + versions |
|
|
57
|
+
| `safeword upgrade` | Update project (always reinstalls) |
|
|
58
|
+
| `safeword diff` | Preview changes |
|
|
59
|
+
| `safeword reset` | Remove (prompts for confirm) |
|
|
60
|
+
|
|
61
|
+
**Global Flags:**
|
|
62
|
+
|
|
63
|
+
- `--version` — Show CLI version
|
|
64
|
+
- `--help` — Show help
|
|
65
|
+
|
|
66
|
+
**Command Flags:**
|
|
67
|
+
|
|
68
|
+
- `--yes` — Accept defaults (no prompts)
|
|
69
|
+
- `--verbose` — Detailed output (for `diff`)
|
|
70
|
+
- `--offline` — Skip version check (for `check`)
|
|
71
|
+
|
|
72
|
+
**Deferred:** `doctor` (v1.x)
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## File Structure
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
.safeword/
|
|
80
|
+
SAFEWORD.md # Core patterns
|
|
81
|
+
version # "1.2.0"
|
|
82
|
+
README.md # "Managed by CLI"
|
|
83
|
+
hooks/
|
|
84
|
+
skills/
|
|
85
|
+
guides/
|
|
86
|
+
scripts/
|
|
87
|
+
prompts/
|
|
88
|
+
templates/
|
|
89
|
+
|
|
90
|
+
.claude/
|
|
91
|
+
settings.json
|
|
92
|
+
skills/safeword-*/
|
|
93
|
+
|
|
94
|
+
.git/hooks/
|
|
95
|
+
pre-commit # If git repo
|
|
96
|
+
|
|
97
|
+
AGENTS.md # With link prepended at top
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Setup Flow
|
|
103
|
+
|
|
104
|
+
1. Check for existing `.safeword/`
|
|
105
|
+
- If exists → Error: "Already configured. Run `safeword upgrade` to update."
|
|
106
|
+
2. Detect project type (Next.js, React, TS, etc.)
|
|
107
|
+
3. Copy templates to `.safeword/`
|
|
108
|
+
4. Register hooks in `.claude/settings.json`
|
|
109
|
+
- Includes SessionStart hook to verify AGENTS.md
|
|
110
|
+
5. Copy skills to `.claude/skills/safeword-*/`
|
|
111
|
+
6. Install + configure linting
|
|
112
|
+
- Add `lint` and `format` scripts to package.json
|
|
113
|
+
- If fails → Exit 1 (core failure)
|
|
114
|
+
7. Check for `.git/`
|
|
115
|
+
- TTY: Prompt — Initialize git?
|
|
116
|
+
- No TTY or `--yes`: Auto-skip with warning
|
|
117
|
+
8. Prepend link to `AGENTS.md` (create if missing)
|
|
118
|
+
9. Print summary
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## Upgrade Flow
|
|
123
|
+
|
|
124
|
+
1. Check `.safeword/version` exists
|
|
125
|
+
- If missing → Error: "Not configured. Run `safeword setup`."
|
|
126
|
+
2. Compare versions (for display only)
|
|
127
|
+
3. Overwrite all `.safeword/` files with CLI's templates
|
|
128
|
+
4. Update `.claude/skills/safeword-*/`
|
|
129
|
+
5. Update hooks if needed
|
|
130
|
+
6. Update `.safeword/version`
|
|
131
|
+
7. Print summary of changes
|
|
132
|
+
|
|
133
|
+
**Note:** Always reinstalls, even if same version.
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## Commands on Unconfigured Project
|
|
138
|
+
|
|
139
|
+
| Command | Behavior |
|
|
140
|
+
| --------- | ----------------------------------------------------- |
|
|
141
|
+
| `check` | Show "Not configured. Run `safeword setup`." (exit 0) |
|
|
142
|
+
| `diff` | Error: "Not configured." (exit 1) |
|
|
143
|
+
| `reset` | "Nothing to remove." (exit 0) |
|
|
144
|
+
| `upgrade` | Error: "Not configured." (exit 1) |
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## Non-Interactive Behavior
|
|
149
|
+
|
|
150
|
+
**Auto-TTY detection:**
|
|
151
|
+
|
|
152
|
+
- Terminal (TTY) → Show prompts
|
|
153
|
+
- CI/pipe (no TTY) → Use defaults automatically
|
|
154
|
+
|
|
155
|
+
**`--yes` flag:**
|
|
156
|
+
|
|
157
|
+
- Force defaults even in terminal
|
|
158
|
+
- Defaults: skip git init, auto-confirm reset
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## Hooks
|
|
163
|
+
|
|
164
|
+
**Claude Code:**
|
|
165
|
+
|
|
166
|
+
- Append to `.claude/settings.json` arrays
|
|
167
|
+
- Reference via `$CLAUDE_PROJECT_DIR/.safeword/hooks/`
|
|
168
|
+
- Remove by path pattern
|
|
169
|
+
|
|
170
|
+
**SessionStart hook** (new):
|
|
171
|
+
|
|
172
|
+
- Checks if AGENTS.md still has safeword link
|
|
173
|
+
- If missing, re-adds and alerts user
|
|
174
|
+
|
|
175
|
+
**Git pre-commit:**
|
|
176
|
+
|
|
177
|
+
- Marker-based: `SAFEWORD_ARCH_CHECK_START/END`
|
|
178
|
+
- Append or create
|
|
179
|
+
- Remove only between markers
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## Skills
|
|
184
|
+
|
|
185
|
+
- Source: `.safeword/skills/X/SKILL.md`
|
|
186
|
+
- Destination: `.claude/skills/safeword-X/SKILL.md`
|
|
187
|
+
- Overwrite silently (we own this namespace)
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## Root File Strategy
|
|
192
|
+
|
|
193
|
+
**Setup:**
|
|
194
|
+
|
|
195
|
+
1. Create `.safeword/SAFEWORD.md`
|
|
196
|
+
2. **Prepend** to `AGENTS.md` (create if missing):
|
|
197
|
+
```markdown
|
|
198
|
+
**⚠️ ALWAYS READ FIRST: @./.safeword/SAFEWORD.md**
|
|
199
|
+
```
|
|
200
|
+
3. Check if link already exists (avoid duplicates)
|
|
201
|
+
|
|
202
|
+
**SessionStart Hook:**
|
|
203
|
+
|
|
204
|
+
- Verifies link still in AGENTS.md
|
|
205
|
+
- If removed, re-adds and shows warning
|
|
206
|
+
|
|
207
|
+
**Reset:**
|
|
208
|
+
|
|
209
|
+
- Search for exact string in `AGENTS.md`
|
|
210
|
+
- Remove the line
|
|
211
|
+
|
|
212
|
+
**Note:** Only handles AGENTS.md, not CLAUDE.md. Prepend for LLM primacy effect.
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
## package.json Updates
|
|
217
|
+
|
|
218
|
+
Setup adds these scripts:
|
|
219
|
+
|
|
220
|
+
```json
|
|
221
|
+
{
|
|
222
|
+
"scripts": {
|
|
223
|
+
"lint": "eslint .",
|
|
224
|
+
"format": "prettier --write ."
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Also adds devDependencies for ESLint/Prettier.
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## Reset Flow
|
|
234
|
+
|
|
235
|
+
1. Check `.safeword/` exists
|
|
236
|
+
- If missing → "Nothing to remove." (exit 0)
|
|
237
|
+
2. Prompt: "This will remove safeword. Continue? [y/N]"
|
|
238
|
+
- With `--yes`: auto-confirm
|
|
239
|
+
3. Remove `.safeword/`
|
|
240
|
+
4. Remove safeword hooks from `.claude/settings.json`
|
|
241
|
+
5. Remove safeword skills from `.claude/skills/`
|
|
242
|
+
6. Remove git hook markers from `.git/hooks/pre-commit`
|
|
243
|
+
7. Remove link from `AGENTS.md`
|
|
244
|
+
8. Print summary
|
|
245
|
+
|
|
246
|
+
**What reset leaves intact (by design):**
|
|
247
|
+
|
|
248
|
+
- `lint`/`format` scripts in package.json
|
|
249
|
+
- ESLint/Prettier devDependencies
|
|
250
|
+
- `eslint.config.mjs`, `.prettierrc`
|
|
251
|
+
|
|
252
|
+
**Rationale:** Linting config is useful independently. User may have customized. Standard CLI behavior is to leave configuration artifacts.
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## Diff Command
|
|
257
|
+
|
|
258
|
+
**Default:** Summary only
|
|
259
|
+
|
|
260
|
+
```
|
|
261
|
+
Changes from v1.0.0 → v1.2.0:
|
|
262
|
+
|
|
263
|
+
Modified: 3 files
|
|
264
|
+
.safeword/SAFEWORD.md
|
|
265
|
+
.safeword/guides/testing-methodology.md
|
|
266
|
+
.safeword/hooks/auto-quality-review.sh
|
|
267
|
+
|
|
268
|
+
Added: 1 file
|
|
269
|
+
.safeword/guides/zombie-process-cleanup.md
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
**With `--verbose`:** Full unified diff
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
## Version Check
|
|
277
|
+
|
|
278
|
+
**Online (default):**
|
|
279
|
+
|
|
280
|
+
```
|
|
281
|
+
Safeword CLI: v1.2.0 (latest)
|
|
282
|
+
Project config: v1.0.0 (v1.2.0 available)
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
**Offline/timeout:**
|
|
286
|
+
|
|
287
|
+
```
|
|
288
|
+
Safeword CLI: v1.2.0
|
|
289
|
+
Project config: v1.0.0
|
|
290
|
+
|
|
291
|
+
Note: Couldn't check for updates (offline?)
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
---
|
|
295
|
+
|
|
296
|
+
## Exit Codes
|
|
297
|
+
|
|
298
|
+
| Code | Meaning |
|
|
299
|
+
| ---- | ----------------------------------- |
|
|
300
|
+
| 0 | Success (may have warnings) |
|
|
301
|
+
| 1 | Failure (core functionality failed) |
|
|
302
|
+
|
|
303
|
+
**Core failures (exit 1):**
|
|
304
|
+
|
|
305
|
+
- Can't write to `.safeword/`
|
|
306
|
+
- Linting install fails
|
|
307
|
+
- Can't register hooks
|
|
308
|
+
- `diff`/`upgrade` on unconfigured
|
|
309
|
+
|
|
310
|
+
**Warnings (exit 0):**
|
|
311
|
+
|
|
312
|
+
- Git hooks skipped (no git)
|
|
313
|
+
- Version check failed (offline)
|
|
314
|
+
- `reset` on unconfigured
|
|
315
|
+
|
|
316
|
+
---
|
|
317
|
+
|
|
318
|
+
## Output Design
|
|
319
|
+
|
|
320
|
+
- Labeled values: `Project: v1.0.0`
|
|
321
|
+
- Explicit status: `(v1.2.0 available)`
|
|
322
|
+
- Symbols: `✓` `✗` `⚠`
|
|
323
|
+
- Action blocks: `To fix: safeword setup`
|
|
324
|
+
|
|
325
|
+
---
|
|
326
|
+
|
|
327
|
+
## Related
|
|
328
|
+
|
|
329
|
+
- [Ticket #005](../tickets/005-cli-implementation.md)
|
|
330
|
+
- [Implementation Plan](../../docs/001-cli-implementation-plan.md)
|