@digital-lake/lognexus 1.3.7 → 1.4.1
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/LICENSE +2 -2
- package/NOTICE.md +2 -2
- package/README.md +72 -47
- package/dist/audit/audit.d.ts +37 -2
- package/dist/audit/audit.d.ts.map +1 -1
- package/dist/audit/audit.js +540 -57
- package/dist/audit/audit.js.map +1 -1
- package/dist/cli.d.ts +9 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +342 -34
- package/dist/cli.js.map +1 -1
- package/dist/commit.d.ts +6 -0
- package/dist/commit.d.ts.map +1 -1
- package/dist/commit.js +61 -23
- package/dist/commit.js.map +1 -1
- package/dist/doctor.d.ts +1 -0
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +31 -8
- package/dist/doctor.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp/prompts.d.ts.map +1 -1
- package/dist/mcp/prompts.js +14 -10
- package/dist/mcp/prompts.js.map +1 -1
- package/dist/notes/attach.d.ts +11 -0
- package/dist/notes/attach.d.ts.map +1 -1
- package/dist/notes/attach.js +22 -5
- package/dist/notes/attach.js.map +1 -1
- package/dist/routing/profile.d.ts +44 -0
- package/dist/routing/profile.d.ts.map +1 -0
- package/dist/routing/profile.js +261 -0
- package/dist/routing/profile.js.map +1 -0
- package/dist/scaffold.d.ts +3 -3
- package/dist/scaffold.d.ts.map +1 -1
- package/dist/scaffold.js +31 -19
- package/dist/scaffold.js.map +1 -1
- package/dist/state/handoff.d.ts +18 -0
- package/dist/state/handoff.d.ts.map +1 -1
- package/dist/state/handoff.js +60 -10
- package/dist/state/handoff.js.map +1 -1
- package/dist/state/manager.d.ts.map +1 -1
- package/dist/state/manager.js +60 -1
- package/dist/state/manager.js.map +1 -1
- package/dist/state/schema.d.ts +38 -0
- package/dist/state/schema.d.ts.map +1 -1
- package/dist/state/schema.js +9 -0
- package/dist/state/schema.js.map +1 -1
- package/dist/status.d.ts +10 -0
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +171 -42
- package/dist/status.js.map +1 -1
- package/dist/telemetry/benchmark.d.ts +51 -0
- package/dist/telemetry/benchmark.d.ts.map +1 -0
- package/dist/telemetry/benchmark.js +541 -0
- package/dist/telemetry/benchmark.js.map +1 -0
- package/dist/telemetry/collector.d.ts +109 -3
- package/dist/telemetry/collector.d.ts.map +1 -1
- package/dist/telemetry/collector.js +737 -178
- package/dist/telemetry/collector.js.map +1 -1
- package/dist/telemetry/consent-prompt.d.ts +35 -0
- package/dist/telemetry/consent-prompt.d.ts.map +1 -0
- package/dist/telemetry/consent-prompt.js +215 -0
- package/dist/telemetry/consent-prompt.js.map +1 -0
- package/dist/telemetry/detector.d.ts +16 -1
- package/dist/telemetry/detector.d.ts.map +1 -1
- package/dist/telemetry/detector.js +362 -38
- package/dist/telemetry/detector.js.map +1 -1
- package/dist/telemetry/index.d.ts +5 -4
- package/dist/telemetry/index.d.ts.map +1 -1
- package/dist/telemetry/index.js +5 -4
- package/dist/telemetry/index.js.map +1 -1
- package/dist/telemetry/report.d.ts +3 -2
- package/dist/telemetry/report.d.ts.map +1 -1
- package/dist/telemetry/report.js +66 -14
- package/dist/telemetry/report.js.map +1 -1
- package/dist/telemetry/schema.d.ts +305 -2
- package/dist/telemetry/schema.d.ts.map +1 -1
- package/dist/telemetry/schema.js +142 -4
- package/dist/telemetry/schema.js.map +1 -1
- package/dist/update/gate.d.ts +1 -1
- package/dist/update/gate.d.ts.map +1 -1
- package/dist/update/gate.js +2 -0
- package/dist/update/gate.js.map +1 -1
- package/package.json +2 -2
- package/server.json +3 -3
package/dist/audit/audit.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { execFileSync } from "node:child_process";
|
|
2
2
|
import { rejectNotesReference, validateGitReference } from "../git/safe.js";
|
|
3
3
|
import { getNote } from "../notes/notes.js";
|
|
4
|
-
import {
|
|
4
|
+
import { parseRoutingConfigContent, resolveRoutingProfile, } from "../routing/profile.js";
|
|
5
|
+
import { inferTierFromAuthor, isGovernanceOrConfigSurface } from "../telemetry/detector.js";
|
|
5
6
|
import { getJourneyTimeline } from "../timeline/timeline.js";
|
|
6
7
|
const VALID_TYPES = "feat, fix, docs, refactor, test, chore, style, perf, ci, build";
|
|
7
8
|
export const TICKET_PATTERN_SOURCE = "(?:#\\d+|[A-Z][A-Z0-9]*-\\d+)";
|
|
@@ -9,6 +10,100 @@ export const SUBTASK_PATTERN_SOURCE = "T\\d+(?:-[a-zA-Z0-9]+)?";
|
|
|
9
10
|
export const COMMIT_FORMAT_PATTERN = new RegExp(`^(feat|fix|docs|refactor|test|chore|style|perf|ci|build)\\(${TICKET_PATTERN_SOURCE}(\\/${SUBTASK_PATTERN_SOURCE})?\\): \\S+`);
|
|
10
11
|
export const SUBJECT_TASK_PATTERN = new RegExp(`\\(${TICKET_PATTERN_SOURCE}\\/(${SUBTASK_PATTERN_SOURCE})\\)`, "i");
|
|
11
12
|
const FAMILY_PATTERN = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_. -]+$/;
|
|
13
|
+
/**
|
|
14
|
+
* Strips matched outer parenthesis pairs (`((...))` -> `...`) in a single linear pass
|
|
15
|
+
* without removing sibling groups such as `(a) (b)`.
|
|
16
|
+
*/
|
|
17
|
+
export function unwrapOuterBalancedParens(input) {
|
|
18
|
+
const trimmed = input.trim();
|
|
19
|
+
if (trimmed.length < 2 || trimmed[0] !== "(" || trimmed[trimmed.length - 1] !== ")") {
|
|
20
|
+
return trimmed;
|
|
21
|
+
}
|
|
22
|
+
const matchClose = new Int32Array(trimmed.length).fill(-1);
|
|
23
|
+
const stack = [];
|
|
24
|
+
for (let i = 0; i < trimmed.length; i += 1) {
|
|
25
|
+
const ch = trimmed.charCodeAt(i);
|
|
26
|
+
if (ch === 40) {
|
|
27
|
+
stack.push(i);
|
|
28
|
+
}
|
|
29
|
+
else if (ch === 41) {
|
|
30
|
+
const openIdx = stack.pop();
|
|
31
|
+
if (openIdx !== undefined) {
|
|
32
|
+
matchClose[openIdx] = i;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
let left = 0;
|
|
37
|
+
let right = trimmed.length - 1;
|
|
38
|
+
while (left < right && matchClose[left] === right) {
|
|
39
|
+
left += 1;
|
|
40
|
+
right -= 1;
|
|
41
|
+
while (left <= right && trimmed.charCodeAt(left) <= 32)
|
|
42
|
+
left += 1;
|
|
43
|
+
while (right >= left && trimmed.charCodeAt(right) <= 32)
|
|
44
|
+
right -= 1;
|
|
45
|
+
}
|
|
46
|
+
return left > right ? "" : trimmed.slice(left, right + 1);
|
|
47
|
+
}
|
|
48
|
+
function stripStrayOuterParens(value) {
|
|
49
|
+
let start = 0;
|
|
50
|
+
let end = value.length;
|
|
51
|
+
while (start < end && value[start] === "(")
|
|
52
|
+
start += 1;
|
|
53
|
+
while (end > start && value[end - 1] === ")")
|
|
54
|
+
end -= 1;
|
|
55
|
+
return value.slice(start, end);
|
|
56
|
+
}
|
|
57
|
+
function extractBalancedParenthetical(value, openIdx) {
|
|
58
|
+
let depth = 0;
|
|
59
|
+
for (let i = openIdx; i < value.length; i += 1) {
|
|
60
|
+
if (value[i] === "(") {
|
|
61
|
+
depth += 1;
|
|
62
|
+
}
|
|
63
|
+
else if (value[i] === ")") {
|
|
64
|
+
depth -= 1;
|
|
65
|
+
if (depth === 0) {
|
|
66
|
+
return value.slice(openIdx + 1, i).trim();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return value.slice(openIdx + 1).trim();
|
|
71
|
+
}
|
|
72
|
+
const INVALID_PLACEHOLDER_HEADS = new Set(["auto", "unknown", "unknown/other"]);
|
|
73
|
+
/**
|
|
74
|
+
* Rejects template or placeholder agent identities (`auto`, bare `orchestrator`,
|
|
75
|
+
* `unknown`, `unknown/other`, or `<provider>/<model>` placeholders) while keeping
|
|
76
|
+
* empty/omitted strings (`false`) and qualified orchestrators (`Orchestrator (Carbon)`) distinct.
|
|
77
|
+
*/
|
|
78
|
+
export function isInvalidPlaceholderIdentity(raw) {
|
|
79
|
+
if (raw == null)
|
|
80
|
+
return false;
|
|
81
|
+
let current = raw.trim().toLowerCase();
|
|
82
|
+
if (current === "")
|
|
83
|
+
return false;
|
|
84
|
+
if (current.includes("<") || current.includes(">")) {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
for (let depth = 0; depth < 16 && current !== ""; depth += 1) {
|
|
88
|
+
const parenIdx = current.indexOf("(");
|
|
89
|
+
const head = (parenIdx === -1 ? current : current.slice(0, parenIdx)).trim();
|
|
90
|
+
if (INVALID_PLACEHOLDER_HEADS.has(head)) {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
if (head !== "orchestrator") {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
if (parenIdx === -1) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
const qualifier = extractBalancedParenthetical(current, parenIdx);
|
|
100
|
+
if (qualifier === "") {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
current = qualifier;
|
|
104
|
+
}
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
12
107
|
/**
|
|
13
108
|
* Client qualifiers can carry spaces (`deepseek/VS Code (kimi-code)`), so a naive
|
|
14
109
|
* first-token match would truncate the family to `deepseek/vs`. The family is the
|
|
@@ -16,11 +111,12 @@ const FAMILY_PATTERN = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_. -]+$/;
|
|
|
16
111
|
* to single dashes; `deepseek/chat` keeps resolving to `deepseek/chat`.
|
|
17
112
|
*/
|
|
18
113
|
function extractFamily(value) {
|
|
19
|
-
const head = value.split("(")[0].trim();
|
|
114
|
+
const head = stripStrayOuterParens(value.split("(")[0].trim());
|
|
20
115
|
if (FAMILY_PATTERN.test(head)) {
|
|
21
116
|
return head.replace(/\s+/g, "-").toLowerCase();
|
|
22
117
|
}
|
|
23
|
-
for (const
|
|
118
|
+
for (const rawToken of value.trim().split(/\s+/)) {
|
|
119
|
+
const token = stripStrayOuterParens(rawToken);
|
|
24
120
|
const slashIdx = token.indexOf("/");
|
|
25
121
|
if (slashIdx > 0 && slashIdx < token.length - 1) {
|
|
26
122
|
return token.toLowerCase();
|
|
@@ -29,50 +125,226 @@ function extractFamily(value) {
|
|
|
29
125
|
return null;
|
|
30
126
|
}
|
|
31
127
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
128
|
+
* Official provider prefixes that may decorate a flagship slug.
|
|
129
|
+
*
|
|
130
|
+
* Stripping them is a `startsWith` probe rather than a regex alternation, so normalization
|
|
131
|
+
* stays linear in the length of the identity string.
|
|
132
|
+
*/
|
|
133
|
+
const EFFORT_VARIANT_SUFFIXES = [
|
|
134
|
+
"-extra-high",
|
|
135
|
+
"-ultrafast",
|
|
136
|
+
"-xtrahigh",
|
|
137
|
+
"-minimal",
|
|
138
|
+
"-medium",
|
|
139
|
+
"-xhigh",
|
|
140
|
+
"-extra",
|
|
141
|
+
"-light",
|
|
142
|
+
"-high",
|
|
143
|
+
"-fast",
|
|
144
|
+
"-none",
|
|
145
|
+
"-low",
|
|
146
|
+
"-max",
|
|
147
|
+
];
|
|
148
|
+
const PROVIDER_ALIASES = [
|
|
149
|
+
[["google/", "vertex/", "vertexai/"], "gemini"],
|
|
150
|
+
[["anthropic/"], "claude"],
|
|
151
|
+
[["codex/"], "openai"],
|
|
152
|
+
];
|
|
153
|
+
function isAsciiDigits(value) {
|
|
154
|
+
if (value.length === 0)
|
|
155
|
+
return false;
|
|
156
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
157
|
+
const code = value.charCodeAt(i);
|
|
158
|
+
if (code < 48 || code > 57)
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
function isVersionDigitSegment(value) {
|
|
164
|
+
return (value.length >= 1 &&
|
|
165
|
+
value.length <= 2 &&
|
|
166
|
+
isAsciiDigits(value) &&
|
|
167
|
+
!(value.length > 1 && value.startsWith("0")));
|
|
168
|
+
}
|
|
169
|
+
function shouldSkipEffortSuffix(slug, suffix) {
|
|
170
|
+
if (suffix !== "-max")
|
|
171
|
+
return false;
|
|
172
|
+
return slug.startsWith("qwen/") || slug === "qwen-max" || slug.endsWith("-codex-max");
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Linearly normalizes `<major>-<minor>` dash pairs on `claude/` and `openai/` slugs
|
|
176
|
+
* (e.g. `claude/fable-5-2` -> `claude/fable-5.2`, `openai/gpt-6-2-astra` -> `openai/gpt-6.2-astra`)
|
|
177
|
+
* in O(n) without regex backtracking.
|
|
178
|
+
*/
|
|
179
|
+
function normalizeProviderDashVersions(slug) {
|
|
180
|
+
const prefix = slug.startsWith("claude/")
|
|
181
|
+
? "claude/"
|
|
182
|
+
: slug.startsWith("openai/")
|
|
183
|
+
? "openai/"
|
|
184
|
+
: null;
|
|
185
|
+
if (prefix === null)
|
|
186
|
+
return slug;
|
|
187
|
+
const rest = slug.slice(prefix.length);
|
|
188
|
+
const parts = rest.split("-");
|
|
189
|
+
if (parts.length < 2)
|
|
190
|
+
return slug;
|
|
191
|
+
const out = [];
|
|
192
|
+
for (let i = 0; i < parts.length; i += 1) {
|
|
193
|
+
const cur = parts[i];
|
|
194
|
+
const next = i + 1 < parts.length ? parts[i + 1] : undefined;
|
|
195
|
+
const prevIsNonEmpty = i > 0 ? parts[i - 1] !== "" : false;
|
|
196
|
+
const nextAfterIsNotVersion = i + 2 >= parts.length || !isVersionDigitSegment(parts[i + 2]);
|
|
197
|
+
if (next !== undefined &&
|
|
198
|
+
(i === 0 || prevIsNonEmpty) &&
|
|
199
|
+
isVersionDigitSegment(cur) &&
|
|
200
|
+
isVersionDigitSegment(next) &&
|
|
201
|
+
nextAfterIsNotVersion) {
|
|
202
|
+
out.push(`${cur}.${next}`);
|
|
203
|
+
i += 1;
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
out.push(cur);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return `${prefix}${out.join("-")}`;
|
|
210
|
+
}
|
|
211
|
+
function stripCanonicalDecorations(collapsed) {
|
|
212
|
+
let slug = collapsed;
|
|
213
|
+
for (let i = 0; i < 2; i++) {
|
|
214
|
+
const suffix = EFFORT_VARIANT_SUFFIXES.find((candidate) => slug.endsWith(candidate) && !shouldSkipEffortSuffix(slug, candidate));
|
|
215
|
+
if (!suffix)
|
|
216
|
+
break;
|
|
217
|
+
slug = slug.slice(0, -suffix.length);
|
|
218
|
+
}
|
|
219
|
+
for (const [prefixes, target] of PROVIDER_ALIASES) {
|
|
220
|
+
const prefix = prefixes.find((p) => slug.startsWith(p));
|
|
221
|
+
if (!prefix)
|
|
222
|
+
continue;
|
|
223
|
+
const rest = slug.slice(prefix.length);
|
|
224
|
+
if (rest.startsWith(`${target}-`))
|
|
225
|
+
slug = `${target}/${rest.slice(target.length + 1)}`;
|
|
226
|
+
else
|
|
227
|
+
slug = rest.startsWith(`${target}/`) ? rest : `${target}/${rest}`;
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
if (slug.startsWith("anthropic-")) {
|
|
231
|
+
const rest = slug.slice("anthropic-".length);
|
|
232
|
+
slug = rest.startsWith("claude-") ? `claude/${rest.slice("claude-".length)}` : `claude/${rest}`;
|
|
233
|
+
}
|
|
234
|
+
if (slug.startsWith("openai-")) {
|
|
235
|
+
const rest = slug.slice("openai-".length);
|
|
236
|
+
slug = rest.startsWith("openai-") ? `openai/${rest.slice("openai-".length)}` : `openai/${rest}`;
|
|
237
|
+
}
|
|
238
|
+
if (slug.startsWith("gemini-"))
|
|
239
|
+
slug = `gemini/${slug.slice("gemini-".length)}`;
|
|
240
|
+
if (slug.startsWith("claude-"))
|
|
241
|
+
slug = `claude/${slug.slice("claude-".length)}`;
|
|
242
|
+
if (slug === "fable" || slug.startsWith("fable-"))
|
|
243
|
+
slug = `claude/${slug}`;
|
|
244
|
+
if (slug === "mythos" || slug.startsWith("mythos-"))
|
|
245
|
+
slug = `claude/${slug}`;
|
|
246
|
+
if (slug.startsWith("gpt-") ||
|
|
247
|
+
slug === "o1" ||
|
|
248
|
+
slug.startsWith("o1-") ||
|
|
249
|
+
slug === "o3" ||
|
|
250
|
+
slug.startsWith("o3-") ||
|
|
251
|
+
slug === "o4" ||
|
|
252
|
+
slug.startsWith("o4-") ||
|
|
253
|
+
slug.startsWith("codex-")) {
|
|
254
|
+
slug = `openai/${slug}`;
|
|
255
|
+
}
|
|
256
|
+
slug = normalizeProviderDashVersions(slug);
|
|
257
|
+
return slug;
|
|
258
|
+
}
|
|
259
|
+
function canonicalBasename(slug) {
|
|
260
|
+
if (slug.startsWith("gemini/"))
|
|
261
|
+
return slug.slice("gemini/".length);
|
|
262
|
+
if (slug.startsWith("gemini-"))
|
|
263
|
+
return slug.slice("gemini-".length);
|
|
264
|
+
return slug;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Normalizes display names, provider prefixes, dash/dot versions, and effort suffixes onto a
|
|
268
|
+
* canonical family identifier so formatting or reasoning-effort differences cannot bypass review gates.
|
|
35
269
|
*/
|
|
36
270
|
function normalizeCanonicalFamily(raw) {
|
|
37
271
|
const collapsed = raw
|
|
38
272
|
.trim()
|
|
39
273
|
.toLowerCase()
|
|
40
274
|
.replace(/[\s_]+/g, "-");
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
collapsed === "google/gemini-4-carbon" ||
|
|
45
|
-
collapsed === "google/gemini-carbon") {
|
|
46
|
-
return "gemini/carbon";
|
|
47
|
-
}
|
|
48
|
-
if (collapsed === "gemini-4-argon" ||
|
|
49
|
-
collapsed === "gemini/argon" ||
|
|
50
|
-
collapsed === "gemini/4-argon" ||
|
|
51
|
-
collapsed === "google/gemini-4-argon" ||
|
|
52
|
-
collapsed === "google/gemini-argon") {
|
|
53
|
-
return "gemini/argon";
|
|
54
|
-
}
|
|
55
|
-
return raw;
|
|
275
|
+
const slug = stripCanonicalDecorations(collapsed);
|
|
276
|
+
const basename = canonicalBasename(slug);
|
|
277
|
+
return CANONICAL_FLAGSHIP_BASENAMES.get(basename) ?? slug;
|
|
56
278
|
}
|
|
57
|
-
|
|
279
|
+
/**
|
|
280
|
+
* Tier-1 and tier-2 flagship basenames, keyed by the identity once provider prefix,
|
|
281
|
+
* `gemini/` binder and `-high` suffix have been removed.
|
|
282
|
+
*/
|
|
283
|
+
const CANONICAL_FLAGSHIP_BASENAMES = new Map([
|
|
284
|
+
["4-carbon", "gemini/carbon"],
|
|
285
|
+
["carbon", "gemini/carbon"],
|
|
286
|
+
["pro-orchestrator", "gemini/carbon"],
|
|
287
|
+
["4-argon", "gemini/argon"],
|
|
288
|
+
["argon", "gemini/argon"],
|
|
289
|
+
["pro-orchestrator-argon", "gemini/argon"],
|
|
290
|
+
["4-neon", "gemini/neon"],
|
|
291
|
+
["neon", "gemini/neon"],
|
|
292
|
+
["pro-orchestrator-neon", "gemini/neon"],
|
|
293
|
+
["4-hydrogen", "gemini/hydrogen"],
|
|
294
|
+
["hydrogen", "gemini/hydrogen"],
|
|
295
|
+
["flash-worker-agy", "gemini/flash-worker-agy"],
|
|
296
|
+
]);
|
|
297
|
+
function parseIdentityInternal(value, depth) {
|
|
58
298
|
if (value === null)
|
|
59
299
|
return null;
|
|
60
|
-
const
|
|
61
|
-
|
|
300
|
+
const trimmedValue = value.trim();
|
|
301
|
+
if (trimmedValue === "")
|
|
302
|
+
return null;
|
|
303
|
+
const cleaned = unwrapOuterBalancedParens(trimmedValue);
|
|
304
|
+
if (cleaned === "")
|
|
305
|
+
return null;
|
|
306
|
+
const parenIdx = cleaned.indexOf("(");
|
|
307
|
+
const rawHead = (parenIdx === -1 ? cleaned : cleaned.slice(0, parenIdx)).trim();
|
|
308
|
+
const head = stripStrayOuterParens(rawHead);
|
|
309
|
+
const collapsedHead = head.toLowerCase().replace(/[\s_]+/g, "-");
|
|
310
|
+
if (collapsedHead === "orchestrator" && parenIdx !== -1 && depth < 16) {
|
|
311
|
+
const qualifier = extractBalancedParenthetical(cleaned, parenIdx);
|
|
312
|
+
const lowerQualifier = qualifier.toLowerCase();
|
|
313
|
+
if (lowerQualifier.includes("carbon")) {
|
|
314
|
+
return { full: trimmedValue.toLowerCase(), family: "gemini/carbon" };
|
|
315
|
+
}
|
|
316
|
+
if (lowerQualifier.includes("argon")) {
|
|
317
|
+
return { full: trimmedValue.toLowerCase(), family: "gemini/argon" };
|
|
318
|
+
}
|
|
319
|
+
if (lowerQualifier.includes("neon")) {
|
|
320
|
+
return { full: trimmedValue.toLowerCase(), family: "gemini/neon" };
|
|
321
|
+
}
|
|
322
|
+
if (qualifier !== "") {
|
|
323
|
+
const inner = parseIdentityInternal(qualifier, depth + 1);
|
|
324
|
+
if (inner !== null) {
|
|
325
|
+
return { full: trimmedValue.toLowerCase(), family: inner.family };
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
const family = extractFamily(cleaned);
|
|
62
330
|
if (family === null) {
|
|
63
331
|
const trimmed = head.toLowerCase();
|
|
64
332
|
if (trimmed === "") {
|
|
65
|
-
const
|
|
66
|
-
return
|
|
67
|
-
|
|
68
|
-
|
|
333
|
+
const strippedFull = stripStrayOuterParens(cleaned).toLowerCase();
|
|
334
|
+
return {
|
|
335
|
+
full: trimmedValue.toLowerCase(),
|
|
336
|
+
family: normalizeCanonicalFamily(strippedFull || cleaned.toLowerCase()),
|
|
337
|
+
};
|
|
69
338
|
}
|
|
70
339
|
return {
|
|
71
|
-
full:
|
|
340
|
+
full: trimmedValue.toLowerCase(),
|
|
72
341
|
family: normalizeCanonicalFamily(trimmed),
|
|
73
342
|
};
|
|
74
343
|
}
|
|
75
|
-
return { full:
|
|
344
|
+
return { full: trimmedValue.toLowerCase(), family: normalizeCanonicalFamily(family) };
|
|
345
|
+
}
|
|
346
|
+
export function parseIdentity(value) {
|
|
347
|
+
return parseIdentityInternal(value, 0);
|
|
76
348
|
}
|
|
77
349
|
export function extractTrailers(commitBody) {
|
|
78
350
|
let author = null;
|
|
@@ -95,18 +367,80 @@ export function extractTrailers(commitBody) {
|
|
|
95
367
|
}
|
|
96
368
|
return { author, reviewer };
|
|
97
369
|
}
|
|
98
|
-
|
|
370
|
+
/**
|
|
371
|
+
* Derives vendor strictly from the normalized model family prefix before `/`,
|
|
372
|
+
* never from parenthetical client qualifiers.
|
|
373
|
+
*/
|
|
374
|
+
export function extractVendor(identity) {
|
|
375
|
+
return identity.family.split("/")[0];
|
|
376
|
+
}
|
|
377
|
+
function isClaudeFableOrMythos(family) {
|
|
378
|
+
return family.startsWith("claude/fable") || family.startsWith("claude/mythos");
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Evaluates review-gate separation under the resolved `review_gate` mode.
|
|
382
|
+
* Identical full identity (`author.full === reviewer.full`) is an unbreakable error floor in all modes.
|
|
383
|
+
*/
|
|
384
|
+
export function checkReviewGate(authorStr, reviewerStr, mode = "intra-fleet") {
|
|
385
|
+
if (isInvalidPlaceholderIdentity(authorStr)) {
|
|
386
|
+
return {
|
|
387
|
+
violated: true,
|
|
388
|
+
severity: "error",
|
|
389
|
+
message: `Invalid placeholder author identity '${authorStr}'. Specify the exact runtime model identity (e.g. 'google/gemini-3.8-flash-high (antigravity)').`,
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
if (reviewerStr !== null &&
|
|
393
|
+
reviewerStr.trim() !== "" &&
|
|
394
|
+
isInvalidPlaceholderIdentity(reviewerStr)) {
|
|
395
|
+
return {
|
|
396
|
+
violated: true,
|
|
397
|
+
severity: "error",
|
|
398
|
+
message: `Invalid placeholder reviewer identity '${reviewerStr}'. Specify the exact runtime model identity (e.g. 'claude/opus-4.6 (claude-code)').`,
|
|
399
|
+
};
|
|
400
|
+
}
|
|
99
401
|
const author = parseIdentity(authorStr);
|
|
100
402
|
const reviewer = parseIdentity(reviewerStr);
|
|
101
|
-
if (author
|
|
102
|
-
|
|
403
|
+
if (author === null || reviewer === null) {
|
|
404
|
+
return { violated: false, severity: "error" };
|
|
405
|
+
}
|
|
406
|
+
if (author.full === reviewer.full) {
|
|
407
|
+
return {
|
|
408
|
+
violated: true,
|
|
409
|
+
severity: "error",
|
|
410
|
+
message: `Self-approval detected: author '${authorStr}' and reviewer '${reviewerStr}' share the same identity ('${author.full}').`,
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
if (mode === "off")
|
|
414
|
+
return { violated: false, severity: "warn" };
|
|
415
|
+
if (author.family === reviewer.family) {
|
|
416
|
+
return {
|
|
417
|
+
violated: true,
|
|
418
|
+
severity: mode === "advisory" ? "warn" : "error",
|
|
419
|
+
message: `Self-approval detected: author '${authorStr}' and reviewer '${reviewerStr}' share the same model family ('${author.family}')${mode === "advisory" ? " (advisory review_gate mode)" : ""}.`,
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
if (isClaudeFableOrMythos(author.family) && isClaudeFableOrMythos(reviewer.family)) {
|
|
423
|
+
return {
|
|
424
|
+
violated: true,
|
|
425
|
+
severity: mode === "advisory" ? "warn" : "error",
|
|
426
|
+
message: `Self-approval detected: Claude Fable and Claude Mythos share identical base model weights ('${author.family}' vs '${reviewer.family}')${mode === "advisory" ? " (advisory review_gate mode)" : ""}.`,
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
if (mode === "cross-vendor") {
|
|
430
|
+
const vendor = extractVendor(author);
|
|
431
|
+
if (vendor === extractVendor(reviewer)) {
|
|
103
432
|
return {
|
|
104
|
-
|
|
105
|
-
|
|
433
|
+
violated: true,
|
|
434
|
+
severity: "error",
|
|
435
|
+
message: `Cross-vendor review-gate violation: author '${authorStr}' and reviewer '${reviewerStr}' share the same vendor ('${vendor}').`,
|
|
106
436
|
};
|
|
107
437
|
}
|
|
108
438
|
}
|
|
109
|
-
return {
|
|
439
|
+
return { violated: false, severity: mode === "advisory" ? "warn" : "error" };
|
|
440
|
+
}
|
|
441
|
+
export function checkSelfApproval(authorStr, reviewerStr) {
|
|
442
|
+
const res = checkReviewGate(authorStr, reviewerStr, "intra-fleet");
|
|
443
|
+
return res.violated ? { isSelfApproval: true, message: res.message } : { isSelfApproval: false };
|
|
110
444
|
}
|
|
111
445
|
function normalizePath(value) {
|
|
112
446
|
return value.replace(/\\/g, "/").replace(/^\.\//, "").trim();
|
|
@@ -116,19 +450,89 @@ function toStringList(value) {
|
|
|
116
450
|
return [];
|
|
117
451
|
return value.filter((entry) => typeof entry === "string").map(normalizePath);
|
|
118
452
|
}
|
|
119
|
-
function
|
|
120
|
-
if (
|
|
453
|
+
function matchSegment(segment, pattern) {
|
|
454
|
+
if (pattern === "*" || pattern === "**")
|
|
455
|
+
return true;
|
|
456
|
+
if (!pattern.includes("*"))
|
|
457
|
+
return segment === pattern;
|
|
458
|
+
const parts = pattern.split("*");
|
|
459
|
+
const first = parts[0];
|
|
460
|
+
const last = parts[parts.length - 1];
|
|
461
|
+
if (!segment.startsWith(first))
|
|
462
|
+
return false;
|
|
463
|
+
if (last !== "" && !segment.endsWith(last))
|
|
464
|
+
return false;
|
|
465
|
+
let pos = first.length;
|
|
466
|
+
const limit = segment.length - last.length;
|
|
467
|
+
if (pos > limit)
|
|
468
|
+
return false;
|
|
469
|
+
for (let i = 1; i < parts.length - 1; i += 1) {
|
|
470
|
+
const part = parts[i];
|
|
471
|
+
if (part === "")
|
|
472
|
+
continue;
|
|
473
|
+
const idx = segment.indexOf(part, pos);
|
|
474
|
+
if (idx === -1 || idx + part.length > limit)
|
|
475
|
+
return false;
|
|
476
|
+
pos = idx + part.length;
|
|
477
|
+
}
|
|
478
|
+
return true;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Matches a normalized repository path against a contract rule (`dir/`, exact path,
|
|
482
|
+
* intra-segment `*` wildcards, or `**` directory-crossing segments) in deterministic
|
|
483
|
+
* linear time without `new RegExp`.
|
|
484
|
+
*/
|
|
485
|
+
export function matchesPath(file, rule) {
|
|
486
|
+
const normFile = normalizePath(file);
|
|
487
|
+
const normRule = normalizePath(rule);
|
|
488
|
+
if (normFile === "" || normRule === "")
|
|
121
489
|
return false;
|
|
122
|
-
if (
|
|
123
|
-
return
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
490
|
+
if (normRule.endsWith("/") && !normRule.includes("*")) {
|
|
491
|
+
return normFile.startsWith(normRule);
|
|
492
|
+
}
|
|
493
|
+
if (!normRule.includes("*"))
|
|
494
|
+
return normFile === normRule;
|
|
495
|
+
const fileSegments = normFile.split("/");
|
|
496
|
+
let ruleSegments;
|
|
497
|
+
if (normRule.endsWith("/")) {
|
|
498
|
+
let dirPrefix = normRule;
|
|
499
|
+
while (dirPrefix.endsWith("/")) {
|
|
500
|
+
dirPrefix = dirPrefix.slice(0, -1);
|
|
501
|
+
}
|
|
502
|
+
if (dirPrefix === "")
|
|
503
|
+
return false;
|
|
504
|
+
ruleSegments = [...dirPrefix.split("/"), "*", "**"];
|
|
505
|
+
}
|
|
506
|
+
else {
|
|
507
|
+
ruleSegments = normRule.split("/");
|
|
130
508
|
}
|
|
131
|
-
|
|
509
|
+
let fi = 0;
|
|
510
|
+
let ri = 0;
|
|
511
|
+
let starRi = -1;
|
|
512
|
+
let matchFi = 0;
|
|
513
|
+
while (fi < fileSegments.length) {
|
|
514
|
+
if (ri < ruleSegments.length && ruleSegments[ri] === "**") {
|
|
515
|
+
starRi = ri;
|
|
516
|
+
matchFi = fi;
|
|
517
|
+
ri += 1;
|
|
518
|
+
}
|
|
519
|
+
else if (ri < ruleSegments.length && matchSegment(fileSegments[fi], ruleSegments[ri])) {
|
|
520
|
+
fi += 1;
|
|
521
|
+
ri += 1;
|
|
522
|
+
}
|
|
523
|
+
else if (starRi !== -1) {
|
|
524
|
+
matchFi += 1;
|
|
525
|
+
fi = matchFi;
|
|
526
|
+
ri = starRi + 1;
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
return false;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
while (ri < ruleSegments.length && ruleSegments[ri] === "**") {
|
|
533
|
+
ri += 1;
|
|
534
|
+
}
|
|
535
|
+
return ri === ruleSegments.length;
|
|
132
536
|
}
|
|
133
537
|
function listCommitFiles(sha, targetDir) {
|
|
134
538
|
try {
|
|
@@ -173,8 +577,23 @@ function isEscalationAcknowledged(note, subject) {
|
|
|
173
577
|
return false;
|
|
174
578
|
}
|
|
175
579
|
}
|
|
580
|
+
/**
|
|
581
|
+
* A tier-1 issue declares its subtasks as orchestrator work, so a tier-1 author editing
|
|
582
|
+
* implementation files there is inside its scope and needs no escalation acknowledgement.
|
|
583
|
+
*/
|
|
584
|
+
function isTierOneIssue(note) {
|
|
585
|
+
if (note === null)
|
|
586
|
+
return false;
|
|
587
|
+
try {
|
|
588
|
+
const parsed = JSON.parse(note);
|
|
589
|
+
return parsed?.issue?.tier === "tier-1";
|
|
590
|
+
}
|
|
591
|
+
catch {
|
|
592
|
+
return false;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
176
595
|
function isImplementationFile(file) {
|
|
177
|
-
return !file
|
|
596
|
+
return !isGovernanceOrConfigSurface(file) && !file.startsWith(".lognexus/");
|
|
178
597
|
}
|
|
179
598
|
/**
|
|
180
599
|
* Framework bookkeeping (`state.json`, plan files) is rewritten by the CLI on the
|
|
@@ -184,7 +603,31 @@ function isImplementationFile(file) {
|
|
|
184
603
|
function isBookkeepingFile(file) {
|
|
185
604
|
return file.startsWith(".lognexus/") || file.startsWith("docs/contexto/");
|
|
186
605
|
}
|
|
187
|
-
|
|
606
|
+
const GATE_STRICTNESS = {
|
|
607
|
+
off: 0,
|
|
608
|
+
advisory: 1,
|
|
609
|
+
"intra-fleet": 2,
|
|
610
|
+
"cross-vendor": 3,
|
|
611
|
+
};
|
|
612
|
+
function readGitFileAtRef(ref, filePath, targetDir) {
|
|
613
|
+
try {
|
|
614
|
+
const safeRef = validateGitReference(ref);
|
|
615
|
+
return execFileSync("git", ["show", `${safeRef}:${filePath}`], {
|
|
616
|
+
cwd: targetDir,
|
|
617
|
+
encoding: "utf8",
|
|
618
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
619
|
+
shell: false,
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
catch {
|
|
623
|
+
return null;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
function parseEffectiveGate(content) {
|
|
627
|
+
const { configuredReviewGate } = parseRoutingConfigContent(content);
|
|
628
|
+
return configuredReviewGate === "auto" ? "intra-fleet" : configuredReviewGate;
|
|
629
|
+
}
|
|
630
|
+
function auditCommit(item, targetDir, gateMode) {
|
|
188
631
|
const violations = [];
|
|
189
632
|
const base = { commitSha: item.sha, shortSha: item.shortSha };
|
|
190
633
|
if (item.author === null) {
|
|
@@ -195,16 +638,51 @@ function auditCommit(item, targetDir) {
|
|
|
195
638
|
severity: "error",
|
|
196
639
|
});
|
|
197
640
|
}
|
|
198
|
-
const
|
|
199
|
-
|
|
641
|
+
const hasInvalidAuthor = isInvalidPlaceholderIdentity(item.author);
|
|
642
|
+
const hasInvalidReviewer = isInvalidPlaceholderIdentity(item.reviewer);
|
|
643
|
+
if (hasInvalidAuthor) {
|
|
200
644
|
violations.push({
|
|
201
645
|
...base,
|
|
202
|
-
rule: "
|
|
203
|
-
message:
|
|
204
|
-
`Self-approval detected: author '${item.author}' and reviewer '${item.reviewer}' share the same identity.`,
|
|
646
|
+
rule: "invalid-identity",
|
|
647
|
+
message: `Invalid placeholder Authored-by identity '${item.author}'. Specify the exact runtime model identity (e.g. 'google/gemini-3.8-flash-high (antigravity)').`,
|
|
205
648
|
severity: "error",
|
|
206
649
|
});
|
|
207
650
|
}
|
|
651
|
+
if (hasInvalidReviewer) {
|
|
652
|
+
violations.push({
|
|
653
|
+
...base,
|
|
654
|
+
rule: "invalid-identity",
|
|
655
|
+
message: `Invalid placeholder Reviewed-by identity '${item.reviewer}'. Specify the exact runtime model identity (e.g. 'claude/opus-4.6 (claude-code)').`,
|
|
656
|
+
severity: "error",
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
if (!hasInvalidAuthor && !hasInvalidReviewer) {
|
|
660
|
+
const gateCheck = checkReviewGate(item.author, item.reviewer, gateMode);
|
|
661
|
+
if (gateCheck.violated) {
|
|
662
|
+
violations.push({
|
|
663
|
+
...base,
|
|
664
|
+
rule: "review-gate-separation",
|
|
665
|
+
message: gateCheck.message ??
|
|
666
|
+
`Self-approval detected: author '${item.author}' and reviewer '${item.reviewer}' share the same identity.`,
|
|
667
|
+
severity: gateCheck.severity,
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
const changedFiles = listCommitFiles(item.sha, targetDir);
|
|
672
|
+
if (changedFiles.includes(".lognexus/routing.md")) {
|
|
673
|
+
const commitRouting = readGitFileAtRef(item.sha, ".lognexus/routing.md", targetDir);
|
|
674
|
+
if (commitRouting !== null) {
|
|
675
|
+
const commitGate = parseEffectiveGate(commitRouting);
|
|
676
|
+
if (GATE_STRICTNESS[commitGate] < GATE_STRICTNESS[gateMode]) {
|
|
677
|
+
violations.push({
|
|
678
|
+
...base,
|
|
679
|
+
rule: "review-gate-separation",
|
|
680
|
+
message: `Commit modifies .lognexus/routing.md and weakens review_gate from '${gateMode}' to '${commitGate}'; base branch gate '${gateMode}' remains enforced.`,
|
|
681
|
+
severity: "warn",
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
}
|
|
208
686
|
const note = getNote(item.sha, { cwd: targetDir });
|
|
209
687
|
if (note === null) {
|
|
210
688
|
violations.push({
|
|
@@ -234,7 +712,6 @@ function auditCommit(item, targetDir) {
|
|
|
234
712
|
if (contract !== null) {
|
|
235
713
|
const allowedFiles = toStringList(contract.allowedFiles);
|
|
236
714
|
const forbiddenFiles = toStringList(contract.forbiddenFiles);
|
|
237
|
-
const changedFiles = listCommitFiles(item.sha, targetDir);
|
|
238
715
|
const forbidden = changedFiles.filter((file) => forbiddenFiles.some((rule) => matchesPath(file, rule)));
|
|
239
716
|
if (forbidden.length > 0) {
|
|
240
717
|
violations.push({
|
|
@@ -256,6 +733,7 @@ function auditCommit(item, targetDir) {
|
|
|
256
733
|
}
|
|
257
734
|
}
|
|
258
735
|
if (inferTierFromAuthor(item.author) === "tier-1" &&
|
|
736
|
+
!isTierOneIssue(note) &&
|
|
259
737
|
!isEscalationAcknowledged(note, item.subject)) {
|
|
260
738
|
const implementationFiles = changedFiles.filter(isImplementationFile);
|
|
261
739
|
if (implementationFiles.length > 0) {
|
|
@@ -270,10 +748,15 @@ function auditCommit(item, targetDir) {
|
|
|
270
748
|
}
|
|
271
749
|
return violations;
|
|
272
750
|
}
|
|
273
|
-
export function auditBranch(baseBranch = "main", targetDir = process.cwd()) {
|
|
751
|
+
export function auditBranch(baseBranch = "main", targetDir = process.cwd(), options) {
|
|
274
752
|
const safeBase = rejectNotesReference(baseBranch, "audit base branch");
|
|
753
|
+
const baseRoutingRaw = readGitFileAtRef(safeBase, ".lognexus/routing.md", targetDir);
|
|
754
|
+
const gateMode = options?.reviewGateMode ??
|
|
755
|
+
(baseRoutingRaw !== null
|
|
756
|
+
? parseEffectiveGate(baseRoutingRaw)
|
|
757
|
+
: resolveRoutingProfile(targetDir).effectiveReviewGate);
|
|
275
758
|
const timeline = getJourneyTimeline(safeBase, targetDir);
|
|
276
|
-
const violations = timeline.items.flatMap((item) => auditCommit(item, targetDir));
|
|
759
|
+
const violations = timeline.items.flatMap((item) => auditCommit(item, targetDir, gateMode));
|
|
277
760
|
const normalizedCurrent = timeline.branch.replace(/^refs\/heads\//, "");
|
|
278
761
|
const normalizedBase = safeBase.replace(/^refs\/heads\//, "").replace(/^origin\//, "");
|
|
279
762
|
if (normalizedCurrent === normalizedBase && timeline.commitCount === 0) {
|