@phnx-labs/agents-cli 1.22.41 → 1.22.43

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 (253) hide show
  1. package/CHANGELOG.md +86 -0
  2. package/README.md +10 -4
  3. package/dist/bin/agents +0 -0
  4. package/dist/bootstrap.js +25 -7
  5. package/dist/cli/command-registry.d.ts +2 -3
  6. package/dist/cli/command-registry.js +4 -8
  7. package/dist/commands/accounts.d.ts +29 -0
  8. package/dist/commands/accounts.js +220 -29
  9. package/dist/commands/alias.d.ts +7 -4
  10. package/dist/commands/alias.js +34 -9
  11. package/dist/commands/auth.d.ts +9 -0
  12. package/dist/commands/auth.js +108 -0
  13. package/dist/commands/browser-sessions-picker.js +42 -62
  14. package/dist/commands/browser.js +30 -38
  15. package/dist/commands/computer-actions.d.ts +1 -1
  16. package/dist/commands/computer-actions.js +1 -1
  17. package/dist/commands/computer-sessions-picker.js +32 -55
  18. package/dist/commands/computer.d.ts +1 -1
  19. package/dist/commands/computer.js +22 -8
  20. package/dist/commands/daemon.js +1 -1
  21. package/dist/commands/doctor.d.ts +5 -3
  22. package/dist/commands/doctor.js +23 -8
  23. package/dist/commands/exec.js +3 -2
  24. package/dist/commands/feed.js +2 -31
  25. package/dist/commands/harness.js +3 -3
  26. package/dist/commands/hooks.js +1 -1
  27. package/dist/commands/import.js +1 -1
  28. package/dist/commands/insights.js +163 -85
  29. package/dist/commands/inspect.js +2 -2
  30. package/dist/commands/mine.js +1 -1
  31. package/dist/commands/monitors.js +1 -1
  32. package/dist/commands/org.d.ts +6 -0
  33. package/dist/commands/org.js +175 -0
  34. package/dist/commands/packages.js +1 -1
  35. package/dist/commands/profiles.js +2 -2
  36. package/dist/commands/prune.js +1 -1
  37. package/dist/commands/routines.js +44 -26
  38. package/dist/commands/run-account-picker.d.ts +19 -0
  39. package/dist/commands/run-account-picker.js +81 -0
  40. package/dist/commands/sessions-picker-factory.d.ts +40 -0
  41. package/dist/commands/sessions-picker-factory.js +67 -0
  42. package/dist/commands/sessions-picker.js +124 -122
  43. package/dist/commands/setup-browser.js +4 -4
  44. package/dist/commands/setup-mine.js +1 -1
  45. package/dist/commands/setup-preferences.js +2 -2
  46. package/dist/commands/setup.js +10 -4
  47. package/dist/commands/snapshot.d.ts +1 -1
  48. package/dist/commands/snapshot.js +4 -4
  49. package/dist/commands/status.d.ts +4 -2
  50. package/dist/commands/status.js +10 -7
  51. package/dist/commands/sync.d.ts +1 -0
  52. package/dist/commands/sync.js +30 -3
  53. package/dist/commands/versions.js +1 -1
  54. package/dist/commands/view.js +7 -1
  55. package/dist/commands/webhook.js +1 -1
  56. package/dist/lib/account-capabilities.d.ts +10 -0
  57. package/dist/lib/account-capabilities.js +34 -0
  58. package/dist/lib/accounting/rotate.d.ts +5 -3
  59. package/dist/lib/accounting/rotate.js +36 -7
  60. package/dist/lib/accounting/usage.d.ts +18 -4
  61. package/dist/lib/accounting/usage.js +138 -27
  62. package/dist/lib/agent-spec/agents.d.ts +584 -0
  63. package/dist/lib/agent-spec/agents.js +3127 -0
  64. package/dist/lib/agent-spec/provider.js +1 -1
  65. package/dist/lib/agents.d.ts +2 -584
  66. package/dist/lib/agents.js +2 -3127
  67. package/dist/lib/browser/drivers/local.d.ts +8 -2
  68. package/dist/lib/browser/drivers/local.js +8 -2
  69. package/dist/lib/browser/drivers/ssh.d.ts +8 -2
  70. package/dist/lib/browser/drivers/ssh.js +10 -4
  71. package/dist/lib/browser/hygiene.d.ts +1 -1
  72. package/dist/lib/browser/hygiene.js +5 -1
  73. package/dist/lib/browser/profiles.d.ts +74 -1
  74. package/dist/lib/browser/profiles.js +114 -5
  75. package/dist/lib/browser/runtime-state.d.ts +11 -5
  76. package/dist/lib/browser/runtime-state.js +13 -9
  77. package/dist/lib/browser/service.d.ts +68 -30
  78. package/dist/lib/browser/service.js +305 -194
  79. package/dist/lib/browser/types.d.ts +95 -3
  80. package/dist/lib/browser/types.js +51 -0
  81. package/dist/lib/catchup.js +1 -1
  82. package/dist/lib/cloud/rush.d.ts +0 -15
  83. package/dist/lib/cloud/rush.js +0 -35
  84. package/dist/lib/computer/actions.d.ts +1 -1
  85. package/dist/lib/computer/actions.js +1 -1
  86. package/dist/lib/{computer-rpc.js → computer/computer-rpc.js} +5 -5
  87. package/dist/lib/computer/dispatch.d.ts +1 -1
  88. package/dist/lib/computer/download.d.ts +1 -1
  89. package/dist/lib/computer/download.js +3 -3
  90. package/dist/lib/{ssh-tunnel.d.ts → computer/ssh-tunnel.d.ts} +1 -1
  91. package/dist/lib/{ssh-tunnel.js → computer/ssh-tunnel.js} +12 -12
  92. package/dist/lib/crabbox/runtimes.d.ts +6 -2
  93. package/dist/lib/crabbox/runtimes.js +21 -5
  94. package/dist/lib/daemon/daemon.js +87 -59
  95. package/dist/lib/{runner.d.ts → daemon/runner.d.ts} +28 -11
  96. package/dist/lib/{runner.js → daemon/runner.js} +143 -123
  97. package/dist/lib/devices/doctor-findings.d.ts +1 -1
  98. package/dist/lib/devices/doctor-findings.js +4 -4
  99. package/dist/lib/devices/fleet-inventory.js +1 -1
  100. package/dist/lib/devices/harness-inventory.js +1 -1
  101. package/dist/lib/devices/health-report.js +1 -1
  102. package/dist/lib/devices/registry.js +4 -22
  103. package/dist/lib/doctor-diff.d.ts +1 -1
  104. package/dist/lib/doctor-diff.js +1 -1
  105. package/dist/lib/drift-sync.d.ts +1 -1
  106. package/dist/lib/drift-sync.js +2 -2
  107. package/dist/lib/drift.d.ts +1 -1
  108. package/dist/lib/drift.js +1 -1
  109. package/dist/lib/entitlement.d.ts +31 -0
  110. package/dist/lib/entitlement.js +137 -0
  111. package/dist/lib/exec.js +52 -205
  112. package/dist/lib/feed/feed.js +2 -8
  113. package/dist/lib/format.d.ts +9 -0
  114. package/dist/lib/format.js +16 -0
  115. package/dist/lib/fs-atomic.d.ts +7 -0
  116. package/dist/lib/fs-atomic.js +9 -0
  117. package/dist/lib/github/pr-mergeable.d.ts +49 -0
  118. package/dist/lib/github/pr-mergeable.js +157 -0
  119. package/dist/lib/github/pr-verdict.d.ts +67 -0
  120. package/dist/lib/github/pr-verdict.js +72 -0
  121. package/dist/lib/harness/adapter.d.ts +161 -0
  122. package/dist/lib/harness/adapter.js +47 -0
  123. package/dist/lib/harness/adapters/claude.d.ts +2 -0
  124. package/dist/lib/harness/adapters/claude.js +110 -0
  125. package/dist/lib/harness/adapters/codex.d.ts +2 -0
  126. package/dist/lib/harness/adapters/codex.js +83 -0
  127. package/dist/lib/harness/adapters/copilot.d.ts +2 -0
  128. package/dist/lib/harness/adapters/copilot.js +23 -0
  129. package/dist/lib/harness/adapters/cursor.d.ts +2 -0
  130. package/dist/lib/harness/adapters/cursor.js +38 -0
  131. package/dist/lib/harness/adapters/droid.d.ts +2 -0
  132. package/dist/lib/harness/adapters/droid.js +17 -0
  133. package/dist/lib/harness/adapters/grok.d.ts +2 -0
  134. package/dist/lib/harness/adapters/grok.js +14 -0
  135. package/dist/lib/harness/adapters/kimi.d.ts +2 -0
  136. package/dist/lib/harness/adapters/kimi.js +49 -0
  137. package/dist/lib/harness/adapters/muse.d.ts +2 -0
  138. package/dist/lib/harness/adapters/muse.js +44 -0
  139. package/dist/lib/harness/adapters/opencode.d.ts +2 -0
  140. package/dist/lib/harness/adapters/opencode.js +14 -0
  141. package/dist/lib/harness/exec-config-version.d.ts +8 -0
  142. package/dist/lib/harness/exec-config-version.js +22 -0
  143. package/dist/lib/harness/index.d.ts +1 -0
  144. package/dist/lib/harness/index.js +34 -0
  145. package/dist/lib/{hooks.d.ts → hooks/install.d.ts} +1 -1
  146. package/dist/lib/{hooks.js → hooks/install.js} +11 -11
  147. package/dist/lib/hosts/passthrough.d.ts +10 -0
  148. package/dist/lib/hosts/passthrough.js +28 -6
  149. package/dist/lib/hosts/session-index.js +1 -1
  150. package/dist/lib/import.js +1 -1
  151. package/dist/lib/installations/index.d.ts +4 -4
  152. package/dist/lib/installations/index.js +3 -4
  153. package/dist/lib/installations/migrate.js +6 -6
  154. package/dist/lib/{shims.d.ts → installations/shims.d.ts} +2 -2
  155. package/dist/lib/{shims.js → installations/shims.js} +13 -115
  156. package/dist/lib/installations/store.d.ts +141 -3
  157. package/dist/lib/installations/store.js +475 -5
  158. package/dist/lib/installations/versions.d.ts +40 -125
  159. package/dist/lib/installations/versions.js +57 -462
  160. package/dist/lib/isolation-boundary-report.d.ts +1 -1
  161. package/dist/lib/isolation-boundary-report.js +1 -1
  162. package/dist/lib/mailbox-gc.js +2 -3
  163. package/dist/lib/menubar/MenubarHelper.app/Contents/CodeResources +0 -0
  164. package/dist/lib/menubar/MenubarHelper.app/Contents/MacOS/MenubarHelper +0 -0
  165. package/dist/lib/menubar/install-menubar.js +19 -8
  166. package/dist/lib/monitors/config.d.ts +2 -2
  167. package/dist/lib/monitors/config.js +3 -2
  168. package/dist/lib/monitors/dispatch.d.ts +1 -1
  169. package/dist/lib/monitors/dispatch.js +2 -2
  170. package/dist/lib/monitors/state.d.ts +1 -1
  171. package/dist/lib/origin-machine.d.ts +18 -0
  172. package/dist/lib/origin-machine.js +34 -0
  173. package/dist/lib/perf/db.js +1 -1
  174. package/dist/lib/perf/spool.js +1 -1
  175. package/dist/lib/plugins/plugins.js +1 -1
  176. package/dist/lib/plugins/skills.js +1 -1
  177. package/dist/lib/prix-account.d.ts +158 -0
  178. package/dist/lib/prix-account.js +214 -0
  179. package/dist/lib/profiles.d.ts +7 -0
  180. package/dist/lib/profiles.js +26 -1
  181. package/dist/lib/project-key.js +2 -2
  182. package/dist/lib/project-launch.js +1 -1
  183. package/dist/lib/refresh.js +2 -2
  184. package/dist/lib/resource-inventory.d.ts +1 -1
  185. package/dist/lib/resource-inventory.js +1 -1
  186. package/dist/lib/rules/rules.js +1 -1
  187. package/dist/lib/sandbox.d.ts +24 -0
  188. package/dist/lib/sandbox.js +101 -0
  189. package/dist/lib/scheduling/routines.d.ts +18 -9
  190. package/dist/lib/scheduling/routines.js +17 -9
  191. package/dist/lib/secrets/Agents CLI.app/Contents/CodeResources +0 -0
  192. package/dist/lib/secrets/Agents CLI.app/Contents/MacOS/Agents CLI +0 -0
  193. package/dist/lib/secrets/agent.js +9 -1
  194. package/dist/lib/secrets/index.js +1 -1
  195. package/dist/lib/secrets/list-filter.js +1 -1
  196. package/dist/lib/self-heal/checks/hook-runtime.js +1 -1
  197. package/dist/lib/self-heal/checks/path.js +1 -1
  198. package/dist/lib/self-heal/checks/shadowing.js +1 -1
  199. package/dist/lib/self-heal/checks/shims.js +1 -1
  200. package/dist/lib/service-manifest.d.ts +20 -0
  201. package/dist/lib/service-manifest.js +34 -0
  202. package/dist/lib/session/cloud.js +1 -1
  203. package/dist/lib/session/db.js +1 -1
  204. package/dist/lib/session/discover.d.ts +39 -0
  205. package/dist/lib/session/discover.js +3 -3
  206. package/dist/lib/session/fork.js +1 -1
  207. package/dist/lib/session/live-metadata.js +1 -1
  208. package/dist/lib/session/origin-machine.d.ts +1 -18
  209. package/dist/lib/session/origin-machine.js +4 -34
  210. package/dist/lib/session/parse.js +24 -42
  211. package/dist/lib/session/recovery.js +1 -1
  212. package/dist/lib/session/relative-time.d.ts +1 -44
  213. package/dist/lib/session/relative-time.js +4 -120
  214. package/dist/lib/session/remote-list.js +1 -1
  215. package/dist/lib/session/remote.js +2 -2
  216. package/dist/lib/session/short-id.d.ts +1 -17
  217. package/dist/lib/session/short-id.js +4 -20
  218. package/dist/lib/session/width.d.ts +1 -29
  219. package/dist/lib/session/width.js +4 -101
  220. package/dist/lib/snapshot.d.ts +2 -2
  221. package/dist/lib/snapshot.js +1 -1
  222. package/dist/lib/staleness/prune.d.ts +1 -1
  223. package/dist/lib/staleness/prune.js +1 -1
  224. package/dist/lib/staleness/writers/hooks.js +1 -1
  225. package/dist/lib/startup/command-registry.d.ts +4 -1
  226. package/dist/lib/startup/command-registry.js +12 -5
  227. package/dist/lib/teams/agents.js +2 -19
  228. package/dist/lib/teams/parsers.js +20 -26
  229. package/dist/lib/teams/placement-probe.js +1 -1
  230. package/dist/lib/teams/registry.js +2 -21
  231. package/dist/lib/teams/scheduler.js +1 -1
  232. package/dist/lib/text/relative-time.d.ts +44 -0
  233. package/dist/lib/text/relative-time.js +120 -0
  234. package/dist/lib/text/short-id.d.ts +17 -0
  235. package/dist/lib/text/short-id.js +20 -0
  236. package/dist/lib/text/width.d.ts +29 -0
  237. package/dist/lib/text/width.js +101 -0
  238. package/dist/lib/triggers/handlers.d.ts +7 -0
  239. package/dist/lib/triggers/handlers.js +9 -1
  240. package/dist/lib/triggers/webhook.d.ts +1 -0
  241. package/dist/lib/triggers/webhook.js +3 -2
  242. package/dist/lib/uninstall.js +1 -1
  243. package/dist/lib/version.d.ts +9 -2
  244. package/dist/lib/version.js +11 -9
  245. package/dist/lib/view-types.d.ts +4 -0
  246. package/package.json +1 -1
  247. package/dist/commands/tickets.d.ts +0 -2
  248. package/dist/commands/tickets.js +0 -43
  249. package/dist/lib/observe-aliases.d.ts +0 -30
  250. package/dist/lib/observe-aliases.js +0 -38
  251. package/dist/lib/tickets/list.d.ts +0 -53
  252. package/dist/lib/tickets/list.js +0 -153
  253. /package/dist/lib/{computer-rpc.d.ts → computer/computer-rpc.d.ts} +0 -0
