@bun-native/runtime 0.0.0-stage → 0.33.1

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 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
- # Temporary Holding Version
1
+ # @bun-native/runtime
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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.1 was built from [c56fdd675365](https://github.com/0xPlayerOne/bun-native/tree/c56fdd6753653a10144a4167c1d3dfb3c38a0647) 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/c56fdd6753653a10144a4167c1d3dfb3c38a0647/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": "c56fdd6753653a10144a4167c1d3dfb3c38a0647",
4
+ "tree": "c6e81b3f9d041e11dd0413b5fdd7a50910383854",
5
+ "files": {
6
+ "package.json": {
7
+ "bytes": 2115,
8
+ "sha256": "caf866d56f3cd7530d5735ecbf62512e9e22526bc44c75a4b48a18c26352c0b8"
9
+ },
10
+ "packages/runtime/package.json": {
11
+ "bytes": 195,
12
+ "sha256": "30d8e6684ee94e266b3bc63d151f718a5d0a8804b2155c11f74de3e7189af63a"
13
+ },
14
+ "packages/runtime/src/exit-diagnostic.ts": {
15
+ "bytes": 5059,
16
+ "sha256": "0c93ad077ad4cfcdf32a8092da1aff6cdc0f65322feadf538768439d67b11e06"
17
+ },
18
+ "packages/runtime/src/index.ts": {
19
+ "bytes": 39579,
20
+ "sha256": "a5f20057a2baa2117176a59c29e65438904f3758bfed3e29e981b55758e93adb"
21
+ },
22
+ "packages/runtime/src/installation.ts": {
23
+ "bytes": 1871,
24
+ "sha256": "a89c677fad56ace6839bda86891fafa088f3a37e0248c313a72d7918a0538a10"
25
+ },
26
+ "packages/runtime/src/startup-trace.ts": {
27
+ "bytes": 3345,
28
+ "sha256": "19efe954374e1cd486277bc8df144d8dd711cffd12e2888d14021c871de840d6"
29
+ },
30
+ "LICENSE": {
31
+ "bytes": 1075,
32
+ "sha256": "86673fb485f12fa9aaa3941dfccc9f69a7f8322f8141d0d5c73db4323de10ac5"
33
+ }
34
+ },
35
+ "toolchain": {
36
+ "bytes": 3234,
37
+ "sha256": "9f4d9362cb4cc38c0f4e705295789a0cbfec46ffdd007e0541b9441a7c3003a7"
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.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.33.1",
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.1"
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,136 @@
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 redact(text: string, environment: Readonly<Record<string, string | undefined>>): string {
50
+ let redacted = text.replace(/\p{Cc}/gu, (control) =>
51
+ control === '\n' || control === '\t' ? control : ''
52
+ )
53
+ const values = [
54
+ ...new Set(
55
+ Object.values(environment).filter(
56
+ (value): value is string =>
57
+ typeof value === 'string' && value.trim().length >= MIN_REDACTED_ENV_VALUE
58
+ )
59
+ ),
60
+ ].sort((left, right) => right.length - left.length)
61
+ for (const value of values)
62
+ redacted = redacted.replace(new RegExp(escapeRegExp(value), 'g'), REDACTED)
63
+ return redacted
64
+ .replace(/\b([A-Za-z_][A-Za-z0-9_]*)=("[^"]*"|'[^']*'|\S+)/g, `$1=${REDACTED}`)
65
+ .replace(
66
+ /\b(authorization|bearer|token|secret|password|passwd|api[_-]?key|cookie)(\s*[:=]\s*|\s+)("[^"]*"|'[^']*'|\S+)/gi,
67
+ `$1$2${REDACTED}`
68
+ )
69
+ .replace(/\b[A-Za-z0-9+_-]{32,}={0,2}/g, REDACTED)
70
+ }
71
+
72
+ /**
73
+ * Captured native stderr, safe to log or record. A clipped first line can hold
74
+ * the end of a secret that no longer matches its full environment value, so it
75
+ * is dropped before redaction.
76
+ */
77
+ export function redactDiagnostic(
78
+ stderr: string,
79
+ clipped: boolean,
80
+ environment: Readonly<Record<string, string | undefined>>
81
+ ): string {
82
+ return redact(
83
+ clipped ? stderr.slice(stderr.indexOf('\n') + 1 || stderr.length) : stderr,
84
+ environment
85
+ )
86
+ }
87
+
88
+ export function exitDiagnostic(input: {
89
+ exitCode: number | null
90
+ signal: string | null
91
+ phase: NativeHostExitDiagnostic['phase']
92
+ pendingRequests: number
93
+ stderr: string
94
+ /** The captured stderr lost its beginning; its first line may be a fragment. */
95
+ stderrClipped: boolean
96
+ /**
97
+ * Complete `panicked at` header and message lines kept while stderr was
98
+ * captured, so a long backtrace that clips the bounded capture cannot hide
99
+ * the panic itself.
100
+ */
101
+ panicReport?: string | null
102
+ environment: Readonly<Record<string, string | undefined>>
103
+ }): Readonly<NativeHostExitDiagnostic> {
104
+ const redacted = redactDiagnostic(input.stderr, input.stderrClipped, input.environment)
105
+ let panic = PANIC_LOCATION.exec(redacted)
106
+ // The kept report leads the tail only when the captured stderr lost it.
107
+ const report =
108
+ !panic && input.panicReport
109
+ ? redact(input.panicReport, input.environment)
110
+ .trimEnd()
111
+ .slice(0, MAX_DIAGNOSTIC_TAIL / 2)
112
+ : null
113
+ if (report) panic = PANIC_LOCATION.exec(report)
114
+ const reportLines = report ? [...report.split('\n'), CLIPPED] : []
115
+ let lines = redacted.trimEnd().split('\n')
116
+ const room = MAX_DIAGNOSTIC_LINES - reportLines.length
117
+ let truncated = input.stderrClipped || lines.length > room
118
+ lines = lines.slice(-room)
119
+ let tail = lines.join('\n')
120
+ const tailRoom = MAX_DIAGNOSTIC_TAIL - (report ? report.length + CLIPPED.length + 2 : 0)
121
+ if (tail.length > tailRoom) {
122
+ tail = tail.slice(-tailRoom)
123
+ truncated = true
124
+ }
125
+ if (report) tail = [...reportLines, tail].join('\n')
126
+ return Object.freeze({
127
+ reason: panic ? 'panic' : input.signal ? 'signal' : 'exit',
128
+ exitCode: input.exitCode,
129
+ signal: input.signal,
130
+ phase: input.phase,
131
+ pendingRequests: input.pendingRequests,
132
+ panicLocation: panic?.[1] ?? null,
133
+ stderrTail: tail,
134
+ stderrTruncated: truncated,
135
+ })
136
+ }