aiterm-steer-delivery 0.1.4 → 0.1.6

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,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.6
4
+
5
+ - Cursor CLI(cursor-agent)の親もCursor親として見分ける。CLIはMCPのinitializeで`clientInfo.name`を`"Cursor"`と名乗り、`"cursor-vscode"`(Desktop)しか見ていなかったため、CLIから呼ぶとhookと背景受信の配送に乗らなかった(紅蓮氏の報告、macbookのcursor-agent 2026.09.28で確認)。
6
+ ## 0.1.5
7
+
8
+ - Steerの導入で「再起動が要るCodex」を数える時、別のCODEX_HOMEで動くCodex(同じ端末の他の利用者やBot)まで数えていた(紅蓮氏の報告)。Linuxではprocessの環境からCODEX_HOME(無ければHOME/.codex)を読み、hookを入れた場所のものだけを数える。macOS・Windowsは他processの環境を読めないので、今までどおり数える。
9
+
3
10
  ## 0.1.4
4
11
 
5
12
  - CodexのSteerのhookを外した後、自製品のhookが居た位置の承認記録(`hooks.state`の`trusted_hash`・`enabled`)が`config.toml`に残っていた(ラプンツェル氏の報告)。他のhookが入らずに空いた位置の記録を消す。別のfileや他の位置の記録は触らない。記録の後片付けが公式APIの都合でできなくても、hookの解除そのものは止めない。
@@ -52,7 +52,14 @@ export type CodexSteerRuntime = {
52
52
  prepareDirectory: (directory: string) => void;
53
53
  /** Windowsでhookを起動するPowerShell 7の絶対path。 */
54
54
  powershell: () => string;
55
+ /** processが使うCODEX_HOME。読めなければnull(その時は再起動待ちに数える)。 */
56
+ codexHomeOf: (pid: number) => string | null;
55
57
  };
58
+ /**
59
+ * processの環境変数からCODEX_HOME(無ければHOME/.codex)を読む。Linuxの /proc だけで読める。
60
+ * macOSとWindowsは他processの環境を読めないのでnull。
61
+ */
62
+ export declare function processCodexHome(pid: number, platform?: NodeJS.Platform, read?: (file: string) => Buffer): string | null;
56
63
  export declare function verifyCodexHookRegistration(profile: ProductProfile, config: CodexHookConfig, approve: boolean, directory?: string): Promise<void>;
57
64
  /** hookは製品が同梱するCodex hook入口(パッケージのrunCodexResultHookを呼ぶ小さなファイル)の絶対path。 */
58
65
  export declare function configureCodexSteer(profile: ProductProfile, action: CodexSteerAction | undefined, overrides: Partial<CodexSteerRuntime> & {
@@ -180,6 +180,28 @@ function samePath(a, b) {
180
180
  return process.platform === "win32" && a.toLowerCase() === b.toLowerCase();
181
181
  }
182
182
  }
183
+ /**
184
+ * processの環境変数からCODEX_HOME(無ければHOME/.codex)を読む。Linuxの /proc だけで読める。
185
+ * macOSとWindowsは他processの環境を読めないのでnull。
186
+ */
187
+ export function processCodexHome(pid, platform = process.platform, read = file => fs.readFileSync(file)) {
188
+ if (platform !== "linux")
189
+ return null;
190
+ let raw;
191
+ try {
192
+ raw = read(`/proc/${pid}/environ`);
193
+ }
194
+ catch {
195
+ return null;
196
+ }
197
+ const env = new Map(raw.toString("utf8").split("\0").filter(Boolean).map(entry => {
198
+ const index = entry.indexOf("=");
199
+ return [entry.slice(0, index), entry.slice(index + 1)];
200
+ }));
201
+ // Linuxのprocessの値なので、どのOSで試験してもPOSIXの規則で組み立てる。
202
+ const home = env.get("CODEX_HOME") || (env.get("HOME") ? path.posix.join(env.get("HOME"), ".codex") : null);
203
+ return home ? path.posix.resolve(home) : null;
204
+ }
183
205
  export async function verifyCodexHookRegistration(profile, config, approve, directory = codexHookDirectory(profile)) {
184
206
  fs.accessSync(config.node, fs.constants.X_OK);
185
207
  fs.accessSync(config.hook, fs.constants.R_OK);
@@ -210,7 +232,7 @@ export async function configureCodexSteer(profile, action = "status", overrides)
210
232
  node: process.execPath, findBinary: () => findSteerBinary(),
211
233
  processes: readRuntimeProcesses, legacy: () => null,
212
234
  disableLegacy: async () => ({ status: "disabled" }), verify: (config, approve) => verifyCodexHookRegistration(profile, config, approve, directory),
213
- prepareDirectory: () => undefined, powershell: () => resolveWindowsPowerShell7(), ...overrides };
235
+ prepareDirectory: () => undefined, powershell: () => resolveWindowsPowerShell7(), codexHomeOf: pid => processCodexHome(pid), ...overrides };
214
236
  const previous = readCodexHookConfig(profile, runtime.directory);
