@phnx-labs/agents-cli 1.23.48 → 1.23.50

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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.23.50
4
+
5
+ - **A launch killed in its first second no longer locks the harness for ten minutes (PHNX-4610).** `withFileLockAsync` took its lock through proper-lockfile's async `lock()`, which registers the exit cleanup only after `mkdir` and two more fs callbacks, and its async `unlock()` drops that registration before the `rmdir`. A SIGTERM or SIGHUP landing in either gap left `<target>.lock` behind, and every later caller read it as held until it went stale. For the installation lock that is ten minutes, longer than the three minutes `agents __launch-lease` waits, so the next launch of that harness failed with `Could not acquire lock … Lock file is already being held` and `could not safely coordinate this launch with a possibly in-progress update`. Rush Cloud hit it when Stop landed during the shim's launch: the follow-up waited six minutes and failed. The async variant now takes and releases the lock through the same sync API `withFileLock` uses, so registration and removal never straddle an event-loop turn; the retry wait between attempts stays asynchronous. Measured with 12 children cycling the lock and killed mid-cycle: 8 of 12 left the lock before, 0 of 12 after. A SIGKILL still leaves it, as before. Source: `cli/src/lib/fs-atomic.ts`, `cli/src/lib/fs-atomic.test.ts`.
6
+
7
+ ## 1.23.49
8
+
9
+ - **You hear the seat count before the names.** The daemon now notifies you once when the seat count differs from your active accounts at low confidence ("claude: about 5 of 8 accounts cover your usage"), saying when it will name which ones. Before, it stayed silent until every account had 3 weeks of readings. Source: `cli/src/lib/accounting/advise.ts`.
10
+
3
11
  ## 1.23.48
4
12
 
5
13
  - **`agents accounts usage --json` reports the rules it applied.** A new `thresholds` object carries the target share, the coverage needed before a seat count (`minCoverage`, `minMeasured`), the weeks each account needs before accounts are named (`weeksNeeded`) and the limit percent, so the AGI Menu Accounts tab can show why it recommends what it does. Source: `cli/src/lib/accounting/advise.ts`.
@@ -217,7 +217,25 @@ export function renderAccountsAdvice(result) {
217
217
  return lines;
218
218
  }