@@ -19,7 +19,7 @@ import * as fs from 'fs';
19
19
  import * as path from 'path';
20
20
  import { upsertSession } from './db.js';
21
21
  import { recordRunName } from './run-names.js';
22
- import { deriveShortId } from './short-id.js';
22
+ import { deriveShortId } from '../text/short-id.js';
23
23
  /** Agents that `fork` can branch today (see the module doc for why). */
24
24
  export const FORKABLE_AGENTS = ['claude'];
25
25
  /** Whether a session's agent can be forked by {@link forkSession}. */
@@ -16,7 +16,7 @@
16
16
  // state the live registry already computed. When the transcript IS on disk, the
17
17
  // synthesized row carries its path, so the downstream `buildPreview` renders the
18
18
  // real digest; otherwise it renders the header + a "not indexed here" note.
19
- import { deriveShortId } from './short-id.js';
19
+ import { deriveShortId } from '../text/short-id.js';
20
20
  import { isSessionTrackedAgent } from './types.js';
21
21
  /**
22
22
  * Reshape one live `ActiveSession` into a `SessionMeta` candidate for the id
@@ -1,18 +1 @@
1
- /**
2
- * Resolve which machine a session transcript originated on.
3
- *
4
- * Cross-machine sync mirrors a remote transcript to
5
- * `backups/<agent>/<machine>/<subdir>/…`. Every other transcript is a live-home
6
- * file on this box, so the origin is the local machine id.
7
- *
8
- * Kept in a leaf module (no session/db imports) so both discovery and the
9
- * sessions DB upsert path can stamp `machine` without circular deps.
10
- */
11
- /** Local machine id, cached for the process lifetime. */
12
- export declare function localMachineId(): string;
13
- /**
14
- * The machine a discovered session originated on.
15
- * When the path sits under the agent's backups root, the first segment below it
16
- * is the origin machine id; otherwise it's the local machine.
17
- */
18
- export declare function machineForSessionFile(filePath: string, agent: string): string;
1
+ export * from '../origin-machine.js';
@@ -1,34 +1,4 @@
1
- /**
2
- * Resolve which machine a session transcript originated on.
3
- *
4
- * Cross-machine sync mirrors a remote transcript to
5
- * `backups/<agent>/<machine>/<subdir>/…`. Every other transcript is a live-home
6
- * file on this box, so the origin is the local machine id.
7
- *
8
- * Kept in a leaf module (no session/db imports) so both discovery and the
9
- * sessions DB upsert path can stamp `machine` without circular deps.
10
- */
11
- import * as path from 'path';
12
- import { getHistoryDir } from '../state.js';
13
- import { machineId } from '../machine-id.js';
14
- let _localMachineId;
15
- /** Local machine id, cached for the process lifetime. */
16
- export function localMachineId() {
17
- return (_localMachineId ??= machineId());
18
- }
19
- /**
20
- * The machine a discovered session originated on.
21
- * When the path sits under the agent's backups root, the first segment below it
22
- * is the origin machine id; otherwise it's the local machine.
23
- */
24
- export function machineForSessionFile(filePath, agent) {
25
- if (!filePath)
26
- return localMachineId();
27
- const base = path.join(getHistoryDir(), 'backups', agent) + path.sep;
28
- if (filePath.startsWith(base)) {
29
- const seg = filePath.slice(base.length).split(path.sep)[0];
30
- if (seg)
31
- return seg;
32
- }
33
- return localMachineId();
34
- }
1
+ // Moved to ../origin-machine.ts (move 1 of the core-module refactor — see
2
+ // .agents/artifacts/2026-08-20/plan-*.md). Kept as a re-export shim so
3
+ // existing importers don't break.
4
+ export * from '../origin-machine.js';
@@ -117,53 +117,35 @@ function truncateNormalizedToolOutput(output, maxChars) {
117
117
  return output;
118
118
  return `${output.slice(0, maxChars)}\n\n[Output truncated: ${output.length - maxChars} characters omitted.]`;
119
119
  }
