@covro/covro 0.8.1-dev.6 → 0.8.1-dev.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/README.zh-CN.md +8 -8
- package/dist/backups/manager.js +21 -1
- package/dist/backups/manager.js.map +2 -2
- package/dist/cli/backup.js +33 -2
- package/dist/cli/backup.js.map +2 -2
- package/dist/cli/daemon.js +84 -18
- package/dist/cli/daemon.js.map +2 -2
- package/dist/cli/logs.js +141 -0
- package/dist/cli/logs.js.map +7 -0
- package/dist/cli/main.js +33 -10
- package/dist/cli/main.js.map +2 -2
- package/dist/cli/paths.js +9 -1
- package/dist/cli/paths.js.map +2 -2
- package/dist/codex/adapter.js +114 -6
- package/dist/codex/adapter.js.map +3 -3
- package/dist/codex/thread-titles.js +143 -21
- package/dist/codex/thread-titles.js.map +2 -2
- package/dist/codex/transport.js +32 -2
- package/dist/codex/transport.js.map +2 -2
- package/dist/logging/bootstrap.js +25 -0
- package/dist/logging/bootstrap.js.map +7 -0
- package/dist/logging/config.js +38 -0
- package/dist/logging/config.js.map +7 -0
- package/dist/logging/context.js +11 -0
- package/dist/logging/context.js.map +7 -0
- package/dist/logging/fields.js +82 -0
- package/dist/logging/fields.js.map +7 -0
- package/dist/logging/lifecycle.js +14 -0
- package/dist/logging/lifecycle.js.map +7 -0
- package/dist/logging/logger.js +216 -0
- package/dist/logging/logger.js.map +7 -0
- package/dist/logging/retention.js +62 -0
- package/dist/logging/retention.js.map +7 -0
- package/dist/server/capacity-retry.js +26 -1
- package/dist/server/capacity-retry.js.map +2 -2
- package/dist/server/db/operations.js +69 -13
- package/dist/server/db/operations.js.map +3 -3
- package/dist/server/db/question-tracking.js +29 -3
- package/dist/server/db/question-tracking.js.map +2 -2
- package/dist/server/file-references.js +66 -0
- package/dist/server/file-references.js.map +7 -0
- package/dist/server/http.js +50 -2
- package/dist/server/http.js.map +3 -3
- package/dist/server/main.js +57 -10
- package/dist/server/main.js.map +2 -2
- package/dist/server/mcp/server.js +17 -3
- package/dist/server/mcp/server.js.map +2 -2
- package/dist/server/project-clones.js +19 -1
- package/dist/server/project-clones.js.map +2 -2
- package/dist/server/projects.js +6 -0
- package/dist/server/projects.js.map +2 -2
- package/dist/server/service.js +130 -12
- package/dist/server/service.js.map +2 -2
- package/dist/server/websocket.js +24 -4
- package/dist/server/websocket.js.map +2 -2
- package/dist/shared/file-references.js +17 -0
- package/dist/shared/file-references.js.map +7 -0
- package/dist/shared/validation.js +23 -1
- package/dist/shared/validation.js.map +2 -2
- package/dist/update-worker.cjs +17027 -299
- package/dist/updates/manager.js +32 -5
- package/dist/updates/manager.js.map +2 -2
- package/dist/updates/worker.js +37 -4
- package/dist/updates/worker.js.map +2 -2
- package/dist/web/assets/{abnfDiagram-WEYOIA3C-B--HLBRU.js → abnfDiagram-WEYOIA3C-C_Sk7t78.js} +1 -1
- package/dist/web/assets/{arc-BA6LM9qR.js → arc-B7fhzjrW.js} +1 -1
- package/dist/web/assets/{architecture-WOLXFQ4H-BxH8Y_8w.js → architecture-WOLXFQ4H-DvtXEB8r.js} +1 -1
- package/dist/web/assets/{architectureDiagram-ZHVYKT53-Du_JEDSO.js → architectureDiagram-ZHVYKT53-qAhYJ66U.js} +1 -1
- package/dist/web/assets/{blockDiagram-RJAE7QA3-0mm-0YlH.js → blockDiagram-RJAE7QA3-BMfuVXgv.js} +1 -1
- package/dist/web/assets/{c4Diagram-XDPPPE54-Ca0mkJNX.js → c4Diagram-XDPPPE54-ChdFg4eh.js} +1 -1
- package/dist/web/assets/channel-C6FErhe0.js +1 -0
- package/dist/web/assets/{chunk-2E7WHVMD-kp8Z0o7K.js → chunk-2E7WHVMD-2254qq_b.js} +1 -1
- package/dist/web/assets/{chunk-4EMNKR2T-BKAE5YSO.js → chunk-4EMNKR2T-Btdfe8a5.js} +1 -1
- package/dist/web/assets/{chunk-55XCU76K-Dv0RzzJs.js → chunk-55XCU76K-hLv-2Klf.js} +1 -1
- package/dist/web/assets/{chunk-7S6XSTFO-dmBhSH5V.js → chunk-7S6XSTFO-CuVWLL5t.js} +1 -1
- package/dist/web/assets/{chunk-AQDTSKZB-ub-4UHFO.js → chunk-AQDTSKZB-ClcdhAcX.js} +1 -1
- package/dist/web/assets/{chunk-DSNLSHJZ-B4qpSl3v.js → chunk-DSNLSHJZ-DEnLBCCf.js} +1 -1
- package/dist/web/assets/{chunk-HAGFOTED-CTAe2Flk.js → chunk-HAGFOTED-CRPL1-GG.js} +1 -1
- package/dist/web/assets/{chunk-HNE4Q36P-wznprb2K.js → chunk-HNE4Q36P-rD1kJp06.js} +1 -1
- package/dist/web/assets/{chunk-NQOKRVIF-DFuVmaPf.js → chunk-NQOKRVIF-CyASuGCR.js} +1 -1
- package/dist/web/assets/{chunk-UHW7PFBP-BcHbXwO0.js → chunk-UHW7PFBP-4ya9RmmM.js} +1 -1
- package/dist/web/assets/{chunk-VQ5W62QI-TO80sYcs.js → chunk-VQ5W62QI-CPdxzKpk.js} +1 -1
- package/dist/web/assets/{chunk-WQQL4CDK-C074NuuH.js → chunk-WQQL4CDK-BnQt-9E2.js} +1 -1
- package/dist/web/assets/{chunk-XXDRQBXY-Dv8lvdin.js → chunk-XXDRQBXY-DrcyNGDJ.js} +1 -1
- package/dist/web/assets/{chunk-YZO67HFG-Cpt12wWD.js → chunk-YZO67HFG-CoMbVgDo.js} +1 -1
- package/dist/web/assets/{chunk-ZAUX2LTX-BvVO4mcK.js → chunk-ZAUX2LTX-8Cogs47O.js} +1 -1
- package/dist/web/assets/{chunk-ZCHMQSOR-D6-S1iot.js → chunk-ZCHMQSOR-CL9qHytJ.js} +1 -1
- package/dist/web/assets/{classDiagram-v2-4MYWR3UA-Czyj6aDC.js → classDiagram-v2-4MYWR3UA-CczNsQz8.js} +1 -1
- package/dist/web/assets/{cose-bilkent-JH36ORCC-DlZgG4Hy.js → cose-bilkent-JH36ORCC-DIN3sKoH.js} +1 -1
- package/dist/web/assets/{cynefin-EF2NZ3EQ-DggCmuEk.js → cynefin-EF2NZ3EQ-DRzCk374.js} +1 -1
- package/dist/web/assets/{cynefinDiagram-WF24UDRP-Y78QRDke.js → cynefinDiagram-WF24UDRP-C5a5aAFu.js} +1 -1
- package/dist/web/assets/{dagre-NK4GIZVX-B2D2GmfS.js → dagre-NK4GIZVX-9MUbUNbg.js} +1 -1
- package/dist/web/assets/{diagram-CBK3MWTC-B1fM9Qzn.js → diagram-CBK3MWTC-ly2ORVWq.js} +1 -1
- package/dist/web/assets/{diagram-I5XIIV2D-BmltjFNx.js → diagram-I5XIIV2D-Cwbptpw7.js} +1 -1
- package/dist/web/assets/{diagram-ODIL2UCW-B0fi6X8i.js → diagram-ODIL2UCW-C3s7b-u8.js} +1 -1
- package/dist/web/assets/{diagram-PFBEJUXE-RMJfHUUq.js → diagram-PFBEJUXE-BjlCGRjf.js} +1 -1
- package/dist/web/assets/{diagram-RJA3I4VV-B_4_qIV3.js → diagram-RJA3I4VV-DP1a6Mzo.js} +1 -1
- package/dist/web/assets/{diagram-TYUNFSNR-De-Mp1Xj.js → diagram-TYUNFSNR-DSz6ip6J.js} +1 -1
- package/dist/web/assets/{dist-BiJ4161L.js → dist-DOLJVqQr.js} +1 -1
- package/dist/web/assets/{ebnfDiagram-V4P3TTPT-Cb5L22nj.js → ebnfDiagram-V4P3TTPT-C1d9eRxH.js} +1 -1
- package/dist/web/assets/{elk-QONTBCTQ-BN5FRcIS.js → elk-QONTBCTQ-C9g1LS-p.js} +1 -1
- package/dist/web/assets/{erDiagram-KYQIGQAA-CTXR4zV5.js → erDiagram-KYQIGQAA-dxkp2bJZ.js} +1 -1
- package/dist/web/assets/{eventmodeling-K75KTNOO-B24F56y5.js → eventmodeling-K75KTNOO-VwADn86w.js} +1 -1
- package/dist/web/assets/flowDiagram-IUGLLWBU-DyjwVt7W.js +1 -0
- package/dist/web/assets/{ganttDiagram-R7GPNTJY-DqIqpS5W.js → ganttDiagram-R7GPNTJY-3GbViMJK.js} +1 -1
- package/dist/web/assets/{gitGraph-VSP46ZUC-CNkDi5d2.js → gitGraph-VSP46ZUC-GJjAtt_a.js} +1 -1
- package/dist/web/assets/{gitGraphDiagram-PDYL7XHY-hXfHsAUl.js → gitGraphDiagram-PDYL7XHY-zsxQdGsc.js} +1 -1
- package/dist/web/assets/{index-CJhiAWU_.css → index-DsTjqvUr.css} +1 -1
- package/dist/web/assets/index-U534hj4k.js +164 -0
- package/dist/web/assets/{info-OHQRW6UA-DZGW96Y3.js → info-OHQRW6UA-CwnUsM1e.js} +1 -1
- package/dist/web/assets/{infoDiagram-MVDRKAX5-C9UeusiS.js → infoDiagram-MVDRKAX5-BxjMvrog.js} +1 -1
- package/dist/web/assets/{ishikawaDiagram-HPEHV2GE--HXMPDsM.js → ishikawaDiagram-HPEHV2GE-DFnmkvoA.js} +1 -1
- package/dist/web/assets/{journeyDiagram-BOSHW7O7-eFghSzTd.js → journeyDiagram-BOSHW7O7-C64DJ862.js} +1 -1
- package/dist/web/assets/{kanban-definition-FNSA4HC5-Dp5pHCpQ.js → kanban-definition-FNSA4HC5-Boh6Iitf.js} +1 -1
- package/dist/web/assets/{line-J416Rwo7.js → line-rdP4ipIJ.js} +1 -1
- package/dist/web/assets/{linear-dcDMI4fS.js → linear-DSMIEOwe.js} +1 -1
- package/dist/web/assets/{mermaid-parser.core-6EMrqqvY.js → mermaid-parser.core-CCp9eot8.js} +3 -3
- package/dist/web/assets/{mermaid.core-_EZe9w4Q.js → mermaid.core-DjIok1BV.js} +4 -4
- package/dist/web/assets/{mindmap-definition-6OY57UG3-BVBTKQ8N.js → mindmap-definition-6OY57UG3-BzJR8se0.js} +1 -1
- package/dist/web/assets/{packet-JDAUHWVQ-D4OpL_fK.js → packet-JDAUHWVQ-DMmKjELh.js} +1 -1
- package/dist/web/assets/{pegDiagram-ECIUJNBX-DCpMX73b.js → pegDiagram-ECIUJNBX-KC3oILsA.js} +1 -1
- package/dist/web/assets/{pie-XZMESJXO-B_mtTP5p.js → pie-XZMESJXO-Df--bbSa.js} +1 -1
- package/dist/web/assets/{pieDiagram-GNMPY74T-Dk6Or5Uv.js → pieDiagram-GNMPY74T-BMZfiPGv.js} +1 -1
- package/dist/web/assets/{quadrantDiagram-D57K4MC3-BnSh6JoJ.js → quadrantDiagram-D57K4MC3-DXnNWG5F.js} +1 -1
- package/dist/web/assets/{radar-ABXABTNO-CoN9Pkqv.js → radar-ABXABTNO-TzHTEemc.js} +1 -1
- package/dist/web/assets/{railroad-I3PHUGI6-DxA2tnxP.js → railroad-I3PHUGI6-C27Kcuho.js} +1 -1
- package/dist/web/assets/{railroad-abnf-LNEFI6M7-DkDJfzRH.js → railroad-abnf-LNEFI6M7-BKk57xcr.js} +1 -1
- package/dist/web/assets/{railroad-ebnf-DWYD2UWJ-Bo0zFBCo.js → railroad-ebnf-DWYD2UWJ-BvaRzQQW.js} +1 -1
- package/dist/web/assets/{railroad-peg-JR7BVNR7-D3JyY5On.js → railroad-peg-JR7BVNR7-CfLsYmww.js} +1 -1
- package/dist/web/assets/{railroadDiagram-Y72NRBL7-CYcoEReQ.js → railroadDiagram-Y72NRBL7-BQ_k45oS.js} +1 -1
- package/dist/web/assets/{requirementDiagram-EQYSW5RA-DutpDlKa.js → requirementDiagram-EQYSW5RA-CwXsnupD.js} +1 -1
- package/dist/web/assets/{sankeyDiagram-SY24JHO5-Fbmy8e4_.js → sankeyDiagram-SY24JHO5-sAHZCcw7.js} +1 -1
- package/dist/web/assets/{sequenceDiagram-BLEHNHQU-B8SNnYz7.js → sequenceDiagram-BLEHNHQU-DZ9UcJYF.js} +1 -1
- package/dist/web/assets/{src-hqM7f81e.js → src-C0lp0upm.js} +1 -1
- package/dist/web/assets/{stateDiagram-v2-A6IESKWZ-e4xY7mwP.js → stateDiagram-v2-A6IESKWZ-kAOy9VMW.js} +1 -1
- package/dist/web/assets/{swimlanes-B3ENRKFQ-CI3leNOt.js → swimlanes-B3ENRKFQ-Cy-Kpx4-.js} +1 -1
- package/dist/web/assets/swimlanesDiagram-AYQRV4AK-BJTyt_U0.js +8 -0
- package/dist/web/assets/{timeline-definition-JXYKGLGB-D95GU6j8.js → timeline-definition-JXYKGLGB-BTuyBK6b.js} +1 -1
- package/dist/web/assets/{treeView-D4JQ5SDB-Bsp-gDES.js → treeView-D4JQ5SDB-Dbd_GUqT.js} +1 -1
- package/dist/web/assets/{treemap-SAJKECNS-DSI1aNHS.js → treemap-SAJKECNS-BnoQOlaS.js} +1 -1
- package/dist/web/assets/{usecaseDiagram-WPOLBNNX-DfD2COFw.js → usecaseDiagram-WPOLBNNX-BwtNMDaH.js} +1 -1
- package/dist/web/assets/{vennDiagram-Q3Y3IDCW-DXUg2b7J.js → vennDiagram-Q3Y3IDCW-P8nADf8v.js} +1 -1
- package/dist/web/assets/{wardley-7MLQ67FV-E0PgYABo.js → wardley-7MLQ67FV-CR_jX6KD.js} +1 -1
- package/dist/web/assets/{wardleyDiagram-IVAIDKWA-PNByLwH3.js → wardleyDiagram-IVAIDKWA-BdII6XrZ.js} +1 -1
- package/dist/web/assets/{xychartDiagram-4URNHDU4-DP2Jd2fL.js → xychartDiagram-4URNHDU4-Cu4707Wp.js} +1 -1
- package/dist/web/index.html +2 -2
- package/package.json +5 -3
- package/dist/web/assets/channel-DemP4h_q.js +0 -1
- package/dist/web/assets/flowDiagram-IUGLLWBU-DXv5cjup.js +0 -1
- package/dist/web/assets/index-CPjR9NI_.js +0 -164
- package/dist/web/assets/swimlanesDiagram-AYQRV4AK-DiqLNgRn.js +0 -8
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/logging/bootstrap.ts"],
|
|
4
|
+
"sourcesContent": ["import { constants } from 'node:fs';\nimport { open } from 'node:fs/promises';\n\n/** Retain a bounded tail in-place: a service manager may already hold the append fd. */\nexport async function trimBootstrap(path: string, maxBytes = 1024 * 1024, keepBytes = 64 * 1024) {\n let file;\n try {\n file = await open(path, constants.O_RDWR | (constants.O_NOFOLLOW ?? 0));\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return;\n throw error;\n }\n try {\n const info = await file.stat();\n if (!info.isFile() || info.size <= maxBytes) return;\n const tail = Buffer.alloc(Math.min(keepBytes, info.size));\n const { bytesRead } = await file.read(tail, 0, tail.length, info.size - tail.length);\n await file.truncate(0);\n await file.write(tail.subarray(0, bytesRead), 0, bytesRead, 0);\n } finally {\n await file.close();\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iBAAiB;AAC1B,SAAS,YAAY;AAGrB,eAAsB,cAAc,MAAc,WAAW,OAAO,MAAM,YAAY,KAAK,MAAM;AAC/F,MAAI;AACJ,MAAI;AACF,WAAO,MAAM,KAAK,MAAM,UAAU,UAAU,UAAU,cAAc,EAAE;AAAA,EACxE,SAAS,OAAO;AACd,QAAK,MAAgC,SAAS,SAAU;AACxD,UAAM;AAAA,EACR;AACA,MAAI;AACF,UAAM,OAAO,MAAM,KAAK,KAAK;AAC7B,QAAI,CAAC,KAAK,OAAO,KAAK,KAAK,QAAQ,SAAU;AAC7C,UAAM,OAAO,OAAO,MAAM,KAAK,IAAI,WAAW,KAAK,IAAI,CAAC;AACxD,UAAM,EAAE,UAAU,IAAI,MAAM,KAAK,KAAK,MAAM,GAAG,KAAK,QAAQ,KAAK,OAAO,KAAK,MAAM;AACnF,UAAM,KAAK,SAAS,CAAC;AACrB,UAAM,KAAK,MAAM,KAAK,SAAS,GAAG,SAAS,GAAG,GAAG,WAAW,CAAC;AAAA,EAC/D,UAAE;AACA,UAAM,KAAK,MAAM;AAAA,EACnB;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { logLevel } from "./logger.js";
|
|
2
|
+
function loggingOptions(directory, version, env = process.env) {
|
|
3
|
+
const integer = (name, fallback, min, max) => {
|
|
4
|
+
const text = env[name];
|
|
5
|
+
if (text === void 0) return fallback;
|
|
6
|
+
const value = Number(text);
|
|
7
|
+
if (!/^\d+$/.test(text) || !Number.isSafeInteger(value) || value < min || value > max)
|
|
8
|
+
throw new Error(`${name} must be an integer between ${min} and ${max}`);
|
|
9
|
+
return value;
|
|
10
|
+
};
|
|
11
|
+
const maxFileBytes = integer(
|
|
12
|
+
"COVRO_LOG_MAX_FILE_BYTES",
|
|
13
|
+
10 * 1024 * 1024,
|
|
14
|
+
256,
|
|
15
|
+
1024 * 1024 * 1024
|
|
16
|
+
);
|
|
17
|
+
const maxTotalBytes = integer(
|
|
18
|
+
"COVRO_LOG_MAX_TOTAL_BYTES",
|
|
19
|
+
200 * 1024 * 1024,
|
|
20
|
+
256,
|
|
21
|
+
10 * 1024 * 1024 * 1024
|
|
22
|
+
);
|
|
23
|
+
if (maxTotalBytes < maxFileBytes)
|
|
24
|
+
throw new Error("COVRO_LOG_MAX_TOTAL_BYTES must be at least COVRO_LOG_MAX_FILE_BYTES");
|
|
25
|
+
return {
|
|
26
|
+
directory,
|
|
27
|
+
version,
|
|
28
|
+
level: logLevel(env),
|
|
29
|
+
maxFileBytes,
|
|
30
|
+
maxTotalBytes,
|
|
31
|
+
maxAgeDays: integer("COVRO_LOG_MAX_AGE_DAYS", 14, 1, 365),
|
|
32
|
+
maxBufferBytes: integer("COVRO_LOG_MAX_BUFFER_BYTES", 1024 * 1024, 4096, 64 * 1024 * 1024)
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export {
|
|
36
|
+
loggingOptions
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/logging/config.ts"],
|
|
4
|
+
"sourcesContent": ["import type { LoggingOptions } from './logger.js';\nimport { logLevel } from './logger.js';\n\nexport function loggingOptions(\n directory: string,\n version: string,\n env = process.env,\n): LoggingOptions {\n const integer = (name: string, fallback: number, min: number, max: number) => {\n const text = env[name];\n if (text === undefined) return fallback;\n const value = Number(text);\n if (!/^\\d+$/.test(text) || !Number.isSafeInteger(value) || value < min || value > max)\n throw new Error(`${name} must be an integer between ${min} and ${max}`);\n return value;\n };\n const maxFileBytes = integer(\n 'COVRO_LOG_MAX_FILE_BYTES',\n 10 * 1024 * 1024,\n 256,\n 1024 * 1024 * 1024,\n );\n const maxTotalBytes = integer(\n 'COVRO_LOG_MAX_TOTAL_BYTES',\n 200 * 1024 * 1024,\n 256,\n 10 * 1024 * 1024 * 1024,\n );\n if (maxTotalBytes < maxFileBytes)\n throw new Error('COVRO_LOG_MAX_TOTAL_BYTES must be at least COVRO_LOG_MAX_FILE_BYTES');\n return {\n directory,\n version,\n level: logLevel(env),\n maxFileBytes,\n maxTotalBytes,\n maxAgeDays: integer('COVRO_LOG_MAX_AGE_DAYS', 14, 1, 365),\n maxBufferBytes: integer('COVRO_LOG_MAX_BUFFER_BYTES', 1024 * 1024, 4096, 64 * 1024 * 1024),\n };\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,gBAAgB;AAElB,SAAS,eACd,WACA,SACA,MAAM,QAAQ,KACE;AAChB,QAAM,UAAU,CAAC,MAAc,UAAkB,KAAa,QAAgB;AAC5E,UAAM,OAAO,IAAI,IAAI;AACrB,QAAI,SAAS,OAAW,QAAO;AAC/B,UAAM,QAAQ,OAAO,IAAI;AACzB,QAAI,CAAC,QAAQ,KAAK,IAAI,KAAK,CAAC,OAAO,cAAc,KAAK,KAAK,QAAQ,OAAO,QAAQ;AAChF,YAAM,IAAI,MAAM,GAAG,IAAI,+BAA+B,GAAG,QAAQ,GAAG,EAAE;AACxE,WAAO;AAAA,EACT;AACA,QAAM,eAAe;AAAA,IACnB;AAAA,IACA,KAAK,OAAO;AAAA,IACZ;AAAA,IACA,OAAO,OAAO;AAAA,EAChB;AACA,QAAM,gBAAgB;AAAA,IACpB;AAAA,IACA,MAAM,OAAO;AAAA,IACb;AAAA,IACA,KAAK,OAAO,OAAO;AAAA,EACrB;AACA,MAAI,gBAAgB;AAClB,UAAM,IAAI,MAAM,qEAAqE;AACvF,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,OAAO,SAAS,GAAG;AAAA,IACnB;AAAA,IACA;AAAA,IACA,YAAY,QAAQ,0BAA0B,IAAI,GAAG,GAAG;AAAA,IACxD,gBAAgB,QAAQ,8BAA8B,OAAO,MAAM,MAAM,KAAK,OAAO,IAAI;AAAA,EAC3F;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
const context = new AsyncLocalStorage();
|
|
3
|
+
const logContext = () => context.getStore() ?? {};
|
|
4
|
+
function withLogContext(fields, run) {
|
|
5
|
+
return context.run({ ...logContext(), ...fields }, run);
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
logContext,
|
|
9
|
+
withLogContext
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/logging/context.ts"],
|
|
4
|
+
"sourcesContent": ["import { AsyncLocalStorage } from 'node:async_hooks';\n\nexport interface LogContext {\n requestId?: string;\n operationId?: string;\n threadId?: string;\n sourceThreadId?: string;\n turnId?: string;\n jobId?: string;\n codexEpoch?: string;\n}\nconst context = new AsyncLocalStorage<LogContext>();\nexport const logContext = (): LogContext => context.getStore() ?? {};\nexport function withLogContext<T>(fields: LogContext, run: () => T): T {\n return context.run({ ...logContext(), ...fields }, run);\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,yBAAyB;AAWlC,MAAM,UAAU,IAAI,kBAA8B;AAC3C,MAAM,aAAa,MAAkB,QAAQ,SAAS,KAAK,CAAC;AAC5D,SAAS,eAAkB,QAAoB,KAAiB;AACrE,SAAO,QAAQ,IAAI,EAAE,GAAG,WAAW,GAAG,GAAG,OAAO,GAAG,GAAG;AACxD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
const identifiers = /* @__PURE__ */ new Set([
|
|
2
|
+
"component",
|
|
3
|
+
"requestId",
|
|
4
|
+
"operationId",
|
|
5
|
+
"threadId",
|
|
6
|
+
"sourceThreadId",
|
|
7
|
+
"turnId",
|
|
8
|
+
"jobId",
|
|
9
|
+
"codexEpoch",
|
|
10
|
+
"temporaryThreadId",
|
|
11
|
+
"connectionId",
|
|
12
|
+
"rpcId",
|
|
13
|
+
"backupId",
|
|
14
|
+
"updateId",
|
|
15
|
+
"cloneId",
|
|
16
|
+
"actionId"
|
|
17
|
+
]);
|
|
18
|
+
const labels = /* @__PURE__ */ new Set([
|
|
19
|
+
"stage",
|
|
20
|
+
"outcome",
|
|
21
|
+
"reason",
|
|
22
|
+
"errorCode",
|
|
23
|
+
"errorType",
|
|
24
|
+
"method",
|
|
25
|
+
"route",
|
|
26
|
+
"model",
|
|
27
|
+
"provider",
|
|
28
|
+
"version",
|
|
29
|
+
"codexVersion",
|
|
30
|
+
"signal",
|
|
31
|
+
"kind",
|
|
32
|
+
"state",
|
|
33
|
+
"previousState"
|
|
34
|
+
]);
|
|
35
|
+
const numbers = /* @__PURE__ */ new Set([
|
|
36
|
+
"durationMs",
|
|
37
|
+
"status",
|
|
38
|
+
"rpcCode",
|
|
39
|
+
"attempt",
|
|
40
|
+
"timeoutMs",
|
|
41
|
+
"exitCode",
|
|
42
|
+
"pendingRequests",
|
|
43
|
+
"receivedBytes",
|
|
44
|
+
"maxLineBytes",
|
|
45
|
+
"outputBytes",
|
|
46
|
+
"inputBytes",
|
|
47
|
+
"bufferedBytes",
|
|
48
|
+
"limitBytes",
|
|
49
|
+
"droppedRecords",
|
|
50
|
+
"count",
|
|
51
|
+
"port"
|
|
52
|
+
]);
|
|
53
|
+
const flags = /* @__PURE__ */ new Set(["uncertain", "willRetry", "ephemeral", "replayed", "truncated"]);
|
|
54
|
+
function safeFields(fields) {
|
|
55
|
+
const safe = {};
|
|
56
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
57
|
+
if (identifiers.has(key) && (typeof value === "string" || typeof value === "number")) {
|
|
58
|
+
const text = String(value);
|
|
59
|
+
if (/^[a-zA-Z0-9_.:-]{1,160}$/.test(text)) safe[key] = text;
|
|
60
|
+
} else if (labels.has(key) && typeof value === "string") {
|
|
61
|
+
if (/^[a-zA-Z0-9_./:@+ -]{1,180}$/.test(value) && !value.includes("://")) safe[key] = value;
|
|
62
|
+
} else if (numbers.has(key) && typeof value === "number" && Number.isFinite(value)) {
|
|
63
|
+
safe[key] = value;
|
|
64
|
+
} else if (flags.has(key) && typeof value === "boolean") safe[key] = value;
|
|
65
|
+
}
|
|
66
|
+
return safe;
|
|
67
|
+
}
|
|
68
|
+
function errorFields(error) {
|
|
69
|
+
if (!error || typeof error !== "object") return { errorCode: "UNKNOWN_ERROR" };
|
|
70
|
+
const value = error;
|
|
71
|
+
return safeFields({
|
|
72
|
+
errorCode: typeof value.code === "string" && /^[A-Z][A-Z0-9_]{0,79}$/.test(value.code) ? value.code : "UNEXPECTED_ERROR",
|
|
73
|
+
errorType: typeof value.name === "string" && /^[A-Za-z][A-Za-z0-9]{0,79}$/.test(value.name) ? value.name : "Error",
|
|
74
|
+
rpcCode: value.rpcCode,
|
|
75
|
+
uncertain: value.uncertain
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
export {
|
|
79
|
+
errorFields,
|
|
80
|
+
safeFields
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=fields.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/logging/fields.ts"],
|
|
4
|
+
"sourcesContent": ["/** Only explicitly approved metadata can cross the logging boundary. Never log payloads. */\nexport type LogFields = Record<string, unknown>;\nconst identifiers = new Set([\n 'component',\n 'requestId',\n 'operationId',\n 'threadId',\n 'sourceThreadId',\n 'turnId',\n 'jobId',\n 'codexEpoch',\n 'temporaryThreadId',\n 'connectionId',\n 'rpcId',\n 'backupId',\n 'updateId',\n 'cloneId',\n 'actionId',\n]);\nconst labels = new Set([\n 'stage',\n 'outcome',\n 'reason',\n 'errorCode',\n 'errorType',\n 'method',\n 'route',\n 'model',\n 'provider',\n 'version',\n 'codexVersion',\n 'signal',\n 'kind',\n 'state',\n 'previousState',\n]);\nconst numbers = new Set([\n 'durationMs',\n 'status',\n 'rpcCode',\n 'attempt',\n 'timeoutMs',\n 'exitCode',\n 'pendingRequests',\n 'receivedBytes',\n 'maxLineBytes',\n 'outputBytes',\n 'inputBytes',\n 'bufferedBytes',\n 'limitBytes',\n 'droppedRecords',\n 'count',\n 'port',\n]);\nconst flags = new Set(['uncertain', 'willRetry', 'ephemeral', 'replayed', 'truncated']);\n\nexport function safeFields(fields: LogFields): LogFields {\n const safe: LogFields = {};\n for (const [key, value] of Object.entries(fields)) {\n if (identifiers.has(key) && (typeof value === 'string' || typeof value === 'number')) {\n // IDs cannot contain prose, URLs, paths or injected log lines.\n const text = String(value);\n if (/^[a-zA-Z0-9_.:-]{1,160}$/.test(text)) safe[key] = text;\n } else if (labels.has(key) && typeof value === 'string') {\n if (/^[a-zA-Z0-9_./:@+ -]{1,180}$/.test(value) && !value.includes('://')) safe[key] = value;\n } else if (numbers.has(key) && typeof value === 'number' && Number.isFinite(value)) {\n safe[key] = value;\n } else if (flags.has(key) && typeof value === 'boolean') safe[key] = value;\n }\n return safe;\n}\n\n/** Exception text, stack, cause and details can contain prompts or credentials. */\nexport function errorFields(error: unknown): LogFields {\n if (!error || typeof error !== 'object') return { errorCode: 'UNKNOWN_ERROR' };\n const value = error as { code?: unknown; rpcCode?: unknown; uncertain?: unknown; name?: unknown };\n return safeFields({\n errorCode:\n typeof value.code === 'string' && /^[A-Z][A-Z0-9_]{0,79}$/.test(value.code)\n ? value.code\n : 'UNEXPECTED_ERROR',\n errorType:\n typeof value.name === 'string' && /^[A-Za-z][A-Za-z0-9]{0,79}$/.test(value.name)\n ? value.name\n : 'Error',\n rpcCode: value.rpcCode,\n uncertain: value.uncertain,\n });\n}\n"],
|
|
5
|
+
"mappings": "AAEA,MAAM,cAAc,oBAAI,IAAI;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AACD,MAAM,SAAS,oBAAI,IAAI;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AACD,MAAM,UAAU,oBAAI,IAAI;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AACD,MAAM,QAAQ,oBAAI,IAAI,CAAC,aAAa,aAAa,aAAa,YAAY,WAAW,CAAC;AAE/E,SAAS,WAAW,QAA8B;AACvD,QAAM,OAAkB,CAAC;AACzB,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,MAAM,GAAG;AACjD,QAAI,YAAY,IAAI,GAAG,MAAM,OAAO,UAAU,YAAY,OAAO,UAAU,WAAW;AAEpF,YAAM,OAAO,OAAO,KAAK;AACzB,UAAI,2BAA2B,KAAK,IAAI,EAAG,MAAK,GAAG,IAAI;AAAA,IACzD,WAAW,OAAO,IAAI,GAAG,KAAK,OAAO,UAAU,UAAU;AACvD,UAAI,+BAA+B,KAAK,KAAK,KAAK,CAAC,MAAM,SAAS,KAAK,EAAG,MAAK,GAAG,IAAI;AAAA,IACxF,WAAW,QAAQ,IAAI,GAAG,KAAK,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,GAAG;AAClF,WAAK,GAAG,IAAI;AAAA,IACd,WAAW,MAAM,IAAI,GAAG,KAAK,OAAO,UAAU,UAAW,MAAK,GAAG,IAAI;AAAA,EACvE;AACA,SAAO;AACT;AAGO,SAAS,YAAY,OAA2B;AACrD,MAAI,CAAC,SAAS,OAAO,UAAU,SAAU,QAAO,EAAE,WAAW,gBAAgB;AAC7E,QAAM,QAAQ;AACd,SAAO,WAAW;AAAA,IAChB,WACE,OAAO,MAAM,SAAS,YAAY,yBAAyB,KAAK,MAAM,IAAI,IACtE,MAAM,OACN;AAAA,IACN,WACE,OAAO,MAAM,SAAS,YAAY,8BAA8B,KAAK,MAAM,IAAI,IAC3E,MAAM,OACN;AAAA,IACN,SAAS,MAAM;AAAA,IACf,WAAW,MAAM;AAAA,EACnB,CAAC;AACH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { errorFields } from "./fields.js";
|
|
2
|
+
function monitorCrashes(logger, flush) {
|
|
3
|
+
const monitor = (error) => {
|
|
4
|
+
logger.fatal("process.uncaught_exception", errorFields(error));
|
|
5
|
+
flush();
|
|
6
|
+
process.exit(1);
|
|
7
|
+
};
|
|
8
|
+
process.on("uncaughtException", monitor);
|
|
9
|
+
return () => process.removeListener("uncaughtException", monitor);
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
monitorCrashes
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=lifecycle.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/logging/lifecycle.ts"],
|
|
4
|
+
"sourcesContent": ["import { errorFields } from './fields.js';\nimport type { Logger } from './logger.js';\n\n/** Fatal exceptions terminate with status 1; never continue serving or print raw error content. */\nexport function monitorCrashes(logger: Logger, flush: () => void): () => void {\n const monitor = (error: Error) => {\n logger.fatal('process.uncaught_exception', errorFields(error));\n flush();\n process.exit(1);\n };\n process.on('uncaughtException', monitor);\n return () => process.removeListener('uncaughtException', monitor);\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,mBAAmB;AAIrB,SAAS,eAAe,QAAgB,OAA+B;AAC5E,QAAM,UAAU,CAAC,UAAiB;AAChC,WAAO,MAAM,8BAA8B,YAAY,KAAK,CAAC;AAC7D,UAAM;AACN,YAAQ,KAAK,CAAC;AAAA,EAChB;AACA,UAAQ,GAAG,qBAAqB,OAAO;AACvC,SAAO,MAAM,QAAQ,eAAe,qBAAqB,OAAO;AAClE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { writeSync } from "node:fs";
|
|
2
|
+
import pino from "pino";
|
|
3
|
+
import roll from "pino-roll";
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
import { chmod, mkdir, writeFile, unlink } from "node:fs/promises";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { logContext } from "./context.js";
|
|
8
|
+
import { safeFields } from "./fields.js";
|
|
9
|
+
import { cleanLogs } from "./retention.js";
|
|
10
|
+
const levels = ["debug", "info", "warn", "error", "fatal"];
|
|
11
|
+
const noop = () => {
|
|
12
|
+
};
|
|
13
|
+
const nullLogger = {
|
|
14
|
+
debug: noop,
|
|
15
|
+
info: noop,
|
|
16
|
+
warn: noop,
|
|
17
|
+
error: noop,
|
|
18
|
+
fatal: noop,
|
|
19
|
+
child: () => nullLogger
|
|
20
|
+
};
|
|
21
|
+
function wrapLogger(output, bindings = {}) {
|
|
22
|
+
const write = (level, event, fields = {}) => {
|
|
23
|
+
if (!/^[a-z][a-z0-9_.]{0,99}$/.test(event)) return;
|
|
24
|
+
output[level]({
|
|
25
|
+
...safeFields({ ...logContext() }),
|
|
26
|
+
...safeFields(bindings),
|
|
27
|
+
...safeFields(fields),
|
|
28
|
+
event
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
debug: (event, fields) => write("debug", event, fields),
|
|
33
|
+
info: (event, fields) => write("info", event, fields),
|
|
34
|
+
warn: (event, fields) => write("warn", event, fields),
|
|
35
|
+
error: (event, fields) => write("error", event, fields),
|
|
36
|
+
fatal: (event, fields) => write("fatal", event, fields),
|
|
37
|
+
child: (fields) => wrapLogger(output, { ...bindings, ...safeFields(fields) })
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
async function createLogging(options) {
|
|
41
|
+
const runId = randomUUID();
|
|
42
|
+
const marker = join(options.directory, `.active.${process.pid}.${runId}`);
|
|
43
|
+
const health = {
|
|
44
|
+
mode: "file",
|
|
45
|
+
directory: options.directory,
|
|
46
|
+
runId,
|
|
47
|
+
droppedRecords: 0
|
|
48
|
+
};
|
|
49
|
+
const fallback = options.fallback ?? ((line) => {
|
|
50
|
+
writeSync(2, line);
|
|
51
|
+
});
|
|
52
|
+
let lastFallback = 0;
|
|
53
|
+
let closed = false;
|
|
54
|
+
const report = (errorCode, disable = true) => {
|
|
55
|
+
if (disable) health.mode = "stderr";
|
|
56
|
+
health.errorCode = errorCode;
|
|
57
|
+
if (Date.now() - lastFallback < 1e4) return;
|
|
58
|
+
lastFallback = Date.now();
|
|
59
|
+
try {
|
|
60
|
+
fallback(
|
|
61
|
+
JSON.stringify({
|
|
62
|
+
time: (/* @__PURE__ */ new Date()).toISOString(),
|
|
63
|
+
level: 50,
|
|
64
|
+
event: disable ? "logging.write_failed" : "logging.cleanup_failed",
|
|
65
|
+
runId,
|
|
66
|
+
errorCode
|
|
67
|
+
}) + "\n"
|
|
68
|
+
);
|
|
69
|
+
} catch {
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
let stream;
|
|
73
|
+
const cleanup = () => cleanLogs(options.directory, {
|
|
74
|
+
maxAgeDays: options.maxAgeDays ?? 14,
|
|
75
|
+
maxTotalBytes: options.maxTotalBytes ?? 200 * 1024 * 1024,
|
|
76
|
+
activeRunIds: closed ? [] : [runId]
|
|
77
|
+
});
|
|
78
|
+
try {
|
|
79
|
+
await mkdir(options.directory, { recursive: true, mode: 448 });
|
|
80
|
+
await chmod(options.directory, 448);
|
|
81
|
+
await cleanup();
|
|
82
|
+
await writeFile(marker, "", { flag: "wx", mode: 384 });
|
|
83
|
+
stream = await roll({
|
|
84
|
+
file: join(options.directory, `covro.${runId}.jsonl`),
|
|
85
|
+
frequency: "daily",
|
|
86
|
+
dateFormat: "yyyy-MM-dd",
|
|
87
|
+
size: `${options.maxFileBytes ?? 10 * 1024 * 1024}b`,
|
|
88
|
+
mkdir: true,
|
|
89
|
+
mode: 384,
|
|
90
|
+
sync: false,
|
|
91
|
+
maxLength: options.maxBufferBytes ?? 1024 * 1024
|
|
92
|
+
});
|
|
93
|
+
stream.on(
|
|
94
|
+
"error",
|
|
95
|
+
(error) => report(/^[A-Z0-9_]+$/.test(error.code ?? "") ? error.code : "LOG_WRITE_FAILED")
|
|
96
|
+
);
|
|
97
|
+
stream.on("drop", () => {
|
|
98
|
+
health.droppedRecords++;
|
|
99
|
+
if (Date.now() - lastFallback < 1e4) return;
|
|
100
|
+
lastFallback = Date.now();
|
|
101
|
+
try {
|
|
102
|
+
fallback(
|
|
103
|
+
JSON.stringify({
|
|
104
|
+
time: (/* @__PURE__ */ new Date()).toISOString(),
|
|
105
|
+
level: 40,
|
|
106
|
+
event: "logging.records_dropped",
|
|
107
|
+
runId,
|
|
108
|
+
droppedRecords: health.droppedRecords
|
|
109
|
+
}) + "\n"
|
|
110
|
+
);
|
|
111
|
+
} catch {
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
if (stream.fd < 0)
|
|
115
|
+
await new Promise((resolve, reject) => {
|
|
116
|
+
stream.once("ready", resolve);
|
|
117
|
+
stream.once("error", reject);
|
|
118
|
+
});
|
|
119
|
+
stream.on("ready", () => {
|
|
120
|
+
void cleanup().catch(() => report("LOG_CLEANUP_FAILED", false));
|
|
121
|
+
});
|
|
122
|
+
} catch {
|
|
123
|
+
report("LOG_INIT_FAILED");
|
|
124
|
+
}
|
|
125
|
+
const destination = {
|
|
126
|
+
write(line) {
|
|
127
|
+
if (closed) return;
|
|
128
|
+
if (stream && health.mode === "file") {
|
|
129
|
+
try {
|
|
130
|
+
stream.write(line);
|
|
131
|
+
} catch {
|
|
132
|
+
report("LOG_WRITE_FAILED");
|
|
133
|
+
}
|
|
134
|
+
} else {
|
|
135
|
+
health.droppedRecords++;
|
|
136
|
+
if (/"level":(?:40|50|60)/.test(line) && Date.now() - lastFallback >= 1e3) {
|
|
137
|
+
lastFallback = Date.now();
|
|
138
|
+
try {
|
|
139
|
+
fallback(line);
|
|
140
|
+
} catch {
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
const output = pino(
|
|
147
|
+
{
|
|
148
|
+
level: options.level ?? "info",
|
|
149
|
+
timestamp: pino.stdTimeFunctions.isoTime,
|
|
150
|
+
base: { pid: process.pid, version: options.version, runId }
|
|
151
|
+
},
|
|
152
|
+
destination
|
|
153
|
+
);
|
|
154
|
+
const logger = wrapLogger(output, { component: options.component ?? "gateway" });
|
|
155
|
+
const timer = setInterval(() => {
|
|
156
|
+
void cleanup().catch(() => report("LOG_CLEANUP_FAILED", false));
|
|
157
|
+
}, 6e4);
|
|
158
|
+
timer.unref();
|
|
159
|
+
let closing;
|
|
160
|
+
const close = () => closing ??= (async () => {
|
|
161
|
+
clearInterval(timer);
|
|
162
|
+
if (!stream || stream.destroyed) {
|
|
163
|
+
closed = true;
|
|
164
|
+
await unlink(marker).catch(() => {
|
|
165
|
+
});
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
await new Promise((resolve) => {
|
|
169
|
+
const timeout = setTimeout(() => {
|
|
170
|
+
stream.destroy();
|
|
171
|
+
resolve();
|
|
172
|
+
}, 3e3);
|
|
173
|
+
const done = () => {
|
|
174
|
+
clearTimeout(timeout);
|
|
175
|
+
resolve();
|
|
176
|
+
};
|
|
177
|
+
stream.once("close", done);
|
|
178
|
+
stream.once("error", done);
|
|
179
|
+
try {
|
|
180
|
+
stream.end();
|
|
181
|
+
} catch {
|
|
182
|
+
done();
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
closed = true;
|
|
186
|
+
await unlink(marker).catch(() => {
|
|
187
|
+
});
|
|
188
|
+
await cleanup().catch(() => report("LOG_CLEANUP_FAILED", false));
|
|
189
|
+
})();
|
|
190
|
+
return {
|
|
191
|
+
logger,
|
|
192
|
+
health: () => ({ ...health }),
|
|
193
|
+
close,
|
|
194
|
+
flushSync: () => {
|
|
195
|
+
try {
|
|
196
|
+
if (stream && !stream.destroyed) stream.flushSync();
|
|
197
|
+
} catch {
|
|
198
|
+
report("LOG_FLUSH_FAILED");
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function logLevel(env = process.env) {
|
|
204
|
+
const value = env.COVRO_LOG_LEVEL ?? "info";
|
|
205
|
+
if (!levels.includes(value))
|
|
206
|
+
throw new Error("COVRO_LOG_LEVEL must be debug, info, warn, error or fatal");
|
|
207
|
+
return value;
|
|
208
|
+
}
|
|
209
|
+
export {
|
|
210
|
+
createLogging,
|
|
211
|
+
levels,
|
|
212
|
+
logLevel,
|
|
213
|
+
nullLogger,
|
|
214
|
+
wrapLogger
|
|
215
|
+
};
|
|
216
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/logging/logger.ts"],
|
|
4
|
+
"sourcesContent": ["import { writeSync } from 'node:fs';\nimport pino from 'pino';\nimport roll from 'pino-roll';\nimport { randomUUID } from 'node:crypto';\nimport { chmod, mkdir, writeFile, unlink } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { logContext } from './context.js';\nimport { safeFields, type LogFields } from './fields.js';\nimport { cleanLogs } from './retention.js';\n\nexport const levels = ['debug', 'info', 'warn', 'error', 'fatal'] as const;\nexport type LogLevel = (typeof levels)[number];\nexport interface Logger {\n debug(event: string, fields?: LogFields): void;\n info(event: string, fields?: LogFields): void;\n warn(event: string, fields?: LogFields): void;\n error(event: string, fields?: LogFields): void;\n fatal(event: string, fields?: LogFields): void;\n child(fields: LogFields): Logger;\n}\nconst noop = () => {};\nexport const nullLogger: Logger = {\n debug: noop,\n info: noop,\n warn: noop,\n error: noop,\n fatal: noop,\n child: () => nullLogger,\n};\nexport interface LogHealth {\n mode: 'file' | 'stderr';\n directory: string;\n runId: string;\n droppedRecords: number;\n errorCode?: string;\n}\nexport interface LoggingOptions {\n directory: string;\n version: string;\n component?: string;\n level?: LogLevel;\n maxFileBytes?: number;\n maxTotalBytes?: number;\n maxAgeDays?: number;\n maxBufferBytes?: number;\n /** Testing/embedding hook: receives sanitized records only. */\n fallback?: (line: string) => void;\n}\nexport function wrapLogger(output: pino.Logger, bindings: LogFields = {}): Logger {\n const write = (level: LogLevel, event: string, fields: LogFields = {}) => {\n if (!/^[a-z][a-z0-9_.]{0,99}$/.test(event)) return;\n output[level]({\n ...safeFields({ ...logContext() }),\n ...safeFields(bindings),\n ...safeFields(fields),\n event,\n });\n };\n return {\n debug: (event, fields) => write('debug', event, fields),\n info: (event, fields) => write('info', event, fields),\n warn: (event, fields) => write('warn', event, fields),\n error: (event, fields) => write('error', event, fields),\n fatal: (event, fields) => write('fatal', event, fields),\n child: (fields) => wrapLogger(output, { ...bindings, ...safeFields(fields) }),\n };\n}\nexport async function createLogging(options: LoggingOptions) {\n const runId = randomUUID();\n const marker = join(options.directory, `.active.${process.pid}.${runId}`);\n const health: LogHealth = {\n mode: 'file',\n directory: options.directory,\n runId,\n droppedRecords: 0,\n };\n const fallback =\n options.fallback ??\n ((line: string) => {\n // A failed stderr stream can emit an asynchronous unhandled error.\n // This rare, rate-limited fallback must fail synchronously inside our catch.\n writeSync(2, line);\n });\n let lastFallback = 0;\n let closed = false;\n const report = (errorCode: string, disable = true) => {\n if (disable) health.mode = 'stderr';\n health.errorCode = errorCode;\n if (Date.now() - lastFallback < 10_000) return;\n lastFallback = Date.now();\n try {\n fallback(\n JSON.stringify({\n time: new Date().toISOString(),\n level: 50,\n event: disable ? 'logging.write_failed' : 'logging.cleanup_failed',\n runId,\n errorCode,\n }) + '\\n',\n );\n } catch {\n /* Logging never fails a user operation. */\n }\n };\n let stream: Awaited<ReturnType<typeof roll>> | undefined;\n const cleanup = () =>\n cleanLogs(options.directory, {\n maxAgeDays: options.maxAgeDays ?? 14,\n maxTotalBytes: options.maxTotalBytes ?? 200 * 1024 * 1024,\n activeRunIds: closed ? [] : [runId],\n });\n try {\n await mkdir(options.directory, { recursive: true, mode: 0o700 });\n await chmod(options.directory, 0o700);\n await cleanup();\n await writeFile(marker, '', { flag: 'wx', mode: 0o600 });\n stream = await roll({\n file: join(options.directory, `covro.${runId}.jsonl`),\n frequency: 'daily',\n dateFormat: 'yyyy-MM-dd',\n size: `${options.maxFileBytes ?? 10 * 1024 * 1024}b`,\n mkdir: true,\n mode: 0o600,\n sync: false,\n maxLength: options.maxBufferBytes ?? 1024 * 1024,\n });\n stream.on('error', (error: NodeJS.ErrnoException) =>\n report(/^[A-Z0-9_]+$/.test(error.code ?? '') ? error.code! : 'LOG_WRITE_FAILED'),\n );\n stream.on('drop', () => {\n health.droppedRecords++;\n if (Date.now() - lastFallback < 10_000) return;\n lastFallback = Date.now();\n try {\n fallback(\n JSON.stringify({\n time: new Date().toISOString(),\n level: 40,\n event: 'logging.records_dropped',\n runId,\n droppedRecords: health.droppedRecords,\n }) + '\\n',\n );\n } catch {\n /* Best effort. */\n }\n });\n if (stream.fd < 0)\n await new Promise<void>((resolve, reject) => {\n stream!.once('ready', resolve);\n stream!.once('error', reject);\n });\n stream.on('ready', () => {\n void cleanup().catch(() => report('LOG_CLEANUP_FAILED', false));\n });\n } catch {\n report('LOG_INIT_FAILED');\n }\n const destination = {\n write(line: string) {\n if (closed) return;\n if (stream && health.mode === 'file') {\n try {\n stream.write(line);\n } catch {\n report('LOG_WRITE_FAILED');\n }\n } else {\n // On failure emit bounded safe error records, rather than queue indefinitely.\n health.droppedRecords++;\n if (/\"level\":(?:40|50|60)/.test(line) && Date.now() - lastFallback >= 1000) {\n lastFallback = Date.now();\n try {\n fallback(line);\n } catch {\n /* Best effort. */\n }\n }\n }\n },\n };\n const output = pino(\n {\n level: options.level ?? 'info',\n timestamp: pino.stdTimeFunctions.isoTime,\n base: { pid: process.pid, version: options.version, runId },\n },\n destination,\n );\n const logger = wrapLogger(output, { component: options.component ?? 'gateway' });\n const timer = setInterval(() => {\n void cleanup().catch(() => report('LOG_CLEANUP_FAILED', false));\n }, 60_000);\n timer.unref();\n let closing: Promise<void> | undefined;\n const close = () =>\n (closing ??= (async () => {\n clearInterval(timer);\n if (!stream || stream.destroyed) {\n closed = true;\n await unlink(marker).catch(() => {});\n return;\n }\n await new Promise<void>((resolve) => {\n const timeout = setTimeout(() => {\n stream!.destroy();\n resolve();\n }, 3000);\n const done = () => {\n clearTimeout(timeout);\n resolve();\n };\n stream!.once('close', done);\n stream!.once('error', done);\n try {\n stream!.end();\n } catch {\n done();\n }\n });\n closed = true;\n await unlink(marker).catch(() => {});\n await cleanup().catch(() => report('LOG_CLEANUP_FAILED', false));\n })());\n return {\n logger,\n health: () => ({ ...health }),\n close,\n flushSync: () => {\n try {\n if (stream && !stream.destroyed) stream.flushSync();\n } catch {\n report('LOG_FLUSH_FAILED');\n }\n },\n };\n}\nexport function logLevel(env = process.env): LogLevel {\n const value = env.COVRO_LOG_LEVEL ?? 'info';\n if (!levels.includes(value as LogLevel))\n throw new Error('COVRO_LOG_LEVEL must be debug, info, warn, error or fatal');\n return value as LogLevel;\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iBAAiB;AAC1B,OAAO,UAAU;AACjB,OAAO,UAAU;AACjB,SAAS,kBAAkB;AAC3B,SAAS,OAAO,OAAO,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AAQ;AACN,eAAO,kBAAkB;AAAA,MAC3B;AAAA,IACF;AAAA,EACF;AACF;AACO,SAAS,SAAS,MAAM,QAAQ,KAAe;AACpD,QAAM,QAAQ,IAAI,mBAAmB;AACrC,MAAI,CAAC,OAAO,SAAS,KAAiB;AACpC,UAAM,IAAI,MAAM,2DAA2D;AAC7E,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { readdir, lstat, unlink } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
const logFilename = /^covro\.[a-z0-9-]+(?:\.[0-9-]+)*\.\d+\.jsonl$/;
|
|
4
|
+
async function logFiles(directory) {
|
|
5
|
+
const entries = await readdir(directory).catch((error) => {
|
|
6
|
+
if (error.code === "ENOENT") return [];
|
|
7
|
+
throw error;
|
|
8
|
+
});
|
|
9
|
+
const files = await Promise.all(
|
|
10
|
+
entries.filter((name) => logFilename.test(name)).map(async (name) => {
|
|
11
|
+
const path = join(directory, name);
|
|
12
|
+
try {
|
|
13
|
+
const stat = await lstat(path);
|
|
14
|
+
return stat.isFile() && !stat.isSymbolicLink() ? { name, path, size: stat.size, mtimeMs: stat.mtimeMs } : void 0;
|
|
15
|
+
} catch (error) {
|
|
16
|
+
if (error.code === "ENOENT") return;
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
return files.filter((file) => file !== void 0).sort(
|
|
22
|
+
(a, b) => a.mtimeMs - b.mtimeMs || a.name.localeCompare(b.name, void 0, { numeric: true })
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
async function cleanLogs(directory, options) {
|
|
26
|
+
const files = await logFiles(directory);
|
|
27
|
+
let total = files.reduce((size, file) => size + file.size, 0);
|
|
28
|
+
const cutoff = (options.now ?? Date.now()) - options.maxAgeDays * 864e5;
|
|
29
|
+
const activeRuns = new Set(options.activeRunIds);
|
|
30
|
+
for (const name of await readdir(directory)) {
|
|
31
|
+
const match = /^\.active\.(\d+)\.([a-f0-9-]{36})$/.exec(name);
|
|
32
|
+
if (!match) continue;
|
|
33
|
+
try {
|
|
34
|
+
process.kill(Number(match[1]), 0);
|
|
35
|
+
activeRuns.add(match[2]);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
if (error.code === "ESRCH")
|
|
38
|
+
await unlink(join(directory, name)).catch(() => {
|
|
39
|
+
});
|
|
40
|
+
else activeRuns.add(match[2]);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const protectedFiles = /* @__PURE__ */ new Set();
|
|
44
|
+
for (const id of activeRuns) {
|
|
45
|
+
const latest = files.filter((file) => file.name.startsWith(`covro.${id}.`)).at(-1);
|
|
46
|
+
if (latest) protectedFiles.add(latest.path);
|
|
47
|
+
}
|
|
48
|
+
for (const file of files) {
|
|
49
|
+
if (protectedFiles.has(file.path)) continue;
|
|
50
|
+
if (file.mtimeMs >= cutoff && total <= options.maxTotalBytes) continue;
|
|
51
|
+
await unlink(file.path).catch((error) => {
|
|
52
|
+
if (error.code !== "ENOENT") throw error;
|
|
53
|
+
});
|
|
54
|
+
total -= file.size;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
cleanLogs,
|
|
59
|
+
logFilename,
|
|
60
|
+
logFiles
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=retention.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/logging/retention.ts"],
|
|
4
|
+
"sourcesContent": ["import { readdir, lstat, unlink } from 'node:fs/promises';\nimport { join } from 'node:path';\n\n// Per-process names prevent competing rotation writers; cleanup spans previous runs.\nexport const logFilename = /^covro\\.[a-z0-9-]+(?:\\.[0-9-]+)*\\.\\d+\\.jsonl$/;\nexport async function logFiles(directory: string) {\n const entries = await readdir(directory).catch((error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') return [];\n throw error;\n });\n const files = await Promise.all(\n entries\n .filter((name) => logFilename.test(name))\n .map(async (name) => {\n const path = join(directory, name);\n try {\n const stat = await lstat(path);\n return stat.isFile() && !stat.isSymbolicLink()\n ? { name, path, size: stat.size, mtimeMs: stat.mtimeMs }\n : undefined;\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return;\n throw error;\n }\n }),\n );\n return files\n .filter((file) => file !== undefined)\n .sort(\n (a, b) => a.mtimeMs - b.mtimeMs || a.name.localeCompare(b.name, undefined, { numeric: true }),\n );\n}\nexport async function cleanLogs(\n directory: string,\n options: {\n maxAgeDays: number;\n maxTotalBytes: number;\n activeRunIds?: string[];\n now?: number;\n },\n) {\n const files = await logFiles(directory);\n let total = files.reduce((size, file) => size + file.size, 0);\n const cutoff = (options.now ?? Date.now()) - options.maxAgeDays * 86400_000;\n const activeRuns = new Set(options.activeRunIds);\n for (const name of await readdir(directory)) {\n const match = /^\\.active\\.(\\d+)\\.([a-f0-9-]{36})$/.exec(name);\n if (!match) continue;\n try {\n process.kill(Number(match[1]), 0);\n activeRuns.add(match[2]!);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ESRCH')\n await unlink(join(directory, name)).catch(() => {});\n else activeRuns.add(match[2]!);\n }\n }\n const protectedFiles = new Set<string>();\n for (const id of activeRuns) {\n const latest = files.filter((file) => file.name.startsWith(`covro.${id}.`)).at(-1);\n if (latest) protectedFiles.add(latest.path);\n }\n for (const file of files) {\n // Never unlink another live process's active file. Its own writer handles rotation.\n if (protectedFiles.has(file.path)) continue;\n if (file.mtimeMs >= cutoff && total <= options.maxTotalBytes) continue;\n await unlink(file.path).catch((error: NodeJS.ErrnoException) => {\n if (error.code !== 'ENOENT') throw error;\n });\n total -= file.size;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,SAAS,OAAO,cAAc;AACvC,SAAS,YAAY;AAGd,MAAM,cAAc;AAC3B,eAAsB,SAAS,WAAmB;AACh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MAAgC,SAAS;AAC5C,cAAM,OAAO,KAAK,WAAW,IAAI,CAAC,EAAE,MAAM,MAAM;AAAA,QAAC,CAAC;AAAA,UAC/C,YAAW,IAAI,MAAM,CAAC,CAAE;AAAA,IAC/B;AAAA,EACF;AACA,QAAM,iBAAiB,oBAAI,IAAY;AACvC,aAAW,MAAM,YAAY;AAC3B,UAAM,SAAS,MAAM,OAAO,CAAC,SAAS,KAAK,KAAK,WAAW,SAAS,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE;AACjF,QAAI,OAAQ,gBAAe,IAAI,OAAO,IAAI;AAAA,EAC5C;AACA,aAAW,QAAQ,OAAO;AAExB,QAAI,eAAe,IAAI,KAAK,IAAI,EAAG;AACnC,QAAI,KAAK,WAAW,UAAU,SAAS,QAAQ,cAAe;AAC9D,UAAM,OAAO,KAAK,IAAI,EAAE,MAAM,CAAC,UAAiC;AAC9D,UAAI,MAAM,SAAS,SAAU,OAAM;AAAA,IACrC,CAAC;AACD,aAAS,KAAK;AAAA,EAChB;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
import { nullLogger } from "../logging/logger.js";
|
|
1
2
|
import { randomUUID } from "node:crypto";
|
|
2
3
|
import { isModelCapacityError } from "../shared/turn-errors.js";
|
|
3
4
|
const DELAYS = [5e3, 1e4, 2e4];
|
|
4
5
|
class CapacityRetries {
|
|
5
|
-
constructor(run, changed) {
|
|
6
|
+
constructor(run, changed, logger = nullLogger) {
|
|
6
7
|
this.run = run;
|
|
7
8
|
this.changed = changed;
|
|
9
|
+
this.logger = logger;
|
|
8
10
|
}
|
|
9
11
|
run;
|
|
10
12
|
changed;
|
|
13
|
+
logger;
|
|
11
14
|
jobs = /* @__PURE__ */ new Map();
|
|
12
15
|
begin(threadId, operationId, settings, epoch) {
|
|
13
16
|
this.clear(threadId);
|
|
@@ -50,6 +53,11 @@ class CapacityRetries {
|
|
|
50
53
|
for (const id of this.jobs.keys()) this.clear(id);
|
|
51
54
|
}
|
|
52
55
|
cancel(job) {
|
|
56
|
+
this.logger.info("capacity_retry.cancelled", {
|
|
57
|
+
threadId: job.threadId,
|
|
58
|
+
operationId: job.operationId,
|
|
59
|
+
attempt: job.attempt
|
|
60
|
+
});
|
|
53
61
|
if (job.timer) clearTimeout(job.timer);
|
|
54
62
|
delete job.timer;
|
|
55
63
|
job.cancelled = true;
|
|
@@ -135,6 +143,12 @@ class CapacityRetries {
|
|
|
135
143
|
attempt: job.attempt + 1,
|
|
136
144
|
nextAttemptAt: Date.now() + delay
|
|
137
145
|
};
|
|
146
|
+
this.logger.info("capacity_retry.scheduled", {
|
|
147
|
+
threadId: job.threadId,
|
|
148
|
+
operationId: job.operationId,
|
|
149
|
+
attempt: job.attempt + 1,
|
|
150
|
+
timeoutMs: delay
|
|
151
|
+
});
|
|
138
152
|
job.timer = setTimeout(() => {
|
|
139
153
|
delete job.timer;
|
|
140
154
|
if (!this.owns(job)) return;
|
|
@@ -149,6 +163,11 @@ class CapacityRetries {
|
|
|
149
163
|
nextAttemptAt: void 0
|
|
150
164
|
};
|
|
151
165
|
this.changed(job.threadId);
|
|
166
|
+
this.logger.info("capacity_retry.dispatching", {
|
|
167
|
+
threadId: job.threadId,
|
|
168
|
+
operationId: job.operationId,
|
|
169
|
+
attempt: job.attempt
|
|
170
|
+
});
|
|
152
171
|
void this.run(job).catch(() => {
|
|
153
172
|
if (this.owns(job)) {
|
|
154
173
|
this.stop(job, "error");
|
|
@@ -164,6 +183,12 @@ class CapacityRetries {
|
|
|
164
183
|
else this.clear(threadId);
|
|
165
184
|
}
|
|
166
185
|
stop(job, reason) {
|
|
186
|
+
this.logger.info("capacity_retry.stopped", {
|
|
187
|
+
threadId: job.threadId,
|
|
188
|
+
operationId: job.operationId,
|
|
189
|
+
attempt: job.attempt,
|
|
190
|
+
reason
|
|
191
|
+
});
|
|
167
192
|
if (job.timer) clearTimeout(job.timer);
|
|
168
193
|
delete job.timer;
|
|
169
194
|
if (job.view) job.view = { ...job.view, status: "stopped", reason, nextAttemptAt: void 0 };
|