@shimatoworks/stw-agent 0.1.0 → 0.1.1

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
@@ -51,6 +51,12 @@ stw-agent --help
51
51
  `stw-manage` の `docs/guides/案件コンテキストの集め方.md`
52
52
  - なぜこの形なのか・過去の判断: `stw-manage` の `docs/records/235-agent-read-api.md`
53
53
 
54
+ ## 変更履歴
55
+
56
+ - **0.1.1** — `npm i -g` した `stw-agent`(symlink)が無出力で終了する不具合を修正。
57
+ 実体パスでの直接実行は 0.1.0 でも動いていた
58
+ - 0.1.0 — 最初の公開
59
+
54
60
  ## ライセンス
55
61
 
56
62
  `UNLICENSED`(社内利用)。npm の scope は公開だが、利用許諾を与えるものではない。
package/bin/stw-agent.mjs CHANGED
@@ -31,6 +31,7 @@
31
31
  // 契約が 2 か所に増えて食い違う。**CLI が自分で断るのは「使い方」だけ**
32
32
  // (`--project` と `--channel` の排他など、要求を組み立てられない場合)。
33
33
 
34
+ import { realpathSync } from 'node:fs';
34
35
  import { readFile } from 'node:fs/promises';
35
36
  import os from 'node:os';
36
37
  import path from 'node:path';
@@ -632,6 +633,41 @@ export async function runCli(argv, overrides = {}) {
632
633
  }
633
634
  }
634
635
 
635
- const isDirectExecution =
636
- process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href;
637
- if (isDirectExecution) process.exitCode = await runCli(process.argv.slice(2));
636
+ /**
637
+ * この実行が「CLI として直接呼ばれた」ものか(ライブラリとして import されたのではなく)。
638
+ *
639
+ * ## symlink 経由で無出力になっていた(0.1.0 の不具合)
640
+ *
641
+ * `npm i -g` が作る `~/.npm-global/bin/stw-agent` は
642
+ * `../lib/node_modules/@shimatoworks/stw-agent/bin/stw-agent.mjs` への **symlink** である。
643
+ * このとき Node が渡す値は 2 つで食い違う。
644
+ *
645
+ * ```text
646
+ * process.argv[1] /Users/x/.npm-global/bin/stw-agent ← 呼ばれた名前(symlink)
647
+ * import.meta.url file:///Users/x/.npm-global/lib/…/bin/stw-agent.mjs ← 実体
648
+ * ```
649
+ *
650
+ * Node は既定でモジュールの**実体パス**で `import.meta.url` を作るので、
651
+ * `argv[1]` をそのまま URL 化して比べると一致しない。判定が false になり、
652
+ * **何も実行せず exit 0**(無出力)になっていた。
653
+ *
654
+ * symlink は bin 自体だけでなく**途中のディレクトリ**にもある(macOS の `/tmp` は
655
+ * `/private/tmp` への symlink)。だから「realpath に直してから比べる」で両方に効く。
656
+ *
657
+ * `--preserve-symlinks-main` を付けて起動した場合は逆に `import.meta.url` が
658
+ * symlink 側になるので、**素の比較も残して両方を許す**。
659
+ */
660
+ export function isDirectExecution(argv1, moduleUrl) {
661
+ if (!argv1) return false;
662
+ if (pathToFileURL(argv1).href === moduleUrl) return true;
663
+ try {
664
+ return pathToFileURL(realpathSync(argv1)).href === moduleUrl;
665
+ } catch {
666
+ // argv[1] が実在しない(`node --eval` など)。**ここで落とさない。**
667
+ return false;
668
+ }
669
+ }
670
+
671
+ if (isDirectExecution(process.argv[1], import.meta.url)) {
672
+ process.exitCode = await runCli(process.argv.slice(2));
673
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shimatoworks/stw-agent",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "CLI for the Shimatoworks project-context read API (project registry entries and Slack discussion).",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",