@trazum/cli 2.7.11 → 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 +4 -2
- package/assets/trazum-statusline.sh +131 -0
- package/dist/git.d.ts +38 -0
- package/dist/git.d.ts.map +1 -1
- package/dist/git.js +54 -0
- package/dist/git.js.map +1 -1
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +170 -3
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/es.d.ts.map +1 -1
- package/dist/i18n/es.js +174 -3
- package/dist/i18n/es.js.map +1 -1
- package/dist/i18n/types.d.ts +84 -0
- package/dist/i18n/types.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +670 -262
- package/dist/index.js.map +1 -1
- package/dist/proactive.d.ts +344 -0
- package/dist/proactive.d.ts.map +1 -0
- package/dist/proactive.js +1079 -0
- package/dist/proactive.js.map +1 -0
- package/dist/style.d.ts +305 -26
- package/dist/style.d.ts.map +1 -1
- package/dist/style.js +449 -47
- package/dist/style.js.map +1 -1
- package/dist/watch-notify.d.ts +82 -0
- package/dist/watch-notify.d.ts.map +1 -0
- package/dist/watch-notify.js +118 -0
- package/dist/watch-notify.js.map +1 -0
- package/dist/watch-run.d.ts +7 -0
- package/dist/watch-run.d.ts.map +1 -1
- package/dist/watch-run.js.map +1 -1
- package/dist/weekly.d.ts +32 -0
- package/dist/weekly.d.ts.map +1 -0
- package/dist/weekly.js +119 -0
- package/dist/weekly.js.map +1 -0
- package/package.json +3 -2
- package/src/git.ts +77 -0
- package/src/i18n/en.ts +198 -3
- package/src/i18n/es.ts +202 -3
- package/src/i18n/types.ts +130 -0
- package/src/index.ts +715 -302
- package/src/proactive.ts +1319 -0
- package/src/style.ts +502 -54
- package/src/watch-notify.ts +152 -0
- package/src/watch-run.ts +7 -0
- package/src/weekly.ts +133 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A desktop notification for the person at the machine, through what the
|
|
3
|
+
* platform already has.
|
|
4
|
+
*
|
|
5
|
+
* `trazum watch` has three transports (an exit code, a JSON event, a webhook),
|
|
6
|
+
* and all three assume somebody already has a place alerts go. A person at
|
|
7
|
+
* their own machine has a screen. This is the fourth: off unless `--notify`
|
|
8
|
+
* asks, and it says what the terminal says.
|
|
9
|
+
*
|
|
10
|
+
* The spawn itself is `runNotifier` in `git.ts`, the one module that runs
|
|
11
|
+
* another program: the security suite holds that to one file, and a second
|
|
12
|
+
* caller would get none of its rules. This module only decides what to run and
|
|
13
|
+
* what to hand it.
|
|
14
|
+
*
|
|
15
|
+
* **Nothing is installed and nothing is added.** macOS has `osascript`, a
|
|
16
|
+
* Linux desktop has `notify-send` where it has a notification daemon, and
|
|
17
|
+
* Windows has PowerShell and the toast API in it. Where the platform has none
|
|
18
|
+
* of them the answer is `unavailable`, which the caller says out loud and then
|
|
19
|
+
* carries on with the other transports: a notifier that cannot notify must not
|
|
20
|
+
* take the alert down with it, and must not look as if it had.
|
|
21
|
+
*
|
|
22
|
+
* **The text never reaches a shell, and never becomes code.** The program is
|
|
23
|
+
* started with an argument array and `shell: false`, so there is no shell to
|
|
24
|
+
* break out of. The text itself is handed over as data and never spliced into a
|
|
25
|
+
* script: as arguments to a fixed AppleScript handler on macOS, as environment
|
|
26
|
+
* variables read by a fixed script on Windows (sent as `-EncodedCommand`, so
|
|
27
|
+
* no quoting rule applies to it either), and after `--` on Linux so it cannot
|
|
28
|
+
* be read as an option. A quote, a backtick or a newline in a sentence is a
|
|
29
|
+
* character in the sentence and nothing else.
|
|
30
|
+
*
|
|
31
|
+
* **What it carries is decided by the one function that builds it.** The
|
|
32
|
+
* sentence is the one the terminal prints for a crossing: figures, the limit,
|
|
33
|
+
* the day a day gate means. Never a prompt, never a path, never a project's
|
|
34
|
+
* name. `notificationFor` takes the sentences and nothing else, so there is no
|
|
35
|
+
* way to hand it a path by accident.
|
|
36
|
+
*/
|
|
37
|
+
import type { NotifierRun } from './git.js';
|
|
38
|
+
/** The title is fixed and not translated: it names the sender, not the news. */
|
|
39
|
+
export declare const NOTIFICATION_TITLE = "Trazum";
|
|
40
|
+
export type NotifierName = 'osascript' | 'notify-send' | 'powershell.exe';
|
|
41
|
+
export interface Notification {
|
|
42
|
+
title: string;
|
|
43
|
+
body: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The notification for a cycle's new crossings: the sentences the terminal
|
|
47
|
+
* printed for them, one to a line, and a fixed title. Nothing else goes in.
|
|
48
|
+
*/
|
|
49
|
+
export declare function notificationFor(sentences: readonly string[]): Notification;
|
|
50
|
+
/** What to run, and what to hand it, to show one notification on this platform. */
|
|
51
|
+
export interface NotifierCall {
|
|
52
|
+
command: NotifierName;
|
|
53
|
+
args: string[];
|
|
54
|
+
/** Variables added to the environment, for the one platform that reads its text from there. */
|
|
55
|
+
env: Record<string, string>;
|
|
56
|
+
}
|
|
57
|
+
export declare function notifierCall(platform: NodeJS.Platform, notification: Notification): NotifierCall;
|
|
58
|
+
export type NotifyOutcome =
|
|
59
|
+
/** The platform's notifier accepted it. Not a promise that a screen showed it. */
|
|
60
|
+
{
|
|
61
|
+
outcome: 'sent';
|
|
62
|
+
command: NotifierName;
|
|
63
|
+
}
|
|
64
|
+
/** The platform has no such program: said, and the other transports carry on. */
|
|
65
|
+
| {
|
|
66
|
+
outcome: 'unavailable';
|
|
67
|
+
command: NotifierName;
|
|
68
|
+
}
|
|
69
|
+
/** The program is there and refused, usually because there is no desktop session. */
|
|
70
|
+
| {
|
|
71
|
+
outcome: 'failed';
|
|
72
|
+
command: NotifierName;
|
|
73
|
+
error: string;
|
|
74
|
+
};
|
|
75
|
+
/** The part of the spawn this uses, so a test can stand in for the notifier. */
|
|
76
|
+
export type NotifierRunner = (command: NotifierName, args: readonly string[], env: NodeJS.ProcessEnv) => NotifierRun;
|
|
77
|
+
export declare function sendNotification(notification: Notification, options?: {
|
|
78
|
+
platform?: NodeJS.Platform;
|
|
79
|
+
run?: NotifierRunner;
|
|
80
|
+
env?: NodeJS.ProcessEnv;
|
|
81
|
+
}): NotifyOutcome;
|
|
82
|
+
//# sourceMappingURL=watch-notify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watch-notify.d.ts","sourceRoot":"","sources":["../src/watch-notify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,gFAAgF;AAChF,eAAO,MAAM,kBAAkB,WAAW,CAAC;AAE3C,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG,aAAa,GAAG,gBAAgB,CAAC;AAE1E,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,YAAY,CAE1E;AAED,mFAAmF;AACnF,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,YAAY,CAAC;IACtB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,+FAA+F;IAC/F,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC7B;AAiCD,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,YAAY,GAAG,YAAY,CA6BhG;AAED,MAAM,MAAM,aAAa;AACvB,kFAAkF;AAChF;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,YAAY,CAAA;CAAE;AAC5C,iFAAiF;GAC/E;IAAE,OAAO,EAAE,aAAa,CAAC;IAAC,OAAO,EAAE,YAAY,CAAA;CAAE;AACnD,qFAAqF;GACnF;IAAE,OAAO,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhE,gFAAgF;AAChF,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,CAAC,UAAU,KAAK,WAAW,CAAC;AAErH,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,YAAY,EAC1B,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC;IAAC,GAAG,CAAC,EAAE,cAAc,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAA;CAAO,GAC1F,aAAa,CASf"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A desktop notification for the person at the machine, through what the
|
|
3
|
+
* platform already has.
|
|
4
|
+
*
|
|
5
|
+
* `trazum watch` has three transports (an exit code, a JSON event, a webhook),
|
|
6
|
+
* and all three assume somebody already has a place alerts go. A person at
|
|
7
|
+
* their own machine has a screen. This is the fourth: off unless `--notify`
|
|
8
|
+
* asks, and it says what the terminal says.
|
|
9
|
+
*
|
|
10
|
+
* The spawn itself is `runNotifier` in `git.ts`, the one module that runs
|
|
11
|
+
* another program: the security suite holds that to one file, and a second
|
|
12
|
+
* caller would get none of its rules. This module only decides what to run and
|
|
13
|
+
* what to hand it.
|
|
14
|
+
*
|
|
15
|
+
* **Nothing is installed and nothing is added.** macOS has `osascript`, a
|
|
16
|
+
* Linux desktop has `notify-send` where it has a notification daemon, and
|
|
17
|
+
* Windows has PowerShell and the toast API in it. Where the platform has none
|
|
18
|
+
* of them the answer is `unavailable`, which the caller says out loud and then
|
|
19
|
+
* carries on with the other transports: a notifier that cannot notify must not
|
|
20
|
+
* take the alert down with it, and must not look as if it had.
|
|
21
|
+
*
|
|
22
|
+
* **The text never reaches a shell, and never becomes code.** The program is
|
|
23
|
+
* started with an argument array and `shell: false`, so there is no shell to
|
|
24
|
+
* break out of. The text itself is handed over as data and never spliced into a
|
|
25
|
+
* script: as arguments to a fixed AppleScript handler on macOS, as environment
|
|
26
|
+
* variables read by a fixed script on Windows (sent as `-EncodedCommand`, so
|
|
27
|
+
* no quoting rule applies to it either), and after `--` on Linux so it cannot
|
|
28
|
+
* be read as an option. A quote, a backtick or a newline in a sentence is a
|
|
29
|
+
* character in the sentence and nothing else.
|
|
30
|
+
*
|
|
31
|
+
* **What it carries is decided by the one function that builds it.** The
|
|
32
|
+
* sentence is the one the terminal prints for a crossing: figures, the limit,
|
|
33
|
+
* the day a day gate means. Never a prompt, never a path, never a project's
|
|
34
|
+
* name. `notificationFor` takes the sentences and nothing else, so there is no
|
|
35
|
+
* way to hand it a path by accident.
|
|
36
|
+
*/
|
|
37
|
+
import { runNotifier } from './git.js';
|
|
38
|
+
/** The title is fixed and not translated: it names the sender, not the news. */
|
|
39
|
+
export const NOTIFICATION_TITLE = 'Trazum';
|
|
40
|
+
/**
|
|
41
|
+
* The notification for a cycle's new crossings: the sentences the terminal
|
|
42
|
+
* printed for them, one to a line, and a fixed title. Nothing else goes in.
|
|
43
|
+
*/
|
|
44
|
+
export function notificationFor(sentences) {
|
|
45
|
+
return { title: NOTIFICATION_TITLE, body: sentences.join('\n') };
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The AppleScript is a constant. The text arrives as `argv`, so it is a value
|
|
49
|
+
* the script displays and never a part of the script's own text.
|
|
50
|
+
*/
|
|
51
|
+
const APPLESCRIPT = [
|
|
52
|
+
'on run argv',
|
|
53
|
+
'display notification (item 1 of argv) with title (item 2 of argv)',
|
|
54
|
+
'end run',
|
|
55
|
+
];
|
|
56
|
+
/**
|
|
57
|
+
* The PowerShell script is a constant too, and reads its text from two
|
|
58
|
+
* variables. It builds the toast with the XML document's own `InnerText`, which
|
|
59
|
+
* escapes what it is given, rather than by joining the text into markup. The
|
|
60
|
+
* application id is the one Windows PowerShell is registered under, because a
|
|
61
|
+
* toast from an id nothing registered is dropped silently.
|
|
62
|
+
*/
|
|
63
|
+
const POWERSHELL = [
|
|
64
|
+
"$ErrorActionPreference = 'Stop'",
|
|
65
|
+
'[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null',
|
|
66
|
+
'[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null',
|
|
67
|
+
'$xml = New-Object Windows.Data.Xml.Dom.XmlDocument',
|
|
68
|
+
"$xml.LoadXml('<toast><visual><binding template=\"ToastGeneric\"><text/><text/></binding></visual></toast>')",
|
|
69
|
+
"$texts = $xml.GetElementsByTagName('text')",
|
|
70
|
+
'$texts.Item(0).InnerText = $env:TRAZUM_NOTIFY_TITLE',
|
|
71
|
+
'$texts.Item(1).InnerText = $env:TRAZUM_NOTIFY_BODY',
|
|
72
|
+
'$toast = [Windows.UI.Notifications.ToastNotification]::new($xml)',
|
|
73
|
+
"$id = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\\WindowsPowerShell\\v1.0\\powershell.exe'",
|
|
74
|
+
'[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($id).Show($toast)',
|
|
75
|
+
].join('\n');
|
|
76
|
+
export function notifierCall(platform, notification) {
|
|
77
|
+
if (platform === 'darwin') {
|
|
78
|
+
return {
|
|
79
|
+
command: 'osascript',
|
|
80
|
+
args: [...APPLESCRIPT.flatMap((line) => ['-e', line]), notification.body, notification.title],
|
|
81
|
+
env: {},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (platform === 'win32') {
|
|
85
|
+
return {
|
|
86
|
+
command: 'powershell.exe',
|
|
87
|
+
args: [
|
|
88
|
+
'-NoProfile',
|
|
89
|
+
'-NonInteractive',
|
|
90
|
+
'-ExecutionPolicy',
|
|
91
|
+
'Bypass',
|
|
92
|
+
'-EncodedCommand',
|
|
93
|
+
Buffer.from(POWERSHELL, 'utf16le').toString('base64'),
|
|
94
|
+
],
|
|
95
|
+
env: { TRAZUM_NOTIFY_TITLE: notification.title, TRAZUM_NOTIFY_BODY: notification.body },
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
// Linux and the other desktops that follow freedesktop.org: the `--` ends
|
|
99
|
+
// the options, so a sentence that began with a dash would still be a sentence.
|
|
100
|
+
return {
|
|
101
|
+
command: 'notify-send',
|
|
102
|
+
args: ['--app-name=Trazum', '--', notification.title, notification.body],
|
|
103
|
+
env: {},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
export function sendNotification(notification, options = {}) {
|
|
107
|
+
const call = notifierCall(options.platform ?? process.platform, notification);
|
|
108
|
+
const run = options.run ?? runNotifier;
|
|
109
|
+
const result = run(call.command, call.args, { ...(options.env ?? process.env), ...call.env });
|
|
110
|
+
if (result.errorCode === 'ENOENT')
|
|
111
|
+
return { outcome: 'unavailable', command: call.command };
|
|
112
|
+
if (result.errorCode === null && result.status === 0)
|
|
113
|
+
return { outcome: 'sent', command: call.command };
|
|
114
|
+
const said = result.stderr.trim().split('\n')[0] ?? '';
|
|
115
|
+
const why = said !== '' ? said : (result.errorCode ?? `exited with ${String(result.status)}`);
|
|
116
|
+
return { outcome: 'failed', command: call.command, error: why };
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=watch-notify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watch-notify.js","sourceRoot":"","sources":["../src/watch-notify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAGvC,gFAAgF;AAChF,MAAM,CAAC,MAAM,kBAAkB,GAAG,QAAQ,CAAC;AAS3C;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,SAA4B;IAC1D,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AACnE,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HANGED
|
@@ -22,6 +22,13 @@ export interface WatchState {
|
|
|
22
22
|
lastCoveredToMs: number | null;
|
|
23
23
|
/** Gate keys already alerted on, so a restart is not amnesia. */
|
|
24
24
|
fired: Record<string, number>;
|
|
25
|
+
/**
|
|
26
|
+
* Written only by a watch of the sessions on this machine (`--sessions`).
|
|
27
|
+
* Absent is the store, or a saved payload, as every state written before it
|
|
28
|
+
* existed. What was reported about one source says nothing about the other's
|
|
29
|
+
* figures, so a cycle that finds the other source's mark starts over.
|
|
30
|
+
*/
|
|
31
|
+
source?: 'sessions';
|
|
25
32
|
}
|
|
26
33
|
export declare function readWatchState(root: string): Promise<WatchState | null>;
|
|
27
34
|
export declare function writeWatchState(root: string, state: WatchState): Promise<void>;
|
package/dist/watch-run.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watch-run.d.ts","sourceRoot":"","sources":["../src/watch-run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,eAAO,MAAM,gBAAgB,uBAAuB,CAAC;AAErD,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC,MAAM,WAAW,UAAU;IACzB,CAAC,EAAE,MAAM,CAAC;IACV,+EAA+E;IAC/E,WAAW,EAAE,MAAM,CAAC;IACpB,8DAA8D;IAC9D,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,iEAAiE;IACjE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"watch-run.d.ts","sourceRoot":"","sources":["../src/watch-run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,eAAO,MAAM,gBAAgB,uBAAuB,CAAC;AAErD,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC,MAAM,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"version":3,"file":"watch-run.js","sourceRoot":"","sources":["../src/watch-run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,MAAM,CAAC,MAAM,gBAAgB,GAAG,oBAAoB,CAAC;AAErD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"watch-run.js","sourceRoot":"","sources":["../src/watch-run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,MAAM,CAAC,MAAM,gBAAgB,GAAG,oBAAoB,CAAC;AAErD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAmBrC,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,IAAY;IAC/C,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,gBAAgB,CAAC,EAAE,MAAM,CAAC,CAAe,CAAC;QAC9F,IAAI,MAAM,EAAE,CAAC,KAAK,mBAAmB;YAAE,OAAO,IAAI,CAAC;QACnD,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,MAAM,CAAC;QACP,yEAAyE;QACzE,4DAA4D;QAC5D,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,IAAY,EAAE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E,CAAC;AAClD,CAAC;AAgBD,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,GAAQ,EACR,KAAiB,EACjB,SAAS,GAAiB,KAAK;IAE/B,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE;YAC/C,GAAG,eAAe;YAClB,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;YAC3B,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC;SACpC,CAAC,CAAC;QACH,OAAO,EAAE,EAAE,EAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACnE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf;;;;;WAKG;QACH,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;IACpG,CAAC;AACH,CAAC"}
|
package/dist/weekly.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The weekly summary as Markdown.
|
|
3
|
+
*
|
|
4
|
+
* `@trazum/core` decides what the week holds (`buildWeeklySummary`); this
|
|
5
|
+
* writes it down in the reader's language. Two rules shape the text, and
|
|
6
|
+
* `weekly.test.js` holds both:
|
|
7
|
+
*
|
|
8
|
+
* - **Every name is code.** A workload, a model and a command sit between
|
|
9
|
+
* backticks. GitHub does not turn an `@name` inside one into a mention, a
|
|
10
|
+
* label that happens to hold a `%` or a `$` is not read as a figure, and
|
|
11
|
+
* `strayFigures` skips code when it reads the finished text back.
|
|
12
|
+
* - **The marker is the last line.** It is what the Action finds a week's
|
|
13
|
+
* summary by, so a second run on the same day replaces the first instead of
|
|
14
|
+
* adding another.
|
|
15
|
+
*/
|
|
16
|
+
import type { BillFigures, WeeklySummary } from '@trazum/core';
|
|
17
|
+
import type { CliMessages } from './i18n/types.js';
|
|
18
|
+
/** The sentence a desktop notification carries: figures from the summary and no name from the logs. */
|
|
19
|
+
export declare function weeklyHeadline(summary: WeeklySummary, t: CliMessages): string;
|
|
20
|
+
export declare function renderWeekly(summary: WeeklySummary, t: CliMessages): string;
|
|
21
|
+
/**
|
|
22
|
+
* The summary and its notification line, or a refusal.
|
|
23
|
+
*
|
|
24
|
+
* Both are read back against `figures`, the dollar amounts and percentages the
|
|
25
|
+
* two weeks' bills hold. One that is in neither throws, naming it, and the
|
|
26
|
+
* caller writes nothing: a number nobody can find in the bill is not printed.
|
|
27
|
+
*/
|
|
28
|
+
export declare function checkedWeekly(summary: WeeklySummary, figures: BillFigures, t: CliMessages): {
|
|
29
|
+
markdown: string;
|
|
30
|
+
headline: string;
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=weekly.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"weekly.d.ts","sourceRoot":"","sources":["../src/weekly.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAgB,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAwBnD,uGAAuG;AACvG,wBAAgB,cAAc,CAAC,OAAO,EAAE,aAAa,EAAE,CAAC,EAAE,WAAW,GAAG,MAAM,CAS7E;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,EAAE,CAAC,EAAE,WAAW,GAAG,MAAM,CA2D3E;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,aAAa,EACtB,OAAO,EAAE,WAAW,EACpB,CAAC,EAAE,WAAW,GACb;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAMxC"}
|
package/dist/weekly.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The weekly summary as Markdown.
|
|
3
|
+
*
|
|
4
|
+
* `@trazum/core` decides what the week holds (`buildWeeklySummary`); this
|
|
5
|
+
* writes it down in the reader's language. Two rules shape the text, and
|
|
6
|
+
* `weekly.test.js` holds both:
|
|
7
|
+
*
|
|
8
|
+
* - **Every name is code.** A workload, a model and a command sit between
|
|
9
|
+
* backticks. GitHub does not turn an `@name` inside one into a mention, a
|
|
10
|
+
* label that happens to hold a `%` or a `$` is not read as a figure, and
|
|
11
|
+
* `strayFigures` skips code when it reads the finished text back.
|
|
12
|
+
* - **The marker is the last line.** It is what the Action finds a week's
|
|
13
|
+
* summary by, so a second run on the same day replaces the first instead of
|
|
14
|
+
* adding another.
|
|
15
|
+
*/
|
|
16
|
+
import { UNLABELLED, formatSignedUsd, formatUsd, strayFigures, weeklyMarker } from '@trazum/core';
|
|
17
|
+
/** A name from a log, made safe to sit in a code span on one line. */
|
|
18
|
+
const code = (name) => `\`${name.replace(/[`<>\r\n]+/g, ' ').trim()}\``;
|
|
19
|
+
const sign = (value) => (value > 0 ? '+' : value < 0 ? '-' : '');
|
|
20
|
+
function changeLines(change, t, unlabelled) {
|
|
21
|
+
const label = code(change.label === UNLABELLED ? unlabelled : change.label);
|
|
22
|
+
const action = t.plan.action(change.kind, label, code(change.model));
|
|
23
|
+
const title = change.routeTo === null ? action : `${action} ${t.plan.routeTo(code(change.routeTo), change.kind === 'route+batch')}`;
|
|
24
|
+
const lines = [];
|
|
25
|
+
const money = change.projectedSavingUsd !== null
|
|
26
|
+
? t.weekly.projected(formatUsd(change.projectedSavingUsd))
|
|
27
|
+
: t.weekly.stake(formatUsd(change.measuredStakeUsd ?? 0));
|
|
28
|
+
lines.push(`${change.rank}. **${title}.** ${money}`);
|
|
29
|
+
if (change.sliceUsd !== null && change.sliceCalls !== null) {
|
|
30
|
+
lines.push(` - ${t.weekly.measuredBefore(formatUsd(change.sliceUsd), change.sliceCalls.toLocaleString(t.numberLocale))}`);
|
|
31
|
+
}
|
|
32
|
+
for (const assumption of change.assumes)
|
|
33
|
+
lines.push(` - ${t.plan.assume(assumption)}`);
|
|
34
|
+
return lines;
|
|
35
|
+
}
|
|
36
|
+
/** The sentence a desktop notification carries: figures from the summary and no name from the logs. */
|
|
37
|
+
export function weeklyHeadline(summary, t) {
|
|
38
|
+
const cmp = summary.comparison;
|
|
39
|
+
const pct = cmp === null || cmp.deltaPct === null ? null : `${sign(cmp.deltaPct)}${Math.abs(cmp.deltaPct).toFixed(1)}%`;
|
|
40
|
+
return t.weekly.headline(formatUsd(summary.totalUsd), summary.calls.toLocaleString(t.numberLocale), cmp === null ? null : formatSignedUsd(cmp.deltaUsd), pct);
|
|
41
|
+
}
|
|
42
|
+
export function renderWeekly(summary, t) {
|
|
43
|
+
const n = (value) => value.toLocaleString(t.numberLocale);
|
|
44
|
+
const { current, previous } = summary;
|
|
45
|
+
const out = [];
|
|
46
|
+
out.push(`## ${t.weekly.heading(current.firstDay, current.lastDay)}`, '');
|
|
47
|
+
out.push(`### ${t.weekly.billHeading()}`, '');
|
|
48
|
+
if (summary.calls === 0 && summary.unpricedCalls === 0) {
|
|
49
|
+
out.push(t.weekly.noCalls(current.firstDay, current.lastDay));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
out.push(t.weekly.billTotal(formatUsd(summary.totalUsd), n(summary.calls)));
|
|
53
|
+
if (summary.models.length > 0) {
|
|
54
|
+
out.push('', `| ${t.weekly.colModel()} | ${t.weekly.colCalls()} | ${t.weekly.colUsd()} |`, '| --- | ---: | ---: |');
|
|
55
|
+
for (const row of summary.models)
|
|
56
|
+
out.push(`| ${code(row.model)} | ${n(row.calls)} | ${formatUsd(row.usd)} |`);
|
|
57
|
+
if (summary.moreModels > 0)
|
|
58
|
+
out.push('', t.weekly.moreModels(n(summary.moreModels)));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (summary.unpricedCalls > 0) {
|
|
62
|
+
out.push('', t.weekly.unpriced(summary.unpricedModels.map(code).join(', '), n(summary.unpricedCalls)));
|
|
63
|
+
}
|
|
64
|
+
if (summary.undatedExcluded > 0)
|
|
65
|
+
out.push('', t.weekly.undated(n(summary.undatedExcluded)));
|
|
66
|
+
out.push('', `### ${t.weekly.movedHeading(previous.firstDay, previous.lastDay)}`, '');
|
|
67
|
+
const cmp = summary.comparison;
|
|
68
|
+
if (cmp === null) {
|
|
69
|
+
out.push(t.weekly.noWeekBefore());
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
if (cmp.deltaUsd === 0) {
|
|
73
|
+
out.push(t.weekly.unchanged(formatUsd(summary.totalUsd), formatUsd(cmp.previousUsd)));
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
const pct = cmp.deltaPct === null ? null : `${sign(cmp.deltaPct)}${Math.abs(cmp.deltaPct).toFixed(1)}%`;
|
|
77
|
+
out.push(t.weekly.moved(formatSignedUsd(cmp.deltaUsd), pct, formatUsd(summary.totalUsd), formatUsd(cmp.previousUsd), n(cmp.previousCalls)));
|
|
78
|
+
}
|
|
79
|
+
if (cmp.movers.length > 0) {
|
|
80
|
+
out.push('', t.weekly.moversHeading(), '');
|
|
81
|
+
for (const row of cmp.movers) {
|
|
82
|
+
out.push(`- ${t.weekly.mover(code(row.model), formatUsd(row.previousUsd), formatUsd(row.currentUsd), formatSignedUsd(row.deltaUsd))}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
out.push('', `### ${t.weekly.changesHeading()}`, '');
|
|
87
|
+
if (summary.changes.length === 0) {
|
|
88
|
+
out.push(t.weekly.noChanges());
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
summary.changes.forEach((change, index) => {
|
|
92
|
+
if (index > 0)
|
|
93
|
+
out.push('');
|
|
94
|
+
out.push(...changeLines(change, t, t.profile.unlabelled()));
|
|
95
|
+
});
|
|
96
|
+
const more = summary.changesAvailable - summary.changes.length;
|
|
97
|
+
if (more > 0)
|
|
98
|
+
out.push('', t.weekly.moreChanges(n(more)));
|
|
99
|
+
out.push('', t.weekly.verifyHow());
|
|
100
|
+
}
|
|
101
|
+
out.push('', `_${t.weekly.footer()}_`, '', weeklyMarker(current.lastDay), '');
|
|
102
|
+
return out.join('\n');
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The summary and its notification line, or a refusal.
|
|
106
|
+
*
|
|
107
|
+
* Both are read back against `figures`, the dollar amounts and percentages the
|
|
108
|
+
* two weeks' bills hold. One that is in neither throws, naming it, and the
|
|
109
|
+
* caller writes nothing: a number nobody can find in the bill is not printed.
|
|
110
|
+
*/
|
|
111
|
+
export function checkedWeekly(summary, figures, t) {
|
|
112
|
+
const markdown = renderWeekly(summary, t);
|
|
113
|
+
const headline = weeklyHeadline(summary, t);
|
|
114
|
+
const stray = [...strayFigures(markdown, figures), ...strayFigures(headline, figures)];
|
|
115
|
+
if (stray.length > 0)
|
|
116
|
+
throw new Error(t.weekly.strayFigures([...new Set(stray)].join(', ')));
|
|
117
|
+
return { markdown, headline };
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=weekly.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"weekly.js","sourceRoot":"","sources":["../src/weekly.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAIlG,sEAAsE;AACtE,MAAM,IAAI,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,KAAK,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,IAA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AAQ,GAAG,cAAc,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IAC5C,MAAM,KAAK,GAAG,CAAC,GAAG,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,GAAG,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;IACvF,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC7F,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;AAChC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trazum/cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "What your AI agents cost, per project, offline: one bill across Claude Code, Codex and Gemini CLI sessions, plus Anthropic, OpenAI, Gemini, OpenRouter, OTel and LiteLLM usage, written as PDF, HTML or CSV, with budgets enforced in CI.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "David Mu\u00f1oz Rey",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"files": [
|
|
44
44
|
"dist",
|
|
45
45
|
"src",
|
|
46
|
+
"assets",
|
|
46
47
|
"LICENSE",
|
|
47
48
|
"README.md"
|
|
48
49
|
],
|
|
@@ -53,7 +54,7 @@
|
|
|
53
54
|
"prepublishOnly": "npm run build && npm test"
|
|
54
55
|
},
|
|
55
56
|
"dependencies": {
|
|
56
|
-
"@trazum/core": "
|
|
57
|
+
"@trazum/core": "3.0.0"
|
|
57
58
|
},
|
|
58
59
|
"devDependencies": {
|
|
59
60
|
"@types/node": "^26.6.6",
|
package/src/git.ts
CHANGED
|
@@ -219,6 +219,83 @@ export function runSelf(scriptPath: string, args: readonly string[]): string {
|
|
|
219
219
|
return result.stdout;
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
+
/** What `crontab` said: its exit status and both streams, or the error that kept it from starting. */
|
|
223
|
+
export interface CrontabResult {
|
|
224
|
+
status: number | null;
|
|
225
|
+
stdout: string;
|
|
226
|
+
stderr: string;
|
|
227
|
+
/** `ENOENT` when there is no `crontab` program on this machine. */
|
|
228
|
+
errorCode: string | null;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Runs the system `crontab` with one of its two fixed argument lists.
|
|
233
|
+
*
|
|
234
|
+
* `trazum proactive` reads the user's crontab with `crontab -l` and writes it
|
|
235
|
+
* back with `crontab -`, the text on stdin. It is here, beside the other two
|
|
236
|
+
* spawns, so the invariant the security suite asserts, that child_process
|
|
237
|
+
* appears in exactly one file, stays whole. The same rules: no shell, and
|
|
238
|
+
* **no argument of anybody's**: the argv is one of two literals, and the text
|
|
239
|
+
* that changes travels on stdin, where a `;` is a character and not a command.
|
|
240
|
+
*/
|
|
241
|
+
export function runCrontab(args: readonly ['-l'] | readonly ['-'], input?: string): CrontabResult {
|
|
242
|
+
const result = spawnSync('crontab', [...args], {
|
|
243
|
+
shell: false,
|
|
244
|
+
encoding: 'utf8',
|
|
245
|
+
timeout: TIMEOUT_MS,
|
|
246
|
+
maxBuffer: MAX_BUFFER,
|
|
247
|
+
...(input === undefined ? {} : { input }),
|
|
248
|
+
});
|
|
249
|
+
const code = result.error !== undefined && 'code' in result.error ? String((result.error as { code: unknown }).code) : null;
|
|
250
|
+
return {
|
|
251
|
+
status: result.status,
|
|
252
|
+
stdout: typeof result.stdout === 'string' ? result.stdout : '',
|
|
253
|
+
stderr: typeof result.stderr === 'string' ? result.stderr : '',
|
|
254
|
+
errorCode: result.error === undefined ? null : (code ?? 'ERROR'),
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** What a desktop notifier said: its exit status and stderr, or the error that kept it from starting. */
|
|
259
|
+
export interface NotifierRun {
|
|
260
|
+
status: number | null;
|
|
261
|
+
stderr: string;
|
|
262
|
+
/** `ENOENT` when this machine has no such program. */
|
|
263
|
+
errorCode: string | null;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Runs the platform's notifier, for `trazum watch --notify`.
|
|
268
|
+
*
|
|
269
|
+
* It is here, beside the other spawns, so the invariant the security suite
|
|
270
|
+
* asserts, that child_process appears in exactly one file, stays whole. The
|
|
271
|
+
* same rules: no shell, a timeout so a notifier that hangs cannot hang the
|
|
272
|
+
* watcher, and output bounded. The command is one of three literals, and the
|
|
273
|
+
* argument list is built by `watch-notify.ts`, which hands the text over as
|
|
274
|
+
* data (arguments of a fixed script, an environment variable, or after `--`)
|
|
275
|
+
* and never splices it into anything a program would run.
|
|
276
|
+
*/
|
|
277
|
+
export function runNotifier(
|
|
278
|
+
command: 'osascript' | 'notify-send' | 'powershell.exe',
|
|
279
|
+
args: readonly string[],
|
|
280
|
+
env: NodeJS.ProcessEnv,
|
|
281
|
+
): NotifierRun {
|
|
282
|
+
const result = spawnSync(command, [...args], {
|
|
283
|
+
shell: false,
|
|
284
|
+
encoding: 'utf8',
|
|
285
|
+
timeout: TIMEOUT_MS,
|
|
286
|
+
maxBuffer: MAX_BUFFER,
|
|
287
|
+
windowsHide: true,
|
|
288
|
+
stdio: ['ignore', 'ignore', 'pipe'],
|
|
289
|
+
env,
|
|
290
|
+
});
|
|
291
|
+
const code = result.error !== undefined && 'code' in result.error ? String((result.error as { code: unknown }).code) : null;
|
|
292
|
+
return {
|
|
293
|
+
status: result.status,
|
|
294
|
+
stderr: typeof result.stderr === 'string' ? result.stderr : '',
|
|
295
|
+
errorCode: result.error === undefined ? null : (code ?? 'ERROR'),
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
222
299
|
/**
|
|
223
300
|
* Commits that touched `repoPath`, newest first.
|
|
224
301
|
*
|