clawrk 0.0.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/dist/index.js +180 -0
- package/package.json +26 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
|
|
6
|
+
// src/api.ts
|
|
7
|
+
var API_URL = process.env.API_URL || "http://localhost:3000";
|
|
8
|
+
async function api(path, opts) {
|
|
9
|
+
const res = await fetch(`${API_URL}${path}`, {
|
|
10
|
+
method: opts?.method ?? "GET",
|
|
11
|
+
headers: { "Content-Type": "application/json" },
|
|
12
|
+
...opts?.body ? { body: JSON.stringify(opts.body) } : {}
|
|
13
|
+
});
|
|
14
|
+
if (!res.ok) {
|
|
15
|
+
const err = await res.json().catch(() => ({ error: res.statusText }));
|
|
16
|
+
throw new Error(err.error || `HTTP ${res.status}`);
|
|
17
|
+
}
|
|
18
|
+
return res.json();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/commands/create.ts
|
|
22
|
+
function registerCreate(program2) {
|
|
23
|
+
program2.command("create").description("Create a new job from a prompt").argument("<prompt>", "The job prompt").option("-s, --sender <sender>", "Sender identity", process.env.SENDER_ID || "cli-sender").action(async (prompt, opts) => {
|
|
24
|
+
const job = await api("/api/jobs", {
|
|
25
|
+
method: "POST",
|
|
26
|
+
body: { prompt, sender: opts.sender }
|
|
27
|
+
});
|
|
28
|
+
console.log("Job created:");
|
|
29
|
+
console.log(JSON.stringify(job, null, 2));
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/commands/list.ts
|
|
34
|
+
function registerList(program2) {
|
|
35
|
+
program2.command("list").description("List jobs").option("--status <status>", "Filter by status").option("--sender <sender>", "Filter by sender").option("--receiver <receiver>", "Filter by receiver").action(async (opts) => {
|
|
36
|
+
const params = new URLSearchParams();
|
|
37
|
+
if (opts.status) params.set("status", opts.status);
|
|
38
|
+
if (opts.sender) params.set("sender", opts.sender);
|
|
39
|
+
if (opts.receiver) params.set("receiver", opts.receiver);
|
|
40
|
+
const qs = params.toString();
|
|
41
|
+
const jobs = await api(`/api/jobs${qs ? `?${qs}` : ""}`);
|
|
42
|
+
if (jobs.length === 0) {
|
|
43
|
+
console.log("No jobs found.");
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
for (const j of jobs) {
|
|
47
|
+
console.log(` ${j.id} [${j.status.padEnd(11)}] ${j.title}`);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/commands/accept.ts
|
|
53
|
+
function registerAccept(program2) {
|
|
54
|
+
program2.command("accept").description("Accept a job").argument("<id>", "Job ID").option("-r, --receiver <receiver>", "Receiver identity", process.env.RECEIVER_ID || "cli-receiver").action(async (id, opts) => {
|
|
55
|
+
const job = await api(`/api/jobs/${id}/accept`, {
|
|
56
|
+
method: "POST",
|
|
57
|
+
body: { receiver: opts.receiver }
|
|
58
|
+
});
|
|
59
|
+
console.log("Job accepted:");
|
|
60
|
+
console.log(JSON.stringify(job, null, 2));
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ../openai/src/index.ts
|
|
65
|
+
import OpenAI from "openai";
|
|
66
|
+
var client = null;
|
|
67
|
+
function getClient() {
|
|
68
|
+
if (!client) {
|
|
69
|
+
const apiKey = process.env.OPENAI_API_KEY;
|
|
70
|
+
if (!apiKey) throw new Error("OPENAI_API_KEY is not set");
|
|
71
|
+
client = new OpenAI({ apiKey });
|
|
72
|
+
}
|
|
73
|
+
return client;
|
|
74
|
+
}
|
|
75
|
+
function isConfigured() {
|
|
76
|
+
return !!process.env.OPENAI_API_KEY;
|
|
77
|
+
}
|
|
78
|
+
async function chat(system, user, opts) {
|
|
79
|
+
const res = await getClient().chat.completions.create({
|
|
80
|
+
model: opts?.model ?? "gpt-4o-mini",
|
|
81
|
+
messages: [
|
|
82
|
+
{ role: "system", content: system },
|
|
83
|
+
{ role: "user", content: user }
|
|
84
|
+
],
|
|
85
|
+
...opts?.json ? { response_format: { type: "json_object" } } : {}
|
|
86
|
+
});
|
|
87
|
+
return res.choices[0]?.message?.content ?? "";
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ../skills/src/research.ts
|
|
91
|
+
var SYSTEM = `You are a research assistant. Given a research topic or question, produce a clear, well-structured markdown summary. Include key facts, context, and cite areas for further exploration. Keep it concise but informative (300-600 words).`;
|
|
92
|
+
var researchSkill = {
|
|
93
|
+
name: "research",
|
|
94
|
+
description: "Research and summarize a topic using an LLM",
|
|
95
|
+
creditCost: 2,
|
|
96
|
+
async execute(input) {
|
|
97
|
+
if (!isConfigured()) {
|
|
98
|
+
return `# Research: ${input}
|
|
99
|
+
|
|
100
|
+
[Mock output \u2014 set OPENAI_API_KEY for real LLM responses]
|
|
101
|
+
|
|
102
|
+
This is a placeholder research summary for: "${input}". In production, this would contain a detailed LLM-generated analysis.`;
|
|
103
|
+
}
|
|
104
|
+
return chat(SYSTEM, input);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// ../skills/src/index.ts
|
|
109
|
+
var registry = /* @__PURE__ */ new Map();
|
|
110
|
+
function register(skill) {
|
|
111
|
+
registry.set(skill.name, skill);
|
|
112
|
+
}
|
|
113
|
+
register(researchSkill);
|
|
114
|
+
function getSkill(name) {
|
|
115
|
+
return registry.get(name);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// src/commands/run.ts
|
|
119
|
+
function registerRun(program2) {
|
|
120
|
+
program2.command("run").description("Run the assigned skill for a job locally").argument("<id>", "Job ID").action(async (id) => {
|
|
121
|
+
const job = await api(`/api/jobs/${id}`);
|
|
122
|
+
if (job.status !== "accepted" && job.status !== "in_progress") {
|
|
123
|
+
console.error(`Cannot run skill: job is in status '${job.status}'`);
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
126
|
+
const skill = getSkill(job.skill);
|
|
127
|
+
if (!skill) {
|
|
128
|
+
console.error(`Unknown skill: ${job.skill}`);
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
131
|
+
console.log(`Running skill '${skill.name}' for job ${id}...`);
|
|
132
|
+
const output = await skill.execute(job.intent);
|
|
133
|
+
console.log("\n--- Output ---\n");
|
|
134
|
+
console.log(output);
|
|
135
|
+
console.log("\nUse 'clawrk submit " + id + "' to submit this via the API (runs skill server-side),");
|
|
136
|
+
console.log("or 'clawrk submit " + id + ` --output "..."' to submit custom output.`);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// src/commands/submit.ts
|
|
141
|
+
function registerSubmit(program2) {
|
|
142
|
+
program2.command("submit").description("Submit output for a job").argument("<id>", "Job ID").option("-o, --output <output>", "Output text (if omitted, skill runs server-side)").action(async (id, opts) => {
|
|
143
|
+
const body = opts.output ? { output: opts.output } : {};
|
|
144
|
+
const job = await api(`/api/jobs/${id}/submit`, {
|
|
145
|
+
method: "POST",
|
|
146
|
+
body
|
|
147
|
+
});
|
|
148
|
+
console.log("Submission recorded:");
|
|
149
|
+
console.log(JSON.stringify(job, null, 2));
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// src/commands/verify.ts
|
|
154
|
+
function registerVerify(program2) {
|
|
155
|
+
program2.command("verify").description("Trigger verification for a submitted job").argument("<id>", "Job ID").action(async (id) => {
|
|
156
|
+
const job = await api(`/api/jobs/${id}/verify`, {
|
|
157
|
+
method: "POST"
|
|
158
|
+
});
|
|
159
|
+
console.log(`Status: ${job.status}`);
|
|
160
|
+
if (job.verification) {
|
|
161
|
+
const v = JSON.parse(job.verification);
|
|
162
|
+
console.log(`Pass: ${v.pass}`);
|
|
163
|
+
console.log(`Reasoning: ${v.reasoning}`);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// src/index.ts
|
|
169
|
+
var program = new Command();
|
|
170
|
+
program.name("clawrk").description("Agent Job Exchange CLI").version("0.0.1");
|
|
171
|
+
registerCreate(program);
|
|
172
|
+
registerList(program);
|
|
173
|
+
registerAccept(program);
|
|
174
|
+
registerRun(program);
|
|
175
|
+
registerSubmit(program);
|
|
176
|
+
registerVerify(program);
|
|
177
|
+
var args = process.argv.slice();
|
|
178
|
+
var sep = args.indexOf("--", 2);
|
|
179
|
+
if (sep !== -1) args.splice(sep, 1);
|
|
180
|
+
program.parse(args);
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "clawrk",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"bin": {
|
|
6
|
+
"clawrk": "./dist/index.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"commander": "^13",
|
|
13
|
+
"openai": "^4",
|
|
14
|
+
"@clawrk/openai": "0.0.1",
|
|
15
|
+
"@clawrk/skills": "0.0.1"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"tsup": "^8",
|
|
19
|
+
"tsx": "^4",
|
|
20
|
+
"typescript": "^5"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsup",
|
|
24
|
+
"start": "tsx src/index.ts"
|
|
25
|
+
}
|
|
26
|
+
}
|