@agimon-ai/po-notification 0.0.0-alpha.36 → 0.0.0-alpha.38
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 +32 -39
- package/dist/index.cjs +70 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +5 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +70 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
# @agimon-ai/po-notification
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Native push delivery, notification text helpers, and shell-tab title utilities for
|
|
4
4
|
[Po](https://www.npmjs.com/package/@agimon-ai/po) sessions.
|
|
5
5
|
|
|
6
|
-
Long agent runs are worth walking away from. This package
|
|
7
|
-
|
|
6
|
+
Long agent runs are worth walking away from. This package supplies the native push sender and `/notify` command. Hosts own notification
|
|
7
|
+
routing through the shared `po/notification` service and live session entries.
|
|
8
8
|
|
|
9
9
|
## What it does
|
|
10
10
|
|
|
11
|
-
| Surface | Behavior
|
|
12
|
-
| ---------------- |
|
|
13
|
-
| Shell tab title | `π - <session or first prompt> - <repository>`, with a braille spinner while the agent works
|
|
14
|
-
| Notification API | caller-authored notices through the shared `po/notification` Cordis service
|
|
15
|
-
| Mid-run |
|
|
16
|
-
| At rest |
|
|
11
|
+
| Surface | Behavior |
|
|
12
|
+
| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
|
|
13
|
+
| Shell tab title | `π - <session or first prompt> - <repository>`, with a braille spinner while the agent works |
|
|
14
|
+
| Notification API | caller-authored notices through the shared `po/notification` Cordis service |
|
|
15
|
+
| Mid-run | server-derived native push for each dialog during a run, parent sessions only |
|
|
16
|
+
| At rest | server-derived native push for settled parent runs with no queued follow-up; requires host execution state, skipped for sandbox sessions |
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
stay silent.
|
|
18
|
+
The package exports shell-title controllers and a system-notification helper (`cmux notify`, then
|
|
19
|
+
`osascript` on macOS), but does not install a terminal router or shell-title lifecycle itself.
|
|
20
|
+
The `/notify` command calls the active headless client's notification API, which appends a versioned
|
|
21
|
+
`po-notification` session entry for live clients and the native push subscriber.
|
|
23
22
|
|
|
24
23
|
## Service usage
|
|
25
24
|
|
|
@@ -38,13 +37,8 @@ ctx.inject([PO_NOTIFICATION_SERVICE], (notificationContext) => {
|
|
|
38
37
|
```
|
|
39
38
|
|
|
40
39
|
`body` is required. `title`, `subtitle`, and `level` are optional, and `level` accepts `info`,
|
|
41
|
-
`warning`, or `error`.
|
|
42
|
-
|
|
43
|
-
unavailable providers, and delivery failures are silent so notifications cannot fail an agent turn.
|
|
44
|
-
|
|
45
|
-
The package also wraps Pi's broad `ui.notify(message, level)` API while active, so existing extensions
|
|
46
|
-
use the same route without changing their calls. If this package is muted or the process is a detached
|
|
47
|
-
subagent child, it does not install that wrapper and Pi's original `ui.notify` behavior remains.
|
|
40
|
+
`warning`, or `error`. Entry normalization defaults title and subtitle to empty strings and level to
|
|
41
|
+
`info`. A host must provide the optional service. This package does not wrap Pi's `ui.notify` API.
|
|
48
42
|
|
|
49
43
|
## Browser delivery
|
|
50
44
|
|
|
@@ -54,7 +48,9 @@ is requested only from an explicit settings action.
|
|
|
54
48
|
|
|
55
49
|
Browser Web Push is not supported. Closed-app delivery uses the paired native iOS or Android app,
|
|
56
50
|
with explicit notification permission and native push enrollment. The server subscribes once to live
|
|
57
|
-
notification entries across all sessions, even with no client sockets connected. It
|
|
51
|
+
notification entries across all sessions, even with no client sockets connected. It also derives
|
|
52
|
+
"Input needed" (`Po needs your input`) and "Run finished" (`Po finished`) pushes from live hub events,
|
|
53
|
+
without adding transcript entries. It never reads history
|
|
58
54
|
for push, and has no durable outbox or replay. Enrollment is persisted on the trusted device record;
|
|
59
55
|
revocation, token rotation and remote disable are rechecked before queued work is dispatched.
|
|
60
56
|
|
|
@@ -80,8 +76,9 @@ For Apple, provision the company `ai.po.app` App ID with Push Notifications, sig
|
|
|
80
76
|
matching entitlement and provisioning profile, and create an APNs signing key in the Apple Developer
|
|
81
77
|
team. The server topic is fixed to `ai.po.app`. The native build-only variable
|
|
82
78
|
`PO_NATIVE_APNS_ENVIRONMENT` selects `development` or `production` to match the signed entitlement;
|
|
83
|
-
it is not a server credential. At runtime the native app reads the
|
|
84
|
-
`expo-application`,
|
|
79
|
+
it is not a server credential. At runtime the native app reads the provisioning profile through
|
|
80
|
+
`expo-application`, falling back to production for App Store/TestFlight installs without a profile,
|
|
81
|
+
and registers its token with that environment for server routing. iOS push enrollment
|
|
85
82
|
refuses a different application ID, including the previous `ai.agimon.po` development app. Rebuild and
|
|
86
83
|
pair the company iOS app with its matching profile; old iOS installs are a separate app identity.
|
|
87
84
|
|
|
@@ -92,6 +89,9 @@ The native build-only `PO_NATIVE_ANDROID_GOOGLE_SERVICES_FILE` points to the mat
|
|
|
92
89
|
`google-services.json`. This client configuration is not the server service-account private key.
|
|
93
90
|
Rebuild and reinstall the app when changing native build configuration.
|
|
94
91
|
|
|
92
|
+
Provider rejections produce redacted `Native push <provider>: <outcome> <status> <reason>` notices;
|
|
93
|
+
status and allowlisted APNs reason are included when available, never tokens, text, or keys.
|
|
94
|
+
|
|
95
95
|
**Privacy:** native push carries the full notification title, subtitle and body, subject to provider
|
|
96
96
|
payload limits. Apple or Google and the device lock screen can receive that text, including sensitive
|
|
97
97
|
agent output. This is not generic-copy-only delivery. Do not enable it for content you cannot share
|
|
@@ -120,27 +120,20 @@ escape sequences never end up in machine-read output.
|
|
|
120
120
|
|
|
121
121
|
## Quiet by design
|
|
122
122
|
|
|
123
|
-
-
|
|
124
|
-
|
|
125
|
-
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
silent, so one question is announced once.
|
|
129
|
-
- A settled run with pending follow-up messages notifies nothing: the agent is about to keep going.
|
|
123
|
+
- Server-derived pushes are silent for child sessions.
|
|
124
|
+
- Dialogs notify only during a run, once per dialog id. A new run resets deduplication.
|
|
125
|
+
- A finished push requires the host to report idle with no pending follow-up messages.
|
|
126
|
+
- Missing execution-state readers, including sandbox mirrors, skip completion pushes and log one
|
|
127
|
+
redacted notice per session. Dialog pushes still work.
|
|
130
128
|
|
|
131
129
|
## Installation
|
|
132
130
|
|
|
133
131
|
Po depends on this package and activates it as fixed host core, so a Po install already has
|
|
134
132
|
it. It is not selectable from `.po/modes.yaml`.
|
|
135
133
|
|
|
136
|
-
The
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
The Pi declaration installs its router and optional session binding before handling events.
|
|
141
|
-
`onStop` restores the original UI methods and shell title before service registrations are removed.
|
|
142
|
-
`onDispose` provides the same cleanup after partial startup. Detached children return before
|
|
143
|
-
acquiring a Cordis connection, leaving notification ownership with the parent.
|
|
134
|
+
The server loader uses `/extensions/server`, built from `src/extensions`. The root export contains
|
|
135
|
+
reusable notification helpers and types. The session command delegates to the host client; this package
|
|
136
|
+
has no Pi entry, notification wrapper, or automatically installed shell-title controller.
|
|
144
137
|
|
|
145
138
|
## License
|
|
146
139
|
|
package/dist/index.cjs
CHANGED
|
@@ -174,12 +174,12 @@ function createWorkerTitleController() {
|
|
|
174
174
|
//#endregion
|
|
175
175
|
//#region src/services/notificationText/index.ts
|
|
176
176
|
const ATTENTION_SUBTITLE = "Approval or feedback required";
|
|
177
|
-
const ATTENTION_TITLE = "
|
|
177
|
+
const ATTENTION_TITLE = "Po needs your input";
|
|
178
178
|
const ELLIPSIS = "…";
|
|
179
179
|
const MAX_BODY_LENGTH = 240;
|
|
180
180
|
const MAX_PROMPT_TITLE_LENGTH = 36;
|
|
181
181
|
const SETTLED_BODY = "The agent finished its work and is waiting for you.";
|
|
182
|
-
const SETTLED_TITLE = "
|
|
182
|
+
const SETTLED_TITLE = "Po finished";
|
|
183
183
|
const SHELL_TITLE_SEPARATOR = " - ";
|
|
184
184
|
const SHELL_TITLE_PREFIX = "π";
|
|
185
185
|
function collapseWhitespace(value) {
|
|
@@ -351,6 +351,37 @@ function createPushTransport() {
|
|
|
351
351
|
//#region src/services/nativePushSender/index.ts
|
|
352
352
|
const MAX_PAYLOAD_BYTES = 4096;
|
|
353
353
|
const APNS_TOPIC = "ai.po.app";
|
|
354
|
+
const APNS_REASONS = /* @__PURE__ */ new Set([
|
|
355
|
+
"BadCollapseId",
|
|
356
|
+
"BadDeviceToken",
|
|
357
|
+
"BadExpirationDate",
|
|
358
|
+
"BadMessageId",
|
|
359
|
+
"BadPriority",
|
|
360
|
+
"BadTopic",
|
|
361
|
+
"DeviceTokenNotForTopic",
|
|
362
|
+
"DuplicateHeaders",
|
|
363
|
+
"IdleTimeout",
|
|
364
|
+
"InvalidPushType",
|
|
365
|
+
"MissingDeviceToken",
|
|
366
|
+
"MissingTopic",
|
|
367
|
+
"PayloadEmpty",
|
|
368
|
+
"TopicDisallowed",
|
|
369
|
+
"BadCertificate",
|
|
370
|
+
"BadCertificateEnvironment",
|
|
371
|
+
"ExpiredProviderToken",
|
|
372
|
+
"Forbidden",
|
|
373
|
+
"InvalidProviderToken",
|
|
374
|
+
"MissingProviderToken",
|
|
375
|
+
"BadPath",
|
|
376
|
+
"MethodNotAllowed",
|
|
377
|
+
"Unregistered",
|
|
378
|
+
"PayloadTooLarge",
|
|
379
|
+
"TooManyProviderTokenUpdates",
|
|
380
|
+
"TooManyRequests",
|
|
381
|
+
"InternalServerError",
|
|
382
|
+
"ServiceUnavailable",
|
|
383
|
+
"Shutdown"
|
|
384
|
+
]);
|
|
354
385
|
const OAUTH_URL = "https://oauth2.googleapis.com/token";
|
|
355
386
|
const FCM_ERROR_TYPE = "type.googleapis.com/google.firebase.fcm.v1.FcmError";
|
|
356
387
|
const encoder = new TextEncoder();
|
|
@@ -439,7 +470,7 @@ function createNativePushSender(options) {
|
|
|
439
470
|
}
|
|
440
471
|
}
|
|
441
472
|
return {
|
|
442
|
-
async send(registration, notification) {
|
|
473
|
+
async send(registration, notification, sessionId) {
|
|
443
474
|
const provider = registration.platform === "ios" ? "apns" : "fcm";
|
|
444
475
|
if (closed || !options[provider]) {
|
|
445
476
|
options.diagnostic?.({
|
|
@@ -449,7 +480,12 @@ function createNativePushSender(options) {
|
|
|
449
480
|
return { invalid: false };
|
|
450
481
|
}
|
|
451
482
|
try {
|
|
483
|
+
const data = {
|
|
484
|
+
...registration.hostRef ? { hostRef: registration.hostRef } : {},
|
|
485
|
+
...sessionId ? { sessionId } : {}
|
|
486
|
+
};
|
|
452
487
|
let response;
|
|
488
|
+
let reason;
|
|
453
489
|
if (registration.platform === "ios") {
|
|
454
490
|
const credentials = options.apns;
|
|
455
491
|
if (!apnsJwt || now() >= apnsJwt.expires) apnsJwt = {
|
|
@@ -474,16 +510,30 @@ function createNativePushSender(options) {
|
|
|
474
510
|
"apns-expiration": "0",
|
|
475
511
|
"content-type": "application/json"
|
|
476
512
|
},
|
|
477
|
-
body: payload(notification, (text) => ({
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
513
|
+
body: payload(notification, (text) => ({
|
|
514
|
+
aps: {
|
|
515
|
+
alert: text,
|
|
516
|
+
sound: "default"
|
|
517
|
+
},
|
|
518
|
+
data,
|
|
519
|
+
body: data
|
|
520
|
+
}))
|
|
481
521
|
});
|
|
482
|
-
const
|
|
483
|
-
if (
|
|
522
|
+
const value = parse(response.body).reason;
|
|
523
|
+
if (typeof value === "string" && APNS_REASONS.has(value)) reason = value;
|
|
524
|
+
if (response.status === 410 && reason === "Unregistered" || response.status === 400 && reason === "BadDeviceToken") {
|
|
525
|
+
options.diagnostic?.({
|
|
526
|
+
provider,
|
|
527
|
+
outcome: "invalid",
|
|
528
|
+
status: response.status,
|
|
529
|
+
...reason ? { reason } : {}
|
|
530
|
+
});
|
|
531
|
+
return { invalid: true };
|
|
532
|
+
}
|
|
484
533
|
} else {
|
|
485
534
|
const body = payload(notification, (text) => ({ message: {
|
|
486
535
|
token: registration.token,
|
|
536
|
+
data,
|
|
487
537
|
notification: {
|
|
488
538
|
title: text.title,
|
|
489
539
|
body: [text.subtitle, text.body].filter(Boolean).join("\n")
|
|
@@ -506,12 +556,21 @@ function createNativePushSender(options) {
|
|
|
506
556
|
timeoutMs
|
|
507
557
|
});
|
|
508
558
|
const error = parse(response.body).error;
|
|
509
|
-
if (response.status === 404 && error && typeof error === "object" && "details" in error && Array.isArray(error.details) && error.details.some((detail) => detail && typeof detail === "object" && "@type" in detail && detail["@type"] === FCM_ERROR_TYPE && "errorCode" in detail && detail.errorCode === "UNREGISTERED"))
|
|
559
|
+
if (response.status === 404 && error && typeof error === "object" && "details" in error && Array.isArray(error.details) && error.details.some((detail) => detail && typeof detail === "object" && "@type" in detail && detail["@type"] === FCM_ERROR_TYPE && "errorCode" in detail && detail.errorCode === "UNREGISTERED")) {
|
|
560
|
+
options.diagnostic?.({
|
|
561
|
+
provider,
|
|
562
|
+
outcome: "invalid",
|
|
563
|
+
status: response.status,
|
|
564
|
+
...reason ? { reason } : {}
|
|
565
|
+
});
|
|
566
|
+
return { invalid: true };
|
|
567
|
+
}
|
|
510
568
|
}
|
|
511
569
|
if (response.status < 200 || response.status >= 300) options.diagnostic?.({
|
|
512
570
|
provider,
|
|
513
571
|
outcome: "failed",
|
|
514
|
-
status: response.status
|
|
572
|
+
status: response.status,
|
|
573
|
+
...reason ? { reason } : {}
|
|
515
574
|
});
|
|
516
575
|
} catch {
|
|
517
576
|
options.diagnostic?.({
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["Worker","path","sign","connect","request"],"sources":["../src/services/shellTitleController/mainThread.ts","../src/services/shellTitleController/index.ts","../src/services/notificationText/index.ts","../src/services/systemNotification/index.ts","../src/services/nativePushSender/sync.ts","../src/services/nativePushSender/index.ts","../src/services/notificationPolicy/index.ts"],"sourcesContent":["import type { ShellTitleController } from '../../types/notifications';\n\nexport const BRAILLE_FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\nexport const TITLE_FRAME_INTERVAL_MS = 80;\n\n/** Animates on the main thread, for hosts where a worker could not be started. */\nexport function createMainThreadTitleController(): ShellTitleController {\n let frameIndex = 0;\n let timer: ReturnType<typeof setInterval> | undefined;\n const stopAnimation = () => {\n if (timer) clearInterval(timer);\n timer = undefined;\n frameIndex = 0;\n };\n\n return {\n set(title, write) {\n stopAnimation();\n write(title);\n },\n start(title, write) {\n stopAnimation();\n const render = () => {\n write(`${BRAILLE_FRAMES[frameIndex % BRAILLE_FRAMES.length]} ${title}`);\n frameIndex += 1;\n };\n render();\n timer = setInterval(render, TITLE_FRAME_INTERVAL_MS);\n },\n stop(title, write) {\n stopAnimation();\n write(title);\n },\n dispose(title, write) {\n stopAnimation();\n write(title);\n },\n };\n}\n","import { Worker } from 'node:worker_threads';\n\nimport type { ShellTitleCommand, ShellTitleController, WriteTitle } from '../../types/notifications';\nimport { BRAILLE_FRAMES, TITLE_FRAME_INTERVAL_MS, createMainThreadTitleController } from './mainThread';\n\nexport { createMainThreadTitleController } from './mainThread';\n/**\n * The animator runs off the main thread so a busy agent turn cannot stall the\n * spinner. It is an inline eval source rather than a shipped file because the\n * package is bundled per entry, and a separate worker module would have to be\n * located on disk at runtime.\n */\nconst TITLE_WORKER_SOURCE = `\nconst { writeSync } = require('node:fs');\nconst { parentPort, workerData } = require('node:worker_threads');\nlet frameIndex = 0;\nlet timer;\nconst writeTitle = (title) => writeSync(1, '\\\\u001b]0;' + title + '\\\\u0007');\nconst stop = () => {\n if (timer) clearInterval(timer);\n timer = undefined;\n frameIndex = 0;\n};\nparentPort.on('message', (command) => {\n stop();\n if (command.action === 'start') {\n const render = () => {\n writeTitle(workerData.frames[frameIndex % workerData.frames.length] + ' ' + command.title);\n frameIndex += 1;\n };\n render();\n timer = setInterval(render, workerData.intervalMs);\n return;\n }\n writeTitle(command.title);\n if (command.action === 'dispose') parentPort.close();\n});\n`;\n\n/**\n * Animates from a worker thread, replaying the last command on the main thread\n * if the worker never started, failed, or exited under us. The worker is\n * unreferenced so a pending frame never holds the process open.\n */\nexport function createWorkerTitleController(): ShellTitleController {\n const fallback = createMainThreadTitleController();\n let lastCommand: ShellTitleCommand | undefined;\n let lastWrite: WriteTitle | undefined;\n let worker: Worker | undefined;\n\n const fallBack = () => {\n worker = undefined;\n if (!lastCommand || !lastWrite) return;\n fallback[lastCommand.action](lastCommand.title, lastWrite);\n };\n\n try {\n const titleWorker = new Worker(TITLE_WORKER_SOURCE, {\n eval: true,\n workerData: { frames: BRAILLE_FRAMES, intervalMs: TITLE_FRAME_INTERVAL_MS },\n });\n titleWorker.unref();\n titleWorker.once('error', fallBack);\n titleWorker.once('exit', (code) => {\n if (code !== 0 && worker === titleWorker) fallBack();\n });\n worker = titleWorker;\n } catch {\n // Workers are unavailable on this host, which the main-thread animator covers.\n worker = undefined;\n }\n\n const dispatch = (command: ShellTitleCommand, write: WriteTitle) => {\n lastCommand = command;\n lastWrite = write;\n if (!worker) {\n fallback[command.action](command.title, write);\n return;\n }\n try {\n worker.postMessage(command);\n } catch {\n // The worker closed between the last frame and this command.\n fallBack();\n }\n };\n\n return {\n set: (title, write) => dispatch({ action: 'set', title }, write),\n start: (title, write) => dispatch({ action: 'start', title }, write),\n stop: (title, write) => dispatch({ action: 'stop', title }, write),\n dispose: (title, write) => dispatch({ action: 'dispose', title }, write),\n };\n}\n","import path from 'node:path';\n\nimport type { DesktopNotification } from '../../types/notifications';\n\nconst ATTENTION_SUBTITLE = 'Approval or feedback required';\nconst ATTENTION_TITLE = 'Pi needs your input';\nconst ELLIPSIS = '…';\nconst MAX_BODY_LENGTH = 240;\nconst MAX_PROMPT_TITLE_LENGTH = 36;\nconst SETTLED_BODY = 'The agent finished its work and is waiting for you.';\nconst SETTLED_TITLE = 'Pi finished';\nconst SHELL_TITLE_SEPARATOR = ' - ';\nconst SHELL_TITLE_PREFIX = 'π';\n\nfunction collapseWhitespace(value: string): string {\n return value.replace(/\\s+/g, ' ').trim();\n}\n\nfunction truncate(value: string, maxLength: number): string {\n return value.length > maxLength ? `${value.slice(0, maxLength - 1)}${ELLIPSIS}` : value;\n}\n\n/** The first user prompt, shortened to fit a shell tab. A blank prompt names nothing. */\nexport function promptTitle(prompt: string): string | undefined {\n const normalized = collapseWhitespace(prompt);\n return normalized ? truncate(normalized, MAX_PROMPT_TITLE_LENGTH) : undefined;\n}\n\nexport interface ShellTabTitleInput {\n cwd: string;\n sessionName?: string;\n prompt?: string;\n}\n\n/**\n * The idle shell-tab title: `π - <label> - <repository>`.\n *\n * The session name wins over the first prompt because the user chose it. With\n * neither, the repository alone still tells two tabs apart.\n */\nexport function shellTabTitle({ cwd, sessionName, prompt }: ShellTabTitleInput): string {\n const repository = path.basename(cwd);\n const label = sessionName ?? prompt;\n return label\n ? `${SHELL_TITLE_PREFIX}${SHELL_TITLE_SEPARATOR}${label}${SHELL_TITLE_SEPARATOR}${repository}`\n : `${SHELL_TITLE_PREFIX}${SHELL_TITLE_SEPARATOR}${repository}`;\n}\n\n/** Notification bodies are one line in a system panel, so they collapse and truncate. */\nexport function notificationBody(body: string): string {\n return truncate(collapseWhitespace(body), MAX_BODY_LENGTH);\n}\n\n/** Sent while the agent holds the turn and something is blocking on the user. */\nexport function attentionNotification(body: string): DesktopNotification {\n return { title: ATTENTION_TITLE, subtitle: ATTENTION_SUBTITLE, body };\n}\n\n/** Sent once a run has stopped, subtitled with whichever name the user recognises. */\nexport function settledNotification({ cwd, sessionName }: { cwd: string; sessionName?: string }): DesktopNotification {\n return { title: SETTLED_TITLE, subtitle: sessionName ?? path.basename(cwd), body: SETTLED_BODY };\n}\n","import type { DesktopNotification, NotificationExecutor } from '../../types/notifications';\nimport { notificationBody } from '../notificationText';\n\nconst CMUX_COMMAND = 'cmux';\nconst COMMAND_TIMEOUT_MS = 3_000;\nconst DARWIN_PLATFORM = 'darwin';\nconst OSASCRIPT_COMMAND = 'osascript';\nconst OSASCRIPT_EXPRESSION_FLAG = '-e';\n\nasync function execute(pi: NotificationExecutor, command: string, args: string[]): Promise<boolean> {\n try {\n const result = await pi.exec(command, args, { timeout: COMMAND_TIMEOUT_MS });\n return result.code === 0;\n } catch {\n // A notifier that is not installed is the ordinary case, not a fault: report\n // \"not delivered\" and let the caller decide whether another one exists.\n return false;\n }\n}\n\n/**\n * Delivers one desktop notification on a best-effort basis.\n *\n * cmux is tried first because it routes the notification to the window the\n * session actually lives in. Only macOS has a second option worth attempting,\n * and a host with neither stays silent rather than failing the turn.\n */\nexport async function sendSystemNotification(\n pi: NotificationExecutor,\n notification: DesktopNotification,\n platform: string = process.platform,\n): Promise<void> {\n const body = notificationBody(notification.body);\n const sentToCmux = await execute(pi, CMUX_COMMAND, [\n 'notify',\n '--title',\n notification.title,\n '--subtitle',\n notification.subtitle,\n '--body',\n body,\n ]);\n if (sentToCmux || platform !== DARWIN_PLATFORM) return;\n\n await execute(pi, OSASCRIPT_COMMAND, [\n OSASCRIPT_EXPRESSION_FLAG,\n 'on run argv',\n OSASCRIPT_EXPRESSION_FLAG,\n 'display notification (item 3 of argv) with title (item 1 of argv) subtitle (item 2 of argv)',\n OSASCRIPT_EXPRESSION_FLAG,\n 'end run',\n notification.title,\n notification.subtitle,\n body,\n ]);\n}\n","import { sign } from 'node:crypto';\nimport { connect } from 'node:http2';\nimport { request } from 'node:https';\n\nimport type { NativePushRequest, NativePushResponse } from './type';\n\nconst MAX_RESPONSE_BYTES = 65_536;\n\nexport function signPushJwt(header: object, claims: object, key: string, algorithm: 'ES256' | 'RS256'): string {\n const input = [header, claims].map((part) => Buffer.from(JSON.stringify(part)).toString('base64url')).join('.');\n const signature = sign('sha256', Buffer.from(input), { key, dsaEncoding: 'ieee-p1363' });\n // APNs requires the raw P1363 ECDSA signature, not ASN.1 DER.\n if (algorithm === 'ES256' && signature.length !== 64) throw new Error('Invalid signing key');\n return `${input}.${signature.toString('base64url')}`;\n}\n\nexport function createPushTransport() {\n const pending = new Set<() => void>();\n return {\n request(this: void, input: NativePushRequest): Promise<NativePushResponse> {\n return new Promise((resolve, reject) => {\n const url = new URL(input.url);\n let size = 0;\n const chunks: Buffer[] = [];\n let done = false;\n let dispose = () => {};\n const finish = (error?: Error, status = 0) => {\n if (done) return;\n done = true;\n clearTimeout(timer);\n pending.delete(cancel);\n dispose();\n if (error) reject(error);\n else resolve({ status, body: Buffer.concat(chunks).toString('utf8') });\n };\n const cancel = () => finish(new Error('Push request cancelled'));\n const timer = setTimeout(() => finish(new Error('Push request timed out')), input.timeoutMs);\n pending.add(cancel);\n const data = (chunk: Buffer) => {\n size += chunk.length;\n if (size > MAX_RESPONSE_BYTES) finish(new Error('Push response too large'));\n else chunks.push(Buffer.from(chunk));\n };\n if (input.http2) {\n const session = connect(url.origin);\n dispose = () => session.destroy();\n session.on('error', (error) => finish(error));\n const stream = session.request({ ':method': 'POST', ':path': url.pathname, ...input.headers });\n let status = 0;\n stream.on('response', (headers) => {\n status = Number(headers[':status']);\n });\n stream.on('data', data);\n stream.on('error', (error) => finish(error));\n stream.on('end', () => finish(undefined, status));\n stream.end(input.body);\n } else {\n const req = request(url, { method: 'POST', headers: input.headers }, (response) => {\n response.on('data', data);\n response.on('error', (error) => finish(error));\n response.on('end', () => finish(undefined, response.statusCode));\n });\n dispose = () => req.destroy();\n req.on('error', (error) => finish(error));\n req.end(input.body);\n }\n });\n },\n close() {\n for (const cancel of pending) cancel();\n },\n };\n}\n","import type { PoNotificationEntryData } from '@agimon-ai/po-core';\n\nimport { createPushTransport, signPushJwt } from './sync';\nimport type { NativePushSender, NativePushSenderOptions } from './type';\n\nconst MAX_PAYLOAD_BYTES = 4096;\nconst APNS_TOPIC = 'ai.po.app';\nconst OAUTH_URL = 'https://oauth2.googleapis.com/token';\nconst FCM_ERROR_TYPE = 'type.googleapis.com/google.firebase.fcm.v1.FcmError';\nconst encoder = new TextEncoder();\n\nfunction parse(body: string): Record<string, unknown> {\n try {\n const value: unknown = JSON.parse(body);\n return value && typeof value === 'object' ? (value as Record<string, unknown>) : {};\n } catch {\n return {};\n } // Malformed provider responses never invalidate registrations.\n}\n\nfunction payload(\n notification: PoNotificationEntryData,\n build: (text: { title: string; subtitle: string; body: string }) => object,\n): string {\n const text = { title: notification.title, subtitle: notification.subtitle, body: notification.body };\n let result = JSON.stringify(build(text));\n // Measure the full serialized envelope, including escaped text and the FCM token.\n for (const field of ['body', 'subtitle', 'title'] as const) {\n if (encoder.encode(result).length <= MAX_PAYLOAD_BYTES) break;\n const points = Array.from(text[field]);\n let low = 0;\n let high = points.length;\n while (low < high) {\n const middle = Math.ceil((low + high) / 2);\n text[field] = points.slice(0, middle).join('');\n if (encoder.encode(JSON.stringify(build(text))).length <= MAX_PAYLOAD_BYTES) low = middle;\n else high = middle - 1;\n }\n text[field] = points.slice(0, low).join('');\n result = JSON.stringify(build(text));\n }\n if (encoder.encode(result).length > MAX_PAYLOAD_BYTES) throw new Error('Push payload too large');\n return result;\n}\n\nexport function createNativePushSender(options: NativePushSenderOptions): NativePushSender {\n const transport = createPushTransport();\n const request = options.request ?? transport.request;\n const now = options.now ?? Date.now;\n const timeoutMs = Number.isFinite(options.timeoutMs) ? Math.max(1, Math.min(options.timeoutMs!, 30_000)) : 10_000;\n let closed = false;\n let apnsJwt: { value: string; expires: number } | undefined;\n let oauth: { value: string; expires: number } | undefined;\n let oauthPending: Promise<string> | undefined;\n\n async function accessToken(): Promise<string> {\n if (oauth && now() < oauth.expires) return oauth.value;\n if (oauthPending) return oauthPending;\n oauthPending = (async () => {\n const credentials = options.fcm!;\n const issued = Math.floor(now() / 1000);\n const assertion = signPushJwt(\n { alg: 'RS256', typ: 'JWT' },\n {\n iss: credentials.clientEmail,\n scope: 'https://www.googleapis.com/auth/firebase.messaging',\n aud: OAUTH_URL,\n iat: issued,\n exp: issued + 3600,\n },\n credentials.privateKey,\n 'RS256',\n );\n const response = await request({\n url: OAUTH_URL,\n headers: { 'content-type': 'application/x-www-form-urlencoded' },\n body: new URLSearchParams({ grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer', assertion }).toString(),\n timeoutMs,\n });\n const data = parse(response.body);\n if (\n response.status !== 200 ||\n typeof data.access_token !== 'string' ||\n !data.access_token ||\n typeof data.expires_in !== 'number' ||\n !Number.isFinite(data.expires_in) ||\n data.expires_in <= 0\n )\n throw new Error('OAuth failed');\n oauth = { value: data.access_token, expires: now() + Math.max(0, Math.min(data.expires_in, 3600) - 60) * 1000 };\n return oauth.value;\n })();\n try {\n return await oauthPending;\n } finally {\n oauthPending = undefined;\n }\n }\n\n return {\n async send(registration, notification) {\n const provider = registration.platform === 'ios' ? 'apns' : 'fcm';\n if (closed || !options[provider]) {\n options.diagnostic?.({ provider, outcome: 'unavailable' });\n return { invalid: false };\n }\n try {\n let response;\n if (registration.platform === 'ios') {\n const credentials = options.apns!;\n if (!apnsJwt || now() >= apnsJwt.expires) {\n apnsJwt = {\n value: signPushJwt(\n { alg: 'ES256', kid: credentials.keyId },\n {\n iss: credentials.teamId,\n iat: Math.floor(now() / 1000),\n },\n credentials.key,\n 'ES256',\n ),\n expires: now() + 50 * 60_000,\n };\n }\n response = await request({\n url: `https://${registration.environment === 'development' ? 'api.sandbox.push.apple.com' : 'api.push.apple.com'}/3/device/${encodeURIComponent(registration.token)}`,\n http2: true,\n timeoutMs,\n headers: {\n authorization: `bearer ${apnsJwt.value}`,\n 'apns-topic': APNS_TOPIC,\n 'apns-push-type': 'alert',\n 'apns-priority': '10',\n 'apns-expiration': '0',\n 'content-type': 'application/json',\n },\n // ponytail: live alerts only; add a durable outbox if delayed delivery becomes a requirement.\n body: payload(notification, (text) => ({ aps: { alert: text, sound: 'default' } })),\n });\n const reason = parse(response.body).reason;\n if (\n (response.status === 410 && reason === 'Unregistered') ||\n (response.status === 400 && reason === 'BadDeviceToken')\n )\n return { invalid: true };\n } else {\n const body = payload(notification, (text) => ({\n message: {\n token: registration.token,\n notification: { title: text.title, body: [text.subtitle, text.body].filter(Boolean).join('\\n') },\n // ponytail: zero TTL, no offline delivery; an outbox would own delayed sends.\n android: { ttl: '0s', priority: 'HIGH', notification: { channel_id: 'po-notifications' } },\n },\n }));\n const token = await accessToken();\n if (closed) return { invalid: false };\n response = await request({\n url: `https://fcm.googleapis.com/v1/projects/${encodeURIComponent(options.fcm!.projectId)}/messages:send`,\n headers: { authorization: `Bearer ${token}`, 'content-type': 'application/json' },\n body,\n timeoutMs,\n });\n const error = parse(response.body).error;\n if (\n response.status === 404 &&\n error &&\n typeof error === 'object' &&\n 'details' in error &&\n Array.isArray(error.details) &&\n error.details.some(\n (detail: unknown) =>\n detail &&\n typeof detail === 'object' &&\n '@type' in detail &&\n detail['@type'] === FCM_ERROR_TYPE &&\n 'errorCode' in detail &&\n detail.errorCode === 'UNREGISTERED',\n )\n )\n return { invalid: true };\n }\n if (response.status < 200 || response.status >= 300)\n options.diagnostic?.({ provider, outcome: 'failed', status: response.status });\n } catch {\n // Never expose provider bodies, credentials, device tokens, or network errors.\n options.diagnostic?.({ provider, outcome: 'failed' });\n }\n return { invalid: false };\n },\n close() {\n closed = true;\n apnsJwt = undefined;\n oauth = undefined;\n transport.close();\n },\n };\n}\n","const DEFAULT_ASK_USER_BODY = 'The agent is waiting for your feedback.';\nconst RPC_MODE = 'rpc';\n\nexport interface AttentionState {\n agentRunning: boolean;\n askUserBlocked: boolean;\n}\n\nexport interface ShellSurface {\n hasUI: boolean;\n mode?: string;\n}\n\n/**\n * A dialog is worth interrupting the user for only while the agent holds the turn.\n *\n * Outside a run the user opened the dialog themselves and is already looking at\n * it. An ask-user prompt is announced by its own event, so the dialog it then\n * opens must stay silent or the same question notifies twice.\n */\nexport function warrantsAttentionNotification({ agentRunning, askUserBlocked }: AttentionState): boolean {\n return agentRunning && !askUserBlocked;\n}\n\n/** A queued follow-up means the agent keeps working, so the run has not stopped for the user. */\nexport function warrantsSettledNotification(hasPendingMessages: boolean): boolean {\n return !hasPendingMessages;\n}\n\n/** Terminal title escapes only mean something on an attached terminal; RPC output stays clean. */\nexport function supportsShellTitle({ hasUI, mode }: ShellSurface): boolean {\n return hasUI && mode !== RPC_MODE;\n}\n\n/** The question an ask-user prompt is blocking on, or a stand-in when it asked none. */\nexport function askUserPromptBody(questions: readonly { question: string }[]): string {\n return questions[0]?.question ?? DEFAULT_ASK_USER_BODY;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,MAAa,iBAAiB;CAAC;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;AAAG;;AAI/E,SAAgB,kCAAwD;CACtE,IAAI,aAAa;CACjB,IAAI;CACJ,MAAM,sBAAsB;EAC1B,IAAI,OAAO,cAAc,KAAK;EAC9B,QAAQ,KAAA;EACR,aAAa;CACf;CAEA,OAAO;EACL,IAAI,OAAO,OAAO;GAChB,cAAc;GACd,MAAM,KAAK;EACb;EACA,MAAM,OAAO,OAAO;GAClB,cAAc;GACd,MAAM,eAAe;IACnB,MAAM,GAAG,eAAe,aAAa,eAAe,QAAQ,GAAG,OAAO;IACtE,cAAc;GAChB;GACA,OAAO;GACP,QAAQ,YAAY,QAAA,EAA+B;EACrD;EACA,KAAK,OAAO,OAAO;GACjB,cAAc;GACd,MAAM,KAAK;EACb;EACA,QAAQ,OAAO,OAAO;GACpB,cAAc;GACd,MAAM,KAAK;EACb;CACF;AACF;;;;;;;;;AC1BA,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgC5B,SAAgB,8BAAoD;CAClE,MAAM,WAAW,gCAAgC;CACjD,IAAI;CACJ,IAAI;CACJ,IAAI;CAEJ,MAAM,iBAAiB;EACrB,SAAS,KAAA;EACT,IAAI,CAAC,eAAe,CAAC,WAAW;EAChC,SAAS,YAAY,OAAO,CAAC,YAAY,OAAO,SAAS;CAC3D;CAEA,IAAI;EACF,MAAM,cAAc,IAAIA,oBAAAA,OAAO,qBAAqB;GAClD,MAAM;GACN,YAAY;IAAE,QAAQ;IAAgB,YAAA;GAAoC;EAC5E,CAAC;EACD,YAAY,MAAM;EACl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AAa,kBACpB,eAAe,UACf,OAAO,cAAc,cACzB,GAEA,OAAO,EAAE,SAAS,KAAK;IAC3B;IACA,IAAI,SAAS,SAAS,OAAO,SAAS,UAAU,KAC9C,QAAQ,aAAa;KAAE;KAAU,SAAS;KAAU,QAAQ,SAAS;IAAO,CAAC;GACjF,QAAQ;IAEN,QAAQ,aAAa;KAAE;KAAU,SAAS;IAAS,CAAC;GACtD;GACA,OAAO,EAAE,SAAS,MAAM;EAC1B;EACA,QAAQ;GACN,SAAS;GACT,UAAU,KAAA;GACV,QAAQ,KAAA;GACR,UAAU,MAAM;EAClB;CACF;AACF;;;ACpMA,MAAM,wBAAwB;AAC9B,MAAM,WAAW;;;;;;;;AAmBjB,SAAgB,8BAA8B,EAAE,cAAc,kBAA2C;CACvG,OAAO,gBAAgB,CAAC;AAC1B;;AAGA,SAAgB,4BAA4B,oBAAsC;CAChF,OAAO,CAAC;AACV;;AAGA,SAAgB,mBAAmB,EAAE,OAAO,QAA+B;CACzE,OAAO,SAAS,SAAS;AAC3B;;AAGA,SAAgB,kBAAkB,WAAoD;CACpF,OAAO,UAAU,EAAE,EAAE,YAAY;AACnC"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["Worker","path","sign","connect","request"],"sources":["../src/services/shellTitleController/mainThread.ts","../src/services/shellTitleController/index.ts","../src/services/notificationText/index.ts","../src/services/systemNotification/index.ts","../src/services/nativePushSender/sync.ts","../src/services/nativePushSender/index.ts","../src/services/notificationPolicy/index.ts"],"sourcesContent":["import type { ShellTitleController } from '../../types/notifications';\n\nexport const BRAILLE_FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\nexport const TITLE_FRAME_INTERVAL_MS = 80;\n\n/** Animates on the main thread, for hosts where a worker could not be started. */\nexport function createMainThreadTitleController(): ShellTitleController {\n let frameIndex = 0;\n let timer: ReturnType<typeof setInterval> | undefined;\n const stopAnimation = () => {\n if (timer) clearInterval(timer);\n timer = undefined;\n frameIndex = 0;\n };\n\n return {\n set(title, write) {\n stopAnimation();\n write(title);\n },\n start(title, write) {\n stopAnimation();\n const render = () => {\n write(`${BRAILLE_FRAMES[frameIndex % BRAILLE_FRAMES.length]} ${title}`);\n frameIndex += 1;\n };\n render();\n timer = setInterval(render, TITLE_FRAME_INTERVAL_MS);\n },\n stop(title, write) {\n stopAnimation();\n write(title);\n },\n dispose(title, write) {\n stopAnimation();\n write(title);\n },\n };\n}\n","import { Worker } from 'node:worker_threads';\n\nimport type { ShellTitleCommand, ShellTitleController, WriteTitle } from '../../types/notifications';\nimport { BRAILLE_FRAMES, TITLE_FRAME_INTERVAL_MS, createMainThreadTitleController } from './mainThread';\n\nexport { createMainThreadTitleController } from './mainThread';\n/**\n * The animator runs off the main thread so a busy agent turn cannot stall the\n * spinner. It is an inline eval source rather than a shipped file because the\n * package is bundled per entry, and a separate worker module would have to be\n * located on disk at runtime.\n */\nconst TITLE_WORKER_SOURCE = `\nconst { writeSync } = require('node:fs');\nconst { parentPort, workerData } = require('node:worker_threads');\nlet frameIndex = 0;\nlet timer;\nconst writeTitle = (title) => writeSync(1, '\\\\u001b]0;' + title + '\\\\u0007');\nconst stop = () => {\n if (timer) clearInterval(timer);\n timer = undefined;\n frameIndex = 0;\n};\nparentPort.on('message', (command) => {\n stop();\n if (command.action === 'start') {\n const render = () => {\n writeTitle(workerData.frames[frameIndex % workerData.frames.length] + ' ' + command.title);\n frameIndex += 1;\n };\n render();\n timer = setInterval(render, workerData.intervalMs);\n return;\n }\n writeTitle(command.title);\n if (command.action === 'dispose') parentPort.close();\n});\n`;\n\n/**\n * Animates from a worker thread, replaying the last command on the main thread\n * if the worker never started, failed, or exited under us. The worker is\n * unreferenced so a pending frame never holds the process open.\n */\nexport function createWorkerTitleController(): ShellTitleController {\n const fallback = createMainThreadTitleController();\n let lastCommand: ShellTitleCommand | undefined;\n let lastWrite: WriteTitle | undefined;\n let worker: Worker | undefined;\n\n const fallBack = () => {\n worker = undefined;\n if (!lastCommand || !lastWrite) return;\n fallback[lastCommand.action](lastCommand.title, lastWrite);\n };\n\n try {\n const titleWorker = new Worker(TITLE_WORKER_SOURCE, {\n eval: true,\n workerData: { frames: BRAILLE_FRAMES, intervalMs: TITLE_FRAME_INTERVAL_MS },\n });\n titleWorker.unref();\n titleWorker.once('error', fallBack);\n titleWorker.once('exit', (code) => {\n if (code !== 0 && worker === titleWorker) fallBack();\n });\n worker = titleWorker;\n } catch {\n // Workers are unavailable on this host, which the main-thread animator covers.\n worker = undefined;\n }\n\n const dispatch = (command: ShellTitleCommand, write: WriteTitle) => {\n lastCommand = command;\n lastWrite = write;\n if (!worker) {\n fallback[command.action](command.title, write);\n return;\n }\n try {\n worker.postMessage(command);\n } catch {\n // The worker closed between the last frame and this command.\n fallBack();\n }\n };\n\n return {\n set: (title, write) => dispatch({ action: 'set', title }, write),\n start: (title, write) => dispatch({ action: 'start', title }, write),\n stop: (title, write) => dispatch({ action: 'stop', title }, write),\n dispose: (title, write) => dispatch({ action: 'dispose', title }, write),\n };\n}\n","import path from 'node:path';\n\nimport type { DesktopNotification } from '../../types/notifications';\n\nconst ATTENTION_SUBTITLE = 'Approval or feedback required';\nconst ATTENTION_TITLE = 'Po needs your input';\nconst ELLIPSIS = '…';\nconst MAX_BODY_LENGTH = 240;\nconst MAX_PROMPT_TITLE_LENGTH = 36;\nconst SETTLED_BODY = 'The agent finished its work and is waiting for you.';\nconst SETTLED_TITLE = 'Po finished';\nconst SHELL_TITLE_SEPARATOR = ' - ';\nconst SHELL_TITLE_PREFIX = 'π';\n\nfunction collapseWhitespace(value: string): string {\n return value.replace(/\\s+/g, ' ').trim();\n}\n\nfunction truncate(value: string, maxLength: number): string {\n return value.length > maxLength ? `${value.slice(0, maxLength - 1)}${ELLIPSIS}` : value;\n}\n\n/** The first user prompt, shortened to fit a shell tab. A blank prompt names nothing. */\nexport function promptTitle(prompt: string): string | undefined {\n const normalized = collapseWhitespace(prompt);\n return normalized ? truncate(normalized, MAX_PROMPT_TITLE_LENGTH) : undefined;\n}\n\nexport interface ShellTabTitleInput {\n cwd: string;\n sessionName?: string;\n prompt?: string;\n}\n\n/**\n * The idle shell-tab title: `π - <label> - <repository>`.\n *\n * The session name wins over the first prompt because the user chose it. With\n * neither, the repository alone still tells two tabs apart.\n */\nexport function shellTabTitle({ cwd, sessionName, prompt }: ShellTabTitleInput): string {\n const repository = path.basename(cwd);\n const label = sessionName ?? prompt;\n return label\n ? `${SHELL_TITLE_PREFIX}${SHELL_TITLE_SEPARATOR}${label}${SHELL_TITLE_SEPARATOR}${repository}`\n : `${SHELL_TITLE_PREFIX}${SHELL_TITLE_SEPARATOR}${repository}`;\n}\n\n/** Notification bodies are one line in a system panel, so they collapse and truncate. */\nexport function notificationBody(body: string): string {\n return truncate(collapseWhitespace(body), MAX_BODY_LENGTH);\n}\n\n/** Sent while the agent holds the turn and something is blocking on the user. */\nexport function attentionNotification(body: string): DesktopNotification {\n return { title: ATTENTION_TITLE, subtitle: ATTENTION_SUBTITLE, body };\n}\n\n/** Sent once a run has stopped, subtitled with whichever name the user recognises. */\nexport function settledNotification({ cwd, sessionName }: { cwd: string; sessionName?: string }): DesktopNotification {\n return { title: SETTLED_TITLE, subtitle: sessionName ?? path.basename(cwd), body: SETTLED_BODY };\n}\n","import type { DesktopNotification, NotificationExecutor } from '../../types/notifications';\nimport { notificationBody } from '../notificationText';\n\nconst CMUX_COMMAND = 'cmux';\nconst COMMAND_TIMEOUT_MS = 3_000;\nconst DARWIN_PLATFORM = 'darwin';\nconst OSASCRIPT_COMMAND = 'osascript';\nconst OSASCRIPT_EXPRESSION_FLAG = '-e';\n\nasync function execute(pi: NotificationExecutor, command: string, args: string[]): Promise<boolean> {\n try {\n const result = await pi.exec(command, args, { timeout: COMMAND_TIMEOUT_MS });\n return result.code === 0;\n } catch {\n // A notifier that is not installed is the ordinary case, not a fault: report\n // \"not delivered\" and let the caller decide whether another one exists.\n return false;\n }\n}\n\n/**\n * Delivers one desktop notification on a best-effort basis.\n *\n * cmux is tried first because it routes the notification to the window the\n * session actually lives in. Only macOS has a second option worth attempting,\n * and a host with neither stays silent rather than failing the turn.\n */\nexport async function sendSystemNotification(\n pi: NotificationExecutor,\n notification: DesktopNotification,\n platform: string = process.platform,\n): Promise<void> {\n const body = notificationBody(notification.body);\n const sentToCmux = await execute(pi, CMUX_COMMAND, [\n 'notify',\n '--title',\n notification.title,\n '--subtitle',\n notification.subtitle,\n '--body',\n body,\n ]);\n if (sentToCmux || platform !== DARWIN_PLATFORM) return;\n\n await execute(pi, OSASCRIPT_COMMAND, [\n OSASCRIPT_EXPRESSION_FLAG,\n 'on run argv',\n OSASCRIPT_EXPRESSION_FLAG,\n 'display notification (item 3 of argv) with title (item 1 of argv) subtitle (item 2 of argv)',\n OSASCRIPT_EXPRESSION_FLAG,\n 'end run',\n notification.title,\n notification.subtitle,\n body,\n ]);\n}\n","import { sign } from 'node:crypto';\nimport { connect } from 'node:http2';\nimport { request } from 'node:https';\n\nimport type { NativePushRequest, NativePushResponse } from './type';\n\nconst MAX_RESPONSE_BYTES = 65_536;\n\nexport function signPushJwt(header: object, claims: object, key: string, algorithm: 'ES256' | 'RS256'): string {\n const input = [header, claims].map((part) => Buffer.from(JSON.stringify(part)).toString('base64url')).join('.');\n const signature = sign('sha256', Buffer.from(input), { key, dsaEncoding: 'ieee-p1363' });\n // APNs requires the raw P1363 ECDSA signature, not ASN.1 DER.\n if (algorithm === 'ES256' && signature.length !== 64) throw new Error('Invalid signing key');\n return `${input}.${signature.toString('base64url')}`;\n}\n\nexport function createPushTransport() {\n const pending = new Set<() => void>();\n return {\n request(this: void, input: NativePushRequest): Promise<NativePushResponse> {\n return new Promise((resolve, reject) => {\n const url = new URL(input.url);\n let size = 0;\n const chunks: Buffer[] = [];\n let done = false;\n let dispose = () => {};\n const finish = (error?: Error, status = 0) => {\n if (done) return;\n done = true;\n clearTimeout(timer);\n pending.delete(cancel);\n dispose();\n if (error) reject(error);\n else resolve({ status, body: Buffer.concat(chunks).toString('utf8') });\n };\n const cancel = () => finish(new Error('Push request cancelled'));\n const timer = setTimeout(() => finish(new Error('Push request timed out')), input.timeoutMs);\n pending.add(cancel);\n const data = (chunk: Buffer) => {\n size += chunk.length;\n if (size > MAX_RESPONSE_BYTES) finish(new Error('Push response too large'));\n else chunks.push(Buffer.from(chunk));\n };\n if (input.http2) {\n const session = connect(url.origin);\n dispose = () => session.destroy();\n session.on('error', (error) => finish(error));\n const stream = session.request({ ':method': 'POST', ':path': url.pathname, ...input.headers });\n let status = 0;\n stream.on('response', (headers) => {\n status = Number(headers[':status']);\n });\n stream.on('data', data);\n stream.on('error', (error) => finish(error));\n stream.on('end', () => finish(undefined, status));\n stream.end(input.body);\n } else {\n const req = request(url, { method: 'POST', headers: input.headers }, (response) => {\n response.on('data', data);\n response.on('error', (error) => finish(error));\n response.on('end', () => finish(undefined, response.statusCode));\n });\n dispose = () => req.destroy();\n req.on('error', (error) => finish(error));\n req.end(input.body);\n }\n });\n },\n close() {\n for (const cancel of pending) cancel();\n },\n };\n}\n","import type { PoNotificationEntryData } from '@agimon-ai/po-core';\n\nimport { createPushTransport, signPushJwt } from './sync';\nimport type { NativePushSender, NativePushSenderOptions } from './type';\n\nconst MAX_PAYLOAD_BYTES = 4096;\nconst APNS_TOPIC = 'ai.po.app';\n// Only documented provider codes may enter diagnostics, never arbitrary response text.\nconst APNS_REASONS = new Set([\n 'BadCollapseId',\n 'BadDeviceToken',\n 'BadExpirationDate',\n 'BadMessageId',\n 'BadPriority',\n 'BadTopic',\n 'DeviceTokenNotForTopic',\n 'DuplicateHeaders',\n 'IdleTimeout',\n 'InvalidPushType',\n 'MissingDeviceToken',\n 'MissingTopic',\n 'PayloadEmpty',\n 'TopicDisallowed',\n 'BadCertificate',\n 'BadCertificateEnvironment',\n 'ExpiredProviderToken',\n 'Forbidden',\n 'InvalidProviderToken',\n 'MissingProviderToken',\n 'BadPath',\n 'MethodNotAllowed',\n 'Unregistered',\n 'PayloadTooLarge',\n 'TooManyProviderTokenUpdates',\n 'TooManyRequests',\n 'InternalServerError',\n 'ServiceUnavailable',\n 'Shutdown',\n]);\nconst OAUTH_URL = 'https://oauth2.googleapis.com/token';\nconst FCM_ERROR_TYPE = 'type.googleapis.com/google.firebase.fcm.v1.FcmError';\nconst encoder = new TextEncoder();\n\nfunction parse(body: string): Record<string, unknown> {\n try {\n const value: unknown = JSON.parse(body);\n return value && typeof value === 'object' ? (value as Record<string, unknown>) : {};\n } catch {\n return {};\n } // Malformed provider responses never invalidate registrations.\n}\n\nfunction payload(\n notification: PoNotificationEntryData,\n build: (text: { title: string; subtitle: string; body: string }) => object,\n): string {\n const text = { title: notification.title, subtitle: notification.subtitle, body: notification.body };\n let result = JSON.stringify(build(text));\n // Measure the full serialized envelope, including escaped text and the FCM token.\n for (const field of ['body', 'subtitle', 'title'] as const) {\n if (encoder.encode(result).length <= MAX_PAYLOAD_BYTES) break;\n const points = Array.from(text[field]);\n let low = 0;\n let high = points.length;\n while (low < high) {\n const middle = Math.ceil((low + high) / 2);\n text[field] = points.slice(0, middle).join('');\n if (encoder.encode(JSON.stringify(build(text))).length <= MAX_PAYLOAD_BYTES) low = middle;\n else high = middle - 1;\n }\n text[field] = points.slice(0, low).join('');\n result = JSON.stringify(build(text));\n }\n if (encoder.encode(result).length > MAX_PAYLOAD_BYTES) throw new Error('Push payload too large');\n return result;\n}\n\nexport function createNativePushSender(options: NativePushSenderOptions): NativePushSender {\n const transport = createPushTransport();\n const request = options.request ?? transport.request;\n const now = options.now ?? Date.now;\n const timeoutMs = Number.isFinite(options.timeoutMs) ? Math.max(1, Math.min(options.timeoutMs!, 30_000)) : 10_000;\n let closed = false;\n let apnsJwt: { value: string; expires: number } | undefined;\n let oauth: { value: string; expires: number } | undefined;\n let oauthPending: Promise<string> | undefined;\n\n async function accessToken(): Promise<string> {\n if (oauth && now() < oauth.expires) return oauth.value;\n if (oauthPending) return oauthPending;\n oauthPending = (async () => {\n const credentials = options.fcm!;\n const issued = Math.floor(now() / 1000);\n const assertion = signPushJwt(\n { alg: 'RS256', typ: 'JWT' },\n {\n iss: credentials.clientEmail,\n scope: 'https://www.googleapis.com/auth/firebase.messaging',\n aud: OAUTH_URL,\n iat: issued,\n exp: issued + 3600,\n },\n credentials.privateKey,\n 'RS256',\n );\n const response = await request({\n url: OAUTH_URL,\n headers: { 'content-type': 'application/x-www-form-urlencoded' },\n body: new URLSearchParams({ grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer', assertion }).toString(),\n timeoutMs,\n });\n const data = parse(response.body);\n if (\n response.status !== 200 ||\n typeof data.access_token !== 'string' ||\n !data.access_token ||\n typeof data.expires_in !== 'number' ||\n !Number.isFinite(data.expires_in) ||\n data.expires_in <= 0\n )\n throw new Error('OAuth failed');\n oauth = { value: data.access_token, expires: now() + Math.max(0, Math.min(data.expires_in, 3600) - 60) * 1000 };\n return oauth.value;\n })();\n try {\n return await oauthPending;\n } finally {\n oauthPending = undefined;\n }\n }\n\n return {\n async send(registration, notification, sessionId) {\n const provider = registration.platform === 'ios' ? 'apns' : 'fcm';\n if (closed || !options[provider]) {\n options.diagnostic?.({ provider, outcome: 'unavailable' });\n return { invalid: false };\n }\n try {\n const data = {\n ...(registration.hostRef ? { hostRef: registration.hostRef } : {}),\n ...(sessionId ? { sessionId } : {}),\n };\n let response;\n let reason: string | undefined;\n if (registration.platform === 'ios') {\n const credentials = options.apns!;\n if (!apnsJwt || now() >= apnsJwt.expires) {\n apnsJwt = {\n value: signPushJwt(\n { alg: 'ES256', kid: credentials.keyId },\n {\n iss: credentials.teamId,\n iat: Math.floor(now() / 1000),\n },\n credentials.key,\n 'ES256',\n ),\n expires: now() + 50 * 60_000,\n };\n }\n response = await request({\n url: `https://${registration.environment === 'development' ? 'api.sandbox.push.apple.com' : 'api.push.apple.com'}/3/device/${encodeURIComponent(registration.token)}`,\n http2: true,\n timeoutMs,\n headers: {\n authorization: `bearer ${apnsJwt.value}`,\n 'apns-topic': APNS_TOPIC,\n 'apns-push-type': 'alert',\n 'apns-priority': '10',\n 'apns-expiration': '0',\n 'content-type': 'application/json',\n },\n // ponytail: live alerts only; add a durable outbox if delayed delivery becomes a requirement.\n // Expo iOS reads custom remote data from userInfo.body. Keep data as the provider-neutral payload.\n body: payload(notification, (text) => ({ aps: { alert: text, sound: 'default' }, data, body: data })),\n });\n const value = parse(response.body).reason;\n if (typeof value === 'string' && APNS_REASONS.has(value)) reason = value;\n if (\n (response.status === 410 && reason === 'Unregistered') ||\n (response.status === 400 && reason === 'BadDeviceToken')\n ) {\n options.diagnostic?.({\n provider,\n outcome: 'invalid',\n status: response.status,\n ...(reason ? { reason } : {}),\n });\n return { invalid: true };\n }\n } else {\n const body = payload(notification, (text) => ({\n message: {\n token: registration.token,\n data,\n notification: { title: text.title, body: [text.subtitle, text.body].filter(Boolean).join('\\n') },\n // ponytail: zero TTL, no offline delivery; an outbox would own delayed sends.\n android: { ttl: '0s', priority: 'HIGH', notification: { channel_id: 'po-notifications' } },\n },\n }));\n const token = await accessToken();\n if (closed) return { invalid: false };\n response = await request({\n url: `https://fcm.googleapis.com/v1/projects/${encodeURIComponent(options.fcm!.projectId)}/messages:send`,\n headers: { authorization: `Bearer ${token}`, 'content-type': 'application/json' },\n body,\n timeoutMs,\n });\n const error = parse(response.body).error;\n if (\n response.status === 404 &&\n error &&\n typeof error === 'object' &&\n 'details' in error &&\n Array.isArray(error.details) &&\n error.details.some(\n (detail: unknown) =>\n detail &&\n typeof detail === 'object' &&\n '@type' in detail &&\n detail['@type'] === FCM_ERROR_TYPE &&\n 'errorCode' in detail &&\n detail.errorCode === 'UNREGISTERED',\n )\n ) {\n options.diagnostic?.({\n provider,\n outcome: 'invalid',\n status: response.status,\n ...(reason ? { reason } : {}),\n });\n return { invalid: true };\n }\n }\n if (response.status < 200 || response.status >= 300)\n options.diagnostic?.({ provider, outcome: 'failed', status: response.status, ...(reason ? { reason } : {}) });\n } catch {\n // Never expose provider bodies, credentials, device tokens, or network errors.\n options.diagnostic?.({ provider, outcome: 'failed' });\n }\n return { invalid: false };\n },\n close() {\n closed = true;\n apnsJwt = undefined;\n oauth = undefined;\n transport.close();\n },\n };\n}\n","const DEFAULT_ASK_USER_BODY = 'The agent is waiting for your feedback.';\nconst RPC_MODE = 'rpc';\n\nexport interface AttentionState {\n agentRunning: boolean;\n askUserBlocked: boolean;\n}\n\nexport interface ShellSurface {\n hasUI: boolean;\n mode?: string;\n}\n\n/**\n * A dialog is worth interrupting the user for only while the agent holds the turn.\n *\n * Outside a run the user opened the dialog themselves and is already looking at\n * it. An ask-user prompt is announced by its own event, so the dialog it then\n * opens must stay silent or the same question notifies twice.\n */\nexport function warrantsAttentionNotification({ agentRunning, askUserBlocked }: AttentionState): boolean {\n return agentRunning && !askUserBlocked;\n}\n\n/** A queued follow-up means the agent keeps working, so the run has not stopped for the user. */\nexport function warrantsSettledNotification(hasPendingMessages: boolean): boolean {\n return !hasPendingMessages;\n}\n\n/** Terminal title escapes only mean something on an attached terminal; RPC output stays clean. */\nexport function supportsShellTitle({ hasUI, mode }: ShellSurface): boolean {\n return hasUI && mode !== RPC_MODE;\n}\n\n/** The question an ask-user prompt is blocking on, or a stand-in when it asked none. */\nexport function askUserPromptBody(questions: readonly { question: string }[]): string {\n return questions[0]?.question ?? DEFAULT_ASK_USER_BODY;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,MAAa,iBAAiB;CAAC;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;AAAG;;AAI/E,SAAgB,kCAAwD;CACtE,IAAI,aAAa;CACjB,IAAI;CACJ,MAAM,sBAAsB;EAC1B,IAAI,OAAO,cAAc,KAAK;EAC9B,QAAQ,KAAA;EACR,aAAa;CACf;CAEA,OAAO;EACL,IAAI,OAAO,OAAO;GAChB,cAAc;GACd,MAAM,KAAK;EACb;EACA,MAAM,OAAO,OAAO;GAClB,cAAc;GACd,MAAM,eAAe;IACnB,MAAM,GAAG,eAAe,aAAa,eAAe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a;OACnB;OACA,SAAS;OACT,QAAQ,SAAS;OACjB,GAAI,SAAS,EAAE,OAAO,IAAI,CAAC;MAC7B,CAAC;MACD,OAAO,EAAE,SAAS,KAAK;KACzB;IACF;IACA,IAAI,SAAS,SAAS,OAAO,SAAS,UAAU,KAC9C,QAAQ,aAAa;KAAE;KAAU,SAAS;KAAU,QAAQ,SAAS;KAAQ,GAAI,SAAS,EAAE,OAAO,IAAI,CAAC;IAAG,CAAC;GAChH,QAAQ;IAEN,QAAQ,aAAa;KAAE;KAAU,SAAS;IAAS,CAAC;GACtD;GACA,OAAO,EAAE,SAAS,MAAM;EAC1B;EACA,QAAQ;GACN,SAAS;GACT,UAAU,KAAA;GACV,QAAQ,KAAA;GACR,UAAU,MAAM;EAClB;CACF;AACF;;;AC1PA,MAAM,wBAAwB;AAC9B,MAAM,WAAW;;;;;;;;AAmBjB,SAAgB,8BAA8B,EAAE,cAAc,kBAA2C;CACvG,OAAO,gBAAgB,CAAC;AAC1B;;AAGA,SAAgB,4BAA4B,oBAAsC;CAChF,OAAO,CAAC;AACV;;AAGA,SAAgB,mBAAmB,EAAE,OAAO,QAA+B;CACzE,OAAO,SAAS,SAAS;AAC3B;;AAGA,SAAgB,kBAAkB,WAAoD;CACpF,OAAO,UAAU,EAAE,EAAE,YAAY;AACnC"}
|
package/dist/index.d.mts
CHANGED
|
@@ -68,10 +68,12 @@ export declare function sendSystemNotification(pi: NotificationExecutor, notific
|
|
|
68
68
|
type NativePushRegistration = {
|
|
69
69
|
platform: 'ios';
|
|
70
70
|
token: string;
|
|
71
|
+
hostRef?: string;
|
|
71
72
|
environment: 'development' | 'production';
|
|
72
73
|
} | {
|
|
73
74
|
platform: 'android';
|
|
74
75
|
token: string;
|
|
76
|
+
hostRef?: string;
|
|
75
77
|
};
|
|
76
78
|
interface NativePushRequest {
|
|
77
79
|
url: string;
|
|
@@ -100,12 +102,13 @@ interface NativePushSenderOptions {
|
|
|
100
102
|
timeoutMs?: number;
|
|
101
103
|
diagnostic?: (event: {
|
|
102
104
|
provider: 'apns' | 'fcm';
|
|
103
|
-
outcome: 'failed' | 'unavailable';
|
|
105
|
+
outcome: 'failed' | 'unavailable' | 'invalid';
|
|
104
106
|
status?: number;
|
|
107
|
+
reason?: string;
|
|
105
108
|
}) => void;
|
|
106
109
|
}
|
|
107
110
|
interface NativePushSender {
|
|
108
|
-
send(registration: NativePushRegistration, notification: PoNotificationEntryData): Promise<{
|
|
111
|
+
send(registration: NativePushRegistration, notification: PoNotificationEntryData, sessionId?: string): Promise<{
|
|
109
112
|
invalid: boolean;
|
|
110
113
|
}>;
|
|
111
114
|
close(): void;
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types/notifications.ts","../src/services/shellTitleController/mainThread.ts","../src/services/shellTitleController/index.ts","../src/services/systemNotification/index.ts","../src/services/nativePushSender/type.ts","../src/services/nativePushSender/index.ts","../src/services/notificationPolicy/index.ts","../src/services/notificationText/index.ts"],"mappings":";;UAAiB;;EAEf,kBAAkB;EAClB,cAAc,OAAO;;UAGN;EACf,KAAK,iBAAiB,gBAAgB;IAAW;MAAoB;IAAU;;;;KAIrE,cAAc;;KAGd;;UAGK;EACf,QAAQ;EACR;;;;;;;;;;UAWe;EACf,IAAI,eAAe,OAAO;EAC1B,MAAM,eAAe,OAAO;EAC5B,KAAK,eAAe,OAAO;EAC3B,QAAQ,eAAe,OAAO;;;UAIf;EACf;EACA;EACA;;;;;wBCnCc,mCAAmC;;;;;;;;wBCsCnC,+BAA+B;;;;;;;;;;wBCjBzB,uBACpB,IAAI,sBACJ,cAAc,qBACd,oBACC;;;KC7BS;EACN;EAAiB;EAAe;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types/notifications.ts","../src/services/shellTitleController/mainThread.ts","../src/services/shellTitleController/index.ts","../src/services/systemNotification/index.ts","../src/services/nativePushSender/type.ts","../src/services/nativePushSender/index.ts","../src/services/notificationPolicy/index.ts","../src/services/notificationText/index.ts"],"mappings":";;UAAiB;;EAEf,kBAAkB;EAClB,cAAc,OAAO;;UAGN;EACf,KAAK,iBAAiB,gBAAgB;IAAW;MAAoB;IAAU;;;;KAIrE,cAAc;;KAGd;;UAGK;EACf,QAAQ;EACR;;;;;;;;;;UAWe;EACf,IAAI,eAAe,OAAO;EAC1B,MAAM,eAAe,OAAO;EAC5B,KAAK,eAAe,OAAO;EAC3B,QAAQ,eAAe,OAAO;;;UAIf;EACf;EACA;EACA;;;;;wBCnCc,mCAAmC;;;;;;;;wBCsCnC,+BAA+B;;;;;;;;;;wBCjBzB,uBACpB,IAAI,sBACJ,cAAc,qBACd,oBACC;;;KC7BS;EACN;EAAiB;EAAe;EAAkB;;EAClD;EAAqB;EAAe;;UAEzB;EACf;EACA,SAAS;EACT;EACA;EACA;;UAEe;EACf;EACA;;UAEe;EACf;IAAS;IAAa;IAAe;;EACrC;IAAQ;IAAqB;IAAoB;;EACjD;EACA,WAAW,SAAS,sBAAsB,QAAQ;EAClD;EACA,cAAc;IACZ;IACA;IACA;IACA;;;UAGa;EACf,KACE,cAAc,wBACd,cAAc,yBACd,qBACC;IAAU;;EACb;;;;wBCyCc,uBAAuB,SAAS,0BAA0B;;;UC1EzD;EACf;EACA;;UAGe;EACf;EACA;;;;;;;;;wBAUc,gCAAgC,cAAc,kBAAkB;;wBAKhE,4BAA4B;;wBAK5B,qBAAqB,OAAO,QAAQ;;wBAKpC,kBAAkB;EAAsB;;;;;wBCZxC,YAAY;UAKX;EACf;EACA;EACA;;;;;;;;wBASc,gBAAgB,KAAK,aAAa,UAAU;;wBAS5C,iBAAiB;;wBAKjB,sBAAsB,eAAe;;wBAKrC,sBAAsB,KAAK;EAAiB;EAAa;IAAyB"}
|
package/dist/index.mjs
CHANGED
|
@@ -150,12 +150,12 @@ function createWorkerTitleController() {
|
|
|
150
150
|
//#endregion
|
|
151
151
|
//#region src/services/notificationText/index.ts
|
|
152
152
|
const ATTENTION_SUBTITLE = "Approval or feedback required";
|
|
153
|
-
const ATTENTION_TITLE = "
|
|
153
|
+
const ATTENTION_TITLE = "Po needs your input";
|
|
154
154
|
const ELLIPSIS = "…";
|
|
155
155
|
const MAX_BODY_LENGTH = 240;
|
|
156
156
|
const MAX_PROMPT_TITLE_LENGTH = 36;
|
|
157
157
|
const SETTLED_BODY = "The agent finished its work and is waiting for you.";
|
|
158
|
-
const SETTLED_TITLE = "
|
|
158
|
+
const SETTLED_TITLE = "Po finished";
|
|
159
159
|
const SHELL_TITLE_SEPARATOR = " - ";
|
|
160
160
|
const SHELL_TITLE_PREFIX = "π";
|
|
161
161
|
function collapseWhitespace(value) {
|
|
@@ -327,6 +327,37 @@ function createPushTransport() {
|
|
|
327
327
|
//#region src/services/nativePushSender/index.ts
|
|
328
328
|
const MAX_PAYLOAD_BYTES = 4096;
|
|
329
329
|
const APNS_TOPIC = "ai.po.app";
|
|
330
|
+
const APNS_REASONS = /* @__PURE__ */ new Set([
|
|
331
|
+
"BadCollapseId",
|
|
332
|
+
"BadDeviceToken",
|
|
333
|
+
"BadExpirationDate",
|
|
334
|
+
"BadMessageId",
|
|
335
|
+
"BadPriority",
|
|
336
|
+
"BadTopic",
|
|
337
|
+
"DeviceTokenNotForTopic",
|
|
338
|
+
"DuplicateHeaders",
|
|
339
|
+
"IdleTimeout",
|
|
340
|
+
"InvalidPushType",
|
|
341
|
+
"MissingDeviceToken",
|
|
342
|
+
"MissingTopic",
|
|
343
|
+
"PayloadEmpty",
|
|
344
|
+
"TopicDisallowed",
|
|
345
|
+
"BadCertificate",
|
|
346
|
+
"BadCertificateEnvironment",
|
|
347
|
+
"ExpiredProviderToken",
|
|
348
|
+
"Forbidden",
|
|
349
|
+
"InvalidProviderToken",
|
|
350
|
+
"MissingProviderToken",
|
|
351
|
+
"BadPath",
|
|
352
|
+
"MethodNotAllowed",
|
|
353
|
+
"Unregistered",
|
|
354
|
+
"PayloadTooLarge",
|
|
355
|
+
"TooManyProviderTokenUpdates",
|
|
356
|
+
"TooManyRequests",
|
|
357
|
+
"InternalServerError",
|
|
358
|
+
"ServiceUnavailable",
|
|
359
|
+
"Shutdown"
|
|
360
|
+
]);
|
|
330
361
|
const OAUTH_URL = "https://oauth2.googleapis.com/token";
|
|
331
362
|
const FCM_ERROR_TYPE = "type.googleapis.com/google.firebase.fcm.v1.FcmError";
|
|
332
363
|
const encoder = new TextEncoder();
|
|
@@ -415,7 +446,7 @@ function createNativePushSender(options) {
|
|
|
415
446
|
}
|
|
416
447
|
}
|
|
417
448
|
return {
|
|
418
|
-
async send(registration, notification) {
|
|
449
|
+
async send(registration, notification, sessionId) {
|
|
419
450
|
const provider = registration.platform === "ios" ? "apns" : "fcm";
|
|
420
451
|
if (closed || !options[provider]) {
|
|
421
452
|
options.diagnostic?.({
|
|
@@ -425,7 +456,12 @@ function createNativePushSender(options) {
|
|
|
425
456
|
return { invalid: false };
|
|
426
457
|
}
|
|
427
458
|
try {
|
|
459
|
+
const data = {
|
|
460
|
+
...registration.hostRef ? { hostRef: registration.hostRef } : {},
|
|
461
|
+
...sessionId ? { sessionId } : {}
|
|
462
|
+
};
|
|
428
463
|
let response;
|
|
464
|
+
let reason;
|
|
429
465
|
if (registration.platform === "ios") {
|
|
430
466
|
const credentials = options.apns;
|
|
431
467
|
if (!apnsJwt || now() >= apnsJwt.expires) apnsJwt = {
|
|
@@ -450,16 +486,30 @@ function createNativePushSender(options) {
|
|
|
450
486
|
"apns-expiration": "0",
|
|
451
487
|
"content-type": "application/json"
|
|
452
488
|
},
|
|
453
|
-
body: payload(notification, (text) => ({
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
489
|
+
body: payload(notification, (text) => ({
|
|
490
|
+
aps: {
|
|
491
|
+
alert: text,
|
|
492
|
+
sound: "default"
|
|
493
|
+
},
|
|
494
|
+
data,
|
|
495
|
+
body: data
|
|
496
|
+
}))
|
|
457
497
|
});
|
|
458
|
-
const
|
|
459
|
-
if (
|
|
498
|
+
const value = parse(response.body).reason;
|
|
499
|
+
if (typeof value === "string" && APNS_REASONS.has(value)) reason = value;
|
|
500
|
+
if (response.status === 410 && reason === "Unregistered" || response.status === 400 && reason === "BadDeviceToken") {
|
|
501
|
+
options.diagnostic?.({
|
|
502
|
+
provider,
|
|
503
|
+
outcome: "invalid",
|
|
504
|
+
status: response.status,
|
|
505
|
+
...reason ? { reason } : {}
|
|
506
|
+
});
|
|
507
|
+
return { invalid: true };
|
|
508
|
+
}
|
|
460
509
|
} else {
|
|
461
510
|
const body = payload(notification, (text) => ({ message: {
|
|
462
511
|
token: registration.token,
|
|
512
|
+
data,
|
|
463
513
|
notification: {
|
|
464
514
|
title: text.title,
|
|
465
515
|
body: [text.subtitle, text.body].filter(Boolean).join("\n")
|
|
@@ -482,12 +532,21 @@ function createNativePushSender(options) {
|
|
|
482
532
|
timeoutMs
|
|
483
533
|
});
|
|
484
534
|
const error = parse(response.body).error;
|
|
485
|
-
if (response.status === 404 && error && typeof error === "object" && "details" in error && Array.isArray(error.details) && error.details.some((detail) => detail && typeof detail === "object" && "@type" in detail && detail["@type"] === FCM_ERROR_TYPE && "errorCode" in detail && detail.errorCode === "UNREGISTERED"))
|
|
535
|
+
if (response.status === 404 && error && typeof error === "object" && "details" in error && Array.isArray(error.details) && error.details.some((detail) => detail && typeof detail === "object" && "@type" in detail && detail["@type"] === FCM_ERROR_TYPE && "errorCode" in detail && detail.errorCode === "UNREGISTERED")) {
|
|
536
|
+
options.diagnostic?.({
|
|
537
|
+
provider,
|
|
538
|
+
outcome: "invalid",
|
|
539
|
+
status: response.status,
|
|
540
|
+
...reason ? { reason } : {}
|
|
541
|
+
});
|
|
542
|
+
return { invalid: true };
|
|
543
|
+
}
|
|
486
544
|
}
|
|
487
545
|
if (response.status < 200 || response.status >= 300) options.diagnostic?.({
|
|
488
546
|
provider,
|
|
489
547
|
outcome: "failed",
|
|
490
|
-
status: response.status
|
|
548
|
+
status: response.status,
|
|
549
|
+
...reason ? { reason } : {}
|
|
491
550
|
});
|
|
492
551
|
} catch {
|
|
493
552
|
options.diagnostic?.({
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/services/shellTitleController/mainThread.ts","../src/services/shellTitleController/index.ts","../src/services/notificationText/index.ts","../src/services/systemNotification/index.ts","../src/services/nativePushSender/sync.ts","../src/services/nativePushSender/index.ts","../src/services/notificationPolicy/index.ts"],"sourcesContent":["import type { ShellTitleController } from '../../types/notifications';\n\nexport const BRAILLE_FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\nexport const TITLE_FRAME_INTERVAL_MS = 80;\n\n/** Animates on the main thread, for hosts where a worker could not be started. */\nexport function createMainThreadTitleController(): ShellTitleController {\n let frameIndex = 0;\n let timer: ReturnType<typeof setInterval> | undefined;\n const stopAnimation = () => {\n if (timer) clearInterval(timer);\n timer = undefined;\n frameIndex = 0;\n };\n\n return {\n set(title, write) {\n stopAnimation();\n write(title);\n },\n start(title, write) {\n stopAnimation();\n const render = () => {\n write(`${BRAILLE_FRAMES[frameIndex % BRAILLE_FRAMES.length]} ${title}`);\n frameIndex += 1;\n };\n render();\n timer = setInterval(render, TITLE_FRAME_INTERVAL_MS);\n },\n stop(title, write) {\n stopAnimation();\n write(title);\n },\n dispose(title, write) {\n stopAnimation();\n write(title);\n },\n };\n}\n","import { Worker } from 'node:worker_threads';\n\nimport type { ShellTitleCommand, ShellTitleController, WriteTitle } from '../../types/notifications';\nimport { BRAILLE_FRAMES, TITLE_FRAME_INTERVAL_MS, createMainThreadTitleController } from './mainThread';\n\nexport { createMainThreadTitleController } from './mainThread';\n/**\n * The animator runs off the main thread so a busy agent turn cannot stall the\n * spinner. It is an inline eval source rather than a shipped file because the\n * package is bundled per entry, and a separate worker module would have to be\n * located on disk at runtime.\n */\nconst TITLE_WORKER_SOURCE = `\nconst { writeSync } = require('node:fs');\nconst { parentPort, workerData } = require('node:worker_threads');\nlet frameIndex = 0;\nlet timer;\nconst writeTitle = (title) => writeSync(1, '\\\\u001b]0;' + title + '\\\\u0007');\nconst stop = () => {\n if (timer) clearInterval(timer);\n timer = undefined;\n frameIndex = 0;\n};\nparentPort.on('message', (command) => {\n stop();\n if (command.action === 'start') {\n const render = () => {\n writeTitle(workerData.frames[frameIndex % workerData.frames.length] + ' ' + command.title);\n frameIndex += 1;\n };\n render();\n timer = setInterval(render, workerData.intervalMs);\n return;\n }\n writeTitle(command.title);\n if (command.action === 'dispose') parentPort.close();\n});\n`;\n\n/**\n * Animates from a worker thread, replaying the last command on the main thread\n * if the worker never started, failed, or exited under us. The worker is\n * unreferenced so a pending frame never holds the process open.\n */\nexport function createWorkerTitleController(): ShellTitleController {\n const fallback = createMainThreadTitleController();\n let lastCommand: ShellTitleCommand | undefined;\n let lastWrite: WriteTitle | undefined;\n let worker: Worker | undefined;\n\n const fallBack = () => {\n worker = undefined;\n if (!lastCommand || !lastWrite) return;\n fallback[lastCommand.action](lastCommand.title, lastWrite);\n };\n\n try {\n const titleWorker = new Worker(TITLE_WORKER_SOURCE, {\n eval: true,\n workerData: { frames: BRAILLE_FRAMES, intervalMs: TITLE_FRAME_INTERVAL_MS },\n });\n titleWorker.unref();\n titleWorker.once('error', fallBack);\n titleWorker.once('exit', (code) => {\n if (code !== 0 && worker === titleWorker) fallBack();\n });\n worker = titleWorker;\n } catch {\n // Workers are unavailable on this host, which the main-thread animator covers.\n worker = undefined;\n }\n\n const dispatch = (command: ShellTitleCommand, write: WriteTitle) => {\n lastCommand = command;\n lastWrite = write;\n if (!worker) {\n fallback[command.action](command.title, write);\n return;\n }\n try {\n worker.postMessage(command);\n } catch {\n // The worker closed between the last frame and this command.\n fallBack();\n }\n };\n\n return {\n set: (title, write) => dispatch({ action: 'set', title }, write),\n start: (title, write) => dispatch({ action: 'start', title }, write),\n stop: (title, write) => dispatch({ action: 'stop', title }, write),\n dispose: (title, write) => dispatch({ action: 'dispose', title }, write),\n };\n}\n","import path from 'node:path';\n\nimport type { DesktopNotification } from '../../types/notifications';\n\nconst ATTENTION_SUBTITLE = 'Approval or feedback required';\nconst ATTENTION_TITLE = 'Pi needs your input';\nconst ELLIPSIS = '…';\nconst MAX_BODY_LENGTH = 240;\nconst MAX_PROMPT_TITLE_LENGTH = 36;\nconst SETTLED_BODY = 'The agent finished its work and is waiting for you.';\nconst SETTLED_TITLE = 'Pi finished';\nconst SHELL_TITLE_SEPARATOR = ' - ';\nconst SHELL_TITLE_PREFIX = 'π';\n\nfunction collapseWhitespace(value: string): string {\n return value.replace(/\\s+/g, ' ').trim();\n}\n\nfunction truncate(value: string, maxLength: number): string {\n return value.length > maxLength ? `${value.slice(0, maxLength - 1)}${ELLIPSIS}` : value;\n}\n\n/** The first user prompt, shortened to fit a shell tab. A blank prompt names nothing. */\nexport function promptTitle(prompt: string): string | undefined {\n const normalized = collapseWhitespace(prompt);\n return normalized ? truncate(normalized, MAX_PROMPT_TITLE_LENGTH) : undefined;\n}\n\nexport interface ShellTabTitleInput {\n cwd: string;\n sessionName?: string;\n prompt?: string;\n}\n\n/**\n * The idle shell-tab title: `π - <label> - <repository>`.\n *\n * The session name wins over the first prompt because the user chose it. With\n * neither, the repository alone still tells two tabs apart.\n */\nexport function shellTabTitle({ cwd, sessionName, prompt }: ShellTabTitleInput): string {\n const repository = path.basename(cwd);\n const label = sessionName ?? prompt;\n return label\n ? `${SHELL_TITLE_PREFIX}${SHELL_TITLE_SEPARATOR}${label}${SHELL_TITLE_SEPARATOR}${repository}`\n : `${SHELL_TITLE_PREFIX}${SHELL_TITLE_SEPARATOR}${repository}`;\n}\n\n/** Notification bodies are one line in a system panel, so they collapse and truncate. */\nexport function notificationBody(body: string): string {\n return truncate(collapseWhitespace(body), MAX_BODY_LENGTH);\n}\n\n/** Sent while the agent holds the turn and something is blocking on the user. */\nexport function attentionNotification(body: string): DesktopNotification {\n return { title: ATTENTION_TITLE, subtitle: ATTENTION_SUBTITLE, body };\n}\n\n/** Sent once a run has stopped, subtitled with whichever name the user recognises. */\nexport function settledNotification({ cwd, sessionName }: { cwd: string; sessionName?: string }): DesktopNotification {\n return { title: SETTLED_TITLE, subtitle: sessionName ?? path.basename(cwd), body: SETTLED_BODY };\n}\n","import type { DesktopNotification, NotificationExecutor } from '../../types/notifications';\nimport { notificationBody } from '../notificationText';\n\nconst CMUX_COMMAND = 'cmux';\nconst COMMAND_TIMEOUT_MS = 3_000;\nconst DARWIN_PLATFORM = 'darwin';\nconst OSASCRIPT_COMMAND = 'osascript';\nconst OSASCRIPT_EXPRESSION_FLAG = '-e';\n\nasync function execute(pi: NotificationExecutor, command: string, args: string[]): Promise<boolean> {\n try {\n const result = await pi.exec(command, args, { timeout: COMMAND_TIMEOUT_MS });\n return result.code === 0;\n } catch {\n // A notifier that is not installed is the ordinary case, not a fault: report\n // \"not delivered\" and let the caller decide whether another one exists.\n return false;\n }\n}\n\n/**\n * Delivers one desktop notification on a best-effort basis.\n *\n * cmux is tried first because it routes the notification to the window the\n * session actually lives in. Only macOS has a second option worth attempting,\n * and a host with neither stays silent rather than failing the turn.\n */\nexport async function sendSystemNotification(\n pi: NotificationExecutor,\n notification: DesktopNotification,\n platform: string = process.platform,\n): Promise<void> {\n const body = notificationBody(notification.body);\n const sentToCmux = await execute(pi, CMUX_COMMAND, [\n 'notify',\n '--title',\n notification.title,\n '--subtitle',\n notification.subtitle,\n '--body',\n body,\n ]);\n if (sentToCmux || platform !== DARWIN_PLATFORM) return;\n\n await execute(pi, OSASCRIPT_COMMAND, [\n OSASCRIPT_EXPRESSION_FLAG,\n 'on run argv',\n OSASCRIPT_EXPRESSION_FLAG,\n 'display notification (item 3 of argv) with title (item 1 of argv) subtitle (item 2 of argv)',\n OSASCRIPT_EXPRESSION_FLAG,\n 'end run',\n notification.title,\n notification.subtitle,\n body,\n ]);\n}\n","import { sign } from 'node:crypto';\nimport { connect } from 'node:http2';\nimport { request } from 'node:https';\n\nimport type { NativePushRequest, NativePushResponse } from './type';\n\nconst MAX_RESPONSE_BYTES = 65_536;\n\nexport function signPushJwt(header: object, claims: object, key: string, algorithm: 'ES256' | 'RS256'): string {\n const input = [header, claims].map((part) => Buffer.from(JSON.stringify(part)).toString('base64url')).join('.');\n const signature = sign('sha256', Buffer.from(input), { key, dsaEncoding: 'ieee-p1363' });\n // APNs requires the raw P1363 ECDSA signature, not ASN.1 DER.\n if (algorithm === 'ES256' && signature.length !== 64) throw new Error('Invalid signing key');\n return `${input}.${signature.toString('base64url')}`;\n}\n\nexport function createPushTransport() {\n const pending = new Set<() => void>();\n return {\n request(this: void, input: NativePushRequest): Promise<NativePushResponse> {\n return new Promise((resolve, reject) => {\n const url = new URL(input.url);\n let size = 0;\n const chunks: Buffer[] = [];\n let done = false;\n let dispose = () => {};\n const finish = (error?: Error, status = 0) => {\n if (done) return;\n done = true;\n clearTimeout(timer);\n pending.delete(cancel);\n dispose();\n if (error) reject(error);\n else resolve({ status, body: Buffer.concat(chunks).toString('utf8') });\n };\n const cancel = () => finish(new Error('Push request cancelled'));\n const timer = setTimeout(() => finish(new Error('Push request timed out')), input.timeoutMs);\n pending.add(cancel);\n const data = (chunk: Buffer) => {\n size += chunk.length;\n if (size > MAX_RESPONSE_BYTES) finish(new Error('Push response too large'));\n else chunks.push(Buffer.from(chunk));\n };\n if (input.http2) {\n const session = connect(url.origin);\n dispose = () => session.destroy();\n session.on('error', (error) => finish(error));\n const stream = session.request({ ':method': 'POST', ':path': url.pathname, ...input.headers });\n let status = 0;\n stream.on('response', (headers) => {\n status = Number(headers[':status']);\n });\n stream.on('data', data);\n stream.on('error', (error) => finish(error));\n stream.on('end', () => finish(undefined, status));\n stream.end(input.body);\n } else {\n const req = request(url, { method: 'POST', headers: input.headers }, (response) => {\n response.on('data', data);\n response.on('error', (error) => finish(error));\n response.on('end', () => finish(undefined, response.statusCode));\n });\n dispose = () => req.destroy();\n req.on('error', (error) => finish(error));\n req.end(input.body);\n }\n });\n },\n close() {\n for (const cancel of pending) cancel();\n },\n };\n}\n","import type { PoNotificationEntryData } from '@agimon-ai/po-core';\n\nimport { createPushTransport, signPushJwt } from './sync';\nimport type { NativePushSender, NativePushSenderOptions } from './type';\n\nconst MAX_PAYLOAD_BYTES = 4096;\nconst APNS_TOPIC = 'ai.po.app';\nconst OAUTH_URL = 'https://oauth2.googleapis.com/token';\nconst FCM_ERROR_TYPE = 'type.googleapis.com/google.firebase.fcm.v1.FcmError';\nconst encoder = new TextEncoder();\n\nfunction parse(body: string): Record<string, unknown> {\n try {\n const value: unknown = JSON.parse(body);\n return value && typeof value === 'object' ? (value as Record<string, unknown>) : {};\n } catch {\n return {};\n } // Malformed provider responses never invalidate registrations.\n}\n\nfunction payload(\n notification: PoNotificationEntryData,\n build: (text: { title: string; subtitle: string; body: string }) => object,\n): string {\n const text = { title: notification.title, subtitle: notification.subtitle, body: notification.body };\n let result = JSON.stringify(build(text));\n // Measure the full serialized envelope, including escaped text and the FCM token.\n for (const field of ['body', 'subtitle', 'title'] as const) {\n if (encoder.encode(result).length <= MAX_PAYLOAD_BYTES) break;\n const points = Array.from(text[field]);\n let low = 0;\n let high = points.length;\n while (low < high) {\n const middle = Math.ceil((low + high) / 2);\n text[field] = points.slice(0, middle).join('');\n if (encoder.encode(JSON.stringify(build(text))).length <= MAX_PAYLOAD_BYTES) low = middle;\n else high = middle - 1;\n }\n text[field] = points.slice(0, low).join('');\n result = JSON.stringify(build(text));\n }\n if (encoder.encode(result).length > MAX_PAYLOAD_BYTES) throw new Error('Push payload too large');\n return result;\n}\n\nexport function createNativePushSender(options: NativePushSenderOptions): NativePushSender {\n const transport = createPushTransport();\n const request = options.request ?? transport.request;\n const now = options.now ?? Date.now;\n const timeoutMs = Number.isFinite(options.timeoutMs) ? Math.max(1, Math.min(options.timeoutMs!, 30_000)) : 10_000;\n let closed = false;\n let apnsJwt: { value: string; expires: number } | undefined;\n let oauth: { value: string; expires: number } | undefined;\n let oauthPending: Promise<string> | undefined;\n\n async function accessToken(): Promise<string> {\n if (oauth && now() < oauth.expires) return oauth.value;\n if (oauthPending) return oauthPending;\n oauthPending = (async () => {\n const credentials = options.fcm!;\n const issued = Math.floor(now() / 1000);\n const assertion = signPushJwt(\n { alg: 'RS256', typ: 'JWT' },\n {\n iss: credentials.clientEmail,\n scope: 'https://www.googleapis.com/auth/firebase.messaging',\n aud: OAUTH_URL,\n iat: issued,\n exp: issued + 3600,\n },\n credentials.privateKey,\n 'RS256',\n );\n const response = await request({\n url: OAUTH_URL,\n headers: { 'content-type': 'application/x-www-form-urlencoded' },\n body: new URLSearchParams({ grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer', assertion }).toString(),\n timeoutMs,\n });\n const data = parse(response.body);\n if (\n response.status !== 200 ||\n typeof data.access_token !== 'string' ||\n !data.access_token ||\n typeof data.expires_in !== 'number' ||\n !Number.isFinite(data.expires_in) ||\n data.expires_in <= 0\n )\n throw new Error('OAuth failed');\n oauth = { value: data.access_token, expires: now() + Math.max(0, Math.min(data.expires_in, 3600) - 60) * 1000 };\n return oauth.value;\n })();\n try {\n return await oauthPending;\n } finally {\n oauthPending = undefined;\n }\n }\n\n return {\n async send(registration, notification) {\n const provider = registration.platform === 'ios' ? 'apns' : 'fcm';\n if (closed || !options[provider]) {\n options.diagnostic?.({ provider, outcome: 'unavailable' });\n return { invalid: false };\n }\n try {\n let response;\n if (registration.platform === 'ios') {\n const credentials = options.apns!;\n if (!apnsJwt || now() >= apnsJwt.expires) {\n apnsJwt = {\n value: signPushJwt(\n { alg: 'ES256', kid: credentials.keyId },\n {\n iss: credentials.teamId,\n iat: Math.floor(now() / 1000),\n },\n credentials.key,\n 'ES256',\n ),\n expires: now() + 50 * 60_000,\n };\n }\n response = await request({\n url: `https://${registration.environment === 'development' ? 'api.sandbox.push.apple.com' : 'api.push.apple.com'}/3/device/${encodeURIComponent(registration.token)}`,\n http2: true,\n timeoutMs,\n headers: {\n authorization: `bearer ${apnsJwt.value}`,\n 'apns-topic': APNS_TOPIC,\n 'apns-push-type': 'alert',\n 'apns-priority': '10',\n 'apns-expiration': '0',\n 'content-type': 'application/json',\n },\n // ponytail: live alerts only; add a durable outbox if delayed delivery becomes a requirement.\n body: payload(notification, (text) => ({ aps: { alert: text, sound: 'default' } })),\n });\n const reason = parse(response.body).reason;\n if (\n (response.status === 410 && reason === 'Unregistered') ||\n (response.status === 400 && reason === 'BadDeviceToken')\n )\n return { invalid: true };\n } else {\n const body = payload(notification, (text) => ({\n message: {\n token: registration.token,\n notification: { title: text.title, body: [text.subtitle, text.body].filter(Boolean).join('\\n') },\n // ponytail: zero TTL, no offline delivery; an outbox would own delayed sends.\n android: { ttl: '0s', priority: 'HIGH', notification: { channel_id: 'po-notifications' } },\n },\n }));\n const token = await accessToken();\n if (closed) return { invalid: false };\n response = await request({\n url: `https://fcm.googleapis.com/v1/projects/${encodeURIComponent(options.fcm!.projectId)}/messages:send`,\n headers: { authorization: `Bearer ${token}`, 'content-type': 'application/json' },\n body,\n timeoutMs,\n });\n const error = parse(response.body).error;\n if (\n response.status === 404 &&\n error &&\n typeof error === 'object' &&\n 'details' in error &&\n Array.isArray(error.details) &&\n error.details.some(\n (detail: unknown) =>\n detail &&\n typeof detail === 'object' &&\n '@type' in detail &&\n detail['@type'] === FCM_ERROR_TYPE &&\n 'errorCode' in detail &&\n detail.errorCode === 'UNREGISTERED',\n )\n )\n return { invalid: true };\n }\n if (response.status < 200 || response.status >= 300)\n options.diagnostic?.({ provider, outcome: 'failed', status: response.status });\n } catch {\n // Never expose provider bodies, credentials, device tokens, or network errors.\n options.diagnostic?.({ provider, outcome: 'failed' });\n }\n return { invalid: false };\n },\n close() {\n closed = true;\n apnsJwt = undefined;\n oauth = undefined;\n transport.close();\n },\n };\n}\n","const DEFAULT_ASK_USER_BODY = 'The agent is waiting for your feedback.';\nconst RPC_MODE = 'rpc';\n\nexport interface AttentionState {\n agentRunning: boolean;\n askUserBlocked: boolean;\n}\n\nexport interface ShellSurface {\n hasUI: boolean;\n mode?: string;\n}\n\n/**\n * A dialog is worth interrupting the user for only while the agent holds the turn.\n *\n * Outside a run the user opened the dialog themselves and is already looking at\n * it. An ask-user prompt is announced by its own event, so the dialog it then\n * opens must stay silent or the same question notifies twice.\n */\nexport function warrantsAttentionNotification({ agentRunning, askUserBlocked }: AttentionState): boolean {\n return agentRunning && !askUserBlocked;\n}\n\n/** A queued follow-up means the agent keeps working, so the run has not stopped for the user. */\nexport function warrantsSettledNotification(hasPendingMessages: boolean): boolean {\n return !hasPendingMessages;\n}\n\n/** Terminal title escapes only mean something on an attached terminal; RPC output stays clean. */\nexport function supportsShellTitle({ hasUI, mode }: ShellSurface): boolean {\n return hasUI && mode !== RPC_MODE;\n}\n\n/** The question an ask-user prompt is blocking on, or a stand-in when it asked none. */\nexport function askUserPromptBody(questions: readonly { question: string }[]): string {\n return questions[0]?.question ?? DEFAULT_ASK_USER_BODY;\n}\n"],"mappings":";;;;;;AAEA,MAAa,iBAAiB;CAAC;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;AAAG;;AAI/E,SAAgB,kCAAwD;CACtE,IAAI,aAAa;CACjB,IAAI;CACJ,MAAM,sBAAsB;EAC1B,IAAI,OAAO,cAAc,KAAK;EAC9B,QAAQ,KAAA;EACR,aAAa;CACf;CAEA,OAAO;EACL,IAAI,OAAO,OAAO;GAChB,cAAc;GACd,MAAM,KAAK;EACb;EACA,MAAM,OAAO,OAAO;GAClB,cAAc;GACd,MAAM,eAAe;IACnB,MAAM,GAAG,eAAe,aAAa,eAAe,QAAQ,GAAG,OAAO;IACtE,cAAc;GAChB;GACA,OAAO;GACP,QAAQ,YAAY,QAAA,EAA+B;EACrD;EACA,KAAK,OAAO,OAAO;GACjB,cAAc;GACd,MAAM,KAAK;EACb;EACA,QAAQ,OAAO,OAAO;GACpB,cAAc;GACd,MAAM,KAAK;EACb;CACF;AACF;;;;;;;;;AC1BA,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgC5B,SAAgB,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e,UAAU;OAAS,gBAAgB;MAAmB;MAChF;MACA;KACF,CAAC;KACD,MAAM,QAAQ,MAAM,SAAS,IAAI,CAAC,CAAC;KACnC,IACE,SAAS,WAAW,OACpB,SACA,OAAO,UAAU,YACjB,aAAa,SACb,MAAM,QAAQ,MAAM,OAAO,KAC3B,MAAM,QAAQ,MACX,WACC,UACA,OAAO,WAAW,YAClB,WAAW,UACX,OAAO,aAAa,kBACpB,eAAe,UACf,OAAO,cAAc,cACzB,GAEA,OAAO,EAAE,SAAS,KAAK;IAC3B;IACA,IAAI,SAAS,SAAS,OAAO,SAAS,UAAU,KAC9C,QAAQ,aAAa;KAAE;KAAU,SAAS;KAAU,QAAQ,SAAS;IAAO,CAAC;GACjF,QAAQ;IAEN,QAAQ,aAAa;KAAE;KAAU,SAAS;IAAS,CAAC;GACtD;GACA,OAAO,EAAE,SAAS,MAAM;EAC1B;EACA,QAAQ;GACN,SAAS;GACT,UAAU,KAAA;GACV,QAAQ,KAAA;GACR,UAAU,MAAM;EAClB;CACF;AACF;;;ACpMA,MAAM,wBAAwB;AAC9B,MAAM,WAAW;;;;;;;;AAmBjB,SAAgB,8BAA8B,EAAE,cAAc,kBAA2C;CACvG,OAAO,gBAAgB,CAAC;AAC1B;;AAGA,SAAgB,4BAA4B,oBAAsC;CAChF,OAAO,CAAC;AACV;;AAGA,SAAgB,mBAAmB,EAAE,OAAO,QAA+B;CACzE,OAAO,SAAS,SAAS;AAC3B;;AAGA,SAAgB,kBAAkB,WAAoD;CACpF,OAAO,UAAU,EAAE,EAAE,YAAY;AACnC"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/services/shellTitleController/mainThread.ts","../src/services/shellTitleController/index.ts","../src/services/notificationText/index.ts","../src/services/systemNotification/index.ts","../src/services/nativePushSender/sync.ts","../src/services/nativePushSender/index.ts","../src/services/notificationPolicy/index.ts"],"sourcesContent":["import type { ShellTitleController } from '../../types/notifications';\n\nexport const BRAILLE_FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\nexport const TITLE_FRAME_INTERVAL_MS = 80;\n\n/** Animates on the main thread, for hosts where a worker could not be started. */\nexport function createMainThreadTitleController(): ShellTitleController {\n let frameIndex = 0;\n let timer: ReturnType<typeof setInterval> | undefined;\n const stopAnimation = () => {\n if (timer) clearInterval(timer);\n timer = undefined;\n frameIndex = 0;\n };\n\n return {\n set(title, write) {\n stopAnimation();\n write(title);\n },\n start(title, write) {\n stopAnimation();\n const render = () => {\n write(`${BRAILLE_FRAMES[frameIndex % BRAILLE_FRAMES.length]} ${title}`);\n frameIndex += 1;\n };\n render();\n timer = setInterval(render, TITLE_FRAME_INTERVAL_MS);\n },\n stop(title, write) {\n stopAnimation();\n write(title);\n },\n dispose(title, write) {\n stopAnimation();\n write(title);\n },\n };\n}\n","import { Worker } from 'node:worker_threads';\n\nimport type { ShellTitleCommand, ShellTitleController, WriteTitle } from '../../types/notifications';\nimport { BRAILLE_FRAMES, TITLE_FRAME_INTERVAL_MS, createMainThreadTitleController } from './mainThread';\n\nexport { createMainThreadTitleController } from './mainThread';\n/**\n * The animator runs off the main thread so a busy agent turn cannot stall the\n * spinner. It is an inline eval source rather than a shipped file because the\n * package is bundled per entry, and a separate worker module would have to be\n * located on disk at runtime.\n */\nconst TITLE_WORKER_SOURCE = `\nconst { writeSync } = require('node:fs');\nconst { parentPort, workerData } = require('node:worker_threads');\nlet frameIndex = 0;\nlet timer;\nconst writeTitle = (title) => writeSync(1, '\\\\u001b]0;' + title + '\\\\u0007');\nconst stop = () => {\n if (timer) clearInterval(timer);\n timer = undefined;\n frameIndex = 0;\n};\nparentPort.on('message', (command) => {\n stop();\n if (command.action === 'start') {\n const render = () => {\n writeTitle(workerData.frames[frameIndex % workerData.frames.length] + ' ' + command.title);\n frameIndex += 1;\n };\n render();\n timer = setInterval(render, workerData.intervalMs);\n return;\n }\n writeTitle(command.title);\n if (command.action === 'dispose') parentPort.close();\n});\n`;\n\n/**\n * Animates from a worker thread, replaying the last command on the main thread\n * if the worker never started, failed, or exited under us. The worker is\n * unreferenced so a pending frame never holds the process open.\n */\nexport function createWorkerTitleController(): ShellTitleController {\n const fallback = createMainThreadTitleController();\n let lastCommand: ShellTitleCommand | undefined;\n let lastWrite: WriteTitle | undefined;\n let worker: Worker | undefined;\n\n const fallBack = () => {\n worker = undefined;\n if (!lastCommand || !lastWrite) return;\n fallback[lastCommand.action](lastCommand.title, lastWrite);\n };\n\n try {\n const titleWorker = new Worker(TITLE_WORKER_SOURCE, {\n eval: true,\n workerData: { frames: BRAILLE_FRAMES, intervalMs: TITLE_FRAME_INTERVAL_MS },\n });\n titleWorker.unref();\n titleWorker.once('error', fallBack);\n titleWorker.once('exit', (code) => {\n if (code !== 0 && worker === titleWorker) fallBack();\n });\n worker = titleWorker;\n } catch {\n // Workers are unavailable on this host, which the main-thread animator covers.\n worker = undefined;\n }\n\n const dispatch = (command: ShellTitleCommand, write: WriteTitle) => {\n lastCommand = command;\n lastWrite = write;\n if (!worker) {\n fallback[command.action](command.title, write);\n return;\n }\n try {\n worker.postMessage(command);\n } catch {\n // The worker closed between the last frame and this command.\n fallBack();\n }\n };\n\n return {\n set: (title, write) => dispatch({ action: 'set', title }, write),\n start: (title, write) => dispatch({ action: 'start', title }, write),\n stop: (title, write) => dispatch({ action: 'stop', title }, write),\n dispose: (title, write) => dispatch({ action: 'dispose', title }, write),\n };\n}\n","import path from 'node:path';\n\nimport type { DesktopNotification } from '../../types/notifications';\n\nconst ATTENTION_SUBTITLE = 'Approval or feedback required';\nconst ATTENTION_TITLE = 'Po needs your input';\nconst ELLIPSIS = '…';\nconst MAX_BODY_LENGTH = 240;\nconst MAX_PROMPT_TITLE_LENGTH = 36;\nconst SETTLED_BODY = 'The agent finished its work and is waiting for you.';\nconst SETTLED_TITLE = 'Po finished';\nconst SHELL_TITLE_SEPARATOR = ' - ';\nconst SHELL_TITLE_PREFIX = 'π';\n\nfunction collapseWhitespace(value: string): string {\n return value.replace(/\\s+/g, ' ').trim();\n}\n\nfunction truncate(value: string, maxLength: number): string {\n return value.length > maxLength ? `${value.slice(0, maxLength - 1)}${ELLIPSIS}` : value;\n}\n\n/** The first user prompt, shortened to fit a shell tab. A blank prompt names nothing. */\nexport function promptTitle(prompt: string): string | undefined {\n const normalized = collapseWhitespace(prompt);\n return normalized ? truncate(normalized, MAX_PROMPT_TITLE_LENGTH) : undefined;\n}\n\nexport interface ShellTabTitleInput {\n cwd: string;\n sessionName?: string;\n prompt?: string;\n}\n\n/**\n * The idle shell-tab title: `π - <label> - <repository>`.\n *\n * The session name wins over the first prompt because the user chose it. With\n * neither, the repository alone still tells two tabs apart.\n */\nexport function shellTabTitle({ cwd, sessionName, prompt }: ShellTabTitleInput): string {\n const repository = path.basename(cwd);\n const label = sessionName ?? prompt;\n return label\n ? `${SHELL_TITLE_PREFIX}${SHELL_TITLE_SEPARATOR}${label}${SHELL_TITLE_SEPARATOR}${repository}`\n : `${SHELL_TITLE_PREFIX}${SHELL_TITLE_SEPARATOR}${repository}`;\n}\n\n/** Notification bodies are one line in a system panel, so they collapse and truncate. */\nexport function notificationBody(body: string): string {\n return truncate(collapseWhitespace(body), MAX_BODY_LENGTH);\n}\n\n/** Sent while the agent holds the turn and something is blocking on the user. */\nexport function attentionNotification(body: string): DesktopNotification {\n return { title: ATTENTION_TITLE, subtitle: ATTENTION_SUBTITLE, body };\n}\n\n/** Sent once a run has stopped, subtitled with whichever name the user recognises. */\nexport function settledNotification({ cwd, sessionName }: { cwd: string; sessionName?: string }): DesktopNotification {\n return { title: SETTLED_TITLE, subtitle: sessionName ?? path.basename(cwd), body: SETTLED_BODY };\n}\n","import type { DesktopNotification, NotificationExecutor } from '../../types/notifications';\nimport { notificationBody } from '../notificationText';\n\nconst CMUX_COMMAND = 'cmux';\nconst COMMAND_TIMEOUT_MS = 3_000;\nconst DARWIN_PLATFORM = 'darwin';\nconst OSASCRIPT_COMMAND = 'osascript';\nconst OSASCRIPT_EXPRESSION_FLAG = '-e';\n\nasync function execute(pi: NotificationExecutor, command: string, args: string[]): Promise<boolean> {\n try {\n const result = await pi.exec(command, args, { timeout: COMMAND_TIMEOUT_MS });\n return result.code === 0;\n } catch {\n // A notifier that is not installed is the ordinary case, not a fault: report\n // \"not delivered\" and let the caller decide whether another one exists.\n return false;\n }\n}\n\n/**\n * Delivers one desktop notification on a best-effort basis.\n *\n * cmux is tried first because it routes the notification to the window the\n * session actually lives in. Only macOS has a second option worth attempting,\n * and a host with neither stays silent rather than failing the turn.\n */\nexport async function sendSystemNotification(\n pi: NotificationExecutor,\n notification: DesktopNotification,\n platform: string = process.platform,\n): Promise<void> {\n const body = notificationBody(notification.body);\n const sentToCmux = await execute(pi, CMUX_COMMAND, [\n 'notify',\n '--title',\n notification.title,\n '--subtitle',\n notification.subtitle,\n '--body',\n body,\n ]);\n if (sentToCmux || platform !== DARWIN_PLATFORM) return;\n\n await execute(pi, OSASCRIPT_COMMAND, [\n OSASCRIPT_EXPRESSION_FLAG,\n 'on run argv',\n OSASCRIPT_EXPRESSION_FLAG,\n 'display notification (item 3 of argv) with title (item 1 of argv) subtitle (item 2 of argv)',\n OSASCRIPT_EXPRESSION_FLAG,\n 'end run',\n notification.title,\n notification.subtitle,\n body,\n ]);\n}\n","import { sign } from 'node:crypto';\nimport { connect } from 'node:http2';\nimport { request } from 'node:https';\n\nimport type { NativePushRequest, NativePushResponse } from './type';\n\nconst MAX_RESPONSE_BYTES = 65_536;\n\nexport function signPushJwt(header: object, claims: object, key: string, algorithm: 'ES256' | 'RS256'): string {\n const input = [header, claims].map((part) => Buffer.from(JSON.stringify(part)).toString('base64url')).join('.');\n const signature = sign('sha256', Buffer.from(input), { key, dsaEncoding: 'ieee-p1363' });\n // APNs requires the raw P1363 ECDSA signature, not ASN.1 DER.\n if (algorithm === 'ES256' && signature.length !== 64) throw new Error('Invalid signing key');\n return `${input}.${signature.toString('base64url')}`;\n}\n\nexport function createPushTransport() {\n const pending = new Set<() => void>();\n return {\n request(this: void, input: NativePushRequest): Promise<NativePushResponse> {\n return new Promise((resolve, reject) => {\n const url = new URL(input.url);\n let size = 0;\n const chunks: Buffer[] = [];\n let done = false;\n let dispose = () => {};\n const finish = (error?: Error, status = 0) => {\n if (done) return;\n done = true;\n clearTimeout(timer);\n pending.delete(cancel);\n dispose();\n if (error) reject(error);\n else resolve({ status, body: Buffer.concat(chunks).toString('utf8') });\n };\n const cancel = () => finish(new Error('Push request cancelled'));\n const timer = setTimeout(() => finish(new Error('Push request timed out')), input.timeoutMs);\n pending.add(cancel);\n const data = (chunk: Buffer) => {\n size += chunk.length;\n if (size > MAX_RESPONSE_BYTES) finish(new Error('Push response too large'));\n else chunks.push(Buffer.from(chunk));\n };\n if (input.http2) {\n const session = connect(url.origin);\n dispose = () => session.destroy();\n session.on('error', (error) => finish(error));\n const stream = session.request({ ':method': 'POST', ':path': url.pathname, ...input.headers });\n let status = 0;\n stream.on('response', (headers) => {\n status = Number(headers[':status']);\n });\n stream.on('data', data);\n stream.on('error', (error) => finish(error));\n stream.on('end', () => finish(undefined, status));\n stream.end(input.body);\n } else {\n const req = request(url, { method: 'POST', headers: input.headers }, (response) => {\n response.on('data', data);\n response.on('error', (error) => finish(error));\n response.on('end', () => finish(undefined, response.statusCode));\n });\n dispose = () => req.destroy();\n req.on('error', (error) => finish(error));\n req.end(input.body);\n }\n });\n },\n close() {\n for (const cancel of pending) cancel();\n },\n };\n}\n","import type { PoNotificationEntryData } from '@agimon-ai/po-core';\n\nimport { createPushTransport, signPushJwt } from './sync';\nimport type { NativePushSender, NativePushSenderOptions } from './type';\n\nconst MAX_PAYLOAD_BYTES = 4096;\nconst APNS_TOPIC = 'ai.po.app';\n// Only documented provider codes may enter diagnostics, never arbitrary response text.\nconst APNS_REASONS = new Set([\n 'BadCollapseId',\n 'BadDeviceToken',\n 'BadExpirationDate',\n 'BadMessageId',\n 'BadPriority',\n 'BadTopic',\n 'DeviceTokenNotForTopic',\n 'DuplicateHeaders',\n 'IdleTimeout',\n 'InvalidPushType',\n 'MissingDeviceToken',\n 'MissingTopic',\n 'PayloadEmpty',\n 'TopicDisallowed',\n 'BadCertificate',\n 'BadCertificateEnvironment',\n 'ExpiredProviderToken',\n 'Forbidden',\n 'InvalidProviderToken',\n 'MissingProviderToken',\n 'BadPath',\n 'MethodNotAllowed',\n 'Unregistered',\n 'PayloadTooLarge',\n 'TooManyProviderTokenUpdates',\n 'TooManyRequests',\n 'InternalServerError',\n 'ServiceUnavailable',\n 'Shutdown',\n]);\nconst OAUTH_URL = 'https://oauth2.googleapis.com/token';\nconst FCM_ERROR_TYPE = 'type.googleapis.com/google.firebase.fcm.v1.FcmError';\nconst encoder = new TextEncoder();\n\nfunction parse(body: string): Record<string, unknown> {\n try {\n const value: unknown = JSON.parse(body);\n return value && typeof value === 'object' ? (value as Record<string, unknown>) : {};\n } catch {\n return {};\n } // Malformed provider responses never invalidate registrations.\n}\n\nfunction payload(\n notification: PoNotificationEntryData,\n build: (text: { title: string; subtitle: string; body: string }) => object,\n): string {\n const text = { title: notification.title, subtitle: notification.subtitle, body: notification.body };\n let result = JSON.stringify(build(text));\n // Measure the full serialized envelope, including escaped text and the FCM token.\n for (const field of ['body', 'subtitle', 'title'] as const) {\n if (encoder.encode(result).length <= MAX_PAYLOAD_BYTES) break;\n const points = Array.from(text[field]);\n let low = 0;\n let high = points.length;\n while (low < high) {\n const middle = Math.ceil((low + high) / 2);\n text[field] = points.slice(0, middle).join('');\n if (encoder.encode(JSON.stringify(build(text))).length <= MAX_PAYLOAD_BYTES) low = middle;\n else high = middle - 1;\n }\n text[field] = points.slice(0, low).join('');\n result = JSON.stringify(build(text));\n }\n if (encoder.encode(result).length > MAX_PAYLOAD_BYTES) throw new Error('Push payload too large');\n return result;\n}\n\nexport function createNativePushSender(options: NativePushSenderOptions): NativePushSender {\n const transport = createPushTransport();\n const request = options.request ?? transport.request;\n const now = options.now ?? Date.now;\n const timeoutMs = Number.isFinite(options.timeoutMs) ? Math.max(1, Math.min(options.timeoutMs!, 30_000)) : 10_000;\n let closed = false;\n let apnsJwt: { value: string; expires: number } | undefined;\n let oauth: { value: string; expires: number } | undefined;\n let oauthPending: Promise<string> | undefined;\n\n async function accessToken(): Promise<string> {\n if (oauth && now() < oauth.expires) return oauth.value;\n if (oauthPending) return oauthPending;\n oauthPending = (async () => {\n const credentials = options.fcm!;\n const issued = Math.floor(now() / 1000);\n const assertion = signPushJwt(\n { alg: 'RS256', typ: 'JWT' },\n {\n iss: credentials.clientEmail,\n scope: 'https://www.googleapis.com/auth/firebase.messaging',\n aud: OAUTH_URL,\n iat: issued,\n exp: issued + 3600,\n },\n credentials.privateKey,\n 'RS256',\n );\n const response = await request({\n url: OAUTH_URL,\n headers: { 'content-type': 'application/x-www-form-urlencoded' },\n body: new URLSearchParams({ grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer', assertion }).toString(),\n timeoutMs,\n });\n const data = parse(response.body);\n if (\n response.status !== 200 ||\n typeof data.access_token !== 'string' ||\n !data.access_token ||\n typeof data.expires_in !== 'number' ||\n !Number.isFinite(data.expires_in) ||\n data.expires_in <= 0\n )\n throw new Error('OAuth failed');\n oauth = { value: data.access_token, expires: now() + Math.max(0, Math.min(data.expires_in, 3600) - 60) * 1000 };\n return oauth.value;\n })();\n try {\n return await oauthPending;\n } finally {\n oauthPending = undefined;\n }\n }\n\n return {\n async send(registration, notification, sessionId) {\n const provider = registration.platform === 'ios' ? 'apns' : 'fcm';\n if (closed || !options[provider]) {\n options.diagnostic?.({ provider, outcome: 'unavailable' });\n return { invalid: false };\n }\n try {\n const data = {\n ...(registration.hostRef ? { hostRef: registration.hostRef } : {}),\n ...(sessionId ? { sessionId } : {}),\n };\n let response;\n let reason: string | undefined;\n if (registration.platform === 'ios') {\n const credentials = options.apns!;\n if (!apnsJwt || now() >= apnsJwt.expires) {\n apnsJwt = {\n value: signPushJwt(\n { alg: 'ES256', kid: credentials.keyId },\n {\n iss: credentials.teamId,\n iat: Math.floor(now() / 1000),\n },\n credentials.key,\n 'ES256',\n ),\n expires: now() + 50 * 60_000,\n };\n }\n response = await request({\n url: `https://${registration.environment === 'development' ? 'api.sandbox.push.apple.com' : 'api.push.apple.com'}/3/device/${encodeURIComponent(registration.token)}`,\n http2: true,\n timeoutMs,\n headers: {\n authorization: `bearer ${apnsJwt.value}`,\n 'apns-topic': APNS_TOPIC,\n 'apns-push-type': 'alert',\n 'apns-priority': '10',\n 'apns-expiration': '0',\n 'content-type': 'application/json',\n },\n // ponytail: live alerts only; add a durable outbox if delayed delivery becomes a requirement.\n // Expo iOS reads custom remote data from userInfo.body. Keep data as the provider-neutral payload.\n body: payload(notification, (text) => ({ aps: { alert: text, sound: 'default' }, data, body: data })),\n });\n const value = parse(response.body).reason;\n if (typeof value === 'string' && APNS_REASONS.has(value)) reason = value;\n if (\n (response.status === 410 && reason === 'Unregistered') ||\n (response.status === 400 && reason === 'BadDeviceToken')\n ) {\n options.diagnostic?.({\n provider,\n outcome: 'invalid',\n status: response.status,\n ...(reason ? { reason } : {}),\n });\n return { invalid: true };\n }\n } else {\n const body = payload(notification, (text) => ({\n message: {\n token: registration.token,\n data,\n notification: { title: text.title, body: [text.subtitle, text.body].filter(Boolean).join('\\n') },\n // ponytail: zero TTL, no offline delivery; an outbox would own delayed sends.\n android: { ttl: '0s', priority: 'HIGH', notification: { channel_id: 'po-notifications' } },\n },\n }));\n const token = await accessToken();\n if (closed) return { invalid: false };\n response = await request({\n url: `https://fcm.googleapis.com/v1/projects/${encodeURIComponent(options.fcm!.projectId)}/messages:send`,\n headers: { authorization: `Bearer ${token}`, 'content-type': 'application/json' },\n body,\n timeoutMs,\n });\n const error = parse(response.body).error;\n if (\n response.status === 404 &&\n error &&\n typeof error === 'object' &&\n 'details' in error &&\n Array.isArray(error.details) &&\n error.details.some(\n (detail: unknown) =>\n detail &&\n typeof detail === 'object' &&\n '@type' in detail &&\n detail['@type'] === FCM_ERROR_TYPE &&\n 'errorCode' in detail &&\n detail.errorCode === 'UNREGISTERED',\n )\n ) {\n options.diagnostic?.({\n provider,\n outcome: 'invalid',\n status: response.status,\n ...(reason ? { reason } : {}),\n });\n return { invalid: true };\n }\n }\n if (response.status < 200 || response.status >= 300)\n options.diagnostic?.({ provider, outcome: 'failed', status: response.status, ...(reason ? { reason } : {}) });\n } catch {\n // Never expose provider bodies, credentials, device tokens, or network errors.\n options.diagnostic?.({ provider, outcome: 'failed' });\n }\n return { invalid: false };\n },\n close() {\n closed = true;\n apnsJwt = undefined;\n oauth = undefined;\n transport.close();\n },\n };\n}\n","const DEFAULT_ASK_USER_BODY = 'The agent is waiting for your feedback.';\nconst RPC_MODE = 'rpc';\n\nexport interface AttentionState {\n agentRunning: boolean;\n askUserBlocked: boolean;\n}\n\nexport interface ShellSurface {\n hasUI: boolean;\n mode?: string;\n}\n\n/**\n * A dialog is worth interrupting the user for only while the agent holds the turn.\n *\n * Outside a run the user opened the dialog themselves and is already looking at\n * it. An ask-user prompt is announced by its own event, so the dialog it then\n * opens must stay silent or the same question notifies twice.\n */\nexport function warrantsAttentionNotification({ agentRunning, askUserBlocked }: AttentionState): boolean {\n return agentRunning && !askUserBlocked;\n}\n\n/** A queued follow-up means the agent keeps working, so the run has not stopped for the user. */\nexport function warrantsSettledNotification(hasPendingMessages: boolean): boolean {\n return !hasPendingMessages;\n}\n\n/** Terminal title escapes only mean something on an attached terminal; RPC output stays clean. */\nexport function supportsShellTitle({ hasUI, mode }: ShellSurface): boolean {\n return hasUI && mode !== RPC_MODE;\n}\n\n/** The question an ask-user prompt is blocking on, or a stand-in when it asked none. */\nexport function askUserPromptBody(questions: readonly { question: string }[]): string {\n return questions[0]?.question ?? DEFAULT_ASK_USER_BODY;\n}\n"],"mappings":";;;;;;AAEA,MAAa,iBAAiB;CAAC;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;AAAG;;AAI/E,SAAgB,kCAAwD;CACtE,IAAI,aAAa;CACjB,IAAI;CACJ,MAAM,sBAAsB;EAC1B,IA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M,QAAQ,MACX,WACC,UACA,OAAO,WAAW,YAClB,WAAW,UACX,OAAO,aAAa,kBACpB,eAAe,UACf,OAAO,cAAc,cACzB,GACA;MACA,QAAQ,aAAa;OACnB;OACA,SAAS;OACT,QAAQ,SAAS;OACjB,GAAI,SAAS,EAAE,OAAO,IAAI,CAAC;MAC7B,CAAC;MACD,OAAO,EAAE,SAAS,KAAK;KACzB;IACF;IACA,IAAI,SAAS,SAAS,OAAO,SAAS,UAAU,KAC9C,QAAQ,aAAa;KAAE;KAAU,SAAS;KAAU,QAAQ,SAAS;KAAQ,GAAI,SAAS,EAAE,OAAO,IAAI,CAAC;IAAG,CAAC;GAChH,QAAQ;IAEN,QAAQ,aAAa;KAAE;KAAU,SAAS;IAAS,CAAC;GACtD;GACA,OAAO,EAAE,SAAS,MAAM;EAC1B;EACA,QAAQ;GACN,SAAS;GACT,UAAU,KAAA;GACV,QAAQ,KAAA;GACR,UAAU,MAAM;EAClB;CACF;AACF;;;AC1PA,MAAM,wBAAwB;AAC9B,MAAM,WAAW;;;;;;;;AAmBjB,SAAgB,8BAA8B,EAAE,cAAc,kBAA2C;CACvG,OAAO,gBAAgB,CAAC;AAC1B;;AAGA,SAAgB,4BAA4B,oBAAsC;CAChF,OAAO,CAAC;AACV;;AAGA,SAAgB,mBAAmB,EAAE,OAAO,QAA+B;CACzE,OAAO,SAAS,SAAS;AAC3B;;AAGA,SAAgB,kBAAkB,WAAoD;CACpF,OAAO,UAAU,EAAE,EAAE,YAAY;AACnC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agimon-ai/po-notification",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.38",
|
|
4
4
|
"description": "Desktop notifications and an animated shell-tab title for Po sessions.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -60,12 +60,12 @@
|
|
|
60
60
|
"access": "public"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@agimon-ai/po-core": "0.0.0-alpha.
|
|
63
|
+
"@agimon-ai/po-core": "0.0.0-alpha.38",
|
|
64
64
|
"@deepseek-ai/cordis": "4.0.5"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@agimon-ai/po-build": "0.0.0-alpha.
|
|
68
|
-
"@agimon-ai/vibe-lint-plugin-po-extension": "0.0.0-alpha.
|
|
67
|
+
"@agimon-ai/po-build": "0.0.0-alpha.38",
|
|
68
|
+
"@agimon-ai/vibe-lint-plugin-po-extension": "0.0.0-alpha.38",
|
|
69
69
|
"@earendil-works/pi-coding-agent": "1.3.0",
|
|
70
70
|
"@types/node": "26.6.5",
|
|
71
71
|
"@vitest/coverage-v8": "5.0.4",
|