@bun-native/runtime 0.0.0-stage → 0.33.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 +21 -0
- package/README.md +4 -2
- package/bun-native-source.json +43 -0
- package/package.json +29 -4
- package/src/exit-diagnostic.ts +128 -0
- package/src/index.ts +1032 -0
- package/src/installation.ts +46 -0
- package/src/startup-trace.ts +95 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bunly contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @bun-native/runtime
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Bun Native host process lifecycle and bridge runtime.
|
|
4
|
+
|
|
5
|
+
Part of [Bun Native](https://github.com/0xPlayerOne/bun-native), an experimental developer preview. Version 0.33.0 was built from [fa8bef754122](https://github.com/0xPlayerOne/bun-native/tree/fa8bef754122621d4235eb06e30bb1085b4f7b1e) and published from GitHub Actions with npm provenance. Use the Bun revision pinned in that commit's toolchain.json. Start with the [getting-started guide](https://github.com/0xPlayerOne/bun-native/blob/fa8bef754122621d4235eb06e30bb1085b4f7b1e/docs/getting-started.md); `bun-native host install` fetches the matching release host. The license notice is in LICENSE.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"commit": "fa8bef754122621d4235eb06e30bb1085b4f7b1e",
|
|
4
|
+
"tree": "f805e2eb19a4e10fc29d1dc827cf5bc617b5773b",
|
|
5
|
+
"files": {
|
|
6
|
+
"package.json": {
|
|
7
|
+
"bytes": 2164,
|
|
8
|
+
"sha256": "db50b6f81f25c113a46f8c9b038bc548a92effaeb4ad9562e5e95044baa7b66f"
|
|
9
|
+
},
|
|
10
|
+
"packages/runtime/package.json": {
|
|
11
|
+
"bytes": 195,
|
|
12
|
+
"sha256": "30d8e6684ee94e266b3bc63d151f718a5d0a8804b2155c11f74de3e7189af63a"
|
|
13
|
+
},
|
|
14
|
+
"packages/runtime/src/exit-diagnostic.ts": {
|
|
15
|
+
"bytes": 4876,
|
|
16
|
+
"sha256": "f73b2259d80a6584427ad3b27ad239b5950b816468cca8d64bdfc35a5f3cfce8"
|
|
17
|
+
},
|
|
18
|
+
"packages/runtime/src/index.ts": {
|
|
19
|
+
"bytes": 38743,
|
|
20
|
+
"sha256": "aba3c6c58e2b9089b4faaf32e512736e660314bc2c0f74f62fe6dba45df5b053"
|
|
21
|
+
},
|
|
22
|
+
"packages/runtime/src/installation.ts": {
|
|
23
|
+
"bytes": 1871,
|
|
24
|
+
"sha256": "a89c677fad56ace6839bda86891fafa088f3a37e0248c313a72d7918a0538a10"
|
|
25
|
+
},
|
|
26
|
+
"packages/runtime/src/startup-trace.ts": {
|
|
27
|
+
"bytes": 3021,
|
|
28
|
+
"sha256": "b34971a20cb541fa8cd97eb611d59923297844186b6653ecb607b4b29bf80b2d"
|
|
29
|
+
},
|
|
30
|
+
"LICENSE": {
|
|
31
|
+
"bytes": 1075,
|
|
32
|
+
"sha256": "86673fb485f12fa9aaa3941dfccc9f69a7f8322f8141d0d5c73db4323de10ac5"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"toolchain": {
|
|
36
|
+
"bytes": 3012,
|
|
37
|
+
"sha256": "00c3f707aae8abe9ca75cd2e162f5e1c7c34362a03675da39afead60d856066a"
|
|
38
|
+
},
|
|
39
|
+
"dependencyLock": {
|
|
40
|
+
"bytes": 28357,
|
|
41
|
+
"sha256": "65e3dbd01be4a1889367690faf1a9c3f08fb31d22dbd273d9bb9f39dd6baa6fb"
|
|
42
|
+
}
|
|
43
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bun-native/runtime",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.33.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"src",
|
|
8
|
+
"LICENSE",
|
|
9
|
+
"README.md",
|
|
10
|
+
"bun-native-source.json"
|
|
11
|
+
],
|
|
12
|
+
"engines": {
|
|
13
|
+
"bun": "1.4.4-canary.1"
|
|
14
|
+
},
|
|
15
|
+
"exports": "./src/index.ts",
|
|
16
|
+
"description": "Bun Native host process lifecycle and bridge runtime.",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@bun-native/protocol": "0.33.0"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/0xPlayerOne/bun-native.git",
|
|
23
|
+
"directory": "packages/runtime"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/0xPlayerOne/bun-native#readme",
|
|
26
|
+
"bugs": "https://github.com/0xPlayerOne/bun-native/issues",
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public",
|
|
29
|
+
"provenance": true
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/** Upper bound for the redacted native stderr tail carried by an exit diagnostic. */
|
|
2
|
+
export const MAX_DIAGNOSTIC_TAIL = 2_048
|
|
3
|
+
const MAX_DIAGNOSTIC_LINES = 32
|
|
4
|
+
const MIN_REDACTED_ENV_VALUE = 6
|
|
5
|
+
const REDACTED = '[redacted]'
|
|
6
|
+
const CLIPPED = '…'
|
|
7
|
+
const PANIC_LOCATION = /panicked at ([^\s:]+(?::\d+){2})/
|
|
8
|
+
|
|
9
|
+
export type NativeHostExitReason = 'panic' | 'signal' | 'exit'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Bounded record of an unexpected native host exit. It never carries the
|
|
13
|
+
* environment, command line or unredacted native output, so it is safe to log.
|
|
14
|
+
*/
|
|
15
|
+
export interface NativeHostExitDiagnostic {
|
|
16
|
+
readonly reason: NativeHostExitReason
|
|
17
|
+
/** Process exit code, or null when the host was terminated by a signal. */
|
|
18
|
+
readonly exitCode: number | null
|
|
19
|
+
readonly signal: string | null
|
|
20
|
+
/** Transport phase when the host exited. */
|
|
21
|
+
readonly phase: 'starting' | 'running' | 'stopping'
|
|
22
|
+
/** Requests that were awaiting acknowledgement and were rejected with this error. */
|
|
23
|
+
readonly pendingRequests: number
|
|
24
|
+
/** `file:line:column` of a Rust panic reported on stderr, if any. */
|
|
25
|
+
readonly panicLocation: string | null
|
|
26
|
+
/** Redacted last native stderr lines, at most MAX_DIAGNOSTIC_TAIL characters. */
|
|
27
|
+
readonly stderrTail: string
|
|
28
|
+
readonly stderrTruncated: boolean
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class NativeHostExitError extends Error {
|
|
32
|
+
override readonly name = 'NativeHostExitError'
|
|
33
|
+
constructor(
|
|
34
|
+
readonly diagnostic: Readonly<NativeHostExitDiagnostic>,
|
|
35
|
+
status: number
|
|
36
|
+
) {
|
|
37
|
+
super(`Native host exited unexpectedly (${status}). ${diagnostic.stderrTail}`)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function escapeRegExp(text: string): string {
|
|
42
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Removes inherited environment values, assignments and credential-shaped
|
|
47
|
+
* tokens from native output. Over-redaction is acceptable; leaks are not.
|
|
48
|
+
*/
|
|
49
|
+
function redactDiagnostic(
|
|
50
|
+
text: string,
|
|
51
|
+
environment: Readonly<Record<string, string | undefined>>
|
|
52
|
+
): string {
|
|
53
|
+
let redacted = text.replace(/\p{Cc}/gu, (control) =>
|
|
54
|
+
control === '\n' || control === '\t' ? control : ''
|
|
55
|
+
)
|
|
56
|
+
const values = [
|
|
57
|
+
...new Set(
|
|
58
|
+
Object.values(environment).filter(
|
|
59
|
+
(value): value is string =>
|
|
60
|
+
typeof value === 'string' && value.trim().length >= MIN_REDACTED_ENV_VALUE
|
|
61
|
+
)
|
|
62
|
+
),
|
|
63
|
+
].sort((left, right) => right.length - left.length)
|
|
64
|
+
for (const value of values)
|
|
65
|
+
redacted = redacted.replace(new RegExp(escapeRegExp(value), 'g'), REDACTED)
|
|
66
|
+
return redacted
|
|
67
|
+
.replace(/\b([A-Za-z_][A-Za-z0-9_]*)=("[^"]*"|'[^']*'|\S+)/g, `$1=${REDACTED}`)
|
|
68
|
+
.replace(
|
|
69
|
+
/\b(authorization|bearer|token|secret|password|passwd|api[_-]?key|cookie)(\s*[:=]\s*|\s+)("[^"]*"|'[^']*'|\S+)/gi,
|
|
70
|
+
`$1$2${REDACTED}`
|
|
71
|
+
)
|
|
72
|
+
.replace(/\b[A-Za-z0-9+_-]{32,}={0,2}/g, REDACTED)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function exitDiagnostic(input: {
|
|
76
|
+
exitCode: number | null
|
|
77
|
+
signal: string | null
|
|
78
|
+
phase: NativeHostExitDiagnostic['phase']
|
|
79
|
+
pendingRequests: number
|
|
80
|
+
stderr: string
|
|
81
|
+
/** The captured stderr lost its beginning; its first line may be a fragment. */
|
|
82
|
+
stderrClipped: boolean
|
|
83
|
+
/**
|
|
84
|
+
* Complete `panicked at` header and message lines kept while stderr was
|
|
85
|
+
* captured, so a long backtrace that clips the bounded capture cannot hide
|
|
86
|
+
* the panic itself.
|
|
87
|
+
*/
|
|
88
|
+
panicReport?: string | null
|
|
89
|
+
environment: Readonly<Record<string, string | undefined>>
|
|
90
|
+
}): Readonly<NativeHostExitDiagnostic> {
|
|
91
|
+
// A clipped first line can hold the end of a secret that no longer matches
|
|
92
|
+
// its full environment value, so it is dropped before redaction.
|
|
93
|
+
const stderr = input.stderrClipped
|
|
94
|
+
? input.stderr.slice(input.stderr.indexOf('\n') + 1 || input.stderr.length)
|
|
95
|
+
: input.stderr
|
|
96
|
+
const redacted = redactDiagnostic(stderr, input.environment)
|
|
97
|
+
let panic = PANIC_LOCATION.exec(redacted)
|
|
98
|
+
// The kept report leads the tail only when the captured stderr lost it.
|
|
99
|
+
const report =
|
|
100
|
+
!panic && input.panicReport
|
|
101
|
+
? redactDiagnostic(input.panicReport, input.environment)
|
|
102
|
+
.trimEnd()
|
|
103
|
+
.slice(0, MAX_DIAGNOSTIC_TAIL / 2)
|
|
104
|
+
: null
|
|
105
|
+
if (report) panic = PANIC_LOCATION.exec(report)
|
|
106
|
+
const reportLines = report ? [...report.split('\n'), CLIPPED] : []
|
|
107
|
+
let lines = redacted.trimEnd().split('\n')
|
|
108
|
+
const room = MAX_DIAGNOSTIC_LINES - reportLines.length
|
|
109
|
+
let truncated = input.stderrClipped || lines.length > room
|
|
110
|
+
lines = lines.slice(-room)
|
|
111
|
+
let tail = lines.join('\n')
|
|
112
|
+
const tailRoom = MAX_DIAGNOSTIC_TAIL - (report ? report.length + CLIPPED.length + 2 : 0)
|
|
113
|
+
if (tail.length > tailRoom) {
|
|
114
|
+
tail = tail.slice(-tailRoom)
|
|
115
|
+
truncated = true
|
|
116
|
+
}
|
|
117
|
+
if (report) tail = [...reportLines, tail].join('\n')
|
|
118
|
+
return Object.freeze({
|
|
119
|
+
reason: panic ? 'panic' : input.signal ? 'signal' : 'exit',
|
|
120
|
+
exitCode: input.exitCode,
|
|
121
|
+
signal: input.signal,
|
|
122
|
+
phase: input.phase,
|
|
123
|
+
pendingRequests: input.pendingRequests,
|
|
124
|
+
panicLocation: panic?.[1] ?? null,
|
|
125
|
+
stderrTail: tail,
|
|
126
|
+
stderrTruncated: truncated,
|
|
127
|
+
})
|
|
128
|
+
}
|