attention-secretary 0.1.1 → 0.1.2

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/README.md CHANGED
@@ -60,6 +60,8 @@ Installing the npm package runs no scripts; nothing happens until you type one o
60
60
 
61
61
  When a new version is out, the About page says so. "Update Attention" there, or `attention update`, waits until the secretary finishes its current round. Without Node.js, download the new DMG and replace the app.
62
62
 
63
+ The `attention` command itself updates through npm: `npm install -g attention-secretary@latest`. `attention update` tells you when there is a newer one.
64
+
63
65
  </details>
64
66
 
65
67
  <details>
package/bin/attention.js CHANGED
@@ -45,6 +45,7 @@ const EN = {
45
45
  "下载 {name} …": "Downloading {name} …",
46
46
  "下载的文件和发布时的校验值对不上,可能被篡改或下载不完整,不安装。": "The download doesn't match the release's checksum; it may be tampered with or incomplete. Not installing.",
47
47
  "校验通过。": "Checksum OK.",
48
+ "\n提示:attention 命令有新版本 {latest}(现在是 {current}),运行 npm install -g attention-secretary@latest 更新。": "\nTip: a newer attention command is available ({latest}, you have {current}). Update it with npm install -g attention-secretary@latest.",
48
49
  "正在解压并检查安装包 …": "Unpacking and checking the package …",
49
50
  "正在安装到 {path} …": "Installing to {path} …",
50
51
  "正在启动 Attention …": "Starting Attention …",
@@ -302,12 +303,15 @@ async function stop(app) {
302
303
  const file=path.join(DATA,"runtime","endpoint.json");
303
304
  if(fs.existsSync(file)){
304
305
  readEndpoint(file);
305
- const stopped=run(backend(app),["stop","--root-dir",DATA],{timeout:30000});
306
- if(!stopped.ok)throw Error("Owned service could not be stopped; not replacing app");
306
+ // --wait: stop and confirm it, and treat an endpoint left behind by a Host that already exited as stopped.
307
+ const stopped=run(backend(app),["stop","--wait","--root-dir",DATA],{timeout:60000});
308
+ if(!stopped.ok)throw Error(`Owned service could not be stopped (${stopped.err.split("\n").pop() || "no detail"}); not replacing app`);
307
309
  }
308
310
  if(descriptor){
309
311
  const result=run("/bin/launchctl",["bootout",`gui/${UID}/${LABEL}`],{timeout:10000});
310
312
  if(!result.ok && run("/bin/launchctl",["print",`gui/${UID}/${LABEL}`],{timeout:5000}).ok)throw Error("Service unload not confirmed");
313
+ for(let waited=0;waited<15000 && run("/bin/launchctl",["print",`gui/${UID}/${LABEL}`],{timeout:5000}).ok;waited+=500)
314
+ await new Promise(resolve=>setTimeout(resolve,500)); // bootout returns before the job is fully gone
311
315
  }
312
316
  // Never pkill by a broad command-line substring; unrelated UI/processes remain untouched.
313
317
  }
@@ -346,13 +350,20 @@ function writeService(app) {
346
350
  }
347
351
  async function start(app, prior, overrides={}) {
348
352
  const ops={run,endpoint:readEndpoint,identity:e=>localGet(e,"/v1/identity"),now:Date.now,
349
- delay:ms=>new Promise(resolve=>setTimeout(resolve,ms)),timeout:30000,...overrides};
353
+ delay:ms=>new Promise(resolve=>setTimeout(resolve,ms)),timeout:90000,...overrides};
350
354
  if(prior===undefined) {
351
355
  prior=null;
352
356
  if(fs.existsSync(path.join(DATA,"runtime","endpoint.json")))prior=ops.endpoint();
353
357
  }
354
- const boot=ops.run("/bin/launchctl",["bootstrap",`gui/${UID}`,PLIST],{timeout:10000});
355
- if(!boot.ok)throw Error("Background service registration failed; startup not confirmed");
358
+ // Right after a bootout launchd can still be tearing the old job down and refuses the new one (5: Input/output
359
+ // error) for a few seconds: try again before giving up.
360
+ let boot;
361
+ for(let attempt=0;attempt<6;attempt++) {
362
+ boot=ops.run("/bin/launchctl",["bootstrap",`gui/${UID}`,PLIST],{timeout:10000});
363
+ if(boot.ok)break;
364
+ await ops.delay(2000);
365
+ }
366
+ if(!boot.ok)throw Error(`Background service registration failed (${boot.err || "launchctl bootstrap"}); startup not confirmed`);
356
367
  const deadline=ops.now()+ops.timeout;
357
368
  while(ops.now()<deadline) {
358
369
  try {
@@ -537,7 +548,7 @@ async function replaceBundle(fresh,target,backup,ops) {
537
548
  if(moved) {if(ops.compatible)ops.compatible(backup);ops.move(backup,target);if(ops.forgetBackup)ops.forgetBackup(backup);await startRecovered(target);}
538
549
  else if(oldStopped && fs.existsSync(target)) {await startRecovered(target);}
539
550
  persist("recovered");
540
- } catch(recovery) {persist("recovery_failed");throw Error(`Update failed; recovery needs review: ${recovery.message}`);}
551
+ } catch(recovery) {persist("recovery_failed");throw Error(`Update failed (${error.message}); recovery needs review: ${recovery.message}`);}
541
552
  throw error;
542
553
  }
543
554
  }