219
219
  export function accountsAdviceNotification(result, lastNotified, now = new Date()) {
220
- const { harness, advice, coverage, peakDemand } = result;
220
+ const { harness, advice, coverage, peakDemand, thresholds } = result;
221
+ const week = new Date(weekStartUtc(now.getTime())).toISOString().slice(0, 10);
222
+ const demand = peakDemand === null ? '' : ` Peak weekly demand was ${peakDemand.toFixed(2)} account-weeks.`;
223
+ if (advice.confidence === 'low') {
224
+ if (advice.keep === coverage.total)
225
+ return null;
226
+ const fingerprint = [harness, 'low', advice.keep, coverage.total].join('|');
227
+ if (fingerprint === lastNotified)
228
+ return null;
229
+ const title = advice.keep < coverage.total
230
+ ? `${harness}: about ${advice.keep} of ${coverage.total} accounts cover your usage`
231
+ : `${harness}: you may need ${advice.keep} accounts, ${coverage.total} are active`;
232
+ return {
233
+ fingerprint,
234
+ title,
235
+ body: `Which accounts to ${advice.keep < coverage.total ? 'pause' : 'resume'} is named once each has readings in ${thresholds.weeksNeeded} of the last ${result.weeks.length} weeks.${demand} Details: agents accounts usage ${harness}`,
236
+ dedupKey: `accounts-advice:${harness}:${week}:low:${advice.keep}`,
237
+ };
238
+ }
221
239
  if (advice.confidence !== 'high')
222
240
  return null;
223
241
  if (advice.pause.length === 0 && advice.resume.length === 0 && advice.add === 0)
@@ -225,8 +243,6 @@ export function accountsAdviceNotification(result, lastNotified, now = new Date(
225
243
  const fingerprint = [harness, advice.keep, [...advice.pause].sort().join(','), [...advice.resume].sort().join(','), advice.add].join('|');
226
244
  if (fingerprint === lastNotified)
227
245
  return null;
228
- const week = new Date(weekStartUtc(now.getTime())).toISOString().slice(0, 10);
229
- const demand = peakDemand === null ? '' : ` Peak weekly demand was ${peakDemand.toFixed(2)} account-weeks.`;
230
246
  let title;
231
247
  let action;
232
248
  if (advice.pause.length > 0) {
@@ -53,6 +53,24 @@ export async function atomicWriteFile(filePath, content, options = 'utf-8') {
53
53
  throw err;
54
54
  }
55
55
  }
56
+ function lockOnce(filePath, staleMs, realpath, onCompromised) {
57
+ try {
58
+ return lockfile.lockSync(filePath, { stale: staleMs, realpath, onCompromised });
59
+ }
60
+ catch (err) {
61
+ if (err instanceof Error && err.code === 'ENOTDIR') {
62
+ try {
63
+ const base = realpath ? fs.realpathSync(filePath) : filePath;
64
+ const lockPath = `${base}.lock`;
65
+ const st = fs.statSync(lockPath);
66
+ if (st.isFile())
67
+ fs.unlinkSync(lockPath);
68
+ }
69
+ catch { }
70
+ }
71
+ throw err;
72
+ }
73
+ }
56
74
  export function withFileLock(filePath, fn, opts = {}) {
57
75
  let release = null;
58
76
  let lastError;
@@ -62,25 +80,11 @@ export function withFileLock(filePath, fn, opts = {}) {
62
80
  const deadline = Date.now() + acquireTimeoutMs;
63
81
  for (let attempt = 0;; attempt++) {
64
82
  try {
65
- release = lockfile.lockSync(filePath, {
66
- stale: staleMs,
67
- realpath: opts.realpath ?? true,
68
- onCompromised: (err) => { compromised = err; },
69
- });
83
+ release = lockOnce(filePath, staleMs, opts.realpath ?? true, (err) => { compromised = err; });
70
84
  break;
71
85
  }
72
86
  catch (err) {
73
87
  lastError = err;
74
- if (err instanceof Error && err.code === 'ENOTDIR') {
75
- try {
76
- const base = (opts.realpath ?? true) ? fs.realpathSync(filePath) : filePath;
77
- const lockPath = `${base}.lock`;
78
- const st = fs.statSync(lockPath);
79
- if (st.isFile())
80
- fs.unlinkSync(lockPath);
81
- }
82
- catch { }
83
- }
84
88
  if (Date.now() >= deadline)
85
89
  break;
86
90
  const backoff = Math.min(LOCK_RETRY_MIN_MS * (attempt + 1), LOCK_RETRY_MAX_MS);
@@ -123,25 +127,11 @@ export async function withFileLockAsync(filePath, fn, opts = {}) {
123
127
  const deadline = Date.now() + acquireTimeoutMs;
124
128
  for (let attempt = 0;; attempt++) {
125
129
  try {
126
- release = await lockfile.lock(filePath, {
127
- stale: staleMs,
128
- realpath: opts.realpath ?? true,
129
- onCompromised: (err) => { compromised = err; },
130
- });
130
+ release = lockOnce(filePath, staleMs, opts.realpath ?? true, (err) => { compromised = err; });
131
131
  break;
132
132
  }
133
133
  catch (err) {
134
134
  lastError = err;
135
- if (err instanceof Error && err.code === 'ENOTDIR') {
136
- try {
137
- const base = (opts.realpath ?? true) ? fs.realpathSync(filePath) : filePath;
138
- const lockPath = `${base}.lock`;
139
- const st = fs.statSync(lockPath);
140
- if (st.isFile())
141
- fs.unlinkSync(lockPath);
142
- }
143
- catch { }
144
- }
145
135
  if (Date.now() >= deadline)
146
136
  break;
147
137
  const backoff = Math.min(LOCK_RETRY_MIN_MS * (attempt + 1), LOCK_RETRY_MAX_MS);
@@ -170,7 +160,7 @@ export async function withFileLockAsync(filePath, fn, opts = {}) {
170
160
  }
171
161
  finally {
172
162
  try {
173
- await release();
163
+ release();
174
164
  }
175
165
  catch { }
176
166
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phnx-labs/agents-cli",
3
- "version": "1.23.48",
3
+ "version": "1.23.50",
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",