session-peer 0.1.0 → 0.2.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/dist/windows.js CHANGED
@@ -70,6 +70,11 @@ function Openers([string]$location) {
70
70
  } finally { [void][Reader]::RmEndSession($session) }
71
71
  }
72
72
  `;
73
+ // Add-Type compiles the helper with csc on every inspectWindows call, which has
74
+ // exceeded 8 s on slow runners (#47, #65). Timeouts still fail closed. The
75
+ // compile-free creation-time probe keeps the shorter deadline.
76
+ export const COMPILED_INSPECTION_TIMEOUT_MS = 20000;
77
+ export const START_PROBE_TIMEOUT_MS = 8000;
73
78
  export function inspectWindows(mode, value) {
74
79
  if (process.platform !== 'win32')
75
80
  throw new Refusal('windows_inspection_unavailable', 1);
@@ -82,7 +87,7 @@ try {
82
87
  } catch { exit 1 }
83
88
  `;
84
89
  const done = spawnSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command',
85
- '$script = [Console]::In.ReadToEnd(); Invoke-Expression $script'], { input: code, encoding: 'utf8', timeout: 8000, maxBuffer: 65536, windowsHide: true });
90
+ '$script = [Console]::In.ReadToEnd(); Invoke-Expression $script'], { input: code, encoding: 'utf8', timeout: COMPILED_INSPECTION_TIMEOUT_MS, maxBuffer: 65536, windowsHide: true });
86
91
  if (done.status !== 0 || done.error)
87
92
  throw new Refusal('windows_owner_inspection_failed', 1);
88
93
  let rows;
@@ -101,9 +106,31 @@ try {
101
106
  return rows;
102
107
  }
