@cortexkit/opencode-openai-auth 0.11.1 → 1.0.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/README.md +15 -26
- package/dist/index-766sfrh5.js +1 -0
- package/dist/index-8kj7sa1p.js +12 -0
- package/dist/index-8rqfbhfw.js +221 -0
- package/dist/index-b3q3j39x.js +2 -0
- package/dist/index-bmd7x5aq.js +2 -0
- package/dist/index-eqh53k8v.js +2 -0
- package/dist/{index-sdt2d2ra.js → index-hy9030jh.js} +1 -1
- package/dist/index-jyr8y8k4.js +7 -0
- package/dist/index-rv08jmd4.js +2 -0
- package/dist/index.d.ts +578 -145
- package/dist/index.js +1 -110
- package/dist/pool-lifecycle-DbDmgabd.d.ts +2430 -0
- package/dist/port-file-Do3lQIEk.d.ts +29 -0
- package/dist/protocol-BOBdkqqm.d.ts +198 -0
- package/dist/rpc/port-file.d.ts +4 -17
- package/dist/rpc/port-file.js +1 -1
- package/dist/rpc/protocol.d.ts +2 -2
- package/dist/rpc/protocol.js +1 -0
- package/dist/rpc/rpc-client.d.ts +5 -4
- package/dist/rpc/rpc-client.js +1 -1
- package/dist/rpc/rpc-dir.d.ts +2 -0
- package/dist/rpc/rpc-dir.js +1 -1
- package/dist/sidebar-state-D6cUKgkm.d.ts +385 -0
- package/dist/sidebar-state.d.ts +2 -2
- package/dist/sidebar-state.js +1 -1
- package/dist/token-util-wdza526f.js +1 -0
- package/dist/{token-9823y0pc.js → token-ypk61xj0.js} +1 -1
- package/dist/tui-preferences.js +5 -2
- package/dist/tui.d.ts +9 -4
- package/dist/v2/server.d.ts +54 -0
- package/dist/v2/server.js +4 -0
- package/package.json +21 -9
- package/src/tui/entry.mjs +26 -25
- package/src/tui-compiled/raw/logger.js +24 -0
- package/src/tui-compiled/raw/rpc/protocol.js +3 -0
- package/src/tui-compiled/raw/rpc/rpc-client.js +7 -0
- package/src/tui-compiled/raw/rpc/rpc-dir.js +27 -0
- package/src/tui-compiled/raw/selector.js +21 -0
- package/src/tui-compiled/raw/shared/0332701351b3eeec-format.js +138 -0
- package/src/tui-compiled/raw/shared/04a6357627de5ed0-errors.js +38 -0
- package/src/tui-compiled/raw/shared/053cc17b5419261e-codec.js +12 -0
- package/src/tui-compiled/raw/shared/0766d78c6f481f18-watcher.js +157 -0
- package/src/tui-compiled/raw/shared/08eef45626a94992-reserved.js +13 -0
- package/src/tui-compiled/raw/shared/39c3cb05738fcf6d-projection.js +134 -0
- package/src/tui-compiled/raw/shared/3c2d4169d00f907e-tui-support.js +5 -0
- package/src/tui-compiled/raw/shared/3e7d45a77c6ad4d5-index.js +4 -0
- package/src/tui-compiled/raw/shared/415792e85d80819e-capture-sink.js +13 -0
- package/src/tui-compiled/raw/shared/42ae93ab554fcec2-open-url.js +28 -0
- package/src/tui-compiled/raw/shared/43fc9e6b994519c7-refresh-lock.js +136 -0
- package/src/tui-compiled/raw/shared/458b934e92490331-mutate.js +500 -0
- package/src/tui-compiled/raw/shared/45bf5343bbbf9add-admission.js +142 -0
- package/src/tui-compiled/raw/shared/46f3dff1266160e8-client.js +2 -0
- package/src/tui-compiled/raw/shared/4825e03209d6ae3e-with-lock.js +48 -0
- package/src/tui-compiled/raw/shared/4f36d333d081d040-merge.js +162 -0
- package/src/tui-compiled/raw/shared/54eba94fd64c8c3c-index.js +7 -0
- package/src/tui-compiled/raw/shared/7211cfec06a298bc-atomic-write.js +80 -0
- package/src/tui-compiled/raw/shared/754d6017f8e419cf-builtins.js +534 -0
- package/src/tui-compiled/raw/shared/75bd8c3bd63b315f-identity.js +79 -0
- package/src/tui-compiled/raw/shared/7a91bb630e6f4804-index.js +1 -0
- package/src/tui-compiled/raw/shared/826342a4b6a8b89b-model.js +16 -0
- package/src/tui-compiled/raw/shared/83068c0dbe8a6f13-publication.js +304 -0
- package/src/tui-compiled/raw/shared/836fc615de6afbd9-settings.js +120 -0
- package/src/tui-compiled/raw/shared/83bc3ba9d0fe2761-runtime.js +68 -0
- package/src/tui-compiled/raw/shared/8a18abe4fa2977c8-menu.js +300 -0
- package/src/tui-compiled/raw/shared/901e149c5a0dbbff-sticky.js +339 -0
- package/src/tui-compiled/raw/shared/9020c407ce64f672-ordered.js +58 -0
- package/src/tui-compiled/raw/shared/905bffc0220f43d0-map.js +105 -0
- package/src/tui-compiled/raw/shared/94820e324f2b4c09-seam.js +301 -0
- package/src/tui-compiled/raw/shared/97484d9bb98c705b-provider-state.js +226 -0
- package/src/tui-compiled/raw/shared/9968e3cade6969a1-index.js +2 -0
- package/src/tui-compiled/raw/shared/9b4da614c45f9cd0-lock-constants.js +14 -0
- package/src/tui-compiled/raw/shared/9d3fc9e37456504e-refresh.js +225 -0
- package/src/tui-compiled/raw/shared/9deae3c4da4fd63b-hooks.js +34 -0
- package/src/tui-compiled/raw/shared/a09b6a533c11858f-tui-preferences.js +77 -0
- package/src/tui-compiled/raw/shared/a62a27a204266acd-attribution.js +60 -0
- package/src/tui-compiled/raw/shared/a910277ac43a8626-pull.js +143 -0
- package/src/tui-compiled/raw/shared/b85c5301fddcb98a-paths.js +5 -0
- package/src/tui-compiled/raw/shared/c14988621dc60a75-port-file.js +217 -0
- package/src/tui-compiled/raw/shared/c64d7afbc14ca125-sidebar-file.js +157 -0
- package/src/tui-compiled/raw/shared/c6b176708c446d6d-pins.js +34 -0
- package/src/tui-compiled/raw/shared/c7d252bedee01600-pi.js +206 -0
- package/src/tui-compiled/raw/shared/c852a15cfe489d12-pool.js +120 -0
- package/src/tui-compiled/raw/shared/cc9e0702a752cea7-index.js +3 -0
- package/src/tui-compiled/raw/shared/cd94316a888b0a8e-schema.js +754 -0
- package/src/tui-compiled/raw/shared/d319517e3ea6ad70-redact.js +83 -0
- package/src/tui-compiled/raw/shared/d5a8f1061ee2f114-index.js +5 -0
- package/src/tui-compiled/raw/shared/d669d72c40e9e116-logger.js +19 -0
- package/src/tui-compiled/raw/shared/d7dcba96fea1685c-engine.js +246 -0
- package/src/tui-compiled/raw/shared/dbef697d1df1cd84-index.js +5 -0
- package/src/tui-compiled/raw/shared/e4acc4cb713f300c-protocol.js +3 -0
- package/src/tui-compiled/raw/shared/e8cd4929507508d8-refresh-file-lock.js +501 -0
- package/src/tui-compiled/raw/shared/ec971142548df90e-index.js +6 -0
- package/src/tui-compiled/raw/shared/f37fcefc7aedbf25-error.js +11 -0
- package/src/tui-compiled/raw/shared/fbcdcd0f925e74c0-rpc-client.js +253 -0
- package/src/tui-compiled/raw/shared/fd45e82f2f9c0a0d-torn.js +294 -0
- package/src/tui-compiled/raw/shared/fe02abeadc535f77-rows.js +1258 -0
- package/src/tui-compiled/raw/sidebar-state.js +960 -0
- package/src/tui-compiled/raw/tui/command-dialogs.tsx +424 -0
- package/src/tui-compiled/raw/tui-preferences.js +135 -0
- package/src/tui-compiled/raw/tui.tsx +135 -143
- package/src/tui-compiled/runtime/logger.js +24 -0
- package/src/tui-compiled/runtime/rpc/protocol.js +3 -0
- package/src/tui-compiled/runtime/rpc/rpc-client.js +7 -0
- package/src/tui-compiled/runtime/rpc/rpc-dir.js +27 -0
- package/src/tui-compiled/runtime/selector.js +21 -0
- package/src/tui-compiled/runtime/shared/0332701351b3eeec-format.js +138 -0
- package/src/tui-compiled/runtime/shared/04a6357627de5ed0-errors.js +38 -0
- package/src/tui-compiled/runtime/shared/053cc17b5419261e-codec.js +12 -0
- package/src/tui-compiled/runtime/shared/0766d78c6f481f18-watcher.js +157 -0
- package/src/tui-compiled/runtime/shared/08eef45626a94992-reserved.js +13 -0
- package/src/tui-compiled/runtime/shared/39c3cb05738fcf6d-projection.js +134 -0
- package/src/tui-compiled/runtime/shared/3c2d4169d00f907e-tui-support.js +5 -0
- package/src/tui-compiled/runtime/shared/3e7d45a77c6ad4d5-index.js +4 -0
- package/src/tui-compiled/runtime/shared/415792e85d80819e-capture-sink.js +13 -0
- package/src/tui-compiled/runtime/shared/42ae93ab554fcec2-open-url.js +28 -0
- package/src/tui-compiled/runtime/shared/43fc9e6b994519c7-refresh-lock.js +136 -0
- package/src/tui-compiled/runtime/shared/458b934e92490331-mutate.js +500 -0
- package/src/tui-compiled/runtime/shared/45bf5343bbbf9add-admission.js +142 -0
- package/src/tui-compiled/runtime/shared/46f3dff1266160e8-client.js +2 -0
- package/src/tui-compiled/runtime/shared/4825e03209d6ae3e-with-lock.js +48 -0
- package/src/tui-compiled/runtime/shared/4f36d333d081d040-merge.js +162 -0
- package/src/tui-compiled/runtime/shared/54eba94fd64c8c3c-index.js +7 -0
- package/src/tui-compiled/runtime/shared/7211cfec06a298bc-atomic-write.js +80 -0
- package/src/tui-compiled/runtime/shared/754d6017f8e419cf-builtins.js +534 -0
- package/src/tui-compiled/runtime/shared/75bd8c3bd63b315f-identity.js +79 -0
- package/src/tui-compiled/runtime/shared/7a91bb630e6f4804-index.js +1 -0
- package/src/tui-compiled/runtime/shared/826342a4b6a8b89b-model.js +16 -0
- package/src/tui-compiled/runtime/shared/83068c0dbe8a6f13-publication.js +304 -0
- package/src/tui-compiled/runtime/shared/836fc615de6afbd9-settings.js +120 -0
- package/src/tui-compiled/runtime/shared/83bc3ba9d0fe2761-runtime.js +68 -0
- package/src/tui-compiled/runtime/shared/8a18abe4fa2977c8-menu.js +300 -0
- package/src/tui-compiled/runtime/shared/901e149c5a0dbbff-sticky.js +339 -0
- package/src/tui-compiled/runtime/shared/9020c407ce64f672-ordered.js +58 -0
- package/src/tui-compiled/runtime/shared/905bffc0220f43d0-map.js +105 -0
- package/src/tui-compiled/runtime/shared/94820e324f2b4c09-seam.js +301 -0
- package/src/tui-compiled/runtime/shared/97484d9bb98c705b-provider-state.js +226 -0
- package/src/tui-compiled/runtime/shared/9968e3cade6969a1-index.js +2 -0
- package/src/tui-compiled/runtime/shared/9b4da614c45f9cd0-lock-constants.js +14 -0
- package/src/tui-compiled/runtime/shared/9d3fc9e37456504e-refresh.js +225 -0
- package/src/tui-compiled/runtime/shared/9deae3c4da4fd63b-hooks.js +34 -0
- package/src/tui-compiled/runtime/shared/a09b6a533c11858f-tui-preferences.js +77 -0
- package/src/tui-compiled/runtime/shared/a62a27a204266acd-attribution.js +60 -0
- package/src/tui-compiled/runtime/shared/a910277ac43a8626-pull.js +143 -0
- package/src/tui-compiled/runtime/shared/b85c5301fddcb98a-paths.js +5 -0
- package/src/tui-compiled/runtime/shared/c14988621dc60a75-port-file.js +217 -0
- package/src/tui-compiled/runtime/shared/c64d7afbc14ca125-sidebar-file.js +157 -0
- package/src/tui-compiled/runtime/shared/c6b176708c446d6d-pins.js +34 -0
- package/src/tui-compiled/runtime/shared/c7d252bedee01600-pi.js +206 -0
- package/src/tui-compiled/runtime/shared/c852a15cfe489d12-pool.js +120 -0
- package/src/tui-compiled/runtime/shared/cc9e0702a752cea7-index.js +3 -0
- package/src/tui-compiled/runtime/shared/cd94316a888b0a8e-schema.js +754 -0
- package/src/tui-compiled/runtime/shared/d319517e3ea6ad70-redact.js +83 -0
- package/src/tui-compiled/runtime/shared/d5a8f1061ee2f114-index.js +5 -0
- package/src/tui-compiled/runtime/shared/d669d72c40e9e116-logger.js +19 -0
- package/src/tui-compiled/runtime/shared/d7dcba96fea1685c-engine.js +246 -0
- package/src/tui-compiled/runtime/shared/dbef697d1df1cd84-index.js +5 -0
- package/src/tui-compiled/runtime/shared/e4acc4cb713f300c-protocol.js +3 -0
- package/src/tui-compiled/runtime/shared/e8cd4929507508d8-refresh-file-lock.js +501 -0
- package/src/tui-compiled/runtime/shared/ec971142548df90e-index.js +6 -0
- package/src/tui-compiled/runtime/shared/f37fcefc7aedbf25-error.js +11 -0
- package/src/tui-compiled/runtime/shared/fbcdcd0f925e74c0-rpc-client.js +253 -0
- package/src/tui-compiled/runtime/shared/fd45e82f2f9c0a0d-torn.js +294 -0
- package/src/tui-compiled/runtime/shared/fe02abeadc535f77-rows.js +1258 -0
- package/src/tui-compiled/runtime/sidebar-state.js +960 -0
- package/src/tui-compiled/runtime/tui/command-dialogs.js +378 -0
- package/src/tui-compiled/runtime/tui-preferences.js +135 -0
- package/src/tui-compiled/runtime/{tui.tsx → tui.js} +288 -316
- package/dist/index-4effjmr6.js +0 -2
- package/dist/index-9ehhb051.js +0 -2
- package/dist/index-g3hsdjh4.js +0 -2
- package/dist/index-hh52v8sb.js +0 -2
- package/dist/index-jwn4r3sw.js +0 -1
- package/dist/index-sq36b120.js +0 -211
- package/dist/internal-BTndPmW2.d.ts +0 -914
- package/dist/quota-normalize-08hpp51v.js +0 -1
- package/dist/sidebar-state-CoKYKcLn.d.ts +0 -220
- package/dist/token-util-ypgz7rge.js +0 -1
- package/src/tui-compiled/raw/core-account-paths.ts +0 -114
- package/src/tui-compiled/raw/core-custody-state.ts +0 -243
- package/src/tui-compiled/raw/logger.ts +0 -53
- package/src/tui-compiled/raw/rpc-port-file.ts +0 -177
- package/src/tui-compiled/raw/rpc-protocol.ts +0 -12
- package/src/tui-compiled/raw/rpc-rpc-client.ts +0 -82
- package/src/tui-compiled/raw/rpc-rpc-dir.ts +0 -46
- package/src/tui-compiled/raw/sidebar-state.ts +0 -1659
- package/src/tui-compiled/raw/tui-command-dialogs.tsx +0 -1096
- package/src/tui-compiled/raw/tui-preferences.ts +0 -328
- package/src/tui-compiled/runtime/core-account-paths.ts +0 -114
- package/src/tui-compiled/runtime/core-custody-state.ts +0 -243
- package/src/tui-compiled/runtime/logger.ts +0 -53
- package/src/tui-compiled/runtime/rpc-port-file.ts +0 -177
- package/src/tui-compiled/runtime/rpc-protocol.ts +0 -12
- package/src/tui-compiled/runtime/rpc-rpc-client.ts +0 -82
- package/src/tui-compiled/runtime/rpc-rpc-dir.ts +0 -46
- package/src/tui-compiled/runtime/sidebar-state.ts +0 -1659
- package/src/tui-compiled/runtime/tui-command-dialogs.tsx +0 -855
- package/src/tui-compiled/runtime/tui-preferences.ts +0 -328
- package/src/tui-compiled/shared/internal.ts +0 -6
- package/src/tui-compiled/shared/logger.ts +0 -264
- package/src/tui-compiled/shared/paths.ts +0 -33
- package/src/tui-compiled/shared/refresh-file-lock.ts +0 -384
- package/src/tui-compiled/shared/util/error.ts +0 -9
- package/src/tui-compiled/shared/util/open-url.ts +0 -30
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const SECRET_KEY_EXACT = /^(authorization|x-api-key|cookie|set-cookie|refresh|access|token)$/i;
|
|
2
|
+
const TOKEN_VALUE = /\b(Bearer\s+[\w.-]+|sk-[\w-]+|eyJ[\w.-]+)\b|ckh_[A-Za-z0-9_-]{20,}/g;
|
|
3
|
+
const MASK = '***REDACTED***';
|
|
4
|
+
// How many errors deep a cause chain is followed. A chain this long is
|
|
5
|
+
// already unreadable in a log line, and an unbounded one (each cause a fresh
|
|
6
|
+
// object, so the cycle check never trips) must not grow the line forever.
|
|
7
|
+
const MAX_ERROR_DEPTH = 8;
|
|
8
|
+
// Error's own fields are non-enumerable, so a plain entry walk renders an
|
|
9
|
+
// Error as `{}` and the name, message and stack a plugin logged are lost.
|
|
10
|
+
// The tag check also recognises an Error from another realm (a worker or a
|
|
11
|
+
// vm context), whose prototype is not this realm's Error.
|
|
12
|
+
function isError(value) {
|
|
13
|
+
return (value instanceof Error ||
|
|
14
|
+
Object.prototype.toString.call(value) === '[object Error]');
|
|
15
|
+
}
|
|
16
|
+
export function createRedactor(options = {}) {
|
|
17
|
+
const patterns = [TOKEN_VALUE, ...(options.extraValuePatterns ?? [])].map((pattern) => new RegExp(pattern.source, pattern.flags.includes('g') ? pattern.flags : `${pattern.flags}g`));
|
|
18
|
+
function isSecretKey(key) {
|
|
19
|
+
const normalized = key.toLowerCase().replace(/[-_]/g, '');
|
|
20
|
+
return (SECRET_KEY_EXACT.test(key) ||
|
|
21
|
+
normalized.includes('apikey') ||
|
|
22
|
+
normalized.endsWith('secret') ||
|
|
23
|
+
normalized.endsWith('password') ||
|
|
24
|
+
(normalized.endsWith('token') && !normalized.endsWith('tokens')) ||
|
|
25
|
+
!!options.extraSecretKeys?.(normalized));
|
|
26
|
+
}
|
|
27
|
+
// The fields every log reader wants first, then whatever else the error
|
|
28
|
+
// carries as its own enumerable properties (which is all an Error rendered
|
|
29
|
+
// as before). Every entry goes through the same key and string scrubbing as
|
|
30
|
+
// any other object, so a token in a message or stack is still masked.
|
|
31
|
+
function errorEntries(error) {
|
|
32
|
+
const fields = error;
|
|
33
|
+
const entries = [
|
|
34
|
+
['name', error.name],
|
|
35
|
+
['message', error.message],
|
|
36
|
+
['stack', error.stack],
|
|
37
|
+
];
|
|
38
|
+
for (const key of ['code', 'status', 'cause'])
|
|
39
|
+
if (fields[key] !== undefined)
|
|
40
|
+
entries.push([key, fields[key]]);
|
|
41
|
+
const listed = new Set(entries.map(([key]) => key));
|
|
42
|
+
for (const entry of Object.entries(error))
|
|
43
|
+
if (!listed.has(entry[0]))
|
|
44
|
+
entries.push(entry);
|
|
45
|
+
return entries;
|
|
46
|
+
}
|
|
47
|
+
function walk(value, keys, seen, errorDepth = 0) {
|
|
48
|
+
if (typeof value === 'string') {
|
|
49
|
+
return patterns.reduce((text, pattern) => text.replace(pattern, MASK), value);
|
|
50
|
+
}
|
|
51
|
+
if (!value || typeof value !== 'object')
|
|
52
|
+
return value;
|
|
53
|
+
if (seen.has(value))
|
|
54
|
+
return '[Circular]';
|
|
55
|
+
seen.add(value);
|
|
56
|
+
try {
|
|
57
|
+
if (Array.isArray(value))
|
|
58
|
+
return value.map((item) => walk(item, keys, seen, errorDepth));
|
|
59
|
+
const error = isError(value);
|
|
60
|
+
if (error && errorDepth >= MAX_ERROR_DEPTH)
|
|
61
|
+
return '[Truncated]';
|
|
62
|
+
const childDepth = error ? errorDepth + 1 : errorDepth;
|
|
63
|
+
// Define own properties so a diagnostic __proto__ key cannot change the output prototype.
|
|
64
|
+
return Object.fromEntries((error ? errorEntries(value) : Object.entries(value)).map(([key, item]) => [
|
|
65
|
+
key,
|
|
66
|
+
keys && isSecretKey(key)
|
|
67
|
+
? MASK
|
|
68
|
+
: walk(item, keys, seen, childDepth),
|
|
69
|
+
]));
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
seen.delete(value);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
redact: (value) => walk(value, true, new WeakSet()),
|
|
77
|
+
// Schema keys describe arguments, not credentials; only their string values are scrubbed.
|
|
78
|
+
redactStrings: (value) => walk(value, false, new WeakSet()),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const defaultRedactor = createRedactor();
|
|
82
|
+
export const redact = defaultRedactor.redact;
|
|
83
|
+
export const redactStrings = defaultRedactor.redactStrings;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { quotaCodec } from "./053cc17b5419261e-codec.js";
|
|
2
|
+
export { formatQuota, NO_LIMITS_REPORTED, NO_QUOTA_READING, QUOTA_STALE_AFTER_MS, quotaTextParts, quotaWindowName, } from "./0332701351b3eeec-format.js";
|
|
3
|
+
export { ALL_SCOPE, DEFAULT_REQUIRED_LABELS, emptyQuotaMap, isQuotaMap, } from "./905bffc0220f43d0-map.js";
|
|
4
|
+
export { isQuotaObservation, mergeQuotaObservation, QuotaCodecError, } from "./4f36d333d081d040-merge.js";
|
|
5
|
+
export { budgetExhaustedResetAt, futureResetAt, projectQuota, readsExhausted, } from "./39c3cb05738fcf6d-projection.js";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
initLogger as commonInitLogger,
|
|
3
|
+
createRedactor
|
|
4
|
+
} from "./cc9e0702a752cea7-index.js";
|
|
5
|
+
export {
|
|
6
|
+
createLogger,
|
|
7
|
+
flushForTest,
|
|
8
|
+
flushLogs,
|
|
9
|
+
resetLoggerForTest,
|
|
10
|
+
setLogLevel
|
|
11
|
+
} from "./cc9e0702a752cea7-index.js";
|
|
12
|
+
function isOpenaiIdentityKey(normalizedKey) {
|
|
13
|
+
return normalizedKey === "chatgptaccountid" || normalizedKey === "email" || normalizedKey === "orgname" || normalizedKey === "organizationname";
|
|
14
|
+
}
|
|
15
|
+
const openaiRedactor = createRedactor({ extraSecretKeys: isOpenaiIdentityKey });
|
|
16
|
+
export const { redact, redactStrings } = openaiRedactor;
|
|
17
|
+
export function initLogger(options) {
|
|
18
|
+
commonInitLogger({ ...options, extraSecretKeys: isOpenaiIdentityKey });
|
|
19
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { appendFileSync, chmodSync, existsSync, renameSync, statSync, } from "node:fs";
|
|
2
|
+
import { createRedactor } from "./d319517e3ea6ad70-redact.js";
|
|
3
|
+
const ORDER = {
|
|
4
|
+
error: 0,
|
|
5
|
+
warn: 1,
|
|
6
|
+
info: 2,
|
|
7
|
+
debug: 3,
|
|
8
|
+
trace: 4,
|
|
9
|
+
};
|
|
10
|
+
const MAX_BYTES = 5 * 1024 * 1024;
|
|
11
|
+
const ROTATE_KEEP = 3;
|
|
12
|
+
function chmodPrivate(path) {
|
|
13
|
+
try {
|
|
14
|
+
chmodSync(path, 0o600);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
/* never throw */
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function rotateIfNeeded(f) {
|
|
21
|
+
try {
|
|
22
|
+
if (!(existsSync(f) && statSync(f).size >= MAX_BYTES))
|
|
23
|
+
return;
|
|
24
|
+
for (let i = ROTATE_KEEP - 1; i >= 1; i--) {
|
|
25
|
+
if (existsSync(`${f}.${i}`)) {
|
|
26
|
+
const rotated = `${f}.${i + 1}`;
|
|
27
|
+
renameSync(`${f}.${i}`, rotated);
|
|
28
|
+
chmodPrivate(rotated);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const rotated = `${f}.1`;
|
|
32
|
+
renameSync(f, rotated);
|
|
33
|
+
chmodPrivate(rotated);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
/* never throw */
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function safeSerialize(data) {
|
|
40
|
+
try {
|
|
41
|
+
return ` ${JSON.stringify(data)}`;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return ' [unserializable]';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* One logger's settings and buffer.
|
|
49
|
+
*
|
|
50
|
+
* Where lines are written and the level floor start unset unless `options`
|
|
51
|
+
* supplies them. A host decides where its log lives (that decision reads host
|
|
52
|
+
* environment variables and host directories, neither of which belongs in
|
|
53
|
+
* shared code) and configures the logger before it runs any command. Until
|
|
54
|
+
* then every `log.*` call is a silent no-op: throwing would turn the first
|
|
55
|
+
* command a host forgot to wire into a crash, and buffering would hold
|
|
56
|
+
* credential-bearing lines for a configuration that may never arrive.
|
|
57
|
+
*/
|
|
58
|
+
function createEngine(options) {
|
|
59
|
+
let logFileSource;
|
|
60
|
+
let initLevelSource;
|
|
61
|
+
let runtimeLevel;
|
|
62
|
+
let redactor = createRedactor();
|
|
63
|
+
let captureSink;
|
|
64
|
+
let buffer = [];
|
|
65
|
+
let timer;
|
|
66
|
+
function configure(next) {
|
|
67
|
+
logFileSource = next.file;
|
|
68
|
+
initLevelSource = next.level;
|
|
69
|
+
redactor = createRedactor(next);
|
|
70
|
+
captureSink = next.captureSink;
|
|
71
|
+
}
|
|
72
|
+
function setLogLevel(l) {
|
|
73
|
+
if (l === undefined || l in ORDER)
|
|
74
|
+
runtimeLevel = l;
|
|
75
|
+
}
|
|
76
|
+
function logFilePath() {
|
|
77
|
+
if (logFileSource === undefined)
|
|
78
|
+
return undefined;
|
|
79
|
+
const resolved = typeof logFileSource === 'function' ? logFileSource() : logFileSource;
|
|
80
|
+
return resolved || undefined;
|
|
81
|
+
}
|
|
82
|
+
function configuredLevel() {
|
|
83
|
+
if (runtimeLevel)
|
|
84
|
+
return runtimeLevel;
|
|
85
|
+
const floor = typeof initLevelSource === 'function'
|
|
86
|
+
? initLevelSource()
|
|
87
|
+
: initLevelSource;
|
|
88
|
+
if (floor && floor in ORDER)
|
|
89
|
+
return floor;
|
|
90
|
+
return 'info';
|
|
91
|
+
}
|
|
92
|
+
function flushLogs() {
|
|
93
|
+
if (timer) {
|
|
94
|
+
clearTimeout(timer);
|
|
95
|
+
timer = undefined;
|
|
96
|
+
}
|
|
97
|
+
if (!buffer.length)
|
|
98
|
+
return;
|
|
99
|
+
let file;
|
|
100
|
+
try {
|
|
101
|
+
file = logFilePath();
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
buffer = [];
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const text = buffer.join('');
|
|
108
|
+
buffer = [];
|
|
109
|
+
if (!file)
|
|
110
|
+
return;
|
|
111
|
+
try {
|
|
112
|
+
rotateIfNeeded(file);
|
|
113
|
+
if (existsSync(file))
|
|
114
|
+
chmodPrivate(file);
|
|
115
|
+
appendFileSync(file, text, { encoding: 'utf8', mode: 0o600 });
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
/* never throw */
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function schedule() {
|
|
122
|
+
if (!timer)
|
|
123
|
+
timer = setTimeout(() => {
|
|
124
|
+
timer = undefined;
|
|
125
|
+
flushLogs();
|
|
126
|
+
}, 500);
|
|
127
|
+
}
|
|
128
|
+
function emit(channel, level, message, data) {
|
|
129
|
+
// Unconfigured (neither a file nor a sink) stays a silent no-op.
|
|
130
|
+
if (logFileSource === undefined && captureSink === undefined)
|
|
131
|
+
return;
|
|
132
|
+
try {
|
|
133
|
+
if (ORDER[level] > ORDER[configuredLevel()])
|
|
134
|
+
return;
|
|
135
|
+
const scrubbedMessage = redactor.redactStrings(message);
|
|
136
|
+
let scrubbedData;
|
|
137
|
+
try {
|
|
138
|
+
scrubbedData = redactor.redact(data);
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
scrubbedData = '[unserializable]';
|
|
142
|
+
}
|
|
143
|
+
const line = `[${new Date().toISOString()}] ${level.toUpperCase()} [${channel}] ${scrubbedMessage}` +
|
|
144
|
+
(data === undefined ? '' : safeSerialize(scrubbedData)) +
|
|
145
|
+
'\n';
|
|
146
|
+
// A failing observer must not prevent file logging or escape into the host.
|
|
147
|
+
try {
|
|
148
|
+
captureSink?.({
|
|
149
|
+
channel,
|
|
150
|
+
level,
|
|
151
|
+
message: scrubbedMessage,
|
|
152
|
+
data: scrubbedData,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
catch { }
|
|
156
|
+
// A sink-only logger has no file to buffer lines for.
|
|
157
|
+
if (logFileSource === undefined)
|
|
158
|
+
return;
|
|
159
|
+
buffer.push(line);
|
|
160
|
+
if (buffer.length >= 50)
|
|
161
|
+
flushLogs();
|
|
162
|
+
else
|
|
163
|
+
schedule();
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
// Provider and redaction failures must never turn diagnostics into a host crash.
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function createLogger(channel) {
|
|
170
|
+
return {
|
|
171
|
+
error: (m, d) => emit(channel, 'error', m, d),
|
|
172
|
+
warn: (m, d) => emit(channel, 'warn', m, d),
|
|
173
|
+
info: (m, d) => emit(channel, 'info', m, d),
|
|
174
|
+
debug: (m, d) => emit(channel, 'debug', m, d),
|
|
175
|
+
trace: (m, d) => emit(channel, 'trace', m, d),
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function reset() {
|
|
179
|
+
buffer = [];
|
|
180
|
+
if (timer) {
|
|
181
|
+
clearTimeout(timer);
|
|
182
|
+
timer = undefined;
|
|
183
|
+
}
|
|
184
|
+
logFileSource = undefined;
|
|
185
|
+
initLevelSource = undefined;
|
|
186
|
+
runtimeLevel = undefined;
|
|
187
|
+
redactor = createRedactor();
|
|
188
|
+
captureSink = undefined;
|
|
189
|
+
}
|
|
190
|
+
if (options)
|
|
191
|
+
configure(options);
|
|
192
|
+
return { configure, createLogger, setLogLevel, flushLogs, reset };
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* A logger instance of its own, configured with `options`. A plugin whose
|
|
196
|
+
* copy of this module may be shared with another plugin in the same process
|
|
197
|
+
* uses this instead of `initLogger`, so neither replaces the other's file,
|
|
198
|
+
* level, redaction or capture sink.
|
|
199
|
+
*/
|
|
200
|
+
export function createLoggerInstance(options) {
|
|
201
|
+
const { configure, createLogger, setLogLevel, flushLogs } = createEngine(options);
|
|
202
|
+
return { configure, createLogger, setLogLevel, flushLogs };
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* The instance behind the module-level functions below, which keep the
|
|
206
|
+
* single-plugin API: one plugin per copy of this module calls `initLogger`
|
|
207
|
+
* and `createLogger` without holding an instance.
|
|
208
|
+
*/
|
|
209
|
+
const defaultEngine = createEngine();
|
|
210
|
+
/**
|
|
211
|
+
* Point the module's default logger at a host's file and level, and return
|
|
212
|
+
* it. Idempotent: calling it again replaces both. A runtime level installed
|
|
213
|
+
* by `setLogLevel` is deliberately left alone, because it is the operator's
|
|
214
|
+
* explicit choice and outranks the floor a host computed at start-up.
|
|
215
|
+
*/
|
|
216
|
+
export function initLogger(options) {
|
|
217
|
+
defaultEngine.configure(options);
|
|
218
|
+
const { configure, createLogger, setLogLevel, flushLogs } = defaultEngine;
|
|
219
|
+
return { configure, createLogger, setLogLevel, flushLogs };
|
|
220
|
+
}
|
|
221
|
+
export function setLogLevel(l) {
|
|
222
|
+
defaultEngine.setLogLevel(l);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Write whatever the default logger has buffered. Safe to call synchronously
|
|
226
|
+
* from a process-exit handler, which is how each host drains the buffer on
|
|
227
|
+
* shutdown.
|
|
228
|
+
*/
|
|
229
|
+
export function flushLogs() {
|
|
230
|
+
defaultEngine.flushLogs();
|
|
231
|
+
}
|
|
232
|
+
export function createLogger(channel) {
|
|
233
|
+
return defaultEngine.createLogger(channel);
|
|
234
|
+
}
|
|
235
|
+
export async function flushForTest() {
|
|
236
|
+
defaultEngine.flushLogs();
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Return the default logger to its uninitialised state. Only a test needs
|
|
240
|
+
* this: a single process runs every test file, so a file path left over from
|
|
241
|
+
* one test would keep a later "logger was never initialised" case writing
|
|
242
|
+
* lines.
|
|
243
|
+
*/
|
|
244
|
+
export function resetLoggerForTest() {
|
|
245
|
+
defaultEngine.reset();
|
|
246
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { MENU_DISABLED_REASON } from "./754d6017f8e419cf-builtins.js";
|
|
2
|
+
export { createCommandMenu, parseApplyRequest } from "./8a18abe4fa2977c8-menu.js";
|
|
3
|
+
export { SECTION_SLOTS } from "./826342a4b6a8b89b-model.js";
|
|
4
|
+
export { runPiCommandMenu } from "./c7d252bedee01600-pi.js";
|
|
5
|
+
export { ACTION_FAILED, CommandError, createTextRedactor, DEFAULT_IRREVERSIBLE_CONFIRMATION, projectFailure, } from "./94820e324f2b4c09-seam.js";
|