kordexa 0.4.3 → 0.4.4
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/package.json +1 -1
- package/src/cli.js +40 -16
- package/src/terminal-view.js +308 -0
- package/tests/node/terminal-view.test.js +106 -0
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -12,6 +12,7 @@ import { appendProgress, createWeeklySummary, planStatus, reviewProgress } from
|
|
|
12
12
|
import { SetupCancelled, askEmailDelivery, collectOnboarding, createTerminalIO } from "./prompts.js";
|
|
13
13
|
import { appendResearchIndex, createResearchDigest, enrichDigestLinks, saveResearchDigest } from "./research.js";
|
|
14
14
|
import { parsePlanDays } from "./setup-answers.js";
|
|
15
|
+
import { renderView, terminalSupportsColor } from "./terminal-view.js";
|
|
15
16
|
import { workflowStatus, writeGithubWorkflow } from "./workflow.js";
|
|
16
17
|
|
|
17
18
|
const COMMANDS = ["plan", "status", "harness", "courses", "research", "links", "send-today", "log-progress", "weekly-summary", "recommend-next", "progress-card", "terminal-card", "setup-email", "setup-secrets", "doctor", "help"];
|
|
@@ -37,7 +38,11 @@ const SETUP_VALUE_FLAGS = {
|
|
|
37
38
|
};
|
|
38
39
|
const SETUP_SWITCHES = ["--yes", "--non-interactive", "--offline", "--restart", "--allow-home", "--json"];
|
|
39
40
|
|
|
41
|
+
// People at a terminal get readable results. Agents, scripts and --json get JSON.
|
|
42
|
+
let jsonOutput = true;
|
|
43
|
+
|
|
40
44
|
export async function main(argv = []) {
|
|
45
|
+
jsonOutput = argv.includes("--json") || !process.stdout.isTTY;
|
|
41
46
|
const command = normalizeCommand(argv[0]);
|
|
42
47
|
if (command === "send-today") return sendToday(argv.slice(1));
|
|
43
48
|
if (command === "plan") return regeneratePlan(argv.slice(1));
|
|
@@ -168,7 +173,7 @@ async function init(argv) {
|
|
|
168
173
|
appendResearchIndex(config, digestPath, digest);
|
|
169
174
|
const workflowPath = writeGithubWorkflow(config);
|
|
170
175
|
const { warnings } = workflowStatus();
|
|
171
|
-
if (!nonInteractive && !argv.includes("--json")) {
|
|
176
|
+
if ((!nonInteractive || !jsonOutput) && !argv.includes("--json")) {
|
|
172
177
|
printSetupComplete(config, plan, answers.emailConnected, warnings);
|
|
173
178
|
return;
|
|
174
179
|
}
|
|
@@ -272,7 +277,7 @@ function regeneratePlan(argv) {
|
|
|
272
277
|
const plan = generate30DayPlan(config.learner);
|
|
273
278
|
writeDataJson(config, "30-day-plan.json", plan);
|
|
274
279
|
saveConfig(config);
|
|
275
|
-
|
|
280
|
+
present("plan", { status: "saved", plan: "data/30-day-plan.json", days: plan.days.length }, { plan });
|
|
276
281
|
}
|
|
277
282
|
|
|
278
283
|
async function sendToday(argv) {
|
|
@@ -289,7 +294,7 @@ async function sendToday(argv) {
|
|
|
289
294
|
recommendation: plan.nextSkillRecommendation
|
|
290
295
|
};
|
|
291
296
|
writeDataJson(config, "latest-email.json", { generatedAt: new Date().toISOString(), ...result });
|
|
292
|
-
|
|
297
|
+
present("skipped", result);
|
|
293
298
|
return;
|
|
294
299
|
}
|
|
295
300
|
const progressReview = reviewProgress(config, plan);
|
|
@@ -314,7 +319,17 @@ async function sendToday(argv) {
|
|
|
314
319
|
? await sendWithResend({ resend, message, idempotencyKey: dailyEmailKey(message.to, config.schedule?.startDate, day) })
|
|
315
320
|
: await sendMail({ smtp, message, dryRun });
|
|
316
321
|
writeDataJson(config, "latest-email.json", { generatedAt: new Date().toISOString(), researchDigest: digestPath, ...result });
|
|
317
|
-
|
|
322
|
+
const previewPath = path.join(config.dataDir || "data", "email-preview.html");
|
|
323
|
+
if (dryRun) fs.writeFileSync(path.join(process.cwd(), previewPath), message.html, "utf8");
|
|
324
|
+
present("email", result, {
|
|
325
|
+
day: plan.days.find((entry) => entry.day === day) || plan.days[0],
|
|
326
|
+
digest,
|
|
327
|
+
review: progressReview,
|
|
328
|
+
totalDays: plan.days.length,
|
|
329
|
+
completedDays: progressReview.completedDays,
|
|
330
|
+
previewPath,
|
|
331
|
+
emailConnected: Boolean(resend || (smtp.host && smtp.user && smtp.pass))
|
|
332
|
+
});
|
|
318
333
|
}
|
|
319
334
|
|
|
320
335
|
export function resolveScheduledDay(config, plan, now = new Date()) {
|
|
@@ -328,7 +343,7 @@ export function resolveScheduledDay(config, plan, now = new Date()) {
|
|
|
328
343
|
|
|
329
344
|
function showStatus() {
|
|
330
345
|
const { config, plan } = loadRuntime();
|
|
331
|
-
|
|
346
|
+
present("status", planStatus(config, plan));
|
|
332
347
|
}
|
|
333
348
|
|
|
334
349
|
async function research(argv) {
|
|
@@ -339,7 +354,7 @@ async function research(argv) {
|
|
|
339
354
|
await enrichDigestLinks(digest, { offline: argv.includes("--offline") });
|
|
340
355
|
const digestPath = saveResearchDigest(config, digest);
|
|
341
356
|
appendResearchIndex(config, digestPath, digest);
|
|
342
|
-
|
|
357
|
+
present("research", { status: "saved", path: digestPath, digest });
|
|
343
358
|
}
|
|
344
359
|
|
|
345
360
|
async function links(argv) {
|
|
@@ -360,7 +375,7 @@ async function links(argv) {
|
|
|
360
375
|
repos: digest.repos || []
|
|
361
376
|
};
|
|
362
377
|
writeDataJson(config, "links.json", payload);
|
|
363
|
-
|
|
378
|
+
present("links", { status: "resolved", path: "data/links.json", ...payload });
|
|
364
379
|
}
|
|
365
380
|
|
|
366
381
|
function harness(argv) {
|
|
@@ -368,14 +383,14 @@ function harness(argv) {
|
|
|
368
383
|
const mode = valueAfter(argv, "--mode") || "daily";
|
|
369
384
|
const payload = createHarness(config, plan, mode);
|
|
370
385
|
const paths = saveHarness(config, payload);
|
|
371
|
-
|
|
386
|
+
present("harness", { status: "saved", ...paths, harness: payload });
|
|
372
387
|
}
|
|
373
388
|
|
|
374
389
|
function courses() {
|
|
375
390
|
const { config, plan } = loadRuntime();
|
|
376
391
|
const pack = createCoursePack(config, plan);
|
|
377
392
|
const paths = saveCoursePack(config, pack);
|
|
378
|
-
|
|
393
|
+
present("courses", { status: "saved", ...paths, learningSources: pack });
|
|
379
394
|
}
|
|
380
395
|
|
|
381
396
|
function logProgress(argv) {
|
|
@@ -400,7 +415,7 @@ function logProgress(argv) {
|
|
|
400
415
|
const review = reviewProgress(config, plan);
|
|
401
416
|
const cardPaths = saveProgressionCard(config, buildProgressionCard(config, plan));
|
|
402
417
|
writeDataJson(config, "latest-review.json", review);
|
|
403
|
-
|
|
418
|
+
present("logged", { status: "logged", entry, review, progressionCard: cardPaths.markdownPath });
|
|
404
419
|
}
|
|
405
420
|
|
|
406
421
|
function weeklySummary(argv) {
|
|
@@ -409,7 +424,7 @@ function weeklySummary(argv) {
|
|
|
409
424
|
const week = assertWholeNumber(valueAfter(argv, "--week") ?? "1", "--week", 1, totalWeeks);
|
|
410
425
|
const summary = createWeeklySummary(config, plan, week);
|
|
411
426
|
writeDataJson(config, `weekly-summary-${week}.json`, summary);
|
|
412
|
-
|
|
427
|
+
present("weekly", summary);
|
|
413
428
|
}
|
|
414
429
|
|
|
415
430
|
function recommendNext() {
|
|
@@ -431,21 +446,21 @@ function recommendNext() {
|
|
|
431
446
|
...recommendation
|
|
432
447
|
};
|
|
433
448
|
writeDataJson(config, "next-skill-recommendation.json", payload);
|
|
434
|
-
|
|
449
|
+
present("recommendation", payload);
|
|
435
450
|
}
|
|
436
451
|
|
|
437
452
|
function progressCard() {
|
|
438
453
|
const { config, plan } = loadRuntime();
|
|
439
454
|
const card = buildProgressionCard(config, plan);
|
|
440
455
|
const paths = saveProgressionCard(config, card);
|
|
441
|
-
|
|
456
|
+
present("card", { status: "saved", ...paths, card });
|
|
442
457
|
}
|
|
443
458
|
|
|
444
459
|
function terminalCard() {
|
|
445
460
|
const { config, plan } = loadRuntime();
|
|
446
461
|
const card = buildProgressionCard(config, plan);
|
|
447
462
|
const paths = saveProgressionCard(config, card);
|
|
448
|
-
|
|
463
|
+
present("terminalCard", {
|
|
449
464
|
status: "saved",
|
|
450
465
|
terminalSvgPath: paths.terminalSvgPath,
|
|
451
466
|
terminalLines: card.terminalLines
|
|
@@ -467,7 +482,7 @@ function setupSecrets() {
|
|
|
467
482
|
note: "Run these after gh auth login. Secrets are not committed.",
|
|
468
483
|
commands
|
|
469
484
|
};
|
|
470
|
-
|
|
485
|
+
present("secrets", payload);
|
|
471
486
|
return payload;
|
|
472
487
|
}
|
|
473
488
|
|
|
@@ -513,7 +528,7 @@ function doctor() {
|
|
|
513
528
|
...(scheduled.warnings.length ? { warnings: scheduled.warnings } : {}),
|
|
514
529
|
...(configValidation.errors.length > 0 && configExists ? { configErrors: configValidation.errors } : {})
|
|
515
530
|
};
|
|
516
|
-
|
|
531
|
+
present("doctor", result);
|
|
517
532
|
return result;
|
|
518
533
|
}
|
|
519
534
|
|
|
@@ -541,6 +556,7 @@ Commands:
|
|
|
541
556
|
npx kordexa setup-secrets
|
|
542
557
|
npx kordexa doctor
|
|
543
558
|
|
|
559
|
+
Add --json to any command to get machine-readable output.
|
|
544
560
|
Note: /eduorchestrate stays available inside agents as a legacy alias for /kordexa.
|
|
545
561
|
`);
|
|
546
562
|
}
|
|
@@ -632,6 +648,14 @@ function writeDataJson(config, fileName, payload) {
|
|
|
632
648
|
writeJson(path.join(resolveDataDir(config), fileName), payload);
|
|
633
649
|
}
|
|
634
650
|
|
|
651
|
+
function present(view, payload, context) {
|
|
652
|
+
if (jsonOutput) {
|
|
653
|
+
outputJson(payload);
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
656
|
+
console.log(`\n${renderView(view, payload, context, { color: terminalSupportsColor(), width: process.stdout.columns })}\n`);
|
|
657
|
+
}
|
|
658
|
+
|
|
635
659
|
function outputJson(payload) {
|
|
636
660
|
console.log(JSON.stringify(payload, null, 2));
|
|
637
661
|
}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { cleanText } from "./setup-answers.js";
|
|
2
|
+
|
|
3
|
+
// Readable command results for people. Agents and scripts keep receiving JSON.
|
|
4
|
+
|
|
5
|
+
const OPEN_COMMAND = { darwin: "open", win32: "start" }[process.platform] || "xdg-open";
|
|
6
|
+
const STYLES = { bold: 1, dim: 2, accent: 36, good: 32, warn: 33 };
|
|
7
|
+
const MOMENTUM = { strong: "Strong", steady: "Steady", "needs-support": "Needs support", blocked: "Blocked", "not-started": "Not started" };
|
|
8
|
+
const DOCTOR_CHECKS = {
|
|
9
|
+
config: "Learner settings",
|
|
10
|
+
agentsMd: "Codex and generic agent instructions",
|
|
11
|
+
geminiMd: "Gemini instructions",
|
|
12
|
+
claudeSkill: "Claude Code skill",
|
|
13
|
+
mcpManifest: "MCP connection",
|
|
14
|
+
workflow: "Daily email schedule",
|
|
15
|
+
localEnv: "Local settings file",
|
|
16
|
+
localEmail: "Email connection"
|
|
17
|
+
};
|
|
18
|
+
const DOCTOR_STATUS = {
|
|
19
|
+
ready: "Everything is ready.",
|
|
20
|
+
"needs-setup": "Setup isn't finished yet.",
|
|
21
|
+
"needs-upgrade": "Your project needs a small update.",
|
|
22
|
+
"needs-email-setup": "Kordexa is ready, but email isn't connected yet."
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function createPainter({ color, width }) {
|
|
26
|
+
const paint = (style, text) => (color ? `\u001b[${STYLES[style]}m${text}\u001b[0m` : text);
|
|
27
|
+
const pageWidth = Math.max(40, Math.min(width || 80, 88));
|
|
28
|
+
|
|
29
|
+
const wrap = (value, indent = 2) => {
|
|
30
|
+
const limit = pageWidth - indent;
|
|
31
|
+
const lines = [];
|
|
32
|
+
let line = "";
|
|
33
|
+
for (const word of cleanText(value).split(" ")) {
|
|
34
|
+
if (line && `${line} ${word}`.length > limit) {
|
|
35
|
+
lines.push(line);
|
|
36
|
+
line = word;
|
|
37
|
+
} else {
|
|
38
|
+
line = line ? `${line} ${word}` : word;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (line) lines.push(line);
|
|
42
|
+
return lines.map((text) => `${" ".repeat(indent)}${text}`);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const rows = (entries) => {
|
|
46
|
+
const visible = entries.filter(([, value]) => value !== undefined && value !== null && value !== "");
|
|
47
|
+
const labelWidth = Math.max(...visible.map(([label]) => label.length), 0) + 2;
|
|
48
|
+
return visible.flatMap(([label, value]) => {
|
|
49
|
+
const [first, ...rest] = wrap(value, labelWidth + 2).map((line) => line.trimStart());
|
|
50
|
+
return [
|
|
51
|
+
` ${paint("dim", label.padEnd(labelWidth))}${first}`,
|
|
52
|
+
...rest.map((line) => `${" ".repeat(labelWidth + 2)}${line}`)
|
|
53
|
+
];
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
paint,
|
|
59
|
+
wrap,
|
|
60
|
+
rows,
|
|
61
|
+
title: (text) => [paint("bold", cleanText(text))],
|
|
62
|
+
section: (text) => ["", paint("accent", paint("bold", text))],
|
|
63
|
+
rule: () => [paint("dim", "─".repeat(Math.min(pageWidth, 56)))],
|
|
64
|
+
success: (text) => [`${paint("good", "✓")} ${paint("bold", cleanText(text))}`],
|
|
65
|
+
notice: (text) => [`${paint("warn", "!")} ${paint("bold", cleanText(text))}`],
|
|
66
|
+
bullets: (items) => items.flatMap((item) => {
|
|
67
|
+
const [first, ...rest] = wrap(item, 4);
|
|
68
|
+
return [` • ${first.trimStart()}`, ...rest];
|
|
69
|
+
}),
|
|
70
|
+
command: (text, purpose) => [` ${paint("accent", text)}${purpose ? ` ${paint("dim", purpose)}` : ""}`],
|
|
71
|
+
resource: (label, item) => {
|
|
72
|
+
if (!item?.url) return [];
|
|
73
|
+
const name = cleanText(item.title) || item.url;
|
|
74
|
+
return [` ${paint("dim", label.padEnd(7))}${name}`, ` ${" ".repeat(7)}${paint("accent", cleanText(item.url))}`];
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function momentumLabel(value) {
|
|
80
|
+
return MOMENTUM[value] || value;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const VIEWS = {
|
|
84
|
+
email(p, result, { day, digest, review, totalDays, completedDays, previewPath, emailConnected }) {
|
|
85
|
+
const message = result.message || result;
|
|
86
|
+
const time = day.timeBox;
|
|
87
|
+
return [
|
|
88
|
+
...(result.dryRun ? p.notice("Preview only. No email was sent.") : p.success(`Email sent to ${result.to}`)),
|
|
89
|
+
"",
|
|
90
|
+
...p.title(message.subject),
|
|
91
|
+
...p.rows([["To", message.to]]),
|
|
92
|
+
...p.rule(),
|
|
93
|
+
...p.section("Today's task"),
|
|
94
|
+
...p.wrap(day.setupOrBuildTask),
|
|
95
|
+
"",
|
|
96
|
+
...p.rows([
|
|
97
|
+
["Skill", day.primarySkill],
|
|
98
|
+
["Concepts", day.concepts.join(", ")],
|
|
99
|
+
["Time", `Learn ${time.learnMinutes}m · Build ${time.buildMinutes}m · Review ${time.reviewMinutes}m`],
|
|
100
|
+
["Level", day.difficulty.replaceAll("-", " ")]
|
|
101
|
+
]),
|
|
102
|
+
...p.section("Open these first"),
|
|
103
|
+
...p.resource("Watch", digest.topVideo),
|
|
104
|
+
...p.resource("Build", digest.topRepo),
|
|
105
|
+
...p.resource("Read", digest.topDoc),
|
|
106
|
+
...p.section("Before you finish"),
|
|
107
|
+
...p.bullets(day.reviewQuestions),
|
|
108
|
+
...p.section("Your progress"),
|
|
109
|
+
...p.rows([
|
|
110
|
+
["Completed", `${completedDays} of ${totalDays} days`],
|
|
111
|
+
["Momentum", momentumLabel(review.momentum)]
|
|
112
|
+
]),
|
|
113
|
+
...(result.dryRun ? [
|
|
114
|
+
...p.section("Next"),
|
|
115
|
+
...p.command(`${OPEN_COMMAND} ${previewPath}`, "See the full email"),
|
|
116
|
+
...p.command(emailConnected ? "npx kordexa send-today" : "npx kordexa setup-email", emailConnected ? "Send it" : "Connect your email")
|
|
117
|
+
] : [])
|
|
118
|
+
];
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
skipped(p, result) {
|
|
122
|
+
return [
|
|
123
|
+
...p.success("Your plan is complete, so no email was sent."),
|
|
124
|
+
...p.rows([["Next skill", result.recommendation?.recommendedNextSkill]]),
|
|
125
|
+
...p.section("Next"),
|
|
126
|
+
...p.command("npx kordexa recommend-next", "See what to learn next")
|
|
127
|
+
];
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
plan(p, result, { plan }) {
|
|
131
|
+
return [
|
|
132
|
+
...p.success(`Your ${result.days}-day plan is ready`),
|
|
133
|
+
"",
|
|
134
|
+
...p.rows([
|
|
135
|
+
["Goal", plan.learner.targetRole],
|
|
136
|
+
["First skill", plan.primarySkill],
|
|
137
|
+
["Day 1", plan.days[0].title]
|
|
138
|
+
]),
|
|
139
|
+
...p.section("Plan phases"),
|
|
140
|
+
...p.rows(plan.phases.map((phase) => [`Days ${phase.days}`, phase.name])),
|
|
141
|
+
...p.section("Next"),
|
|
142
|
+
...p.command("npx kordexa status", "See today's task")
|
|
143
|
+
];
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
status(p, status) {
|
|
147
|
+
return [
|
|
148
|
+
...p.title(`${status.learner}'s learning plan`),
|
|
149
|
+
...p.rule(),
|
|
150
|
+
...p.rows([
|
|
151
|
+
["Goal", status.targetRole],
|
|
152
|
+
["First skill", status.primarySkill],
|
|
153
|
+
["Progress", `${status.completedDays} of ${status.daysPlanned} days`],
|
|
154
|
+
["Current day", `Day ${status.activeDay}`],
|
|
155
|
+
["Momentum", momentumLabel(status.momentum)],
|
|
156
|
+
["Daily email", status.emailTime]
|
|
157
|
+
]),
|
|
158
|
+
...p.section("Next task"),
|
|
159
|
+
...p.wrap(status.nextAction),
|
|
160
|
+
...(status.latestEvidence ? [...p.section("Latest proof"), ...p.wrap(status.latestEvidence)] : []),
|
|
161
|
+
...(/^Resolve blocker/.test(status.risk) ? [...p.section("Needs attention"), ...p.wrap(status.risk)] : [])
|
|
162
|
+
];
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
research(p, { path, digest }) {
|
|
166
|
+
return [
|
|
167
|
+
...p.success(`Research is ready for Day ${digest.day}`),
|
|
168
|
+
"",
|
|
169
|
+
...p.title(digest.topic),
|
|
170
|
+
...p.section("Start here"),
|
|
171
|
+
...p.resource("Watch", digest.topVideo),
|
|
172
|
+
...p.resource("Build", digest.topRepo),
|
|
173
|
+
...p.resource("Read", digest.topDoc),
|
|
174
|
+
"",
|
|
175
|
+
...p.rows([["Saved to", path]])
|
|
176
|
+
];
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
links(p, result) {
|
|
180
|
+
return [
|
|
181
|
+
...p.success(`Links are ready for Day ${result.day}`),
|
|
182
|
+
"",
|
|
183
|
+
...p.title(result.topic),
|
|
184
|
+
...p.section("Start here"),
|
|
185
|
+
...p.resource("Watch", result.topVideo),
|
|
186
|
+
...p.resource("Build", result.topRepo),
|
|
187
|
+
...p.resource("Read", result.topDoc),
|
|
188
|
+
"",
|
|
189
|
+
...p.rows([["Saved to", result.path]])
|
|
190
|
+
];
|
|
191
|
+
},
|
|
192
|
+
|
|
193
|
+
harness(p, { jsonPath, harness }) {
|
|
194
|
+
return [
|
|
195
|
+
...p.success("Your AI agent instructions are ready"),
|
|
196
|
+
"",
|
|
197
|
+
...p.rows([
|
|
198
|
+
["Current day", `Day ${harness.activeDay.day}: ${harness.activeDay.title}`],
|
|
199
|
+
["Task", harness.activeDay.task],
|
|
200
|
+
["Saved to", jsonPath]
|
|
201
|
+
])
|
|
202
|
+
];
|
|
203
|
+
},
|
|
204
|
+
|
|
205
|
+
courses(p, { markdownPath, learningSources }) {
|
|
206
|
+
const list = (items) => items.flatMap((item) => [` ${cleanText(item.title)}`, ` ${p.paint("accent", cleanText(item.url))}`]);
|
|
207
|
+
return [
|
|
208
|
+
...p.success(`Learning sources are ready for ${learningSources.targetRole}`),
|
|
209
|
+
...p.section("Recommended courses"),
|
|
210
|
+
...list(learningSources.recommendedSources.slice(0, 5)),
|
|
211
|
+
...p.section("Stay updated"),
|
|
212
|
+
...list(learningSources.newsletters.slice(0, 3)),
|
|
213
|
+
"",
|
|
214
|
+
...p.rows([["Full list", markdownPath]])
|
|
215
|
+
];
|
|
216
|
+
},
|
|
217
|
+
|
|
218
|
+
logged(p, { entry, review }) {
|
|
219
|
+
return [
|
|
220
|
+
...p.success(`Day ${entry.day} is logged`),
|
|
221
|
+
"",
|
|
222
|
+
...p.rows([
|
|
223
|
+
["Completed", entry.completed],
|
|
224
|
+
["Proof", entry.evidence],
|
|
225
|
+
["Progress", `${review.completedDays} days completed`],
|
|
226
|
+
["Momentum", momentumLabel(review.momentum)]
|
|
227
|
+
]),
|
|
228
|
+
...p.section(`Next: Day ${review.activeDay}`),
|
|
229
|
+
...p.wrap(review.nextAction)
|
|
230
|
+
];
|
|
231
|
+
},
|
|
232
|
+
|
|
233
|
+
weekly(p, summary) {
|
|
234
|
+
return [
|
|
235
|
+
...p.title(`Week ${summary.week} summary`),
|
|
236
|
+
...p.rows([["Days", summary.range]]),
|
|
237
|
+
...p.rule(),
|
|
238
|
+
...p.wrap(summary.summary),
|
|
239
|
+
...(summary.completed.length ? [...p.section("Completed"), ...p.bullets(summary.completed.map((item) => `Day ${item.day}: ${item.completed}`))] : []),
|
|
240
|
+
...p.section("Next week's focus"),
|
|
241
|
+
...p.wrap(summary.nextWeekFocus)
|
|
242
|
+
];
|
|
243
|
+
},
|
|
244
|
+
|
|
245
|
+
recommendation(p, result) {
|
|
246
|
+
return [
|
|
247
|
+
...p.title("Your next skill"),
|
|
248
|
+
...p.rule(),
|
|
249
|
+
...p.wrap(result.recommendedNextSkill),
|
|
250
|
+
"",
|
|
251
|
+
...p.rows([
|
|
252
|
+
["Why", result.reason],
|
|
253
|
+
["Progress", `${result.completedDays} of ${result.requiredDays} days completed`]
|
|
254
|
+
]),
|
|
255
|
+
...(result.canAdvance ? [] : ["", ...p.wrap("Finish your current plan before moving to this skill.")])
|
|
256
|
+
];
|
|
257
|
+
},
|
|
258
|
+
|
|
259
|
+
card(p, { card, markdownPath, terminalSvgPath }) {
|
|
260
|
+
return [
|
|
261
|
+
...p.title(`${card.role} progress`),
|
|
262
|
+
...p.rule(),
|
|
263
|
+
...p.rows([
|
|
264
|
+
["First skill", card.skill],
|
|
265
|
+
["Progress", `${card.completedDays} of ${card.totalDays} days`],
|
|
266
|
+
["Current day", `Day ${card.activeDay}: ${card.activeTopic}`]
|
|
267
|
+
]),
|
|
268
|
+
...p.section("Your plan"),
|
|
269
|
+
...card.grid.map((row) => ` ${row}`),
|
|
270
|
+
"",
|
|
271
|
+
...p.wrap("# done > today . upcoming"),
|
|
272
|
+
"",
|
|
273
|
+
...p.rows([["Report", markdownPath], ["Image", terminalSvgPath]])
|
|
274
|
+
];
|
|
275
|
+
},
|
|
276
|
+
|
|
277
|
+
terminalCard(p, { terminalSvgPath }) {
|
|
278
|
+
return [...p.success("Your progress image is ready"), "", ...p.rows([["Saved to", terminalSvgPath]])];
|
|
279
|
+
},
|
|
280
|
+
|
|
281
|
+
secrets(p, { commands }) {
|
|
282
|
+
return [
|
|
283
|
+
...p.title("Add these secrets to GitHub"),
|
|
284
|
+
...p.wrap("Run each command from your project folder after signing in with GitHub CLI."),
|
|
285
|
+
"",
|
|
286
|
+
...commands.flatMap((command) => p.command(command))
|
|
287
|
+
];
|
|
288
|
+
},
|
|
289
|
+
|
|
290
|
+
doctor(p, { status, checks, nextSteps = [], warnings = [] }) {
|
|
291
|
+
return [
|
|
292
|
+
...(status === "ready" ? p.success(DOCTOR_STATUS[status]) : p.notice(DOCTOR_STATUS[status])),
|
|
293
|
+
"",
|
|
294
|
+
...Object.entries(DOCTOR_CHECKS).map(([key, label]) => ` ${checks[key] ? p.paint("good", "✓") : p.paint("warn", "•")} ${label}`),
|
|
295
|
+
...(nextSteps.length ? [...p.section("Next"), ...p.bullets(nextSteps)] : []),
|
|
296
|
+
...(warnings.length ? [...p.section("Warnings"), ...p.bullets(warnings)] : [])
|
|
297
|
+
];
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
export function renderView(kind, payload, context = {}, options = {}) {
|
|
302
|
+
const painter = createPainter({ color: Boolean(options.color), width: options.width });
|
|
303
|
+
return VIEWS[kind](painter, payload, context).join("\n");
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export function terminalSupportsColor(stream = process.stdout, env = process.env) {
|
|
307
|
+
return Boolean(stream.isTTY) && !env.NO_COLOR && env.TERM !== "dumb";
|
|
308
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import test from "node:test";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
import { generate30DayPlan } from "../../src/planner.js";
|
|
10
|
+
import { renderView, terminalSupportsColor } from "../../src/terminal-view.js";
|
|
11
|
+
|
|
12
|
+
const CLI = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../bin/kordexa.js");
|
|
13
|
+
const plan = generate30DayPlan({ targetRole: "Data Scientist", focusSkill: "pandas", planDays: 30 });
|
|
14
|
+
const review = { momentum: "not-started", completedDays: 0, activeDay: 1, nextAction: "Analyze a small CSV." };
|
|
15
|
+
const digest = {
|
|
16
|
+
day: 1,
|
|
17
|
+
topic: "pandas basics",
|
|
18
|
+
topVideo: { title: "pandas tutorial", url: "https://www.youtube.com/watch?v=abc12345678" },
|
|
19
|
+
topRepo: { title: "pandas-dev/pandas", url: "https://github.com/pandas-dev/pandas" },
|
|
20
|
+
topDoc: { title: "pandas docs", url: "https://pandas.pydata.org/docs/" }
|
|
21
|
+
};
|
|
22
|
+
const preview = {
|
|
23
|
+
dryRun: true,
|
|
24
|
+
message: { to: "asha@gmail.com", subject: "Kordexa Day 1: Setup", text: "plain", html: "<!doctype html><html></html>" }
|
|
25
|
+
};
|
|
26
|
+
const context = { day: plan.days[0], digest, review, totalDays: 30, completedDays: 0, previewPath: "data/email-preview.html", emailConnected: false };
|
|
27
|
+
|
|
28
|
+
test("email preview is readable and hides raw JSON and HTML", () => {
|
|
29
|
+
const output = renderView("email", preview, context);
|
|
30
|
+
assert.match(output, /Preview only\. No email was sent\./);
|
|
31
|
+
assert.match(output, /Kordexa Day 1: Setup/);
|
|
32
|
+
assert.match(output, /Today's task/);
|
|
33
|
+
assert.match(output, /Learn 35m · Build 45m · Review 15m/);
|
|
34
|
+
assert.match(output, /https:\/\/github\.com\/pandas-dev\/pandas/);
|
|
35
|
+
assert.match(output, /(open|start|xdg-open) data\/email-preview\.html/);
|
|
36
|
+
assert.match(output, /npx kordexa setup-email/);
|
|
37
|
+
assert.doesNotMatch(output, /<html|<!doctype|"dryRun"|\\n/);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("a sent email confirms delivery without preview steps", () => {
|
|
41
|
+
const output = renderView("email", { sent: true, to: "asha@gmail.com", subject: "Kordexa Day 1: Setup" }, { ...context, emailConnected: true });
|
|
42
|
+
assert.match(output, /Email sent to asha@gmail\.com/);
|
|
43
|
+
assert.doesNotMatch(output, /Preview only|email-preview/);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("every command has a readable view", () => {
|
|
47
|
+
const card = { role: "Data Scientist", skill: "pandas", completedDays: 1, totalDays: 30, activeDay: 2, activeTopic: "SQL", grid: ["01-07 # > . . . . ."] };
|
|
48
|
+
const views = {
|
|
49
|
+
skipped: [{ recommendation: { recommendedNextSkill: "model evaluation" } }],
|
|
50
|
+
plan: [{ days: 30 }, { plan }],
|
|
51
|
+
status: [{ learner: "Asha", targetRole: "Data Scientist", primarySkill: "pandas", completedDays: 1, daysPlanned: 30, activeDay: 2, momentum: "strong", emailTime: "20:00 UTC", nextAction: "Build", latestEvidence: "repo", risk: "No active blocker logged." }],
|
|
52
|
+
research: [{ path: "data/r.json", digest }],
|
|
53
|
+
links: [{ path: "data/links.json", day: 1, topic: "pandas", ...digest }],
|
|
54
|
+
harness: [{ jsonPath: "data/h.json", harness: { activeDay: { day: 1, title: "Setup", task: "Build" } } }],
|
|
55
|
+
courses: [{ markdownPath: "data/l.md", learningSources: { targetRole: "Data Scientist", recommendedSources: [{ title: "Kaggle", url: "https://kaggle.com" }], newsletters: [{ title: "Blog", url: "https://example.com" }] } }],
|
|
56
|
+
logged: [{ entry: { day: 1, completed: "Built", evidence: "repo" }, review }],
|
|
57
|
+
weekly: [{ week: 1, range: "1-7", summary: "Good work.", completed: [{ day: 1, completed: "Built" }], nextWeekFocus: "SQL" }],
|
|
58
|
+
recommendation: [{ recommendedNextSkill: "SQL", reason: "Useful.", completedDays: 1, requiredDays: 30, canAdvance: false }],
|
|
59
|
+
card: [{ card, markdownPath: "data/c.md", terminalSvgPath: "data/c.svg" }],
|
|
60
|
+
terminalCard: [{ terminalSvgPath: "data/c.svg" }],
|
|
61
|
+
secrets: [{ commands: ["gh secret set RESEND_API_KEY"] }],
|
|
62
|
+
doctor: [{ status: "needs-email-setup", checks: { config: true, localEmail: false }, nextSteps: ["Connect email."] }]
|
|
63
|
+
};
|
|
64
|
+
for (const [kind, [payload, viewContext]] of Object.entries(views)) {
|
|
65
|
+
const output = renderView(kind, payload, viewContext);
|
|
66
|
+
assert.ok(output.trim().length > 10, kind);
|
|
67
|
+
assert.doesNotMatch(output.trimStart(), /^[{[]"?/, kind);
|
|
68
|
+
assert.doesNotMatch(output, /undefined|\[object Object\]|NaN/, kind);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("long text wraps to the terminal width", () => {
|
|
73
|
+
const long = { learner: "Asha", targetRole: "Data Scientist", primarySkill: "pandas", completedDays: 0, daysPlanned: 30, activeDay: 1, momentum: "steady", emailTime: "20:00", risk: "", nextAction: "word ".repeat(40) };
|
|
74
|
+
const lines = renderView("status", long, {}, { width: 50 }).split("\n");
|
|
75
|
+
assert.ok(lines.every((line) => line.length <= 56), lines.join("\n"));
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("colors appear only when enabled and external text cannot inject terminal codes", () => {
|
|
79
|
+
const unsafe = { ...digest, topVideo: { title: "Safe\u001b[31m title\u0007", url: "https://youtube.com/watch?v=1" } };
|
|
80
|
+
const plain = renderView("research", { path: "data/r.json", digest: unsafe });
|
|
81
|
+
assert.doesNotMatch(plain, /\u001b|\u0007/);
|
|
82
|
+
assert.match(plain, /Safe title/);
|
|
83
|
+
assert.match(renderView("research", { path: "data/r.json", digest }, {}, { color: true }), /\u001b\[/);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("color follows the terminal and NO_COLOR", () => {
|
|
87
|
+
assert.equal(terminalSupportsColor({ isTTY: true }, {}), true);
|
|
88
|
+
assert.equal(terminalSupportsColor({ isTTY: false }, {}), false);
|
|
89
|
+
assert.equal(terminalSupportsColor({ isTTY: true }, { NO_COLOR: "1" }), false);
|
|
90
|
+
assert.equal(terminalSupportsColor({ isTTY: true }, { TERM: "dumb" }), false);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("agents and scripts still receive complete JSON", () => {
|
|
94
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "kordexa-view-"));
|
|
95
|
+
try {
|
|
96
|
+
const run = (...args) => spawnSync(process.execPath, [CLI, ...args], { cwd: dir, encoding: "utf8", env: { ...process.env, KORDEXA_OFFLINE: "1" } });
|
|
97
|
+
assert.equal(run("--yes", "--offline", "--name", "Asha", "--email", "asha@gmail.com", "--role", "Data Scientist").status, 0);
|
|
98
|
+
const result = JSON.parse(run("send-today", "--dry-run", "--offline").stdout);
|
|
99
|
+
assert.equal(result.dryRun, true);
|
|
100
|
+
assert.match(result.message.html, /<html/);
|
|
101
|
+
assert.match(fs.readFileSync(path.join(dir, "data/email-preview.html"), "utf8"), /<html/);
|
|
102
|
+
assert.equal(JSON.parse(run("status", "--json").stdout).learner, "Asha");
|
|
103
|
+
} finally {
|
|
104
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
105
|
+
}
|
|
106
|
+
});
|