session-peer 0.5.0 → 0.5.2
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/CONTRIBUTING.md +26 -0
- package/PARITY.md +133 -1
- package/README.ja.md +13 -10
- package/README.ko.md +13 -10
- package/README.md +13 -10
- package/README.zh-CN.md +13 -10
- package/RELEASING.md +122 -0
- package/VALIDATION.md +80 -2
- package/dist/app-server.d.ts +10 -2
- package/dist/app-server.js +115 -53
- package/dist/codex-storage.d.ts +46 -0
- package/dist/codex-storage.js +447 -0
- package/dist/diagnostics.js +7 -5
- package/dist/discovery.d.ts +0 -1
- package/dist/discovery.js +1 -22
- package/dist/handoff-operations.js +17 -7
- package/dist/process.d.ts +1 -0
- package/dist/process.js +1 -1
- package/dist/protocol.d.ts +2 -2
- package/dist/protocol.js +1 -1
- package/dist/send.d.ts +9 -1
- package/dist/send.js +132 -15
- package/dist/skill-metadata.js +5 -3
- package/docs/api.md +130 -7
- package/docs/design/remote-deployment.md +8 -0
- package/docs/design/typescript-skill-compatibility.md +39 -1
- package/docs/guide.ja.md +21 -15
- package/docs/guide.ko.md +24 -19
- package/docs/guide.md +22 -16
- package/docs/guide.zh-CN.md +21 -15
- package/docs/shorthand.md +1 -1
- package/package.json +5 -3
package/VALIDATION.md
CHANGED
|
@@ -1,4 +1,82 @@
|
|
|
1
|
-
# Validation record — updated 2026-10-
|
|
1
|
+
# Validation record — updated 2026-10-30 KST
|
|
2
|
+
|
|
3
|
+
## 0.5.2 preparation scope — 2026-10-30 KST
|
|
4
|
+
|
|
5
|
+
Preparation baseline is merged main
|
|
6
|
+
`1b9e762c154e1050b04f98d5c36cee0d332cf484`: #169's storage guards, scoped parity
|
|
7
|
+
matrix and current-version maintenance, plus #160's repository-only local static
|
|
8
|
+
qualification reporter. This release preparation selects package/banner/current
|
|
9
|
+
examples 0.5.2 and one finite doctor row preserving the four exact 0.5.1 skill
|
|
10
|
+
profiles. Historical evidence, the ordinary Python 1.1.0 oracle, frozen handoff
|
|
11
|
+
fixtures, native observation profiles and independent skill pins stay separate.
|
|
12
|
+
|
|
13
|
+
The guarded local loader-source versions are Codex 0.160.1, 0.162.1 and 0.165.0.
|
|
14
|
+
Source review and fixture refusal tests are not new native submission, positive
|
|
15
|
+
managed-preference/MDM, Linux/Windows observation, live delivery or ACK
|
|
16
|
+
qualification. Ordinary signed-in file-auth/keyring/cloud-unclassifiable homes
|
|
17
|
+
can refuse even when their accounts would not receive cloud policy. Windows
|
|
18
|
+
Codex send/dry-run remain unqualified and refuse before submission; ordinary
|
|
19
|
+
Claude behavior is separate. The owned stdio route requires its actual opened
|
|
20
|
+
storage binding. Existing unknown/no-resend and explicit operator-confirmed
|
|
21
|
+
receipt boundaries are retained.
|
|
22
|
+
|
|
23
|
+
The reporter measures only operator-selected local static metadata/digests and
|
|
24
|
+
keeps execution/ownership/qualification predicates independent. Its source
|
|
25
|
+
script, tests and two review/design documents are excluded from the npm archive;
|
|
26
|
+
it is not an installed command, SDK API, readiness certificate, deployment or
|
|
27
|
+
cleanup engine. Draft #155 and experiments #82/#142 remain excluded. The
|
|
28
|
+
remaining remote/platform acceptance gates in #20/#23/#130/#131/#132 are not
|
|
29
|
+
completed by this release preparation.
|
|
30
|
+
|
|
31
|
+
For source provenance, #169's reviewed head
|
|
32
|
+
`76f556cca869da95ad4368af914bad6f0f43af3d` passed its current-head matrix and
|
|
33
|
+
release gate; its macOS Node 24 retry followed an execution-free hosted-runner
|
|
34
|
+
capacity cancellation. #160's integrated head
|
|
35
|
+
`d2760958ebf5f1f160fb716af54e63dabcce8862` passed 12 checks in
|
|
36
|
+
[run 40980450661](https://github.com/abruption/session-peer-ts/actions/runs/40980450661).
|
|
37
|
+
Its local full suite recorded 503 tests: 491 pass, 0 fail, 11 platform skips and
|
|
38
|
+
1 existing TODO. The earlier integrated macOS Node 24 result had observation
|
|
39
|
+
`unsupported` instead of `pending`; the original cause remains unconfirmed.
|
|
40
|
+
The follow-up added assertion diagnostics only and did not relax outcomes,
|
|
41
|
+
deadlines or product guards. A later pass does not establish that original cause.
|
|
42
|
+
These 0.5.1 implementation-head results do not substitute for final 0.5.2
|
|
43
|
+
source, package, profile and exact merged-main checks.
|
|
44
|
+
|
|
45
|
+
At this dated preparation checkpoint the public registry baseline is
|
|
46
|
+
latest=0.5.1, preview=0.1.0-preview.1 and target 0.5.2 absent. Fresh authenticated
|
|
47
|
+
publisher/MFA/pending-stage checks, final-source approval, staging and publication
|
|
48
|
+
belong to their separate release gates. No new live-host/native/model/ACK
|
|
49
|
+
experiment, existing user-session input, global installation or operational
|
|
50
|
+
change is claimed. Final release-preparation PR and artifact records must name
|
|
51
|
+
the exact tested source and bytes before source/publication approval.
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
## 0.5.1 dependency patch preparation — 2026-10-27 KST
|
|
55
|
+
|
|
56
|
+
Baseline source: main `028780338310c9cfe469e1e1587857f730e99a1a`.
|
|
57
|
+
The only intervening change from public 0.5.0 is README download-badge wording.
|
|
58
|
+
Fresh npm advisory bulk checks across current main and the four open PR locks
|
|
59
|
+
reported no advisory; open Dependabot and CodeQL alerts were empty. The scheduled
|
|
60
|
+
[audit run](https://github.com/abruption/session-peer-ts/actions/runs/40295976850)
|
|
61
|
+
on that exact main passed npm audit and signature/provenance checks on 2026-10-26.
|
|
62
|
+
These facts do not prove the absence of every vulnerability.
|
|
63
|
+
|
|
64
|
+
The actionable dependency defect is official smol-toml 1.9.1's
|
|
65
|
+
[repeated-exponent-sign fix](https://github.com/squirrelchat/smol-toml/releases/tag/v1.9.1).
|
|
66
|
+
With installed 1.9.0, `foo=3e++20` and `foo=3e--20` both produced `{foo:3}`.
|
|
67
|
+
Two new doctor/transport regressions failed before the update: doctor reported
|
|
68
|
+
`available` instead of `unknown`, and send/dry-run did not report
|
|
69
|
+
`codex_config_unreadable`. With pinned 1.9.1 both regressions pass, including
|
|
70
|
+
root/nested invalid numbers, valid single-sign controls and no fixture queue call
|
|
71
|
+
on refusal. This establishes incorrect malformed-config handling, not an actual
|
|
72
|
+
relocated-storage bypass, credential exposure or live-agent exploit.
|
|
73
|
+
|
|
74
|
+
The tests use isolated fixture homes/queues. No existing user session, remote
|
|
75
|
+
host, global installation or native/model/ACK experiment is used. Full package,
|
|
76
|
+
profile/release and current-head CI results belong to the patch PR and its exact
|
|
77
|
+
source. This dated preparation record does not claim publication or fresh npm
|
|
78
|
+
publisher/MFA settings approval.
|
|
79
|
+
|
|
2
80
|
|
|
3
81
|
## 0.5.0 preparation scope — 2026-10-20 KST
|
|
4
82
|
|
|
@@ -1568,7 +1646,7 @@ All three operating systems run Node 22/24. The checks differ:
|
|
|
1568
1646
|
| Platform | Automated scope |
|
|
1569
1647
|
| --- | --- |
|
|
1570
1648
|
| macOS/Linux | Full contract suite, type checks, Python reference fixtures, package smoke, release pack/artifact checks and audit. |
|
|
1571
|
-
| Windows x64 | Build/type checks, Claude named-pipe/auth/stale-record fixtures, held/free kernel locks, writer ownership and pre-submit races, native
|
|
1649
|
+
| Windows x64 | Build/type checks, Claude named-pipe/auth/stale-record fixtures, held/free kernel locks, writer ownership and pre-submit races, Codex storage-refusal fixtures and synthetic native-exit/SSH response outcomes, PowerShell/.cmd SSH framing through a fake endpoint, package/native-load smoke and audit. |
|
|
1572
1650
|
|
|
1573
1651
|
Windows runs its native suite, not the POSIX/Python reference suite. Both
|
|
1574
1652
|
Windows Node jobs are required by the aggregate release gate. The x64/Node 24
|
package/dist/app-server.d.ts
CHANGED
|
@@ -98,6 +98,8 @@ export type NativeQueueOptions = {
|
|
|
98
98
|
deadlineMs: number;
|
|
99
99
|
verifyOwner: (scope: AppServerScope) => Promise<boolean>;
|
|
100
100
|
beforeEffect: () => Promise<void>;
|
|
101
|
+
verifyStorage?: () => Promise<void>;
|
|
102
|
+
verifyStorageSync?: () => void;
|
|
101
103
|
env?: NodeJS.ProcessEnv;
|
|
102
104
|
};
|
|
103
105
|
export declare function nativeQueueCapability(context: AppServerContext): {
|
|
@@ -148,6 +150,7 @@ export declare class BoundedAppServerClient implements AppServerPort {
|
|
|
148
150
|
private readonly verifyOwner;
|
|
149
151
|
private readonly nativeQueue;
|
|
150
152
|
private readonly beforeEffect;
|
|
153
|
+
private readonly beforeWrite;
|
|
151
154
|
private readonly pending;
|
|
152
155
|
private readonly observers;
|
|
153
156
|
private readonly operations;
|
|
@@ -169,7 +172,7 @@ export declare class BoundedAppServerClient implements AppServerPort {
|
|
|
169
172
|
private constructor();
|
|
170
173
|
static connectMetadataFixture(scope: AppServerScope, transport: MetadataOnlyTransport, deadlineMs: number, verifyOwner: (scope: AppServerScope) => Promise<boolean>): Promise<BoundedAppServerClient>;
|
|
171
174
|
static connectNativeQueueFixture(scope: AppServerScope, transport: MetadataOnlyTransport, deadlineMs: number, verifyOwner: (scope: AppServerScope) => Promise<boolean>, beforeEffect: () => Promise<void>, nativeVersion?: string, platform?: string, profiles?: readonly NativeProfile[]): Promise<NativeQueuePort>;
|
|
172
|
-
static connectNativeQueueWire(scope: AppServerScope, transport: NativeQueueTransport, deadlineMs: number, verifyOwner: (scope: AppServerScope) => Promise<boolean>, beforeEffect: () => Promise<void>, profile: NativeProfile): Promise<NativeQueuePort>;
|
|
175
|
+
static connectNativeQueueWire(scope: AppServerScope, transport: NativeQueueTransport, deadlineMs: number, verifyOwner: (scope: AppServerScope) => Promise<boolean>, beforeEffect: () => Promise<void>, profile: NativeProfile, beforeWrite: () => void): Promise<NativeQueuePort>;
|
|
173
176
|
private static connectWire;
|
|
174
177
|
private check;
|
|
175
178
|
private owner;
|
|
@@ -193,8 +196,13 @@ export declare class BoundedAppServerClient implements AppServerPort {
|
|
|
193
196
|
private fail;
|
|
194
197
|
close(): Promise<void>;
|
|
195
198
|
}
|
|
199
|
+
type SqliteBindingProof = readonly Readonly<{
|
|
200
|
+
path: string;
|
|
201
|
+
dev: bigint | null;
|
|
202
|
+
ino: bigint | null;
|
|
203
|
+
}>[];
|
|
196
204
|
export declare function artifactDigest(path: string, deadlineMs: number, maxBytes?: number): Promise<string>;
|
|
197
|
-
export declare function verifyProcfsSqliteBinding(pid: number | undefined, home: string, deadlineMs: number, binary: string, reader?: ProcReader): Promise<
|
|
205
|
+
export declare function verifyProcfsSqliteBinding(pid: number | undefined, home: string, deadlineMs: number, binary: string, reader?: ProcReader): Promise<SqliteBindingProof>;
|
|
198
206
|
export declare function nativeQueueOnce(options: NativeQueueOptions): Promise<{
|
|
199
207
|
queueId: string;
|
|
200
208
|
clientUserMessageId: string;
|
package/dist/app-server.js
CHANGED
|
@@ -13,6 +13,7 @@ import { basename, isAbsolute, join } from 'node:path';
|
|
|
13
13
|
import { performance } from 'node:perf_hooks';
|
|
14
14
|
import { TextDecoder } from 'node:util';
|
|
15
15
|
import { run } from './process.js';
|
|
16
|
+
import { classifyCodexStorage, codexConsumerCwd, codexConsumerSnapshotSync, codexStoragePin, decodeLsofFilename } from './codex-storage.js';
|
|
16
17
|
import { CANDIDATE_PROFILES, NATIVE_PROFILES, platformProfiled, selectNativeProfile, validateNativeProfiles } from './native-profiles.js';
|
|
17
18
|
import { procOwnedFiles } from './linux-proc.js';
|
|
18
19
|
import { fileURLToPath } from 'node:url';
|
|
@@ -286,6 +287,7 @@ export class BoundedAppServerClient {
|
|
|
286
287
|
verifyOwner;
|
|
287
288
|
nativeQueue;
|
|
288
289
|
beforeEffect;
|
|
290
|
+
beforeWrite;
|
|
289
291
|
pending = new Map();
|
|
290
292
|
observers = new Set();
|
|
291
293
|
operations = new Set();
|
|
@@ -304,13 +306,14 @@ export class BoundedAppServerClient {
|
|
|
304
306
|
fault;
|
|
305
307
|
closing;
|
|
306
308
|
timer;
|
|
307
|
-
constructor(scope, transport, deadlineMs, verifyOwner, nativeQueue = false, beforeEffect = async () => { }) {
|
|
309
|
+
constructor(scope, transport, deadlineMs, verifyOwner, nativeQueue = false, beforeEffect = async () => { }, beforeWrite = () => { }) {
|
|
308
310
|
this.scope = scope;
|
|
309
311
|
this.transport = transport;
|
|
310
312
|
this.deadlineMs = deadlineMs;
|
|
311
313
|
this.verifyOwner = verifyOwner;
|
|
312
314
|
this.nativeQueue = nativeQueue;
|
|
313
315
|
this.beforeEffect = beforeEffect;
|
|
316
|
+
this.beforeWrite = beforeWrite;
|
|
314
317
|
this.timer = setTimeout(() => this.fail('deadline'), Math.max(1, deadlineMs - performance.now()));
|
|
315
318
|
transport.input.on('data', this.receive);
|
|
316
319
|
transport.input.once('end', this.ended);
|
|
@@ -327,10 +330,10 @@ export class BoundedAppServerClient {
|
|
|
327
330
|
static async connectNativeQueueFixture(scope, transport, deadlineMs, verifyOwner, beforeEffect, nativeVersion = APP_SERVER_EVIDENCE.version, platform = APP_SERVER_EVIDENCE.inspectedPlatform, profiles = NATIVE_PROFILES) {
|
|
328
331
|
return this.connectWire(scope, transport, deadlineMs, verifyOwner, true, beforeEffect, selectNativeProfile({ platform, version: nativeVersion }, validateNativeProfiles(profiles)));
|
|
329
332
|
}
|
|
330
|
-
static async connectNativeQueueWire(scope, transport, deadlineMs, verifyOwner, beforeEffect, profile) {
|
|
331
|
-
return this.connectWire(scope, transport, deadlineMs, verifyOwner, true, beforeEffect, profile);
|
|
333
|
+
static async connectNativeQueueWire(scope, transport, deadlineMs, verifyOwner, beforeEffect, profile, beforeWrite) {
|
|
334
|
+
return this.connectWire(scope, transport, deadlineMs, verifyOwner, true, beforeEffect, profile, beforeWrite);
|
|
332
335
|
}
|
|
333
|
-
static async connectWire(scope, transport, deadlineMs, verifyOwner, nativeQueue, beforeEffect = async () => { }, profile) {
|
|
336
|
+
static async connectWire(scope, transport, deadlineMs, verifyOwner, nativeQueue, beforeEffect = async () => { }, profile, beforeWrite) {
|
|
334
337
|
let original;
|
|
335
338
|
try {
|
|
336
339
|
original = scopeValue(scope);
|
|
@@ -348,7 +351,7 @@ export class BoundedAppServerClient {
|
|
|
348
351
|
await disposeTransport(transport);
|
|
349
352
|
throw new AppServerFault('deadline', false);
|
|
350
353
|
}
|
|
351
|
-
const client = new BoundedAppServerClient(original, transport, deadlineMs, verifyOwner, nativeQueue, beforeEffect);
|
|
354
|
+
const client = new BoundedAppServerClient(original, transport, deadlineMs, verifyOwner, nativeQueue, beforeEffect, beforeWrite);
|
|
352
355
|
try {
|
|
353
356
|
await client.owner();
|
|
354
357
|
if (nativeQueue) {
|
|
@@ -404,9 +407,9 @@ export class BoundedAppServerClient {
|
|
|
404
407
|
return new Promise((resolve, reject) => {
|
|
405
408
|
const wait = { reject };
|
|
406
409
|
this.operations.add(wait);
|
|
407
|
-
promise.then(value => { this.operations.delete(wait); resolve(value); },
|
|
410
|
+
promise.then(value => { this.operations.delete(wait); resolve(value); }, error => {
|
|
408
411
|
this.operations.delete(wait);
|
|
409
|
-
this.fail(failureCode);
|
|
412
|
+
this.fail(error instanceof AppServerFault ? error.code : failureCode);
|
|
410
413
|
reject(this.fault);
|
|
411
414
|
});
|
|
412
415
|
});
|
|
@@ -542,6 +545,7 @@ export class BoundedAppServerClient {
|
|
|
542
545
|
// owner after that await, before marking an attempt or writing the RPC.
|
|
543
546
|
// The ledger may already be fenced; this never authorizes a new effect.
|
|
544
547
|
await this.owner();
|
|
548
|
+
this.beforeWrite();
|
|
545
549
|
this.check();
|
|
546
550
|
}
|
|
547
551
|
return new Promise((resolve, reject) => {
|
|
@@ -668,7 +672,7 @@ async function beforeDeadline(deadlineMs, operation, code) {
|
|
|
668
672
|
async function verifyOwnedSqliteBinding(pid, home, deadlineMs) {
|
|
669
673
|
if (!pid || pid < 2 || performance.now() >= deadlineMs)
|
|
670
674
|
throw new AppServerFault('storage_binding_unverified', false);
|
|
671
|
-
verifyOpenedSqlite(await darwinOpenedFiles(pid, deadlineMs), home);
|
|
675
|
+
return verifyOpenedSqlite(await darwinOpenedFiles(pid, deadlineMs), home);
|
|
672
676
|
}
|
|
673
677
|
async function darwinOpenedFiles(pid, deadlineMs) {
|
|
674
678
|
// Only the owned app-server PID is queried, never a session inventory/PID scan.
|
|
@@ -694,8 +698,14 @@ async function darwinOpenedFiles(pid, deadlineMs) {
|
|
|
694
698
|
current = {};
|
|
695
699
|
files.push(current);
|
|
696
700
|
}
|
|
697
|
-
else if (current && field.startsWith('n'))
|
|
698
|
-
|
|
701
|
+
else if (current && field.startsWith('n')) {
|
|
702
|
+
try {
|
|
703
|
+
current.name = decodeLsofFilename(field.slice(1));
|
|
704
|
+
}
|
|
705
|
+
catch {
|
|
706
|
+
throw new AppServerFault('storage_binding_unverified', false);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
699
709
|
else if (current && /^D0x[0-9a-f]+$/i.test(field))
|
|
700
710
|
current.dev = BigInt(field.slice(1));
|
|
701
711
|
else if (current && /^i[0-9]+$/.test(field))
|
|
@@ -707,6 +717,7 @@ async function darwinOpenedFiles(pid, deadlineMs) {
|
|
|
707
717
|
// be opened by the owned PID with the inode now at that canonical path.
|
|
708
718
|
function verifyOpenedSqlite(files, home) {
|
|
709
719
|
const required = ['state_5.sqlite', 'queue_1.sqlite'];
|
|
720
|
+
const proof = new Map();
|
|
710
721
|
for (const file of required) {
|
|
711
722
|
const expected = join(home, file);
|
|
712
723
|
const opened = files.filter(row => row.name && [file, file + '-wal', file + '-shm'].includes(basename(row.name)));
|
|
@@ -719,12 +730,52 @@ function verifyOpenedSqlite(files, home) {
|
|
|
719
730
|
const canonical = lstatSync(row.name, { bigint: true });
|
|
720
731
|
if (!canonical.isFile() || canonical.isSymbolicLink() || row.dev !== canonical.dev || row.ino !== canonical.ino)
|
|
721
732
|
throw new Error('storage identity changed');
|
|
733
|
+
const prior = proof.get(row.name);
|
|
734
|
+
if (prior && (prior.dev !== row.dev || prior.ino !== row.ino))
|
|
735
|
+
throw new Error('conflicting opened identities');
|
|
736
|
+
// Retain the opened FD's identity, not a later sample of the pathname.
|
|
737
|
+
proof.set(row.name, Object.freeze({ path: row.name, dev: row.dev, ino: row.ino }));
|
|
722
738
|
}
|
|
723
739
|
catch {
|
|
724
740
|
throw new AppServerFault('storage_binding_unverified', false);
|
|
725
741
|
}
|
|
726
742
|
}
|
|
727
743
|
}
|
|
744
|
+
// The fixed WAL/SHM paths may not be opened yet. Retain their named presence
|
|
745
|
+
// and identity too, without claiming FD evidence for these additional paths.
|
|
746
|
+
for (const file of required)
|
|
747
|
+
for (const suffix of ['', '-wal', '-shm']) {
|
|
748
|
+
const path = join(home, file + suffix);
|
|
749
|
+
if (proof.has(path))
|
|
750
|
+
continue;
|
|
751
|
+
try {
|
|
752
|
+
const info = lstatSync(path, { bigint: true });
|
|
753
|
+
if (!info.isFile() || info.isSymbolicLink())
|
|
754
|
+
throw new Error();
|
|
755
|
+
proof.set(path, Object.freeze({ path, dev: info.dev, ino: info.ino }));
|
|
756
|
+
}
|
|
757
|
+
catch (error) {
|
|
758
|
+
if (error.code !== 'ENOENT')
|
|
759
|
+
throw new AppServerFault('storage_binding_unverified', false);
|
|
760
|
+
proof.set(path, Object.freeze({ path, dev: null, ino: null }));
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
return Object.freeze([...proof.values()]);
|
|
764
|
+
}
|
|
765
|
+
function revalidateSqliteBinding(proof) {
|
|
766
|
+
if (!proof)
|
|
767
|
+
throw new AppServerFault('storage_binding_unverified', false);
|
|
768
|
+
for (const expected of proof) {
|
|
769
|
+
try {
|
|
770
|
+
const info = lstatSync(expected.path, { bigint: true });
|
|
771
|
+
if (!info.isFile() || info.isSymbolicLink() || info.dev !== expected.dev || info.ino !== expected.ino)
|
|
772
|
+
throw new Error();
|
|
773
|
+
}
|
|
774
|
+
catch (error) {
|
|
775
|
+
if (expected.dev !== null || error.code !== 'ENOENT')
|
|
776
|
+
throw new AppServerFault('storage_binding_unverified', false);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
728
779
|
}
|
|
729
780
|
// Synchronous native-profile I/O (executable digest, procfs walk) runs in an
|
|
730
781
|
// owned worker. Supervisor refusal boundary for that worker only: run()
|
|
@@ -797,38 +848,7 @@ export async function verifyProcfsSqliteBinding(pid, home, deadlineMs, binary, r
|
|
|
797
848
|
}
|
|
798
849
|
if (performance.now() >= deadlineMs)
|
|
799
850
|
throw new AppServerFault('deadline', false);
|
|
800
|
-
verifyOpenedSqlite(files, home);
|
|
801
|
-
}
|
|
802
|
-
// lsof field output escapes backslashes and non-ASCII bytes even with NUL field
|
|
803
|
-
// delimiters. Decode the protected system tool's filename representation, then
|
|
804
|
-
// compare exact canonical paths; never accept a prefix/substring match.
|
|
805
|
-
function lsofFilename(raw) {
|
|
806
|
-
const bytes = [];
|
|
807
|
-
for (let i = 0; i < raw.length; i++) {
|
|
808
|
-
if (raw[i] !== '\\') {
|
|
809
|
-
const char = String.fromCodePoint(raw.codePointAt(i));
|
|
810
|
-
bytes.push(...Buffer.from(char));
|
|
811
|
-
i += char.length - 1;
|
|
812
|
-
continue;
|
|
813
|
-
}
|
|
814
|
-
const next = raw[++i];
|
|
815
|
-
if (next === '\\') {
|
|
816
|
-
bytes.push(92);
|
|
817
|
-
continue;
|
|
818
|
-
}
|
|
819
|
-
if (next === 'x' && /^[0-9a-f]{2}$/i.test(raw.slice(i + 1, i + 3))) {
|
|
820
|
-
bytes.push(parseInt(raw.slice(i + 1, i + 3), 16));
|
|
821
|
-
i += 2;
|
|
822
|
-
continue;
|
|
823
|
-
}
|
|
824
|
-
throw new AppServerFault('storage_binding_unverified', false);
|
|
825
|
-
}
|
|
826
|
-
try {
|
|
827
|
-
return new TextDecoder('utf-8', { fatal: true }).decode(Buffer.from(bytes));
|
|
828
|
-
}
|
|
829
|
-
catch {
|
|
830
|
-
throw new AppServerFault('storage_binding_unverified', false);
|
|
831
|
-
}
|
|
851
|
+
return verifyOpenedSqlite(files, home);
|
|
832
852
|
}
|
|
833
853
|
function executableIdentity(binary) {
|
|
834
854
|
try {
|
|
@@ -870,21 +890,39 @@ export async function nativeQueueOnceWithProfiles(options, table) {
|
|
|
870
890
|
// Reject malformed effect input before even a version probe or bootstrap can
|
|
871
891
|
// start the binary and access/create native files in the selected home.
|
|
872
892
|
validateQueueInput(options, false);
|
|
873
|
-
// In the qualified versions config.sqlite_home precedes CODEX_SQLITE_HOME. Pin BOTH env and
|
|
874
|
-
// a quoted CLI value so an ordinary config A->B->A load cannot redirect us.
|
|
875
|
-
// Managed policy can still supersede the CLI pin, hence the FD-path check.
|
|
876
|
-
const env = { ...(options.env ?? process.env), CODEX_HOME: original.codexHome,
|
|
877
|
-
CODEX_SQLITE_HOME: original.codexHome };
|
|
878
893
|
if (!await beforeDeadline(options.deadlineMs, () => options.verifyOwner(original), 'owner_changed'))
|
|
879
894
|
throw new AppServerFault('owner_changed', false);
|
|
880
895
|
if (performance.now() >= options.deadlineMs)
|
|
881
896
|
throw new AppServerFault('deadline', false);
|
|
897
|
+
const consumerCwd = await codexConsumerCwd(original.codexHome, original.threadId).catch(() => {
|
|
898
|
+
throw new AppServerFault('storage_binding_unverified', false);
|
|
899
|
+
});
|
|
900
|
+
const checkStorage = (version) => {
|
|
901
|
+
const value = classifyCodexStorage({ home: original.codexHome, queueCwd: original.codexHome,
|
|
902
|
+
consumerCwds: [consumerCwd], ownedAppServer: true, version, environment: options.env ?? process.env });
|
|
903
|
+
if (value.status !== 'classified')
|
|
904
|
+
throw new AppServerFault('storage_binding_unverified', false);
|
|
905
|
+
return value;
|
|
906
|
+
};
|
|
907
|
+
const initialStorage = checkStorage();
|
|
908
|
+
const consumerDatabase = codexConsumerSnapshotSync(original.codexHome, original.threadId).database;
|
|
909
|
+
const revalidateStorage = async (version) => {
|
|
910
|
+
if (await codexConsumerCwd(original.codexHome, original.threadId).catch(() => '') !== consumerCwd ||
|
|
911
|
+
checkStorage(version).fingerprint !== initialStorage.fingerprint)
|
|
912
|
+
throw new AppServerFault('storage_binding_unverified', false);
|
|
913
|
+
};
|
|
914
|
+
// In the qualified versions config.sqlite_home precedes CODEX_SQLITE_HOME. Pin BOTH env and
|
|
915
|
+
// a quoted CLI value so an ordinary config A->B->A load cannot redirect us.
|
|
916
|
+
// Managed policy can still supersede the CLI pin, hence the FD-path check.
|
|
917
|
+
const inherited = Object.fromEntries(Object.entries(options.env ?? process.env).filter(([key]) => !['CODEX_HOME', 'CODEX_SQLITE_HOME'].includes(key.toUpperCase())));
|
|
918
|
+
const env = { ...inherited, CODEX_HOME: original.codexHome,
|
|
919
|
+
CODEX_SQLITE_HOME: original.codexHome, PWD: initialStorage.queueCwd };
|
|
882
920
|
const binaryIdentity = executableIdentity(options.binary);
|
|
883
921
|
const probeRemaining = options.deadlineMs - performance.now();
|
|
884
922
|
if (probeRemaining <= 0)
|
|
885
923
|
throw new AppServerFault('deadline', false);
|
|
886
924
|
const version = await run(options.binary, ['--version'], {
|
|
887
|
-
env, timeout: probeRemaining, limit: 4096,
|
|
925
|
+
env, cwd: initialStorage.queueCwd, timeout: probeRemaining, limit: 4096,
|
|
888
926
|
});
|
|
889
927
|
if (performance.now() >= options.deadlineMs)
|
|
890
928
|
throw new AppServerFault('deadline', false);
|
|
@@ -894,6 +932,7 @@ export async function nativeQueueOnceWithProfiles(options, table) {
|
|
|
894
932
|
throw new AppServerFault('unsupported_version', false);
|
|
895
933
|
}
|
|
896
934
|
verifyExecutableIdentity(options.binary, binaryIdentity);
|
|
935
|
+
await revalidateStorage(nativeVersion);
|
|
897
936
|
if (performance.now() >= options.deadlineMs)
|
|
898
937
|
throw new AppServerFault('deadline', false);
|
|
899
938
|
if (profile.artifact) {
|
|
@@ -917,8 +956,9 @@ export async function nativeQueueOnceWithProfiles(options, table) {
|
|
|
917
956
|
verifyOwnedSqliteBinding(pid, original.codexHome, options.deadlineMs);
|
|
918
957
|
const transport = { qualification: 'native_queue_only_stdio',
|
|
919
958
|
...spawnOwnedStdio(options.binary, ['app-server', '--stdio', '-c', 'analytics.enabled=false',
|
|
920
|
-
'-c',
|
|
959
|
+
'-c', codexStoragePin(original.codexHome)], env, original.codexHome) };
|
|
921
960
|
let client;
|
|
961
|
+
let lastBinding;
|
|
922
962
|
try {
|
|
923
963
|
verifyExecutableIdentity(options.binary, binaryIdentity);
|
|
924
964
|
let effectGuarded = false;
|
|
@@ -927,12 +967,34 @@ export async function nativeQueueOnceWithProfiles(options, table) {
|
|
|
927
967
|
if (valid && effectGuarded) {
|
|
928
968
|
// Run after the LAST asynchronous owner verification. The durable guard
|
|
929
969
|
// and owner probe can both await I/O and change canonical file bindings.
|
|
930
|
-
|
|
931
|
-
|
|
970
|
+
try {
|
|
971
|
+
await options.verifyStorage?.();
|
|
972
|
+
await revalidateStorage(nativeVersion);
|
|
973
|
+
lastBinding = await bind(transport.pid);
|
|
974
|
+
}
|
|
975
|
+
catch (error) {
|
|
976
|
+
throw error instanceof AppServerFault ? error : new AppServerFault('storage_binding_unverified', false);
|
|
977
|
+
}
|
|
932
978
|
}
|
|
933
979
|
return valid;
|
|
934
|
-
}, async () => { await options.beforeEffect(); effectGuarded = true; }, profile)
|
|
935
|
-
|
|
980
|
+
}, async () => { await options.beforeEffect(); effectGuarded = true; }, profile, () => {
|
|
981
|
+
// The effect writer calls this after its final await, before setting the
|
|
982
|
+
// attempted marker. No async callback follows these continuity checks.
|
|
983
|
+
try {
|
|
984
|
+
options.verifyStorageSync?.();
|
|
985
|
+
if (checkStorage(nativeVersion).fingerprint !== initialStorage.fingerprint)
|
|
986
|
+
throw new Error();
|
|
987
|
+
const current = codexConsumerSnapshotSync(original.codexHome, original.threadId);
|
|
988
|
+
if (current.database !== consumerDatabase || current.cwd !== consumerCwd)
|
|
989
|
+
throw new Error();
|
|
990
|
+
revalidateSqliteBinding(lastBinding);
|
|
991
|
+
verifyExecutableIdentity(options.binary, binaryIdentity);
|
|
992
|
+
}
|
|
993
|
+
catch (error) {
|
|
994
|
+
throw error instanceof AppServerFault ? error : new AppServerFault('storage_binding_unverified', false);
|
|
995
|
+
}
|
|
996
|
+
});
|
|
997
|
+
lastBinding = await bind(transport.pid);
|
|
936
998
|
return await client.queueOnce({ clientUserMessageId: options.clientUserMessageId, message: options.message });
|
|
937
999
|
}
|
|
938
1000
|
finally {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export declare const STORAGE_LOADER_VERSIONS: readonly ["0.160.1", "0.162.1", "0.165.0"];
|
|
2
|
+
export declare function codexStoragePin(home: string): string;
|
|
3
|
+
type Layer = 'home' | 'system' | 'requirements' | 'legacy' | 'preferences' | 'project' | 'context' | 'daemon' | 'cloud';
|
|
4
|
+
export type StorageCheck = {
|
|
5
|
+
status: 'classified' | 'unsupported' | 'unknown';
|
|
6
|
+
code: string;
|
|
7
|
+
verification: 'local_loader_layers';
|
|
8
|
+
loaderVersion: string | null;
|
|
9
|
+
loaderVersionVerified: boolean;
|
|
10
|
+
localLoaderPlatformSupported: boolean;
|
|
11
|
+
layers: Layer[];
|
|
12
|
+
consumerContext: 'inspected' | 'not_provided';
|
|
13
|
+
cloudConfiguration: 'ineligible_by_metadata' | 'requires_owned_storage_binding' | 'unclassified';
|
|
14
|
+
fingerprint: string;
|
|
15
|
+
queueCwd?: string;
|
|
16
|
+
};
|
|
17
|
+
export type StorageOptions = {
|
|
18
|
+
home: string;
|
|
19
|
+
queueCwd?: string;
|
|
20
|
+
consumerCwds?: string[];
|
|
21
|
+
version?: string;
|
|
22
|
+
platform?: string;
|
|
23
|
+
ownedAppServer?: boolean;
|
|
24
|
+
systemBase?: string;
|
|
25
|
+
preferences?: () => {
|
|
26
|
+
forced: boolean;
|
|
27
|
+
value: unknown;
|
|
28
|
+
}[];
|
|
29
|
+
environment?: NodeJS.ProcessEnv;
|
|
30
|
+
};
|
|
31
|
+
export declare function managedStoragePreferences(): {
|
|
32
|
+
forced: boolean;
|
|
33
|
+
value: unknown;
|
|
34
|
+
}[];
|
|
35
|
+
export declare function storageDiagnostic(check: StorageCheck): Omit<StorageCheck, 'fingerprint' | 'queueCwd'>;
|
|
36
|
+
export declare function classifyCodexStorage(options: StorageOptions): StorageCheck;
|
|
37
|
+
export declare function codexStateIdentity(home: string): string;
|
|
38
|
+
export declare function codexConsumerSnapshotSync(home: string, threadId: string): {
|
|
39
|
+
cwd: string;
|
|
40
|
+
database: string;
|
|
41
|
+
};
|
|
42
|
+
export declare function codexConsumerCwd(home: string, threadId: string): Promise<string>;
|
|
43
|
+
export declare function codexWriterCwd(pid: number): string;
|
|
44
|
+
export declare function decodeLsofFilename(raw: string): string;
|
|
45
|
+
export declare function codexWriterStorage(pid: number, home: string): void;
|
|
46
|
+
export {};
|