connore 0.1.0 → 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 (280) hide show
  1. package/README.md +58 -46
  2. package/package.json +36 -33
  3. package/packs/CONTRIBUTING.md +32 -0
  4. package/packs/base/catalog/README.md +24 -0
  5. package/packs/base/catalog/api.md +46 -0
  6. package/packs/base/catalog/auth.md +46 -0
  7. package/packs/base/catalog/backend.md +46 -0
  8. package/packs/base/catalog/blueprints.md +46 -0
  9. package/packs/base/catalog/components.md +46 -0
  10. package/packs/base/catalog/database.md +46 -0
  11. package/packs/base/catalog/docs.md +46 -0
  12. package/packs/base/catalog/github.md +46 -0
  13. package/packs/base/catalog/golden.md +46 -0
  14. package/packs/base/catalog/motion.md +46 -0
  15. package/packs/base/catalog/plan.md +46 -0
  16. package/packs/base/catalog/screenshots.md +46 -0
  17. package/packs/base/catalog/skills.md +46 -0
  18. package/packs/base/catalog/tokens.md +47 -0
  19. package/packs/base/planning/START.md +29 -0
  20. package/packs/base/planning/blueprint-template.md +46 -0
  21. package/packs/base/planning/plan-template.md +46 -0
  22. package/packs/base/rules/anti-patterns.md +46 -0
  23. package/packs/base/rules/code-style.md +46 -0
  24. package/packs/base/rules/definition-of-done.md +47 -0
  25. package/packs/base/rules/dependency-policy.md +46 -0
  26. package/packs/base/rules/error-handling.md +46 -0
  27. package/packs/base/rules/security-audit.md +47 -0
  28. package/packs/base/rules/security-baseline.md +46 -0
  29. package/packs/base/templates/bug-report.md +46 -0
  30. package/packs/base/templates/feature-spec.md +46 -0
  31. package/packs/base/templates/handoff.md +46 -0
  32. package/packs/base/templates/project-brief.md +46 -0
  33. package/packs/base/workflow/build-loop.md +48 -0
  34. package/packs/base/workflow/code-review.md +46 -0
  35. package/packs/base/workflow/debugging.md +47 -0
  36. package/packs/base/workflow/git-and-commits.md +46 -0
  37. package/packs/base/workflow/idea-to-spec.md +46 -0
  38. package/packs/base/workflow/session-handoff.md +46 -0
  39. package/packs/base/workflow/spec-to-plan.md +46 -0
  40. package/packs/knowledge/backend/api/conventions.md +21 -0
  41. package/packs/knowledge/backend/architecture/local-sqlite.md +20 -0
  42. package/packs/knowledge/backend/authentication/session-and-engine.md +24 -0
  43. package/packs/knowledge/backend/database/schema.md +21 -0
  44. package/packs/knowledge/components/custom/ambient-background.md +26 -0
  45. package/packs/knowledge/components/custom/ambient-background.tsx +12 -0
  46. package/packs/knowledge/components/custom/corner-frame.md +26 -0
  47. package/packs/knowledge/components/custom/corner-frame.tsx +48 -0
  48. package/packs/knowledge/components/custom/cta-button.md +26 -0
  49. package/packs/knowledge/components/custom/cta-button.tsx +10 -0
  50. package/packs/knowledge/components/custom/page-transition.md +26 -0
  51. package/packs/knowledge/components/custom/page-transition.tsx +10 -0
  52. package/packs/knowledge/components/custom/smooth-scroll.md +26 -0
  53. package/packs/knowledge/components/custom/smooth-scroll.tsx +32 -0
  54. package/packs/knowledge/components/motion-effects/README.md +30 -0
  55. package/packs/knowledge/components/ui-primitives/LICENSE +21 -0
  56. package/packs/knowledge/components/ui-primitives/README.md +22 -0
  57. package/packs/knowledge/components/ui-primitives/badge.md +26 -0
  58. package/packs/knowledge/components/ui-primitives/badge.tsx +48 -0
  59. package/packs/knowledge/components/ui-primitives/button.md +27 -0
  60. package/packs/knowledge/components/ui-primitives/button.tsx +66 -0
  61. package/packs/knowledge/components/ui-primitives/card.md +26 -0
  62. package/packs/knowledge/components/ui-primitives/card.tsx +102 -0
  63. package/packs/knowledge/components/ui-primitives/checkbox.md +26 -0
  64. package/packs/knowledge/components/ui-primitives/checkbox.tsx +32 -0
  65. package/packs/knowledge/components/ui-primitives/dialog.md +26 -0
  66. package/packs/knowledge/components/ui-primitives/dialog.tsx +168 -0
  67. package/packs/knowledge/components/ui-primitives/dropdown-menu.md +26 -0
  68. package/packs/knowledge/components/ui-primitives/dropdown-menu.tsx +268 -0
  69. package/packs/knowledge/components/ui-primitives/input.md +27 -0
  70. package/packs/knowledge/components/ui-primitives/input.tsx +18 -0
  71. package/packs/knowledge/components/ui-primitives/label.md +26 -0
  72. package/packs/knowledge/components/ui-primitives/label.tsx +23 -0
  73. package/packs/knowledge/components/ui-primitives/progress.md +26 -0
  74. package/packs/knowledge/components/ui-primitives/progress.tsx +30 -0
  75. package/packs/knowledge/components/ui-primitives/scroll-area.md +26 -0
  76. package/packs/knowledge/components/ui-primitives/scroll-area.tsx +54 -0
  77. package/packs/knowledge/components/ui-primitives/select.md +26 -0
  78. package/packs/knowledge/components/ui-primitives/select.tsx +191 -0
  79. package/packs/knowledge/components/ui-primitives/separator.md +26 -0
  80. package/packs/knowledge/components/ui-primitives/separator.tsx +27 -0
  81. package/packs/knowledge/components/ui-primitives/sonner.md +26 -0
  82. package/packs/knowledge/components/ui-primitives/sonner.tsx +49 -0
  83. package/packs/knowledge/components/ui-primitives/switch.md +26 -0
  84. package/packs/knowledge/components/ui-primitives/switch.tsx +32 -0
  85. package/packs/knowledge/components/ui-primitives/tabs.md +26 -0
  86. package/packs/knowledge/components/ui-primitives/tabs.tsx +89 -0
  87. package/packs/knowledge/components/ui-primitives/textarea.md +26 -0
  88. package/packs/knowledge/components/ui-primitives/textarea.tsx +17 -0
  89. package/packs/knowledge/components/ui-primitives/tooltip.md +26 -0
  90. package/packs/knowledge/components/ui-primitives/tooltip.tsx +56 -0
  91. package/packs/knowledge/design/aesthetics/app-shell.md +41 -0
  92. package/packs/knowledge/design/aesthetics/code-neutral.md +40 -0
  93. package/packs/knowledge/design/aesthetics/match.md +46 -0
  94. package/packs/knowledge/design/aesthetics/ruled-outline.md +40 -0
  95. package/packs/knowledge/design/aesthetics/solid-accent.md +43 -0
  96. package/packs/knowledge/design/animations/motion.md +40 -0
  97. package/packs/knowledge/design/project-style.md +50 -0
  98. package/packs/knowledge/design/references/benefit-card-grid.md +27 -0
  99. package/packs/knowledge/design/references/benefit-card-grid.png +0 -0
  100. package/packs/knowledge/design/references/cta-centered.md +27 -0
  101. package/packs/knowledge/design/references/cta-centered.png +0 -0
  102. package/packs/knowledge/design/references/cta-split-media.md +27 -0
  103. package/packs/knowledge/design/references/cta-split-media.png +0 -0
  104. package/packs/knowledge/design/references/dashboard-overview.md +31 -0
  105. package/packs/knowledge/design/references/dashboard-overview.png +0 -0
  106. package/packs/knowledge/design/references/faq-split-accordion.md +27 -0
  107. package/packs/knowledge/design/references/faq-split-accordion.png +0 -0
  108. package/packs/knowledge/design/references/feature-split-checklist.md +27 -0
  109. package/packs/knowledge/design/references/feature-split-checklist.png +0 -0
  110. package/packs/knowledge/design/references/footer-four-column.md +27 -0
  111. package/packs/knowledge/design/references/footer-four-column.png +0 -0
  112. package/packs/knowledge/design/references/footer-two-column.md +27 -0
  113. package/packs/knowledge/design/references/footer-two-column.png +0 -0
  114. package/packs/knowledge/design/references/hero-accent-curtain.md +27 -0
  115. package/packs/knowledge/design/references/hero-accent-curtain.png +0 -0
  116. package/packs/knowledge/design/references/hero-split-media.md +27 -0
  117. package/packs/knowledge/design/references/hero-split-media.png +0 -0
  118. package/packs/knowledge/design/references/logo-cloud-grid.md +27 -0
  119. package/packs/knowledge/design/references/logo-cloud-grid.png +0 -0
  120. package/packs/knowledge/design/references/logo-row-ruled.md +27 -0
  121. package/packs/knowledge/design/references/logo-row-ruled.png +0 -0
  122. package/packs/knowledge/design/references/pricing-three-card.md +27 -0
  123. package/packs/knowledge/design/references/pricing-three-card.png +0 -0
  124. package/packs/knowledge/design/references/steps-ruled-grid.md +27 -0
  125. package/packs/knowledge/design/references/steps-ruled-grid.png +0 -0
  126. package/packs/knowledge/design/rules.md +35 -0
  127. package/packs/knowledge/design/token-structure.md +46 -0
  128. package/packs/knowledge/design/tokens.md +55 -0
  129. package/packs/knowledge/frontend/README.md +50 -0
  130. package/packs/knowledge/frontend/SOURCES.md +40 -0
  131. package/packs/knowledge/frontend/accessibility/focus-and-dialogs.md +47 -0
  132. package/packs/knowledge/frontend/accessibility/semantics-and-keyboard.md +45 -0
  133. package/packs/knowledge/frontend/accessibility/wcag-targets.md +43 -0
  134. package/packs/knowledge/frontend/architecture/agent-context-files.md +43 -0
  135. package/packs/knowledge/frontend/architecture/app-foundations.md +43 -0
  136. package/packs/knowledge/frontend/architecture/error-handling.md +47 -0
  137. package/packs/knowledge/frontend/architecture/feature-modules.md +49 -0
  138. package/packs/knowledge/frontend/architecture/import-boundaries.md +44 -0
  139. package/packs/knowledge/frontend/architecture/naming.md +43 -0
  140. package/packs/knowledge/frontend/architecture/project-structure.md +48 -0
  141. package/packs/knowledge/frontend/architecture/routing.md +45 -0
  142. package/packs/knowledge/frontend/architecture/security.md +44 -0
  143. package/packs/knowledge/frontend/architecture/typescript.md +44 -0
  144. package/packs/knowledge/frontend/components/composition.md +45 -0
  145. package/packs/knowledge/frontend/components/data-display.md +47 -0
  146. package/packs/knowledge/frontend/components/library-choice.md +45 -0
  147. package/packs/knowledge/frontend/components/variants.md +44 -0
  148. package/packs/knowledge/frontend/forms/form-architecture.md +49 -0
  149. package/packs/knowledge/frontend/forms/multi-step.md +43 -0
  150. package/packs/knowledge/frontend/forms/validation.md +47 -0
  151. package/packs/knowledge/frontend/layout/responsive.md +41 -0
  152. package/packs/knowledge/frontend/page-blueprints/app-shell.md +16 -0
  153. package/packs/knowledge/frontend/page-blueprints/faq-footer.md +22 -0
  154. package/packs/knowledge/frontend/page-blueprints/feature-grid.md +22 -0
  155. package/packs/knowledge/frontend/page-blueprints/pricing.md +16 -0
  156. package/packs/knowledge/frontend/page-blueprints/saas-hero.md +24 -0
  157. package/packs/knowledge/frontend/patterns/dark-marketing.md +18 -0
  158. package/packs/knowledge/frontend/patterns/status-pill.md +19 -0
  159. package/packs/knowledge/frontend/performance/code-splitting.md +47 -0
  160. package/packs/knowledge/frontend/performance/images-and-vitals.md +44 -0
  161. package/packs/knowledge/frontend/performance/rendering.md +40 -0
  162. package/packs/knowledge/frontend/rendering/server-and-client.md +50 -0
  163. package/packs/knowledge/frontend/state/api-layer.md +49 -0
  164. package/packs/knowledge/frontend/state/async-ui-states.md +43 -0
  165. package/packs/knowledge/frontend/state/client-store.md +46 -0
  166. package/packs/knowledge/frontend/state/server-cache.md +42 -0
  167. package/packs/knowledge/frontend/state/state-categories.md +50 -0
  168. package/packs/knowledge/frontend/testing/component-tests.md +44 -0
  169. package/packs/knowledge/frontend/testing/strategy.md +46 -0
  170. package/packs/knowledge/inbox/README.md +14 -0
  171. package/packs/knowledge/workflows/authentication.md +18 -0
  172. package/packs/knowledge/workflows/crud.md +20 -0
  173. package/packs/knowledge/workflows/dashboard.md +22 -0
  174. package/packs/nextjs-fullstack/backend/api-conventions.md +48 -0
  175. package/packs/nextjs-fullstack/backend/auth-and-roles.md +46 -0
  176. package/packs/nextjs-fullstack/backend/background-jobs.md +46 -0
  177. package/packs/nextjs-fullstack/backend/caching.md +46 -0
  178. package/packs/nextjs-fullstack/backend/database.md +46 -0
  179. package/packs/nextjs-fullstack/backend/file-uploads.md +46 -0
  180. package/packs/nextjs-fullstack/backend/logging.md +46 -0
  181. package/packs/nextjs-fullstack/backend/migrations.md +46 -0
  182. package/packs/nextjs-fullstack/backend/rate-limiting.md +46 -0
  183. package/packs/nextjs-fullstack/backend/secrets-and-env.md +46 -0
  184. package/packs/nextjs-fullstack/backend/validation.md +46 -0
  185. package/packs/nextjs-fullstack/blueprints/ai-app.md +84 -0
  186. package/packs/nextjs-fullstack/blueprints/internal-tool.md +83 -0
  187. package/packs/nextjs-fullstack/blueprints/saas-app.md +83 -0
  188. package/packs/nextjs-fullstack/build-deploy/ci.md +45 -0
  189. package/packs/nextjs-fullstack/build-deploy/deploy.md +46 -0
  190. package/packs/nextjs-fullstack/build-deploy/monitoring.md +45 -0
  191. package/packs/nextjs-fullstack/build-deploy/performance.md +46 -0
  192. package/packs/nextjs-fullstack/build-deploy/project-structure.md +45 -0
  193. package/packs/nextjs-fullstack/build-deploy/release-checklist.md +47 -0
  194. package/packs/nextjs-fullstack/build-deploy/testing.md +46 -0
  195. package/packs/nextjs-fullstack/evals/README.md +46 -0
  196. package/packs/nextjs-fullstack/examples/golden-app/README.md +45 -0
  197. package/packs/nextjs-fullstack/frontend/accessibility.md +46 -0
  198. package/packs/nextjs-fullstack/frontend/components.md +46 -0
  199. package/packs/nextjs-fullstack/frontend/copy.md +46 -0
  200. package/packs/nextjs-fullstack/frontend/data-fetching.md +46 -0
  201. package/packs/nextjs-fullstack/frontend/forms.md +46 -0
  202. package/packs/nextjs-fullstack/frontend/layout.md +46 -0
  203. package/packs/nextjs-fullstack/frontend/loading-empty-error.md +46 -0
  204. package/packs/nextjs-fullstack/frontend/motion.md +46 -0
  205. package/packs/nextjs-fullstack/frontend/responsive.md +46 -0
  206. package/packs/nextjs-fullstack/frontend/seo.md +47 -0
  207. package/packs/nextjs-fullstack/frontend/tables.md +46 -0
  208. package/packs/nextjs-fullstack/frontend/tokens.md +45 -0
  209. package/packs/nextjs-fullstack/integrations/analytics.md +46 -0
  210. package/packs/nextjs-fullstack/integrations/email.md +46 -0
  211. package/packs/nextjs-fullstack/integrations/llm-apis.md +46 -0
  212. package/packs/nextjs-fullstack/integrations/oauth.md +46 -0
  213. package/packs/nextjs-fullstack/integrations/object-storage.md +46 -0
  214. package/packs/nextjs-fullstack/integrations/payments.md +46 -0
  215. package/packs/nextjs-fullstack/integrations/queues.md +46 -0
  216. package/packs/nextjs-fullstack/integrations/search.md +46 -0
  217. package/packs/nextjs-fullstack/integrations/webhooks.md +46 -0
  218. package/packs/nextjs-fullstack/playbooks/add-ai-feature.md +46 -0
  219. package/packs/nextjs-fullstack/playbooks/add-auth.md +46 -0
  220. package/packs/nextjs-fullstack/playbooks/add-billing.md +50 -0
  221. package/packs/nextjs-fullstack/playbooks/add-crud.md +46 -0
  222. package/packs/nextjs-fullstack/playbooks/add-email.md +46 -0
  223. package/packs/nextjs-fullstack/playbooks/add-file-upload.md +46 -0
  224. package/packs/nextjs-fullstack/playbooks/add-webhook.md +46 -0
  225. package/packs/nextjs-fullstack/playbooks/ship-to-prod.md +47 -0
  226. package/plugins/connore/.claude-plugin/plugin.json +10 -0
  227. package/plugins/connore/hooks/hooks.json +16 -0
  228. package/plugins/connore/skills/connore-backend/SKILL.md +32 -0
  229. package/plugins/connore/skills/connore-handoff/SKILL.md +15 -0
  230. package/plugins/connore/skills/connore-routes/SKILL.md +16 -0
  231. package/plugins/connore/skills/connore-validate/SKILL.md +15 -0
  232. package/src/cli.js +377 -90
  233. package/src/commands/add.js +61 -57
  234. package/src/commands/catalog.js +21 -0
  235. package/src/commands/doctor.js +44 -0
  236. package/src/commands/edit.js +88 -0
  237. package/src/commands/graph.js +20 -0
  238. package/src/commands/handoff.js +45 -0
  239. package/src/commands/hook.js +67 -50
  240. package/src/commands/init.js +74 -55
  241. package/src/commands/learn.js +39 -0
  242. package/src/commands/lint.js +13 -0
  243. package/src/commands/list.js +10 -10
  244. package/src/commands/log.js +49 -0
  245. package/src/commands/memory.js +14 -0
  246. package/src/commands/packs.js +21 -0
  247. package/src/commands/plan.js +41 -0
  248. package/src/commands/reindex.js +8 -8
  249. package/src/commands/review.js +31 -0
  250. package/src/commands/routes.js +13 -0
  251. package/src/commands/search.js +26 -0
  252. package/src/commands/stats.js +35 -0
  253. package/src/commands/undo.js +7 -0
  254. package/src/commands/update.js +20 -14
  255. package/src/lib/catalog.js +32 -0
  256. package/src/lib/config.js +67 -0
  257. package/src/lib/fs-safe.js +36 -11
  258. package/src/lib/gitlog.js +75 -0
  259. package/src/lib/graph.js +96 -0
  260. package/src/lib/ignore.js +47 -0
  261. package/src/lib/index.js +88 -57
  262. package/src/lib/lessons.js +173 -0
  263. package/src/lib/lint.js +185 -0
  264. package/src/lib/lock.js +47 -0
  265. package/src/lib/memory.js +49 -0
  266. package/src/lib/mutate.js +26 -0
  267. package/src/lib/packs.js +25 -0
  268. package/src/lib/paths.js +6 -2
  269. package/src/lib/plan.js +156 -0
  270. package/src/lib/pointers.js +3 -3
  271. package/src/lib/prompts.js +66 -0
  272. package/src/lib/provider.js +27 -0
  273. package/src/lib/report.js +41 -17
  274. package/src/lib/routes.js +59 -0
  275. package/src/lib/run.js +116 -0
  276. package/src/lib/search.js +64 -0
  277. package/src/lib/secrets.js +25 -0
  278. package/src/lib/signals.js +55 -0
  279. package/src/lib/sync.js +20 -12
  280. package/src/lib/tokens.js +8 -0
