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.
- package/README.md +53 -46
- package/package.json +35 -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 +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/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 -90
- package/src/commands/add.js +61 -57
- package/src/commands/catalog.js +21 -0
- package/src/commands/doctor.js +42 -0
- package/src/commands/hook.js +67 -50
- package/src/commands/init.js +69 -55
- package/src/commands/learn.js +39 -0
- package/src/commands/lint.js +5 -0
- package/src/commands/list.js +10 -10
- 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 -8
- 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 -14
- package/src/lib/catalog.js +32 -0
- package/src/lib/config.js +64 -0
- package/src/lib/fs-safe.js +36 -11
- package/src/lib/gitlog.js +75 -0
- package/src/lib/ignore.js +47 -0
- package/src/lib/index.js +27 -12
- 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 +6 -2
- package/src/lib/plan.js +156 -0
- package/src/lib/pointers.js +3 -3
- package/src/lib/provider.js +27 -0
- package/src/lib/report.js +20 -4
- 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 +20 -12
package/src/cli.js
CHANGED
|
@@ -1,90 +1,288 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
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
|
+
}
|
package/src/commands/add.js
CHANGED
|
@@ -1,57 +1,61 @@
|
|
|
1
|
-
import { readFile, stat } from "node:fs/promises"
|
|
2
|
-
import { basename, join, relative, resolve } from "node:path"
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
+
}
|