@trazum/cli 3.0.0 → 3.0.2
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 -1
- package/assets/trazum-statusline.sh +45 -0
- package/dist/base-cost.d.ts +173 -0
- package/dist/base-cost.d.ts.map +1 -0
- package/dist/base-cost.js +244 -0
- package/dist/base-cost.js.map +1 -0
- package/dist/bill-range.d.ts +118 -0
- package/dist/bill-range.d.ts.map +1 -0
- package/dist/bill-range.js +122 -0
- package/dist/bill-range.js.map +1 -0
- package/dist/command-help.d.ts +17 -0
- package/dist/command-help.d.ts.map +1 -0
- package/dist/command-help.js +69 -0
- package/dist/command-help.js.map +1 -0
- package/dist/filter.d.ts +7 -1
- package/dist/filter.d.ts.map +1 -1
- package/dist/filter.js +10 -18
- package/dist/filter.js.map +1 -1
- package/dist/gateway-metrics.d.ts +83 -0
- package/dist/gateway-metrics.d.ts.map +1 -0
- package/dist/gateway-metrics.js +181 -0
- package/dist/gateway-metrics.js.map +1 -0
- package/dist/gateway-server.d.ts +23 -5
- package/dist/gateway-server.d.ts.map +1 -1
- package/dist/gateway-server.js +26 -1
- package/dist/gateway-server.js.map +1 -1
- package/dist/gateway-spend.d.ts +11 -1
- package/dist/gateway-spend.d.ts.map +1 -1
- package/dist/gateway-spend.js +44 -32
- package/dist/gateway-spend.js.map +1 -1
- package/dist/git.d.ts +70 -0
- package/dist/git.d.ts.map +1 -1
- package/dist/git.js +145 -0
- package/dist/git.js.map +1 -1
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +358 -6
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/es.d.ts +0 -1
- package/dist/i18n/es.d.ts.map +1 -1
- package/dist/i18n/es.js +456 -35
- package/dist/i18n/es.js.map +1 -1
- package/dist/i18n/types.d.ts +205 -0
- package/dist/i18n/types.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +942 -59
- package/dist/index.js.map +1 -1
- package/dist/loopback-guard.d.ts +37 -0
- package/dist/loopback-guard.d.ts.map +1 -0
- package/dist/loopback-guard.js +65 -0
- package/dist/loopback-guard.js.map +1 -0
- package/dist/markdown.d.ts +23 -0
- package/dist/markdown.d.ts.map +1 -1
- package/dist/markdown.js +105 -0
- package/dist/markdown.js.map +1 -1
- package/dist/plan-edits.d.ts +63 -0
- package/dist/plan-edits.d.ts.map +1 -0
- package/dist/plan-edits.js +96 -0
- package/dist/plan-edits.js.map +1 -0
- package/dist/proactive.d.ts +17 -2
- package/dist/proactive.d.ts.map +1 -1
- package/dist/proactive.js +16 -9
- package/dist/proactive.js.map +1 -1
- package/dist/receipt-send.d.ts +44 -0
- package/dist/receipt-send.d.ts.map +1 -0
- package/dist/receipt-send.js +71 -0
- package/dist/receipt-send.js.map +1 -0
- package/dist/serve.d.ts +7 -0
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +22 -1
- package/dist/serve.js.map +1 -1
- package/dist/session-guard.d.ts +210 -0
- package/dist/session-guard.d.ts.map +1 -0
- package/dist/session-guard.js +463 -0
- package/dist/session-guard.js.map +1 -0
- package/dist/task.d.ts +7 -1
- package/dist/task.d.ts.map +1 -1
- package/dist/task.js +7 -26
- package/dist/task.js.map +1 -1
- package/dist/waste.d.ts +25 -0
- package/dist/waste.d.ts.map +1 -0
- package/dist/waste.js +39 -0
- package/dist/waste.js.map +1 -0
- package/dist/zone.d.ts +27 -0
- package/dist/zone.d.ts.map +1 -0
- package/dist/zone.js +96 -0
- package/dist/zone.js.map +1 -0
- package/package.json +2 -2
- package/src/base-cost.ts +384 -0
- package/src/bill-range.ts +206 -0
- package/src/command-help.ts +65 -0
- package/src/filter.ts +11 -18
- package/src/gateway-metrics.ts +209 -0
- package/src/gateway-server.ts +43 -6
- package/src/gateway-spend.ts +45 -33
- package/src/git.ts +158 -0
- package/src/i18n/en.ts +424 -6
- package/src/i18n/es.ts +542 -35
- package/src/i18n/types.ts +208 -0
- package/src/index.ts +952 -58
- package/src/loopback-guard.ts +74 -0
- package/src/markdown.ts +117 -0
- package/src/plan-edits.ts +120 -0
- package/src/proactive.ts +22 -13
- package/src/receipt-send.ts +89 -0
- package/src/serve.ts +23 -1
- package/src/session-guard.ts +541 -0
- package/src/task.ts +8 -26
- package/src/waste.ts +42 -0
- package/src/zone.ts +95 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `trazum bill --receipt --send <url>`: the receipt, posted to the endpoint
|
|
3
|
+
* an organisation named, and nothing else.
|
|
4
|
+
*
|
|
5
|
+
* Three properties, each held by `packages/cli/test/bill-send.test.js`:
|
|
6
|
+
*
|
|
7
|
+
* - **Only the receipt leaves.** `sendReceipt` takes the bytes the same run
|
|
8
|
+
* wrote and posts them as they are. It is handed no log line, no path and no
|
|
9
|
+
* prompt, so there is nothing else for it to send.
|
|
10
|
+
* - **The key is read here and goes nowhere but the header.** It comes from
|
|
11
|
+
* `TRAZUM_RECEIPT_KEY`, never from a flag, and this module has no `console`:
|
|
12
|
+
* what it returns is already scrubbed of the key, and the caller prints that.
|
|
13
|
+
* - **The URL is `watch --webhook`'s.** `checkWebhook` is imported, not copied:
|
|
14
|
+
* https except on loopback, no credentials in the URL. Redirects are refused
|
|
15
|
+
* by `SAFE_FETCH_INIT`, so a response from somewhere else never arrives.
|
|
16
|
+
*
|
|
17
|
+
* One request, one attempt, awaited: no retry and nothing in the background.
|
|
18
|
+
*/
|
|
19
|
+
import { SAFE_FETCH_INIT } from '@trazum/core/node';
|
|
20
|
+
import { redact } from './connect.js';
|
|
21
|
+
import { checkWebhook } from './watch-run.js';
|
|
22
|
+
/** The environment variable the key is read from. A flag would end up in shell history. */
|
|
23
|
+
export const RECEIPT_KEY_ENV = 'TRAZUM_RECEIPT_KEY';
|
|
24
|
+
/** How much of a response body is shown. An endpoint's error page is not ours to print whole. */
|
|
25
|
+
const BODY_LIMIT = 2000;
|
|
26
|
+
/**
|
|
27
|
+
* Whether this URL and this key are ones a receipt may be sent with.
|
|
28
|
+
* Checked before any log is read, so a refusal costs nothing.
|
|
29
|
+
*/
|
|
30
|
+
export function checkReceiptTarget(raw, env = process.env) {
|
|
31
|
+
const checked = checkWebhook(raw);
|
|
32
|
+
if (!checked.ok)
|
|
33
|
+
return checked;
|
|
34
|
+
const key = env[RECEIPT_KEY_ENV];
|
|
35
|
+
if (key === undefined || key === '')
|
|
36
|
+
return { ok: true, url: checked.url, key: undefined };
|
|
37
|
+
// A header value with a space, a control character or a non-ASCII byte is
|
|
38
|
+
// one the HTTP client refuses by quoting it back in its error.
|
|
39
|
+
if (!/^[\x21-\x7e]+$/.test(key))
|
|
40
|
+
return { ok: false, reason: 'bad-key' };
|
|
41
|
+
return { ok: true, url: checked.url, key };
|
|
42
|
+
}
|
|
43
|
+
const scrub = (text, key) => {
|
|
44
|
+
let out = text;
|
|
45
|
+
if (key !== undefined && key !== '')
|
|
46
|
+
out = out.split(key).join('[redacted]');
|
|
47
|
+
return redact(out);
|
|
48
|
+
};
|
|
49
|
+
export async function sendReceipt(url, key, body, fetchImpl = fetch) {
|
|
50
|
+
try {
|
|
51
|
+
const response = await fetchImpl(url.toString(), {
|
|
52
|
+
...SAFE_FETCH_INIT,
|
|
53
|
+
method: 'POST',
|
|
54
|
+
headers: {
|
|
55
|
+
'content-type': 'application/json',
|
|
56
|
+
...(key !== undefined ? { authorization: `Bearer ${key}` } : {}),
|
|
57
|
+
},
|
|
58
|
+
body,
|
|
59
|
+
signal: AbortSignal.timeout(10_000),
|
|
60
|
+
});
|
|
61
|
+
// Scrubbed before it is cut, so a key that straddles the limit is not left half shown.
|
|
62
|
+
const text = scrub(await response.text(), key).slice(0, BODY_LIMIT).trim();
|
|
63
|
+
return { ok: response.ok, status: response.status, detail: text };
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
const cause = error instanceof Error && error.cause instanceof Error ? ` (${error.cause.message})` : '';
|
|
67
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
68
|
+
return { ok: false, status: null, detail: scrub(`${message}${cause}`, key) };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=receipt-send.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"receipt-send.js","sourceRoot":"","sources":["../src/receipt-send.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,YAAY,EAAyB,MAAM,gBAAgB,CAAC;AAErE,2FAA2F;AAC3F,MAAM,CAAC,MAAM,eAAe,GAAG,oBAAoB,CAAC;AAEpD,iGAAiG;AACjG,MAAM,UAAU,GAAG,IAAI,CAAC;AAMxB;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAW,EAAE,GAAG,GAAsB,OAAO,CAAC,GAAG;IAClF,MAAM,OAAO,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,CAAC,OAAO,CAAC,EAAE;QAAE,OAAO,OAAO,CAAC;IAChC,MAAM,GAAG,GAAG,GAAG,CAAC,eAAe,CAAC,CAAC;IACjC,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,EAAE;QAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC;IAC3F,0EAA0E;IAC1E,+DAA+D;IAC/D,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IACzE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC;AAC7C,CAAC;AAWD,MAAM,KAAK,GAAG,CAAC,IAAY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CAAC,CAAC,CAAC,EAAE,CAAC;QACxG,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,OAAO,GAAG,KAAK,EAAE,EAAE,GAAG,CAAC,EAAE,CAAC;IAC/E,CAAC;AACH,CAAC"}
|
package/dist/serve.d.ts
CHANGED
|
@@ -10,6 +10,13 @@
|
|
|
10
10
|
* being no way to say otherwise. `127.0.0.1` is compiled in. A Unix socket is
|
|
11
11
|
* offered for callers that would rather not use a port at all.
|
|
12
12
|
*
|
|
13
|
+
* **A web page on this machine is not "only the local machine".** A page can
|
|
14
|
+
* rebind its own hostname to 127.0.0.1 and read what this answers. So a
|
|
15
|
+
* request whose `Host` is not a loopback name on the bound port is refused
|
|
16
|
+
* with 403, and a POST without `content-type: application/json` with 415,
|
|
17
|
+
* which a page cannot send cross-origin without a preflight nothing answers.
|
|
18
|
+
* See `loopback-guard.ts`.
|
|
19
|
+
*
|
|
13
20
|
* **No auth, on purpose.** Anything reachable only from the machine it runs on
|
|
14
21
|
* is already behind the operating system's own boundary, and a token checked
|
|
15
22
|
* over loopback is theatre: whoever can reach the socket can read the token
|
package/dist/serve.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAOH,OAAO,KAAK,EAAmB,MAAM,EAAkB,MAAM,WAAW,CAAC;AAEzE,OAAO,KAAK,EAAc,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE7G,0EAA0E;AAC1E,eAAO,MAAM,SAAS,cAAc,CAAC;AAErC,eAAO,MAAM,YAAY,OAAO,CAAC;AAEjC;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,UAAY,CAAC;AAExC,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,gBAAgB,CAAC;IAC5B;;;;;;;;OAQG;IACH,QAAQ,EAAE,MAAM;QAAE,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE;YAAE,MAAM,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,GAAG,IAAI,CAAA;KAAE,CAAC;IAC9G,uDAAuD;IACvD,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,gBAAgB,CAAC;IAC5E,kFAAkF;IAClF,OAAO,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;CACjC;AAyBD,wBAAgB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,CA2IzD;AAED,MAAM,WAAW,YAAY;IAC3B,uEAAuE;IACvE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAa5E"}
|
package/dist/serve.js
CHANGED
|
@@ -10,6 +10,13 @@
|
|
|
10
10
|
* being no way to say otherwise. `127.0.0.1` is compiled in. A Unix socket is
|
|
11
11
|
* offered for callers that would rather not use a port at all.
|
|
12
12
|
*
|
|
13
|
+
* **A web page on this machine is not "only the local machine".** A page can
|
|
14
|
+
* rebind its own hostname to 127.0.0.1 and read what this answers. So a
|
|
15
|
+
* request whose `Host` is not a loopback name on the bound port is refused
|
|
16
|
+
* with 403, and a POST without `content-type: application/json` with 415,
|
|
17
|
+
* which a page cannot send cross-origin without a preflight nothing answers.
|
|
18
|
+
* See `loopback-guard.ts`.
|
|
19
|
+
*
|
|
13
20
|
* **No auth, on purpose.** Anything reachable only from the machine it runs on
|
|
14
21
|
* is already behind the operating system's own boundary, and a token checked
|
|
15
22
|
* over loopback is theatre: whoever can reach the socket can read the token
|
|
@@ -23,6 +30,7 @@
|
|
|
23
30
|
* into a hot path.
|
|
24
31
|
*/
|
|
25
32
|
import { createServer } from 'node:http';
|
|
33
|
+
import { refuseContentType, refuseHost } from './loopback-guard.js';
|
|
26
34
|
import { importUsage, validateImportPayload } from './serve-import.js';
|
|
27
35
|
import { planSavings, verifySavings, validateSavingsPayload } from './serve-savings.js';
|
|
28
36
|
import { SERVE_OPENAPI, validateCostPayload } from './serve-schema.js';
|
|
@@ -61,8 +69,15 @@ const send = (response, status, body) => {
|
|
|
61
69
|
response.end(text);
|
|
62
70
|
};
|
|
63
71
|
export function buildServer(context) {
|
|
64
|
-
|
|
72
|
+
const server = createServer((request, response) => {
|
|
65
73
|
void (async () => {
|
|
74
|
+
// Before anything is routed: a page that rebound its own hostname to
|
|
75
|
+
// this address must not read an answer, not even a 404.
|
|
76
|
+
const refused = refuseHost(server, request);
|
|
77
|
+
if (refused !== null) {
|
|
78
|
+
send(response, refused.status, { error: refused.error, detail: refused.detail });
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
66
81
|
const url = new URL(request.url ?? '/', `http://${BIND_HOST}`);
|
|
67
82
|
if (request.method === 'GET' && url.pathname === '/capabilities') {
|
|
68
83
|
send(response, 200, HARNESS_CAPABILITIES);
|
|
@@ -85,6 +100,11 @@ export function buildServer(context) {
|
|
|
85
100
|
});
|
|
86
101
|
return;
|
|
87
102
|
}
|
|
103
|
+
const untyped = refuseContentType(request);
|
|
104
|
+
if (untyped !== null) {
|
|
105
|
+
send(response, untyped.status, { error: untyped.error, detail: untyped.detail });
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
88
108
|
let payload;
|
|
89
109
|
try {
|
|
90
110
|
const raw = await readBody(request);
|
|
@@ -174,6 +194,7 @@ export function buildServer(context) {
|
|
|
174
194
|
send(response, 200, { ...answer, policy });
|
|
175
195
|
})();
|
|
176
196
|
});
|
|
197
|
+
return server;
|
|
177
198
|
}
|
|
178
199
|
export function listen(server, target) {
|
|
179
200
|
return new Promise((resolve, reject) => {
|
package/dist/serve.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.js","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"serve.js","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AACxF,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAEvE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAG7E,0EAA0E;AAC1E,MAAM,CAAC,MAAM,SAAS,GAAG,WAAW,CAAC;AAErC,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,CAAC;AAEjC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAC;AAyBxC,KAAK,UAAU,QAAQ,CAAC,OAAwB;IAC9C,MAAM,MAAM,GAAa,E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,CAAC,CAAC,qBAAqB;iBACvE,CAAC,CAAC;gBACH,OAAO;YACT,CAAC;YACD,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QAC7C,CAAC,CAAC,EAAE,CAAC;IACP,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC;AAQD,MAAM,UAAU,MAAM,CAAC,MAAc,EAAE,MAAoB;IACzD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC7B,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAChC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,MAAO,CAAC,CAAC,CAAC;YAC5D,OAAO;QACT,CAAC;QACD,oDAAoD;QACpD,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,IAAI,YAAY,EAAE,SAAS,EAAE,GAAG,EAAE;YACzD,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;YACjC,OAAO,CAAC,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,SAAS,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;QAC9G,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `trazum session-guard`: a Claude Code hook that warns, then stops, at two
|
|
3
|
+
* dollar figures the person chose.
|
|
4
|
+
*
|
|
5
|
+
* It is built on the machinery `trazum proactive` already has, and borrows it
|
|
6
|
+
* rather than copying it:
|
|
7
|
+
*
|
|
8
|
+
* - **The same door for every write.** The settings file is changed through
|
|
9
|
+
* `applyChange` and read through `readJsonObject`, so the same refusals hold
|
|
10
|
+
* (a symbolic link, a file that changed since it was read, a file `JSON.parse`
|
|
11
|
+
* rejects) and the same backup is kept beside the file the first time.
|
|
12
|
+
* - **The same record of what was added.** `~/.trazum/proactive.json` gains a
|
|
13
|
+
* `guard` entry, so `uninstall` removes the hook and the containers this
|
|
14
|
+
* command created and leaves every hook that was the person's.
|
|
15
|
+
* - **The same reading of the session.** The running session's transcript is
|
|
16
|
+
* converted by `claudeCodeRecords`, as `from-claude-code` does, with its
|
|
17
|
+
* subagents' transcripts as the status line script reads them, and priced by
|
|
18
|
+
* `profileUsage` at the bundled, dated catalogue.
|
|
19
|
+
* - **The same place for state.** "The warning was given" is a file in the
|
|
20
|
+
* status line's cache directory, `TRAZUM_STATUSLINE_CACHE` or
|
|
21
|
+
* `$TMPDIR/trazum-statusline`. Nothing is written anywhere else.
|
|
22
|
+
*
|
|
23
|
+
* **The hook protocol.** Claude Code's hooks page, read on 2026-11-19
|
|
24
|
+
* (code.claude.com/docs/en/hooks), says:
|
|
25
|
+
*
|
|
26
|
+
* - A command hook gets `session_id` and `transcript_path` as JSON on stdin.
|
|
27
|
+
* - "Exit with code 2 to block the action. On events that can block, Claude Code
|
|
28
|
+
* stops the action: a `PreToolUse` hook blocks the tool call, for example, and
|
|
29
|
+
* a `UserPromptSubmit` hook rejects the prompt." Stderr is the reason, shown
|
|
30
|
+
* to Claude (PreToolUse) or as the block reason (UserPromptSubmit).
|
|
31
|
+
* - Exit 0 with no output is "no decision": the action goes ahead.
|
|
32
|
+
* - `systemMessage` in JSON on stdout at exit 0 is a "warning message shown to
|
|
33
|
+
* the user". Plain stdout on UserPromptSubmit is added as context for the
|
|
34
|
+
* model, which is why a warning is never printed as plain text: it would cost
|
|
35
|
+
* tokens and change what the model reads.
|
|
36
|
+
*
|
|
37
|
+
* So a stop is exit code 2 with the reason on stderr, on both events, and a
|
|
38
|
+
* warning is `{"systemMessage": ...}` on stdout with exit 0.
|
|
39
|
+
*
|
|
40
|
+
* **Nothing has a default.** Two thresholds and a failure policy are required,
|
|
41
|
+
* and a missing one is refused by name. A threshold is a decision about money
|
|
42
|
+
* and the policy is a decision about which failure to accept; neither is
|
|
43
|
+
* Trazum's to make.
|
|
44
|
+
*
|
|
45
|
+
* **Never $0 by guessing.** A transcript that cannot be read, a model with no
|
|
46
|
+
* price, or no transcript at all is "cannot tell". What happens then is
|
|
47
|
+
* `--on-cannot-tell`, with the meaning the gateway gives it: `fail-open` lets
|
|
48
|
+
* the work go on and says so, `fail-closed` stops it and says so. The one thing
|
|
49
|
+
* it never does is count the unpriced calls as free. When the calls that were
|
|
50
|
+
* priced already reach a threshold, that is a floor and the threshold holds.
|
|
51
|
+
*
|
|
52
|
+
* Nothing here sends anything anywhere.
|
|
53
|
+
*/
|
|
54
|
+
import type { FailurePolicy, PricingCatalogue } from '@trazum/core';
|
|
55
|
+
import type { CliMessages } from './i18n/index.js';
|
|
56
|
+
import type { Change, Ctx, Finding, Manifest, Obj } from './proactive.js';
|
|
57
|
+
export interface Thresholds {
|
|
58
|
+
warnUsd: number;
|
|
59
|
+
stopUsd: number;
|
|
60
|
+
policy: FailurePolicy;
|
|
61
|
+
}
|
|
62
|
+
export type ThresholdRefusal = {
|
|
63
|
+
code: 'missing';
|
|
64
|
+
flags: string[];
|
|
65
|
+
} | {
|
|
66
|
+
code: 'notAmount';
|
|
67
|
+
flag: string;
|
|
68
|
+
given: string;
|
|
69
|
+
} | {
|
|
70
|
+
code: 'badPolicy';
|
|
71
|
+
given: string;
|
|
72
|
+
allowed: string;
|
|
73
|
+
} | {
|
|
74
|
+
code: 'warnNotBelowStop';
|
|
75
|
+
};
|
|
76
|
+
/** Both amounts and the policy, as given, or the first thing wrong with them. */
|
|
77
|
+
export declare function parseThresholds(given: {
|
|
78
|
+
warn: string | undefined;
|
|
79
|
+
stop: string | undefined;
|
|
80
|
+
policy: string | undefined;
|
|
81
|
+
}): {
|
|
82
|
+
ok: true;
|
|
83
|
+
thresholds: Thresholds;
|
|
84
|
+
} | {
|
|
85
|
+
ok: false;
|
|
86
|
+
refusal: ThresholdRefusal;
|
|
87
|
+
};
|
|
88
|
+
export type CannotTellCause = 'no-transcript' | 'unreadable' | 'unparseable' | 'skipped';
|
|
89
|
+
export type SessionCost = {
|
|
90
|
+
kind: 'measured';
|
|
91
|
+
usd: number;
|
|
92
|
+
}
|
|
93
|
+
/** Some calls are on a model with no price: `usd` is what the priced ones cost, and the truth is more. */
|
|
94
|
+
| {
|
|
95
|
+
kind: 'floor';
|
|
96
|
+
usd: number;
|
|
97
|
+
unpricedModels: string[];
|
|
98
|
+
} | {
|
|
99
|
+
kind: 'cannot-tell';
|
|
100
|
+
cause: CannotTellCause;
|
|
101
|
+
};
|
|
102
|
+
export declare function jsonlFiles(folder: string): Promise<string[] | null>;
|
|
103
|
+
/**
|
|
104
|
+
* What the running session has cost so far, at the catalogue, or why that
|
|
105
|
+
* cannot be said.
|
|
106
|
+
*
|
|
107
|
+
* The transcript is the session's own file and its subagents' transcripts are
|
|
108
|
+
* in the folder beside it named after the session: the status line script reads
|
|
109
|
+
* them the same way, and says what leaving them out cost.
|
|
110
|
+
*/
|
|
111
|
+
export declare function sessionCost(transcriptPath: unknown, catalogue: PricingCatalogue, on: Date): Promise<SessionCost>;
|
|
112
|
+
export type Decision = {
|
|
113
|
+
action: 'allow';
|
|
114
|
+
} | {
|
|
115
|
+
action: 'warn';
|
|
116
|
+
usd: number;
|
|
117
|
+
atLeast: boolean;
|
|
118
|
+
} | {
|
|
119
|
+
action: 'block';
|
|
120
|
+
usd: number;
|
|
121
|
+
atLeast: boolean;
|
|
122
|
+
} | {
|
|
123
|
+
action: 'allow-cannot-tell';
|
|
124
|
+
cause: CannotTellCause | 'unpriced';
|
|
125
|
+
models: string[];
|
|
126
|
+
} | {
|
|
127
|
+
action: 'block-cannot-tell';
|
|
128
|
+
cause: CannotTellCause | 'unpriced';
|
|
129
|
+
models: string[];
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Thresholds against cost, and the policy where the cost cannot be said.
|
|
133
|
+
*
|
|
134
|
+
* The comparison is "at or over": a session at exactly the stop figure is
|
|
135
|
+
* stopped. A floor counts as far as it goes: calls that were priced and already
|
|
136
|
+
* reach a threshold are a fact, and the unpriced ones can only add to it.
|
|
137
|
+
*/
|
|
138
|
+
export declare function decide(cost: SessionCost, thresholds: Thresholds): Decision;
|
|
139
|
+
/** The status line's cache directory, as its script resolves it. */
|
|
140
|
+
export declare function stateDir(env: NodeJS.ProcessEnv): string;
|
|
141
|
+
export declare function alreadyGiven(dir: string, session: string, kind: 'warned' | 'cannot-tell'): Promise<boolean>;
|
|
142
|
+
/** Never throws: a notice that cannot be remembered is given again, which is the safe direction. */
|
|
143
|
+
export declare function remember(dir: string, session: string, kind: 'warned' | 'cannot-tell'): Promise<void>;
|
|
144
|
+
/** The events the hook is wired to, both of which can block. */
|
|
145
|
+
export declare const GUARD_EVENTS: readonly ['UserPromptSubmit', 'PreToolUse'];
|
|
146
|
+
export type GuardEvent = (typeof GUARD_EVENTS)[number];
|
|
147
|
+
/** The command written into the settings: the CLI that stays, then the exact thresholds. */
|
|
148
|
+
export declare function guardCommand(node: string, entry: string, thresholds: Thresholds): string;
|
|
149
|
+
/**
|
|
150
|
+
* Whether a command is the one `guardCommand` writes, and what it carries.
|
|
151
|
+
*
|
|
152
|
+
* JSON has no comments, so a hook is Trazum's by being exactly this shape. A
|
|
153
|
+
* hook of the person's that merely mentions `session-guard` is not matched.
|
|
154
|
+
*/
|
|
155
|
+
export declare function parseGuardCommand(command: string): {
|
|
156
|
+
node: string;
|
|
157
|
+
entry: string;
|
|
158
|
+
thresholds: Thresholds;
|
|
159
|
+
} | null;
|
|
160
|
+
export interface GuardView {
|
|
161
|
+
/** The thresholds of the hooks that are ours, by event; an event with none is absent. */
|
|
162
|
+
found: Partial<Record<GuardEvent, Thresholds>>;
|
|
163
|
+
/** The key whose shape this command cannot edit, when there is one. */
|
|
164
|
+
shape: string | null;
|
|
165
|
+
}
|
|
166
|
+
export declare function viewGuard(settings: Obj): GuardView;
|
|
167
|
+
/** Adds the hook to each event, or rewrites ours there; touches no other hook. Returns the containers it created. */
|
|
168
|
+
export declare function withGuard(settings: Obj, command: string): string[];
|
|
169
|
+
/** Removes exactly the hooks `withGuard` wrote, and the containers it made when they are empty. */
|
|
170
|
+
export declare function withoutGuard(settings: Obj, created: string[]): void;
|
|
171
|
+
export interface CheckResult {
|
|
172
|
+
/** What goes to standard output: JSON for Claude Code, or nothing. */
|
|
173
|
+
stdout: string;
|
|
174
|
+
/** What goes to standard error: the reason, when the exit code is 2. */
|
|
175
|
+
stderr: string;
|
|
176
|
+
/** 0 lets the action go on. 2 is the code the hooks page documents for blocking it. */
|
|
177
|
+
code: 0 | 2;
|
|
178
|
+
}
|
|
179
|
+
/** One hook call: the JSON Claude Code wrote on stdin, in; what to print and how to exit, out. */
|
|
180
|
+
export declare function check(stdin: string, thresholds: Thresholds, options: {
|
|
181
|
+
catalogue: PricingCatalogue;
|
|
182
|
+
env: NodeJS.ProcessEnv;
|
|
183
|
+
now: Date;
|
|
184
|
+
t: CliMessages;
|
|
185
|
+
}): Promise<CheckResult>;
|
|
186
|
+
export type GuardPlan = {
|
|
187
|
+
kind: 'refused';
|
|
188
|
+
message: string;
|
|
189
|
+
} | {
|
|
190
|
+
kind: 'nothing';
|
|
191
|
+
message: string;
|
|
192
|
+
} | {
|
|
193
|
+
kind: 'plan';
|
|
194
|
+
changes: Change[];
|
|
195
|
+
patch: (m: Manifest) => void;
|
|
196
|
+
};
|
|
197
|
+
/** What an install or an uninstall would change, read from the disk and written to nothing. */
|
|
198
|
+
export declare function planGuard(ctx: Ctx, action: 'install' | 'uninstall', thresholds: Thresholds | null, t: CliMessages): Promise<GuardPlan>;
|
|
199
|
+
/** A write that failed, as the finding `trazum proactive` would report for it. */
|
|
200
|
+
export declare class GuardWriteFailed extends Error {
|
|
201
|
+
readonly finding: Finding;
|
|
202
|
+
constructor(finding: Finding);
|
|
203
|
+
}
|
|
204
|
+
/** Writes a plan through the one door, then the record of it; puts it all back if any write fails. */
|
|
205
|
+
export declare function applyGuardPlan(ctx: Ctx, plan: Extract<GuardPlan, {
|
|
206
|
+
kind: 'plan';
|
|
207
|
+
}>, action: 'install' | 'uninstall'): Promise<void>;
|
|
208
|
+
/** Which of the two events carry the hook: both, one, or none. */
|
|
209
|
+
export declare function guardState(view: GuardView): 'on' | 'partial' | 'off';
|
|
210
|
+
//# sourceMappingURL=session-guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-guard.d.ts","sourceRoot":"","sources":["../src/session-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AAMH,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAiBnD,OAAO,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAM1E,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,aAAa,CAAC;CACvB;AAED,MAAM,MAAM,gBAAgB,GACxB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAClD;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACrD;IAAE,IAAI,EAA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