@indigoai-us/hq-cli 5.147.0 → 5.148.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/CHANGELOG.md +5 -0
- package/dist/commands/mcp-registration.d.ts +29 -16
- package/dist/commands/mcp-registration.js +254 -17
- package/dist/sentry.js +15 -7
- package/dist/utils/sentry-fingerprint.d.ts +11 -0
- package/dist/utils/sentry-fingerprint.js +56 -11
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,10 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [5.148.0] — 2026-09-23
|
|
6
|
+
|
|
5
7
|
## [5.147.0] — 2026-09-23
|
|
6
8
|
|
|
7
9
|
### Fixed
|
|
8
10
|
|
|
11
|
+
- Reinstalling an MCP server now updates its definition when the existing
|
|
12
|
+
Claude or Codex entry belongs to the same HQ pack. Unmarked and other-pack
|
|
13
|
+
entries still refuse replacement.
|
|
9
14
|
- `hq mesh context prd-sync` now moves the Board. Its task_status events carry the session's company and project, and take sequence numbers from the session's shared counter (the same file the hooks use), so the server no longer rejects them as duplicates. Rejections print their codes.
|
|
10
15
|
- The mesh daemon no longer treats a missing company slug, a membership timeout, or a lookup error as proof that the device owner is not a member. A device-default session that was cleared to `needs_company` is checked once against the configured default company and, when that membership is active, the company is put back and held events flush. The same cleared session is not counted as a new denial on every later flush.
|
|
11
16
|
- `hq mesh project ensure` no longer fails when the server refuses to close the extra genesis thread; it leaves that thread open and prints one line. Registration and the calling session's binding complete.
|
|
@@ -74,6 +74,15 @@ export declare class ConfigParseError extends McpRegistrationError {
|
|
|
74
74
|
export declare class ConfigPermissionError extends McpRegistrationError {
|
|
75
75
|
readonly code: "ConfigPermissionError";
|
|
76
76
|
}
|
|
77
|
+
export type CodexMcpCollisionOwner = 'hq' | 'foreign' | 'unknown';
|
|
78
|
+
export type CodexMcpCollisionField = 'command' | 'args' | 'env' | 'url' | 'other';
|
|
79
|
+
/** Safe, value-free context for a Codex name collision reported to Sentry. */
|
|
80
|
+
export interface CodexMcpCollisionDiagnostics {
|
|
81
|
+
client: 'codex';
|
|
82
|
+
serverName: string;
|
|
83
|
+
existingEntryOwner: CodexMcpCollisionOwner;
|
|
84
|
+
diffFields: CodexMcpCollisionField[];
|
|
85
|
+
}
|
|
77
86
|
/**
|
|
78
87
|
* A server name is already present in the target config with a DIFFERENT
|
|
79
88
|
* definition than the one being merged (def-equal = idempotent no-op;
|
|
@@ -82,6 +91,8 @@ export declare class ConfigPermissionError extends McpRegistrationError {
|
|
|
82
91
|
*/
|
|
83
92
|
export declare class McpNameCollisionError extends McpRegistrationError {
|
|
84
93
|
readonly code: "McpNameCollisionError";
|
|
94
|
+
readonly codexDiagnostics?: CodexMcpCollisionDiagnostics;
|
|
95
|
+
constructor(message: string, codexDiagnostics?: CodexMcpCollisionDiagnostics);
|
|
85
96
|
}
|
|
86
97
|
/**
|
|
87
98
|
* The Codex runtime is absent (`~/.codex` missing). This is a FIRST-CLASS SKIP,
|
|
@@ -494,7 +505,8 @@ export declare function serverDefsEqual(a: unknown, b: unknown): boolean;
|
|
|
494
505
|
* it — but byte-equality of the rest means {@link writeConfigAtomic} writes
|
|
495
506
|
* nothing unless the stamp itself is the only delta, which we treat as a no-op
|
|
496
507
|
* by returning the original doc.
|
|
497
|
-
* - name PRESENT, def-DIFFERS ->
|
|
508
|
+
* - name PRESENT, def-DIFFERS, same non-empty `_hqPack` -> replace the entry.
|
|
509
|
+
* - name PRESENT, def-DIFFERS, unmarked or different owner -> collision ABORT.
|
|
498
510
|
*
|
|
499
511
|
* Never touches any OTHER server entry or any other top-level key.
|
|
500
512
|
*/
|
|
@@ -646,8 +658,8 @@ type TomlTable = Record<string, unknown>;
|
|
|
646
658
|
* The Codex doc threaded through the safe-write core. We carry BOTH the parsed
|
|
647
659
|
* value (`value`, for the merge fn + verify) AND the ORIGINAL file text
|
|
648
660
|
* (`originalText`, `null` for a fresh/empty file). {@link codexConfigFormat.serialize}
|
|
649
|
-
* uses `originalText` to APPEND
|
|
650
|
-
*
|
|
661
|
+
* uses `originalText` to APPEND a new table or replace sections of a same-pack
|
|
662
|
+
* owned table without re-serializing unrelated content. This is the seam that
|
|
651
663
|
* makes "preserves comments" honest within a value-only TOML library.
|
|
652
664
|
*/
|
|
653
665
|
export interface CodexTomlDoc {
|
|
@@ -661,7 +673,7 @@ export declare const CODEX_MCP_SERVERS_KEY = "mcp_servers";
|
|
|
661
673
|
/**
|
|
662
674
|
* Serialize EXACTLY ONE server table (`[mcp_servers.<name>]` + its sub-tables)
|
|
663
675
|
* by wrapping the def under `mcp_servers.<name>` and round-tripping it through
|
|
664
|
-
* smol-toml. Used
|
|
676
|
+
* smol-toml. Used for appending new servers, replacing an owned table, and the
|
|
665
677
|
* collision/equality comparison. The output is deterministic for a given def so a
|
|
666
678
|
* re-install produces byte-identical text (idempotency depends on it).
|
|
667
679
|
*/
|
|
@@ -670,15 +682,15 @@ export declare function serializeOneCodexServer(name: string, def: TomlTable): s
|
|
|
670
682
|
* The Codex `ConfigFormat`. `parse` round-trips the file through smol-toml
|
|
671
683
|
* (throwing `TomlError` on malformed NON-empty input → the substrate maps it to
|
|
672
684
|
* {@link ConfigParseError}, FAIL-CLOSED). `serialize` is comment-preserving: when
|
|
673
|
-
* the doc carries `originalText` (the file pre-existed) it APPENDS
|
|
674
|
-
*
|
|
675
|
-
* whole value
|
|
676
|
-
*
|
|
677
|
-
*
|
|
678
|
-
* Because `serialize` needs
|
|
679
|
-
*
|
|
680
|
-
*
|
|
681
|
-
*
|
|
685
|
+
* the doc carries `originalText` (the file pre-existed) it APPENDS a new server
|
|
686
|
+
* table or replaces only a same-pack owned table, rather than re-serializing the
|
|
687
|
+
* whole value. Only a fresh file (`null`) is serialized from scratch.
|
|
688
|
+
* `assertEntry` checks `mcp_servers.<name>` is present.
|
|
689
|
+
*
|
|
690
|
+
* Because `serialize` needs to know WHICH server to append or replace, the merge
|
|
691
|
+
* fn ({@link mergeCodexServer}) records the operation on the doc. For an
|
|
692
|
+
* idempotent no-op (server already present, def-equal) the merge returns the doc
|
|
693
|
+
* UNCHANGED, so
|
|
682
694
|
* `serialize` reproduces the original text exactly (no write happens).
|
|
683
695
|
*/
|
|
684
696
|
export declare const codexConfigFormat: ConfigFormat<CodexTomlDoc>;
|
|
@@ -716,9 +728,10 @@ export declare function buildCodexToolsTable(tools: McpManifest['tools']): TomlT
|
|
|
716
728
|
* - name PRESENT, def-equal (provenance-ignored) → NO-OP (idempotent re-install /
|
|
717
729
|
* PARTIAL self-heal): return the doc UNCHANGED with no pending append, so the
|
|
718
730
|
* original text round-trips byte-for-byte.
|
|
719
|
-
* - name PRESENT, def-DIFFERS →
|
|
720
|
-
*
|
|
721
|
-
*
|
|
731
|
+
* - name PRESENT, def-DIFFERS, same `_hqPack` owner → update that owned table
|
|
732
|
+
* while preserving unrelated TOML bytes and comments.
|
|
733
|
+
* - name PRESENT, def-DIFFERS, any other owner → {@link McpNameCollisionError}
|
|
734
|
+
* ABORT with value-free diagnostics.
|
|
722
735
|
*
|
|
723
736
|
* Never touches any OTHER server table or any other top-level table.
|
|
724
737
|
*/
|
|
@@ -99,6 +99,11 @@ export class ConfigPermissionError extends McpRegistrationError {
|
|
|
99
99
|
*/
|
|
100
100
|
export class McpNameCollisionError extends McpRegistrationError {
|
|
101
101
|
code = 'McpNameCollisionError';
|
|
102
|
+
codexDiagnostics;
|
|
103
|
+
constructor(message, codexDiagnostics) {
|
|
104
|
+
super(message);
|
|
105
|
+
this.codexDiagnostics = codexDiagnostics;
|
|
106
|
+
}
|
|
102
107
|
}
|
|
103
108
|
/**
|
|
104
109
|
* The Codex runtime is absent (`~/.codex` missing). This is a FIRST-CLASS SKIP,
|
|
@@ -1009,7 +1014,8 @@ function canonicalJson(v) {
|
|
|
1009
1014
|
* it — but byte-equality of the rest means {@link writeConfigAtomic} writes
|
|
1010
1015
|
* nothing unless the stamp itself is the only delta, which we treat as a no-op
|
|
1011
1016
|
* by returning the original doc.
|
|
1012
|
-
* - name PRESENT, def-DIFFERS ->
|
|
1017
|
+
* - name PRESENT, def-DIFFERS, same non-empty `_hqPack` -> replace the entry.
|
|
1018
|
+
* - name PRESENT, def-DIFFERS, unmarked or different owner -> collision ABORT.
|
|
1013
1019
|
*
|
|
1014
1020
|
* Never touches any OTHER server entry or any other top-level key.
|
|
1015
1021
|
*/
|
|
@@ -1023,6 +1029,12 @@ export function mergeClaudeServer(name, def) {
|
|
|
1023
1029
|
// (do not re-stamp) so a re-install is a true byte-for-byte no-op.
|
|
1024
1030
|
return doc;
|
|
1025
1031
|
}
|
|
1032
|
+
const existingPack = provenanceOf(existing);
|
|
1033
|
+
const incomingPack = provenanceOf(def);
|
|
1034
|
+
if (existingPack && existingPack === incomingPack) {
|
|
1035
|
+
servers[name] = def;
|
|
1036
|
+
return { ...doc, mcpServers: servers };
|
|
1037
|
+
}
|
|
1026
1038
|
throw new McpNameCollisionError(`MCP server "${name}" is already defined in ~/.claude.json with a different ` +
|
|
1027
1039
|
'definition — refusing to overwrite. Remove or rename the existing server, ' +
|
|
1028
1040
|
'or uninstall the conflicting pack, then re-install.');
|
|
@@ -1302,7 +1314,7 @@ export const CODEX_MCP_SERVERS_KEY = 'mcp_servers';
|
|
|
1302
1314
|
/**
|
|
1303
1315
|
* Serialize EXACTLY ONE server table (`[mcp_servers.<name>]` + its sub-tables)
|
|
1304
1316
|
* by wrapping the def under `mcp_servers.<name>` and round-tripping it through
|
|
1305
|
-
* smol-toml. Used
|
|
1317
|
+
* smol-toml. Used for appending new servers, replacing an owned table, and the
|
|
1306
1318
|
* collision/equality comparison. The output is deterministic for a given def so a
|
|
1307
1319
|
* re-install produces byte-identical text (idempotency depends on it).
|
|
1308
1320
|
*/
|
|
@@ -1313,15 +1325,15 @@ export function serializeOneCodexServer(name, def) {
|
|
|
1313
1325
|
* The Codex `ConfigFormat`. `parse` round-trips the file through smol-toml
|
|
1314
1326
|
* (throwing `TomlError` on malformed NON-empty input → the substrate maps it to
|
|
1315
1327
|
* {@link ConfigParseError}, FAIL-CLOSED). `serialize` is comment-preserving: when
|
|
1316
|
-
* the doc carries `originalText` (the file pre-existed) it APPENDS
|
|
1317
|
-
*
|
|
1318
|
-
* whole value
|
|
1319
|
-
*
|
|
1328
|
+
* the doc carries `originalText` (the file pre-existed) it APPENDS a new server
|
|
1329
|
+
* table or replaces only a same-pack owned table, rather than re-serializing the
|
|
1330
|
+
* whole value. Only a fresh file (`null`) is serialized from scratch.
|
|
1331
|
+
* `assertEntry` checks `mcp_servers.<name>` is present.
|
|
1320
1332
|
*
|
|
1321
|
-
* Because `serialize` needs
|
|
1322
|
-
*
|
|
1323
|
-
*
|
|
1324
|
-
*
|
|
1333
|
+
* Because `serialize` needs to know WHICH server to append or replace, the merge
|
|
1334
|
+
* fn ({@link mergeCodexServer}) records the operation on the doc. For an
|
|
1335
|
+
* idempotent no-op (server already present, def-equal) the merge returns the doc
|
|
1336
|
+
* UNCHANGED, so
|
|
1325
1337
|
* `serialize` reproduces the original text exactly (no write happens).
|
|
1326
1338
|
*/
|
|
1327
1339
|
export const codexConfigFormat = {
|
|
@@ -1332,7 +1344,16 @@ export const codexConfigFormat = {
|
|
|
1332
1344
|
return { value, originalText: text };
|
|
1333
1345
|
},
|
|
1334
1346
|
serialize(doc) {
|
|
1335
|
-
const
|
|
1347
|
+
const pendingDoc = doc;
|
|
1348
|
+
const pendingUpdate = pendingDoc[PENDING_UPDATE];
|
|
1349
|
+
if (doc.originalText !== null && pendingUpdate) {
|
|
1350
|
+
const updated = replaceCodexTable(doc.originalText, pendingUpdate.name, pendingUpdate.def);
|
|
1351
|
+
if (updated === null) {
|
|
1352
|
+
throw new McpNameCollisionError(codexCollisionMessage(pendingUpdate.name), pendingUpdate.diagnostics);
|
|
1353
|
+
}
|
|
1354
|
+
return updated;
|
|
1355
|
+
}
|
|
1356
|
+
const pending = pendingDoc[PENDING_APPEND];
|
|
1336
1357
|
if (doc.originalText !== null && pending) {
|
|
1337
1358
|
// APPEND path: keep the original bytes verbatim (comments + every existing
|
|
1338
1359
|
// table/sub-table preserved), then append the one new server table.
|
|
@@ -1362,6 +1383,7 @@ export const codexConfigFormat = {
|
|
|
1362
1383
|
};
|
|
1363
1384
|
/** Symbol carrying the pending append on a {@link CodexTomlDoc} (merge → serialize). */
|
|
1364
1385
|
const PENDING_APPEND = Symbol('hqPendingCodexAppend');
|
|
1386
|
+
const PENDING_UPDATE = Symbol('hqPendingCodexUpdate');
|
|
1365
1387
|
/** Return a copy of `value` with `mcp_servers.<name> = def` set (used for fresh-file serialize). */
|
|
1366
1388
|
function withServer(value, name, def) {
|
|
1367
1389
|
const servers = { ...(value[CODEX_MCP_SERVERS_KEY] ?? {}) };
|
|
@@ -1384,6 +1406,171 @@ export function appendCodexTable(originalText, name, def) {
|
|
|
1384
1406
|
const body = block.endsWith('\n') ? block : `${block}\n`;
|
|
1385
1407
|
return `${trimmed}\n\n${body}`;
|
|
1386
1408
|
}
|
|
1409
|
+
/** Return the decoded table path for a valid TOML table header, or null. */
|
|
1410
|
+
function codexTablePath(headerLine) {
|
|
1411
|
+
try {
|
|
1412
|
+
const value = parseToml(headerLine);
|
|
1413
|
+
const matches = [];
|
|
1414
|
+
const visit = (current, pathParts) => {
|
|
1415
|
+
if (current === null || typeof current !== 'object')
|
|
1416
|
+
return;
|
|
1417
|
+
if (Array.isArray(current)) {
|
|
1418
|
+
current.forEach((item, index) => visit(item, [...pathParts, String(index)]));
|
|
1419
|
+
return;
|
|
1420
|
+
}
|
|
1421
|
+
const table = current;
|
|
1422
|
+
const entries = Object.entries(table);
|
|
1423
|
+
if (entries.length === 0) {
|
|
1424
|
+
matches.push(pathParts);
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
1427
|
+
for (const [key, child] of entries) {
|
|
1428
|
+
visit(child, [...pathParts, key]);
|
|
1429
|
+
}
|
|
1430
|
+
};
|
|
1431
|
+
visit(value, []);
|
|
1432
|
+
return matches.length === 1 ? matches[0] : null;
|
|
1433
|
+
}
|
|
1434
|
+
catch {
|
|
1435
|
+
// The caller has already parsed the whole document. Ordinary values are
|
|
1436
|
+
// not table headers.
|
|
1437
|
+
return null;
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
/**
|
|
1441
|
+
* Locate real table headers without mistaking bracket-like text in TOML values
|
|
1442
|
+
* for a header. Parsing the preceding prefix ensures a candidate is not inside
|
|
1443
|
+
* an unfinished multiline string or array; smol-toml decodes quoted key paths.
|
|
1444
|
+
*/
|
|
1445
|
+
function codexTomlSections(text) {
|
|
1446
|
+
const headers = [];
|
|
1447
|
+
let offset = 0;
|
|
1448
|
+
for (const line of text.match(/[^\n]*(?:\n|$)/g) ?? []) {
|
|
1449
|
+
if (line.length === 0)
|
|
1450
|
+
continue;
|
|
1451
|
+
const content = line.replace(/\r?\n$/, '');
|
|
1452
|
+
if (content.trimStart().startsWith('[')) {
|
|
1453
|
+
try {
|
|
1454
|
+
parseToml(text.slice(0, offset));
|
|
1455
|
+
const path = codexTablePath(content);
|
|
1456
|
+
if (path)
|
|
1457
|
+
headers.push({ start: offset, path });
|
|
1458
|
+
}
|
|
1459
|
+
catch {
|
|
1460
|
+
// The prefix is incomplete TOML, so this bracket is part of a value.
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
offset += line.length;
|
|
1464
|
+
}
|
|
1465
|
+
return headers.map((header, index) => {
|
|
1466
|
+
const nextStart = headers[index + 1]?.start ?? text.length;
|
|
1467
|
+
let end = nextStart;
|
|
1468
|
+
const trailingLines = text.slice(header.start, nextStart).match(/[^\n]*(?:\n|$)/g) ?? [];
|
|
1469
|
+
for (let lineIndex = trailingLines.length - 1; lineIndex >= 0; lineIndex -= 1) {
|
|
1470
|
+
const content = trailingLines[lineIndex].replace(/\r?\n$/, '');
|
|
1471
|
+
if (content.trim() === '' || content.trimStart().startsWith('#')) {
|
|
1472
|
+
end -= trailingLines[lineIndex].length;
|
|
1473
|
+
}
|
|
1474
|
+
else {
|
|
1475
|
+
break;
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
return { ...header, end };
|
|
1479
|
+
});
|
|
1480
|
+
}
|
|
1481
|
+
/** Extract comment text outside TOML strings so updating an owned table drops no user notes. */
|
|
1482
|
+
function codexTomlComments(text) {
|
|
1483
|
+
const comments = [];
|
|
1484
|
+
let multiline = null;
|
|
1485
|
+
let lineOffset = 0;
|
|
1486
|
+
for (const lineWithEnding of text.match(/[^\n]*(?:\n|$)/g) ?? []) {
|
|
1487
|
+
if (lineWithEnding.length === 0)
|
|
1488
|
+
continue;
|
|
1489
|
+
const line = lineWithEnding.replace(/\r?\n$/, '');
|
|
1490
|
+
let quote = null;
|
|
1491
|
+
let index = 0;
|
|
1492
|
+
while (index < line.length) {
|
|
1493
|
+
if (multiline) {
|
|
1494
|
+
const delimiter = multiline === 'basic' ? '"""' : "'''";
|
|
1495
|
+
if (multiline === 'basic' && line[index] === '\\') {
|
|
1496
|
+
index += 2;
|
|
1497
|
+
}
|
|
1498
|
+
else if (line.startsWith(delimiter, index)) {
|
|
1499
|
+
multiline = null;
|
|
1500
|
+
index += 3;
|
|
1501
|
+
}
|
|
1502
|
+
else {
|
|
1503
|
+
index += 1;
|
|
1504
|
+
}
|
|
1505
|
+
continue;
|
|
1506
|
+
}
|
|
1507
|
+
if (quote) {
|
|
1508
|
+
const closing = quote === 'basic' ? '"' : "'";
|
|
1509
|
+
if (quote === 'basic' && line[index] === '\\') {
|
|
1510
|
+
index += 2;
|
|
1511
|
+
}
|
|
1512
|
+
else if (line[index] === closing) {
|
|
1513
|
+
quote = null;
|
|
1514
|
+
index += 1;
|
|
1515
|
+
}
|
|
1516
|
+
else {
|
|
1517
|
+
index += 1;
|
|
1518
|
+
}
|
|
1519
|
+
continue;
|
|
1520
|
+
}
|
|
1521
|
+
if (line[index] === '#') {
|
|
1522
|
+
comments.push({ offset: lineOffset + index, text: line.slice(index) });
|
|
1523
|
+
break;
|
|
1524
|
+
}
|
|
1525
|
+
if (line.startsWith('"""', index)) {
|
|
1526
|
+
multiline = 'basic';
|
|
1527
|
+
index += 3;
|
|
1528
|
+
}
|
|
1529
|
+
else if (line.startsWith("'''", index)) {
|
|
1530
|
+
multiline = 'literal';
|
|
1531
|
+
index += 3;
|
|
1532
|
+
}
|
|
1533
|
+
else if (line[index] === '"') {
|
|
1534
|
+
quote = 'basic';
|
|
1535
|
+
index += 1;
|
|
1536
|
+
}
|
|
1537
|
+
else if (line[index] === "'") {
|
|
1538
|
+
quote = 'literal';
|
|
1539
|
+
index += 1;
|
|
1540
|
+
}
|
|
1541
|
+
else {
|
|
1542
|
+
index += 1;
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
lineOffset += lineWithEnding.length;
|
|
1546
|
+
}
|
|
1547
|
+
return comments;
|
|
1548
|
+
}
|
|
1549
|
+
/** Replace all sections for one same-pack server while retaining unrelated bytes and comments. */
|
|
1550
|
+
function replaceCodexTable(originalText, name, def) {
|
|
1551
|
+
const sections = codexTomlSections(originalText);
|
|
1552
|
+
const target = sections.filter((section) => section.path[0] === CODEX_MCP_SERVERS_KEY && section.path[1] === name);
|
|
1553
|
+
if (!target.some((section) => section.path.length === 2))
|
|
1554
|
+
return null;
|
|
1555
|
+
const newline = originalText.includes('\r\n') ? '\r\n' : '\n';
|
|
1556
|
+
const comments = codexTomlComments(originalText)
|
|
1557
|
+
.filter((comment) => target.some((section) => comment.offset >= section.start && comment.offset < section.end))
|
|
1558
|
+
.map((comment) => comment.text);
|
|
1559
|
+
let output = '';
|
|
1560
|
+
let cursor = 0;
|
|
1561
|
+
let inserted = false;
|
|
1562
|
+
for (const section of target) {
|
|
1563
|
+
output += originalText.slice(cursor, section.start);
|
|
1564
|
+
if (!inserted) {
|
|
1565
|
+
output += serializeOneCodexServer(name, def).replace(/\n/g, newline);
|
|
1566
|
+
if (comments.length > 0)
|
|
1567
|
+
output += comments.join(newline) + newline;
|
|
1568
|
+
inserted = true;
|
|
1569
|
+
}
|
|
1570
|
+
cursor = section.end;
|
|
1571
|
+
}
|
|
1572
|
+
return inserted ? output + originalText.slice(cursor) : null;
|
|
1573
|
+
}
|
|
1387
1574
|
/**
|
|
1388
1575
|
* Build the Codex server table emitted as `[mcp_servers.<name>]`: pass the
|
|
1389
1576
|
* transport fields through, resolve `${secret:}` in every argument/header/env value
|
|
@@ -1447,9 +1634,10 @@ export function buildCodexToolsTable(tools) {
|
|
|
1447
1634
|
* - name PRESENT, def-equal (provenance-ignored) → NO-OP (idempotent re-install /
|
|
1448
1635
|
* PARTIAL self-heal): return the doc UNCHANGED with no pending append, so the
|
|
1449
1636
|
* original text round-trips byte-for-byte.
|
|
1450
|
-
* - name PRESENT, def-DIFFERS →
|
|
1451
|
-
*
|
|
1452
|
-
*
|
|
1637
|
+
* - name PRESENT, def-DIFFERS, same `_hqPack` owner → update that owned table
|
|
1638
|
+
* while preserving unrelated TOML bytes and comments.
|
|
1639
|
+
* - name PRESENT, def-DIFFERS, any other owner → {@link McpNameCollisionError}
|
|
1640
|
+
* ABORT with value-free diagnostics.
|
|
1453
1641
|
*
|
|
1454
1642
|
* Never touches any OTHER server table or any other top-level table.
|
|
1455
1643
|
*/
|
|
@@ -1463,9 +1651,23 @@ export function mergeCodexServer(name, def) {
|
|
|
1463
1651
|
// so serialize reproduces the original text exactly.
|
|
1464
1652
|
return doc;
|
|
1465
1653
|
}
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1654
|
+
const diagnostics = codexCollisionDiagnostics(name, existing, def);
|
|
1655
|
+
const existingPack = isTomlTable(existing)
|
|
1656
|
+
? existing[HQ_PACK_PROVENANCE_KEY]
|
|
1657
|
+
: undefined;
|
|
1658
|
+
if (doc.originalText !== null &&
|
|
1659
|
+
isTomlTable(existing) &&
|
|
1660
|
+
typeof existingPack === 'string' &&
|
|
1661
|
+
existingPack.length > 0 &&
|
|
1662
|
+
existingPack === def[HQ_PACK_PROVENANCE_KEY]) {
|
|
1663
|
+
const next = {
|
|
1664
|
+
value: withServer(doc.value, name, def),
|
|
1665
|
+
originalText: doc.originalText,
|
|
1666
|
+
[PENDING_UPDATE]: { name, def, diagnostics },
|
|
1667
|
+
};
|
|
1668
|
+
return next;
|
|
1669
|
+
}
|
|
1670
|
+
throw new McpNameCollisionError(codexCollisionMessage(name), diagnostics);
|
|
1469
1671
|
}
|
|
1470
1672
|
// Insert into the value (for verify-after-write) AND record the pending append
|
|
1471
1673
|
// (for comment-preserving serialize).
|
|
@@ -1478,6 +1680,41 @@ export function mergeCodexServer(name, def) {
|
|
|
1478
1680
|
return next;
|
|
1479
1681
|
};
|
|
1480
1682
|
}
|
|
1683
|
+
function isTomlTable(value) {
|
|
1684
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
1685
|
+
}
|
|
1686
|
+
function codexCollisionMessage(name) {
|
|
1687
|
+
return `MCP server "${name}" is already defined in ~/.codex/config.toml with a different ` +
|
|
1688
|
+
'definition — refusing to overwrite. Remove or rename the existing server, ' +
|
|
1689
|
+
'or uninstall the conflicting pack, then re-install.';
|
|
1690
|
+
}
|
|
1691
|
+
function codexCollisionDiagnostics(name, existing, incoming) {
|
|
1692
|
+
const existingTable = isTomlTable(existing) ? existing : {};
|
|
1693
|
+
const owner = typeof existingTable[HQ_PACK_PROVENANCE_KEY] === 'string' &&
|
|
1694
|
+
existingTable[HQ_PACK_PROVENANCE_KEY].length > 0
|
|
1695
|
+
? 'hq'
|
|
1696
|
+
: 'unknown';
|
|
1697
|
+
const keys = new Set([...Object.keys(existingTable), ...Object.keys(incoming)]);
|
|
1698
|
+
keys.delete(HQ_PACK_PROVENANCE_KEY);
|
|
1699
|
+
const fields = new Set();
|
|
1700
|
+
for (const key of keys) {
|
|
1701
|
+
const existingHasKey = Object.prototype.hasOwnProperty.call(existingTable, key);
|
|
1702
|
+
const incomingHasKey = Object.prototype.hasOwnProperty.call(incoming, key);
|
|
1703
|
+
if (existingHasKey === incomingHasKey &&
|
|
1704
|
+
canonicalJson(existingTable[key]) === canonicalJson(incoming[key])) {
|
|
1705
|
+
continue;
|
|
1706
|
+
}
|
|
1707
|
+
fields.add(key === 'command' || key === 'args' || key === 'env' || key === 'url'
|
|
1708
|
+
? key
|
|
1709
|
+
: 'other');
|
|
1710
|
+
}
|
|
1711
|
+
return {
|
|
1712
|
+
client: 'codex',
|
|
1713
|
+
serverName: name,
|
|
1714
|
+
existingEntryOwner: owner,
|
|
1715
|
+
diffFields: [...fields].sort(),
|
|
1716
|
+
};
|
|
1717
|
+
}
|
|
1481
1718
|
/**
|
|
1482
1719
|
* Emit ONE server into the GLOBAL Codex surface (`~/.codex/config.toml`
|
|
1483
1720
|
* `[mcp_servers.<name>]`) via {@link writeConfigAtomic}. A FIRST-CLASS SKIP when the
|
package/dist/sentry.js
CHANGED
|
@@ -7,7 +7,7 @@ import { getCachedSentryUser } from "./utils/sentry-identity.js";
|
|
|
7
7
|
import { isEpipe } from "./utils/epipe.js";
|
|
8
8
|
import { environmentalFsErrorMessage } from "./utils/environmental-error.js";
|
|
9
9
|
import { incompleteInstallCaptureContext, incompleteInstallMessage, } from "./utils/incomplete-install-error.js";
|
|
10
|
-
import { sentryFingerprintFor } from "./utils/sentry-fingerprint.js";
|
|
10
|
+
import { sentryFingerprintFor, sentryMcpCollisionContextFor, } from "./utils/sentry-fingerprint.js";
|
|
11
11
|
/**
|
|
12
12
|
* Drop broken-pipe (EPIPE) crashes before scrubbing/send. A closed downstream
|
|
13
13
|
* reader (`hq … | head`, `source <(hq …)`, a parent that exited) is normal
|
|
@@ -70,12 +70,20 @@ export function epipeAwareBeforeSend(event, hint) {
|
|
|
70
70
|
// before the fleet scrubber — so it covers EVERY capture route (the top-level
|
|
71
71
|
// boundary, the command-level captureException sites, bin/hq-auth-refresh,
|
|
72
72
|
// any uncaughtException), mirroring the EPIPE and environmental-fs drops
|
|
73
|
-
// above. The
|
|
74
|
-
//
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
73
|
+
// above. The typed error classifiers use closed allowlists. The Codex
|
|
74
|
+
// collision branch uses one fixed bucket and adds the validated server name
|
|
75
|
+
// only as a tag; it sends no config values or paths. Unclassifiable
|
|
76
|
+
// events retain Sentry's default grouping.
|
|
77
|
+
const mcpCollision = sentryMcpCollisionContextFor(hint?.originalException);
|
|
78
|
+
if (mcpCollision) {
|
|
79
|
+
event.tags = { ...event.tags, ...mcpCollision.tags };
|
|
80
|
+
event.fingerprint = mcpCollision.fingerprint;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
const fingerprint = sentryFingerprintFor(hint?.originalException);
|
|
84
|
+
if (fingerprint)
|
|
85
|
+
event.fingerprint = fingerprint;
|
|
86
|
+
}
|
|
79
87
|
return beforeSend(event, hint);
|
|
80
88
|
}
|
|
81
89
|
/**
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
export interface SentryMcpCollisionContext {
|
|
2
|
+
tags: {
|
|
3
|
+
mcp_client: "codex";
|
|
4
|
+
server_name: string;
|
|
5
|
+
existing_entry_owner: "hq" | "foreign" | "unknown";
|
|
6
|
+
diff_fields: string;
|
|
7
|
+
};
|
|
8
|
+
fingerprint: string[];
|
|
9
|
+
}
|
|
10
|
+
/** Return bounded, value-free Sentry context for an instrumented Codex name collision. */
|
|
11
|
+
export declare function sentryMcpCollisionContextFor(err: unknown): SentryMcpCollisionContext | null;
|
|
1
12
|
/**
|
|
2
13
|
* Return a bounded `event.fingerprint` array for `err`, or `null` when `err`
|
|
3
14
|
* carries no discriminator from the closed allowlist (in which case the caller
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// src/utils/sentry-fingerprint.ts
|
|
2
2
|
//
|
|
3
|
-
// Compute a BOUNDED Sentry grouping fingerprint from an error, using only
|
|
4
|
-
//
|
|
5
|
-
// user-minted text. Sibling in spirit to qmd-collection-missing-error.ts
|
|
3
|
+
// Compute a BOUNDED Sentry grouping fingerprint from an error, using only
|
|
4
|
+
// closed discriminators and a fixed Codex collision bucket, never arbitrary
|
|
5
|
+
// upstream- or user-minted text. Sibling in spirit to qmd-collection-missing-error.ts
|
|
6
6
|
// (HQ-CLI-S): the same unbounded-fingerprint discipline, applied to grouping
|
|
7
7
|
// instead of to a printed line.
|
|
8
8
|
//
|
|
@@ -45,14 +45,14 @@
|
|
|
45
45
|
// grouping untouched.
|
|
46
46
|
//
|
|
47
47
|
// Two hard rules, mirroring HQ-CLI-S:
|
|
48
|
-
// 1.
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
//
|
|
54
|
-
//
|
|
55
|
-
//
|
|
48
|
+
// 1. BOUNDED DISCRIMINATORS. RPC/HTTP values use closed allowlists and
|
|
49
|
+
// fallback buckets. Codex collisions use one fixed client bucket. The
|
|
50
|
+
// server-name tag is restricted to 64 lowercase letters, digits,
|
|
51
|
+
// underscores or hyphens; other names share one fallback value. Owner and
|
|
52
|
+
// field tags also use closed sets.
|
|
53
|
+
// 2. NO FREE TEXT. Error messages, argv, URLs, connection ids, company slugs,
|
|
54
|
+
// config values and paths never reach a fingerprint or tags. The Codex
|
|
55
|
+
// branch uses a fixed fingerprint and bounded diagnostic tags.
|
|
56
56
|
//
|
|
57
57
|
// An error that carries no bounded discriminator returns `null`: the caller
|
|
58
58
|
// leaves `event.fingerprint` unset and Sentry keeps its DEFAULT grouping, so the
|
|
@@ -79,6 +79,48 @@ const KNOWN_HTTP_STATUSES = new Set([
|
|
|
79
79
|
]);
|
|
80
80
|
/** Sentry's placeholder for "keep the normal, stack-based grouping too". */
|
|
81
81
|
const DEFAULT_GROUPING = "{{ default }}";
|
|
82
|
+
const CODEX_COLLISION_NAME_RE = /^[a-z0-9_-]{1,64}$/;
|
|
83
|
+
const CODEX_COLLISION_OWNERS = new Set(["hq", "foreign", "unknown"]);
|
|
84
|
+
const CODEX_COLLISION_FIELDS = new Set(["command", "args", "env", "url", "other"]);
|
|
85
|
+
function isCodexCollisionOwner(value) {
|
|
86
|
+
return typeof value === "string" && CODEX_COLLISION_OWNERS.has(value);
|
|
87
|
+
}
|
|
88
|
+
/** Return bounded, value-free Sentry context for an instrumented Codex name collision. */
|
|
89
|
+
export function sentryMcpCollisionContextFor(err) {
|
|
90
|
+
if (err === null || typeof err !== "object")
|
|
91
|
+
return null;
|
|
92
|
+
const record = err;
|
|
93
|
+
if (record.name !== "McpNameCollisionError" || record.code !== "McpNameCollisionError") {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
const diagnostics = record.codexDiagnostics;
|
|
97
|
+
if (diagnostics === null || typeof diagnostics !== "object")
|
|
98
|
+
return null;
|
|
99
|
+
const context = diagnostics;
|
|
100
|
+
const owner = context.existingEntryOwner;
|
|
101
|
+
if (context.client !== "codex" ||
|
|
102
|
+
typeof context.serverName !== "string" ||
|
|
103
|
+
!isCodexCollisionOwner(owner) ||
|
|
104
|
+
!Array.isArray(context.diffFields) ||
|
|
105
|
+
context.diffFields.length === 0 ||
|
|
106
|
+
context.diffFields.length > CODEX_COLLISION_FIELDS.size ||
|
|
107
|
+
!context.diffFields.every((field) => typeof field === "string" && CODEX_COLLISION_FIELDS.has(field))) {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
const fields = [...new Set(context.diffFields)].sort();
|
|
111
|
+
const serverName = CODEX_COLLISION_NAME_RE.test(context.serverName)
|
|
112
|
+
? context.serverName
|
|
113
|
+
: "other";
|
|
114
|
+
return {
|
|
115
|
+
tags: {
|
|
116
|
+
mcp_client: "codex",
|
|
117
|
+
server_name: serverName,
|
|
118
|
+
existing_entry_owner: owner,
|
|
119
|
+
diff_fields: fields.join(","),
|
|
120
|
+
},
|
|
121
|
+
fingerprint: ["mcp-name-collision", "codex"],
|
|
122
|
+
};
|
|
123
|
+
}
|
|
82
124
|
/**
|
|
83
125
|
* The CLOSED set of error class names allowed to appear VERBATIM in a
|
|
84
126
|
* fingerprint. This hook runs on every capture route and accepts `unknown`, so
|
|
@@ -216,6 +258,9 @@ export function sentryFingerprintFor(err) {
|
|
|
216
258
|
const rawName = typeof record.name === "string" && record.name.length > 0 ? record.name : null;
|
|
217
259
|
if (rawName === null)
|
|
218
260
|
return null;
|
|
261
|
+
const mcpCollision = sentryMcpCollisionContextFor(record);
|
|
262
|
+
if (mcpCollision)
|
|
263
|
+
return mcpCollision.fingerprint;
|
|
219
264
|
// qmd process failures carry a PROCESS EXIT CODE in `status` (never an HTTP
|
|
220
265
|
// status) plus a subcommand in args[0]. Fingerprint them on a dedicated,
|
|
221
266
|
// fully-bounded key BEFORE the HTTP-status branch so an exit code is never read
|