@research-copilot/cli 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/rc.js +203 -0
- package/package.json +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ldm2060
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/rc.js
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/program.ts
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
|
|
6
|
+
// src/commands/context.ts
|
|
7
|
+
import { buildContext } from "@research-copilot/core";
|
|
8
|
+
function runContext(args) {
|
|
9
|
+
return buildContext(args.repo, { format: args.format, now: args.now, eventName: args.eventName });
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// src/commands/doctor.ts
|
|
13
|
+
import * as fs from "fs";
|
|
14
|
+
import * as path from "path";
|
|
15
|
+
function runDoctor(repo) {
|
|
16
|
+
const report = [];
|
|
17
|
+
let ok = true;
|
|
18
|
+
const checks = [
|
|
19
|
+
[".research/ exists", fs.existsSync(path.join(repo, ".research"))],
|
|
20
|
+
["workflow.md exists", fs.existsSync(path.join(repo, ".research/workflow.md"))],
|
|
21
|
+
[".claude/settings.json exists", fs.existsSync(path.join(repo, ".claude/settings.json"))]
|
|
22
|
+
];
|
|
23
|
+
for (const [name, pass] of checks) {
|
|
24
|
+
report.push(`${pass ? "OK " : "FAIL"} ${name}`);
|
|
25
|
+
if (!pass) ok = false;
|
|
26
|
+
}
|
|
27
|
+
return { ok, report };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// src/commands/init.ts
|
|
31
|
+
import * as fs2 from "fs";
|
|
32
|
+
import * as path2 from "path";
|
|
33
|
+
import { fileURLToPath } from "url";
|
|
34
|
+
import { researchPaths } from "@research-copilot/core";
|
|
35
|
+
import { configurePlatform, kitRoot } from "@research-copilot/adapters";
|
|
36
|
+
var __dirname = path2.dirname(fileURLToPath(import.meta.url));
|
|
37
|
+
function runInit(args) {
|
|
38
|
+
const p = researchPaths(args.repo);
|
|
39
|
+
for (const d of [p.tasks, p.spec, p.workspace, p.runtime]) fs2.mkdirSync(d, { recursive: true });
|
|
40
|
+
for (const s of ["venue", "writing", "baselines", "methodology", "novelty"])
|
|
41
|
+
fs2.mkdirSync(path2.join(p.spec, s), { recursive: true });
|
|
42
|
+
const KIT = kitRoot(__dirname);
|
|
43
|
+
fs2.copyFileSync(path2.join(KIT, "workflow.md"), p.workflow);
|
|
44
|
+
fs2.copyFileSync(path2.join(KIT, "config.defaults.yaml"), p.config);
|
|
45
|
+
for (const p2 of args.platforms) configurePlatform(args.repo, p2);
|
|
46
|
+
}
|
|
47
|
+
function registerInit(program2, repo) {
|
|
48
|
+
program2.command("init").option("--claude", "Claude Code", false).option("--codex", "OpenAI Codex", false).option("--opencode", "OpenCode", false).option("--gemini", "Gemini CLI", false).option("--cursor", "Cursor", false).option("--windsurf", "Windsurf", false).requiredOption("-u, --user <name>", "developer identity").action((opts) => {
|
|
49
|
+
const platforms = [];
|
|
50
|
+
if (opts.claude) platforms.push("claude-code");
|
|
51
|
+
if (opts.codex) platforms.push("codex");
|
|
52
|
+
if (opts.opencode) platforms.push("opencode");
|
|
53
|
+
if (opts.gemini) platforms.push("gemini");
|
|
54
|
+
if (opts.cursor) platforms.push("cursor");
|
|
55
|
+
if (opts.windsurf) platforms.push("windsurf");
|
|
56
|
+
if (platforms.length === 0) platforms.push("claude-code");
|
|
57
|
+
runInit({ repo, platforms, user: opts.user });
|
|
58
|
+
process.stdout.write(`Initialized .research/ for: ${platforms.join(", ")}
|
|
59
|
+
`);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// src/commands/task.ts
|
|
64
|
+
import * as fs3 from "fs";
|
|
65
|
+
import * as path3 from "path";
|
|
66
|
+
import {
|
|
67
|
+
createTask,
|
|
68
|
+
readTask,
|
|
69
|
+
writeTask,
|
|
70
|
+
setStatus,
|
|
71
|
+
setActive,
|
|
72
|
+
getActive,
|
|
73
|
+
numberTraceability,
|
|
74
|
+
researchPaths as researchPaths2
|
|
75
|
+
} from "@research-copilot/core";
|
|
76
|
+
function taskCreate(repo, i) {
|
|
77
|
+
const t = createTask(repo, i);
|
|
78
|
+
setActive(repo, t.id);
|
|
79
|
+
return t;
|
|
80
|
+
}
|
|
81
|
+
function taskSetStatus(repo, id, to, now) {
|
|
82
|
+
setStatus(repo, id, to, now);
|
|
83
|
+
}
|
|
84
|
+
function taskAddGap(repo, id, desc, suggest_kind) {
|
|
85
|
+
const t = readTask(repo, id);
|
|
86
|
+
t.gaps.push({ desc, suggest_kind, status: "open" });
|
|
87
|
+
writeTask(repo, t, (/* @__PURE__ */ new Date()).toISOString());
|
|
88
|
+
}
|
|
89
|
+
function taskCurrent(repo) {
|
|
90
|
+
return getActive(repo);
|
|
91
|
+
}
|
|
92
|
+
function runVerifyGate(repo, id, now) {
|
|
93
|
+
const t = readTask(repo, id);
|
|
94
|
+
const dir = path3.join(researchPaths2(repo).taskDir(id), "artifacts");
|
|
95
|
+
const read = (glob) => fs3.existsSync(dir) ? fs3.readdirSync(dir).filter((f) => glob.test(f)).map((f) => fs3.readFileSync(path3.join(dir, f), "utf8")).join("\n") : "";
|
|
96
|
+
let result = { ok: true, missing: [] };
|
|
97
|
+
if (t.kind === "writing") {
|
|
98
|
+
const draft = read(/\.tex$/);
|
|
99
|
+
const artifacts = read(/\.(log|txt|json|csv)$/);
|
|
100
|
+
result = numberTraceability(draft, artifacts);
|
|
101
|
+
}
|
|
102
|
+
if (!result.ok && t.status === "verify") setStatus(repo, id, "in_progress", now);
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
function registerTask(program2, repo) {
|
|
106
|
+
const today = () => (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
107
|
+
const task = program2.command("task");
|
|
108
|
+
task.command("create").requiredOption("--kind <k>").requiredOption("--title <t>").option("--venue <v>").option("--parent <p>").action((o) => {
|
|
109
|
+
const t = taskCreate(repo, { title: o.title, kind: o.kind, date: today(), venue: o.venue, parent: o.parent });
|
|
110
|
+
process.stdout.write(t.id + "\n");
|
|
111
|
+
});
|
|
112
|
+
for (const [cmd, to] of [["start", "in_progress"], ["complete", "completed"]])
|
|
113
|
+
task.command(cmd).argument("<id>").action((id) => taskSetStatus(repo, id, to, (/* @__PURE__ */ new Date()).toISOString()));
|
|
114
|
+
task.command("verify").argument("<id>").action((id) => {
|
|
115
|
+
const r = runVerifyGate(repo, id, (/* @__PURE__ */ new Date()).toISOString());
|
|
116
|
+
if (r.ok) process.stdout.write(`verify OK for ${id}
|
|
117
|
+
`);
|
|
118
|
+
else {
|
|
119
|
+
process.stdout.write(`verify FAILED (untraceable: ${r.missing.join(", ")}); rolled back to in_progress
|
|
120
|
+
`);
|
|
121
|
+
process.exitCode = 1;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
task.command("set-status").argument("<id>").argument("<state>").action((id, state) => taskSetStatus(repo, id, state, (/* @__PURE__ */ new Date()).toISOString()));
|
|
125
|
+
task.command("add-gap").argument("<id>").requiredOption("--desc <d>").requiredOption("--suggest <k>").action((id, o) => taskAddGap(repo, id, o.desc, o.suggest));
|
|
126
|
+
task.command("current").action(() => process.stdout.write((taskCurrent(repo) ?? "none") + "\n"));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// src/commands/sync.ts
|
|
130
|
+
import { homedir } from "os";
|
|
131
|
+
import { join as join4 } from "path";
|
|
132
|
+
import { syncSkillpacks, writeLockFile } from "@research-copilot/core";
|
|
133
|
+
function sync(args) {
|
|
134
|
+
const repoRoot = args.repo;
|
|
135
|
+
const cacheDir = args.cacheDir || join4(homedir(), ".cache", "research-copilot", "skillpacks");
|
|
136
|
+
const targetDir = args.targetDir || join4(repoRoot, "research-kit");
|
|
137
|
+
console.error(`[sync] Repository: ${repoRoot}`);
|
|
138
|
+
console.error(`[sync] Cache: ${cacheDir}`);
|
|
139
|
+
console.error(`[sync] Target: ${targetDir}`);
|
|
140
|
+
console.error("");
|
|
141
|
+
const lock = syncSkillpacks(repoRoot, cacheDir, targetDir);
|
|
142
|
+
const lockPath = join4(repoRoot, "skillpacks.lock.yaml");
|
|
143
|
+
writeLockFile(lockPath, lock);
|
|
144
|
+
console.error("");
|
|
145
|
+
console.error(`[sync] Lock file written: ${lockPath}`);
|
|
146
|
+
console.error(`[sync] Synced ${lock.packs.length} packs with ${lock.packs.reduce((sum, p) => sum + p.agentCount, 0)} agents and ${lock.packs.reduce((sum, p) => sum + p.specCount, 0)} specs`);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// src/program.ts
|
|
150
|
+
function buildProgram(repo = process.cwd()) {
|
|
151
|
+
const program2 = new Command("rc");
|
|
152
|
+
program2.command("context").option("--platform <p>", "platform", "claude-code").option("--inject", "inject mode", false).option("--format <f>", "text|json", "text").option("--event <name>", "hook event name for json envelope").action((opts) => {
|
|
153
|
+
process.stdout.write(runContext({ repo, format: opts.format, now: (/* @__PURE__ */ new Date()).toISOString(), eventName: opts.event }));
|
|
154
|
+
});
|
|
155
|
+
program2.command("doctor").action(() => {
|
|
156
|
+
const { ok, report } = runDoctor(repo);
|
|
157
|
+
process.stdout.write(report.join("\n") + "\n");
|
|
158
|
+
process.exitCode = ok ? 0 : 1;
|
|
159
|
+
});
|
|
160
|
+
registerInit(program2, repo);
|
|
161
|
+
registerTask(program2, repo);
|
|
162
|
+
program2.command("sync").description("Fetch skillpacks and render agents/specs").option("--repo <path>", "Repository root", repo).option("--cache-dir <path>", "Cache directory for skillpacks").option("--target-dir <path>", "Target directory for rendered files").action((opts) => {
|
|
163
|
+
sync({
|
|
164
|
+
repo: opts.repo,
|
|
165
|
+
cacheDir: opts.cacheDir,
|
|
166
|
+
targetDir: opts.targetDir
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
return program2;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// src/errors.ts
|
|
173
|
+
function classifyCliError(err) {
|
|
174
|
+
const e = err;
|
|
175
|
+
if (e && typeof e.code === "string" && e.code.startsWith("commander.")) {
|
|
176
|
+
if (e.code === "commander.helpDisplayed" || e.code === "commander.version") {
|
|
177
|
+
return { exitCode: 0, message: null };
|
|
178
|
+
}
|
|
179
|
+
return { exitCode: 2, message: null };
|
|
180
|
+
}
|
|
181
|
+
const raw = err instanceof Error ? err.message : String(err);
|
|
182
|
+
if (/illegal transition/i.test(raw)) return { exitCode: 2, message: raw };
|
|
183
|
+
if (e?.code === "ENOENT" || /ENOENT|no such file/i.test(raw)) {
|
|
184
|
+
return { exitCode: 1, message: "not found: the requested task or a required file does not exist" };
|
|
185
|
+
}
|
|
186
|
+
return { exitCode: 1, message: raw };
|
|
187
|
+
}
|
|
188
|
+
function applyExitOverride(cmd) {
|
|
189
|
+
cmd.exitOverride();
|
|
190
|
+
for (const sub of cmd.commands) applyExitOverride(sub);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// bin/rc.ts
|
|
194
|
+
var program = buildProgram();
|
|
195
|
+
applyExitOverride(program);
|
|
196
|
+
try {
|
|
197
|
+
program.parse(process.argv);
|
|
198
|
+
} catch (err) {
|
|
199
|
+
const { exitCode, message } = classifyCliError(err);
|
|
200
|
+
if (message) process.stderr.write(`rc: ${message}
|
|
201
|
+
`);
|
|
202
|
+
process.exit(exitCode);
|
|
203
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@research-copilot/cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Multi-platform AI research assistant with MCP integration and skillpacks",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"rc": "./dist/rc.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"keywords": [
|
|
14
|
+
"ai",
|
|
15
|
+
"research",
|
|
16
|
+
"mcp",
|
|
17
|
+
"claude",
|
|
18
|
+
"gemini",
|
|
19
|
+
"cursor"
|
|
20
|
+
],
|
|
21
|
+
"author": "ldm2060",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/ldm2060/research_copilot.git"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=18.0.0"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@research-copilot/core": "^1.0.0",
|
|
32
|
+
"@research-copilot/adapters": "^1.0.0",
|
|
33
|
+
"commander": "^12.1.0"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsup bin/rc.ts --format esm"
|
|
37
|
+
}
|
|
38
|
+
}
|