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
@@ -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
+ }
@@ -3,7 +3,8 @@ import { join } from "node:path"
3
3
  import { readOptional } from "../lib/fs-safe.js"
4
4
  import { collectEntries } from "../lib/index.js"
5
5
  import { absFromPosix } from "../lib/paths.js"
6
- import { rankEntries } from "../lib/search.js"
6
+ import { buildGraph } from "../lib/graph.js"
7
+ import { rankEntries, relatedHits } from "../lib/search.js"
7
8
 
8
9
  export async function search(root, query, flags) {
9
10
  if (!(await readOptional(join(root, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
@@ -17,5 +18,9 @@ export async function search(root, query, flags) {
17
18
  const title = body.match(/^# (.+)$/m)?.[1] || entry.path
18
19
  ranked.push({ ...entry, title, headings, body })
19
20
  }
20
- return rankEntries(ranked, query).map(({ path, score, description, title }) => ({ path, score, title, description }))
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)]
21
26
  }
@@ -1,16 +1,20 @@
1
1
  import { join } from "node:path"
2
+ import { readConfig } from "../lib/config.js"
2
3
  import { readOptional } from "../lib/fs-safe.js"
3
4
  import { rebuildIndex } from "../lib/index.js"
4
5
  import { packDir } from "../lib/packs.js"
6
+ import { patchTools } from "../lib/pointers.js"
5
7
  import { syncTree } from "../lib/sync.js"
6
8
 
7
9
  export async function update(root, flags, report) {
8
10
  if (!(await readOptional(join(root, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
9
- const source = await packDir(flags.pack || "frontend")
11
+ const { config } = await readConfig(root)
12
+ const source = await packDir(flags.pack || config?.pack || "knowledge")
10
13
  await syncTree(source, join(root, ".ctx", "library"), root, {
11
14
  overwrite: true,
12
15
  report,
13
16
  includeDrafts: flags.includeDrafts,
14
17
  })
18
+ if (config?.tools?.length) await patchTools(root, config.tools, report)
15
19
  await rebuildIndex(root, report, { includeDrafts: flags.includeDrafts })
16
20
  }
package/src/lib/config.js CHANGED
@@ -1,64 +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
- ignore: [...DEFAULT_IGNORE],
14
- provider: "local",
15
- lessonBudget: 400,
16
- lessonLimit: 5,
17
- }
18
- }
19
-
20
- export function configText(config) {
21
- return `${JSON.stringify(config, null, 2)}\n`
22
- }
23
-
24
- export function migrateConfig(input) {
25
- const source = input && typeof input === "object" && !Array.isArray(input) ? input : {}
26
- const version = Number.isInteger(source.schemaVersion) ? source.schemaVersion : 0
27
- if (version > SCHEMA_VERSION) {
28
- throw new Error(`This folder uses schemaVersion ${version}. Upgrade connore before writing to it.`)
29
- }
30
- const next = defaultConfig(Array.isArray(source.tools) ? source.tools.filter((tool) => typeof tool === "string") : [])
31
- if (Array.isArray(source.ignore) && source.ignore.length) next.ignore = source.ignore.map(String)
32
- if (typeof source.provider === "string" && source.provider) next.provider = source.provider
33
- if (Number.isInteger(source.lessonBudget) && source.lessonBudget > 0) next.lessonBudget = source.lessonBudget
34
- if (Number.isInteger(source.lessonLimit) && source.lessonLimit > 0) next.lessonLimit = source.lessonLimit
35
- next.schemaVersion = SCHEMA_VERSION
36
- return next
37
- }
38
-
39
- export function configPath(root) {
40
- return join(root, ".ctx", "config.json")
41
- }
42
-
43
- export async function readConfig(root) {
44
- const file = configPath(root)
45
- const raw = await readOptional(file)
46
- if (!raw) return { file, raw: null, parsed: null, config: null }
47
- let parsed
48
- try {
49
- parsed = JSON.parse(raw.toString("utf8"))
50
- } catch {
51
- throw new Error(".ctx/config.json is not valid JSON.")
52
- }
53
- return { file, raw, parsed, config: migrateConfig(parsed) }
54
- }
55
-
56
- export async function ensureConfig(root, report, tools, options = {}) {
57
- const current = await readConfig(root)
58
- const config = current.config || defaultConfig(tools || [])
59
- if (!current.raw || options.replaceTools) config.tools = [...(tools || [])]
60
- const next = configText(config)
61
- if (!current.raw || current.raw.toString("utf8") !== next) await commitWrite(current.file, next, report, ".ctx/config.json")
62
- else report.add("skipped", ".ctx/config.json")
63
- return config
64
- }
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
+ }
@@ -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
+ }
package/src/lib/index.js CHANGED
@@ -1,72 +1,88 @@
1
- import { readFile } from "node:fs/promises"
2
- import { join } from "node:path"
3
- import { exists, readOptional, walkFiles } from "./fs-safe.js"
4
- import { commitWrite } from "./mutate.js"
5
- import { parseFrontmatter } from "./frontmatter.js"
6
- import { ctxPath, fromRoot } from "./paths.js"
7
-
8
- export function entryVisible(data, file, { includeDrafts = false } = {}) {
9
- if (!data) return false
10
- const path = file.replace(/\\/g, "/")
11
- if (path.includes("/_proposed/") || path.includes("/_rejected/") || path.includes("/vault/")) return false
12
- if (path.includes("/library/catalog/")) return false
13
- if (data.status === "proposed" || data.status === "rejected") return false
14
- if (data.status === "draft" && !includeDrafts) return false
15
- return true
16
- }
17
-
18
- export async function collectEntries(root, options = {}) {
19
- const files = []
20
- for (const dir of [ctxPath(root, "library"), ctxPath(root, "mine"), ctxPath(root, "memory")]) files.push(...(await walkFiles(dir)))
21
- const processFile = ctxPath(root, "PROCESS.md")
22
- if (await exists(processFile)) files.push(processFile)
23
- const startFile = ctxPath(root, "START.md")
24
- if (await exists(startFile)) files.push(startFile)
25
-
26
- const entries = []
27
- for (const file of files) {
28
- if (!file.endsWith(".md")) continue
29
- const text = await readFile(file, "utf8")
30
- const data = parseFrontmatter(text)
31
- if (!entryVisible(data, file, options)) continue
32
- if (file.replace(/\\/g, "/").includes("/memory/") && !/^## \d{4}-\d{2}-\d{2}\s*$/m.test(text)) continue
33
- entries.push({
34
- path: fromRoot(root, file),
35
- type: data.type || "",
36
- tags: Array.isArray(data.tags) ? data.tags.join(", ") : data.tags || "",
37
- description: data.description || "",
38
- })
39
- }
40
- entries.sort((a, b) => a.path.localeCompare(b.path))
41
- const start = entries.filter((entry) => entry.path === ".ctx/START.md")
42
- const rest = entries.filter((entry) => entry.path !== ".ctx/START.md")
43
- return [...start, ...rest]
44
- }
45
-
46
- export function renderIndex(entries) {
47
- const lines = [
48
- "# Index",
49
- "",
50
- "Read .ctx/START.md before new work. Load only the entries relevant to the task. Prefer text specs over opening images.",
51
- "",
52
- "| Path | Type | Tags | Description |",
53
- "| --- | --- | --- | --- |",
54
- ]
55
- for (const entry of entries) {
56
- lines.push(`| \`${entry.path}\` | ${entry.type} | ${entry.tags} | ${entry.description} |`)
57
- }
58
- lines.push("")
59
- return lines.join("\n")
60
- }
61
-
62
- export async function rebuildIndex(root, report, options = {}) {
63
- const file = join(root, ".ctx", "INDEX.md")
64
- const next = renderIndex(await collectEntries(root, options))
65
- const current = await readOptional(file)
66
- const currentText = current ? current.toString("utf8") : null
67
- if (currentText === next) {
68
- report.add("skipped", ".ctx/INDEX.md")
69
- return
70
- }
71
- await commitWrite(file, next, report, ".ctx/INDEX.md")
72
- }
1
+ import { readFile } from "node:fs/promises"
2
+ import { join } from "node:path"
3
+ import { exists, readOptional, walkFiles } from "./fs-safe.js"
4
+ import { commitWrite } from "./mutate.js"
5
+ import { parseFrontmatter } from "./frontmatter.js"
6
+ import { ctxPath, fromRoot } from "./paths.js"
7
+ import { estimateTokens } from "./tokens.js"
8
+
9
+ export function entryVisible(data, file, { includeDrafts = false } = {}) {
10
+ if (!data) return false
11
+ const path = file.replace(/\\/g, "/")
12
+ if (path.includes("/_proposed/") || path.includes("/_rejected/") || path.includes("/vault/")) return false
13
+ if (path.includes("/library/catalog/")) return false
14
+ if (data.status === "proposed" || data.status === "rejected") return false
15
+ if (data.status === "draft" && !includeDrafts) return false
16
+ return true
17
+ }
18
+
19
+ export async function collectEntries(root, options = {}) {
20
+ const files = []
21
+ for (const dir of [ctxPath(root, "library"), ctxPath(root, "mine"), ctxPath(root, "memory"), ctxPath(root, "prompts")]) {
22
+ files.push(...(await walkFiles(dir)))
23
+ }
24
+ const processFile = ctxPath(root, "PROCESS.md")
25
+ if (await exists(processFile)) files.push(processFile)
26
+ const startFile = ctxPath(root, "START.md")
27
+ if (await exists(startFile)) files.push(startFile)
28
+
29
+ const entries = []
30
+ for (const file of files) {
31
+ if (!file.endsWith(".md")) continue
32
+ const text = await readFile(file, "utf8")
33
+ const data = parseFrontmatter(text)
34
+ if (!entryVisible(data, file, options)) continue
35
+ if (file.replace(/\\/g, "/").includes("/memory/") && !/^## \d{4}-\d{2}-\d{2}\s*$/m.test(text)) continue
36
+ entries.push({
37
+ path: fromRoot(root, file),
38
+ type: data.type || "",
39
+ tags: Array.isArray(data.tags) ? data.tags.join(", ") : data.tags || "",
40
+ tokens: estimateTokens(text),
41
+ description: data.description || "",
42
+ })
43
+ }
44
+ // A mine file with the same path under library replaces that library row.
45
+ const chosen = new Map()
46
+ for (const entry of entries) {
47
+ const match = /^\.ctx\/(?:library|mine)\/(.+)$/.exec(entry.path)
48
+ const key = match ? match[1] : entry.path
49
+ const prev = chosen.get(key)
50
+ if (prev && prev.path.includes("/mine/") && !entry.path.includes("/mine/")) continue
51
+ chosen.set(key, entry)
52
+ }
53
+ const visible = [...chosen.values()]
54
+ visible.sort((a, b) => a.path.localeCompare(b.path))
55
+ const start = visible.filter((entry) => entry.path === ".ctx/START.md")
56
+ const rest = visible.filter((entry) => entry.path !== ".ctx/START.md")
57
+ return [...start, ...rest]
58
+ }
59
+
60
+ export function renderIndex(entries) {
61
+ const lines = [
62
+ "# Index",
63
+ "",
64
+ "Read .ctx/START.md before new work. Load only the entries relevant to the task. Prefer text specs over opening images.",
65
+ "",
66
+ "Tokens is a rough size estimate, not an exact count.",
67
+ "",
68
+ "| Path | Type | Tags | Tokens | Description |",
69
+ "| --- | --- | --- | --- | --- |",
70
+ ]
71
+ for (const entry of entries) {
72
+ lines.push(`| \`${entry.path}\` | ${entry.type} | ${entry.tags} | ${entry.tokens ?? 0} | ${entry.description} |`)
73
+ }
74
+ lines.push("")
75
+ return lines.join("\n")
76
+ }
77
+
78
+ export async function rebuildIndex(root, report, options = {}) {
79
+ const file = join(root, ".ctx", "INDEX.md")
80
+ const next = renderIndex(await collectEntries(root, options))
81
+ const current = await readOptional(file)
82
+ const currentText = current ? current.toString("utf8") : null
83
+ if (currentText === next) {
84
+ report.add("skipped", ".ctx/INDEX.md")
85
+ return
86
+ }
87
+ await commitWrite(file, next, report, ".ctx/INDEX.md")
88
+ }