connore 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -46
- package/package.json +36 -33
- package/packs/CONTRIBUTING.md +32 -0
- package/packs/base/catalog/README.md +24 -0
- package/packs/base/catalog/api.md +46 -0
- package/packs/base/catalog/auth.md +46 -0
- package/packs/base/catalog/backend.md +46 -0
- package/packs/base/catalog/blueprints.md +46 -0
- package/packs/base/catalog/components.md +46 -0
- package/packs/base/catalog/database.md +46 -0
- package/packs/base/catalog/docs.md +46 -0
- package/packs/base/catalog/github.md +46 -0
- package/packs/base/catalog/golden.md +46 -0
- package/packs/base/catalog/motion.md +46 -0
- package/packs/base/catalog/plan.md +46 -0
- package/packs/base/catalog/screenshots.md +46 -0
- package/packs/base/catalog/skills.md +46 -0
- package/packs/base/catalog/tokens.md +47 -0
- package/packs/base/planning/START.md +29 -0
- package/packs/base/planning/blueprint-template.md +46 -0
- package/packs/base/planning/plan-template.md +46 -0
- package/packs/base/rules/anti-patterns.md +46 -0
- package/packs/base/rules/code-style.md +46 -0
- package/packs/base/rules/definition-of-done.md +47 -0
- package/packs/base/rules/dependency-policy.md +46 -0
- package/packs/base/rules/error-handling.md +46 -0
- package/packs/base/rules/security-audit.md +47 -0
- package/packs/base/rules/security-baseline.md +46 -0
- package/packs/base/templates/bug-report.md +46 -0
- package/packs/base/templates/feature-spec.md +46 -0
- package/packs/base/templates/handoff.md +46 -0
- package/packs/base/templates/project-brief.md +46 -0
- package/packs/base/workflow/build-loop.md +48 -0
- package/packs/base/workflow/code-review.md +46 -0
- package/packs/base/workflow/debugging.md +47 -0
- package/packs/base/workflow/git-and-commits.md +46 -0
- package/packs/base/workflow/idea-to-spec.md +46 -0
- package/packs/base/workflow/session-handoff.md +46 -0
- package/packs/base/workflow/spec-to-plan.md +46 -0
- 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/api-conventions.md +48 -0
- package/packs/nextjs-fullstack/backend/auth-and-roles.md +46 -0
- package/packs/nextjs-fullstack/backend/background-jobs.md +46 -0
- package/packs/nextjs-fullstack/backend/caching.md +46 -0
- package/packs/nextjs-fullstack/backend/database.md +46 -0
- package/packs/nextjs-fullstack/backend/file-uploads.md +46 -0
- package/packs/nextjs-fullstack/backend/logging.md +46 -0
- package/packs/nextjs-fullstack/backend/migrations.md +46 -0
- package/packs/nextjs-fullstack/backend/rate-limiting.md +46 -0
- package/packs/nextjs-fullstack/backend/secrets-and-env.md +46 -0
- package/packs/nextjs-fullstack/backend/validation.md +46 -0
- package/packs/nextjs-fullstack/blueprints/ai-app.md +84 -0
- package/packs/nextjs-fullstack/blueprints/internal-tool.md +83 -0
- package/packs/nextjs-fullstack/blueprints/saas-app.md +83 -0
- package/packs/nextjs-fullstack/build-deploy/ci.md +45 -0
- package/packs/nextjs-fullstack/build-deploy/deploy.md +46 -0
- package/packs/nextjs-fullstack/build-deploy/monitoring.md +45 -0
- package/packs/nextjs-fullstack/build-deploy/performance.md +46 -0
- package/packs/nextjs-fullstack/build-deploy/project-structure.md +45 -0
- package/packs/nextjs-fullstack/build-deploy/release-checklist.md +47 -0
- package/packs/nextjs-fullstack/build-deploy/testing.md +46 -0
- package/packs/nextjs-fullstack/evals/README.md +46 -0
- package/packs/nextjs-fullstack/examples/golden-app/README.md +45 -0
- package/packs/nextjs-fullstack/frontend/accessibility.md +46 -0
- package/packs/nextjs-fullstack/frontend/components.md +46 -0
- 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 +46 -0
- package/packs/nextjs-fullstack/frontend/layout.md +46 -0
- package/packs/nextjs-fullstack/frontend/loading-empty-error.md +46 -0
- package/packs/nextjs-fullstack/frontend/motion.md +46 -0
- package/packs/nextjs-fullstack/frontend/responsive.md +46 -0
- package/packs/nextjs-fullstack/frontend/seo.md +47 -0
- package/packs/nextjs-fullstack/frontend/tables.md +46 -0
- package/packs/nextjs-fullstack/frontend/tokens.md +45 -0
- package/packs/nextjs-fullstack/integrations/analytics.md +46 -0
- package/packs/nextjs-fullstack/integrations/email.md +46 -0
- package/packs/nextjs-fullstack/integrations/llm-apis.md +46 -0
- package/packs/nextjs-fullstack/integrations/oauth.md +46 -0
- package/packs/nextjs-fullstack/integrations/object-storage.md +46 -0
- package/packs/nextjs-fullstack/integrations/payments.md +46 -0
- package/packs/nextjs-fullstack/integrations/queues.md +46 -0
- package/packs/nextjs-fullstack/integrations/search.md +46 -0
- package/packs/nextjs-fullstack/integrations/webhooks.md +46 -0
- package/packs/nextjs-fullstack/playbooks/add-ai-feature.md +46 -0
- package/packs/nextjs-fullstack/playbooks/add-auth.md +46 -0
- package/packs/nextjs-fullstack/playbooks/add-billing.md +50 -0
- package/packs/nextjs-fullstack/playbooks/add-crud.md +46 -0
- package/packs/nextjs-fullstack/playbooks/add-email.md +46 -0
- package/packs/nextjs-fullstack/playbooks/add-file-upload.md +46 -0
- package/packs/nextjs-fullstack/playbooks/add-webhook.md +46 -0
- package/packs/nextjs-fullstack/playbooks/ship-to-prod.md +47 -0
- 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 +377 -90
- package/src/commands/add.js +61 -57
- package/src/commands/catalog.js +21 -0
- package/src/commands/doctor.js +44 -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/hook.js +67 -50
- package/src/commands/init.js +74 -55
- package/src/commands/learn.js +39 -0
- package/src/commands/lint.js +13 -0
- package/src/commands/list.js +10 -10
- package/src/commands/log.js +49 -0
- package/src/commands/memory.js +14 -0
- package/src/commands/packs.js +21 -0
- package/src/commands/plan.js +41 -0
- package/src/commands/reindex.js +8 -8
- package/src/commands/review.js +31 -0
- package/src/commands/routes.js +13 -0
- package/src/commands/search.js +26 -0
- package/src/commands/stats.js +35 -0
- package/src/commands/undo.js +7 -0
- package/src/commands/update.js +20 -14
- package/src/lib/catalog.js +32 -0
- package/src/lib/config.js +67 -0
- package/src/lib/fs-safe.js +36 -11
- package/src/lib/gitlog.js +75 -0
- package/src/lib/graph.js +96 -0
- package/src/lib/ignore.js +47 -0
- package/src/lib/index.js +88 -57
- package/src/lib/lessons.js +173 -0
- package/src/lib/lint.js +185 -0
- package/src/lib/lock.js +47 -0
- package/src/lib/memory.js +49 -0
- package/src/lib/mutate.js +26 -0
- package/src/lib/packs.js +25 -0
- package/src/lib/paths.js +6 -2
- package/src/lib/plan.js +156 -0
- package/src/lib/pointers.js +3 -3
- package/src/lib/prompts.js +66 -0
- package/src/lib/provider.js +27 -0
- package/src/lib/report.js +41 -17
- package/src/lib/routes.js +59 -0
- package/src/lib/run.js +116 -0
- package/src/lib/search.js +64 -0
- package/src/lib/secrets.js +25 -0
- package/src/lib/signals.js +55 -0
- package/src/lib/sync.js +20 -12
- package/src/lib/tokens.js +8 -0
package/src/lib/paths.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { dirname, relative, resolve, sep } from "node:path"
|
|
1
|
+
import { dirname, join, relative, resolve, sep } from "node:path"
|
|
2
2
|
import { fileURLToPath } from "node:url"
|
|
3
3
|
|
|
4
4
|
export const packRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..", "..")
|
|
@@ -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."
|
|
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("/")
|
|
@@ -19,3 +19,7 @@ export function fromRoot(root, filePath) {
|
|
|
19
19
|
export function ctxPath(root, ...parts) {
|
|
20
20
|
return resolve(root, ".ctx", ...parts)
|
|
21
21
|
}
|
|
22
|
+
|
|
23
|
+
export function absFromPosix(root, posixPath) {
|
|
24
|
+
return join(root, ...posixPath.split("/"))
|
|
25
|
+
}
|
package/src/lib/plan.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { join } from "node:path"
|
|
2
|
+
import { readOptional } from "./fs-safe.js"
|
|
3
|
+
import { parseFrontmatter } from "./frontmatter.js"
|
|
4
|
+
import { packRoot } from "./paths.js"
|
|
5
|
+
|
|
6
|
+
const BLUEPRINT_DIRS = [
|
|
7
|
+
join(packRoot, "packs", "nextjs-fullstack", "blueprints"),
|
|
8
|
+
join(packRoot, "packs", "base", "planning"),
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
export function capText(text, budget) {
|
|
12
|
+
if (!text) return ""
|
|
13
|
+
const max = Math.max(0, budget) * 4
|
|
14
|
+
if (text.length <= max) return text.endsWith("\n") ? text : `${text}\n`
|
|
15
|
+
if (max < 8) return ""
|
|
16
|
+
const cut = text.slice(0, max).replace(/\s+\S*$/, "").trimEnd()
|
|
17
|
+
return cut ? `${cut}\n` : ""
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function parseBlueprint(text) {
|
|
21
|
+
const normalized = text.replace(/\r\n/g, "\n")
|
|
22
|
+
const data = parseFrontmatter(normalized) || {}
|
|
23
|
+
const phases = []
|
|
24
|
+
let current = null
|
|
25
|
+
for (const line of normalized.split("\n")) {
|
|
26
|
+
const heading = /^### Phase (\d+): (.+)$/.exec(line.trim())
|
|
27
|
+
if (heading) {
|
|
28
|
+
current = { number: Number(heading[1]), title: heading[2].trim(), tasks: [], acceptance: "", gate: "", entries: "" }
|
|
29
|
+
phases.push(current)
|
|
30
|
+
continue
|
|
31
|
+
}
|
|
32
|
+
if (!current) continue
|
|
33
|
+
if (line.startsWith("- ")) current.tasks.push(line.slice(2).trim())
|
|
34
|
+
else if (line.startsWith("Acceptance:")) current.acceptance = line.slice("Acceptance:".length).trim()
|
|
35
|
+
else if (line.startsWith("Gate:")) current.gate = line.slice("Gate:".length).trim()
|
|
36
|
+
else if (line.startsWith("Entries:")) current.entries = line.slice("Entries:".length).trim()
|
|
37
|
+
}
|
|
38
|
+
return { title: data.title || "Plan", phases }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function renderPlan(name, blueprint) {
|
|
42
|
+
const blocks = blueprint.phases.map((phase) => {
|
|
43
|
+
const tasks = phase.tasks.map((task) => `- [ ] ${task}`).join("\n")
|
|
44
|
+
const gate = phase.gate ? `Gate: [ ] ${phase.gate}` : ""
|
|
45
|
+
return [`## Phase ${phase.number}: ${phase.title}`, tasks, phase.acceptance ? `Acceptance: ${phase.acceptance}` : "", gate, phase.entries ? `Entries: ${phase.entries}` : ""]
|
|
46
|
+
.filter(Boolean)
|
|
47
|
+
.join("\n")
|
|
48
|
+
})
|
|
49
|
+
const first = blueprint.phases[0]
|
|
50
|
+
const next = first?.tasks[0] || first?.gate || "Review the plan"
|
|
51
|
+
const phaseLine = first ? `${first.number}. ${first.title}` : "0. Scope"
|
|
52
|
+
return `---
|
|
53
|
+
title: ${blueprint.title} plan
|
|
54
|
+
type: plan
|
|
55
|
+
tags: [plan]
|
|
56
|
+
blueprint: ${name}
|
|
57
|
+
description: Phase ${phaseLine}. Next: ${next}
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
# ${blueprint.title} plan
|
|
61
|
+
|
|
62
|
+
Current phase: ${phaseLine}
|
|
63
|
+
Next step: ${next}
|
|
64
|
+
Failed gate: none
|
|
65
|
+
|
|
66
|
+
## Current state
|
|
67
|
+
Phase ${phaseLine} is open. No task is done.
|
|
68
|
+
|
|
69
|
+
## Next step
|
|
70
|
+
${next}
|
|
71
|
+
|
|
72
|
+
${blocks.join("\n\n")}
|
|
73
|
+
`
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function planItems(text) {
|
|
77
|
+
const items = []
|
|
78
|
+
let phase = 0
|
|
79
|
+
for (const line of text.replace(/\r\n/g, "\n").split("\n")) {
|
|
80
|
+
const heading = /^## Phase (\d+): /.exec(line)
|
|
81
|
+
if (heading) {
|
|
82
|
+
phase = Number(heading[1])
|
|
83
|
+
continue
|
|
84
|
+
}
|
|
85
|
+
const task = /^- \[([ x])\] (.+)$/.exec(line)
|
|
86
|
+
if (task) {
|
|
87
|
+
items.push({ phase, kind: "task", done: task[1] === "x", text: task[2] })
|
|
88
|
+
continue
|
|
89
|
+
}
|
|
90
|
+
const gate = /^Gate: \[([ x])\] (.+)$/.exec(line)
|
|
91
|
+
if (gate) items.push({ phase, kind: "gate", done: gate[1] === "x", text: gate[2] })
|
|
92
|
+
}
|
|
93
|
+
return items
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function planView(text) {
|
|
97
|
+
const data = parseFrontmatter(text) || {}
|
|
98
|
+
const items = planItems(text)
|
|
99
|
+
const open = items.find((item) => !item.done)
|
|
100
|
+
const phaseItem = open || items.at(-1)
|
|
101
|
+
const phaseHeading = phaseItem ? text.match(new RegExp(`^## Phase ${phaseItem.phase}: (.+)$`, "m")) : null
|
|
102
|
+
const failed = items.find((item) => item.kind === "gate" && !item.done && items.some((other) => other.done && other.phase > item.phase))
|
|
103
|
+
return {
|
|
104
|
+
blueprint: data.blueprint || "",
|
|
105
|
+
title: data.title || "Plan",
|
|
106
|
+
phase: phaseHeading ? `${phaseItem.phase}. ${phaseHeading[1]}` : "0",
|
|
107
|
+
next: open ? open.text : "Plan complete",
|
|
108
|
+
failedGate: failed ? `Phase ${failed.phase}: ${failed.text}` : null,
|
|
109
|
+
done: items.filter((item) => item.done).length,
|
|
110
|
+
total: items.length,
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function markTaskDone(text, query) {
|
|
115
|
+
const needle = query.trim().toLowerCase()
|
|
116
|
+
if (!needle) throw new Error("Name the task to mark done.")
|
|
117
|
+
let flipped = false
|
|
118
|
+
const next = text.replace(/\r\n/g, "\n").split("\n").map((line) => {
|
|
119
|
+
if (flipped) return line
|
|
120
|
+
const task = /^- \[ \] (.+)$/.exec(line)
|
|
121
|
+
const gate = /^Gate: \[ \] (.+)$/.exec(line)
|
|
122
|
+
const label = task?.[1] || gate?.[1]
|
|
123
|
+
if (!label || !label.toLowerCase().includes(needle)) return line
|
|
124
|
+
flipped = true
|
|
125
|
+
return task ? `- [x] ${task[1]}` : `Gate: [x] ${gate[1]}`
|
|
126
|
+
}).join("\n")
|
|
127
|
+
if (!flipped) throw new Error(`No open task matches "${query}".`)
|
|
128
|
+
const view = planView(next)
|
|
129
|
+
return next
|
|
130
|
+
.replace(/^Current phase: .*$/m, `Current phase: ${view.phase}`)
|
|
131
|
+
.replace(/^Next step: .*$/m, `Next step: ${view.next}`)
|
|
132
|
+
.replace(/^## Next step\n[\s\S]*?(?=\n## )/, () => `## Next step\n${view.next}\n`)
|
|
133
|
+
.replace(/^Failed gate: .*$/m, `Failed gate: ${view.failedGate || "none"}`)
|
|
134
|
+
.replace(/^description: .*$/m, `description: Phase ${view.phase}. Next: ${view.next}`)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function planHookText(text, budget) {
|
|
138
|
+
const view = planView(text)
|
|
139
|
+
const lines = [
|
|
140
|
+
"Read .ctx/START.md before new work.",
|
|
141
|
+
`Current phase: ${view.phase}`,
|
|
142
|
+
`Next step: ${view.next}`,
|
|
143
|
+
]
|
|
144
|
+
if (view.failedGate) lines.push(`Failed gate: ${view.failedGate}`)
|
|
145
|
+
return capText(`${lines.join("\n")}\n`, budget)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export async function readBlueprint(name) {
|
|
149
|
+
for (const dir of BLUEPRINT_DIRS) {
|
|
150
|
+
const file = join(dir, `${name}.md`)
|
|
151
|
+
const data = await readOptional(file)
|
|
152
|
+
if (data) return { file, text: data.toString("utf8") }
|
|
153
|
+
}
|
|
154
|
+
throw new Error(`Unknown blueprint "${name}".`)
|
|
155
|
+
}
|
|
156
|
+
|
package/src/lib/pointers.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { join, sep } from "node:path"
|
|
2
|
-
import { exists, readOptional
|
|
2
|
+
import { exists, readOptional } from "./fs-safe.js"
|
|
3
|
+
import { commitWrite } from "./mutate.js"
|
|
3
4
|
import { POINTER } from "./paths.js"
|
|
4
5
|
|
|
5
6
|
const START = "<!-- ctx:start -->"
|
|
@@ -65,8 +66,7 @@ export async function patchPointer(file, preface, report, relative) {
|
|
|
65
66
|
report.add("skipped", relative)
|
|
66
67
|
return
|
|
67
68
|
}
|
|
68
|
-
|
|
69
|
-
report.add(text === null ? "created" : "changed", relative)
|
|
69
|
+
await commitWrite(file, next, report, relative)
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
export async function patchTools(root, tools, report) {
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { redactSecrets } from "./secrets.js"
|
|
2
|
+
|
|
3
|
+
export function previewCluster(cluster) {
|
|
4
|
+
return redactSecrets(cluster.rows.map((row) => `${row.kind}: ${row.text}`).join("\n"))
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function localLesson(cluster) {
|
|
8
|
+
const rows = cluster.rows
|
|
9
|
+
const first = rows[0]
|
|
10
|
+
const fix = rows.find((row) => row.kind === "fix") || rows.find((row) => row.kind === "decision")
|
|
11
|
+
const failure = rows.find((row) => row.kind === "failure")
|
|
12
|
+
const mistake = redactSecrets(failure?.text || first.text)
|
|
13
|
+
const repair = redactSecrets(fix?.text || first.text)
|
|
14
|
+
const files = [...new Set(rows.flatMap((row) => row.files || []))]
|
|
15
|
+
return {
|
|
16
|
+
title: mistake.slice(0, 72) || "Lesson",
|
|
17
|
+
scope: "project",
|
|
18
|
+
trigger: files[0] ? `when editing ${files[0]}` : "when this mistake shows up again",
|
|
19
|
+
mistake,
|
|
20
|
+
fix: repair,
|
|
21
|
+
evidence: `${rows.length} signals, first ${String(first.at || "").slice(0, 10)}`,
|
|
22
|
+
confidence: rows.length >= 5 ? "high" : "medium",
|
|
23
|
+
source: rows.every((row) => row.source === "git") ? "code-derived" : "agent-inferred",
|
|
24
|
+
files: files.join(", "),
|
|
25
|
+
lastSeen: new Date().toISOString().slice(0, 10),
|
|
26
|
+
}
|
|
27
|
+
}
|
package/src/lib/report.js
CHANGED
|
@@ -1,17 +1,41 @@
|
|
|
1
|
-
export function createReport(dryRun) {
|
|
2
|
-
const events = []
|
|
3
|
-
return {
|
|
4
|
-
dryRun,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
},
|
|
16
|
-
|
|
17
|
-
|
|
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
ADDED
|
@@ -0,0 +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
|
+
// 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
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export function tokenize(query) {
|
|
2
|
+
return String(query || "")
|
|
3
|
+
.toLowerCase()
|
|
4
|
+
.split(/[^a-z0-9]+/)
|
|
5
|
+
.filter((term) => term.length > 1)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function scoreEntry(entry, terms) {
|
|
9
|
+
if (!terms.length) return 0
|
|
10
|
+
const title = `${entry.title || ""}`.toLowerCase()
|
|
11
|
+
const path = `${entry.path || ""}`.toLowerCase()
|
|
12
|
+
const tags = `${entry.tags || ""} ${entry.description || ""}`.toLowerCase()
|
|
13
|
+
const headings = `${entry.headings || ""}`.toLowerCase()
|
|
14
|
+
const body = `${entry.body || ""}`.toLowerCase()
|
|
15
|
+
let score = 0
|
|
16
|
+
for (const term of terms) {
|
|
17
|
+
if (title.includes(term)) score += 8
|
|
18
|
+
if (path.includes(term)) score += 5
|
|
19
|
+
if (headings.includes(term)) score += 4
|
|
20
|
+
if (tags.includes(term)) score += 3
|
|
21
|
+
let found = 0
|
|
22
|
+
let from = 0
|
|
23
|
+
while (found < 5 && from < body.length) {
|
|
24
|
+
const at = body.indexOf(term, from)
|
|
25
|
+
if (at === -1) break
|
|
26
|
+
found += 1
|
|
27
|
+
from = at + term.length
|
|
28
|
+
}
|
|
29
|
+
score += found
|
|
30
|
+
}
|
|
31
|
+
return score
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function rankEntries(entries, query) {
|
|
35
|
+
const terms = tokenize(query)
|
|
36
|
+
return entries
|
|
37
|
+
.map((entry) => ({ ...entry, score: scoreEntry(entry, terms) }))
|
|
38
|
+
.filter((entry) => entry.score > 0)
|
|
39
|
+
.sort((a, b) => b.score - a.score || a.path.localeCompare(b.path))
|
|
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,25 @@
|
|
|
1
|
+
const PATTERNS = [
|
|
2
|
+
{ name: "aws-access-key", re: /AKIA[0-9A-Z]{16}/g },
|
|
3
|
+
{ name: "private-key", re: /-----BEGIN [A-Z ]*PRIVATE KEY-----/g },
|
|
4
|
+
{ name: "stripe-live", re: /sk_live_[0-9a-zA-Z]{8,}/g },
|
|
5
|
+
{ name: "openai", re: /\bsk-[A-Za-z0-9]{20,}/g },
|
|
6
|
+
{ name: "github-token", re: /\bghp_[A-Za-z0-9]{20,}/g },
|
|
7
|
+
]
|
|
8
|
+
|
|
9
|
+
export function secretHits(text) {
|
|
10
|
+
const hits = []
|
|
11
|
+
for (const pattern of PATTERNS) {
|
|
12
|
+
pattern.re.lastIndex = 0
|
|
13
|
+
if (pattern.re.test(text)) hits.push(pattern.name)
|
|
14
|
+
}
|
|
15
|
+
return hits
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function redactSecrets(text) {
|
|
19
|
+
let next = text
|
|
20
|
+
for (const pattern of PATTERNS) {
|
|
21
|
+
pattern.re.lastIndex = 0
|
|
22
|
+
next = next.replace(pattern.re, "[redacted]")
|
|
23
|
+
}
|
|
24
|
+
return next
|
|
25
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { createHash } from "node:crypto"
|
|
2
|
+
import { join } from "node:path"
|
|
3
|
+
import { readOptional } from "./fs-safe.js"
|
|
4
|
+
import { commitWrite } from "./mutate.js"
|
|
5
|
+
import { redactSecrets } from "./secrets.js"
|
|
6
|
+
|
|
7
|
+
export function signalPath(root) {
|
|
8
|
+
return join(root, ".ctx", ".signals", "log.jsonl")
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function readSignals(root) {
|
|
12
|
+
const raw = await readOptional(signalPath(root))
|
|
13
|
+
if (!raw) return []
|
|
14
|
+
const signals = []
|
|
15
|
+
for (const line of raw.toString("utf8").split(/\r?\n/)) {
|
|
16
|
+
if (!line.trim()) continue
|
|
17
|
+
try {
|
|
18
|
+
signals.push(JSON.parse(line))
|
|
19
|
+
} catch {
|
|
20
|
+
// A torn line is ignored so one bad append does not hide the rest.
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return signals
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function appendSignal(root, signal, report) {
|
|
27
|
+
const file = signalPath(root)
|
|
28
|
+
const current = (await readOptional(file))?.toString("utf8") || ""
|
|
29
|
+
const line = `${JSON.stringify(signal)}\n`
|
|
30
|
+
await commitWrite(file, `${current}${line}`, report, ".ctx/.signals/log.jsonl")
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function normalizeText(text) {
|
|
34
|
+
return redactSecrets(String(text || ""))
|
|
35
|
+
.toLowerCase()
|
|
36
|
+
.replace(/[^a-z0-9]+/g, " ")
|
|
37
|
+
.trim()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function clusterSignals(signals, minimum = 3) {
|
|
41
|
+
const groups = new Map()
|
|
42
|
+
for (const signal of signals) {
|
|
43
|
+
const key = normalizeText(signal.text)
|
|
44
|
+
if (!key) continue
|
|
45
|
+
if (!groups.has(key)) groups.set(key, [])
|
|
46
|
+
groups.get(key).push(signal)
|
|
47
|
+
}
|
|
48
|
+
return [...groups.entries()]
|
|
49
|
+
.filter(([, rows]) => rows.length >= minimum)
|
|
50
|
+
.map(([key, rows]) => ({
|
|
51
|
+
key,
|
|
52
|
+
id: createHash("sha256").update(key).digest("hex").slice(0, 10),
|
|
53
|
+
rows,
|
|
54
|
+
}))
|
|
55
|
+
}
|