215
237
  const legacy = runtime.legacy();
216
238
  const file = path.join(action === "disable" && previous ? previous.codex_home : runtime.codex_home, "hooks.json");
@@ -264,6 +286,11 @@ export async function configureCodexSteer(profile, action = "status", overrides)
264
286
  || command.startsWith(candidate + " ") || command.startsWith(`"${candidate}" `)
265
287
  || command.endsWith(" " + candidate) || command.includes(` ${candidate} `) || command.includes(` "${candidate}"`);
266
288
  }) || roots.some(root => normalize(row.command).includes(root + (runtime.platform === "win32" ? "\\" : "/"))))
289
+ // 別のCODEX_HOMEで動くCodex(同じ端末の他の利用者やBot)は、このhookを読まないので再起動を求めない。
290
+ .filter(row => {
291
+ const home = runtime.codexHomeOf(row.pid);
292
+ return home === null || samePath(home, runtime.codex_home);
293
+ })
267
294
  .map(({ pid, started_identity }) => ({ pid, started_identity }))
268
295
  : previous.stale_processes;
269
296
  const config = { schema: profile.codex_hook_schema, enabled: true,
@@ -11,10 +11,12 @@ export const cursorParentSchema = z.object({
11
11
  hook_root: z.string(),
12
12
  }).strict();
13
13
  const deliveryIdSchema = z.string().uuid();
14
+ // Cursor DesktopはMCPのinitializeで "cursor-vscode"、Cursor CLI(cursor-agent)は "Cursor" と名乗る。
15
+ // どちらも同じ ~/.cursor/hooks.json のhookで届く。
14
16
  export function isCursorMcpClient(clientName) {
15
17
  if (clientName === undefined)
16
18
  return false;
17
- return clientName === "cursor-vscode" || clientName.startsWith("cursor-vscode ");
19
+ return clientName === "cursor-vscode" || clientName.startsWith("cursor-vscode ") || clientName === "Cursor";
18
20
  }
19
21
  export function cursorHooksFile(home = process.env.HOME ?? homedir()) {
20
22
  return path.join(process.env.CURSOR_HOME ?? path.join(home, ".cursor"), "hooks.json");
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@ export { realCodexHome, resolveCodexExecutable, desktopBundledCodex, findDesktop
8
8
  export { codexHookConfigSchema, readCodexHookConfig, codexInputDirectory, hookInputSchema, answerDigest, registerCodexHookInput, finishCodexHookSubmission, codexHookDeliveryState, ownedCodexHooks, assertCodexHooksReady, assertCodexHookParentCurrent, type CodexHookConfig, } from "./codex-hook-state.js";
9
9
  export { codexParentFromRequest, withCodexReceiver, verifyCodexParent, submitCodexParentAnswer, type CodexParent, type CodexParentThread, type CodexReceiverRuntime, } from "./codex-receiver.js";
10
10
  export { runCodexResultHook } from "./codex-hooks.js";
11
- export { codexHookCommand, mergeCodexParentHooks, planCodexParentHooks, writeCodexHookPlan, applyCodexHookPlan, verifyCodexHookRegistration, configureCodexSteer, type CodexHookMove, type CodexHookPlan, type CodexSteerAction, type CodexSteerResult, type CodexSteerRuntime, } from "./codex-setup.js";
11
+ export { codexHookCommand, processCodexHome, mergeCodexParentHooks, planCodexParentHooks, writeCodexHookPlan, applyCodexHookPlan, verifyCodexHookRegistration, configureCodexSteer, type CodexHookMove, type CodexHookPlan, type CodexSteerAction, type CodexSteerResult, type CodexSteerRuntime, } from "./codex-setup.js";
12
12
  export { claudeParentSchema, prepareClaudeHookRequest, claudeParentFromRequest, verifyClaudeParent, bindClaudeParentDelivery, closeClaudeParentSession, submitClaudeParentAnswer, runClaudeResultHook, type ClaudeParent, } from "./claude-receiver.js";
13
13
  export { cursorParentSchema, isCursorMcpClient, cursorHooksFile, cursorParentHooksRegistered, verifyCursorParent, cursorParentFromRequest, prepareCursorDelivery, submitCursorParentAnswer, handleCursorHook, receiveCursorAnswer, type CursorParent, type CursorReceiveResult, } from "./cursor-receiver.js";
14
14
  export { cursorReceiveProcess, runCursorReceive, type WaitProcess } from "./cursor-receive.js";
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ export { realCodexHome, resolveCodexExecutable, desktopBundledCodex, findDesktop
10
10
  export { codexHookConfigSchema, readCodexHookConfig, codexInputDirectory, hookInputSchema, answerDigest, registerCodexHookInput, finishCodexHookSubmission, codexHookDeliveryState, ownedCodexHooks, assertCodexHooksReady, assertCodexHookParentCurrent, } from "./codex-hook-state.js";
11
11
  export { codexParentFromRequest, withCodexReceiver, verifyCodexParent, submitCodexParentAnswer, } from "./codex-receiver.js";
12
12
  export { runCodexResultHook } from "./codex-hooks.js";
13
- export { codexHookCommand, mergeCodexParentHooks, planCodexParentHooks, writeCodexHookPlan, applyCodexHookPlan, verifyCodexHookRegistration, configureCodexSteer, } from "./codex-setup.js";
13
+ export { codexHookCommand, processCodexHome, mergeCodexParentHooks, planCodexParentHooks, writeCodexHookPlan, applyCodexHookPlan, verifyCodexHookRegistration, configureCodexSteer, } from "./codex-setup.js";
14
14
  export { claudeParentSchema, prepareClaudeHookRequest, claudeParentFromRequest, verifyClaudeParent, bindClaudeParentDelivery, closeClaudeParentSession, submitClaudeParentAnswer, runClaudeResultHook, } from "./claude-receiver.js";
15
15
  export { cursorParentSchema, isCursorMcpClient, cursorHooksFile, cursorParentHooksRegistered, verifyCursorParent, cursorParentFromRequest, prepareCursorDelivery, submitCursorParentAnswer, handleCursorHook, receiveCursorAnswer, } from "./cursor-receiver.js";
16
16
  export { cursorReceiveProcess, runCursorReceive } from "./cursor-receive.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aiterm-steer-delivery",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Aiterm's steer delivery as a library: deliver text to the parent AI session that called your MCP tool — steered into the running turn when it is busy, delivered normally when it is idle. Codex (official queue + sync hooks), Claude Code (asyncRewake hooks), Cursor (hooks + background receiver).",
5
5
  "type": "module",
6
6
  "license": "MIT",