103
108
  export function windowsProcessStart(pid) {
109
+ if (process.platform !== 'win32' || !Number.isSafeInteger(pid) || pid <= 1 || pid > 2147483647)
110
+ return undefined;
111
+ // Claude discovery only needs the creation time. Avoid compiling Reader and
112
+ // querying CIM/GetOwnerSid for every listed PID; Codex ownership still uses
113
+ // inspectWindows above. Dispose the native process handle on every path.
114
+ const code = `
115
+ $ErrorActionPreference = 'Stop'
116
+ try {
117
+ $item = [Diagnostics.Process]::GetProcessById(${pid})
118
+ try {
119
+ if ($item.HasExited) { exit 1 }
120
+ $ticks = $item.StartTime.ToUniversalTime().ToFileTimeUtc()
121
+ [Console]::Out.WriteLine($ticks.ToString([Globalization.CultureInfo]::InvariantCulture))
122
+ } finally { $item.Dispose() }
123
+ } catch { exit 1 }
124
+ `;
104
125
  try {
105
- const rows = inspectWindows('identity', String(pid));
106
- return rows.length === 1 ? BigInt(rows[0].start) : undefined;
126
+ const done = spawnSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', code], { encoding: 'utf8', timeout: START_PROBE_TIMEOUT_MS, maxBuffer: 65536, windowsHide: true });
127
+ if (done.status !== 0 || done.error)
128
+ return undefined;
129
+ const text = done.stdout.trim();
130
+ if (!/^[1-9][0-9]{0,18}$/.test(text))
131
+ return undefined;
132
+ const ticks = BigInt(text);
133
+ return ticks <= 9223372036854775807n ? ticks : undefined;
107
134
  }
108
135
  catch {
109
136
  return undefined;
package/dist/writer.d.ts CHANGED
@@ -1,8 +1,39 @@
1
+ import { Refusal } from './discovery.js';
1
2
  export declare const uuid: (value: string) => boolean;
2
3
  export declare function probeLock(path: string): Promise<'free' | 'held' | 'absent' | 'unknown'>;
3
4
  export declare function inspectWriter(home: string, id: string): Promise<{
4
- activity: string;
5
+ activity: "inactive";
6
+ writerLock: "absent" | "free";
7
+ identity: string;
8
+ } | {
9
+ activity: "live_writer";
10
+ writerLock: "held";
5
11
  identity: string;
6
12
  }>;
7
- export declare function homes(selected: string): string[];
8
- export declare function resolveWriter(selected: string, id: string): Promise<string>;
13
+ export type HomeCandidate = {
14
+ codexHome: string;
15
+ sources: string[];
16
+ savedThread: boolean | null;
17
+ writerLock: 'not_checked' | 'held' | 'free' | 'absent' | 'unknown';
18
+ activity?: 'inactive' | 'live_writer' | 'unknown';
19
+ reason: string;
20
+ };
21
+ export type HomeResolution = {
22
+ schemaVersion: 1;
23
+ status: 'selected' | 'explicit' | 'ambiguous' | 'unknown';
24
+ selected: string | null;
25
+ reason: string;
26
+ candidates: HomeCandidate[];
27
+ };
28
+ export declare class HomeRefusal extends Refusal {
29
+ readonly codexHomeResolution: HomeResolution;
30
+ constructor(code: string, codexHomeResolution: HomeResolution, exitCode?: number);
31
+ }
32
+ export declare function homes(selected?: string): string[];
33
+ export type WriterSelection = {
34
+ home: string;
35
+ evidence: string;
36
+ resolution: HomeResolution;
37
+ };
38
+ export declare function resolveWriter(selected: string | undefined, id: string, allowInactive?: boolean): Promise<WriterSelection>;
39
+ export declare function revalidateWriter(previous: WriterSelection, selected: string | undefined, id: string, allowInactive?: boolean): Promise<void>;
package/dist/writer.js CHANGED
@@ -1,8 +1,7 @@
1
- import { closeSync, constants, fstatSync, lstatSync, openSync, readdirSync, statSync } from 'node:fs';
2
- import { homedir } from 'node:os';
3
- import { isAbsolute, join } from 'node:path';
1
+ import { closeSync, constants, fstatSync, lstatSync, openSync, statSync } from 'node:fs';
2
+ import { join } from 'node:path';
4
3
  import { setTimeout as delay } from 'node:timers/promises';
5
- import { canonical, Refusal } from './discovery.js';
4
+ import { listingCandidates, Refusal } from './discovery.js';
6
5
  import { executable, run } from './process.js';
7
6
  import { inspectWindows } from './windows.js';
8
7
  const missing = (error) => ['ENOENT', 'ENOTDIR'].includes(error.code ?? '');
@@ -54,7 +53,7 @@ export async function probeLock(path) {
54
53
  async function sample(path) {
55
54
  const state = await probeLock(path);
56
55
  if (state !== 'held')
57
- return { state, fingerprint: '', owners: [], valid: true };
56
+ return { state, fingerprint: state === 'free' ? snapshot(path) : '', owners: [], valid: true };
58
57
  const fingerprint = snapshot(path);
59
58
  if (process.platform === 'win32') {
60
59
  const owners = inspectWindows('openers', path);
@@ -87,7 +86,7 @@ export async function inspectWriter(home, id) {
87
86
  const path = join(home, 'thread-writer-locks', `${id}.lock`);
88
87
  const before = await sample(path);
89
88
  if (before.state === 'free' || before.state === 'absent')
90
- return { activity: 'inactive', identity: '' };
89
+ return { activity: 'inactive', writerLock: before.state, identity: JSON.stringify({ state: before.state, fingerprint: before.fingerprint }) };
91
90
  if (before.state !== 'held')
92
91
  throw new Refusal('active_writer_unverified', 1);
93
92
  await delay(250);
@@ -99,81 +98,153 @@ export async function inspectWriter(home, id) {
99
98
  !owner?.start || !ownId || owner.uid !== ownId || !/^codex(?:\.exe|-|$)/i.test(owner.command ?? '')) {
100
99
  throw new Refusal('active_writer_unverified', 1);
101
100
  }
102
- return { activity: 'live_writer', identity: JSON.stringify({ fingerprint: after.fingerprint, ...owner }) };
101
+ return { activity: 'live_writer', writerLock: 'held', identity: JSON.stringify({ fingerprint: after.fingerprint, ...owner }) };
103
102
  }
104
- export function homes(selected) {
105
- const result = new Set([canonical(selected)]);
106
- const addExisting = (home) => {
107
- try {
108
- if (!statSync(join(home, 'state_5.sqlite')).isFile())
109
- throw new Refusal('home_inventory_unreadable', 1);
110
- result.add(canonical(home));
111
- }
112
- catch (error) {
113
- if (!missing(error))
114
- throw new Refusal('home_inventory_unreadable', 1);
115
- }
116
- };
117
- addExisting(join(homedir(), '.codex'));
118
- if (process.env.CODEX_HOME)
119
- addExisting(process.env.CODEX_HOME);
120
- if (process.platform === 'darwin') {
121
- const directory = join(homedir(), 'Library/Application Support/orca/codex-accounts');
122
- let entries = [];
123
- try {
124
- entries = readdirSync(directory).sort();
125
- }
126
- catch (error) {
127
- if (!missing(error))
128
- throw new Refusal('home_inventory_unreadable', 1);
129
- }
130
- for (const entry of entries)
131
- addExisting(join(directory, entry, 'home'));
103
+ export class HomeRefusal extends Refusal {
104
+ codexHomeResolution;
105
+ constructor(code, codexHomeResolution, exitCode = 1) {
106
+ super(code, exitCode);
107
+ this.codexHomeResolution = codexHomeResolution;
132
108
  }
133
- if (process.env.SESSION_PEER_CODEX_HOMES) {
134
- let paths;
135
- try {
136
- paths = JSON.parse(process.env.SESSION_PEER_CODEX_HOMES);
137
- }
138
- catch {
139
- throw new Refusal('invalid_home_configuration', 1);
109
+ }
110
+ function resolution(status, selected, reason, candidates) {
111
+ return { schemaVersion: 1, status, selected, reason, candidates };
112
+ }
113
+ function inventory(selected) {
114
+ // Never pass selected as listing's pin: send must inventory competing homes.
115
+ const automatic = listingCandidates();
116
+ const explicit = selected === undefined ? undefined : listingCandidates(selected);
117
+ const items = [...(explicit?.homes ?? []), ...automatic.homes];
118
+ const merged = new Map();
119
+ for (const item of items) {
120
+ const old = merged.get(item.codexHome);
121
+ if (old) {
122
+ old.required ||= item.required;
123
+ old.sources = [...new Set([...old.sources, ...item.sources])];
140
124
  }
141
- if (!Array.isArray(paths) || paths.some(p => typeof p !== 'string' || (!isAbsolute(p) && !p.startsWith('~/'))))
142
- throw new Refusal('invalid_home_configuration', 1);
143
- for (const path of paths)
144
- result.add(canonical(path));
125
+ else
126
+ merged.set(item.codexHome, { ...item, sources: [...item.sources] });
127
+ }
128
+ const homes = [...merged.values()].sort((a, b) => a.codexHome < b.codexHome ? -1 : a.codexHome > b.codexHome ? 1 : 0);
129
+ const candidates = homes.map(item => ({ codexHome: item.codexHome, sources: item.sources,
130
+ savedThread: null, writerLock: 'not_checked', reason: 'not_inspected' }));
131
+ const errors = [...(explicit?.errors ?? []), ...automatic.errors];
132
+ if (errors.length) {
133
+ const reason = errors.some(e => e.code === 'invalid_home_configuration') ? 'invalid_home_configuration' :
134
+ errors.some(e => e.code === 'home_resolution_failed') ? 'home_resolution_failed' : 'home_inventory_unreadable';
135
+ throw new HomeRefusal(reason, resolution('unknown', null, reason, candidates));
145
136
  }
146
- return [...result].sort();
137
+ return { homes, candidates, explicit: explicit?.homes[0]?.codexHome };
147
138
  }
148
- export async function resolveWriter(selected, id) {
139
+ export function homes(selected) { return inventory(selected).homes.map(item => item.codexHome); }
140
+ export async function resolveWriter(selected, id, allowInactive = false) {
141
+ if (!uuid(id))
142
+ throw new HomeRefusal('codex_uuid_required', resolution('unknown', null, 'invalid_thread_id', []), 2);
143
+ if (selected !== undefined && !selected)
144
+ throw new HomeRefusal('invalid_codex_home', resolution('unknown', null, 'invalid_codex_home', []), 2);
145
+ if (allowInactive && !selected)
146
+ throw new HomeRefusal('inactive_opt_in_requires_explicit_home', resolution('unknown', null, 'inactive_opt_in_requires_explicit_home', []), 2);
147
+ const { homes: inventoryHomes, candidates, explicit } = inventory(selected);
149
148
  const { DatabaseSync } = await import('node:sqlite');
150
- const candidates = homes(selected);
151
- const matches = [];
152
- for (const home of candidates) {
153
- let saved = false;
149
+ const fingerprints = [];
150
+ for (const [index, item] of inventoryHomes.entries()) {
151
+ const candidate = candidates[index];
152
+ let dbFingerprint = 'absent';
153
+ let present = true;
154
154
  try {
155
- const db = new DatabaseSync(join(home, 'state_5.sqlite'), { readOnly: true });
156
155
  try {
157
- db.exec('PRAGMA query_only=ON; PRAGMA trusted_schema=OFF; PRAGMA busy_timeout=3000');
158
- saved = Boolean(db.prepare('SELECT 1 FROM threads WHERE id=? LIMIT 1').get(id));
156
+ if (!statSync(item.stateDb).isFile()) {
157
+ candidate.reason = 'state_db_not_regular';
158
+ throw new Error();
159
+ }
160
+ }
161
+ catch (error) {
162
+ if (!missing(error))
163
+ throw error;
164
+ present = false;
165
+ candidate.savedThread = false;
166
+ candidate.reason = item.required ? 'state_db_missing' : 'state_db_absent';
167
+ if (item.required)
168
+ throw new Error();
159
169
  }
160
- finally {
161
- db.close();
170
+ if (present) {
171
+ // Track file identity, not mtime: normal unrelated DB activity is allowed.
172
+ const before = statSync(item.stateDb, { bigint: true });
173
+ const db = new DatabaseSync(item.stateDb, { readOnly: true });
174
+ try {
175
+ db.exec('PRAGMA query_only=ON; PRAGMA trusted_schema=OFF; PRAGMA busy_timeout=3000');
176
+ candidate.savedThread = Boolean(db.prepare('SELECT 1 FROM threads WHERE id=? LIMIT 1').get(id));
177
+ }
178
+ finally {
179
+ db.close();
180
+ }
181
+ const after = statSync(item.stateDb, { bigint: true });
182
+ if (before.dev !== after.dev || before.ino !== after.ino) {
183
+ candidate.reason = 'state_db_changed';
184
+ throw new Error();
185
+ }
186
+ dbFingerprint = `${after.dev}:${after.ino}`;
187
+ candidate.reason = candidate.savedThread ? 'saved_thread' : 'thread_not_saved';
162
188
  }
163
189
  }
190
+ catch (error) {
191
+ if (candidate.reason === 'not_inspected')
192
+ candidate.reason =
193
+ ['EACCES', 'EPERM'].includes(error.code ?? '') ? 'permission_denied' : 'state_db_read_failed';
194
+ throw new HomeRefusal('home_inventory_unreadable', resolution('unknown', null, 'home_inventory_unreadable', candidates));
195
+ }
196
+ // Inspect this UUID even without a saved row: an unsaved competing first turn
197
+ // is not permission to queue elsewhere. Optional absent homes remain bounded.
198
+ try {
199
+ const writer = await inspectWriter(item.codexHome, id);
200
+ candidate.activity = writer.activity;
201
+ candidate.writerLock = writer.writerLock;
202
+ if (writer.activity === 'live_writer')
203
+ candidate.reason = 'stable_live_writer';
204
+ fingerprints.push({ home: item.codexHome, database: dbFingerprint, writer: writer.identity });
205
+ }
164
206
  catch {
165
- throw new Refusal('home_inventory_unreadable', 1);
207
+ candidate.activity = 'unknown';
208
+ candidate.writerLock = 'unknown';
209
+ candidate.reason = 'active_writer_unverified';
210
+ throw new HomeRefusal('active_writer_unverified', resolution('unknown', null, 'active_writer_unverified', candidates));
166
211
  }
167
- if (saved)
168
- matches.push({ home, ...await inspectWriter(home, id) });
169
212
  }
170
- const live = matches.filter(c => c.activity === 'live_writer');
171
- if (!matches.length)
172
- throw new Refusal('thread_not_saved_in_known_homes', 2);
173
- if (live.length !== 1)
174
- throw new Refusal(live.length ? 'multiple_live_writers' : 'inactive_writer', 1);
175
- if (live[0].home !== canonical(selected))
176
- throw new Refusal('explicit_home_conflicts_with_live_writer', 1);
177
- // Include inactive competitors and inventory in the pre-submit revalidation token.
178
- return JSON.stringify({ candidates, matches });
213
+ const refuse = (code, status = 'unknown', exitCode = 1, reason = code) => {
214
+ throw new HomeRefusal(code, resolution(status, null, reason, candidates), exitCode);
215
+ };
216
+ const live = candidates.filter(c => c.activity === 'live_writer');
217
+ if (live.length > 1)
218
+ refuse('multiple_live_writers', 'ambiguous');
219
+ let chosen;
220
+ let reason;
221
+ if (live.length === 1) {
222
+ chosen = live[0];
223
+ if (explicit !== undefined && chosen.codexHome !== explicit)
224
+ refuse('explicit_home_conflicts_with_live_writer', 'ambiguous');
225
+ if (!chosen.savedThread)
226
+ refuse('thread_not_yet_persisted', 'unknown', 2);
227
+ reason = explicit === undefined ? 'single_stable_live_writer' : 'explicit_live_writer';
228
+ }
229
+ else {
230
+ if (!candidates.some(c => c.savedThread))
231
+ refuse('thread_not_saved_in_known_homes', 'unknown', 2);
232
+ const pinned = candidates.find(c => c.codexHome === explicit);
233
+ if (explicit !== undefined && !pinned?.savedThread)
234
+ refuse('thread_not_saved_in_explicit_home', 'unknown', 2);
235
+ if (!allowInactive || !pinned)
236
+ refuse('inactive_writer', 'ambiguous', 1, 'inactive_queue_requires_opt_in');
237
+ chosen = pinned;
238
+ reason = 'explicit_inactive_opt_in';
239
+ }
240
+ const result = resolution(explicit === undefined ? 'selected' : 'explicit', chosen.codexHome, reason, candidates);
241
+ // Bind all candidates (including inactive, absent and unsaved competitors),
242
+ // saved-row presence, DB identity and native owner/file evidence to revalidation.
243
+ return { home: chosen.codexHome, resolution: result, evidence: JSON.stringify({ result, fingerprints }) };
244
+ }
245
+ export async function revalidateWriter(previous, selected, id, allowInactive = false) {
246
+ const current = await resolveWriter(selected, id, allowInactive);
247
+ if (current.evidence !== previous.evidence) {
248
+ throw new HomeRefusal('writer_evidence_changed_before_queue', resolution('unknown', null, 'writer_evidence_changed_before_queue', current.resolution.candidates));
249
+ }
179
250
  }
package/docs/api.md ADDED
@@ -0,0 +1,30 @@
1
+ # API reference
2
+
3
+ [Back to README](../README.md) · [User guide](guide.md)
4
+
5
+ The package exposes a small ESM API with TypeScript declarations. Install it
6
+ locally with `npm install --ignore-scripts session-peer@0.2.1` before importing it.
7
+ Importing the package does not execute the CLI or submit a message.
8
+
9
+ ```js
10
+ import { VERSION, VERSION_LINE, reply, envelope } from 'session-peer';
11
+
12
+ console.log(VERSION); // 0.2.1
13
+ console.log(VERSION_LINE); // session-peer 0.2.1 (typescript)
14
+ const address = 'session-peer://v1/reply?agent=claude&session=12345&transport=local';
15
+ console.log(reply(address)); // { to: '12345' }
16
+ console.log(envelope('Please review and reply.', true, address));
17
+ ```
18
+
19
+ | Export | Contract |
20
+ | --- | --- |
21
+ | `VERSION` | Package version string. |
22
+ | `VERSION_LINE` | CLI version string including the TypeScript marker. |
23
+ | `reply(uri)` | Parse a supported Reply-To URI into `{ to, host?, home? }`; throw on invalid input. Parsing does not discover or authorize the destination. |
24
+ | `envelope(text, noFrom, address?)` | Trim leading/trailing newlines, optionally prepend valid Codex sender metadata from the environment, and append a validated Reply-To URI. Returns text only. |
25
+
26
+ The example uses a placeholder PID and performs no delivery. These helpers do
27
+ not verify a live writer, establish a return route, or confirm consumption.
28
+ Only the exports above form the public package API; internal `dist` modules are
29
+ not package subpath exports. Use the [CLI guide](guide.md#use) for sending and
30
+ [CONTRIBUTING.md](../CONTRIBUTING.md) for development and test setup.
@@ -0,0 +1,208 @@
1
+ # ユーザーガイド — session-peer (TypeScript)
2
+
3
+ [README に戻る](../README.ja.md)
4
+
5
+ [English](guide.md) | [한국어](guide.ko.md) | [日本語](guide.ja.md) | [简体中文](guide.zh-CN.md)
6
+
7
+ 0.2.1 の詳細ガイドです。0.2.1 は 0.2.0 の信頼性・堅牢性向上アップデートです([変更点](../PARITY.md#021-reliability-and-hardening))。前回の公開記録は [0.2.0 公開リリースの証拠](../VALIDATION.md#public-020--2026-09-28-kst) にあります。以下の 0.1.0 の説明は旧版との比較です。
8
+
9
+ ## 目次
10
+
11
+ - [機能と範囲](#機能と範囲)
12
+ - [必要条件](#必要条件)
13
+ - [インストール](#インストール)
14
+ - [使い方](#使い方)
15
+ - [成功の意味と安全性](#成功の意味と安全性)
16
+ - [開発と検証](#開発と検証)
17
+ - [npm リリース](#npm-リリース)
18
+ - [関連プロジェクト](#関連プロジェクト)
19
+ - [エージェントスキルの明示的な導入](#エージェントスキルの明示的な導入)
20
+
21
+
22
+ 実行中の **Claude Code と Codex セッション**に、ローカルまたは SSH 経由でメッセージを送る TypeScript クライアントです。Node.js で動作し、Python は不要です。
23
+
24
+ **0.2.1 の利用ガイドです。**パッケージ名は `session-peer`、CLI コマンドは **`session-peer`**。Relay サーバーやホスティングサービスは提供しません。
25
+
26
+ ## 機能と範囲
27
+
28
+ - ローカル Claude/Codex セッションと既知の Codex home の検出(0.2.0 の機能、下記参照)。
29
+ - `--dry-run` で宛先を確認し、ネイティブ inbox / queue にメッセージを一度だけ提出。Codex は一意かつ安定した live writer が必要です。
30
+ - インストール済みの同じクライアントへの SSH 接続、構造化 Reply-To URI、JSON 出力。
31
+ - 宛先や所有者が曖昧なら拒否。不確実な提出を自動再送しません。
32
+
33
+ Relay 通信、MCP、wake/resume、Antigravity、自動更新は未実装です。未対応コマンドは明示的に失敗します。汎用オーケストレーターではありません。
34
+
35
+ クライアント機能の計画は [バージョン別互換性表と npm 移行ガイド](../PARITY.md) で追跡します。計画は現在の対応を意味しません。Relay サーバーやホスティングサービスの提供は本クライアントの範囲外です。
36
+
37
+ ### 0.2.0 の統合一覧
38
+
39
+ ビルド後の `node dist/cli.js list --json` は Claude/Codex をまとめて表示し、`list --agent codex --json` は既知の home を検索します。公開 npm **0.1.0** では引き続き agent と Codex 一覧の home を明示します。0.2.0 でも明示的なコマンド形式を利用できます。
40
+
41
+ 対象は既定の `~/.codex`、`CODEX_HOME`、macOS Orca 直下のアカウント home、JSON 配列 `SESSION_PEER_CODEX_HOMES` のみです。`--codex-home` は Codex 一覧を固定して無関係な設定エラーを回避し、`--agent claude` は Codex 探索を省略します。同じ home の別名は統合し、異なる home の同じ UUID は保持します。送信には各行の `codexHome` を使ってください。任意 home の不在はエラーではなく、明示した home の不在・不正は読み取れた行を保持して終了コード 1 を返します。一覧は writer を選択せず、メッセージを提出しません。[一覧契約](../PARITY.md#source-unified-listing-contract--16--020)に順序・診断・`--all`・SSH を記載しています。0.2.0の Codex 送信は `--codex-home` 省略時に一意で安定した live writer を選択します。明示 home でも既知の競合 home をすべて検査します。非アクティブなキュー送信には保存済みスレッド、全候補の非アクティブ検証、および `--codex-home HOME --allow-inactive-codex-home` が必要で、wake/resume は実行しません。Dry-run は提出しません。JSON に診断 `codexHomeResolution` と、ネイティブ出力にある場合のみ `queueId` を追加しますが、消費確認ではありません。[選択契約](../PARITY.md#source-codex-home-selection--17--020)を参照してください。公開 **0.1.0** には明示 live home が必要で、非アクティブ許可オプションはありません。SSH 両端で同一の0.2.1 ビルドを使ってください。
42
+
43
+ ### 0.2.0 CLI の使いやすさ
44
+
45
+ 0.2.0は `list --help`、`send --help`、`doctor --help`、`--output-format text` を提供します。
46
+ 出力指定は引き続き必須です: `--json` または `--output-format json|text`。
47
+ 構文エラーは JSON、有効な text 要求の実行結果・エラーはテキストです。SSH
48
+ 内部通信は常に JSON です。`send --to TARGET "message" --json` の位置本文に
49
+ 対応し、`--message`/`-m` との併用は拒否します。本文省略または `-` は stdin、
50
+ オプション形式の位置本文には `--` を前置します。空・空白本文は送信者情報の
51
+ 追加前に拒否します。Claude 名は Unicode 14.0.0 のデフォルト full casefold
52
+ による完全一致です。正規化・曖昧検索はせず、衝突時は PID が必要です。
53
+ 公開済み 0.1.0 にこのソース機能が遡及適用されることはありません。
54
+
55
+
56
+ ## 必要条件
57
+
58
+ macOS / Linux / Windows native、Node **22.x の 22.13 以上、または 24.x**。Node 26 は対象外です。ネイティブロック依存には対応する x64/arm64 バイナリが必要で、純 JavaScript パッケージではありません。Codex 送信には `codex` が必要で、macOS/Linux では `lsof`・`ps` も必要です。Windows はネイティブロックと Restart Manager で所有者を確認します。Claude にはアクセス可能な inbox を持つ稼働中 TUI が必要です。SSH は既存の鍵・ホスト信頼と、接続先の**同一バージョン**のクライアントを使います。
59
+
60
+ ## インストール
61
+
62
+ 検証済みの安定版は、Node 22.x の 22.13 以上または 24.x でインストールできます。Python CLI も同じコマンド名を使うため、既存のインストールがあれば先に PATH を確認してください。
63
+
64
+ ```sh
65
+ npm install --global --ignore-scripts session-peer@0.2.1
66
+ session-peer --version
67
+ ```
68
+
69
+ 期待値は `session-peer 0.2.1 (typescript)`。
70
+
71
+ 1. `session-peer list --agent claude --json` で宛先を探し、正確な PID を選びます。
72
+ 2. `session-peer send --to CLAUDE_PID --message 'Please reply after checking.' --dry-run --json` で提出せずに確認します。
73
+ 3. 送る場合は選んだ PID を使い、同じコマンドから `--dry-run` を外して一度だけ実行します。
74
+ 4. ACK が必要なら本文で明示的な返信を依頼し、宛先 TUI の応答を別途確認します。`posted` / `queued` は提出のみを示します。
75
+
76
+ ### ソースからビルド
77
+
78
+ 公開済みの npm パッケージではなくレビュー済みのソースを使うには、ビルドして必要ならローカル tarball をインストールします。
79
+
80
+ ```sh
81
+ git clone https://github.com/abruption/session-peer-ts.git
82
+ cd session-peer-ts
83
+ npm ci --ignore-scripts
84
+ npm run build
85
+ node dist/cli.js --version
86
+ npm pack --ignore-scripts
87
+ # 任意のグローバルインストール前に PATH の既存コマンドを確認
88
+ npm install --global --ignore-scripts ./session-peer-0.2.1.tgz
89
+ session-peer --version
90
+ ```
91
+
92
+ `./...tgz` を省略せず、ローカルの成果物を選択してください。後のバージョンのソースを使う場合は、チェックアウトしたバージョンを先に確認してください。
93
+
94
+ ### 既存インストールとの共存
95
+
96
+ インストール前後に `type -a session-peer` と `command -v session-peer` を確認します。他の実装も同名コマンドを提供するため、PATH 上の一つを選ぶか `node /absolute/path/dist/cli.js` を使ってください。`--force` で他の管理ツールのファイルを上書きしないでください。Python パッケージ・スキル・サービスを自動変更しません。削除は `npm uninstall --global session-peer` を使い、PATH を再確認します。
97
+
98
+ Windows PowerShell では `Get-Command session-peer -All` で既存コマンドを確認します。Python CLI を置換せずに試すには、`npm ci --ignore-scripts`、`npm run build`、`npm pack --ignore-scripts` の後、`npm install --prefix "$env:TEMP\session-peer-ts-source" --ignore-scripts .\session-peer-0.2.1.tgz` を実行し、`& "$env:TEMP\session-peer-ts-source\node_modules\.bin\session-peer.cmd" --version` で確認します。同じ prefix の `npm uninstall --prefix "$env:TEMP\session-peer-ts-source" session-peer` で削除します。
99
+
100
+ ## 使い方
101
+
102
+ ```sh
103
+ session-peer list --agent claude --json
104
+ session-peer list --agent codex --codex-home "$HOME/.codex" --json
105
+ session-peer send --to CLAUDE_PID --message 'Please review the API contract.' --dry-run --json
106
+ session-peer send --to codex:THREAD_UUID --codex-home "$HOME/.codex" --message 'Please review the API contract.' --dry-run --json
107
+ ```
108
+
109
+ 実際に送るときだけ `--dry-run` を外します。`--message` の省略または `--message -` は UTF-8 stdin を読みます。`--all` は古い / アーカイブ済み記録の一覧用で、送信許可にはなりません。Claude の宛先は PID、`claude:PID`、一意な Unicode 14.0.0 casefold 名です。衝突時は PID を使います。Codex 送信には完全な UUID が必要で、home は上記の選択規則に従います。実行ファイルは `--codex-bin` で指定できます。出力には `--json` または `--output-format json|text` が必要です。
110
+
111
+ ### SSH
112
+
113
+ ```sh
114
+ session-peer send --host user@machine --remote-bin /absolute/path/session-peer \
115
+ --to CLAUDE_PID --message 'Please review the API contract.' --dry-run --json
116
+ ```
117
+
118
+ 既定のリモートコマンドは PATH の `session-peer`。絶対パスの `--remote-bin` で対応 Node を使うラッパーも指定できます。TypeScript マーカーと正確なバージョンを確認し、異なる実装は拒否します。BatchMode / StrictHostKeyChecking を使い、新しいホスト鍵の自動受理、リモートランタイムのインストール、Python フォールバックはしません。本文はリモートシェル引数ではなく JSON stdin で渡します。任意の `--ssh-opt`、IPv6 リテラル、Tailscale の正規名補完は非対応です。SSH alias / hostname を使ってください。片方向の接続成功は逆方向の接続を保証しません。
119
+
120
+ Windows の SSH 宛先では `--remote-platform win32` を指定し、必要に応じて `--remote-bin 'C:\absolute\path\session-peer.cmd'` を使います。既に認証済みの OpenSSH 制御ソケットは `--ssh-control-path /local/absolute/socket` で選択できます。ホスト鍵の確認や新しいログイン権限を回避しません。Windows ローカルの Codex home には完全な `C:\Users\...\.codex` パスを使います。既存の Python CLI は自動削除・置換しません。
121
+
122
+ ### 返信
123
+
124
+ `session-peer://v1/reply?...` URI を `--to` に指定できます。不明 / 重複フィールド、不正ホスト・エンコード、明示した経路との矛盾は拒否します。`--reply-address URI` は明示的な返信先を付けますが、経路を自動推測・検証しません。新しい返信先なしで返すときは `--no-reply-to`。有効な CODEX_THREAD_ID / CODEX_SESSION_ID は参考用 From 情報になり、`--no-from` で省略できます。不明な送信者は捏造しません。peer 情報は権限ではなく、URI をシェルとして実行しません。
125
+
126
+ ## 成功の意味と安全性
127
+
128
+ | 結果 | 意味 |
129
+ | --- | --- |
130
+ | `validated`, `submitted:false` | dry-run 成功。未送信。 |
131
+ | `posted` / `queued` | inbox 書き込み / queue 受理。**消費や ACK ではありません**。 |
132
+ | `refused`, `submitted:false` | 提出前の拒否。 |
133
+ | `unknown`, `submitted:null` | 提出済みの可能性あり。自動再送禁止。 |
134
+
135
+ 提出後に返信がない、または宛先が終了したという事実だけでは、消費や失敗を確定できません。自動再送しないでください。
136
+
137
+ `consumptionConfirmed` は常に false。実際の ACK は宛先 TUI で別途確認し、queue や transcript polling から推定しません。終了コード 0/1/2 は成功/エラー/用法エラー。エラーは固定コードで、ネイティブ stderr や本文を返しません。Codex は実際の kernel flock、ファイル同一性、同一ユーザーの所有者開始時刻を複数回調べ、提出直前にも再検証します。lock の削除や所有エージェントへのシグナル送信はしません。一覧の名前・パス・ID は共有前に伏せてください。
138
+
139
+ ## 開発と検証
140
+
141
+ ```sh
142
+ npm ci --ignore-scripts
143
+ npm run build
144
+ node scripts/check-repository.mjs
145
+ SESSION_PEER_PYTHON_ROOT=/path/to/python-reference npm test
146
+ npm run test:package
147
+ npm audit
148
+ ```
149
+
150
+ Python は開発時の互換検証基準のみです(v1.0.2、`47c23713d0a2a3c11ebde6186afd8c43489b8b65`)。実行時依存ではありません。POSIX 契約テストには C コンパイラーと lsof も必要です。CI は三つの OS で Node 22/24 を使います。macOS/Linux は固定した基準に対する全契約・パッケージ検査、Windows x64 はビルド・型検査、ネイティブ Claude inbox、保持/未保持ロック、writer 所有権と提出直前の競合、CLI queue 結果、隔離した模擬 SSH 宛先での実 PowerShell/.cmd フレーミング、パッケージのインストール・ネイティブ読込・削除と audit を実行します。これらは fixture 検査で、Windows では POSIX/Python 参照スイートを実行しません。Windows x64/Node 24 の実機 ACK は別の一回限りの証拠です。SQLite・Unix inbox・実 lock の fixture と、専用実 TUI の証拠 [VALIDATION.md](../VALIDATION.md) は別です。fixture 成功は ACK ではありません。パッケージ内容、反復 pack ハッシュ、新規インストール、アンインストールも検証します。ネイティブ依存の通常の install script は実行せず、検証した prebuilt 経路は `--ignore-scripts` を使います。SQLite 読み取り専用接続も WAL 共有メモリー管理に関与し得るため、スナップショットではありません。
151
+
152
+ [CONTRIBUTING.md](../CONTRIBUTING.md)、[RELEASING.md](../RELEASING.md)、[SECURITY.md](../SECURITY.md) を参照してください。今後のリリースの公開には別途承認が必要で、自動 npm 公開はありません。[MIT](../LICENSE) ライセンスです。
153
+
154
+ ## npm リリース
155
+
156
+ 0.2.0 は 2026-09-28 KST に公開・検証されました。[公開記録](../VALIDATION.md#public-020--2026-09-28-kst)を
157
+ 参照し、導入前に正確なバージョンと現在のタグを確認してください。
158
+
159
+ ```sh
160
+ npm view session-peer@0.2.0 version dist.integrity
161
+ npm view session-peer dist-tags
162
+ ```
163
+
164
+ 0.1.0 tarball の古い記述と検証結果は[日付付き記録](../VALIDATION.md#public-010--2026-09-27-kst)に保存しています。
165
+ OIDC staging と別途の 2FA 承認を使用します。Staging 成功は公開完了ではありません。
166
+ [RELEASING.md](../RELEASING.md) を参照してください。
167
+
168
+ ## 関連プロジェクト
169
+
170
+ [Python session-peer](https://github.com/abruption/session-peer) は独立して保守・リリースされ、任意機能や `pipx install session-peer` などの導入方法はそちらで案内します。同じ `session-peer` コマンドなので上記 PATH の注意が必要です。このクライアントはそのインストールに依存せず、全機能・フラグの同等性を約束しません。
171
+
172
+ ### 0.2.0 の読み取り専用診断
173
+
174
+ ```sh
175
+ session-peer doctor --json
176
+ session-peer doctor --agent codex --codex-home /absolute/home --json
177
+ session-peer doctor --host user@host --json
178
+ ```
179
+
180
+ 公開 npm 0.1.0 には含まれません。診断の成功(`ok:true`、終了コード 0)と
181
+ エージェントの準備状態(`ready`、エージェント・home ごとの結果)は別です。
182
+ 限定されたメタデータと実行ファイルのパスのみを確認し、Codex の実行、inbox 接続、
183
+ writer ロック取得、メッセージ送信はしません。Windows では生存プロセスによる
184
+ pipe の広告を確認するだけで、pipe の存在や接続可能性は保証しません。
185
+ `capabilities` は wake/wait/ACK と消費確認を未対応と明示します。任意の TS スキル
186
+ メタデータ検査もインストールを行いません。[診断の境界](../PARITY.md#source-read-only-doctor--18--020)
187
+ を参照してください。SSH の両端には同じソースビルドが必要です。
188
+ ## エージェントスキルの明示的な導入
189
+
190
+ 別の `session-peer-ts` スキルを関連 PR で管理します。新しい npm 公開やスキルタグではありません。公開済み 0.1.0 の基本機能に対応し、TypeScript 表示とヘルプで開発機能を確認します。Python の `session-peer` スキルは別に維持します。
191
+
192
+ [固定したスキルのソース](https://github.com/abruption/session-peer-skill/tree/081cc3c1d16a394bd92824333f4bc61c36951799/session-peer-ts)を確認してから、エージェントと導入範囲を選択してください。
193
+ 以下の例は **Codex、現在のプロジェクト** を指定します。そのプロジェクトのディレクトリで実行してください。
194
+ Claude Code では `--agent claude-code` を使用します。ユーザー単位の場合は add/list/remove の
195
+ すべてに `--global` を付けてください。既存の `session-peer-ts` を置き換える前にローカルの変更を確認してください。
196
+ Codex の `.agents/skills` は、このパスを探索する他のクライアントと共有されます。
197
+
198
+ ```sh
199
+ npx -y skills@1.7.0 add https://github.com/abruption/session-peer-skill/tree/081cc3c1d16a394bd92824333f4bc61c36951799/session-peer-ts --skill session-peer-ts --agent codex --copy --yes
200
+ npx -y skills@1.7.0 list --agent codex --json
201
+ npx -y skills@1.7.0 remove session-peer-ts --agent codex --yes
202
+ ```
203
+
204
+ 固定バージョンを更新するには、別の正確なコミットを確認し、同じエージェントと範囲で `add` を再実行します。
205
+ 一覧がキャッシュされている場合はエージェントを再起動してください。ランタイムとスキルは独立して管理されます。
206
+ npm `--ignore-scripts` は利用でき、postinstall は Skills CLI を呼び出しません。
207
+ このスキルの導入は Python スキルを上書きせず、ランタイムもインストールしません。
208
+ [互換性と検証](../PARITY.md#source-ts-skill-guidance--25--020)を参照してください。