@dzhechkov/harness-core 0.7.3 → 0.7.5
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/.dz-manifest.json +131 -51
- package/README.md +1 -1
- package/dist/agentdb-index.d.ts.map +1 -1
- package/dist/agentdb-index.js +26 -2
- package/dist/agentdb-index.js.map +1 -1
- package/dist/amendment-trace.d.ts.map +1 -1
- package/dist/amendment-trace.js +6 -1
- package/dist/amendment-trace.js.map +1 -1
- package/dist/cadence.d.ts +66 -0
- package/dist/cadence.d.ts.map +1 -0
- package/dist/cadence.js +222 -0
- package/dist/cadence.js.map +1 -0
- package/dist/cli-flag-notice.d.ts +50 -0
- package/dist/cli-flag-notice.d.ts.map +1 -0
- package/dist/cli-flag-notice.js +106 -0
- package/dist/cli-flag-notice.js.map +1 -0
- package/dist/feature-adr-routing.d.ts.map +1 -1
- package/dist/feature-adr-routing.js +1 -1
- package/dist/feature-adr-routing.js.map +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/loop-blobs.generated.js +2 -2
- package/dist/loop-blobs.generated.js.map +1 -1
- package/dist/operations.d.ts.map +1 -1
- package/dist/operations.js +61 -19
- package/dist/operations.js.map +1 -1
- package/dist/publish.d.ts +31 -0
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +78 -0
- package/dist/publish.js.map +1 -1
- package/dist/recall-hook-policy.d.ts +3 -1
- package/dist/recall-hook-policy.d.ts.map +1 -1
- package/dist/recall-hook-policy.js +15 -2
- package/dist/recall-hook-policy.js.map +1 -1
- package/dist/recall-usage.d.ts +15 -0
- package/dist/recall-usage.d.ts.map +1 -1
- package/dist/recall-usage.js +51 -1
- package/dist/recall-usage.js.map +1 -1
- package/dist/score.d.ts.map +1 -1
- package/dist/score.js +38 -4
- package/dist/score.js.map +1 -1
- package/dist/tg-post.d.ts +54 -0
- package/dist/tg-post.d.ts.map +1 -0
- package/dist/tg-post.js +117 -0
- package/dist/tg-post.js.map +1 -0
- package/dist/usage.d.ts +31 -0
- package/dist/usage.d.ts.map +1 -1
- package/dist/usage.js +108 -21
- package/dist/usage.js.map +1 -1
- package/dist/writer-quiescence.d.ts +42 -0
- package/dist/writer-quiescence.d.ts.map +1 -0
- package/dist/writer-quiescence.js +82 -0
- package/dist/writer-quiescence.js.map +1 -0
- package/package.json +13 -13
- package/sbom.json +250 -50
- package/src/agentdb-index.ts +26 -2
- package/src/amendment-trace.ts +6 -1
- package/src/cadence.ts +227 -0
- package/src/cli-flag-notice.ts +114 -0
- package/src/feature-adr-routing.ts +1 -1
- package/src/index.ts +8 -1
- package/src/loop-blobs.generated.ts +2 -2
- package/src/operations.ts +60 -20
- package/src/publish.ts +98 -0
- package/src/recall-hook-policy.ts +15 -2
- package/src/recall-usage.ts +44 -1
- package/src/score.ts +30 -4
- package/src/tg-post.ts +137 -0
- package/src/usage.ts +132 -17
- package/src/writer-quiescence.ts +95 -0
package/dist/score.js
CHANGED
|
@@ -50,7 +50,12 @@ const NEGATION_RE = /\b(no|not|never|without|wasn'?t|isn'?t)\b/i;
|
|
|
50
50
|
* `\bno\b` does NOT match "Nothing". Hedges like "skipped" stay out of both lists — they routinely
|
|
51
51
|
* appear inside genuine evidence lines.
|
|
52
52
|
*/
|
|
53
|
-
|
|
53
|
+
// RU negation quantifiers joined 2026-08-24 with the RU live-markers (773185ca): a corpus where
|
|
54
|
+
// 63% of traffic is Russian was screened by an English-only list — «ничего не измерено» would have
|
|
55
|
+
// read as a live marker the moment ИЗМЕРЕНО joined the positives.
|
|
56
|
+
// \b is ASCII-only in JS even under /u — «не» never matched through it (measured by the pin the
|
|
57
|
+
// moment it was written). Unicode lookarounds carry the boundary instead.
|
|
58
|
+
const NEGATION_QUANTIFIED_RE = /\b(no|not|never|without|nothing|none|neither|nor|nobody|wasn'?t|isn'?t)\b|(?<![\p{L}\p{N}])(не|нет|ни одного|ничего|никогда|без)(?![\p{L}\p{N}])/iu;
|
|
54
59
|
function evidenceLinePositive(text, re, negationRe = NEGATION_RE) {
|
|
55
60
|
for (const line of text.split('\n')) {
|
|
56
61
|
if (!re.test(line))
|
|
@@ -99,7 +104,33 @@ function normaliseGradeSign(grade) {
|
|
|
99
104
|
*/
|
|
100
105
|
export function readQeGrade(qeText) {
|
|
101
106
|
const found = [];
|
|
107
|
+
const lines = qeText.split('\n');
|
|
108
|
+
// Line offsets once, so each match maps to ITS line for the negation screen (67d7883d: the
|
|
109
|
+
// parser was negation-blind — «No Grade: B was assigned» contributed B and a cross-model PASS;
|
|
110
|
+
// the display-locator fix could not reach this because the GRADE rests here). The same
|
|
111
|
+
// deliberate trade as evidenceLinePositive: a genuine grade on a line that happens to carry a
|
|
112
|
+
// negation is SKIPPED (visible in `found`'s absence) rather than a negated line being COUNTED.
|
|
113
|
+
const lineStarts = [0];
|
|
114
|
+
for (let i = 0; i < lines.length - 1; i++)
|
|
115
|
+
lineStarts.push(lineStarts[i] + lines[i].length + 1);
|
|
116
|
+
// The screen covers the line PREFIX up to the match, not the whole line: «No Grade: B was
|
|
117
|
+
// assigned» negates BEFORE the grade; «**Grade: B** — no blockers remain» carries its negation
|
|
118
|
+
// AFTER, about something else entirely, and whole-line screening dropped that real, common
|
|
119
|
+
// phrase (caught by the standing display-locator pin the moment the sweep was «completed»).
|
|
120
|
+
const linePrefixOf = (idx) => {
|
|
121
|
+
let lo = 0, hi = lineStarts.length - 1;
|
|
122
|
+
while (lo < hi) {
|
|
123
|
+
const mid = (lo + hi + 1) >> 1;
|
|
124
|
+
if (lineStarts[mid] <= idx)
|
|
125
|
+
lo = mid;
|
|
126
|
+
else
|
|
127
|
+
hi = mid - 1;
|
|
128
|
+
}
|
|
129
|
+
return qeText.slice(lineStarts[lo], idx);
|
|
130
|
+
};
|
|
102
131
|
for (const m of qeText.matchAll(new RegExp(GRADE_RE.source, 'g'))) {
|
|
132
|
+
if (NEGATION_QUANTIFIED_RE.test(linePrefixOf(m.index ?? 0)))
|
|
133
|
+
continue;
|
|
103
134
|
const g = normaliseGradeSign(m[1]);
|
|
104
135
|
if (!found.includes(g))
|
|
105
136
|
found.push(g);
|
|
@@ -170,9 +201,12 @@ export function scoreRun(slug, artifacts) {
|
|
|
170
201
|
// report is the cautionary case: "✅ (mechanism)" with no live evidence shipped a dead feature.
|
|
171
202
|
// POSITIVE (wave1-scorer-negation): "nothing was MEASURED" / "no reproducer was run" is the
|
|
172
203
|
// claim's exact opposite and used to score as proof of it (the crossrt-1 6/7 shape).
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
204
|
+
// 773185ca: MEASURED-class markers in BOTH working languages. dz-recap carried 10× ИЗМЕРЕНО and
|
|
205
|
+
// 0× MEASURED and scored «всё выведено рассуждением» — the cyrillic-tokenizer class again.
|
|
206
|
+
const LIVE_MARKER_RE = /MEASURED|verified live|VERIFIED LIVE|reproducer|ИЗМЕРЕНО|МЕРЕНО|измерено|проверено живьём|живой прогон|репродьюсер/iu;
|
|
207
|
+
const live = evidenceLinePositive(qeText, LIVE_MARKER_RE, NEGATION_QUANTIFIED_RE);
|
|
208
|
+
const liveAnywhere = live ?? evidenceLinePositive(allText, LIVE_MARKER_RE, NEGATION_QUANTIFIED_RE);
|
|
209
|
+
add('live-verification', 'claims verified by running, not by reasoning', live !== null ? 'pass' : liveAnywhere !== null ? 'partial' : 'absent', live ?? liveAnywhere ?? 'no MEASURED/ИЗМЕРЕНО/verified-live/reproducer marker anywhere — every claim is inferred');
|
|
176
210
|
// 5. README-first — the docs travelled in the same change.
|
|
177
211
|
// POSITIVE (wave1-scorer-negation): THE acid-A5 defect. crossrt-1-agents-md scored ✓ here over
|
|
178
212
|
// its own finding "README-first not satisfied — no README was touched": a negation rendered as
|
package/dist/score.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"score.js","sourceRoot":"","sources":["../src/score.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;G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AAK,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;QAC5C,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;IAClC,CAAC;IACD,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACb,GAAG,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IAC9B,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dz tg-post` — the pure half: validate an approved draft against what Telegram will accept and
|
|
3
|
+
* what the channel's own accepted design demands.
|
|
4
|
+
*
|
|
5
|
+
* The design is NOT this module's to invent. features/genai-tweets-channel/ carries four ACCEPTED
|
|
6
|
+
* ADRs (2026-08-04): HTML mode, never MarkdownV2 (18 escapes against 3, one miss is a 400); the
|
|
7
|
+
* cadence rule "no posts 00:00-06:00 MSK"; link previews off by default because x.com previews in
|
|
8
|
+
* Telegram have been broken since 2022; and ADR-004's standing order — publishing stays MANUAL, and
|
|
9
|
+
* autonomous publishing means REVISING the ADR, not flipping a quiet flag. This module only makes
|
|
10
|
+
* those decisions checkable.
|
|
11
|
+
*
|
|
12
|
+
* PURE: no filesystem, no network, no clock — the timestamp arrives as a parameter, or the MSK
|
|
13
|
+
* night-window rule could not be tested at all.
|
|
14
|
+
*/
|
|
15
|
+
/** Tags Bot API accepts in HTML mode (verified against the live docs, Bot API 10.2). */
|
|
16
|
+
export declare const TG_ALLOWED_TAGS: readonly string[];
|
|
17
|
+
/** Hard ceiling for `sendMessage.text`, characters after entity parsing. */
|
|
18
|
+
export declare const TG_TEXT_LIMIT = 4096;
|
|
19
|
+
export interface TgHtmlIssue {
|
|
20
|
+
readonly kind: 'unknown-tag' | 'unclosed-tag' | 'stray-close' | 'bare-ampersand' | 'bare-angle' | 'over-limit' | 'empty';
|
|
21
|
+
readonly detail: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The character count Telegram limits: text WITHOUT the markup. An approximation is stated as one —
|
|
25
|
+
* entities like tg-emoji count differently — but a draft within this bound by a margin is safe, and
|
|
26
|
+
* the render prints the number so the author sees the headroom, not a verdict.
|
|
27
|
+
*/
|
|
28
|
+
export declare function tgVisibleLength(html: string): number;
|
|
29
|
+
/**
|
|
30
|
+
* Everything wrong with a draft, or an empty list. One pass, every finding named — a validator that
|
|
31
|
+
* stops at the first fault sends the author around the loop once per mistake.
|
|
32
|
+
*/
|
|
33
|
+
export declare function tgPostHtmlIssues(html: string): TgHtmlIssue[];
|
|
34
|
+
export interface TgSendDecision {
|
|
35
|
+
readonly action: 'send' | 'refuse';
|
|
36
|
+
readonly reason: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* May this draft go out NOW?
|
|
40
|
+
*
|
|
41
|
+
* The night window is ADR-003's cadence rule, encoded as a refusal with an explicit override rather
|
|
42
|
+
* than as advice: 00:00-06:00 MSK is when the channel's audience is asleep and its author is too —
|
|
43
|
+
* a send landing then is far more often a timezone mistake than an intention. `--night` states the
|
|
44
|
+
* intention; without it the refusal names the local MSK time it computed, so the operator can check
|
|
45
|
+
* the arithmetic instead of trusting it.
|
|
46
|
+
*/
|
|
47
|
+
export declare function decideTgSend(input: {
|
|
48
|
+
readonly issues: readonly TgHtmlIssue[];
|
|
49
|
+
readonly provenanceOutcome: 'allowed' | 'blocked' | 'not-established' | 'skipped';
|
|
50
|
+
readonly confirmed: boolean;
|
|
51
|
+
readonly nowUtcIso: string;
|
|
52
|
+
readonly nightOverride: boolean;
|
|
53
|
+
}): TgSendDecision;
|
|
54
|
+
//# sourceMappingURL=tg-post.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tg-post.d.ts","sourceRoot":"","sources":["../src/tg-post.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,wFAAwF;AACxF,eAAO,MAAM,eAAe,EAAE,SAAS,MAAM,EAG5C,CAAC;AAEF,4EAA4E;AAC5E,eAAO,MAAM,aAAa,OAAO,CAAC;AAElC,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,aAAa,GAAG,cAAc,GAAG,aAAa,GAAG,gBAAgB,GAAG,YAAY,GAAG,YAAY,GAAG,OAAO,CAAC;IACzH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,EAAE,CA+C5D;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE;IAClC,QAAQ,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC;IACxC,QAAQ,CAAC,iBAAiB,EAAE,SAAS,GAAG,SAAS,GAAG,iBAAiB,GAAG,SAAS,CAAC;IAClF,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;CACjC,GAAG,cAAc,CAyBjB"}
|
package/dist/tg-post.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dz tg-post` — the pure half: validate an approved draft against what Telegram will accept and
|
|
3
|
+
* what the channel's own accepted design demands.
|
|
4
|
+
*
|
|
5
|
+
* The design is NOT this module's to invent. features/genai-tweets-channel/ carries four ACCEPTED
|
|
6
|
+
* ADRs (2026-08-04): HTML mode, never MarkdownV2 (18 escapes against 3, one miss is a 400); the
|
|
7
|
+
* cadence rule "no posts 00:00-06:00 MSK"; link previews off by default because x.com previews in
|
|
8
|
+
* Telegram have been broken since 2022; and ADR-004's standing order — publishing stays MANUAL, and
|
|
9
|
+
* autonomous publishing means REVISING the ADR, not flipping a quiet flag. This module only makes
|
|
10
|
+
* those decisions checkable.
|
|
11
|
+
*
|
|
12
|
+
* PURE: no filesystem, no network, no clock — the timestamp arrives as a parameter, or the MSK
|
|
13
|
+
* night-window rule could not be tested at all.
|
|
14
|
+
*/
|
|
15
|
+
/** Tags Bot API accepts in HTML mode (verified against the live docs, Bot API 10.2). */
|
|
16
|
+
export const TG_ALLOWED_TAGS = [
|
|
17
|
+
'b', 'strong', 'i', 'em', 'u', 'ins', 's', 'strike', 'del', 'tg-spoiler',
|
|
18
|
+
'a', 'tg-emoji', 'code', 'pre', 'blockquote',
|
|
19
|
+
];
|
|
20
|
+
/** Hard ceiling for `sendMessage.text`, characters after entity parsing. */
|
|
21
|
+
export const TG_TEXT_LIMIT = 4096;
|
|
22
|
+
/**
|
|
23
|
+
* The character count Telegram limits: text WITHOUT the markup. An approximation is stated as one —
|
|
24
|
+
* entities like tg-emoji count differently — but a draft within this bound by a margin is safe, and
|
|
25
|
+
* the render prints the number so the author sees the headroom, not a verdict.
|
|
26
|
+
*/
|
|
27
|
+
export function tgVisibleLength(html) {
|
|
28
|
+
return html.replace(/<[^>]*>/g, '').replace(/</g, '<').replace(/>/g, '>').replace(/&/g, '&').length;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Everything wrong with a draft, or an empty list. One pass, every finding named — a validator that
|
|
32
|
+
* stops at the first fault sends the author around the loop once per mistake.
|
|
33
|
+
*/
|
|
34
|
+
export function tgPostHtmlIssues(html) {
|
|
35
|
+
const issues = [];
|
|
36
|
+
const text = html.trim();
|
|
37
|
+
if (text === '')
|
|
38
|
+
return [{ kind: 'empty', detail: 'the draft is empty — nothing to send' }];
|
|
39
|
+
// Tag balance over the allowed set. Telegram closes nothing for you: an unclosed <b> is a 400.
|
|
40
|
+
const stack = [];
|
|
41
|
+
const tagRe = /<(\/?)([a-zA-Z-]+)((?:\s+[a-zA-Z-]+(?:="[^"]*")?)*)\s*(\/?)>/g;
|
|
42
|
+
let covered = 0;
|
|
43
|
+
for (let m = tagRe.exec(text); m !== null; m = tagRe.exec(text)) {
|
|
44
|
+
covered += 1;
|
|
45
|
+
const closing = m[1] === '/';
|
|
46
|
+
const name = m[2].toLowerCase();
|
|
47
|
+
const expandable = name === 'blockquote'; // `<blockquote expandable>` is the ADR-003 body form
|
|
48
|
+
if (!TG_ALLOWED_TAGS.includes(name) && !expandable) {
|
|
49
|
+
issues.push({ kind: 'unknown-tag', detail: `<${name}> is not a Bot API HTML tag — Telegram answers 400 to tags it does not know` });
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (closing) {
|
|
53
|
+
if (stack.length === 0 || stack[stack.length - 1] !== name) {
|
|
54
|
+
issues.push({ kind: 'stray-close', detail: `</${name}> closes nothing that is open — tags must nest, not interleave` });
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
stack.pop();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else if (m[4] !== '/') {
|
|
61
|
+
stack.push(name);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
for (const open of stack) {
|
|
65
|
+
issues.push({ kind: 'unclosed-tag', detail: `<${open}> is never closed — Telegram closes nothing for you, this is a 400` });
|
|
66
|
+
}
|
|
67
|
+
// Bare & and < outside tags: HTML mode requires entity-escaping exactly these.
|
|
68
|
+
const outside = text.replace(/<[^>]*>/g, '');
|
|
69
|
+
if (/&(?!(lt|gt|amp|quot|#\d+|#x[0-9a-fA-F]+);)/.test(outside)) {
|
|
70
|
+
issues.push({ kind: 'bare-ampersand', detail: 'a bare & outside an entity — HTML mode needs &' });
|
|
71
|
+
}
|
|
72
|
+
if (/</.test(outside.replace(/</g, ''))) {
|
|
73
|
+
issues.push({ kind: 'bare-angle', detail: 'a bare < that is not a known tag — Telegram reads it as markup and answers 400' });
|
|
74
|
+
}
|
|
75
|
+
const visible = tgVisibleLength(text);
|
|
76
|
+
if (visible > TG_TEXT_LIMIT) {
|
|
77
|
+
issues.push({ kind: 'over-limit', detail: `${visible} visible characters against the ${TG_TEXT_LIMIT} hard limit — cut ${visible - TG_TEXT_LIMIT}` });
|
|
78
|
+
}
|
|
79
|
+
void covered;
|
|
80
|
+
return issues;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* May this draft go out NOW?
|
|
84
|
+
*
|
|
85
|
+
* The night window is ADR-003's cadence rule, encoded as a refusal with an explicit override rather
|
|
86
|
+
* than as advice: 00:00-06:00 MSK is when the channel's audience is asleep and its author is too —
|
|
87
|
+
* a send landing then is far more often a timezone mistake than an intention. `--night` states the
|
|
88
|
+
* intention; without it the refusal names the local MSK time it computed, so the operator can check
|
|
89
|
+
* the arithmetic instead of trusting it.
|
|
90
|
+
*/
|
|
91
|
+
export function decideTgSend(input) {
|
|
92
|
+
if (input.issues.length > 0) {
|
|
93
|
+
return { action: 'refuse', reason: `${input.issues.length} formatting issue(s) — Telegram would refuse or mangle this draft` };
|
|
94
|
+
}
|
|
95
|
+
// The provenance gate is not optional and "skipped" is not a pass: ADR-002 of the provenance
|
|
96
|
+
// feature — nothing leaves this machine citing a source that may not.
|
|
97
|
+
if (input.provenanceOutcome !== 'allowed') {
|
|
98
|
+
return {
|
|
99
|
+
action: 'refuse',
|
|
100
|
+
reason: input.provenanceOutcome === 'skipped'
|
|
101
|
+
? 'no provenance manifest was checked — an unchecked draft is not an approved draft'
|
|
102
|
+
: `the provenance gate said ${input.provenanceOutcome} — nothing goes out citing a source that may not leave this machine`,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
if (!input.confirmed) {
|
|
106
|
+
return { action: 'refuse', reason: 'publishing is MANUAL by the channel\'s own ADR-004 — pass --send --yes to state the decision out loud' };
|
|
107
|
+
}
|
|
108
|
+
const utc = Date.parse(input.nowUtcIso);
|
|
109
|
+
if (Number.isFinite(utc)) {
|
|
110
|
+
const mskHour = new Date(utc + 3 * 3600_000).getUTCHours();
|
|
111
|
+
if (mskHour < 6 && !input.nightOverride) {
|
|
112
|
+
return { action: 'refuse', reason: `it is ${String(mskHour).padStart(2, '0')}:xx MSK — the channel posts nothing between 00:00 and 06:00 MSK (ADR-003). Pass --night if this is deliberate` };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return { action: 'send', reason: 'formatted, provenance-cleared, confirmed, and inside posting hours' };
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=tg-post.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tg-post.js","sourceRoot":"","sources":["../src/tg-post.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,wFAAwF;AACxF,MAAM,CAAC,MAAM,eAAe,GAAsB;IAChD,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,YAAY;IACxE,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY;CAC7C,CAAC;AAEF,4EAA4E;AAC5E,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAC;AAOlC;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC;AAChH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,MAAM,MAAM,GAAkB,EAAE,CAAC;IACjC,MAAM,I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calibratedAt?: string;
|
|
95
95
|
readonly source?: string;
|
|
96
|
+
/** Routing must not read the estimated pcts (ADR-001 usage-honesty, FR-3). Legacy
|
|
97
|
+
* `_disabledReason` free-text also reads as true — the note WAS the switch, now it is data. */
|
|
98
|
+
readonly routingDisabled?: boolean;
|
|
99
|
+
/** Account identity captured at calibration time (FR-4); a login change stales the calibration. */
|
|
100
|
+
readonly calibrationAccount?: string | null;
|
|
96
101
|
}
|
|
97
102
|
export interface UsageModelEstimate {
|
|
98
103
|
readonly tokens: number;
|
|
@@ -123,6 +128,24 @@ export interface UsageEstimate {
|
|
|
123
128
|
/** Traceability for tests and calibration diagnostics. */
|
|
124
129
|
readonly sessionStartedAt: string | null;
|
|
125
130
|
readonly weeklyStartedAt: string | null;
|
|
131
|
+
/**
|
|
132
|
+
* Why the routed pcts are null (ADR-001 usage-honesty): empty ⇔ the numbers are established.
|
|
133
|
+
* `scan-empty` — recent transcripts exist yet the scan extracted nothing (instrument failure);
|
|
134
|
+
* `window-miss:*` — samples exist but the configured window filtered them all (misaligned
|
|
135
|
+
* anchor); `routing-disabled` — config says the estimates must not steer; `calibration-stale` —
|
|
136
|
+
* the account changed since calibration. A zero pct is legitimate ONLY on a machine with no
|
|
137
|
+
* recent transcripts at all.
|
|
138
|
+
*/
|
|
139
|
+
readonly notEstablished: readonly UsageNotEstablishedReason[];
|
|
140
|
+
/**
|
|
141
|
+
* The raw estimates when the routed pcts are nulled by `routing-disabled`/`calibration-stale` —
|
|
142
|
+
* for HUMAN eyes (recalled lesson: an estimated pct must never drive routing until its window is
|
|
143
|
+
* verified against the provider). Absent when the top-level pcts already carry the numbers.
|
|
144
|
+
*/
|
|
145
|
+
readonly estimatesNotForRouting?: {
|
|
146
|
+
readonly sessionPct: number | null;
|
|
147
|
+
readonly weeklyPct: number | null;
|
|
148
|
+
};
|
|
126
149
|
}
|
|
127
150
|
export interface UsageCalibrationInput {
|
|
128
151
|
readonly sessionPct?: unknown;
|
|
@@ -158,6 +181,14 @@ export declare function normalizeClaudeUsageModelKey(raw: unknown): ClaudeUsageM
|
|
|
158
181
|
* The `~/.claude/projects` root (the account-wide transcript store). Overridable via
|
|
159
182
|
* `DZ_CLAUDE_PROJECTS_ROOT` — used by tests to point at a temp tree. Never throws.
|
|
160
183
|
*/
|
|
184
|
+
/**
|
|
185
|
+
* The logged-in account identity, from `~/.claude.json` (oauthAccount email or uuid). Honest null
|
|
186
|
+
* when unreadable/absent — and null==null is NOT an account change (machines that never expose it
|
|
187
|
+
* keep the pre-FR-4 behavior). Never throws.
|
|
188
|
+
*/
|
|
189
|
+
export declare function readClaudeAccountId(): string | null;
|
|
190
|
+
/** Closed set of not-established reasons (ADR-001). */
|
|
191
|
+
export type UsageNotEstablishedReason = 'scan-empty' | 'window-miss:weekly' | 'routing-disabled' | 'calibration-stale:account-changed' | 'calibration-stale:account-unverifiable';
|
|
161
192
|
export declare function claudeProjectsRoot(): string;
|
|
162
193
|
/**
|
|
163
194
|
* Read `memory.usage.*` from `<projectRoot>/.dz/config.json`. NEVER throws —
|
package/dist/usage.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../src/usage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAYH;;;;GAIG;AACH,eAAO,MAAM,aAAa;;;;;;CAAsF,CAAC;AAEjH,gFAAgF;AAChF,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,+FAA+F;IAC/F,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAMD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAiBzD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB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AAG,IAAI,CAuCjF;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAOzF;AAED,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,OAAO,GAAG,gBAAgB,GAAG,IAAI,CAQ/E;AAED,wBAAgB,4BAA4B,CAAC,GAAG,EAAE,OAAO,GAAG,gBAAgB,GAAG,IAAI,CAIlF;AAuBD;;;GAGG;AACH;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,GAAG,IAAI,CAanD;AAED,uDAAuD;AACvD,MAAM,MAAM,yBAAyB,GACjC,YAAY,GACZ,oBAAoB,GACpB,kBAAkB,GAClB,mCAAmC,GACnC,wCAAwC,CAAC;AAE7C,wBAAgB,kBAAkB,IAAI,MAAM,CAI3C;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,WAAW,CA8ChE;AAmMD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,aAAa,CAqH7E;AAyCD,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,aAAa,EACtB,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,qBAAqB,GAC3B,oBAAoB,CAsEtB"}
|
package/dist/usage.js
CHANGED
|
@@ -211,10 +211,55 @@ export function normalizeClaudeUsageModelKey(raw) {
|
|
|
211
211
|
const key = raw.trim().toLowerCase();
|
|
212
212
|
return CLAUDE_USAGE_MODELS.includes(key) ? key : null;
|
|
213
213
|
}
|
|
214
|
+
/** Recursive .jsonl collector under a subagents tree — bounded depth, lstat-guarded. */
|
|
215
|
+
function walkTranscriptTree(dir, depthLeft, out) {
|
|
216
|
+
if (depthLeft <= 0)
|
|
217
|
+
return;
|
|
218
|
+
let entries;
|
|
219
|
+
try {
|
|
220
|
+
if (!lstatSync(dir).isDirectory())
|
|
221
|
+
return; // symlinked dir ⇒ not walked
|
|
222
|
+
entries = readdirSync(dir);
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
for (const e of entries) {
|
|
228
|
+
const p = join(dir, e);
|
|
229
|
+
if (e.endsWith('.jsonl')) {
|
|
230
|
+
const m = regularFileMtime(p);
|
|
231
|
+
if (m !== null)
|
|
232
|
+
out.push({ path: p, mtimeMs: m });
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
walkTranscriptTree(p, depthLeft - 1, out);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
214
239
|
/**
|
|
215
240
|
* The `~/.claude/projects` root (the account-wide transcript store). Overridable via
|
|
216
241
|
* `DZ_CLAUDE_PROJECTS_ROOT` — used by tests to point at a temp tree. Never throws.
|
|
217
242
|
*/
|
|
243
|
+
/**
|
|
244
|
+
* The logged-in account identity, from `~/.claude.json` (oauthAccount email or uuid). Honest null
|
|
245
|
+
* when unreadable/absent — and null==null is NOT an account change (machines that never expose it
|
|
246
|
+
* keep the pre-FR-4 behavior). Never throws.
|
|
247
|
+
*/
|
|
248
|
+
export function readClaudeAccountId() {
|
|
249
|
+
try {
|
|
250
|
+
const raw = JSON.parse(readFileSync(join(homedir(), '.claude.json'), 'utf-8'));
|
|
251
|
+
const email = raw.oauthAccount?.emailAddress;
|
|
252
|
+
if (typeof email === 'string' && email !== '')
|
|
253
|
+
return email;
|
|
254
|
+
const uuid = raw.oauthAccount?.accountUuid;
|
|
255
|
+
if (typeof uuid === 'string' && uuid !== '')
|
|
256
|
+
return uuid;
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
catch {
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
218
263
|
export function claudeProjectsRoot() {
|
|
219
264
|
const override = process.env['DZ_CLAUDE_PROJECTS_ROOT'];
|
|
220
265
|
if (typeof override === 'string' && override.length > 0)
|
|
@@ -268,6 +313,13 @@ export function readUsageLimits(projectRoot) {
|
|
|
268
313
|
out.calibratedAt = u['calibratedAt'];
|
|
269
314
|
if (typeof u['source'] === 'string')
|
|
270
315
|
out.source = u['source'];
|
|
316
|
+
// routingDisabled: the boolean is authoritative; the legacy free-text note counts as true so
|
|
317
|
+
// the fleet's existing config disables TODAY, without an edit.
|
|
318
|
+
if (u['routingDisabled'] === true || typeof u['_disabledReason'] === 'string')
|
|
319
|
+
out.routingDisabled = true;
|
|
320
|
+
if (typeof u['calibrationAccount'] === 'string' || u['calibrationAccount'] === null) {
|
|
321
|
+
out.calibrationAccount = u['calibrationAccount'];
|
|
322
|
+
}
|
|
271
323
|
return out;
|
|
272
324
|
}
|
|
273
325
|
catch {
|
|
@@ -316,26 +368,15 @@ function listTranscriptFiles(root) {
|
|
|
316
368
|
continue;
|
|
317
369
|
}
|
|
318
370
|
for (const f of files) {
|
|
319
|
-
// A session's SUBAGENT transcripts live
|
|
320
|
-
//
|
|
321
|
-
//
|
|
371
|
+
// A session's SUBAGENT transcripts live under `<session>/subagents/` and carry real,
|
|
372
|
+
// non-duplicated usage that was silently excluded (MEASURED: 27 such files in the first
|
|
373
|
+
// round). The walk is RECURSIVE with a depth cap: workflow agents write to
|
|
374
|
+
// `subagents/workflows/wf_*/agent-*.jsonl` — one level deeper than the first fix reached —
|
|
375
|
+
// and that blind spot alone hid 283.62M weighted tokens across 551 files (MEASURED
|
|
376
|
+
// 2026-08-24, 7-day window, this machine). Depth 4 covers today's deepest layout plus one
|
|
377
|
+
// future level; lstat at EVERY step keeps symlinked directories unwalked.
|
|
322
378
|
if (!f.endsWith('.jsonl')) {
|
|
323
|
-
|
|
324
|
-
try {
|
|
325
|
-
if (!lstatSync(nested).isDirectory())
|
|
326
|
-
continue; // no symlinked session/subagent dirs
|
|
327
|
-
for (const sf of readdirSync(nested)) {
|
|
328
|
-
if (!sf.endsWith('.jsonl'))
|
|
329
|
-
continue;
|
|
330
|
-
const sp = join(nested, sf);
|
|
331
|
-
const m = regularFileMtime(sp);
|
|
332
|
-
if (m !== null)
|
|
333
|
-
out.push({ path: sp, mtimeMs: m });
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
catch {
|
|
337
|
-
/* not a session dir — skip */
|
|
338
|
-
}
|
|
379
|
+
walkTranscriptTree(join(projDir, f, 'subagents'), 4, out);
|
|
339
380
|
continue;
|
|
340
381
|
}
|
|
341
382
|
const p = join(projDir, f);
|
|
@@ -480,12 +521,14 @@ export function computeUsage(projectRoot, now) {
|
|
|
480
521
|
const scanCutoff = Math.min(sessionScanCutoff, weeklyScanCutoff) - MTIME_SLACK_MS;
|
|
481
522
|
const samples = [];
|
|
482
523
|
const seen = new Set();
|
|
524
|
+
let scanFileCount = 0;
|
|
483
525
|
try {
|
|
484
526
|
const files = listTranscriptFiles(claudeProjectsRoot());
|
|
485
527
|
for (const f of files) {
|
|
486
528
|
// mtime prefilter: a file last written before every relevant cutoff cannot contribute.
|
|
487
529
|
if (f.mtimeMs < scanCutoff)
|
|
488
530
|
continue;
|
|
531
|
+
scanFileCount += 1;
|
|
489
532
|
extractSamples(f.path, scanCutoff, samples, seen);
|
|
490
533
|
}
|
|
491
534
|
}
|
|
@@ -522,11 +565,47 @@ export function computeUsage(projectRoot, now) {
|
|
|
522
565
|
}
|
|
523
566
|
}
|
|
524
567
|
}
|
|
568
|
+
// ── Establishment gate (ADR-001): a number may only flow to the routed pct fields when the
|
|
569
|
+
// scan actually established it. Fail-closed in exactly four named ways; the raw estimates stay
|
|
570
|
+
// visible to humans under estimatesNotForRouting when policy (not measurement) nulls them.
|
|
571
|
+
const reasons = [];
|
|
572
|
+
const recentFiles = scanFileCount > 0;
|
|
573
|
+
if (recentFiles && samples.length === 0)
|
|
574
|
+
reasons.push('scan-empty');
|
|
575
|
+
// An IDLE session inside a busy week (block 0, weekly > 0) is a MEASURED zero, not a miss — the
|
|
576
|
+
// first cut of this gate flagged it and four standing tests rightly reddened. Second narrowing
|
|
577
|
+
// (cross-family review): a week that JUST reset over an idle machine still scans pre-reset
|
|
578
|
+
// samples (the session cutoff reaches 10h back), and weekly 0 is then a healthy fresh week. The
|
|
579
|
+
// true miss signature needs a sample AT or PAST the window start that the window still refuses —
|
|
580
|
+
// future-stamped (clock skew) or beyond-reset (stale anchor) — exactly d3639bf0's shape.
|
|
581
|
+
if (weeklyWindow !== null &&
|
|
582
|
+
weeklyTokens <= 0 &&
|
|
583
|
+
samples.some((smp) => smp.ts >= weeklyWindow.startedAtMs)) {
|
|
584
|
+
reasons.push('window-miss:weekly');
|
|
585
|
+
}
|
|
586
|
+
if (limits.routingDisabled === true)
|
|
587
|
+
reasons.push('routing-disabled');
|
|
588
|
+
const account = readClaudeAccountId();
|
|
589
|
+
if (limits.calibrationAccount !== undefined && limits.calibrationAccount !== null) {
|
|
590
|
+
// A stored identity DEMANDS verification (cross-family review: null-current was fail-open —
|
|
591
|
+
// an unreadable ~/.claude.json silently reused another account's calibration). A stored null
|
|
592
|
+
// stays exempt: those machines never claimed an identity to verify.
|
|
593
|
+
if (account === null)
|
|
594
|
+
reasons.push('calibration-stale:account-unverifiable');
|
|
595
|
+
else if (account !== limits.calibrationAccount)
|
|
596
|
+
reasons.push('calibration-stale:account-changed');
|
|
597
|
+
}
|
|
598
|
+
const rawSessionPct = pct(block.tokens, limits.sessionTokenLimit);
|
|
599
|
+
const rawWeeklyPct = weeklyPct;
|
|
600
|
+
const measurementBroken = reasons.some((r) => r === 'scan-empty' || r.startsWith('window-miss'));
|
|
601
|
+
const policyNulled = reasons.some((r) => r === 'routing-disabled' || r.startsWith('calibration-stale'));
|
|
602
|
+
const gatedSessionPct = measurementBroken || policyNulled ? null : rawSessionPct;
|
|
603
|
+
const gatedWeeklyPct = measurementBroken || policyNulled ? null : rawWeeklyPct;
|
|
525
604
|
return {
|
|
526
605
|
sessionTokens: block.tokens,
|
|
527
606
|
weeklyTokens,
|
|
528
|
-
sessionPct:
|
|
529
|
-
weeklyPct,
|
|
607
|
+
sessionPct: gatedSessionPct,
|
|
608
|
+
weeklyPct: gatedWeeklyPct,
|
|
530
609
|
sessionResetsAt: block.resetsAtMs === null ? null : new Date(block.resetsAtMs).toISOString(),
|
|
531
610
|
weeklyResetsAt: weeklyWindow === null ? null : new Date(weeklyWindow.resetsAtMs).toISOString(),
|
|
532
611
|
estimated: true,
|
|
@@ -535,6 +614,10 @@ export function computeUsage(projectRoot, now) {
|
|
|
535
614
|
...(weeklyBindingModel !== undefined ? { weeklyBindingModel } : {}),
|
|
536
615
|
sessionStartedAt: block.startedAtMs === null ? null : new Date(block.startedAtMs).toISOString(),
|
|
537
616
|
weeklyStartedAt: weeklyWindow === null ? null : new Date(weeklyWindow.startedAtMs).toISOString(),
|
|
617
|
+
notEstablished: reasons,
|
|
618
|
+
...(policyNulled && !measurementBroken
|
|
619
|
+
? { estimatesNotForRouting: { sessionPct: rawSessionPct, weeklyPct: rawWeeklyPct } }
|
|
620
|
+
: {}),
|
|
538
621
|
};
|
|
539
622
|
}
|
|
540
623
|
function validPct(label, value, skipped) {
|
|
@@ -627,6 +710,10 @@ export function deriveUsageCalibration(current, before, input) {
|
|
|
627
710
|
if (changes.length > 0) {
|
|
628
711
|
after.calibratedAt = input.calibratedAt;
|
|
629
712
|
after.source = input.source;
|
|
713
|
+
// FR-4: a calibration is a claim about ONE account's limits. Stamp whose — a later login under
|
|
714
|
+
// a different identity then stales it by itself (the 2026-08-24 re-login is the reproducer:
|
|
715
|
+
// the old anchor kept printing 55% on the new account).
|
|
716
|
+
after.calibrationAccount = readClaudeAccountId();
|
|
630
717
|
}
|
|
631
718
|
return { before, after, changes, skipped };
|
|
632
719
|
}
|