120
+ /**
121
+ * Registry-dispatch table: each `SessionAgentId` to its offline transcript
122
+ * parser. Replaces the per-harness `switch` — the harness axis of Move 3. Kept
123
+ * as its own table (not on the HarnessAdapter registry) because its id domain is
124
+ * `SessionAgentId`: `rush` is a session agent with no `AgentId`, and the offline
125
+ * transcript reader is a deliberately separate concern from live team events.
126
+ * The `Record` is total, so a new session harness must add an entry here.
127
+ */
128
+ const TRANSCRIPT_PARSERS = {
129
+ claude: (filePath, opts) => parseClaude(filePath, opts),
130
+ codex: (filePath) => parseCodex(filePath),
131
+ gemini: (filePath) => parseGemini(filePath),
132
+ antigravity: (filePath) => parseAntigravity(filePath),
133
+ opencode: (filePath) => parseOpenCode(filePath),
134
+ grok: (filePath) => parseGrok(filePath),
135
+ rush: (filePath) => parseRush(filePath),
136
+ openclaw: () => [], // OpenClaw sessions don't have parseable files yet
137
+ hermes: (filePath) => parseHermes(filePath),
138
+ kimi: (filePath) => parseKimi(filePath),
139
+ droid: (filePath) => parseDroid(filePath),
140
+ cursor: (filePath) => parseCursor(filePath),
141
+ muse: (filePath) => parseMuse(filePath),
142
+ };
120
143
  export function parseSession(filePath, agent, opts = {}) {
121
144
  const detected = agent || detectAgent(filePath);
122
145
  if (!detected) {
123
146
  throw new Error(`Cannot detect agent type from path: ${filePath}`);
124
147
  }
125
- let events;
126
- switch (detected) {
127
- case 'claude':
128
- events = parseClaude(filePath, opts);
129
- break;
130
- case 'codex':
131
- events = parseCodex(filePath);
132
- break;
133
- case 'gemini':
134
- events = parseGemini(filePath);
135
- break;
136
- case 'antigravity':
137
- events = parseAntigravity(filePath);
138
- break;
139
- case 'opencode':
140
- events = parseOpenCode(filePath);
141
- break;
142
- case 'grok':
143
- events = parseGrok(filePath);
144
- break;
145
- case 'rush':
146
- events = parseRush(filePath);
147
- break;
148
- case 'openclaw':
149
- events = [];
150
- break; // OpenClaw sessions don't have parseable files yet
151
- case 'hermes':
152
- events = parseHermes(filePath);
153
- break;
154
- case 'kimi':
155
- events = parseKimi(filePath);
156
- break;
157
- case 'droid':
158
- events = parseDroid(filePath);
159
- break;
160
- case 'cursor':
161
- events = parseCursor(filePath);
162
- break;
163
- case 'muse':
164
- events = parseMuse(filePath);
165
- break;
166
- }
148
+ const events = TRANSCRIPT_PARSERS[detected](filePath, opts);
167
149
  // Chokepoint: every string field that originated in an untrusted session
168
150
  // file gets stripped of terminal escapes here, so renderers downstream can
169
151
  // safely splat values into chalk/console output. Same pass flags
@@ -5,7 +5,7 @@ import { isSelfHost } from '../devices/self-host.js';
5
5
  import { nativeResume } from '../exec.js';
6
6
  import { machineId, normalizeHost } from '../machine-id.js';
7
7
  import { collectRunCandidates, formatNoHealthyAccountError, pickBalancedCandidate, readinessFromCandidate, } from '../accounting/rotate.js';
8
- import { getVersionHomePath } from '../installations/versions.js';
8
+ import { getVersionHomePath } from '../installations/store.js';
9
9
  export class SessionRecoveryError extends Error {
10
10
  constructor(message) {
11
11
  super(message);
@@ -1,44 +1 @@
1
- /**
2
- * Human-readable "time since" formatting for session timestamps. Lives here (not
3
- * inline in `sessions.ts`) so both the session list renderer and the remote
4
- * offline-cache banner (`remote.ts`) share one formatter — `sessions.ts` imports
5
- * `remote.ts`, so a back-import would cycle.
6
- */
7
- export declare function formatRelativeTime(isoTimestamp: string): string;
8
- /**
9
- * Compact age — `now`, `45m`, `3h`, `2d`, then the calendar date. This is the
10
- * *creation* half of a session's time cell: it renders right next to the long
11
- * last-activity label, and one row can afford one long form, not two.
12
- */
13
- export declare function formatCompactAge(isoTimestamp: string): string;
14
- /** The two time fields a session listing shows for one row. */
15
- export interface SessionAgeParts {
16
- /**
17
- * Compact age of the session's creation, set only when the session ran long
18
- * enough (>= a minute) for it to say something `last` does not.
19
- */
20
- created?: string;
21
- /** Last-activity label — the long relative form the listing sorts by. */
22
- last: string;
23
- }
24
- /**
25
- * Split a session's timestamps into the two fields a listing renders: when it
26
- * was created and when it was last active. One last-activity label answers
27
- * neither "is this the old session I'm looking for" nor "how long did it run" —
28
- * a session touched an hour ago may have started last week.
29
- */
30
- export declare function sessionAgeParts(createdIso: string, lastActivityIso?: string): SessionAgeParts;
31
- /**
32
- * Parse a time filter string (relative like '7d' or an ISO timestamp) into epoch
33
- * milliseconds. Backs `--since` on `sessions`, `cost`, `teams`, and `output`, and
34
- * `--unused` on `secrets list`.
35
- *
36
- * It lives here, in a module with no imports, rather than in `discover.ts` where
37
- * it started: `discover.ts` loads `../sqlite.js`, so importing this one function
38
- * from there pulls `node:sqlite` into the caller's module graph and Node prints
39
- * `ExperimentalWarning: SQLite …` on stderr. That is invisible in a command that
40
- * already touches the session DB, and a broken contract in one that doesn't —
41
- * `monitors --json` asserts a clean stderr. `discover.ts` re-exports it, so
42
- * existing importers are unaffected.
43
- */
44
- export declare function parseTimeFilter(input: string): number;
1
+ export * from '../text/relative-time.js';
@@ -1,120 +1,4 @@
1
- /**
2
- * Human-readable "time since" formatting for session timestamps. Lives here (not
3
- * inline in `sessions.ts`) so both the session list renderer and the remote
4
- * offline-cache banner (`remote.ts`) share one formatter — `sessions.ts` imports
5
- * `remote.ts`, so a back-import would cycle.
6
- */
7
- const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
8
- /**
9
- * Calendar label for a timestamp older than the relative window. A 2-digit year
10
- * is appended outside the current year so "Jun 28" is never ambiguous across
11
- * years (e.g. "Jun 28 '25").
12
- */
13
- function calendarLabel(thenMs, nowMs) {
14
- const d = new Date(thenMs);
15
- const label = `${MONTHS[d.getMonth()]} ${d.getDate()}`;
16
- return d.getFullYear() === new Date(nowMs).getFullYear()
17
- ? label
18
- : `${label} '${String(d.getFullYear()).slice(-2)}`;
19
- }
20
- export function formatRelativeTime(isoTimestamp) {
21
- const now = Date.now();
22
- const then = new Date(isoTimestamp).getTime();
23
- if (isNaN(then))
24
- return isoTimestamp;
25
- const diffMs = now - then;
26
- const diffMin = Math.floor(diffMs / 60_000);
27
- const diffHrs = Math.floor(diffMs / 3_600_000);
28
- const diffDays = Math.floor(diffMs / 86_400_000);
29
- if (diffMin < 1)
30
- return 'just now';
31
- if (diffMin < 60)
32
- return `${diffMin} min ago`;
33
- if (diffHrs < 24)
34
- return `${diffHrs} hour${diffHrs === 1 ? '' : 's'} ago`;
35
- if (diffDays < 7)
36
- return `${diffDays} day${diffDays === 1 ? '' : 's'} ago`;
37
- // Older: show the date.
38
- return calendarLabel(then, now);
39
- }
40
- /**
41
- * Compact age — `now`, `45m`, `3h`, `2d`, then the calendar date. This is the
42
- * *creation* half of a session's time cell: it renders right next to the long
43
- * last-activity label, and one row can afford one long form, not two.
44
- */
45
- export function formatCompactAge(isoTimestamp) {
46
- const now = Date.now();
47
- const then = new Date(isoTimestamp).getTime();
48
- if (isNaN(then))
49
- return isoTimestamp;
50
- const diffMs = now - then;
51
- const diffMin = Math.floor(diffMs / 60_000);
52
- const diffHrs = Math.floor(diffMs / 3_600_000);
53
- const diffDays = Math.floor(diffMs / 86_400_000);
54
- if (diffMin < 1)
55
- return 'now';
56
- if (diffMin < 60)
57
- return `${diffMin}m`;
58
- if (diffHrs < 24)
59
- return `${diffHrs}h`;
60
- if (diffDays < 7)
61
- return `${diffDays}d`;
62
- return calendarLabel(then, now);
63
- }
64
- /**
65
- * Shortest creation→last-activity gap worth rendering as two fields. Below it
66
- * both halves name the same minute, so the row would carry a duplicate instead
67
- * of information.
68
- */
69
- const SPAN_MIN_MS = 60_000;
70
- /**
71
- * Split a session's timestamps into the two fields a listing renders: when it
72
- * was created and when it was last active. One last-activity label answers
73
- * neither "is this the old session I'm looking for" nor "how long did it run" —
74
- * a session touched an hour ago may have started last week.
75
- */
76
- export function sessionAgeParts(createdIso, lastActivityIso) {
77
- const lastIso = lastActivityIso ?? createdIso;
78
- const last = formatRelativeTime(lastIso);
79
- const createdMs = new Date(createdIso).getTime();
80
- const lastMs = new Date(lastIso).getTime();
81
- if (isNaN(createdMs) || isNaN(lastMs) || lastMs - createdMs < SPAN_MIN_MS)
82
- return { last };
83
- return { created: formatCompactAge(createdIso), last };
84
- }
85
- /**
86
- * Parse a time filter string (relative like '7d' or an ISO timestamp) into epoch
87
- * milliseconds. Backs `--since` on `sessions`, `cost`, `teams`, and `output`, and
88
- * `--unused` on `secrets list`.
89
- *
90
- * It lives here, in a module with no imports, rather than in `discover.ts` where
91
- * it started: `discover.ts` loads `../sqlite.js`, so importing this one function
92
- * from there pulls `node:sqlite` into the caller's module graph and Node prints
93
- * `ExperimentalWarning: SQLite …` on stderr. That is invisible in a command that
94
- * already touches the session DB, and a broken contract in one that doesn't —
95
- * `monitors --json` asserts a clean stderr. `discover.ts` re-exports it, so
96
- * existing importers are unaffected.
97
- */
98
- export function parseTimeFilter(input) {
99
- // Units: m=minute, h=hour, d=day, w=week, mo=month(30d), y=year(365d). `mo`
100
- // must precede the single-letter alternatives so "1mo" isn't read as "1m"+"o".
101
- const relativeMatch = input.match(/^(\d+)(mo|[mhdwy])$/i);
102
- if (relativeMatch) {
103
- const value = parseInt(relativeMatch[1], 10);
104
- const unit = relativeMatch[2].toLowerCase();
105
- if (unit === 'm')
106
- return Date.now() - value * 60_000;
107
- if (unit === 'h')
108
- return Date.now() - value * 3_600_000;
109
- if (unit === 'd')
110
- return Date.now() - value * 86_400_000;
111
- if (unit === 'w')
112
- return Date.now() - value * 7 * 86_400_000;
113
- if (unit === 'mo')
114
- return Date.now() - value * 30 * 86_400_000;
115
- if (unit === 'y')
116
- return Date.now() - value * 365 * 86_400_000;
117
- }
118
- const ts = new Date(input).getTime();
119
- return Number.isNaN(ts) ? 0 : ts;
120
- }
1
+ // Moved to ../text/relative-time.ts (move 1 of the core-module refactor — see
2
+ // .agents/artifacts/2026-08-20/plan-*.md). Kept as a re-export shim so
3
+ // existing importers don't break.
4
+ export * from '../text/relative-time.js';
@@ -23,7 +23,7 @@ import { remoteShellFor, buildWindowsAgentsCommand, stripClixml } from '../hosts
23
23
  import { gatherRemoteAgentsJson } from '../remote-agents-json.js';
24
24
  import { machineId, normalizeHost } from './sync/config.js';
25
25
  import { NO_FANOUT_ENV } from './remote-active.js';
26
- import { terminalWidth } from './width.js';
26
+ import { terminalWidth } from '../text/width.js';
27
27
  import { sanitizeForTerminal } from '../redact.js';
28
28
  import { mapBounded } from '../concurrency.js';
29
29
  import { TOOL_QUERY_MAX_CLAUSE_BYTES, TOOL_QUERY_MAX_CALL_ROWS, TOOL_QUERY_MAX_CLAUSES, TOOL_QUERY_MAX_RESULT_SESSIONS, TOOL_QUERY_MAX_SERIALIZED_BYTES, serializedToolSearchEnvelopeBytes, } from './tool-index.js';
@@ -32,8 +32,8 @@ import { SSH_OPTS, controlOpts, assertValidSshTarget } from '../ssh-exec.js';
32
32
  import { remoteShellFor, buildWindowsAgentsCommand } from '../hosts/remote-cmd.js';
33
33
  import { resolveRemoteOsSync } from '../hosts/remote-os.js';
34
34
  import { NO_FANOUT_ENV } from './remote-active.js';
35
- import { formatRelativeTime } from './relative-time.js';
36
- import { terminalWidth } from './width.js';
35
+ import { formatRelativeTime } from '../text/relative-time.js';
36
+ import { terminalWidth } from '../text/width.js';
37
37
  /**
38
38
  * POSIX single-quote a string for safe interpolation into a remote shell command.
39
39
  * Always wraps (unlike the bare-passthrough variant in `ssh-exec.ts`) — the
@@ -1,17 +1 @@
1
- /**
2
- * Canonical derivation of a session's 8-char `shortId`.
3
- *
4
- * Every session parser used to inline `id.slice(0, 8)` — some with a
5
- * `.replace(prefix, '')` strip first (`session_`, `api-`, `ses_`). That strip is
6
- * the bug: an id that is *only* its prefix (a bare `session_` directory, an id of
7
- * exactly `api-`) strips to `''`, and `''.slice(0, 8)` is still `''`. An empty
8
- * shortId then passes the `short_id TEXT NOT NULL` constraint (empty string is not
9
- * NULL) yet matches nothing in the `short_id LIKE ?` picker lookups — a silently
10
- * corrupt index row.
11
- *
12
- * This helper is the single source of truth: it strips the optional prefix, takes
13
- * the first 8 chars, and — the whole point — guarantees a NON-EMPTY result by
14
- * falling back to the unstripped id when the strip empties it, so a row always
15
- * stays addressable by its shortId.
16
- */
17
- export declare function deriveShortId(id: string, stripPrefix?: RegExp): string;
1
+ export * from '../text/short-id.js';
@@ -1,20 +1,4 @@
1
- /**
2
- * Canonical derivation of a session's 8-char `shortId`.
3
- *
4
- * Every session parser used to inline `id.slice(0, 8)` — some with a
5
- * `.replace(prefix, '')` strip first (`session_`, `api-`, `ses_`). That strip is
6
- * the bug: an id that is *only* its prefix (a bare `session_` directory, an id of
7
- * exactly `api-`) strips to `''`, and `''.slice(0, 8)` is still `''`. An empty
8
- * shortId then passes the `short_id TEXT NOT NULL` constraint (empty string is not
9
- * NULL) yet matches nothing in the `short_id LIKE ?` picker lookups — a silently
10
- * corrupt index row.
11
- *
12
- * This helper is the single source of truth: it strips the optional prefix, takes
13
- * the first 8 chars, and — the whole point — guarantees a NON-EMPTY result by
14
- * falling back to the unstripped id when the strip empties it, so a row always
15
- * stays addressable by its shortId.
16
- */
17
- export function deriveShortId(id, stripPrefix) {
18
- const stripped = stripPrefix ? id.replace(stripPrefix, '') : id;
19
- return stripped.slice(0, 8) || id.slice(0, 8) || id;
20
- }
1
+ // Moved to ../text/short-id.ts (move 1 of the core-module refactor — see
2
+ // .agents/artifacts/2026-08-20/plan-*.md). Kept as a re-export shim so
3
+ // existing importers don't break.
4
+ export * from '../text/short-id.js';
@@ -1,29 +1 @@
1
- /**
2
- * Terminal display-width helpers.
3
- *
4
- * `String.length` is the wrong ruler for a terminal: it over-counts ANSI colour
5
- * escapes (chalk output) and under-counts wide glyphs (CJK, emoji) which occupy
6
- * two cells. The result is the drifting, wrapping session-table line users see
7
- * under tmux and over `--device` SSH. Every renderer that sizes a session-table
8
- * cell measures and truncates through this module so alignment is computed once,
9
- * correctly, from the same source of truth.
10
- */
11
- /** Strip SGR colour + OSC-8 hyperlink escapes so width is measured on visible characters only. */
12
- export declare function stripAnsi(s: string): string;
13
- /** Visible display width of a string, ANSI-aware and wide-char-aware. */
14
- export declare function stringWidth(s: string): number;
15
- /**
16
- * Truncate to a target display width, appending '…' when shortened. Operates on
17
- * the visible (ANSI-stripped) string; callers colour the result afterwards so
18
- * the ellipsis is never inserted mid-escape.
19
- */
20
- export declare function truncateToWidth(s: string, max: number): string;
21
- /** Right-pad with spaces to a target display width. Never truncates. */
22
- export declare function padToWidth(s: string, width: number): string;
23
- /**
24
- * Effective terminal width. Reads `$COLUMNS` first so it survives tmux and
25
- * `--device` SSH (where `process.stdout.columns` is unset or wrong), falls back to
26
- * the TTY's reported width, then to `fallback`. Clamped to a sane band so a
27
- * bogus value can't produce a 0-wide or absurdly long table.
28
- */
29
- export declare function terminalWidth(fallback?: number): number;
1
+ export * from '../text/width.js';
@@ -1,101 +1,4 @@
1
- /**
2
- * Terminal display-width helpers.
3
- *
4
- * `String.length` is the wrong ruler for a terminal: it over-counts ANSI colour
5
- * escapes (chalk output) and under-counts wide glyphs (CJK, emoji) which occupy
6
- * two cells. The result is the drifting, wrapping session-table line users see
7
- * under tmux and over `--device` SSH. Every renderer that sizes a session-table
8
- * cell measures and truncates through this module so alignment is computed once,
9
- * correctly, from the same source of truth.
10
- */
11
- /** SGR colour sequences emitted by chalk (e.g. `\x1b[32m`). */
12
- const SGR_REGEX = /\x1b\[[0-9;]*m/g;
13
- /**
14
- * OSC-8 hyperlink sequences (`\x1b]8;;<url>\x1b\\` … `\x1b]8;;\x1b\\`, or with a
15
- * BEL `\x07` terminator) emitted by `osc8()` in render.ts for clickable
16
- * ticket/PR/path badges. These carry the URL, which is NOT visible — leaving it
17
- * in over-counts width and, worse, lets a truncation land *inside* the escape and
18
- * corrupt it. Stripping both the opener and closer leaves only the visible label
19
- * between them, so width is measured on what the user sees and `truncateToWidth`
20
- * can never cut a hyperlink in half.
21
- */
22
- const OSC8_REGEX = /\x1b\]8;[^;]*;.*?(?:\x1b\\|\x07)/g;
23
- /** Strip SGR colour + OSC-8 hyperlink escapes so width is measured on visible characters only. */
24
- export function stripAnsi(s) {
25
- return s.replace(OSC8_REGEX, '').replace(SGR_REGEX, '');
26
- }
27
- /**
28
- * Display cells for one code point: 0 for zero-width combining/ZWJ/variation
29
- * selectors, 2 for East-Asian-wide and emoji ranges, 1 otherwise. Compact and
30
- * dependency-free — covers the glyphs that actually show up in prompts/titles.
31
- */
32
- function charWidth(cp) {
33
- if (cp === 0)
34
- return 0;
35
- // Zero-width: combining marks, zero-width joiner, variation selectors.
36
- if ((cp >= 0x0300 && cp <= 0x036f) ||
37
- cp === 0x200b || cp === 0x200d ||
38
- (cp >= 0xfe00 && cp <= 0xfe0f))
39
- return 0;
40
- // Wide (2 cells): CJK, Hangul, fullwidth forms, emoji & pictographs.
41
- if ((cp >= 0x1100 && cp <= 0x115f) || // Hangul Jamo
42
- (cp >= 0x2e80 && cp <= 0xa4cf) || // CJK radicals … Yi
43
- (cp >= 0xac00 && cp <= 0xd7a3) || // Hangul syllables
44
- (cp >= 0xf900 && cp <= 0xfaff) || // CJK compatibility ideographs
45
- (cp >= 0xfe30 && cp <= 0xfe4f) || // CJK compatibility forms
46
- (cp >= 0xff00 && cp <= 0xff60) || // Fullwidth forms
47
- (cp >= 0xffe0 && cp <= 0xffe6) || // Fullwidth signs
48
- (cp >= 0x1f300 && cp <= 0x1faff) || // emoji & symbols
49
- (cp >= 0x20000 && cp <= 0x3fffd) // CJK Ext-B and beyond
50
- )
51
- return 2;
52
- return 1;
53
- }
54
- /** Visible display width of a string, ANSI-aware and wide-char-aware. */
55
- export function stringWidth(s) {
56
- const plain = stripAnsi(s);
57
- let w = 0;
58
- for (const ch of plain)
59
- w += charWidth(ch.codePointAt(0));
60
- return w;
61
- }
62
- /**
63
- * Truncate to a target display width, appending '…' when shortened. Operates on
64
- * the visible (ANSI-stripped) string; callers colour the result afterwards so
65
- * the ellipsis is never inserted mid-escape.
66
- */
67
- export function truncateToWidth(s, max) {
68
- if (max <= 0)
69
- return '';
70
- const plain = stripAnsi(s);
71
- if (stringWidth(plain) <= max)
72
- return plain;
73
- let w = 0;
74
- let out = '';
75
- for (const ch of plain) {
76
- const cw = charWidth(ch.codePointAt(0));
77
- if (w + cw > max - 1)
78
- break; // reserve one cell for the ellipsis
79
- out += ch;
80
- w += cw;
81
- }
82
- return out + '…';
83
- }
84
- /** Right-pad with spaces to a target display width. Never truncates. */
85
- export function padToWidth(s, width) {
86
- const pad = width - stringWidth(s);
87
- return pad > 0 ? s + ' '.repeat(pad) : s;
88
- }
89
- /**
90
- * Effective terminal width. Reads `$COLUMNS` first so it survives tmux and
91
- * `--device` SSH (where `process.stdout.columns` is unset or wrong), falls back to
92
- * the TTY's reported width, then to `fallback`. Clamped to a sane band so a
93
- * bogus value can't produce a 0-wide or absurdly long table.
94
- */
95
- export function terminalWidth(fallback = 100) {
96
- const env = Number.parseInt(process.env.COLUMNS ?? '', 10);
97
- const raw = Number.isFinite(env) && env > 0
98
- ? env
99
- : (process.stdout.columns || fallback);
100
- return Math.max(60, Math.min(200, raw));
101
- }
1
+ // Moved to ../text/width.ts (move 1 of the core-module refactor — see
2
+ // .agents/artifacts/2026-08-20/plan-*.md). Kept as a re-export shim so
3
+ // existing importers don't break.
4
+ export * from '../text/width.js';
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * That is N+2 process starts per poll tick. This module gathers the same
10
10
  * shapes in one invocation so poll count drops to 1 without redefining
11
- * `agents status` (which stays the UnifiedSyncStatus sync contract).
11
+ * `agents sync status` (which stays the UnifiedSyncStatus sync contract).
12
12
  *
13
13
  * Stores are not merged — inventory still comes from view, active rows from
14
14
  * sessions, blocks from feed. Only the reader is consolidated.
@@ -63,7 +63,7 @@ export interface FleetSnapshot {
63
63
  agents: FleetAgentCounts;
64
64
  /** Present when --with-feed. */
65
65
  feed?: SnapshotFeedSummary;
66
- /** Present when --with-sync (UnifiedSyncStatus; does not replace `agents status`). */
66
+ /** Present when --with-sync (UnifiedSyncStatus; does not replace `agents sync status`). */
67
67
  sync?: UnifiedSyncStatus;
68
68
  }
69
69
  export interface ComputeSnapshotOptions {
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * That is N+2 process starts per poll tick. This module gathers the same
10
10
  * shapes in one invocation so poll count drops to 1 without redefining
11
- * `agents status` (which stays the UnifiedSyncStatus sync contract).
11
+ * `agents sync status` (which stays the UnifiedSyncStatus sync contract).
12
12
  *
13
13
  * Stores are not merged — inventory still comes from view, active rows from
14
14
  * sessions, blocks from feed. Only the reader is consolidated.
@@ -42,7 +42,7 @@ import type { SyncManifest } from './types.js';
42
42
  * - hooks — a version-home hook script is coupled to a settings.json /
43
43
  * hooks.json REGISTRATION. Pruning the last hook to zero would delete the
44
44
  * script but must also GC its registration in the same pass, and that lands
45
- * in `src/lib/hooks.ts` — a Windows-portable-path surface the CI windows leg
45
+ * in `src/lib/hooks/install.ts` — a Windows-portable-path surface the CI windows leg
46
46
  * gates on. Split to RUSH-2456 so this PR stays Linux-only-green; hook FILES
47
47
  * are still reconciled by the in-write orphan sweep (versions.ts, gated on
48
48
  * `hooksToSync > 0`).
@@ -5,7 +5,7 @@ import { getWriter, getDetector } from './registry.js';
5
5
  * - hooks — a version-home hook script is coupled to a settings.json /
6
6
  * hooks.json REGISTRATION. Pruning the last hook to zero would delete the
7
7
  * script but must also GC its registration in the same pass, and that lands
8
- * in `src/lib/hooks.ts` — a Windows-portable-path surface the CI windows leg
8
+ * in `src/lib/hooks/install.ts` — a Windows-portable-path surface the CI windows leg
9
9
  * gates on. Split to RUSH-2456 so this PR stays Linux-only-green; hook FILES
10
10
  * are still reconciled by the in-write orphan sweep (versions.ts, gated on
11
11
  * `hooksToSync > 0`).
@@ -9,7 +9,7 @@ import { agentConfigDirName } from '../../agents.js';
9
9
  import * as path from 'path';
10
10
  import { capableAgents } from '../../capabilities.js';
11
11
  import { safeJoin } from '../../paths.js';
12
- import { registerHooksToSettings } from '../../hooks.js';
12
+ import { registerHooksToSettings } from '../../hooks/install.js';
13
13
  import { resolveHookSource } from './sources.js';
14
14
  import { lazyAgentMap } from './lazy-map.js';
15
15
  function removePath(target) {
@@ -21,7 +21,10 @@ export declare const KNOWN_TOP_LEVEL_COMMANDS: ReadonlySet<string>;
21
21
  * under `agents artifacts share` (RUSH-2580). login/logout/budget/bench/mine/
22
22
  * cost/output/profiles/snapshot/cp/resume/roster moved under nested homes
23
23
  * (cli-surface-consolidate). `timeline` was removed as a duplicated surface —
24
- * use `agents feed --filter updates` (RUSH-2692).
24
+ * use `agents feed --filter updates` (RUSH-2692). `status` moved under
25
+ * `agents sync status` (RUSH-2864). `tickets` was removed — use `linear`
26
+ * (linear-cli) (RUSH-2932). `alias` moved under `agents setup alias` (RUSH-2965).
27
+ * `inbox` was a pure alias of `agents feed` (RUSH-2984).
25
28
  */
26
29
  export declare const RETIRED_TOP_LEVEL_COMMANDS: ReadonlySet<string>;
27
30
  export declare function isKnownTopLevelCommand(name: string): boolean;