session-peer 0.2.0 → 0.3.0

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,12 @@ 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.
75
+ export const COMPILED_INSPECTION_TIMEOUT_MS = 20000;
76
+ // The compile-free creation-time probe also exceeded 8 s on a cold runner (#78);
77
+ // discovery runs it once per listed PID, so it stays below the compiling path.
78
+ export const START_PROBE_TIMEOUT_MS = 15000;
73
79
  export function inspectWindows(mode, value) {
74
80
  if (process.platform !== 'win32')
75
81
  throw new Refusal('windows_inspection_unavailable', 1);
@@ -82,7 +88,7 @@ try {
82
88
  } catch { exit 1 }
83
89
  `;
84
90
  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 });
91
+ '$script = [Console]::In.ReadToEnd(); Invoke-Expression $script'], { input: code, encoding: 'utf8', timeout: COMPILED_INSPECTION_TIMEOUT_MS, maxBuffer: 65536, windowsHide: true });
86
92
  if (done.status !== 0 || done.error)
87
93
  throw new Refusal('windows_owner_inspection_failed', 1);
88
94
  let rows;
@@ -101,9 +107,31 @@ try {
101
107
  return rows;
102
108
  }
103
109
  export function windowsProcessStart(pid) {
110
+ if (process.platform !== 'win32' || !Number.isSafeInteger(pid) || pid <= 1 || pid > 2147483647)
111
+ return undefined;
112
+ // Claude discovery only needs the creation time. Avoid compiling Reader and
113
+ // querying CIM/GetOwnerSid for every listed PID; Codex ownership still uses
114
+ // inspectWindows above. Dispose the native process handle on every path.
115
+ const code = `
116
+ $ErrorActionPreference = 'Stop'
117
+ try {
118
+ $item = [Diagnostics.Process]::GetProcessById(${pid})
119
+ try {
120
+ if ($item.HasExited) { exit 1 }
121
+ $ticks = $item.StartTime.ToUniversalTime().ToFileTimeUtc()
122
+ [Console]::Out.WriteLine($ticks.ToString([Globalization.CultureInfo]::InvariantCulture))
123
+ } finally { $item.Dispose() }
124
+ } catch { exit 1 }
125
+ `;
104
126
  try {
105
- const rows = inspectWindows('identity', String(pid));
106
- return rows.length === 1 ? BigInt(rows[0].start) : undefined;
127
+ const done = spawnSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', code], { encoding: 'utf8', timeout: START_PROBE_TIMEOUT_MS, maxBuffer: 65536, windowsHide: true });
128
+ if (done.status !== 0 || done.error)
129
+ return undefined;
130
+ const text = done.stdout.trim();
131
+ if (!/^[1-9][0-9]{0,18}$/.test(text))
132
+ return undefined;
133
+ const ticks = BigInt(text);
134
+ return ticks <= 9223372036854775807n ? ticks : undefined;
107
135
  }
108
136
  catch {
109
137
  return undefined;
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.3.0` 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.3.0
13
+ console.log(VERSION_LINE); // session-peer 0.3.0 (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?, sender?)` | Trim leading/trailing newlines, optionally prepend sender metadata, and append a validated Reply-To URI. `sender` is `{ agent, id }` or `null` for none; when omitted, a valid Codex UUID from the environment is used. 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.