@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
|
@@ -16,9 +16,11 @@ import { enabledRoutineNames, replaceEnabledRoutines } from '../routine-activati
|
|
|
16
16
|
import { evaluateActivationReadiness } from '../routine-readiness.js';
|
|
17
17
|
import { migrateDeviceConfigStores } from '../devices/config-migration.js';
|
|
18
18
|
import { detrackViaGitExclude } from '../project-resources.js';
|
|
19
|
-
import { META_HEADER as DEVICE_META_HEADER } from '../state.js';
|
|
19
|
+
import { META_HEADER as DEVICE_META_HEADER, commitCentralConfig } from '../state.js';
|
|
20
20
|
const LEGACY_DEFAULT_BROWSER_PROFILE_NAME = 'default';
|
|
21
21
|
import { COMPILED_HEADER_PROJECT } from '../rules/compile.js';
|
|
22
|
+
import { putOwnerPreferences, resolveOwnerCredential } from '../owner-notify.js';
|
|
23
|
+
import { moveFileToTrash } from '../trash.js';
|
|
22
24
|
const HOME = process.env.HOME ?? os.homedir();
|
|
23
25
|
const USER_DIR = path.join(HOME, '.agents');
|
|
24
26
|
const SYSTEM_DIR = path.join(USER_DIR, '.system');
|
|
@@ -1605,99 +1607,108 @@ export function migrateCliDirToClis(agentsDirs) {
|
|
|
1605
1607
|
fs.renameSync(src, dest);
|
|
1606
1608
|
}
|
|
1607
1609
|
}
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1610
|
+
export const LEGACY_HUMANS_FILE = 'humans.yaml';
|
|
1611
|
+
const SEVERITY_EVENTS = {
|
|
1612
|
+
critical: ['needs_you'],
|
|
1613
|
+
normal: ['failed', 'message'],
|
|
1614
|
+
low: ['completed'],
|
|
1615
|
+
};
|
|
1616
|
+
function accountChannelFor(transport) {
|
|
1617
|
+
const t = transport.trim().toLowerCase();
|
|
1618
|
+
return t === 'imessage' || t === 'slack' || t === 'email' ? t : null;
|
|
1619
|
+
}
|
|
1620
|
+
export function humansToPreferencesPatch(doc) {
|
|
1621
|
+
const owner = (doc && typeof doc === 'object' ? doc.owner : undefined);
|
|
1622
|
+
const rawChannels = Array.isArray(owner?.channels) ? owner.channels : [];
|
|
1623
|
+
const legacy = owner?.notify;
|
|
1624
|
+
const channels = rawChannels.length > 0
|
|
1625
|
+
? rawChannels
|
|
1626
|
+
: (typeof legacy?.channel === 'string' ? [{ id: legacy.channel, transport: legacy.channel, to: legacy.to }] : []);
|
|
1627
|
+
const byId = new Map();
|
|
1628
|
+
const dropped = [];
|
|
1629
|
+
let imessageAddress;
|
|
1630
|
+
for (const entry of channels) {
|
|
1631
|
+
if (typeof entry.id !== 'string')
|
|
1632
|
+
continue;
|
|
1633
|
+
const transport = typeof entry.transport === 'string' ? entry.transport : entry.id;
|
|
1634
|
+
const channel = accountChannelFor(transport);
|
|
1635
|
+
if (!channel) {
|
|
1636
|
+
dropped.push(`${entry.id} (${transport})`);
|
|
1637
|
+
continue;
|
|
1632
1638
|
}
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
ownerDefaultSeverity = fm['default_severity'];
|
|
1650
|
-
if (Array.isArray(fm['channels']))
|
|
1651
|
-
ownerChannels = fm['channels'];
|
|
1652
|
-
if (fm['policy'] && typeof fm['policy'] === 'object')
|
|
1653
|
-
ownerPolicy = fm['policy'];
|
|
1639
|
+
byId.set(entry.id, channel);
|
|
1640
|
+
if (channel === 'imessage' && typeof entry.to === 'string' && entry.to.trim())
|
|
1641
|
+
imessageAddress ??= entry.to.trim();
|
|
1642
|
+
}
|
|
1643
|
+
const policy = (owner?.policy ?? {});
|
|
1644
|
+
const [firstChannel] = byId.keys();
|
|
1645
|
+
const preferences = [];
|
|
1646
|
+
if (byId.size > 0) {
|
|
1647
|
+
for (const severity of ['critical', 'normal', 'low']) {
|
|
1648
|
+
const listed = Array.isArray(policy[severity])
|
|
1649
|
+
? policy[severity].filter((id) => typeof id === 'string')
|
|
1650
|
+
: (severity === 'low' ? [] : [firstChannel]);
|
|
1651
|
+
const enabled = new Set(listed.map((id) => byId.get(id)).filter((c) => Boolean(c)));
|
|
1652
|
+
for (const event of SEVERITY_EVENTS[severity]) {
|
|
1653
|
+
for (const channel of ['email', 'slack', 'imessage']) {
|
|
1654
|
+
preferences.push({ event, channel, enabled: enabled.has(channel) });
|
|
1654
1655
|
}
|
|
1655
1656
|
}
|
|
1656
1657
|
}
|
|
1657
|
-
catch { }
|
|
1658
1658
|
}
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
const
|
|
1663
|
-
if (
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
if (
|
|
1674
|
-
|
|
1675
|
-
if (
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
return;
|
|
1659
|
+
const patch = {};
|
|
1660
|
+
if (preferences.length > 0)
|
|
1661
|
+
patch.preferences = preferences;
|
|
1662
|
+
const settings = {};
|
|
1663
|
+
if (typeof owner?.timezone === 'string' && owner.timezone.trim())
|
|
1664
|
+
settings.timezone = owner.timezone.trim();
|
|
1665
|
+
const quiet = typeof owner?.quiet_hours === 'string' ? owner.quiet_hours.match(/^\s*(\d{1,2}:\d{2})\s*-\s*(\d{1,2}:\d{2})\s*$/) : null;
|
|
1666
|
+
if (quiet) {
|
|
1667
|
+
settings.quietStart = quiet[1].padStart(5, '0');
|
|
1668
|
+
settings.quietEnd = quiet[2].padStart(5, '0');
|
|
1669
|
+
}
|
|
1670
|
+
else if (typeof owner?.quiet_hours === 'string' && owner.quiet_hours.trim()) {
|
|
1671
|
+
dropped.push(`quiet_hours '${owner.quiet_hours}' (expected HH:MM-HH:MM)`);
|
|
1672
|
+
}
|
|
1673
|
+
if (Object.keys(settings).length > 0)
|
|
1674
|
+
patch.settings = settings;
|
|
1675
|
+
if (imessageAddress)
|
|
1676
|
+
patch.destinations = { imessage: { address: imessageAddress } };
|
|
1677
|
+
return { patch, dropped };
|
|
1678
|
+
}
|
|
1679
|
+
const HUMANS_RETRY_MS = 60 * 60_000;
|
|
1680
|
+
export async function migrateHumansToAccount(userDir = USER_DIR, failureStamp = path.join(CACHE_DIR, 'humans-migration-failed')) {
|
|
1681
|
+
const humansFile = path.join(userDir, LEGACY_HUMANS_FILE);
|
|
1682
|
+
if (!fs.existsSync(humansFile))
|
|
1683
|
+
return 'absent';
|
|
1684
|
+
if (resolveOwnerCredential()?.kind !== 'session')
|
|
1685
|
+
return 'pending';
|
|
1686
|
+
try {
|
|
1687
|
+
if (Date.now() - fs.statSync(failureStamp).mtimeMs < HUMANS_RETRY_MS)
|
|
1688
|
+
return 'pending';
|
|
1686
1689
|
}
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
if (notifyNode instanceof yaml.YAMLMap) {
|
|
1693
|
-
notifyNode.delete('owner');
|
|
1694
|
-
if (notifyNode.items.length === 0)
|
|
1695
|
-
doc.delete('notify');
|
|
1696
|
-
}
|
|
1697
|
-
fs.writeFileSync(agentsYamlPath, stringifyDoc(doc), 'utf-8');
|
|
1698
|
-
}
|
|
1699
|
-
catch { }
|
|
1690
|
+
catch { }
|
|
1691
|
+
const { patch, dropped } = humansToPreferencesPatch(yaml.parse(fs.readFileSync(humansFile, 'utf-8')));
|
|
1692
|
+
try {
|
|
1693
|
+
if (Object.keys(patch).length > 0)
|
|
1694
|
+
await putOwnerPreferences(patch);
|
|
1700
1695
|
}
|
|
1696
|
+
catch (err) {
|
|
1697
|
+
fs.mkdirSync(path.dirname(failureStamp), { recursive: true });
|
|
1698
|
+
fs.writeFileSync(failureStamp, `${err.message}\n`);
|
|
1699
|
+
console.error(`humans.yaml migration: ${err.message} The file is kept and the upload retries in an hour.`);
|
|
1700
|
+
return 'pending';
|
|
1701
|
+
}
|
|
1702
|
+
fs.rmSync(failureStamp, { force: true });
|
|
1703
|
+
const trashed = moveFileToTrash(humansFile);
|
|
1704
|
+
const committed = commitCentralConfig(userDir, LEGACY_HUMANS_FILE, 'chore(config): humans.yaml moved to account notification preferences');
|
|
1705
|
+
console.error(`Moved owner notification settings from ${humansFile} to your account (console Settings). Old file: ${trashed}`);
|
|
1706
|
+
if (!committed && fs.existsSync(path.join(userDir, '.git'))) {
|
|
1707
|
+
console.error(`Could not commit the removal of ${LEGACY_HUMANS_FILE}; commit and push it with: agents repo push`);
|
|
1708
|
+
}
|
|
1709
|
+
if (dropped.length > 0)
|
|
1710
|
+
console.error(`No account equivalent, not migrated: ${dropped.join(', ')}`);
|
|
1711
|
+
return 'migrated';
|
|
1701
1712
|
}
|
|
1702
1713
|
export function seedActiveCursorLoginPerVersion() {
|
|
1703
1714
|
const realHome = process.env.AGENTS_REAL_HOME || os.homedir();
|
|
@@ -1848,7 +1859,7 @@ export async function runMigration() {
|
|
|
1848
1859
|
cliMigrateDirs.push(projectDotAgents);
|
|
1849
1860
|
migrateCliDirToClis(cliMigrateDirs);
|
|
1850
1861
|
migrateAgentsYaml();
|
|
1851
|
-
|
|
1862
|
+
await migrateHumansToAccount();
|
|
1852
1863
|
deleteSystemPromptsJson();
|
|
1853
1864
|
migrateSystemConfigJson();
|
|
1854
1865
|
detrackUserChangelog();
|
|
@@ -1302,10 +1302,10 @@ export function printTrashFooter(moved) {
|
|
|
1302
1302
|
console.log(chalk.gray('Sessions remain accessible via `agents sessions`.'));
|
|
1303
1303
|
if (moved.length === 1) {
|
|
1304
1304
|
const { agent, version } = moved[0];
|
|
1305
|
-
console.log(chalk.gray(`Restore with: agents restore ${agent}@${version}`));
|
|
1305
|
+
console.log(chalk.gray(`Restore with: agents trash restore ${agent}@${version}`));
|
|
1306
1306
|
}
|
|
1307
1307
|
else {
|
|
1308
|
-
console.log(chalk.gray('Restore with: agents restore <agent>@<version> (run `agents trash list` to see)'));
|
|
1308
|
+
console.log(chalk.gray('Restore with: agents trash restore <agent>@<version> (run `agents trash list` to see)'));
|
|
1309
1309
|
}
|
|
1310
1310
|
}
|
|
1311
1311
|
export function removeAllVersions(agent) {
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
export declare function launchIdentityEnv(env?: NodeJS.ProcessEnv): Record<string, string>;
|
|
2
|
-
export
|
|
2
|
+
export interface LaunchOrigin {
|
|
3
|
+
device: string;
|
|
4
|
+
terminalId: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function launchOrigin(identity?: Record<string, string>): LaunchOrigin | undefined;
|
|
7
|
+
export declare const LAUNCH_IDENTITY_KEYS: readonly ["AGENT_TERMINAL_ID", "AGENT_SESSION_ID", "AGENTS_SESSION_ID", "AGENTS_MAILBOX_DIR", "AGENT_LAUNCH_ID", "AGENTS_PARENT_SESSION_ID", "AGENTS_PARENT_LAUNCH_ID", "AGENTS_ORIGIN_TERMINAL_ID", "AGENTS_ORIGIN_DEVICE"];
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
import { machineId } from './machine-id.js';
|
|
1
2
|
export function launchIdentityEnv(env = process.env) {
|
|
2
3
|
const result = {};
|
|
3
4
|
const terminal = env.AGENT_TERMINAL_ID?.trim();
|
|
4
5
|
const nested = env.AGENTS_RUNTIME === 'terminal' || env.AGENTS_RUNTIME === 'headless' || env.AGENTS_RUNTIME === 'teams';
|
|
5
6
|
if (terminal && !nested)
|
|
6
7
|
result.AGENT_TERMINAL_ID = terminal;
|
|
7
|
-
const
|
|
8
|
-
|
|
8
|
+
const inheritedTerminal = env.AGENTS_ORIGIN_TERMINAL_ID?.trim();
|
|
9
|
+
const originTerminal = inheritedTerminal || terminal;
|
|
10
|
+
if (originTerminal) {
|
|
9
11
|
result.AGENTS_ORIGIN_TERMINAL_ID = originTerminal;
|
|
12
|
+
result.AGENTS_ORIGIN_DEVICE = (inheritedTerminal && env.AGENTS_ORIGIN_DEVICE?.trim()) || machineId();
|
|
13
|
+
}
|
|
10
14
|
const parentLaunch = nested ? env.AGENT_LAUNCH_ID : env.AGENTS_PARENT_LAUNCH_ID;
|
|
11
15
|
const parentSession = nested
|
|
12
16
|
? env.AGENTS_SESSION_ID || env.AGENT_SESSION_ID
|
|
@@ -17,7 +21,13 @@ export function launchIdentityEnv(env = process.env) {
|
|
|
17
21
|
result.AGENTS_PARENT_SESSION_ID = parentSession;
|
|
18
22
|
return result;
|
|
19
23
|
}
|
|
24
|
+
export function launchOrigin(identity = launchIdentityEnv()) {
|
|
25
|
+
const device = identity.AGENTS_ORIGIN_DEVICE;
|
|
26
|
+
const terminalId = identity.AGENTS_ORIGIN_TERMINAL_ID;
|
|
27
|
+
return device && terminalId && identity.AGENT_TERMINAL_ID ? { device, terminalId } : undefined;
|
|
28
|
+
}
|
|
20
29
|
export const LAUNCH_IDENTITY_KEYS = [
|
|
21
30
|
'AGENT_TERMINAL_ID', 'AGENT_SESSION_ID', 'AGENTS_SESSION_ID', 'AGENTS_MAILBOX_DIR',
|
|
22
31
|
'AGENT_LAUNCH_ID', 'AGENTS_PARENT_SESSION_ID', 'AGENTS_PARENT_LAUNCH_ID', 'AGENTS_ORIGIN_TERMINAL_ID',
|
|
32
|
+
'AGENTS_ORIGIN_DEVICE',
|
|
23
33
|
];
|
|
@@ -71,6 +71,7 @@ export declare function mayInstallMenubarHelper(opts: {
|
|
|
71
71
|
cooldownMs: number;
|
|
72
72
|
sourceIsDeveloperId: boolean;
|
|
73
73
|
}): boolean;
|
|
74
|
+
export declare function menubarGateVersion(source: string | null, cached?: () => string): string;
|
|
74
75
|
export declare function installMenubarLaunchAgentOnUpgrade(): void;
|
|
75
76
|
export declare function shouldMigrateMenubarTcc(opts: {
|
|
76
77
|
needsDevIdHeal: boolean;
|
|
@@ -493,9 +493,12 @@ function stampMenubarHeal() {
|
|
|
493
493
|
}
|
|
494
494
|
catch { }
|
|
495
495
|
}
|
|
496
|
-
function
|
|
496
|
+
export function menubarGateVersion(source, cached = availableHelperLabel) {
|
|
497
|
+
return source ? stampVersionLabel(stampFor(source)) ?? LOCAL_BUILD_LABEL : cached();
|
|
498
|
+
}
|
|
499
|
+
function mayHealMenubar(needsDevIdHeal, source = sourceAppPath()) {
|
|
497
500
|
const plistEntry = readPlistEnvValue('AGENTS_ENTRY');
|
|
498
|
-
const src =
|
|
501
|
+
const src = source;
|
|
499
502
|
return mayInstallMenubarHelper({
|
|
500
503
|
plistEntry,
|
|
501
504
|
activeEntry: resolveCliEntry(),
|
|
@@ -503,7 +506,7 @@ function mayHealMenubar(needsDevIdHeal) {
|
|
|
503
506
|
helperExecMissing: !fs.existsSync(installedExecutablePath()),
|
|
504
507
|
needsDevIdHeal,
|
|
505
508
|
installedVersion: stampVersionLabel(readInstalledMenubarStamp()),
|
|
506
|
-
currentVersion:
|
|
509
|
+
currentVersion: menubarGateVersion(src),
|
|
507
510
|
msSinceLastHeal: msSinceLastMenubarHeal(),
|
|
508
511
|
cooldownMs: MENUBAR_TAKEOVER_COOLDOWN_MS,
|
|
509
512
|
sourceIsDeveloperId: Boolean(src) && hasDeveloperIdSignature(src),
|
|
@@ -807,12 +810,12 @@ export async function updateMenubarHelperIfNewer(opts = {}) {
|
|
|
807
810
|
if (menubarUpdateOutcome(release.helperVersion, available) === 'current') {
|
|
808
811
|
return { outcome: 'current', installed, available, detail: `AGI Menu ${installed} is the newest published build` };
|
|
809
812
|
}
|
|
810
|
-
if (!mayHealMenubar(false))
|
|
811
|
-
return skip(`another install owns the helper; it will update on its own cooldown`, available);
|
|
812
813
|
if (opts.dryRun)
|
|
813
814
|
return { outcome: 'updated', installed, available, detail: `would update AGI Menu ${installed} → ${available}` };
|
|
814
815
|
try {
|
|
815
816
|
const src = await downloadMenubarHelperApp(available);
|
|
817
|
+
if (!mayHealMenubar(false, src))
|
|
818
|
+
return skip(`another install owns the helper; it will update on its own cooldown`, available);
|
|
816
819
|
const exec = ensureMenubarAppInstalled({ forceReinstall: true, sourceAppPath: src });
|
|
817
820
|
if (!exec)
|
|
818
821
|
return { outcome: 'failed', installed, available, detail: 'the verified bundle could not be installed' };
|
|
@@ -8,7 +8,7 @@ import { backfillActiveRowsFromIndex, isRunningLiveSession, serializeActiveSessi
|
|
|
8
8
|
import { getConfigValue, listConfiguredDeviceRoles, loadAutoLaunchPreferences } from '../device-config.js';
|
|
9
9
|
import { filterAutoPool } from '../devices/pool.js';
|
|
10
10
|
import { isFreshDeviceStats, readStatsCache } from '../devices/stats-cache.js';
|
|
11
|
-
import {
|
|
11
|
+
import { MENUBAR_CONFIG_KEYS } from '../config-keys.js';
|
|
12
12
|
import { migrateMenubarPreferencesFromUserDefaults } from './migrate-prefs.js';
|
|
13
13
|
import { loadDevices } from '../devices/registry.js';
|
|
14
14
|
import { machineId } from '../machine-id.js';
|
|
@@ -53,8 +53,7 @@ export function buildMenuListPreferences() {
|
|
|
53
53
|
}
|
|
54
54
|
function effectiveMenuPreferences() {
|
|
55
55
|
const out = [];
|
|
56
|
-
for (const
|
|
57
|
-
const name = `menubar.menu.${prop}`;
|
|
56
|
+
for (const name of MENUBAR_CONFIG_KEYS) {
|
|
58
57
|
const entry = getConfigValue(name);
|
|
59
58
|
const value = entry.value !== undefined ? entry.value : entry.spec.defaultValue;
|
|
60
59
|
if (value === undefined)
|
package/dist/lib/notify.d.ts
CHANGED
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
import type { OpenBlock } from './feed/feed.js';
|
|
2
|
-
import type { Meta } from './types.js';
|
|
3
2
|
import type { SendResult } from './channels/registry.js';
|
|
4
|
-
import { type
|
|
5
|
-
export interface OwnerNotifyOptions {
|
|
6
|
-
meta?: Meta;
|
|
7
|
-
channel?: string;
|
|
8
|
-
target?: string;
|
|
9
|
-
dryRun?: boolean;
|
|
10
|
-
thread?: string;
|
|
11
|
-
attachments?: string[];
|
|
12
|
-
from?: string;
|
|
13
|
-
composeForFormat?: (format: SinkMessageFormat) => string;
|
|
14
|
-
}
|
|
3
|
+
import { type OwnerNotification } from './owner-notify.js';
|
|
15
4
|
export interface NotifyResult {
|
|
16
5
|
ok: boolean;
|
|
17
6
|
skipped?: boolean;
|
|
@@ -23,5 +12,9 @@ export declare function buildOpenClawNotifyArgs(text: string, opts: {
|
|
|
23
12
|
channel?: string;
|
|
24
13
|
account?: string;
|
|
25
14
|
}): string[];
|
|
26
|
-
export declare function sendToOwner(
|
|
27
|
-
|
|
15
|
+
export declare function sendToOwner(notification: OwnerNotification, options?: {
|
|
16
|
+
dryRun?: boolean;
|
|
17
|
+
}): Promise<SendResult>;
|
|
18
|
+
export declare function notifyUrgentBlock(block: OpenBlock, options?: {
|
|
19
|
+
dryRun?: boolean;
|
|
20
|
+
}): Promise<NotifyResult>;
|
package/dist/lib/notify.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getOwnerNotifyDestinationsFromHumans } from './humans.js';
|
|
3
|
-
import { registerBuiltinProviders } from './channels/providers/index.js';
|
|
4
|
-
import { lookupTransport } from './channels/resolve.js';
|
|
5
|
-
import { forwardOwnerNotifyToPeer } from './channels/owner-forward.js';
|
|
6
|
-
import { sinkMessageFormat } from './sink-format.js';
|
|
1
|
+
import { describeOwnerResult, postOwnerNotification, resolveOwnerCredential, OwnerNotSignedInError, } from './owner-notify.js';
|
|
7
2
|
export function formatUrgentBlockMessage(block) {
|
|
8
3
|
const q = block.questions[0];
|
|
9
4
|
const header = q?.header ? `[${q.header}] ` : '';
|
|
@@ -29,78 +24,28 @@ export function buildOpenClawNotifyArgs(text, opts) {
|
|
|
29
24
|
text,
|
|
30
25
|
];
|
|
31
26
|
}
|
|
32
|
-
export async function sendToOwner(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
to: configured[0]?.to,
|
|
43
|
-
}]
|
|
44
|
-
: configured;
|
|
45
|
-
const addressable = destinations.filter((dest) => Boolean(dest.channel && dest.to));
|
|
46
|
-
if (addressable.length === 0) {
|
|
27
|
+
export async function sendToOwner(notification, options = {}) {
|
|
28
|
+
try {
|
|
29
|
+
if (options.dryRun) {
|
|
30
|
+
if (!resolveOwnerCredential())
|
|
31
|
+
throw new OwnerNotSignedInError();
|
|
32
|
+
return { ok: true, channel: 'owner', id: notification.dedupKey, body: notification.body };
|
|
33
|
+
}
|
|
34
|
+
const result = await postOwnerNotification(notification);
|
|
35
|
+
const partial = result.skipped.length > 0 && result.delivered.length + result.queued.length > 0;
|
|
36
|
+
const reachedNobody = result.suppressed === null && result.delivered.length + result.queued.length === 0;
|
|
47
37
|
return {
|
|
48
|
-
ok:
|
|
49
|
-
channel:
|
|
50
|
-
id:
|
|
51
|
-
|
|
38
|
+
ok: !reachedNobody,
|
|
39
|
+
channel: 'owner',
|
|
40
|
+
id: result.dispatchId ?? notification.dedupKey,
|
|
41
|
+
body: notification.body,
|
|
42
|
+
msgId: describeOwnerResult(result),
|
|
43
|
+
...(partial || reachedNobody ? { error: describeOwnerResult(result) } : {}),
|
|
52
44
|
};
|
|
53
45
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
for (const { channel, to: target } of addressable) {
|
|
57
|
-
const { provider, providerName, error } = lookupTransport(channel, meta);
|
|
58
|
-
const body = options.composeForFormat
|
|
59
|
-
? options.composeForFormat(sinkMessageFormat(providerName))
|
|
60
|
-
: text;
|
|
61
|
-
let result;
|
|
62
|
-
try {
|
|
63
|
-
result = provider
|
|
64
|
-
? await provider.send(body, {
|
|
65
|
-
target,
|
|
66
|
-
ownerScoped: options.target === undefined,
|
|
67
|
-
dryRun: options.dryRun,
|
|
68
|
-
thread: options.thread,
|
|
69
|
-
attachments: options.attachments,
|
|
70
|
-
from: options.from,
|
|
71
|
-
})
|
|
72
|
-
: { ok: false, channel, id: target, error };
|
|
73
|
-
}
|
|
74
|
-
catch (err) {
|
|
75
|
-
result = { ok: false, channel, id: target, error: err.message };
|
|
76
|
-
}
|
|
77
|
-
if (!result.ok && !options.dryRun && options.target === undefined) {
|
|
78
|
-
if (options.attachments?.length) {
|
|
79
|
-
result = {
|
|
80
|
-
...result,
|
|
81
|
-
error: `${result.error ?? 'local delivery failed'}; owner attachments cannot be forwarded to another device`,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
result = await forwardOwnerNotifyToPeer(body, channel, target, meta, {
|
|
86
|
-
envelope: { thread: options.thread, from: options.from },
|
|
87
|
-
}) ?? result;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
deliveries.push({ ...result, body });
|
|
46
|
+
catch (err) {
|
|
47
|
+
return { ok: false, channel: 'owner', id: notification.dedupKey, error: err.message };
|
|
91
48
|
}
|
|
92
|
-
if (deliveries.length === 1)
|
|
93
|
-
return deliveries[0];
|
|
94
|
-
const failures = deliveries.filter((result) => !result.ok);
|
|
95
|
-
return {
|
|
96
|
-
ok: deliveries.some((result) => result.ok),
|
|
97
|
-
channel: 'owner',
|
|
98
|
-
id: deliveries.map((result) => `${result.channel}:${result.id}`).join(','),
|
|
99
|
-
...(failures.length > 0
|
|
100
|
-
? { error: failures.map((result) => `${result.channel}: ${result.error ?? 'failed'}`).join('; ') }
|
|
101
|
-
: {}),
|
|
102
|
-
deliveries,
|
|
103
|
-
};
|
|
104
49
|
}
|
|
105
50
|
export async function notifyUrgentBlock(block, options = {}) {
|
|
106
51
|
if (block.notifiedAt) {
|
|
@@ -109,6 +54,15 @@ export async function notifyUrgentBlock(block, options = {}) {
|
|
|
109
54
|
if (options.dryRun) {
|
|
110
55
|
return { ok: true, skipped: true };
|
|
111
56
|
}
|
|
112
|
-
const
|
|
57
|
+
const q = block.questions[0];
|
|
58
|
+
const result = await sendToOwner({
|
|
59
|
+
event: 'needs_you',
|
|
60
|
+
title: q?.header?.trim() || 'Agent needs input',
|
|
61
|
+
body: formatUrgentBlockMessage(block),
|
|
62
|
+
sessionId: block.sessionId,
|
|
63
|
+
...(block.ticket ? { ticket: block.ticket } : {}),
|
|
64
|
+
dedupKey: `block:${block.blockId}`,
|
|
65
|
+
source: { device: block.host },
|
|
66
|
+
});
|
|
113
67
|
return result.ok ? { ok: true } : { ok: false, error: result.error };
|
|
114
68
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { OwnerNotification } from './owner-notify.js';
|
|
2
2
|
interface OwnerMessageOptions {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
format?: SinkMessageFormat;
|
|
3
|
+
agent?: string;
|
|
4
|
+
url?: string;
|
|
6
5
|
}
|
|
7
|
-
export declare function
|
|
8
|
-
export declare function ownerMessageComposer(rawText: string, opts?: OwnerMessageOptions): (format: SinkMessageFormat) => string;
|
|
6
|
+
export declare function ownerMessageNotification(rawText: string, opts?: OwnerMessageOptions): OwnerNotification;
|
|
9
7
|
export {};
|
|
@@ -1,25 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { randomUUID } from 'crypto';
|
|
2
|
+
import { ownerNotificationFromContext } from './feed-broadcast.js';
|
|
2
3
|
import { resolvePostIdentity } from './feed-post.js';
|
|
3
4
|
import { getSessionById, resolveFullSessionId } from './session/db.js';
|
|
4
5
|
import { linearIssueUrl } from '@phnx-labs/sessions-cli/reader';
|
|
5
|
-
function ownerMessageContext(rawText, opts
|
|
6
|
-
const identity = resolvePostIdentity({
|
|
6
|
+
function ownerMessageContext(rawText, opts) {
|
|
7
|
+
const identity = resolvePostIdentity({});
|
|
7
8
|
const session = resolveFullSessionId(identity?.sessionId);
|
|
8
9
|
const ticket = session ? getSessionById(session)?.ticketId : undefined;
|
|
10
|
+
const agent = opts.agent ?? identity?.agent;
|
|
9
11
|
return {
|
|
10
|
-
...(opts.title?.trim() ? { title: opts.title.trim() } : {}),
|
|
11
12
|
text: rawText,
|
|
12
13
|
level: 'important',
|
|
13
14
|
...(ticket ? { ticket, ticketUrl: linearIssueUrl(ticket) } : {}),
|
|
14
|
-
...(
|
|
15
|
+
...(agent ? { agent } : {}),
|
|
15
16
|
...(identity?.host ? { host: identity.host } : {}),
|
|
16
17
|
...(session ? { session } : {}),
|
|
18
|
+
...(opts.url ? { links: [opts.url] } : {}),
|
|
17
19
|
};
|
|
18
20
|
}
|
|
19
|
-
export function
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return (format) => composeBroadcastMessage(ctx, format);
|
|
21
|
+
export function ownerMessageNotification(rawText, opts = {}) {
|
|
22
|
+
const notification = ownerNotificationFromContext(ownerMessageContext(rawText, opts), 'message', `send:${randomUUID()}`);
|
|
23
|
+
if (!notification)
|
|
24
|
+
throw new Error('Message is empty.');
|
|
25
|
+
return notification;
|
|
25
26
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { PushBundleResult } from './secrets-types.js';
|
|
2
|
+
import { type DeviceProfile } from './devices/registry.js';
|
|
3
|
+
import { selfConfiguredDeviceRole } from './device-config.js';
|
|
4
|
+
export declare const OWNER_NOTIFY_PEER_FRESH_MS: number;
|
|
5
|
+
type Role = ReturnType<typeof selfConfiguredDeviceRole>;
|
|
6
|
+
export declare function publishOwnerNotifyState(opts?: {
|
|
7
|
+
device?: string;
|
|
8
|
+
userAgentsDir?: string;
|
|
9
|
+
}): Promise<{
|
|
10
|
+
signedIn: boolean;
|
|
11
|
+
deviceToken: boolean;
|
|
12
|
+
changed: boolean;
|
|
13
|
+
}>;
|
|
14
|
+
export declare function electOwnerNotifyMinter(signedInHeaded: readonly string[]): string | null;
|
|
15
|
+
interface OwnerNotifySyncResult {
|
|
16
|
+
minter: string | null;
|
|
17
|
+
minted: string[];
|
|
18
|
+
pushed: string[];
|
|
19
|
+
revoked: string[];
|
|
20
|
+
skipped: Array<{
|
|
21
|
+
device: string;
|
|
22
|
+
reason: string;
|
|
23
|
+
}>;
|
|
24
|
+
errors: Array<{
|
|
25
|
+
device: string;
|
|
26
|
+
message: string;
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
29
|
+
interface OwnerNotifySyncDeps {
|
|
30
|
+
localName?: string;
|
|
31
|
+
userAgentsDir?: string;
|
|
32
|
+
cacheDir?: string;
|
|
33
|
+
listDevices?: () => DeviceProfile[];
|
|
34
|
+
selfRole?: () => Role;
|
|
35
|
+
peerRole?: (name: string) => Role;
|
|
36
|
+
isPinned?: (name: string) => boolean;
|
|
37
|
+
push?: (bundle: string, host: string) => Promise<PushBundleResult>;
|
|
38
|
+
sshTarget?: (device: DeviceProfile) => string;
|
|
39
|
+
now?: () => number;
|
|
40
|
+
}
|
|
41
|
+
export declare function syncOwnerNotifyTokens(deps?: OwnerNotifySyncDeps): Promise<OwnerNotifySyncResult>;
|
|
42
|
+
export declare function revokeMintedOwnerNotifyTokens(cacheDir?: string): Promise<{
|
|
43
|
+
revoked: string[];
|
|
44
|
+
errors: Array<{
|
|
45
|
+
device: string;
|
|
46
|
+
message: string;
|
|
47
|
+
}>;
|
|
48
|
+
}>;
|
|
49
|
+
export {};
|