connore 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/README.md +13 -8
  2. package/package.json +2 -1
  3. package/packs/base/planning/START.md +29 -28
  4. package/packs/base/planning/blueprint-template.md +46 -46
  5. package/packs/base/planning/plan-template.md +46 -45
  6. package/packs/base/rules/anti-patterns.md +19 -16
  7. package/packs/base/rules/code-style.md +19 -16
  8. package/packs/base/rules/dependency-policy.md +19 -16
  9. package/packs/base/rules/error-handling.md +19 -16
  10. package/packs/base/rules/security-audit.md +47 -0
  11. package/packs/base/rules/security-baseline.md +19 -16
  12. package/packs/base/templates/bug-report.md +19 -16
  13. package/packs/base/templates/feature-spec.md +19 -16
  14. package/packs/base/templates/handoff.md +19 -16
  15. package/packs/base/templates/project-brief.md +19 -16
  16. package/packs/base/workflow/code-review.md +19 -16
  17. package/packs/base/workflow/debugging.md +18 -14
  18. package/packs/base/workflow/git-and-commits.md +19 -16
  19. package/packs/base/workflow/idea-to-spec.md +19 -16
  20. package/packs/base/workflow/session-handoff.md +19 -16
  21. package/packs/base/workflow/spec-to-plan.md +19 -16
  22. package/packs/knowledge/backend/api/conventions.md +21 -0
  23. package/packs/knowledge/backend/architecture/local-sqlite.md +20 -0
  24. package/packs/knowledge/backend/authentication/session-and-engine.md +24 -0
  25. package/packs/knowledge/backend/database/schema.md +21 -0
  26. package/packs/knowledge/components/custom/ambient-background.md +26 -0
  27. package/packs/knowledge/components/custom/ambient-background.tsx +12 -0
  28. package/packs/knowledge/components/custom/corner-frame.md +26 -0
  29. package/packs/knowledge/components/custom/corner-frame.tsx +48 -0
  30. package/packs/knowledge/components/custom/cta-button.md +26 -0
  31. package/packs/knowledge/components/custom/cta-button.tsx +10 -0
  32. package/packs/knowledge/components/custom/page-transition.md +26 -0
  33. package/packs/knowledge/components/custom/page-transition.tsx +10 -0
  34. package/packs/knowledge/components/custom/smooth-scroll.md +26 -0
  35. package/packs/knowledge/components/custom/smooth-scroll.tsx +32 -0
  36. package/packs/knowledge/components/motion-effects/README.md +30 -0
  37. package/packs/knowledge/components/ui-primitives/LICENSE +21 -0
  38. package/packs/knowledge/components/ui-primitives/README.md +22 -0
  39. package/packs/knowledge/components/ui-primitives/badge.md +26 -0
  40. package/packs/knowledge/components/ui-primitives/badge.tsx +48 -0
  41. package/packs/knowledge/components/ui-primitives/button.md +27 -0
  42. package/packs/knowledge/components/ui-primitives/button.tsx +66 -0
  43. package/packs/knowledge/components/ui-primitives/card.md +26 -0
  44. package/packs/knowledge/components/ui-primitives/card.tsx +102 -0
  45. package/packs/knowledge/components/ui-primitives/checkbox.md +26 -0
  46. package/packs/knowledge/components/ui-primitives/checkbox.tsx +32 -0
  47. package/packs/knowledge/components/ui-primitives/dialog.md +26 -0
  48. package/packs/knowledge/components/ui-primitives/dialog.tsx +168 -0
  49. package/packs/knowledge/components/ui-primitives/dropdown-menu.md +26 -0
  50. package/packs/knowledge/components/ui-primitives/dropdown-menu.tsx +268 -0
  51. package/packs/knowledge/components/ui-primitives/input.md +27 -0
  52. package/packs/knowledge/components/ui-primitives/input.tsx +18 -0
  53. package/packs/knowledge/components/ui-primitives/label.md +26 -0
  54. package/packs/knowledge/components/ui-primitives/label.tsx +23 -0
  55. package/packs/knowledge/components/ui-primitives/progress.md +26 -0
  56. package/packs/knowledge/components/ui-primitives/progress.tsx +30 -0
  57. package/packs/knowledge/components/ui-primitives/scroll-area.md +26 -0
  58. package/packs/knowledge/components/ui-primitives/scroll-area.tsx +54 -0
  59. package/packs/knowledge/components/ui-primitives/select.md +26 -0
  60. package/packs/knowledge/components/ui-primitives/select.tsx +191 -0
  61. package/packs/knowledge/components/ui-primitives/separator.md +26 -0
  62. package/packs/knowledge/components/ui-primitives/separator.tsx +27 -0
  63. package/packs/knowledge/components/ui-primitives/sonner.md +26 -0
  64. package/packs/knowledge/components/ui-primitives/sonner.tsx +49 -0
  65. package/packs/knowledge/components/ui-primitives/switch.md +26 -0
  66. package/packs/knowledge/components/ui-primitives/switch.tsx +32 -0
  67. package/packs/knowledge/components/ui-primitives/tabs.md +26 -0
  68. package/packs/knowledge/components/ui-primitives/tabs.tsx +89 -0
  69. package/packs/knowledge/components/ui-primitives/textarea.md +26 -0
  70. package/packs/knowledge/components/ui-primitives/textarea.tsx +17 -0
  71. package/packs/knowledge/components/ui-primitives/tooltip.md +26 -0
  72. package/packs/knowledge/components/ui-primitives/tooltip.tsx +56 -0
  73. package/packs/knowledge/design/aesthetics/app-shell.md +41 -0
  74. package/packs/knowledge/design/aesthetics/code-neutral.md +40 -0
  75. package/packs/knowledge/design/aesthetics/match.md +46 -0
  76. package/packs/knowledge/design/aesthetics/ruled-outline.md +40 -0
  77. package/packs/knowledge/design/aesthetics/solid-accent.md +43 -0
  78. package/packs/knowledge/design/animations/motion.md +40 -0
  79. package/packs/knowledge/design/project-style.md +50 -0
  80. package/packs/knowledge/design/references/benefit-card-grid.md +27 -0
  81. package/packs/knowledge/design/references/benefit-card-grid.png +0 -0
  82. package/packs/knowledge/design/references/cta-centered.md +27 -0
  83. package/packs/knowledge/design/references/cta-centered.png +0 -0
  84. package/packs/knowledge/design/references/cta-split-media.md +27 -0
  85. package/packs/knowledge/design/references/cta-split-media.png +0 -0
  86. package/packs/knowledge/design/references/dashboard-overview.md +31 -0
  87. package/packs/knowledge/design/references/dashboard-overview.png +0 -0
  88. package/packs/knowledge/design/references/faq-split-accordion.md +27 -0
  89. package/packs/knowledge/design/references/faq-split-accordion.png +0 -0
  90. package/packs/knowledge/design/references/feature-split-checklist.md +27 -0
  91. package/packs/knowledge/design/references/feature-split-checklist.png +0 -0
  92. package/packs/knowledge/design/references/footer-four-column.md +27 -0
  93. package/packs/knowledge/design/references/footer-four-column.png +0 -0
  94. package/packs/knowledge/design/references/footer-two-column.md +27 -0
  95. package/packs/knowledge/design/references/footer-two-column.png +0 -0
  96. package/packs/knowledge/design/references/hero-accent-curtain.md +27 -0
  97. package/packs/knowledge/design/references/hero-accent-curtain.png +0 -0
  98. package/packs/knowledge/design/references/hero-split-media.md +27 -0
  99. package/packs/knowledge/design/references/hero-split-media.png +0 -0
  100. package/packs/knowledge/design/references/logo-cloud-grid.md +27 -0
  101. package/packs/knowledge/design/references/logo-cloud-grid.png +0 -0
  102. package/packs/knowledge/design/references/logo-row-ruled.md +27 -0
  103. package/packs/knowledge/design/references/logo-row-ruled.png +0 -0
  104. package/packs/knowledge/design/references/pricing-three-card.md +27 -0
  105. package/packs/knowledge/design/references/pricing-three-card.png +0 -0
  106. package/packs/knowledge/design/references/steps-ruled-grid.md +27 -0
  107. package/packs/knowledge/design/references/steps-ruled-grid.png +0 -0
  108. package/packs/knowledge/design/rules.md +35 -0
  109. package/packs/knowledge/design/token-structure.md +46 -0
  110. package/packs/knowledge/design/tokens.md +55 -0
  111. package/packs/knowledge/frontend/README.md +50 -0
  112. package/packs/knowledge/frontend/SOURCES.md +40 -0
  113. package/packs/knowledge/frontend/accessibility/focus-and-dialogs.md +47 -0
  114. package/packs/knowledge/frontend/accessibility/semantics-and-keyboard.md +45 -0
  115. package/packs/knowledge/frontend/accessibility/wcag-targets.md +43 -0
  116. package/packs/knowledge/frontend/architecture/agent-context-files.md +43 -0
  117. package/packs/knowledge/frontend/architecture/app-foundations.md +43 -0
  118. package/packs/knowledge/frontend/architecture/error-handling.md +47 -0
  119. package/packs/knowledge/frontend/architecture/feature-modules.md +49 -0
  120. package/packs/knowledge/frontend/architecture/import-boundaries.md +44 -0
  121. package/packs/knowledge/frontend/architecture/naming.md +43 -0
  122. package/packs/knowledge/frontend/architecture/project-structure.md +48 -0
  123. package/packs/knowledge/frontend/architecture/routing.md +45 -0
  124. package/packs/knowledge/frontend/architecture/security.md +44 -0
  125. package/packs/knowledge/frontend/architecture/typescript.md +44 -0
  126. package/packs/knowledge/frontend/components/composition.md +45 -0
  127. package/packs/knowledge/frontend/components/data-display.md +47 -0
  128. package/packs/knowledge/frontend/components/library-choice.md +45 -0
  129. package/packs/knowledge/frontend/components/variants.md +44 -0
  130. package/packs/knowledge/frontend/forms/form-architecture.md +49 -0
  131. package/packs/knowledge/frontend/forms/multi-step.md +43 -0
  132. package/packs/knowledge/frontend/forms/validation.md +47 -0
  133. package/packs/knowledge/frontend/layout/responsive.md +41 -0
  134. package/packs/knowledge/frontend/page-blueprints/app-shell.md +16 -0
  135. package/packs/knowledge/frontend/page-blueprints/faq-footer.md +22 -0
  136. package/packs/knowledge/frontend/page-blueprints/feature-grid.md +22 -0
  137. package/packs/knowledge/frontend/page-blueprints/pricing.md +16 -0
  138. package/packs/knowledge/frontend/page-blueprints/saas-hero.md +24 -0
  139. package/packs/knowledge/frontend/patterns/dark-marketing.md +18 -0
  140. package/packs/knowledge/frontend/patterns/status-pill.md +19 -0
  141. package/packs/knowledge/frontend/performance/code-splitting.md +47 -0
  142. package/packs/knowledge/frontend/performance/images-and-vitals.md +44 -0
  143. package/packs/knowledge/frontend/performance/rendering.md +40 -0
  144. package/packs/knowledge/frontend/rendering/server-and-client.md +50 -0
  145. package/packs/knowledge/frontend/state/api-layer.md +49 -0
  146. package/packs/knowledge/frontend/state/async-ui-states.md +43 -0
  147. package/packs/knowledge/frontend/state/client-store.md +46 -0
  148. package/packs/knowledge/frontend/state/server-cache.md +42 -0
  149. package/packs/knowledge/frontend/state/state-categories.md +50 -0
  150. package/packs/knowledge/frontend/testing/component-tests.md +44 -0
  151. package/packs/knowledge/frontend/testing/strategy.md +46 -0
  152. package/packs/knowledge/inbox/README.md +14 -0
  153. package/packs/knowledge/workflows/authentication.md +18 -0
  154. package/packs/knowledge/workflows/crud.md +20 -0
  155. package/packs/knowledge/workflows/dashboard.md +22 -0
  156. package/packs/nextjs-fullstack/backend/auth-and-roles.md +19 -16
  157. package/packs/nextjs-fullstack/backend/background-jobs.md +19 -16
  158. package/packs/nextjs-fullstack/backend/caching.md +17 -14
  159. package/packs/nextjs-fullstack/backend/database.md +19 -16
  160. package/packs/nextjs-fullstack/backend/file-uploads.md +19 -16
  161. package/packs/nextjs-fullstack/backend/logging.md +17 -14
  162. package/packs/nextjs-fullstack/backend/migrations.md +17 -14
  163. package/packs/nextjs-fullstack/backend/rate-limiting.md +19 -16
  164. package/packs/nextjs-fullstack/backend/secrets-and-env.md +19 -16
  165. package/packs/nextjs-fullstack/backend/validation.md +19 -16
  166. package/packs/nextjs-fullstack/blueprints/ai-app.md +1 -1
  167. package/packs/nextjs-fullstack/blueprints/internal-tool.md +1 -1
  168. package/packs/nextjs-fullstack/blueprints/saas-app.md +1 -1
  169. package/packs/nextjs-fullstack/build-deploy/ci.md +18 -16
  170. package/packs/nextjs-fullstack/build-deploy/deploy.md +19 -16
  171. package/packs/nextjs-fullstack/build-deploy/monitoring.md +16 -14
  172. package/packs/nextjs-fullstack/build-deploy/performance.md +17 -14
  173. package/packs/nextjs-fullstack/build-deploy/project-structure.md +18 -16
  174. package/packs/nextjs-fullstack/build-deploy/release-checklist.md +20 -16
  175. package/packs/nextjs-fullstack/build-deploy/testing.md +19 -16
  176. package/packs/nextjs-fullstack/evals/README.md +18 -15
  177. package/packs/nextjs-fullstack/examples/golden-app/README.md +18 -16
  178. package/packs/nextjs-fullstack/frontend/accessibility.md +17 -14
  179. package/packs/nextjs-fullstack/frontend/components.md +19 -16
  180. package/packs/nextjs-fullstack/frontend/copy.md +46 -0
  181. package/packs/nextjs-fullstack/frontend/data-fetching.md +46 -0
  182. package/packs/nextjs-fullstack/frontend/forms.md +17 -14
  183. package/packs/nextjs-fullstack/frontend/layout.md +19 -16
  184. package/packs/nextjs-fullstack/frontend/loading-empty-error.md +19 -16
  185. package/packs/nextjs-fullstack/frontend/motion.md +17 -14
  186. package/packs/nextjs-fullstack/frontend/responsive.md +19 -16
  187. package/packs/nextjs-fullstack/frontend/seo.md +20 -16
  188. package/packs/nextjs-fullstack/frontend/tables.md +17 -14
  189. package/packs/nextjs-fullstack/frontend/tokens.md +18 -16
  190. package/packs/nextjs-fullstack/integrations/analytics.md +17 -14
  191. package/packs/nextjs-fullstack/integrations/email.md +17 -14
  192. package/packs/nextjs-fullstack/integrations/llm-apis.md +19 -16
  193. package/packs/nextjs-fullstack/integrations/oauth.md +19 -16
  194. package/packs/nextjs-fullstack/integrations/object-storage.md +19 -16
  195. package/packs/nextjs-fullstack/integrations/payments.md +17 -14
  196. package/packs/nextjs-fullstack/integrations/queues.md +17 -14
  197. package/packs/nextjs-fullstack/integrations/search.md +19 -16
  198. package/packs/nextjs-fullstack/integrations/webhooks.md +17 -14
  199. package/packs/nextjs-fullstack/playbooks/add-ai-feature.md +19 -16
  200. package/packs/nextjs-fullstack/playbooks/add-auth.md +19 -16
  201. package/packs/nextjs-fullstack/playbooks/add-crud.md +19 -16
  202. package/packs/nextjs-fullstack/playbooks/add-email.md +19 -16
  203. package/packs/nextjs-fullstack/playbooks/add-file-upload.md +19 -16
  204. package/packs/nextjs-fullstack/playbooks/add-webhook.md +19 -16
  205. package/packs/nextjs-fullstack/playbooks/ship-to-prod.md +20 -16
  206. package/plugins/connore/.claude-plugin/plugin.json +10 -0
  207. package/plugins/connore/hooks/hooks.json +16 -0
  208. package/plugins/connore/skills/connore-backend/SKILL.md +32 -0
  209. package/plugins/connore/skills/connore-handoff/SKILL.md +15 -0
  210. package/plugins/connore/skills/connore-routes/SKILL.md +16 -0
  211. package/plugins/connore/skills/connore-validate/SKILL.md +15 -0
  212. package/src/cli.js +110 -21
  213. package/src/commands/doctor.js +2 -0
  214. package/src/commands/edit.js +88 -0
  215. package/src/commands/graph.js +20 -0
  216. package/src/commands/handoff.js +45 -0
  217. package/src/commands/init.js +8 -3
  218. package/src/commands/lint.js +13 -5
  219. package/src/commands/log.js +49 -25
  220. package/src/commands/packs.js +21 -0
  221. package/src/commands/routes.js +13 -0
  222. package/src/commands/search.js +7 -2
  223. package/src/commands/update.js +5 -1
  224. package/src/lib/config.js +67 -64
  225. package/src/lib/graph.js +96 -0
  226. package/src/lib/index.js +88 -72
  227. package/src/lib/lessons.js +173 -173
  228. package/src/lib/lint.js +185 -67
  229. package/src/lib/mutate.js +26 -24
  230. package/src/lib/packs.js +25 -10
  231. package/src/lib/paths.js +1 -1
  232. package/src/lib/prompts.js +66 -0
  233. package/src/lib/report.js +41 -33
  234. package/src/lib/routes.js +59 -0
  235. package/src/lib/run.js +116 -73
  236. package/src/lib/search.js +24 -0
  237. package/src/lib/tokens.js +8 -0
