session-peer 0.5.2 → 0.6.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.
Files changed (45) hide show
  1. package/CONTRIBUTING.md +11 -5
  2. package/PARITY.md +20 -5
  3. package/README.ja.md +8 -8
  4. package/README.ko.md +8 -8
  5. package/README.md +8 -8
  6. package/README.zh-CN.md +8 -8
  7. package/RELEASING.md +116 -0
  8. package/VALIDATION.md +137 -1
  9. package/dist/cli.js +54 -4
  10. package/dist/diagnostics.js +17 -98
  11. package/dist/discovery.d.ts +32 -0
  12. package/dist/discovery.js +405 -68
  13. package/dist/handoff-operations.js +88 -34
  14. package/dist/help.js +18 -2
  15. package/dist/macos-acl.d.ts +10 -0
  16. package/dist/macos-acl.js +75 -0
  17. package/dist/output.js +6 -1
  18. package/dist/protocol.d.ts +2 -2
  19. package/dist/protocol.js +1 -1
  20. package/dist/receipt-collector.d.ts +12 -0
  21. package/dist/receipt-collector.js +283 -0
  22. package/dist/receipt-command.d.ts +10 -0
  23. package/dist/receipt-command.js +246 -0
  24. package/dist/receipt-producer.d.ts +7 -0
  25. package/dist/receipt-producer.js +107 -0
  26. package/dist/receipt-protocol.d.ts +219 -0
  27. package/dist/receipt-protocol.js +374 -0
  28. package/dist/receipt-send.d.ts +26 -0
  29. package/dist/receipt-send.js +375 -0
  30. package/dist/receipt-state.d.ts +89 -0
  31. package/dist/receipt-state.js +503 -0
  32. package/dist/receipt-store.d.ts +32 -0
  33. package/dist/receipt-store.js +286 -0
  34. package/dist/replies.js +3 -1
  35. package/dist/send.d.ts +5 -2
  36. package/dist/send.js +34 -49
  37. package/dist/skill-metadata.js +5 -3
  38. package/docs/api.md +32 -7
  39. package/docs/design/typescript-skill-compatibility.md +48 -0
  40. package/docs/guide.ja.md +41 -15
  41. package/docs/guide.ko.md +43 -17
  42. package/docs/guide.md +42 -16
  43. package/docs/guide.zh-CN.md +41 -15
  44. package/docs/shorthand.md +1 -1
  45. package/package.json +3 -3
package/dist/cli.js CHANGED
@@ -1,11 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
  import { handoffCommand, handoffSend, prepareHandoff, privateMessage } from './handoff-operations.js';
3
+ import { receiptCommand } from './receipt-command.js';
4
+ import { managedReceiptSend } from './receipt-send.js';
3
5
  import { canonicalId, closed, HANDOFF_LIMITS, HandoffBudget, parseStrictJson, parseWaitTimeout, safeInteger, systemClock } from './handoff.js';
4
6
  import { doctor } from './diagnostics.js';
5
7
  import { help } from './help.js';
6
8
  import { renderOutput } from './output.js';
7
9
  import { hostname } from 'node:os';
8
10
  import { lstatSync } from 'node:fs';
11
+ import { isAbsolute } from 'node:path';
9
12
  import { listing, Refusal } from './discovery.js';
10
13
  import { executable, run, UnknownOutcome } from './process.js';
11
14
  import { checkMessage, send, CodexUnknownOutcome } from './send.js';
