connore 0.1.0 → 0.1.1

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 (128) hide show
  1. package/README.md +53 -46
  2. package/package.json +35 -33
  3. package/packs/CONTRIBUTING.md +32 -0
  4. package/packs/base/catalog/README.md +24 -0
  5. package/packs/base/catalog/api.md +46 -0
  6. package/packs/base/catalog/auth.md +46 -0
  7. package/packs/base/catalog/backend.md +46 -0
  8. package/packs/base/catalog/blueprints.md +46 -0
  9. package/packs/base/catalog/components.md +46 -0
  10. package/packs/base/catalog/database.md +46 -0
  11. package/packs/base/catalog/docs.md +46 -0
  12. package/packs/base/catalog/github.md +46 -0
  13. package/packs/base/catalog/golden.md +46 -0
  14. package/packs/base/catalog/motion.md +46 -0
  15. package/packs/base/catalog/plan.md +46 -0
  16. package/packs/base/catalog/screenshots.md +46 -0
  17. package/packs/base/catalog/skills.md +46 -0
  18. package/packs/base/catalog/tokens.md +47 -0
  19. package/packs/base/planning/START.md +28 -0
  20. package/packs/base/planning/blueprint-template.md +46 -0
  21. package/packs/base/planning/plan-template.md +45 -0
  22. package/packs/base/rules/anti-patterns.md +43 -0
  23. package/packs/base/rules/code-style.md +43 -0
  24. package/packs/base/rules/definition-of-done.md +47 -0
  25. package/packs/base/rules/dependency-policy.md +43 -0
  26. package/packs/base/rules/error-handling.md +43 -0
  27. package/packs/base/rules/security-baseline.md +43 -0
  28. package/packs/base/templates/bug-report.md +43 -0
  29. package/packs/base/templates/feature-spec.md +43 -0
  30. package/packs/base/templates/handoff.md +43 -0
  31. package/packs/base/templates/project-brief.md +43 -0
  32. package/packs/base/workflow/build-loop.md +48 -0
  33. package/packs/base/workflow/code-review.md +43 -0
  34. package/packs/base/workflow/debugging.md +43 -0
  35. package/packs/base/workflow/git-and-commits.md +43 -0
  36. package/packs/base/workflow/idea-to-spec.md +43 -0
  37. package/packs/base/workflow/session-handoff.md +43 -0
  38. package/packs/base/workflow/spec-to-plan.md +43 -0
  39. package/packs/nextjs-fullstack/backend/api-conventions.md +48 -0
  40. package/packs/nextjs-fullstack/backend/auth-and-roles.md +43 -0
  41. package/packs/nextjs-fullstack/backend/background-jobs.md +43 -0
  42. package/packs/nextjs-fullstack/backend/caching.md +43 -0
  43. package/packs/nextjs-fullstack/backend/database.md +43 -0
  44. package/packs/nextjs-fullstack/backend/file-uploads.md +43 -0
  45. package/packs/nextjs-fullstack/backend/logging.md +43 -0
  46. package/packs/nextjs-fullstack/backend/migrations.md +43 -0
  47. package/packs/nextjs-fullstack/backend/rate-limiting.md +43 -0
  48. package/packs/nextjs-fullstack/backend/secrets-and-env.md +43 -0
  49. package/packs/nextjs-fullstack/backend/validation.md +43 -0
  50. package/packs/nextjs-fullstack/blueprints/ai-app.md +84 -0
  51. package/packs/nextjs-fullstack/blueprints/internal-tool.md +83 -0
  52. package/packs/nextjs-fullstack/blueprints/saas-app.md +83 -0
  53. package/packs/nextjs-fullstack/build-deploy/ci.md +43 -0
  54. package/packs/nextjs-fullstack/build-deploy/deploy.md +43 -0
  55. package/packs/nextjs-fullstack/build-deploy/monitoring.md +43 -0
  56. package/packs/nextjs-fullstack/build-deploy/performance.md +43 -0
  57. package/packs/nextjs-fullstack/build-deploy/project-structure.md +43 -0
  58. package/packs/nextjs-fullstack/build-deploy/release-checklist.md +43 -0
  59. package/packs/nextjs-fullstack/build-deploy/testing.md +43 -0
  60. package/packs/nextjs-fullstack/evals/README.md +43 -0
  61. package/packs/nextjs-fullstack/examples/golden-app/README.md +43 -0
  62. package/packs/nextjs-fullstack/frontend/accessibility.md +43 -0
  63. package/packs/nextjs-fullstack/frontend/components.md +43 -0
  64. package/packs/nextjs-fullstack/frontend/forms.md +43 -0
  65. package/packs/nextjs-fullstack/frontend/layout.md +43 -0
  66. package/packs/nextjs-fullstack/frontend/loading-empty-error.md +43 -0
  67. package/packs/nextjs-fullstack/frontend/motion.md +43 -0
  68. package/packs/nextjs-fullstack/frontend/responsive.md +43 -0
  69. package/packs/nextjs-fullstack/frontend/seo.md +43 -0
  70. package/packs/nextjs-fullstack/frontend/tables.md +43 -0
  71. package/packs/nextjs-fullstack/frontend/tokens.md +43 -0
  72. package/packs/nextjs-fullstack/integrations/analytics.md +43 -0
  73. package/packs/nextjs-fullstack/integrations/email.md +43 -0
  74. package/packs/nextjs-fullstack/integrations/llm-apis.md +43 -0
  75. package/packs/nextjs-fullstack/integrations/oauth.md +43 -0
  76. package/packs/nextjs-fullstack/integrations/object-storage.md +43 -0
  77. package/packs/nextjs-fullstack/integrations/payments.md +43 -0
  78. package/packs/nextjs-fullstack/integrations/queues.md +43 -0
  79. package/packs/nextjs-fullstack/integrations/search.md +43 -0
  80. package/packs/nextjs-fullstack/integrations/webhooks.md +43 -0
  81. package/packs/nextjs-fullstack/playbooks/add-ai-feature.md +43 -0
  82. package/packs/nextjs-fullstack/playbooks/add-auth.md +43 -0
  83. package/packs/nextjs-fullstack/playbooks/add-billing.md +50 -0
  84. package/packs/nextjs-fullstack/playbooks/add-crud.md +43 -0
  85. package/packs/nextjs-fullstack/playbooks/add-email.md +43 -0
  86. package/packs/nextjs-fullstack/playbooks/add-file-upload.md +43 -0
  87. package/packs/nextjs-fullstack/playbooks/add-webhook.md +43 -0
  88. package/packs/nextjs-fullstack/playbooks/ship-to-prod.md +43 -0
  89. package/src/cli.js +288 -90
  90. package/src/commands/add.js +61 -57
  91. package/src/commands/catalog.js +21 -0
  92. package/src/commands/doctor.js +42 -0
  93. package/src/commands/hook.js +67 -50
  94. package/src/commands/init.js +69 -55
  95. package/src/commands/learn.js +39 -0
  96. package/src/commands/lint.js +5 -0
  97. package/src/commands/list.js +10 -10
  98. package/src/commands/log.js +25 -0
  99. package/src/commands/memory.js +14 -0
  100. package/src/commands/plan.js +41 -0
  101. package/src/commands/reindex.js +8 -8
  102. package/src/commands/review.js +31 -0
  103. package/src/commands/search.js +21 -0
  104. package/src/commands/stats.js +35 -0
  105. package/src/commands/undo.js +7 -0
  106. package/src/commands/update.js +16 -14
  107. package/src/lib/catalog.js +32 -0
  108. package/src/lib/config.js +64 -0
  109. package/src/lib/fs-safe.js +36 -11
  110. package/src/lib/gitlog.js +75 -0
  111. package/src/lib/ignore.js +47 -0
  112. package/src/lib/index.js +27 -12
  113. package/src/lib/lessons.js +173 -0
  114. package/src/lib/lint.js +67 -0
  115. package/src/lib/lock.js +47 -0
  116. package/src/lib/memory.js +49 -0
  117. package/src/lib/mutate.js +24 -0
  118. package/src/lib/packs.js +10 -0
  119. package/src/lib/paths.js +6 -2
  120. package/src/lib/plan.js +156 -0
  121. package/src/lib/pointers.js +3 -3
  122. package/src/lib/provider.js +27 -0
  123. package/src/lib/report.js +20 -4
  124. package/src/lib/run.js +73 -0
  125. package/src/lib/search.js +40 -0
  126. package/src/lib/secrets.js +25 -0
  127. package/src/lib/signals.js +55 -0
  128. package/src/lib/sync.js +20 -12
