Files
wehub-resource-sync d48cda4081
CI / Test (ubuntu-latest, Node 18.x, bun) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, npm) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, pnpm) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, yarn) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 20.x, bun) (push) Failing after 17m13s
CI / Test (ubuntu-latest, Node 20.x, npm) (push) Failing after 18m42s
CI / Test (ubuntu-latest, Node 20.x, pnpm) (push) Failing after 15m0s
CI / Test (ubuntu-latest, Node 20.x, yarn) (push) Failing after 49m44s
CI / Test (ubuntu-latest, Node 22.x, bun) (push) Failing after 51m55s
CI / Test (ubuntu-latest, Node 22.x, pnpm) (push) Failing after 21m57s
CI / Test (ubuntu-latest, Node 22.x, npm) (push) Failing after 37m39s
CI / Test (ubuntu-latest, Node 22.x, yarn) (push) Failing after 34m7s
CI / Validate Components (push) Failing after 37m15s
CI / Python Tests (push) Failing after 10m1s
CI / Security Scan (push) Failing after 10m1s
CI / Lint (push) Failing after 17m12s
CI / Coverage (push) Failing after 20m19s
CI / Test (macos-latest, Node 18.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, yarn) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, yarn) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, yarn) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:55 +08:00

71 lines
2.5 KiB
JavaScript

'use strict';
/**
* Concrete message sink for proximity triggers: delivers a session-to-session
* message through the canonical writer, the `ecc-tui messages send` CLI. The CLI
* owns the ecc2 session DB (the `messages` table the control pane reads), so we
* shell out to it rather than writing the SQLite directly and racing the daemon.
*
* Best-effort: if the binary is not found / the command fails, the call throws,
* and the dispatcher counts it as skipped — proximity never blocks on delivery.
* The command runner and binary path are injectable for tests.
*/
const fs = require('fs');
const path = require('path');
const { execFileSync } = require('child_process');
// Proximity trigger type → ecc-tui message kind (value_enum on `--kind`).
// A steer/hold is a collision warning; a transmit is a "what are you doing" query.
const KIND_BY_TYPE = {
proximity_steer: 'conflict',
proximity_hold: 'conflict',
proximity_transmit: 'query'
};
/**
* Resolve the ecc-tui binary: explicit override, env var, a built target in the
* repo, then the bare name (hope it's on PATH).
*/
function resolveEccBin(deps = {}) {
if (deps.binPath) return deps.binPath;
if (process.env.ECC_TUI_BIN && process.env.ECC_TUI_BIN.trim()) return process.env.ECC_TUI_BIN.trim();
const repoRoot = deps.repoRoot || path.join(__dirname, '..', '..', '..');
for (const rel of ['ecc2/target/release/ecc-tui', 'ecc2/target/debug/ecc-tui']) {
const candidate = path.join(repoRoot, rel);
try {
if (fs.existsSync(candidate)) return candidate;
} catch {
/* ignore */
}
}
return 'ecc-tui';
}
/**
* Build the `messages send` argv for a proximity message.
*/
function buildSendArgs({ fromSession, toSession, content, msgType }) {
const kind = KIND_BY_TYPE[msgType] || 'query';
return ['messages', 'send', '--from', String(fromSession), '--to', String(toSession), '--kind', kind, '--text', String(content)];
}
/**
* Create a `sendMessage({ fromSession, toSession, content, msgType })` sink that
* delivers via `ecc-tui messages send`. Inject `runCommand(bin, args)` for tests.
*/
function createEccMessageSink(deps = {}) {
const run = deps.runCommand || ((bin, args) => execFileSync(bin, args, { encoding: 'utf8', timeout: 5000, stdio: ['ignore', 'pipe', 'pipe'] }));
const bin = resolveEccBin(deps);
return function sendMessage(message) {
run(bin, buildSendArgs(message));
};
}
module.exports = {
KIND_BY_TYPE,
resolveEccBin,
buildSendArgs,
createEccMessageSink
};