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.
- package/README.md +13 -8
- package/package.json +2 -1
- package/packs/base/planning/START.md +29 -28
- package/packs/base/planning/blueprint-template.md +46 -46
- package/packs/base/planning/plan-template.md +46 -45
- package/packs/base/rules/anti-patterns.md +19 -16
- package/packs/base/rules/code-style.md +19 -16
- package/packs/base/rules/dependency-policy.md +19 -16
- package/packs/base/rules/error-handling.md +19 -16
- package/packs/base/rules/security-audit.md +47 -0
- package/packs/base/rules/security-baseline.md +19 -16
- package/packs/base/templates/bug-report.md +19 -16
- package/packs/base/templates/feature-spec.md +19 -16
- package/packs/base/templates/handoff.md +19 -16
- package/packs/base/templates/project-brief.md +19 -16
- package/packs/base/workflow/code-review.md +19 -16
- package/packs/base/workflow/debugging.md +18 -14
- package/packs/base/workflow/git-and-commits.md +19 -16
- package/packs/base/workflow/idea-to-spec.md +19 -16
- package/packs/base/workflow/session-handoff.md +19 -16
- package/packs/base/workflow/spec-to-plan.md +19 -16
- package/packs/knowledge/backend/api/conventions.md +21 -0
- package/packs/knowledge/backend/architecture/local-sqlite.md +20 -0
- package/packs/knowledge/backend/authentication/session-and-engine.md +24 -0
- package/packs/knowledge/backend/database/schema.md +21 -0
- package/packs/knowledge/components/custom/ambient-background.md +26 -0
- package/packs/knowledge/components/custom/ambient-background.tsx +12 -0
- package/packs/knowledge/components/custom/corner-frame.md +26 -0
- package/packs/knowledge/components/custom/corner-frame.tsx +48 -0
- package/packs/knowledge/components/custom/cta-button.md +26 -0
- package/packs/knowledge/components/custom/cta-button.tsx +10 -0
- package/packs/knowledge/components/custom/page-transition.md +26 -0
- package/packs/knowledge/components/custom/page-transition.tsx +10 -0
- package/packs/knowledge/components/custom/smooth-scroll.md +26 -0
- package/packs/knowledge/components/custom/smooth-scroll.tsx +32 -0
- package/packs/knowledge/components/motion-effects/README.md +30 -0
- package/packs/knowledge/components/ui-primitives/LICENSE +21 -0
- package/packs/knowledge/components/ui-primitives/README.md +22 -0
- package/packs/knowledge/components/ui-primitives/badge.md +26 -0
- package/packs/knowledge/components/ui-primitives/badge.tsx +48 -0
- package/packs/knowledge/components/ui-primitives/button.md +27 -0
- package/packs/knowledge/components/ui-primitives/button.tsx +66 -0
- package/packs/knowledge/components/ui-primitives/card.md +26 -0
- package/packs/knowledge/components/ui-primitives/card.tsx +102 -0
- package/packs/knowledge/components/ui-primitives/checkbox.md +26 -0
- package/packs/knowledge/components/ui-primitives/checkbox.tsx +32 -0
- package/packs/knowledge/components/ui-primitives/dialog.md +26 -0
- package/packs/knowledge/components/ui-primitives/dialog.tsx +168 -0
- package/packs/knowledge/components/ui-primitives/dropdown-menu.md +26 -0
- package/packs/knowledge/components/ui-primitives/dropdown-menu.tsx +268 -0
- package/packs/knowledge/components/ui-primitives/input.md +27 -0
- package/packs/knowledge/components/ui-primitives/input.tsx +18 -0
- package/packs/knowledge/components/ui-primitives/label.md +26 -0
- package/packs/knowledge/components/ui-primitives/label.tsx +23 -0
- package/packs/knowledge/components/ui-primitives/progress.md +26 -0
- package/packs/knowledge/components/ui-primitives/progress.tsx +30 -0
- package/packs/knowledge/components/ui-primitives/scroll-area.md +26 -0
- package/packs/knowledge/components/ui-primitives/scroll-area.tsx +54 -0
- package/packs/knowledge/components/ui-primitives/select.md +26 -0
- package/packs/knowledge/components/ui-primitives/select.tsx +191 -0
- package/packs/knowledge/components/ui-primitives/separator.md +26 -0
- package/packs/knowledge/components/ui-primitives/separator.tsx +27 -0
- package/packs/knowledge/components/ui-primitives/sonner.md +26 -0
- package/packs/knowledge/components/ui-primitives/sonner.tsx +49 -0
- package/packs/knowledge/components/ui-primitives/switch.md +26 -0
- package/packs/knowledge/components/ui-primitives/switch.tsx +32 -0
- package/packs/knowledge/components/ui-primitives/tabs.md +26 -0
- package/packs/knowledge/components/ui-primitives/tabs.tsx +89 -0
- package/packs/knowledge/components/ui-primitives/textarea.md +26 -0
- package/packs/knowledge/components/ui-primitives/textarea.tsx +17 -0
- package/packs/knowledge/components/ui-primitives/tooltip.md +26 -0
- package/packs/knowledge/components/ui-primitives/tooltip.tsx +56 -0
- package/packs/knowledge/design/aesthetics/app-shell.md +41 -0
- package/packs/knowledge/design/aesthetics/code-neutral.md +40 -0
- package/packs/knowledge/design/aesthetics/match.md +46 -0
- package/packs/knowledge/design/aesthetics/ruled-outline.md +40 -0
- package/packs/knowledge/design/aesthetics/solid-accent.md +43 -0
- package/packs/knowledge/design/animations/motion.md +40 -0
- package/packs/knowledge/design/project-style.md +50 -0
- package/packs/knowledge/design/references/benefit-card-grid.md +27 -0
- package/packs/knowledge/design/references/benefit-card-grid.png +0 -0
- package/packs/knowledge/design/references/cta-centered.md +27 -0
- package/packs/knowledge/design/references/cta-centered.png +0 -0
- package/packs/knowledge/design/references/cta-split-media.md +27 -0
- package/packs/knowledge/design/references/cta-split-media.png +0 -0
- package/packs/knowledge/design/references/dashboard-overview.md +31 -0
- package/packs/knowledge/design/references/dashboard-overview.png +0 -0
- package/packs/knowledge/design/references/faq-split-accordion.md +27 -0
- package/packs/knowledge/design/references/faq-split-accordion.png +0 -0
- package/packs/knowledge/design/references/feature-split-checklist.md +27 -0
- package/packs/knowledge/design/references/feature-split-checklist.png +0 -0
- package/packs/knowledge/design/references/footer-four-column.md +27 -0
- package/packs/knowledge/design/references/footer-four-column.png +0 -0
- package/packs/knowledge/design/references/footer-two-column.md +27 -0
- package/packs/knowledge/design/references/footer-two-column.png +0 -0
- package/packs/knowledge/design/references/hero-accent-curtain.md +27 -0
- package/packs/knowledge/design/references/hero-accent-curtain.png +0 -0
- package/packs/knowledge/design/references/hero-split-media.md +27 -0
- package/packs/knowledge/design/references/hero-split-media.png +0 -0
- package/packs/knowledge/design/references/logo-cloud-grid.md +27 -0
- package/packs/knowledge/design/references/logo-cloud-grid.png +0 -0
- package/packs/knowledge/design/references/logo-row-ruled.md +27 -0
- package/packs/knowledge/design/references/logo-row-ruled.png +0 -0
- package/packs/knowledge/design/references/pricing-three-card.md +27 -0
- package/packs/knowledge/design/references/pricing-three-card.png +0 -0
- package/packs/knowledge/design/references/steps-ruled-grid.md +27 -0
- package/packs/knowledge/design/references/steps-ruled-grid.png +0 -0
- package/packs/knowledge/design/rules.md +35 -0
- package/packs/knowledge/design/token-structure.md +46 -0
- package/packs/knowledge/design/tokens.md +55 -0
- package/packs/knowledge/frontend/README.md +50 -0
- package/packs/knowledge/frontend/SOURCES.md +40 -0
- package/packs/knowledge/frontend/accessibility/focus-and-dialogs.md +47 -0
- package/packs/knowledge/frontend/accessibility/semantics-and-keyboard.md +45 -0
- package/packs/knowledge/frontend/accessibility/wcag-targets.md +43 -0
- package/packs/knowledge/frontend/architecture/agent-context-files.md +43 -0
- package/packs/knowledge/frontend/architecture/app-foundations.md +43 -0
- package/packs/knowledge/frontend/architecture/error-handling.md +47 -0
- package/packs/knowledge/frontend/architecture/feature-modules.md +49 -0
- package/packs/knowledge/frontend/architecture/import-boundaries.md +44 -0
- package/packs/knowledge/frontend/architecture/naming.md +43 -0
- package/packs/knowledge/frontend/architecture/project-structure.md +48 -0
- package/packs/knowledge/frontend/architecture/routing.md +45 -0
- package/packs/knowledge/frontend/architecture/security.md +44 -0
- package/packs/knowledge/frontend/architecture/typescript.md +44 -0
- package/packs/knowledge/frontend/components/composition.md +45 -0
- package/packs/knowledge/frontend/components/data-display.md +47 -0
- package/packs/knowledge/frontend/components/library-choice.md +45 -0
- package/packs/knowledge/frontend/components/variants.md +44 -0
- package/packs/knowledge/frontend/forms/form-architecture.md +49 -0
- package/packs/knowledge/frontend/forms/multi-step.md +43 -0
- package/packs/knowledge/frontend/forms/validation.md +47 -0
- package/packs/knowledge/frontend/layout/responsive.md +41 -0
- package/packs/knowledge/frontend/page-blueprints/app-shell.md +16 -0
- package/packs/knowledge/frontend/page-blueprints/faq-footer.md +22 -0
- package/packs/knowledge/frontend/page-blueprints/feature-grid.md +22 -0
- package/packs/knowledge/frontend/page-blueprints/pricing.md +16 -0
- package/packs/knowledge/frontend/page-blueprints/saas-hero.md +24 -0
- package/packs/knowledge/frontend/patterns/dark-marketing.md +18 -0
- package/packs/knowledge/frontend/patterns/status-pill.md +19 -0
- package/packs/knowledge/frontend/performance/code-splitting.md +47 -0
- package/packs/knowledge/frontend/performance/images-and-vitals.md +44 -0
- package/packs/knowledge/frontend/performance/rendering.md +40 -0
- package/packs/knowledge/frontend/rendering/server-and-client.md +50 -0
- package/packs/knowledge/frontend/state/api-layer.md +49 -0
- package/packs/knowledge/frontend/state/async-ui-states.md +43 -0
- package/packs/knowledge/frontend/state/client-store.md +46 -0
- package/packs/knowledge/frontend/state/server-cache.md +42 -0
- package/packs/knowledge/frontend/state/state-categories.md +50 -0
- package/packs/knowledge/frontend/testing/component-tests.md +44 -0
- package/packs/knowledge/frontend/testing/strategy.md +46 -0
- package/packs/knowledge/inbox/README.md +14 -0
- package/packs/knowledge/workflows/authentication.md +18 -0
- package/packs/knowledge/workflows/crud.md +20 -0
- package/packs/knowledge/workflows/dashboard.md +22 -0
- package/packs/nextjs-fullstack/backend/auth-and-roles.md +19 -16
- package/packs/nextjs-fullstack/backend/background-jobs.md +19 -16
- package/packs/nextjs-fullstack/backend/caching.md +17 -14
- package/packs/nextjs-fullstack/backend/database.md +19 -16
- package/packs/nextjs-fullstack/backend/file-uploads.md +19 -16
- package/packs/nextjs-fullstack/backend/logging.md +17 -14
- package/packs/nextjs-fullstack/backend/migrations.md +17 -14
- package/packs/nextjs-fullstack/backend/rate-limiting.md +19 -16
- package/packs/nextjs-fullstack/backend/secrets-and-env.md +19 -16
- package/packs/nextjs-fullstack/backend/validation.md +19 -16
- package/packs/nextjs-fullstack/blueprints/ai-app.md +1 -1
- package/packs/nextjs-fullstack/blueprints/internal-tool.md +1 -1
- package/packs/nextjs-fullstack/blueprints/saas-app.md +1 -1
- package/packs/nextjs-fullstack/build-deploy/ci.md +18 -16
- package/packs/nextjs-fullstack/build-deploy/deploy.md +19 -16
- package/packs/nextjs-fullstack/build-deploy/monitoring.md +16 -14
- package/packs/nextjs-fullstack/build-deploy/performance.md +17 -14
- package/packs/nextjs-fullstack/build-deploy/project-structure.md +18 -16
- package/packs/nextjs-fullstack/build-deploy/release-checklist.md +20 -16
- package/packs/nextjs-fullstack/build-deploy/testing.md +19 -16
- package/packs/nextjs-fullstack/evals/README.md +18 -15
- package/packs/nextjs-fullstack/examples/golden-app/README.md +18 -16
- package/packs/nextjs-fullstack/frontend/accessibility.md +17 -14
- package/packs/nextjs-fullstack/frontend/components.md +19 -16
- package/packs/nextjs-fullstack/frontend/copy.md +46 -0
- package/packs/nextjs-fullstack/frontend/data-fetching.md +46 -0
- package/packs/nextjs-fullstack/frontend/forms.md +17 -14
- package/packs/nextjs-fullstack/frontend/layout.md +19 -16
- package/packs/nextjs-fullstack/frontend/loading-empty-error.md +19 -16
- package/packs/nextjs-fullstack/frontend/motion.md +17 -14
- package/packs/nextjs-fullstack/frontend/responsive.md +19 -16
- package/packs/nextjs-fullstack/frontend/seo.md +20 -16
- package/packs/nextjs-fullstack/frontend/tables.md +17 -14
- package/packs/nextjs-fullstack/frontend/tokens.md +18 -16
- package/packs/nextjs-fullstack/integrations/analytics.md +17 -14
- package/packs/nextjs-fullstack/integrations/email.md +17 -14
- package/packs/nextjs-fullstack/integrations/llm-apis.md +19 -16
- package/packs/nextjs-fullstack/integrations/oauth.md +19 -16
- package/packs/nextjs-fullstack/integrations/object-storage.md +19 -16
- package/packs/nextjs-fullstack/integrations/payments.md +17 -14
- package/packs/nextjs-fullstack/integrations/queues.md +17 -14
- package/packs/nextjs-fullstack/integrations/search.md +19 -16
- package/packs/nextjs-fullstack/integrations/webhooks.md +17 -14
- package/packs/nextjs-fullstack/playbooks/add-ai-feature.md +19 -16
- package/packs/nextjs-fullstack/playbooks/add-auth.md +19 -16
- package/packs/nextjs-fullstack/playbooks/add-crud.md +19 -16
- package/packs/nextjs-fullstack/playbooks/add-email.md +19 -16
- package/packs/nextjs-fullstack/playbooks/add-file-upload.md +19 -16
- package/packs/nextjs-fullstack/playbooks/add-webhook.md +19 -16
- package/packs/nextjs-fullstack/playbooks/ship-to-prod.md +20 -16
- package/plugins/connore/.claude-plugin/plugin.json +10 -0
- package/plugins/connore/hooks/hooks.json +16 -0
- package/plugins/connore/skills/connore-backend/SKILL.md +32 -0
- package/plugins/connore/skills/connore-handoff/SKILL.md +15 -0
- package/plugins/connore/skills/connore-routes/SKILL.md +16 -0
- package/plugins/connore/skills/connore-validate/SKILL.md +15 -0
- package/src/cli.js +110 -21
- package/src/commands/doctor.js +2 -0
- package/src/commands/edit.js +88 -0
- package/src/commands/graph.js +20 -0
- package/src/commands/handoff.js +45 -0
- package/src/commands/init.js +8 -3
- package/src/commands/lint.js +13 -5
- package/src/commands/log.js +49 -25
- package/src/commands/packs.js +21 -0
- package/src/commands/routes.js +13 -0
- package/src/commands/search.js +7 -2
- package/src/commands/update.js +5 -1
- package/src/lib/config.js +67 -64
- package/src/lib/graph.js +96 -0
- package/src/lib/index.js +88 -72
- package/src/lib/lessons.js +173 -173
- package/src/lib/lint.js +185 -67
- package/src/lib/mutate.js +26 -24
- package/src/lib/packs.js +25 -10
- package/src/lib/paths.js +1 -1
- package/src/lib/prompts.js +66 -0
- package/src/lib/report.js +41 -33
- package/src/lib/routes.js +59 -0
- package/src/lib/run.js +116 -73
- package/src/lib/search.js +24 -0
- 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
|
+
}
|
package/src/commands/search.js
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
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
|
}
|
package/src/commands/update.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (typeof source.
|
|
33
|
-
if (
|
|
34
|
-
if (
|
|
35
|
-
next.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
if (!current.raw ||
|
|
62
|
-
|
|
63
|
-
|
|
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
|
+
}
|
package/src/lib/graph.js
ADDED
|
@@ -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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (path.includes("/
|
|
13
|
-
if (
|
|
14
|
-
if (data.status === "
|
|
15
|
-
return
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (!
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
+
}
|