@@ -16,7 +19,7 @@ import { CHANNELS, checkUpdate, noticeText, refreshCache, refuseSelfUpdate, REFR
16
19
  import { jumpOptions, sshConfig, sshJump, sshOptions } from './ssh.js';
17
20
  import { configuredHost, detectedHost, isSelf, probeReturnRoute, unsafeReturnHost, replyUri, returnHost, route, sender, tailnet } from './replies.js';
18
21
  const FLAGS = ['--json', '--all', '--dry-run', '--no-from', '--no-reply-to', '--no-update-notice', '--allow-inactive-codex-home', '--check-return-route', '--check', '--request-ack', '--observe-delivery'];
19
- const VALUES = ['--agent', '--codex-home', '--codex-bin', '--output-format', '--to', '--message', '-m', '--host', '--remote-bin', '--remote-platform', '--ssh-control-path', '--reply-address', '--ssh-opt', '--ssh-jump', '--reply-to', '--return-route-host', '--channel', '--correlation-id', '--wait-for', '--wait-timeout', '--message-file'];
22
+ const VALUES = ['--agent', '--codex-home', '--codex-bin', '--output-format', '--to', '--message', '-m', '--host', '--remote-bin', '--remote-platform', '--ssh-control-path', '--reply-address', '--ssh-opt', '--ssh-jump', '--reply-to', '--return-route-host', '--channel', '--correlation-id', '--wait-for', '--wait-timeout', '--message-file', '--receipt-collector'];
20
23
  // Repeated in order; every other value option is single.
21
24
  const REPEATED = ['--host', '--ssh-opt'];
22
25
  // Requested destinations, so a command-wide refusal can be attributed to each.
@@ -91,6 +94,16 @@ export function parse(args) {
91
94
  if (!flags.has('--json') && !values.has('--output-format'))
92
95
  throw new Refusal('json_output_required');
93
96
  const handoff = flags.has('--request-ack') || flags.has('--observe-delivery') || values.has('--correlation-id') || values.has('--wait-for') || values.has('--wait-timeout');
97
+ if (values.has('--receipt-collector')) {
98
+ const selector = values.get('--receipt-collector');
99
+ if (command !== 'send' || !isAbsolute(selector) || selector.includes('\0') || hosts.length ||
100
+ repeated.get('--ssh-opt').length || values.has('--remote-bin') || values.has('--remote-platform') ||
101
+ values.has('--ssh-control-path') || values.has('--ssh-jump') || values.has('--correlation-id') ||
102
+ flags.has('--observe-delivery') || values.get('--wait-for') === 'delivered' || flags.has('--allow-inactive-codex-home'))
103
+ throw new Refusal('inapplicable_option');
104
+ if (!flags.has('--dry-run') && !flags.has('--request-ack') && values.get('--wait-for') !== 'acknowledged')
105
+ throw new Refusal('receipt_opt_in_required', 2);
106
+ }
94
107
  if (handoff) {
95
108
  if (command !== 'send')
96
109
  throw new Refusal('inapplicable_option');
@@ -172,6 +185,8 @@ export function parse(args) {
172
185
  if (process.platform === 'win32' || values.get('--remote-platform') === 'win32')
173
186
  throw new Refusal('remote_handoff_unsupported', 1);
174
187
  }
188
+ if (values.has('--receipt-collector') && hosts.length)
189
+ throw new Refusal('remote_receipt_unsupported', 1);
175
190
  if (command === 'send' && flags.has('--allow-inactive-codex-home')) {
176
191
  if (!values.get('--to').startsWith('codex:'))
177
192
  throw new Refusal('inapplicable_option');
@@ -469,8 +484,35 @@ try {
469
484
  else if (args.length === 1 && args[0] === '--version')
470
485
  console.log(VERSION_LINE);
471
486
  else if ((args.length === 1 && ['--help', '-h'].includes(args[0])) ||
472
- (args.length === 2 && ['list', 'send', 'doctor', 'update', 'handoff', 'ack'].includes(args[0]) && ['--help', '-h'].includes(args[1])))
487
+ (args.length === 2 && ['list', 'send', 'doctor', 'update', 'handoff', 'ack', 'receipt'].includes(args[0]) && ['--help', '-h'].includes(args[1])))
473
488
  console.log(help(args.length === 2 ? args[0] : undefined));
489
+ else if (args[0] === 'receipt') {
490
+ command = 'receipt';
491
+ const operation = await receiptCommand(args, (limit, privateInput, timeoutMs) => input(limit, privateInput ?? true, timeoutMs));
492
+ console.log(JSON.stringify(operation.raw ? operation.value : { schemaVersion: 1, host: hostname(), command, ok: operation.exitCode === 0, ...operation.value }));
493
+ process.exitCode = operation.exitCode;
494
+ if (operation.collector) {
495
+ const collector = operation.collector;
496
+ let stopping = false;
497
+ const stop = (code) => {
498
+ if (stopping)
499
+ return;
500
+ stopping = true;
501
+ void collector.close().then(result => {
502
+ process.removeListener('SIGINT', interrupt);
503
+ process.removeListener('SIGTERM', terminate);
504
+ process.exitCode = code;
505
+ if (result.cleanup !== 'confirmed') {
506
+ console.error('receipt_cleanup_unconfirmed');
507
+ process.exit(code || 1);
508
+ }
509
+ }, () => { console.error('receipt_cleanup_unconfirmed'); process.exit(code || 1); });
510
+ };
511
+ const interrupt = () => stop(130), terminate = () => stop(143);
512
+ process.once('SIGINT', interrupt);
513
+ process.once('SIGTERM', terminate);
514
+ }
515
+ }
474
516
  else if (args[0] === 'handoff' || args[0] === 'ack') {
475
517
  command = args[0];
476
518
  const operation = await handoffCommand(args, limit => input(limit, true));
@@ -530,6 +572,8 @@ try {
530
572
  }
531
573
  command = ['list', 'send', 'doctor', 'update'].includes(args[0] ?? '') ? args[0] : 'unknown';
532
574
  const options = parse(args);
575
+ if (wire && options.values.has('--receipt-collector'))
576
+ throw new Refusal('remote_receipt_unsupported', 1);
533
577
  const handoffEnabled = options.flags.has('--request-ack') || options.flags.has('--observe-delivery') || options.values.has('--correlation-id') || options.values.has('--wait-for') || options.values.has('--wait-timeout');
534
578
  if (wire && (handoffEnabled !== !!wireContext || handoffEnabled !== !!wireBudget))
535
579
  throw new Refusal('remote_handoff_context_required', 1);
@@ -649,6 +693,12 @@ try {
649
693
  const enabled = options.flags.has('--request-ack') || options.flags.has('--observe-delivery') || options.values.has('--correlation-id') || options.values.has('--wait-for') || options.values.has('--wait-timeout');
650
694
  if (wireContext?.preparation)
651
695
  ({ value: result, exitCode } = await prepareHandoff(settings, undefined, options.values.get('--correlation-id'), handoffBudget));
696
+ else if (options.values.has('--receipt-collector'))
697
+ ({ value: result, exitCode } = await managedReceiptSend(settings, {
698
+ collector: options.values.get('--receipt-collector'), requestAck: options.flags.has('--request-ack'),
699
+ waitFor: options.values.get('--wait-for'),
700
+ seconds: parseWaitTimeout(options.values.get('--wait-timeout') ?? '30'), payload: rawMessage, budget: handoffBudget
701
+ }));
652
702
  else if (enabled)
653
703
  ({ value: result, exitCode } = await handoffSend(settings, { remote: wireContext !== undefined, correlationId: options.values.get('--correlation-id'), requestAck: options.flags.has('--request-ack'), observeDelivery: options.flags.has('--observe-delivery'), waitFor: options.values.get('--wait-for'), seconds: parseWaitTimeout(options.values.get('--wait-timeout') ?? '30'), payload: rawMessage, budget: handoffBudget, resultOverhead: Buffer.byteLength(JSON.stringify(routing)) + 1024 }));
654
704
  else
@@ -691,8 +741,8 @@ try {
691
741
  }
692
742
  catch (error) {
693
743
  // A command-wide refusal before dispatch applies to every requested host.
694
- if (command === 'handoff' || command === 'ack') {
695
- const failureCode = error instanceof Refusal ? error.code : 'handoff_operation_failed';
744
+ if (command === 'handoff' || command === 'ack' || command === 'receipt') {
745
+ const failureCode = error instanceof Refusal ? error.code : command === 'receipt' ? 'receipt_operation_failed' : 'handoff_operation_failed';
696
746
  console.log(JSON.stringify({ schemaVersion: 1, host: hostname(), command, ok: false, error: failureCode }));
697
747
  process.exitCode = error instanceof Refusal ? error.exitCode : 1;
698
748
  }
@@ -1,14 +1,13 @@
1
1
  // Diagnostics read bounded configuration and metadata, returning sanitized checks.
2
2
  // Never probe/connect to an inbox,
3
3
  // acquire a writer lock, execute an agent binary, or write configuration.
4
- import { accessSync, constants, readdirSync, readFileSync, statSync } from 'node:fs';
4
+ import { accessSync, constants, statSync } from 'node:fs';
5
5
  import { homedir } from 'node:os';
6
6
  import { delimiter, isAbsolute, join } from 'node:path';
7
- import { listingCandidates } from './discovery.js';
7
+ import { claudeInventory, listingCandidates } from './discovery.js';
8
8
  import { classifyCodexStorage, storageDiagnostic } from './codex-storage.js';
9
9
  import { inspectSkill } from './skill-metadata.js';
10
10
  import { batchShim } from './process.js';
11
- import { windowsProcessStart } from './windows.js';
12
11
  const failure = (error, missing, unknown) => {
13
12
  const code = error.code;
14
13
  return code === 'ENOENT' || code === 'ENOTDIR' ? { status: 'missing', code: missing } :
@@ -86,104 +85,24 @@ export async function diagnoseCodex(home, binary) {
86
85
  sendAuthorized: false };
87
86
  }
88
87
  export function diagnoseClaude() {
89
- const directory = join(process.env.CLAUDE_CONFIG_DIR || process.env.ANTHROPIC_CONFIG_DIR || join(homedir(), '.claude'), 'sessions');
90
- const result = { sessionsDir: directory, records: 0, invalidRecords: 0, aliveSessions: 0,
91
- availableInboxes: 0, staleRecords: 0, unknownInspections: 0, permissionFailures: 0 };
92
- let entries;
93
- try {
94
- if (!statSync(directory).isDirectory())
95
- return { ...result, ready: false, status: 'unsupported', code: 'sessions_path_not_directory' };
96
- entries = readdirSync(directory).sort();
97
- }
98
- catch (error) {
99
- return { ...result, ready: false, ...failure(error, 'sessions_dir_missing', 'sessions_dir_unreadable') };
100
- }
101
- for (const entry of entries) {
102
- if (!/^[0-9]+\.json$/.test(entry))
103
- continue;
104
- let record;
105
- try {
106
- const path = join(directory, entry), info = statSync(path);
107
- if (!info.isFile() || info.size > 65536) {
108
- result.invalidRecords++;
109
- continue;
110
- }
111
- const value = JSON.parse(readFileSync(path, 'utf8'));
112
- if (!value || typeof value !== 'object' || Array.isArray(value)) {
113
- result.invalidRecords++;
114
- continue;
115
- }
116
- record = value;
117
- }
118
- catch (error) {
119
- if (['EACCES', 'EPERM'].includes(error.code ?? ''))
120
- result.permissionFailures++;
121
- else if (error instanceof SyntaxError)
122
- result.invalidRecords++;
123
- else
124
- result.unknownInspections++;
125
- continue;
126
- }
127
- const pid = record.pid;
128
- if (typeof pid !== 'number' || !Number.isSafeInteger(pid) || pid <= 1 || pid > 2147483647) {
129
- result.invalidRecords++;
130
- continue;
131
- }
132
- result.records++;
133
- if (pid !== Number(entry.slice(0, -5))) {
134
- result.staleRecords++;
135
- continue;
136
- }
137
- let live = false;
138
- if (process.platform === 'win32') {
139
- const ticks = windowsProcessStart(pid);
140
- if (ticks === undefined || typeof record.startedAt !== 'number' || !Number.isSafeInteger(record.startedAt) || record.startedAt <= 0) {
141
- result.unknownInspections++;
142
- continue;
143
- }
144
- live = Number((ticks - 116444736000000000n) / 10000n) <= record.startedAt + 2000;
145
- }
146
- else {
147
- try {
148
- process.kill(pid, 0);
149
- live = true;
150
- }
151
- catch (error) {
152
- if (error.code !== 'ESRCH') {
153
- result.unknownInspections++;
154
- continue;
155
- }
156
- }
157
- }
158
- if (!live) {
159
- result.staleRecords++;
160
- continue;
161
- }
162
- result.aliveSessions++;
163
- const socket = typeof record.messagingSocketPath === 'string' ? record.messagingSocketPath : '';
164
- if (process.platform === 'win32') {
165
- // A named pipe advertisement is not proof that the pipe exists or accepts connections.
166
- if (/^\\\\\.\\pipe\\[^\r\n]+$/i.test(socket))
167
- result.availableInboxes++;
168
- }
169
- else if (socket) {
170
- try {
171
- if (statSync(socket).isSocket())
172
- result.availableInboxes++;
173
- }
174
- catch (error) {
175
- if (!['ENOENT', 'ENOTDIR'].includes(error.code ?? '')) {
176
- result.unknownInspections++;
177
- if (['EACCES', 'EPERM'].includes(error.code ?? ''))
178
- result.permissionFailures++;
179
- }
180
- }
181
- }
88
+ const inventory = claudeInventory(), rows = inventory.sessions;
89
+ const result = { sessionsDir: inventory.directories[0], records: inventory.records,
90
+ invalidRecords: inventory.invalidRecords, aliveSessions: rows.filter(row => row.alive).length,
91
+ availableInboxes: rows.filter(row => row.reachable).length,
92
+ staleRecords: rows.filter(row => !row.alive && row.staleReason !== 'process_unverified').length,
93
+ unknownInspections: inventory.unknownInspections, permissionFailures: inventory.permissionFailures };
94
+ if (inventory.selectedStatus !== 'present' && (inventory.selectedStatus !== 'missing' || inventory.errors.length === 0) &&
95
+ rows.length === 0 && inventory.directories.length === 1) {
96
+ const status = inventory.selectedStatus;
97
+ return { ...result, ready: false, status, code: status === 'missing' ? 'sessions_dir_missing' :
98
+ status === 'unsupported' ? 'sessions_path_not_directory' : status === 'permission_denied' ? 'permission_denied' : 'sessions_dir_unreadable' };
182
99
  }
183
- const ready = result.availableInboxes > 0 && result.permissionFailures === 0 && result.unknownInspections === 0;
100
+ const ready = result.availableInboxes > 0 && inventory.errors.length === 0 && result.unknownInspections === 0;
184
101
  const code = result.permissionFailures ? 'permission_denied' : result.unknownInspections ? 'inspection_unknown' :
185
- result.availableInboxes ? 'inbox_advertised' : result.aliveSessions ? 'inbox_unavailable' : 'no_live_sessions';
102
+ inventory.errors.length ? 'claude_discovery_incomplete' : result.availableInboxes ? 'inbox_advertised' :
103
+ result.aliveSessions ? 'inbox_unavailable' : 'no_live_sessions';
186
104
  return { ...result, ready, status: ready ? 'available' : 'unavailable', code,
105
+ ...(inventory.errors.length ? { errors: inventory.errors } : {}),
187
106
  verification: process.platform === 'win32' ? 'process_and_pipe_advertisement' : 'process_and_filesystem',
188
107
  inboxConnected: false, sendAuthorized: false };
189
108
  }
@@ -5,6 +5,38 @@ export declare class Refusal extends Error {
5
5
  constructor(code: string, exitCode?: number);
6
6
  }
7
7
  export declare function canonical(path: string): string;
8
+ export declare const CLAUDE_PROFILE_LIMIT = 128;
9
+ export declare const CLAUDE_ENTRY_LIMIT = 4096;
10
+ export declare const CLAUDE_ACL_LIMITS: Readonly<{
11
+ paths: 4481;
12
+ batchPaths: 128;
13
+ argumentBytes: 32768;
14
+ batchOutput: 262144;
15
+ totalOutput: 8388608;
16
+ batches: 128;
17
+ timeoutMs: 5000;
18
+ }>;
19
+ export type ClaudeInventory = {
20
+ sessions: Row[];
21
+ errors: string[];
22
+ directories: string[];
23
+ records: number;
24
+ invalidRecords: number;
25
+ permissionFailures: number;
26
+ unknownInspections: number;
27
+ selectedStatus: 'present' | 'missing' | 'unsupported' | 'permission_denied' | 'unknown';
28
+ };
29
+ export declare function claudeInventory(): ClaudeInventory;
30
+ export declare function revalidateClaudeInventory(row: Row, other?: Row): void;
31
+ export declare function claudeSelectionIdentity(row: Row): string;
32
+ export type ClaudeReceiptProvenance = Readonly<{
33
+ registryDirectory: string;
34
+ registryRecordPath: string;
35
+ registryIdentity: string;
36
+ socketPath: string;
37
+ routeIdentity: string;
38
+ }>;
39
+ export declare function claudeReceiptProvenance(row: Row): ClaudeReceiptProvenance;
8
40
  export declare function claude(all: boolean): Row;
9
41
  export declare function configuredHomePaths(): string[];
10
42
  export declare function orcaHomePaths(): string[];