@phnx-labs/agents-cli 1.22.121 → 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 +316 -0
- package/README.md +53 -53
- package/dist/bootstrap.js +22 -17
- package/dist/cli/command-registry.d.ts +0 -1
- package/dist/cli/command-registry.js +2 -12
- 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 +13 -8
- 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/mailboxes.js +1 -1
- package/dist/commands/models.js +1 -1
- package/dist/commands/projects.js +3 -3
- 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-mine.js +0 -1
- package/dist/commands/setup.js +1 -1
- package/dist/commands/sync.js +101 -1
- package/dist/commands/teams.js +2 -2
- 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 -23
- 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 -10
- package/dist/lib/daemon-webhooks.d.ts +1 -1
- package/dist/lib/daemon-webhooks.js +1 -1
- package/dist/lib/device-config.d.ts +4 -1
- package/dist/lib/device-config.js +58 -8
- 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 +20 -7
- 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 -9
- 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/plugins/plugins.d.ts +7 -1
- package/dist/lib/plugins/plugins.js +26 -5
- package/dist/lib/pr-land-detach.js +2 -2
- 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/refresh.js +4 -1
- 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/scheduling/routines.d.ts +1 -1
- package/dist/lib/scheduling/routines.js +1 -1
- 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 +3 -1
- package/dist/lib/session/db.js +64 -32
- 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/staleness/index.js +12 -0
- package/dist/lib/staleness/types.d.ts +5 -0
- package/dist/lib/standalone-tools.js +1 -1
- package/dist/lib/startup/command-registry.js +10 -5
- package/dist/lib/state.d.ts +2 -5
- package/dist/lib/state.js +3 -11
- package/dist/lib/sync-delete.d.ts +21 -0
- package/dist/lib/sync-delete.js +113 -0
- 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 -3
- 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/monitors.d.ts +0 -2
- package/dist/commands/monitors.js +0 -1070
- 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/daemon/monitor-engine-service.d.ts +0 -13
- package/dist/lib/daemon/monitor-engine-service.js +0 -25
- package/dist/lib/humans.d.ts +0 -12
- package/dist/lib/humans.js +0 -64
- package/dist/lib/monitors/config.d.ts +0 -77
- package/dist/lib/monitors/config.js +0 -405
- package/dist/lib/monitors/dispatch.d.ts +0 -10
- package/dist/lib/monitors/dispatch.js +0 -72
- package/dist/lib/monitors/engine.d.ts +0 -45
- package/dist/lib/monitors/engine.js +0 -243
- package/dist/lib/monitors/fingerprint.d.ts +0 -3
- package/dist/lib/monitors/fingerprint.js +0 -43
- package/dist/lib/monitors/pid-watch.d.ts +0 -4
- package/dist/lib/monitors/pid-watch.js +0 -14
- package/dist/lib/monitors/remote.d.ts +0 -31
- package/dist/lib/monitors/remote.js +0 -63
- package/dist/lib/monitors/sources/command.d.ts +0 -4
- package/dist/lib/monitors/sources/command.js +0 -20
- package/dist/lib/monitors/sources/device.d.ts +0 -3
- package/dist/lib/monitors/sources/device.js +0 -31
- package/dist/lib/monitors/sources/failure.d.ts +0 -5
- package/dist/lib/monitors/sources/failure.js +0 -25
- package/dist/lib/monitors/sources/file.d.ts +0 -4
- package/dist/lib/monitors/sources/file.js +0 -46
- package/dist/lib/monitors/sources/http.d.ts +0 -3
- package/dist/lib/monitors/sources/http.js +0 -25
- package/dist/lib/monitors/sources/index.d.ts +0 -5
- package/dist/lib/monitors/sources/index.js +0 -22
- package/dist/lib/monitors/sources/poll.d.ts +0 -1
- package/dist/lib/monitors/sources/poll.js +0 -1
- package/dist/lib/monitors/sources/types.d.ts +0 -9
- package/dist/lib/monitors/sources/webhook.d.ts +0 -3
- package/dist/lib/monitors/sources/webhook.js +0 -3
- package/dist/lib/monitors/sources/ws.d.ts +0 -4
- package/dist/lib/monitors/sources/ws.js +0 -35
- package/dist/lib/monitors/state.d.ts +0 -51
- package/dist/lib/monitors/state.js +0 -221
- /package/dist/{lib/monitors/sources/types.js → commands/testdata/feed-hub.d.ts} +0 -0
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { getCliLaunch } from '../cli-entry.js';
|
|
2
|
+
import { ArtifactsClientError, invocation, resolveArtifactsBin } from '../artifacts-client.js';
|
|
3
|
+
import { machineId } from '../machine-id.js';
|
|
4
|
+
import { RecordingIdentityError, verifyOrganizationIdentity } from './identity.js';
|
|
5
|
+
import { RecordingLedger } from './ledger.js';
|
|
6
|
+
import { isNewerRecording } from './model.js';
|
|
7
|
+
import { processFailure, runProcess } from './process.js';
|
|
8
|
+
import { RecordingDependencyError, transcodeRecording } from './transcode.js';
|
|
9
|
+
function rowCandidate(row) {
|
|
10
|
+
return {
|
|
11
|
+
path: row.path,
|
|
12
|
+
stem: row.stem,
|
|
13
|
+
slug: row.slug,
|
|
14
|
+
size: row.size,
|
|
15
|
+
mtimeMs: row.mtimeMs,
|
|
16
|
+
recordedAt: row.recordedAt,
|
|
17
|
+
sessionId: row.sessionId,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function resultUrl(stdout) {
|
|
21
|
+
try {
|
|
22
|
+
const parsed = JSON.parse(stdout);
|
|
23
|
+
if (typeof parsed.url === 'string' && parsed.url.length > 0)
|
|
24
|
+
return parsed.url;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
const line = stdout.trim().split(/\r?\n/).find((value) => /^https?:\/\//.test(value));
|
|
28
|
+
if (line)
|
|
29
|
+
return line;
|
|
30
|
+
}
|
|
31
|
+
throw new Error('artifacts share completed without returning a URL.');
|
|
32
|
+
}
|
|
33
|
+
function isUnauthorizedOutput(exitCode, output) {
|
|
34
|
+
return exitCode === 401 || /\b401\b|unauthori[sz]ed|authentication expired|not signed in/i.test(output);
|
|
35
|
+
}
|
|
36
|
+
async function defaultAttention(message) {
|
|
37
|
+
const session = `recordings-${machineId()}`;
|
|
38
|
+
const launch = getCliLaunch([
|
|
39
|
+
'feed', 'post', '--title', 'Recordings need attention', message, '--blocked', '--session', session,
|
|
40
|
+
]);
|
|
41
|
+
const result = await runProcess(launch.command, launch.args, { timeoutMs: 30_000 });
|
|
42
|
+
if (result.exitCode !== 0)
|
|
43
|
+
throw processFailure(launch.command, launch.args, result);
|
|
44
|
+
}
|
|
45
|
+
export function buildArtifactsRecordingArgs(candidate, transcodedPath) {
|
|
46
|
+
const args = [
|
|
47
|
+
'share', transcodedPath,
|
|
48
|
+
'--visibility', 'org',
|
|
49
|
+
'--expire', 'never',
|
|
50
|
+
'--slug', candidate.slug,
|
|
51
|
+
'--meta', 'source=cleanshot',
|
|
52
|
+
'--meta', `recorded-at=${candidate.recordedAt}`,
|
|
53
|
+
'--meta', `stem=${candidate.stem}`,
|
|
54
|
+
];
|
|
55
|
+
args.push('--json');
|
|
56
|
+
return args;
|
|
57
|
+
}
|
|
58
|
+
export function buildArtifactsRecordingEnv(candidate, base) {
|
|
59
|
+
const env = { ...base };
|
|
60
|
+
delete env.AGENTS_SESSION_ID;
|
|
61
|
+
delete env.AGENT_SESSION_ID;
|
|
62
|
+
if (candidate.sessionId)
|
|
63
|
+
env.AGENTS_SESSION_ID = candidate.sessionId;
|
|
64
|
+
return env;
|
|
65
|
+
}
|
|
66
|
+
export class RecordingPipeline {
|
|
67
|
+
ledger;
|
|
68
|
+
active = new Map();
|
|
69
|
+
configuredArtifactsBin;
|
|
70
|
+
env;
|
|
71
|
+
transcode;
|
|
72
|
+
verifyIdentity;
|
|
73
|
+
raiseAttention;
|
|
74
|
+
reportError;
|
|
75
|
+
retryDelayMs;
|
|
76
|
+
dependencyRetryDelayMs;
|
|
77
|
+
constructor(options = {}) {
|
|
78
|
+
this.ledger = options.ledger ?? new RecordingLedger();
|
|
79
|
+
this.configuredArtifactsBin = options.artifactsBin;
|
|
80
|
+
this.env = options.env ?? process.env;
|
|
81
|
+
this.transcode = options.transcode ?? ((source, signal) => transcodeRecording(source, signal));
|
|
82
|
+
this.verifyIdentity = options.verifyIdentity
|
|
83
|
+
?? ((signal) => verifyOrganizationIdentity(signal, { artifactsBin: this.artifactsBin(), env: this.env }));
|
|
84
|
+
this.raiseAttention = options.raiseAttention ?? defaultAttention;
|
|
85
|
+
this.reportError = options.reportError ?? (() => undefined);
|
|
86
|
+
this.retryDelayMs = options.retryDelayMs ?? 60_000;
|
|
87
|
+
this.dependencyRetryDelayMs = options.dependencyRetryDelayMs ?? 15 * 60_000;
|
|
88
|
+
}
|
|
89
|
+
artifactsBin() {
|
|
90
|
+
return this.configuredArtifactsBin ?? resolveArtifactsBin();
|
|
91
|
+
}
|
|
92
|
+
observeLatest(candidate) {
|
|
93
|
+
const active = this.active.get(candidate.stem);
|
|
94
|
+
if (!active || active.candidate.path === candidate.path)
|
|
95
|
+
return;
|
|
96
|
+
if (!isNewerRecording(candidate, active.candidate))
|
|
97
|
+
return;
|
|
98
|
+
active.superseded = true;
|
|
99
|
+
active.controller.abort();
|
|
100
|
+
void this.ledger.update(active.candidate.stem, active.candidate.path, {
|
|
101
|
+
status: 'failed',
|
|
102
|
+
error: `Superseded by ${candidate.path}`,
|
|
103
|
+
retryAt: '9999-12-31T23:59:59.999Z',
|
|
104
|
+
}).catch((error) => {
|
|
105
|
+
this.reportError(error instanceof Error ? error.message : String(error));
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
async queue(candidates) {
|
|
109
|
+
for (const candidate of candidates)
|
|
110
|
+
await this.ledger.queue(candidate);
|
|
111
|
+
}
|
|
112
|
+
async recoverInterrupted() {
|
|
113
|
+
await this.ledger.recoverInterrupted();
|
|
114
|
+
}
|
|
115
|
+
async attention(message) {
|
|
116
|
+
if (!await this.ledger.shouldPostAttention(message))
|
|
117
|
+
return;
|
|
118
|
+
try {
|
|
119
|
+
await this.raiseAttention(message);
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
await this.ledger.clearAttention();
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async share(candidate, filePath, signal) {
|
|
127
|
+
const launch = invocation(this.artifactsBin());
|
|
128
|
+
const args = [...launch.prefix, ...buildArtifactsRecordingArgs(candidate, filePath)];
|
|
129
|
+
const env = buildArtifactsRecordingEnv(candidate, this.env);
|
|
130
|
+
const result = await runProcess(launch.command, args, { signal, env });
|
|
131
|
+
if (result.exitCode !== 0) {
|
|
132
|
+
const output = `${result.stderr}\n${result.stdout}`;
|
|
133
|
+
if (isUnauthorizedOutput(result.exitCode, output)) {
|
|
134
|
+
throw new RecordingIdentityError('AUTH_REQUIRED', 'Artifacts authentication expired during upload. Run `artifacts auth login`; recordings remain queued.');
|
|
135
|
+
}
|
|
136
|
+
if (/bad --meta|--meta .+ is reserved|unknown option|invalid choice/i.test(output)) {
|
|
137
|
+
throw new RecordingDependencyError(`The installed artifacts CLI cannot accept the recordings publish contract. ${output.trim()}`);
|
|
138
|
+
}
|
|
139
|
+
throw processFailure('artifacts', args, result);
|
|
140
|
+
}
|
|
141
|
+
return resultUrl(result.stdout);
|
|
142
|
+
}
|
|
143
|
+
start(candidate) {
|
|
144
|
+
const controller = new AbortController();
|
|
145
|
+
const active = {
|
|
146
|
+
candidate,
|
|
147
|
+
controller,
|
|
148
|
+
superseded: false,
|
|
149
|
+
promise: Promise.resolve(null),
|
|
150
|
+
};
|
|
151
|
+
const promise = (async () => {
|
|
152
|
+
let transcoded;
|
|
153
|
+
try {
|
|
154
|
+
if (!await this.ledger.claim(candidate.stem, candidate.path))
|
|
155
|
+
return null;
|
|
156
|
+
transcoded = await this.transcode(candidate.path, controller.signal);
|
|
157
|
+
await this.ledger.update(candidate.stem, candidate.path, { status: 'uploading' });
|
|
158
|
+
const url = await this.share(candidate, transcoded.filePath, controller.signal);
|
|
159
|
+
const row = await this.ledger.update(candidate.stem, candidate.path, {
|
|
160
|
+
status: 'uploaded',
|
|
161
|
+
url,
|
|
162
|
+
error: null,
|
|
163
|
+
retryAt: undefined,
|
|
164
|
+
});
|
|
165
|
+
await this.ledger.clearAttention();
|
|
166
|
+
return row;
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
if (active.superseded)
|
|
170
|
+
return null;
|
|
171
|
+
if (error instanceof RecordingIdentityError && error.code === 'AUTH_REQUIRED') {
|
|
172
|
+
await this.ledger.update(candidate.stem, candidate.path, {
|
|
173
|
+
status: 'queued',
|
|
174
|
+
error: error.message,
|
|
175
|
+
retryAt: new Date(Date.now() + this.retryDelayMs).toISOString(),
|
|
176
|
+
});
|
|
177
|
+
await this.attention(error.message);
|
|
178
|
+
throw error;
|
|
179
|
+
}
|
|
180
|
+
if (error instanceof RecordingDependencyError) {
|
|
181
|
+
await this.ledger.update(candidate.stem, candidate.path, {
|
|
182
|
+
status: 'failed',
|
|
183
|
+
error: error.message,
|
|
184
|
+
retryAt: new Date(Date.now() + this.dependencyRetryDelayMs).toISOString(),
|
|
185
|
+
});
|
|
186
|
+
await this.attention(error.message);
|
|
187
|
+
throw error;
|
|
188
|
+
}
|
|
189
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
190
|
+
await this.ledger.update(candidate.stem, candidate.path, {
|
|
191
|
+
status: 'failed',
|
|
192
|
+
error: message,
|
|
193
|
+
retryAt: new Date(Date.now() + this.retryDelayMs).toISOString(),
|
|
194
|
+
});
|
|
195
|
+
throw error;
|
|
196
|
+
}
|
|
197
|
+
finally {
|
|
198
|
+
await transcoded?.cleanup();
|
|
199
|
+
}
|
|
200
|
+
})();
|
|
201
|
+
active.promise = promise;
|
|
202
|
+
this.active.set(candidate.stem, active);
|
|
203
|
+
void promise.finally(() => {
|
|
204
|
+
if (this.active.get(candidate.stem) === active)
|
|
205
|
+
this.active.delete(candidate.stem);
|
|
206
|
+
}).catch((error) => {
|
|
207
|
+
if (!active.superseded)
|
|
208
|
+
this.reportError(error instanceof Error ? error.message : String(error));
|
|
209
|
+
});
|
|
210
|
+
return promise;
|
|
211
|
+
}
|
|
212
|
+
async drain(options = {}) {
|
|
213
|
+
const pending = await this.ledger.pending();
|
|
214
|
+
const candidates = pending.map(rowCandidate).filter((candidate) => !this.active.has(candidate.stem));
|
|
215
|
+
if (candidates.length === 0)
|
|
216
|
+
return [];
|
|
217
|
+
try {
|
|
218
|
+
await this.verifyIdentity(options.signal);
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
222
|
+
const delay = error instanceof ArtifactsClientError ? this.dependencyRetryDelayMs : this.retryDelayMs;
|
|
223
|
+
const retryAt = new Date(Date.now() + delay).toISOString();
|
|
224
|
+
for (const candidate of candidates) {
|
|
225
|
+
await this.ledger.update(candidate.stem, candidate.path, { status: 'queued', error: message, retryAt });
|
|
226
|
+
}
|
|
227
|
+
await this.attention(message);
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
230
|
+
const uploads = candidates.map((candidate) => this.start(candidate));
|
|
231
|
+
if (options.awaitUploads === false)
|
|
232
|
+
return [];
|
|
233
|
+
const rows = await Promise.all(uploads);
|
|
234
|
+
return rows.filter((row) => row !== null);
|
|
235
|
+
}
|
|
236
|
+
async upload(candidate, signal) {
|
|
237
|
+
this.observeLatest(candidate);
|
|
238
|
+
const queued = await this.ledger.queue(candidate);
|
|
239
|
+
if (queued.status === 'uploaded')
|
|
240
|
+
return queued;
|
|
241
|
+
if (queued.status === 'transcoding' || queued.status === 'uploading') {
|
|
242
|
+
throw new Error(`Recording upload is already in progress: ${candidate.path}`);
|
|
243
|
+
}
|
|
244
|
+
if (queued.status === 'failed' || queued.retryAt) {
|
|
245
|
+
await this.ledger.update(candidate.stem, candidate.path, { status: 'queued', retryAt: undefined });
|
|
246
|
+
}
|
|
247
|
+
try {
|
|
248
|
+
await this.verifyIdentity(signal);
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
252
|
+
const delay = error instanceof ArtifactsClientError ? this.dependencyRetryDelayMs : this.retryDelayMs;
|
|
253
|
+
await this.ledger.update(candidate.stem, candidate.path, {
|
|
254
|
+
status: 'queued',
|
|
255
|
+
error: message,
|
|
256
|
+
retryAt: new Date(Date.now() + delay).toISOString(),
|
|
257
|
+
});
|
|
258
|
+
await this.attention(message);
|
|
259
|
+
throw error;
|
|
260
|
+
}
|
|
261
|
+
const row = await this.start(candidate);
|
|
262
|
+
if (!row || row.status !== 'uploaded')
|
|
263
|
+
throw new Error(`Recording did not upload: ${candidate.path}`);
|
|
264
|
+
return row;
|
|
265
|
+
}
|
|
266
|
+
async stop() {
|
|
267
|
+
const active = [...this.active.values()];
|
|
268
|
+
for (const upload of active)
|
|
269
|
+
upload.controller.abort();
|
|
270
|
+
await Promise.allSettled(active.map((upload) => upload.promise));
|
|
271
|
+
}
|
|
272
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface ProcessResult {
|
|
2
|
+
exitCode: number;
|
|
3
|
+
stdout: string;
|
|
4
|
+
stderr: string;
|
|
5
|
+
}
|
|
6
|
+
export interface RunProcessOptions {
|
|
7
|
+
cwd?: string;
|
|
8
|
+
env?: NodeJS.ProcessEnv;
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
timeoutMs?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare class RecordingProcessError extends Error {
|
|
13
|
+
readonly result?: ProcessResult | undefined;
|
|
14
|
+
constructor(message: string, result?: ProcessResult | undefined);
|
|
15
|
+
}
|
|
16
|
+
export declare function runProcess(command: string, args: string[], options?: RunProcessOptions): Promise<ProcessResult>;
|
|
17
|
+
export declare function processFailure(command: string, args: string[], result: ProcessResult): RecordingProcessError;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
export class RecordingProcessError extends Error {
|
|
3
|
+
result;
|
|
4
|
+
constructor(message, result) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.result = result;
|
|
7
|
+
this.name = 'RecordingProcessError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const MAX_OUTPUT_BYTES = 1024 * 1024;
|
|
11
|
+
function appendBounded(current, chunk) {
|
|
12
|
+
const next = current + chunk.toString('utf8');
|
|
13
|
+
return next.length > MAX_OUTPUT_BYTES ? next.slice(-MAX_OUTPUT_BYTES) : next;
|
|
14
|
+
}
|
|
15
|
+
export async function runProcess(command, args, options = {}) {
|
|
16
|
+
if (options.signal?.aborted)
|
|
17
|
+
throw new DOMException('The operation was aborted', 'AbortError');
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
const child = spawn(command, args, {
|
|
20
|
+
cwd: options.cwd,
|
|
21
|
+
env: options.env,
|
|
22
|
+
detached: process.platform !== 'win32',
|
|
23
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
24
|
+
});
|
|
25
|
+
let stdout = '';
|
|
26
|
+
let stderr = '';
|
|
27
|
+
let settled = false;
|
|
28
|
+
let timer;
|
|
29
|
+
let killTimer;
|
|
30
|
+
let terminationError;
|
|
31
|
+
const signalChild = (signal) => {
|
|
32
|
+
if (child.exitCode !== null || child.signalCode !== null)
|
|
33
|
+
return;
|
|
34
|
+
try {
|
|
35
|
+
if (process.platform !== 'win32' && child.pid)
|
|
36
|
+
process.kill(-child.pid, signal);
|
|
37
|
+
else
|
|
38
|
+
child.kill(signal);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
try {
|
|
42
|
+
child.kill(signal);
|
|
43
|
+
}
|
|
44
|
+
catch { }
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const stop = (error) => {
|
|
48
|
+
if (terminationError)
|
|
49
|
+
return;
|
|
50
|
+
terminationError = error;
|
|
51
|
+
signalChild('SIGTERM');
|
|
52
|
+
killTimer = setTimeout(() => signalChild('SIGKILL'), 2_000);
|
|
53
|
+
};
|
|
54
|
+
const abort = () => stop(new DOMException('The operation was aborted', 'AbortError'));
|
|
55
|
+
const cleanup = () => {
|
|
56
|
+
if (timer)
|
|
57
|
+
clearTimeout(timer);
|
|
58
|
+
if (killTimer)
|
|
59
|
+
clearTimeout(killTimer);
|
|
60
|
+
options.signal?.removeEventListener('abort', abort);
|
|
61
|
+
};
|
|
62
|
+
const finishReject = (error) => {
|
|
63
|
+
if (settled)
|
|
64
|
+
return;
|
|
65
|
+
settled = true;
|
|
66
|
+
cleanup();
|
|
67
|
+
reject(error);
|
|
68
|
+
};
|
|
69
|
+
options.signal?.addEventListener('abort', abort, { once: true });
|
|
70
|
+
if (options.timeoutMs) {
|
|
71
|
+
timer = setTimeout(() => {
|
|
72
|
+
stop(new RecordingProcessError(`Command timed out after ${options.timeoutMs}ms: ${command}`, { exitCode: -1, stdout, stderr }));
|
|
73
|
+
}, options.timeoutMs);
|
|
74
|
+
}
|
|
75
|
+
child.stdout.on('data', (chunk) => { stdout = appendBounded(stdout, chunk); });
|
|
76
|
+
child.stderr.on('data', (chunk) => { stderr = appendBounded(stderr, chunk); });
|
|
77
|
+
child.on('error', (error) => finishReject(error));
|
|
78
|
+
child.on('close', (code) => {
|
|
79
|
+
if (settled)
|
|
80
|
+
return;
|
|
81
|
+
if (terminationError) {
|
|
82
|
+
finishReject(terminationError);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
settled = true;
|
|
86
|
+
cleanup();
|
|
87
|
+
resolve({ exitCode: code ?? -1, stdout, stderr });
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
export function processFailure(command, args, result) {
|
|
92
|
+
const detail = result.stderr.trim() || result.stdout.trim() || `exit ${result.exitCode}`;
|
|
93
|
+
return new RecordingProcessError(`${command} ${args.join(' ')} failed: ${detail}`, result);
|
|
94
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DaemonContext } from '../daemon/service.js';
|
|
2
|
+
import { BasePeriodicService } from '../daemon/service.js';
|
|
3
|
+
export declare class RecordingsService extends BasePeriodicService {
|
|
4
|
+
readonly id: "recordings";
|
|
5
|
+
readonly intervalMs = 2000;
|
|
6
|
+
readonly deadlineMs = 25000;
|
|
7
|
+
private directory;
|
|
8
|
+
private watchedSinceMs;
|
|
9
|
+
private startedAtMs;
|
|
10
|
+
private pipeline;
|
|
11
|
+
private settler;
|
|
12
|
+
protected onStart(ctx: DaemonContext): Promise<void>;
|
|
13
|
+
protected onTick(ctx: DaemonContext, signal: AbortSignal): Promise<void>;
|
|
14
|
+
protected onStop(): Promise<void>;
|
|
15
|
+
}
|
|
@@ -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/refresh.js
CHANGED
|
@@ -11,7 +11,7 @@ import { installVersion, listInstalledVersions, isVersionIsolated, getGlobalDefa
|
|
|
11
11
|
import { listCliStatus, installCli, describeMethod, describeCheck, selectInstallMethod, } from './cli-resources.js';
|
|
12
12
|
import { ensureShimCurrent, ensureGhOverloadShim, isShimsInPath, addShimsToPath, getPathSetupInstructions, switchConfigSymlink, switchHomeFileSymlinks, } from './installations/shims.js';
|
|
13
13
|
import { parseHookManifest, registerHooksToSettings } from './hooks/install.js';
|
|
14
|
-
import { isPromptCancelled } from './format.js';
|
|
14
|
+
import { isInteractiveTerminal, isPromptCancelled } from './format.js';
|
|
15
15
|
function migratePromptcutsToRoot(agentsDir, quiet = false) {
|
|
16
16
|
const rootPath = path.join(agentsDir, 'promptcuts.yaml');
|
|
17
17
|
if (fs.existsSync(rootPath))
|
|
@@ -137,6 +137,9 @@ export async function refresh(options = {}) {
|
|
|
137
137
|
else if (skipPrompts) {
|
|
138
138
|
forceFullSync = true;
|
|
139
139
|
}
|
|
140
|
+
else if (!isInteractiveTerminal() && (!hasAnySynced || (newResources && hasNewResources(newResources, agentId, defaultVer)))) {
|
|
141
|
+
log(chalk.gray(`Skipped resource selection for ${agentLabel(agentId)}@${defaultVer} (no terminal; rerun with --yes to sync new resources)`));
|
|
142
|
+
}
|
|
140
143
|
else if (!hasAnySynced) {
|
|
141
144
|
log(chalk.yellow(`\n${agentLabel(agentId)}@${defaultVer} has no synced resources.`));
|
|
142
145
|
const userSelection = await promptResourceSelection(agentId);
|
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;
|