@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.
Files changed (194) hide show
  1. package/CHANGELOG.md +261 -0
  2. package/README.md +49 -10
  3. package/dist/bootstrap.js +22 -17
  4. package/dist/cli/command-registry.d.ts +0 -1
  5. package/dist/cli/command-registry.js +2 -10
  6. package/dist/commands/auth.js +13 -4
  7. package/dist/commands/browser.js +3 -4
  8. package/dist/commands/cloud-transcripts.d.ts +7 -0
  9. package/dist/commands/cloud-transcripts.js +100 -0
  10. package/dist/commands/cloud.js +5 -0
  11. package/dist/commands/computer.d.ts +0 -12
  12. package/dist/commands/computer.js +14 -124
  13. package/dist/commands/config.js +5 -4
  14. package/dist/commands/daemon-index.d.ts +2 -0
  15. package/dist/commands/daemon-index.js +44 -0
  16. package/dist/commands/daemon.js +6 -0
  17. package/dist/commands/doctor.js +3 -4
  18. package/dist/commands/exec.d.ts +5 -0
  19. package/dist/commands/exec.js +35 -7
  20. package/dist/commands/feed-watch.js +12 -0
  21. package/dist/commands/feed.d.ts +1 -1
  22. package/dist/commands/feed.js +7 -4
  23. package/dist/commands/insights.js +3 -1
  24. package/dist/commands/inspect.js +1 -1
  25. package/dist/commands/logs.js +2 -1
  26. package/dist/commands/models.js +1 -1
  27. package/dist/commands/prune.js +6 -28
  28. package/dist/commands/ps-roster.d.ts +0 -1
  29. package/dist/commands/ps-roster.js +2 -21
  30. package/dist/commands/ps.js +13 -1
  31. package/dist/commands/recordings.d.ts +2 -0
  32. package/dist/commands/recordings.js +117 -0
  33. package/dist/commands/routines.js +1 -1
  34. package/dist/commands/secrets-passthrough.js +3 -3
  35. package/dist/commands/send.js +33 -20
  36. package/dist/commands/sessions-backfill.d.ts +1 -0
  37. package/dist/commands/sessions-backfill.js +48 -13
  38. package/dist/commands/sessions-migrate.d.ts +1 -1
  39. package/dist/commands/sessions-migrate.js +11 -10
  40. package/dist/commands/sessions-optimize.d.ts +1 -0
  41. package/dist/commands/sessions-optimize.js +7 -4
  42. package/dist/commands/sessions-resume.js +8 -1
  43. package/dist/commands/sessions-stats.d.ts +2 -0
  44. package/dist/commands/sessions-stats.js +24 -7
  45. package/dist/commands/sessions.d.ts +5 -11
  46. package/dist/commands/sessions.js +8 -236
  47. package/dist/commands/setup-computer.js +1 -2
  48. package/dist/commands/setup.js +1 -1
  49. package/dist/commands/teams.js +2 -2
  50. package/dist/commands/testdata/feed-hub.d.ts +1 -0
  51. package/dist/commands/testdata/feed-hub.js +11 -0
  52. package/dist/commands/trash.d.ts +0 -1
  53. package/dist/commands/trash.js +74 -10
  54. package/dist/lib/accounting/usage-sync.js +7 -0
  55. package/dist/lib/agent-modes.d.ts +1 -1
  56. package/dist/lib/agent-modes.js +11 -5
  57. package/dist/lib/auth-mint.d.ts +4 -0
  58. package/dist/lib/auth-mint.js +6 -4
  59. package/dist/lib/browser/native-history.test-fixture.d.ts +12 -0
  60. package/dist/lib/browser/native-history.test-fixture.js +43 -0
  61. package/dist/lib/browser/paths.d.ts +5 -0
  62. package/dist/lib/browser/paths.js +7 -1
  63. package/dist/lib/browser/sessions-list.d.ts +28 -1
  64. package/dist/lib/browser/sessions-list.js +137 -25
  65. package/dist/lib/channels/providers/rush.d.ts +2 -1
  66. package/dist/lib/channels/providers/rush.js +2 -2
  67. package/dist/lib/channels/providers/session.d.ts +1 -0
  68. package/dist/lib/channels/providers/session.js +23 -12
  69. package/dist/lib/channels/registry.d.ts +9 -2
  70. package/dist/lib/channels/send.d.ts +5 -10
  71. package/dist/lib/channels/send.js +88 -50
  72. package/dist/lib/cloud/rush.d.ts +6 -0
  73. package/dist/lib/cloud/rush.js +18 -3
  74. package/dist/lib/computer-client.d.ts +19 -0
  75. package/dist/lib/computer-client.js +104 -0
  76. package/dist/lib/config-keys.d.ts +5 -1
  77. package/dist/lib/config-keys.js +14 -11
  78. package/dist/lib/daemon/auth-sync-service.js +13 -0
  79. package/dist/lib/daemon/daemon.js +20 -8
  80. package/dist/lib/daemon/owner-device-delivery-service.d.ts +10 -0
  81. package/dist/lib/daemon/owner-device-delivery-service.js +28 -0
  82. package/dist/lib/daemon-services.d.ts +2 -1
  83. package/dist/lib/daemon-services.js +17 -5
  84. package/dist/lib/device-config.d.ts +4 -1
  85. package/dist/lib/device-config.js +57 -7
  86. package/dist/lib/devices/doctor-findings.d.ts +2 -3
  87. package/dist/lib/devices/doctor-findings.js +10 -19
  88. package/dist/lib/event-provenance.d.ts +1 -0
  89. package/dist/lib/event-provenance.js +2 -0
  90. package/dist/lib/exec.d.ts +1 -0
  91. package/dist/lib/exec.js +20 -15
  92. package/dist/lib/feed/pr-status.d.ts +5 -1
  93. package/dist/lib/feed/pr-status.js +44 -3
  94. package/dist/lib/feed/tool-activity.js +9 -6
  95. package/dist/lib/feed/tools.d.ts +4 -1
  96. package/dist/lib/feed/tools.js +8 -11
  97. package/dist/lib/feed-broadcast.d.ts +5 -3
  98. package/dist/lib/feed-broadcast.js +47 -36
  99. package/dist/lib/fleet-shared-state.d.ts +5 -0
  100. package/dist/lib/fleet-shared-state.js +8 -0
  101. package/dist/lib/github/project-prs.d.ts +4 -1
  102. package/dist/lib/github/project-prs.js +18 -5
  103. package/dist/lib/help.d.ts +1 -0
  104. package/dist/lib/help.js +8 -0
  105. package/dist/lib/helper-versions.js +1 -1
  106. package/dist/lib/hosts/passthrough.js +5 -8
  107. package/dist/lib/hosts/remote-cmd.d.ts +2 -7
  108. package/dist/lib/hosts/remote-cmd.js +14 -22
  109. package/dist/lib/hosts/routing-flag.d.ts +22 -0
  110. package/dist/lib/hosts/routing-flag.js +127 -14
  111. package/dist/lib/identity/index.d.ts +22 -0
  112. package/dist/lib/identity/index.js +3 -0
  113. package/dist/lib/installations/migrate.d.ts +7 -0
  114. package/dist/lib/installations/migrate.js +99 -88
  115. package/dist/lib/installations/versions.js +2 -2
  116. package/dist/lib/launch-identity.d.ts +6 -1
  117. package/dist/lib/launch-identity.js +12 -2
  118. package/dist/lib/menubar/install-menubar.d.ts +1 -0
  119. package/dist/lib/menubar/install-menubar.js +8 -5
  120. package/dist/lib/menubar/snapshot.js +2 -3
  121. package/dist/lib/notify.d.ts +7 -14
  122. package/dist/lib/notify.js +29 -75
  123. package/dist/lib/owner-message.d.ts +4 -6
  124. package/dist/lib/owner-message.js +12 -11
  125. package/dist/lib/owner-notify-tokens.d.ts +49 -0
  126. package/dist/lib/owner-notify-tokens.js +214 -0
  127. package/dist/lib/owner-notify.d.ts +75 -0
  128. package/dist/lib/owner-notify.js +144 -0
  129. package/dist/lib/recordings/config.d.ts +11 -0
  130. package/dist/lib/recordings/config.js +54 -0
  131. package/dist/lib/recordings/identity.d.ts +12 -0
  132. package/dist/lib/recordings/identity.js +57 -0
  133. package/dist/lib/recordings/ledger.d.ts +16 -0
  134. package/dist/lib/recordings/ledger.js +141 -0
  135. package/dist/lib/recordings/model.d.ts +29 -0
  136. package/dist/lib/recordings/model.js +28 -0
  137. package/dist/lib/recordings/pipeline.d.ts +44 -0
  138. package/dist/lib/recordings/pipeline.js +272 -0
  139. package/dist/lib/recordings/process.d.ts +17 -0
  140. package/dist/lib/recordings/process.js +94 -0
  141. package/dist/lib/recordings/service.d.ts +15 -0
  142. package/dist/lib/recordings/service.js +45 -0
  143. package/dist/lib/recordings/settle.d.ts +21 -0
  144. package/dist/lib/recordings/settle.js +92 -0
  145. package/dist/lib/recordings/transcode.d.ts +13 -0
  146. package/dist/lib/recordings/transcode.js +44 -0
  147. package/dist/lib/reminders.d.ts +0 -1
  148. package/dist/lib/reminders.js +1 -1
  149. package/dist/lib/reserved-stores.d.ts +3 -0
  150. package/dist/lib/reserved-stores.js +13 -0
  151. package/dist/lib/routine-notify-owner.d.ts +3 -23
  152. package/dist/lib/routine-notify-owner.js +26 -107
  153. package/dist/lib/rush-api.d.ts +1 -0
  154. package/dist/lib/rush-api.js +1 -0
  155. package/dist/lib/session/active.d.ts +18 -2
  156. package/dist/lib/session/active.js +47 -37
  157. package/dist/lib/session/cloud.js +18 -45
  158. package/dist/lib/session/db.d.ts +2 -0
  159. package/dist/lib/session/db.js +13 -4
  160. package/dist/lib/session/glance-files.d.ts +4 -3
  161. package/dist/lib/session/glance-files.js +31 -0
  162. package/dist/lib/session/inject-target.js +12 -2
  163. package/dist/lib/session/pid-registry.d.ts +2 -0
  164. package/dist/lib/session/pid-registry.js +6 -2
  165. package/dist/lib/session/presentation.d.ts +21 -0
  166. package/dist/lib/session/presentation.js +198 -0
  167. package/dist/lib/session/projection.js +9 -2
  168. package/dist/lib/sqlite.d.ts +3 -1
  169. package/dist/lib/sqlite.js +7 -3
  170. package/dist/lib/standalone-tools.js +1 -1
  171. package/dist/lib/startup/command-registry.js +9 -4
  172. package/dist/lib/state.d.ts +2 -2
  173. package/dist/lib/state.js +3 -5
  174. package/dist/lib/terminal/inject.js +1 -1
  175. package/dist/lib/testdata/owner-notify-api.d.ts +36 -0
  176. package/dist/lib/testdata/owner-notify-api.js +102 -0
  177. package/dist/lib/trash.d.ts +14 -0
  178. package/dist/lib/trash.js +75 -0
  179. package/dist/lib/types.d.ts +0 -34
  180. package/package.json +1 -1
  181. package/dist/commands/feedback.d.ts +0 -2
  182. package/dist/commands/feedback.js +0 -68
  183. package/dist/commands/humans.d.ts +0 -2
  184. package/dist/commands/humans.js +0 -83
  185. package/dist/commands/modes.d.ts +0 -2
  186. package/dist/commands/modes.js +0 -134
  187. package/dist/commands/reminders.d.ts +0 -2
  188. package/dist/commands/reminders.js +0 -49
  189. package/dist/lib/channels/owner-forward.d.ts +0 -25
  190. package/dist/lib/channels/owner-forward.js +0 -78
  191. package/dist/lib/channels/owner-sink.d.ts +0 -10
  192. package/dist/lib/channels/owner-sink.js +0 -26
  193. package/dist/lib/humans.d.ts +0 -12
  194. package/dist/lib/humans.js +0 -64
