aiterm-steer-delivery 0.1.6 → 0.1.8
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 +6 -0
- package/dist/cursor-receive.d.ts +3 -2
- package/dist/cursor-receive.js +9 -2
- package/dist/cursor-receiver.js +2 -2
- package/dist/files.d.ts +2 -0
- package/dist/files.js +4 -0
- package/dist/hook-main.d.ts +7 -3
- package/dist/hook-main.js +14 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.8
|
|
4
|
+
|
|
5
|
+
- `runCursorHookMain`・`runCursorReceiveMain`・`runCursorReceive`が置き場を複数受け取れる。Cursor CLIはMCPを削った環境(XDG_RUNTIME_DIR・TMPDIR等が無い)で起動し、hookと背景processは画面側の環境で起動する。環境から置き場を決める製品(Aiterm)はMCPとhookで置き場が割れ、hookが配送記録を見つけられずに何もしていなかった(rabbit・macbookで確認)。hookは渡した置き場それぞれで結び付けと差し込みを行い、受信は配送記録のある置き場で待つ。配送記録の無い置き場には何も作らない。
|
|
6
|
+
## 0.1.7
|
|
7
|
+
|
|
8
|
+
- WindowsのCursor(cursor-agent 2026.09.28)はhookのstdinのJSONの先頭にBOM(U+FEFF)を付ける。`handleCursorHook`がそのまま読んで失敗し、会話への結び付けも作業中の差し込みも起きず、配送は`sending`のまま止まっていた(紅蓮氏の報告、foxで確認)。hook入口の読み取り(Codex・Claude Code・Cursor共通)と`handleCursorHook`で先頭のBOMを落とす。`withoutBom`も公開する。
|
|
3
9
|
## 0.1.6
|
|
4
10
|
|
|
5
11
|
- Cursor CLI(cursor-agent)の親もCursor親として見分ける。CLIはMCPのinitializeで`clientInfo.name`を`"Cursor"`と名乗り、`"cursor-vscode"`(Desktop)しか見ていなかったため、CLIから呼ぶとhookと背景受信の配送に乗らなかった(紅蓮氏の報告、macbookのcursor-agent 2026.09.28で確認)。
|
package/dist/cursor-receive.d.ts
CHANGED
|
@@ -5,5 +5,6 @@ export interface WaitProcess {
|
|
|
5
5
|
}
|
|
6
6
|
/** 親の背景process APIへそのまま渡す起動情報。scriptは製品のCursor受信入口の絶対path。 */
|
|
7
7
|
export declare function cursorReceiveProcess(script: string, deliveryId: string, executable?: string): WaitProcess;
|
|
8
|
-
/** 受信入口の本体。結果を1行のJSONでstdoutへ出し、exit codeを返す(0=受取、3=期限切れ、1=誤り)。
|
|
9
|
-
|
|
8
|
+
/** 受信入口の本体。結果を1行のJSONでstdoutへ出し、exit codeを返す(0=受取、3=期限切れ、1=誤り)。
|
|
9
|
+
* hookRootを複数渡すと、配送記録のある置き場で待つ(runCursorHookMainと同じ理由)。どこにも無ければ先頭の置き場で誤りを返す。 */
|
|
10
|
+
export declare function runCursorReceive(hookRoot: string | readonly string[], argv: string[], emit?: (value: unknown) => void, usage?: string): Promise<number>;
|
package/dist/cursor-receive.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// Cursor親がidleのとき、背景で起動して回答本文の到着を待つ受け口。
|
|
2
2
|
// 起動するファイルは製品が同梱する入口で、そこからrunCursorReceiveを呼ぶ。
|
|
3
|
+
import * as fs from "node:fs";
|
|
4
|
+
import * as path from "node:path";
|
|
3
5
|
import { receiveCursorAnswer } from "./cursor-receiver.js";
|
|
4
6
|
import { windowsStartProcessArgumentList } from "./windows.js";
|
|
5
7
|
/** 親の背景process APIへそのまま渡す起動情報。scriptは製品のCursor受信入口の絶対path。 */
|
|
@@ -11,13 +13,18 @@ export function cursorReceiveProcess(script, deliveryId, executable = process.ex
|
|
|
11
13
|
windows_start_process_argument_list: process.platform === "win32" ? windowsStartProcessArgumentList(args) : null,
|
|
12
14
|
};
|
|
13
15
|
}
|
|
14
|
-
/** 受信入口の本体。結果を1行のJSONでstdoutへ出し、exit codeを返す(0=受取、3=期限切れ、1=誤り)。
|
|
16
|
+
/** 受信入口の本体。結果を1行のJSONでstdoutへ出し、exit codeを返す(0=受取、3=期限切れ、1=誤り)。
|
|
17
|
+
* hookRootを複数渡すと、配送記録のある置き場で待つ(runCursorHookMainと同じ理由)。どこにも無ければ先頭の置き場で誤りを返す。 */
|
|
15
18
|
export async function runCursorReceive(hookRoot, argv, emit = value => { process.stdout.write(JSON.stringify(value) + "\n"); }, usage = "usage: cursor-parent-receive --delivery <uuid>") {
|
|
16
19
|
if (argv.length !== 2 || argv[0] !== "--delivery" || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(argv[1])) {
|
|
17
20
|
emit({ ok: false, code: "CURSOR_PARENT_RECEIVE_USAGE", message: usage });
|
|
18
21
|
return 1;
|
|
19
22
|
}
|
|
20
|
-
const
|
|
23
|
+
const roots = typeof hookRoot === "string" ? [hookRoot] : [...hookRoot];
|
|
24
|
+
const root = roots.find(each => fs.existsSync(path.join(each, "deliveries", argv[1]))) ?? roots[0];
|
|
25
|
+
if (root === undefined)
|
|
26
|
+
throw new Error("受信の置き場がありません");
|
|
27
|
+
const result = await receiveCursorAnswer(root, argv[1]);
|
|
21
28
|
if (result.outcome === "timeout") {
|
|
22
29
|
emit({ delivery_id: argv[1], outcome: "timeout" });
|
|
23
30
|
return 3;
|
package/dist/cursor-receiver.js
CHANGED
|
@@ -4,7 +4,7 @@ import * as fs from "node:fs";
|
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import * as path from "node:path";
|
|
6
6
|
import { z } from "zod";
|
|
7
|
-
import { waitForFileState, writeJson0600 } from "./files.js";
|
|
7
|
+
import { waitForFileState, withoutBom, writeJson0600 } from "./files.js";
|
|
8
8
|
import { CursorDeliveryError } from "./errors.js";
|
|
9
9
|
export const cursorParentSchema = z.object({
|
|
10
10
|
kind: z.literal("cursor"),
|
|
@@ -193,7 +193,7 @@ function inject(hookRoot, conv) {
|
|
|
193
193
|
export async function handleCursorHook(profile, raw, hookRoot) {
|
|
194
194
|
let parsed;
|
|
195
195
|
try {
|
|
196
|
-
parsed = JSON.parse(raw);
|
|
196
|
+
parsed = JSON.parse(withoutBom(raw));
|
|
197
197
|
}
|
|
198
198
|
catch {
|
|
199
199
|
return {};
|
package/dist/files.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** WindowsのCursorはhookのstdinのJSONの先頭にBOM(U+FEFF)を付ける。JSONとして読む前に落とす。 */
|
|
2
|
+
export declare function withoutBom(text: string): string;
|
|
1
3
|
export declare function writeJson0600(p: string, v: unknown): void;
|
|
2
4
|
export declare function writeHookJson(file: string, value: unknown): void;
|
|
3
5
|
/** directory内の状態変化を待つ。inspectが値を返した時点でresolveする。timeoutMsを省くと期限なし。 */
|
package/dist/files.js
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
import * as fs from "node:fs";
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import { randomBytes, randomUUID } from "node:crypto";
|
|
5
|
+
/** WindowsのCursorはhookのstdinのJSONの先頭にBOM(U+FEFF)を付ける。JSONとして読む前に落とす。 */
|
|
6
|
+
export function withoutBom(text) {
|
|
7
|
+
return text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;
|
|
8
|
+
}
|
|
5
9
|
export function writeJson0600(p, v) {
|
|
6
10
|
// truncate-in-place はクラッシュ/ENOSPC の窓で空・途中 JSON を残すので、temp→rename の原子的置換にする
|
|
7
11
|
const tmp = `${p}.${randomBytes(6).toString("hex")}.tmp`;
|
package/dist/hook-main.d.ts
CHANGED
|
@@ -3,10 +3,14 @@ import { type ProductProfile } from "./profile.js";
|
|
|
3
3
|
export declare function runCodexHookMain(profile: ProductProfile, directory?: string | undefined): Promise<void>;
|
|
4
4
|
/** Claude Codeが直接起動する公式hook(PreToolUse/PostToolUse/SessionEnd)。本文はstderrへ返す。 */
|
|
5
5
|
export declare function runClaudeHookMain(profile: ProductProfile, root?: string): Promise<void>;
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Cursorが起動する公式hook。差し込み文をstdoutのJSONへ返す。
|
|
8
|
+
* rootを複数渡すと、各置き場で結び付けと差し込みを行う。Cursor CLIはMCPを削った環境で起動し、hookは画面側の環境で起動するため、
|
|
9
|
+
* 環境から置き場を決める製品はMCPとhookで置き場が割れる。配送記録の無い置き場では何もしない。
|
|
10
|
+
*/
|
|
11
|
+
export declare function runCursorHookMain(profile: ProductProfile, root?: string | readonly string[]): Promise<void>;
|
|
8
12
|
/** Cursor親の背景受信。 */
|
|
9
|
-
export declare function runCursorReceiveMain(profile: ProductProfile, argv?: string[], root?: string): Promise<void>;
|
|
13
|
+
export declare function runCursorReceiveMain(profile: ProductProfile, argv?: string[], root?: string | readonly string[]): Promise<void>;
|
|
10
14
|
/**
|
|
11
15
|
* channelの背景受信(Cursorのidle時、Grok等)。受け取った本文を1行のJSONで出して終わる(0=受取、3=期限切れ、4=閉鎖、1=誤り)。
|
|
12
16
|
* 受取と期限切れの結果には、同じ受信を張り直すための next_wait_process を付ける。
|
package/dist/hook-main.js
CHANGED
|
@@ -5,6 +5,7 @@ import { claudeHookRoot, cursorHookRoot } from "./profile.js";
|
|
|
5
5
|
import { runCodexResultHook } from "./codex-hooks.js";
|
|
6
6
|
import { prepareClaudeHookRequest, runClaudeResultHook, closeClaudeParentSession } from "./claude-receiver.js";
|
|
7
7
|
import { handleCursorHook } from "./cursor-receiver.js";
|
|
8
|
+
import { withoutBom } from "./files.js";
|
|
8
9
|
import { runCursorReceive } from "./cursor-receive.js";
|
|
9
10
|
import { channelReceiveProcess, closeClaudeSessionChannels, handleCursorChannelHook, receiveFromChannel, runClaudeChannelWaiter } from "./channel.js";
|
|
10
11
|
async function readStdin() {
|
|
@@ -12,7 +13,7 @@ async function readStdin() {
|
|
|
12
13
|
process.stdin.setEncoding("utf8");
|
|
13
14
|
for await (const chunk of process.stdin)
|
|
14
15
|
input += chunk;
|
|
15
|
-
return input;
|
|
16
|
+
return withoutBom(input);
|
|
16
17
|
}
|
|
17
18
|
/** Codexの同期hook(PostToolUse/Stop)。stdoutはCodexの公式hook出力だけに使う。失敗をStop継続のexit 2に変換しない。 */
|
|
18
19
|
export async function runCodexHookMain(profile, directory = process.argv[2]) {
|
|
@@ -62,11 +63,21 @@ export async function runClaudeHookMain(profile, root = claudeHookRoot(profile))
|
|
|
62
63
|
process.exitCode = 2;
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* Cursorが起動する公式hook。差し込み文をstdoutのJSONへ返す。
|
|
68
|
+
* rootを複数渡すと、各置き場で結び付けと差し込みを行う。Cursor CLIはMCPを削った環境で起動し、hookは画面側の環境で起動するため、
|
|
69
|
+
* 環境から置き場を決める製品はMCPとhookで置き場が割れる。配送記録の無い置き場では何もしない。
|
|
70
|
+
*/
|
|
66
71
|
export async function runCursorHookMain(profile, root = cursorHookRoot(profile)) {
|
|
67
72
|
try {
|
|
68
73
|
const input = await readStdin();
|
|
69
|
-
const result =
|
|
74
|
+
const result = {};
|
|
75
|
+
for (const each of typeof root === "string" ? [root] : [...new Set(root)]) {
|
|
76
|
+
const found = await handleCursorHook(profile, input.length > 0 ? input : "{}", each);
|
|
77
|
+
if (typeof found.additional_context === "string") {
|
|
78
|
+
result.additional_context = typeof result.additional_context === "string" ? `${result.additional_context}\n\n${found.additional_context}` : found.additional_context;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
70
81
|
if (profile.channels) {
|
|
71
82
|
let event = null;
|
|
72
83
|
try {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from "./profile.js";
|
|
2
2
|
export * from "./errors.js";
|
|
3
|
-
export { writeJson0600, writeHookJson, waitForFileState } from "./files.js";
|
|
3
|
+
export { writeJson0600, writeHookJson, waitForFileState, withoutBom } from "./files.js";
|
|
4
4
|
export { readRuntimeProcesses, parsePosixProcessTable, type RuntimeProcess, type NativeProcessIdentity } from "./process.js";
|
|
5
5
|
export { resolveWindowsPowerShell7, quotePowerShell, windowsPowerShellSync, windowsStartProcessArgumentList } from "./windows.js";
|
|
6
6
|
export { setupNodeExecutable } from "./setup-node.js";
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// 親AIが作業中ならそのturnへ差し込み、idleなら同じ会話へ普通に届ける。受信方式は親ごとに公式の仕組みを使う。
|
|
3
3
|
export * from "./profile.js";
|
|
4
4
|
export * from "./errors.js";
|
|
5
|
-
export { writeJson0600, writeHookJson, waitForFileState } from "./files.js";
|
|
5
|
+
export { writeJson0600, writeHookJson, waitForFileState, withoutBom } from "./files.js";
|
|
6
6
|
export { readRuntimeProcesses, parsePosixProcessTable } from "./process.js";
|
|
7
7
|
export { resolveWindowsPowerShell7, quotePowerShell, windowsPowerShellSync, windowsStartProcessArgumentList } from "./windows.js";
|
|
8
8
|
export { setupNodeExecutable } from "./setup-node.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aiterm-steer-delivery",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
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",
|