@@ -1,173 +1,173 @@
1
- import { readFile } from "node:fs/promises"
2
- import { join } from "node:path"
3
- import { exists, readOptional, removeFile, walkFiles } from "./fs-safe.js"
4
- import { parseFrontmatter } from "./frontmatter.js"
5
- import { commitWrite } from "./mutate.js"
6
- import { fromRoot } from "./paths.js"
7
-
8
- export function lessonFile(lesson) {
9
- const files = lesson.files ? `\nfiles: ${lesson.files}` : ""
10
- const flagged = lesson.flagged ? `\nflagged: ${lesson.flagged}` : ""
11
- const stale = lesson.stale ? `\nstale: true` : ""
12
- return `---
13
- title: ${one(lesson.title)}
14
- type: lesson
15
- tags: [lesson]
16
- stack: project
17
- status: ${lesson.status || "proposed"}
18
- scope: ${lesson.scope || "project"}
19
- trigger: ${one(lesson.trigger)}
20
- mistake: ${one(lesson.mistake)}
21
- fix: ${one(lesson.fix)}
22
- evidence: ${one(lesson.evidence)}
23
- confidence: ${lesson.confidence || "medium"}
24
- source: ${lesson.source || "agent-inferred"}
25
- last_seen: ${lesson.lastSeen || ""}${files}${flagged}${stale}
26
- description: ${one(lesson.mistake)}
27
- ---
28
-
29
- # ${one(lesson.title)}
30
-
31
- Watch-out: ${one(lesson.mistake)}
32
- Fix: ${one(lesson.fix)}
33
- `
34
- }
35
-
36
- function one(value) {
37
- return String(value || "").replace(/\s+/g, " ").trim()
38
- }
39
-
40
- export function proposedDir(root) {
41
- return join(root, ".ctx", "mine", "lessons", "_proposed")
42
- }
43
-
44
- export function acceptedDir(root) {
45
- return join(root, ".ctx", "mine", "lessons")
46
- }
47
-
48
- export async function writeProposal(root, id, lesson, report) {
49
- const file = join(proposedDir(root), `${id}.md`)
50
- await commitWrite(file, lessonFile({ ...lesson, status: "proposed" }), report, fromRoot(root, file))
51
- return file
52
- }
53
-
54
- async function readLessonFile(file) {
55
- const text = await readFile(file, "utf8")
56
- const data = parseFrontmatter(text)
57
- if (!data || data.type !== "lesson") return null
58
- return {
59
- file,
60
- id: file.split(/[/\\]/).pop().replace(/\.md$/, ""),
61
- title: data.title || "",
62
- status: data.status || "",
63
- scope: data.scope || "project",
64
- trigger: data.trigger || "",
65
- mistake: data.mistake || "",
66
- fix: data.fix || "",
67
- evidence: data.evidence || "",
68
- confidence: data.confidence || "medium",
69
- source: data.source || "agent-inferred",
70
- files: data.files || "",
71
- lastSeen: data.last_seen || "",
72
- flagged: data.flagged || "",
73
- stale: data.stale === "true",
74
- }
75
- }
76
-
77
- export async function listProposals(root) {
78
- const lessons = []
79
- for (const file of await walkFiles(proposedDir(root))) {
80
- if (!file.endsWith(".md")) continue
81
- const lesson = await readLessonFile(file)
82
- if (lesson?.status === "proposed") lessons.push(lesson)
83
- }
84
- return lessons
85
- }
86
-
87
- export async function listAccepted(root) {
88
- const dir = acceptedDir(root)
89
- const lessons = []
90
- for (const file of await walkFiles(dir)) {
91
- if (!file.endsWith(".md")) continue
92
- if (file.includes(`${join("lessons", "_proposed")}`) || file.includes(`${join("lessons", "_rejected")}`)) continue
93
- const lesson = await readLessonFile(file)
94
- if (lesson?.status === "accepted") lessons.push(lesson)
95
- }
96
- return lessons
97
- }
98
-
99
- export async function moveProposal(root, id, status, report, edits = {}) {
100
- const source = join(proposedDir(root), `${id}.md`)
101
- if (!(await exists(source))) throw new Error(`No proposal "${id}".`)
102
- const current = await readLessonFile(source)
103
- const lesson = {
104
- ...current,
105
- ...edits,
106
- status,
107
- lastSeen: status === "accepted" ? new Date().toISOString().slice(0, 10) : current.lastSeen,
108
- }
109
- const destDir = status === "accepted" ? acceptedDir(root) : join(acceptedDir(root), "_rejected")
110
- const dest = join(destDir, `${id}.md`)
111
- await commitWrite(dest, lessonFile(lesson), report, fromRoot(root, dest))
112
- const previous = await readOptional(source)
113
- if (previous) {
114
- if (!report.dryRun) await removeFile(source)
115
- report.add("removed", fromRoot(root, source), { previous })
116
- }
117
- return lesson
118
- }
119
-
120
- export function watchLine(lesson) {
121
- return `- ${lesson.trigger}: ${lesson.mistake} Fix: ${lesson.fix}`
122
- }
123
-
124
- export function selectLessons(lessons, changed, { limit = 5, budget = 400 } = {}) {
125
- const paths = changed.map((file) => file.replace(/\\/g, "/"))
126
- const ranked = []
127
- for (const lesson of lessons) {
128
- if (lesson.status !== "accepted" || lesson.stale) continue
129
- const files = String(lesson.files || "").split(",").map((file) => file.trim()).filter(Boolean)
130
- const trigger = String(lesson.trigger || "").toLowerCase()
131
- let score = 0
132
- for (const path of paths) {
133
- if (files.some((file) => path === file || path.endsWith(file))) score += 3
134
- else if (trigger && path.toLowerCase().includes(trigger.replace(/^when editing /, ""))) score += 1
135
- }
136
- if (score > 0) ranked.push({ lesson, score })
137
- }
138
- ranked.sort((a, b) => b.score - a.score || a.lesson.id.localeCompare(b.lesson.id))
139
- const chosen = []
140
- let used = 0
141
- for (const item of ranked) {
142
- if (chosen.length >= limit) break
143
- const cost = Math.max(1, Math.ceil(watchLine(item.lesson).length / 4))
144
- if (used + cost > budget) continue
145
- used += cost
146
- chosen.push(item.lesson)
147
- }
148
- return chosen
149
- }
150
-
151
- export function lessonBlock(lessons) {
152
- if (!lessons.length) return ""
153
- return `\nWatch-outs\n${lessons.map(watchLine).join("\n")}\n`
154
- }
155
-
156
- const DAY = 24 * 60 * 60 * 1000
157
-
158
- export async function markLessonHealth(root, signals, report, now = new Date()) {
159
- for (const lesson of await listAccepted(root)) {
160
- const seen = Date.parse(lesson.lastSeen)
161
- const stale = Number.isFinite(seen) && now.getTime() - seen > 90 * DAY
162
- const recurring = signals.some((signal) => {
163
- if (signal.kind !== "failure" || !lesson.mistake) return false
164
- const at = Date.parse(signal.at)
165
- if (Number.isFinite(seen) && Number.isFinite(at) && at < seen) return false
166
- return String(signal.text || "").toLowerCase().includes(lesson.mistake.toLowerCase())
167
- })
168
- if (!stale && !recurring) continue
169
- if (Boolean(lesson.stale) === stale && (lesson.flagged === "recurring") === recurring) continue
170
- const next = { ...lesson, stale, flagged: recurring ? "recurring" : lesson.flagged }
171
- await commitWrite(lesson.file, lessonFile(next), report, fromRoot(root, lesson.file))
172
- }
173
- }
1
+ import { readFile } from "node:fs/promises"
2
+ import { join } from "node:path"
3
+ import { exists, readOptional, removeFile, walkFiles } from "./fs-safe.js"
4
+ import { parseFrontmatter } from "./frontmatter.js"
5
+ import { commitWrite } from "./mutate.js"
6
+ import { fromRoot } from "./paths.js"
7
+
8
+ export function lessonFile(lesson) {
9
+ const files = lesson.files ? `\nfiles: ${lesson.files}` : ""
10
+ const flagged = lesson.flagged ? `\nflagged: ${lesson.flagged}` : ""
11
+ const stale = lesson.stale ? `\nstale: true` : ""
12
+ return `---
13
+ title: ${one(lesson.title)}
14
+ type: lesson
15
+ tags: [lesson]
16
+ stack: project
17
+ status: ${lesson.status || "proposed"}
18
+ scope: ${lesson.scope || "project"}
19
+ trigger: ${one(lesson.trigger)}
20
+ mistake: ${one(lesson.mistake)}
21
+ fix: ${one(lesson.fix)}
22
+ evidence: ${one(lesson.evidence)}
23
+ confidence: ${lesson.confidence || "medium"}
24
+ source: ${lesson.source || "agent-inferred"}
25
+ last_seen: ${lesson.lastSeen || ""}${files}${flagged}${stale}
26
+ description: ${one(lesson.mistake)}
27
+ ---
28
+
29
+ # ${one(lesson.title)}
30
+
31
+ Watch-out: ${one(lesson.mistake)}
32
+ Fix: ${one(lesson.fix)}
33
+ `
34
+ }
35
+
36
+ function one(value) {
37
+ return String(value || "").replace(/\s+/g, " ").trim()
38
+ }
39
+
40
+ export function proposedDir(root) {
41
+ return join(root, ".ctx", "mine", "lessons", "_proposed")
42
+ }
43
+
44
+ export function acceptedDir(root) {
45
+ return join(root, ".ctx", "mine", "lessons")
46
+ }
47
+
48
+ export async function writeProposal(root, id, lesson, report) {
49
+ const file = join(proposedDir(root), `${id}.md`)
50
+ await commitWrite(file, lessonFile({ ...lesson, status: "proposed" }), report, fromRoot(root, file))
51
+ return file
52
+ }
53
+
54
+ async function readLessonFile(file) {
55
+ const text = await readFile(file, "utf8")
56
+ const data = parseFrontmatter(text)
57
+ if (!data || data.type !== "lesson") return null
58
+ return {
59
+ file,
60
+ id: file.split(/[/\\]/).pop().replace(/\.md$/, ""),
61
+ title: data.title || "",
62
+ status: data.status || "",
63
+ scope: data.scope || "project",
64
+ trigger: data.trigger || "",
65
+ mistake: data.mistake || "",
66
+ fix: data.fix || "",
67
+ evidence: data.evidence || "",
68
+ confidence: data.confidence || "medium",
69
+ source: data.source || "agent-inferred",
70
+ files: data.files || "",
71
+ lastSeen: data.last_seen || "",
72
+ flagged: data.flagged || "",
73
+ stale: data.stale === "true",
74
+ }
75
+ }
76
+
77
+ export async function listProposals(root) {
78
+ const lessons = []
79
+ for (const file of await walkFiles(proposedDir(root))) {
80
+ if (!file.endsWith(".md")) continue
81
+ const lesson = await readLessonFile(file)
82
+ if (lesson?.status === "proposed") lessons.push(lesson)
83
+ }
84
+ return lessons
85
+ }
86
+
87
+ export async function listAccepted(root) {
88
+ const dir = acceptedDir(root)
89
+ const lessons = []
90
+ for (const file of await walkFiles(dir)) {
91
+ if (!file.endsWith(".md")) continue
92
+ if (file.includes(`${join("lessons", "_proposed")}`) || file.includes(`${join("lessons", "_rejected")}`)) continue
93
+ const lesson = await readLessonFile(file)
94
+ if (lesson?.status === "accepted") lessons.push(lesson)
95
+ }
96
+ return lessons
97
+ }
98
+
99
+ export async function moveProposal(root, id, status, report, edits = {}) {
100
+ const source = join(proposedDir(root), `${id}.md`)
101
+ if (!(await exists(source))) throw new Error(`No proposal "${id}".`)
102
+ const current = await readLessonFile(source)
103
+ const lesson = {
104
+ ...current,
105
+ ...edits,
106
+ status,
107
+ lastSeen: status === "accepted" ? new Date().toISOString().slice(0, 10) : current.lastSeen,
108
+ }
109
+ const destDir = status === "accepted" ? acceptedDir(root) : join(acceptedDir(root), "_rejected")
110
+ const dest = join(destDir, `${id}.md`)
111
+ await commitWrite(dest, lessonFile(lesson), report, fromRoot(root, dest))
112
+ const previous = await readOptional(source)
113
+ if (previous) {
114
+ if (!report.dryRun) await removeFile(source)
115
+ await report.record("removed", fromRoot(root, source), { previous })
116
+ }
117
+ return lesson
118
+ }
119
+
120
+ export function watchLine(lesson) {
121
+ return `- ${lesson.trigger}: ${lesson.mistake} Fix: ${lesson.fix}`
122
+ }
123
+
124
+ export function selectLessons(lessons, changed, { limit = 5, budget = 400 } = {}) {
125
+ const paths = changed.map((file) => file.replace(/\\/g, "/"))
126
+ const ranked = []
127
+ for (const lesson of lessons) {
128
+ if (lesson.status !== "accepted" || lesson.stale) continue
129
+ const files = String(lesson.files || "").split(",").map((file) => file.trim()).filter(Boolean)
130
+ const trigger = String(lesson.trigger || "").toLowerCase()
131
+ let score = 0
132
+ for (const path of paths) {
133
+ if (files.some((file) => path === file || path.endsWith(file))) score += 3
134
+ else if (trigger && path.toLowerCase().includes(trigger.replace(/^when editing /, ""))) score += 1
135
+ }
136
+ if (score > 0) ranked.push({ lesson, score })
137
+ }
138
+ ranked.sort((a, b) => b.score - a.score || a.lesson.id.localeCompare(b.lesson.id))
139
+ const chosen = []
140
+ let used = 0
141
+ for (const item of ranked) {
142
+ if (chosen.length >= limit) break
143
+ const cost = Math.max(1, Math.ceil(watchLine(item.lesson).length / 4))
144
+ if (used + cost > budget) continue
145
+ used += cost
146
+ chosen.push(item.lesson)
147
+ }
148
+ return chosen
149
+ }
150
+
151
+ export function lessonBlock(lessons) {
152
+ if (!lessons.length) return ""
153
+ return `\nWatch-outs\n${lessons.map(watchLine).join("\n")}\n`
154
+ }
155
+
156
+ const DAY = 24 * 60 * 60 * 1000
157
+
158
+ export async function markLessonHealth(root, signals, report, now = new Date()) {
159
+ for (const lesson of await listAccepted(root)) {
160
+ const seen = Date.parse(lesson.lastSeen)
161
+ const stale = Number.isFinite(seen) && now.getTime() - seen > 90 * DAY
162
+ const recurring = signals.some((signal) => {
163
+ if (signal.kind !== "failure" || !lesson.mistake) return false
164
+ const at = Date.parse(signal.at)
165
+ if (Number.isFinite(seen) && Number.isFinite(at) && at < seen) return false
166
+ return String(signal.text || "").toLowerCase().includes(lesson.mistake.toLowerCase())
167
+ })
168
+ if (!stale && !recurring) continue
169
+ if (Boolean(lesson.stale) === stale && (lesson.flagged === "recurring") === recurring) continue
170
+ const next = { ...lesson, stale, flagged: recurring ? "recurring" : lesson.flagged }
171
+ await commitWrite(lesson.file, lessonFile(next), report, fromRoot(root, lesson.file))
172
+ }
173
+ }
package/src/lib/lint.js CHANGED
@@ -1,67 +1,185 @@
1
- import { readFile } from "node:fs/promises"
2
- import { join } from "node:path"
3
- import { walkFiles } from "./fs-safe.js"
4
- import { parseFrontmatter } from "./frontmatter.js"
5
- import { packRoot, toPosix, fromRoot } from "./paths.js"
6
-
7
- const REQUIRED = ["title", "type", "tags", "stack", "status", "verified", "description"]
8
- const HEADINGS = [
9
- "Use when",
10
- "Default",
11
- "Use instead when",
12
- "Never",
13
- "Why",
14
- "Steps",
15
- "Done when",
16
- "Example",
17
- "Common mistakes",
18
- "Sources",
19
- ]
20
-
21
- function section(text, heading) {
22
- const normalized = text.replace(/\r\n/g, "\n")
23
- const match = new RegExp(`^## ${heading}\\n([\\s\\S]*?)(?=\\n## |$)`, "m").exec(normalized)
24
- return match ? match[1].trim() : ""
25
- }
26
-
27
- export function lintText(file, text) {
28
- const problems = []
29
- const data = parseFrontmatter(text)
30
- if (!data) {
31
- problems.push(`${file}: missing frontmatter`)
32
- return problems
33
- }
34
- if (!data.status) return problems
35
- for (const key of REQUIRED) {
36
- if (data[key] === undefined || data[key] === "" && key !== "verified") problems.push(`${file}: frontmatter ${key} is empty`)
37
- }
38
- if (data.status !== "draft" && data.status !== "reviewed") problems.push(`${file}: status must be draft or reviewed`)
39
- if (data.status !== "reviewed") return problems
40
- if (data.type === "blueprint") {
41
- if (!/^\d{4}-\d{2}-\d{2}$/.test(data.verified || "")) problems.push(`${file}: verified must be YYYY-MM-DD`)
42
- for (const heading of ["Summary", "Capabilities", "Reference architecture", "Data model starter", "Integrations", "Phases", "Gate", "Pitfalls", "Confirm with user", "Entries to load"]) {
43
- if (!section(text, heading)) problems.push(`${file}: empty or missing ${heading}`)
44
- }
45
- return problems
46
- }
47
- const lines = text.split(/\r?\n/).length
48
- if (lines > 60) problems.push(`${file}: ${lines} lines, reviewed entries stay under 60`)
49
- if (text.includes("TODO")) problems.push(`${file}: reviewed entries cannot contain TODO`)
50
- if (!/^\d{4}-\d{2}-\d{2}$/.test(data.verified || "")) problems.push(`${file}: verified must be YYYY-MM-DD`)
51
- if (!/^license:/im.test(text)) problems.push(`${file}: missing a license line`)
52
- for (const heading of HEADINGS) {
53
- if (!section(text, heading)) problems.push(`${file}: empty or missing ${heading}`)
54
- }
55
- return problems
56
- }
57
-
58
- export async function lintPacks() {
59
- const root = join(packRoot, "packs")
60
- const files = (await walkFiles(root)).filter((file) => file.endsWith(".md") && !file.endsWith("CONTRIBUTING.md"))
61
- const problems = []
62
- for (const file of files) {
63
- const text = await readFile(file, "utf8")
64
- problems.push(...lintText(toPosix(fromRoot(packRoot, file)), text))
65
- }
66
- return problems
67
- }
1
+ import { readFile } from "node:fs/promises"
2
+ import { join } from "node:path"
3
+ import { walkFiles } from "./fs-safe.js"
4
+ import { parseFrontmatter } from "./frontmatter.js"
5
+ import { ctxPath, packRoot, toPosix, fromRoot } from "./paths.js"
6
+ import { buildGraph } from "./graph.js"
7
+ import { entryVisible } from "./index.js"
8
+ import { secretHits } from "./secrets.js"
9
+
10
+ // The brief's list, plus the three the shipped packs already use
11
+ // (eval, protocol, workflow). Renaming those would rewrite shipped entries.
12
+ export const ENTRY_TYPES = new Set([
13
+ "guide",
14
+ "rule",
15
+ "anti-pattern",
16
+ "playbook",
17
+ "blueprint",
18
+ "process",
19
+ "template",
20
+ "design-token",
21
+ "component",
22
+ "screenshot",
23
+ "flow",
24
+ "doc",
25
+ "plan",
26
+ "log",
27
+ "eval",
28
+ "protocol",
29
+ "workflow",
30
+ ])
31
+
32
+ const STALE_DAYS = 180
33
+
34
+ // Entries that are appended to over the life of the project.
35
+ const LIVING = new Set(["plan", "log"])
36
+
37
+ const REQUIRED = ["title", "type", "tags", "stack", "status", "verified", "description"]
38
+ const HEADINGS = [
39
+ "Use when",
40
+ "Default",
41
+ "Use instead when",
42
+ "Never",
43
+ "Why",
44
+ "Steps",
45
+ "Done when",
46
+ "Example",
47
+ "Common mistakes",
48
+ "Sources",
49
+ ]
50
+
51
+ function section(text, heading) {
52
+ const normalized = text.replace(/\r\n/g, "\n")
53
+ const marker = `## ${heading}\n`
54
+ const start = normalized.indexOf(marker)
55
+ if (start === -1) return ""
56
+ const rest = normalized.slice(start + marker.length)
57
+ // A following ### heading is part of this section. The next ## heading ends it.
58
+ const next = rest.search(/\n## (?!#)/)
59
+ return (next === -1 ? rest : rest.slice(0, next)).trim()
60
+ }
61
+
62
+ export function lintText(file, text) {
63
+ const problems = []
64
+ const data = parseFrontmatter(text)
65
+ if (!data) {
66
+ problems.push(`${file}: missing frontmatter`)
67
+ return problems
68
+ }
69
+ if (!data.status) return problems
70
+ for (const key of REQUIRED) {
71
+ if (data[key] === undefined || data[key] === "" && key !== "verified") problems.push(`${file}: frontmatter ${key} is empty`)
72
+ }
73
+ if (data.status !== "draft" && data.status !== "reviewed") problems.push(`${file}: status must be draft or reviewed`)
74
+ if (data.status !== "reviewed") return problems
75
+ if (data.type === "blueprint") {
76
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(data.verified || "")) problems.push(`${file}: verified must be YYYY-MM-DD`)
77
+ for (const heading of ["Summary", "Capabilities", "Reference architecture", "Data model starter", "Integrations", "Phases", "Gate", "Pitfalls", "Confirm with user", "Entries to load"]) {
78
+ if (!section(text, heading)) problems.push(`${file}: empty or missing ${heading}`)
79
+ }
80
+ return problems
81
+ }
82
+ const lines = text.split(/\r?\n/).length
83
+ if (lines > 60) problems.push(`${file}: ${lines} lines, reviewed entries stay under 60`)
84
+ if (text.includes("TODO")) problems.push(`${file}: reviewed entries cannot contain TODO`)
85
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(data.verified || "")) problems.push(`${file}: verified must be YYYY-MM-DD`)
86
+ if (!/^license:/im.test(text)) problems.push(`${file}: missing a license line`)
87
+ for (const heading of HEADINGS) {
88
+ if (!section(text, heading)) problems.push(`${file}: empty or missing ${heading}`)
89
+ }
90
+ return problems
91
+ }
92
+
93
+ function entryDate(data) {
94
+ const raw = data.verified || data.updated || ""
95
+ return /^\d{4}-\d{2}-\d{2}$/.test(raw) ? raw : null
96
+ }
97
+
98
+ function daysSince(date, now) {
99
+ return Math.floor((now - Date.parse(`${date}T00:00:00Z`)) / 86400000)
100
+ }
101
+
102
+ export function lintEntry(path, text, options = {}) {
103
+ const now = options.now ?? Date.now()
104
+ const staleDays = options.staleDays ?? STALE_DAYS
105
+ const errors = []
106
+ const warnings = []
107
+ const data = parseFrontmatter(text)
108
+ if (!data) {
109
+ errors.push(`${path}: missing frontmatter`)
110
+ return { errors, warnings, data: null }
111
+ }
112
+ const description = String(data.description || "").trim()
113
+ if (!description) errors.push(`${path}: description is empty`)
114
+ else if (description === "TODO" || description.length < 12) {
115
+ errors.push(`${path}: description is a stub, say when to load this entry`)
116
+ }
117
+ if (!data.type) errors.push(`${path}: type is empty`)
118
+ else if (!ENTRY_TYPES.has(String(data.type))) {
119
+ errors.push(`${path}: type "${data.type}" is not an allowed entry type`)
120
+ }
121
+ const hits = secretHits(text)
122
+ if (hits.length) errors.push(`${path}: looks like a secret (${hits.join(", ")})`)
123
+
124
+ // plan.md and journal.md grow as the project runs, so neither a length cap
125
+ // nor a verified date applies to them.
126
+ if (!LIVING.has(String(data.type))) {
127
+ const lines = text.split(/\r?\n/).length
128
+ if (lines > (options.maxLines ?? 60)) warnings.push(`${path}: ${lines} lines, entries read better under 60`)
129
+ const date = entryDate(data)
130
+ if (!date) warnings.push(`${path}: no verified date`)
131
+ else if (daysSince(date, now) > staleDays) warnings.push(`${path}: verified ${date}, older than ${staleDays} days`)
132
+ }
133
+ return { errors, warnings, data }
134
+ }
135
+
136
+ export async function lintProject(root, options = {}) {
137
+ const errors = []
138
+ const warnings = []
139
+ const titles = new Map()
140
+
141
+ const files = []
142
+ for (const dir of ["library", "mine", "memory"]) files.push(...(await walkFiles(ctxPath(root, dir))))
143
+ const present = new Set(files)
144
+
145
+ {
146
+ for (const file of files) {
147
+ const path = toPosix(fromRoot(root, file))
148
+ if (!file.endsWith(".md")) {
149
+ const twin = `${file.replace(/\.[^.]+$/, "")}.md`
150
+ if (!present.has(twin) && !file.endsWith(".gitkeep")) {
151
+ errors.push(`${path}: no text entry beside this file, add ${toPosix(fromRoot(root, twin))}`)
152
+ }
153
+ continue
154
+ }
155
+ const text = await readFile(file, "utf8")
156
+ const data = parseFrontmatter(text)
157
+ // A markdown file with no frontmatter is still a problem to report; only
158
+ // hide the ones entryVisible excludes on purpose (vault, proposals).
159
+ if (data && !entryVisible(data, file, options)) continue
160
+ if (!data && /\/(_proposed|_rejected|vault)\//.test(toPosix(path))) continue
161
+ const result = lintEntry(path, text, options)
162
+ errors.push(...result.errors)
163
+ warnings.push(...result.warnings)
164
+ const title = String(result.data?.title || "").trim().toLowerCase()
165
+ if (!title) continue
166
+ if (titles.has(title)) errors.push(`${path}: duplicate title, also used by ${titles.get(title)}`)
167
+ else titles.set(title, path)
168
+ }
169
+ }
170
+
171
+ const { broken } = await buildGraph(root, options)
172
+ errors.push(...broken)
173
+ return { errors: errors.sort(), warnings: warnings.sort() }
174
+ }
175
+
176
+ export async function lintPacks() {
177
+ const root = join(packRoot, "packs")
178
+ const files = (await walkFiles(root)).filter((file) => file.endsWith(".md") && !file.endsWith("CONTRIBUTING.md"))
179
+ const problems = []
180
+ for (const file of files) {
181
+ const text = await readFile(file, "utf8")
182
+ problems.push(...lintText(toPosix(fromRoot(packRoot, file)), text))
183
+ }
184
+ return problems
185
+ }
package/src/lib/mutate.js CHANGED
@@ -1,24 +1,26 @@
1
- import { readOptional, removeFile, writeAtomic } from "./fs-safe.js"
2
-
3
- function asBuffer(data) {
4
- return Buffer.isBuffer(data) ? data : Buffer.from(data)
5
- }
6
-
7
- export async function commitWrite(file, data, report, display) {
8
- const previous = await readOptional(file)
9
- const buf = asBuffer(data)
10
- if (previous && previous.equals(buf)) {
11
- report.add("skipped", display)
12
- return
13
- }
14
- const kind = previous ? "changed" : "created"
15
- if (!report.dryRun) await writeAtomic(file, buf)
16
- report.add(kind, display, { previous })
17
- }
18
-
19
- export async function commitRemove(file, report, display) {
20
- const previous = await readOptional(file)
21
- if (!previous) return
22
- if (!report.dryRun) await removeFile(file)
23
- report.add("removed", display, { previous })
24
- }
1
+ import { readOptional, removeFile, writeAtomic } from "./fs-safe.js"
2
+
3
+ function asBuffer(data) {
4
+ return Buffer.isBuffer(data) ? data : Buffer.from(data)
5
+ }
6
+
7
+ export async function commitWrite(file, data, report, display) {
8
+ const previous = await readOptional(file)
9
+ const buf = asBuffer(data)
10
+ if (previous && previous.equals(buf)) {
11
+ report.add("skipped", display)
12
+ return
13
+ }
14
+ const kind = previous ? "changed" : "created"
15
+ // Record the change before touching the file, so an interrupted run still
16
+ // leaves a manifest undo can read.
17
+ await report.record(kind, display, { previous })
18
+ if (!report.dryRun) await writeAtomic(file, buf)
19
+ }
20
+
21
+ export async function commitRemove(file, report, display) {
22
+ const previous = await readOptional(file)
23
+ if (!previous) return
24
+ await report.record("removed", display, { previous })
25
+ if (!report.dryRun) await removeFile(file)
26
+ }