@digital-lake/lognexus 1.3.6 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +2 -1
- package/NOTICE.md +15 -7
- package/README.md +67 -42
- package/dist/audit/audit.d.ts +37 -2
- package/dist/audit/audit.d.ts.map +1 -1
- package/dist/audit/audit.js +483 -57
- package/dist/audit/audit.js.map +1 -1
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +292 -32
- 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 -16
- 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 +12 -8
- 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 +256 -0
- package/dist/routing/profile.js.map +1 -0
- package/dist/scaffold.d.ts +2 -2
- package/dist/scaffold.d.ts.map +1 -1
- package/dist/scaffold.js +22 -17
- 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 +167 -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 +213 -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 +261 -31
- 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 +4 -4
- 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,179 @@ 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
|
+
"-xtrahigh",
|
|
136
|
+
"-xhigh",
|
|
137
|
+
"-extra",
|
|
138
|
+
"-minimal",
|
|
139
|
+
"-medium",
|
|
140
|
+
"-high",
|
|
141
|
+
"-low",
|
|
142
|
+
"-none",
|
|
143
|
+
];
|
|
144
|
+
const PROVIDER_ALIASES = [
|
|
145
|
+
[["google/", "vertex/", "vertexai/"], "gemini"],
|
|
146
|
+
[["anthropic/"], "claude"],
|
|
147
|
+
];
|
|
148
|
+
function isAsciiDigits(value) {
|
|
149
|
+
if (value.length === 0)
|
|
150
|
+
return false;
|
|
151
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
152
|
+
const code = value.charCodeAt(i);
|
|
153
|
+
if (code < 48 || code > 57)
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
function isLowerAlnumOrDash(value) {
|
|
159
|
+
if (value.length === 0)
|
|
160
|
+
return false;
|
|
161
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
162
|
+
const code = value.charCodeAt(i);
|
|
163
|
+
const isLower = code >= 97 && code <= 122;
|
|
164
|
+
const isDigit = code >= 48 && code <= 57;
|
|
165
|
+
if (!isLower && !isDigit && code !== 45)
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
/** Converts trailing `-<major>-<minor>` dash pairs on `claude/` slugs to `.<minor>` in O(n). */
|
|
171
|
+
function normalizeClaudeTrailingVersion(slug) {
|
|
172
|
+
if (!slug.startsWith("claude/"))
|
|
173
|
+
return slug;
|
|
174
|
+
const rest = slug.slice("claude/".length);
|
|
175
|
+
const parts = rest.split("-");
|
|
176
|
+
if (parts.length < 3)
|
|
177
|
+
return slug;
|
|
178
|
+
const minor = parts[parts.length - 1];
|
|
179
|
+
const major = parts[parts.length - 2];
|
|
180
|
+
const prefix = parts.slice(0, -2).join("-");
|
|
181
|
+
if (!isLowerAlnumOrDash(prefix) || !isAsciiDigits(major) || !isAsciiDigits(minor)) {
|
|
182
|
+
return slug;
|
|
183
|
+
}
|
|
184
|
+
return `claude/${prefix}-${major}.${minor}`;
|
|
185
|
+
}
|
|
186
|
+
function stripCanonicalDecorations(collapsed) {
|
|
187
|
+
let slug = collapsed;
|
|
188
|
+
for (let i = 0; i < 2; i++) {
|
|
189
|
+
const suffix = EFFORT_VARIANT_SUFFIXES.find((candidate) => slug.endsWith(candidate));
|
|
190
|
+
if (!suffix)
|
|
191
|
+
break;
|
|
192
|
+
slug = slug.slice(0, -suffix.length);
|
|
193
|
+
}
|
|
194
|
+
for (const [prefixes, target] of PROVIDER_ALIASES) {
|
|
195
|
+
const prefix = prefixes.find((p) => slug.startsWith(p));
|
|
196
|
+
if (!prefix)
|
|
197
|
+
continue;
|
|
198
|
+
const rest = slug.slice(prefix.length);
|
|
199
|
+
if (rest.startsWith(`${target}-`))
|
|
200
|
+
slug = `${target}/${rest.slice(target.length + 1)}`;
|
|
201
|
+
else
|
|
202
|
+
slug = rest.startsWith(`${target}/`) ? rest : `${target}/${rest}`;
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
if (slug.startsWith("gemini-"))
|
|
206
|
+
slug = `gemini/${slug.slice("gemini-".length)}`;
|
|
207
|
+
if (slug.startsWith("claude-"))
|
|
208
|
+
slug = `claude/${slug.slice("claude-".length)}`;
|
|
209
|
+
slug = normalizeClaudeTrailingVersion(slug);
|
|
210
|
+
return slug;
|
|
211
|
+
}
|
|
212
|
+
function canonicalBasename(slug) {
|
|
213
|
+
if (slug.startsWith("gemini/"))
|
|
214
|
+
return slug.slice("gemini/".length);
|
|
215
|
+
if (slug.startsWith("gemini-"))
|
|
216
|
+
return slug.slice("gemini-".length);
|
|
217
|
+
return slug;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Normalizes display names, provider prefixes, dash/dot versions, and effort suffixes onto a
|
|
221
|
+
* canonical family identifier so formatting or reasoning-effort differences cannot bypass review gates.
|
|
35
222
|
*/
|
|
36
223
|
function normalizeCanonicalFamily(raw) {
|
|
37
224
|
const collapsed = raw
|
|
38
225
|
.trim()
|
|
39
226
|
.toLowerCase()
|
|
40
227
|
.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;
|
|
228
|
+
const slug = stripCanonicalDecorations(collapsed);
|
|
229
|
+
const basename = canonicalBasename(slug);
|
|
230
|
+
return CANONICAL_FLAGSHIP_BASENAMES.get(basename) ?? slug;
|
|
56
231
|
}
|
|
57
|
-
|
|
232
|
+
/**
|
|
233
|
+
* Tier-1 and tier-2 flagship basenames, keyed by the identity once provider prefix,
|
|
234
|
+
* `gemini/` binder and `-high` suffix have been removed.
|
|
235
|
+
*/
|
|
236
|
+
const CANONICAL_FLAGSHIP_BASENAMES = new Map([
|
|
237
|
+
["4-carbon", "gemini/carbon"],
|
|
238
|
+
["carbon", "gemini/carbon"],
|
|
239
|
+
["pro-orchestrator", "gemini/carbon"],
|
|
240
|
+
["4-argon", "gemini/argon"],
|
|
241
|
+
["argon", "gemini/argon"],
|
|
242
|
+
["pro-orchestrator-argon", "gemini/argon"],
|
|
243
|
+
["4-neon", "gemini/neon"],
|
|
244
|
+
["neon", "gemini/neon"],
|
|
245
|
+
["pro-orchestrator-neon", "gemini/neon"],
|
|
246
|
+
["4-hydrogen", "gemini/hydrogen"],
|
|
247
|
+
["hydrogen", "gemini/hydrogen"],
|
|
248
|
+
["flash-worker-agy", "gemini/flash-worker-agy"],
|
|
249
|
+
]);
|
|
250
|
+
function parseIdentityInternal(value, depth) {
|
|
58
251
|
if (value === null)
|
|
59
252
|
return null;
|
|
60
|
-
const
|
|
61
|
-
|
|
253
|
+
const trimmedValue = value.trim();
|
|
254
|
+
if (trimmedValue === "")
|
|
255
|
+
return null;
|
|
256
|
+
const cleaned = unwrapOuterBalancedParens(trimmedValue);
|
|
257
|
+
if (cleaned === "")
|
|
258
|
+
return null;
|
|
259
|
+
const parenIdx = cleaned.indexOf("(");
|
|
260
|
+
const rawHead = (parenIdx === -1 ? cleaned : cleaned.slice(0, parenIdx)).trim();
|
|
261
|
+
const head = stripStrayOuterParens(rawHead);
|
|
262
|
+
const collapsedHead = head.toLowerCase().replace(/[\s_]+/g, "-");
|
|
263
|
+
if (collapsedHead === "orchestrator" && parenIdx !== -1 && depth < 16) {
|
|
264
|
+
const qualifier = extractBalancedParenthetical(cleaned, parenIdx);
|
|
265
|
+
const lowerQualifier = qualifier.toLowerCase();
|
|
266
|
+
if (lowerQualifier.includes("carbon")) {
|
|
267
|
+
return { full: trimmedValue.toLowerCase(), family: "gemini/carbon" };
|
|
268
|
+
}
|
|
269
|
+
if (lowerQualifier.includes("argon")) {
|
|
270
|
+
return { full: trimmedValue.toLowerCase(), family: "gemini/argon" };
|
|
271
|
+
}
|
|
272
|
+
if (lowerQualifier.includes("neon")) {
|
|
273
|
+
return { full: trimmedValue.toLowerCase(), family: "gemini/neon" };
|
|
274
|
+
}
|
|
275
|
+
if (qualifier !== "") {
|
|
276
|
+
const inner = parseIdentityInternal(qualifier, depth + 1);
|
|
277
|
+
if (inner !== null) {
|
|
278
|
+
return { full: trimmedValue.toLowerCase(), family: inner.family };
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
const family = extractFamily(cleaned);
|
|
62
283
|
if (family === null) {
|
|
63
284
|
const trimmed = head.toLowerCase();
|
|
64
285
|
if (trimmed === "") {
|
|
65
|
-
const
|
|
66
|
-
return
|
|
67
|
-
|
|
68
|
-
|
|
286
|
+
const strippedFull = stripStrayOuterParens(cleaned).toLowerCase();
|
|
287
|
+
return {
|
|
288
|
+
full: trimmedValue.toLowerCase(),
|
|
289
|
+
family: normalizeCanonicalFamily(strippedFull || cleaned.toLowerCase()),
|
|
290
|
+
};
|
|
69
291
|
}
|
|
70
292
|
return {
|
|
71
|
-
full:
|
|
293
|
+
full: trimmedValue.toLowerCase(),
|
|
72
294
|
family: normalizeCanonicalFamily(trimmed),
|
|
73
295
|
};
|
|
74
296
|
}
|
|
75
|
-
return { full:
|
|
297
|
+
return { full: trimmedValue.toLowerCase(), family: normalizeCanonicalFamily(family) };
|
|
298
|
+
}
|
|
299
|
+
export function parseIdentity(value) {
|
|
300
|
+
return parseIdentityInternal(value, 0);
|
|
76
301
|
}
|
|
77
302
|
export function extractTrailers(commitBody) {
|
|
78
303
|
let author = null;
|
|
@@ -95,18 +320,70 @@ export function extractTrailers(commitBody) {
|
|
|
95
320
|
}
|
|
96
321
|
return { author, reviewer };
|
|
97
322
|
}
|
|
98
|
-
|
|
323
|
+
/**
|
|
324
|
+
* Derives vendor strictly from the normalized model family prefix before `/`,
|
|
325
|
+
* never from parenthetical client qualifiers.
|
|
326
|
+
*/
|
|
327
|
+
export function extractVendor(identity) {
|
|
328
|
+
return identity.family.split("/")[0];
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Evaluates review-gate separation under the resolved `review_gate` mode.
|
|
332
|
+
* Identical full identity (`author.full === reviewer.full`) is an unbreakable error floor in all modes.
|
|
333
|
+
*/
|
|
334
|
+
export function checkReviewGate(authorStr, reviewerStr, mode = "intra-fleet") {
|
|
335
|
+
if (isInvalidPlaceholderIdentity(authorStr)) {
|
|
336
|
+
return {
|
|
337
|
+
violated: true,
|
|
338
|
+
severity: "error",
|
|
339
|
+
message: `Invalid placeholder author identity '${authorStr}'. Specify the exact runtime model identity (e.g. 'google/gemini-3.8-flash-high (antigravity)').`,
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
if (reviewerStr !== null &&
|
|
343
|
+
reviewerStr.trim() !== "" &&
|
|
344
|
+
isInvalidPlaceholderIdentity(reviewerStr)) {
|
|
345
|
+
return {
|
|
346
|
+
violated: true,
|
|
347
|
+
severity: "error",
|
|
348
|
+
message: `Invalid placeholder reviewer identity '${reviewerStr}'. Specify the exact runtime model identity (e.g. 'claude/opus-4.6 (claude-code)').`,
|
|
349
|
+
};
|
|
350
|
+
}
|
|
99
351
|
const author = parseIdentity(authorStr);
|
|
100
352
|
const reviewer = parseIdentity(reviewerStr);
|
|
101
|
-
if (author
|
|
102
|
-
|
|
353
|
+
if (author === null || reviewer === null) {
|
|
354
|
+
return { violated: false, severity: "error" };
|
|
355
|
+
}
|
|
356
|
+
if (author.full === reviewer.full) {
|
|
357
|
+
return {
|
|
358
|
+
violated: true,
|
|
359
|
+
severity: "error",
|
|
360
|
+
message: `Self-approval detected: author '${authorStr}' and reviewer '${reviewerStr}' share the same identity ('${author.full}').`,
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
if (mode === "off")
|
|
364
|
+
return { violated: false, severity: "warn" };
|
|
365
|
+
if (author.family === reviewer.family) {
|
|
366
|
+
return {
|
|
367
|
+
violated: true,
|
|
368
|
+
severity: mode === "advisory" ? "warn" : "error",
|
|
369
|
+
message: `Self-approval detected: author '${authorStr}' and reviewer '${reviewerStr}' share the same model family ('${author.family}')${mode === "advisory" ? " (advisory review_gate mode)" : ""}.`,
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
if (mode === "cross-vendor") {
|
|
373
|
+
const vendor = extractVendor(author);
|
|
374
|
+
if (vendor === extractVendor(reviewer)) {
|
|
103
375
|
return {
|
|
104
|
-
|
|
105
|
-
|
|
376
|
+
violated: true,
|
|
377
|
+
severity: "error",
|
|
378
|
+
message: `Cross-vendor review-gate violation: author '${authorStr}' and reviewer '${reviewerStr}' share the same vendor ('${vendor}').`,
|
|
106
379
|
};
|
|
107
380
|
}
|
|
108
381
|
}
|
|
109
|
-
return {
|
|
382
|
+
return { violated: false, severity: mode === "advisory" ? "warn" : "error" };
|
|
383
|
+
}
|
|
384
|
+
export function checkSelfApproval(authorStr, reviewerStr) {
|
|
385
|
+
const res = checkReviewGate(authorStr, reviewerStr, "intra-fleet");
|
|
386
|
+
return res.violated ? { isSelfApproval: true, message: res.message } : { isSelfApproval: false };
|
|
110
387
|
}
|
|
111
388
|
function normalizePath(value) {
|
|
112
389
|
return value.replace(/\\/g, "/").replace(/^\.\//, "").trim();
|
|
@@ -116,19 +393,89 @@ function toStringList(value) {
|
|
|
116
393
|
return [];
|
|
117
394
|
return value.filter((entry) => typeof entry === "string").map(normalizePath);
|
|
118
395
|
}
|
|
119
|
-
function
|
|
120
|
-
if (
|
|
396
|
+
function matchSegment(segment, pattern) {
|
|
397
|
+
if (pattern === "*" || pattern === "**")
|
|
398
|
+
return true;
|
|
399
|
+
if (!pattern.includes("*"))
|
|
400
|
+
return segment === pattern;
|
|
401
|
+
const parts = pattern.split("*");
|
|
402
|
+
const first = parts[0];
|
|
403
|
+
const last = parts[parts.length - 1];
|
|
404
|
+
if (!segment.startsWith(first))
|
|
405
|
+
return false;
|
|
406
|
+
if (last !== "" && !segment.endsWith(last))
|
|
121
407
|
return false;
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
408
|
+
let pos = first.length;
|
|
409
|
+
const limit = segment.length - last.length;
|
|
410
|
+
if (pos > limit)
|
|
411
|
+
return false;
|
|
412
|
+
for (let i = 1; i < parts.length - 1; i += 1) {
|
|
413
|
+
const part = parts[i];
|
|
414
|
+
if (part === "")
|
|
415
|
+
continue;
|
|
416
|
+
const idx = segment.indexOf(part, pos);
|
|
417
|
+
if (idx === -1 || idx + part.length > limit)
|
|
418
|
+
return false;
|
|
419
|
+
pos = idx + part.length;
|
|
130
420
|
}
|
|
131
|
-
return
|
|
421
|
+
return true;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Matches a normalized repository path against a contract rule (`dir/`, exact path,
|
|
425
|
+
* intra-segment `*` wildcards, or `**` directory-crossing segments) in deterministic
|
|
426
|
+
* linear time without `new RegExp`.
|
|
427
|
+
*/
|
|
428
|
+
export function matchesPath(file, rule) {
|
|
429
|
+
const normFile = normalizePath(file);
|
|
430
|
+
const normRule = normalizePath(rule);
|
|
431
|
+
if (normFile === "" || normRule === "")
|
|
432
|
+
return false;
|
|
433
|
+
if (normRule.endsWith("/") && !normRule.includes("*")) {
|
|
434
|
+
return normFile.startsWith(normRule);
|
|
435
|
+
}
|
|
436
|
+
if (!normRule.includes("*"))
|
|
437
|
+
return normFile === normRule;
|
|
438
|
+
const fileSegments = normFile.split("/");
|
|
439
|
+
let ruleSegments;
|
|
440
|
+
if (normRule.endsWith("/")) {
|
|
441
|
+
let dirPrefix = normRule;
|
|
442
|
+
while (dirPrefix.endsWith("/")) {
|
|
443
|
+
dirPrefix = dirPrefix.slice(0, -1);
|
|
444
|
+
}
|
|
445
|
+
if (dirPrefix === "")
|
|
446
|
+
return false;
|
|
447
|
+
ruleSegments = [...dirPrefix.split("/"), "*", "**"];
|
|
448
|
+
}
|
|
449
|
+
else {
|
|
450
|
+
ruleSegments = normRule.split("/");
|
|
451
|
+
}
|
|
452
|
+
let fi = 0;
|
|
453
|
+
let ri = 0;
|
|
454
|
+
let starRi = -1;
|
|
455
|
+
let matchFi = 0;
|
|
456
|
+
while (fi < fileSegments.length) {
|
|
457
|
+
if (ri < ruleSegments.length && ruleSegments[ri] === "**") {
|
|
458
|
+
starRi = ri;
|
|
459
|
+
matchFi = fi;
|
|
460
|
+
ri += 1;
|
|
461
|
+
}
|
|
462
|
+
else if (ri < ruleSegments.length && matchSegment(fileSegments[fi], ruleSegments[ri])) {
|
|
463
|
+
fi += 1;
|
|
464
|
+
ri += 1;
|
|
465
|
+
}
|
|
466
|
+
else if (starRi !== -1) {
|
|
467
|
+
matchFi += 1;
|
|
468
|
+
fi = matchFi;
|
|
469
|
+
ri = starRi + 1;
|
|
470
|
+
}
|
|
471
|
+
else {
|
|
472
|
+
return false;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
while (ri < ruleSegments.length && ruleSegments[ri] === "**") {
|
|
476
|
+
ri += 1;
|
|
477
|
+
}
|
|
478
|
+
return ri === ruleSegments.length;
|
|
132
479
|
}
|
|
133
480
|
function listCommitFiles(sha, targetDir) {
|
|
134
481
|
try {
|
|
@@ -173,8 +520,23 @@ function isEscalationAcknowledged(note, subject) {
|
|
|
173
520
|
return false;
|
|
174
521
|
}
|
|
175
522
|
}
|
|
523
|
+
/**
|
|
524
|
+
* A tier-1 issue declares its subtasks as orchestrator work, so a tier-1 author editing
|
|
525
|
+
* implementation files there is inside its scope and needs no escalation acknowledgement.
|
|
526
|
+
*/
|
|
527
|
+
function isTierOneIssue(note) {
|
|
528
|
+
if (note === null)
|
|
529
|
+
return false;
|
|
530
|
+
try {
|
|
531
|
+
const parsed = JSON.parse(note);
|
|
532
|
+
return parsed?.issue?.tier === "tier-1";
|
|
533
|
+
}
|
|
534
|
+
catch {
|
|
535
|
+
return false;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
176
538
|
function isImplementationFile(file) {
|
|
177
|
-
return !file
|
|
539
|
+
return !isGovernanceOrConfigSurface(file) && !file.startsWith(".lognexus/");
|
|
178
540
|
}
|
|
179
541
|
/**
|
|
180
542
|
* Framework bookkeeping (`state.json`, plan files) is rewritten by the CLI on the
|
|
@@ -184,7 +546,31 @@ function isImplementationFile(file) {
|
|
|
184
546
|
function isBookkeepingFile(file) {
|
|
185
547
|
return file.startsWith(".lognexus/") || file.startsWith("docs/contexto/");
|
|
186
548
|
}
|
|
187
|
-
|
|
549
|
+
const GATE_STRICTNESS = {
|
|
550
|
+
off: 0,
|
|
551
|
+
advisory: 1,
|
|
552
|
+
"intra-fleet": 2,
|
|
553
|
+
"cross-vendor": 3,
|
|
554
|
+
};
|
|
555
|
+
function readGitFileAtRef(ref, filePath, targetDir) {
|
|
556
|
+
try {
|
|
557
|
+
const safeRef = validateGitReference(ref);
|
|
558
|
+
return execFileSync("git", ["show", `${safeRef}:${filePath}`], {
|
|
559
|
+
cwd: targetDir,
|
|
560
|
+
encoding: "utf8",
|
|
561
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
562
|
+
shell: false,
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
catch {
|
|
566
|
+
return null;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
function parseEffectiveGate(content) {
|
|
570
|
+
const { configuredReviewGate } = parseRoutingConfigContent(content);
|
|
571
|
+
return configuredReviewGate === "auto" ? "intra-fleet" : configuredReviewGate;
|
|
572
|
+
}
|
|
573
|
+
function auditCommit(item, targetDir, gateMode) {
|
|
188
574
|
const violations = [];
|
|
189
575
|
const base = { commitSha: item.sha, shortSha: item.shortSha };
|
|
190
576
|
if (item.author === null) {
|
|
@@ -195,16 +581,51 @@ function auditCommit(item, targetDir) {
|
|
|
195
581
|
severity: "error",
|
|
196
582
|
});
|
|
197
583
|
}
|
|
198
|
-
const
|
|
199
|
-
|
|
584
|
+
const hasInvalidAuthor = isInvalidPlaceholderIdentity(item.author);
|
|
585
|
+
const hasInvalidReviewer = isInvalidPlaceholderIdentity(item.reviewer);
|
|
586
|
+
if (hasInvalidAuthor) {
|
|
200
587
|
violations.push({
|
|
201
588
|
...base,
|
|
202
|
-
rule: "
|
|
203
|
-
message:
|
|
204
|
-
`Self-approval detected: author '${item.author}' and reviewer '${item.reviewer}' share the same identity.`,
|
|
589
|
+
rule: "invalid-identity",
|
|
590
|
+
message: `Invalid placeholder Authored-by identity '${item.author}'. Specify the exact runtime model identity (e.g. 'google/gemini-3.8-flash-high (antigravity)').`,
|
|
205
591
|
severity: "error",
|
|
206
592
|
});
|
|
207
593
|
}
|
|
594
|
+
if (hasInvalidReviewer) {
|
|
595
|
+
violations.push({
|
|
596
|
+
...base,
|
|
597
|
+
rule: "invalid-identity",
|
|
598
|
+
message: `Invalid placeholder Reviewed-by identity '${item.reviewer}'. Specify the exact runtime model identity (e.g. 'claude/opus-4.6 (claude-code)').`,
|
|
599
|
+
severity: "error",
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
if (!hasInvalidAuthor && !hasInvalidReviewer) {
|
|
603
|
+
const gateCheck = checkReviewGate(item.author, item.reviewer, gateMode);
|
|
604
|
+
if (gateCheck.violated) {
|
|
605
|
+
violations.push({
|
|
606
|
+
...base,
|
|
607
|
+
rule: "review-gate-separation",
|
|
608
|
+
message: gateCheck.message ??
|
|
609
|
+
`Self-approval detected: author '${item.author}' and reviewer '${item.reviewer}' share the same identity.`,
|
|
610
|
+
severity: gateCheck.severity,
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
const changedFiles = listCommitFiles(item.sha, targetDir);
|
|
615
|
+
if (changedFiles.includes(".lognexus/routing.md")) {
|
|
616
|
+
const commitRouting = readGitFileAtRef(item.sha, ".lognexus/routing.md", targetDir);
|
|
617
|
+
if (commitRouting !== null) {
|
|
618
|
+
const commitGate = parseEffectiveGate(commitRouting);
|
|
619
|
+
if (GATE_STRICTNESS[commitGate] < GATE_STRICTNESS[gateMode]) {
|
|
620
|
+
violations.push({
|
|
621
|
+
...base,
|
|
622
|
+
rule: "review-gate-separation",
|
|
623
|
+
message: `Commit modifies .lognexus/routing.md and weakens review_gate from '${gateMode}' to '${commitGate}'; base branch gate '${gateMode}' remains enforced.`,
|
|
624
|
+
severity: "warn",
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
}
|
|
208
629
|
const note = getNote(item.sha, { cwd: targetDir });
|
|
209
630
|
if (note === null) {
|
|
210
631
|
violations.push({
|
|
@@ -234,7 +655,6 @@ function auditCommit(item, targetDir) {
|
|
|
234
655
|
if (contract !== null) {
|
|
235
656
|
const allowedFiles = toStringList(contract.allowedFiles);
|
|
236
657
|
const forbiddenFiles = toStringList(contract.forbiddenFiles);
|
|
237
|
-
const changedFiles = listCommitFiles(item.sha, targetDir);
|
|
238
658
|
const forbidden = changedFiles.filter((file) => forbiddenFiles.some((rule) => matchesPath(file, rule)));
|
|
239
659
|
if (forbidden.length > 0) {
|
|
240
660
|
violations.push({
|
|
@@ -256,6 +676,7 @@ function auditCommit(item, targetDir) {
|
|
|
256
676
|
}
|
|
257
677
|
}
|
|
258
678
|
if (inferTierFromAuthor(item.author) === "tier-1" &&
|
|
679
|
+
!isTierOneIssue(note) &&
|
|
259
680
|
!isEscalationAcknowledged(note, item.subject)) {
|
|
260
681
|
const implementationFiles = changedFiles.filter(isImplementationFile);
|
|
261
682
|
if (implementationFiles.length > 0) {
|
|
@@ -270,10 +691,15 @@ function auditCommit(item, targetDir) {
|
|
|
270
691
|
}
|
|
271
692
|
return violations;
|
|
272
693
|
}
|
|
273
|
-
export function auditBranch(baseBranch = "main", targetDir = process.cwd()) {
|
|
694
|
+
export function auditBranch(baseBranch = "main", targetDir = process.cwd(), options) {
|
|
274
695
|
const safeBase = rejectNotesReference(baseBranch, "audit base branch");
|
|
696
|
+
const baseRoutingRaw = readGitFileAtRef(safeBase, ".lognexus/routing.md", targetDir);
|
|
697
|
+
const gateMode = options?.reviewGateMode ??
|
|
698
|
+
(baseRoutingRaw !== null
|
|
699
|
+
? parseEffectiveGate(baseRoutingRaw)
|
|
700
|
+
: resolveRoutingProfile(targetDir).effectiveReviewGate);
|
|
275
701
|
const timeline = getJourneyTimeline(safeBase, targetDir);
|
|
276
|
-
const violations = timeline.items.flatMap((item) => auditCommit(item, targetDir));
|
|
702
|
+
const violations = timeline.items.flatMap((item) => auditCommit(item, targetDir, gateMode));
|
|
277
703
|
const normalizedCurrent = timeline.branch.replace(/^refs\/heads\//, "");
|
|
278
704
|
const normalizedBase = safeBase.replace(/^refs\/heads\//, "").replace(/^origin\//, "");
|
|
279
705
|
if (normalizedCurrent === normalizedBase && timeline.commitCount === 0) {
|