@careerarchitect/cli 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +103 -2
- package/dist/auth/oauth.js +125 -0
- package/dist/auth/session.js +25 -0
- package/dist/auth/store.js +122 -0
- package/dist/bin.js +8 -0
- package/dist/cli.js +214 -0
- package/dist/commands/auth.js +134 -0
- package/dist/commands/calendar.js +38 -0
- package/dist/commands/context.js +1 -0
- package/dist/commands/cv.js +138 -0
- package/dist/commands/jobs.js +264 -0
- package/dist/commands/journey.js +187 -0
- package/dist/commands/lint.js +26 -0
- package/dist/config.js +21 -0
- package/dist/cv-file.js +80 -0
- package/dist/errors.js +23 -0
- package/dist/io.js +44 -0
- package/dist/job-ref.js +90 -0
- package/dist/journey-progress.js +44 -0
- package/dist/lint.js +149 -0
- package/dist/mcp.js +79 -0
- package/dist/shapes.js +374 -0
- package/dist/spend.js +55 -0
- package/dist/stage-pick.js +96 -0
- package/dist/state.js +55 -0
- package/package.json +41 -4
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { CliError, EXIT } from "../errors.js";
|
|
2
|
+
import { askText, canPrompt, formatScore, info, printJson } from "../io.js";
|
|
3
|
+
import { callTool } from "../mcp.js";
|
|
4
|
+
import { callWithQuote } from "../spend.js";
|
|
5
|
+
import { outJourneyRun, outJourneyStatus, readReply, replyJourneyStatus, replyOptimiseOptions, replyStageRun, } from "../shapes.js";
|
|
6
|
+
import { LAST, jobLabel, resolveJobRef } from "../job-ref.js";
|
|
7
|
+
import { pickStages } from "../stage-pick.js";
|
|
8
|
+
import { journeyProgress, latestScore, stageLabel, startingScore } from "../journey-progress.js";
|
|
9
|
+
import { loadJourneyStages, rememberJourneyStages } from "../state.js";
|
|
10
|
+
function statusBody(jobId, reply) {
|
|
11
|
+
const r = readReply(replyJourneyStatus, reply, "journey status");
|
|
12
|
+
return {
|
|
13
|
+
job_id: r.jobId || jobId,
|
|
14
|
+
journey_id: r.journeyId,
|
|
15
|
+
status: r.status,
|
|
16
|
+
initial_score: r.initialScore,
|
|
17
|
+
final_score: r.finalScore,
|
|
18
|
+
stages: r.stages.map((s) => ({
|
|
19
|
+
stage: s.stageType,
|
|
20
|
+
order: s.stageOrder,
|
|
21
|
+
status: s.status,
|
|
22
|
+
score_before: s.scoreBefore,
|
|
23
|
+
score_after: s.scoreAfter,
|
|
24
|
+
})),
|
|
25
|
+
unfixable_gaps: r.unfixableGaps.map((g) => ({ description: g.gapDescription, mitigation: g.mitigation })),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/** `chosen`: the stages picked for this journey, when this terminal knows them. */
|
|
29
|
+
function printStatus(ctx, s, chosen) {
|
|
30
|
+
if (!s.journey_id) {
|
|
31
|
+
info(ctx, `No optimisation journey for this job yet. Start one with: ca journey start ${LAST}`);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const p = journeyProgress(chosen, s.stages);
|
|
35
|
+
const scores = `${formatScore(startingScore(s.initial_score, s.stages))} → ${formatScore(latestScore(s.final_score, s.stages))}`;
|
|
36
|
+
const done = p.total == null ? `${p.done} stage${p.done === 1 ? "" : "s"} done` : `${p.done} of ${p.total} chosen stages done`;
|
|
37
|
+
info(ctx, `Progress: ${done} CV score ${scores}`);
|
|
38
|
+
const rows = [...s.stages].sort((a, b) => a.order - b.order);
|
|
39
|
+
for (const st of rows) {
|
|
40
|
+
const change = st.score_after != null ? ` ${formatScore(st.score_before)} → ${formatScore(st.score_after)}` : "";
|
|
41
|
+
info(ctx, ` ${stageLabel(st.stage).padEnd(22)} ${st.status.replace(/_/g, " ")}${change}`);
|
|
42
|
+
}
|
|
43
|
+
for (const key of chosen ?? []) {
|
|
44
|
+
if (!rows.some((st) => st.stage === key))
|
|
45
|
+
info(ctx, ` ${stageLabel(key).padEnd(22)} to do`);
|
|
46
|
+
}
|
|
47
|
+
if (s.unfixable_gaps.length) {
|
|
48
|
+
info(ctx, "");
|
|
49
|
+
info(ctx, "Gaps your CV can't close:");
|
|
50
|
+
for (const g of s.unfixable_gaps)
|
|
51
|
+
info(ctx, ` • ${g.description}${g.mitigation ? ` — ${g.mitigation}` : ""}`);
|
|
52
|
+
}
|
|
53
|
+
info(ctx, "");
|
|
54
|
+
info(ctx, "Answer questions, see changes and export on the website (ca recs, diff and export are coming soon).");
|
|
55
|
+
}
|
|
56
|
+
export function parseStageList(raw) {
|
|
57
|
+
if (!raw)
|
|
58
|
+
return undefined;
|
|
59
|
+
const list = raw
|
|
60
|
+
.split(/[\s,]+/)
|
|
61
|
+
.map((s) => s.trim())
|
|
62
|
+
.filter(Boolean);
|
|
63
|
+
return list.length ? list : undefined;
|
|
64
|
+
}
|
|
65
|
+
async function chooseStages(ctx, options) {
|
|
66
|
+
const keys = options.stages.filter((s) => s.unlocked).map((s) => s.key).join(",");
|
|
67
|
+
if (!canPrompt()) {
|
|
68
|
+
throw new CliError(`Pick stages with --stages, e.g. ca journey start ${LAST} --stages ${options.suggested_stages.join(",") || keys}`, EXIT.needsInput, "needs_input");
|
|
69
|
+
}
|
|
70
|
+
info(ctx, "Choose what to optimise:");
|
|
71
|
+
options.stages.forEach((s, i) => {
|
|
72
|
+
const tick = options.suggested_stages.includes(s.key) ? "[x]" : "[ ]";
|
|
73
|
+
const lock = s.unlocked ? "" : " (not on your plan)";
|
|
74
|
+
info(ctx, ` ${String(i + 1).padStart(2)}. ${tick} ${s.label}${lock}`);
|
|
75
|
+
if (s.recommended && s.reason)
|
|
76
|
+
info(ctx, ` ${s.reason}`);
|
|
77
|
+
});
|
|
78
|
+
const hasTicked = options.suggested_stages.length > 0;
|
|
79
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
80
|
+
const answer = await askText(`Which stages? Numbers or names, separated by commas${hasTicked ? " (Enter for the ticked ones)" : ""}:`, "");
|
|
81
|
+
const pick = pickStages(answer, options.stages, options.suggested_stages);
|
|
82
|
+
if (pick.ok) {
|
|
83
|
+
const labels = options.stages.filter((s) => pick.keys.includes(s.key)).map((s) => s.label);
|
|
84
|
+
info(ctx, `Chosen: ${labels.join(", ")}`);
|
|
85
|
+
return pick.keys;
|
|
86
|
+
}
|
|
87
|
+
for (const p of pick.problems)
|
|
88
|
+
info(ctx, p);
|
|
89
|
+
}
|
|
90
|
+
throw new CliError("No stages chosen. Nothing was started.");
|
|
91
|
+
}
|
|
92
|
+
export async function journeyStart(ctx, ref) {
|
|
93
|
+
const job = await resolveJobRef(ctx, ref, "Usage: ca journey start <job> [--stages a,b]");
|
|
94
|
+
return startJourneyFor(ctx, job);
|
|
95
|
+
}
|
|
96
|
+
/** Also used by ca fit when you say yes to "Optimise your CV for this job now?". */
|
|
97
|
+
export async function startJourneyFor(ctx, job) {
|
|
98
|
+
const jobId = job.id;
|
|
99
|
+
if (job.title || job.company)
|
|
100
|
+
info(ctx, `Optimising for ${jobLabel(job)}`);
|
|
101
|
+
let stages = parseStageList(ctx.flags.stages);
|
|
102
|
+
if (!stages) {
|
|
103
|
+
const first = await callTool("start_journey", { job_id: jobId });
|
|
104
|
+
const started = replyStageRun.safeParse(first);
|
|
105
|
+
if (started.success && started.data.alreadyStarted) {
|
|
106
|
+
info(ctx, `A journey already exists for this job. Run the next stage with: ca journey run ${LAST}`);
|
|
107
|
+
info(ctx, "");
|
|
108
|
+
return showStatus({ ...ctx, flags: { ...ctx.flags, watch: false } }, jobId);
|
|
109
|
+
}
|
|
110
|
+
const options = readReply(replyOptimiseOptions, first, "optimise options");
|
|
111
|
+
stages = await chooseStages(ctx, options);
|
|
112
|
+
}
|
|
113
|
+
const reply = await callWithQuote("start_journey", { job_id: jobId, stages }, ctx);
|
|
114
|
+
const run = readReply(replyStageRun, reply, "journey start");
|
|
115
|
+
if (run.ok === false)
|
|
116
|
+
throw new CliError(run.error ?? "The stage failed.");
|
|
117
|
+
await rememberJourneyStages(jobId, stages);
|
|
118
|
+
await finishRun(ctx, jobId, run, stages);
|
|
119
|
+
}
|
|
120
|
+
export async function journeyRun(ctx, ref) {
|
|
121
|
+
const { id: jobId } = await resolveJobRef(ctx, ref, "Usage: ca journey run <job> [--stage <key>]");
|
|
122
|
+
// The server doesn't keep the stages chosen at start, so send them on every run; otherwise it
|
|
123
|
+
// runs the next stage in its own order, which may be one that wasn't chosen.
|
|
124
|
+
const newChoice = parseStageList(ctx.flags.stages);
|
|
125
|
+
if (newChoice)
|
|
126
|
+
await rememberJourneyStages(jobId, newChoice);
|
|
127
|
+
const chosen = newChoice ?? (await loadJourneyStages(jobId));
|
|
128
|
+
const stages = ctx.flags.stage ? [ctx.flags.stage] : chosen;
|
|
129
|
+
if (!stages) {
|
|
130
|
+
info(ctx, "This terminal doesn't know which stages you chose for this job, so the next stage in the usual order runs. To choose, add --stages (e.g. --stages gap_analysis,human_touch).");
|
|
131
|
+
}
|
|
132
|
+
const reply = await callWithQuote("run_next_stage", { job_id: jobId, ...(stages ? { stages } : {}) }, ctx);
|
|
133
|
+
const run = readReply(replyStageRun, reply, "stage run");
|
|
134
|
+
if (run.ok === false)
|
|
135
|
+
throw new CliError(run.error ?? "The stage failed.");
|
|
136
|
+
await finishRun(ctx, jobId, run, chosen);
|
|
137
|
+
}
|
|
138
|
+
async function finishRun(ctx, jobId, run, chosen) {
|
|
139
|
+
const status = statusBody(jobId, await callTool("get_journey_status", { job_id: jobId }));
|
|
140
|
+
if (ctx.json) {
|
|
141
|
+
return printJson(outJourneyRun.parse({
|
|
142
|
+
schema: "journey-run/v1",
|
|
143
|
+
job_id: jobId,
|
|
144
|
+
stage_run: run.stageType ?? null,
|
|
145
|
+
done: run.done === true,
|
|
146
|
+
journey: status,
|
|
147
|
+
}));
|
|
148
|
+
}
|
|
149
|
+
if (run.stageType && !run.done)
|
|
150
|
+
info(ctx, `Ran ${stageLabel(run.stageType)}.`);
|
|
151
|
+
info(ctx, "");
|
|
152
|
+
printStatus(ctx, status, chosen);
|
|
153
|
+
const p = journeyProgress(chosen, status.stages);
|
|
154
|
+
if (run.done || (p.total != null && p.next == null))
|
|
155
|
+
info(ctx, "All your chosen stages have run.");
|
|
156
|
+
else if (p.next)
|
|
157
|
+
info(ctx, `Next: ${stageLabel(p.next)} — ca journey run ${LAST}`);
|
|
158
|
+
else
|
|
159
|
+
info(ctx, `Next stage: ca journey run ${LAST}`);
|
|
160
|
+
}
|
|
161
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
162
|
+
export async function journeyStatus(ctx, ref) {
|
|
163
|
+
const { id: jobId } = await resolveJobRef(ctx, ref, "Usage: ca journey status <job> [--watch]");
|
|
164
|
+
return showStatus(ctx, jobId);
|
|
165
|
+
}
|
|
166
|
+
async function showStatus(ctx, jobId) {
|
|
167
|
+
const chosen = await loadJourneyStages(jobId);
|
|
168
|
+
let last = "";
|
|
169
|
+
for (;;) {
|
|
170
|
+
const s = statusBody(jobId, await callTool("get_journey_status", { job_id: jobId }));
|
|
171
|
+
const running = s.stages.some((st) => st.status === "running");
|
|
172
|
+
const key = JSON.stringify(s);
|
|
173
|
+
if (key !== last) {
|
|
174
|
+
if (ctx.json)
|
|
175
|
+
printJson(outJourneyStatus.parse({ schema: "journey-status/v1", ...s }));
|
|
176
|
+
else {
|
|
177
|
+
if (last)
|
|
178
|
+
info(ctx, "—");
|
|
179
|
+
printStatus(ctx, s, chosen);
|
|
180
|
+
}
|
|
181
|
+
last = key;
|
|
182
|
+
}
|
|
183
|
+
if (!ctx.flags.watch || !running)
|
|
184
|
+
return;
|
|
185
|
+
await sleep(5000);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { CliError, EXIT } from "../errors.js";
|
|
2
|
+
import { info, printJson } from "../io.js";
|
|
3
|
+
import { readCvText } from "../cv-file.js";
|
|
4
|
+
import { lintCv } from "../lint.js";
|
|
5
|
+
import { outLint } from "../shapes.js";
|
|
6
|
+
const MARK = { pass: "✓", warn: "!", fail: "✗" };
|
|
7
|
+
/** Returns the exit code: 1 when a check fails (or warns, with --strict). */
|
|
8
|
+
export async function lint(ctx, path) {
|
|
9
|
+
if (!path)
|
|
10
|
+
throw new CliError("Usage: ca lint <file> [--strict]");
|
|
11
|
+
const { name, text } = await readCvText(path);
|
|
12
|
+
const result = lintCv(text, { strict: ctx.flags.strict });
|
|
13
|
+
if (ctx.json) {
|
|
14
|
+
printJson(outLint.parse({ schema: "lint/v1", file: name, ...result }));
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
info(ctx, name);
|
|
18
|
+
for (const c of result.checks) {
|
|
19
|
+
info(ctx, ` ${MARK[c.status]} ${c.message}`);
|
|
20
|
+
for (const d of c.details)
|
|
21
|
+
info(ctx, ` ${d}`);
|
|
22
|
+
}
|
|
23
|
+
info(ctx, result.passed ? "Passed." : "Failed.");
|
|
24
|
+
}
|
|
25
|
+
return result.passed ? EXIT.ok : EXIT.lintFailed;
|
|
26
|
+
}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
/** The CLI's fixed public OAuth client, seeded on the server (no secret, device flow only). */
|
|
4
|
+
export const CLIENT_ID = "careerarchitect-cli";
|
|
5
|
+
/** Every scope the CLI may ask for; the user picks the actual access level in the browser. */
|
|
6
|
+
export const REQUESTED_SCOPES = "read write spend";
|
|
7
|
+
export const DEFAULT_BASE_URL = "https://careerarchitect.coach";
|
|
8
|
+
/** `CA_BASE_URL` points the CLI at another server (a preview deploy, or local development). */
|
|
9
|
+
export function baseUrl() {
|
|
10
|
+
const raw = process.env.CA_BASE_URL?.trim();
|
|
11
|
+
return (raw || DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
12
|
+
}
|
|
13
|
+
export function cliVersion() {
|
|
14
|
+
try {
|
|
15
|
+
const pkg = require("../package.json");
|
|
16
|
+
return pkg.version ?? "0.0.0";
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return "0.0.0";
|
|
20
|
+
}
|
|
21
|
+
}
|
package/dist/cv-file.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { readFile, stat } from "node:fs/promises";
|
|
2
|
+
import { basename } from "node:path";
|
|
3
|
+
import { CliError } from "./errors.js";
|
|
4
|
+
/**
|
|
5
|
+
* Local file handling. `ca cv score` sends the file's bytes and the server reads them with the
|
|
6
|
+
* website's own code (design decision 4); this module only checks the file before sending it.
|
|
7
|
+
* `ca lint` reads the text here, offline, with the same libraries the server uses.
|
|
8
|
+
*/
|
|
9
|
+
/** The server's cap: base64 grows a file by a third, and requests over 4.5 MB never arrive. */
|
|
10
|
+
export const MAX_UPLOAD_BYTES = 3 * 1024 * 1024;
|
|
11
|
+
const FORMATS = { pdf: "pdf", docx: "docx", txt: "text", text: "text", md: "markdown" };
|
|
12
|
+
export function cvFormatOf(fileName) {
|
|
13
|
+
const ext = fileName.toLowerCase().split(".").pop() ?? "";
|
|
14
|
+
if (ext === "doc") {
|
|
15
|
+
throw new CliError("Legacy .doc files aren't supported. Resave your CV as a .pdf or .docx and try again.");
|
|
16
|
+
}
|
|
17
|
+
const format = FORMATS[ext];
|
|
18
|
+
if (!format)
|
|
19
|
+
throw new CliError("Unsupported file type. Use a .pdf, .docx, .txt or .md file.");
|
|
20
|
+
return format;
|
|
21
|
+
}
|
|
22
|
+
export async function readCvFileBytes(path, maxBytes = MAX_UPLOAD_BYTES) {
|
|
23
|
+
const name = basename(path);
|
|
24
|
+
cvFormatOf(name);
|
|
25
|
+
let size;
|
|
26
|
+
try {
|
|
27
|
+
const s = await stat(path);
|
|
28
|
+
if (!s.isFile())
|
|
29
|
+
throw new CliError(`${path} is not a file.`);
|
|
30
|
+
size = s.size;
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
if (err instanceof CliError)
|
|
34
|
+
throw err;
|
|
35
|
+
throw new CliError(`Can't read ${path}: no such file.`);
|
|
36
|
+
}
|
|
37
|
+
if (size > maxBytes) {
|
|
38
|
+
throw new CliError(`File is too large (${(size / 1024 / 1024).toFixed(1)} MB). Maximum size is ${maxBytes / 1024 / 1024} MB.`);
|
|
39
|
+
}
|
|
40
|
+
if (size === 0)
|
|
41
|
+
throw new CliError(`${name} is empty.`);
|
|
42
|
+
return { name, bytes: await readFile(path) };
|
|
43
|
+
}
|
|
44
|
+
function cleanExtractedText(raw) {
|
|
45
|
+
return raw.replace(/\r\n/g, "\n").replace(/ {3,}/g, "\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
46
|
+
}
|
|
47
|
+
/** Text for `ca lint`, read entirely on this machine. */
|
|
48
|
+
export async function readCvText(path) {
|
|
49
|
+
const { name, bytes } = await readCvFileBytes(path, 20 * 1024 * 1024);
|
|
50
|
+
const format = cvFormatOf(name);
|
|
51
|
+
let text;
|
|
52
|
+
if (format === "pdf") {
|
|
53
|
+
const { extractText } = await import("unpdf");
|
|
54
|
+
const { text: pages } = await extractText(new Uint8Array(bytes), { mergePages: false });
|
|
55
|
+
text = cleanExtractedText((Array.isArray(pages) ? pages : [pages]).join("\n\n"));
|
|
56
|
+
}
|
|
57
|
+
else if (format === "docx") {
|
|
58
|
+
const mammoth = await import("mammoth");
|
|
59
|
+
// Markdown-ish output keeps list items recognisable as bullets.
|
|
60
|
+
const html = (await mammoth.convertToHtml({ buffer: bytes })).value ?? "";
|
|
61
|
+
text = cleanExtractedText(html
|
|
62
|
+
.replace(/<li[^>]*>/gi, "\n- ")
|
|
63
|
+
.replace(/<\/(p|h\d|li|tr)>/gi, "\n")
|
|
64
|
+
.replace(/<br\s*\/?>/gi, "\n")
|
|
65
|
+
.replace(/<[^>]+>/g, "")
|
|
66
|
+
.replace(/&/g, "&")
|
|
67
|
+
.replace(/</g, "<")
|
|
68
|
+
.replace(/>/g, ">")
|
|
69
|
+
.replace(/"/g, '"')
|
|
70
|
+
.replace(/'/g, "'")
|
|
71
|
+
.replace(/ /g, " "));
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
text = bytes.toString("utf8").trim();
|
|
75
|
+
}
|
|
76
|
+
if (!text) {
|
|
77
|
+
throw new CliError("No text could be read from that file. If it's a scanned PDF, save it as text and try again.");
|
|
78
|
+
}
|
|
79
|
+
return { name, text };
|
|
80
|
+
}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Exit codes, documented in README.md. */
|
|
2
|
+
export const EXIT = {
|
|
3
|
+
ok: 0,
|
|
4
|
+
/** `ca lint` found a problem. */
|
|
5
|
+
lintFailed: 1,
|
|
6
|
+
/** Bad arguments, a refused action, or a server error. */
|
|
7
|
+
error: 2,
|
|
8
|
+
/** Not signed in, or the sign-in expired. */
|
|
9
|
+
auth: 3,
|
|
10
|
+
/** A credit action or a question needs an answer, and there is no terminal to ask in. */
|
|
11
|
+
needsInput: 4,
|
|
12
|
+
};
|
|
13
|
+
/** An error whose message is meant for the user as-is. */
|
|
14
|
+
export class CliError extends Error {
|
|
15
|
+
exitCode;
|
|
16
|
+
code;
|
|
17
|
+
constructor(message, exitCode = EXIT.error, code) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.exitCode = exitCode;
|
|
20
|
+
this.code = code;
|
|
21
|
+
this.name = "CliError";
|
|
22
|
+
}
|
|
23
|
+
}
|
package/dist/io.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createInterface } from "node:readline/promises";
|
|
2
|
+
import { CliError, EXIT } from "./errors.js";
|
|
3
|
+
/** With --json, stdout carries only the JSON payload; everything for people goes to stderr. */
|
|
4
|
+
export function info(mode, line = "") {
|
|
5
|
+
(mode.json ? process.stderr : process.stdout).write(line + "\n");
|
|
6
|
+
}
|
|
7
|
+
export function warn(line) {
|
|
8
|
+
process.stderr.write(line + "\n");
|
|
9
|
+
}
|
|
10
|
+
export function printJson(payload) {
|
|
11
|
+
process.stdout.write(JSON.stringify(payload, null, 2) + "\n");
|
|
12
|
+
}
|
|
13
|
+
export function canPrompt() {
|
|
14
|
+
return Boolean(process.stdin.isTTY && process.stderr.isTTY) && process.env.CI !== "true";
|
|
15
|
+
}
|
|
16
|
+
async function ask(question) {
|
|
17
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
18
|
+
try {
|
|
19
|
+
return (await rl.question(question)).trim();
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
rl.close();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** y/N question. Without a terminal it refuses with `hint` (exit 4) rather than guessing. */
|
|
26
|
+
export async function confirm(question, hint) {
|
|
27
|
+
if (!canPrompt())
|
|
28
|
+
throw new CliError(hint, EXIT.needsInput, "needs_confirmation");
|
|
29
|
+
const answer = (await ask(`${question} [y/N] `)).toLowerCase();
|
|
30
|
+
return answer === "y" || answer === "yes";
|
|
31
|
+
}
|
|
32
|
+
/** Free-text question. Without a terminal it refuses with `hint` (exit 4). */
|
|
33
|
+
export async function askText(question, hint, fallback) {
|
|
34
|
+
if (!canPrompt())
|
|
35
|
+
throw new CliError(hint, EXIT.needsInput, "needs_input");
|
|
36
|
+
const suffix = fallback ? ` [${fallback}]` : "";
|
|
37
|
+
const answer = await ask(`${question}${suffix} `);
|
|
38
|
+
return answer || fallback || "";
|
|
39
|
+
}
|
|
40
|
+
export function formatScore(n, outOf = 5) {
|
|
41
|
+
if (n == null || !Number.isFinite(n))
|
|
42
|
+
return "–";
|
|
43
|
+
return `${Number(n).toFixed(1)} / ${outOf}`;
|
|
44
|
+
}
|
package/dist/job-ref.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { CliError, EXIT } from "./errors.js";
|
|
2
|
+
import { askText, canPrompt, info } from "./io.js";
|
|
3
|
+
import { callTool } from "./mcp.js";
|
|
4
|
+
import { readReply, replyJobs } from "./shapes.js";
|
|
5
|
+
import { loadLastJob, rememberJob } from "./state.js";
|
|
6
|
+
/**
|
|
7
|
+
* Commands that act on a saved job take a friendly reference instead of a long id:
|
|
8
|
+
* - a number from `ca jobs` (1 is the newest saved job),
|
|
9
|
+
* - `last`, the last job you worked with in this terminal,
|
|
10
|
+
* - or the job's id, which still works for scripts.
|
|
11
|
+
*/
|
|
12
|
+
export const MAX_JOB_NUMBER = 50;
|
|
13
|
+
export function parseJobRef(raw) {
|
|
14
|
+
const ref = raw.trim().replace(/^#/, "");
|
|
15
|
+
if (/^\d{1,3}$/.test(ref))
|
|
16
|
+
return { kind: "number", n: Number(ref) };
|
|
17
|
+
if (ref.toLowerCase() === "last")
|
|
18
|
+
return { kind: "last" };
|
|
19
|
+
return { kind: "id", id: ref };
|
|
20
|
+
}
|
|
21
|
+
export function jobLabel(job) {
|
|
22
|
+
if (job.company && job.title)
|
|
23
|
+
return `${job.company} — ${job.title}`;
|
|
24
|
+
return job.title ?? job.company ?? "this job";
|
|
25
|
+
}
|
|
26
|
+
/** How a tip refers to a job you have just worked with. */
|
|
27
|
+
export const LAST = "last";
|
|
28
|
+
async function recentJobs(limit) {
|
|
29
|
+
const r = readReply(replyJobs, await callTool("list_jobs", { limit }), "jobs");
|
|
30
|
+
return r.jobs.map((j) => ({ id: j.id, title: j.title, company: j.company }));
|
|
31
|
+
}
|
|
32
|
+
async function byNumber(n) {
|
|
33
|
+
if (n < 1 || n > MAX_JOB_NUMBER) {
|
|
34
|
+
throw new CliError(`Job numbers run from 1 to ${MAX_JOB_NUMBER}. Run ca jobs to see them.`);
|
|
35
|
+
}
|
|
36
|
+
const job = (await recentJobs(n))[n - 1];
|
|
37
|
+
if (!job)
|
|
38
|
+
throw new CliError(`There's no job ${n}. Run ca jobs to see your saved jobs and their numbers.`);
|
|
39
|
+
return job;
|
|
40
|
+
}
|
|
41
|
+
async function pickInteractively(ctx, usage) {
|
|
42
|
+
if (ctx.json || !canPrompt()) {
|
|
43
|
+
throw new CliError(`${usage}\nName the job by its number from ca jobs (e.g. 1), or use last.`, EXIT.needsInput, "needs_input");
|
|
44
|
+
}
|
|
45
|
+
const jobs = await recentJobs(10);
|
|
46
|
+
if (!jobs.length)
|
|
47
|
+
throw new CliError("No saved jobs yet. Try: ca fit <job-url>");
|
|
48
|
+
info(ctx, "Your recent jobs:");
|
|
49
|
+
jobs.forEach((j, i) => info(ctx, ` ${String(i + 1).padStart(2)}. ${jobLabel(j)}`));
|
|
50
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
51
|
+
const answer = await askText("Which job? (number)", usage, "1");
|
|
52
|
+
const n = Number(answer.replace(/^#/, ""));
|
|
53
|
+
const job = Number.isInteger(n) ? jobs[n - 1] : undefined;
|
|
54
|
+
if (job)
|
|
55
|
+
return job;
|
|
56
|
+
info(ctx, `Type a number from 1 to ${jobs.length}.`);
|
|
57
|
+
}
|
|
58
|
+
throw new CliError("No job chosen. Nothing was changed.");
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Turn what the user typed into a saved job, and remember it as `last`. `usage` is shown when
|
|
62
|
+
* there is no reference and no terminal to ask in.
|
|
63
|
+
*/
|
|
64
|
+
export async function resolveJobRef(ctx, raw, usage) {
|
|
65
|
+
let job;
|
|
66
|
+
if (raw === undefined || raw.trim() === "") {
|
|
67
|
+
job = await pickInteractively(ctx, usage);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
const ref = parseJobRef(raw);
|
|
71
|
+
if (ref.kind === "number")
|
|
72
|
+
job = await byNumber(ref.n);
|
|
73
|
+
else if (ref.kind === "last") {
|
|
74
|
+
const last = await loadLastJob();
|
|
75
|
+
if (!last)
|
|
76
|
+
throw new CliError("No recent job in this terminal yet. Use a number from ca jobs instead.");
|
|
77
|
+
job = last;
|
|
78
|
+
}
|
|
79
|
+
else
|
|
80
|
+
job = { id: ref.id, title: null, company: null };
|
|
81
|
+
}
|
|
82
|
+
if (job.title || job.company)
|
|
83
|
+
await rememberJob(job);
|
|
84
|
+
else {
|
|
85
|
+
// A bare id: keep whatever we already know about it rather than forgetting the name.
|
|
86
|
+
const last = await loadLastJob();
|
|
87
|
+
await rememberJob(last?.id === job.id ? last : job);
|
|
88
|
+
}
|
|
89
|
+
return job;
|
|
90
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How far a journey has got through the stages you chose. Pure, so it is unit-tested.
|
|
3
|
+
*
|
|
4
|
+
* The server's journey `status` says "completed" after every stage (that is what the website
|
|
5
|
+
* reads), so the CLI counts your chosen stages instead of showing that word.
|
|
6
|
+
*/
|
|
7
|
+
const STAGE_LABELS = {
|
|
8
|
+
gap_analysis: "Gap Analysis",
|
|
9
|
+
impact_optimization_car: "Impact Optimization",
|
|
10
|
+
ats_compliance: "ATS Compliance",
|
|
11
|
+
semantic_engineering: "Semantic Engineering",
|
|
12
|
+
human_touch: "Human Touch",
|
|
13
|
+
cover_letter: "Cover Letter",
|
|
14
|
+
};
|
|
15
|
+
export function stageLabel(key) {
|
|
16
|
+
return STAGE_LABELS[key] ?? key.replace(/_/g, " ");
|
|
17
|
+
}
|
|
18
|
+
const finished = (status) => status === "completed" || status === "skipped";
|
|
19
|
+
/** `chosen` is null when this terminal doesn't know the choice (e.g. it was made in another app). */
|
|
20
|
+
export function journeyProgress(chosen, stages) {
|
|
21
|
+
const statusOf = (key) => stages.find((s) => s.stage === key)?.status;
|
|
22
|
+
if (!chosen?.length) {
|
|
23
|
+
return { done: stages.filter((s) => s.status === "completed").length, total: null, next: null };
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
done: chosen.filter((k) => statusOf(k) === "completed").length,
|
|
27
|
+
total: chosen.length,
|
|
28
|
+
next: chosen.find((k) => !finished(statusOf(k))) ?? null,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** Journeys started outside the website have no initial score; the first stage's "before" is it. */
|
|
32
|
+
export function startingScore(initial, stages) {
|
|
33
|
+
if (initial != null)
|
|
34
|
+
return initial;
|
|
35
|
+
const first = [...stages].sort((a, b) => a.order - b.order)[0];
|
|
36
|
+
return first?.score_before ?? null;
|
|
37
|
+
}
|
|
38
|
+
/** The server's final score, or else the latest stage's "after" score. */
|
|
39
|
+
export function latestScore(final, stages) {
|
|
40
|
+
if (final != null)
|
|
41
|
+
return final;
|
|
42
|
+
const scored = [...stages].sort((a, b) => b.order - a.order).find((s) => s.score_after != null);
|
|
43
|
+
return scored?.score_after ?? null;
|
|
44
|
+
}
|
package/dist/lint.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ca lint`: quick offline checks on a CV's text. No account, no network (design decision 8: this is
|
|
3
|
+
* what robots and CI get). A failed check makes the command exit 1; `--strict` counts warnings too.
|
|
4
|
+
*/
|
|
5
|
+
export const LENGTH_LIMITS = { failBelow: 200, warnBelow: 350, warnAbove: 1100, failAbove: 1500 };
|
|
6
|
+
export const GAP_MONTHS = { warn: 6, fail: 12 };
|
|
7
|
+
const BULLET_RE = /^\s*(?:[-*•▪◦·‣–]|\d{1,2}[.)])\s+(.+)$/;
|
|
8
|
+
/** A bullet "has a number" if it has a digit or a written-out quantity word. */
|
|
9
|
+
const NUMBER_RE = /\d|\b(?:one|two|three|four|five|six|seven|eight|nine|ten|twelve|twenty|fifty|hundred|thousand|million|billion|half|double[ds]?|tripled?)\b/i;
|
|
10
|
+
export function countWords(text) {
|
|
11
|
+
return (text.match(/[\p{L}\p{N}][\p{L}\p{N}'’&.-]*/gu) ?? []).length;
|
|
12
|
+
}
|
|
13
|
+
export function findBullets(text) {
|
|
14
|
+
const out = [];
|
|
15
|
+
for (const line of text.split(/\n/)) {
|
|
16
|
+
const m = BULLET_RE.exec(line);
|
|
17
|
+
// Ignore list items that are only a word or two (skills lists, contact lines).
|
|
18
|
+
if (m?.[1] && countWords(m[1]) >= 5)
|
|
19
|
+
out.push(m[1].trim());
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
const MONTHS = {
|
|
24
|
+
jan: 0, feb: 1, mar: 2, apr: 3, may: 4, jun: 5, jul: 6, aug: 7, sep: 8, sept: 8, oct: 9, nov: 10, dec: 11,
|
|
25
|
+
};
|
|
26
|
+
const MONTH_WORD = "(?:jan(?:uary)?|feb(?:ruary)?|mar(?:ch)?|apr(?:il)?|may|june?|july?|aug(?:ust)?|sep(?:t(?:ember)?)?|oct(?:ober)?|nov(?:ember)?|dec(?:ember)?)\\.?";
|
|
27
|
+
const POINT = `(?:${MONTH_WORD}\\s+\\d{4}|\\d{1,2}[/.]\\d{4}|\\d{4})`;
|
|
28
|
+
const END = `(?:${POINT}|present|current|now|today|date)`;
|
|
29
|
+
const RANGE_RE = new RegExp(`(${POINT})\\s*(?:-|–|—|to|until)\\s*(${END})`, "gi");
|
|
30
|
+
/** Months since year 0, from "Mar 2021", "03/2021", "2021" (start: Jan, end: Dec) or "Present". */
|
|
31
|
+
export function parsePoint(raw, isEnd, now) {
|
|
32
|
+
const s = raw.trim().toLowerCase().replace(/\.$/, "");
|
|
33
|
+
if (/^(present|current|now|today|date)$/.test(s))
|
|
34
|
+
return now.getUTCFullYear() * 12 + now.getUTCMonth();
|
|
35
|
+
let m = /^([a-z]+)\.?\s+(\d{4})$/.exec(s);
|
|
36
|
+
if (m) {
|
|
37
|
+
const month = MONTHS[m[1].slice(0, m[1].startsWith("sept") ? 4 : 3)];
|
|
38
|
+
return month == null ? null : Number(m[2]) * 12 + month;
|
|
39
|
+
}
|
|
40
|
+
m = /^(\d{1,2})[/.](\d{4})$/.exec(s);
|
|
41
|
+
if (m) {
|
|
42
|
+
const month = Number(m[1]) - 1;
|
|
43
|
+
return month < 0 || month > 11 ? null : Number(m[2]) * 12 + month;
|
|
44
|
+
}
|
|
45
|
+
m = /^(\d{4})$/.exec(s);
|
|
46
|
+
if (m)
|
|
47
|
+
return Number(m[1]) * 12 + (isEnd ? 11 : 0);
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
export function findDateRanges(text, now = new Date()) {
|
|
51
|
+
const out = [];
|
|
52
|
+
for (const m of text.matchAll(RANGE_RE)) {
|
|
53
|
+
const start = parsePoint(m[1], false, now);
|
|
54
|
+
const end = parsePoint(m[2], true, now);
|
|
55
|
+
if (start == null || end == null || end < start)
|
|
56
|
+
continue;
|
|
57
|
+
const year = Math.floor(start / 12);
|
|
58
|
+
if (year < 1950 || year > now.getUTCFullYear() + 1)
|
|
59
|
+
continue;
|
|
60
|
+
out.push({ start, end, label: m[0].replace(/\s+/g, " ").trim() });
|
|
61
|
+
}
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
function monthLabel(m) {
|
|
65
|
+
const names = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
66
|
+
return `${names[m % 12]} ${Math.floor(m / 12)}`;
|
|
67
|
+
}
|
|
68
|
+
/** Gaps between the dated periods (overlaps merged), longest first. */
|
|
69
|
+
export function findGaps(ranges) {
|
|
70
|
+
const sorted = [...ranges].sort((a, b) => a.start - b.start);
|
|
71
|
+
const gaps = [];
|
|
72
|
+
let coveredTo = null;
|
|
73
|
+
for (const r of sorted) {
|
|
74
|
+
if (coveredTo != null && r.start > coveredTo + 1) {
|
|
75
|
+
gaps.push({ from: coveredTo + 1, to: r.start - 1, months: r.start - coveredTo - 1 });
|
|
76
|
+
}
|
|
77
|
+
coveredTo = coveredTo == null ? r.end : Math.max(coveredTo, r.end);
|
|
78
|
+
}
|
|
79
|
+
return gaps.sort((a, b) => b.months - a.months);
|
|
80
|
+
}
|
|
81
|
+
export function lintCv(text, opts = {}) {
|
|
82
|
+
const now = opts.now ?? new Date();
|
|
83
|
+
const checks = [];
|
|
84
|
+
// ——— length ———
|
|
85
|
+
const words = countWords(text);
|
|
86
|
+
const L = LENGTH_LIMITS;
|
|
87
|
+
checks.push(words < L.failBelow
|
|
88
|
+
? { id: "length", status: "fail", message: `Only ${words} words: too short to show your experience.`, details: [] }
|
|
89
|
+
: words < L.warnBelow
|
|
90
|
+
? { id: "length", status: "warn", message: `${words} words: on the short side.`, details: [] }
|
|
91
|
+
: words > L.failAbove
|
|
92
|
+
? { id: "length", status: "fail", message: `${words} words: likely over two pages. Aim for under ${L.warnAbove}.`, details: [] }
|
|
93
|
+
: words > L.warnAbove
|
|
94
|
+
? { id: "length", status: "warn", message: `${words} words: on the long side. Aim for under ${L.warnAbove}.`, details: [] }
|
|
95
|
+
: { id: "length", status: "pass", message: `${words} words.`, details: [] });
|
|
96
|
+
// ——— numbers in bullets ———
|
|
97
|
+
const bullets = findBullets(text);
|
|
98
|
+
const withNumbers = bullets.filter((b) => NUMBER_RE.test(b));
|
|
99
|
+
const without = bullets.filter((b) => !NUMBER_RE.test(b));
|
|
100
|
+
if (bullets.length === 0) {
|
|
101
|
+
checks.push({
|
|
102
|
+
id: "bullet_numbers",
|
|
103
|
+
status: "warn",
|
|
104
|
+
message: "No bullet points found. Recruiters scan bullets; list achievements as bullets.",
|
|
105
|
+
details: [],
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
const share = withNumbers.length / bullets.length;
|
|
110
|
+
const pct = Math.round(share * 100);
|
|
111
|
+
const details = without.slice(0, 5).map((b) => (b.length > 90 ? `${b.slice(0, 87)}…` : b));
|
|
112
|
+
checks.push({
|
|
113
|
+
id: "bullet_numbers",
|
|
114
|
+
status: share < 0.3 ? "fail" : share < 0.5 ? "warn" : "pass",
|
|
115
|
+
message: `${withNumbers.length} of ${bullets.length} bullets (${pct}%) include a number.${share < 0.5 ? " Add results: %, £, time saved, team size." : ""}`,
|
|
116
|
+
details: share < 0.5 ? details : [],
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
// ——— gaps ———
|
|
120
|
+
const ranges = findDateRanges(text, now);
|
|
121
|
+
if (ranges.length < 2) {
|
|
122
|
+
checks.push({
|
|
123
|
+
id: "gaps",
|
|
124
|
+
status: ranges.length === 0 ? "warn" : "pass",
|
|
125
|
+
message: ranges.length === 0
|
|
126
|
+
? "No date ranges found (e.g. \"Mar 2021 – Present\"), so gaps could not be checked."
|
|
127
|
+
: "Only one dated role; no gaps to check.",
|
|
128
|
+
details: [],
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
const gaps = findGaps(ranges).filter((g) => g.months >= GAP_MONTHS.warn);
|
|
133
|
+
const longest = gaps[0]?.months ?? 0;
|
|
134
|
+
checks.push({
|
|
135
|
+
id: "gaps",
|
|
136
|
+
status: longest >= GAP_MONTHS.fail ? "fail" : longest >= GAP_MONTHS.warn ? "warn" : "pass",
|
|
137
|
+
message: gaps.length === 0
|
|
138
|
+
? "No gaps of 6 months or more between dated roles."
|
|
139
|
+
: `${gaps.length} gap${gaps.length === 1 ? "" : "s"} of 6+ months. Explain them in a line (study, caring, travel, freelance).`,
|
|
140
|
+
details: gaps.map((g) => `${monthLabel(g.from)} – ${monthLabel(g.to)} (${g.months} months)`),
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
const failing = checks.some((c) => c.status === "fail" || (opts.strict && c.status === "warn"));
|
|
144
|
+
return {
|
|
145
|
+
passed: !failing,
|
|
146
|
+
stats: { words, bullets: bullets.length, bullets_with_numbers: withNumbers.length, roles_with_dates: ranges.length },
|
|
147
|
+
checks,
|
|
148
|
+
};
|
|
149
|
+
}
|