@wix/pathgrade 1.0.31 → 1.0.33
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/adapters/jest/invocation-adapter.d.ts +2 -2
- package/dist/adapters/jest/invocation-adapter.js +1 -1
- package/dist/adapters/jest/lifecycle.d.ts +3 -3
- package/dist/adapters/jest/lifecycle.js +1 -1
- package/dist/adapters/jest/metadata.d.ts +0 -1
- package/dist/adapters/jest/metadata.js +1 -1
- package/dist/adapters/jest/results.d.ts +3 -2
- package/dist/affected/format.d.ts +0 -23
- package/dist/affected/format.js +1 -1
- package/dist/affected/sidecar.d.ts +0 -1
- package/dist/affected/sidecar.js +1 -1
- package/dist/affected/types.d.ts +2 -17
- package/dist/agents/claude/ask-user-answer-store.d.ts +2 -1
- package/dist/agents/claude/tool-results.d.ts +1 -1
- package/dist/agents/claude/tool-results.js +1 -1
- package/dist/agents/claude.d.ts +2 -1
- package/dist/agents/codex-app-server/agent.js +24 -8
- package/dist/agents/codex-app-server/protocol/ClientRequest.d.ts +3 -2
- package/dist/agents/codex-app-server/protocol/DynamicToolCallParams.d.ts +2 -1
- package/dist/agents/codex-app-server/protocol/GetAccountTokenUsageParams.d.ts +3 -0
- package/dist/agents/codex-app-server/protocol/GetAccountTokenUsageParams.js +4 -0
- package/dist/agents/codex-app-server/protocol/GetAccountTokenUsageResponse.d.ts +6 -0
- package/dist/agents/codex-app-server/protocol/GetAccountTokenUsageResponse.js +4 -0
- package/dist/agents/codex-app-server/protocol/GrantedPermissionProfile.d.ts +3 -2
- package/dist/agents/codex-app-server/protocol/McpElicitationRequestParams.d.ts +3 -2
- package/dist/agents/codex-app-server/protocol/PermissionsRequestApprovalParams.d.ts +3 -2
- package/dist/agents/codex-app-server/protocol/ThreadStartParams.d.ts +7 -6
- package/dist/agents/codex-app-server/protocol/ThreadTokenUsage.d.ts +6 -0
- package/dist/agents/codex-app-server/protocol/ThreadTokenUsage.js +4 -0
- package/dist/agents/codex-app-server/protocol/ThreadTokenUsageUpdatedNotification.d.ts +6 -0
- package/dist/agents/codex-app-server/protocol/ThreadTokenUsageUpdatedNotification.js +4 -0
- package/dist/agents/codex-app-server/protocol/ThreadUsage.d.ts +7 -0
- package/dist/agents/codex-app-server/protocol/ThreadUsage.js +4 -0
- package/dist/agents/codex-app-server/protocol/ThreadUsageBreakdownGroup.d.ts +11 -0
- package/dist/agents/codex-app-server/protocol/ThreadUsageBreakdownGroup.js +4 -0
- package/dist/agents/codex-app-server/protocol/TokenUsageBreakdown.d.ts +8 -0
- package/dist/agents/codex-app-server/protocol/TokenUsageBreakdown.js +4 -0
- package/dist/agents/codex-app-server/protocol/TurnCompletedNotification.d.ts +2 -1
- package/dist/agents/codex-app-server/protocol/index.d.ts +7 -0
- package/dist/agents/codex-app-server/transport.d.ts +2 -2
- package/dist/agents/codex-app-server/turn-notifications.js +4 -0
- package/dist/agents/codex-app-server/turn-state.d.ts +3 -0
- package/dist/agents/codex-app-server/usage-accounting.d.ts +18 -0
- package/dist/agents/codex-app-server/usage-accounting.js +121 -0
- package/dist/commands/analyze.d.ts +0 -13
- package/dist/commands/report.d.ts +0 -7
- package/dist/commands/report.js +1 -1
- package/dist/core/generated-mcp-protocol.d.ts +0 -2
- package/dist/core/generated-mcp-protocol.js +2 -2
- package/dist/evals/discovery.d.ts +0 -1
- package/dist/evals/discovery.js +1 -1
- package/dist/internal/direct-mcp-v2/acp-client.d.ts +0 -8
- package/dist/internal/direct-mcp-v2/acp-direct-mcp.d.ts +2 -1
- package/dist/internal/direct-mcp-v2/claude-direct-mcp.d.ts +1 -1
- package/dist/internal/direct-mcp-v2/claude-profile.d.ts +0 -10
- package/dist/internal/direct-mcp-v2/claude-profile.js +3 -3
- package/dist/internal/direct-mcp-v2/codex-direct-mcp.d.ts +2 -1
- package/dist/internal/direct-mcp-v2/compiler.d.ts +0 -1
- package/dist/internal/direct-mcp-v2/compiler.js +1 -1
- package/dist/internal/direct-mcp-v2/json.d.ts +0 -2
- package/dist/internal/direct-mcp-v2/json.js +2 -2
- package/dist/internal/direct-mcp-v2/runtime-lock.d.ts +2 -1
- package/dist/internal/direct-mcp-v2/runtime-profile.d.ts +0 -1
- package/dist/internal/direct-mcp-v2/runtime-profile.js +1 -1
- package/dist/internal/direct-mcp-v2/types.d.ts +5 -4
- package/dist/openai-oauth/chatgpt-oauth-llm.js +12 -1
- package/dist/providers/mcp-config.d.ts +0 -2
- package/dist/providers/mcp-config.js +2 -2
- package/dist/providers/mcp-runtime-mounting.d.ts +1 -9
- package/dist/providers/sandbox-lifecycle.d.ts +0 -2
- package/dist/providers/sandbox-lifecycle.js +2 -2
- package/dist/providers/scripted-mcp-mock-host.d.ts +1 -1
- package/dist/providers/workspace.d.ts +0 -1
- package/dist/reporters/github-comment.d.ts +0 -11
- package/dist/reporters/github-comment.js +1 -1
- package/dist/reporters/verbose-emitter.d.ts +7 -19
- package/dist/reporters/verbose-emitter.js +5 -5
- package/dist/reporting/types.d.ts +2 -1
- package/dist/runners/adapter-loader.d.ts +0 -3
- package/dist/runners/model-validation.d.ts +2 -1
- package/dist/runners/repeated-attempts.d.ts +0 -5
- package/dist/runners/repeated-attempts.js +1 -1
- package/dist/runners/vitest-invocation.d.ts +2 -2
- package/dist/runners/vitest-invocation.js +1 -1
- package/dist/runners/vitest-lifecycle.d.ts +0 -2
- package/dist/runners/vitest-lifecycle.js +1 -1
- package/dist/sdk/agent.js +1 -3
- package/dist/sdk/ask-bus/handler.d.ts +3 -2
- package/dist/sdk/diagnostics.d.ts +4 -3
- package/dist/sdk/evaluate.js +3 -2
- package/dist/sdk/judge-tool-runner.d.ts +1 -2
- package/dist/sdk/lifecycle.js +4 -0
- package/dist/sdk/mcp-mock-approvals.d.ts +3 -2
- package/dist/sdk/reaction-loader.d.ts +1 -2
- package/dist/sdk/reaction-preview.d.ts +1 -4
- package/dist/sdk/reaction-preview.js +3 -3
- package/dist/sdk/run-scorer.d.ts +1 -4
- package/dist/sdk/run-scorer.js +3 -3
- package/dist/sdk/runtime-policy.d.ts +0 -1
- package/dist/sdk/runtime-policy.js +1 -1
- package/dist/tool-events.d.ts +0 -1
- package/dist/tool-events.js +1 -1
- package/dist/types.d.ts +10 -32
- package/dist/types.js +1 -1
- package/dist/utils/cli.d.ts +0 -15
- package/dist/utils/cli.js +4 -4
- package/dist/utils/llm-mocks.d.ts +3 -2
- package/dist/utils/llm-mocks.js +5 -0
- package/dist/utils/llm-providers/cli.d.ts +0 -1
- package/dist/utils/llm-providers/cli.js +1 -1
- package/dist/utils/llm-types.d.ts +7 -4
- package/dist/utils/llm.d.ts +2 -2
- package/dist/utils/llm.js +6 -1
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ResolvedPathgradeConfig, type RunnerInvocationAdapter } from '@wix/pathgrade/adapter-kit';
|
|
2
|
-
|
|
2
|
+
interface SpawnJestRequest {
|
|
3
3
|
argv: string[];
|
|
4
4
|
env: NodeJS.ProcessEnv;
|
|
5
5
|
cwd: string;
|
|
@@ -12,4 +12,4 @@ export declare function createJestInvocationAdapter(input: {
|
|
|
12
12
|
export declare function createPathgradeInvocationAdapter(input: {
|
|
13
13
|
config: ResolvedPathgradeConfig;
|
|
14
14
|
}): RunnerInvocationAdapter;
|
|
15
|
-
export
|
|
15
|
+
export {};
|
|
@@ -99,7 +99,7 @@ async function defaultSpawnJest(req) {
|
|
|
99
99
|
child.on('error', () => resolve(1));
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
|
-
|
|
102
|
+
function resolveLocalJestBinPath(cwd) {
|
|
103
103
|
let packageJsonPath;
|
|
104
104
|
try {
|
|
105
105
|
const req = createRequire(path.join(cwd, 'package.json'));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type CaseContext, type CaseContextProviderHandle, type ResultObserverHandle, type PathgradeTestMeta, type AdapterLifecycleHooks, type EvalResultEvent } from '@wix/pathgrade/adapter-kit';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
type JestHook = (fn: () => void | Promise<void>) => void;
|
|
3
|
+
interface JestState {
|
|
4
4
|
testPath?: string;
|
|
5
5
|
currentTestName?: string;
|
|
6
6
|
}
|
|
@@ -18,4 +18,4 @@ export interface JestLifecycleInstallHandle {
|
|
|
18
18
|
}
|
|
19
19
|
export declare function installJestLifecycle(input: JestLifecycleInstallInput): JestLifecycleInstallHandle;
|
|
20
20
|
export declare function getJestLifecycleMetadata(): Map<string, PathgradeTestMeta[]>;
|
|
21
|
-
export
|
|
21
|
+
export {};
|
|
@@ -54,7 +54,7 @@ export function installJestLifecycle(input) {
|
|
|
54
54
|
export function getJestLifecycleMetadata() {
|
|
55
55
|
return new Map(metadataByCaseId);
|
|
56
56
|
}
|
|
57
|
-
|
|
57
|
+
function resetJestLifecycleMetadata() {
|
|
58
58
|
metadataByCaseId.clear();
|
|
59
59
|
}
|
|
60
60
|
function defaultSubscribeToResults(callback) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { PathgradeTestMeta } from '@wix/pathgrade/adapter-kit';
|
|
2
|
-
export declare function resolveJestMetadataPath(cwd?: string): string;
|
|
3
2
|
export declare function withJestMetadataEnv(env: NodeJS.ProcessEnv, cwd: string): NodeJS.ProcessEnv;
|
|
4
3
|
export declare function appendJestMetadata(caseId: string, metadata: PathgradeTestMeta[]): void;
|
|
5
4
|
export declare function readJestMetadata(metadataPath?: string): Map<string, PathgradeTestMeta[]>;
|
|
@@ -2,7 +2,7 @@ import * as fs from 'node:fs';
|
|
|
2
2
|
import * as path from 'node:path';
|
|
3
3
|
const METADATA_ENV = 'PATHGRADE_JEST_METADATA_PATH';
|
|
4
4
|
const FALLBACK_METADATA_FILE = 'jest-metadata.jsonl';
|
|
5
|
-
|
|
5
|
+
function resolveJestMetadataPath(cwd = process.cwd()) {
|
|
6
6
|
return process.env[METADATA_ENV] ?? path.join(cwd, '.pathgrade', FALLBACK_METADATA_FILE);
|
|
7
7
|
}
|
|
8
8
|
export function withJestMetadataEnv(env, cwd) {
|
|
@@ -2,12 +2,12 @@ import type { AdapterRunHandle, NormalizedRunSnapshot, PathgradeTestMeta } from
|
|
|
2
2
|
export interface JestAggregatedResult {
|
|
3
3
|
testResults?: JestFileResult[];
|
|
4
4
|
}
|
|
5
|
-
|
|
5
|
+
interface JestFileResult {
|
|
6
6
|
testFilePath: string;
|
|
7
7
|
assertionResults?: JestAssertionResult[];
|
|
8
8
|
testResults?: JestAssertionResult[];
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
interface JestAssertionResult {
|
|
11
11
|
ancestorTitles?: string[];
|
|
12
12
|
title: string;
|
|
13
13
|
fullName?: string;
|
|
@@ -30,3 +30,4 @@ export declare function jestCaseId(input: {
|
|
|
30
30
|
fullName: string;
|
|
31
31
|
occurrenceCounts?: Map<string, number>;
|
|
32
32
|
}): string;
|
|
33
|
+
export {};
|
|
@@ -9,28 +9,6 @@
|
|
|
9
9
|
* size-optimized `changed_files_count` summary).
|
|
10
10
|
*/
|
|
11
11
|
import type { SelectionResult } from './types.js';
|
|
12
|
-
interface JsonSelectionEntry {
|
|
13
|
-
file: string;
|
|
14
|
-
reason: string;
|
|
15
|
-
matched_glob?: string;
|
|
16
|
-
}
|
|
17
|
-
interface JsonSelectionSkipped {
|
|
18
|
-
file: string;
|
|
19
|
-
reason: string;
|
|
20
|
-
}
|
|
21
|
-
export interface JsonSelectionResult {
|
|
22
|
-
base_ref: string;
|
|
23
|
-
changed_files: string[];
|
|
24
|
-
global_match?: string;
|
|
25
|
-
selected: JsonSelectionEntry[];
|
|
26
|
-
skipped: JsonSelectionSkipped[];
|
|
27
|
-
warnings: string[];
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Transform `SelectionResult` (camelCase) into the snake_case wire shape
|
|
31
|
-
* consumed by `--json` and the sidecar-writer (Issue 11).
|
|
32
|
-
*/
|
|
33
|
-
export declare function toJsonShape(result: SelectionResult): JsonSelectionResult;
|
|
34
12
|
/**
|
|
35
13
|
* Stable JSON: keys in a fixed order, arrays pre-sorted by `toJsonShape`.
|
|
36
14
|
* Emits a trailing newline so downstream tools can treat it like any other
|
|
@@ -42,4 +20,3 @@ export declare function formatJson(result: SelectionResult): string;
|
|
|
42
20
|
* changed files, per-eval decision with reason, warnings footer.
|
|
43
21
|
*/
|
|
44
22
|
export declare function formatExplain(result: SelectionResult): string;
|
|
45
|
-
export {};
|
package/dist/affected/format.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* Transform `SelectionResult` (camelCase) into the snake_case wire shape
|
|
13
13
|
* consumed by `--json` and the sidecar-writer (Issue 11).
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
function toJsonShape(result) {
|
|
16
16
|
const out = {
|
|
17
17
|
base_ref: result.baseRef,
|
|
18
18
|
changed_files: [...result.changedFiles].sort(),
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import type { SelectionResult } from './types.js';
|
|
16
16
|
import type { PathgradeSelectionReport } from '../types.js';
|
|
17
|
-
export declare const SIDECAR_FILENAME = "selection.json";
|
|
18
17
|
export declare function getSidecarPath(cwd: string): string;
|
|
19
18
|
/**
|
|
20
19
|
* Flatten a `SelectionResult` into the compact shape written to
|
package/dist/affected/sidecar.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
import * as path from 'path';
|
|
16
16
|
import fs from 'fs-extra';
|
|
17
17
|
import { getPathgradeDir } from '../reporters/results-path.js';
|
|
18
|
-
|
|
18
|
+
const SIDECAR_FILENAME = 'selection.json';
|
|
19
19
|
export function getSidecarPath(cwd) {
|
|
20
20
|
return path.join(getPathgradeDir(cwd), SIDECAR_FILENAME);
|
|
21
21
|
}
|
package/dist/affected/types.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This file is the single source of truth for the `SelectionResult` shape
|
|
5
5
|
* and `SelectionReason` enum. Extended across Issues 5–11; do not duplicate.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
type SelectionReason = 'deps-match' | 'always-run' | 'global-match' | 'on-missing-fail-closed';
|
|
8
8
|
export interface SelectionEntry {
|
|
9
9
|
file: string;
|
|
10
10
|
reason: SelectionReason;
|
|
@@ -25,19 +25,4 @@ export interface SelectionResult {
|
|
|
25
25
|
skipped: SelectionSkipped[];
|
|
26
26
|
warnings: string[];
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
* Public SDK type — exported from `@wix/pathgrade` so evals can annotate
|
|
30
|
-
* their `__pathgradeMeta` export with a typed shape.
|
|
31
|
-
*
|
|
32
|
-
* `onMissing` is intentionally NOT a user-writable field: it names
|
|
33
|
-
* pathgrade's *runtime behavior* when an eval has neither a SKILL.md
|
|
34
|
-
* anchor nor an explicit meta declaration.
|
|
35
|
-
*/
|
|
36
|
-
export interface PathgradeMeta {
|
|
37
|
-
/** Full-override dep globs (repo-relative). Replaces auto-detected SKILL.md anchor. */
|
|
38
|
-
deps?: string[];
|
|
39
|
-
/** Additional dep globs unioned with the auto-detected SKILL.md anchor. */
|
|
40
|
-
extraDeps?: string[];
|
|
41
|
-
/** When true, unconditionally include this eval in every `pathgrade run --changed`. */
|
|
42
|
-
alwaysRun?: boolean;
|
|
43
|
-
}
|
|
28
|
+
export {};
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* the projector ultimately sees — both sides need a join key.
|
|
16
16
|
*/
|
|
17
17
|
import type { AskAnswerSource } from '../../sdk/ask-bus/types.js';
|
|
18
|
-
|
|
18
|
+
interface AskUserAnswerEntry {
|
|
19
19
|
/** The SDK-shape `answers` map (question text → answer string). */
|
|
20
20
|
readonly answers: Record<string, string>;
|
|
21
21
|
/** Source tag from the `AskAnswer` resolution — what the projector stamps. */
|
|
@@ -26,3 +26,4 @@ export interface AskUserAnswerStore {
|
|
|
26
26
|
get(toolUseId: string | undefined): AskUserAnswerEntry | undefined;
|
|
27
27
|
}
|
|
28
28
|
export declare function createAskUserAnswerStore(): AskUserAnswerStore;
|
|
29
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SDKMessage } from '@anthropic-ai/claude-agent-sdk';
|
|
2
2
|
import type { ToolEvent } from '../../tool-events.js';
|
|
3
|
-
export { collectSensitiveEnvValues,
|
|
3
|
+
export { collectSensitiveEnvValues, } from '../../tool-event-results.js';
|
|
4
4
|
export interface ClaudeSdkMessageTiming {
|
|
5
5
|
receivedAt: string;
|
|
6
6
|
receivedMonotonicMs: number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { sanitizeToolEventResult, } from '../../tool-event-results.js';
|
|
2
|
-
export { collectSensitiveEnvValues,
|
|
2
|
+
export { collectSensitiveEnvValues, } from '../../tool-event-results.js';
|
|
3
3
|
export function hasToolLifecycleBoundary(message) {
|
|
4
4
|
if (message.type !== 'assistant' && message.type !== 'user')
|
|
5
5
|
return false;
|
package/dist/agents/claude.d.ts
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
import { type Options as SdkOptions, type Query } from '@anthropic-ai/claude-agent-sdk';
|
|
25
25
|
import { AgentCommandRunner, AgentSession, AgentSessionOptions, BaseAgent, EnvironmentHandle } from '../types.js';
|
|
26
26
|
/** Shape of the SDK `query()` callable, narrowed for orchestration use. */
|
|
27
|
-
|
|
27
|
+
type ClaudeSdkQueryFn = (args: {
|
|
28
28
|
prompt: string | unknown;
|
|
29
29
|
options?: SdkOptions;
|
|
30
30
|
}) => Query;
|
|
@@ -60,3 +60,4 @@ export declare class ClaudeAgent extends BaseAgent {
|
|
|
60
60
|
constructor(deps?: ClaudeAgentDeps, opts?: ClaudeAgentOptions);
|
|
61
61
|
createSession(runtime: EnvironmentHandle, _runCommand: AgentCommandRunner, sessionOptions?: AgentSessionOptions): Promise<AgentSession>;
|
|
62
62
|
}
|
|
63
|
+
export {};
|
|
@@ -17,6 +17,7 @@ import { CodexItemLifecycle, } from './item-lifecycle.js';
|
|
|
17
17
|
import { createCodexManagedAuth } from './managed-auth.js';
|
|
18
18
|
import { clearTurnAuthorityDeadline, closeUncorrelatedTurnTransport, establishAuthoritativeTurn, isAbortError, isAuthoritativeTurnCompletion, rememberAuthoritativeTurnId, shouldRetireAuthoritativeTurnTransport, } from './turn-authority.js';
|
|
19
19
|
import { dispatchCodexNotification, failTurn } from './turn-notifications.js';
|
|
20
|
+
import { CodexThreadCostAccounting, CodexTurnUsageAccounting, readCodexThreadCost, } from './usage-accounting.js';
|
|
20
21
|
const TURN_COMPLETED_METHOD = 'turn/completed';
|
|
21
22
|
function recordFromUnknown(value) {
|
|
22
23
|
return value && typeof value === 'object' && !Array.isArray(value)
|
|
@@ -74,6 +75,7 @@ export class CodexAppServerAgent extends BaseAgent {
|
|
|
74
75
|
let disposed = false;
|
|
75
76
|
let sessionRetired = false;
|
|
76
77
|
let codexUserAgent = 'unknown';
|
|
78
|
+
const costAccounting = new CodexThreadCostAccounting();
|
|
77
79
|
const managedAuth = createCodexManagedAuth({
|
|
78
80
|
enabled: !runtimeEnv.OPENAI_API_KEY && !runtimeEnv.OPENAI_BASE_URL
|
|
79
81
|
&& (this.deps.authBroker !== undefined || this.deps.createTransport === undefined),
|
|
@@ -165,6 +167,7 @@ export class CodexAppServerAgent extends BaseAgent {
|
|
|
165
167
|
assistantMessageParts: [],
|
|
166
168
|
turnFailed: false,
|
|
167
169
|
pendingTurnCompletions: [],
|
|
170
|
+
usageAccounting: new CodexTurnUsageAccounting(),
|
|
168
171
|
};
|
|
169
172
|
const turnStartController = new AbortController();
|
|
170
173
|
let turnStartCanReuseTransport = false;
|
|
@@ -196,6 +199,7 @@ export class CodexAppServerAgent extends BaseAgent {
|
|
|
196
199
|
throw new Error(`Codex app-server scripted MCP approval policy drift (userAgent=${codexUserAgent})`);
|
|
197
200
|
}
|
|
198
201
|
threadId = resp.thread.id;
|
|
202
|
+
costAccounting.beginThread(threadId);
|
|
199
203
|
}
|
|
200
204
|
const authoritativeThreadId = threadId;
|
|
201
205
|
turn.authoritativeThreadId = authoritativeThreadId;
|
|
@@ -224,14 +228,20 @@ export class CodexAppServerAgent extends BaseAgent {
|
|
|
224
228
|
const authoritativeTurnReady = new Promise((resolve) => {
|
|
225
229
|
resolveAuthoritativeTurn = resolve;
|
|
226
230
|
});
|
|
227
|
-
const markAuthoritativeTurn = (candidateTurnId) =>
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
231
|
+
const markAuthoritativeTurn = (candidateTurnId) => {
|
|
232
|
+
const established = establishAuthoritativeTurn({
|
|
233
|
+
turn,
|
|
234
|
+
candidateTurnId,
|
|
235
|
+
authoritativeThreadId,
|
|
236
|
+
authoritativeTurnIds,
|
|
237
|
+
correlator,
|
|
238
|
+
onReady: () => resolveAuthoritativeTurn?.(),
|
|
239
|
+
});
|
|
240
|
+
if (established)
|
|
241
|
+
turn.usageAccounting.authorize(authoritativeThreadId, candidateTurnId);
|
|
242
|
+
return established;
|
|
243
|
+
};
|
|
244
|
+
let terminalCompletionAccepted = false;
|
|
235
245
|
const turnCompletion = new Promise((resolve, reject) => {
|
|
236
246
|
let settled = false;
|
|
237
247
|
const off = t.onNotification((n) => {
|
|
@@ -253,6 +263,7 @@ export class CodexAppServerAgent extends BaseAgent {
|
|
|
253
263
|
}))
|
|
254
264
|
return;
|
|
255
265
|
settled = true;
|
|
266
|
+
terminalCompletionAccepted = true;
|
|
256
267
|
off();
|
|
257
268
|
closeOff();
|
|
258
269
|
const failure = extractTurnCompletionFailure(params);
|
|
@@ -350,6 +361,9 @@ export class CodexAppServerAgent extends BaseAgent {
|
|
|
350
361
|
sensitiveValues, resolvedModel: model,
|
|
351
362
|
});
|
|
352
363
|
}
|
|
364
|
+
if (terminalCompletionAccepted) {
|
|
365
|
+
turn.costUsd = await readCodexThreadCost(t, authoritativeThreadId, costAccounting, options?.getRemainingMs);
|
|
366
|
+
}
|
|
353
367
|
if (turn.turnFailed) {
|
|
354
368
|
return assembleTurnResult({
|
|
355
369
|
askBus,
|
|
@@ -592,6 +606,8 @@ function assembleTurnResult(args) {
|
|
|
592
606
|
exitCode,
|
|
593
607
|
traceOutput: rawOutput,
|
|
594
608
|
toolEvents, resolvedModel,
|
|
609
|
+
...activeTurn.usageAccounting.result(),
|
|
610
|
+
...(activeTurn.costUsd === undefined ? {} : { costUsd: activeTurn.costUsd }),
|
|
595
611
|
...(exitCode !== 0
|
|
596
612
|
? {
|
|
597
613
|
crashInfo: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
2
|
+
* The 9 client-request methods the pathgrade driver may send to the Codex
|
|
3
3
|
* app-server. Scoped to this driver's surface rather than the full upstream
|
|
4
4
|
* protocol; phantom response-shaped entries are deliberately excluded because
|
|
5
5
|
* JSON-RPC responses to server-initiated requests flow through
|
|
@@ -13,8 +13,9 @@
|
|
|
13
13
|
* - thread/read
|
|
14
14
|
* - thread/list
|
|
15
15
|
* - review/start
|
|
16
|
+
* - account/usage/read
|
|
16
17
|
*/
|
|
17
|
-
export type ClientRequestMethod = 'initialize' | 'thread/start' | 'turn/start' | 'turn/interrupt' | 'thread/inject_items' | 'thread/read' | 'thread/list' | 'review/start';
|
|
18
|
+
export type ClientRequestMethod = 'initialize' | 'thread/start' | 'turn/start' | 'turn/interrupt' | 'thread/inject_items' | 'thread/read' | 'thread/list' | 'review/start' | 'account/usage/read';
|
|
18
19
|
/**
|
|
19
20
|
* JSON-RPC 2.0 client→server request envelope the driver constructs.
|
|
20
21
|
* Generic over the params type for the chosen method.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
type AdditionalFileSystemPermissions = unknown;
|
|
2
|
+
type AdditionalNetworkPermissions = unknown;
|
|
3
3
|
export type GrantedPermissionProfile = {
|
|
4
4
|
network?: AdditionalNetworkPermissions;
|
|
5
5
|
fileSystem?: AdditionalFileSystemPermissions;
|
|
6
6
|
};
|
|
7
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
type JsonValue = unknown;
|
|
2
|
+
type McpElicitationSchema = unknown;
|
|
3
3
|
export type McpElicitationRequestParams = {
|
|
4
4
|
threadId: string;
|
|
5
5
|
/**
|
|
@@ -26,3 +26,4 @@ export type McpElicitationRequestParams = {
|
|
|
26
26
|
url: string;
|
|
27
27
|
elicitationId: string;
|
|
28
28
|
});
|
|
29
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
type AbsolutePathBuf = string;
|
|
2
|
+
type RequestPermissionProfile = unknown;
|
|
3
3
|
export type PermissionsRequestApprovalParams = {
|
|
4
4
|
threadId: string;
|
|
5
5
|
turnId: string;
|
|
@@ -11,3 +11,4 @@ export type PermissionsRequestApprovalParams = {
|
|
|
11
11
|
reason: string | null;
|
|
12
12
|
permissions: RequestPermissionProfile;
|
|
13
13
|
};
|
|
14
|
+
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { SandboxMode } from './SandboxMode.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
type Personality = unknown;
|
|
3
|
+
type JsonValue = unknown;
|
|
4
|
+
type ApprovalsReviewer = 'user' | 'auto_review' | 'guardian_subagent';
|
|
5
|
+
type AskForApproval = 'untrusted' | 'on-request' | {
|
|
6
6
|
granular: {
|
|
7
7
|
sandbox_approval: boolean;
|
|
8
8
|
rules: boolean;
|
|
@@ -11,8 +11,8 @@ export type AskForApproval = 'untrusted' | 'on-request' | {
|
|
|
11
11
|
mcp_elicitations: boolean;
|
|
12
12
|
};
|
|
13
13
|
} | 'never';
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
type ThreadStartSource = unknown;
|
|
15
|
+
type ThreadSource = unknown;
|
|
16
16
|
export type ThreadStartParams = {
|
|
17
17
|
model?: string | null;
|
|
18
18
|
modelProvider?: string | null;
|
|
@@ -39,3 +39,4 @@ export type ThreadStartParams = {
|
|
|
39
39
|
*/
|
|
40
40
|
threadSource?: ThreadSource | null;
|
|
41
41
|
};
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type ThreadUsageBreakdownGroup = {
|
|
2
|
+
model: string | null;
|
|
3
|
+
reasoningEffort: string | null;
|
|
4
|
+
speed: string | null;
|
|
5
|
+
estimatedUsageCreditsMicros: bigint;
|
|
6
|
+
netNewInputTokens: bigint | null;
|
|
7
|
+
cachedInputTokens: bigint | null;
|
|
8
|
+
inputTokens: bigint | null;
|
|
9
|
+
outputTokens: bigint | null;
|
|
10
|
+
totalTokens: bigint | null;
|
|
11
|
+
};
|
|
@@ -14,3 +14,10 @@ export type { McpElicitationRequestParams } from './McpElicitationRequestParams.
|
|
|
14
14
|
export type { ThreadStartParams } from './ThreadStartParams.js';
|
|
15
15
|
export type { SandboxMode } from './SandboxMode.js';
|
|
16
16
|
export type { TurnCompletedNotification } from './TurnCompletedNotification.js';
|
|
17
|
+
export type { TokenUsageBreakdown } from './TokenUsageBreakdown.js';
|
|
18
|
+
export type { ThreadTokenUsage } from './ThreadTokenUsage.js';
|
|
19
|
+
export type { ThreadTokenUsageUpdatedNotification } from './ThreadTokenUsageUpdatedNotification.js';
|
|
20
|
+
export type { ThreadUsageBreakdownGroup } from './ThreadUsageBreakdownGroup.js';
|
|
21
|
+
export type { ThreadUsage } from './ThreadUsage.js';
|
|
22
|
+
export type { GetAccountTokenUsageParams } from './GetAccountTokenUsageParams.js';
|
|
23
|
+
export type { GetAccountTokenUsageResponse } from './GetAccountTokenUsageResponse.js';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Readable, Writable } from 'stream';
|
|
2
|
-
|
|
2
|
+
type Unsubscribe = () => void;
|
|
3
3
|
export interface ServerRequestMessage {
|
|
4
4
|
readonly id: number | string;
|
|
5
5
|
readonly method: string;
|
|
6
6
|
readonly params: unknown;
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
interface ServerNotificationMessage {
|
|
9
9
|
readonly method: string;
|
|
10
10
|
readonly params: unknown;
|
|
11
11
|
}
|
|
@@ -12,6 +12,10 @@ export function dispatchCodexNotification(notification, turn, sensitiveValues) {
|
|
|
12
12
|
}
|
|
13
13
|
if (!turn)
|
|
14
14
|
return;
|
|
15
|
+
if (notification.method === 'thread/tokenUsage/updated') {
|
|
16
|
+
turn.usageAccounting.receive(notification.params, turn.authoritativeThreadId, turn.authoritativeTurnId);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
15
19
|
const params = notification.params;
|
|
16
20
|
if (notification.method === 'item/started') {
|
|
17
21
|
if (params)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ToolEvent } from '../../tool-events.js';
|
|
2
2
|
import type { PendingMcpDenial } from './mcp-approval-correlator.js';
|
|
3
3
|
import type { CodexItemLifecycle } from './item-lifecycle.js';
|
|
4
|
+
import type { CodexTurnUsageAccounting } from './usage-accounting.js';
|
|
4
5
|
export interface ActiveTurnState {
|
|
5
6
|
turnNumber: number;
|
|
6
7
|
askBatchIds: string[];
|
|
@@ -14,6 +15,8 @@ export interface ActiveTurnState {
|
|
|
14
15
|
authoritativeThreadId?: string;
|
|
15
16
|
authoritativeTurnId?: string;
|
|
16
17
|
pendingTurnCompletions: unknown[];
|
|
18
|
+
usageAccounting: CodexTurnUsageAccounting;
|
|
19
|
+
costUsd?: number;
|
|
17
20
|
acceptTurnCompletion?: (params: unknown) => void;
|
|
18
21
|
authorityDeadlineTimer?: ReturnType<typeof setTimeout>;
|
|
19
22
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AgentTurnResult } from '../../types.js';
|
|
2
|
+
import type { AppServerTransport } from './transport.js';
|
|
3
|
+
export declare const WIX_CODEX_USD_PER_CREDIT = 0.034;
|
|
4
|
+
export declare class CodexTurnUsageAccounting {
|
|
5
|
+
private baseline?;
|
|
6
|
+
private latest?;
|
|
7
|
+
private pending;
|
|
8
|
+
authorize(threadId: string, turnId: string): void;
|
|
9
|
+
receive(value: unknown, threadId: string | undefined, turnId: string | undefined): void;
|
|
10
|
+
result(): Pick<AgentTurnResult, 'inputTokens' | 'outputTokens' | 'cacheReadInputTokens' | 'cacheCreationInputTokens'>;
|
|
11
|
+
}
|
|
12
|
+
export declare class CodexThreadCostAccounting {
|
|
13
|
+
private threadId?;
|
|
14
|
+
private cumulativeUsd;
|
|
15
|
+
beginThread(threadId: string): void;
|
|
16
|
+
receive(value: unknown, threadId: string): number | undefined;
|
|
17
|
+
}
|
|
18
|
+
export declare function readCodexThreadCost(transport: AppServerTransport, threadId: string, accounting: CodexThreadCostAccounting, getRemainingMs?: () => number): Promise<number | undefined>;
|