connore 0.0.0-stage → 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.
- package/LICENSE +21 -0
- package/README.md +52 -2
- package/bin/ctxkit.js +5 -0
- package/package.json +33 -4
- 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 +28 -0
- package/packs/base/planning/blueprint-template.md +46 -0
- package/packs/base/planning/plan-template.md +45 -0
- package/packs/base/rules/anti-patterns.md +43 -0
- package/packs/base/rules/code-style.md +43 -0
- package/packs/base/rules/definition-of-done.md +47 -0
- package/packs/base/rules/dependency-policy.md +43 -0
- package/packs/base/rules/error-handling.md +43 -0
- package/packs/base/rules/security-baseline.md +43 -0
- package/packs/base/templates/bug-report.md +43 -0
- package/packs/base/templates/feature-spec.md +43 -0
- package/packs/base/templates/handoff.md +43 -0
- package/packs/base/templates/project-brief.md +43 -0
- package/packs/base/workflow/build-loop.md +48 -0
- package/packs/base/workflow/code-review.md +43 -0
- package/packs/base/workflow/debugging.md +43 -0
- package/packs/base/workflow/git-and-commits.md +43 -0
- package/packs/base/workflow/idea-to-spec.md +43 -0
- package/packs/base/workflow/session-handoff.md +43 -0
- package/packs/base/workflow/spec-to-plan.md +43 -0
- package/packs/frontend/components/button.md +25 -0
- package/packs/frontend/components/card.md +25 -0
- package/packs/frontend/components/input.md +25 -0
- package/packs/frontend/design/rules.md +24 -0
- package/packs/frontend/design/tokens.md +40 -0
- package/packs/nextjs-fullstack/backend/api-conventions.md +48 -0
- package/packs/nextjs-fullstack/backend/auth-and-roles.md +43 -0
- package/packs/nextjs-fullstack/backend/background-jobs.md +43 -0
- package/packs/nextjs-fullstack/backend/caching.md +43 -0
- package/packs/nextjs-fullstack/backend/database.md +43 -0
- package/packs/nextjs-fullstack/backend/file-uploads.md +43 -0
- package/packs/nextjs-fullstack/backend/logging.md +43 -0
- package/packs/nextjs-fullstack/backend/migrations.md +43 -0
- package/packs/nextjs-fullstack/backend/rate-limiting.md +43 -0
- package/packs/nextjs-fullstack/backend/secrets-and-env.md +43 -0
- package/packs/nextjs-fullstack/backend/validation.md +43 -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 +43 -0
- package/packs/nextjs-fullstack/build-deploy/deploy.md +43 -0
- package/packs/nextjs-fullstack/build-deploy/monitoring.md +43 -0
- package/packs/nextjs-fullstack/build-deploy/performance.md +43 -0
- package/packs/nextjs-fullstack/build-deploy/project-structure.md +43 -0
- package/packs/nextjs-fullstack/build-deploy/release-checklist.md +43 -0
- package/packs/nextjs-fullstack/build-deploy/testing.md +43 -0
- package/packs/nextjs-fullstack/evals/README.md +43 -0
- package/packs/nextjs-fullstack/examples/golden-app/README.md +43 -0
- package/packs/nextjs-fullstack/frontend/accessibility.md +43 -0
- package/packs/nextjs-fullstack/frontend/components.md +43 -0
- package/packs/nextjs-fullstack/frontend/forms.md +43 -0
- package/packs/nextjs-fullstack/frontend/layout.md +43 -0
- package/packs/nextjs-fullstack/frontend/loading-empty-error.md +43 -0
- package/packs/nextjs-fullstack/frontend/motion.md +43 -0
- package/packs/nextjs-fullstack/frontend/responsive.md +43 -0
- package/packs/nextjs-fullstack/frontend/seo.md +43 -0
- package/packs/nextjs-fullstack/frontend/tables.md +43 -0
- package/packs/nextjs-fullstack/frontend/tokens.md +43 -0
- package/packs/nextjs-fullstack/integrations/analytics.md +43 -0
- package/packs/nextjs-fullstack/integrations/email.md +43 -0
- package/packs/nextjs-fullstack/integrations/llm-apis.md +43 -0
- package/packs/nextjs-fullstack/integrations/oauth.md +43 -0
- package/packs/nextjs-fullstack/integrations/object-storage.md +43 -0
- package/packs/nextjs-fullstack/integrations/payments.md +43 -0
- package/packs/nextjs-fullstack/integrations/queues.md +43 -0
- package/packs/nextjs-fullstack/integrations/search.md +43 -0
- package/packs/nextjs-fullstack/integrations/webhooks.md +43 -0
- package/packs/nextjs-fullstack/playbooks/add-ai-feature.md +43 -0
- package/packs/nextjs-fullstack/playbooks/add-auth.md +43 -0
- package/packs/nextjs-fullstack/playbooks/add-billing.md +50 -0
- package/packs/nextjs-fullstack/playbooks/add-crud.md +43 -0
- package/packs/nextjs-fullstack/playbooks/add-email.md +43 -0
- package/packs/nextjs-fullstack/playbooks/add-file-upload.md +43 -0
- package/packs/nextjs-fullstack/playbooks/add-webhook.md +43 -0
- package/packs/nextjs-fullstack/playbooks/ship-to-prod.md +43 -0
- package/src/cli.js +288 -0
- package/src/commands/add.js +61 -0
- package/src/commands/catalog.js +21 -0
- package/src/commands/doctor.js +42 -0
- package/src/commands/hook.js +67 -0
- package/src/commands/init.js +69 -0
- package/src/commands/learn.js +39 -0
- package/src/commands/lint.js +5 -0
- package/src/commands/list.js +10 -0
- package/src/commands/log.js +25 -0
- package/src/commands/memory.js +14 -0
- package/src/commands/plan.js +41 -0
- package/src/commands/reindex.js +8 -0
- package/src/commands/review.js +31 -0
- package/src/commands/search.js +21 -0
- package/src/commands/stats.js +35 -0
- package/src/commands/undo.js +7 -0
- package/src/commands/update.js +16 -0
- package/src/lib/catalog.js +32 -0
- package/src/lib/config.js +64 -0
- package/src/lib/frontmatter.js +70 -0
- package/src/lib/fs-safe.js +87 -0
- package/src/lib/gitlog.js +75 -0
- package/src/lib/ignore.js +47 -0
- package/src/lib/index.js +72 -0
- package/src/lib/lessons.js +173 -0
- package/src/lib/lint.js +67 -0
- package/src/lib/lock.js +47 -0
- package/src/lib/memory.js +49 -0
- package/src/lib/mutate.js +24 -0
- package/src/lib/packs.js +10 -0
- package/src/lib/paths.js +25 -0
- package/src/lib/plan.js +156 -0
- package/src/lib/pointers.js +76 -0
- package/src/lib/provider.js +27 -0
- package/src/lib/report.js +33 -0
- package/src/lib/run.js +73 -0
- package/src/lib/search.js +40 -0
- package/src/lib/secrets.js +25 -0
- package/src/lib/signals.js +55 -0
- package/src/lib/sync.js +36 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Ship To Prod
|
|
3
|
+
type: playbook
|
|
4
|
+
tags: [playbook]
|
|
5
|
+
stack: nextjs
|
|
6
|
+
status: draft
|
|
7
|
+
verified:
|
|
8
|
+
description: Draft direction for Ship To Prod.
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# Ship To Prod
|
|
12
|
+
|
|
13
|
+
## Use when
|
|
14
|
+
TODO
|
|
15
|
+
|
|
16
|
+
## Default
|
|
17
|
+
TODO
|
|
18
|
+
|
|
19
|
+
## Use instead when
|
|
20
|
+
TODO
|
|
21
|
+
|
|
22
|
+
## Never
|
|
23
|
+
TODO
|
|
24
|
+
|
|
25
|
+
## Why
|
|
26
|
+
TODO
|
|
27
|
+
|
|
28
|
+
## Steps
|
|
29
|
+
1. TODO
|
|
30
|
+
|
|
31
|
+
## Done when
|
|
32
|
+
TODO
|
|
33
|
+
|
|
34
|
+
## Example
|
|
35
|
+
TODO
|
|
36
|
+
|
|
37
|
+
## Common mistakes
|
|
38
|
+
TODO
|
|
39
|
+
|
|
40
|
+
## Sources
|
|
41
|
+
TODO
|
|
42
|
+
|
|
43
|
+
License: MIT
|
package/src/cli.js
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { join } from "node:path"
|
|
2
|
+
import { add } from "./commands/add.js"
|
|
3
|
+
import { catalog } from "./commands/catalog.js"
|
|
4
|
+
import { doctor } from "./commands/doctor.js"
|
|
5
|
+
import { printIndex } from "./commands/hook.js"
|
|
6
|
+
import { init } from "./commands/init.js"
|
|
7
|
+
import { learn } from "./commands/learn.js"
|
|
8
|
+
import { lint } from "./commands/lint.js"
|
|
9
|
+
import { list } from "./commands/list.js"
|
|
10
|
+
import { memory } from "./commands/memory.js"
|
|
11
|
+
import { log } from "./commands/log.js"
|
|
12
|
+
import { plan } from "./commands/plan.js"
|
|
13
|
+
import { search } from "./commands/search.js"
|
|
14
|
+
import { reindex } from "./commands/reindex.js"
|
|
15
|
+
import { review } from "./commands/review.js"
|
|
16
|
+
import { stats } from "./commands/stats.js"
|
|
17
|
+
import { undo } from "./commands/undo.js"
|
|
18
|
+
import { update } from "./commands/update.js"
|
|
19
|
+
import { ensureConfig } from "./lib/config.js"
|
|
20
|
+
import { readOptional } from "./lib/fs-safe.js"
|
|
21
|
+
import { withLock } from "./lib/lock.js"
|
|
22
|
+
import { packDir } from "./lib/packs.js"
|
|
23
|
+
import { parseTools } from "./lib/pointers.js"
|
|
24
|
+
import { createReport } from "./lib/report.js"
|
|
25
|
+
import { sealRun } from "./lib/run.js"
|
|
26
|
+
|
|
27
|
+
const USAGE = `connore <command> [options]
|
|
28
|
+
|
|
29
|
+
init [--tools all|claude,cursor,codex,copilot,windsurf,gemini] [--pack frontend] [--hooks] [--include-drafts] [--dry-run] [--json]
|
|
30
|
+
add <path> [--type t] [--tags a,b] [--dry-run] [--json]
|
|
31
|
+
update [--pack name] [--include-drafts] [--dry-run] [--json]
|
|
32
|
+
list [--json]
|
|
33
|
+
index [--include-drafts] [--dry-run] [--json]
|
|
34
|
+
hook [--json]
|
|
35
|
+
lint [--json]
|
|
36
|
+
doctor [--json]
|
|
37
|
+
undo [--json]
|
|
38
|
+
log <fix|decision|failure> "text" [--files a,b] [--json]
|
|
39
|
+
memory [project|architecture|decision|agent|preferences|task|knowledge] ["text"] [--json]
|
|
40
|
+
catalog [--json]
|
|
41
|
+
learn [--input file] [--yes] [--json]
|
|
42
|
+
review [accept|reject|edit <id>] [--mistake text] [--fix text] [--json]
|
|
43
|
+
stats [--json]
|
|
44
|
+
search "query" [--include-drafts] [--json]
|
|
45
|
+
plan init <blueprint> | status | next | done <task> [--json]
|
|
46
|
+
`
|
|
47
|
+
|
|
48
|
+
const VALUE_FLAGS = new Set(["--tools", "--pack", "--type", "--tags", "--files", "--mistake", "--fix", "--input"])
|
|
49
|
+
const WRITES = new Set(["init", "add", "update", "index", "undo", "log", "learn", "review", "plan", "memory"])
|
|
50
|
+
|
|
51
|
+
function usage(message) {
|
|
52
|
+
const error = new Error(message)
|
|
53
|
+
error.exitCode = 2
|
|
54
|
+
return error
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function parse(argv) {
|
|
58
|
+
const flags = { dryRun: false, hooks: false, json: false, includeDrafts: false, yes: false }
|
|
59
|
+
const positionals = []
|
|
60
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
61
|
+
const arg = argv[index]
|
|
62
|
+
if (arg === "--dry-run") flags.dryRun = true
|
|
63
|
+
else if (arg === "--hooks") flags.hooks = true
|
|
64
|
+
else if (arg === "--json") flags.json = true
|
|
65
|
+
else if (arg === "--include-drafts") flags.includeDrafts = true
|
|
66
|
+
else if (arg === "--yes") flags.yes = true
|
|
67
|
+
else if (VALUE_FLAGS.has(arg)) {
|
|
68
|
+
const value = argv[index + 1]
|
|
69
|
+
if (!value || value.startsWith("--")) throw usage(`Missing value for ${arg}.`)
|
|
70
|
+
flags[arg.slice(2)] = value
|
|
71
|
+
index += 1
|
|
72
|
+
} else if (arg.startsWith("--")) throw usage(`Unknown flag ${arg}.`)
|
|
73
|
+
else positionals.push(arg)
|
|
74
|
+
}
|
|
75
|
+
return { command: positionals[0], args: positionals.slice(1), flags }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function printJson(stdout, payload) {
|
|
79
|
+
stdout.write(`${JSON.stringify(payload)}\n`)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export async function run(argv, io = {}) {
|
|
83
|
+
const stdout = io.stdout || process.stdout
|
|
84
|
+
const stderr = io.stderr || process.stderr
|
|
85
|
+
const cwd = io.cwd || process.cwd()
|
|
86
|
+
let flags = { json: argv.includes("--json") }
|
|
87
|
+
try {
|
|
88
|
+
const parsed = parse(argv)
|
|
89
|
+
flags = parsed.flags
|
|
90
|
+
const { command, args } = parsed
|
|
91
|
+
if (!command) {
|
|
92
|
+
if (flags.json) printJson(stdout, { ok: false, error: "Missing command." })
|
|
93
|
+
else stdout.write(USAGE)
|
|
94
|
+
return 2
|
|
95
|
+
}
|
|
96
|
+
if (command === "init") {
|
|
97
|
+
if (args.length) throw usage("init does not take a path. Run it inside the project.")
|
|
98
|
+
if (flags.tools) {
|
|
99
|
+
try {
|
|
100
|
+
parseTools(flags.tools)
|
|
101
|
+
} catch (error) {
|
|
102
|
+
error.exitCode = 2
|
|
103
|
+
throw error
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
await packDir(flags.pack || "frontend")
|
|
108
|
+
} catch (error) {
|
|
109
|
+
error.exitCode = 2
|
|
110
|
+
throw error
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const report = createReport(flags.dryRun, { json: flags.json })
|
|
114
|
+
const body = async () => {
|
|
115
|
+
if (command !== "init" && WRITES.has(command)) {
|
|
116
|
+
if (!(await readOptional(join(cwd, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
|
|
117
|
+
await ensureConfig(cwd, report)
|
|
118
|
+
}
|
|
119
|
+
if (command === "init") {
|
|
120
|
+
await init(cwd, flags, report)
|
|
121
|
+
report.print(stdout)
|
|
122
|
+
return
|
|
123
|
+
}
|
|
124
|
+
if (flags.hooks) throw usage("--hooks is only valid with init.")
|
|
125
|
+
if (flags.tools) throw usage("--tools is only valid with init.")
|
|
126
|
+
if (command === "add") {
|
|
127
|
+
if (flags.pack) throw usage("--pack is only valid with init and update.")
|
|
128
|
+
if (args.length !== 1) throw usage("Usage: connore add <path>.")
|
|
129
|
+
await add(cwd, args[0], flags, report)
|
|
130
|
+
report.print(stdout)
|
|
131
|
+
return
|
|
132
|
+
}
|
|
133
|
+
if (flags.type || flags.tags) throw usage("--type and --tags are only valid with add.")
|
|
134
|
+
if (command === "update") {
|
|
135
|
+
if (args.length) throw usage("update does not take a path.")
|
|
136
|
+
await update(cwd, flags, report)
|
|
137
|
+
report.print(stdout)
|
|
138
|
+
return
|
|
139
|
+
}
|
|
140
|
+
if (flags.pack) throw usage("--pack is only valid with init and update.")
|
|
141
|
+
if (command === "list") {
|
|
142
|
+
if (flags.json) {
|
|
143
|
+
const { collectEntries } = await import("./lib/index.js")
|
|
144
|
+
if (!(await readOptional(join(cwd, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
|
|
145
|
+
printJson(stdout, { ok: true, entries: await collectEntries(cwd, { includeDrafts: flags.includeDrafts }) })
|
|
146
|
+
} else await list(cwd, stdout)
|
|
147
|
+
return
|
|
148
|
+
}
|
|
149
|
+
if (command === "index") {
|
|
150
|
+
await reindex(cwd, flags, report)
|
|
151
|
+
report.print(stdout)
|
|
152
|
+
return
|
|
153
|
+
}
|
|
154
|
+
if (command === "hook") {
|
|
155
|
+
let output = ""
|
|
156
|
+
await printIndex(cwd, { write(chunk) { output += chunk } })
|
|
157
|
+
if (flags.json) printJson(stdout, { ok: true, output })
|
|
158
|
+
else stdout.write(output)
|
|
159
|
+
return
|
|
160
|
+
}
|
|
161
|
+
if (command === "lint") {
|
|
162
|
+
const problems = await lint()
|
|
163
|
+
printJsonish(stdout, flags, problems.length ? { ok: false, problems } : { ok: true, problems }, () => {
|
|
164
|
+
for (const problem of problems) stdout.write(`${problem}\n`)
|
|
165
|
+
stdout.write(problems.length ? `${problems.length} problems\n` : "lint clean\n")
|
|
166
|
+
})
|
|
167
|
+
if (problems.length) throw Object.assign(new Error("lint failed"), { exitCode: 1, handled: true })
|
|
168
|
+
return
|
|
169
|
+
}
|
|
170
|
+
if (command === "doctor") {
|
|
171
|
+
const problems = await doctor(cwd)
|
|
172
|
+
printJsonish(stdout, flags, { ok: problems.length === 0, problems }, () => {
|
|
173
|
+
for (const problem of problems) stdout.write(`${problem}\n`)
|
|
174
|
+
stdout.write(problems.length ? `${problems.length} problems\n` : "doctor clean\n")
|
|
175
|
+
})
|
|
176
|
+
if (problems.length) throw Object.assign(new Error("doctor failed"), { exitCode: 1, handled: true })
|
|
177
|
+
return
|
|
178
|
+
}
|
|
179
|
+
if (command === "undo") {
|
|
180
|
+
if (args.length) throw usage("undo does not take a path.")
|
|
181
|
+
await undo(cwd, report)
|
|
182
|
+
report.print(stdout)
|
|
183
|
+
return
|
|
184
|
+
}
|
|
185
|
+
if (command === "catalog") {
|
|
186
|
+
if (args.length) throw usage("catalog does not take a path.")
|
|
187
|
+
await catalog(cwd, flags, stdout)
|
|
188
|
+
return
|
|
189
|
+
}
|
|
190
|
+
if (command === "memory") {
|
|
191
|
+
await memory(cwd, args, report, stdout, flags)
|
|
192
|
+
if (args.length) report.print(stdout)
|
|
193
|
+
return
|
|
194
|
+
}
|
|
195
|
+
if (command === "log") {
|
|
196
|
+
if (args.length !== 2) throw usage('Usage: connore log <fix|decision|failure> "text".')
|
|
197
|
+
await log(cwd, args[0], args[1], flags, report)
|
|
198
|
+
report.print(stdout)
|
|
199
|
+
return
|
|
200
|
+
}
|
|
201
|
+
if (command === "learn") {
|
|
202
|
+
const result = await learn(cwd, flags, report, io)
|
|
203
|
+
if (flags.json) printJson(stdout, { ok: true, ...result, summary: countEvents(report) })
|
|
204
|
+
else {
|
|
205
|
+
if (!result.proposals) stdout.write("No pattern has 3 occurrences yet.\n")
|
|
206
|
+
else if (!result.wrote) stdout.write(`${result.preview}\nRe-run with --yes to write proposals.\n`)
|
|
207
|
+
report.print(stdout)
|
|
208
|
+
}
|
|
209
|
+
return
|
|
210
|
+
}
|
|
211
|
+
if (command === "review") {
|
|
212
|
+
const result = await review(cwd, args, flags, report)
|
|
213
|
+
if (!args[0]) {
|
|
214
|
+
if (flags.json) printJson(stdout, { ok: true, proposals: result.proposals })
|
|
215
|
+
else if (!result.proposals.length) stdout.write("No proposals.\n")
|
|
216
|
+
else {
|
|
217
|
+
for (const lesson of result.proposals) {
|
|
218
|
+
stdout.write(`${lesson.id}\t${lesson.evidence}\t${lesson.mistake}\n`)
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return
|
|
222
|
+
}
|
|
223
|
+
report.print(stdout)
|
|
224
|
+
return
|
|
225
|
+
}
|
|
226
|
+
if (command === "search") {
|
|
227
|
+
if (!args.length) throw usage('Usage: connore search "query".')
|
|
228
|
+
const results = await search(cwd, args.join(" "), flags)
|
|
229
|
+
if (flags.json) printJson(stdout, { ok: true, results })
|
|
230
|
+
else if (!results.length) stdout.write("No entries match.\n")
|
|
231
|
+
else {
|
|
232
|
+
for (const hit of results) stdout.write(`${hit.score}\t${hit.path}\t${hit.description}\n`)
|
|
233
|
+
}
|
|
234
|
+
return
|
|
235
|
+
}
|
|
236
|
+
if (command === "plan") {
|
|
237
|
+
if (!args.length) throw usage("Usage: connore plan init <blueprint> | status | next | done <task>.")
|
|
238
|
+
const view = await plan(cwd, args, report)
|
|
239
|
+
if (flags.json) printJson(stdout, { ok: true, ...view })
|
|
240
|
+
else {
|
|
241
|
+
stdout.write(`Phase ${view.phase}\nNext: ${view.next}\n`)
|
|
242
|
+
if (view.failedGate) stdout.write(`Failed gate: ${view.failedGate}\n`)
|
|
243
|
+
stdout.write(`${view.done}/${view.total} done\n`)
|
|
244
|
+
}
|
|
245
|
+
return
|
|
246
|
+
}
|
|
247
|
+
if (command === "stats") {
|
|
248
|
+
const data = await stats(cwd)
|
|
249
|
+
if (flags.json) printJson(stdout, { ok: true, ...data })
|
|
250
|
+
else if (!data.weeks.length) stdout.write("No signals yet.\n")
|
|
251
|
+
else {
|
|
252
|
+
for (const week of data.weeks) {
|
|
253
|
+
stdout.write(`${week.week}\tsignals ${week.signals}\taccepted ${week.accepted}\trecurring ${week.recurring}\n`)
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return
|
|
257
|
+
}
|
|
258
|
+
throw usage(`Unknown command "${command}".`)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (!flags.dryRun && WRITES.has(command) && (command === "init" || (await readOptional(join(cwd, ".ctx", "PROCESS.md"))))) {
|
|
262
|
+
await withLock(cwd, async () => {
|
|
263
|
+
await body()
|
|
264
|
+
await sealRun(cwd, command, report)
|
|
265
|
+
})
|
|
266
|
+
} else {
|
|
267
|
+
await body()
|
|
268
|
+
if (!flags.dryRun && WRITES.has(command)) await sealRun(cwd, command, report)
|
|
269
|
+
}
|
|
270
|
+
return 0
|
|
271
|
+
} catch (error) {
|
|
272
|
+
if (error.handled) return error.exitCode || 1
|
|
273
|
+
const code = error.exitCode || 1
|
|
274
|
+
if (flags.json) printJson(stdout, { ok: false, error: error.message })
|
|
275
|
+
else stderr.write(`${error.message}\n`)
|
|
276
|
+
return code
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function countEvents(report) {
|
|
281
|
+
const count = (kind) => report.events.filter((event) => event.kind === kind).length
|
|
282
|
+
return { created: count("created"), changed: count("changed"), skipped: count("skipped"), removed: count("removed") }
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function printJsonish(stdout, flags, payload, text) {
|
|
286
|
+
if (flags.json) printJson(stdout, payload)
|
|
287
|
+
else text()
|
|
288
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { readFile, stat } from "node:fs/promises"
|
|
2
|
+
import { basename, join, relative, resolve } from "node:path"
|
|
3
|
+
import { readConfig } from "../lib/config.js"
|
|
4
|
+
import { readOptional, walkFiles } from "../lib/fs-safe.js"
|
|
5
|
+
import { twinStub, today } from "../lib/frontmatter.js"
|
|
6
|
+
import { ignoreNames } from "../lib/ignore.js"
|
|
7
|
+
import { rebuildIndex } from "../lib/index.js"
|
|
8
|
+
import { commitWrite } from "../lib/mutate.js"
|
|
9
|
+
import { ctxPath, fromRoot } from "../lib/paths.js"
|
|
10
|
+
import { secretHits } from "../lib/secrets.js"
|
|
11
|
+
|
|
12
|
+
const TYPES = new Set(["design-token", "component", "rule", "screenshot", "flow", "doc"])
|
|
13
|
+
const IMAGE = /\.(png|jpe?g|webp|gif|svg)$/i
|
|
14
|
+
const CODE = /\.(tsx|jsx|ts|js|mjs|cjs|css)$/i
|
|
15
|
+
|
|
16
|
+
function defaultType(name) {
|
|
17
|
+
if (IMAGE.test(name)) return "screenshot"
|
|
18
|
+
if (CODE.test(name)) return "component"
|
|
19
|
+
return null
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function placeFile(source, target, root, flags, report) {
|
|
23
|
+
const display = fromRoot(root, target)
|
|
24
|
+
const bytes = await readFile(source)
|
|
25
|
+
const hits = secretHits(bytes.toString("utf8"))
|
|
26
|
+
if (hits.length) throw new Error(`Refusing to copy ${display} because it looks like a secret (${hits.join(", ")}).`)
|
|
27
|
+
if (await readOptional(target)) report.add("skipped", display)
|
|
28
|
+
else await commitWrite(target, bytes, report, display)
|
|
29
|
+
const type = flags.type || defaultType(basename(target))
|
|
30
|
+
if (!type || target.endsWith(".md")) return
|
|
31
|
+
const twin = target.replace(/\.[^.]+$/, ".md")
|
|
32
|
+
const twinDisplay = fromRoot(root, twin)
|
|
33
|
+
if (await readOptional(twin)) {
|
|
34
|
+
report.add("skipped", twinDisplay)
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
const tags = flags.tags ? flags.tags.split(",").map((tag) => tag.trim()).filter(Boolean) : []
|
|
38
|
+
const body = twinStub({ title: basename(twin, ".md"), type, tags, date: today() })
|
|
39
|
+
await commitWrite(twin, body, report, twinDisplay)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function add(root, sourceArg, flags, report) {
|
|
43
|
+
if (flags.type && !TYPES.has(flags.type)) throw new Error(`Unknown type "${flags.type}".`)
|
|
44
|
+
if (!(await readOptional(join(root, ".ctx", "INDEX.md"))) && !(await readOptional(join(root, ".ctx", "PROCESS.md")))) {
|
|
45
|
+
throw new Error("No .ctx/ folder. Run connore init first.")
|
|
46
|
+
}
|
|
47
|
+
const source = resolve(root, sourceArg)
|
|
48
|
+
let info
|
|
49
|
+
try {
|
|
50
|
+
info = await stat(source)
|
|
51
|
+
} catch {
|
|
52
|
+
throw new Error(`Cannot read ${sourceArg}.`)
|
|
53
|
+
}
|
|
54
|
+
const mine = ctxPath(root, "mine")
|
|
55
|
+
const ignore = await ignoreNames(root, (await readConfig(root)).config)
|
|
56
|
+
if (info.isDirectory()) {
|
|
57
|
+
const files = await walkFiles(source, ignore)
|
|
58
|
+
for (const file of files) await placeFile(file, join(mine, basename(source), relative(source, file)), root, flags, report)
|
|
59
|
+
} else await placeFile(source, join(mine, basename(source)), root, flags, report)
|
|
60
|
+
await rebuildIndex(root, report, { includeDrafts: flags.includeDrafts })
|
|
61
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { join } from "node:path"
|
|
2
|
+
import { readOptional } from "../lib/fs-safe.js"
|
|
3
|
+
import { GROUPS, countGroup } from "../lib/catalog.js"
|
|
4
|
+
|
|
5
|
+
export async function catalog(root, flags, stdout) {
|
|
6
|
+
if (!(await readOptional(join(root, ".ctx", "PROCESS.md")))) throw new Error("No .ctx/ folder. Run connore init first.")
|
|
7
|
+
const groups = []
|
|
8
|
+
for (const group of GROUPS) {
|
|
9
|
+
const count = await countGroup(root, group.id)
|
|
10
|
+
groups.push({ ...group, count, met: count >= group.target })
|
|
11
|
+
}
|
|
12
|
+
const started = groups.filter((group) => group.count > 0).length
|
|
13
|
+
if (flags.json) {
|
|
14
|
+
stdout.write(`${JSON.stringify({ ok: true, started, total: groups.length, groups })}\n`)
|
|
15
|
+
return
|
|
16
|
+
}
|
|
17
|
+
stdout.write(`${started}/${groups.length} groups started\n`)
|
|
18
|
+
for (const group of groups) {
|
|
19
|
+
stdout.write(`${group.count}/${group.target}\t${group.label}\t.ctx/mine/catalog/${group.id}\n`)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { join } from "node:path"
|
|
2
|
+
import { readConfig } from "../lib/config.js"
|
|
3
|
+
import { exists, readOptional, walkFiles } from "../lib/fs-safe.js"
|
|
4
|
+
import { lockIsStale } from "../lib/lock.js"
|
|
5
|
+
import { secretHits } from "../lib/secrets.js"
|
|
6
|
+
import { readFile } from "node:fs/promises"
|
|
7
|
+
|
|
8
|
+
export async function doctor(root) {
|
|
9
|
+
const problems = []
|
|
10
|
+
if (!(await readOptional(join(root, ".ctx", "PROCESS.md")))) {
|
|
11
|
+
return ["No .ctx/ folder. Run connore init first."]
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
const { config } = await readConfig(root)
|
|
15
|
+
if (!config) problems.push("missing .ctx/config.json")
|
|
16
|
+
else if (config.schemaVersion !== 1) problems.push(`schemaVersion is ${config.schemaVersion}`)
|
|
17
|
+
} catch (error) {
|
|
18
|
+
problems.push(error.message)
|
|
19
|
+
}
|
|
20
|
+
const lock = await readOptional(join(root, ".ctx", ".lock"))
|
|
21
|
+
if (lock) {
|
|
22
|
+
try {
|
|
23
|
+
const parsed = JSON.parse(lock.toString("utf8"))
|
|
24
|
+
if (!lockIsStale(parsed)) problems.push(`a run holds .ctx/.lock (pid ${parsed.pid})`)
|
|
25
|
+
} catch {
|
|
26
|
+
problems.push(".ctx/.lock is not valid JSON")
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (!(await exists(join(root, ".ctx", "vault")))) problems.push("missing .ctx/vault")
|
|
30
|
+
const gitignore = await readOptional(join(root, ".gitignore"))
|
|
31
|
+
if (!gitignore || !gitignore.toString("utf8").includes(".ctx/.signals/")) {
|
|
32
|
+
problems.push(".gitignore is missing the connore local-state block")
|
|
33
|
+
}
|
|
34
|
+
for (const dir of ["library", "mine"]) {
|
|
35
|
+
for (const file of await walkFiles(join(root, ".ctx", dir))) {
|
|
36
|
+
if (!file.endsWith(".md")) continue
|
|
37
|
+
const hits = secretHits(await readFile(file, "utf8"))
|
|
38
|
+
if (hits.length) problems.push(`${file} looks like a secret (${hits.join(", ")})`)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return problems
|
|
42
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
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,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
|
+
}
|