@@ -1,50 +1,67 @@
1
- import { join } from "node:path"
2
- import { readOptional, writeAtomic } from "../lib/fs-safe.js"
3
-
4
- export const HOOK_COMMAND = "connore hook"
5
-
6
- export function mergeHookSettings(settings) {
7
- const hooks = settings.hooks && typeof settings.hooks === "object" && !Array.isArray(settings.hooks) ? settings.hooks : {}
8
- const session = Array.isArray(hooks.SessionStart) ? hooks.SessionStart : []
9
- const present = session.some((group) => Array.isArray(group?.hooks) && group.hooks.some((hook) => hook?.command === HOOK_COMMAND))
10
- if (present) return { changed: false, settings }
11
- return {
12
- changed: true,
13
- settings: {
14
- ...settings,
15
- hooks: {
16
- ...hooks,
17
- SessionStart: [...session, { hooks: [{ type: "command", command: HOOK_COMMAND }] }],
18
- },
19
- },
20
- }
21
- }
22
-
23
- export async function installHook(root, report) {
24
- const file = join(root, ".claude", "settings.json")
25
- const current = await readOptional(file)
26
- let json = {}
27
- if (current) {
28
- try {
29
- json = JSON.parse(current.toString("utf8"))
30
- } catch {
31
- throw new Error(".claude/settings.json is not valid JSON, so it was left untouched.")
32
- }
33
- if (!json || typeof json !== "object" || Array.isArray(json)) {
34
- throw new Error(".claude/settings.json must be a JSON object.")
35
- }
36
- }
37
- const merged = mergeHookSettings(json)
38
- const display = ".claude/settings.json"
39
- if (!merged.changed) {
40
- report.add("skipped", display)
41
- return
42
- }
43
- if (!report.dryRun) await writeAtomic(file, `${JSON.stringify(merged.settings, null, 2)}\n`)
44
- report.add(current ? "changed" : "created", display)
45
- }
46
-
47
- export async function printIndex(root, stdout) {
48
- const data = await readOptional(join(root, ".ctx", "INDEX.md"))
49
- if (data) stdout.write(data)
50
- }
1
+ import { join } from "node:path"
2
+ import { readOptional } from "../lib/fs-safe.js"
3
+ import { commitWrite } from "../lib/mutate.js"
4
+
5
+ export const HOOK_COMMAND = "connore hook"
6
+
7
+ export function mergeHookSettings(settings) {
8
+ const hooks = settings.hooks && typeof settings.hooks === "object" && !Array.isArray(settings.hooks) ? settings.hooks : {}
9
+ const session = Array.isArray(hooks.SessionStart) ? hooks.SessionStart : []
10
+ const present = session.some((group) => Array.isArray(group?.hooks) && group.hooks.some((hook) => hook?.command === HOOK_COMMAND))
11
+ if (present) return { changed: false, settings }
12
+ return {
13
+ changed: true,
14
+ settings: {
15
+ ...settings,
16
+ hooks: {
17
+ ...hooks,
18
+ SessionStart: [...session, { hooks: [{ type: "command", command: HOOK_COMMAND }] }],
19
+ },
20
+ },
21
+ }
22
+ }
23
+
24
+ export async function installHook(root, report) {
25
+ const file = join(root, ".claude", "settings.json")
26
+ const current = await readOptional(file)
27
+ let json = {}
28
+ if (current) {
29
+ try {
30
+ json = JSON.parse(current.toString("utf8"))
31
+ } catch {
32
+ throw new Error(".claude/settings.json is not valid JSON, so it was left untouched.")
33
+ }
34
+ if (!json || typeof json !== "object" || Array.isArray(json)) {
35
+ throw new Error(".claude/settings.json must be a JSON object.")
36
+ }
37
+ }
38
+ const merged = mergeHookSettings(json)
39
+ const display = ".claude/settings.json"
40
+ if (!merged.changed) {
41
+ report.add("skipped", display)
42
+ return
43
+ }
44
+ await commitWrite(file, `${JSON.stringify(merged.settings, null, 2)}\n`, report, display)
45
+ }
46
+
47
+ export async function printIndex(root, stdout) {
48
+ const data = await readOptional(join(root, ".ctx", "INDEX.md"))
49
+ let text = data ? data.toString("utf8") : ""
50
+ const { readConfig } = await import("../lib/config.js")
51
+ const config = (await readConfig(root)).config
52
+ if (config) {
53
+ const { changedFiles } = await import("../lib/gitlog.js")
54
+ const { lessonBlock, listAccepted, selectLessons } = await import("../lib/lessons.js")
55
+ const { planHookText } = await import("../lib/plan.js")
56
+ const planFile = await readOptional(join(root, ".ctx", "mine", "plan.md"))
57
+ const planText = planFile ? planHookText(planFile.toString("utf8"), config.lessonBudget) : ""
58
+ const planTokens = Math.ceil(planText.length / 4)
59
+ const chosen = selectLessons(await listAccepted(root), await changedFiles(root), {
60
+ limit: config.lessonLimit,
61
+ budget: Math.max(0, config.lessonBudget - planTokens),
62
+ })
63
+ text += lessonBlock(chosen)
64
+ text += planText
65
+ }
66
+ if (text) stdout.write(text)
67
+ }
@@ -1,55 +1,69 @@
1
- import { join } from "node:path"
2
- import { installHook } from "./hook.js"
3
- import { readOptional, writeAtomic } from "../lib/fs-safe.js"
4
- import { rebuildIndex } from "../lib/index.js"
5
- import { packRoot } from "../lib/paths.js"
6
- import { detectTools, parseTools, patchTools } from "../lib/pointers.js"
7
- import { syncTree } from "../lib/sync.js"
8
-
9
- export const PROCESS_MD = `---
10
- title: Process the inbox
11
- type: doc
12
- tags: [inbox]
13
- source: library
14
- updated: 2026-11-19
15
- description: How an agent turns raw inbox files into entries under mine/.
16
- ---
17
-
18
- # Process the inbox
19
-
20
- When asked to process \`.ctx/inbox\`, write only inside \`.ctx/\`.
21
-
22
- 1. List the inbox files before moving anything.
23
- 2. Copy each finished entry into \`.ctx/mine/\`. Do not edit \`.ctx/library/\`.
24
- 3. Every image or code file needs a same-name \`.md\` twin. Frontmatter: title, type, tags, source: user, updated, description.
25
- 4. Spec the twin in concrete terms: hex colors, font and size, spacing, radius, shadow, animation, and components. Mark anything you cannot see as TODO.
26
- 5. Leave the raw file in \`inbox/\` until the twin exists, then you may remove that inbox file.
27
- 6. Rebuild the index with \`connore index\`.
28
- 7. On later tasks, read \`INDEX.md\` and open only the relevant rows. Prefer the text spec over the image.
29
- `
30
-
31
- async function writeNew(file, contents, display, report) {
32
- if (await readOptional(file)) {
33
- report.add("skipped", display)
34
- return
35
- }
36
- if (!report.dryRun) await writeAtomic(file, contents)
37
- report.add("created", display)
38
- }
39
-
40
- export async function init(root, flags, report) {
41
- const pack = flags.pack || "frontend"
42
- const packDir = join(packRoot, "packs", pack)
43
- if (!(await readOptional(join(packDir, "design", "tokens.md")))) {
44
- throw new Error(`Unknown pack "${pack}".`)
45
- }
46
- const detected = await detectTools(root)
47
- const tools = flags.tools ? parseTools(flags.tools) : detected.length ? detected : ["claude", "codex"]
48
- await syncTree(packDir, join(root, ".ctx", "library"), root, { overwrite: false, report })
49
- await writeNew(join(root, ".ctx", "inbox", ".gitkeep"), "", ".ctx/inbox/.gitkeep", report)
50
- await writeNew(join(root, ".ctx", "mine", ".gitkeep"), "", ".ctx/mine/.gitkeep", report)
51
- await writeNew(join(root, ".ctx", "PROCESS.md"), PROCESS_MD, ".ctx/PROCESS.md", report)
52
- await patchTools(root, tools, report)
53
- if (flags.hooks) await installHook(root, report)
54
- await rebuildIndex(root, report)
55
- }
1
+ import { readFile } from "node:fs/promises"
2
+ import { join } from "node:path"
3
+ import { installHook } from "./hook.js"
4
+ import { ensureConfig } from "../lib/config.js"
5
+ import { ensureLocalIgnores } from "../lib/ignore.js"
6
+ import { readOptional } from "../lib/fs-safe.js"
7
+ import { rebuildIndex } from "../lib/index.js"
8
+ import { commitWrite } from "../lib/mutate.js"
9
+ import { packRoot } from "../lib/paths.js"
10
+ import { packDir } from "../lib/packs.js"
11
+ import { detectTools, parseTools, patchTools } from "../lib/pointers.js"
12
+ import { syncTree } from "../lib/sync.js"
13
+
14
+ export const PROCESS_MD = `---
15
+ title: Process the inbox
16
+ type: doc
17
+ tags: [inbox]
18
+ source: library
19
+ updated: 2026-11-19
20
+ description: How an agent turns raw inbox files into entries under mine/.
21
+ ---
22
+
23
+ # Process the inbox
24
+
25
+ When asked to process \`.ctx/inbox\`, write only inside \`.ctx/\`.
26
+
27
+ 1. List the inbox files before moving anything.
28
+ 2. Copy each finished entry into \`.ctx/mine/\`. Do not edit \`.ctx/library/\`.
29
+ 3. Every image or code file needs a same-name \`.md\` twin. Frontmatter: title, type, tags, source: user, updated, description.
30
+ 4. Spec the twin in concrete terms: hex colors, font and size, spacing, radius, shadow, animation, and components. Mark anything you cannot see as TODO.
31
+ 5. Leave the raw file in \`inbox/\` until the twin exists, then you may remove that inbox file.
32
+ 6. Rebuild the index with \`connore index\`.
33
+ 7. On later tasks, read \`INDEX.md\` and open only the relevant rows. Prefer the text spec over the image.
34
+ `
35
+
36
+ const VAULT_README = `# Vault
37
+
38
+ Put secrets and local credentials here. connore does not index this folder, copy it into a pack, or send it to a provider.
39
+ `
40
+
41
+ async function writeNew(file, contents, display, report) {
42
+ if (await readOptional(file)) {
43
+ report.add("skipped", display)
44
+ return
45
+ }
46
+ await commitWrite(file, contents, report, display)
47
+ }
48
+
49
+ export async function init(root, flags, report) {
50
+ const pack = flags.pack || "frontend"
51
+ const source = await packDir(pack)
52
+ const detected = await detectTools(root)
53
+ const tools = flags.tools ? parseTools(flags.tools) : detected.length ? detected : ["claude", "codex"]
54
+ await syncTree(source, join(root, ".ctx", "library"), root, {
55
+ overwrite: false,
56
+ report,
57
+ includeDrafts: flags.includeDrafts,
58
+ })
59
+ await writeNew(join(root, ".ctx", "inbox", ".gitkeep"), "", ".ctx/inbox/.gitkeep", report)
60
+ await writeNew(join(root, ".ctx", "mine", ".gitkeep"), "", ".ctx/mine/.gitkeep", report)
61
+ await writeNew(join(root, ".ctx", "vault", "README.md"), VAULT_README, ".ctx/vault/README.md", report)
62
+ await ensureConfig(root, report, tools, { replaceTools: Boolean(flags.tools) })
63
+ await writeNew(join(root, ".ctx", "PROCESS.md"), PROCESS_MD, ".ctx/PROCESS.md", report)
64
+ await writeNew(join(root, ".ctx", "START.md"), await readFile(join(packRoot, "packs", "base", "planning", "START.md")), ".ctx/START.md", report)
65
+ await ensureLocalIgnores(root, report)
66
+ await patchTools(root, tools, report)
67
+ if (flags.hooks) await installHook(root, report)
68
+ await rebuildIndex(root, report, { includeDrafts: flags.includeDrafts })
69
+ }
@@ -0,0 +1,39 @@
1
+ import { readFile } from "node:fs/promises"
2
+ import { readOptional } from "../lib/fs-safe.js"
3
+ import { join } from "node:path"
4
+ import { readGitSignals } from "../lib/gitlog.js"
5
+ import { markLessonHealth, writeProposal } from "../lib/lessons.js"
6
+ import { localLesson, previewCluster } from "../lib/provider.js"
7
+ import { readConfig } from "../lib/config.js"
8
+ import { redactSecrets, secretHits } from "../lib/secrets.js"
9
+ import { clusterSignals, readSignals } from "../lib/signals.js"
10
+
11
+ export async function learn(root, flags, report, io = {}) {
12
+ if (!(await readOptional(join(root, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
13
+ const { config } = await readConfig(root)
14
+ if ((config?.provider || "local") !== "local" && !io.draft) {
15
+ throw new Error("Refusing to send signals to an unknown provider. Set provider to local.")
16
+ }
17
+ const signals = [...(await readSignals(root)), ...(await readGitSignals(root))]
18
+ if (flags.input) {
19
+ const pasted = redactSecrets(await readFile(flags.input, "utf8"))
20
+ signals.push({ at: new Date().toISOString(), kind: "failure", text: pasted, files: [], source: "input" })
21
+ }
22
+ await markLessonHealth(root, signals, report)
23
+ const clusters = clusterSignals(signals, 3)
24
+ const preview = clusters.map((cluster) => previewCluster(cluster)).join("\n---\n")
25
+ if (!clusters.length || !flags.yes) return { wrote: false, proposals: clusters.length, preview }
26
+ const draft = io.draft || localLesson
27
+ for (const cluster of clusters) {
28
+ const safe = {
29
+ ...cluster,
30
+ rows: cluster.rows.map((row) => ({ ...row, text: redactSecrets(row.text) })),
31
+ }
32
+ const lesson = await draft(safe)
33
+ const rendered = JSON.stringify(lesson)
34
+ const hits = secretHits(rendered)
35
+ if (hits.length) throw new Error(`The drafted lesson still looks like a secret (${hits.join(", ")}).`)
36
+ await writeProposal(root, cluster.id, lesson, report)
37
+ }
38
+ return { wrote: true, proposals: clusters.length, preview }
39
+ }
@@ -0,0 +1,5 @@
1
+ import { lintPacks } from "../lib/lint.js"
2
+
3
+ export async function lint() {
4
+ return lintPacks()
5
+ }
@@ -1,10 +1,10 @@
1
- import { join } from "node:path"
2
- import { readOptional } from "../lib/fs-safe.js"
3
- import { collectEntries } from "../lib/index.js"
4
-
5
- export async function list(root, stdout) {
6
- if (!(await readOptional(join(root, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
7
- for (const entry of await collectEntries(root)) {
8
- stdout.write(`${entry.type}\t${entry.path}\t${entry.description}\n`)
9
- }
10
- }
1
+ import { join } from "node:path"
2
+ import { readOptional } from "../lib/fs-safe.js"
3
+ import { collectEntries } from "../lib/index.js"
4
+
5
+ export async function list(root, stdout) {
6
+ if (!(await readOptional(join(root, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
7
+ for (const entry of await collectEntries(root)) {
8
+ stdout.write(`${entry.type}\t${entry.path}\t${entry.description}\n`)
9
+ }
10
+ }
@@ -0,0 +1,25 @@
1
+ import { readOptional } from "../lib/fs-safe.js"
2
+ import { join } from "node:path"
3
+ import { appendSignal } from "../lib/signals.js"
4
+ import { redactSecrets } from "../lib/secrets.js"
5
+
6
+ const KINDS = new Set(["fix", "decision", "failure"])
7
+
8
+ export async function log(root, kind, text, flags, report) {
9
+ if (!KINDS.has(kind) || !text) {
10
+ throw Object.assign(new Error('Usage: connore log <fix|decision|failure> "text".'), { exitCode: 2 })
11
+ }
12
+ if (!(await readOptional(join(root, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
13
+ const files = flags.files ? flags.files.split(",").map((file) => file.trim()).filter(Boolean) : []
14
+ await appendSignal(
15
+ root,
16
+ {
17
+ at: new Date().toISOString(),
18
+ kind,
19
+ text: redactSecrets(text),
20
+ files,
21
+ source: "log",
22
+ },
23
+ report,
24
+ )
25
+ }
@@ -0,0 +1,14 @@
1
+ import { MEMORIES, appendMemory } from "../lib/memory.js"
2
+ import { rebuildIndex } from "../lib/index.js"
3
+
4
+ export async function memory(root, args, report, stdout, flags) {
5
+ if (!args.length) {
6
+ const lines = MEMORIES.map((item) => `${item.id}\t.ctx/memory/${item.file}\t${item.description}`)
7
+ if (flags.json) stdout.write(`${JSON.stringify({ ok: true, memories: MEMORIES })}\n`)
8
+ else stdout.write(`${lines.join("\n")}\n`)
9
+ return
10
+ }
11
+ const [id, ...rest] = args
12
+ await appendMemory(root, id, rest.join(" "), report)
13
+ await rebuildIndex(root, report, { includeDrafts: flags.includeDrafts })
14
+ }
@@ -0,0 +1,41 @@
1
+ import { join } from "node:path"
2
+ import { readOptional } from "../lib/fs-safe.js"
3
+ import { rebuildIndex } from "../lib/index.js"
4
+ import { commitWrite } from "../lib/mutate.js"
5
+ import { markTaskDone, parseBlueprint, planView, readBlueprint, renderPlan } from "../lib/plan.js"
6
+
7
+ function planPath(root) {
8
+ return join(root, ".ctx", "mine", "plan.md")
9
+ }
10
+
11
+ async function requirePlan(root) {
12
+ const file = planPath(root)
13
+ const raw = await readOptional(file)
14
+ if (!raw) throw new Error("No plan. Run connore plan init <blueprint>.")
15
+ return { file, text: raw.toString("utf8") }
16
+ }
17
+
18
+ export async function plan(root, args, report) {
19
+ if (!(await readOptional(join(root, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
20
+ const [sub, ...rest] = args
21
+ if (sub === "init") {
22
+ const name = rest[0]
23
+ const file = planPath(root)
24
+ if (await readOptional(file)) throw new Error("A plan already exists at .ctx/mine/plan.md.")
25
+ const source = await readBlueprint(name)
26
+ const rendered = renderPlan(name, parseBlueprint(source.text))
27
+ if (!parseBlueprint(source.text).phases.length) throw new Error(`Blueprint "${name}" has no phases.`)
28
+ await commitWrite(file, rendered, report, ".ctx/mine/plan.md")
29
+ await rebuildIndex(root, report)
30
+ return planView(rendered)
31
+ }
32
+ const current = await requirePlan(root)
33
+ if (sub === "status" || sub === "next") return planView(current.text)
34
+ if (sub === "done") {
35
+ const updated = markTaskDone(current.text, rest.join(" "))
36
+ await commitWrite(current.file, updated, report, ".ctx/mine/plan.md")
37
+ await rebuildIndex(root, report)
38
+ return planView(updated)
39
+ }
40
+ throw Object.assign(new Error("Usage: connore plan init <blueprint> | status | next | done <task>."), { exitCode: 2 })
41
+ }
@@ -1,8 +1,8 @@
1
- import { join } from "node:path"
2
- import { readOptional } from "../lib/fs-safe.js"
3
- import { rebuildIndex } from "../lib/index.js"
4
-
5
- export async function reindex(root, report) {
6
- if (!(await readOptional(join(root, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
7
- await rebuildIndex(root, report)
8
- }
1
+ import { join } from "node:path"
2
+ import { readOptional } from "../lib/fs-safe.js"
3
+ import { rebuildIndex } from "../lib/index.js"
4
+
5
+ export async function reindex(root, flags, report) {
6
+ if (!(await readOptional(join(root, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
7
+ await rebuildIndex(root, report, { includeDrafts: flags.includeDrafts })
8
+ }
@@ -0,0 +1,31 @@
1
+ import { join } from "node:path"
2
+ import { readOptional } from "../lib/fs-safe.js"
3
+ import { rebuildIndex } from "../lib/index.js"
4
+ import { lessonFile, listProposals, moveProposal } from "../lib/lessons.js"
5
+ import { commitWrite } from "../lib/mutate.js"
6
+ import { fromRoot } from "../lib/paths.js"
7
+
8
+ export async function review(root, args, flags, report) {
9
+ if (!(await readOptional(join(root, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
10
+ const [action, id] = args
11
+ if (!action) return { proposals: await listProposals(root) }
12
+ if (!id || !["accept", "reject", "edit"].includes(action)) {
13
+ throw Object.assign(new Error("Usage: connore review [accept|reject|edit <id>]."), { exitCode: 2 })
14
+ }
15
+ if (action === "edit") {
16
+ const proposals = await listProposals(root)
17
+ const lesson = proposals.find((item) => item.id === id)
18
+ if (!lesson) throw new Error(`No proposal "${id}".`)
19
+ const next = {
20
+ ...lesson,
21
+ mistake: flags.mistake || lesson.mistake,
22
+ fix: flags.fix || lesson.fix,
23
+ status: "proposed",
24
+ }
25
+ await commitWrite(lesson.file, lessonFile(next), report, fromRoot(root, lesson.file))
26
+ return { proposals: [next] }
27
+ }
28
+ const lesson = await moveProposal(root, id, action === "accept" ? "accepted" : "rejected", report)
29
+ if (action === "accept") await rebuildIndex(root, report, { includeDrafts: flags.includeDrafts })
30
+ return { proposals: [lesson] }
31
+ }
@@ -0,0 +1,21 @@
1
+ import { readFile } from "node:fs/promises"
2
+ import { join } from "node:path"
3
+ import { readOptional } from "../lib/fs-safe.js"
4
+ import { collectEntries } from "../lib/index.js"
5
+ import { absFromPosix } from "../lib/paths.js"
6
+ import { rankEntries } from "../lib/search.js"
7
+
8
+ export async function search(root, query, flags) {
9
+ if (!(await readOptional(join(root, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
10
+ const entries = await collectEntries(root, { includeDrafts: flags.includeDrafts })
11
+ const ranked = []
12
+ for (const entry of entries) {
13
+ const abs = absFromPosix(root, entry.path)
14
+ const text = (await readFile(abs, "utf8")).replace(/\r\n/g, "\n")
15
+ const body = text.replace(/^---[\s\S]*?---\n/, "")
16
+ const headings = [...body.matchAll(/^#{1,3} (.+)$/gm)].map((match) => match[1]).join(" ")
17
+ const title = body.match(/^# (.+)$/m)?.[1] || entry.path
18
+ ranked.push({ ...entry, title, headings, body })
19
+ }
20
+ return rankEntries(ranked, query).map(({ path, score, description, title }) => ({ path, score, title, description }))
21
+ }
@@ -0,0 +1,35 @@
1
+ import { listAccepted } from "../lib/lessons.js"
2
+ import { readSignals } from "../lib/signals.js"
3
+
4
+ function isoWeek(date) {
5
+ const copy = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()))
6
+ const day = copy.getUTCDay() || 7
7
+ copy.setUTCDate(copy.getUTCDate() + 4 - day)
8
+ const start = new Date(Date.UTC(copy.getUTCFullYear(), 0, 1))
9
+ const week = Math.ceil(((copy - start) / 86400000 + 1) / 7)
10
+ return `${copy.getUTCFullYear()}-W${String(week).padStart(2, "0")}`
11
+ }
12
+
13
+ export function buildStats(signals, lessons) {
14
+ const weeks = new Map()
15
+ function bump(week, key) {
16
+ if (!week) return
17
+ if (!weeks.has(week)) weeks.set(week, { week, signals: 0, accepted: 0, recurring: 0 })
18
+ weeks.get(week)[key] += 1
19
+ }
20
+ for (const signal of signals) {
21
+ const at = new Date(signal.at)
22
+ if (!Number.isNaN(at.getTime())) bump(isoWeek(at), "signals")
23
+ }
24
+ for (const lesson of lessons) {
25
+ const at = new Date(lesson.lastSeen)
26
+ const week = Number.isNaN(at.getTime()) ? null : isoWeek(at)
27
+ if (lesson.status === "accepted") bump(week, "accepted")
28
+ if (lesson.flagged === "recurring") bump(week, "recurring")
29
+ }
30
+ return { weeks: [...weeks.values()].sort((a, b) => a.week.localeCompare(b.week)) }
31
+ }
32
+
33
+ export async function stats(root) {
34
+ return buildStats(await readSignals(root), await listAccepted(root))
35
+ }
@@ -0,0 +1,7 @@
1
+ import { undoLastRun } from "../lib/run.js"
2
+
3
+ export async function undo(root, report) {
4
+ const manifest = await undoLastRun(root)
5
+ report.add("changed", `.ctx/.runs/${manifest.id}.json`)
6
+ for (const file of manifest.files) report.add("changed", file.path)
7
+ }
@@ -1,14 +1,16 @@
1
- import { join } from "node:path"
2
- import { readOptional } from "../lib/fs-safe.js"
3
- import { rebuildIndex } from "../lib/index.js"
4
- import { packRoot } from "../lib/paths.js"
5
- import { syncTree } from "../lib/sync.js"
6
-
7
- export async function update(root, flags, report) {
8
- if (!(await readOptional(join(root, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
9
- const pack = flags.pack || "frontend"
10
- const packDir = join(packRoot, "packs", pack)
11
- if (!(await readOptional(join(packDir, "design", "tokens.md")))) throw new Error(`Unknown pack "${pack}".`)
12
- await syncTree(packDir, join(root, ".ctx", "library"), root, { overwrite: true, report })
13
- await rebuildIndex(root, report)
14
- }
1
+ import { join } from "node:path"
2
+ import { readOptional } from "../lib/fs-safe.js"
3
+ import { rebuildIndex } from "../lib/index.js"
4
+ import { packDir } from "../lib/packs.js"
5
+ import { syncTree } from "../lib/sync.js"
6
+
7
+ export async function update(root, flags, report) {
8
+ if (!(await readOptional(join(root, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
9
+ const source = await packDir(flags.pack || "frontend")
10
+ await syncTree(source, join(root, ".ctx", "library"), root, {
11
+ overwrite: true,
12
+ report,
13
+ includeDrafts: flags.includeDrafts,
14
+ })
15
+ await rebuildIndex(root, report, { includeDrafts: flags.includeDrafts })
16
+ }
@@ -0,0 +1,32 @@
1
+ import { readdir } from "node:fs/promises"
2
+ import { join } from "node:path"
3
+
4
+ export const GROUPS = [
5
+ { id: "screenshots", label: "UI screenshots", target: 20 },
6
+ { id: "pages", label: "Complete page references", target: 5 },
7
+ { id: "tokens", label: "Design token system", target: 1 },
8
+ { id: "rules", label: "Design rules", target: 10 },
9
+ { id: "components", label: "Component notes", target: 15 },
10
+ { id: "motion", label: "Motion notes", target: 10 },
11
+ { id: "custom", label: "Custom components", target: 5 },
12
+ { id: "golden", label: "Golden projects", target: 3 },
13
+ { id: "blueprints", label: "Page blueprints", target: 5 },
14
+ { id: "patterns", label: "Frontend patterns", target: 5 },
15
+ { id: "architecture", label: "Backend architecture", target: 3 },
16
+ { id: "schemas", label: "Database schemas", target: 5 },
17
+ { id: "api", label: "API examples", target: 5 },
18
+ { id: "auth", label: "Authentication workflows", target: 3 },
19
+ { id: "docs", label: "Versioned documentation sets", target: 5 },
20
+ { id: "coding-rules", label: "Coding rules", target: 10 },
21
+ { id: "skills", label: "Agent skills", target: 5 },
22
+ ]
23
+
24
+ export async function countGroup(root, id) {
25
+ try {
26
+ const names = await readdir(join(root, ".ctx", "mine", "catalog", id))
27
+ return names.filter((name) => name.endsWith(".md")).length
28
+ } catch (error) {
29
+ if (error.code === "ENOENT") return 0
30
+ throw error
31
+ }
32
+ }