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
package/src/cli.js CHANGED
@@ -1,90 +1,377 @@
1
- import { add } from "./commands/add.js"
2
- import { printIndex } from "./commands/hook.js"
3
- import { init } from "./commands/init.js"
4
- import { list } from "./commands/list.js"
5
- import { reindex } from "./commands/reindex.js"
6
- import { update } from "./commands/update.js"
7
- import { createReport } from "./lib/report.js"
8
-
9
- const USAGE = `connore <command> [options]
10
-
11
- init [--tools all|claude,cursor,codex,copilot,windsurf,gemini] [--pack frontend] [--hooks] [--dry-run]
12
- add <path> [--type t] [--tags a,b] [--dry-run]
13
- update [--pack frontend] [--dry-run]
14
- list
15
- index [--dry-run]
16
- hook
17
- `
18
-
19
- function parse(argv) {
20
- const flags = { dryRun: false, hooks: false }
21
- const positionals = []
22
- for (let index = 0; index < argv.length; index += 1) {
23
- const arg = argv[index]
24
- if (arg === "--dry-run") flags.dryRun = true
25
- else if (arg === "--hooks") flags.hooks = true
26
- else if (arg === "--tools" || arg === "--pack" || arg === "--type" || arg === "--tags") {
27
- const value = argv[index + 1]
28
- if (!value || value.startsWith("--")) throw new Error(`Missing value for ${arg}.`)
29
- flags[arg.slice(2)] = value
30
- index += 1
31
- } else if (arg.startsWith("--")) throw new Error(`Unknown flag ${arg}.`)
32
- else positionals.push(arg)
33
- }
34
- return { command: positionals[0], args: positionals.slice(1), flags }
35
- }
36
-
37
- export async function run(argv, io = {}) {
38
- const stdout = io.stdout || process.stdout
39
- const stderr = io.stderr || process.stderr
40
- const cwd = io.cwd || process.cwd()
41
- try {
42
- const { command, args, flags } = parse(argv)
43
- if (!command) {
44
- stdout.write(USAGE)
45
- return 1
46
- }
47
- const report = createReport(flags.dryRun)
48
- if (command === "init") {
49
- if (args.length) throw new Error("init does not take a path. Run it inside the project.")
50
- await init(cwd, flags, report)
51
- report.print(stdout)
52
- return 0
53
- }
54
- if (flags.hooks) throw new Error("--hooks is only valid with init.")
55
- if (flags.tools) throw new Error("--tools is only valid with init.")
56
- if (command === "add") {
57
- if (flags.pack) throw new Error("--pack is only valid with init and update.")
58
- if (args.length !== 1) throw new Error("Usage: connore add <path>.")
59
- await add(cwd, args[0], flags, report)
60
- report.print(stdout)
61
- return 0
62
- }
63
- if (flags.type || flags.tags) throw new Error("--type and --tags are only valid with add.")
64
- if (command === "update") {
65
- if (args.length) throw new Error("update does not take a path.")
66
- await update(cwd, flags, report)
67
- report.print(stdout)
68
- return 0
69
- }
70
- if (flags.pack) throw new Error("--pack is only valid with init and update.")
71
- if (command === "list") {
72
- await list(cwd, stdout)
73
- if (flags.dryRun) report.print(stdout)
74
- return 0
75
- }
76
- if (command === "index") {
77
- await reindex(cwd, report)
78
- report.print(stdout)
79
- return 0
80
- }
81
- if (command === "hook") {
82
- await printIndex(cwd, stdout)
83
- return 0
84
- }
85
- throw new Error(`Unknown command "${command}".`)
86
- } catch (error) {
87
- stderr.write(`${error.message}\n`)
88
- return 1
89
- }
90
- }
1
+ import { readFile } from "node:fs/promises"
2
+ import { join } from "node:path"
3
+ import { add } from "./commands/add.js"
4
+ import { catalog } from "./commands/catalog.js"
5
+ import { doctor } from "./commands/doctor.js"
6
+ import { edit, remove } from "./commands/edit.js"
7
+ import { graph } from "./commands/graph.js"
8
+ import { handoff } from "./commands/handoff.js"
9
+ import { packs } from "./commands/packs.js"
10
+ import { printIndex } from "./commands/hook.js"
11
+ import { init } from "./commands/init.js"
12
+ import { learn } from "./commands/learn.js"
13
+ import { lint } from "./commands/lint.js"
14
+ import { list } from "./commands/list.js"
15
+ import { memory } from "./commands/memory.js"
16
+ import { log } from "./commands/log.js"
17
+ import { plan } from "./commands/plan.js"
18
+ import { search } from "./commands/search.js"
19
+ import { reindex } from "./commands/reindex.js"
20
+ import { routes } from "./commands/routes.js"
21
+ import { review } from "./commands/review.js"
22
+ import { stats } from "./commands/stats.js"
23
+ import { undo } from "./commands/undo.js"
24
+ import { update } from "./commands/update.js"
25
+ import { ensureConfig } from "./lib/config.js"
26
+ import { readOptional } from "./lib/fs-safe.js"
27
+ import { withLock } from "./lib/lock.js"
28
+ import { packDir } from "./lib/packs.js"
29
+ import { packRoot } from "./lib/paths.js"
30
+ import { parseTools } from "./lib/pointers.js"
31
+ import { createReport } from "./lib/report.js"
32
+ import { closeRun, openRun, sealRun } from "./lib/run.js"
33
+
34
+ const USAGE = `connore <command> [options]
35
+
36
+ init [--tools all|claude,cursor,codex,copilot,windsurf,gemini] [--pack knowledge] [--hooks] [--include-drafts] [--dry-run] [--json]
37
+ add <path> [--type t] [--tags a,b] [--dry-run] [--json]
38
+ edit mine/<file>.md [--title t] [--description d] [--tags a,b] [--text body] [--json]
39
+ remove mine/<file>.md [--json]
40
+ update [--pack name] [--include-drafts] [--dry-run] [--json]
41
+ list [--json]
42
+ index [--include-drafts] [--dry-run] [--json]
43
+ hook [--json]
44
+ lint [--strict] [--json]
45
+ doctor [--json]
46
+ graph [--include-drafts] [--json]
47
+ packs [--json]
48
+ undo [--json]
49
+ log <decision|fix|failure|note> "text" [--files a,b] [--json]
50
+ memory [project|architecture|decision|agent|preferences|task|knowledge] ["text"] [--json]
51
+ catalog [--json]
52
+ learn [--input file] [--yes] [--json]
53
+ review [accept|reject|edit <id>] [--mistake text] [--fix text] [--json]
54
+ stats [--json]
55
+ search "query" [--related] [--include-drafts] [--json]
56
+ routes [--include-drafts] [--dry-run] [--json]
57
+ handoff ["note"] [--json]
58
+ plan init <blueprint> | status | next | done <task> [--json]
59
+
60
+ --version print the package version
61
+ --help print this message
62
+ `
63
+
64
+ const VALUE_FLAGS = new Set(["--tools", "--pack", "--type", "--tags", "--files", "--mistake", "--fix", "--input", "--title", "--description", "--text"])
65
+ const WRITES = new Set(["init", "add", "update", "index", "undo", "log", "learn", "review", "plan", "memory", "routes", "handoff", "edit", "remove"])
66
+
67
+ function usage(message) {
68
+ const error = new Error(message)
69
+ error.exitCode = 2
70
+ return error
71
+ }
72
+
73
+ function parse(argv) {
74
+ const flags = { dryRun: false, hooks: false, json: false, includeDrafts: false, yes: false, strict: false }
75
+ const positionals = []
76
+ for (let index = 0; index < argv.length; index += 1) {
77
+ const arg = argv[index]
78
+ if (arg === "--dry-run") flags.dryRun = true
79
+ else if (arg === "--hooks") flags.hooks = true
80
+ else if (arg === "--json") flags.json = true
81
+ else if (arg === "--include-drafts") flags.includeDrafts = true
82
+ else if (arg === "--yes") flags.yes = true
83
+ else if (arg === "--strict") flags.strict = true
84
+ else if (arg === "--related") flags.related = true
85
+ else if (arg === "--version" || arg === "-v") flags.version = true
86
+ else if (arg === "--help" || arg === "-h") flags.help = true
87
+ else if (VALUE_FLAGS.has(arg)) {
88
+ const value = argv[index + 1]
89
+ if (!value || value.startsWith("--")) throw usage(`Missing value for ${arg}.`)
90
+ flags[arg.slice(2)] = value
91
+ index += 1
92
+ } else if (arg.startsWith("--")) throw usage(`Unknown flag ${arg}.`)
93
+ else positionals.push(arg)
94
+ }
95
+ return { command: positionals[0], args: positionals.slice(1), flags }
96
+ }
97
+
98
+ function printJson(stdout, payload) {
99
+ stdout.write(`${JSON.stringify(payload)}\n`)
100
+ }
101
+
102
+ export async function run(argv, io = {}) {
103
+ const stdout = io.stdout || process.stdout
104
+ const stderr = io.stderr || process.stderr
105
+ const cwd = io.cwd || process.cwd()
106
+ let flags = { json: argv.includes("--json") }
107
+ try {
108
+ const parsed = parse(argv)
109
+ flags = parsed.flags
110
+ const { command, args } = parsed
111
+ if (flags.version) {
112
+ const pkg = JSON.parse(await readFile(join(packRoot, "package.json"), "utf8"))
113
+ if (flags.json) printJson(stdout, { ok: true, version: pkg.version })
114
+ else stdout.write(`${pkg.version}\n`)
115
+ return 0
116
+ }
117
+ if (flags.help) {
118
+ stdout.write(USAGE)
119
+ return 0
120
+ }
121
+ if (!command) {
122
+ if (flags.json) printJson(stdout, { ok: false, error: "Missing command." })
123
+ else stdout.write(USAGE)
124
+ return 2
125
+ }
126
+ if (command === "init") {
127
+ if (args.length) throw usage("init does not take a path. Run it inside the project.")
128
+ if (flags.tools) {
129
+ try {
130
+ parseTools(flags.tools)
131
+ } catch (error) {
132
+ error.exitCode = 2
133
+ throw error
134
+ }
135
+ }
136
+ try {
137
+ await packDir(flags.pack || "knowledge")
138
+ } catch (error) {
139
+ error.exitCode = 2
140
+ throw error
141
+ }
142
+ }
143
+ const report = createReport(flags.dryRun, { json: flags.json })
144
+ const body = async () => {
145
+ if (command !== "init" && WRITES.has(command)) {
146
+ if (!(await readOptional(join(cwd, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
147
+ await ensureConfig(cwd, report)
148
+ }
149
+ if (command === "init") {
150
+ await init(cwd, flags, report)
151
+ report.print(stdout)
152
+ return
153
+ }
154
+ if (flags.hooks) throw usage("--hooks is only valid with init.")
155
+ if (flags.tools) throw usage("--tools is only valid with init.")
156
+ if (command === "edit") {
157
+ if (args.length !== 1) throw usage("Usage: connore edit mine/<file>.md [--title t] [--description d] [--tags a,b] [--text body].")
158
+ const result = await edit(cwd, args[0], flags, report)
159
+ if (flags.json) printJson(stdout, { ok: true, ...result, summary: countEvents(report) })
160
+ else report.print(stdout)
161
+ return
162
+ }
163
+ if (command === "remove") {
164
+ if (args.length !== 1) throw usage("Usage: connore remove mine/<file>.md.")
165
+ const result = await remove(cwd, args[0], report)
166
+ if (flags.json) printJson(stdout, { ok: true, ...result, summary: countEvents(report) })
167
+ else report.print(stdout)
168
+ return
169
+ }
170
+ if (command === "add") {
171
+ if (flags.pack) throw usage("--pack is only valid with init and update.")
172
+ if (args.length !== 1) throw usage("Usage: connore add <path>.")
173
+ await add(cwd, args[0], flags, report)
174
+ report.print(stdout)
175
+ return
176
+ }
177
+ if (flags.type || flags.tags) throw usage("--type and --tags are only valid with add.")
178
+ if (flags.title || flags.description || flags.text) throw usage("--title, --description, and --text are only valid with edit.")
179
+ if (command === "update") {
180
+ if (args.length) throw usage("update does not take a path.")
181
+ await update(cwd, flags, report)
182
+ report.print(stdout)
183
+ return
184
+ }
185
+ if (flags.pack) throw usage("--pack is only valid with init and update.")
186
+ if (command === "list") {
187
+ if (flags.json) {
188
+ const { collectEntries } = await import("./lib/index.js")
189
+ if (!(await readOptional(join(cwd, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
190
+ printJson(stdout, { ok: true, entries: await collectEntries(cwd, { includeDrafts: flags.includeDrafts }) })
191
+ } else await list(cwd, stdout)
192
+ return
193
+ }
194
+ if (command === "index") {
195
+ await reindex(cwd, flags, report)
196
+ report.print(stdout)
197
+ return
198
+ }
199
+ if (command === "hook") {
200
+ let output = ""
201
+ await printIndex(cwd, { write(chunk) { output += chunk } })
202
+ if (flags.json) printJson(stdout, { ok: true, output })
203
+ else stdout.write(output)
204
+ return
205
+ }
206
+ if (command === "lint") {
207
+ const { errors, warnings, scope } = await lint(cwd, { includeDrafts: flags.includeDrafts })
208
+ const failed = errors.length > 0 || (flags.strict && warnings.length > 0)
209
+ printJsonish(stdout, flags, { ok: !failed, scope, errors, warnings }, () => {
210
+ for (const problem of errors) stdout.write(`error ${problem}\n`)
211
+ for (const problem of warnings) stdout.write(`warn ${problem}\n`)
212
+ if (!errors.length && !warnings.length) stdout.write(`lint clean (${scope})\n`)
213
+ else stdout.write(`${errors.length} errors, ${warnings.length} warnings (${scope})\n`)
214
+ })
215
+ if (failed) throw Object.assign(new Error("lint failed"), { exitCode: 1, handled: true })
216
+ return
217
+ }
218
+ if (command === "graph") {
219
+ if (args.length) throw usage("graph does not take a path.")
220
+ if (!(await readOptional(join(cwd, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
221
+ const code = await graph(cwd, flags, stdout)
222
+ if (code) throw Object.assign(new Error("graph found broken references"), { exitCode: 1, handled: true })
223
+ return
224
+ }
225
+ if (command === "packs") {
226
+ if (args.length) throw usage("packs does not take a path.")
227
+ await packs(cwd, flags, stdout)
228
+ return
229
+ }
230
+ if (command === "doctor") {
231
+ const problems = await doctor(cwd)
232
+ printJsonish(stdout, flags, { ok: problems.length === 0, problems }, () => {
233
+ for (const problem of problems) stdout.write(`${problem}\n`)
234
+ stdout.write(problems.length ? `${problems.length} problems\n` : "doctor clean\n")
235
+ })
236
+ if (problems.length) throw Object.assign(new Error("doctor failed"), { exitCode: 1, handled: true })
237
+ return
238
+ }
239
+ if (command === "undo") {
240
+ if (args.length) throw usage("undo does not take a path.")
241
+ await undo(cwd, report)
242
+ report.print(stdout)
243
+ return
244
+ }
245
+ if (command === "catalog") {
246
+ if (args.length) throw usage("catalog does not take a path.")
247
+ await catalog(cwd, flags, stdout)
248
+ return
249
+ }
250
+ if (command === "memory") {
251
+ await memory(cwd, args, report, stdout, flags)
252
+ if (args.length) report.print(stdout)
253
+ return
254
+ }
255
+ if (command === "log") {
256
+ if (args.length !== 2) throw usage('Usage: connore log <decision|fix|failure|note> "text".')
257
+ await log(cwd, args[0], args[1], flags, report)
258
+ report.print(stdout)
259
+ return
260
+ }
261
+ if (command === "learn") {
262
+ const result = await learn(cwd, flags, report, io)
263
+ if (flags.json) printJson(stdout, { ok: true, ...result, summary: countEvents(report) })
264
+ else {
265
+ if (!result.proposals) stdout.write("No pattern has 3 occurrences yet.\n")
266
+ else if (!result.wrote) stdout.write(`${result.preview}\nRe-run with --yes to write proposals.\n`)
267
+ report.print(stdout)
268
+ }
269
+ return
270
+ }
271
+ if (command === "review") {
272
+ const result = await review(cwd, args, flags, report)
273
+ if (!args[0]) {
274
+ if (flags.json) printJson(stdout, { ok: true, proposals: result.proposals })
275
+ else if (!result.proposals.length) stdout.write("No proposals.\n")
276
+ else {
277
+ for (const lesson of result.proposals) {
278
+ stdout.write(`${lesson.id}\t${lesson.evidence}\t${lesson.mistake}\n`)
279
+ }
280
+ }
281
+ return
282
+ }
283
+ report.print(stdout)
284
+ return
285
+ }
286
+ if (command === "routes") {
287
+ if (args.length) throw usage("routes does not take a path.")
288
+ const text = await routes(cwd, flags, report)
289
+ if (flags.json) printJson(stdout, { ok: true, output: text, summary: countEvents(report) })
290
+ else {
291
+ stdout.write(text)
292
+ report.print(stdout)
293
+ }
294
+ return
295
+ }
296
+ if (command === "handoff") {
297
+ if (args.length > 1) throw usage('Usage: connore handoff "note".')
298
+ const result = await handoff(cwd, args[0] || "", report)
299
+ if (flags.json) printJson(stdout, { ok: true, ...result, summary: countEvents(report) })
300
+ else report.print(stdout)
301
+ return
302
+ }
303
+ if (command === "search") {
304
+ if (!args.length) throw usage('Usage: connore search "query".')
305
+ const results = await search(cwd, args.join(" "), flags)
306
+ if (flags.json) printJson(stdout, { ok: true, results })
307
+ else if (!results.length) stdout.write("No entries match.\n")
308
+ else {
309
+ for (const hit of results) stdout.write(`${hit.score}\t${hit.path}\t${hit.description}\n`)
310
+ }
311
+ return
312
+ }
313
+ if (command === "plan") {
314
+ if (!args.length) throw usage("Usage: connore plan init <blueprint> | status | next | done <task>.")
315
+ const view = await plan(cwd, args, report)
316
+ if (flags.json) printJson(stdout, { ok: true, ...view })
317
+ else {
318
+ stdout.write(`Phase ${view.phase}\nNext: ${view.next}\n`)
319
+ if (view.failedGate) stdout.write(`Failed gate: ${view.failedGate}\n`)
320
+ stdout.write(`${view.done}/${view.total} done\n`)
321
+ }
322
+ return
323
+ }
324
+ if (command === "stats") {
325
+ const data = await stats(cwd)
326
+ if (flags.json) printJson(stdout, { ok: true, ...data })
327
+ else if (!data.weeks.length) stdout.write("No signals yet.\n")
328
+ else {
329
+ for (const week of data.weeks) {
330
+ stdout.write(`${week.week}\tsignals ${week.signals}\taccepted ${week.accepted}\trecurring ${week.recurring}\n`)
331
+ }
332
+ }
333
+ return
334
+ }
335
+ throw usage(`Unknown command "${command}".`)
336
+ }
337
+
338
+ // undo restores from a manifest, so it must not open one of its own: that
339
+ // manifest would be the newest and undo would read its own empty record.
340
+ const writeAhead = !flags.dryRun && WRITES.has(command) && command !== "undo"
341
+ const guarded = async () => {
342
+ const handle = writeAhead ? await openRun(cwd, command, report) : null
343
+ try {
344
+ await body()
345
+ } finally {
346
+ await closeRun(cwd, handle)
347
+ }
348
+ if (!writeAhead && !flags.dryRun && WRITES.has(command)) await sealRun(cwd, command, report)
349
+ }
350
+
351
+ if (!flags.dryRun && WRITES.has(command) && (command === "init" || (await readOptional(join(cwd, ".ctx", "PROCESS.md"))))) {
352
+ await withLock(cwd, guarded)
353
+ } else {
354
+ await guarded()
355
+ }
356
+ return 0
357
+ } catch (error) {
358
+ if (error.handled) return error.exitCode || 1
359
+ const code = error.exitCode || 1
360
+ if (flags.json) printJson(stdout, { ok: false, error: error.message })
361
+ else stderr.write(`${error.message}\n`)
362
+ return code
363
+ }
364
+ }
365
+
366
+ // Tests and embedders call this with a captured io.
367
+ export const main = run
368
+
369
+ function countEvents(report) {
370
+ const count = (kind) => report.events.filter((event) => event.kind === kind).length
371
+ return { created: count("created"), changed: count("changed"), skipped: count("skipped"), removed: count("removed") }
372
+ }
373
+
374
+ function printJsonish(stdout, flags, payload, text) {
375
+ if (flags.json) printJson(stdout, payload)
376
+ else text()
377
+ }
@@ -1,57 +1,61 @@
1
- import { readFile, stat } from "node:fs/promises"
2
- import { basename, join, relative, resolve } from "node:path"
3
- import { readOptional, walkFiles, writeAtomic } from "../lib/fs-safe.js"
4
- import { twinStub, today } from "../lib/frontmatter.js"
5
- import { rebuildIndex } from "../lib/index.js"
6
- import { ctxPath, fromRoot } from "../lib/paths.js"
7
-
8
- const TYPES = new Set(["design-token", "component", "rule", "screenshot", "flow", "doc"])
9
- const IMAGE = /\.(png|jpe?g|webp|gif|svg)$/i
10
- const CODE = /\.(tsx|jsx|ts|js|mjs|cjs|css)$/i
11
-
12
- function defaultType(name) {
13
- if (IMAGE.test(name)) return "screenshot"
14
- if (CODE.test(name)) return "component"
15
- return null
16
- }
17
-
18
- async function placeFile(source, target, root, flags, report) {
19
- const display = fromRoot(root, target)
20
- if (await readOptional(target)) report.add("skipped", display)
21
- else {
22
- if (!report.dryRun) await writeAtomic(target, await readFile(source))
23
- report.add("created", display)
24
- }
25
- const type = flags.type || defaultType(basename(target))
26
- if (!type || target.endsWith(".md")) return
27
- const twin = target.replace(/\.[^.]+$/, ".md")
28
- const twinDisplay = fromRoot(root, twin)
29
- if (await readOptional(twin)) {
30
- report.add("skipped", twinDisplay)
31
- return
32
- }
33
- const tags = flags.tags ? flags.tags.split(",").map((tag) => tag.trim()).filter(Boolean) : []
34
- const body = twinStub({ title: basename(twin, ".md"), type, tags, date: today() })
35
- if (!report.dryRun) await writeAtomic(twin, body)
36
- report.add("created", twinDisplay)
37
- }
38
-
39
- export async function add(root, sourceArg, flags, report) {
40
- if (flags.type && !TYPES.has(flags.type)) throw new Error(`Unknown type "${flags.type}".`)
41
- if (!(await readOptional(join(root, ".ctx", "INDEX.md"))) && !(await readOptional(join(root, ".ctx", "PROCESS.md")))) {
42
- throw new Error("No .ctx/ folder. Run connore init first.")
43
- }
44
- const source = resolve(root, sourceArg)
45
- let info
46
- try {
47
- info = await stat(source)
48
- } catch {
49
- throw new Error(`Cannot read ${sourceArg}.`)
50
- }
51
- const mine = ctxPath(root, "mine")
52
- if (info.isDirectory()) {
53
- const files = await walkFiles(source)
54
- for (const file of files) await placeFile(file, join(mine, basename(source), relative(source, file)), root, flags, report)
55
- } else await placeFile(source, join(mine, basename(source)), root, flags, report)
56
- await rebuildIndex(root, report)
57
- }
1
+ import { readFile, stat } from "node:fs/promises"
2
+ import { basename, join, relative, resolve } from "node:path"
3
+ import { readConfig } from "../lib/config.js"
4
+ import { readOptional, walkFiles } from "../lib/fs-safe.js"
5
+ import { twinStub, today } from "../lib/frontmatter.js"
6
+ import { ignoreNames } from "../lib/ignore.js"
7
+ import { rebuildIndex } from "../lib/index.js"
8
+ import { commitWrite } from "../lib/mutate.js"
9
+ import { ctxPath, fromRoot } from "../lib/paths.js"
10
+ import { secretHits } from "../lib/secrets.js"
11
+
12
+ const TYPES = new Set(["design-token", "component", "rule", "screenshot", "flow", "doc"])
13
+ const IMAGE = /\.(png|jpe?g|webp|gif|svg)$/i
14
+ const CODE = /\.(tsx|jsx|ts|js|mjs|cjs|css)$/i
15
+
16
+ function defaultType(name) {
17
+ if (IMAGE.test(name)) return "screenshot"
18
+ if (CODE.test(name)) return "component"
19
+ return null
20
+ }
21
+
22
+ async function placeFile(source, target, root, flags, report) {
23
+ const display = fromRoot(root, target)
24
+ const bytes = await readFile(source)
25
+ const hits = secretHits(bytes.toString("utf8"))
26
+ if (hits.length) throw new Error(`Refusing to copy ${display} because it looks like a secret (${hits.join(", ")}).`)
27
+ if (await readOptional(target)) report.add("skipped", display)
28
+ else await commitWrite(target, bytes, report, display)
29
+ const type = flags.type || defaultType(basename(target))
30
+ if (!type || target.endsWith(".md")) return
31
+ const twin = target.replace(/\.[^.]+$/, ".md")
32
+ const twinDisplay = fromRoot(root, twin)
33
+ if (await readOptional(twin)) {
34
+ report.add("skipped", twinDisplay)
35
+ return
36
+ }
37
+ const tags = flags.tags ? flags.tags.split(",").map((tag) => tag.trim()).filter(Boolean) : []
38
+ const body = twinStub({ title: basename(twin, ".md"), type, tags, date: today() })
39
+ await commitWrite(twin, body, report, twinDisplay)
40
+ }
41
+
42
+ export async function add(root, sourceArg, flags, report) {
43
+ if (flags.type && !TYPES.has(flags.type)) throw new Error(`Unknown type "${flags.type}".`)
44
+ if (!(await readOptional(join(root, ".ctx", "INDEX.md"))) && !(await readOptional(join(root, ".ctx", "PROCESS.md")))) {
45
+ throw new Error("No .ctx/ folder. Run connore init first.")
46
+ }
47
+ const source = resolve(root, sourceArg)
48
+ let info
49
+ try {
50
+ info = await stat(source)
51
+ } catch {
52
+ throw new Error(`Cannot read ${sourceArg}.`)
53
+ }
54
+ const mine = ctxPath(root, "mine")
55
+ const ignore = await ignoreNames(root, (await readConfig(root)).config)
56
+ if (info.isDirectory()) {
57
+ const files = await walkFiles(source, ignore)
58
+ for (const file of files) await placeFile(file, join(mine, basename(source), relative(source, file)), root, flags, report)
59
+ } else await placeFile(source, join(mine, basename(source)), root, flags, report)
60
+ await rebuildIndex(root, report, { includeDrafts: flags.includeDrafts })
61
+ }
@@ -0,0 +1,21 @@
1
+ import { join } from "node:path"
2
+ import { readOptional } from "../lib/fs-safe.js"
3
+ import { GROUPS, countGroup } from "../lib/catalog.js"
4
+
5
+ export async function catalog(root, flags, stdout) {
6
+ if (!(await readOptional(join(root, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
7
+ const groups = []
8
+ for (const group of GROUPS) {
9
+ const count = await countGroup(root, group.id)
10
+ groups.push({ ...group, count, met: count >= group.target })
11
+ }
12
+ const started = groups.filter((group) => group.count > 0).length
13
+ if (flags.json) {
14
+ stdout.write(`${JSON.stringify({ ok: true, started, total: groups.length, groups })}\n`)
15
+ return
16
+ }
17
+ stdout.write(`${started}/${groups.length} groups started\n`)
18
+ for (const group of groups) {
19
+ stdout.write(`${group.count}/${group.target}\t${group.label}\t.ctx/mine/catalog/${group.id}\n`)
20
+ }
21
+ }