@phnx-labs/agents-cli 1.22.122 → 1.22.123
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 +261 -0
- package/README.md +49 -10
- package/dist/bootstrap.js +22 -17
- package/dist/cli/command-registry.d.ts +0 -1
- package/dist/cli/command-registry.js +2 -10
- package/dist/commands/auth.js +13 -4
- package/dist/commands/browser.js +3 -4
- package/dist/commands/cloud-transcripts.d.ts +7 -0
- package/dist/commands/cloud-transcripts.js +100 -0
- package/dist/commands/cloud.js +5 -0
- package/dist/commands/computer.d.ts +0 -12
- package/dist/commands/computer.js +14 -124
- package/dist/commands/config.js +5 -4
- package/dist/commands/daemon-index.d.ts +2 -0
- package/dist/commands/daemon-index.js +44 -0
- package/dist/commands/daemon.js +6 -0
- package/dist/commands/doctor.js +3 -4
- package/dist/commands/exec.d.ts +5 -0
- package/dist/commands/exec.js +35 -7
- package/dist/commands/feed-watch.js +12 -0
- package/dist/commands/feed.d.ts +1 -1
- package/dist/commands/feed.js +7 -4
- package/dist/commands/insights.js +3 -1
- package/dist/commands/inspect.js +1 -1
- package/dist/commands/logs.js +2 -1
- package/dist/commands/models.js +1 -1
- package/dist/commands/prune.js +6 -28
- package/dist/commands/ps-roster.d.ts +0 -1
- package/dist/commands/ps-roster.js +2 -21
- package/dist/commands/ps.js +13 -1
- package/dist/commands/recordings.d.ts +2 -0
- package/dist/commands/recordings.js +117 -0
- package/dist/commands/routines.js +1 -1
- package/dist/commands/secrets-passthrough.js +3 -3
- package/dist/commands/send.js +33 -20
- package/dist/commands/sessions-backfill.d.ts +1 -0
- package/dist/commands/sessions-backfill.js +48 -13
- package/dist/commands/sessions-migrate.d.ts +1 -1
- package/dist/commands/sessions-migrate.js +11 -10
- package/dist/commands/sessions-optimize.d.ts +1 -0
- package/dist/commands/sessions-optimize.js +7 -4
- package/dist/commands/sessions-resume.js +8 -1
- package/dist/commands/sessions-stats.d.ts +2 -0
- package/dist/commands/sessions-stats.js +24 -7
- package/dist/commands/sessions.d.ts +5 -11
- package/dist/commands/sessions.js +8 -236
- package/dist/commands/setup-computer.js +1 -2
- package/dist/commands/setup.js +1 -1
- package/dist/commands/teams.js +2 -2
- package/dist/commands/testdata/feed-hub.d.ts +1 -0
- package/dist/commands/testdata/feed-hub.js +11 -0
- package/dist/commands/trash.d.ts +0 -1
- package/dist/commands/trash.js +74 -10
- package/dist/lib/accounting/usage-sync.js +7 -0
- package/dist/lib/agent-modes.d.ts +1 -1
- package/dist/lib/agent-modes.js +11 -5
- package/dist/lib/auth-mint.d.ts +4 -0
- package/dist/lib/auth-mint.js +6 -4
- package/dist/lib/browser/native-history.test-fixture.d.ts +12 -0
- package/dist/lib/browser/native-history.test-fixture.js +43 -0
- package/dist/lib/browser/paths.d.ts +5 -0
- package/dist/lib/browser/paths.js +7 -1
- package/dist/lib/browser/sessions-list.d.ts +28 -1
- package/dist/lib/browser/sessions-list.js +137 -25
- package/dist/lib/channels/providers/rush.d.ts +2 -1
- package/dist/lib/channels/providers/rush.js +2 -2
- package/dist/lib/channels/providers/session.d.ts +1 -0
- package/dist/lib/channels/providers/session.js +23 -12
- package/dist/lib/channels/registry.d.ts +9 -2
- package/dist/lib/channels/send.d.ts +5 -10
- package/dist/lib/channels/send.js +88 -50
- package/dist/lib/cloud/rush.d.ts +6 -0
- package/dist/lib/cloud/rush.js +18 -3
- package/dist/lib/computer-client.d.ts +19 -0
- package/dist/lib/computer-client.js +104 -0
- package/dist/lib/config-keys.d.ts +5 -1
- package/dist/lib/config-keys.js +14 -11
- package/dist/lib/daemon/auth-sync-service.js +13 -0
- package/dist/lib/daemon/daemon.js +20 -8
- package/dist/lib/daemon/owner-device-delivery-service.d.ts +10 -0
- package/dist/lib/daemon/owner-device-delivery-service.js +28 -0
- package/dist/lib/daemon-services.d.ts +2 -1
- package/dist/lib/daemon-services.js +17 -5
- package/dist/lib/device-config.d.ts +4 -1
- package/dist/lib/device-config.js +57 -7
- package/dist/lib/devices/doctor-findings.d.ts +2 -3
- package/dist/lib/devices/doctor-findings.js +10 -19
- package/dist/lib/event-provenance.d.ts +1 -0
- package/dist/lib/event-provenance.js +2 -0
- package/dist/lib/exec.d.ts +1 -0
- package/dist/lib/exec.js +20 -15
- package/dist/lib/feed/pr-status.d.ts +5 -1
- package/dist/lib/feed/pr-status.js +44 -3
- package/dist/lib/feed/tool-activity.js +9 -6
- package/dist/lib/feed/tools.d.ts +4 -1
- package/dist/lib/feed/tools.js +8 -11
- package/dist/lib/feed-broadcast.d.ts +5 -3
- package/dist/lib/feed-broadcast.js +47 -36
- package/dist/lib/fleet-shared-state.d.ts +5 -0
- package/dist/lib/fleet-shared-state.js +8 -0
- package/dist/lib/github/project-prs.d.ts +4 -1
- package/dist/lib/github/project-prs.js +18 -5
- package/dist/lib/help.d.ts +1 -0
- package/dist/lib/help.js +8 -0
- package/dist/lib/helper-versions.js +1 -1
- package/dist/lib/hosts/passthrough.js +5 -8
- package/dist/lib/hosts/remote-cmd.d.ts +2 -7
- package/dist/lib/hosts/remote-cmd.js +14 -22
- package/dist/lib/hosts/routing-flag.d.ts +22 -0
- package/dist/lib/hosts/routing-flag.js +127 -14
- package/dist/lib/identity/index.d.ts +22 -0
- package/dist/lib/identity/index.js +3 -0
- package/dist/lib/installations/migrate.d.ts +7 -0
- package/dist/lib/installations/migrate.js +99 -88
- package/dist/lib/installations/versions.js +2 -2
- package/dist/lib/launch-identity.d.ts +6 -1
- package/dist/lib/launch-identity.js +12 -2
- package/dist/lib/menubar/install-menubar.d.ts +1 -0
- package/dist/lib/menubar/install-menubar.js +8 -5
- package/dist/lib/menubar/snapshot.js +2 -3
- package/dist/lib/notify.d.ts +7 -14
- package/dist/lib/notify.js +29 -75
- package/dist/lib/owner-message.d.ts +4 -6
- package/dist/lib/owner-message.js +12 -11
- package/dist/lib/owner-notify-tokens.d.ts +49 -0
- package/dist/lib/owner-notify-tokens.js +214 -0
- package/dist/lib/owner-notify.d.ts +75 -0
- package/dist/lib/owner-notify.js +144 -0
- package/dist/lib/recordings/config.d.ts +11 -0
- package/dist/lib/recordings/config.js +54 -0
- package/dist/lib/recordings/identity.d.ts +12 -0
- package/dist/lib/recordings/identity.js +57 -0
- package/dist/lib/recordings/ledger.d.ts +16 -0
- package/dist/lib/recordings/ledger.js +141 -0
- package/dist/lib/recordings/model.d.ts +29 -0
- package/dist/lib/recordings/model.js +28 -0
- package/dist/lib/recordings/pipeline.d.ts +44 -0
- package/dist/lib/recordings/pipeline.js +272 -0
- package/dist/lib/recordings/process.d.ts +17 -0
- package/dist/lib/recordings/process.js +94 -0
- package/dist/lib/recordings/service.d.ts +15 -0
- package/dist/lib/recordings/service.js +45 -0
- package/dist/lib/recordings/settle.d.ts +21 -0
- package/dist/lib/recordings/settle.js +92 -0
- package/dist/lib/recordings/transcode.d.ts +13 -0
- package/dist/lib/recordings/transcode.js +44 -0
- package/dist/lib/reminders.d.ts +0 -1
- package/dist/lib/reminders.js +1 -1
- package/dist/lib/reserved-stores.d.ts +3 -0
- package/dist/lib/reserved-stores.js +13 -0
- package/dist/lib/routine-notify-owner.d.ts +3 -23
- package/dist/lib/routine-notify-owner.js +26 -107
- package/dist/lib/rush-api.d.ts +1 -0
- package/dist/lib/rush-api.js +1 -0
- package/dist/lib/session/active.d.ts +18 -2
- package/dist/lib/session/active.js +47 -37
- package/dist/lib/session/cloud.js +18 -45
- package/dist/lib/session/db.d.ts +2 -0
- package/dist/lib/session/db.js +13 -4
- package/dist/lib/session/glance-files.d.ts +4 -3
- package/dist/lib/session/glance-files.js +31 -0
- package/dist/lib/session/inject-target.js +12 -2
- package/dist/lib/session/pid-registry.d.ts +2 -0
- package/dist/lib/session/pid-registry.js +6 -2
- package/dist/lib/session/presentation.d.ts +21 -0
- package/dist/lib/session/presentation.js +198 -0
- package/dist/lib/session/projection.js +9 -2
- package/dist/lib/sqlite.d.ts +3 -1
- package/dist/lib/sqlite.js +7 -3
- package/dist/lib/standalone-tools.js +1 -1
- package/dist/lib/startup/command-registry.js +9 -4
- package/dist/lib/state.d.ts +2 -2
- package/dist/lib/state.js +3 -5
- package/dist/lib/terminal/inject.js +1 -1
- package/dist/lib/testdata/owner-notify-api.d.ts +36 -0
- package/dist/lib/testdata/owner-notify-api.js +102 -0
- package/dist/lib/trash.d.ts +14 -0
- package/dist/lib/trash.js +75 -0
- package/dist/lib/types.d.ts +0 -34
- package/package.json +1 -1
- package/dist/commands/feedback.d.ts +0 -2
- package/dist/commands/feedback.js +0 -68
- package/dist/commands/humans.d.ts +0 -2
- package/dist/commands/humans.js +0 -83
- package/dist/commands/modes.d.ts +0 -2
- package/dist/commands/modes.js +0 -134
- package/dist/commands/reminders.d.ts +0 -2
- package/dist/commands/reminders.js +0 -49
- package/dist/lib/channels/owner-forward.d.ts +0 -25
- package/dist/lib/channels/owner-forward.js +0 -78
- package/dist/lib/channels/owner-sink.d.ts +0 -10
- package/dist/lib/channels/owner-sink.js +0 -26
- package/dist/lib/humans.d.ts +0 -12
- package/dist/lib/humans.js +0 -64
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { BasePeriodicService } from '../daemon/service.js';
|
|
2
|
+
import { readRecordingsConfig, resolveRecordingDirectory } from './config.js';
|
|
3
|
+
import { RecordingPipeline } from './pipeline.js';
|
|
4
|
+
import { RecordingSettler } from './settle.js';
|
|
5
|
+
export class RecordingsService extends BasePeriodicService {
|
|
6
|
+
id = 'recordings';
|
|
7
|
+
intervalMs = 2_000;
|
|
8
|
+
deadlineMs = 25_000;
|
|
9
|
+
directory = '';
|
|
10
|
+
watchedSinceMs = 0;
|
|
11
|
+
startedAtMs = 0;
|
|
12
|
+
pipeline = null;
|
|
13
|
+
settler = null;
|
|
14
|
+
async onStart(ctx) {
|
|
15
|
+
this.pipeline = new RecordingPipeline({
|
|
16
|
+
reportError: (message) => ctx.log('ERROR', `recordings: ${message}`),
|
|
17
|
+
});
|
|
18
|
+
this.settler = new RecordingSettler();
|
|
19
|
+
this.startedAtMs = Date.now();
|
|
20
|
+
await this.pipeline.recoverInterrupted();
|
|
21
|
+
}
|
|
22
|
+
async onTick(ctx, signal) {
|
|
23
|
+
if (!this.pipeline || !this.settler)
|
|
24
|
+
return;
|
|
25
|
+
const directory = await resolveRecordingDirectory();
|
|
26
|
+
const configuredSince = Date.parse((await readRecordingsConfig()).watchedSince ?? '');
|
|
27
|
+
const watchedSinceMs = Number.isFinite(configuredSince) ? configuredSince : this.startedAtMs;
|
|
28
|
+
if (directory !== this.directory || watchedSinceMs !== this.watchedSinceMs) {
|
|
29
|
+
this.directory = directory;
|
|
30
|
+
this.watchedSinceMs = watchedSinceMs;
|
|
31
|
+
this.settler = new RecordingSettler();
|
|
32
|
+
ctx.log('INFO', `Recordings watching ${this.directory}`);
|
|
33
|
+
}
|
|
34
|
+
const scan = await this.settler.scan(this.directory, { notBeforeMs: this.watchedSinceMs });
|
|
35
|
+
for (const candidate of scan.latest)
|
|
36
|
+
this.pipeline.observeLatest(candidate);
|
|
37
|
+
await this.pipeline.queue(scan.ready);
|
|
38
|
+
await this.pipeline.drain({ awaitUploads: false, signal });
|
|
39
|
+
}
|
|
40
|
+
async onStop() {
|
|
41
|
+
await this.pipeline?.stop();
|
|
42
|
+
this.pipeline = null;
|
|
43
|
+
this.settler = null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type RecordingCandidate } from './model.js';
|
|
2
|
+
export interface RecordingScan {
|
|
3
|
+
latest: RecordingCandidate[];
|
|
4
|
+
ready: RecordingCandidate[];
|
|
5
|
+
}
|
|
6
|
+
export interface RecordingSettlerOptions {
|
|
7
|
+
settleMs?: number;
|
|
8
|
+
now?: () => number;
|
|
9
|
+
sessionsAt?: (recordedAtMs: number) => Promise<string | undefined>;
|
|
10
|
+
}
|
|
11
|
+
export declare class RecordingSettler {
|
|
12
|
+
private readonly observations;
|
|
13
|
+
private readonly settleMs;
|
|
14
|
+
private readonly now;
|
|
15
|
+
private readonly sessionsAt;
|
|
16
|
+
constructor(options?: RecordingSettlerOptions);
|
|
17
|
+
scan(directory: string, options?: {
|
|
18
|
+
notBeforeMs?: number;
|
|
19
|
+
}): Promise<RecordingScan>;
|
|
20
|
+
}
|
|
21
|
+
export declare function candidateForFile(filePath: string): Promise<RecordingCandidate>;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { getActiveSessions } from '../session/active.js';
|
|
4
|
+
import { cleanShotStem, isNewerRecording, isRecordingFile, slugifyRecordingStem, } from './model.js';
|
|
5
|
+
async function sessionAtRecordingTime(recordedAtMs) {
|
|
6
|
+
const sessions = await getActiveSessions({ localOnly: true });
|
|
7
|
+
const matching = sessions.filter((session) => session.sessionId && (session.startedAtMs ?? Number.POSITIVE_INFINITY) <= recordedAtMs);
|
|
8
|
+
return matching.length === 1 ? matching[0].sessionId : undefined;
|
|
9
|
+
}
|
|
10
|
+
export class RecordingSettler {
|
|
11
|
+
observations = new Map();
|
|
12
|
+
settleMs;
|
|
13
|
+
now;
|
|
14
|
+
sessionsAt;
|
|
15
|
+
constructor(options = {}) {
|
|
16
|
+
this.settleMs = options.settleMs ?? 10_000;
|
|
17
|
+
this.now = options.now ?? Date.now;
|
|
18
|
+
this.sessionsAt = options.sessionsAt ?? sessionAtRecordingTime;
|
|
19
|
+
}
|
|
20
|
+
async scan(directory, options = {}) {
|
|
21
|
+
const names = await fs.readdir(directory);
|
|
22
|
+
const now = this.now();
|
|
23
|
+
const seen = new Set();
|
|
24
|
+
const candidates = [];
|
|
25
|
+
await Promise.all(names.map(async (name) => {
|
|
26
|
+
const filePath = path.join(directory, name);
|
|
27
|
+
if (!isRecordingFile(filePath))
|
|
28
|
+
return;
|
|
29
|
+
const stat = await fs.stat(filePath).catch(() => null);
|
|
30
|
+
if (!stat?.isFile())
|
|
31
|
+
return;
|
|
32
|
+
seen.add(filePath);
|
|
33
|
+
const previous = this.observations.get(filePath);
|
|
34
|
+
const recordedAtMs = stat.birthtimeMs > 0 ? stat.birthtimeMs : stat.mtimeMs;
|
|
35
|
+
if (options.notBeforeMs !== undefined && recordedAtMs < options.notBeforeMs)
|
|
36
|
+
return;
|
|
37
|
+
const candidate = {
|
|
38
|
+
path: filePath,
|
|
39
|
+
stem: cleanShotStem(filePath),
|
|
40
|
+
slug: slugifyRecordingStem(cleanShotStem(filePath)),
|
|
41
|
+
size: stat.size,
|
|
42
|
+
mtimeMs: stat.mtimeMs,
|
|
43
|
+
recordedAt: new Date(recordedAtMs).toISOString(),
|
|
44
|
+
sessionId: previous?.candidate.sessionId ?? await this.sessionsAt(recordedAtMs),
|
|
45
|
+
};
|
|
46
|
+
const unchangedSinceMs = previous && previous.candidate.size === candidate.size
|
|
47
|
+
? previous.unchangedSinceMs
|
|
48
|
+
: now;
|
|
49
|
+
const readyEmitted = previous?.candidate.size === candidate.size && previous.readyEmitted;
|
|
50
|
+
this.observations.set(filePath, { candidate, unchangedSinceMs, readyEmitted: readyEmitted === true });
|
|
51
|
+
candidates.push(candidate);
|
|
52
|
+
}));
|
|
53
|
+
for (const filePath of this.observations.keys()) {
|
|
54
|
+
if (!seen.has(filePath))
|
|
55
|
+
this.observations.delete(filePath);
|
|
56
|
+
}
|
|
57
|
+
const latestByStem = new Map();
|
|
58
|
+
for (const candidate of candidates) {
|
|
59
|
+
const current = latestByStem.get(candidate.stem);
|
|
60
|
+
if (!current || isNewerRecording(candidate, current))
|
|
61
|
+
latestByStem.set(candidate.stem, candidate);
|
|
62
|
+
}
|
|
63
|
+
const latest = [...latestByStem.values()];
|
|
64
|
+
const ready = latest.filter((candidate) => {
|
|
65
|
+
const observation = this.observations.get(candidate.path);
|
|
66
|
+
if (!observation || observation.readyEmitted || now - observation.unchangedSinceMs < this.settleMs)
|
|
67
|
+
return false;
|
|
68
|
+
observation.readyEmitted = true;
|
|
69
|
+
return true;
|
|
70
|
+
});
|
|
71
|
+
return { latest, ready };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export async function candidateForFile(filePath) {
|
|
75
|
+
const resolved = path.resolve(filePath);
|
|
76
|
+
if (!isRecordingFile(resolved))
|
|
77
|
+
throw new Error('Recording must be an .mp4 or .mov file.');
|
|
78
|
+
const stat = await fs.stat(resolved);
|
|
79
|
+
if (!stat.isFile())
|
|
80
|
+
throw new Error(`Recording is not a file: ${resolved}`);
|
|
81
|
+
const recordedAtMs = stat.birthtimeMs > 0 ? stat.birthtimeMs : stat.mtimeMs;
|
|
82
|
+
const stem = cleanShotStem(resolved);
|
|
83
|
+
return {
|
|
84
|
+
path: resolved,
|
|
85
|
+
stem,
|
|
86
|
+
slug: slugifyRecordingStem(stem),
|
|
87
|
+
size: stat.size,
|
|
88
|
+
mtimeMs: stat.mtimeMs,
|
|
89
|
+
recordedAt: new Date(recordedAtMs).toISOString(),
|
|
90
|
+
sessionId: await sessionAtRecordingTime(recordedAtMs),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const FFMPEG_INSTALL_HINT: string;
|
|
2
|
+
export declare class RecordingDependencyError extends Error {
|
|
3
|
+
constructor(message: string);
|
|
4
|
+
}
|
|
5
|
+
export declare function resolveFfmpegBin(): string;
|
|
6
|
+
export interface TranscodedRecording {
|
|
7
|
+
filePath: string;
|
|
8
|
+
cleanup: () => Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export declare function transcodeRecording(sourcePath: string, signal?: AbortSignal, options?: {
|
|
11
|
+
ffmpegBin?: string;
|
|
12
|
+
platform?: NodeJS.Platform;
|
|
13
|
+
}): Promise<TranscodedRecording>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import * as os from 'node:os';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import { findInPath } from '../agent-spec/agents.js';
|
|
5
|
+
import { processFailure, runProcess } from './process.js';
|
|
6
|
+
export const FFMPEG_INSTALL_HINT = process.platform === 'darwin'
|
|
7
|
+
? 'Install it with `brew install ffmpeg`.'
|
|
8
|
+
: 'Install it with your system package manager (for example `apt install ffmpeg`).';
|
|
9
|
+
export class RecordingDependencyError extends Error {
|
|
10
|
+
constructor(message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = 'RecordingDependencyError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function resolveFfmpegBin() {
|
|
16
|
+
const explicit = process.env.FFMPEG_BIN?.trim();
|
|
17
|
+
const resolved = explicit || findInPath('ffmpeg');
|
|
18
|
+
if (!resolved)
|
|
19
|
+
throw new RecordingDependencyError(`ffmpeg is required to publish recordings. ${FFMPEG_INSTALL_HINT}`);
|
|
20
|
+
return resolved;
|
|
21
|
+
}
|
|
22
|
+
export async function transcodeRecording(sourcePath, signal, options = {}) {
|
|
23
|
+
const ffmpeg = options.ffmpegBin ?? resolveFfmpegBin();
|
|
24
|
+
const directory = await fs.mkdtemp(path.join(os.tmpdir(), 'agents-recording-'));
|
|
25
|
+
const output = path.join(directory, 'recording.mp4');
|
|
26
|
+
const codec = (options.platform ?? process.platform) === 'darwin' ? 'h264_videotoolbox' : 'libx264';
|
|
27
|
+
const args = [
|
|
28
|
+
'-hide_banner', '-loglevel', 'error', '-y', '-i', sourcePath,
|
|
29
|
+
'-map', '0:v:0', '-map', '0:a?',
|
|
30
|
+
'-vf', "scale=w='min(1920,iw)':h='min(1080,ih)':force_original_aspect_ratio=decrease:force_divisible_by=2,fps=30",
|
|
31
|
+
'-c:v', codec, '-b:v', '3M', '-maxrate', '3M', '-bufsize', '6M', '-pix_fmt', 'yuv420p',
|
|
32
|
+
'-c:a', 'aac', '-b:a', '128k', '-movflags', '+faststart', output,
|
|
33
|
+
];
|
|
34
|
+
try {
|
|
35
|
+
const result = await runProcess(ffmpeg, args, { signal });
|
|
36
|
+
if (result.exitCode !== 0)
|
|
37
|
+
throw processFailure('ffmpeg', args, result);
|
|
38
|
+
return { filePath: output, cleanup: () => fs.rm(directory, { recursive: true, force: true }) };
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
await fs.rm(directory, { recursive: true, force: true });
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
package/dist/lib/reminders.d.ts
CHANGED
|
@@ -3,6 +3,5 @@ export interface Reminder {
|
|
|
3
3
|
full: string;
|
|
4
4
|
}
|
|
5
5
|
export declare function setRemindersFilePathForTest(filePath: string | null): string | null;
|
|
6
|
-
export declare function remindersFilePath(): string;
|
|
7
6
|
export declare function loadReminders(filePath?: string): Reminder[];
|
|
8
7
|
export declare function pickReminderForSession(reminders: Reminder[], sessionId?: string): Reminder | null;
|
package/dist/lib/reminders.js
CHANGED
|
@@ -8,7 +8,7 @@ export function setRemindersFilePathForTest(filePath) {
|
|
|
8
8
|
remindersFilePathOverride = filePath;
|
|
9
9
|
return prev;
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
function remindersFilePath() {
|
|
12
12
|
return remindersFilePathOverride ?? path.join(getUserAgentsDir(), 'reminders', 'reminders.yaml');
|
|
13
13
|
}
|
|
14
14
|
function isRecord(value) {
|
|
@@ -13,6 +13,9 @@ export declare function assertReservedAuthBackend(backend: SecretsBackend): void
|
|
|
13
13
|
export declare function isReservedBundleBackendError(error: unknown): boolean;
|
|
14
14
|
export declare const RESERVED_STORES: Record<AgentId, string>;
|
|
15
15
|
export declare function reservedStoreName(harness: AgentId): string;
|
|
16
|
+
export declare const OWNER_NOTIFY_TOKEN_KEY = "PHOENIX_DEVICE_TOKEN";
|
|
17
|
+
export declare function canHoldOwnerNotifyToken(device: string): boolean;
|
|
18
|
+
export declare function ownerNotifyStoreName(device: string): string;
|
|
16
19
|
export declare function isReservedStoreName(name: string): boolean;
|
|
17
20
|
export type StorableCredentialKind = 'setup-token' | 'api-key';
|
|
18
21
|
export declare function assertStorableCredentialKind(kind: string, harness?: AgentId): asserts kind is StorableCredentialKind;
|
|
@@ -50,10 +50,23 @@ export function reservedStoreName(harness) {
|
|
|
50
50
|
throw new Error(`No reserved store for '${harness}'.`);
|
|
51
51
|
return name;
|
|
52
52
|
}
|
|
53
|
+
const OWNER_NOTIFY_STORE_PREFIX = '__notify-';
|
|
54
|
+
const OWNER_NOTIFY_STORE_PATTERN = /^__notify-[a-z0-9._-]{1,37}__$/;
|
|
55
|
+
export const OWNER_NOTIFY_TOKEN_KEY = 'PHOENIX_DEVICE_TOKEN';
|
|
56
|
+
export function canHoldOwnerNotifyToken(device) {
|
|
57
|
+
return OWNER_NOTIFY_STORE_PATTERN.test(`${OWNER_NOTIFY_STORE_PREFIX}${device.trim().toLowerCase()}__`);
|
|
58
|
+
}
|
|
59
|
+
export function ownerNotifyStoreName(device) {
|
|
60
|
+
if (!canHoldOwnerNotifyToken(device))
|
|
61
|
+
throw new Error(`Device name '${device}' is too long or malformed to key an owner-notify token store (37 characters max).`);
|
|
62
|
+
return `${OWNER_NOTIFY_STORE_PREFIX}${device.trim().toLowerCase()}__`;
|
|
63
|
+
}
|
|
53
64
|
export function isReservedStoreName(name) {
|
|
54
65
|
const n = name.trim().toLowerCase();
|
|
55
66
|
if (n === AUTH_STORE_ALIAS)
|
|
56
67
|
return true;
|
|
68
|
+
if (OWNER_NOTIFY_STORE_PATTERN.test(n))
|
|
69
|
+
return true;
|
|
57
70
|
return AGENT_IDS.some((id) => RESERVED_STORES[id].toLowerCase() === n);
|
|
58
71
|
}
|
|
59
72
|
// Only durable setup tokens/API keys are portable; rotating OAuth and session credentials stay device-local.
|
|
@@ -1,24 +1,4 @@
|
|
|
1
|
-
import type { Meta } from './types.js';
|
|
2
1
|
import type { JobConfig, RunMeta } from './scheduling/routines.js';
|
|
3
|
-
|
|
4
|
-
export declare function
|
|
5
|
-
|
|
6
|
-
channel: string;
|
|
7
|
-
to: string;
|
|
8
|
-
}
|
|
9
|
-
export declare function ownerFailureDeliveryPlan(meta: Meta): OwnerDest[];
|
|
10
|
-
interface OwnerDeliveryAttempt {
|
|
11
|
-
channel: string;
|
|
12
|
-
ok: boolean;
|
|
13
|
-
error?: string;
|
|
14
|
-
}
|
|
15
|
-
interface OwnerDeliveryResult {
|
|
16
|
-
delivered: boolean;
|
|
17
|
-
channel?: string;
|
|
18
|
-
attempts: OwnerDeliveryAttempt[];
|
|
19
|
-
}
|
|
20
|
-
export declare function deliverOwnerFailure(text: string, meta: Meta): Promise<OwnerDeliveryResult>;
|
|
21
|
-
export declare function __resetOwnerFailureDedup(): void;
|
|
22
|
-
export declare function notifyOwnerRoutineFinish(meta: RunMeta): Promise<OwnerDeliveryResult>;
|
|
23
|
-
export declare function notifyOwnerRoutineStartFailed(config: JobConfig, error: string): Promise<OwnerDeliveryResult>;
|
|
24
|
-
export {};
|
|
2
|
+
import { type OwnerNotifyResult } from './owner-notify.js';
|
|
3
|
+
export declare function notifyOwnerRoutineFinish(meta: RunMeta): Promise<OwnerNotifyResult | null>;
|
|
4
|
+
export declare function notifyOwnerRoutineStartFailed(config: JobConfig, error: string, scheduledFor?: Date): Promise<OwnerNotifyResult>;
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import * as os from 'os';
|
|
2
2
|
import { routineKind } from './routine-notify.js';
|
|
3
|
-
import {
|
|
4
|
-
import { getOwnerFromHumans } from './humans.js';
|
|
5
|
-
import { readOwnerDest } from './channels/send.js';
|
|
6
|
-
import { registerBuiltinProviders } from './channels/providers/index.js';
|
|
7
|
-
import { lookupTransport } from './channels/resolve.js';
|
|
8
|
-
const TELEGRAM_TRANSPORTS = new Set(['telegram', 'openclaw-telegram']);
|
|
3
|
+
import { postOwnerNotification } from './owner-notify.js';
|
|
9
4
|
function routineLabel(r) {
|
|
10
5
|
const kind = routineKind(r);
|
|
11
6
|
if (kind === 'command')
|
|
@@ -21,110 +16,34 @@ function failureReason(meta) {
|
|
|
21
16
|
return meta.errorMessage;
|
|
22
17
|
return `Exited with code ${meta.exitCode ?? '?'}`;
|
|
23
18
|
}
|
|
24
|
-
|
|
19
|
+
function routineFinishOwnerText(meta, host) {
|
|
25
20
|
if (meta.status !== 'failed' && meta.status !== 'timeout')
|
|
26
21
|
return null;
|
|
27
|
-
return
|
|
22
|
+
return `${failureReason(meta)}\n${routineLabel(meta)} · ${host}`;
|
|
28
23
|
}
|
|
29
|
-
|
|
30
|
-
return
|
|
24
|
+
function routineStartFailedOwnerText(config, error, host) {
|
|
25
|
+
return `${error}\n${routineLabel(config)} · ${host}`;
|
|
31
26
|
}
|
|
32
|
-
function isTelegramChannel(channelId, meta, humansTransport) {
|
|
33
|
-
if (channelId.trim().toLowerCase() === 'telegram')
|
|
34
|
-
return true;
|
|
35
|
-
if (humansTransport && TELEGRAM_TRANSPORTS.has(humansTransport.trim().toLowerCase())) {
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
const transport = meta.notify?.transports?.[channelId] ?? channelId;
|
|
39
|
-
return TELEGRAM_TRANSPORTS.has(transport.trim().toLowerCase());
|
|
40
|
-
}
|
|
41
|
-
export function ownerFailureDeliveryPlan(meta) {
|
|
42
|
-
const plan = [];
|
|
43
|
-
const seen = new Set();
|
|
44
|
-
const ownerChannels = getOwnerFromHumans()?.channels ?? [];
|
|
45
|
-
const byId = new Map(ownerChannels.map((ch) => [ch.id, ch]));
|
|
46
|
-
const push = (channel, to) => {
|
|
47
|
-
const c = channel?.trim();
|
|
48
|
-
const t = to?.trim();
|
|
49
|
-
if (!c || !t)
|
|
50
|
-
return;
|
|
51
|
-
const entry = byId.get(c);
|
|
52
|
-
if (entry?.intrusive)
|
|
53
|
-
return;
|
|
54
|
-
if (isTelegramChannel(c, meta, entry?.transport))
|
|
55
|
-
return;
|
|
56
|
-
const key = `${c} ${t}`;
|
|
57
|
-
if (seen.has(key))
|
|
58
|
-
return;
|
|
59
|
-
seen.add(key);
|
|
60
|
-
plan.push({ channel: c, to: t });
|
|
61
|
-
};
|
|
62
|
-
const primary = readOwnerDest(meta);
|
|
63
|
-
if (primary)
|
|
64
|
-
push(primary.channel, primary.to);
|
|
65
|
-
for (const ch of ownerChannels) {
|
|
66
|
-
push(ch.id, ch.to);
|
|
67
|
-
}
|
|
68
|
-
return plan;
|
|
69
|
-
}
|
|
70
|
-
export async function deliverOwnerFailure(text, meta) {
|
|
71
|
-
const plan = ownerFailureDeliveryPlan(meta);
|
|
72
|
-
const attempts = [];
|
|
73
|
-
if (plan.length === 0)
|
|
74
|
-
return { delivered: false, attempts };
|
|
75
|
-
registerBuiltinProviders();
|
|
76
|
-
for (const dest of plan) {
|
|
77
|
-
const { provider, error } = lookupTransport(dest.channel, meta);
|
|
78
|
-
if (!provider) {
|
|
79
|
-
attempts.push({ channel: dest.channel, ok: false, error });
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
try {
|
|
83
|
-
const result = await provider.send(text, {
|
|
84
|
-
target: dest.to,
|
|
85
|
-
from: 'routines',
|
|
86
|
-
ownerScoped: true,
|
|
87
|
-
});
|
|
88
|
-
attempts.push({ channel: dest.channel, ok: result.ok, error: result.error });
|
|
89
|
-
if (result.ok)
|
|
90
|
-
return { delivered: true, channel: dest.channel, attempts };
|
|
91
|
-
}
|
|
92
|
-
catch (err) {
|
|
93
|
-
attempts.push({ channel: dest.channel, ok: false, error: err.message });
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return { delivered: false, attempts };
|
|
97
|
-
}
|
|
98
|
-
const notifiedFailures = new Set();
|
|
99
|
-
const MAX_DEDUP_KEYS = 1000;
|
|
100
|
-
function claimFailureKey(key) {
|
|
101
|
-
if (notifiedFailures.has(key))
|
|
102
|
-
return false;
|
|
103
|
-
if (notifiedFailures.size >= MAX_DEDUP_KEYS)
|
|
104
|
-
notifiedFailures.clear();
|
|
105
|
-
notifiedFailures.add(key);
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
108
|
-
function releaseFailureKey(key) {
|
|
109
|
-
notifiedFailures.delete(key);
|
|
110
|
-
}
|
|
111
|
-
export function __resetOwnerFailureDedup() {
|
|
112
|
-
notifiedFailures.clear();
|
|
113
|
-
}
|
|
114
|
-
const NO_DELIVERY = { delivered: false, attempts: [] };
|
|
115
27
|
export async function notifyOwnerRoutineFinish(meta) {
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
28
|
+
const host = os.hostname();
|
|
29
|
+
const body = routineFinishOwnerText(meta, host);
|
|
30
|
+
if (!body)
|
|
31
|
+
return null;
|
|
32
|
+
return postOwnerNotification({
|
|
33
|
+
event: 'failed',
|
|
34
|
+
title: `Routine failed: ${meta.jobName}`,
|
|
35
|
+
body,
|
|
36
|
+
dedupKey: `routine:${meta.jobName}:${meta.runId}`,
|
|
37
|
+
source: { device: host, agent: 'routines' },
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
export async function notifyOwnerRoutineStartFailed(config, error, scheduledFor = new Date()) {
|
|
41
|
+
const host = os.hostname();
|
|
42
|
+
return postOwnerNotification({
|
|
43
|
+
event: 'failed',
|
|
44
|
+
title: `Routine failed to start: ${config.name}`,
|
|
45
|
+
body: routineStartFailedOwnerText(config, error, host),
|
|
46
|
+
dedupKey: `routine-start:${config.name}:${scheduledFor.toISOString()}`,
|
|
47
|
+
source: { device: host, agent: 'routines' },
|
|
48
|
+
});
|
|
130
49
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const RUSH_API_BASE: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const RUSH_API_BASE = process.env.RUSH_PROXY_BASE ?? 'https://api.prix.dev';
|
|
@@ -41,6 +41,20 @@ export interface SessionImportantMessage {
|
|
|
41
41
|
text: string;
|
|
42
42
|
kind: ImportantMessageKind;
|
|
43
43
|
}
|
|
44
|
+
export interface PrCheckItem {
|
|
45
|
+
name: string;
|
|
46
|
+
state: 'passed' | 'failed' | 'running' | 'skipped';
|
|
47
|
+
url?: string;
|
|
48
|
+
}
|
|
49
|
+
export type SessionPr = DetectedPr & {
|
|
50
|
+
headSha?: string;
|
|
51
|
+
title?: string;
|
|
52
|
+
checkItems?: PrCheckItem[];
|
|
53
|
+
};
|
|
54
|
+
export type WatchSubagent = import('@phnx-labs/sessions-cli/reader').SessionSubagent & {
|
|
55
|
+
model?: string;
|
|
56
|
+
prompt?: string;
|
|
57
|
+
};
|
|
44
58
|
export interface ActiveSession {
|
|
45
59
|
context: ActiveContext;
|
|
46
60
|
kind: string;
|
|
@@ -68,14 +82,14 @@ export interface ActiveSession {
|
|
|
68
82
|
failures?: import('@phnx-labs/sessions-cli/reader').SessionFailure[];
|
|
69
83
|
activityHistogram?: import('@phnx-labs/sessions-cli/reader').SessionActivityHistogram;
|
|
70
84
|
userTurns?: import('@phnx-labs/sessions-cli/reader').SessionUserTurn[];
|
|
71
|
-
subagents?:
|
|
85
|
+
subagents?: WatchSubagent[];
|
|
72
86
|
tokPerSec?: number;
|
|
73
87
|
awaitingReason?: AwaitingReason;
|
|
74
88
|
question?: StructuredQuestion;
|
|
75
89
|
plan?: string;
|
|
76
90
|
todos?: TodoProgress;
|
|
77
91
|
tail?: string[];
|
|
78
|
-
pr?:
|
|
92
|
+
pr?: SessionPr;
|
|
79
93
|
worktree?: DetectedWorktree;
|
|
80
94
|
ticket?: DetectedTicket;
|
|
81
95
|
rateLimited?: boolean;
|
|
@@ -128,6 +142,7 @@ export interface ActiveSession {
|
|
|
128
142
|
tab?: number;
|
|
129
143
|
};
|
|
130
144
|
terminalId?: string;
|
|
145
|
+
originTerminal?: import('../launch-identity.js').LaunchOrigin;
|
|
131
146
|
tabIndex?: number;
|
|
132
147
|
launchId?: string;
|
|
133
148
|
paneId?: string;
|
|
@@ -165,6 +180,7 @@ export declare function sessionFileTimes(sessionFile: string | undefined): {
|
|
|
165
180
|
export declare function lifecycleStatus(pidAlive: boolean, mtimeMs: number | undefined, nowMs?: number): ActiveStatus | undefined;
|
|
166
181
|
export declare function resolveFallbackStatus(sessionFile: string | undefined, pidAlive: boolean, nowMs?: number): ActiveStatus;
|
|
167
182
|
export declare function findSessionFileForKind(kind: string, cwd?: string, sessionId?: string): string | undefined;
|
|
183
|
+
export declare function sessionIdFromFile(kind: string, file?: string): string | undefined;
|
|
168
184
|
interface LiveSignals {
|
|
169
185
|
state?: SessionState;
|
|
170
186
|
tokPerSec?: number;
|