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
package/src/lib/packs.js CHANGED
@@ -1,10 +1,25 @@
1
- import { join } from "node:path"
2
- import { walkFiles } from "./fs-safe.js"
3
- import { packRoot } from "./paths.js"
4
-
5
- export async function packDir(name) {
6
- const dir = join(packRoot, "packs", name)
7
- const files = await walkFiles(dir)
8
- if (!files.some((file) => file.endsWith(".md"))) throw new Error(`Unknown pack "${name}".`)
9
- return dir
10
- }
1
+ import { readdir } from "node:fs/promises"
2
+ import { join } from "node:path"
3
+ import { walkFiles } from "./fs-safe.js"
4
+ import { packRoot } from "./paths.js"
5
+
6
+ export async function listPacks() {
7
+ const root = join(packRoot, "packs")
8
+ const names = (await readdir(root, { withFileTypes: true }))
9
+ .filter((entry) => entry.isDirectory())
10
+ .map((entry) => entry.name)
11
+ .sort()
12
+ const packs = []
13
+ for (const name of names) {
14
+ const files = (await walkFiles(join(root, name))).filter((file) => file.endsWith(".md"))
15
+ if (files.length) packs.push({ name, entries: files.length })
16
+ }
17
+ return packs
18
+ }
19
+
20
+ export async function packDir(name) {
21
+ const dir = join(packRoot, "packs", name)
22
+ const files = await walkFiles(dir)
23
+ if (!files.some((file) => file.endsWith(".md"))) throw new Error(`Unknown pack "${name}".`)
24
+ return dir
25
+ }
package/src/lib/paths.js CHANGED
@@ -6,7 +6,7 @@ export const packRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..", "
6
6
  export const TOOLS = ["claude", "cursor", "codex", "copilot", "windsurf", "gemini"]
7
7
 
8
8
  export const POINTER =
9
- "Before building UI or backend features, read .ctx/INDEX.md and load only the entries relevant to the task. Prefer text specs over opening images. Before new work, read .ctx/START.md. When a decision is made, record it with connore log decision."
9
+ "Before building UI or backend features, read .ctx/INDEX.md and load only the entries relevant to the task. Prefer text specs over opening images. Before new work, read .ctx/START.md and .ctx/routes.md. When a moment matches a file in .ctx/prompts/, run that command. Record a decision with connore log. Edit user entries with connore edit under mine/. Do not open .ctx/vault."
10
10
 