@@ -0,0 +1,198 @@
1
+ import * as fs from 'fs';
2
+ import chalk from 'chalk';
3
+ import ora from 'ora';
4
+ import { computeSummaryStats, filterEvents, inferSessionState, linearIssueUrl, linkUrl, parseRoleList, parseSession, renderConversationMarkdown, renderJson, renderSummary, renderSummaryHeader, sessionDisplayAgent, } from '@phnx-labs/sessions-cli/reader';
5
+ import { colorAgent } from '../agents.js';
6
+ import { renderMarkdown } from '../markdown.js';
7
+ import { redactSecrets } from '../redact.js';
8
+ import { readArchivedSessionPreview, readSessionContent } from './db.js';
9
+ import { formatRelativeTime } from './relative-time.js';
10
+ import { sessionHeadline } from './title.js';
11
+ export function signalBadges(s) {
12
+ const parts = [];
13
+ if (s.awaitingReason === 'plan_review')
14
+ parts.push(chalk.yellow('plan'));
15
+ else if (s.awaitingReason === 'question')
16
+ parts.push(chalk.yellow('ask'));
17
+ else if (s.awaitingReason === 'permission')
18
+ parts.push(chalk.yellow('perm'));
19
+ if (s.ticket) {
20
+ const url = linearIssueUrl(s.ticket.id);
21
+ parts.push(chalk.cyan(url ? linkUrl(url, s.ticket.id) : s.ticket.id));
22
+ }
23
+ if (s.pr) {
24
+ const label = `PR#${s.pr.number ?? '?'}`;
25
+ parts.push(chalk.blue(s.pr.url ? linkUrl(s.pr.url, label) : label));
26
+ }
27
+ if (s.worktree)
28
+ parts.push(chalk.magenta(`wt:${s.worktree.slug}`));
29
+ return parts.join(' ');
30
+ }
31
+ export function metaSignals(s) {
32
+ return {
33
+ pr: s.prUrl ? { url: s.prUrl, number: s.prNumber } : undefined,
34
+ worktree: s.worktreeSlug ? { path: s.cwd ?? '', slug: s.worktreeSlug } : undefined,
35
+ ticket: s.ticketId ? { id: s.ticketId } : undefined,
36
+ };
37
+ }
38
+ export function buildFilterOptions(options) {
39
+ const opts = {};
40
+ if (options.include)
41
+ opts.include = parseRoleList(options.include, '--include');
42
+ if (options.exclude)
43
+ opts.exclude = parseRoleList(options.exclude, '--exclude');
44
+ if (opts.include && opts.exclude) {
45
+ throw new Error('--include and --exclude are mutually exclusive');
46
+ }
47
+ const parseCount = (raw, flag) => {
48
+ const n = Number(raw);
49
+ if (!Number.isFinite(n) || !Number.isInteger(n) || n <= 0) {
50
+ throw new Error(`${flag} expects a positive integer, got "${raw}"`);
51
+ }
52
+ return n;
53
+ };
54
+ if (options.first !== undefined)
55
+ opts.first = parseCount(options.first, '--first');
56
+ if (options.last !== undefined)
57
+ opts.last = parseCount(options.last, '--last');
58
+ if (opts.first !== undefined && opts.last !== undefined) {
59
+ throw new Error('--first and --last are mutually exclusive');
60
+ }
61
+ return opts;
62
+ }
63
+ export function hasAnyFilter(opts) {
64
+ return !!(opts.include?.length || opts.exclude?.length || opts.first !== undefined || opts.last !== undefined);
65
+ }
66
+ export function resolveViewMode(options, filters) {
67
+ if (options.markdown)
68
+ return 'markdown';
69
+ if (options.json)
70
+ return 'json';
71
+ if (hasAnyFilter(filters))
72
+ return 'markdown';
73
+ return 'summary';
74
+ }
75
+ export async function renderSessionLog(session, mode = 'summary') {
76
+ await renderSession(session, mode, {});
77
+ }
78
+ export async function renderSessionLogJson(session) {
79
+ await renderSession(session, 'json', {});
80
+ }
81
+ function renderArchivedSession(session, mode, options = {}) {
82
+ const redact = (text) => options.redact !== false ? redactSecrets(text) : text;
83
+ const content = redact((readSessionContent(session.id) ?? '').trim());
84
+ const digestRaw = readArchivedSessionPreview(session.id);
85
+ const digest = digestRaw
86
+ ? { ...digestRaw, lastAssistant: redact(digestRaw.lastAssistant ?? '') }
87
+ : undefined;
88
+ if (mode === 'json') {
89
+ console.log(JSON.stringify({
90
+ session: {
91
+ ...session,
92
+ topic: session.topic != null ? redact(session.topic) : session.topic,
93
+ label: session.label != null ? redact(session.label) : session.label,
94
+ plan: session.plan != null ? redact(session.plan) : session.plan,
95
+ archived: true,
96
+ },
97
+ archived: true,
98
+ userContent: content,
99
+ preview: digest ?? null,
100
+ }, null, 2));
101
+ return;
102
+ }
103
+ const shown = sessionDisplayAgent(session);
104
+ const agentColor = colorAgent(shown);
105
+ const absTime = formatAbsoluteTime(session.timestamp);
106
+ const title = sessionHeadline(session);
107
+ console.log('');
108
+ if (title)
109
+ console.log(chalk.bold.white(title));
110
+ console.log(agentColor(shown) +
111
+ (session.version ? chalk.yellow(` ${session.version}`) : '') +
112
+ (session.project ? chalk.cyan(` ${session.project}`) : '') +
113
+ chalk.gray(` ${absTime} (${formatRelativeTime(session.timestamp)})`) +
114
+ (session.account ? chalk.gray(` · ${session.account}`) : ''));
115
+ console.log(chalk.yellow('archived — transcript file removed; user turns served from the local DB'));
116
+ console.log(chalk.gray('─'.repeat(60)));
117
+ console.log(chalk.cyan('User:'));
118
+ console.log(content);
119
+ if (digest?.lastAssistant?.trim()) {
120
+ console.log('');
121
+ console.log(chalk.magenta('Last assistant:'));
122
+ console.log(digest.lastAssistant.trim());
123
+ }
124
+ }
125
+ export async function renderSession(session, mode, filters, options = {}) {
126
+ const { hydrateSessionTranscript } = await import('./discover.js');
127
+ session = await hydrateSessionTranscript(session);
128
+ const realPath = session.filePath.split('#')[0];
129
+ if (!fs.existsSync(realPath)) {
130
+ const archivedContent = readSessionContent(session.id);
131
+ if (archivedContent && archivedContent.trim() !== '') {
132
+ renderArchivedSession(session, mode, options);
133
+ return;
134
+ }
135
+ process.exitCode = 1;
136
+ console.log(chalk.yellow('Session transcript is unavailable after checking its recorded home and the session index.'));
137
+ console.log(chalk.gray(`Path: ${session.filePath}`));
138
+ if (session.version)
139
+ console.log(chalk.gray(`Version: ${sessionDisplayAgent(session)} ${session.version}`));
140
+ if (session.project)
141
+ console.log(chalk.gray(`Project: ${session.project}`));
142
+ if (session.account)
143
+ console.log(chalk.gray(`Account: ${session.account}`));
144
+ console.log(chalk.gray(`Time: ${session.timestamp}`));
145
+ return;
146
+ }
147
+ const spinner = ora(`Parsing ${sessionDisplayAgent(session)} session...`).start();
148
+ const parsedEvents = parseSession(session.filePath, session.agent);
149
+ spinner.stop();
150
+ let events = filterEvents(parsedEvents, filters);
151
+ const shown = sessionDisplayAgent(session);
152
+ const agentColor = colorAgent(shown);
153
+ console.log('');
154
+ if (mode === 'summary') {
155
+ const stats = computeSummaryStats(events);
156
+ const modelStr = stats.models.length > 0 ? chalk.yellow(` ${stats.models.join(', ')}`) : '';
157
+ const branchStr = session.gitBranch ? chalk.gray(` (${session.gitBranch})`) : '';
158
+ const absTime = formatAbsoluteTime(session.timestamp);
159
+ const title = sessionHeadline(session);
160
+ if (title) {
161
+ const badges = signalBadges(metaSignals(session));
162
+ console.log(chalk.bold.white(title) + (badges ? ' ' + badges : ''));
163
+ }
164
+ console.log(agentColor(shown) +
165
+ (session.version ? chalk.yellow(` ${session.version}`) : '') +
166
+ modelStr +
167
+ (session.project ? chalk.cyan(` ${session.project}`) + branchStr : branchStr) +
168
+ chalk.gray(` ${absTime} (${formatRelativeTime(session.timestamp)})`) +
169
+ (session.account ? chalk.gray(` · ${session.account}`) : ''));
170
+ const statsLine = renderSummaryHeader(stats);
171
+ if (statsLine)
172
+ console.log(chalk.gray(statsLine));
173
+ console.log(chalk.gray('─'.repeat(60)));
174
+ process.stdout.write(renderSummary(events, session.cwd));
175
+ return;
176
+ }
177
+ if (mode === 'markdown') {
178
+ console.log(agentColor(shown) +
179
+ (session.version ? chalk.yellow(` ${session.version}`) : '') +
180
+ (session.project ? chalk.cyan(` ${session.project}`) : '') +
181
+ chalk.gray(` ${formatRelativeTime(session.timestamp)}`) +
182
+ (session.account ? chalk.gray(` (${session.account})`) : ''));
183
+ console.log(chalk.gray('─'.repeat(60)));
184
+ process.stdout.write(renderMarkdown(renderConversationMarkdown(events, { redact: options.redact !== false })));
185
+ return;
186
+ }
187
+ const todos = inferSessionState(parsedEvents, { cwd: session.cwd }).todos;
188
+ process.stdout.write(renderJson(events, todos ? { ...session, todos } : session, { redact: options.redact !== false }));
189
+ }
190
+ function formatAbsoluteTime(isoTimestamp) {
191
+ const d = new Date(isoTimestamp);
192
+ if (isNaN(d.getTime()))
193
+ return isoTimestamp;
194
+ const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
195
+ const hh = String(d.getHours()).padStart(2, '0');
196
+ const mm = String(d.getMinutes()).padStart(2, '0');
197
+ return `${months[d.getMonth()]} ${d.getDate()} ${hh}:${mm}`;
198
+ }
@@ -63,8 +63,15 @@ export class SessionProjection {
63
63
  continue;
64
64
  selected.set(`${candidate.scope}\0${chosen.rowKey}`, rowKey);
65
65
  const observerTerminals = observations.filter(item => !item.row.previous && (item.row.terminalId || item.row.viewingIn || item.row.provenance?.reply))
66
- .map(({ scope: device, row }) => ({ device, terminalId: row.terminalId, launchId: row.launchId, viewingIn: row.viewingIn, provenance: row.provenance }))
67
- .sort((a, b) => a.device.localeCompare(b.device) || (a.terminalId ?? '').localeCompare(b.terminalId ?? ''));
66
+ .map(({ scope: device, row }) => ({ device, terminalId: row.terminalId, launchId: row.launchId, viewingIn: row.viewingIn, provenance: row.provenance }));
67
+ const origin = chosen.originTerminal;
68
+ if (!chosen.previous && origin && normalizeHost(origin.device) !== owner) {
69
+ const device = normalizeHost(origin.device);
70
+ if (!observerTerminals.some(item => item.device === device && item.terminalId === origin.terminalId)) {
71
+ observerTerminals.push({ device, terminalId: origin.terminalId, launchId: chosen.launchId, viewingIn: null });
72
+ }
73
+ }
74
+ observerTerminals.sort((a, b) => a.device.localeCompare(b.device) || (a.terminalId ?? '').localeCompare(b.terminalId ?? ''));
68
75
  next.set(rowKey, {
69
76
  ...chosen, rowKey, sourceDevice: owner, machine: owner,
70
77
  observerTerminals,
@@ -16,7 +16,9 @@ declare class StatementImpl<_T = unknown> {
16
16
  }
17
17
  declare class Database {
18
18
  private readonly inner;
19
- constructor(filename: string);
19
+ constructor(filename: string, options?: {
20
+ readOnly?: boolean;
21
+ });
20
22
  prepare<T = unknown>(sql: string): StatementImpl<T>;
21
23
  exec(sql: string): void;
22
24
  pragma(stmt: string): void;
@@ -29,7 +29,11 @@ const sqliteMod = isBun
29
29
  : loadNodeSqlite();
30
30
  const NativeDatabase = sqliteMod.Database
31
31
  ?? sqliteMod.DatabaseSync;
32
- const NATIVE_ARGS = isBun ? [{ strict: true }] : [];
32
+ function nativeOptions(readOnly) {
33
+ if (isBun)
34
+ return readOnly ? { strict: true, readonly: true } : { strict: true };
35
+ return readOnly ? { readOnly: true } : {};
36
+ }
33
37
  function bindArgs(params) {
34
38
  if (params.length === 1 &&
35
39
  params[0] !== null &&
@@ -57,8 +61,8 @@ class StatementImpl {
57
61
  }
58
62
  class Database {
59
63
  inner;
60
- constructor(filename) {
61
- this.inner = new NativeDatabase(filename, ...NATIVE_ARGS);
64
+ constructor(filename, options = {}) {
65
+ this.inner = new NativeDatabase(filename, nativeOptions(options.readOnly === true));
62
66
  }
63
67
  prepare(sql) {
64
68
  return new StatementImpl(this.inner.prepare(sql));
@@ -4,7 +4,7 @@ import { SECRETS_CLI_PACKAGE, SECRETS_CLI_VERSION } from './secrets-cli.js';
4
4
  export const STANDALONE_TOOLS = ['sessions', 'browser', 'secrets', 'computer', 'term'];
5
5
  export const STANDALONE_TOOL_PINS = {
6
6
  sessions: { tool: 'sessions', pkg: '@phnx-labs/sessions-cli', floor: '0.5.0' },
7
- browser: { tool: 'browser', pkg: '@phnx-labs/browser-cli', floor: '0.1.15' },
7
+ browser: { tool: 'browser', pkg: '@phnx-labs/browser-cli', floor: '0.1.16' },
8
8
  secrets: { tool: 'secrets', pkg: SECRETS_CLI_PACKAGE, floor: SECRETS_CLI_VERSION },
9
9
  computer: { tool: 'computer', pkg: '@phnx-labs/computer-cli', floor: '0.1.5' },
10
10
  term: { tool: 'term', pkg: '@phnx-labs/term-cli', floor: '0.1.0' },
@@ -1,16 +1,16 @@
1
1
  const LOADED_COMMAND_NAMES = [
2
- 'accounts', 'auth', 'view', 'inspect', 'feedback', 'commands', 'hooks', 'skills', 'rules', 'memory',
2
+ 'accounts', 'auth', 'view', 'inspect', 'commands', 'hooks', 'skills', 'rules', 'memory',
3
3
  'permissions', 'mcp', 'clis', 'subagents', 'plugins', 'workflows', 'add', 'use',
4
4
  'remove', 'rm', 'purge', 'update', 'prune', 'import', 'registry', 'search', 'install', 'packages',
5
5
  'routines', 'projects', 'run', '_callback', 'open', 'fork', 'config',
6
- 'models', 'modes', 'trash', 'restore', 'doctor',
6
+ 'models', 'trash', 'doctor',
7
7
  'route', 'routes', 'harness', 'harnesses', 'secrets', 'menubar', 'sync',
8
- 'refresh-rules', 'factory', 'insights', 'trace', 'reminders',
8
+ 'refresh-rules', 'factory', 'insights', 'trace',
9
9
  'tmux', 'watchdog', 'browser', 'computer', 'logs', 'events',
10
10
  'ssh', 'devices', 'fleet', 'repos', 'repo', 'setup', 'uninstall', 'upgrade', 'sessions',
11
11
  'teams', 'cloud', 'message', 'ps', 'send', 'feed',
12
12
  'mailboxes', 'mailbox', 'webhooks',
13
- 'humans', 'daemon', 'traces',
13
+ 'daemon', 'traces', 'recordings',
14
14
  ];
15
15
  const INLINE_COMMAND_NAMES = [
16
16
  'perms', 'exec', 'jobs', 'cron', 'check', 'resources', 'hq', '_internal',
@@ -51,6 +51,11 @@ export const RETIRED_TOP_LEVEL_COMMANDS = new Set([
51
51
  'beta',
52
52
  'perf',
53
53
  'list',
54
+ 'humans',
55
+ 'reminders',
56
+ 'modes',
57
+ 'feedback',
58
+ 'restore',
54
59
  ]);
55
60
  export function isKnownTopLevelCommand(name) {
56
61
  return KNOWN_TOP_LEVEL_COMMANDS.has(name);
@@ -1,5 +1,4 @@
1
1
  import type { Meta } from './types.js';
2
- export declare function getHumansFilePath(): string;
3
2
  export declare const META_HEADER = "# agents-cli metadata\n# Auto-generated - do not edit manually\n# https://github.com/phnx-labs/agi-cli\n# yaml-language-server: $schema=https://raw.githubusercontent.com/phnx-labs/agi-cli/main/cli/schema/agents-yaml.schema.json\n\n";
4
3
  export declare function getAgentsDir(): string;
5
4
  export declare function getSystemAgentsDir(): string;
@@ -115,6 +114,7 @@ export declare function getTrashHooksDir(): string;
115
114
  export declare function getTrashPluginsDir(): string;
116
115
  export declare function getTrashSubagentsDir(): string;
117
116
  export declare function getTrashWorkflowsDir(): string;
117
+ export declare function getTrashFilesDir(): string;
118
118
  export declare function getExtraRepoDir(alias: string): string;
119
119
  export declare function resolveExtraRepoDir(alias: string, config?: {
120
120
  path?: string;
@@ -129,7 +129,7 @@ export declare function createDefaultMeta(): Meta;
129
129
  export declare function getDeviceMetaPath(): string;
130
130
  export declare function getVersionResourcesPath(): string;
131
131
  export declare function withMetaLock<T>(fn: () => T): T;
132
- export declare function commitCentralConfig(userDir: string): boolean;
132
+ export declare function commitCentralConfig(userDir: string, rel?: string, message?: string): boolean;
133
133
  export declare function hasStaleMetaHeader(): boolean;
134
134
  export declare function readTopLevelUserMeta(): Record<string, unknown> | null;
135
135
  export declare function writeMetaUnlocked(meta: Meta): boolean;
package/dist/lib/state.js CHANGED
@@ -22,8 +22,6 @@ const SYSTEM_AGENTS_DIR = path.join(USER_AGENTS_DIR, '.system');
22
22
  const LEGACY_SYSTEM_AGENTS_DIR = path.join(HOME, '.agents-system');
23
23
  const META_FILE = path.join(USER_AGENTS_DIR, 'agents.yaml');
24
24
  const SYSTEM_META_FILE = path.join(SYSTEM_AGENTS_DIR, 'agents.yaml');
25
- const HUMANS_FILE = path.join(USER_AGENTS_DIR, 'humans.yaml');
26
- export function getHumansFilePath() { return process.env.AGENTS_HUMANS_FILE ?? HUMANS_FILE; }
27
25
  const SYSTEM_COMMANDS_DIR = path.join(SYSTEM_AGENTS_DIR, 'commands');
28
26
  const SYSTEM_HOOKS_DIR = path.join(SYSTEM_AGENTS_DIR, 'hooks');
29
27
  const SYSTEM_SKILLS_DIR = path.join(SYSTEM_AGENTS_DIR, 'skills');
@@ -349,6 +347,7 @@ export function getTrashHooksDir() { return path.join(TRASH_DIR, 'hooks'); }
349
347
  export function getTrashPluginsDir() { return path.join(TRASH_DIR, 'plugins'); }
350
348
  export function getTrashSubagentsDir() { return path.join(TRASH_DIR, 'subagents'); }
351
349
  export function getTrashWorkflowsDir() { return path.join(TRASH_DIR, 'workflows'); }
350
+ export function getTrashFilesDir() { return path.join(TRASH_DIR, 'files'); }
352
351
  export function getExtraRepoDir(alias) {
353
352
  return path.join(HOME, `.agents-${alias}`);
354
353
  }
@@ -478,8 +477,7 @@ function writeIfChanged(filePath, content) {
478
477
  atomicWriteFileSync(filePath, content);
479
478
  return true;
480
479
  }
481
- export function commitCentralConfig(userDir) {
482
- const rel = 'agents.yaml';
480
+ export function commitCentralConfig(userDir, rel = 'agents.yaml', message = 'chore(config): update agents.yaml') {
483
481
  try {
484
482
  execFileSync('git', ['-C', userDir, 'rev-parse', '--is-inside-work-tree'], { stdio: 'ignore' });
485
483
  }
@@ -494,7 +492,7 @@ export function commitCentralConfig(userDir) {
494
492
  }
495
493
  catch { }
496
494
  execFileSync('git', ['-C', userDir, '-c', 'commit.gpgsign=false', 'commit', '--no-verify',
497
- '-m', 'chore(config): update agents.yaml', '--', rel], { stdio: 'ignore' });
495
+ '-m', message, '--', rel], { stdio: 'ignore' });
498
496
  return true;
499
497
  }
500
498
  catch {
@@ -18,7 +18,7 @@ export function tmuxSendKeysArgv(pane, keys, opts = {}) {
18
18
  argv.push('send-keys', '-t', pane);
19
19
  if (opts.literal)
20
20
  argv.push('-l');
21
- argv.push(keys);
21
+ argv.push('--', keys);
22
22
  return argv;
23
23
  }
24
24
  export function tmuxInjectSpecs(target, text, o) {
@@ -0,0 +1,36 @@
1
+ export interface RecordedRequest {
2
+ method: string;
3
+ path: string;
4
+ bearer: string | null;
5
+ body: unknown;
6
+ }
7
+ interface DeviceToken {
8
+ id: string;
9
+ token: string;
10
+ device: string;
11
+ createdAt: string;
12
+ }
13
+ interface Delivery {
14
+ id: string;
15
+ address: string;
16
+ body: string;
17
+ createdAt: string;
18
+ claimedBy?: string;
19
+ result?: {
20
+ ok: boolean;
21
+ error?: string;
22
+ };
23
+ }
24
+ export interface OwnerNotifyApi {
25
+ url: string;
26
+ requests: RecordedRequest[];
27
+ sessionToken: string;
28
+ deviceTokens: DeviceToken[];
29
+ deliveries: Delivery[];
30
+ dedupKeys: string[];
31
+ imessageAddress: string | null;
32
+ preferencesStatus: number;
33
+ close(): Promise<void>;
34
+ }
35
+ export declare function startOwnerNotifyApi(sessionToken?: string): Promise<OwnerNotifyApi>;
36
+ export {};
@@ -0,0 +1,102 @@
1
+ import * as http from 'node:http';
2
+ const EVENTS = new Set(['needs_you', 'completed', 'failed', 'spend_threshold', 'message']);
3
+ function send(res, status, body) {
4
+ res.writeHead(status, { 'Content-Type': 'application/json' });
5
+ res.end(body === undefined ? undefined : JSON.stringify(body));
6
+ }
7
+ export async function startOwnerNotifyApi(sessionToken = 'phx-session-token') {
8
+ let seq = 0;
9
+ const seen = new Set();
10
+ const api = {
11
+ url: '',
12
+ requests: [],
13
+ sessionToken,
14
+ deviceTokens: [],
15
+ deliveries: [],
16
+ dedupKeys: [],
17
+ imessageAddress: '+15555550100',
18
+ preferencesStatus: 200,
19
+ close: async () => { },
20
+ };
21
+ const server = http.createServer((req, res) => {
22
+ let raw = '';
23
+ req.on('data', (chunk) => { raw += chunk.toString('utf-8'); });
24
+ req.on('end', () => {
25
+ const url = new URL(req.url ?? '/', 'http://fixture');
26
+ const bearer = req.headers.authorization?.replace(/^Bearer /, '') ?? null;
27
+ const body = raw ? JSON.parse(raw) : null;
28
+ api.requests.push({ method: req.method ?? '', path: url.pathname, bearer, body });
29
+ const device = api.deviceTokens.find((t) => t.token === bearer);
30
+ const isSession = bearer === api.sessionToken;
31
+ if (!isSession && !device)
32
+ return send(res, 401, { error: 'Unauthorized', code: 'UNAUTHORIZED' });
33
+ const tokenId = url.pathname.match(/^\/api\/v1\/auth\/tokens\/([^/]+)$/);
34
+ if (tokenId && req.method === 'DELETE') {
35
+ if (!isSession)
36
+ return send(res, 403, { error: 'device_token_forbidden' });
37
+ const before = api.deviceTokens.length;
38
+ api.deviceTokens = api.deviceTokens.filter((t) => t.id !== decodeURIComponent(tokenId[1]));
39
+ return send(res, before === api.deviceTokens.length ? 404 : 204);
40
+ }
41
+ if (url.pathname === '/api/v1/auth/tokens') {
42
+ if (!isSession)
43
+ return send(res, 403, { error: 'device_token_forbidden' });
44
+ if (req.method === 'GET') {
45
+ return send(res, 200, api.deviceTokens.map((t) => ({ id: t.id, kind: 'device', device: t.device, scopes: ['notify'], createdAt: t.createdAt })));
46
+ }
47
+ const name = String(body?.device);
48
+ api.deviceTokens = api.deviceTokens.filter((t) => t.device !== name);
49
+ const minted = { id: `tok-${++seq}`, token: `phx-device-${name}-${seq}`, device: name, createdAt: new Date().toISOString() };
50
+ api.deviceTokens.push(minted);
51
+ return send(res, 201, { id: minted.id, token: minted.token, kind: 'device', device: name, scopes: ['notify'], createdAt: minted.createdAt });
52
+ }
53
+ if (url.pathname === '/me/preferences' && req.method === 'PUT') {
54
+ if (!isSession)
55
+ return send(res, 403, { error: 'device_token_scope', code: 'DEVICE_TOKEN_SCOPE' });
56
+ return api.preferencesStatus === 200
57
+ ? send(res, 200, { ok: true })
58
+ : send(res, api.preferencesStatus, { error: 'unknown event: message', code: 'INVALID_EVENT' });
59
+ }
60
+ if (url.pathname === '/me/notifications' && req.method === 'POST') {
61
+ if (!body || !EVENTS.has(String(body.event)) || typeof body.title !== 'string' || typeof body.body !== 'string' || typeof body.dedupKey !== 'string') {
62
+ return send(res, 400, { error: 'invalid notification', code: 'INVALID_BODY' });
63
+ }
64
+ api.dedupKeys.push(body.dedupKey);
65
+ const key = `${body.event}\0${body.dedupKey}`;
66
+ if (seen.has(key))
67
+ return send(res, 200, { dispatchId: null, delivered: [], queued: [], skipped: [], suppressed: 'duplicate' });
68
+ seen.add(key);
69
+ const queued = api.imessageAddress ? ['imessage'] : [];
70
+ if (api.imessageAddress) {
71
+ api.deliveries.push({ id: `dlv-${++seq}`, address: api.imessageAddress, body: String(body.body), createdAt: new Date().toISOString() });
72
+ }
73
+ return send(res, 200, {
74
+ dispatchId: `dsp-${++seq}`,
75
+ delivered: ['slack'],
76
+ queued,
77
+ skipped: api.imessageAddress ? [] : [{ channel: 'imessage', reason: 'no imessage destination' }],
78
+ suppressed: null,
79
+ });
80
+ }
81
+ if (url.pathname === '/me/device-deliveries/claim' && req.method === 'POST') {
82
+ const claimed = api.deliveries.filter((d) => !d.claimedBy && !d.result).slice(0, Number(body?.limit ?? 10));
83
+ for (const d of claimed)
84
+ d.claimedBy = String(body?.device);
85
+ return send(res, 200, { deliveries: claimed.map((d) => ({ id: d.id, channel: 'imessage', address: d.address, body: d.body, createdAt: d.createdAt })) });
86
+ }
87
+ const result = url.pathname.match(/^\/me\/device-deliveries\/([^/]+)\/result$/);
88
+ if (result && req.method === 'POST') {
89
+ const delivery = api.deliveries.find((d) => d.id === decodeURIComponent(result[1]));
90
+ if (!delivery)
91
+ return send(res, 404, { error: 'not found' });
92
+ delivery.result = { ok: Boolean(body?.ok), ...(typeof body?.error === 'string' ? { error: body.error } : {}) };
93
+ return send(res, 204);
94
+ }
95
+ return send(res, 404, { error: `no route ${req.method} ${url.pathname}` });
96
+ });
97
+ });
98
+ await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
99
+ api.url = `http://127.0.0.1:${server.address().port}`;
100
+ api.close = () => new Promise((resolve) => server.close(() => resolve()));
101
+ return api;
102
+ }
@@ -0,0 +1,14 @@
1
+ export interface TrashItem {
2
+ path: string;
3
+ trashedAtMs: number;
4
+ }
5
+ export declare function listTrashItems(root?: string): TrashItem[];
6
+ export declare function emptyTrash(opts?: {
7
+ olderThanMs?: number;
8
+ now?: number;
9
+ root?: string;
10
+ }): {
11
+ removed: TrashItem[];
12
+ kept: number;
13
+ };
14
+ export declare function moveFileToTrash(file: string): string;
@@ -0,0 +1,75 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import { getTrashDir, getTrashFilesDir } from './state.js';
4
+ const ITEM_DEPTH = {
5
+ versions: 3,
6
+ homes: 3,
7
+ hooks: 4,
8
+ commands: 3,
9
+ skills: 3,
10
+ subagents: 3,
11
+ plugins: 1,
12
+ workflows: 1,
13
+ files: 1,
14
+ };
15
+ function childrenAtDepth(dir, depth) {
16
+ if (depth === 0)
17
+ return [dir];
18
+ let names;
19
+ try {
20
+ if (!fs.statSync(dir).isDirectory())
21
+ return [];
22
+ names = fs.readdirSync(dir);
23
+ }
24
+ catch {
25
+ return [];
26
+ }
27
+ return names.flatMap((name) => childrenAtDepth(path.join(dir, name), depth - 1));
28
+ }
29
+ export function listTrashItems(root = getTrashDir()) {
30
+ let names;
31
+ try {
32
+ names = fs.readdirSync(root);
33
+ }
34
+ catch {
35
+ return [];
36
+ }
37
+ return names
38
+ .flatMap((name) => childrenAtDepth(path.join(root, name), ITEM_DEPTH[name] ?? 0))
39
+ .map((item) => ({ path: item, trashedAtMs: fs.lstatSync(item).ctimeMs }));
40
+ }
41
+ function removeEmptyParents(item, root) {
42
+ for (let dir = path.dirname(item); dir !== root && dir.startsWith(root); dir = path.dirname(dir)) {
43
+ try {
44
+ if (fs.readdirSync(dir).length > 0)
45
+ return;
46
+ fs.rmdirSync(dir);
47
+ }
48
+ catch {
49
+ return;
50
+ }
51
+ }
52
+ }
53
+ export function emptyTrash(opts = {}) {
54
+ const root = opts.root ?? getTrashDir();
55
+ const now = opts.now ?? Date.now();
56
+ const items = listTrashItems(root);
57
+ const removed = [];
58
+ for (const item of items) {
59
+ if (opts.olderThanMs !== undefined && now - item.trashedAtMs < opts.olderThanMs)
60
+ continue;
61
+ fs.rmSync(item.path, { recursive: true, force: true });
62
+ removeEmptyParents(item.path, root);
63
+ removed.push(item);
64
+ }
65
+ return { removed, kept: items.length - removed.length };
66
+ }
67
+ export function moveFileToTrash(file) {
68
+ const dir = getTrashFilesDir();
69
+ fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
70
+ const ext = path.extname(file);
71
+ const stamp = new Date().toISOString().replace(/[:.]/g, '-');
72
+ const dest = path.join(dir, `${path.basename(file, ext)}-${stamp}${ext}`);
73
+ fs.renameSync(file, dest);
74
+ return dest;
75
+ }
@@ -527,43 +527,9 @@ export interface Meta {
527
527
  templateHash?: string;
528
528
  };
529
529
  notify?: {
530
- owner?: {
531
- channel: string;
532
- to: string;
533
- };
534
530
  transports?: Record<string, string>;
535
531
  };
536
532
  }
537
- export interface HumanChannel {
538
- id: string;
539
- transport: string;
540
- to?: string;
541
- watch?: boolean;
542
- cmd?: string;
543
- creds?: string;
544
- intrusive?: boolean;
545
- }
546
- export interface HumanPolicy {
547
- low?: string[];
548
- normal?: string[];
549
- critical?: string[];
550
- }
551
- export interface HumanOwner {
552
- name?: string;
553
- timezone?: string;
554
- quiet_hours?: string;
555
- default_severity?: 'low' | 'normal' | 'critical';
556
- notify?: {
557
- channel: string;
558
- to: string;
559
- };
560
- channels?: HumanChannel[];
561
- policy?: HumanPolicy;
562
- }
563
- export interface HumansConfig {
564
- version: 1;
565
- owner?: HumanOwner;
566
- }
567
533
  export interface HostEntry {
568
534
  source: 'ssh-config' | 'inline';
569
535
  address?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phnx-labs/agents-cli",
3
- "version": "1.22.122",
3
+ "version": "1.22.123",
4
4
  "description": "One CLI for all your AI coding agents - versions, config, cloud dispatch, sessions, and teams (now with first-class Grok Build CLI support)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,2 +0,0 @@
1
- import type { Command } from 'commander';
2
- export declare function registerFeedbackCommand(program: Command): void;