@phnx-labs/agents-cli 1.23.38 → 1.23.40
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/CHANGELOG.md +22 -0
- package/README.md +7 -20
- package/dist/cli/command-registry.js +0 -2
- package/dist/commands/config.js +0 -4
- package/dist/commands/daemon.js +5 -5
- package/dist/commands/events.js +1 -1
- package/dist/commands/exec.d.ts +4 -0
- package/dist/commands/exec.js +14 -1
- package/dist/commands/lead.js +4 -3
- package/dist/commands/setup.d.ts +1 -1
- package/dist/commands/setup.js +1 -9
- package/dist/commands/ssh.js +4 -5
- package/dist/lib/accounting/account-pool-collect.d.ts +1 -0
- package/dist/lib/accounting/account-pool-collect.js +13 -7
- package/dist/lib/accounting/account-pool.d.ts +1 -0
- package/dist/lib/accounting/account-pool.js +4 -3
- package/dist/lib/accounting/usage.d.ts +1 -1
- package/dist/lib/answer-router.d.ts +1 -1
- package/dist/lib/answer-router.js +16 -6
- package/dist/lib/channels/providers/session.js +13 -0
- package/dist/lib/channels/registry.d.ts +1 -1
- package/dist/lib/config-keys.d.ts +1 -1
- package/dist/lib/config-keys.js +1 -4
- package/dist/lib/daemon/daemon.js +1 -6
- package/dist/lib/daemon/device-probe-service.js +8 -0
- package/dist/lib/daemon-services.d.ts +1 -1
- package/dist/lib/daemon-services.js +1 -6
- package/dist/lib/device-config.js +2 -11
- package/dist/lib/devices/stats-cache.d.ts +24 -1
- package/dist/lib/devices/stats-cache.js +52 -18
- package/dist/lib/devices/worker-pick.d.ts +1 -1
- package/dist/lib/devices/worker-pick.js +8 -1
- package/dist/lib/feed/answer.js +25 -1
- package/dist/lib/feed/attention.d.ts +8 -0
- package/dist/lib/feed/attention.js +39 -0
- package/dist/lib/feed/tab-delivery.d.ts +27 -0
- package/dist/lib/feed/tab-delivery.js +102 -0
- package/dist/lib/feed/watch.d.ts +3 -0
- package/dist/lib/feed/watch.js +63 -13
- package/dist/lib/hosts/passthrough.js +0 -1
- package/dist/lib/hosts/ready.d.ts +3 -0
- package/dist/lib/hosts/ready.js +41 -1
- package/dist/lib/installations/migrate.d.ts +0 -1
- package/dist/lib/installations/migrate.js +0 -17
- package/dist/lib/lead/drafts.d.ts +11 -0
- package/dist/lib/lead/drafts.js +34 -0
- package/dist/lib/lead/host.d.ts +5 -0
- package/dist/lib/lead/host.js +52 -1
- package/dist/lib/lead/paths.js +1 -1
- package/dist/lib/lead/tools.d.ts +1 -0
- package/dist/lib/lead/tools.js +22 -0
- package/dist/lib/menubar/snapshot.d.ts +0 -6
- package/dist/lib/menubar/snapshot.js +0 -18
- package/dist/lib/session/active.d.ts +2 -1
- package/dist/lib/session/active.js +21 -9
- package/dist/lib/session/hook-sessions.d.ts +10 -0
- package/dist/lib/session/hook-sessions.js +22 -10
- package/dist/lib/session/inject-target.d.ts +1 -0
- package/dist/lib/session/inject-target.js +2 -1
- package/dist/lib/session/pid-registry.d.ts +1 -0
- package/dist/lib/session/remote/watch.d.ts +1 -0
- package/dist/lib/smart-launch.d.ts +5 -1
- package/dist/lib/smart-launch.js +41 -20
- package/dist/lib/startup/command-registry.js +2 -1
- package/dist/lib/state.js +0 -1
- package/dist/lib/teams/placement-probe.d.ts +5 -2
- package/dist/lib/teams/placement-probe.js +119 -57
- package/dist/lib/teams/scheduler.d.ts +1 -0
- package/dist/lib/terminal/index.d.ts +1 -1
- package/dist/lib/terminal/index.js +1 -1
- package/dist/lib/terminal/inject.d.ts +0 -15
- package/dist/lib/terminal/inject.js +2 -16
- package/dist/lib/terminal/resolve.d.ts +2 -1
- package/dist/lib/terminal/resolve.js +13 -18
- package/dist/lib/types.d.ts +0 -3
- package/package.json +1 -1
- package/dist/commands/setup-watchdog.d.ts +0 -3
- package/dist/commands/setup-watchdog.js +0 -49
- package/dist/commands/watchdog.d.ts +0 -4
- package/dist/commands/watchdog.js +0 -361
- package/dist/lib/daemon/watchdog-service.d.ts +0 -10
- package/dist/lib/daemon/watchdog-service.js +0 -27
- package/dist/lib/session/presence.d.ts +0 -47
- package/dist/lib/session/presence.js +0 -100
- package/dist/lib/watchdog/history.d.ts +0 -20
- package/dist/lib/watchdog/history.js +0 -43
- package/dist/lib/watchdog/log.d.ts +0 -33
- package/dist/lib/watchdog/log.js +0 -117
- package/dist/lib/watchdog/read.d.ts +0 -8
- package/dist/lib/watchdog/read.js +0 -93
- package/dist/lib/watchdog/rotate.d.ts +0 -55
- package/dist/lib/watchdog/rotate.js +0 -220
- package/dist/lib/watchdog/runner.d.ts +0 -100
- package/dist/lib/watchdog/runner.js +0 -727
- package/dist/lib/watchdog/service.d.ts +0 -15
- package/dist/lib/watchdog/service.js +0 -36
- package/dist/lib/watchdog/watchdog-agent.d.ts +0 -8
- package/dist/lib/watchdog/watchdog-agent.js +0 -32
- package/dist/lib/watchdog/watchdog.d.ts +0 -43
- package/dist/lib/watchdog/watchdog.js +0 -116
- package/dist/lib/watchdog/watchdogTail.d.ts +0 -6
- package/dist/lib/watchdog/watchdogTail.js +0 -116
|
@@ -7,22 +7,34 @@ import path from 'path';
|
|
|
7
7
|
import { getTerminalsDir } from '../state.js';
|
|
8
8
|
import { listPidSessionEntries, parseSessionRecord, pidSessionEntryMatchesLiveProcess, readLivePidSessionEntry, readPidSessionEntry, readStateSessionRecord, RECORD_SKEW_MS, stateSessionRecordPath, } from './pid-registry.js';
|
|
9
9
|
const VERDICT_STATES = new Set(['done', 'open', 'unchecked']);
|
|
10
|
+
const TURN_KINDS = new Set(['asks', 'waiting', 'not_done', 'done', 'unjudged']);
|
|
10
11
|
function hookSessionsDir() {
|
|
11
12
|
return path.join(getTerminalsDir(), 'sessions');
|
|
12
13
|
}
|
|
13
|
-
export function
|
|
14
|
+
export function readSessionVerdicts(pid, sessionId, processStartedAtMs) {
|
|
14
15
|
const rec = readStateSessionRecord(pid, processStartedAtMs);
|
|
15
16
|
if (!rec || rec.pid !== pid || rec.session_id !== sessionId)
|
|
16
|
-
return
|
|
17
|
+
return {};
|
|
18
|
+
const current = (at) => typeof at === 'number' && Number.isFinite(at) && (processStartedAtMs === undefined || at >= processStartedAtMs - RECORD_SKEW_MS);
|
|
19
|
+
const out = {};
|
|
17
20
|
const v = rec.verdict;
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
if (v && typeof v === 'object' && typeof v.state === 'string' && VERDICT_STATES.has(v.state) && current(v.at)) {
|
|
22
|
+
const gaps = Array.isArray(v.gaps) ? v.gaps.filter((g) => typeof g === 'string' && g.length > 0) : [];
|
|
23
|
+
out.done = { state: v.state, gaps, at: new Date(v.at).toISOString() };
|
|
24
|
+
}
|
|
25
|
+
const t = rec.turnVerdict;
|
|
26
|
+
if (t && typeof t === 'object' && typeof t.kind === 'string' && TURN_KINDS.has(t.kind) && current(t.at)) {
|
|
27
|
+
out.turn = {
|
|
28
|
+
kind: t.kind,
|
|
29
|
+
quote: typeof t.quote === 'string' ? t.quote : '',
|
|
30
|
+
choices: Array.isArray(t.choices) ? t.choices.filter((c) => typeof c === 'string' && c.trim().length > 0) : [],
|
|
31
|
+
atMs: t.at,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
export function readDoneVerdict(pid, sessionId, processStartedAtMs) {
|
|
37
|
+
return readSessionVerdicts(pid, sessionId, processStartedAtMs).done;
|
|
26
38
|
}
|
|
27
39
|
function keepNewest(map, key, rec) {
|
|
28
40
|
const prev = map.get(key);
|
|
@@ -3,6 +3,7 @@ import { type InjectTarget } from '../terminal/index.js';
|
|
|
3
3
|
export declare function matchInjectSelector(session: ActiveSession, token: string): boolean;
|
|
4
4
|
export declare function resolveLiveInjectTarget(selector: string): Promise<{
|
|
5
5
|
target: InjectTarget | null;
|
|
6
|
+
session?: ActiveSession;
|
|
6
7
|
reason?: string;
|
|
7
8
|
hint?: string;
|
|
8
9
|
}>;
|
|
@@ -34,9 +34,10 @@ export async function resolveLiveInjectTarget(selector) {
|
|
|
34
34
|
if (!resolution.addressable) {
|
|
35
35
|
return {
|
|
36
36
|
target: null,
|
|
37
|
+
session: match,
|
|
37
38
|
reason: `Session "${selector}": ${resolution.reason}`,
|
|
38
39
|
hint: resolution.hint,
|
|
39
40
|
};
|
|
40
41
|
}
|
|
41
|
-
return { target: resolution.target };
|
|
42
|
+
return { target: resolution.target, session: match };
|
|
42
43
|
}
|
|
@@ -27,6 +27,7 @@ export interface SessionStartRecord {
|
|
|
27
27
|
cwd?: string;
|
|
28
28
|
ts?: number;
|
|
29
29
|
verdict?: unknown;
|
|
30
|
+
turnVerdict?: unknown;
|
|
30
31
|
}
|
|
31
32
|
export declare const RECORD_SKEW_MS = 5000;
|
|
32
33
|
export declare function parseSessionRecord<T extends SessionStartRecord = SessionStartRecord>(raw: string): T | undefined;
|
|
@@ -59,6 +59,7 @@ export interface SessionWatchRow extends Omit<ActiveSession, 'viewingIn' | 'cont
|
|
|
59
59
|
branch?: string;
|
|
60
60
|
rowKey: string;
|
|
61
61
|
sourceDevice: string;
|
|
62
|
+
delivery?: import('../../feed/tab-delivery.js').TabDelivery;
|
|
62
63
|
confirmedProject: string | null;
|
|
63
64
|
previous: boolean;
|
|
64
65
|
resumable: boolean;
|
|
@@ -39,7 +39,10 @@ export declare function resolveDeviceAuto(agent?: string, opts?: {
|
|
|
39
39
|
eligibleHosts?: string[];
|
|
40
40
|
localMachine?: string;
|
|
41
41
|
accountPicker?: boolean;
|
|
42
|
-
probe?: (pool: string[], agent?: AgentType
|
|
42
|
+
probe?: (pool: string[], agent?: AgentType, opts?: {
|
|
43
|
+
force?: boolean;
|
|
44
|
+
}) => Promise<Map<string, DevicePlacementSignal>>;
|
|
45
|
+
confirm?: (key: string) => Promise<boolean>;
|
|
43
46
|
preferred?: ReadonlySet<string>;
|
|
44
47
|
}): Promise<DeviceAutoPlan>;
|
|
45
48
|
export declare function resolveDeviceAffinity(opts?: DeviceAffinityOptions): DeviceAffinityPlan;
|
|
@@ -64,5 +67,6 @@ export declare function applyDeviceAutoToOptions(options: DeviceAutoHostOptions,
|
|
|
64
67
|
resolve?: (accountPicker: boolean) => DeviceAutoPlan | Promise<DeviceAutoPlan>;
|
|
65
68
|
agent?: string;
|
|
66
69
|
accountPickerRequested?: boolean;
|
|
70
|
+
onPlacing?: () => void;
|
|
67
71
|
}): Promise<DeviceAutoApplyResult>;
|
|
68
72
|
export {};
|
package/dist/lib/smart-launch.js
CHANGED
|
@@ -4,7 +4,8 @@ import { loadDevicesSync } from './devices/registry.js';
|
|
|
4
4
|
import { blocksPlacement } from './devices/health.js';
|
|
5
5
|
import { autoLaunchPreferredSet, describeAutoPool, filterAutoPool, isAutoPoolMember } from './devices/pool.js';
|
|
6
6
|
import { normalizeHost } from './machine-id.js';
|
|
7
|
-
import { probePoolSignals } from './teams/placement-probe.js';
|
|
7
|
+
import { confirmPlacementTarget, probePoolSignals } from './teams/placement-probe.js';
|
|
8
|
+
import { writePlacementSnapshot } from './devices/stats-cache.js';
|
|
8
9
|
import { pickBestDevice } from './teams/scheduler.js';
|
|
9
10
|
const DEFAULT_AFFINITY_ALPHA = 1.3;
|
|
10
11
|
export function affinityWeights(rows, alpha = DEFAULT_AFFINITY_ALPHA) {
|
|
@@ -102,25 +103,28 @@ export async function resolveDeviceAuto(agent, opts = {}) {
|
|
|
102
103
|
pool.push(local);
|
|
103
104
|
if (pool.length === 0)
|
|
104
105
|
throw new Error(formatEmptyAutoPoolError());
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
106
|
+
const collectSignals = async (force) => {
|
|
107
|
+
const signals = await (opts.probe ?? probePoolSignals)(pool, agent, { force });
|
|
108
|
+
if (!agent && !opts.probe) {
|
|
109
|
+
const { collectFleetHarnesses } = await import('./devices/harness-inventory.js');
|
|
110
|
+
const { isInteractiveTerminal } = await import('./format.js');
|
|
111
|
+
const { default: ora } = await import('ora');
|
|
112
|
+
const inventory = await collectFleetHarnesses({
|
|
113
|
+
devices: pool,
|
|
114
|
+
spinner: isInteractiveTerminal() ? (text) => ora(text).start() : undefined,
|
|
115
|
+
});
|
|
116
|
+
const byHost = new Map(inventory.map((result) => [normalizeHost(result.host), result]));
|
|
117
|
+
for (const key of pool) {
|
|
118
|
+
const result = byHost.get(key);
|
|
119
|
+
const accountEligible = !!result && !result.error && !result.skipped && result.rows.some((row) => row.ready);
|
|
120
|
+
const current = signals.get(key);
|
|
121
|
+
if (current)
|
|
122
|
+
signals.set(key, { ...current, installed: accountEligible, signedIn: accountEligible });
|
|
123
|
+
}
|
|
121
124
|
}
|
|
122
|
-
|
|
123
|
-
|
|
125
|
+
return signals;
|
|
126
|
+
};
|
|
127
|
+
const eligibleIn = (signals) => pool.filter((key) => {
|
|
124
128
|
const signal = signals.get(key);
|
|
125
129
|
if (signal?.reachable !== true || blocksPlacement(signal.headroom))
|
|
126
130
|
return false;
|
|
@@ -130,11 +134,27 @@ export async function resolveDeviceAuto(agent, opts = {}) {
|
|
|
130
134
|
? signal.pickerEligible === true
|
|
131
135
|
: signal.signedIn === true);
|
|
132
136
|
});
|
|
137
|
+
if (!opts.probe)
|
|
138
|
+
writePlacementSnapshot({ demandAt: Date.now() });
|
|
139
|
+
let signals = await collectSignals(false);
|
|
140
|
+
let eligiblePool = eligibleIn(signals);
|
|
141
|
+
if (eligiblePool.length === 0 && [...signals.values()].some((signal) => signal.fromSnapshot)) {
|
|
142
|
+
signals = await collectSignals(true);
|
|
143
|
+
eligiblePool = eligibleIn(signals);
|
|
144
|
+
}
|
|
133
145
|
if (eligiblePool.length === 0) {
|
|
134
146
|
throw new Error(formatNoHealthyDeviceError(pool, signals, agent));
|
|
135
147
|
}
|
|
136
148
|
const preferred = opts.preferred ?? autoLaunchPreferredSet(pool, { roster: pool });
|
|
137
|
-
const
|
|
149
|
+
const confirm = opts.confirm ?? confirmPlacementTarget;
|
|
150
|
+
let picked = pickBestDevice(eligiblePool, [], { signals, agentLabel: agent, preferred });
|
|
151
|
+
while (picked !== local && signals.get(picked)?.fromSnapshot && !(await confirm(picked))) {
|
|
152
|
+
signals.set(picked, { ...signals.get(picked), reachable: false, fromSnapshot: false });
|
|
153
|
+
eligiblePool = eligiblePool.filter((key) => key !== picked);
|
|
154
|
+
if (eligiblePool.length === 0)
|
|
155
|
+
throw new Error(formatNoHealthyDeviceError(pool, signals, agent));
|
|
156
|
+
picked = pickBestDevice(eligiblePool, [], { signals, agentLabel: agent, preferred });
|
|
157
|
+
}
|
|
138
158
|
return {
|
|
139
159
|
host: picked === local ? null : picked,
|
|
140
160
|
pickedDeviceKey: picked,
|
|
@@ -203,6 +223,7 @@ export async function applyDeviceAutoToOptions(options, deps = {}) {
|
|
|
203
223
|
if (!hasAuto) {
|
|
204
224
|
return { attempted: false };
|
|
205
225
|
}
|
|
226
|
+
deps.onPlacing?.();
|
|
206
227
|
const accountPickerRequested = deps.accountPickerRequested ?? false;
|
|
207
228
|
const resolve = deps.resolve ?? ((accountPicker) => resolveDeviceAuto(deps.agent, { accountPicker }));
|
|
208
229
|
const plan = await resolve(accountPickerRequested);
|
|
@@ -6,7 +6,7 @@ const LOADED_COMMAND_NAMES = [
|
|
|
6
6
|
'models', 'doctor',
|
|
7
7
|
'harness', 'harnesses', 'menubar', 'sync',
|
|
8
8
|
'refresh-rules', 'factory', 'insights', 'trace',
|
|
9
|
-
'
|
|
9
|
+
'events',
|
|
10
10
|
'ssh', 'devices', 'fleet', 'repos', 'repo', 'setup', 'uninstall', 'upgrade',
|
|
11
11
|
'teams', 'cloud', 'ps', 'send', 'feed', 'lead',
|
|
12
12
|
'daemon', 'recordings',
|
|
@@ -54,6 +54,7 @@ export const RETIRED_TOP_LEVEL_COMMANDS = new Set([
|
|
|
54
54
|
'perf',
|
|
55
55
|
'list',
|
|
56
56
|
'humans',
|
|
57
|
+
'watchdog',
|
|
57
58
|
'reminders',
|
|
58
59
|
'modes',
|
|
59
60
|
'feedback',
|
package/dist/lib/state.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { type DeviceStats } from '../devices/health.js';
|
|
2
|
+
import { type PlacementSnapshot, type ReadyProbeEntry } from '../devices/stats-cache.js';
|
|
2
3
|
import { type AgentType } from './agents.js';
|
|
3
4
|
import type { DevicePlacementSignal } from './scheduler.js';
|
|
4
5
|
export declare const READY_PROBE_TIMEOUT_MS = 8000;
|
|
5
|
-
export declare const SIGNAL_TTL_MS = 15000;
|
|
6
|
-
export declare function clearPlacementSignalCache(): void;
|
|
7
6
|
interface ReadinessInfo {
|
|
8
7
|
answered: boolean;
|
|
9
8
|
installed: boolean | undefined;
|
|
@@ -12,9 +11,13 @@ interface ReadinessInfo {
|
|
|
12
11
|
reason?: string;
|
|
13
12
|
timedOut?: boolean;
|
|
14
13
|
}
|
|
14
|
+
export declare function readinessFromProbe(entry: ReadyProbeEntry, agent: string): ReadinessInfo;
|
|
15
15
|
export declare function mergePlacementSignal(stats: DeviceStats | undefined, readiness: ReadinessInfo | undefined): DevicePlacementSignal;
|
|
16
|
+
export declare function snapshotSignal(snapshot: PlacementSnapshot, name: string, agent: string | undefined, now: number): DevicePlacementSignal | undefined;
|
|
16
17
|
export declare function probePoolSignals(pool: string[], agent?: AgentType, opts?: {
|
|
17
18
|
force?: boolean;
|
|
18
19
|
now?: number;
|
|
19
20
|
}): Promise<Map<string, DevicePlacementSignal>>;
|
|
21
|
+
export declare function refreshPlacementSnapshot(pool: string[], now?: number): Promise<number | null>;
|
|
22
|
+
export declare function confirmPlacementTarget(name: string): Promise<boolean>;
|
|
20
23
|
export {};
|
|
@@ -4,22 +4,16 @@ import { probeFleetStats, headroom } from '../devices/health.js';
|
|
|
4
4
|
import { loadDevicesSync } from '../devices/registry.js';
|
|
5
5
|
import { buildSshInvocation, writeAskpassShim } from '../devices/connect.js';
|
|
6
6
|
import { resolveDeviceProfile } from '../devices/resolve-profile.js';
|
|
7
|
-
import {
|
|
7
|
+
import { freshReadyProbe, freshSnapshotStats, placementDemandIsRecent, readPlacementSnapshot, retainHardwareFacts, writePlacementSnapshot, } from '../devices/stats-cache.js';
|
|
8
|
+
import { buildReadyProbeCommand, compactReadyView, hostAnswers, parseReadyProbe, viewAgentAccountEligibility, viewHasAgent, } from '../hosts/ready.js';
|
|
9
|
+
import { resolveHost } from '../hosts/registry.js';
|
|
8
10
|
import { collectRunCandidates, isSignInRecoverable, readinessFromCandidate, } from '../accounting/rotate.js';
|
|
9
11
|
import { localMachineId } from '../origin-machine.js';
|
|
10
12
|
import { normalizeHost } from '../machine-id.js';
|
|
11
13
|
import { checkCliAvailable } from './agents.js';
|
|
12
14
|
export const READY_PROBE_TIMEOUT_MS = 8_000;
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
function cacheKey(pool, agent) {
|
|
16
|
-
return `${agent ?? 'any-agent'}::${[...pool].map(normalizeHost).sort().join(',')}`;
|
|
17
|
-
}
|
|
18
|
-
export function clearPlacementSignalCache() {
|
|
19
|
-
cache.clear();
|
|
20
|
-
}
|
|
21
|
-
function probeRemoteReadiness(device, agent, usagePayload) {
|
|
22
|
-
const unknown = { answered: false, installed: undefined, signedIn: undefined, pickerEligible: undefined };
|
|
15
|
+
function probeRemoteReady(device, usagePayload) {
|
|
16
|
+
const unknown = () => ({ answered: false, version: null, view: '', fetchedAt: Date.now() });
|
|
23
17
|
let args;
|
|
24
18
|
let env;
|
|
25
19
|
try {
|
|
@@ -28,7 +22,7 @@ function probeRemoteReadiness(device, agent, usagePayload) {
|
|
|
28
22
|
({ args, env } = buildSshInvocation(device, [cmd], shim, {}, { agentOnly: true }));
|
|
29
23
|
}
|
|
30
24
|
catch {
|
|
31
|
-
return Promise.resolve(unknown);
|
|
25
|
+
return Promise.resolve(unknown());
|
|
32
26
|
}
|
|
33
27
|
return new Promise((resolve) => {
|
|
34
28
|
const child = spawn('ssh', args, {
|
|
@@ -54,27 +48,33 @@ function probeRemoteReadiness(device, agent, usagePayload) {
|
|
|
54
48
|
child.stdout.setEncoding('utf-8');
|
|
55
49
|
child.stdout.on('data', (chunk) => { stdout += chunk; });
|
|
56
50
|
child.stderr.resume();
|
|
57
|
-
child.on('error', () => finish(unknown));
|
|
51
|
+
child.on('error', () => finish(unknown()));
|
|
58
52
|
child.on('close', (code) => {
|
|
59
53
|
if (timedOut)
|
|
60
|
-
return finish({ ...unknown, timedOut: true });
|
|
54
|
+
return finish({ ...unknown(), timedOut: true });
|
|
61
55
|
if (code !== 0 || !stdout)
|
|
62
|
-
return finish(unknown);
|
|
56
|
+
return finish(unknown());
|
|
63
57
|
const probe = parseReadyProbe(stdout);
|
|
64
58
|
if (!probe.reachable)
|
|
65
|
-
return finish(unknown);
|
|
66
|
-
|
|
67
|
-
return finish({ answered: true, installed: false, signedIn: false, pickerEligible: false });
|
|
68
|
-
const installed = viewHasAgent(probe.view, agent);
|
|
69
|
-
const eligibility = installed
|
|
70
|
-
? viewAgentAccountEligibility(probe.view, agent)
|
|
71
|
-
: { signedIn: false, pickerEligible: false };
|
|
72
|
-
finish({ answered: true, installed, ...eligibility });
|
|
59
|
+
return finish(unknown());
|
|
60
|
+
finish({ answered: true, version: probe.version, view: compactReadyView(probe.view), fetchedAt: Date.now() });
|
|
73
61
|
});
|
|
74
62
|
child.stdin.on('error', () => { });
|
|
75
63
|
child.stdin.end(usagePayload);
|
|
76
64
|
});
|
|
77
65
|
}
|
|
66
|
+
export function readinessFromProbe(entry, agent) {
|
|
67
|
+
if (!entry.answered) {
|
|
68
|
+
return { answered: false, installed: undefined, signedIn: undefined, pickerEligible: undefined, timedOut: entry.timedOut };
|
|
69
|
+
}
|
|
70
|
+
if (!entry.version)
|
|
71
|
+
return { answered: true, installed: false, signedIn: false, pickerEligible: false };
|
|
72
|
+
const installed = viewHasAgent(entry.view, agent);
|
|
73
|
+
const eligibility = installed
|
|
74
|
+
? viewAgentAccountEligibility(entry.view, agent)
|
|
75
|
+
: { signedIn: false, pickerEligible: false };
|
|
76
|
+
return { answered: true, installed, ...eligibility };
|
|
77
|
+
}
|
|
78
78
|
export function mergePlacementSignal(stats, readiness) {
|
|
79
79
|
const reachable = readiness?.answered === true ? true : stats?.reachable;
|
|
80
80
|
return {
|
|
@@ -90,14 +90,55 @@ export function mergePlacementSignal(stats, readiness) {
|
|
|
90
90
|
reason: readiness?.reason,
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
|
-
export
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (!
|
|
98
|
-
return
|
|
93
|
+
export function snapshotSignal(snapshot, name, agent, now) {
|
|
94
|
+
const stats = freshSnapshotStats(snapshot, name, now);
|
|
95
|
+
if (!stats)
|
|
96
|
+
return undefined;
|
|
97
|
+
if (!agent)
|
|
98
|
+
return { ...mergePlacementSignal(stats, undefined), fromSnapshot: true };
|
|
99
|
+
const probe = freshReadyProbe(snapshot, name, now);
|
|
100
|
+
if (!probe)
|
|
101
|
+
return undefined;
|
|
102
|
+
return { ...mergePlacementSignal(stats, readinessFromProbe(probe, agent)), fromSnapshot: true };
|
|
103
|
+
}
|
|
104
|
+
async function localReadiness(agent) {
|
|
105
|
+
if (!checkCliAvailable(agent)[0])
|
|
106
|
+
return { answered: true, installed: false, signedIn: false, pickerEligible: false };
|
|
107
|
+
const candidates = await collectRunCandidates(agent).catch(() => null);
|
|
108
|
+
if (!candidates)
|
|
109
|
+
return { answered: true, installed: true, signedIn: undefined, pickerEligible: undefined };
|
|
110
|
+
const readiness = candidates.map((candidate) => readinessFromCandidate(candidate));
|
|
111
|
+
return {
|
|
112
|
+
answered: true,
|
|
113
|
+
installed: true,
|
|
114
|
+
signedIn: readiness.some((candidate) => candidate.ready),
|
|
115
|
+
pickerEligible: readiness.some((candidate) => candidate.ready || isSignInRecoverable(candidate)),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
async function probeLive(profiles, selfName, withReadiness) {
|
|
119
|
+
const remote = profiles.filter((d) => d.name !== selfName);
|
|
120
|
+
const usagePayload = withReadiness && remote.length > 0
|
|
121
|
+
? JSON.stringify(buildFleetStatePayload({ usageOnly: true }))
|
|
122
|
+
: '';
|
|
123
|
+
const [stats, probed] = await Promise.all([
|
|
124
|
+
profiles.length > 0 ? probeFleetStats(profiles, { selfName }) : Promise.resolve(new Map()),
|
|
125
|
+
withReadiness
|
|
126
|
+
? Promise.all(remote.map(async (d) => [d.name, await probeRemoteReady(d, usagePayload)]))
|
|
127
|
+
: Promise.resolve([]),
|
|
128
|
+
]);
|
|
129
|
+
const prior = readPlacementSnapshot().stats;
|
|
130
|
+
const rows = {};
|
|
131
|
+
for (const [name, row] of stats) {
|
|
132
|
+
const kept = retainHardwareFacts(row, prior[name]);
|
|
133
|
+
stats.set(name, kept);
|
|
134
|
+
rows[name] = kept;
|
|
135
|
+
}
|
|
136
|
+
const probes = new Map(probed);
|
|
137
|
+
writePlacementSnapshot({ stats: rows, readiness: Object.fromEntries(probes) });
|
|
138
|
+
return { stats, probes };
|
|
139
|
+
}
|
|
140
|
+
function resolvePoolProfiles(pool) {
|
|
99
141
|
const reg = loadDevicesSync();
|
|
100
|
-
const self = normalizeHost(localMachineId());
|
|
101
142
|
const lookup = (name) => reg[name] ?? reg[normalizeHost(name)];
|
|
102
143
|
const profiles = [];
|
|
103
144
|
const seen = new Set();
|
|
@@ -108,40 +149,61 @@ export async function probePoolSignals(pool, agent, opts = {}) {
|
|
|
108
149
|
seen.add(d.name);
|
|
109
150
|
}
|
|
110
151
|
}
|
|
152
|
+
return { lookup, profiles };
|
|
153
|
+
}
|
|
154
|
+
export async function probePoolSignals(pool, agent, opts = {}) {
|
|
155
|
+
const now = opts.now ?? Date.now();
|
|
156
|
+
const self = normalizeHost(localMachineId());
|
|
157
|
+
const { lookup, profiles } = resolvePoolProfiles(pool);
|
|
111
158
|
const selfProfile = profiles.find((d) => normalizeHost(d.name) === self);
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return [d.name, {
|
|
127
|
-
answered: true,
|
|
128
|
-
installed: true,
|
|
129
|
-
signedIn: readiness.some((candidate) => candidate.ready),
|
|
130
|
-
pickerEligible: readiness.some((candidate) => candidate.ready || isSignInRecoverable(candidate)),
|
|
131
|
-
}];
|
|
132
|
-
}
|
|
133
|
-
return [d.name, await probeRemoteReadiness(d, agent, usagePayload)];
|
|
134
|
-
}))
|
|
135
|
-
: []);
|
|
159
|
+
const snapshot = readPlacementSnapshot();
|
|
160
|
+
const cached = new Map();
|
|
161
|
+
const live = [];
|
|
162
|
+
for (const d of profiles) {
|
|
163
|
+
const signal = d === selfProfile || opts.force ? undefined : snapshotSignal(snapshot, d.name, agent, now);
|
|
164
|
+
if (signal)
|
|
165
|
+
cached.set(d.name, signal);
|
|
166
|
+
else
|
|
167
|
+
live.push(d);
|
|
168
|
+
}
|
|
169
|
+
const [{ stats, probes }, selfReadiness] = await Promise.all([
|
|
170
|
+
probeLive(live, selfProfile?.name, agent !== undefined),
|
|
171
|
+
agent && selfProfile ? localReadiness(agent) : Promise.resolve(undefined),
|
|
172
|
+
]);
|
|
136
173
|
const signals = new Map();
|
|
137
174
|
for (const name of pool) {
|
|
138
175
|
const d = lookup(name);
|
|
139
|
-
|
|
140
|
-
|
|
176
|
+
if (!d)
|
|
177
|
+
continue;
|
|
178
|
+
const fromSnapshot = cached.get(d.name);
|
|
179
|
+
if (fromSnapshot) {
|
|
180
|
+
signals.set(name, fromSnapshot);
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
const s = stats.get(d.name);
|
|
184
|
+
const probe = probes.get(d.name);
|
|
185
|
+
const inst = d === selfProfile ? selfReadiness : probe && agent ? readinessFromProbe(probe, agent) : undefined;
|
|
141
186
|
if (!s && !inst)
|
|
142
187
|
continue;
|
|
143
188
|
signals.set(name, mergePlacementSignal(s, inst));
|
|
144
189
|
}
|
|
145
|
-
cache.set(key, { at: now, signals });
|
|
146
190
|
return signals;
|
|
147
191
|
}
|
|
192
|
+
export async function refreshPlacementSnapshot(pool, now = Date.now()) {
|
|
193
|
+
if (!placementDemandIsRecent(readPlacementSnapshot(), now))
|
|
194
|
+
return null;
|
|
195
|
+
const self = normalizeHost(localMachineId());
|
|
196
|
+
const remote = resolvePoolProfiles(pool).profiles.filter((d) => normalizeHost(d.name) !== self);
|
|
197
|
+
const { probes } = await probeLive(remote, undefined, true);
|
|
198
|
+
return probes.size;
|
|
199
|
+
}
|
|
200
|
+
export async function confirmPlacementTarget(name) {
|
|
201
|
+
const host = await resolveHost(name);
|
|
202
|
+
if (host && hostAnswers(host))
|
|
203
|
+
return true;
|
|
204
|
+
const deviceName = resolvePoolProfiles([name]).profiles[0]?.name ?? name;
|
|
205
|
+
writePlacementSnapshot({
|
|
206
|
+
readiness: { [deviceName]: { answered: false, timedOut: true, version: null, view: '', fetchedAt: Date.now() } },
|
|
207
|
+
});
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
@@ -6,7 +6,7 @@ export { makeVscodiumAgentBackend, spawnUri, EDITOR_VARIANTS, type EditorVariant
|
|
|
6
6
|
export { planLayouts, type Packing } from './policy.js';
|
|
7
7
|
export { specsForRequest, describeLaunch, buildRequests, openSurface, openSurfaces, type OpenOptions, type OpenManyOptions, type BuildRequestsOptions, type SurfaceItem, } from './engine.js';
|
|
8
8
|
export { runLocal, runRemote, runSpec, remoteCommand, type HostResolver, type RunResult } from './transport.js';
|
|
9
|
-
export { backendCarriesPaste, injectIntoTerminal, tmuxSendKeysArgv, tmuxInjectSpecs, itermInjectScript, ghosttyInjectScript, appleScriptInjectSpec,
|
|
9
|
+
export { backendCarriesPaste, injectIntoTerminal, tmuxSendKeysArgv, tmuxInjectSpecs, itermInjectScript, ghosttyInjectScript, appleScriptInjectSpec, type InjectTarget, type InjectBackend, type InjectOptions, type InjectResult, } from './inject.js';
|
|
10
10
|
export { resolveInjectTarget, resolveInjectTargetForSession, type InjectResolution, type InjectRail, type ResolveOptions, } from './resolve.js';
|
|
11
11
|
export { iLoginShell } from './shell.js';
|
|
12
12
|
export { shellQuote } from './quote.js';
|
|
@@ -5,7 +5,7 @@ export { makeVscodiumAgentBackend, spawnUri, EDITOR_VARIANTS } from './backends/
|
|
|
5
5
|
export { planLayouts } from './policy.js';
|
|
6
6
|
export { specsForRequest, describeLaunch, buildRequests, openSurface, openSurfaces, } from './engine.js';
|
|
7
7
|
export { runLocal, runRemote, runSpec, remoteCommand } from './transport.js';
|
|
8
|
-
export { backendCarriesPaste, injectIntoTerminal, tmuxSendKeysArgv, tmuxInjectSpecs, itermInjectScript, ghosttyInjectScript, appleScriptInjectSpec,
|
|
8
|
+
export { backendCarriesPaste, injectIntoTerminal, tmuxSendKeysArgv, tmuxInjectSpecs, itermInjectScript, ghosttyInjectScript, appleScriptInjectSpec, } from './inject.js';
|
|
9
9
|
export { resolveInjectTarget, resolveInjectTargetForSession, } from './resolve.js';
|
|
10
10
|
export { iLoginShell } from './shell.js';
|
|
11
11
|
export { shellQuote } from './quote.js';
|
|
@@ -7,11 +7,6 @@ export type InjectTarget = {
|
|
|
7
7
|
} | {
|
|
8
8
|
backend: 'iterm';
|
|
9
9
|
session?: string;
|
|
10
|
-
} | {
|
|
11
|
-
backend: 'vscodium';
|
|
12
|
-
terminalId: string;
|
|
13
|
-
cli: string;
|
|
14
|
-
scheme: string;
|
|
15
10
|
} | {
|
|
16
11
|
backend: 'ghostty';
|
|
17
12
|
window?: string;
|
|
@@ -63,14 +58,4 @@ export declare function ghosttyInjectScript(text: string, opts: {
|
|
|
63
58
|
export declare function appleScriptInjectSpec(target: Extract<InjectTarget, {
|
|
64
59
|
backend: 'iterm' | 'ghostty';
|
|
65
60
|
}>, text: string, enter: boolean, combined?: boolean): LaunchSpec;
|
|
66
|
-
export declare function vscodiumInjectUri(scheme: string, terminalId: string, text: string, opts: {
|
|
67
|
-
enter: boolean;
|
|
68
|
-
combined: boolean;
|
|
69
|
-
}): string;
|
|
70
|
-
export declare function vscodiumInjectSpec(target: Extract<InjectTarget, {
|
|
71
|
-
backend: 'vscodium';
|
|
72
|
-
}>, text: string, opts: {
|
|
73
|
-
enter: boolean;
|
|
74
|
-
combined: boolean;
|
|
75
|
-
}): LaunchSpec;
|
|
76
61
|
export declare function injectIntoTerminal(target: InjectTarget, text: string, opts?: InjectOptions): Promise<InjectResult>;
|
|
@@ -2,9 +2,6 @@ import { appleScriptStr } from './quote.js';
|
|
|
2
2
|
import { runSpec } from './transport.js';
|
|
3
3
|
import { itermBackend, ghosttyBackend } from './backends/index.js';
|
|
4
4
|
import { currentContext } from './types.js';
|
|
5
|
-
function backendConfirmsDelivery(backend) {
|
|
6
|
-
return backend !== 'vscodium';
|
|
7
|
-
}
|
|
8
5
|
const CR = '\r';
|
|
9
6
|
export const BRACKETED_PASTE_START = '\u001b[200~';
|
|
10
7
|
export const BRACKETED_PASTE_END = '\u001b[201~';
|
|
@@ -66,15 +63,6 @@ export function appleScriptInjectSpec(target, text, enter, combined = false) {
|
|
|
66
63
|
: ghosttyInjectScript(text, { window: target.window, enter });
|
|
67
64
|
return { argv: ['osascript', '-e', script] };
|
|
68
65
|
}
|
|
69
|
-
const EXTENSION_AUTHORITY = 'swarmify.swarm-ext';
|
|
70
|
-
export function vscodiumInjectUri(scheme, terminalId, text, opts) {
|
|
71
|
-
const payload = { terminalId, text, enter: opts.enter, combined: opts.combined };
|
|
72
|
-
const p = Buffer.from(JSON.stringify(payload), 'utf8').toString('base64url');
|
|
73
|
-
return `${scheme}://${EXTENSION_AUTHORITY}/inject?p=${p}`;
|
|
74
|
-
}
|
|
75
|
-
export function vscodiumInjectSpec(target, text, opts) {
|
|
76
|
-
return { argv: [target.cli, '--open-url', vscodiumInjectUri(target.scheme, target.terminalId, text, opts)] };
|
|
77
|
-
}
|
|
78
66
|
export async function injectIntoTerminal(target, text, opts = {}) {
|
|
79
67
|
const enter = opts.enter !== false;
|
|
80
68
|
const combined = opts.combined === true;
|
|
@@ -87,15 +75,13 @@ export async function injectIntoTerminal(target, text, opts = {}) {
|
|
|
87
75
|
const payload = opts.paste === true ? `${BRACKETED_PASTE_START}${text}${BRACKETED_PASTE_END}` : text;
|
|
88
76
|
const specs = target.backend === 'tmux'
|
|
89
77
|
? tmuxInjectSpecs(target, payload, { enter, combined, socket: opts.socket })
|
|
90
|
-
: target
|
|
91
|
-
? [vscodiumInjectSpec(target, payload, { enter, combined })]
|
|
92
|
-
: [appleScriptInjectSpec(target, payload, enter, combined)];
|
|
78
|
+
: [appleScriptInjectSpec(target, payload, enter, combined)];
|
|
93
79
|
const writes = target.backend === 'tmux'
|
|
94
80
|
? specs.length
|
|
95
81
|
: target.backend === 'ghostty'
|
|
96
82
|
? enter ? 2 : 1
|
|
97
83
|
: enter && !combined ? 2 : 1;
|
|
98
|
-
const confirmed =
|
|
84
|
+
const confirmed = true;
|
|
99
85
|
if (opts.dryRun)
|
|
100
86
|
return { ok: true, confirmed, backend: target.backend, writes, started: 0, specs };
|
|
101
87
|
if (target.backend === 'iterm' || target.backend === 'ghostty') {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ActiveSession } from '../session/active.js';
|
|
2
2
|
import type { InjectTarget } from './inject.js';
|
|
3
|
-
export type InjectRail = 'tmux' | 'iterm' | '
|
|
3
|
+
export type InjectRail = 'tmux' | 'iterm' | 'ghostty';
|
|
4
4
|
export type InjectResolution = {
|
|
5
5
|
addressable: true;
|
|
6
6
|
rail: InjectRail;
|
|
@@ -14,6 +14,7 @@ export type InjectResolution = {
|
|
|
14
14
|
export interface ResolveOptions {
|
|
15
15
|
allowGhosttyFocus?: boolean;
|
|
16
16
|
}
|
|
17
|
+
export declare function typedByEditorTab(session: Pick<ActiveSession, 'host' | 'sessionId' | 'context'>): boolean;
|
|
17
18
|
export declare function addressabilityRecoveryHint(session: ActiveSession, fallbackId?: string): string;
|
|
18
19
|
export declare function resolveInjectTargetForSession(session: ActiveSession, opts?: ResolveOptions): InjectResolution;
|
|
19
20
|
export declare function resolveInjectTarget(sessionId: string, opts?: ResolveOptions): Promise<InjectResolution>;
|