11
11
  export function toPosix(filePath) {
12
12
  return filePath.split(sep).join("/")
@@ -0,0 +1,66 @@
1
+ import { join } from "node:path"
2
+ import { commitWrite } from "./mutate.js"
3
+ import { readOptional } from "./fs-safe.js"
4
+
5
+ // One file per command. The description is what the agent matches against the moment.
6
+ const COMMANDS = [
7
+ ["init", "Run connore init only when the project has no .ctx folder."],
8
+ ["update", "Run connore update when library entries are stale and mine must stay untouched."],
9
+ ["add", "Run connore add when the user drops a reference file that should enter mine."],
10
+ ["edit", "Run connore edit when a user-owned entry in mine needs a change."],
11
+ ["remove", "Run connore remove when the user wants a mine entry gone. Never remove library."],
12
+ ["list", "Run connore list when you need the catalog and search would be too narrow."],
13
+ ["index", "Run connore index after entries change and the table looks out of date."],
14
+ ["search", "Run connore search before opening the library. Use --related for neighbors."],
15
+ ["routes", "Run connore routes after update or add so the task table matches the library."],
16
+ ["graph", "Run connore graph when a reference looks broken or an entry seems unused."],
17
+ ["lint", "Run connore lint before calling an entry finished."],
18
+ ["doctor", "Run connore doctor when setup fails or before trusting a fresh clone."],
19
+ ["plan", "Run connore plan before writing code on a multi-step build."],
20
+ ["log", "Run connore log when a decision, fix, or failure should survive the session."],
21
+ ["handoff", "Run connore handoff when the session is ending or work is pausing."],
22
+ ["hook", "Run connore hook only from the session start hook, not by hand mid-task."],
23
+ ["undo", "Run connore undo when the last connore command wrote the wrong files."],
24
+ ["packs", "Run connore packs when choosing which library to install."],
25
+ ["learn", "Run connore learn when the same failure has shown up again."],
26
+ ["review", "Run connore review when a proposed lesson is waiting."],
27
+ ["memory", "Run connore memory when a note belongs to the project memory, not the journal."],
28
+ ["catalog", "Run connore catalog when counting references the user captured."],
29
+ ["stats", "Run connore stats when asked how often the layer is used."],
30
+ ]
31
+
32
+ export function promptFiles() {
33
+ return COMMANDS.map(([name, description]) => ({
34
+ name: `${name}.md`,
35
+ text: `---
36
+ title: ${name} command
37
+ type: protocol
38
+ tags: [prompt, ${name}]
39
+ source: library
40
+ updated: 2026-12-07
41
+ description: ${description}
42
+ ---
43
+
44
+ # ${name} command
45
+
46
+ ${description}
47
+
48
+ Run \`connore ${name}\` at that moment. Do not run it on every message. Read the matching rows from INDEX.md first when the command is search, routes, or plan.
49
+
50
+ ## Do not
51
+ Do not point this command at .ctx/vault or at .ctx/library. Library changes come from connore update. User edits go to mine.
52
+ `,
53
+ }))
54
+ }
55
+
56
+ export async function ensurePrompts(root, report) {
57
+ for (const prompt of promptFiles()) {
58
+ const file = join(root, ".ctx", "prompts", prompt.name)
59
+ const display = `.ctx/prompts/${prompt.name}`
60
+ if (await readOptional(file)) {
61
+ report.add("skipped", display)
62
+ continue
63
+ }
64
+ await commitWrite(file, prompt.text, report, display)
65
+ }
66
+ }
package/src/lib/report.js CHANGED
@@ -1,33 +1,41 @@
1
- export function createReport(dryRun, { json = false } = {}) {
2
- const events = []
3
- return {
4
- dryRun,
5
- json,
6
- events,
7
- mutations: [],
8
- add(kind, file, meta) {
9
- events.push({ kind, file })
10
- if (meta && Object.prototype.hasOwnProperty.call(meta, "previous")) {
11
- this.mutations.push({ kind, file, previous: meta.previous })
12
- }
13
- },
14
- print(stdout) {
15
- const count = (kind) => events.filter((event) => event.kind === kind).length
16
- const summary = {
17
- created: count("created"),
18
- changed: count("changed"),
19
- skipped: count("skipped"),
20
- removed: count("removed"),
21
- }
22
- if (json) {
23
- stdout.write(`${JSON.stringify({ ok: true, dryRun, events, summary })}\n`)
24
- return
25
- }
26
- for (const event of events) stdout.write(`${event.kind} ${event.file}\n`)
27
- const mode = dryRun ? " (dry-run)" : ""
28
- stdout.write(
29
- `summary: ${summary.created} created, ${summary.changed} changed, ${summary.skipped} skipped, ${summary.removed} removed${mode}\n`,
30
- )
31
- },
32
- }
33
- }
1
+ export function createReport(dryRun, { json = false } = {}) {
2
+ const events = []
3
+ return {
4
+ dryRun,
5
+ json,
6
+ events,
7
+ mutations: [],
8
+ // Set by openRun so each change reaches the manifest before the next write.
9
+ sink: null,
10
+ add(kind, file, meta) {
11
+ events.push({ kind, file })
12
+ if (meta && Object.prototype.hasOwnProperty.call(meta, "previous")) {
13
+ this.mutations.push({ kind, file, previous: meta.previous })
14
+ }
15
+ },
16
+ async record(kind, file, meta) {
17
+ this.add(kind, file, meta)
18
+ if (this.sink && meta && Object.prototype.hasOwnProperty.call(meta, "previous")) {
19
+ await this.sink({ kind, file, previous: meta.previous })
20
+ }
21
+ },
22
+ print(stdout) {
23
+ const count = (kind) => events.filter((event) => event.kind === kind).length
24
+ const summary = {
25
+ created: count("created"),
26
+ changed: count("changed"),
27
+ skipped: count("skipped"),
28
+ removed: count("removed"),
29
+ }
30
+ if (json) {
31
+ stdout.write(`${JSON.stringify({ ok: true, dryRun, events, summary })}\n`)
32
+ return
33
+ }
34
+ for (const event of events) stdout.write(`${event.kind} ${event.file}\n`)
35
+ const mode = dryRun ? " (dry-run)" : ""
36
+ stdout.write(
37
+ `summary: ${summary.created} created, ${summary.changed} changed, ${summary.skipped} skipped, ${summary.removed} removed${mode}\n`,
38
+ )
39
+ },
40
+ }
41
+ }
@@ -0,0 +1,59 @@
1
+ // One row per task. `match` is matched against entry paths. `skip` names areas
2
+ // the agent should not open for that task. Paths come from the installed library,
3
+ // so a task with nothing installed says so instead of inventing entries.
4
+ export const TASKS = [
5
+ {
6
+ title: "Frontend and design",
7
+ match: ["/frontend/", "/design/"],
8
+ skip: ["Backend and architecture", "Integrations"],
9
+ },
10
+ {
11
+ title: "Backend and architecture",
12
+ match: ["/backend/"],
13
+ skip: ["Frontend and design", "Growth and web"],
14
+ },
15
+ {
16
+ title: "Security and quality",
17
+ match: ["/rules/security", "/rules/definition-of-done", "/build-deploy/testing", "/build-deploy/release", "/rules/error-handling"],
18
+ skip: ["Growth and web"],
19
+ },
20
+ {
21
+ title: "Integrations",
22
+ match: ["/integrations/"],
23
+ skip: ["Frontend and design"],
24
+ },
25
+ {
26
+ title: "Growth and web",
27
+ match: ["/frontend/seo", "/frontend/copy"],
28
+ skip: ["Backend and architecture"],
29
+ },
30
+ {
31
+ title: "Workflow",
32
+ match: ["/planning/", "/workflow/", "/blueprints/", "START.md"],
33
+ skip: [],
34
+ },
35
+ ]
36
+
37
+ const HEAD = `---
38
+ title: Routes
39
+ type: process
40
+ tags: [routes, index]
41
+ updated: 2026-12-06
42
+ description: Per-task read and skip lists. Load the one task, not the library.
43
+ ---
44
+
45
+ # Routes
46
+
47
+ Read INDEX.md, then open one task below. Leave every Skip area closed.
48
+
49
+ `
50
+
51
+ export function renderRoutes(paths) {
52
+ const blocks = TASKS.map((task) => {
53
+ const hits = paths.filter((path) => task.match.some((part) => path.includes(part))).slice(0, 3)
54
+ const read = hits.length ? hits.map((path) => `- \`${path}\``).join("\n") : "- none installed"
55
+ const skip = task.skip.length ? `\nSkip: ${task.skip.join(", ")}.` : ""
56
+ return `## ${task.title}\n\nRead:\n${read}${skip}`
57
+ })
58
+ return `${HEAD}${blocks.join("\n\n")}\n`
59
+ }
package/src/lib/run.js CHANGED
@@ -1,73 +1,116 @@
1
- import { mkdir, readdir, readFile, rm, writeFile } from "node:fs/promises"
2
- import { dirname, join } from "node:path"
3
- import { writeAtomic } from "./fs-safe.js"
4
- import { absFromPosix } from "./paths.js"
5
-
6
- function runStamp(date = new Date()) {
7
- return date.toISOString().replace(/[:.]/g, "-")
8
- }
9
-
10
- export async function sealRun(root, command, report) {
11
- if (report.dryRun || report.mutations.length === 0) return null
12
- const id = runStamp()
13
- const dir = join(root, ".ctx", ".runs", id)
14
- const files = []
15
- for (const change of report.mutations) {
16
- const action = change.kind === "changed" ? "updated" : change.kind
17
- const entry = { path: change.file, action }
18
- if (change.previous) {
19
- const backup = absFromPosix(dir, change.file)
20
- await mkdir(dirname(backup), { recursive: true })
21
- await writeFile(backup, change.previous)
22
- entry.backup = `.ctx/.runs/${id}/${change.file}`
23
- }
24
- files.push(entry)
25
- }
26
- await mkdir(join(root, ".ctx", ".runs"), { recursive: true })
27
- await writeFile(join(root, ".ctx", ".runs", `${id}.json`), `${JSON.stringify({ id, command, files }, null, 2)}\n`)
28
- await pruneRuns(root, 10)
29
- return id
30
- }
31
-
32
- async function listRuns(root) {
33
- const dir = join(root, ".ctx", ".runs")
34
- let names = []
35
- try {
36
- names = await readdir(dir)
37
- } catch (error) {
38
- if (error.code === "ENOENT") return []
39
- throw error
40
- }
41
- return names
42
- .filter((name) => name.endsWith(".json"))
43
- .sort()
44
- .map((name) => ({
45
- id: name.slice(0, -5),
46
- json: join(dir, name),
47
- dir: join(dir, name.slice(0, -5)),
48
- }))
49
- }
50
-
51
- export async function pruneRuns(root, keep) {
52
- const runs = await listRuns(root)
53
- const extra = runs.slice(0, Math.max(0, runs.length - keep))
54
- for (const run of extra) {
55
- await rm(run.json, { force: true })
56
- await rm(run.dir, { recursive: true, force: true })
57
- }
58
- }
59
-
60
- export async function undoLastRun(root) {
61
- const runs = await listRuns(root)
62
- const latest = runs.at(-1)
63
- if (!latest) throw new Error("No run to undo.")
64
- const manifest = JSON.parse(await readFile(latest.json, "utf8"))
65
- for (const entry of [...manifest.files].reverse()) {
66
- const abs = absFromPosix(root, entry.path)
67
- if (entry.action === "created") await rm(abs, { force: true })
68
- else if (entry.backup) await writeAtomic(abs, await readFile(absFromPosix(root, entry.backup)))
69
- }
70
- await rm(latest.json, { force: true })
71
- await rm(latest.dir, { recursive: true, force: true })
72
- return manifest
73
- }
1
+ import { mkdir, readdir, readFile, rm, writeFile } from "node:fs/promises"
2
+ import { dirname, join } from "node:path"
3
+ import { writeAtomic } from "./fs-safe.js"
4
+ import { absFromPosix } from "./paths.js"
5
+
6
+ function runStamp(date = new Date()) {
7
+ return date.toISOString().replace(/[:.]/g, "-")
8
+ }
9
+
10
+ // The manifest is written when the run opens and rewritten after every change,
11
+ // so a run that is killed part-way through still leaves a record. Without this,
12
+ // undo would skip the interrupted writes and reverse an older run instead.
13
+ export async function openRun(root, command, report) {
14
+ if (report.dryRun) return null
15
+ const id = runStamp()
16
+ const runs = join(root, ".ctx", ".runs")
17
+ const dir = join(runs, id)
18
+ const json = join(runs, `${id}.json`)
19
+ const files = []
20
+ await mkdir(runs, { recursive: true })
21
+ const flush = async (complete) => {
22
+ await writeFile(json, `${JSON.stringify({ id, command, complete, files }, null, 2)}\n`)
23
+ }
24
+ await flush(false)
25
+ report.sink = async (change) => {
26
+ const action = change.kind === "changed" ? "updated" : change.kind
27
+ const entry = { path: change.file, action }
28
+ if (change.previous) {
29
+ const backup = absFromPosix(dir, change.file)
30
+ await mkdir(dirname(backup), { recursive: true })
31
+ await writeFile(backup, change.previous)
32
+ entry.backup = `.ctx/.runs/${id}/${change.file}`
33
+ }
34
+ files.push(entry)
35
+ await flush(false)
36
+ }
37
+ return { id, dir, json, files, flush, report }
38
+ }
39
+
40
+ export async function closeRun(root, handle) {
41
+ if (!handle) return null
42
+ handle.report.sink = null
43
+ if (!handle.files.length) {
44
+ await rm(handle.json, { force: true })
45
+ await rm(handle.dir, { recursive: true, force: true })
46
+ return null
47
+ }
48
+ await handle.flush(true)
49
+ await pruneRuns(root, 10)
50
+ return handle.id
51
+ }
52
+
53
+ export async function sealRun(root, command, report) {
54
+ if (report.dryRun || report.mutations.length === 0) return null
55
+ const id = runStamp()
56
+ const dir = join(root, ".ctx", ".runs", id)
57
+ const files = []
58
+ for (const change of report.mutations) {
59
+ const action = change.kind === "changed" ? "updated" : change.kind
60
+ const entry = { path: change.file, action }
61
+ if (change.previous) {
62
+ const backup = absFromPosix(dir, change.file)
63
+ await mkdir(dirname(backup), { recursive: true })
64
+ await writeFile(backup, change.previous)
65
+ entry.backup = `.ctx/.runs/${id}/${change.file}`
66
+ }
67
+ files.push(entry)
68
+ }
69
+ await mkdir(join(root, ".ctx", ".runs"), { recursive: true })
70
+ await writeFile(join(root, ".ctx", ".runs", `${id}.json`), `${JSON.stringify({ id, command, files }, null, 2)}\n`)
71
+ await pruneRuns(root, 10)
72
+ return id
73
+ }
74
+
75
+ async function listRuns(root) {
76
+ const dir = join(root, ".ctx", ".runs")
77
+ let names = []
78
+ try {
79
+ names = await readdir(dir)
80
+ } catch (error) {
81
+ if (error.code === "ENOENT") return []
82
+ throw error
83
+ }
84
+ return names
85
+ .filter((name) => name.endsWith(".json"))
86
+ .sort()
87
+ .map((name) => ({
88
+ id: name.slice(0, -5),
89
+ json: join(dir, name),
90
+ dir: join(dir, name.slice(0, -5)),
91
+ }))
92
+ }
93
+
94
+ export async function pruneRuns(root, keep) {
95
+ const runs = await listRuns(root)
96
+ const extra = runs.slice(0, Math.max(0, runs.length - keep))
97
+ for (const run of extra) {
98
+ await rm(run.json, { force: true })
99
+ await rm(run.dir, { recursive: true, force: true })
100
+ }
101
+ }
102
+
103
+ export async function undoLastRun(root) {
104
+ const runs = await listRuns(root)
105
+ const latest = runs.at(-1)
106
+ if (!latest) throw new Error("No run to undo.")
107
+ const manifest = JSON.parse(await readFile(latest.json, "utf8"))
108
+ for (const entry of [...manifest.files].reverse()) {
109
+ const abs = absFromPosix(root, entry.path)
110
+ if (entry.action === "created") await rm(abs, { force: true })
111
+ else if (entry.backup) await writeAtomic(abs, await readFile(absFromPosix(root, entry.backup)))
112
+ }
113
+ await rm(latest.json, { force: true })
114
+ await rm(latest.dir, { recursive: true, force: true })
115
+ return manifest
116
+ }
package/src/lib/search.js CHANGED
@@ -38,3 +38,27 @@ export function rankEntries(entries, query) {
38
38
  .filter((entry) => entry.score > 0)
39
39
  .sort((a, b) => b.score - a.score || a.path.localeCompare(b.path))
40
40
  }
41
+
42
+ // Direct refs and markdown links only. Shared tags connect too much to be useful here.
43
+ export function relatedHits(ranked, edges, byPath, limit = 5) {
44
+ const seen = new Set(ranked.map((hit) => hit.path))
45
+ const extra = []
46
+ for (const hit of ranked) {
47
+ for (const edge of edges) {
48
+ if (edge.kind !== "ref" && edge.kind !== "link") continue
49
+ const other = edge.from === hit.path ? edge.to : edge.to === hit.path ? edge.from : ""
50
+ if (!other || seen.has(other)) continue
51
+ seen.add(other)
52
+ const node = byPath.get(other)
53
+ extra.push({
54
+ path: other,
55
+ score: hit.score,
56
+ title: node?.title || "",
57
+ description: "related",
58
+ related: true,
59
+ })
60
+ if (extra.length >= limit) return extra
61
+ }
62
+ }
63
+ return extra
64
+ }
@@ -0,0 +1,8 @@
1
+ // A rough, deterministic size estimate so the index can show how much an entry
2
+ // costs to load. It is a character count, not a tokenizer: treat it as a
3
+ // relative guide, not as an exact number for any model.
4
+ export function estimateTokens(text) {
5
+ const normalized = String(text || "").replace(/\r\n/g, "\n").trim()
6
+ if (!normalized) return 0
7
+ return Math.ceil(normalized.length / 4)
8
+ }