knowy-cli 0.1.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.
@@ -0,0 +1,272 @@
1
+ ---
2
+ name: knowy-judge
3
+ description: Cross-check knowledge files for consistency, coherence, and project alignment
4
+ user-invokable: true
5
+ argument-hint: "[scope: file name, file pair, or event description]"
6
+ ---
7
+
8
+ # Knowy Judge
9
+
10
+ Verify that the three knowledge files (principles, vision, experience) are internally sound, consistent with each other, and aligned with the actual project state.
11
+
12
+ ## User Input
13
+
14
+ ```text
15
+ $ARGUMENTS
16
+ ```
17
+
18
+ ## Governance Principles
19
+
20
+ These rules govern how you interact with knowledge files. Follow them in every check:
21
+
22
+ - **Principles are the highest authority.** If vision or experience conflicts with principles, the pressure is on vision/experience to change — unless the conflict reveals that a principle needs revision.
23
+ - **Vision evolves with understanding.** It should be updated after milestones, not frozen.
24
+ - **Experience is distilled, not accumulated.** Only patterns that influence future decisions belong here. Raw events go in history/.
25
+ - **Knowledge files are indexes, not encyclopedias.** Each should be short enough to read in one pass (~100-200 lines). Long content belongs in subdirectories.
26
+ - **Never modify files without explicit user confirmation.** Present findings and suggestions; let the user decide.
27
+
28
+ ## Workflow
29
+
30
+ ### 1. Read knowledge files
31
+
32
+ Read all three core files:
33
+ - `.knowledge/principles.md`
34
+ - `.knowledge/vision.md`
35
+ - `.knowledge/experience.md`
36
+
37
+ Also scan `.knowledge/research/`, `.knowledge/design/`, `.knowledge/history/` for additional context.
38
+
39
+ ### 2. Read project context
40
+
41
+ To check alignment with the actual project, also examine:
42
+ - Project directory structure (what files and directories exist)
43
+ - `package.json`, `Cargo.toml`, or equivalent (tech stack, dependencies)
44
+ - Recent git log (what has actually been built recently)
45
+ - README or other top-level docs
46
+
47
+ ### 3. Determine scope
48
+
49
+ Parse `$ARGUMENTS` to decide what to check:
50
+
51
+ - **No arguments**: full check (all 17 sections below)
52
+ - **Single file** (e.g., "experience"): that file's self-consistency, internal coherence, project alignment, and its cross-references with the other two files
53
+ - **File pair** (e.g., "principles vision"): the 2 directional cross-references for that pair
54
+ - **Event description** (e.g., "just finished the auth system"): impact analysis on all three files
55
+
56
+ ### 4. Execute checks
57
+
58
+ #### A. Self-consistency (3 checks)
59
+
60
+ For each file, check its structural and logical integrity:
61
+
62
+ **Principles:**
63
+ - Does the root axiom exist and is it clearly stated?
64
+ - Does every derived principle trace back to the root axiom or another principle? Are there broken derivation chains?
65
+ - Are there principles that say the same thing in different words (redundancy)?
66
+ - Is the document organized from general to specific?
67
+
68
+ **Vision:**
69
+ - Does the problem statement clearly define who has the problem and why?
70
+ - Does the roadmap flow logically? Are prerequisites respected?
71
+ - Are milestones mutually exclusive or do they overlap?
72
+ - Are success criteria concrete and verifiable?
73
+
74
+ **Experience:**
75
+ - Does each lesson follow the pattern/event/takeaway format?
76
+ - Are there lessons that contradict each other without acknowledging the contradiction?
77
+ - Are lessons specific enough to be actionable?
78
+ - Are source references present and traceable?
79
+
80
+ #### B. Internal Coherence (3 checks)
81
+
82
+ For each file, check for contradictions in content:
83
+
84
+ - Are there statements that directly contradict each other?
85
+ - Are there implicit assumptions that conflict?
86
+ - Are there outdated entries that no longer reflect the project's reality?
87
+
88
+ #### C. Cross-references (6 directional checks)
89
+
90
+ Each direction asks a specific question:
91
+
92
+ | Direction | Core Question | Detailed Probes |
93
+ |-----------|--------------|-----------------|
94
+ | Principles → Vision | Can the vision be derived from the principles? | Does each roadmap item serve at least one principle? Are there vision items with no principled justification? |
95
+ | Vision → Principles | Does the vision require principles that aren't stated? | Are there implicit assumptions in the vision that should be made explicit as principles? |
96
+ | Principles → Experience | Do the principles predict the patterns observed? | Has experience validated the principles? Which principles lack empirical support? |
97
+ | Experience → Principles | Does any experience challenge or extend the principles? | Are there lessons that suggest a principle is wrong, incomplete, or needs nuance? |
98
+ | Vision → Experience | Does experience support the planned direction? | Are there known risks from experience that the vision doesn't address? Has the vision learned from past failures? |
99
+ | Experience → Vision | Are there lessons suggesting opportunities not yet in the vision? | Has experience revealed capabilities or patterns that could open new directions? |
100
+
101
+ #### D. Project Alignment (3 checks)
102
+
103
+ Check each file against the actual project state:
104
+
105
+ **Principles vs Project:**
106
+ - Do claimed technology choices match actual dependencies?
107
+ - Do architectural principles match the actual code structure?
108
+ - Are there principles about practices (e.g., "TDD") that aren't actually followed?
109
+
110
+ **Vision vs Project:**
111
+ - Does the roadmap status match what's actually implemented?
112
+ - Are "completed" milestones truly complete in the code?
113
+ - Are there significant implemented features not reflected in the vision?
114
+ - Does the tech stack in the vision match the actual project?
115
+
116
+ **Experience vs Project:**
117
+ - Are referenced files/features still present in the project?
118
+ - Have lessons been acted upon? (e.g., "always validate first" — is validation actually in place?)
119
+ - Are there stale lessons about problems that have been solved or code that was rewritten?
120
+
121
+ #### E. Overall (1 check)
122
+
123
+ Synthesize all findings:
124
+ - Where is the most pressure? Which file needs the most attention?
125
+ - Is the knowledge system generally healthy or in need of significant work?
126
+ - What is the single most impactful action the user could take?
127
+
128
+ #### F. Beyond Scope (1 check)
129
+
130
+ Look for content that doesn't belong:
131
+ - Lessons about a different project or domain
132
+ - Principles too generic to be useful (e.g., "write clean code")
133
+ - Vision items that belong in a separate project
134
+ - Content that should be in subdirectories instead of core files
135
+
136
+ ### 5. Format output
137
+
138
+ ```markdown
139
+ ## Knowledge Health Check
140
+
141
+ ### Self-consistency
142
+ 🟢 Principles — root axiom present, derivation chains intact.
143
+ 🟡 Vision — Phase 3 and Phase 5 overlap in scope.
144
+ Phase 3 (line 45): "Implement caching layer"
145
+ Phase 5 (line 67): "Add performance optimization including caching"
146
+ → Clarify the boundary or merge these phases.
147
+ 🟢 Experience — all lessons follow consistent format.
148
+
149
+ ### Internal Coherence
150
+ 🟢 Principles — no contradictions.
151
+ 🟡 Vision — current state section says "auth is complete" (line 28)
152
+ but roadmap still lists auth as pending (line 52).
153
+ → Update one or the other.
154
+ 🟢 Experience — consistent.
155
+
156
+ ### Cross-references
157
+ 🟢 Principles → Vision — vision is derivable from principles.
158
+ 🟡 Vision → Principles — vision mentions "progressive disclosure"
159
+ but principles don't include a related principle.
160
+ → Add a principle, or document this as a tactical choice in vision.
161
+ 🟢 Principles → Experience — principles predict observed patterns.
162
+ 🟢 Experience → Principles — no challenges to existing principles.
163
+ 🔴 Vision → Experience — vision plans to use SSR, but experience
164
+ recorded SSR hydration issues.
165
+ Vision line 34: "Phase 2: migrate to SSR"
166
+ Experience line 12: "SSR hydration caused 3-day debug cycle"
167
+ → Address this known risk in vision, or explain why context differs.
168
+ 🟢 Experience → Vision — no missed opportunities.
169
+
170
+ ### Project Alignment
171
+ 🟢 Principles — tech choices match project reality.
172
+ 🟡 Vision — roadmap says Phase 1 complete, but tests/ directory
173
+ is empty. Success criteria mentions "90% test coverage."
174
+ → Either update success criteria or add tests.
175
+ 🟢 Experience — all referenced code still exists.
176
+
177
+ ### Overall
178
+ 🟡 Generally healthy. Main pressure on vision.md — one conflict
179
+ with experience, one internal inconsistency, and one alignment
180
+ gap with project state.
181
+
182
+ ### Beyond Scope
183
+ 🟢 All content is relevant to this project.
184
+
185
+ ## Suggested Actions
186
+ 1. [High] Resolve SSR conflict between vision and experience
187
+ 2. [Medium] Fix auth status inconsistency in vision
188
+ 3. [Medium] Clarify Phase 3/5 overlap in vision
189
+ 4. [Low] Consider adding progressive disclosure principle
190
+ ```
191
+
192
+ ### 6. Event-based analysis (when $ARGUMENTS describes an event)
193
+
194
+ ```markdown
195
+ ## Post-feature Check: [Event]
196
+
197
+ ### Impact on Experience
198
+ 🟡 Worth distilling — [specific observation].
199
+ → Suggest adding a lesson to experience.md
200
+
201
+ ### Impact on Vision
202
+ 🟢 Milestone completed as planned.
203
+ → Mark as complete in roadmap.
204
+
205
+ ### Impact on Principles
206
+ 🟢 No challenge to existing principles.
207
+
208
+ ### Project Alignment
209
+ 🟡 Feature is implemented but vision hasn't been updated.
210
+
211
+ ### Suggested Actions
212
+ 1. Add lesson to experience.md: [specific lesson]
213
+ 2. Update vision.md: mark [milestone] as complete
214
+ ```
215
+
216
+ ### 7. Reorganization offer
217
+
218
+ If checks reveal that files are too disorganized to assess clearly, offer to help reorganize. Common triggers:
219
+
220
+ - **Overgrown core file** (>200 lines): Propose moving detail to subdirectories, keeping only distilled content in core.
221
+ - **Raw events in experience.md**: Propose moving them to history/ and distilling into patterns.
222
+ - **Stale content**: Propose removing or updating entries that reference deleted code, completed milestones, or resolved problems.
223
+ - **Broken structure**: Propose reordering sections to match template structure (root → derived, general → specific).
224
+ - **Mature subdirectory content**: Propose distilling key insights from research/design/history into the appropriate core file.
225
+
226
+ Format the offer clearly:
227
+
228
+ ```markdown
229
+ ## Reorganization Suggested
230
+
231
+ experience.md has grown to 280 lines (recommended: ~200).
232
+ - 5 lessons appear to be raw events rather than distilled patterns
233
+ - 3 lessons reference code that has been rewritten
234
+
235
+ Would you like me to help reorganize?
236
+ - Move raw events to history/
237
+ - Distill remaining lessons into four-part format
238
+ - Remove or update stale references
239
+ ```
240
+
241
+ If the user agrees:
242
+ 1. Show proposed changes as diffs for each file, one at a time
243
+ 2. Wait for user confirmation before each write
244
+ 3. After all changes, run a focused re-check on modified files
245
+
246
+ ### 8. Recursive verification
247
+
248
+ After the user makes changes based on your suggestions:
249
+
250
+ 1. Re-read the modified files
251
+ 2. Run a focused check on the changed areas only
252
+ 3. Confirm the changes resolved the issues without introducing new ones
253
+ 4. If new issues are found, report them (one recursion only — don't loop)
254
+
255
+ ## Display Rules
256
+
257
+ - 🟢 **Healthy**: one line, no details needed
258
+ - 🟡 **Tension**: expand with specific quotes (file + line reference), explain the tension, suggest resolution
259
+ - 🔴 **Conflict**: expand with specific quotes, explain the conflict, suggest concrete action with priority
260
+ - Always quote the specific text from knowledge files that supports your finding
261
+ - End with a numbered list of suggested actions, ordered by priority ([High] / [Medium] / [Low])
262
+
263
+ ## Guidelines
264
+
265
+ - **Language**: Read `.knowy.json` → `language` field (e.g., `"zh-TW"`). Use that language for ALL output — section headers, descriptions, suggestions, everything. If `.knowy.json` is missing or has no language field, detect from conversation context or default to English.
266
+ - Be specific — always quote relevant text from knowledge files
267
+ - Distinguish between true contradictions (🔴) and tensions worth watching (🟡)
268
+ - Don't flag stylistic differences as inconsistencies
269
+ - For Project Alignment checks, actually read project files — don't guess
270
+ - Focus on substance: does the knowledge system help the team make good decisions?
271
+ - Never modify files automatically — only suggest changes
272
+ - After user makes changes, offer to re-check (recursive verification, once)
@@ -0,0 +1,128 @@
1
+ ---
2
+ name: knowy-next
3
+ description: Plan the next step based on project knowledge
4
+ user-invokable: true
5
+ argument-hint: "[direction or feature area to explore]"
6
+ ---
7
+
8
+ # Knowy Next
9
+
10
+ Help the user decide and plan what to work on next, grounded in the project's principles, vision, and experience.
11
+
12
+ ## User Input
13
+
14
+ ```text
15
+ $ARGUMENTS
16
+ ```
17
+
18
+ ## Governance Principles
19
+
20
+ - **Principles are the highest authority.** Every recommendation must be traceable to a principle. If it isn't, flag it as a pragmatic choice.
21
+ - **Vision is the roadmap.** Follow the established order unless experience provides compelling reason to deviate.
22
+ - **Experience is the guardrail.** Always check for relevant lessons before recommending an approach.
23
+ - **Never auto-invoke other skills.** Only suggest them.
24
+
25
+ ## Workflow
26
+
27
+ ### 1. Read knowledge files
28
+
29
+ Read all three core files:
30
+ - `.knowledge/principles.md`
31
+ - `.knowledge/vision.md`
32
+ - `.knowledge/experience.md`
33
+
34
+ Also check:
35
+ - `.knowledge/design/` for relevant design documents
36
+ - Project structure and recent git log for actual state
37
+
38
+ ### 2. Determine direction
39
+
40
+ **If `$ARGUMENTS` provides a direction** (e.g., "error handling", "mobile support"):
41
+ - Locate it in the vision roadmap
42
+ - Check prerequisites — are prior milestones actually complete? (check code, not just what vision says)
43
+ - Find relevant experience entries (lessons, pitfalls, patterns)
44
+ - Find relevant design documents
45
+ - Check if principles constrain the approach
46
+
47
+ **If `$ARGUMENTS` is empty**:
48
+ - Look at the vision roadmap for the next incomplete milestone
49
+ - Cross-reference with actual project state (what's really done?)
50
+ - Consider experience lessons that might affect priority
51
+ - Suggest the most logical next step with justification
52
+
53
+ ### 3. Converge
54
+
55
+ Through conversation with the user, converge on all of these items:
56
+
57
+ - **Feature name**: short, descriptive
58
+ - **One-line description**: what it delivers to the user/system
59
+ - **Roadmap position**: which phase/milestone it belongs to
60
+ - **Prerequisites**: what must be done first (check if actually done)
61
+ - **Scope**:
62
+ - What's included (explicit list)
63
+ - What's explicitly excluded (prevent scope creep)
64
+ - **Grounded in principles**: which principle(s) this serves, and how. Show the derivation chain.
65
+ - **Informed by experience**: relevant lesson(s) and how to apply them. Quote the specific lesson.
66
+ - **Risks**: based on experience, what could go wrong? What mitigation is available?
67
+ - **Success criteria**: how do we know this is done? Make it concrete and verifiable.
68
+
69
+ ### 4. Output
70
+
71
+ Present a concise feature brief:
72
+
73
+ ```markdown
74
+ ## Next: [Feature Name]
75
+
76
+ **Description**: [One-line description]
77
+
78
+ **Roadmap**: [Phase/milestone reference]
79
+
80
+ **Prerequisites**:
81
+ - [x] [Completed prerequisite]
82
+ - [ ] [Missing prerequisite — must be addressed first]
83
+
84
+ **Scope**:
85
+ - ✅ [Included]
86
+ - ✅ [Included]
87
+ - ❌ [Explicitly excluded]
88
+
89
+ **Grounded in principles**:
90
+ - Principle: "[quoted principle]"
91
+ - How this feature serves it: [explanation]
92
+
93
+ **Informed by experience**:
94
+ - Lesson: "[quoted lesson from experience.md]"
95
+ - How to apply: [specific guidance for this feature]
96
+
97
+ **Risks**:
98
+ - [Known risk from experience] → Mitigation: [approach]
99
+
100
+ **Success criteria**:
101
+ - [ ] [Concrete, verifiable criterion]
102
+ - [ ] [Concrete, verifiable criterion]
103
+ ```
104
+
105
+ ### 5. Suggest next action
106
+
107
+ After presenting the feature brief, scan the project for spec/planning tools:
108
+
109
+ - Check `.claude/skills/` for spec-related skills (e.g., `speckit-specify`, `speckit-plan`)
110
+ - Check `.specify/` for Speckit
111
+ - Check `openspec/` for OpenSpec
112
+ - Check `.kiro/specs/` for Kiro Specs
113
+
114
+ **If a spec tool is found**: suggest the specific command.
115
+ Example: "You can now use `/speckit-specify` to create a detailed specification for this feature."
116
+
117
+ **If no spec tool is found**: give a generic prompt.
118
+ "You can now use your preferred specification tool to flesh out the details, or start implementing directly."
119
+
120
+ ## Guidelines
121
+
122
+ - **Language**: Read `.knowy.json` → `language` field (e.g., `"zh-TW"`). Use that language for ALL output — section headers, descriptions, suggestions, everything. If `.knowy.json` is missing or has no language field, detect from conversation context or default to English.
123
+ - Keep the feature brief concise — it's a starting point, not a full spec
124
+ - **Every recommendation must reference knowledge files.** Don't invent principles or cite non-existent experience. If there's no relevant principle, say so explicitly.
125
+ - Verify project state before claiming prerequisites are met — check actual code, not just what vision says
126
+ - If the user's direction conflicts with principles or experience, flag it clearly with the specific conflict, but let them decide
127
+ - If the roadmap is empty or unclear, help the user think through priorities rather than guessing
128
+ - Never auto-invoke other skills — only suggest them
@@ -0,0 +1,142 @@
1
+ ---
2
+ name: knowy-update
3
+ description: Check knowledge file structure completeness and suggest improvements
4
+ user-invokable: true
5
+ argument-hint: "[specific file or area to check]"
6
+ ---
7
+
8
+ # Knowy Update
9
+
10
+ Review existing knowledge files against the latest templates, governance principles, and actual project state. Suggest structural improvements.
11
+
12
+ ## User Input
13
+
14
+ ```text
15
+ $ARGUMENTS
16
+ ```
17
+
18
+ ## Governance Principles
19
+
20
+ - **Principles are the highest authority.** If the structure check reveals that principles are weak or missing derivation chains, this is the highest priority fix.
21
+ - **Vision evolves with understanding.** Suggest updates when the project has moved forward but vision hasn't caught up.
22
+ - **Experience is distilled, not accumulated.** If experience.md is growing too long, suggest distilling. If history/ has entries that should be promoted, flag them.
23
+ - **Knowledge files are indexes, not encyclopedias.** If any core file exceeds ~200 lines, suggest moving detail to subdirectories.
24
+ - **Never modify files without explicit user confirmation.**
25
+
26
+ ## Workflow
27
+
28
+ ### 1. Read current state
29
+
30
+ - Read `.knowledge/principles.md`, `.knowledge/vision.md`, `.knowledge/experience.md`
31
+ - Read `.knowledge/.templates/` for the latest recommended structure
32
+ - Scan `.knowledge/research/`, `.knowledge/design/`, `.knowledge/history/` for existing files
33
+ - Read project structure and recent git log for context
34
+
35
+ ### 2. Structural check
36
+
37
+ Compare each core file against its template. Look for:
38
+
39
+ - **Missing sections**: template suggests a section that the file doesn't have
40
+ - **Empty sections**: section header exists but no content below it
41
+ - **Orphaned content**: content that doesn't fit any recommended section
42
+ - **Overgrown files**: core files exceeding ~200 lines (should move detail to subdirectories)
43
+ - **Weak derivations**: principles without clear derivation chains
44
+ - **Vague milestones**: vision roadmap items without success criteria
45
+ - **Undistilled lessons**: experience entries that are raw events rather than patterns
46
+
47
+ ### 3. Cross-file check
48
+
49
+ - Do principles reference concepts that aren't in the vision?
50
+ - Does experience mention lessons that should update the vision?
51
+ - Are there subdirectory files mature enough to distill into core files?
52
+ - Is the three-file system coherent as a whole?
53
+
54
+ ### 4. Project alignment check
55
+
56
+ - Has the project evolved since the knowledge files were last updated?
57
+ - Are there new features, dependencies, or architectural changes not reflected?
58
+ - Does the git log show recent work that should generate experience entries?
59
+
60
+ ### 5. Report
61
+
62
+ Present findings organized by priority:
63
+
64
+ ```
65
+ ## Structure Check
66
+
67
+ ### principles.md
68
+ 🟢 Root Axiom — present and clearly stated.
69
+ 🟡 Derived Principles — only 1 principle listed, template suggests at least 2-3.
70
+ 🔴 Derivation chains — missing. Principles don't trace back to root axiom.
71
+ → Add "Derived from: [root axiom]" to each principle.
72
+
73
+ ### vision.md
74
+ 🟢 Problem Statement — present and specific.
75
+ 🟢 Current State — honest and up-to-date.
76
+ 🟡 Roadmap — has milestones but no success criteria.
77
+ → Add concrete success criteria to each milestone.
78
+
79
+ ### experience.md
80
+ 🟢 Structure follows template format.
81
+ 🟡 Lesson "caching strategy" (line 23) reads like a raw event, not a distilled pattern.
82
+ → Rewrite using: Theory said X → Actually Y → Solved by Z → Lesson: W
83
+
84
+ ### Subdirectories
85
+ 🟡 design/auth-system.md looks mature — consider distilling key decisions into vision.md.
86
+ 🟡 history/ has 3 new entries since last experience.md update — review for distillation.
87
+
88
+ ### Project Alignment
89
+ 🟡 git log shows 12 commits since last vision update. Phase 2 may be complete.
90
+ → Verify and update roadmap status.
91
+
92
+ ## Suggested Actions (by priority)
93
+ 1. [High] Add derivation chains to principles.md
94
+ 2. [Medium] Add success criteria to roadmap milestones
95
+ 3. [Medium] Distill recent history/ entries into experience.md
96
+ 4. [Low] Review design/auth-system.md for vision.md update
97
+ ```
98
+
99
+ ### 6. Reorganization offer
100
+
101
+ When structural problems are severe enough to warrant reorganization, offer proactively:
102
+
103
+ - **Overgrown core file** (>200 lines): Propose extracting detail to subdirectories.
104
+ - principles.md → move research/exploration to research/
105
+ - vision.md → move detailed designs to design/
106
+ - experience.md → move raw events to history/, keep only distilled lessons
107
+ - **Wrong format**: Propose reformatting entries to match template structure.
108
+ - experience lessons not in four-part format (Theory said → Actually → Resolved by → Lesson)
109
+ - principles without derivation chains
110
+ - roadmap milestones without success criteria
111
+ - **Stale content**: Propose removing or archiving outdated entries.
112
+ - **Mature subdirectory content**: Propose distilling into core files.
113
+
114
+ Format:
115
+
116
+ ```markdown
117
+ ## Reorganization Suggested
118
+
119
+ experience.md has grown to 280 lines (recommended: ~200).
120
+ - 5 lessons appear to be raw events → move to history/, distill patterns
121
+ - 3 lessons reference rewritten code → update or archive
122
+
123
+ Would you like me to help reorganize?
124
+ ```
125
+
126
+ If the user agrees, proceed step by step (one file at a time, show diff, wait for confirmation).
127
+
128
+ ### 7. Assist with changes
129
+
130
+ - If the user wants to act on any suggestion, help them make the change
131
+ - Before writing, verify the change is consistent with other knowledge files
132
+ - Show diffs before writing
133
+ - After writing, offer a focused re-check on the changed area
134
+
135
+ ## Guidelines
136
+
137
+ - **Language**: Read `.knowy.json` → `language` field (e.g., `"zh-TW"`). Use that language for ALL output — section headers, descriptions, suggestions, everything. If `.knowy.json` is missing or has no language field, detect from conversation context or default to English.
138
+ - Be constructive, not critical — the goal is to help, not to grade
139
+ - Prioritize by impact: what would help the AI (and the team) most?
140
+ - Don't suggest adding content the user may not have yet — only structural improvements
141
+ - For project alignment, actually read project files — don't guess
142
+ - If you notice the knowledge files are getting stale, say so directly
@@ -0,0 +1,38 @@
1
+ import { access, stat } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { TOOL_REGISTRY } from './registry.js';
4
+
5
+ async function checkDetect(projectRoot, check) {
6
+ const fullPath = join(projectRoot, check.path);
7
+ try {
8
+ const s = await stat(fullPath);
9
+ if (check.type === 'file') return s.isFile();
10
+ if (check.type === 'dir') return s.isDirectory();
11
+ return false;
12
+ } catch {
13
+ return false;
14
+ }
15
+ }
16
+
17
+ /**
18
+ * Scan the project for installed AI/spec tools.
19
+ * Returns { detected: string[], available: string[] }
20
+ * detected — tool ids whose config files exist
21
+ * available — all tool ids that could be selected
22
+ */
23
+ export async function detectTools(projectRoot) {
24
+ const detected = [];
25
+
26
+ for (const tool of TOOL_REGISTRY) {
27
+ if (tool.detect.length === 0) continue;
28
+ for (const check of tool.detect) {
29
+ if (await checkDetect(projectRoot, check)) {
30
+ detected.push(tool.id);
31
+ break;
32
+ }
33
+ }
34
+ }
35
+
36
+ const available = TOOL_REGISTRY.map(t => t.id);
37
+ return { detected, available };
38
+ }
@@ -0,0 +1,93 @@
1
+ import { readFile, writeFile, mkdir } from 'node:fs/promises';
2
+ import { join, dirname } from 'node:path';
3
+ import { MARKER_START, MARKER_END, KNOWLEDGE_DIR } from '../constants.js';
4
+
5
+ const SNIPPET = `${MARKER_START}
6
+ ## Project Knowledge
7
+
8
+ This project maintains structured knowledge in \`${KNOWLEDGE_DIR}/\`:
9
+
10
+ - **Principles** (\`${KNOWLEDGE_DIR}/principles.md\`): Core axioms and derived development principles — the project's non-negotiable rules.
11
+ - **Vision** (\`${KNOWLEDGE_DIR}/vision.md\`): Goals, current state, architecture decisions, and roadmap.
12
+ - **Experience** (\`${KNOWLEDGE_DIR}/experience.md\`): Distilled lessons from past development — patterns, pitfalls, and takeaways.
13
+
14
+ Read these files at the start of any task to understand the project's *why* and constraints.
15
+ Additional context may be found in \`${KNOWLEDGE_DIR}/research/\`, \`${KNOWLEDGE_DIR}/design/\`, and \`${KNOWLEDGE_DIR}/history/\`.
16
+ ${MARKER_END}`;
17
+
18
+ const MDC_SNIPPET = `---
19
+ description: Project knowledge context from Knowy
20
+ globs:
21
+ alwaysApply: true
22
+ ---
23
+
24
+ ${SNIPPET}`;
25
+
26
+ function buildSnippet(format) {
27
+ if (format === 'mdc') return MDC_SNIPPET;
28
+ return SNIPPET;
29
+ }
30
+
31
+ /**
32
+ * Inject or update the Knowy reference in a tool's config file.
33
+ * Creates the file (and parent dirs) if it doesn't exist.
34
+ */
35
+ export async function injectHandshake(projectRoot, target) {
36
+ const filePath = join(projectRoot, target.file);
37
+ const snippet = buildSnippet(target.format);
38
+
39
+ await mkdir(dirname(filePath), { recursive: true });
40
+
41
+ let content;
42
+ try {
43
+ content = await readFile(filePath, 'utf-8');
44
+ } catch {
45
+ // File doesn't exist — create with just the snippet
46
+ await writeFile(filePath, snippet + '\n');
47
+ return { action: 'created', file: target.file };
48
+ }
49
+
50
+ // Check if markers already exist
51
+ const startIdx = content.indexOf(MARKER_START);
52
+ const endIdx = content.indexOf(MARKER_END);
53
+
54
+ if (startIdx !== -1 && endIdx !== -1) {
55
+ // Replace between markers (inclusive)
56
+ const before = content.slice(0, startIdx);
57
+ const after = content.slice(endIdx + MARKER_END.length);
58
+ await writeFile(filePath, before + snippet + after);
59
+ return { action: 'updated', file: target.file };
60
+ }
61
+
62
+ // Append
63
+ const separator = content.endsWith('\n') ? '\n' : '\n\n';
64
+ await writeFile(filePath, content + separator + snippet + '\n');
65
+ return { action: 'appended', file: target.file };
66
+ }
67
+
68
+ /**
69
+ * Remove the Knowy reference from a file.
70
+ */
71
+ export async function removeHandshake(projectRoot, target) {
72
+ const filePath = join(projectRoot, target.file);
73
+ let content;
74
+ try {
75
+ content = await readFile(filePath, 'utf-8');
76
+ } catch {
77
+ return { action: 'not_found', file: target.file };
78
+ }
79
+
80
+ const startIdx = content.indexOf(MARKER_START);
81
+ const endIdx = content.indexOf(MARKER_END);
82
+
83
+ if (startIdx === -1 || endIdx === -1) {
84
+ return { action: 'no_markers', file: target.file };
85
+ }
86
+
87
+ const before = content.slice(0, startIdx);
88
+ const after = content.slice(endIdx + MARKER_END.length);
89
+ // Clean up extra blank lines
90
+ const cleaned = (before + after).replace(/\n{3,}/g, '\n\n').trim();
91
+ await writeFile(filePath, cleaned ? cleaned + '\n' : '');
92
+ return { action: 'removed', file: target.file };
93
+ }