@noice-tech/pi-terminal-bell 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Igor Samokhovets
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 ADDED
@@ -0,0 +1,47 @@
1
+ # 🔔 @noice-tech/pi-terminal-bell
2
+
3
+ A tiny [Pi](https://github.com/earendil-works/pi) extension that rings your terminal when Pi is ready.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ pi install npm:@noice-tech/pi-terminal-bell
9
+ ```
10
+
11
+ ## How it works
12
+
13
+ Pi emits one standard BEL character after it fully settles. Short runs under 10 seconds are ignored, and non-interactive output is never touched.
14
+
15
+ Change the minimum duration in seconds—or use `0` to ring every time:
16
+
17
+ ```sh
18
+ PI_TERMINAL_BELL_MIN_DURATION=30 pi
19
+ ```
20
+
21
+ ## Ghostty 👻
22
+
23
+ Choose how Ghostty presents the bell:
24
+
25
+ ```ini
26
+ bell-features = attention,title,border
27
+ ```
28
+
29
+ Add `system` if you also want the system alert. Test your setup with:
30
+
31
+ ```sh
32
+ printf '\a'
33
+ ```
34
+
35
+ See Ghostty’s [BEL](https://ghostty.org/docs/vt/control/bel) and [`bell-features`](https://ghostty.org/docs/config/reference#bell-features) docs.
36
+
37
+ ## Why BEL?
38
+
39
+ One byte. No runtime dependencies. Works through interactive SSH and terminal multiplexers. Your terminal keeps control of sound and accessibility, so BEL may be audible, visual-only, suppressed, or require multiplexer configuration.
40
+
41
+ ## Provenance
42
+
43
+ This package migrated from [`samohovets/pi-terminal-bell`](https://github.com/samohovets/pi-terminal-bell) at source snapshot [`63e5b6d`](https://github.com/samohovets/pi-terminal-bell/commit/63e5b6d68c9689f5609af15620bbbd7f7708e4db). The source repository remains the history and provenance record.
44
+
45
+ ## License
46
+
47
+ [MIT](./LICENSE)
@@ -0,0 +1,66 @@
1
+ import { performance } from 'node:perf_hooks'
2
+ import type { ExtensionFactory } from '@earendil-works/pi-coding-agent'
3
+
4
+ export const BELL = '\x07'
5
+ export const DEFAULT_MINIMUM_DURATION_MS = 10_000
6
+
7
+ export interface BellOutput {
8
+ readonly isTTY?: boolean
9
+ write(chunk: string): unknown
10
+ }
11
+
12
+ export interface TerminalBellOptions {
13
+ output?: BellOutput
14
+ now?: () => number
15
+ minimumDurationMs?: number
16
+ }
17
+
18
+ export function parseMinimumDuration(raw: string | undefined): number {
19
+ if (raw === undefined || raw.trim() === '') {
20
+ return DEFAULT_MINIMUM_DURATION_MS
21
+ }
22
+
23
+ const milliseconds = Number(raw) * 1_000
24
+ return Number.isFinite(milliseconds) && milliseconds >= 0
25
+ ? milliseconds
26
+ : DEFAULT_MINIMUM_DURATION_MS
27
+ }
28
+
29
+ export function createTerminalBell(
30
+ options: TerminalBellOptions = {}
31
+ ): ExtensionFactory {
32
+ const output = options.output ?? process.stdout
33
+ const now = options.now ?? (() => performance.now())
34
+ const minimumDurationMs =
35
+ options.minimumDurationMs ??
36
+ parseMinimumDuration(process.env.PI_TERMINAL_BELL_MIN_DURATION)
37
+
38
+ return (pi) => {
39
+ let startedAt: number | undefined
40
+
41
+ pi.on('agent_start', async () => {
42
+ startedAt ??= now()
43
+ })
44
+
45
+ pi.on('agent_settled', async (_event, ctx) => {
46
+ const runStartedAt = startedAt
47
+ startedAt = undefined
48
+
49
+ if (ctx.mode !== 'tui' || output.isTTY !== true) return
50
+ if (runStartedAt === undefined && minimumDurationMs > 0) return
51
+ if (
52
+ runStartedAt !== undefined &&
53
+ now() - runStartedAt < minimumDurationMs
54
+ )
55
+ return
56
+
57
+ try {
58
+ output.write(BELL)
59
+ } catch {
60
+ // A notification failure must never interrupt the agent session.
61
+ }
62
+ })
63
+ }
64
+ }
65
+
66
+ export default createTerminalBell()
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@noice-tech/pi-terminal-bell",
3
+ "version": "1.0.0",
4
+ "description": "Terminal bell notifications when Pi is ready.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "keywords": [
8
+ "pi-package",
9
+ "pi",
10
+ "terminal",
11
+ "bell",
12
+ "notification"
13
+ ],
14
+ "files": [
15
+ "extensions/terminal-bell/index.ts",
16
+ "README.md",
17
+ "LICENSE"
18
+ ],
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/noice-tech/noice-pi.git",
25
+ "directory": "packages/terminal-bell"
26
+ },
27
+ "homepage": "https://github.com/noice-tech/noice-pi/tree/main/packages/terminal-bell#readme",
28
+ "bugs": {
29
+ "url": "https://github.com/noice-tech/noice-pi/issues"
30
+ },
31
+ "engines": {
32
+ "node": ">=22.19.0"
33
+ },
34
+ "peerDependencies": {
35
+ "@earendil-works/pi-coding-agent": "*"
36
+ },
37
+ "devDependencies": {
38
+ "@earendil-works/pi-coding-agent": "0.80.10",
39
+ "@types/node": "22.20.1",
40
+ "typescript": "6.0.3",
41
+ "vitest": "4.1.10"
42
+ },
43
+ "pi": {
44
+ "extensions": [
45
+ "./extensions/terminal-bell/index.ts"
46
+ ]
47
+ },
48
+ "scripts": {
49
+ "typecheck": "tsc --noEmit",
50
+ "test": "vitest run && node ../../scripts/smoke-pack.mjs @noice-tech/pi-terminal-bell packages/terminal-bell"
51
+ }
52
+ }