@skill-harness/adapters 0.16.0 → 0.18.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/index.d.ts +0 -28
- package/dist/index.js +0 -28
- package/dist/pi.js +21 -133
- package/package.json +2 -3
- package/dist/archive-access.d.ts +0 -58
- package/dist/archive-access.js +0 -61
- package/dist/archive-checkpoint.d.ts +0 -47
- package/dist/archive-checkpoint.js +0 -116
- package/dist/archive-facts.d.ts +0 -19
- package/dist/archive-facts.js +0 -20
- package/dist/archive-observer.d.ts +0 -21
- package/dist/archive-observer.js +0 -79
- package/dist/archive-policy.d.ts +0 -107
- package/dist/archive-policy.js +0 -135
- package/dist/archive-read-capability.d.ts +0 -49
- package/dist/archive-read-capability.js +0 -45
- package/dist/archive-retention-policy.d.ts +0 -52
- package/dist/archive-retention-policy.js +0 -49
- package/dist/archived-work.d.ts +0 -45
- package/dist/archived-work.js +0 -78
- package/dist/blind-intervention.d.ts +0 -35
- package/dist/blind-intervention.js +0 -218
- package/dist/codex-diagnostic-model.d.ts +0 -14
- package/dist/codex-diagnostic-model.js +0 -39
- package/dist/codex-host-observer.d.ts +0 -111
- package/dist/codex-host-observer.js +0 -309
- package/dist/codex-https.d.ts +0 -7
- package/dist/codex-https.js +0 -221
- package/dist/codex-model-profile.d.ts +0 -38
- package/dist/codex-model-profile.js +0 -54
- package/dist/codex-producer-ipc.d.ts +0 -55
- package/dist/codex-producer-ipc.js +0 -67
- package/dist/codex-sdk-transport.d.ts +0 -50
- package/dist/codex-sdk-transport.js +0 -294
- package/dist/codex-subscription.d.ts +0 -114
- package/dist/codex-subscription.js +0 -268
- package/dist/evidence-archive.d.ts +0 -65
- package/dist/evidence-archive.js +0 -225
- package/dist/execution-projection-schema.d.ts +0 -10
- package/dist/execution-projection-schema.js +0 -30
- package/dist/execution-retention-archive.d.ts +0 -69
- package/dist/execution-retention-archive.js +0 -154
- package/dist/generated/retention-v2-contract.d.ts +0 -72
- package/dist/generated/retention-v2-contract.js +0 -105
- package/dist/generated/retention-v2-json.d.ts +0 -24
- package/dist/generated/retention-v2-json.js +0 -268
- package/dist/generated/retention-v2-native-json.d.ts +0 -2
- package/dist/generated/retention-v2-native-json.js +0 -33
- package/dist/generated/retention-v2-native.d.ts +0 -58
- package/dist/generated/retention-v2-native.js +0 -155
- package/dist/generated/retention-v2-pin.d.ts +0 -2
- package/dist/generated/retention-v2-pin.js +0 -4
- package/dist/generated/retention-v2-types.d.ts +0 -49
- package/dist/generated/retention-v2-types.js +0 -2
- package/dist/generated/retention-v2-work-types.d.ts +0 -260
- package/dist/generated/retention-v2-work-types.js +0 -13
- package/dist/generated/work-v4/execution-id.d.ts +0 -5
- package/dist/generated/work-v4/execution-id.js +0 -14
- package/dist/generated/work-v4/json.d.ts +0 -24
- package/dist/generated/work-v4/json.js +0 -268
- package/dist/generated/work-v4/occurrences.d.ts +0 -226
- package/dist/generated/work-v4/occurrences.js +0 -116
- package/dist/generated/work-v4/pin.d.ts +0 -1
- package/dist/generated/work-v4/pin.js +0 -3
- package/dist/generated/work-v4/projection.d.ts +0 -294
- package/dist/generated/work-v4/projection.js +0 -238
- package/dist/generated/work-v4/reader.d.ts +0 -24
- package/dist/generated/work-v4/reader.js +0 -109
- package/dist/generated/work-v4/snapshot.d.ts +0 -28
- package/dist/generated/work-v4/snapshot.js +0 -268
- package/dist/generated/work-v4/types.d.ts +0 -260
- package/dist/generated/work-v4/types.js +0 -13
- package/dist/generated/work-v4/validation.d.ts +0 -13
- package/dist/generated/work-v4/validation.js +0 -227
- package/dist/installed-review-session.d.ts +0 -28
- package/dist/installed-review-session.js +0 -166
- package/dist/intervention-run.d.ts +0 -403
- package/dist/intervention-run.js +0 -169
- package/dist/learning-case.d.ts +0 -12
- package/dist/learning-case.js +0 -15
- package/dist/learning-journal.d.ts +0 -18
- package/dist/learning-journal.js +0 -256
- package/dist/learning-lifecycle.d.ts +0 -28
- package/dist/learning-lifecycle.js +0 -66
- package/dist/learning-trust-setup.d.ts +0 -64
- package/dist/learning-trust-setup.js +0 -55
- package/dist/learning-workspace.d.ts +0 -930
- package/dist/learning-workspace.js +0 -663
- package/dist/principal-payload-port.d.ts +0 -25
- package/dist/principal-payload-port.js +0 -40
- package/dist/producer-product.d.ts +0 -70
- package/dist/producer-product.js +0 -186
- package/dist/producer-review.d.ts +0 -53
- package/dist/producer-review.js +0 -207
- package/dist/prompt-capture-extension.d.ts +0 -10
- package/dist/prompt-capture-extension.js +0 -26
- package/dist/prompt-provenance.d.ts +0 -22
- package/dist/prompt-provenance.js +0 -146
- package/dist/reviewed-archive-export.d.ts +0 -42
- package/dist/reviewed-archive-export.js +0 -78
- package/dist/trust-lifecycle.d.ts +0 -152
- package/dist/trust-lifecycle.js +0 -209
- package/dist/weekly-investigation.d.ts +0 -237
- package/dist/weekly-investigation.js +0 -330
- package/dist/work-candidates.d.ts +0 -29
- package/dist/work-candidates.js +0 -78
- package/dist/work-case-archive.d.ts +0 -25
- package/dist/work-case-archive.js +0 -63
- package/dist/work-case-review.d.ts +0 -45
- package/dist/work-case-review.js +0 -220
- package/dist/work-signal-cases.d.ts +0 -15
- package/dist/work-signal-cases.js +0 -54
- package/dist/work-signal-observation.d.ts +0 -23
- package/dist/work-signal-observation.js +0 -89
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { type CodexDiagnosticModelPin } from './codex-diagnostic-model.js';
|
|
2
|
-
import { inspectCodexRoleSeparation, type LocalCodexInvocation } from './codex-host-observer.js';
|
|
3
|
-
import type { CodexSdkBinding, CodexWire } from './codex-sdk-transport.js';
|
|
4
|
-
import { type CodexProducerApi, type CodexProducerBinding } from './codex-producer-ipc.js';
|
|
5
|
-
/** Original capabilities from one pinned producer graph. Queued permits count as active.
|
|
6
|
-
* The caller supplies the existing owner; this entry never mints a replacement budget. */
|
|
7
|
-
export interface CodexQualificationSource {
|
|
8
|
-
producer: CodexProducerApi & {
|
|
9
|
-
producerIpcDemand(binding: CodexProducerBinding): any;
|
|
10
|
-
};
|
|
11
|
-
owner: {
|
|
12
|
-
reserveBatch(demands: any[]): Promise<readonly {
|
|
13
|
-
settle(outcome: 'cancelled'): Promise<void>;
|
|
14
|
-
}[]>;
|
|
15
|
-
};
|
|
16
|
-
bindings: CodexProducerBinding[];
|
|
17
|
-
signal: AbortSignal;
|
|
18
|
-
}
|
|
19
|
-
export declare const CODEX_RUNTIME_FILES: readonly string[];
|
|
20
|
-
export declare const SUBSCRIPTION_ENDPOINT = "https://chatgpt.com/backend-api/codex/responses";
|
|
21
|
-
export interface CodexCharter {
|
|
22
|
-
version: 'codex-synthetic-charter-v1';
|
|
23
|
-
provider: 'openai-codex';
|
|
24
|
-
destination: string;
|
|
25
|
-
rolePolicy: Parameters<typeof inspectCodexRoleSeparation>[0];
|
|
26
|
-
identityEvidence: {
|
|
27
|
-
kind: 'fixture' | 'unresolved' | 'host-resolved';
|
|
28
|
-
reference: string | null;
|
|
29
|
-
};
|
|
30
|
-
hostEvidence: {
|
|
31
|
-
kind: 'fixture' | 'unqualified' | 'qualified-host';
|
|
32
|
-
reference: string | null;
|
|
33
|
-
};
|
|
34
|
-
accountId: string | null;
|
|
35
|
-
serverOutputTokenCap: null;
|
|
36
|
-
runtime: {
|
|
37
|
-
sdkRoot: string;
|
|
38
|
-
oauthFile: string;
|
|
39
|
-
fingerprints: Record<string, string>;
|
|
40
|
-
};
|
|
41
|
-
limits: {
|
|
42
|
-
calls: number;
|
|
43
|
-
requestBytes: number;
|
|
44
|
-
responseBytes: number;
|
|
45
|
-
totalRequestBytes: number;
|
|
46
|
-
totalResponseBytes: number;
|
|
47
|
-
callMs: number;
|
|
48
|
-
wallMs: number;
|
|
49
|
-
};
|
|
50
|
-
invocations: LocalCodexInvocation[];
|
|
51
|
-
diagnosticModel?: CodexDiagnosticModelPin;
|
|
52
|
-
}
|
|
53
|
-
/** A trusted-host approval input, not a signature or a user-consent detector.
|
|
54
|
-
* Neither a subject frame nor the charter itself can supply this separate input. */
|
|
55
|
-
export interface CodexApproval {
|
|
56
|
-
scope: 'fixture' | 'subscription-live';
|
|
57
|
-
charterSha256: string;
|
|
58
|
-
approvalId: string;
|
|
59
|
-
expiresAt: number;
|
|
60
|
-
journalPath: string;
|
|
61
|
-
}
|
|
62
|
-
export interface CodexOAuth {
|
|
63
|
-
type: 'oauth';
|
|
64
|
-
provider: 'openai-codex';
|
|
65
|
-
access: string;
|
|
66
|
-
expires: number;
|
|
67
|
-
accountId: string;
|
|
68
|
-
}
|
|
69
|
-
export interface CodexCredentialPort {
|
|
70
|
-
kind: 'fixture-oauth' | 'oauth-snapshot';
|
|
71
|
-
read(signal: AbortSignal): Promise<unknown>;
|
|
72
|
-
}
|
|
73
|
-
export interface CodexHttpPort {
|
|
74
|
-
kind: 'fixture-http' | 'subscription-http';
|
|
75
|
-
preflight?(): void;
|
|
76
|
-
exchange(wire: CodexWire, credential: CodexOAuth, signal: AbortSignal, record: (v: Record<string, unknown>) => void, limits: CodexCharter['limits']): Promise<Response>;
|
|
77
|
-
}
|
|
78
|
-
export interface CodexExecutionPorts {
|
|
79
|
-
bindings: Record<string, CodexSdkBinding>;
|
|
80
|
-
credentials: CodexCredentialPort;
|
|
81
|
-
transport: CodexHttpPort;
|
|
82
|
-
}
|
|
83
|
-
export declare const codexCharterHash: (charter: CodexCharter) => string;
|
|
84
|
-
export declare function validateCodexCharter(raw: CodexCharter, approval: CodexApproval | undefined): CodexCharter;
|
|
85
|
-
export declare function validateCodexOAuth(value: unknown, accountId: string, mode: 'fixture' | 'subscription-live'): CodexOAuth;
|
|
86
|
-
/** Lazy read-only SDK storage adapter. list FIRST: an API-key entry never reaches read(),
|
|
87
|
-
* so command/env key helpers are unavailable. Never refresh/modify/login or persist secrets. */
|
|
88
|
-
export declare function createReadOnlyCodexOAuthPort(factory: () => {
|
|
89
|
-
list(o?: {
|
|
90
|
-
signal: AbortSignal;
|
|
91
|
-
}): Promise<Array<{
|
|
92
|
-
providerId: string;
|
|
93
|
-
type: string;
|
|
94
|
-
}>>;
|
|
95
|
-
read(id: string, o?: {
|
|
96
|
-
signal: AbortSignal;
|
|
97
|
-
}): Promise<any>;
|
|
98
|
-
}): CodexCredentialPort;
|
|
99
|
-
/** Bounded, no-follow read of the explicitly approved file, invoked lazily AFTER approval.
|
|
100
|
-
* Whole JSON is parsed in trusted host memory; only OAuth is returned, never helper resolution. */
|
|
101
|
-
export declare function createCodexOAuthFilePort(path: string): CodexCredentialPort;
|
|
102
|
-
/** Fixed synthetic evaluation only. Model votes select a conditional third judge, never
|
|
103
|
-
* a worker, grant, production action or adoption. Same journal owns all reservations/results. */
|
|
104
|
-
export declare function executeCodexQualification(path: string, raw: CodexCharter, rawApproval: CodexApproval | undefined, ports: CodexExecutionPorts): Promise<Record<string, unknown>>;
|
|
105
|
-
/** Explicit opt-in; never silently substitutes producer backing for host frames. */
|
|
106
|
-
export declare function executeProducerCodexQualification(path: string, raw: CodexCharter, rawApproval: CodexApproval | undefined, ports: CodexExecutionPorts, source: CodexQualificationSource): Promise<Record<string, unknown>>;
|
|
107
|
-
export interface CodexSingleRequestApproval extends Omit<CodexApproval, 'scope'> {
|
|
108
|
-
scope: 'fixture-single-request' | 'subscription-single-request';
|
|
109
|
-
approvedCalls: 1;
|
|
110
|
-
}
|
|
111
|
-
export declare function assertCodexSingleRequestPlan(c: CodexCharter): void;
|
|
112
|
-
export declare function validateCodexSingleRequestCharter(raw: CodexCharter, a: CodexSingleRequestApproval | undefined): CodexCharter;
|
|
113
|
-
/** Separate one-call authority; five charged original permits are never five callable roles. */
|
|
114
|
-
export declare function executeProducerCodexSingleRequest(path: string, raw: CodexCharter, a: CodexSingleRequestApproval | undefined, ports: CodexExecutionPorts, source: CodexQualificationSource): Promise<Record<string, unknown>>;
|
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
import { loadCodexDiagnosticModel } from './codex-diagnostic-model.js';
|
|
2
|
-
import { existsSync, realpathSync } from 'node:fs';
|
|
3
|
-
import { dirname, isAbsolute, resolve } from 'node:path';
|
|
4
|
-
import { collapseVotePanel } from '@skill-harness/core';
|
|
5
|
-
import { Readable } from 'node:stream';
|
|
6
|
-
import { learningCopy, learningHash, learningJournal, learningFile } from './learning-journal.js';
|
|
7
|
-
import { createLocalCodexHost, openLocalCodexHost, inspectCodexRoleSeparation } from './codex-host-observer.js';
|
|
8
|
-
import { startCodexProducerIpc, validateCodexProducerBinding } from './codex-producer-ipc.js';
|
|
9
|
-
export const CODEX_RUNTIME_FILES = Object.freeze(['node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js', 'node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js', 'node_modules/@earendil-works/pi-ai/dist/providers/data/openai-codex.json', 'dist/core/auth-storage.js']);
|
|
10
|
-
export const SUBSCRIPTION_ENDPOINT = 'https://chatgpt.com/backend-api/codex/responses';
|
|
11
|
-
const closed = (x, keys) => { if (!x || Object.keys(x).sort().join() !== keys.sort().join())
|
|
12
|
-
throw Error('invalid execution charter'); };
|
|
13
|
-
export const codexCharterHash = (charter) => learningHash(charter);
|
|
14
|
-
export function validateCodexCharter(raw, approval) { return validateCharter(raw, approval); }
|
|
15
|
-
function validateCharter(raw, approval, single = false) {
|
|
16
|
-
const c = learningCopy(raw);
|
|
17
|
-
closed(c, ['version', 'provider', 'destination', 'rolePolicy', 'identityEvidence', 'hostEvidence', 'accountId', 'serverOutputTokenCap', 'runtime', 'limits', 'invocations', ...(single && c.diagnosticModel ? ['diagnosticModel'] : [])]);
|
|
18
|
-
if (c.version !== 'codex-synthetic-charter-v1' || c.provider !== 'openai-codex' || c.destination !== SUBSCRIPTION_ENDPOINT || c.serverOutputTokenCap !== null)
|
|
19
|
-
throw Error('unsupported execution charter route/server guarantee');
|
|
20
|
-
closed(c.runtime, ['sdkRoot', 'oauthFile', 'fingerprints']);
|
|
21
|
-
if (!isAbsolute(c.runtime.sdkRoot) || !isAbsolute(c.runtime.oauthFile) || !c.runtime.fingerprints || !Object.values(c.runtime.fingerprints).every(h => /^[a-f0-9]{64}$/.test(h)))
|
|
22
|
-
throw Error('unbound host runtime');
|
|
23
|
-
const l = c.limits;
|
|
24
|
-
closed(l, ['calls', 'requestBytes', 'responseBytes', 'totalRequestBytes', 'totalResponseBytes', 'callMs', 'wallMs']);
|
|
25
|
-
if (!Object.values(l).every(n => Number.isSafeInteger(n) && n > 0) || l.calls !== 5 || l.requestBytes > 4096 || l.responseBytes > 16384 || l.callMs > 30000 || l.wallMs > 150000 || l.totalRequestBytes > 20480 || l.totalResponseBytes > 81920 || l.totalRequestBytes < l.requestBytes || l.totalResponseBytes < l.responseBytes)
|
|
26
|
-
throw Error('invalid aggregate reservation');
|
|
27
|
-
const separation = inspectCodexRoleSeparation(c.rolePolicy);
|
|
28
|
-
if (separation.state === 'BLOCKED')
|
|
29
|
-
throw Error(separation.reason);
|
|
30
|
-
if (!Array.isArray(c.invocations) || c.invocations.length !== 5 || c.invocations.map(i => i.role).join() !== 'proposer,subject,judge,judge,judge' || new Set(c.invocations.map(i => i.id)).size !== 5 || c.invocations.slice(2).some(i => i.subjectId !== c.invocations[1].id))
|
|
31
|
-
throw Error('fixed five-role context policy required');
|
|
32
|
-
if (!approval)
|
|
33
|
-
throw Error('missing execution approval');
|
|
34
|
-
closed(approval, ['scope', 'charterSha256', 'approvalId', 'expiresAt', 'journalPath']);
|
|
35
|
-
if (!['fixture', 'subscription-live'].includes(approval.scope) || approval.charterSha256 !== codexCharterHash(c) || typeof approval.approvalId !== 'string' || !approval.approvalId || !Number.isSafeInteger(approval.expiresAt) || approval.expiresAt <= Date.now())
|
|
36
|
-
throw Error('execution approval mismatch/expired');
|
|
37
|
-
for (const e of [c.identityEvidence, c.hostEvidence])
|
|
38
|
-
closed(e, ['kind', 'reference']);
|
|
39
|
-
if (typeof c.accountId !== 'string' || !c.accountId || c.accountId.length > 256 || /[\r\n]/.test(c.accountId))
|
|
40
|
-
throw Error('unresolved approved account binding');
|
|
41
|
-
if (approval.scope === 'subscription-live' && Object.keys(c.runtime.fingerprints).sort().join() !== [...CODEX_RUNTIME_FILES].sort().join())
|
|
42
|
-
throw Error('unpinned production SDK runtime');
|
|
43
|
-
if (approval.scope === 'subscription-live' && (c.identityEvidence.kind !== 'host-resolved' || !c.identityEvidence.reference || c.hostEvidence.kind !== 'qualified-host' || !c.hostEvidence.reference || c.accountId.startsWith('fixture-')))
|
|
44
|
-
throw Error('production canonical/host qualification unresolved');
|
|
45
|
-
if (approval.scope === 'fixture' && (c.identityEvidence.kind !== 'fixture' || c.hostEvidence.kind !== 'fixture'))
|
|
46
|
-
throw Error('fixture provenance required');
|
|
47
|
-
return c;
|
|
48
|
-
}
|
|
49
|
-
export function validateCodexOAuth(value, accountId, mode) {
|
|
50
|
-
try {
|
|
51
|
-
const v = value;
|
|
52
|
-
if (v.type !== 'oauth' || v.provider !== 'openai-codex' || typeof v.access !== 'string' || v.access.length > 16384 || !Number.isFinite(v.expires) || v.expires <= Date.now() || v.accountId !== accountId)
|
|
53
|
-
throw Error();
|
|
54
|
-
const parts = v.access.split('.');
|
|
55
|
-
if (parts.length !== 3 || parts.some(p => !p || !/^[A-Za-z0-9_-]+$/.test(p)) || mode === 'subscription-live' && (parts[0] === 'fixture' || parts[2] === 'invalid'))
|
|
56
|
-
throw Error();
|
|
57
|
-
const claim = JSON.parse(Buffer.from(parts[1], 'base64url').toString('utf8'));
|
|
58
|
-
if (claim['https://api.openai.com/auth']?.chatgpt_account_id !== accountId)
|
|
59
|
-
throw Error();
|
|
60
|
-
return { type: 'oauth', provider: 'openai-codex', access: v.access, expires: v.expires, accountId };
|
|
61
|
-
}
|
|
62
|
-
catch {
|
|
63
|
-
throw Error('oauth-credential-unavailable');
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/** Lazy read-only SDK storage adapter. list FIRST: an API-key entry never reaches read(),
|
|
67
|
-
* so command/env key helpers are unavailable. Never refresh/modify/login or persist secrets. */
|
|
68
|
-
export function createReadOnlyCodexOAuthPort(factory) {
|
|
69
|
-
let snapshot;
|
|
70
|
-
return { kind: 'oauth-snapshot', async read(signal) { try {
|
|
71
|
-
signal.throwIfAborted();
|
|
72
|
-
if (snapshot)
|
|
73
|
-
return snapshot;
|
|
74
|
-
const store = factory();
|
|
75
|
-
const entries = await store.list({ signal });
|
|
76
|
-
if (entries.filter(e => e.providerId === 'openai-codex' && e.type === 'oauth').length !== 1 || entries.some(e => e.providerId === 'openai-codex' && e.type !== 'oauth'))
|
|
77
|
-
throw Error();
|
|
78
|
-
const value = await store.read('openai-codex', { signal });
|
|
79
|
-
if (value?.type !== 'oauth' || typeof value.access !== 'string')
|
|
80
|
-
throw Error();
|
|
81
|
-
const claim = JSON.parse(Buffer.from(value.access.split('.')[1], 'base64url').toString('utf8'));
|
|
82
|
-
snapshot = { type: 'oauth', provider: 'openai-codex', access: value.access, expires: value.expires, accountId: claim['https://api.openai.com/auth']?.chatgpt_account_id };
|
|
83
|
-
signal.throwIfAborted();
|
|
84
|
-
return snapshot;
|
|
85
|
-
}
|
|
86
|
-
catch {
|
|
87
|
-
throw Error('oauth-credential-unavailable');
|
|
88
|
-
} } };
|
|
89
|
-
}
|
|
90
|
-
/** Bounded, no-follow read of the explicitly approved file, invoked lazily AFTER approval.
|
|
91
|
-
* Whole JSON is parsed in trusted host memory; only OAuth is returned, never helper resolution. */
|
|
92
|
-
export function createCodexOAuthFilePort(path) {
|
|
93
|
-
return createReadOnlyCodexOAuthPort(() => { const data = JSON.parse(learningFile(path, 65536).toString('utf8')); if (!data || typeof data !== 'object' || Array.isArray(data))
|
|
94
|
-
throw Error('invalid credential snapshot'); return { list: async () => Object.entries(data).map(([providerId, v]) => ({ providerId, type: v?.type })), read: async (id) => data[id] }; });
|
|
95
|
-
}
|
|
96
|
-
/** Fixed synthetic evaluation only. Model votes select a conditional third judge, never
|
|
97
|
-
* a worker, grant, production action or adoption. Same journal owns all reservations/results. */
|
|
98
|
-
export function executeCodexQualification(path, raw, rawApproval, ports) {
|
|
99
|
-
return executeQualification(path, raw, rawApproval, ports);
|
|
100
|
-
}
|
|
101
|
-
/** Explicit opt-in; never silently substitutes producer backing for host frames. */
|
|
102
|
-
export async function executeProducerCodexQualification(path, raw, rawApproval, ports, source) {
|
|
103
|
-
if (!source)
|
|
104
|
-
throw Error('explicit original producer source required');
|
|
105
|
-
return executeQualification(path, raw, rawApproval, ports, source);
|
|
106
|
-
}
|
|
107
|
-
export function assertCodexSingleRequestPlan(c) {
|
|
108
|
-
const model = c.diagnosticModel ? loadCodexDiagnosticModel(c.diagnosticModel).id : 'gpt-5.4';
|
|
109
|
-
const i = c.invocations[0];
|
|
110
|
-
if (!i || i.role !== 'proposer' || i.model !== model || i.effort !== 'low' || i.instructions !== 'Return only the integer answer.' || i.input !== 'Return only the integer: 2 + 2.' || i.expectedSha256 !== '4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a' || i.subjectId !== null)
|
|
111
|
-
throw Error('fixed single request plan required');
|
|
112
|
-
}
|
|
113
|
-
function checkedSingleRequest(raw, a) {
|
|
114
|
-
if (!a)
|
|
115
|
-
throw Error('missing single request approval');
|
|
116
|
-
closed(a, ['scope', 'approvedCalls', 'charterSha256', 'approvalId', 'expiresAt', 'journalPath']);
|
|
117
|
-
if (!['fixture-single-request', 'subscription-single-request'].includes(a.scope) || a.approvedCalls !== 1)
|
|
118
|
-
throw Error('single request approval mismatch');
|
|
119
|
-
const { approvedCalls: _, scope, ...rest } = learningCopy(a);
|
|
120
|
-
const approval = { ...rest, scope: scope === 'fixture-single-request' ? 'fixture' : 'subscription-live' };
|
|
121
|
-
const c = validateCharter(raw, approval, true);
|
|
122
|
-
assertCodexSingleRequestPlan(c);
|
|
123
|
-
return { c, approval };
|
|
124
|
-
}
|
|
125
|
-
export function validateCodexSingleRequestCharter(raw, a) { return checkedSingleRequest(raw, a).c; }
|
|
126
|
-
/** Separate one-call authority; five charged original permits are never five callable roles. */
|
|
127
|
-
export async function executeProducerCodexSingleRequest(path, raw, a, ports, source) {
|
|
128
|
-
if (!source)
|
|
129
|
-
throw Error('explicit original producer source required');
|
|
130
|
-
const { c, approval } = checkedSingleRequest(raw, a);
|
|
131
|
-
return executeQualification(path, c, approval, ports, source, true);
|
|
132
|
-
}
|
|
133
|
-
async function executeQualification(path, raw, rawApproval, ports, source, single = false) {
|
|
134
|
-
const approval = rawApproval ? learningCopy(rawApproval) : undefined;
|
|
135
|
-
const c = validateCharter(raw, approval, single), mode = approval.scope, hash = codexCharterHash(c);
|
|
136
|
-
if (c.diagnosticModel) {
|
|
137
|
-
assertCodexSingleRequestPlan(c);
|
|
138
|
-
if (learningHash(ports.bindings[c.invocations[0].model]?.model) !== learningHash(loadCodexDiagnosticModel(c.diagnosticModel)))
|
|
139
|
-
throw Error('frozen diagnostic SDK definition mismatch');
|
|
140
|
-
}
|
|
141
|
-
if (!isAbsolute(path) || resolve(path) !== path || realpathSync(dirname(path)) !== dirname(path) || approval.journalPath !== path)
|
|
142
|
-
throw Error('execution approval owner-path mismatch');
|
|
143
|
-
if (ports.credentials.kind !== (mode === 'fixture' ? 'fixture-oauth' : 'oauth-snapshot') || ports.transport.kind !== (mode === 'fixture' ? 'fixture-http' : 'subscription-http'))
|
|
144
|
-
throw Error('fixture/production port mismatch');
|
|
145
|
-
for (const i of c.invocations) {
|
|
146
|
-
const b = ports.bindings[i.model];
|
|
147
|
-
if (!b || typeof b.stream !== 'function' || b.model.id !== i.model || b.model.provider !== 'openai-codex' || b.model.api !== 'openai-codex-responses' || b.model.baseUrl !== 'https://chatgpt.com/backend-api' || b.model.headers && Object.keys(b.model.headers).length)
|
|
148
|
-
throw Error('unresolved SDK binding');
|
|
149
|
-
}
|
|
150
|
-
const sourceBindings = source?.bindings.map(validateCodexProducerBinding);
|
|
151
|
-
if (source) {
|
|
152
|
-
if (!(source.signal instanceof AbortSignal) || typeof source.owner?.reserveBatch !== 'function' || typeof source.producer?.producerIpcDemand !== 'function' || typeof source.producer?.startProducerIpc !== 'function' || typeof source.producer?.createProducerIpcHost !== 'function')
|
|
153
|
-
throw Error('original producer capabilities required');
|
|
154
|
-
source.signal.throwIfAborted();
|
|
155
|
-
if (!sourceBindings || sourceBindings.length !== 5 || new Set(sourceBindings.map(b => b.executionId)).size !== 5 || sourceBindings.some((b, k) => b.charterSha256 !== hash || b.invocationId !== c.invocations[k].id || ['budgetDigest', 'orderId', 'experimentId'].some(key => b[key] !== sourceBindings[0][key])))
|
|
156
|
-
throw Error('producer source charter/batch mismatch');
|
|
157
|
-
}
|
|
158
|
-
const sourceDeclaration = source ? { kind: 'producer-ipc-v1', bindings: sourceBindings, ...(single ? { diagnostic: 'single-request-v1' } : {}) } : { kind: 'host-frames-v1' };
|
|
159
|
-
ports.transport.preflight?.();
|
|
160
|
-
const reservation = { charterSha256: hash, mode, requestBytes: c.limits.requestBytes, responseBytes: c.limits.responseBytes, totalRequestBytes: c.limits.totalRequestBytes, totalResponseBytes: c.limits.totalResponseBytes, callMs: c.limits.callMs };
|
|
161
|
-
const host = existsSync(path) ? openLocalCodexHost(path) : createLocalCodexHost(path, { version: 'codex-host-local-v1', maxCalls: single ? 1 : c.limits.calls, wallMs: Math.min(c.limits.wallMs, approval.expiresAt - Date.now()), invocations: single ? c.invocations.slice(0, 1) : c.invocations }, c.rolePolicy, reservation);
|
|
162
|
-
const store = learningJournal(path), rows = store.read();
|
|
163
|
-
if (learningHash(rows[0].value.subscription) !== learningHash(reservation) || learningHash(rows[0].value.rolePolicy) !== learningHash(c.rolePolicy))
|
|
164
|
-
throw Error('frozen execution charter changed');
|
|
165
|
-
const append = (v) => store.append(store.read().at(-1).id, v);
|
|
166
|
-
const priorCharter = rows.find(e => e.value.type === 'subscription-charter');
|
|
167
|
-
if (priorCharter && learningHash(priorCharter.value.source ?? { kind: 'host-frames-v1' }) !== learningHash(sourceDeclaration))
|
|
168
|
-
throw Error('frozen execution source changed');
|
|
169
|
-
const old = rows.find(e => e.value.type === 'subscription-finished');
|
|
170
|
-
if (old)
|
|
171
|
-
return old.value;
|
|
172
|
-
if (priorCharter || host.inspect().calls || host.inspect().aborted)
|
|
173
|
-
throw Error('stranded execution; no retry');
|
|
174
|
-
append({ type: 'subscription-charter', charter: c, charterSha256: hash, approvalId: approval.approvalId, executionMode: mode, source: sourceDeclaration, aggregateReservation: c.limits, liveQualified: false });
|
|
175
|
-
let inFlight = false, httpAttempts = 0;
|
|
176
|
-
const transport = { kind: ports.transport.kind, exchange: async (wire, signal, record) => {
|
|
177
|
-
if (inFlight || single && httpAttempts >= 1 || wire.destination !== SUBSCRIPTION_ENDPOINT || wire.method !== 'POST' || wire.body.length > c.limits.requestBytes || approval.expiresAt <= Date.now())
|
|
178
|
-
throw Error('subscription preflight refused');
|
|
179
|
-
inFlight = true;
|
|
180
|
-
httpAttempts++;
|
|
181
|
-
try {
|
|
182
|
-
signal.throwIfAborted();
|
|
183
|
-
const credential = validateCodexOAuth(await ports.credentials.read(signal), c.accountId, mode);
|
|
184
|
-
signal.throwIfAborted();
|
|
185
|
-
if (approval.expiresAt <= Date.now())
|
|
186
|
-
throw Error('execution approval expired before transport');
|
|
187
|
-
const response = await ports.transport.exchange(wire, credential, signal, record, learningCopy(c.limits));
|
|
188
|
-
if (response.redirected || response.status >= 300 && response.status < 400)
|
|
189
|
-
throw Error('redirect refused');
|
|
190
|
-
return response;
|
|
191
|
-
}
|
|
192
|
-
finally {
|
|
193
|
-
inFlight = false;
|
|
194
|
-
}
|
|
195
|
-
} };
|
|
196
|
-
let permits = [], result;
|
|
197
|
-
const handed = new Set();
|
|
198
|
-
try {
|
|
199
|
-
if (source) {
|
|
200
|
-
permits = await source.owner.reserveBatch(sourceBindings.map(b => source.producer.producerIpcDemand(b)));
|
|
201
|
-
if (permits.length !== 5)
|
|
202
|
-
throw Error('whole original reservation required');
|
|
203
|
-
}
|
|
204
|
-
const exchange = async (i) => {
|
|
205
|
-
if (!source)
|
|
206
|
-
return host.exchangeSubscriptionSdk(Readable.from([JSON.stringify({ id: i.id, sequence: 1 }) + '\n']), ports.bindings[i.model], transport, hash);
|
|
207
|
-
source.signal.throwIfAborted();
|
|
208
|
-
const first = store.read()[0].value, k = c.invocations.indexOf(i), remaining = Math.min(c.limits.callMs, approval.expiresAt - Date.now(), Number(first.createdAt) + c.limits.wallMs - Date.now());
|
|
209
|
-
if (remaining < 50)
|
|
210
|
-
throw Error('source deadline expired before launch');
|
|
211
|
-
handed.add(k); // Conservatively never settle a possibly handed-off permit from this caller.
|
|
212
|
-
const run = await startCodexProducerIpc({ path, binding: sourceBindings[k], sdk: ports.bindings[i.model], transport, producer: source.producer, owner: source.owner, permit: permits[k], signal: source.signal, timeoutMs: remaining });
|
|
213
|
-
const done = await Promise.race([run.completion, run.result.then(observed => {
|
|
214
|
-
// A bounded observer can refuse progress, NEVER grant completion or release the hold.
|
|
215
|
-
if (!['pending', 'completed'].includes(observed.outcome))
|
|
216
|
-
throw Error('original source observation failed');
|
|
217
|
-
return run.completion;
|
|
218
|
-
})]);
|
|
219
|
-
if (done.outcome !== 'completed' || done.settlement !== 'acknowledged')
|
|
220
|
-
throw Error('original source not completed');
|
|
221
|
-
const observed = store.read().find(e => e.value.type === 'observation' && e.value.id === i.id);
|
|
222
|
-
if (!observed)
|
|
223
|
-
throw Error('source observation missing');
|
|
224
|
-
return observed.value;
|
|
225
|
-
};
|
|
226
|
-
const evaluate = async () => {
|
|
227
|
-
if (single) {
|
|
228
|
-
const r = await exchange(c.invocations[0]);
|
|
229
|
-
return { type: 'subscription-finished', diagnostic: 'single-request-v1', charterSha256: hash, executionMode: mode, sourceKind: sourceDeclaration.kind, outcome: r.objective === 'PASS' ? 'single-request-completed' : 'objective-failed', objective: r.objective, outputSha256: r.outputSha256, calls: host.inspect().calls, httpAttempts, panel: null, liveQualified: false, routingDefault: null };
|
|
230
|
-
}
|
|
231
|
-
for (const i of c.invocations.slice(0, 2)) {
|
|
232
|
-
const r = await exchange(i);
|
|
233
|
-
if (r.objective !== 'PASS') {
|
|
234
|
-
return { type: 'subscription-finished', charterSha256: hash, executionMode: mode, sourceKind: sourceDeclaration.kind, outcome: 'objective-failed', calls: host.inspect().calls, liveQualified: false, routingDefault: null };
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
await exchange(c.invocations[2]);
|
|
238
|
-
await exchange(c.invocations[3]);
|
|
239
|
-
// Decide only whether the already-reserved clean-split tie-break is needed.
|
|
240
|
-
const observations = store.read().filter(e => e.value.type === 'observation');
|
|
241
|
-
const verdicts = observations.slice(-2).map(e => JSON.parse(Buffer.from(String(e.value.outputBase64), 'base64').toString('utf8')));
|
|
242
|
-
const split = collapseVotePanel(verdicts.map((v, k) => ({ ...v, ordinal: k + 1 }))).split;
|
|
243
|
-
const ids = c.invocations.slice(2, 4).map(i => i.id);
|
|
244
|
-
if (split) {
|
|
245
|
-
await exchange(c.invocations[4]);
|
|
246
|
-
ids.push(c.invocations[4].id);
|
|
247
|
-
}
|
|
248
|
-
const panel = host.panel(c.invocations[1].id, ids, c.rolePolicy);
|
|
249
|
-
return { type: 'subscription-finished', charterSha256: hash, executionMode: mode, sourceKind: sourceDeclaration.kind, outcome: 'advisory-panel', calls: host.inspect().calls, panel, liveQualified: false, routingDefault: null };
|
|
250
|
-
};
|
|
251
|
-
result = await evaluate();
|
|
252
|
-
}
|
|
253
|
-
catch {
|
|
254
|
-
append({ type: 'abort', reason: 'subscription execution failed; no retry', charterSha256: hash });
|
|
255
|
-
throw Error('subscription-execution-failed');
|
|
256
|
-
}
|
|
257
|
-
finally {
|
|
258
|
-
// Only the original unclaimed queued permits are cancelled. Attempts/bytes are not refunded.
|
|
259
|
-
const outcomes = await Promise.allSettled(permits.filter((_, k) => !handed.has(k)).map(p => p.settle('cancelled')));
|
|
260
|
-
if (outcomes.some(o => o.status === 'rejected')) {
|
|
261
|
-
append({ type: 'abort', reason: 'queued original settlement unknown; no retry' });
|
|
262
|
-
throw Error('queued original settlement unknown');
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
append(result);
|
|
266
|
-
return result;
|
|
267
|
-
}
|
|
268
|
-
//# sourceMappingURL=codex-subscription.js.map
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
export type ArchiveRetention = "exact" | "redacted" | "reference-only";
|
|
2
|
-
export interface ArchiveSourceReference {
|
|
3
|
-
schema: "archive-source-v1";
|
|
4
|
-
sourceId: string;
|
|
5
|
-
parser: {
|
|
6
|
-
id: string;
|
|
7
|
-
version: string;
|
|
8
|
-
};
|
|
9
|
-
sha256: string;
|
|
10
|
-
bytes: number;
|
|
11
|
-
retention: ArchiveRetention;
|
|
12
|
-
}
|
|
13
|
-
export interface ArchiveSourceInput {
|
|
14
|
-
sourceId: string;
|
|
15
|
-
parser: {
|
|
16
|
-
id: string;
|
|
17
|
-
version: string;
|
|
18
|
-
};
|
|
19
|
-
bytes: Uint8Array;
|
|
20
|
-
/** Explicit caller policy; this API neither authorizes collection nor redacts data. */
|
|
21
|
-
retention: ArchiveRetention;
|
|
22
|
-
}
|
|
23
|
-
export type ArchiveRead = {
|
|
24
|
-
status: "available";
|
|
25
|
-
reference: ArchiveSourceReference;
|
|
26
|
-
bytes: Buffer;
|
|
27
|
-
} | {
|
|
28
|
-
status: "missing";
|
|
29
|
-
reason: "manifest" | "content" | "not-retained";
|
|
30
|
-
} | {
|
|
31
|
-
status: "error";
|
|
32
|
-
reason: string;
|
|
33
|
-
};
|
|
34
|
-
/** External explicit ingestion only: no session writes, worker callbacks, network or automatic discovery. */
|
|
35
|
-
export declare function retainArchiveSource(root: string, input: ArchiveSourceInput): {
|
|
36
|
-
manifestId: string;
|
|
37
|
-
reference: ArchiveSourceReference;
|
|
38
|
-
};
|
|
39
|
-
export type ArchiveReferenceRead = {
|
|
40
|
-
status: 'available';
|
|
41
|
-
reference: ArchiveSourceReference;
|
|
42
|
-
} | Exclude<ArchiveRead, {
|
|
43
|
-
status: 'available';
|
|
44
|
-
}>;
|
|
45
|
-
/** Metadata only for explicit archive inventory. Does not claim content availability. */
|
|
46
|
-
export declare function readArchiveSourceReference(root: string, manifestId: string): ArchiveReferenceRead;
|
|
47
|
-
export declare function readArchiveSource(root: string, manifestId: string, maxBytes?: number): ArchiveRead;
|
|
48
|
-
export interface ArchivedJsonl {
|
|
49
|
-
status: "complete" | "partial" | "error";
|
|
50
|
-
records: Array<{
|
|
51
|
-
line: number;
|
|
52
|
-
start: number;
|
|
53
|
-
end: number;
|
|
54
|
-
value: unknown;
|
|
55
|
-
}>;
|
|
56
|
-
errors: Array<{
|
|
57
|
-
line: number;
|
|
58
|
-
start: number;
|
|
59
|
-
reason: "invalid-json";
|
|
60
|
-
}>;
|
|
61
|
-
completeBytes: number;
|
|
62
|
-
pendingBytes: number;
|
|
63
|
-
}
|
|
64
|
-
/** Syntax/byte coverage only. No semantic validation, branch inference, deduplication or acceptance. */
|
|
65
|
-
export declare function parseArchivedJsonl(bytes: Uint8Array): ArchivedJsonl;
|