@@ -0,0 +1,41 @@
1
+ import { join } from "node:path"
2
+ import { readOptional } from "../lib/fs-safe.js"
3
+ import { rebuildIndex } from "../lib/index.js"
4
+ import { commitWrite } from "../lib/mutate.js"
5
+ import { markTaskDone, parseBlueprint, planView, readBlueprint, renderPlan } from "../lib/plan.js"
6
+
7
+ function planPath(root) {
8
+ return join(root, ".ctx", "mine", "plan.md")
9
+ }
10
+
11
+ async function requirePlan(root) {
12
+ const file = planPath(root)
13
+ const raw = await readOptional(file)
14
+ if (!raw) throw new Error("No plan. Run connore plan init <blueprint>.")
15
+ return { file, text: raw.toString("utf8") }
16
+ }
17
+
18
+ export async function plan(root, args, report) {
19
+ if (!(await readOptional(join(root, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
20
+ const [sub, ...rest] = args
21
+ if (sub === "init") {
22
+ const name = rest[0]
23
+ const file = planPath(root)
24
+ if (await readOptional(file)) throw new Error("A plan already exists at .ctx/mine/plan.md.")
25
+ const source = await readBlueprint(name)
26
+ const rendered = renderPlan(name, parseBlueprint(source.text))
27
+ if (!parseBlueprint(source.text).phases.length) throw new Error(`Blueprint "${name}" has no phases.`)
28
+ await commitWrite(file, rendered, report, ".ctx/mine/plan.md")
29
+ await rebuildIndex(root, report)
30
+ return planView(rendered)
31
+ }
32
+ const current = await requirePlan(root)
33
+ if (sub === "status" || sub === "next") return planView(current.text)
34
+ if (sub === "done") {
35
+ const updated = markTaskDone(current.text, rest.join(" "))
36
+ await commitWrite(current.file, updated, report, ".ctx/mine/plan.md")
37
+ await rebuildIndex(root, report)
38
+ return planView(updated)
39
+ }
40
+ throw Object.assign(new Error("Usage: connore plan init <blueprint> | status | next | done <task>."), { exitCode: 2 })
41
+ }
@@ -1,8 +1,8 @@
1
- import { join } from "node:path"
2
- import { readOptional } from "../lib/fs-safe.js"
3
- import { rebuildIndex } from "../lib/index.js"
4
-
5
- export async function reindex(root, report) {
6
- if (!(await readOptional(join(root, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
7
- await rebuildIndex(root, report)
8
- }
1
+ import { join } from "node:path"
2
+ import { readOptional } from "../lib/fs-safe.js"
3
+ import { rebuildIndex } from "../lib/index.js"
4
+
5
+ export async function reindex(root, flags, report) {
6
+ if (!(await readOptional(join(root, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
7
+ await rebuildIndex(root, report, { includeDrafts: flags.includeDrafts })
8
+ }
@@ -0,0 +1,31 @@
1
+ import { join } from "node:path"
2
+ import { readOptional } from "../lib/fs-safe.js"
3
+ import { rebuildIndex } from "../lib/index.js"
4
+ import { lessonFile, listProposals, moveProposal } from "../lib/lessons.js"
5
+ import { commitWrite } from "../lib/mutate.js"
6
+ import { fromRoot } from "../lib/paths.js"
7
+
8
+ export async function review(root, args, flags, report) {
9
+ if (!(await readOptional(join(root, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
10
+ const [action, id] = args
11
+ if (!action) return { proposals: await listProposals(root) }
12
+ if (!id || !["accept", "reject", "edit"].includes(action)) {
13
+ throw Object.assign(new Error("Usage: connore review [accept|reject|edit <id>]."), { exitCode: 2 })
14
+ }
15
+ if (action === "edit") {
16
+ const proposals = await listProposals(root)
17
+ const lesson = proposals.find((item) => item.id === id)
18
+ if (!lesson) throw new Error(`No proposal "${id}".`)
19
+ const next = {
20
+ ...lesson,
21
+ mistake: flags.mistake || lesson.mistake,
22
+ fix: flags.fix || lesson.fix,
23
+ status: "proposed",
24
+ }
25
+ await commitWrite(lesson.file, lessonFile(next), report, fromRoot(root, lesson.file))
26
+ return { proposals: [next] }
27
+ }
28
+ const lesson = await moveProposal(root, id, action === "accept" ? "accepted" : "rejected", report)
29
+ if (action === "accept") await rebuildIndex(root, report, { includeDrafts: flags.includeDrafts })
30
+ return { proposals: [lesson] }
31
+ }
@@ -0,0 +1,13 @@
1
+ import { join } from "node:path"
2
+ import { readOptional } from "../lib/fs-safe.js"
3
+ import { collectEntries } from "../lib/index.js"
4
+ import { commitWrite } from "../lib/mutate.js"
5
+ import { renderRoutes } from "../lib/routes.js"
6
+
7
+ export async function routes(root, flags, report) {
8
+ if (!(await readOptional(join(root, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
9
+ const entries = await collectEntries(root, { includeDrafts: flags.includeDrafts })
10
+ const text = renderRoutes(entries.map((entry) => entry.path))
11
+ await commitWrite(join(root, ".ctx", "routes.md"), text, report, ".ctx/routes.md")
12
+ return text
13
+ }
@@ -0,0 +1,26 @@
1
+ import { readFile } from "node:fs/promises"
2
+ import { join } from "node:path"
3
+ import { readOptional } from "../lib/fs-safe.js"
4
+ import { collectEntries } from "../lib/index.js"
5
+ import { absFromPosix } from "../lib/paths.js"
6
+ import { buildGraph } from "../lib/graph.js"
7
+ import { rankEntries, relatedHits } from "../lib/search.js"
8
+
9
+ export async function search(root, query, flags) {
10
+ if (!(await readOptional(join(root, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
11
+ const entries = await collectEntries(root, { includeDrafts: flags.includeDrafts })
12
+ const ranked = []
13
+ for (const entry of entries) {
14
+ const abs = absFromPosix(root, entry.path)
15
+ const text = (await readFile(abs, "utf8")).replace(/\r\n/g, "\n")
16
+ const body = text.replace(/^---[\s\S]*?---\n/, "")
17
+ const headings = [...body.matchAll(/^#{1,3} (.+)$/gm)].map((match) => match[1]).join(" ")
18
+ const title = body.match(/^# (.+)$/m)?.[1] || entry.path
19
+ ranked.push({ ...entry, title, headings, body })
20
+ }
21
+ const hits = rankEntries(ranked, query).map(({ path, score, description, title }) => ({ path, score, title, description }))
22
+ if (!flags.related || !hits.length) return hits
23
+ const graph = await buildGraph(root, { includeDrafts: flags.includeDrafts })
24
+ const byPath = new Map(graph.nodes.map((node) => [node.path, node]))
25
+ return [...hits, ...relatedHits(hits, graph.edges, byPath)]
26
+ }
@@ -0,0 +1,35 @@
1
+ import { listAccepted } from "../lib/lessons.js"
2
+ import { readSignals } from "../lib/signals.js"
3
+
4
+ function isoWeek(date) {
5
+ const copy = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()))
6
+ const day = copy.getUTCDay() || 7
7
+ copy.setUTCDate(copy.getUTCDate() + 4 - day)
8
+ const start = new Date(Date.UTC(copy.getUTCFullYear(), 0, 1))
9
+ const week = Math.ceil(((copy - start) / 86400000 + 1) / 7)
10
+ return `${copy.getUTCFullYear()}-W${String(week).padStart(2, "0")}`
11
+ }
12
+
13
+ export function buildStats(signals, lessons) {
14
+ const weeks = new Map()
15
+ function bump(week, key) {
16
+ if (!week) return
17
+ if (!weeks.has(week)) weeks.set(week, { week, signals: 0, accepted: 0, recurring: 0 })
18
+ weeks.get(week)[key] += 1
19
+ }
20
+ for (const signal of signals) {
21
+ const at = new Date(signal.at)
22
+ if (!Number.isNaN(at.getTime())) bump(isoWeek(at), "signals")
23
+ }
24
+ for (const lesson of lessons) {
25
+ const at = new Date(lesson.lastSeen)
26
+ const week = Number.isNaN(at.getTime()) ? null : isoWeek(at)
27
+ if (lesson.status === "accepted") bump(week, "accepted")
28
+ if (lesson.flagged === "recurring") bump(week, "recurring")
29
+ }
30
+ return { weeks: [...weeks.values()].sort((a, b) => a.week.localeCompare(b.week)) }
31
+ }
32
+
33
+ export async function stats(root) {
34
+ return buildStats(await readSignals(root), await listAccepted(root))
35
+ }
@@ -0,0 +1,7 @@
1
+ import { undoLastRun } from "../lib/run.js"
2
+
3
+ export async function undo(root, report) {
4
+ const manifest = await undoLastRun(root)
5
+ report.add("changed", `.ctx/.runs/${manifest.id}.json`)
6
+ for (const file of manifest.files) report.add("changed", file.path)
7
+ }
@@ -1,14 +1,20 @@
1
- import { join } from "node:path"
2
- import { readOptional } from "../lib/fs-safe.js"
3
- import { rebuildIndex } from "../lib/index.js"
4
- import { packRoot } from "../lib/paths.js"
5
- import { syncTree } from "../lib/sync.js"
6
-
7
- export async function update(root, flags, report) {
8
- if (!(await readOptional(join(root, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
9
- const pack = flags.pack || "frontend"
10
- const packDir = join(packRoot, "packs", pack)
11
- if (!(await readOptional(join(packDir, "design", "tokens.md")))) throw new Error(`Unknown pack "${pack}".`)
12
- await syncTree(packDir, join(root, ".ctx", "library"), root, { overwrite: true, report })
13
- await rebuildIndex(root, report)
14
- }
1
+ import { join } from "node:path"
2
+ import { readConfig } from "../lib/config.js"
3
+ import { readOptional } from "../lib/fs-safe.js"
4
+ import { rebuildIndex } from "../lib/index.js"
5
+ import { packDir } from "../lib/packs.js"
6
+ import { patchTools } from "../lib/pointers.js"
7
+ import { syncTree } from "../lib/sync.js"
8
+
9
+ export async function update(root, flags, report) {
10
+ if (!(await readOptional(join(root, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
11
+ const { config } = await readConfig(root)
12
+ const source = await packDir(flags.pack || config?.pack || "knowledge")
13
+ await syncTree(source, join(root, ".ctx", "library"), root, {
14
+ overwrite: true,
15
+ report,
16
+ includeDrafts: flags.includeDrafts,
17
+ })
18
+ if (config?.tools?.length) await patchTools(root, config.tools, report)
19
+ await rebuildIndex(root, report, { includeDrafts: flags.includeDrafts })
20
+ }
@@ -0,0 +1,32 @@
1
+ import { readdir } from "node:fs/promises"
2
+ import { join } from "node:path"
3
+
4
+ export const GROUPS = [
5
+ { id: "screenshots", label: "UI screenshots", target: 20 },
6
+ { id: "pages", label: "Complete page references", target: 5 },
7
+ { id: "tokens", label: "Design token system", target: 1 },
8
+ { id: "rules", label: "Design rules", target: 10 },
9
+ { id: "components", label: "Component notes", target: 15 },
10
+ { id: "motion", label: "Motion notes", target: 10 },
11
+ { id: "custom", label: "Custom components", target: 5 },
12
+ { id: "golden", label: "Golden projects", target: 3 },
13
+ { id: "blueprints", label: "Page blueprints", target: 5 },
14
+ { id: "patterns", label: "Frontend patterns", target: 5 },
15
+ { id: "architecture", label: "Backend architecture", target: 3 },
16
+ { id: "schemas", label: "Database schemas", target: 5 },
17
+ { id: "api", label: "API examples", target: 5 },
18
+ { id: "auth", label: "Authentication workflows", target: 3 },
19
+ { id: "docs", label: "Versioned documentation sets", target: 5 },
20
+ { id: "coding-rules", label: "Coding rules", target: 10 },
21
+ { id: "skills", label: "Agent skills", target: 5 },
22
+ ]
23
+
24
+ export async function countGroup(root, id) {
25
+ try {
26
+ const names = await readdir(join(root, ".ctx", "mine", "catalog", id))
27
+ return names.filter((name) => name.endsWith(".md")).length
28
+ } catch (error) {
29
+ if (error.code === "ENOENT") return 0
30
+ throw error
31
+ }
32
+ }
@@ -0,0 +1,67 @@
1
+ import { join } from "node:path"
2
+ import { readOptional } from "./fs-safe.js"
3
+ import { commitWrite } from "./mutate.js"
4
+
5
+ export const SCHEMA_VERSION = 1
6
+
7
+ export const DEFAULT_IGNORE = ["node_modules", ".git", "dist", "build", ".next", "out", "coverage", ".turbo", "vault"]
8
+
9
+ export function defaultConfig(tools = []) {
10
+ return {
11
+ schemaVersion: SCHEMA_VERSION,
12
+ tools: [...tools],
13
+ pack: "",
14
+ ignore: [...DEFAULT_IGNORE],
15
+ provider: "local",
16
+ lessonBudget: 400,
17
+ lessonLimit: 5,
18
+ }
19
+ }
20
+
21
+ export function configText(config) {
22
+ return `${JSON.stringify(config, null, 2)}\n`
23
+ }
24
+
25
+ export function migrateConfig(input) {
26
+ const source = input && typeof input === "object" && !Array.isArray(input) ? input : {}
27
+ const version = Number.isInteger(source.schemaVersion) ? source.schemaVersion : 0
28
+ if (version > SCHEMA_VERSION) {
29
+ throw new Error(`This folder uses schemaVersion ${version}. Upgrade connore before writing to it.`)
30
+ }
31
+ const next = defaultConfig(Array.isArray(source.tools) ? source.tools.filter((tool) => typeof tool === "string") : [])
32
+ if (typeof source.pack === "string") next.pack = source.pack
33
+ if (Array.isArray(source.ignore) && source.ignore.length) next.ignore = source.ignore.map(String)
34
+ if (typeof source.provider === "string" && source.provider) next.provider = source.provider
35
+ if (Number.isInteger(source.lessonBudget) && source.lessonBudget > 0) next.lessonBudget = source.lessonBudget
36
+ if (Number.isInteger(source.lessonLimit) && source.lessonLimit > 0) next.lessonLimit = source.lessonLimit
37
+ next.schemaVersion = SCHEMA_VERSION
38
+ return next
39
+ }
40
+
41
+ export function configPath(root) {
42
+ return join(root, ".ctx", "config.json")
43
+ }
44
+
45
+ export async function readConfig(root) {
46
+ const file = configPath(root)
47
+ const raw = await readOptional(file)
48
+ if (!raw) return { file, raw: null, parsed: null, config: null }
49
+ let parsed
50
+ try {
51
+ parsed = JSON.parse(raw.toString("utf8"))
52
+ } catch {
53
+ throw new Error(".ctx/config.json is not valid JSON.")
54
+ }
55
+ return { file, raw, parsed, config: migrateConfig(parsed) }
56
+ }
57
+
58
+ export async function ensureConfig(root, report, tools, options = {}) {
59
+ const current = await readConfig(root)
60
+ const config = current.config || defaultConfig(tools || [])
61
+ if (!current.raw || options.replaceTools) config.tools = [...(tools || [])]
62
+ if (options.pack) config.pack = options.pack
63
+ const next = configText(config)
64
+ if (!current.raw || current.raw.toString("utf8") !== next) await commitWrite(current.file, next, report, ".ctx/config.json")
65
+ else report.add("skipped", ".ctx/config.json")
66
+ return config
67
+ }
@@ -2,6 +2,8 @@ import { randomBytes } from "node:crypto"
2
2
  import { mkdir, readdir, readFile, rename, rm, stat, unlink, writeFile } from "node:fs/promises"
3
3
  import { basename, dirname, join } from "node:path"
4
4
 
5
+ const RETRYABLE = new Set(["EPERM", "EBUSY", "EACCES"])
6
+
5
7
  export async function exists(filePath) {
6
8
  try {
7
9
  await stat(filePath)
@@ -21,41 +23,64 @@ export async function readOptional(filePath) {
21
23
  }
22
24
  }
23
25
 
24
- export async function writeAtomic(filePath, data) {
25
- await mkdir(dirname(filePath), { recursive: true })
26
+ async function writeOnce(filePath, data, io) {
27
+ await io.mkdir(dirname(filePath), { recursive: true })
26
28
  const tmp = join(dirname(filePath), `.${basename(filePath)}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`)
27
- await writeFile(tmp, data)
29
+ await io.writeFile(tmp, data)
28
30
  try {
29
- await rename(tmp, filePath)
31
+ await io.rename(tmp, filePath)
30
32
  } catch (error) {
31
33
  if (error.code !== "EEXIST" && error.code !== "EPERM") {
32
- await unlink(tmp).catch(() => {})
34
+ await io.unlink(tmp).catch(() => {})
33
35
  throw error
34
36
  }
35
37
  const backup = `${filePath}.${process.pid}.bak`
36
- await rename(filePath, backup)
38
+ await io.rename(filePath, backup)
37
39
  try {
38
- await rename(tmp, filePath)
40
+ await io.rename(tmp, filePath)
39
41
  } catch (renameError) {
40
- await rename(backup, filePath).catch(() => {})
42
+ await io.rename(backup, filePath).catch(() => {})
41
43
  throw renameError
42
44
  }
43
- await unlink(backup).catch(() => {})
45
+ await io.unlink(backup).catch(() => {})
46
+ }
47
+ }
48
+
49
+ export async function writeAtomic(filePath, data, io = {}) {
50
+ const fsio = {
51
+ mkdir: io.mkdir || mkdir,
52
+ writeFile: io.writeFile || writeFile,
53
+ rename: io.rename || rename,
54
+ unlink: io.unlink || unlink,
55
+ }
56
+ const sleep = io.sleep || ((ms) => new Promise((resolve) => setTimeout(resolve, ms)))
57
+ let last
58
+ for (let attempt = 0; attempt < 5; attempt += 1) {
59
+ try {
60
+ await writeOnce(filePath, data, fsio)
61
+ return
62
+ } catch (error) {
63
+ last = error
64
+ if (!RETRYABLE.has(error.code) || attempt === 4) throw error
65
+ await sleep(20 * (attempt + 1))
66
+ }
44
67
  }
68
+ throw last
45
69
  }
46
70
 
47
71
  export async function removeFile(filePath) {
48
72
  await rm(filePath, { force: true })
49
73
  }
50
74
 
51
- export async function walkFiles(dir) {
75
+ export async function walkFiles(dir, ignore = new Set()) {
52
76
  if (!(await exists(dir))) return []
53
77
  const entries = await readdir(dir, { withFileTypes: true })
54
78
  entries.sort((a, b) => a.name.localeCompare(b.name))
55
79
  const files = []
56
80
  for (const entry of entries) {
81
+ if (ignore.has(entry.name)) continue
57
82
  const filePath = join(dir, entry.name)
58
- if (entry.isDirectory()) files.push(...(await walkFiles(filePath)))
83
+ if (entry.isDirectory()) files.push(...(await walkFiles(filePath, ignore)))
59
84
  else if (entry.isFile()) files.push(filePath)
60
85
  }
61
86
  return files
@@ -0,0 +1,75 @@
1
+ import { execFile } from "node:child_process"
2
+ import { promisify } from "node:util"
3
+
4
+ const exec = promisify(execFile)
5
+
6
+ export function signalsFromGitLog(text) {
7
+ const commits = []
8
+ let current = null
9
+ for (const line of String(text || "").split(/\r?\n/)) {
10
+ if (!line.trim()) {
11
+ if (current) commits.push(current)
12
+ current = null
13
+ continue
14
+ }
15
+ if (!current) {
16
+ const [hash, date, ...rest] = line.split("\t")
17
+ current = { hash, date, subject: rest.join("\t"), files: [] }
18
+ } else current.files.push(line.trim())
19
+ }
20
+ if (current) commits.push(current)
21
+
22
+ const signals = []
23
+ const seen = new Map()
24
+ for (const commit of commits.reverse()) {
25
+ const when = Date.parse(commit.date)
26
+ if (/^revert\b/i.test(commit.subject)) {
27
+ signals.push({
28
+ at: commit.date,
29
+ kind: "failure",
30
+ text: commit.subject,
31
+ files: commit.files,
32
+ source: "git",
33
+ })
34
+ }
35
+ if (!/^fix\b/i.test(commit.subject)) {
36
+ for (const file of commit.files) seen.set(file, when)
37
+ continue
38
+ }
39
+ for (const file of commit.files) {
40
+ const earlier = seen.get(file)
41
+ if (Number.isFinite(earlier) && Number.isFinite(when) && Math.abs(when - earlier) <= 24 * 60 * 60 * 1000) {
42
+ signals.push({
43
+ at: commit.date,
44
+ kind: "fix",
45
+ text: `fix after a recent change in ${file}`,
46
+ files: [file],
47
+ source: "git",
48
+ })
49
+ }
50
+ }
51
+ }
52
+ return signals
53
+ }
54
+
55
+ export async function readGitSignals(root) {
56
+ try {
57
+ const { stdout } = await exec("git", ["-C", root, "log", "-n", "80", "--pretty=format:%H%x09%cI%x09%s", "--name-only"], {
58
+ timeout: 5000,
59
+ windowsHide: true,
60
+ })
61
+ return signalsFromGitLog(stdout)
62
+ } catch {
63
+ return []
64
+ }
65
+ }
66
+
67
+ export async function changedFiles(root) {
68
+ try {
69
+ const unstaged = await exec("git", ["-C", root, "diff", "--name-only", "HEAD"], { timeout: 5000, windowsHide: true })
70
+ const staged = await exec("git", ["-C", root, "diff", "--name-only", "--cached"], { timeout: 5000, windowsHide: true })
71
+ return [...new Set(`${unstaged.stdout}\n${staged.stdout}`.split(/\r?\n/).map((line) => line.trim()).filter(Boolean))]
72
+ } catch {
73
+ return []
74
+ }
75
+ }
@@ -0,0 +1,96 @@
1
+ import { readFile } from "node:fs/promises"
2
+ import { dirname, resolve } from "node:path"
3
+ import { walkFiles } from "./fs-safe.js"
4
+ import { parseFrontmatter } from "./frontmatter.js"
5
+ import { ctxPath, fromRoot, toPosix } from "./paths.js"
6
+ import { entryVisible } from "./index.js"
7
+
8
+ const LINK = /\[[^\]]*\]\(([^)\s]+\.md)(?:#[^)]*)?\)/g
9
+
10
+ function listOf(value) {
11
+ if (Array.isArray(value)) return value.map(String).map((item) => item.trim()).filter(Boolean)
12
+ if (typeof value === "string" && value.trim()) return [value.trim()]
13
+ return []
14
+ }
15
+
16
+ export async function collectNodes(root, options = {}) {
17
+ const files = []
18
+ for (const dir of ["library", "mine", "memory"]) files.push(...(await walkFiles(ctxPath(root, dir))))
19
+ const nodes = []
20
+ for (const file of files) {
21
+ if (!file.endsWith(".md")) continue
22
+ const text = await readFile(file, "utf8")
23
+ const data = parseFrontmatter(text)
24
+ if (!entryVisible(data, file, options)) continue
25
+ const links = []
26
+ for (const match of text.matchAll(LINK)) links.push(match[1])
27
+ nodes.push({
28
+ file,
29
+ path: fromRoot(root, file),
30
+ title: data.title || "",
31
+ tags: listOf(data.tags),
32
+ refs: listOf(data.refs),
33
+ links,
34
+ })
35
+ }
36
+ nodes.sort((a, b) => a.path.localeCompare(b.path))
37
+ return nodes
38
+ }
39
+
40
+ // Entry paths are written a few ways in practice: root-relative (.ctx/...),
41
+ // relative to the entry itself (../backend/auth.md), or as a bare file name.
42
+ function resolveTarget(root, node, target, byPath) {
43
+ const clean = toPosix(target).replace(/^\.\//, "")
44
+ if (byPath.has(clean)) return clean
45
+ if (byPath.has(`.ctx/${clean}`)) return `.ctx/${clean}`
46
+ const relative = toPosix(fromRoot(root, resolve(dirname(node.file), clean)))
47
+ if (byPath.has(relative)) return relative
48
+ const suffix = [...byPath.keys()].filter((key) => key.endsWith(`/${clean}`))
49
+ return suffix.length === 1 ? suffix[0] : null
50
+ }
51
+
52
+ export async function buildGraph(root, options = {}) {
53
+ const nodes = await collectNodes(root, options)
54
+ const byPath = new Map(nodes.map((node) => [node.path, node]))
55
+ const edges = []
56
+ const broken = []
57
+ const connected = new Set()
58
+
59
+ const connect = (from, to, kind) => {
60
+ edges.push({ from, to, kind })
61
+ connected.add(from)
62
+ connected.add(to)
63
+ }
64
+
65
+ for (const node of nodes) {
66
+ for (const ref of node.refs) {
67
+ const target = resolveTarget(root, node, ref, byPath)
68
+ if (target) connect(node.path, target, "ref")
69
+ else broken.push(`${node.path}: refs ${ref} does not resolve to an entry`)
70
+ }
71
+ for (const link of node.links) {
72
+ if (/^[a-z]+:\/\//i.test(link)) continue
73
+ const target = resolveTarget(root, node, link, byPath)
74
+ if (target) connect(node.path, target, "link")
75
+ else broken.push(`${node.path}: link ${link} does not resolve to an entry`)
76
+ }
77
+ }
78
+
79
+ const byTag = new Map()
80
+ for (const node of nodes) {
81
+ for (const tag of node.tags) {
82
+ const key = tag.toLowerCase()
83
+ if (!byTag.has(key)) byTag.set(key, [])
84
+ byTag.get(key).push(node.path)
85
+ }
86
+ }
87
+ for (const [tag, paths] of [...byTag.entries()].sort()) {
88
+ if (paths.length < 2) continue
89
+ for (let i = 0; i < paths.length; i += 1) {
90
+ for (let j = i + 1; j < paths.length; j += 1) connect(paths[i], paths[j], `tag:${tag}`)
91
+ }
92
+ }
93
+
94
+ const unconnected = nodes.map((node) => node.path).filter((path) => !connected.has(path))
95
+ return { nodes, edges, broken, unconnected }
96
+ }
@@ -0,0 +1,47 @@
1
+ import { join } from "node:path"
2
+ import { readOptional } from "./fs-safe.js"
3
+ import { commitWrite } from "./mutate.js"
4
+
5
+ export const CTXIGNORE = `# Folders connore skips while scanning
6
+ node_modules
7
+ .git
8
+ dist
9
+ build
10
+ .next
11
+ out
12
+ coverage
13
+ .turbo
14
+ vault
15
+ `
16
+
17
+ export const GITIGNORE_BLOCK = `# connore local state
18
+ .ctx/.signals/
19
+ .ctx/.runs/
20
+ .ctx/.lock
21
+ .ctx/vault/
22
+ `
23
+
24
+ export async function ignoreNames(root, config) {
25
+ const names = new Set(config?.ignore || [])
26
+ const file = await readOptional(join(root, ".ctxignore"))
27
+ if (!file) return names
28
+ for (const line of file.toString("utf8").split(/\r?\n/)) {
29
+ const trimmed = line.trim()
30
+ if (!trimmed || trimmed.startsWith("#")) continue
31
+ names.add(trimmed.replace(/^\//, "").replace(/\/$/, ""))
32
+ }
33
+ return names
34
+ }
35
+
36
+ export async function ensureLocalIgnores(root, report) {
37
+ await commitWrite(join(root, ".ctxignore"), CTXIGNORE, report, ".ctxignore")
38
+ const gitignore = join(root, ".gitignore")
39
+ const current = await readOptional(gitignore)
40
+ const text = current ? current.toString("utf8") : ""
41
+ if (text.includes(".ctx/.signals/")) {
42
+ report.add("skipped", ".gitignore")
43
+ return
44
+ }
45
+ const next = text ? `${text.replace(/\s*$/, "\n\n")}${GITIGNORE_BLOCK}` : GITIGNORE_BLOCK
46
+ await commitWrite(gitignore, next, report, ".gitignore")
47
+ }