botmux 3.18.6 → 3.18.7
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/dist/.runtime-build-id +1 -1
- package/dist/adapters/backend/riff-backend.d.ts +158 -0
- package/dist/adapters/backend/riff-backend.d.ts.map +1 -1
- package/dist/adapters/backend/riff-backend.js +330 -7
- package/dist/adapters/backend/riff-backend.js.map +1 -1
- package/dist/adapters/backend/sandbox.d.ts +42 -0
- package/dist/adapters/backend/sandbox.d.ts.map +1 -1
- package/dist/adapters/backend/sandbox.js +95 -5
- package/dist/adapters/backend/sandbox.js.map +1 -1
- package/dist/adapters/cli/codex-app.d.ts.map +1 -1
- package/dist/adapters/cli/codex-app.js +2 -1
- package/dist/adapters/cli/codex-app.js.map +1 -1
- package/dist/adapters/cli/dsh.d.ts.map +1 -1
- package/dist/adapters/cli/dsh.js +2 -1
- package/dist/adapters/cli/dsh.js.map +1 -1
- package/dist/adapters/cli/mir.d.ts.map +1 -1
- package/dist/adapters/cli/mir.js +2 -1
- package/dist/adapters/cli/mir.js.map +1 -1
- package/dist/adapters/cli/mira.d.ts.map +1 -1
- package/dist/adapters/cli/mira.js +2 -1
- package/dist/adapters/cli/mira.js.map +1 -1
- package/dist/adapters/hook-command.d.ts +3 -5
- package/dist/adapters/hook-command.d.ts.map +1 -1
- package/dist/adapters/hook-command.js +59 -13
- package/dist/adapters/hook-command.js.map +1 -1
- package/dist/autostart.d.ts +76 -0
- package/dist/autostart.d.ts.map +1 -1
- package/dist/autostart.js +105 -28
- package/dist/autostart.js.map +1 -1
- package/dist/bot-registry.d.ts +12 -0
- package/dist/bot-registry.d.ts.map +1 -1
- package/dist/bot-registry.js +43 -3
- package/dist/bot-registry.js.map +1 -1
- package/dist/cli/dashboard-command.d.ts +142 -0
- package/dist/cli/dashboard-command.d.ts.map +1 -1
- package/dist/cli/dashboard-command.js +160 -0
- package/dist/cli/dashboard-command.js.map +1 -1
- package/dist/cli/dashboard-endpoint.d.ts +66 -0
- package/dist/cli/dashboard-endpoint.d.ts.map +1 -1
- package/dist/cli/dashboard-endpoint.js +144 -30
- package/dist/cli/dashboard-endpoint.js.map +1 -1
- package/dist/cli/send-dispatch.d.ts +2 -0
- package/dist/cli/send-dispatch.d.ts.map +1 -1
- package/dist/cli/send-dispatch.js +8 -2
- package/dist/cli/send-dispatch.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +270 -38
- package/dist/cli.js.map +1 -1
- package/dist/core/binary-self-update.d.ts +7 -0
- package/dist/core/binary-self-update.d.ts.map +1 -1
- package/dist/core/binary-self-update.js +17 -0
- package/dist/core/binary-self-update.js.map +1 -1
- package/dist/core/command-handler.d.ts.map +1 -1
- package/dist/core/command-handler.js +52 -1
- package/dist/core/command-handler.js.map +1 -1
- package/dist/core/cost-calculator.d.ts +9 -1
- package/dist/core/cost-calculator.d.ts.map +1 -1
- package/dist/core/cost-calculator.js +5 -0
- package/dist/core/cost-calculator.js.map +1 -1
- package/dist/core/passthrough-commands.d.ts.map +1 -1
- package/dist/core/passthrough-commands.js +1 -1
- package/dist/core/passthrough-commands.js.map +1 -1
- package/dist/core/self-spawn.d.ts +46 -1
- package/dist/core/self-spawn.d.ts.map +1 -1
- package/dist/core/self-spawn.js +57 -0
- package/dist/core/self-spawn.js.map +1 -1
- package/dist/core/worker-pool.d.ts.map +1 -1
- package/dist/core/worker-pool.js +81 -5
- package/dist/core/worker-pool.js.map +1 -1
- package/dist/daemon.d.ts.map +1 -1
- package/dist/daemon.js +93 -0
- package/dist/daemon.js.map +1 -1
- package/dist/dashboard/autostart-api.d.ts.map +1 -1
- package/dist/dashboard/autostart-api.js +16 -3
- package/dist/dashboard/autostart-api.js.map +1 -1
- package/dist/dashboard/bot-onboarding.d.ts +2 -1
- package/dist/dashboard/bot-onboarding.d.ts.map +1 -1
- package/dist/dashboard/bot-onboarding.js +22 -6
- package/dist/dashboard/bot-onboarding.js.map +1 -1
- package/dist/dashboard/bot-payload.d.ts +1 -0
- package/dist/dashboard/bot-payload.d.ts.map +1 -1
- package/dist/dashboard/bot-payload.js +3 -0
- package/dist/dashboard/bot-payload.js.map +1 -1
- package/dist/dashboard/connector-api.d.ts.map +1 -1
- package/dist/dashboard/connector-api.js +28 -0
- package/dist/dashboard/connector-api.js.map +1 -1
- package/dist/dashboard/trigger-api.d.ts.map +1 -1
- package/dist/dashboard/trigger-api.js +33 -21
- package/dist/dashboard/trigger-api.js.map +1 -1
- package/dist/dashboard/web/bot-defaults-page.d.ts.map +1 -1
- package/dist/dashboard/web/bot-defaults-page.js +12 -2
- package/dist/dashboard/web/bot-defaults-page.js.map +1 -1
- package/dist/dashboard/web/bot-defaults.d.ts +2 -0
- package/dist/dashboard/web/bot-defaults.d.ts.map +1 -1
- package/dist/dashboard/web/bot-defaults.js.map +1 -1
- package/dist/dashboard/web/bot-onboarding.d.ts +40 -1
- package/dist/dashboard/web/bot-onboarding.d.ts.map +1 -1
- package/dist/dashboard/web/bot-onboarding.js +52 -2
- package/dist/dashboard/web/bot-onboarding.js.map +1 -1
- package/dist/dashboard/web/i18n.d.ts.map +1 -1
- package/dist/dashboard/web/i18n.js +2 -0
- package/dist/dashboard/web/i18n.js.map +1 -1
- package/dist/dashboard/webhook-routes.d.ts.map +1 -1
- package/dist/dashboard/webhook-routes.js +272 -30
- package/dist/dashboard/webhook-routes.js.map +1 -1
- package/dist/dashboard-web/app.js +1 -1
- package/dist/dashboard-web/chunks/{agent-workbench-dock-page-XHJUYFGN.js → agent-workbench-dock-page-6LC422N6.js} +1 -1
- package/dist/dashboard-web/chunks/{agent-workbench-page-FLKTLIRM.js → agent-workbench-page-RSAWY7O2.js} +1 -1
- package/dist/dashboard-web/chunks/{bot-defaults-page-XMGLZZ2E.js → bot-defaults-page-67RAWCSQ.js} +1 -1
- package/dist/dashboard-web/chunks/{chunk-TLG45URB.js → chunk-IA5KMD5O.js} +1 -1
- package/dist/dashboard-web/chunks/{chunk-BU3Q6XC6.js → chunk-K232GT3M.js} +2 -2
- package/dist/dashboard-web/chunks/chunk-MMLTCXHP.js +10 -0
- package/dist/dashboard-web/chunks/{chunk-ECFC7UG2.js → chunk-R3LJUCEO.js} +1 -1
- package/dist/dashboard-web/chunks/{chunk-Z67OSM5P.js → chunk-YJA3KY3J.js} +1 -1
- package/dist/dashboard-web/chunks/{connectors-page-WDM4CEAU.js → connectors-page-DJCTHSFB.js} +1 -1
- package/dist/dashboard-web/chunks/{feedback-page-GMJ4FLJ4.js → feedback-page-O7SZRKNM.js} +1 -1
- package/dist/dashboard-web/chunks/{groups-page-L4ZJNWVR.js → groups-page-7PONUYHE.js} +1 -1
- package/dist/dashboard-web/chunks/{insights-page-7LUJU2CX.js → insights-page-J6DAAJ6D.js} +1 -1
- package/dist/dashboard-web/chunks/{monitor-room-7LZUJQPF.js → monitor-room-F3QNEW7N.js} +1 -1
- package/dist/dashboard-web/chunks/{monitoring-page-AUSXMPYO.js → monitoring-page-JHDD2VS2.js} +1 -1
- package/dist/dashboard-web/chunks/{office-page-6ZU6MAZN.js → office-page-MMTN4IKD.js} +1 -1
- package/dist/dashboard-web/chunks/{overview-page-QBC5CIYH.js → overview-page-IQ2UJAJP.js} +1 -1
- package/dist/dashboard-web/chunks/{roles-page-QO3YCA7D.js → roles-page-FNI4MGX6.js} +1 -1
- package/dist/dashboard-web/chunks/{schedules-page-YNGSKDQW.js → schedules-page-6PUU63KS.js} +1 -1
- package/dist/dashboard-web/chunks/{sessions-page-BWR4UB6X.js → sessions-page-O4N72EXT.js} +4 -4
- package/dist/dashboard-web/chunks/{settings-page-2IRIS3FP.js → settings-page-G7B3STUF.js} +1 -1
- package/dist/dashboard-web/chunks/{skills-page-5RZPM6HJ.js → skills-page-CEWKQOIG.js} +1 -1
- package/dist/dashboard-web/chunks/{team-federation-page-KERG6LKC.js → team-federation-page-NUP4VK4H.js} +1 -1
- package/dist/dashboard-web/chunks/{v3-page-766CBD7H.js → v3-page-M4XF6D5Z.js} +1 -1
- package/dist/dashboard-web/chunks/{whiteboards-page-2M6XZD5C.js → whiteboards-page-L755NZX6.js} +1 -1
- package/dist/dashboard-web/style.css +13 -0
- package/dist/dashboard.js +3 -0
- package/dist/dashboard.js.map +1 -1
- package/dist/global-config.d.ts +3 -0
- package/dist/global-config.d.ts.map +1 -1
- package/dist/global-config.js +10 -3
- package/dist/global-config.js.map +1 -1
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +19 -1
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/zh.d.ts.map +1 -1
- package/dist/i18n/zh.js +19 -1
- package/dist/i18n/zh.js.map +1 -1
- package/dist/im/lark/api-gate.d.ts +53 -0
- package/dist/im/lark/api-gate.d.ts.map +1 -0
- package/dist/im/lark/api-gate.js +322 -0
- package/dist/im/lark/api-gate.js.map +1 -0
- package/dist/im/lark/audio-transcribe.d.ts +23 -0
- package/dist/im/lark/audio-transcribe.d.ts.map +1 -0
- package/dist/im/lark/audio-transcribe.js +126 -0
- package/dist/im/lark/audio-transcribe.js.map +1 -0
- package/dist/im/lark/card-builder.d.ts +6 -0
- package/dist/im/lark/card-builder.d.ts.map +1 -1
- package/dist/im/lark/card-builder.js +53 -1
- package/dist/im/lark/card-builder.js.map +1 -1
- package/dist/im/lark/card-handler.d.ts +10 -0
- package/dist/im/lark/card-handler.d.ts.map +1 -1
- package/dist/im/lark/card-handler.js +68 -1
- package/dist/im/lark/card-handler.js.map +1 -1
- package/dist/im/lark/client.d.ts.map +1 -1
- package/dist/im/lark/client.js +247 -224
- package/dist/im/lark/client.js.map +1 -1
- package/dist/im/lark/event-dispatcher.d.ts.map +1 -1
- package/dist/im/lark/event-dispatcher.js +34 -3
- package/dist/im/lark/event-dispatcher.js.map +1 -1
- package/dist/im/lark/message-parser.d.ts +16 -0
- package/dist/im/lark/message-parser.d.ts.map +1 -1
- package/dist/im/lark/message-parser.js +31 -0
- package/dist/im/lark/message-parser.js.map +1 -1
- package/dist/services/budget-tracker.d.ts +61 -0
- package/dist/services/budget-tracker.d.ts.map +1 -0
- package/dist/services/budget-tracker.js +306 -0
- package/dist/services/budget-tracker.js.map +1 -0
- package/dist/services/connector-store.d.ts +16 -0
- package/dist/services/connector-store.d.ts.map +1 -1
- package/dist/services/connector-store.js.map +1 -1
- package/dist/services/failed-turn-retry.d.ts +43 -0
- package/dist/services/failed-turn-retry.d.ts.map +1 -0
- package/dist/services/failed-turn-retry.js +50 -0
- package/dist/services/failed-turn-retry.js.map +1 -0
- package/dist/services/model-pricing.d.ts +80 -0
- package/dist/services/model-pricing.d.ts.map +1 -0
- package/dist/services/model-pricing.js +182 -0
- package/dist/services/model-pricing.js.map +1 -0
- package/dist/services/session-store.d.ts.map +1 -1
- package/dist/services/session-store.js +13 -3
- package/dist/services/session-store.js.map +1 -1
- package/dist/services/trigger-types.d.ts +10 -0
- package/dist/services/trigger-types.d.ts.map +1 -1
- package/dist/services/trigger-types.js.map +1 -1
- package/dist/services/usage-ledger.d.ts +10 -0
- package/dist/services/usage-ledger.d.ts.map +1 -1
- package/dist/services/usage-ledger.js +36 -0
- package/dist/services/usage-ledger.js.map +1 -1
- package/dist/services/voice/asr.d.ts +17 -0
- package/dist/services/voice/asr.d.ts.map +1 -0
- package/dist/services/voice/asr.js +64 -0
- package/dist/services/voice/asr.js.map +1 -0
- package/dist/services/voice/index.d.ts +17 -2
- package/dist/services/voice/index.d.ts.map +1 -1
- package/dist/services/voice/index.js +43 -0
- package/dist/services/voice/index.js.map +1 -1
- package/dist/services/voice/types.d.ts +15 -0
- package/dist/services/voice/types.d.ts.map +1 -1
- package/dist/services/webhook-idempotency.d.ts +134 -0
- package/dist/services/webhook-idempotency.d.ts.map +1 -0
- package/dist/services/webhook-idempotency.js +265 -0
- package/dist/services/webhook-idempotency.js.map +1 -0
- package/dist/setup/app-name.d.ts +1 -0
- package/dist/setup/app-name.d.ts.map +1 -1
- package/dist/setup/app-name.js +7 -0
- package/dist/setup/app-name.js.map +1 -1
- package/dist/setup/bot-config-editor.d.ts +28 -0
- package/dist/setup/bot-config-editor.d.ts.map +1 -1
- package/dist/setup/bot-config-editor.js +73 -0
- package/dist/setup/bot-config-editor.js.map +1 -1
- package/dist/setup/open-platform-automation.d.ts +26 -0
- package/dist/setup/open-platform-automation.d.ts.map +1 -1
- package/dist/setup/open-platform-automation.js +90 -1
- package/dist/setup/open-platform-automation.js.map +1 -1
- package/dist/setup/open-platform-outcome.d.ts.map +1 -1
- package/dist/setup/open-platform-outcome.js +8 -2
- package/dist/setup/open-platform-outcome.js.map +1 -1
- package/dist/types.d.ts +20 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/usage-limit-tracker.d.ts +29 -9
- package/dist/utils/usage-limit-tracker.d.ts.map +1 -1
- package/dist/utils/usage-limit-tracker.js +122 -14
- package/dist/utils/usage-limit-tracker.js.map +1 -1
- package/dist/worker.js +27 -6
- package/dist/worker.js.map +1 -1
- package/dist/workflows/definition.d.ts +56 -56
- package/dist/workflows/events/payloads.d.ts +2 -2
- package/dist/workflows/events/schema.d.ts +430 -430
- package/dist/workflows/migration/v2-run-archive-schema.d.ts +2 -2
- package/dist/workflows/v3/run-envelope.d.ts +56 -56
- package/package.json +9 -8
- package/scripts/postinstall-bin.mjs +25 -0
- package/dist/dashboard-web/chunks/chunk-NJCJR3U2.js +0 -10
package/dist/core/worker-pool.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Extracted from daemon.ts for modularity.
|
|
4
4
|
*/
|
|
5
5
|
import { execSync } from 'node:child_process';
|
|
6
|
-
import { join, dirname } from 'node:path';
|
|
6
|
+
import { join, dirname, basename } from 'node:path';
|
|
7
7
|
import { homedir } from 'node:os';
|
|
8
8
|
import { readFileSync, readdirSync, mkdirSync, existsSync, realpathSync, unlinkSync } from 'node:fs';
|
|
9
9
|
import { atomicWriteFileSync } from '../utils/atomic-write.js';
|
|
@@ -22,7 +22,7 @@ import * as sessionStore from '../services/session-store.js';
|
|
|
22
22
|
import * as asyncTriggerStore from '../services/async-trigger-store.js';
|
|
23
23
|
import { markMessageListenerRunPreviewFailed, markMessageListenerRunPreviewReplied, markMessageListenerRunPreviewRunning, } from '../services/message-listener-run-preview-store.js';
|
|
24
24
|
import { persistStreamCardState, rememberLastCliInput } from './session-manager.js';
|
|
25
|
-
import { spawnWorker } from './self-spawn.js';
|
|
25
|
+
import { spawnWorker, isStandaloneBinary, WORKER_ENTRY_SUBCOMMAND } from './self-spawn.js';
|
|
26
26
|
import { resolveSessionLaunchModel } from './session-model.js';
|
|
27
27
|
import { fallbackTurnId, frozenReplyContextForTurn, isSubstituteTurn, pickTurnReplyTarget, rehomeReplyTargetState, replyTargetKey } from './reply-target.js';
|
|
28
28
|
import { updateMessage, deleteMessage, sendEphemeralCard, sendUserMessage, addReaction, removeReaction, getMessageChatId, MessageWithdrawnError } from '../im/lark/client.js';
|
|
@@ -65,6 +65,7 @@ import { withBotTurnMutation } from './bot-turn-mutation-gate.js';
|
|
|
65
65
|
import { recordQuarantinedLauncherEnvKeys } from './mojo-launcher-env-quarantine.js';
|
|
66
66
|
import { freezeMojoIdentityForSession } from './mojo-session-identity.js';
|
|
67
67
|
import { getBot, getAllBots, getOwnerOpenId, resolveBrandLabel, getLoadedConfigPath, getLoadedConfigProvenance, resolveUsageDisplay } from '../bot-registry.js';
|
|
68
|
+
import { resolvePricingConfig } from '../services/model-pricing.js';
|
|
68
69
|
import { RestartCoordinator } from './restart-coordinator.js';
|
|
69
70
|
import { runtimeBuildIdentity } from '../utils/runtime-build-id.js';
|
|
70
71
|
import { scrubWorkflowWorkerEnv } from '../utils/child-env.js';
|
|
@@ -76,6 +77,12 @@ const DAEMON_BOOT_ID = randomUUID();
|
|
|
76
77
|
const restartCoordinator = new RestartCoordinator();
|
|
77
78
|
const lifecycleRetiringWorkers = new WeakMap();
|
|
78
79
|
const transferRetiringWorkers = new WeakSet();
|
|
80
|
+
/** 从 bot 配置解析定价(bots.json pricing 块 → 内置表)。未配置时返回 undefined。 */
|
|
81
|
+
function resolvePricingForBot(larkAppId) {
|
|
82
|
+
if (!larkAppId)
|
|
83
|
+
return undefined;
|
|
84
|
+
return resolvePricingConfig(getBot(larkAppId)?.config?.pricing);
|
|
85
|
+
}
|
|
79
86
|
/** 在完整 Worker 模块加载前接住首条 IPC,避免冷启动耗时被误判为投递失败。 */
|
|
80
87
|
function workerForkExecArgv() {
|
|
81
88
|
const preloadPath = join(__dirname, '..', 'worker-ipc-preload.js');
|
|
@@ -228,6 +235,8 @@ export function getDaemonSessionUsageSnapshot(ds, effectiveCliId, opts) {
|
|
|
228
235
|
// card refreshes on every status tick and rides the reader's reparse
|
|
229
236
|
// throttle instead (fresh:false) to stay off the disk.
|
|
230
237
|
fresh: opts?.fresh ?? true,
|
|
238
|
+
// 定价覆盖:从 bot 配置解析,未配置时 undefined(costCny 缺省)。
|
|
239
|
+
pricing: resolvePricingForBot(ds.larkAppId ?? ds.session.larkAppId),
|
|
231
240
|
});
|
|
232
241
|
}
|
|
233
242
|
catch (error) {
|
|
@@ -12056,6 +12065,24 @@ export function listProcesses() {
|
|
|
12056
12065
|
return [];
|
|
12057
12066
|
}
|
|
12058
12067
|
}
|
|
12068
|
+
/**
|
|
12069
|
+
* This executable's absolute, symlink-resolved path.
|
|
12070
|
+
*
|
|
12071
|
+
* `process.execPath` is already absolute and kernel-resolved, so this is normally
|
|
12072
|
+
* a no-op; realpath is applied anyway so a comparison against a `/proc` argv[0]
|
|
12073
|
+
* cannot be defeated by the daemon having been started through a symlink (a
|
|
12074
|
+
* released install commonly sits behind `~/.botmux/bin/botmux`). Falls back to the
|
|
12075
|
+
* raw value when the path cannot be resolved — a failed realpath must not turn the
|
|
12076
|
+
* reaper into a no-op.
|
|
12077
|
+
*/
|
|
12078
|
+
function canonicalExecPath() {
|
|
12079
|
+
try {
|
|
12080
|
+
return realpathSync(process.execPath);
|
|
12081
|
+
}
|
|
12082
|
+
catch {
|
|
12083
|
+
return process.execPath;
|
|
12084
|
+
}
|
|
12085
|
+
}
|
|
12059
12086
|
/**
|
|
12060
12087
|
* Reap worker processes orphaned by a previous daemon that died WITHOUT running
|
|
12061
12088
|
* its graceful shutdown — SIGKILL, OOM, or an uncaught crash. The shutdown()
|
|
@@ -12083,13 +12110,62 @@ export function reapOrphanWorkers(opts = {}) {
|
|
|
12083
12110
|
return 0;
|
|
12084
12111
|
const procs = opts.procs ?? listProcesses();
|
|
12085
12112
|
const kill = opts.kill ?? ((pid, signal) => { process.kill(pid, signal); });
|
|
12086
|
-
|
|
12113
|
+
// How THIS install's workers appear in a command line.
|
|
12114
|
+
//
|
|
12115
|
+
// Node: `<node> <dist>/worker.js` — the script path identifies the install.
|
|
12116
|
+
//
|
|
12117
|
+
// ⚠️ Compiled single-file binary: there IS no worker.js on disk. spawnWorker()
|
|
12118
|
+
// launches `<binary> __worker` (see src/core/self-spawn.ts), while
|
|
12119
|
+
// `join(__dirname,'..','worker.js')` evaluates to `/$bunfs/worker.js` — a
|
|
12120
|
+
// process-private virtual path that appears in NO command line. MEASURED: a real
|
|
12121
|
+
// compiled worker's cmdline is `<binary> __worker`, so the old predicate matched
|
|
12122
|
+
// nothing and orphans were NEVER reaped in the compiled form. That is the failure
|
|
12123
|
+
// this function exists to prevent: each orphan leaks ~0.5 GB and they accumulate
|
|
12124
|
+
// across restarts (daemon.ts records an 841-orphan / ~65 GB incident).
|
|
12125
|
+
//
|
|
12126
|
+
// The compiled predicate must keep the SAME conservatism the worker.js path had:
|
|
12127
|
+
// it identified this install by an ABSOLUTE path, so another botmux install's
|
|
12128
|
+
// orphans could never match. A basename-only check loses that — every released
|
|
12129
|
+
// install names its binary `botmux`, so install A would reap install B's
|
|
12130
|
+
// orphans (verified: with a same-named binary at a different absolute path, a
|
|
12131
|
+
// basename check reaps it).
|
|
12132
|
+
//
|
|
12133
|
+
// So match on the absolute path when the command line carries one. That is the
|
|
12134
|
+
// normal case for OUR workers: spawnWorker launches them via
|
|
12135
|
+
// `resolveEntrySpawn` → `process.execPath`, which the kernel has already
|
|
12136
|
+
// resolved to an absolute path (MEASURED in /proc/<pid>/cmdline:
|
|
12137
|
+
// `/…/botmux-linux-x64 __worker`). Only a RELATIVE argv[0] — a binary started
|
|
12138
|
+
// by a bare PATH lookup, which our own spawns never produce — falls back to the
|
|
12139
|
+
// basename, where cross-install ambiguity is unavoidable but the process was
|
|
12140
|
+
// also not started the way we start ours.
|
|
12141
|
+
const standalone = isStandaloneBinary();
|
|
12142
|
+
const workerPath = opts.workerPath ?? (standalone ? undefined : join(__dirname, '..', 'worker.js'));
|
|
12143
|
+
const selfBinary = standalone ? canonicalExecPath() : '';
|
|
12144
|
+
const selfBinaryName = standalone ? basename(selfBinary) : '';
|
|
12145
|
+
/** Does this command line belong to a worker of THIS install? */
|
|
12146
|
+
const isOurWorker = (cmd) => {
|
|
12147
|
+
if (workerPath !== undefined)
|
|
12148
|
+
return cmd.includes(workerPath);
|
|
12149
|
+
// Compiled form: `<binary> __worker`. The token alone is not enough — a
|
|
12150
|
+
// process merely mentioning `__worker` (a grep, another install) must be
|
|
12151
|
+
// spared.
|
|
12152
|
+
if (!cmd.includes(WORKER_ENTRY_SUBCOMMAND))
|
|
12153
|
+
return false;
|
|
12154
|
+
const argv0 = cmd.split(/\s+/, 1)[0] ?? '';
|
|
12155
|
+
// Absolute argv[0] → require the exact executable, so a same-named binary
|
|
12156
|
+
// from a different install is not ours.
|
|
12157
|
+
if (argv0.startsWith('/'))
|
|
12158
|
+
return argv0 === selfBinary;
|
|
12159
|
+
// Relative argv[0] (never produced by our own spawns) → basename is all
|
|
12160
|
+
// there is to compare.
|
|
12161
|
+
return basename(argv0) === selfBinaryName;
|
|
12162
|
+
};
|
|
12087
12163
|
let reaped = 0;
|
|
12088
12164
|
for (const p of procs) {
|
|
12089
12165
|
if (p.ppid !== 1)
|
|
12090
12166
|
continue; // parent still alive → not an orphan
|
|
12091
|
-
if (!p.cmd
|
|
12092
|
-
continue; // not OUR worker
|
|
12167
|
+
if (!isOurWorker(p.cmd))
|
|
12168
|
+
continue; // not OUR worker
|
|
12093
12169
|
try {
|
|
12094
12170
|
// SIGKILL, not SIGTERM: an orphan can be wedged in a sync code path (the
|
|
12095
12171
|
// very failure mode that produced it) where SIGTERM is lost. It holds no
|