@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
|
@@ -40,6 +40,7 @@ export declare function loadUserConfig(pluginName: string): Record<string, strin
|
|
|
40
40
|
export declare function saveUserConfig(pluginName: string, config: Record<string, string>): void;
|
|
41
41
|
export declare function checkPluginDependencies(manifest: PluginManifest): string[];
|
|
42
42
|
export declare function marketplaceSpecForName(name: string | undefined, cwd?: string): MarketplaceSpec;
|
|
43
|
+
export declare function listVersionMarketplaceNames(agent: AgentId, versionHome: string): string[];
|
|
43
44
|
export declare function syncPluginToVersion(plugin: DiscoveredPlugin, agent: AgentId, versionHome: string, options?: {
|
|
44
45
|
allowExecSurfaces?: boolean;
|
|
45
46
|
version?: string;
|
|
@@ -82,7 +83,12 @@ export type ActivePluginsInput = Set<string> | Array<{
|
|
|
82
83
|
name: string;
|
|
83
84
|
marketplace?: string;
|
|
84
85
|
}>;
|
|
85
|
-
export
|
|
86
|
+
export interface OrphanPluginScope {
|
|
87
|
+
marketplace: string;
|
|
88
|
+
cwd: string;
|
|
89
|
+
dryRun?: boolean;
|
|
90
|
+
}
|
|
91
|
+
export declare function cleanOrphanedPluginSkills(agent: AgentId, versionHome: string, activePlugins: ActivePluginsInput, version?: string, scope?: OrphanPluginScope): string[];
|
|
86
92
|
export interface VersionPluginDiff {
|
|
87
93
|
agent: AgentId;
|
|
88
94
|
version: string;
|
|
@@ -377,7 +377,7 @@ export function marketplaceSpecForName(name, cwd = process.cwd()) {
|
|
|
377
377
|
const alias = name.slice('agents-'.length);
|
|
378
378
|
return { kind: 'extra', alias, root: getExtraPluginsDir(alias) };
|
|
379
379
|
}
|
|
380
|
-
function listVersionMarketplaceNames(agent, versionHome) {
|
|
380
|
+
export function listVersionMarketplaceNames(agent, versionHome) {
|
|
381
381
|
const dir = path.join(versionHome, agentConfigDirName(agent), 'plugins', 'marketplaces');
|
|
382
382
|
if (!fs.existsSync(dir))
|
|
383
383
|
return [];
|
|
@@ -1146,11 +1146,14 @@ function isOrphanMarketplacePlugin(marketplaceName, pluginName, active, cwd) {
|
|
|
1146
1146
|
return true;
|
|
1147
1147
|
return !active.names.has(pluginName);
|
|
1148
1148
|
}
|
|
1149
|
-
export function cleanOrphanedPluginSkills(agent, versionHome, activePlugins, version) {
|
|
1149
|
+
export function cleanOrphanedPluginSkills(agent, versionHome, activePlugins, version, scope) {
|
|
1150
1150
|
const active = indexActivePlugins(activePlugins);
|
|
1151
|
-
const cwd = process.cwd();
|
|
1151
|
+
const cwd = scope?.cwd ?? process.cwd();
|
|
1152
1152
|
const removed = [];
|
|
1153
|
+
const removedPlugins = new Set();
|
|
1153
1154
|
for (const name of listVersionMarketplaceNames(agent, versionHome)) {
|
|
1155
|
+
if (scope && (name !== scope.marketplace || !marketplaceSourceRepoExists(name, cwd)))
|
|
1156
|
+
continue;
|
|
1154
1157
|
const spec = marketplaceSpecForName(name);
|
|
1155
1158
|
const mktPluginsDir = path.join(marketplaceRoot(name, agent, versionHome), 'plugins');
|
|
1156
1159
|
if (!fs.existsSync(mktPluginsDir))
|
|
@@ -1161,6 +1164,11 @@ export function cleanOrphanedPluginSkills(agent, versionHome, activePlugins, ver
|
|
|
1161
1164
|
continue;
|
|
1162
1165
|
if (!isOrphanMarketplacePlugin(name, entry.name, active, cwd))
|
|
1163
1166
|
continue;
|
|
1167
|
+
if (scope?.dryRun) {
|
|
1168
|
+
removed.push(entry.name);
|
|
1169
|
+
removedPlugins.add(entry.name);
|
|
1170
|
+
continue;
|
|
1171
|
+
}
|
|
1164
1172
|
try {
|
|
1165
1173
|
const stamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
1166
1174
|
const trashDir = path.join(getTrashPluginsDir(), agent, version || 'unknown', entry.name);
|
|
@@ -1175,9 +1183,13 @@ export function cleanOrphanedPluginSkills(agent, versionHome, activePlugins, ver
|
|
|
1175
1183
|
unregisterCopilotInstalledPlugin(entry.name, name, agent, versionHome);
|
|
1176
1184
|
}
|
|
1177
1185
|
removed.push(entry.name);
|
|
1186
|
+
removedPlugins.add(entry.name);
|
|
1178
1187
|
trashedHere = true;
|
|
1179
1188
|
}
|
|
1180
|
-
catch {
|
|
1189
|
+
catch (err) {
|
|
1190
|
+
if (scope)
|
|
1191
|
+
throw new Error(`could not trash plugin '${entry.name}' from ${agent}@${version ?? 'unknown'}: ${err.message}`);
|
|
1192
|
+
}
|
|
1181
1193
|
}
|
|
1182
1194
|
if (trashedHere) {
|
|
1183
1195
|
syncMarketplaceManifest(spec, agent, versionHome);
|
|
@@ -1198,6 +1210,12 @@ export function cleanOrphanedPluginSkills(agent, versionHome, activePlugins, ver
|
|
|
1198
1210
|
const pluginName = entry.name.slice(0, dashIdx);
|
|
1199
1211
|
if (active.names.has(pluginName))
|
|
1200
1212
|
continue;
|
|
1213
|
+
if (scope && !removedPlugins.has(pluginName))
|
|
1214
|
+
continue;
|
|
1215
|
+
if (scope?.dryRun) {
|
|
1216
|
+
removed.push(entry.name);
|
|
1217
|
+
continue;
|
|
1218
|
+
}
|
|
1201
1219
|
try {
|
|
1202
1220
|
const stamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
1203
1221
|
const trashDir = path.join(getTrashPluginsDir(), agent, version || 'unknown', entry.name);
|
|
@@ -1206,7 +1224,10 @@ export function cleanOrphanedPluginSkills(agent, versionHome, activePlugins, ver
|
|
|
1206
1224
|
fs.renameSync(path.join(skillsDir, entry.name), trashDest);
|
|
1207
1225
|
removed.push(entry.name);
|
|
1208
1226
|
}
|
|
1209
|
-
catch {
|
|
1227
|
+
catch (err) {
|
|
1228
|
+
if (scope)
|
|
1229
|
+
throw new Error(`could not trash plugin skill '${entry.name}' from ${agent}@${version ?? 'unknown'}: ${err.message}`);
|
|
1230
|
+
}
|
|
1210
1231
|
}
|
|
1211
1232
|
}
|
|
1212
1233
|
return removed;
|
|
@@ -14,8 +14,8 @@ export function formatOrphanedOpenPrWarning(pr) {
|
|
|
14
14
|
` PR #${pr.number} is still OPEN and nothing is watching it. A background`,
|
|
15
15
|
' `gh pr checks --watch` child dies when a headless agent exits, so the PR',
|
|
16
16
|
' will sit green and unmerged.',
|
|
17
|
-
' Merge it once CI is green and a non-author review has cleared it, or
|
|
18
|
-
'
|
|
17
|
+
' Merge it once CI is green and a non-author review has cleared it, or turn on',
|
|
18
|
+
' GitHub auto-merge after that review (`agents projects prs automerge`).',
|
|
19
19
|
'',
|
|
20
20
|
];
|
|
21
21
|
return lines.join('\n');
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface RecordingsConfig {
|
|
2
|
+
directory?: string;
|
|
3
|
+
watchedSince?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function recordingsStateDir(): string;
|
|
6
|
+
export declare function recordingsConfigPath(): string;
|
|
7
|
+
export declare function recordingsLedgerPath(): string;
|
|
8
|
+
export declare function readRecordingsConfig(): Promise<RecordingsConfig>;
|
|
9
|
+
export declare function writeRecordingDirectory(directory: string): Promise<void>;
|
|
10
|
+
export declare function defaultCleanShotDirectory(): Promise<string>;
|
|
11
|
+
export declare function resolveRecordingDirectory(override?: string): Promise<string>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { getUserAgentsDir } from '../state.js';
|
|
4
|
+
import { atomicWriteFile } from '../fs-atomic.js';
|
|
5
|
+
import { runProcess } from './process.js';
|
|
6
|
+
export function recordingsStateDir() {
|
|
7
|
+
return path.join(getUserAgentsDir(), 'recordings');
|
|
8
|
+
}
|
|
9
|
+
export function recordingsConfigPath() {
|
|
10
|
+
return path.join(recordingsStateDir(), 'config.json');
|
|
11
|
+
}
|
|
12
|
+
export function recordingsLedgerPath() {
|
|
13
|
+
return path.join(recordingsStateDir(), 'ledger.json');
|
|
14
|
+
}
|
|
15
|
+
export async function readRecordingsConfig() {
|
|
16
|
+
try {
|
|
17
|
+
return JSON.parse(await fs.readFile(recordingsConfigPath(), 'utf8'));
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export async function writeRecordingDirectory(directory) {
|
|
24
|
+
const resolved = path.resolve(directory);
|
|
25
|
+
const stat = await fs.stat(resolved).catch(() => null);
|
|
26
|
+
if (!stat?.isDirectory())
|
|
27
|
+
throw new Error(`Recording directory does not exist: ${resolved}`);
|
|
28
|
+
await fs.mkdir(recordingsStateDir(), { recursive: true, mode: 0o700 });
|
|
29
|
+
const config = { directory: resolved, watchedSince: new Date().toISOString() };
|
|
30
|
+
await atomicWriteFile(recordingsConfigPath(), `${JSON.stringify(config, null, 2)}\n`, {
|
|
31
|
+
encoding: 'utf8',
|
|
32
|
+
mode: 0o600,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
export async function defaultCleanShotDirectory() {
|
|
36
|
+
if (process.platform !== 'darwin') {
|
|
37
|
+
throw new Error('CleanShot export directory auto-detection is available only on macOS. Pass --dir <path>.');
|
|
38
|
+
}
|
|
39
|
+
const result = await runProcess('defaults', ['read', 'pl.maketheweb.cleanshotx', 'exportPath'], { timeoutMs: 5_000 });
|
|
40
|
+
const directory = result.stdout.trim();
|
|
41
|
+
if (result.exitCode !== 0 || !directory) {
|
|
42
|
+
throw new Error('Could not read CleanShot exportPath. Set it in CleanShot or pass --dir <path>.');
|
|
43
|
+
}
|
|
44
|
+
return directory;
|
|
45
|
+
}
|
|
46
|
+
export async function resolveRecordingDirectory(override) {
|
|
47
|
+
const configured = (await readRecordingsConfig()).directory;
|
|
48
|
+
const directory = override || configured || await defaultCleanShotDirectory();
|
|
49
|
+
const resolved = path.resolve(directory);
|
|
50
|
+
const stat = await fs.stat(resolved).catch(() => null);
|
|
51
|
+
if (!stat?.isDirectory())
|
|
52
|
+
throw new Error(`Recording directory does not exist: ${resolved}`);
|
|
53
|
+
return resolved;
|
|
54
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type RecordingIdentityErrorCode = 'AUTH_REQUIRED' | 'PUBLIC_INBOX' | 'AUTH_UNAVAILABLE';
|
|
2
|
+
export declare class RecordingIdentityError extends Error {
|
|
3
|
+
readonly code: RecordingIdentityErrorCode;
|
|
4
|
+
constructor(code: RecordingIdentityErrorCode, message: string);
|
|
5
|
+
}
|
|
6
|
+
export declare function isPublicInboxEmail(email: string): boolean;
|
|
7
|
+
export declare function verifyOrganizationIdentity(signal?: AbortSignal, options?: {
|
|
8
|
+
artifactsBin?: string;
|
|
9
|
+
env?: NodeJS.ProcessEnv;
|
|
10
|
+
}): Promise<{
|
|
11
|
+
email: string;
|
|
12
|
+
}>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { invocation, resolveArtifactsBin } from '../artifacts-client.js';
|
|
2
|
+
import { processFailure, runProcess } from './process.js';
|
|
3
|
+
const PUBLIC_INBOX_DOMAINS = new Set([
|
|
4
|
+
'aol.com', 'fastmail.com', 'gmail.com', 'googlemail.com', 'hey.com', 'hotmail.com',
|
|
5
|
+
'icloud.com', 'live.com', 'mac.com', 'mail.com', 'me.com', 'msn.com', 'outlook.com',
|
|
6
|
+
'pm.me', 'proton.me', 'protonmail.com', 'rocketmail.com', 'yahoo.com', 'ymail.com',
|
|
7
|
+
'zoho.com', 'gmx.com', 'gmx.net',
|
|
8
|
+
]);
|
|
9
|
+
export class RecordingIdentityError extends Error {
|
|
10
|
+
code;
|
|
11
|
+
constructor(code, message) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.code = code;
|
|
14
|
+
this.name = 'RecordingIdentityError';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function isPublicInboxEmail(email) {
|
|
18
|
+
const domain = email.trim().toLowerCase().split('@').at(-1) ?? '';
|
|
19
|
+
return PUBLIC_INBOX_DOMAINS.has(domain);
|
|
20
|
+
}
|
|
21
|
+
function readIdentity(value) {
|
|
22
|
+
if (!value || typeof value !== 'object')
|
|
23
|
+
return { signedIn: false };
|
|
24
|
+
const record = value;
|
|
25
|
+
const me = record.me && typeof record.me === 'object' ? record.me : record;
|
|
26
|
+
return {
|
|
27
|
+
signedIn: record.signedIn === true || typeof me.email === 'string',
|
|
28
|
+
email: typeof me.email === 'string' ? me.email : undefined,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export async function verifyOrganizationIdentity(signal, options = {}) {
|
|
32
|
+
const bin = options.artifactsBin ?? resolveArtifactsBin();
|
|
33
|
+
const launch = invocation(bin);
|
|
34
|
+
const args = [...launch.prefix, 'auth', 'whoami', '--json'];
|
|
35
|
+
const result = await runProcess(launch.command, args, { signal, env: options.env, timeoutMs: 15_000 });
|
|
36
|
+
if (result.exitCode !== 0) {
|
|
37
|
+
const detail = `${result.stderr}\n${result.stdout}`;
|
|
38
|
+
if (result.exitCode === 401 || /\b401\b|sign(?:ed)?[ -]?out|not signed in|unauthori[sz]ed/i.test(detail)) {
|
|
39
|
+
throw new RecordingIdentityError('AUTH_REQUIRED', 'Artifacts authentication expired. Run `artifacts auth login`; recordings remain queued.');
|
|
40
|
+
}
|
|
41
|
+
throw new RecordingIdentityError('AUTH_UNAVAILABLE', processFailure('artifacts', args, result).message);
|
|
42
|
+
}
|
|
43
|
+
let identity;
|
|
44
|
+
try {
|
|
45
|
+
identity = readIdentity(JSON.parse(result.stdout));
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
throw new RecordingIdentityError('AUTH_UNAVAILABLE', 'artifacts auth whoami returned invalid JSON.');
|
|
49
|
+
}
|
|
50
|
+
if (!identity.signedIn || !identity.email) {
|
|
51
|
+
throw new RecordingIdentityError('AUTH_REQUIRED', 'Artifacts is not signed in. Run `artifacts auth login`; recordings remain queued.');
|
|
52
|
+
}
|
|
53
|
+
if (isPublicInboxEmail(identity.email)) {
|
|
54
|
+
throw new RecordingIdentityError('PUBLIC_INBOX', `Refusing org recording uploads for public-inbox identity ${identity.email}. Sign in with an organization email.`);
|
|
55
|
+
}
|
|
56
|
+
return { email: identity.email };
|
|
57
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { RecordingCandidate, RecordingLedgerRow } from './model.js';
|
|
2
|
+
export declare class RecordingLedger {
|
|
3
|
+
readonly filePath: string;
|
|
4
|
+
constructor(filePath?: string);
|
|
5
|
+
private ensure;
|
|
6
|
+
private readUnlocked;
|
|
7
|
+
private transaction;
|
|
8
|
+
list(): Promise<RecordingLedgerRow[]>;
|
|
9
|
+
queue(candidate: RecordingCandidate): Promise<RecordingLedgerRow>;
|
|
10
|
+
update(stem: string, sourcePath: string, patch: Partial<RecordingLedgerRow>): Promise<RecordingLedgerRow | null>;
|
|
11
|
+
claim(stem: string, sourcePath: string, now?: number): Promise<boolean>;
|
|
12
|
+
recoverInterrupted(now?: number): Promise<void>;
|
|
13
|
+
pending(now?: number): Promise<RecordingLedgerRow[]>;
|
|
14
|
+
shouldPostAttention(reason: string): Promise<boolean>;
|
|
15
|
+
clearAttention(): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { atomicWriteFile, withFileLockAsync } from '../fs-atomic.js';
|
|
4
|
+
import { recordingsLedgerPath } from './config.js';
|
|
5
|
+
const EMPTY_LEDGER = { version: 1, rows: [] };
|
|
6
|
+
export class RecordingLedger {
|
|
7
|
+
filePath;
|
|
8
|
+
constructor(filePath = recordingsLedgerPath()) {
|
|
9
|
+
this.filePath = filePath;
|
|
10
|
+
}
|
|
11
|
+
async ensure() {
|
|
12
|
+
await fs.mkdir(path.dirname(this.filePath), { recursive: true, mode: 0o700 });
|
|
13
|
+
try {
|
|
14
|
+
const handle = await fs.open(this.filePath, 'wx', 0o600);
|
|
15
|
+
await handle.writeFile(`${JSON.stringify(EMPTY_LEDGER, null, 2)}\n`);
|
|
16
|
+
await handle.close();
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
if (error.code !== 'EEXIST')
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
async readUnlocked() {
|
|
24
|
+
try {
|
|
25
|
+
const contents = await fs.readFile(this.filePath, 'utf8');
|
|
26
|
+
if (contents.trim().length === 0)
|
|
27
|
+
return { ...EMPTY_LEDGER, rows: [] };
|
|
28
|
+
const parsed = JSON.parse(contents);
|
|
29
|
+
if (parsed.version !== 1 || !Array.isArray(parsed.rows))
|
|
30
|
+
throw new Error('unsupported ledger schema');
|
|
31
|
+
return { version: 1, rows: parsed.rows, attention: parsed.attention };
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (error.code === 'ENOENT')
|
|
35
|
+
return { ...EMPTY_LEDGER, rows: [] };
|
|
36
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
37
|
+
throw new Error(`Recording ledger is unreadable at ${this.filePath}: ${detail}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async transaction(fn) {
|
|
41
|
+
await this.ensure();
|
|
42
|
+
return withFileLockAsync(this.filePath, async () => {
|
|
43
|
+
const ledger = await this.readUnlocked();
|
|
44
|
+
const before = JSON.stringify(ledger);
|
|
45
|
+
const result = await fn(ledger);
|
|
46
|
+
if (JSON.stringify(ledger) !== before) {
|
|
47
|
+
await atomicWriteFile(this.filePath, `${JSON.stringify(ledger, null, 2)}\n`, { encoding: 'utf8', mode: 0o600 });
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async list() {
|
|
53
|
+
await this.ensure();
|
|
54
|
+
return (await this.readUnlocked()).rows.sort((a, b) => b.recordedAt.localeCompare(a.recordedAt));
|
|
55
|
+
}
|
|
56
|
+
async queue(candidate) {
|
|
57
|
+
return this.transaction((ledger) => {
|
|
58
|
+
const existing = ledger.rows.find((row) => row.stem === candidate.stem);
|
|
59
|
+
const sameFile = existing
|
|
60
|
+
&& existing.path === candidate.path
|
|
61
|
+
&& existing.size === candidate.size
|
|
62
|
+
&& existing.mtimeMs === candidate.mtimeMs;
|
|
63
|
+
if (sameFile)
|
|
64
|
+
return existing;
|
|
65
|
+
const row = {
|
|
66
|
+
...candidate,
|
|
67
|
+
url: null,
|
|
68
|
+
status: 'queued',
|
|
69
|
+
error: null,
|
|
70
|
+
updatedAt: new Date().toISOString(),
|
|
71
|
+
};
|
|
72
|
+
if (existing)
|
|
73
|
+
Object.assign(existing, row, { retryAt: undefined });
|
|
74
|
+
else
|
|
75
|
+
ledger.rows.push(row);
|
|
76
|
+
return existing ?? row;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
async update(stem, sourcePath, patch) {
|
|
80
|
+
return this.transaction((ledger) => {
|
|
81
|
+
const row = ledger.rows.find((entry) => entry.stem === stem && entry.path === sourcePath);
|
|
82
|
+
if (!row)
|
|
83
|
+
return null;
|
|
84
|
+
Object.assign(row, patch, { updatedAt: new Date().toISOString() });
|
|
85
|
+
return row;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
async claim(stem, sourcePath, now = Date.now()) {
|
|
89
|
+
return this.transaction((ledger) => {
|
|
90
|
+
const row = ledger.rows.find((entry) => entry.stem === stem && entry.path === sourcePath);
|
|
91
|
+
if (!row)
|
|
92
|
+
return false;
|
|
93
|
+
if (row.status !== 'queued' && row.status !== 'failed')
|
|
94
|
+
return false;
|
|
95
|
+
if (row.retryAt && Date.parse(row.retryAt) > now)
|
|
96
|
+
return false;
|
|
97
|
+
row.status = 'transcoding';
|
|
98
|
+
row.error = null;
|
|
99
|
+
delete row.retryAt;
|
|
100
|
+
row.updatedAt = new Date(now).toISOString();
|
|
101
|
+
return true;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
async recoverInterrupted(now = Date.now()) {
|
|
105
|
+
await this.transaction((ledger) => {
|
|
106
|
+
for (const row of ledger.rows) {
|
|
107
|
+
if (row.status !== 'transcoding' && row.status !== 'uploading')
|
|
108
|
+
continue;
|
|
109
|
+
row.status = 'queued';
|
|
110
|
+
row.error = 'Interrupted before completion; retrying.';
|
|
111
|
+
row.updatedAt = new Date(now).toISOString();
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
async pending(now = Date.now()) {
|
|
116
|
+
await this.ensure();
|
|
117
|
+
return (await this.readUnlocked()).rows.filter((row) => (row.status === 'queued' && (!row.retryAt || Date.parse(row.retryAt) <= now))
|
|
118
|
+
|| (row.status === 'failed' && (!row.retryAt || Date.parse(row.retryAt) <= now)));
|
|
119
|
+
}
|
|
120
|
+
async shouldPostAttention(reason) {
|
|
121
|
+
await this.ensure();
|
|
122
|
+
return withFileLockAsync(this.filePath, async () => {
|
|
123
|
+
const ledger = await this.readUnlocked();
|
|
124
|
+
if (ledger.attention?.reason === reason)
|
|
125
|
+
return false;
|
|
126
|
+
ledger.attention = { reason, postedAt: new Date().toISOString() };
|
|
127
|
+
await atomicWriteFile(this.filePath, `${JSON.stringify(ledger, null, 2)}\n`, { encoding: 'utf8', mode: 0o600 });
|
|
128
|
+
return true;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
async clearAttention() {
|
|
132
|
+
await this.ensure();
|
|
133
|
+
await withFileLockAsync(this.filePath, async () => {
|
|
134
|
+
const ledger = await this.readUnlocked();
|
|
135
|
+
if (!ledger.attention)
|
|
136
|
+
return;
|
|
137
|
+
delete ledger.attention;
|
|
138
|
+
await atomicWriteFile(this.filePath, `${JSON.stringify(ledger, null, 2)}\n`, { encoding: 'utf8', mode: 0o600 });
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type RecordingStatus = 'queued' | 'transcoding' | 'uploading' | 'uploaded' | 'failed';
|
|
2
|
+
export interface RecordingCandidate {
|
|
3
|
+
path: string;
|
|
4
|
+
stem: string;
|
|
5
|
+
slug: string;
|
|
6
|
+
size: number;
|
|
7
|
+
mtimeMs: number;
|
|
8
|
+
recordedAt: string;
|
|
9
|
+
sessionId?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface RecordingLedgerRow {
|
|
12
|
+
path: string;
|
|
13
|
+
stem: string;
|
|
14
|
+
slug: string;
|
|
15
|
+
url: string | null;
|
|
16
|
+
status: RecordingStatus;
|
|
17
|
+
error: string | null;
|
|
18
|
+
size: number;
|
|
19
|
+
mtimeMs: number;
|
|
20
|
+
recordedAt: string;
|
|
21
|
+
sessionId?: string;
|
|
22
|
+
updatedAt: string;
|
|
23
|
+
retryAt?: string;
|
|
24
|
+
}
|
|
25
|
+
export declare function isRecordingFile(filePath: string): boolean;
|
|
26
|
+
export declare function cleanShotStem(filePath: string): string;
|
|
27
|
+
export declare function slugifyRecordingStem(stem: string): string;
|
|
28
|
+
export declare function candidateVersion(candidate: Pick<RecordingCandidate, 'mtimeMs' | 'path'>): string;
|
|
29
|
+
export declare function isNewerRecording(candidate: Pick<RecordingCandidate, 'mtimeMs' | 'path'>, current: Pick<RecordingCandidate, 'mtimeMs' | 'path'>): boolean;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as path from 'node:path';
|
|
2
|
+
export function isRecordingFile(filePath) {
|
|
3
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
4
|
+
return ext === '.mp4' || ext === '.mov';
|
|
5
|
+
}
|
|
6
|
+
export function cleanShotStem(filePath) {
|
|
7
|
+
const raw = path.basename(filePath, path.extname(filePath));
|
|
8
|
+
const reexport = /^(CleanShot .+?) ([1-9]\d*)$/.exec(raw);
|
|
9
|
+
return reexport?.[1] ?? raw;
|
|
10
|
+
}
|
|
11
|
+
export function slugifyRecordingStem(stem) {
|
|
12
|
+
const slug = stem
|
|
13
|
+
.normalize('NFKD')
|
|
14
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
15
|
+
.toLowerCase()
|
|
16
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
17
|
+
.replace(/^-+|-+$/g, '')
|
|
18
|
+
.slice(0, 96)
|
|
19
|
+
.replace(/-+$/g, '');
|
|
20
|
+
return slug || 'recording';
|
|
21
|
+
}
|
|
22
|
+
export function candidateVersion(candidate) {
|
|
23
|
+
return `${candidate.mtimeMs}:${candidate.path}`;
|
|
24
|
+
}
|
|
25
|
+
export function isNewerRecording(candidate, current) {
|
|
26
|
+
return candidate.mtimeMs > current.mtimeMs
|
|
27
|
+
|| (candidate.mtimeMs === current.mtimeMs && candidate.path.localeCompare(current.path) > 0);
|
|
28
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { RecordingLedger } from './ledger.js';
|
|
2
|
+
import { type RecordingCandidate, type RecordingLedgerRow } from './model.js';
|
|
3
|
+
import { type TranscodedRecording } from './transcode.js';
|
|
4
|
+
export interface RecordingPipelineOptions {
|
|
5
|
+
ledger?: RecordingLedger;
|
|
6
|
+
artifactsBin?: string;
|
|
7
|
+
env?: NodeJS.ProcessEnv;
|
|
8
|
+
transcode?: (sourcePath: string, signal?: AbortSignal) => Promise<TranscodedRecording>;
|
|
9
|
+
verifyIdentity?: (signal?: AbortSignal) => Promise<{
|
|
10
|
+
email: string;
|
|
11
|
+
}>;
|
|
12
|
+
raiseAttention?: (message: string) => Promise<void>;
|
|
13
|
+
reportError?: (message: string) => void;
|
|
14
|
+
retryDelayMs?: number;
|
|
15
|
+
dependencyRetryDelayMs?: number;
|
|
16
|
+
}
|
|
17
|
+
export declare function buildArtifactsRecordingArgs(candidate: RecordingCandidate, transcodedPath: string): string[];
|
|
18
|
+
export declare function buildArtifactsRecordingEnv(candidate: RecordingCandidate, base: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
19
|
+
export declare class RecordingPipeline {
|
|
20
|
+
readonly ledger: RecordingLedger;
|
|
21
|
+
private readonly active;
|
|
22
|
+
private readonly configuredArtifactsBin?;
|
|
23
|
+
private readonly env;
|
|
24
|
+
private readonly transcode;
|
|
25
|
+
private readonly verifyIdentity;
|
|
26
|
+
private readonly raiseAttention;
|
|
27
|
+
private readonly reportError;
|
|
28
|
+
private readonly retryDelayMs;
|
|
29
|
+
private readonly dependencyRetryDelayMs;
|
|
30
|
+
constructor(options?: RecordingPipelineOptions);
|
|
31
|
+
private artifactsBin;
|
|
32
|
+
observeLatest(candidate: RecordingCandidate): void;
|
|
33
|
+
queue(candidates: RecordingCandidate[]): Promise<void>;
|
|
34
|
+
recoverInterrupted(): Promise<void>;
|
|
35
|
+
private attention;
|
|
36
|
+
private share;
|
|
37
|
+
private start;
|
|
38
|
+
drain(options?: {
|
|
39
|
+
awaitUploads?: boolean;
|
|
40
|
+
signal?: AbortSignal;
|
|
41
|
+
}): Promise<RecordingLedgerRow[]>;
|
|
42
|
+
upload(candidate: RecordingCandidate, signal?: AbortSignal): Promise<RecordingLedgerRow>;
|
|
43
|
+
stop(): Promise<void>;
|
|
44
|
+
}
|