zion 2.5.2 → 3.0.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 +1 -0
- package/dist/LiveNow-SLZOTZWP.js +136 -0
- package/dist/{app-YZDBB2BN.js → app-J5BOIGLS.js} +1 -0
- package/dist/chunk-K3NQKI34.js +10 -0
- package/dist/chunk-YKEQSW45.js +188 -0
- package/dist/cli.js +20535 -673
- package/dist/{render-3OJW5JZI.js → render-HFXSXSPT.js} +1 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ run `npx zion`
|
|
|
11
11
|
| `npx zion` | open the terminal version of zzzzion.com |
|
|
12
12
|
| `npx zion dotfiles` | set up [zion's dotfiles](https://github.com/zion-off/dotfiles) |
|
|
13
13
|
| `npx zion skills` | install zion's agent skills |
|
|
14
|
+
| `npx zion now` | see what zion is listening to, reading and coding |
|
|
14
15
|
| `npx zion help` | list commands; `npx zion help <command>` for more |
|
|
15
16
|
|
|
16
17
|
Global flags: `--no-color` (or `NO_COLOR`), `--no-input` (never prompt), `-h/--help`, `-v/--version`.
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
LABEL_WIDTH,
|
|
4
|
+
NOTHING,
|
|
5
|
+
PaintContext,
|
|
6
|
+
entryRows,
|
|
7
|
+
errorMessage,
|
|
8
|
+
palette,
|
|
9
|
+
sectionsOf,
|
|
10
|
+
usePaint
|
|
11
|
+
} from "./chunk-YKEQSW45.js";
|
|
12
|
+
import "./chunk-K3NQKI34.js";
|
|
13
|
+
|
|
14
|
+
// src/commands/now/live/LiveNow.tsx
|
|
15
|
+
import { useEffect, useState } from "react";
|
|
16
|
+
import { Box, Text, render, useApp, useInput } from "ink";
|
|
17
|
+
|
|
18
|
+
// src/commands/now/live/effects.ts
|
|
19
|
+
var WHITE = "#ffffff";
|
|
20
|
+
function shimmer(paint, text, ms) {
|
|
21
|
+
const chars = Array.from(text);
|
|
22
|
+
const reach = 4;
|
|
23
|
+
const center = ms / 1400 % 1 * (chars.length + reach * 2) - reach;
|
|
24
|
+
return chars.map((char, i) => paint.hex(mix(palette.accent, WHITE, Math.max(0, 1 - Math.abs(i - center) / reach)))(char)).join("");
|
|
25
|
+
}
|
|
26
|
+
var LEVELS = ["\u2581", "\u2582", "\u2583", "\u2584", "\u2585", "\u2586", "\u2587", "\u2588"];
|
|
27
|
+
function bars(paint, ms, count = 4) {
|
|
28
|
+
return Array.from({ length: count }, (_, i) => {
|
|
29
|
+
const level = (wave(ms / (260 + i * 70) + i * 1.7) + wave(ms / (410 - i * 45) + i)) / 2;
|
|
30
|
+
return paint.hex(mix(palette.accent, WHITE, level))(LEVELS[Math.round(level * (LEVELS.length - 1))]);
|
|
31
|
+
}).join("");
|
|
32
|
+
}
|
|
33
|
+
function wave(x) {
|
|
34
|
+
return (Math.sin(x) + 1) / 2;
|
|
35
|
+
}
|
|
36
|
+
function mix(from, to, t) {
|
|
37
|
+
const channel = (hex, at) => parseInt(hex.slice(at, at + 2), 16);
|
|
38
|
+
return `#${[1, 3, 5].map((at) => Math.round(channel(from, at) + (channel(to, at) - channel(from, at)) * t)).map((value) => value.toString(16).padStart(2, "0")).join("")}`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/commands/now/live/LiveNow.tsx
|
|
42
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
43
|
+
var FRAME_MS = 80;
|
|
44
|
+
var REFRESH_MS = 3e4;
|
|
45
|
+
async function runLive(ctx, deps) {
|
|
46
|
+
let code = 0;
|
|
47
|
+
const instance = render(
|
|
48
|
+
/* @__PURE__ */ jsx(PaintContext.Provider, { value: ctx.paint.stdout, children: /* @__PURE__ */ jsx(
|
|
49
|
+
LiveNow,
|
|
50
|
+
{
|
|
51
|
+
...deps,
|
|
52
|
+
onQuit: (quitWith) => {
|
|
53
|
+
code = quitWith;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
) }),
|
|
57
|
+
{ stdout: ctx.stdout, stdin: ctx.stdin, exitOnCtrlC: false, patchConsole: false }
|
|
58
|
+
);
|
|
59
|
+
await instance.waitUntilExit();
|
|
60
|
+
return code;
|
|
61
|
+
}
|
|
62
|
+
function LiveNow({ api, clock, onQuit }) {
|
|
63
|
+
const paint = usePaint();
|
|
64
|
+
const { exit } = useApp();
|
|
65
|
+
const [ms, setMs] = useState(() => clock().getTime());
|
|
66
|
+
const [now, setNow] = useState(null);
|
|
67
|
+
const [status, setStatus] = useState("live");
|
|
68
|
+
const [failure, setFailure] = useState(null);
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
const timer = setInterval(() => setMs(clock().getTime()), FRAME_MS);
|
|
71
|
+
return () => clearInterval(timer);
|
|
72
|
+
}, [clock]);
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
const controller = new AbortController();
|
|
75
|
+
let loaded = false;
|
|
76
|
+
let loading = false;
|
|
77
|
+
const load = () => {
|
|
78
|
+
if (loading) return;
|
|
79
|
+
loading = true;
|
|
80
|
+
api.get(controller.signal).then(
|
|
81
|
+
(latest) => {
|
|
82
|
+
loaded = true;
|
|
83
|
+
setNow(latest);
|
|
84
|
+
setStatus((current) => current === "quit" ? current : "live");
|
|
85
|
+
},
|
|
86
|
+
(error) => {
|
|
87
|
+
if (controller.signal.aborted) return;
|
|
88
|
+
if (!loaded) setFailure(error instanceof Error ? error : new Error(errorMessage(error)));
|
|
89
|
+
else setStatus((current) => current === "quit" ? current : "stale");
|
|
90
|
+
}
|
|
91
|
+
).finally(() => {
|
|
92
|
+
loading = false;
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
load();
|
|
96
|
+
const timer = setInterval(load, REFRESH_MS);
|
|
97
|
+
return () => {
|
|
98
|
+
clearInterval(timer);
|
|
99
|
+
controller.abort();
|
|
100
|
+
};
|
|
101
|
+
}, [api]);
|
|
102
|
+
useInput((input, key) => {
|
|
103
|
+
const code = input === "q" || key.escape ? 0 : key.ctrl && input === "c" ? 130 : null;
|
|
104
|
+
if (code === null) return;
|
|
105
|
+
onQuit(code);
|
|
106
|
+
setStatus("quit");
|
|
107
|
+
});
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
if (failure) exit(failure);
|
|
110
|
+
else if (status === "quit") exit();
|
|
111
|
+
}, [exit, failure, status]);
|
|
112
|
+
if (failure) return null;
|
|
113
|
+
return /* @__PURE__ */ jsx(Box, { paddingX: 2, paddingY: 1, children: now ? frame(paint, now, clock(), ms, status) : /* @__PURE__ */ jsx(Text, { children: asking(paint, api.host, ms) }) });
|
|
114
|
+
}
|
|
115
|
+
function asking(paint, host, ms) {
|
|
116
|
+
return `${" ".repeat(LABEL_WIDTH)}${shimmer(paint, `asking ${host}`, ms)}`;
|
|
117
|
+
}
|
|
118
|
+
function frame(paint, now, at, ms, status) {
|
|
119
|
+
const quit = status === "quit";
|
|
120
|
+
const playing = quit ? "" : ` ${bars(paint, ms)}`;
|
|
121
|
+
const sections = sectionsOf(now, at).map(
|
|
122
|
+
(entries) => entries.flatMap((entry) => entryRows(paint, entry, entry.playing ? playing : ""))
|
|
123
|
+
);
|
|
124
|
+
const footer = status === "stale" ? `${paint.warning("\u25B2")} ${paint.muted("couldn't refresh, still trying \xB7 q to quit")}` : paint.muted("q to quit");
|
|
125
|
+
return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", rowGap: 1, children: [
|
|
126
|
+
sections.length === 0 && /* @__PURE__ */ jsx(Text, { children: paint.muted(NOTHING) }),
|
|
127
|
+
sections.map((rows, i) => /* @__PURE__ */ jsx(Box, { flexDirection: "column", children: rows.map((row, j) => /* @__PURE__ */ jsxs(Box, { children: [
|
|
128
|
+
/* @__PURE__ */ jsx(Box, { width: LABEL_WIDTH, flexShrink: 0, children: /* @__PURE__ */ jsx(Text, { children: paint.muted(row.label) }) }),
|
|
129
|
+
/* @__PURE__ */ jsx(Text, { children: row.text })
|
|
130
|
+
] }, j)) }, i)),
|
|
131
|
+
!quit && /* @__PURE__ */ jsx(Text, { children: footer })
|
|
132
|
+
] });
|
|
133
|
+
}
|
|
134
|
+
export {
|
|
135
|
+
runLive
|
|
136
|
+
};
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/cli/errors.ts
|
|
4
|
+
var CliError = class extends Error {
|
|
5
|
+
constructor(message, hint, exitCode = 1) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.hint = hint;
|
|
8
|
+
this.exitCode = exitCode;
|
|
9
|
+
this.name = "CliError";
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
var UsageError = class extends CliError {
|
|
13
|
+
constructor(message, hint) {
|
|
14
|
+
super(message, hint, 2);
|
|
15
|
+
this.name = "UsageError";
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var CancelledError = class extends Error {
|
|
19
|
+
constructor() {
|
|
20
|
+
super("Cancelled");
|
|
21
|
+
this.name = "CancelledError";
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var ReportedError = class extends Error {
|
|
25
|
+
exitCode;
|
|
26
|
+
constructor(cause) {
|
|
27
|
+
super(errorMessage(cause), { cause });
|
|
28
|
+
this.name = "ReportedError";
|
|
29
|
+
this.exitCode = exitCodeFor(cause);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
function exitCodeFor(error) {
|
|
33
|
+
if (error instanceof ReportedError) return error.exitCode;
|
|
34
|
+
if (error instanceof CancelledError) return 130;
|
|
35
|
+
if (error instanceof CliError) return error.exitCode;
|
|
36
|
+
return 1;
|
|
37
|
+
}
|
|
38
|
+
function errorMessage(error) {
|
|
39
|
+
return error instanceof Error ? error.message : String(error);
|
|
40
|
+
}
|
|
41
|
+
function errorCode(error) {
|
|
42
|
+
return error instanceof Error && "code" in error && typeof error.code === "string" ? error.code : void 0;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/prompts/components/PaintContext.ts
|
|
46
|
+
import { createContext, useContext } from "react";
|
|
47
|
+
var PaintContext = createContext(null);
|
|
48
|
+
function usePaint() {
|
|
49
|
+
const paint = useContext(PaintContext);
|
|
50
|
+
if (!paint) throw new Error("usePaint needs a PaintContext provider");
|
|
51
|
+
return paint;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/commands/now/format.ts
|
|
55
|
+
import terminalLink from "terminal-link";
|
|
56
|
+
var LABEL_WIDTH = 14;
|
|
57
|
+
function formatNow(paint, now, at) {
|
|
58
|
+
const sections = sectionsOf(now, at);
|
|
59
|
+
if (sections.length === 0) return `${paint.muted(NOTHING)}
|
|
60
|
+
`;
|
|
61
|
+
return `${sections.map(
|
|
62
|
+
(entries) => entries.flatMap((entry) => entryRows(paint, entry)).map((row) => `${paint.muted(row.label.padEnd(LABEL_WIDTH))}${row.text}`).join("\n")
|
|
63
|
+
).join("\n\n")}
|
|
64
|
+
`;
|
|
65
|
+
}
|
|
66
|
+
var NOTHING = "Nothing to show right now.";
|
|
67
|
+
function sectionsOf(now, at) {
|
|
68
|
+
const sections = [];
|
|
69
|
+
if (now.listening) sections.push([listening(now.listening, at)]);
|
|
70
|
+
if (now.reading?.length) sections.push(now.reading.map(reading));
|
|
71
|
+
if (now.coding) sections.push([coding(now.coding, at)]);
|
|
72
|
+
return sections;
|
|
73
|
+
}
|
|
74
|
+
function entryRows(paint, entry, after = "") {
|
|
75
|
+
const bold = paint.bold(printable(entry.title));
|
|
76
|
+
const linked = /^https:\/\//.test(entry.url) ? terminalLink(bold, printable(entry.url), { fallback: () => bold }) : bold;
|
|
77
|
+
const rows = [{ label: entry.label, text: `${linked}${after}` }];
|
|
78
|
+
if (entry.detail) rows.push({ label: "", text: paint.muted(printable(entry.detail)) });
|
|
79
|
+
return rows;
|
|
80
|
+
}
|
|
81
|
+
function listening(track, at) {
|
|
82
|
+
const played = track.playedAt === null ? null : ago(new Date(track.playedAt), at);
|
|
83
|
+
return {
|
|
84
|
+
label: played === null ? "listening to" : "listened to",
|
|
85
|
+
title: track.title,
|
|
86
|
+
url: track.url,
|
|
87
|
+
detail: played === null ? track.artist : [track.artist, played].join(" \xB7 "),
|
|
88
|
+
playing: played === null
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function reading(book, i) {
|
|
92
|
+
return { label: i === 0 ? "reading" : "", title: book.title, url: book.url, detail: book.author, playing: false };
|
|
93
|
+
}
|
|
94
|
+
function coding(push, at) {
|
|
95
|
+
return {
|
|
96
|
+
label: "pushed to",
|
|
97
|
+
title: push.repo,
|
|
98
|
+
url: push.url,
|
|
99
|
+
detail: [push.message, ago(new Date(push.pushedAt), at)].join(" \xB7 "),
|
|
100
|
+
playing: false
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
var UNITS = [
|
|
104
|
+
["year", 365 * 24 * 3600],
|
|
105
|
+
["month", 30 * 24 * 3600],
|
|
106
|
+
["week", 7 * 24 * 3600],
|
|
107
|
+
["day", 24 * 3600],
|
|
108
|
+
["hour", 3600],
|
|
109
|
+
["minute", 60]
|
|
110
|
+
];
|
|
111
|
+
function ago(then, at) {
|
|
112
|
+
const seconds = (at.getTime() - then.getTime()) / 1e3;
|
|
113
|
+
if (Number.isNaN(seconds)) return "";
|
|
114
|
+
const format = new Intl.RelativeTimeFormat("en", { numeric: "auto" });
|
|
115
|
+
for (const [unit, size] of UNITS) {
|
|
116
|
+
if (seconds >= size) return format.format(-Math.floor(seconds / size), unit);
|
|
117
|
+
}
|
|
118
|
+
return "just now";
|
|
119
|
+
}
|
|
120
|
+
function printable(text) {
|
|
121
|
+
return text.replace(new RegExp("\\p{Cc}", "gu"), "");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// src/lib/theme.ts
|
|
125
|
+
import { Chalk, supportsColor, supportsColorStderr } from "chalk";
|
|
126
|
+
var palette = {
|
|
127
|
+
brand: "#264b96",
|
|
128
|
+
accent: "#5c9fd4",
|
|
129
|
+
success: "#3fb950",
|
|
130
|
+
warning: "#f9a73e",
|
|
131
|
+
error: "#e5534b"
|
|
132
|
+
};
|
|
133
|
+
var symbols = {
|
|
134
|
+
start: "\u250C",
|
|
135
|
+
bar: "\u2502",
|
|
136
|
+
end: "\u2514",
|
|
137
|
+
active: "\u25C6",
|
|
138
|
+
done: "\u25C7",
|
|
139
|
+
warning: "\u25B2",
|
|
140
|
+
error: "\u25A0",
|
|
141
|
+
radioOn: "\u25CF",
|
|
142
|
+
radioOff: "\u25CB",
|
|
143
|
+
checkOn: "\u25FC",
|
|
144
|
+
checkOff: "\u25FB",
|
|
145
|
+
tick: "\u2714",
|
|
146
|
+
cross: "\u2716",
|
|
147
|
+
spinner: ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"]
|
|
148
|
+
};
|
|
149
|
+
function createPaint(chalk) {
|
|
150
|
+
return {
|
|
151
|
+
accent: chalk.hex(palette.accent),
|
|
152
|
+
success: chalk.hex(palette.success),
|
|
153
|
+
warning: chalk.hex(palette.warning),
|
|
154
|
+
error: chalk.hex(palette.error),
|
|
155
|
+
muted: chalk.gray,
|
|
156
|
+
dim: chalk.dim,
|
|
157
|
+
bold: chalk.bold,
|
|
158
|
+
white: chalk.white,
|
|
159
|
+
inverse: chalk.inverse,
|
|
160
|
+
hex: (color) => chalk.hex(color),
|
|
161
|
+
badge: (text) => chalk.bgHex(palette.brand).hex("#ffffff").bold(` ${text} `)
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function paintFor(stream, { color, env }) {
|
|
165
|
+
const detected = stream === process.stderr ? supportsColorStderr : supportsColor;
|
|
166
|
+
const noColor = Boolean(env.NO_COLOR) && !("FORCE_COLOR" in env);
|
|
167
|
+
return createPaint(new Chalk({ level: !color || noColor || !detected ? 0 : detected.level }));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export {
|
|
171
|
+
palette,
|
|
172
|
+
symbols,
|
|
173
|
+
paintFor,
|
|
174
|
+
CliError,
|
|
175
|
+
UsageError,
|
|
176
|
+
CancelledError,
|
|
177
|
+
ReportedError,
|
|
178
|
+
exitCodeFor,
|
|
179
|
+
errorMessage,
|
|
180
|
+
errorCode,
|
|
181
|
+
PaintContext,
|
|
182
|
+
usePaint,
|
|
183
|
+
LABEL_WIDTH,
|
|
184
|
+
formatNow,
|
|
185
|
+
NOTHING,
|
|
186
|
+
sectionsOf,
|
|
187
|
+
entryRows
|
|
188
|
+
};
|