@@ -668,15 +679,26 @@ async function uninstall() {
668
679
  say(T("你的数据还在 {path},如果确定不要了,可以自己把这个文件夹移到废纸篓。", { path: DATA }));
669
680
  }
670
681
 
682
+ // The `attention` command itself is the npm package and doesn't update with the app. Say so when npm has a newer one.
683
+ // Quiet on any failure: this never gets in the way of an install.
684
+ async function cliUpdateHint(fetch=get) {
685
+ try {
686
+ const latest=(await fetch("https://registry.npmjs.org/attention-secretary/latest",true,0,262144,Date.now()+5000)).version;
687
+ if(typeof latest==="string" && newer(latest,pkg.version))
688
+ say(T("\n提示:attention 命令有新版本 {latest}(现在是 {current}),运行 npm install -g attention-secretary@latest 更新。",{latest,current:pkg.version}));
689
+ } catch {}
690
+ }
671
691
  async function main() {
672
692
  const [command, ...rest] = process.argv.slice(2);
673
693
  const flag = name => { const i = rest.indexOf(name); return i >= 0 ? rest[i + 1] : undefined; };
674
694
  switch (command) {
675
- case "install": return withInstallLock(()=>install(flag("--version"), false));
695
+ case "install": await withInstallLock(()=>install(flag("--version"), false)); return cliUpdateHint();
676
696
  case "update": {
677
697
  const selected=flag("--from-app");
678
698
  if(selected && selected!==installedApp())throw Error("Update target is not this installed app");
679
- return withInstallLock(()=>install(flag("--version"), true,!!selected));
699
+ await withInstallLock(()=>install(flag("--version"), true,!!selected));
700
+ if(!selected) await cliUpdateHint(); // the app's own update button runs the copy inside the app
701
+ return;
680
702
  }
681
703
  case "recover": return withInstallLock(()=>recover());
682
704
  case "rollback": return withInstallLock(()=>rollback());
@@ -697,4 +719,4 @@ async function main() {
697
719
  }
698
720
  }
699
721
  if (require.main === module) main().catch(error => {process.stderr.write("✗ "+error.message+"\n");process.exitCode=1;});
700
- else module.exports = { installedApp, installedCopies, download, newer, plistXml, get, checkedUrl, readEndpoint, localGet, replaceBundle, start, rollbackBundle, ensureTransactionSettled, withInstallLock, recoverBundle, bundleFingerprint, writeBackupReceipt, readBackupReceipt, trustedBackups, spin, stopSpin, say };
722
+ else module.exports = { installedApp, installedCopies, download, newer, plistXml, get, checkedUrl, readEndpoint, localGet, replaceBundle, start, rollbackBundle, ensureTransactionSettled, withInstallLock, recoverBundle, bundleFingerprint, writeBackupReceipt, readBackupReceipt, trustedBackups, spin, stopSpin, say, cliUpdateHint };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "attention-secretary",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Attention: a personal secretary for macOS that runs on your own Claude Code. Installs and updates the Attention app.",
5
5
  "license": "MIT",
6
6
  "bin": {