@jini-ai/diagnostics 0.1.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 +201 -0
- package/dist/agent-logs.d.ts +56 -0
- package/dist/agent-logs.d.ts.map +1 -0
- package/dist/agent-logs.js +150 -0
- package/dist/agent-logs.js.map +1 -0
- package/dist/contract.d.ts +13 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +13 -0
- package/dist/contract.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/manifest.d.ts +60 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +44 -0
- package/dist/manifest.js.map +1 -0
- package/dist/redaction.d.ts +7 -0
- package/dist/redaction.d.ts.map +1 -0
- package/dist/redaction.js +64 -0
- package/dist/redaction.js.map +1 -0
- package/dist/sources.d.ts +37 -0
- package/dist/sources.d.ts.map +1 -0
- package/dist/sources.js +95 -0
- package/dist/sources.js.map +1 -0
- package/dist/zip.d.ts +17 -0
- package/dist/zip.d.ts.map +1 -0
- package/dist/zip.js +37 -0
- package/dist/zip.js.map +1 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may choose to offer, and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend,
|
|
172
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
173
|
+
or claims asserted against, such Contributor by reason of your
|
|
174
|
+
accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Open Design contributors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { LogSource } from "./sources.js";
|
|
2
|
+
/**
|
|
3
|
+
* Collect the most-recent per-run event logs (`<runsDir>/<runId>/events.jsonl`).
|
|
4
|
+
*
|
|
5
|
+
* These are a host daemon's capture of each agent CLI's own stdout/stderr/stream
|
|
6
|
+
* for a run — the single richest, agent-agnostic diagnostic signal for "the
|
|
7
|
+
* run failed / produced nothing". Shared so both an HTTP export and a desktop
|
|
8
|
+
* IPC export bundle the same data.
|
|
9
|
+
*/
|
|
10
|
+
export declare function buildRunEventLogSources(runsDir: string | null | undefined, options?: {
|
|
11
|
+
maxRuns?: number;
|
|
12
|
+
tailBytes?: number;
|
|
13
|
+
}): Promise<LogSource[]>;
|
|
14
|
+
export interface AgentCliLogOptions {
|
|
15
|
+
/** User home directory; CLI configs/logs live under here. */
|
|
16
|
+
homeDir: string;
|
|
17
|
+
/** Host application data dir; fallback location of an AMR-style OpenCode home. */
|
|
18
|
+
dataDir?: string | null;
|
|
19
|
+
/**
|
|
20
|
+
* Effective AMR-style OpenCode home (the resolved `OPENCODE_TEST_HOME`).
|
|
21
|
+
* Callers should pass the value a real run would use so this honors a
|
|
22
|
+
* user override; when omitted this falls back to the default
|
|
23
|
+
* `<dataDir>/amr/opencode-home`.
|
|
24
|
+
*/
|
|
25
|
+
amrOpenCodeHome?: string | null;
|
|
26
|
+
/**
|
|
27
|
+
* Effective Claude config home (`CLAUDE_CONFIG_DIR`). Honors a user
|
|
28
|
+
* override; falls back to `~/.claude`.
|
|
29
|
+
*/
|
|
30
|
+
claudeConfigDir?: string | null;
|
|
31
|
+
/**
|
|
32
|
+
* Effective Codex home (`CODEX_HOME`). Honors a user override; falls
|
|
33
|
+
* back to `~/.codex`.
|
|
34
|
+
*/
|
|
35
|
+
codexHome?: string | null;
|
|
36
|
+
/** XDG_DATA_HOME, if set, used for OpenCode's data dir resolution. */
|
|
37
|
+
xdgDataHome?: string | null;
|
|
38
|
+
/** Max log files to include per agent (most-recent first). */
|
|
39
|
+
maxFilesPerAgent?: number;
|
|
40
|
+
/** Max bytes to read from each log file's tail. */
|
|
41
|
+
tailBytes?: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Collect the native on-disk logs of the coding-agent CLIs a host application
|
|
45
|
+
* drives: Claude Code, Codex, OpenCode, and an AMR-style OpenCode runtime.
|
|
46
|
+
* These complement the per-run `events.jsonl` capture with the CLI's own
|
|
47
|
+
* internal diagnostics (provider errors, retries, auth state) that never
|
|
48
|
+
* reach the daemon's stream.
|
|
49
|
+
*
|
|
50
|
+
* Deliberately excluded: secret-bearing files. This only sweeps known *log*
|
|
51
|
+
* directories (`*.log` files) — never `~/.amr/config.json`, `~/.codex/auth.json`,
|
|
52
|
+
* or session transcripts — and the collected text still passes through the
|
|
53
|
+
* bundle's redaction pass.
|
|
54
|
+
*/
|
|
55
|
+
export declare function buildAgentCliLogSources(options: AgentCliLogOptions): Promise<LogSource[]>;
|
|
56
|
+
//# sourceMappingURL=agent-logs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-logs.d.ts","sourceRoot":"","sources":["../src/agent-logs.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAsB9C;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAClC,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GACrD,OAAO,CAAC,SAAS,EAAE,CAAC,CA6BtB;AAyBD,MAAM,WAAW,kBAAkB;IACjC,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAC;IAChB,kFAAkF;IAClF,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,sEAAsE;IACtE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,8DAA8D;IAC9D,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mDAAmD;IACnD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,uBAAuB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CA0D/F"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { readdir, stat } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
const DEFAULT_RUN_EVENT_TAIL_BYTES = 2 * 1024 * 1024;
|
|
4
|
+
const DEFAULT_MAX_RUN_EVENT_LOGS = 20;
|
|
5
|
+
// CLI session logs can be large (e.g. Codex's `codex-tui.log` grows into the
|
|
6
|
+
// hundreds of MB because it logs every TUI frame), so keep a generous-but-
|
|
7
|
+
// bounded tail that still captures the final error frame.
|
|
8
|
+
const DEFAULT_AGENT_LOG_TAIL_BYTES = 2 * 1024 * 1024;
|
|
9
|
+
const DEFAULT_MAX_FILES_PER_AGENT = 3;
|
|
10
|
+
const SAFE_DIR_ENTRY = /^[A-Za-z0-9._-]+$/u;
|
|
11
|
+
async function statSafe(path) {
|
|
12
|
+
try {
|
|
13
|
+
const info = await stat(path);
|
|
14
|
+
return { mtimeMs: info.mtimeMs, isFile: info.isFile() };
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Collect the most-recent per-run event logs (`<runsDir>/<runId>/events.jsonl`).
|
|
22
|
+
*
|
|
23
|
+
* These are a host daemon's capture of each agent CLI's own stdout/stderr/stream
|
|
24
|
+
* for a run — the single richest, agent-agnostic diagnostic signal for "the
|
|
25
|
+
* run failed / produced nothing". Shared so both an HTTP export and a desktop
|
|
26
|
+
* IPC export bundle the same data.
|
|
27
|
+
*/
|
|
28
|
+
export async function buildRunEventLogSources(runsDir, options = {}) {
|
|
29
|
+
if (!runsDir)
|
|
30
|
+
return [];
|
|
31
|
+
const maxRuns = options.maxRuns ?? DEFAULT_MAX_RUN_EVENT_LOGS;
|
|
32
|
+
const tailBytes = options.tailBytes ?? DEFAULT_RUN_EVENT_TAIL_BYTES;
|
|
33
|
+
let entries;
|
|
34
|
+
try {
|
|
35
|
+
entries = await readdir(runsDir, { withFileTypes: true });
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
const candidates = [];
|
|
41
|
+
for (const entry of entries) {
|
|
42
|
+
if (!entry.isDirectory())
|
|
43
|
+
continue;
|
|
44
|
+
if (!SAFE_DIR_ENTRY.test(entry.name))
|
|
45
|
+
continue;
|
|
46
|
+
const absolutePath = join(runsDir, entry.name, "events.jsonl");
|
|
47
|
+
const info = await statSafe(absolutePath);
|
|
48
|
+
if (!info || !info.isFile)
|
|
49
|
+
continue;
|
|
50
|
+
candidates.push({ runId: entry.name, absolutePath, mtimeMs: info.mtimeMs });
|
|
51
|
+
}
|
|
52
|
+
candidates.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
53
|
+
return candidates.slice(0, maxRuns).map(({ runId, absolutePath }) => ({
|
|
54
|
+
name: `runs/${runId}/events.jsonl`,
|
|
55
|
+
absolutePath,
|
|
56
|
+
kind: "text",
|
|
57
|
+
tailBytes,
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
async function latestLogFilesIn(dir, max) {
|
|
61
|
+
let names;
|
|
62
|
+
try {
|
|
63
|
+
names = await readdir(dir);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
const candidates = [];
|
|
69
|
+
for (const name of names) {
|
|
70
|
+
if (!name.endsWith(".log"))
|
|
71
|
+
continue;
|
|
72
|
+
if (!SAFE_DIR_ENTRY.test(name))
|
|
73
|
+
continue;
|
|
74
|
+
const absolutePath = join(dir, name);
|
|
75
|
+
const info = await statSafe(absolutePath);
|
|
76
|
+
if (!info || !info.isFile)
|
|
77
|
+
continue;
|
|
78
|
+
candidates.push({ name, absolutePath, mtimeMs: info.mtimeMs });
|
|
79
|
+
}
|
|
80
|
+
candidates.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
81
|
+
return candidates.slice(0, max).map(({ name, absolutePath }) => ({ name, absolutePath }));
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Collect the native on-disk logs of the coding-agent CLIs a host application
|
|
85
|
+
* drives: Claude Code, Codex, OpenCode, and an AMR-style OpenCode runtime.
|
|
86
|
+
* These complement the per-run `events.jsonl` capture with the CLI's own
|
|
87
|
+
* internal diagnostics (provider errors, retries, auth state) that never
|
|
88
|
+
* reach the daemon's stream.
|
|
89
|
+
*
|
|
90
|
+
* Deliberately excluded: secret-bearing files. This only sweeps known *log*
|
|
91
|
+
* directories (`*.log` files) — never `~/.amr/config.json`, `~/.codex/auth.json`,
|
|
92
|
+
* or session transcripts — and the collected text still passes through the
|
|
93
|
+
* bundle's redaction pass.
|
|
94
|
+
*/
|
|
95
|
+
export async function buildAgentCliLogSources(options) {
|
|
96
|
+
const home = options.homeDir?.trim();
|
|
97
|
+
if (!home)
|
|
98
|
+
return [];
|
|
99
|
+
const maxFiles = options.maxFilesPerAgent ?? DEFAULT_MAX_FILES_PER_AGENT;
|
|
100
|
+
const tailBytes = options.tailBytes ?? DEFAULT_AGENT_LOG_TAIL_BYTES;
|
|
101
|
+
const xdg = options.xdgDataHome?.trim();
|
|
102
|
+
const openCodeUserLogDir = xdg
|
|
103
|
+
? join(xdg, "opencode", "log")
|
|
104
|
+
: join(home, ".local", "share", "opencode", "log");
|
|
105
|
+
// Effective CLI homes honor the user's app-config overrides
|
|
106
|
+
// (`CLAUDE_CONFIG_DIR` / `CODEX_HOME`), falling back to the defaults — the
|
|
107
|
+
// same fix as the AMR-style runtime's `OPENCODE_TEST_HOME` so relocated
|
|
108
|
+
// homes are not missed.
|
|
109
|
+
const claudeDir = options.claudeConfigDir?.trim() || join(home, ".claude");
|
|
110
|
+
const codexHome = options.codexHome?.trim() || join(home, ".codex");
|
|
111
|
+
// Per-agent log directories. `*.log` only; secret files (auth.json,
|
|
112
|
+
// config.json) live outside these dirs and are never swept.
|
|
113
|
+
const agentDirs = [
|
|
114
|
+
// Claude Code operational logs (bash-commands / cost-tracker / daemon).
|
|
115
|
+
{ agent: "claude", dir: claudeDir },
|
|
116
|
+
// Codex tracing logs (codex-tui.log can be very large — tail-bounded).
|
|
117
|
+
{ agent: "codex", dir: join(codexHome, "log") },
|
|
118
|
+
// OpenCode session logs (provider errors live here in headless mode).
|
|
119
|
+
{ agent: "opencode", dir: openCodeUserLogDir },
|
|
120
|
+
];
|
|
121
|
+
// An AMR-style runtime drives a private OpenCode under OPENCODE_TEST_HOME;
|
|
122
|
+
// its session logs land under that home's XDG data dir, where provider
|
|
123
|
+
// failures are recorded. Prefer the effective home a real run resolves
|
|
124
|
+
// (honoring a user override) and fall back to the default
|
|
125
|
+
// `<dataDir>/amr/opencode-home` so the bundle does not silently drop the
|
|
126
|
+
// very logs this is meant to surface.
|
|
127
|
+
const amrHome = options.amrOpenCodeHome?.trim();
|
|
128
|
+
const dataDir = options.dataDir?.trim();
|
|
129
|
+
const amrOpenCodeHome = amrHome || (dataDir ? join(dataDir, "amr", "opencode-home") : "");
|
|
130
|
+
if (amrOpenCodeHome) {
|
|
131
|
+
agentDirs.push({
|
|
132
|
+
agent: "amr",
|
|
133
|
+
dir: join(amrOpenCodeHome, ".local", "share", "opencode", "log"),
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
const sources = [];
|
|
137
|
+
for (const { agent, dir } of agentDirs) {
|
|
138
|
+
const files = await latestLogFilesIn(dir, maxFiles);
|
|
139
|
+
for (const file of files) {
|
|
140
|
+
sources.push({
|
|
141
|
+
name: `agent-cli-logs/${agent}/${file.name}`,
|
|
142
|
+
absolutePath: file.absolutePath,
|
|
143
|
+
kind: "text",
|
|
144
|
+
tailBytes,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return sources;
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=agent-logs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-logs.js","sourceRoot":"","sources":["../src/agent-logs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAIjC,MAAM,4BAA4B,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AACrD,MAAM,0BAA0B,GAAG,EAAE,CAAC;AAEtC,6EAA6E;AAC7E,2EAA2E;AAC3E,0DAA0D;AAC1D,MAAM,4BAA4B,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AACrD,MAAM,2BAA2B,GAAG,CAAC,CAAC;AAEtC,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAE5C,KAAK,UAAU,QAAQ,CAAC,IAAY;IAClC,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9B,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;IAC1D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,OAAkC,EAClC,UAAoD,EAAE;IAEtD,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IACxB,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,0BAA0B,CAAC;IAC9D,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,4BAA4B,CAAC;IAEpE,IAAI,OAAO,CAAC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CAAC,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC1F,IAAI,eAAe,EAAE,CAAC;QACpB,SAAS,CAAC,IAAI,CAAC;YACb,KAAK,EAAE,KAAK;YACZ,GAAG,EAAE,IAAI,CAAC,eAAe,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,CAAC;SACjE,CAAC,CAAC;IACL,CAAC;IAED,MAAM,OAAO,GAAgB,EAAE,CAAC;IAChC,KAAK,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,SAAS,EAAE,CAAC;QACvC,MAAM,KAAK,GAAG,MAAM,gBAAgB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QACpD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,OAAO,CAAC,IAAI,CAAC;gBACX,IAAI,EAAE,kBAAkB,KAAK,IAAI,IAAI,CAAC,IAAI,EAAE;gBAC5C,YAAY,EAAE,IAAI,CAAC,YAAY;gBAC/B,IAAI,EAAE,MAAM;gBACZ,SAAS;aACV,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP endpoint a host daemon can expose to stream a diagnostics zip back to
|
|
3
|
+
* the caller. Body is `application/zip`; the response sets a
|
|
4
|
+
* `Content-Disposition` header naming the download.
|
|
5
|
+
*
|
|
6
|
+
* This module is a pure string-constant module with no Node/fs imports, so
|
|
7
|
+
* web/browser code can safely import it to construct the URL or to verify
|
|
8
|
+
* the response content type.
|
|
9
|
+
*/
|
|
10
|
+
export declare const DIAGNOSTICS_EXPORT_PATH = "/api/diagnostics/export";
|
|
11
|
+
export declare const DIAGNOSTICS_FILENAME_PREFIX = "jini-diagnostics";
|
|
12
|
+
export declare const DIAGNOSTICS_CONTENT_TYPE = "application/zip";
|
|
13
|
+
//# sourceMappingURL=contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,eAAO,MAAM,uBAAuB,4BAA4B,CAAC;AAEjE,eAAO,MAAM,2BAA2B,qBAAqB,CAAC;AAE9D,eAAO,MAAM,wBAAwB,oBAAoB,CAAC"}
|
package/dist/contract.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP endpoint a host daemon can expose to stream a diagnostics zip back to
|
|
3
|
+
* the caller. Body is `application/zip`; the response sets a
|
|
4
|
+
* `Content-Disposition` header naming the download.
|
|
5
|
+
*
|
|
6
|
+
* This module is a pure string-constant module with no Node/fs imports, so
|
|
7
|
+
* web/browser code can safely import it to construct the URL or to verify
|
|
8
|
+
* the response content type.
|
|
9
|
+
*/
|
|
10
|
+
export const DIAGNOSTICS_EXPORT_PATH = "/api/diagnostics/export";
|
|
11
|
+
export const DIAGNOSTICS_FILENAME_PREFIX = "jini-diagnostics";
|
|
12
|
+
export const DIAGNOSTICS_CONTENT_TYPE = "application/zip";
|
|
13
|
+
//# sourceMappingURL=contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,yBAAyB,CAAC;AAEjE,MAAM,CAAC,MAAM,2BAA2B,GAAG,kBAAkB,CAAC;AAE9D,MAAM,CAAC,MAAM,wBAAwB,GAAG,iBAAiB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @jini-ai/diagnostics
|
|
3
|
+
*
|
|
4
|
+
* Diagnostics-bundle tooling shared by any host application's HTTP and desktop
|
|
5
|
+
* export surfaces: endpoint constants, JSON/text secret redaction, log-source
|
|
6
|
+
* collection (incl. macOS crash reports and coding-agent CLI logs), a manifest
|
|
7
|
+
* builder, and a zip packager. See `source-map.md` for full provenance and
|
|
8
|
+
* scope-decision notes (this package is NOT yet in extraction-plan.md's
|
|
9
|
+
* locked §3 package set — see that file for details).
|
|
10
|
+
*/
|
|
11
|
+
export { DIAGNOSTICS_CONTENT_TYPE, DIAGNOSTICS_EXPORT_PATH, DIAGNOSTICS_FILENAME_PREFIX, } from "./contract.js";
|
|
12
|
+
export { redactJsonValue, redactJsonText, redactText, type RedactionOptions, } from "./redaction.js";
|
|
13
|
+
export { collectLogSource, collectLogSources, findMacOSCrashReports, type CollectedFile, type CrashReportLookup, type LogSource, type LogSourceKind, } from "./sources.js";
|
|
14
|
+
export { buildManifest, buildMachineInfo, diagnosticsFileName, type DiagnosticsAppInfo, type DiagnosticsContext, type DiagnosticsManifest, type MachineInfo, } from "./manifest.js";
|
|
15
|
+
export { buildDiagnosticsZip, type DiagnosticsExportInput, type DiagnosticsExportResult, } from "./zip.js";
|
|
16
|
+
export { buildRunEventLogSources, buildAgentCliLogSources, type AgentCliLogOptions, } from "./agent-logs.js";
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,2BAA2B,GAC5B,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,eAAe,EACf,cAAc,EACd,UAAU,EACV,KAAK,gBAAgB,GACtB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACd,KAAK,aAAa,GACnB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,WAAW,GACjB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,mBAAmB,EACnB,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,GAC7B,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,uBAAuB,EACvB,uBAAuB,EACvB,KAAK,kBAAkB,GACxB,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @jini-ai/diagnostics
|
|
3
|
+
*
|
|
4
|
+
* Diagnostics-bundle tooling shared by any host application's HTTP and desktop
|
|
5
|
+
* export surfaces: endpoint constants, JSON/text secret redaction, log-source
|
|
6
|
+
* collection (incl. macOS crash reports and coding-agent CLI logs), a manifest
|
|
7
|
+
* builder, and a zip packager. See `source-map.md` for full provenance and
|
|
8
|
+
* scope-decision notes (this package is NOT yet in extraction-plan.md's
|
|
9
|
+
* locked §3 package set — see that file for details).
|
|
10
|
+
*/
|
|
11
|
+
export { DIAGNOSTICS_CONTENT_TYPE, DIAGNOSTICS_EXPORT_PATH, DIAGNOSTICS_FILENAME_PREFIX, } from "./contract.js";
|
|
12
|
+
export { redactJsonValue, redactJsonText, redactText, } from "./redaction.js";
|
|
13
|
+
export { collectLogSource, collectLogSources, findMacOSCrashReports, } from "./sources.js";
|
|
14
|
+
export { buildManifest, buildMachineInfo, diagnosticsFileName, } from "./manifest.js";
|
|
15
|
+
export { buildDiagnosticsZip, } from "./zip.js";
|
|
16
|
+
export { buildRunEventLogSources, buildAgentCliLogSources, } from "./agent-logs.js";
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,2BAA2B,GAC5B,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,eAAe,EACf,cAAc,EACd,UAAU,GAEX,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,GAKtB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,mBAAmB,GAKpB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,mBAAmB,GAGpB,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,uBAAuB,EACvB,uBAAuB,GAExB,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { CollectedFile } from "./sources.js";
|
|
2
|
+
export interface DiagnosticsAppInfo {
|
|
3
|
+
name: string;
|
|
4
|
+
version?: string | undefined;
|
|
5
|
+
channel?: string | undefined;
|
|
6
|
+
packaged?: boolean | undefined;
|
|
7
|
+
}
|
|
8
|
+
export interface DiagnosticsContext {
|
|
9
|
+
app: DiagnosticsAppInfo;
|
|
10
|
+
/** Identifies which surface triggered the export ("daemon-http", "desktop-ipc"). */
|
|
11
|
+
source: string;
|
|
12
|
+
/** Active runtime namespace, when known. */
|
|
13
|
+
namespace?: string | undefined;
|
|
14
|
+
/** Daemon URL or other endpoint that the UI was connected to. */
|
|
15
|
+
endpoint?: string | undefined;
|
|
16
|
+
/** Whether the host process could reach the daemon when triggering. */
|
|
17
|
+
daemonReachable?: boolean | undefined;
|
|
18
|
+
/** Free-form flags or notes. Will be JSON-stringified into the manifest. */
|
|
19
|
+
extra?: Record<string, unknown> | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Upstream warnings to merge into the manifest's `warnings` array.
|
|
22
|
+
* Useful when the host knows a category of data is unavailable (e.g.
|
|
23
|
+
* file logs in non-sidecar launches) and wants to surface that fact
|
|
24
|
+
* without producing fake "missing file" entries.
|
|
25
|
+
*/
|
|
26
|
+
warnings?: string[] | undefined;
|
|
27
|
+
}
|
|
28
|
+
export interface DiagnosticsManifest {
|
|
29
|
+
exportedAt: string;
|
|
30
|
+
app: DiagnosticsAppInfo;
|
|
31
|
+
source: string;
|
|
32
|
+
namespace?: string | undefined;
|
|
33
|
+
endpoint?: string | undefined;
|
|
34
|
+
daemonReachable?: boolean | undefined;
|
|
35
|
+
files: {
|
|
36
|
+
name: string;
|
|
37
|
+
absolutePath: string;
|
|
38
|
+
bytes: number;
|
|
39
|
+
error?: string | undefined;
|
|
40
|
+
}[];
|
|
41
|
+
warnings: string[];
|
|
42
|
+
extra?: Record<string, unknown> | undefined;
|
|
43
|
+
}
|
|
44
|
+
export interface MachineInfo {
|
|
45
|
+
hostname: string;
|
|
46
|
+
platform: string;
|
|
47
|
+
release: string;
|
|
48
|
+
arch: string;
|
|
49
|
+
type: string;
|
|
50
|
+
totalMemoryBytes: number;
|
|
51
|
+
nodeVersion: string;
|
|
52
|
+
pid: number;
|
|
53
|
+
ppid: number;
|
|
54
|
+
cwd: string;
|
|
55
|
+
username?: string | undefined;
|
|
56
|
+
}
|
|
57
|
+
export declare function buildManifest(context: DiagnosticsContext, files: CollectedFile[]): DiagnosticsManifest;
|
|
58
|
+
export declare function buildMachineInfo(username: string | undefined): MachineInfo;
|
|
59
|
+
export declare function diagnosticsFileName(prefix: string, now?: Date): string;
|
|
60
|
+
//# sourceMappingURL=manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC;AA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zB,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/B;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,kBAAkB,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,mBAAmB,CAqBtG;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,WAAW,CAc1E;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,GAAE,IAAiB,GAAG,MAAM,CAGlF"}
|
package/dist/manifest.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { arch, hostname, platform, release, totalmem, type } from "node:os";
|
|
2
|
+
export function buildManifest(context, files) {
|
|
3
|
+
const warnings = [...(context.warnings ?? [])];
|
|
4
|
+
for (const file of files) {
|
|
5
|
+
if (file.error)
|
|
6
|
+
warnings.push(`${file.name}: ${file.error}`);
|
|
7
|
+
}
|
|
8
|
+
return {
|
|
9
|
+
exportedAt: new Date().toISOString(),
|
|
10
|
+
app: context.app,
|
|
11
|
+
source: context.source,
|
|
12
|
+
namespace: context.namespace,
|
|
13
|
+
endpoint: context.endpoint,
|
|
14
|
+
daemonReachable: context.daemonReachable,
|
|
15
|
+
files: files.map((file) => ({
|
|
16
|
+
name: file.name,
|
|
17
|
+
absolutePath: file.absolutePath,
|
|
18
|
+
bytes: file.bytes,
|
|
19
|
+
error: file.error,
|
|
20
|
+
})),
|
|
21
|
+
warnings,
|
|
22
|
+
extra: context.extra,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function buildMachineInfo(username) {
|
|
26
|
+
return {
|
|
27
|
+
hostname: hostname(),
|
|
28
|
+
platform: platform(),
|
|
29
|
+
release: release(),
|
|
30
|
+
arch: arch(),
|
|
31
|
+
type: type(),
|
|
32
|
+
totalMemoryBytes: totalmem(),
|
|
33
|
+
nodeVersion: process.version,
|
|
34
|
+
pid: process.pid,
|
|
35
|
+
ppid: process.ppid,
|
|
36
|
+
cwd: process.cwd(),
|
|
37
|
+
username,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export function diagnosticsFileName(prefix, now = new Date()) {
|
|
41
|
+
const iso = now.toISOString().replace(/[:.]/g, "-").replace(/-\d{3}Z$/, "Z");
|
|
42
|
+
return `${prefix}-${iso}.zip`;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.js","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AA+D5E,MAAM,UAAU,aAAa,CAAC,OAA2B,EAAE,KAAsB;IAC/E,MAAM,QAAQ,GAAa,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,CAAC;IACzD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,IAAI,CAAC,KAAK;YAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO;QACL,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACpC,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,eAAe,EAAE,OAAO,CAAC,eAAe;QACxC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAC1B,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,KAAK,EAAE,IAAI,CAAC,KAAK;SAClB,CAAC,CAAC;QACH,QAAQ;QACR,KAAK,EAAE,OAAO,CAAC,KAAK;KACrB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,QAA4B;IAC3D,OAAO;QACL,QAAQ,EAAE,QAAQ,EAAE;QACpB,QAAQ,EAAE,QAAQ,EAAE;QACpB,OAAO,EAAE,OAAO,EAAE;QAClB,IAAI,EAAE,IAAI,EAAE;QACZ,IAAI,EAAE,IAAI,EAAE;QACZ,gBAAgB,EAAE,QAAQ,EAAE;QAC5B,WAAW,EAAE,OAAO,CAAC,OAAO;QAC5B,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;QAClB,QAAQ;KACT,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,MAAc,EAAE,MAAY,IAAI,IAAI,EAAE;IACxE,MAAM,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;IAC7E,OAAO,GAAG,MAAM,IAAI,GAAG,MAAM,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface RedactionOptions {
|
|
2
|
+
username?: string | undefined;
|
|
3
|
+
}
|
|
4
|
+
export declare function redactJsonValue(value: unknown, opts?: RedactionOptions): unknown;
|
|
5
|
+
export declare function redactText(text: string, opts?: RedactionOptions): string;
|
|
6
|
+
export declare function redactJsonText(text: string, opts?: RedactionOptions): string;
|
|
7
|
+
//# sourceMappingURL=redaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redaction.d.ts","sourceRoot":"","sources":["../src/redaction.ts"],"names":[],"mappings":"AAuBA,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/B;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,GAAE,gBAAqB,GAAG,OAAO,CAepF;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,gBAAqB,GAAG,MAAM,CAe5E;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,gBAAqB,GAAG,MAAM,CAQhF"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const SENSITIVE_KEY_RE = /token|password|secret|key|dsn|authorization|cookie/i;
|
|
2
|
+
const URL_QUERY_SECRET_RE = /([?&#])(token|password|secret|key|dsn|api[_-]?key|auth|access_token|refresh_token|id_token)(=)([^&\s#"']*)/gi;
|
|
3
|
+
// Catch loose key=value pairs in log lines that aren't inside a URL — e.g. env
|
|
4
|
+
// dumps, command-line args, or json-line meta. The leading boundary stops it
|
|
5
|
+
// from matching mid-identifier (e.g. `not_a_token`). Order alternatives long-
|
|
6
|
+
// first so `access_token` wins over `token`.
|
|
7
|
+
const BARE_SECRET_RE = /(^|[\s,;])(access_token|refresh_token|id_token|api[_-]?key|password|secret|token|auth(?:orization)?)(=|:\s*)([^\s,;"']+)/gi;
|
|
8
|
+
// Bearer / Token / Basic auth schemes embed the secret after the scheme
|
|
9
|
+
// keyword, so the BARE pattern above stops at the space before `Bearer` and
|
|
10
|
+
// leaves the actual credential exposed. This pattern matches the scheme +
|
|
11
|
+
// credential as one unit. Case-insensitive: HTTP auth schemes are
|
|
12
|
+
// case-insensitive per RFC 7235 §2.1, and we routinely see lowercase
|
|
13
|
+
// `authorization: bearer …` in proxy / curl-style logs.
|
|
14
|
+
// Character class covers RFC 6750 token68 (ALPHA / DIGIT / "-" / "." / "_"
|
|
15
|
+
// / "~" / "+" / "/" / "=") plus ":" for Basic credentials. Missing "~"
|
|
16
|
+
// previously left tokens like `Bearer abcd~efgh` partially exposed.
|
|
17
|
+
const HTTP_AUTH_SCHEME_RE = /\b(Bearer|Token|Basic)\s+([A-Za-z0-9._~\-+/=:]{4,})/gi;
|
|
18
|
+
const REDACTED = "[REDACTED]";
|
|
19
|
+
export function redactJsonValue(value, opts = {}) {
|
|
20
|
+
if (Array.isArray(value))
|
|
21
|
+
return value.map((entry) => redactJsonValue(entry, opts));
|
|
22
|
+
if (value !== null && typeof value === "object") {
|
|
23
|
+
const out = {};
|
|
24
|
+
for (const [key, raw] of Object.entries(value)) {
|
|
25
|
+
if (SENSITIVE_KEY_RE.test(key) && typeof raw === "string" && raw.length > 0) {
|
|
26
|
+
out[key] = REDACTED;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
out[key] = redactJsonValue(raw, opts);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
if (typeof value === "string")
|
|
35
|
+
return redactText(value, opts);
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
export function redactText(text, opts = {}) {
|
|
39
|
+
// Run the HTTP auth scheme replacement first so the credential after
|
|
40
|
+
// `Bearer` / `Token` / `Basic` is captured before BARE_SECRET_RE swallows
|
|
41
|
+
// the `Authorization: Bearer` prefix and stops at the space.
|
|
42
|
+
let out = text.replace(HTTP_AUTH_SCHEME_RE, (_match, scheme) => `${scheme} ${REDACTED}`);
|
|
43
|
+
out = out.replace(URL_QUERY_SECRET_RE, (_match, sep, name, eq) => `${sep}${name}${eq}${REDACTED}`);
|
|
44
|
+
out = out.replace(BARE_SECRET_RE, (_match, lead, name, sep) => `${lead}${name}${sep}${REDACTED}`);
|
|
45
|
+
const username = opts.username;
|
|
46
|
+
if (username && username.length > 1) {
|
|
47
|
+
const escaped = username.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
48
|
+
out = out.replace(new RegExp(`/Users/${escaped}(?=[/"\\s])`, "g"), "/Users/<USER>");
|
|
49
|
+
out = out.replace(new RegExp(`\\\\Users\\\\${escaped}(?=[\\\\"\\s])`, "g"), "\\Users\\<USER>");
|
|
50
|
+
out = out.replace(new RegExp(`/home/${escaped}(?=[/"\\s])`, "g"), "/home/<USER>");
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
export function redactJsonText(text, opts = {}) {
|
|
55
|
+
let parsed;
|
|
56
|
+
try {
|
|
57
|
+
parsed = JSON.parse(text);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return redactText(text, opts);
|
|
61
|
+
}
|
|
62
|
+
return JSON.stringify(redactJsonValue(parsed, opts), null, 2);
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=redaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redaction.js","sourceRoot":"","sources":["../src/redaction.ts"],"names":[],"mappings":"AAAA,MAAM,gBAAgB,GAAG,qDAAqD,CAAC;AAE/E,MAAM,mBAAmB,GAAG,8GAA8G,CAAC;AAE3I,+EAA+E;AAC/E,6EAA6E;AAC7E,8EAA8E;AAC9E,6CAA6C;AAC7C,MAAM,cAAc,GAAG,4HAA4H,CAAC;AAEpJ,wEAAwE;AACxE,4EAA4E;AAC5E,0EAA0E;AAC1E,kEAAkE;AAClE,qEAAqE;AACrE,wDAAwD;AACxD,2EAA2E;AAC3E,uEAAuE;AACvE,oEAAoE;AACpE,MAAM,mBAAmB,GAAG,uDAAuD,CAAC;AAEpF,MAAM,QAAQ,GAAG,YAAY,CAAC;AAM9B,MAAM,UAAU,eAAe,CAAC,KAAc,EAAE,OAAyB,EAAE;IACzE,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,eAA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|
|
4
|
+
/** Relative path inside the export zip (forward-slash). */
|
|
5
|
+
name: string;
|
|
6
|
+
/** Absolute path on disk to read from. */
|
|
7
|
+
absolutePath: string;
|
|
8
|
+
/** Whether the file should be parsed/redacted as JSON or plain text. */
|
|
9
|
+
kind: LogSourceKind;
|
|
10
|
+
/** Optional max bytes to read from the file tail; omit for whole file. */
|
|
11
|
+
tailBytes?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface CollectedFile {
|
|
14
|
+
name: string;
|
|
15
|
+
absolutePath: string;
|
|
16
|
+
/** Redacted contents to put into the zip. Null when the file could not be read. */
|
|
17
|
+
content: string | null;
|
|
18
|
+
bytes: number;
|
|
19
|
+
/** Reason the file is missing or unreadable. */
|
|
20
|
+
error?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function collectLogSource(source: LogSource, opts?: RedactionOptions): Promise<CollectedFile>;
|
|
23
|
+
export declare function collectLogSources(sources: LogSource[], opts?: RedactionOptions): Promise<CollectedFile[]>;
|
|
24
|
+
export interface CrashReportLookup {
|
|
25
|
+
/** Filenames must contain at least one of these substrings (case-insensitive). */
|
|
26
|
+
matchSubstrings: string[];
|
|
27
|
+
/** Only include files modified within this many days. */
|
|
28
|
+
withinDays?: number;
|
|
29
|
+
/** Limit how many reports to include. */
|
|
30
|
+
maxReports?: number;
|
|
31
|
+
/** Override base directories to scan. */
|
|
32
|
+
searchDirs?: string[];
|
|
33
|
+
/** Home directory to derive ~/Library/Logs/DiagnosticReports from. */
|
|
34
|
+
homeDir?: string;
|
|
35
|
+
}
|
|
36
|
+
export declare function findMacOSCrashReports(lookup: CrashReportLookup): Promise<LogSource[]>;
|
|
37
|
+
//# sourceMappingURL=sources.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sources.d.ts","sourceRoot":"","sources":["../src/sources.ts"],"names":[],"mappings":"AAGA,OAAO,EAA8B,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEnF,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,CAAC;AAE5C,MAAM,WAAW,SAAS;IACxB,2DAA2D;IAC3D,IAAI,EAAE,MAAM,CAAC;IACb,0CAA0C;IAC1C,YAAY,EAAE,MAAM,CAAC;IACrB,wEAAwE;IACxE,IAAI,EAAE,aAAa,CAAC;IACpB,0EAA0E;IAC1E,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,mFAAmF;IACnF,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,gDAAgD;IAChD,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AA0BD,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,GAAE,gBAAqB,GAAG,OAAO,CAAC,aAAa,CAAC,CAc7G;AAED,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,SAAS,EAAE,EAAE,IAAI,GAAE,gBAAqB,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAEnH;AAMD,MAAM,WAAW,iBAAiB;IAChC,kFAAkF;IAClF,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,yDAAyD;IACzD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yCAAyC;IACzC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yCAAyC;IACzC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,sEAAsE;IACtE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAwC3F"}
|
package/dist/sources.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { open, readFile, readdir, stat } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { redactJsonText, redactText } from "./redaction.js";
|
|
4
|
+
async function readMaybeTail(absolutePath, tailBytes) {
|
|
5
|
+
if (tailBytes == null || tailBytes <= 0) {
|
|
6
|
+
const buf = await readFile(absolutePath);
|
|
7
|
+
return { text: buf.toString("utf8"), bytes: buf.byteLength };
|
|
8
|
+
}
|
|
9
|
+
const info = await stat(absolutePath);
|
|
10
|
+
if (info.size <= tailBytes) {
|
|
11
|
+
const buf = await readFile(absolutePath);
|
|
12
|
+
return { text: buf.toString("utf8"), bytes: buf.byteLength };
|
|
13
|
+
}
|
|
14
|
+
// For large files we do NOT want to load the whole thing into memory just
|
|
15
|
+
// to slice off the tail — open the fd and read the trailing window
|
|
16
|
+
// directly. Long-running daemon logs can be multi-GB.
|
|
17
|
+
const fd = await open(absolutePath, "r");
|
|
18
|
+
try {
|
|
19
|
+
const start = info.size - tailBytes;
|
|
20
|
+
const buffer = Buffer.alloc(tailBytes);
|
|
21
|
+
const { bytesRead } = await fd.read(buffer, 0, tailBytes, start);
|
|
22
|
+
return { text: buffer.subarray(0, bytesRead).toString("utf8"), bytes: bytesRead };
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
await fd.close();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export async function collectLogSource(source, opts = {}) {
|
|
29
|
+
try {
|
|
30
|
+
const { text, bytes } = await readMaybeTail(source.absolutePath, source.tailBytes);
|
|
31
|
+
const redacted = source.kind === "json" ? redactJsonText(text, opts) : redactText(text, opts);
|
|
32
|
+
return { name: source.name, absolutePath: source.absolutePath, content: redacted, bytes };
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
return {
|
|
36
|
+
name: source.name,
|
|
37
|
+
absolutePath: source.absolutePath,
|
|
38
|
+
content: null,
|
|
39
|
+
bytes: 0,
|
|
40
|
+
error: error instanceof Error ? error.message : String(error),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export async function collectLogSources(sources, opts = {}) {
|
|
45
|
+
return await Promise.all(sources.map((source) => collectLogSource(source, opts)));
|
|
46
|
+
}
|
|
47
|
+
const DEFAULT_CRASH_DIRS_DARWIN = [
|
|
48
|
+
"/Library/Logs/DiagnosticReports",
|
|
49
|
+
];
|
|
50
|
+
export async function findMacOSCrashReports(lookup) {
|
|
51
|
+
if (process.platform !== "darwin")
|
|
52
|
+
return [];
|
|
53
|
+
const within = (lookup.withinDays ?? 7) * 24 * 60 * 60 * 1000;
|
|
54
|
+
const cutoff = Date.now() - within;
|
|
55
|
+
const max = lookup.maxReports ?? 20;
|
|
56
|
+
const dirs = lookup.searchDirs ?? [
|
|
57
|
+
...(lookup.homeDir ? [join(lookup.homeDir, "Library/Logs/DiagnosticReports")] : []),
|
|
58
|
+
...DEFAULT_CRASH_DIRS_DARWIN,
|
|
59
|
+
];
|
|
60
|
+
const matches = lookup.matchSubstrings.map((entry) => entry.toLowerCase());
|
|
61
|
+
const found = [];
|
|
62
|
+
for (const dir of dirs) {
|
|
63
|
+
let entries;
|
|
64
|
+
try {
|
|
65
|
+
entries = await readdir(dir);
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
for (const entry of entries) {
|
|
71
|
+
const lower = entry.toLowerCase();
|
|
72
|
+
if (!matches.some((needle) => lower.includes(needle)))
|
|
73
|
+
continue;
|
|
74
|
+
const absolutePath = join(dir, entry);
|
|
75
|
+
try {
|
|
76
|
+
const info = await stat(absolutePath);
|
|
77
|
+
if (!info.isFile())
|
|
78
|
+
continue;
|
|
79
|
+
if (info.mtimeMs < cutoff)
|
|
80
|
+
continue;
|
|
81
|
+
found.push({ absolutePath, mtimeMs: info.mtimeMs, name: entry });
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
found.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
89
|
+
return found.slice(0, max).map(({ absolutePath, name }) => ({
|
|
90
|
+
name: `crash-reports/${name}`,
|
|
91
|
+
absolutePath,
|
|
92
|
+
kind: "text",
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=sources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sources.js","sourceRoot":"","sources":["../src/sources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,cAAc,EAAE,UAAU,EAAyB,MAAM,gBAAgB,CAAC;AAyBnF,KAAK,UAAU,aAAa,CAAC,YAAoB,EAAE,SAA6B;IAC9E,IAAI,SAAS,IAAI,IAAI,IAAI,SAAS,IAAI,CAAC,EAAE,CAAC;QACxC,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,YAAY,CAAC,CAAC;QACzC,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,UAAU,EAAE,CAAC;IAC/D,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,CAAC;IACtC,IAAI,IAAI,CAAC,IAAI,IAAI,SAAS,EAAE,CAAC;QAC3B,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,YAAY,CAAC,CAAC;QACzC,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,UAAU,EAAE,CAAC;IAC/D,CAAC;IACD,0EAA0E;IAC1E,mEAAmE;IACnE,sDAAsD;IACtD,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC;IACzC,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,IAAI,CAAC,I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Context, type DiagnosticsManifest, type MachineInfo } from "./manifest.js";
|
|
3
|
+
import { type CrashReportLookup, type LogSource } from "./sources.js";
|
|
4
|
+
export interface DiagnosticsExportInput {
|
|
5
|
+
context: DiagnosticsContext;
|
|
6
|
+
sources: LogSource[];
|
|
7
|
+
redaction?: RedactionOptions;
|
|
8
|
+
/** When provided, scan macOS crash reports matching these substrings. */
|
|
9
|
+
crashReports?: CrashReportLookup;
|
|
10
|
+
}
|
|
11
|
+
export interface DiagnosticsExportResult {
|
|
12
|
+
zip: Buffer;
|
|
13
|
+
manifest: DiagnosticsManifest;
|
|
14
|
+
machineInfo: MachineInfo;
|
|
15
|
+
}
|
|
16
|
+
export declare function buildDiagnosticsZip(input: DiagnosticsExportInput): Promise<DiagnosticsExportResult>;
|
|
17
|
+
//# sourceMappingURL=zip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zip.d.ts","sourceRoot":"","sources":["../src/zip.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAmC,KAAK,kBAAkB,EAAE,KAAK,mBAAmB,EAAE,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AACrI,OAAO,EAAgE,KAAK,iBAAiB,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAIpI,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,kBAAkB,CAAC;IAC5B,OAAO,EAAE,SAAS,EAAE,CAAC;IACrB,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,yEAAyE;IACzE,YAAY,CAAC,EAAE,iBAAiB,CAAC;CAClC;AAED,MAAM,WAAW,uBAAuB;IACtC,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,WAAW,EAAE,WAAW,CAAC;CAC1B;AAWD,wBAAsB,mBAAmB,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CA2BzG"}
|
package/dist/zip.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import JSZip from "jszip";
|
|
2
|
+
import { redactJsonValue } from "./redaction.js";
|
|
3
|
+
import { buildManifest, buildMachineInfo } from "./manifest.js";
|
|
4
|
+
import { collectLogSources, findMacOSCrashReports } from "./sources.js";
|
|
5
|
+
const PLACEHOLDER_PREFIX = "; file unavailable: ";
|
|
6
|
+
function placeholderForMissing(file) {
|
|
7
|
+
// `collected` here always comes from this module's own collectLogSources()
|
|
8
|
+
// call, whose sole null-content producer (collectLogSource's catch clause)
|
|
9
|
+
// always sets `error` to a string — there's no runtime path in this file
|
|
10
|
+
// that reaches here with `file.error` undefined, so no "unknown error"
|
|
11
|
+
// fallback is needed.
|
|
12
|
+
return `${PLACEHOLDER_PREFIX}${file.error}\n`;
|
|
13
|
+
}
|
|
14
|
+
export async function buildDiagnosticsZip(input) {
|
|
15
|
+
const redaction = input.redaction ?? {};
|
|
16
|
+
const sources = [...input.sources];
|
|
17
|
+
if (input.crashReports != null) {
|
|
18
|
+
const crashes = await findMacOSCrashReports(input.crashReports);
|
|
19
|
+
sources.push(...crashes);
|
|
20
|
+
}
|
|
21
|
+
const collected = await collectLogSources(sources, redaction);
|
|
22
|
+
const manifest = buildManifest(input.context, collected);
|
|
23
|
+
const machineInfo = buildMachineInfo(redaction.username);
|
|
24
|
+
const zip = new JSZip();
|
|
25
|
+
for (const file of collected) {
|
|
26
|
+
zip.file(file.name, file.content ?? placeholderForMissing(file));
|
|
27
|
+
}
|
|
28
|
+
zip.file("summary/manifest.json", JSON.stringify(redactJsonValue(manifest, redaction), null, 2));
|
|
29
|
+
zip.file("summary/machine-info.json", JSON.stringify(redactJsonValue(machineInfo, redaction), null, 2));
|
|
30
|
+
const buffer = await zip.generateAsync({
|
|
31
|
+
type: "nodebuffer",
|
|
32
|
+
compression: "DEFLATE",
|
|
33
|
+
compressionOptions: { level: 6 },
|
|
34
|
+
});
|
|
35
|
+
return { zip: buffer, manifest, machineInfo };
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=zip.js.map
|
package/dist/zip.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zip.js","sourceRoot":"","sources":["../src/zip.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,eAAe,EAAyB,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAuE,MAAM,eAAe,CAAC;AACrI,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAA8D,MAAM,cAAc,CAAC;AAEpI,MAAM,kBAAkB,GAAG,sBAAsB,CAAC;AAgBlD,SAAS,qBAAqB,CAAC,IAAmB;IAChD,2EAA2E;IAC3E,2EAA2E;IAC3E,yEAAyE;IACzE,uEAAuE;IACvE,sBAAsB;IACtB,OAAO,GAAG,kBAAkB,GAAG,IAAI,CAAC,KAAK,IAAI,CAAC;AAChD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,KAA6B;IACrE,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,IAAI,EAAE,CAAC;IACxC,MAAM,OAAO,GAAG,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;IAEnC,IAAI,KAAK,CAAC,YAAY,IAAI,IAAI,EAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,MAAM,qBAAqB,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QAChE,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,iBAAiB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAC9D,MAAM,QAAQ,GAAG,aAAa,CAAC,KAAK,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACzD,MAAM,WAAW,GAAG,gBAAgB,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAEzD,MAAM,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC;IACxB,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;QAC7B,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,IAAI,qBAAqB,CAAC,IAAI,CAAC,CAAC,CAAC;IACnE,CAAC;IACD,GAAG,CAAC,IAAI,CAAC,uBAAuB,EAAE,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,QAAQ,EAAE,SAAS,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IACjG,GAAG,CAAC,IAAI,CAAC,2BAA2B,EAAE,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,WAAW,EAAE,SAAS,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAExG,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,aAAa,CAAC;QACrC,IAAI,EAAE,YAAY;QAClB,WAAW,EAAE,SAAS;QACtB,kBAAkB,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE;KACjC,CAAC,CAAC;IAEH,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;AAChD,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jini-ai/diagnostics",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/AINSEP/Jini.git",
|
|
8
|
+
"directory": "packages/diagnostics"
|
|
9
|
+
},
|
|
10
|
+
"jini": {
|
|
11
|
+
"domain": "tooling",
|
|
12
|
+
"kind": "diagnostics",
|
|
13
|
+
"runtime": "node",
|
|
14
|
+
"admission": "incubating"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"!dist/**/*.test.js",
|
|
26
|
+
"!dist/**/*.test.d.ts",
|
|
27
|
+
"!dist/**/*.test.js.map",
|
|
28
|
+
"!dist/**/*.test.d.ts.map",
|
|
29
|
+
"!dist/**/__tests__/**"
|
|
30
|
+
],
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public",
|
|
33
|
+
"registry": "https://registry.npmjs.org"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"jszip": "^3.10.1"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@vitest/coverage-v8": "^2.1.9"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsc -p tsconfig.json",
|
|
43
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"test:coverage": "vitest run --coverage"
|
|
46
|
+
}
|
|
47
|
+
}
|