@turri-dev/cli 0.4.3-next.fd01774 → 0.5.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.
@@ -1,99 +0,0 @@
1
- import { basename } from "node:path";
2
- import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
3
- import { capturePhases, captureStageText } from "@turri-dev/core";
4
- import { spinner } from "./terminal-marks.js";
5
- import { skillProgressLine } from "./skill-progress.js";
6
- /** The stages whose work is counted as they start - parts, concepts, modules, scripts - rather than from the features. */
7
- const COUNTED_STAGES = new Set(["checking", "extracting", "dividing", "filling", "gathering", "reconciling", "reading", "verifying", "trying", "scripts"]);
8
- /** The phase's work, for its strip: how much there is, how much is done, how much is at work - none while it is not counted. */
9
- export function workOf(status) {
10
- if (status.stage === "capturing") {
11
- const { outlined, done } = status.features;
12
- if (outlined === 0)
13
- return undefined;
14
- const running = status.agents.filter((agent) => agent.label.startsWith("feature ")).length;
15
- return { total: outlined, done, running: Math.min(running, outlined - done) };
16
- }
17
- if (!COUNTED_STAGES.has(status.stage))
18
- return undefined;
19
- const { total, done } = status.work;
20
- if (total === 0)
21
- return undefined;
22
- return { total, done, running: Math.min(status.agents.length, total - done) };
23
- }
24
- /** `40s`, `2m 10s`, `1h 05m`. */
25
- export function duration(ms) {
26
- const seconds = Math.max(0, Math.floor(ms / 1000));
27
- if (seconds < 60)
28
- return `${seconds}s`;
29
- const minutes = Math.floor(seconds / 60);
30
- if (minutes < 60)
31
- return `${minutes}m ${String(seconds % 60).padStart(2, "0")}s`;
32
- return `${Math.floor(minutes / 60)}h ${String(minutes % 60).padStart(2, "0")}m`;
33
- }
34
- const PLAIN = { heading: (t) => t, done: (t) => t, now: (t) => t, muted: (t) => t };
35
- /** How many agents get a line each; the rest are counted on one. */
36
- const AGENT_LINES = 6;
37
- /** The widest an agent's label is padded to. */
38
- const LABEL_WIDTH = 40;
39
- /** The cells of a phase's strip, as many as the regen panel's. */
40
- const STRIP_CELLS = 24;
41
- /** The status as lines across `width`, the spinner at `frame` and the clock at `now`. */
42
- export function captureStatusLines(status, at, style = PLAIN) {
43
- const phases = skillProgressLine({ skill: `capture ${basename(status.root)}`, ...capturePhases(status), attempt: 1, frame: at.frame }, at.width, style);
44
- const work = workOf(status);
45
- const cost = status.cost > 0 ? ` · $${status.cost.toFixed(2)}` : "";
46
- const phase = ` ${work !== undefined ? `${workStrip(work, style)} ` : `${style.now(at.frame)} `}${captureStageText(status, work)} ${style.muted(`· ${duration(at.now - status.started)}${cost}`)}`;
47
- const shown = status.agents.slice(0, AGENT_LINES);
48
- const pad = Math.min(LABEL_WIDTH, Math.max(0, ...shown.map((agent) => visibleWidth(agent.label))));
49
- const agents = shown.map((agent) => {
50
- const label = visibleWidth(agent.label) > pad ? truncateToWidth(agent.label, pad, "…") : agent.label.padEnd(pad);
51
- const what = [agent.did, agent.now !== undefined ? style.muted(agent.now) : undefined].filter((part) => part !== undefined).join(style.muted(" · "));
52
- return ` ${label} ${style.muted(duration(at.now - agent.since).padStart(6))} ${what || style.muted("starting")}`;
53
- });
54
- const more = status.agents.length > shown.length ? [style.muted(` and ${status.agents.length - shown.length} more agents`)] : [];
55
- const last = status.last !== undefined ? [style.muted(` ${status.last}`)] : [];
56
- return [phases, phase, ...agents, ...more, ...last].map((line) => truncateToWidth(line, at.width, "…"));
57
- }
58
- /** A phase's work as the regen panel's strip draws functional specs: done, at work, waiting - in their colours. */
59
- export function workStrip(work, style, cells = STRIP_CELLS) {
60
- const parts = [
61
- { count: work.done, glyph: "█", paint: style.done },
62
- { count: work.running, glyph: "█", paint: style.now },
63
- { count: Math.max(0, work.total - work.done - work.running), glyph: "▓", paint: style.muted },
64
- ];
65
- let used = 0;
66
- let counted = 0;
67
- let out = "";
68
- for (const part of parts) {
69
- counted += part.count;
70
- const upTo = Math.round((counted / Math.max(1, work.total)) * cells);
71
- if (upTo > used)
72
- out += part.paint(part.glyph.repeat(upTo - used));
73
- used = Math.max(used, upTo);
74
- }
75
- return out + style.muted("░".repeat(Math.max(0, cells - used)));
76
- }
77
- /** A capture's status above the chat's input, as its `captureProgress` events tell it, until it ends. */
78
- export function captureProgress(ui) {
79
- const CAPTURE_WIDGET = "turri-capture";
80
- let status;
81
- let redrawNow;
82
- ui.setWidget(CAPTURE_WIDGET, (tui, theme) => {
83
- const redraw = setInterval(() => tui.requestRender(), 1000);
84
- redraw.unref?.();
85
- redrawNow = () => tui.requestRender();
86
- const style = {
87
- heading: (text) => theme.bold(theme.fg("accent", text)),
88
- done: (text) => theme.fg("success", text),
89
- now: (text) => theme.bold(theme.fg("accent", text)),
90
- muted: (text) => theme.fg("muted", text),
91
- };
92
- return {
93
- render: (width) => (status === undefined ? [] : captureStatusLines(status, { frame: spinner(Date.now()), now: Date.now(), width }, style)),
94
- invalidate: () => { },
95
- dispose: () => { clearInterval(redraw); redrawNow = undefined; },
96
- };
97
- });
98
- return { update(next) { status = next; redrawNow?.(); }, close() { ui.setWidget(CAPTURE_WIDGET, undefined); } };
99
- }
package/dist/reopen.js DELETED
@@ -1,80 +0,0 @@
1
- import { readFileSync, rmSync, writeFileSync } from "node:fs";
2
- import { relative } from "node:path";
3
- /**
4
- * turri opened again in another folder, in the same terminal, once its chat has quit: a chat works on the project of
5
- * the folder it was opened in, and after a capture the work is in another - `plain/`, a project of its own. `turri`
6
- * (cli.ts) starts the chat as a process of its own, with turri's theme, its screen and the folder's models, and names
7
- * it a file to write in: a chat that is to open again elsewhere writes where, with what, and quits; `turri` reads it and
8
- * starts the chat there as it started the first. The session's `openProject` asks for it (terminal-view.ts); the chat
9
- * opened again tells the capture's report (`createTurri({ captured })`). The handoff is the CLI's own, between its two
10
- * processes: the core knows nothing of it.
11
- */
12
- /** The file the chat `turri` started writes where it is to open again. */
13
- export const REOPEN_FILE_ENV = "TURRI_CLI_REOPEN_FILE";
14
- /** Said to the chat opened again after a capture, at its start: what the capture said of itself. */
15
- export const CAPTURED_ENV = "TURRI_CLI_CAPTURED";
16
- /** Whether this chat can open again in another folder: `turri` started it. */
17
- export function canReopen(env = process.env) {
18
- return (env[REOPEN_FILE_ENV] ?? "") !== "";
19
- }
20
- /** Ask `turri` to open the chat again in `dir` once it has quit - the caller quits it. False when it cannot (`canReopen`). */
21
- export function reopenIn(dir, options = {}) {
22
- const file = process.env[REOPEN_FILE_ENV];
23
- if (file === undefined || file === "")
24
- return false;
25
- const reopening = { dir, args: options.args ?? [], env: options.env ?? {} };
26
- writeFileSync(file, JSON.stringify(reopening));
27
- return true;
28
- }
29
- /** What the chat that quit asked for, taken - its file removed - or undefined when it asked for nothing. */
30
- export function takeReopening(file) {
31
- let text;
32
- try {
33
- text = readFileSync(file, "utf8");
34
- }
35
- catch {
36
- return undefined;
37
- }
38
- rmSync(file, { force: true });
39
- try {
40
- const parsed = JSON.parse(text);
41
- if (typeof parsed.dir !== "string" || !Array.isArray(parsed.args) || parsed.args.some((arg) => typeof arg !== "string"))
42
- return undefined;
43
- const env = Object.fromEntries(Object.entries(parsed.env ?? {}).filter((entry) => typeof entry[1] === "string"));
44
- return { dir: parsed.dir, args: parsed.args, env };
45
- }
46
- catch {
47
- return undefined;
48
- }
49
- }
50
- /** What the chat opened again after a capture is told at its start, in its environment. */
51
- export function capturedEnv(summary) {
52
- return { [CAPTURED_ENV]: JSON.stringify({ summary }) };
53
- }
54
- /** The capture a chat opened again after it tells - taken from its environment, once - or undefined when it is not that chat. */
55
- export function takeCaptured(env = process.env) {
56
- const told = env[CAPTURED_ENV];
57
- delete env[CAPTURED_ENV];
58
- if (told === undefined)
59
- return undefined;
60
- try {
61
- const parsed = JSON.parse(told);
62
- return typeof parsed.summary === "string" ? { summary: parsed.summary } : undefined;
63
- }
64
- catch {
65
- return undefined;
66
- }
67
- }
68
- /** What the person is asked once a capture in the chat ends: to open turri again in the captured project. */
69
- export function captureOpenQuestion(cwd, dir, summary) {
70
- const folder = `${relative(cwd, dir) || dir}/`;
71
- return {
72
- title: `Open the captured ***plain in ${folder}?`,
73
- message: [
74
- summary,
75
- "",
76
- `turri closes here and opens again in ${folder} - the captured project - where ctrl+h shows its ***plain and /regenerate builds it. Its report is told there.`,
77
- `Not now: it stays here, and \`cd ${folder.slice(0, -1)} && turri\` opens it later.`,
78
- ].join("\n"),
79
- };
80
- }