jobkompass-cli 0.1.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/README.md +43 -0
- package/dist/index.js +492 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# jk — JobKompass CLI
|
|
2
|
+
|
|
3
|
+
Run your JobKompass job search from the terminal — or let an AI agent (Claude Code, Cursor, etc.) run it for you. Covers jobs, resumes, cover letters, email templates, resources, and chat threads.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
1. `npm install -g jobkompass-cli`
|
|
7
|
+
2. Create a key at [myjobkompass.com](https://www.myjobkompass.com) → **Settings → Command Line & AI Agents**. It's shown once — only a hash is stored.
|
|
8
|
+
3. `jk auth login <key>` (saved to `~/.config/jk/config.json`, mode 0600). Or set `JK_API_KEY`.
|
|
9
|
+
|
|
10
|
+
`JK_BASE_URL` overrides the target deployment (defaults to the live one).
|
|
11
|
+
|
|
12
|
+
## For agents
|
|
13
|
+
- Run `jk schema` once — it returns every route, param, and type as JSON.
|
|
14
|
+
- Output is JSON whenever stdout is piped. Exit codes: 0 ok, 1 your mistake (read `error.hint`), 2 server/network.
|
|
15
|
+
- Destructive commands need `--yes`. Nothing ever prompts.
|
|
16
|
+
|
|
17
|
+
## Examples
|
|
18
|
+
jk jobs add --company "Anthropic" --title "Engineer" --link "https://..." --status Interested
|
|
19
|
+
jk jobs list --status Applied
|
|
20
|
+
jk jobs update --id <id> --status Interviewing --notes "phone screen Tue"
|
|
21
|
+
jk resumes add --job-id <id> --name "Anthropic — Engineer"
|
|
22
|
+
jk resumes list
|
|
23
|
+
jk resources add --title "Salary guide" --url "https://..."
|
|
24
|
+
|
|
25
|
+
## Keys
|
|
26
|
+
A key carries full access to one account's data. Name each key after where it lives
|
|
27
|
+
(`laptop`, `claude-code`) so you can revoke just that one. Revoke from the same
|
|
28
|
+
Settings section — it takes effect immediately.
|
|
29
|
+
|
|
30
|
+
## Dev loop
|
|
31
|
+
npm run build && npm link # rebuild global binary
|
|
32
|
+
npm test # unit tests
|
|
33
|
+
JK_BASE_URL=<site> JK_API_KEY=<throwaway user key> npm run smoke
|
|
34
|
+
|
|
35
|
+
Admin key minting (bypasses the UI, for backfills) is internal-only:
|
|
36
|
+
|
|
37
|
+
CONVEX_DEPLOYMENT=dev:proficient-mammoth-632 \
|
|
38
|
+
npx convex run agent/keys:generate '{"userId":"<userId>","name":"cli"}'
|
|
39
|
+
|
|
40
|
+
## Publishing
|
|
41
|
+
cd cli && npm login && npm publish
|
|
42
|
+
|
|
43
|
+
`prepublishOnly` rebuilds and runs the tests first. Only `dist/` and this README ship.
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
|
|
6
|
+
// src/commands.ts
|
|
7
|
+
var jobWriteOpts = [
|
|
8
|
+
{ flag: "--compensation <c>", api: "compensation", type: "str" },
|
|
9
|
+
{ flag: "--keywords <json>", api: "keywords", type: "json", desc: '["kw1","kw2"]' },
|
|
10
|
+
{ flag: "--skills <json>", api: "skills", type: "json", desc: '["skill1"]' },
|
|
11
|
+
{ flag: "--description <text>", api: "description", type: "str" },
|
|
12
|
+
{ flag: "--applied <date>", api: "dateApplied", type: "str", desc: "Date applied (freeform)" },
|
|
13
|
+
{ flag: "--interviewed", api: "interviewed", type: "bool" },
|
|
14
|
+
{ flag: "--easy-apply <yn>", api: "easyApply", type: "str", desc: "Yes|No" },
|
|
15
|
+
{ flag: "--resume-used <name>", api: "resumeUsed", type: "str" },
|
|
16
|
+
{ flag: "--coverletter-used <name>", api: "coverLetterUsed", type: "str" },
|
|
17
|
+
{ flag: "--notes <text>", api: "notes", type: "str" }
|
|
18
|
+
];
|
|
19
|
+
var resourceWriteOpts = [
|
|
20
|
+
{ flag: "--description <text>", api: "description", type: "str" },
|
|
21
|
+
{ flag: "--notes <text>", api: "notes", type: "str" },
|
|
22
|
+
{ flag: "--tags <json>", api: "tags", type: "json", desc: '["tag1"]' },
|
|
23
|
+
{ flag: "--category <cat>", api: "category", type: "str" }
|
|
24
|
+
];
|
|
25
|
+
var commands = [
|
|
26
|
+
// jobs
|
|
27
|
+
{
|
|
28
|
+
name: "jobs list",
|
|
29
|
+
desc: "List jobs (newest updated first)",
|
|
30
|
+
method: "GET",
|
|
31
|
+
path: "/agent/jobs",
|
|
32
|
+
opts: [{ flag: "--status <status>", api: "status", type: "str", desc: "Interested|Applied|Callback|Interviewing|Rejected|Offered" }]
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "jobs get",
|
|
36
|
+
desc: "Get one job",
|
|
37
|
+
method: "GET",
|
|
38
|
+
path: "/agent/jobs/get",
|
|
39
|
+
opts: [{ flag: "--id <id>", api: "id", type: "str", required: true }]
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: "jobs add",
|
|
43
|
+
desc: "Add a job",
|
|
44
|
+
method: "POST",
|
|
45
|
+
path: "/agent/jobs",
|
|
46
|
+
opts: [
|
|
47
|
+
{ flag: "--company <name>", api: "company", type: "str", required: true },
|
|
48
|
+
{ flag: "--title <title>", api: "title", type: "str", required: true },
|
|
49
|
+
{ flag: "--link <url>", api: "link", type: "str", required: true },
|
|
50
|
+
{ flag: "--status <status>", api: "status", type: "str", default: "Interested" },
|
|
51
|
+
...jobWriteOpts
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "jobs update",
|
|
56
|
+
desc: "Update a job",
|
|
57
|
+
method: "PATCH",
|
|
58
|
+
path: "/agent/jobs",
|
|
59
|
+
opts: [
|
|
60
|
+
{ flag: "--id <id>", api: "id", type: "str", required: true },
|
|
61
|
+
{ flag: "--company <name>", api: "company", type: "str" },
|
|
62
|
+
{ flag: "--title <title>", api: "title", type: "str" },
|
|
63
|
+
{ flag: "--link <url>", api: "link", type: "str" },
|
|
64
|
+
{ flag: "--status <status>", api: "status", type: "str" },
|
|
65
|
+
...jobWriteOpts
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: "jobs delete",
|
|
70
|
+
desc: "Delete a job",
|
|
71
|
+
method: "DELETE",
|
|
72
|
+
path: "/agent/jobs",
|
|
73
|
+
confirm: true,
|
|
74
|
+
opts: [{ flag: "--id <id>", api: "id", type: "str", required: true }]
|
|
75
|
+
},
|
|
76
|
+
// resumes
|
|
77
|
+
{ name: "resumes list", desc: "List resumes (metadata)", method: "GET", path: "/agent/resumes", opts: [] },
|
|
78
|
+
{
|
|
79
|
+
name: "resumes get",
|
|
80
|
+
desc: "Get a resume with content",
|
|
81
|
+
method: "GET",
|
|
82
|
+
path: "/agent/resumes/get",
|
|
83
|
+
opts: [{ flag: "--id <id>", api: "id", type: "str", required: true }]
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: "resumes rename",
|
|
87
|
+
desc: "Rename a resume",
|
|
88
|
+
method: "PATCH",
|
|
89
|
+
path: "/agent/resumes",
|
|
90
|
+
opts: [
|
|
91
|
+
{ flag: "--id <id>", api: "id", type: "str", required: true },
|
|
92
|
+
{ flag: "--name <name>", api: "name", type: "str", required: true }
|
|
93
|
+
]
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
name: "resumes duplicate",
|
|
97
|
+
desc: "Duplicate a resume",
|
|
98
|
+
method: "POST",
|
|
99
|
+
path: "/agent/resumes/duplicate",
|
|
100
|
+
opts: [{ flag: "--id <id>", api: "id", type: "str", required: true }]
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: "resumes delete",
|
|
104
|
+
desc: "Delete a resume + stored file",
|
|
105
|
+
method: "DELETE",
|
|
106
|
+
path: "/agent/resumes",
|
|
107
|
+
confirm: true,
|
|
108
|
+
opts: [{ flag: "--id <id>", api: "id", type: "str", required: true }]
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: "resumes add",
|
|
112
|
+
desc: "Generate a resume PDF (Jake template) and save it",
|
|
113
|
+
method: "POST",
|
|
114
|
+
path: "/agent/resumes/generate",
|
|
115
|
+
opts: [
|
|
116
|
+
{
|
|
117
|
+
flag: "--personal-info <json>",
|
|
118
|
+
api: "personalInfo",
|
|
119
|
+
type: "json",
|
|
120
|
+
required: true,
|
|
121
|
+
desc: '{"firstName","lastName","email","citizenship"?,"location"?,"linkedin"?,"github"?,"portfolio"?,"summary"?}'
|
|
122
|
+
},
|
|
123
|
+
{ flag: "--education <json>", api: "education", type: "json", desc: "[{name,degree,field?,location?,startDate?,endDate,details?}]" },
|
|
124
|
+
{ flag: "--experience <json>", api: "experience", type: "json", desc: "[{company,title,location?,date,details}]" },
|
|
125
|
+
{ flag: "--projects <json>", api: "projects", type: "json", desc: "[{name,description,date?,technologies?,details?}]" },
|
|
126
|
+
{ flag: "--skills <json>", api: "skills", type: "json", desc: '{"technical":[...],"additional"?:[...]}' },
|
|
127
|
+
{ flag: "--certifications <json>", api: "certifications", type: "json", desc: "[{name,issuer?,date?,credentialId?}]" },
|
|
128
|
+
{ flag: "--additional-info <json>", api: "additionalInfo", type: "json", desc: '{"languages"?:[...],"references"?}' },
|
|
129
|
+
{ flag: "--target-company <name>", api: "targetCompany", type: "str", desc: "Included in the saved resume's name" }
|
|
130
|
+
]
|
|
131
|
+
},
|
|
132
|
+
// coverletters
|
|
133
|
+
{ name: "coverletters list", desc: "List cover letters (metadata)", method: "GET", path: "/agent/coverletters", opts: [] },
|
|
134
|
+
{
|
|
135
|
+
name: "coverletters get",
|
|
136
|
+
desc: "Get a cover letter with content",
|
|
137
|
+
method: "GET",
|
|
138
|
+
path: "/agent/coverletters/get",
|
|
139
|
+
opts: [{ flag: "--id <id>", api: "id", type: "str", required: true }]
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
name: "coverletters duplicate",
|
|
143
|
+
desc: "Duplicate a cover letter",
|
|
144
|
+
method: "POST",
|
|
145
|
+
path: "/agent/coverletters/duplicate",
|
|
146
|
+
opts: [{ flag: "--id <id>", api: "id", type: "str", required: true }]
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
name: "coverletters delete",
|
|
150
|
+
desc: "Delete a cover letter + stored file",
|
|
151
|
+
method: "DELETE",
|
|
152
|
+
path: "/agent/coverletters",
|
|
153
|
+
confirm: true,
|
|
154
|
+
opts: [{ flag: "--id <id>", api: "id", type: "str", required: true }]
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
name: "coverletters add",
|
|
158
|
+
desc: "Generate a cover letter PDF (Jake template) and save it",
|
|
159
|
+
method: "POST",
|
|
160
|
+
path: "/agent/coverletters/generate",
|
|
161
|
+
opts: [
|
|
162
|
+
{ flag: "--personal-info <json>", api: "personalInfo", type: "json", required: true, desc: '{"firstName","lastName","email","phone"?,"location"?}' },
|
|
163
|
+
{ flag: "--job-info <json>", api: "jobInfo", type: "json", required: true, desc: '{"company","position","hiringManagerName"?,"companyAddress"?}' },
|
|
164
|
+
{ flag: "--letter-content <json>", api: "letterContent", type: "json", required: true, desc: '{"openingParagraph","bodyParagraphs":[...],"closingParagraph"}' }
|
|
165
|
+
]
|
|
166
|
+
},
|
|
167
|
+
// emailtemplates
|
|
168
|
+
{ name: "emailtemplates list", desc: "List email templates", method: "GET", path: "/agent/emailtemplates", opts: [] },
|
|
169
|
+
{
|
|
170
|
+
name: "emailtemplates add",
|
|
171
|
+
desc: "Create an email template",
|
|
172
|
+
method: "POST",
|
|
173
|
+
path: "/agent/emailtemplates",
|
|
174
|
+
opts: [
|
|
175
|
+
{ flag: "--name <name>", api: "name", type: "str", required: true },
|
|
176
|
+
{ flag: "--type <type>", api: "type", type: "str", required: true, desc: "e.g. followup, cold-outreach" },
|
|
177
|
+
{ flag: "--content <json>", api: "content", type: "json", required: true, desc: '{"template":"...","variables":["name"]}' }
|
|
178
|
+
]
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
name: "emailtemplates update",
|
|
182
|
+
desc: "Update an email template",
|
|
183
|
+
method: "PATCH",
|
|
184
|
+
path: "/agent/emailtemplates",
|
|
185
|
+
opts: [
|
|
186
|
+
{ flag: "--id <id>", api: "id", type: "str", required: true },
|
|
187
|
+
{ flag: "--name <name>", api: "name", type: "str" },
|
|
188
|
+
{ flag: "--type <type>", api: "type", type: "str" },
|
|
189
|
+
{ flag: "--content <json>", api: "content", type: "json" }
|
|
190
|
+
]
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
name: "emailtemplates delete",
|
|
194
|
+
desc: "Delete an email template",
|
|
195
|
+
method: "DELETE",
|
|
196
|
+
path: "/agent/emailtemplates",
|
|
197
|
+
confirm: true,
|
|
198
|
+
opts: [{ flag: "--id <id>", api: "id", type: "str", required: true }]
|
|
199
|
+
},
|
|
200
|
+
// resources
|
|
201
|
+
{ name: "resources list", desc: "List saved resources", method: "GET", path: "/agent/resources", opts: [] },
|
|
202
|
+
{
|
|
203
|
+
name: "resources add",
|
|
204
|
+
desc: "Save a resource/link",
|
|
205
|
+
method: "POST",
|
|
206
|
+
path: "/agent/resources",
|
|
207
|
+
opts: [
|
|
208
|
+
{ flag: "--title <title>", api: "title", type: "str", required: true },
|
|
209
|
+
{ flag: "--url <url>", api: "url", type: "str", required: true },
|
|
210
|
+
{ flag: "--type <type>", api: "type", type: "str", default: "resource" },
|
|
211
|
+
...resourceWriteOpts
|
|
212
|
+
]
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
name: "resources update",
|
|
216
|
+
desc: "Update a resource",
|
|
217
|
+
method: "PATCH",
|
|
218
|
+
path: "/agent/resources",
|
|
219
|
+
opts: [
|
|
220
|
+
{ flag: "--id <id>", api: "id", type: "str", required: true },
|
|
221
|
+
{ flag: "--title <title>", api: "title", type: "str" },
|
|
222
|
+
{ flag: "--url <url>", api: "url", type: "str" },
|
|
223
|
+
{ flag: "--type <type>", api: "type", type: "str" },
|
|
224
|
+
...resourceWriteOpts
|
|
225
|
+
]
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
name: "resources delete",
|
|
229
|
+
desc: "Delete a resource",
|
|
230
|
+
method: "DELETE",
|
|
231
|
+
path: "/agent/resources",
|
|
232
|
+
confirm: true,
|
|
233
|
+
opts: [{ flag: "--id <id>", api: "id", type: "str", required: true }]
|
|
234
|
+
},
|
|
235
|
+
// threads (read-only)
|
|
236
|
+
{ name: "threads list", desc: "List AI chat threads", method: "GET", path: "/agent/threads", opts: [] },
|
|
237
|
+
{
|
|
238
|
+
name: "threads get",
|
|
239
|
+
desc: "Get a thread with messages",
|
|
240
|
+
method: "GET",
|
|
241
|
+
path: "/agent/threads/get",
|
|
242
|
+
opts: [{ flag: "--id <id>", api: "id", type: "str", required: true }]
|
|
243
|
+
}
|
|
244
|
+
];
|
|
245
|
+
|
|
246
|
+
// src/config.ts
|
|
247
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "fs";
|
|
248
|
+
import { homedir } from "os";
|
|
249
|
+
import { join } from "path";
|
|
250
|
+
var DEFAULT_BASE_URL = "https://proficient-mammoth-632.convex.site";
|
|
251
|
+
function configDir() {
|
|
252
|
+
return process.env.JK_CONFIG_DIR ?? join(homedir(), ".config", "jk");
|
|
253
|
+
}
|
|
254
|
+
function configPath() {
|
|
255
|
+
return join(configDir(), "config.json");
|
|
256
|
+
}
|
|
257
|
+
function loadConfig() {
|
|
258
|
+
let fileCfg = {};
|
|
259
|
+
if (existsSync(configPath())) {
|
|
260
|
+
try {
|
|
261
|
+
fileCfg = JSON.parse(readFileSync(configPath(), "utf8"));
|
|
262
|
+
} catch {
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return {
|
|
266
|
+
apiKey: process.env.JK_API_KEY ?? fileCfg.apiKey,
|
|
267
|
+
baseUrl: process.env.JK_BASE_URL ?? fileCfg.baseUrl ?? DEFAULT_BASE_URL
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
function saveConfig(cfg) {
|
|
271
|
+
mkdirSync(configDir(), { recursive: true });
|
|
272
|
+
const existing = existsSync(configPath()) ? JSON.parse(readFileSync(configPath(), "utf8")) : {};
|
|
273
|
+
writeFileSync(configPath(), JSON.stringify({ ...existing, ...cfg }, null, 2) + "\n", { mode: 384 });
|
|
274
|
+
}
|
|
275
|
+
function deleteConfig() {
|
|
276
|
+
rmSync(configPath(), { force: true });
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// src/client.ts
|
|
280
|
+
var CliError = class extends Error {
|
|
281
|
+
constructor(code, message, hint, exitCode) {
|
|
282
|
+
super(message);
|
|
283
|
+
this.code = code;
|
|
284
|
+
this.hint = hint;
|
|
285
|
+
this.exitCode = exitCode;
|
|
286
|
+
}
|
|
287
|
+
code;
|
|
288
|
+
hint;
|
|
289
|
+
exitCode;
|
|
290
|
+
};
|
|
291
|
+
async function apiRequest(method, path, opts = {}) {
|
|
292
|
+
const { apiKey, baseUrl } = loadConfig();
|
|
293
|
+
if (!apiKey) {
|
|
294
|
+
throw new CliError(
|
|
295
|
+
"no_key",
|
|
296
|
+
"No API key configured.",
|
|
297
|
+
"Create a key at https://www.myjobkompass.com -> Settings -> Command Line & AI Agents, then run 'jk auth login <key>' (or set JK_API_KEY).",
|
|
298
|
+
1
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
const url = new URL(baseUrl.replace(/\/$/, "") + path);
|
|
302
|
+
for (const [k, v] of Object.entries(opts.query ?? {})) {
|
|
303
|
+
if (v !== void 0) url.searchParams.set(k, typeof v === "object" ? JSON.stringify(v) : String(v));
|
|
304
|
+
}
|
|
305
|
+
let response;
|
|
306
|
+
const init = {
|
|
307
|
+
method,
|
|
308
|
+
headers: {
|
|
309
|
+
Authorization: `Bearer ${apiKey}`,
|
|
310
|
+
...opts.body ? { "Content-Type": "application/json" } : {}
|
|
311
|
+
},
|
|
312
|
+
...opts.body ? { body: JSON.stringify(opts.body) } : {}
|
|
313
|
+
};
|
|
314
|
+
try {
|
|
315
|
+
response = await fetch(url, init);
|
|
316
|
+
} catch {
|
|
317
|
+
try {
|
|
318
|
+
response = await fetch(url, init);
|
|
319
|
+
} catch (err2) {
|
|
320
|
+
throw new CliError("network", `Could not reach ${url.origin}: ${err2 instanceof Error ? err2.message : err2}`, "Check your connection and JK_BASE_URL.", 2);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
let payload;
|
|
324
|
+
try {
|
|
325
|
+
payload = await response.json();
|
|
326
|
+
} catch {
|
|
327
|
+
throw new CliError("bad_response", `Server returned non-JSON (HTTP ${response.status})`, void 0, 2);
|
|
328
|
+
}
|
|
329
|
+
if (payload.ok) return payload.data;
|
|
330
|
+
const err = payload.error ?? {};
|
|
331
|
+
throw new CliError(
|
|
332
|
+
err.code ?? "error",
|
|
333
|
+
err.message ?? `HTTP ${response.status}`,
|
|
334
|
+
err.hint,
|
|
335
|
+
response.status >= 500 ? 2 : 1
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// src/output.ts
|
|
340
|
+
function cell(value) {
|
|
341
|
+
if (value === null || value === void 0) return "";
|
|
342
|
+
if (typeof value === "object") return JSON.stringify(value);
|
|
343
|
+
return String(value);
|
|
344
|
+
}
|
|
345
|
+
function renderPretty(data) {
|
|
346
|
+
if (data === null || data === void 0) return "(none)";
|
|
347
|
+
if (Array.isArray(data)) {
|
|
348
|
+
if (data.length === 0) return "(none)";
|
|
349
|
+
if (typeof data[0] !== "object" || data[0] === null) return data.map(cell).join("\n");
|
|
350
|
+
const rows = data;
|
|
351
|
+
const cols = [...new Set(rows.flatMap((r) => Object.keys(r)))];
|
|
352
|
+
const widths = cols.map((c) => Math.max(c.length, ...rows.map((r) => cell(r[c]).length)));
|
|
353
|
+
const line = (vals) => vals.map((v, i) => v.padEnd(widths[i])).join(" ");
|
|
354
|
+
return [line(cols), ...rows.map((r) => line(cols.map((c) => cell(r[c]))))].join("\n");
|
|
355
|
+
}
|
|
356
|
+
if (typeof data === "object") {
|
|
357
|
+
return Object.entries(data).map(([k, v]) => `${k}: ${cell(v)}`).join("\n");
|
|
358
|
+
}
|
|
359
|
+
return String(data);
|
|
360
|
+
}
|
|
361
|
+
function emit(data, opts = {}) {
|
|
362
|
+
const machine = opts.json || !process.stdout.isTTY;
|
|
363
|
+
process.stdout.write((machine ? JSON.stringify(data, null, 2) : renderPretty(data)) + "\n");
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// src/dates.ts
|
|
367
|
+
function resolveDate(input) {
|
|
368
|
+
const lower = input.trim().toLowerCase();
|
|
369
|
+
const base = /* @__PURE__ */ new Date();
|
|
370
|
+
if (lower === "today") return toIso(base);
|
|
371
|
+
if (lower === "yesterday") {
|
|
372
|
+
base.setDate(base.getDate() - 1);
|
|
373
|
+
return toIso(base);
|
|
374
|
+
}
|
|
375
|
+
if (/^\d{4}-\d{2}-\d{2}$/.test(lower)) return lower;
|
|
376
|
+
throw new Error(`Invalid date '${input}'. Use today, yesterday, or YYYY-MM-DD.`);
|
|
377
|
+
}
|
|
378
|
+
function toIso(d) {
|
|
379
|
+
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// src/index.ts
|
|
383
|
+
var program = new Command();
|
|
384
|
+
program.name("jk").description("Agent-first CLI for JobKompass. All output is JSON when piped; add --json to force it.").option("--json", "Force JSON output").version("0.1.0");
|
|
385
|
+
function coerceOpt(spec, raw) {
|
|
386
|
+
if (raw === void 0) return void 0;
|
|
387
|
+
switch (spec.type) {
|
|
388
|
+
case "num": {
|
|
389
|
+
const n = Number(raw);
|
|
390
|
+
if (Number.isNaN(n)) fatal("invalid_option", `Option ${spec.flag.split(" ")[0]} must be a number, got '${raw}'`, void 0, 1);
|
|
391
|
+
return n;
|
|
392
|
+
}
|
|
393
|
+
case "bool":
|
|
394
|
+
return true;
|
|
395
|
+
// value-less flag
|
|
396
|
+
case "json":
|
|
397
|
+
try {
|
|
398
|
+
return JSON.parse(String(raw));
|
|
399
|
+
} catch {
|
|
400
|
+
fatal("invalid_option", `Option ${spec.flag.split(" ")[0]} must be valid JSON`, `Example: '${spec.desc ?? "[...]"}'`, 1);
|
|
401
|
+
}
|
|
402
|
+
break;
|
|
403
|
+
case "date":
|
|
404
|
+
try {
|
|
405
|
+
return resolveDate(String(raw));
|
|
406
|
+
} catch (err) {
|
|
407
|
+
fatal("invalid_option", err instanceof Error ? err.message : String(err), void 0, 1);
|
|
408
|
+
}
|
|
409
|
+
break;
|
|
410
|
+
default:
|
|
411
|
+
return raw;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
function fatal(code, message, hint, exitCode) {
|
|
415
|
+
const err = { ok: false, error: { code, message, ...hint ? { hint } : {} } };
|
|
416
|
+
if (process.stderr.isTTY) {
|
|
417
|
+
process.stderr.write(`error (${code}): ${message}
|
|
418
|
+
${hint ? `hint: ${hint}
|
|
419
|
+
` : ""}`);
|
|
420
|
+
} else {
|
|
421
|
+
process.stderr.write(JSON.stringify(err) + "\n");
|
|
422
|
+
}
|
|
423
|
+
process.exit(exitCode);
|
|
424
|
+
}
|
|
425
|
+
function register(spec) {
|
|
426
|
+
const [noun, verb] = spec.name.split(" ");
|
|
427
|
+
let parent = program.commands.find((c) => c.name() === noun);
|
|
428
|
+
if (!parent) {
|
|
429
|
+
parent = program.command(noun).description(`${noun} commands`);
|
|
430
|
+
}
|
|
431
|
+
const cmd = parent.command(verb).description(spec.desc);
|
|
432
|
+
for (const opt of spec.opts) {
|
|
433
|
+
const desc = opt.desc ?? "";
|
|
434
|
+
if (opt.required) cmd.requiredOption(opt.flag, desc, opt.default);
|
|
435
|
+
else cmd.option(opt.flag, desc, opt.default);
|
|
436
|
+
}
|
|
437
|
+
if (spec.confirm) cmd.option("--yes", "Confirm this destructive action");
|
|
438
|
+
cmd.action(async (options) => {
|
|
439
|
+
if (spec.confirm && !options.yes) {
|
|
440
|
+
fatal("confirm_required", `'jk ${spec.name}' is destructive.`, `Re-run with --yes to confirm.`, 1);
|
|
441
|
+
}
|
|
442
|
+
const payload = {};
|
|
443
|
+
for (const opt of spec.opts) {
|
|
444
|
+
const flagName = opt.flag.split(" ")[0].replace(/^--/, "").replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
445
|
+
const value = coerceOpt(opt, options[flagName]);
|
|
446
|
+
if (value !== void 0) payload[opt.api] = value;
|
|
447
|
+
}
|
|
448
|
+
try {
|
|
449
|
+
const data = spec.method === "GET" || spec.method === "DELETE" ? await apiRequest(spec.method, spec.path, { query: payload }) : await apiRequest(spec.method, spec.path, { body: payload });
|
|
450
|
+
emit(data, { json: Boolean(program.opts().json) });
|
|
451
|
+
} catch (err) {
|
|
452
|
+
if (err instanceof CliError) fatal(err.code, err.message, err.hint, err.exitCode);
|
|
453
|
+
throw err;
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
for (const spec of commands) register(spec);
|
|
458
|
+
var auth = program.command("auth").description("Manage the API key");
|
|
459
|
+
auth.command("login <key>").description("Save the API key to " + configPath()).action(async (key) => {
|
|
460
|
+
saveConfig({ apiKey: key });
|
|
461
|
+
try {
|
|
462
|
+
const data = await apiRequest("GET", "/agent/ping");
|
|
463
|
+
emit({ saved: true, ...data }, { json: Boolean(program.opts().json) });
|
|
464
|
+
} catch (err) {
|
|
465
|
+
deleteConfig();
|
|
466
|
+
if (err instanceof CliError) fatal(err.code, `Key rejected: ${err.message}`, err.hint, err.exitCode);
|
|
467
|
+
throw err;
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
auth.command("status").description("Verify the configured key").action(async () => {
|
|
471
|
+
try {
|
|
472
|
+
const data = await apiRequest("GET", "/agent/ping");
|
|
473
|
+
emit({ authenticated: true, baseUrl: loadConfig().baseUrl, ...data }, { json: Boolean(program.opts().json) });
|
|
474
|
+
} catch (err) {
|
|
475
|
+
if (err instanceof CliError) fatal(err.code, err.message, err.hint, err.exitCode);
|
|
476
|
+
throw err;
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
auth.command("logout").description("Delete the stored key").action(() => {
|
|
480
|
+
deleteConfig();
|
|
481
|
+
emit({ loggedOut: true }, { json: Boolean(program.opts().json) });
|
|
482
|
+
});
|
|
483
|
+
program.command("schema").description("Full machine-readable API surface (teach an agent everything in one call)").action(async () => {
|
|
484
|
+
try {
|
|
485
|
+
const data = await apiRequest("GET", "/agent/schema");
|
|
486
|
+
emit(data, { json: true });
|
|
487
|
+
} catch (err) {
|
|
488
|
+
if (err instanceof CliError) fatal(err.code, err.message, err.hint, err.exitCode);
|
|
489
|
+
throw err;
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
program.parseAsync(process.argv);
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "jobkompass-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Agent-first CLI for JobKompass — run your job search from the terminal, or let an AI agent run it for you.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"jk": "dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=18"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"jobkompass",
|
|
19
|
+
"cli",
|
|
20
|
+
"job-search",
|
|
21
|
+
"resume",
|
|
22
|
+
"ai-agent",
|
|
23
|
+
"claude-code"
|
|
24
|
+
],
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/itwela/jobkompass-v3.git",
|
|
28
|
+
"directory": "cli"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://www.myjobkompass.com",
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsup",
|
|
36
|
+
"test": "vitest run",
|
|
37
|
+
"smoke": "bash smoke.sh",
|
|
38
|
+
"prepublishOnly": "npm run build && npm test"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"commander": "^12.1.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/node": "^20.14.0",
|
|
45
|
+
"tsup": "^8.1.0",
|
|
46
|
+
"typescript": "^5.5.0",
|
|
47
|
+
"vitest": "^2.0.0"
|
|
48
|
+
}
|
|
49
|
+
}
|