literally-aeo 0.1.0 → 0.2.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/README.md +42 -6
- package/dist/author-tools.js +33 -64
- package/dist/cli.mjs +2723 -1616
- package/dist/lib/agents/author-schema.js +4 -5
- package/dist/lib/agents/author-validation.js +5 -6
- package/dist/lib/agents/copy-validation.js +4 -5
- package/dist/lib/agents/verifier.js +8 -8
- package/dist/lib/analysis/domain-classifier.js +8 -8
- package/dist/lib/analysis/domain-labels.js +3 -4
- package/dist/lib/analysis/progress.js +3 -4
- package/dist/lib/analysis/sentiment.js +8 -8
- package/dist/lib/author/examples.js +5 -6
- package/dist/lib/bundle/contracts.js +5 -6
- package/dist/lib/bundle/export.js +22 -19
- package/dist/lib/bundle/isolation.js +17 -0
- package/dist/lib/bundle/journal.js +6 -7
- package/dist/lib/bundle/project-journal.js +11 -10
- package/dist/lib/bundle/project.js +19 -16
- package/dist/lib/bundle/read.js +23 -20
- package/dist/lib/bundle/recorder.js +9 -8
- package/dist/lib/bundle/redact.js +6 -7
- package/dist/lib/bundle/trace-coverage.js +6 -7
- package/dist/lib/bundle/verify-integrity.js +8 -9
- package/dist/lib/bundle/verify-measurement.js +10 -11
- package/dist/lib/bundle/verify-report.js +11 -12
- package/dist/lib/bundle/verify.js +17 -18
- package/dist/lib/bundle/writer-lock.js +3 -1
- package/dist/lib/capture-manifest.js +3 -4
- package/dist/lib/checks/run-checks.js +10 -9
- package/dist/lib/chunks/chunk-2B5QF6UQ.js +159 -0
- package/dist/lib/chunks/{chunk-4US3OBKJ.js → chunk-2GU6CNQI.js} +12 -7
- package/dist/lib/chunks/{chunk-AWOJWMPN.js → chunk-2ROXN2EC.js} +42 -7
- package/dist/lib/chunks/{chunk-XHWRSGX3.js → chunk-3JO5TXBA.js} +1 -1
- package/dist/lib/chunks/{chunk-5GZVDGTX.js → chunk-4PD65FRJ.js} +7 -3
- package/dist/lib/chunks/{chunk-P4K6BP3L.js → chunk-5JPYM4MD.js} +1 -1
- package/dist/lib/chunks/{chunk-5VNYUCLL.js → chunk-622NMXN6.js} +6 -9
- package/dist/lib/chunks/{chunk-4ZY6P5SO.js → chunk-663HABKP.js} +5 -5
- package/dist/lib/chunks/{chunk-RMFT4KKK.js → chunk-6G25V4CF.js} +1 -1
- package/dist/lib/chunks/{chunk-GVC4LH2N.js → chunk-6GHHNPFJ.js} +1 -1
- package/dist/lib/chunks/{chunk-KMRQSIZW.js → chunk-6GOBBNDU.js} +16 -1
- package/dist/lib/chunks/{chunk-SBAZBOPI.js → chunk-6P7EZJI7.js} +4 -2
- package/dist/lib/chunks/chunk-7XO3SQAX.js +117 -0
- package/dist/lib/chunks/{chunk-M2OD74GP.js → chunk-7Z27HQWL.js} +3 -3
- package/dist/lib/chunks/{chunk-IPNK7FYT.js → chunk-AYY4MYTW.js} +1 -1
- package/dist/lib/chunks/{chunk-WDSCJEDG.js → chunk-BE4ENGUY.js} +10 -10
- package/dist/lib/chunks/{chunk-FKLNEB2P.js → chunk-BGOIPHJZ.js} +39 -11
- package/dist/lib/chunks/{chunk-7GXRDAUY.js → chunk-BLKLPUYR.js} +2 -2
- package/dist/lib/chunks/chunk-BSRKN6FU.js +93 -0
- package/dist/lib/chunks/{chunk-PCYNBDZ7.js → chunk-CO5T6WU5.js} +14 -9
- package/dist/lib/chunks/{chunk-BEQLSAVX.js → chunk-CUYVHXHI.js} +2 -2
- package/dist/lib/chunks/{chunk-RBOO4NDG.js → chunk-D3GE3OCB.js} +1 -1
- package/dist/lib/chunks/chunk-DVFFYY5G.js +74 -0
- package/dist/lib/chunks/{chunk-5H3SNUQT.js → chunk-EBUQPCKB.js} +1 -1
- package/dist/lib/chunks/{chunk-4E4NDGOZ.js → chunk-EE26FNSY.js} +1 -1
- package/dist/lib/chunks/{chunk-AUB5THIS.js → chunk-EJ655TVU.js} +1 -1
- package/dist/lib/chunks/{chunk-S2AM76LT.js → chunk-F4W5YHDZ.js} +2 -2
- package/dist/lib/chunks/chunk-FAUFE7MI.js +31 -0
- package/dist/lib/chunks/{chunk-2KJZ326K.js → chunk-FOCJ7HPC.js} +7 -7
- package/dist/lib/chunks/{chunk-OL746E4T.js → chunk-FUAUPNRO.js} +26 -18
- package/dist/lib/chunks/{chunk-J6IJGYP5.js → chunk-G62E525I.js} +2 -2
- package/dist/lib/chunks/{chunk-2NJEWPCV.js → chunk-GDKGZQ3T.js} +2 -2
- package/dist/lib/chunks/{chunk-HSZ3DM74.js → chunk-GEFKDW7X.js} +15 -2
- package/dist/lib/chunks/{chunk-CS24IL3K.js → chunk-GESHTTSA.js} +2 -2
- package/dist/lib/chunks/chunk-GNMFJ2OK.js +321 -0
- package/dist/lib/chunks/{chunk-H3G3VTT7.js → chunk-HFRAHG5C.js} +44 -26
- package/dist/lib/chunks/{chunk-MHAKYFDF.js → chunk-HQG63ZKO.js} +11 -11
- package/dist/lib/chunks/{chunk-OORO55OM.js → chunk-HTOD4W4E.js} +21 -6
- package/dist/lib/chunks/{chunk-Q2PWES4B.js → chunk-I3XGRGXE.js} +1 -1
- package/dist/lib/chunks/{chunk-WUELMJ22.js → chunk-IE7NAL6B.js} +1 -1
- package/dist/lib/chunks/{chunk-KRFHQQS7.js → chunk-JXMDOAKA.js} +17 -17
- package/dist/lib/chunks/{chunk-S7KJZIUR.js → chunk-KJMU5KH4.js} +2 -2
- package/dist/lib/chunks/{chunk-2ROSV4HD.js → chunk-L7MEIRJB.js} +1 -1
- package/dist/lib/chunks/{chunk-CPT2GKKW.js → chunk-LOBXOZ2R.js} +1 -1
- package/dist/lib/chunks/{chunk-IAR6XGEW.js → chunk-ML4W6KC6.js} +1 -1
- package/dist/lib/chunks/{chunk-WKH6BJAZ.js → chunk-MNWO7EHC.js} +4 -4
- package/dist/lib/chunks/{chunk-D2LPQO6Y.js → chunk-MRL5RUP7.js} +1 -1
- package/dist/lib/chunks/{chunk-IEVAFDW7.js → chunk-NCXSNHXX.js} +3 -3
- package/dist/lib/chunks/{chunk-AKKFERA4.js → chunk-NGHAP2P5.js} +4 -4
- package/dist/lib/chunks/{chunk-ZLOOC46D.js → chunk-OKL7GN2F.js} +3 -3
- package/dist/lib/chunks/{chunk-YOZNLFSB.js → chunk-OQU5IXAJ.js} +5 -5
- package/dist/lib/chunks/{chunk-I7VNIW6Q.js → chunk-OU73OUX4.js} +16 -10
- package/dist/lib/chunks/{chunk-56VOFZ7T.js → chunk-QHUDJVPJ.js} +90 -24
- package/dist/lib/chunks/{chunk-WTQWU522.js → chunk-QSJ4IKUF.js} +9 -9
- package/dist/lib/chunks/{chunk-FBFZBLTY.js → chunk-R6XDZWUL.js} +7 -8
- package/dist/lib/chunks/{chunk-CJ5YD3CU.js → chunk-RJ5R6YYA.js} +5 -5
- package/dist/lib/chunks/{chunk-5EX5DKMA.js → chunk-RR46EDDR.js} +33 -25
- package/dist/lib/chunks/chunk-RYCRL3YA.js +106 -0
- package/dist/lib/chunks/{chunk-Z4LMDKBU.js → chunk-SHUMCKCS.js} +2 -2
- package/dist/lib/chunks/{chunk-3EBWDHPK.js → chunk-TJQ5OPLQ.js} +10 -12
- package/dist/lib/chunks/chunk-U64NCRRR.js +97 -0
- package/dist/lib/chunks/chunk-U772TN32.js +67 -0
- package/dist/lib/chunks/{chunk-YR67JG2V.js → chunk-UEMZYHYJ.js} +8 -3
- package/dist/lib/chunks/{chunk-J46W3EMQ.js → chunk-UZJSTJFP.js} +5 -5
- package/dist/lib/chunks/{chunk-XJVXASDD.js → chunk-V7OAPKNF.js} +3 -3
- package/dist/lib/chunks/{chunk-WE2WPNG2.js → chunk-VKM6MMA4.js} +66 -7
- package/dist/lib/chunks/{chunk-YWJPJI3W.js → chunk-VL253W5C.js} +3 -1
- package/dist/lib/chunks/{chunk-XU6WQ5UL.js → chunk-VPZQGND4.js} +3 -3
- package/dist/lib/chunks/{chunk-X2Y2ZNG3.js → chunk-W2VGLWTS.js} +3 -3
- package/dist/lib/chunks/{chunk-6AUEDSTU.js → chunk-W5DC23OP.js} +1 -1
- package/dist/lib/chunks/chunk-W5X7WJYL.js +91 -0
- package/dist/lib/chunks/{chunk-QFVRCSJ2.js → chunk-WDOA5JEH.js} +2 -0
- package/dist/lib/chunks/{chunk-6KO7HGCQ.js → chunk-WVACVWBL.js} +2 -2
- package/dist/lib/chunks/{chunk-MIF5IYNR.js → chunk-XDG6NPJB.js} +26 -29
- package/dist/lib/chunks/{chunk-X6E44EGV.js → chunk-XR44YSHT.js} +2 -2
- package/dist/lib/chunks/chunk-Y2CZ6FZY.js +61 -0
- package/dist/lib/chunks/{chunk-5KKLUM7M.js → chunk-YAAUWCJ4.js} +1 -1
- package/dist/lib/chunks/{chunk-N2ZZ6JRF.js → chunk-YRBIC5QH.js} +1 -1
- package/dist/lib/chunks/chunk-ZIGNJAPC.js +11 -0
- package/dist/lib/cli/bundle-commands.js +71 -65
- package/dist/lib/cli/guide-command.js +25 -0
- package/dist/lib/cli/io.js +1 -1
- package/dist/lib/cli/run-commands.js +270 -104
- package/dist/lib/cli/status-command.js +234 -0
- package/dist/lib/codex-workflow/aggregate.js +8 -9
- package/dist/lib/codex-workflow/author-tools.js +6 -7
- package/dist/lib/codex-workflow/author.js +17 -17
- package/dist/lib/codex-workflow/capture.js +10 -9
- package/dist/lib/codex-workflow/checkpoint.js +6 -7
- package/dist/lib/codex-workflow/checks.js +6 -7
- package/dist/lib/codex-workflow/codex-binary.js +13 -0
- package/dist/lib/codex-workflow/codex-home.js +6 -3
- package/dist/lib/codex-workflow/copy-editor.js +14 -14
- package/dist/lib/codex-workflow/copy-recovery.js +3 -4
- package/dist/lib/codex-workflow/copy.js +11 -11
- package/dist/lib/codex-workflow/finish.js +17 -18
- package/dist/lib/codex-workflow/host-models.js +7 -7
- package/dist/lib/codex-workflow/loop.js +42 -38
- package/dist/lib/codex-workflow/quality.js +3 -4
- package/dist/lib/codex-workflow/run-inputs.js +5 -6
- package/dist/lib/codex-workflow/run-source.js +14 -13
- package/dist/lib/codex-workflow/schemas.js +5 -6
- package/dist/lib/codex-workflow/session.js +7 -8
- package/dist/lib/codex-workflow/stage.js +26 -23
- package/dist/lib/codex-workflow/workdir.js +6 -7
- package/dist/lib/engine/audit-file.js +7 -6
- package/dist/lib/engine/author.js +37 -31
- package/dist/lib/engine/budget.js +7 -1
- package/dist/lib/engine/cost-estimate.js +41 -0
- package/dist/lib/engine/local-run.js +48 -42
- package/dist/lib/engine/preflight.js +10 -6
- package/dist/lib/engine/rejudge.js +56 -50
- package/dist/lib/engine/resources.js +1 -1
- package/dist/lib/engine/run-configuration.js +2 -1
- package/dist/lib/engine/run-status.js +151 -0
- package/dist/lib/engine/templates.js +8 -7
- package/dist/lib/grounding/controller.js +7 -7
- package/dist/lib/grounding/extract.js +6 -6
- package/dist/lib/grounding/grounding-runtime.js +18 -17
- package/dist/lib/grounding/model.js +5 -5
- package/dist/lib/grounding/recorded-tools.js +10 -9
- package/dist/lib/harness/report/artifacts.js +4 -5
- package/dist/lib/lib/checkpoint.js +3 -4
- package/dist/lib/models/batching.js +5 -5
- package/dist/lib/models/cost-coefficients.js +20 -0
- package/dist/lib/models/local-profile.js +10 -0
- package/dist/lib/models/pricing.js +6 -0
- package/dist/lib/models/profiles.js +7 -14
- package/dist/lib/models/structured-images.js +1 -1
- package/dist/lib/models/structured.js +4 -4
- package/dist/lib/models/supported-models.js +20 -0
- package/dist/lib/pipeline.js +9 -8
- package/dist/lib/probes/agent-cli-parsers.js +1 -1
- package/dist/lib/probes/agent-clis.js +6 -5
- package/dist/lib/probes/charged-trace.js +10 -0
- package/dist/lib/probes/probes.js +6 -6
- package/dist/lib/runner.js +10 -10
- package/dist/lib/schema.js +3 -4
- package/dist/lib/section-result.js +3 -4
- package/dist/lib/stores/artifacts.js +3 -4
- package/dist/lib/stores/files.js +9 -9
- package/dist/lib/stores/local-versions.js +4 -5
- package/dist/lib/stores/memory.js +6 -7
- package/dist/lib/stores/publication.js +5 -6
- package/dist/lib/viewer/server.js +18 -19
- package/dist/lib/workflow/schema.js +2 -3
- package/dist/types/agents/copy-validation.d.ts +4 -4
- package/dist/types/agents/verifier.d.ts +6 -6
- package/dist/types/bundle/contracts.d.ts +1 -1
- package/dist/types/bundle/isolation.d.ts +37 -0
- package/dist/types/bundle/project-journal.d.ts +2 -0
- package/dist/types/bundle/recorder.d.ts +4 -0
- package/dist/types/bundle/writer-lock.d.ts +9 -0
- package/dist/types/cli/guide-command.d.ts +4 -0
- package/dist/types/cli/status-command.d.ts +2 -0
- package/dist/types/codex-workflow/codex-binary.d.ts +26 -0
- package/dist/types/codex-workflow/codex-home.d.ts +24 -20
- package/dist/types/codex-workflow/copy-editor.d.ts +1 -1
- package/dist/types/codex-workflow/copy.d.ts +3 -4
- package/dist/types/codex-workflow/finish.d.ts +5 -3
- package/dist/types/codex-workflow/host-models.d.ts +7 -3
- package/dist/types/codex-workflow/loop.d.ts +10 -1
- package/dist/types/codex-workflow/run-inputs.d.ts +28 -113
- package/dist/types/codex-workflow/stage.d.ts +16 -5
- package/dist/types/engine/audit-file.d.ts +3 -2
- package/dist/types/engine/author.d.ts +7 -1
- package/dist/types/engine/budget.d.ts +46 -15
- package/dist/types/engine/cost-estimate.d.ts +40 -0
- package/dist/types/engine/local-run.d.ts +6 -0
- package/dist/types/engine/preflight.d.ts +5 -0
- package/dist/types/engine/resources.d.ts +2 -0
- package/dist/types/engine/run-configuration.d.ts +4 -3
- package/dist/types/engine/run-status.d.ts +75 -0
- package/dist/types/engine/templates.d.ts +1 -2
- package/dist/types/models/cost-coefficients.d.ts +106 -0
- package/dist/types/models/local-profile.d.ts +12 -0
- package/dist/types/models/pricing.d.ts +8 -0
- package/dist/types/models/profiles.d.ts +55 -160
- package/dist/types/models/served-model.d.ts +2 -3
- package/dist/types/models/structured.d.ts +3 -3
- package/dist/types/models/supported-models.d.ts +48 -0
- package/dist/types/probes/charged-trace.d.ts +8 -0
- package/dist/types/probes/probe-trace.d.ts +2 -0
- package/dist/types/schema.d.ts +28 -113
- package/dist/types/workflow/schema.d.ts +79 -152
- package/package.json +2 -1
- package/resources/guide/OPERATOR.md +180 -0
- package/src/agents/copy-validation.ts +8 -12
- package/src/agents/verifier.ts +10 -14
- package/src/bundle/contracts.ts +3 -3
- package/src/bundle/isolation.ts +157 -0
- package/src/bundle/project-journal.ts +4 -0
- package/src/bundle/project.ts +20 -7
- package/src/bundle/recorder.ts +5 -0
- package/src/bundle/writer-lock.ts +27 -0
- package/src/cli/guide-command.ts +28 -0
- package/src/cli/io.ts +2 -0
- package/src/cli/literally-aeo.ts +39 -19
- package/src/cli/run-commands.ts +236 -18
- package/src/cli/status-command.ts +113 -0
- package/src/codex-workflow/codex-binary.ts +105 -0
- package/src/codex-workflow/codex-home.ts +50 -40
- package/src/codex-workflow/copy.ts +7 -10
- package/src/codex-workflow/finish.ts +13 -8
- package/src/codex-workflow/host-models.ts +33 -24
- package/src/codex-workflow/loop.ts +36 -9
- package/src/codex-workflow/stage.ts +126 -17
- package/src/engine/audit-file.ts +10 -8
- package/src/engine/author.ts +47 -2
- package/src/engine/budget.ts +138 -43
- package/src/engine/cost-estimate.ts +178 -0
- package/src/engine/guide/OPERATOR.md +180 -0
- package/src/engine/local-run.ts +38 -8
- package/src/engine/preflight.ts +90 -7
- package/src/engine/resources.ts +9 -4
- package/src/engine/run-configuration.ts +19 -1
- package/src/engine/run-status.ts +452 -0
- package/src/engine/templates.ts +5 -2
- package/src/models/cost-coefficients.ts +140 -0
- package/src/models/local-profile.ts +150 -0
- package/src/models/pricing.ts +31 -0
- package/src/models/profiles.ts +58 -419
- package/src/models/served-model.ts +2 -3
- package/src/models/structured-images.ts +5 -4
- package/src/models/structured.ts +20 -7
- package/src/models/supported-models.ts +112 -0
- package/src/probes/agent-clis.ts +24 -2
- package/src/probes/charged-trace.ts +87 -0
- package/src/probes/probe-trace.ts +2 -0
- package/src/probes/probes.ts +48 -2
- package/dist/lib/chunks/chunk-CFFPOTP4.js +0 -356
- package/dist/lib/chunks/chunk-LIZX4N3H.js +0 -110
- package/dist/lib/chunks/chunk-OYKV5NDM.js +0 -28
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
import { readFile, stat } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import type { BundleEvent } from '../bundle/contracts';
|
|
5
|
+
import { readJournal } from '../bundle/journal';
|
|
6
|
+
import { runJournalDir } from '../bundle/recorder';
|
|
7
|
+
import { readWriterLock, type WriterLockState } from '../bundle/writer-lock';
|
|
8
|
+
import { readRunInputs } from '../codex-workflow/run-inputs';
|
|
9
|
+
import { unitRecordKey } from '../lib/checkpoint';
|
|
10
|
+
import { chargedCall } from '../models/accounting';
|
|
11
|
+
import { hasErrorCode } from '../stores/fs-errors';
|
|
12
|
+
import { FileProbeStore } from '../stores/files';
|
|
13
|
+
import { capturePlan } from '../capture-manifest';
|
|
14
|
+
import { localReportKey, readAuditFile, toAuditConfig } from './audit-file';
|
|
15
|
+
import { budgetFile } from './budget';
|
|
16
|
+
import { bankDir, runDirectoryState } from './local-run';
|
|
17
|
+
import { auditCopyFile } from './run-configuration';
|
|
18
|
+
|
|
19
|
+
// ============================================================================
|
|
20
|
+
// `literally-aeo status` (specs/aeo-claude-operator-spec.md §4.5): a
|
|
21
|
+
// read-only view of a run directory for whoever watches a run, a person or
|
|
22
|
+
// an agent polling it. It reads the journal, the ledger, the frozen budget
|
|
23
|
+
// and the bank; it never takes the writer lock and never writes, so it is
|
|
24
|
+
// safe beside a live writer. What a file does not say is reported as
|
|
25
|
+
// unknown, never filled in.
|
|
26
|
+
// ============================================================================
|
|
27
|
+
|
|
28
|
+
export const SpendCategory = {
|
|
29
|
+
PROBES: 'probes',
|
|
30
|
+
STAGES: 'stages',
|
|
31
|
+
HOST_CALLS: 'hostCalls',
|
|
32
|
+
SEARCH: 'search',
|
|
33
|
+
} as const;
|
|
34
|
+
|
|
35
|
+
export type SpendCategory = (typeof SpendCategory)[keyof typeof SpendCategory];
|
|
36
|
+
|
|
37
|
+
/** spendCategoryOf names the kind of paid work a ledger role charges:
|
|
38
|
+
* `stage:` Codex sessions, `probe:` assistant answers, `search:` and
|
|
39
|
+
* grounding's research searches, everything else the host's model calls. */
|
|
40
|
+
export const spendCategoryOf = (role: string): SpendCategory => {
|
|
41
|
+
if (role.startsWith('stage:')) {
|
|
42
|
+
return SpendCategory.STAGES;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (role.startsWith('probe:')) {
|
|
46
|
+
return SpendCategory.PROBES;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (role.startsWith('search:') || role === 'research_search') {
|
|
50
|
+
return SpendCategory.SEARCH;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return SpendCategory.HOST_CALLS;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// The ledger as BANK/model-budget.json holds it (src/models/accounting.ts),
|
|
57
|
+
// read loosely: status reports what is there and never refuses a ledger a
|
|
58
|
+
// newer engine wrote.
|
|
59
|
+
const ledgerCallSchema = z.looseObject({
|
|
60
|
+
callId: z.string(),
|
|
61
|
+
role: z.string(),
|
|
62
|
+
reservedUsd: z.number(),
|
|
63
|
+
inputTokens: z.number(),
|
|
64
|
+
maxOutputTokens: z.number(),
|
|
65
|
+
usage: z
|
|
66
|
+
.looseObject({
|
|
67
|
+
costUsd: z.number().optional(),
|
|
68
|
+
inputTokens: z.number().optional(),
|
|
69
|
+
outputTokens: z.number().optional(),
|
|
70
|
+
})
|
|
71
|
+
.optional(),
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const ledgerSchema = z.looseObject({
|
|
75
|
+
limits: z.looseObject({ maxUsd: z.number(), deadlineAt: z.string() }),
|
|
76
|
+
calls: z.record(z.string(), ledgerCallSchema),
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const budgetStateSchema = z.looseObject({
|
|
80
|
+
current: z.looseObject({ maxUsd: z.number() }),
|
|
81
|
+
deadlineAt: z.string(),
|
|
82
|
+
model: z.string().optional(),
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
export type CategorySpend = { usd: number; calls: number };
|
|
86
|
+
|
|
87
|
+
export type RunSpend = {
|
|
88
|
+
currency: 'USD';
|
|
89
|
+
/** The run's frozen cap; undefined before the first run froze one. */
|
|
90
|
+
capUsd: number | undefined;
|
|
91
|
+
/** The model the run froze with its cap. */
|
|
92
|
+
model: string | undefined;
|
|
93
|
+
deadlineAt: string | undefined;
|
|
94
|
+
/** What every call charges: settled cost, else its reservation. */
|
|
95
|
+
chargedUsd: number;
|
|
96
|
+
/** Settled calls: at their reported cost, or at their reservation when
|
|
97
|
+
* the provider reported none. */
|
|
98
|
+
settledUsd: number;
|
|
99
|
+
/** Calls reserved and not settled: dispatched, or lost with a process. */
|
|
100
|
+
openUsd: number;
|
|
101
|
+
remainingUsd: number | undefined;
|
|
102
|
+
byCategory: Record<SpendCategory, CategorySpend>;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export type RunActivity = {
|
|
106
|
+
kind: string;
|
|
107
|
+
/** The Codex stage, for a session. */
|
|
108
|
+
stage: string | undefined;
|
|
109
|
+
/** The model role or surface, for a host call or probe. */
|
|
110
|
+
role: string | undefined;
|
|
111
|
+
at: string;
|
|
112
|
+
/** Started and not yet finished. */
|
|
113
|
+
open: boolean;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export type RunStatus = {
|
|
117
|
+
dir: string;
|
|
118
|
+
state: 'new' | 'resumable' | 'completed';
|
|
119
|
+
writer:
|
|
120
|
+
| {
|
|
121
|
+
purpose: string;
|
|
122
|
+
pid: number;
|
|
123
|
+
host: string;
|
|
124
|
+
since: string;
|
|
125
|
+
state: WriterLockState;
|
|
126
|
+
}
|
|
127
|
+
| undefined;
|
|
128
|
+
/** The run's phase as its journal shows it last. */
|
|
129
|
+
phase: string | undefined;
|
|
130
|
+
lastActivity: RunActivity | undefined;
|
|
131
|
+
/** The Codex stage outputs present in OUT/. */
|
|
132
|
+
completedStages: string[];
|
|
133
|
+
answers: { planned: number | undefined; captured: number; failed: number };
|
|
134
|
+
spend: RunSpend;
|
|
135
|
+
lastError:
|
|
136
|
+
{ type: string; error: string; reason: string; at: string } | undefined;
|
|
137
|
+
stoppedAtBudget: boolean;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const workflowStages = ['analyze', 'qualify', 'review', 'write'] as const;
|
|
141
|
+
|
|
142
|
+
const readText = async (file: string): Promise<string | undefined> => {
|
|
143
|
+
try {
|
|
144
|
+
return await readFile(file, 'utf8');
|
|
145
|
+
} catch (err) {
|
|
146
|
+
if (hasErrorCode(err, 'ENOENT')) {
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
throw err;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const exists = async (file: string): Promise<boolean> => {
|
|
155
|
+
try {
|
|
156
|
+
await stat(file);
|
|
157
|
+
|
|
158
|
+
return true;
|
|
159
|
+
} catch (err) {
|
|
160
|
+
if (hasErrorCode(err, 'ENOENT')) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
throw err;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const parseJson = (text: string | undefined): unknown => {
|
|
169
|
+
if (text === undefined) {
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
try {
|
|
174
|
+
return JSON.parse(text);
|
|
175
|
+
} catch {
|
|
176
|
+
// A file torn by a live writer reads as absent until it is whole.
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const readEvents = async (dir: string): Promise<BundleEvent[]> => {
|
|
182
|
+
const text = await readText(path.join(dir, runJournalDir, 'events.jsonl'));
|
|
183
|
+
|
|
184
|
+
// A damaged chain still reports the events before the damage.
|
|
185
|
+
return text === undefined ? [] : readJournal(text).events;
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
const stringField = (value: unknown): string | undefined => {
|
|
189
|
+
return typeof value === 'string' ? value : undefined;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const phaseOf = (activity: RunActivity): string => {
|
|
193
|
+
switch (activity.kind) {
|
|
194
|
+
case 'probe':
|
|
195
|
+
case 'canary':
|
|
196
|
+
return 'capture';
|
|
197
|
+
|
|
198
|
+
case 'technical_check':
|
|
199
|
+
return 'technical checks';
|
|
200
|
+
|
|
201
|
+
case 'research_tool':
|
|
202
|
+
return 'grounding';
|
|
203
|
+
|
|
204
|
+
case 'codex_session':
|
|
205
|
+
return activity.stage ?? 'codex session';
|
|
206
|
+
|
|
207
|
+
default:
|
|
208
|
+
return activity.role ?? activity.kind;
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const lastActivityOf = (
|
|
213
|
+
events: readonly BundleEvent[],
|
|
214
|
+
): RunActivity | undefined => {
|
|
215
|
+
const started = events.findLast(
|
|
216
|
+
(event) => event.type === 'operation_started',
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
if (!started) {
|
|
220
|
+
return undefined;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const finished = events.some(
|
|
224
|
+
(event) =>
|
|
225
|
+
event.type === 'operation_finished' &&
|
|
226
|
+
event.operationId === started.operationId,
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
const activity: RunActivity = {
|
|
230
|
+
kind: stringField(started.payload.kind) ?? 'unknown',
|
|
231
|
+
stage: stringField(started.payload.stage),
|
|
232
|
+
role: stringField(started.payload.role),
|
|
233
|
+
at: started.at,
|
|
234
|
+
open: !finished,
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
return activity;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
/** The workflow's own end, when the journal's latest writer recorded one. */
|
|
241
|
+
const endOf = (events: readonly BundleEvent[]): BundleEvent | undefined => {
|
|
242
|
+
const writerStart = events.findLastIndex(
|
|
243
|
+
(event) => event.type === 'run_started' || event.type === 'run_resumed',
|
|
244
|
+
);
|
|
245
|
+
const end = events
|
|
246
|
+
.slice(Math.max(writerStart, 0))
|
|
247
|
+
.findLast((event) =>
|
|
248
|
+
['run_completed', 'run_failed', 'run_interrupted'].includes(event.type),
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
return end;
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
const lastErrorOf = (
|
|
255
|
+
events: readonly BundleEvent[],
|
|
256
|
+
): RunStatus['lastError'] => {
|
|
257
|
+
const failure = events.findLast(
|
|
258
|
+
(event) => event.type === 'run_failed' || event.type === 'run_interrupted',
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
if (!failure) {
|
|
262
|
+
return undefined;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const lastError = {
|
|
266
|
+
type: failure.type,
|
|
267
|
+
error: stringField(failure.payload.error) ?? 'unknown',
|
|
268
|
+
reason: stringField(failure.payload.reason) ?? '',
|
|
269
|
+
at: failure.at,
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
return lastError;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
const emptySpend = (): Record<SpendCategory, CategorySpend> => {
|
|
276
|
+
return {
|
|
277
|
+
probes: { usd: 0, calls: 0 },
|
|
278
|
+
stages: { usd: 0, calls: 0 },
|
|
279
|
+
hostCalls: { usd: 0, calls: 0 },
|
|
280
|
+
search: { usd: 0, calls: 0 },
|
|
281
|
+
};
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
const readSpend = async (dir: string): Promise<RunSpend> => {
|
|
285
|
+
const ledger = ledgerSchema.safeParse(
|
|
286
|
+
parseJson(await readText(path.join(dir, bankDir, 'model-budget.json'))),
|
|
287
|
+
);
|
|
288
|
+
const budget = budgetStateSchema.safeParse(
|
|
289
|
+
parseJson(await readText(path.join(dir, budgetFile))),
|
|
290
|
+
);
|
|
291
|
+
const limits = ledger.success ? ledger.data.limits : undefined;
|
|
292
|
+
const byCategory = emptySpend();
|
|
293
|
+
let settledUsd = 0;
|
|
294
|
+
let openUsd = 0;
|
|
295
|
+
|
|
296
|
+
for (const call of Object.values(ledger.success ? ledger.data.calls : {})) {
|
|
297
|
+
const charge = chargedCall(call);
|
|
298
|
+
const category = byCategory[spendCategoryOf(call.role)];
|
|
299
|
+
|
|
300
|
+
category.usd += charge.usd;
|
|
301
|
+
category.calls += 1;
|
|
302
|
+
|
|
303
|
+
if (call.usage === undefined) {
|
|
304
|
+
openUsd += charge.usd;
|
|
305
|
+
} else {
|
|
306
|
+
settledUsd += charge.usd;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const capUsd = budget.success ? budget.data.current.maxUsd : limits?.maxUsd;
|
|
311
|
+
const chargedUsd = settledUsd + openUsd;
|
|
312
|
+
|
|
313
|
+
const spend: RunSpend = {
|
|
314
|
+
currency: 'USD',
|
|
315
|
+
capUsd,
|
|
316
|
+
model: budget.success ? budget.data.model : undefined,
|
|
317
|
+
deadlineAt: budget.success ? budget.data.deadlineAt : limits?.deadlineAt,
|
|
318
|
+
chargedUsd,
|
|
319
|
+
settledUsd,
|
|
320
|
+
openUsd,
|
|
321
|
+
remainingUsd:
|
|
322
|
+
capUsd === undefined ? undefined : Math.max(capUsd - chargedUsd, 0),
|
|
323
|
+
byCategory,
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
return spend;
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
/** The planned unit keys of the run, from the audit.json it ran from, or
|
|
330
|
+
* from its prepared inputs when that copy is unreadable. */
|
|
331
|
+
const plannedUnitsOf = async (
|
|
332
|
+
dir: string,
|
|
333
|
+
): Promise<
|
|
334
|
+
{ reportKey: string; keys: Set<string> | undefined } | undefined
|
|
335
|
+
> => {
|
|
336
|
+
const auditCopy = path.join(dir, auditCopyFile);
|
|
337
|
+
|
|
338
|
+
if (await exists(auditCopy)) {
|
|
339
|
+
try {
|
|
340
|
+
const file = await readAuditFile(auditCopy);
|
|
341
|
+
// The capture plan alone: what a run measures, independent of the
|
|
342
|
+
// model and budget it runs under.
|
|
343
|
+
const plan = capturePlan(toAuditConfig(file), file.surfaces);
|
|
344
|
+
|
|
345
|
+
return {
|
|
346
|
+
reportKey: localReportKey(file),
|
|
347
|
+
keys: new Set(plan.units.map(unitRecordKey)),
|
|
348
|
+
};
|
|
349
|
+
} catch {
|
|
350
|
+
// An audit.json this engine no longer reads: fall back to the inputs.
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const inputs = await readRunInputs(dir).catch(() => undefined);
|
|
355
|
+
|
|
356
|
+
if (!inputs) {
|
|
357
|
+
return undefined;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// The prepared inputs carry the plan's size, not its keys.
|
|
361
|
+
return { reportKey: inputs.reportKey, keys: undefined };
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
const readAnswers = async (dir: string): Promise<RunStatus['answers']> => {
|
|
365
|
+
const planned = await plannedUnitsOf(dir);
|
|
366
|
+
|
|
367
|
+
if (!planned) {
|
|
368
|
+
return { planned: undefined, captured: 0, failed: 0 };
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
const bank = await FileProbeStore.open(planned.reportKey, {
|
|
372
|
+
dir: path.join(dir, bankDir),
|
|
373
|
+
});
|
|
374
|
+
const records = (await bank.list()).filter(
|
|
375
|
+
(record) =>
|
|
376
|
+
planned.keys === undefined || planned.keys.has(unitRecordKey(record)),
|
|
377
|
+
);
|
|
378
|
+
const inputs =
|
|
379
|
+
planned.keys === undefined
|
|
380
|
+
? await readRunInputs(dir).catch(() => undefined)
|
|
381
|
+
: undefined;
|
|
382
|
+
|
|
383
|
+
const answers = {
|
|
384
|
+
planned: planned.keys?.size ?? inputs?.capture.plannedUnits,
|
|
385
|
+
captured: records.filter((record) => record.status === 'captured').length,
|
|
386
|
+
failed: records.filter((record) => record.status !== 'captured').length,
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
return answers;
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
/** readRunStatus reads a run directory's state; undefined when it holds no
|
|
393
|
+
* run (no journal, no bank, no prepared inputs). */
|
|
394
|
+
export const readRunStatus = async (
|
|
395
|
+
dir: string,
|
|
396
|
+
): Promise<RunStatus | undefined> => {
|
|
397
|
+
const [events, directoryState, hasBank, hasJournal] = await Promise.all([
|
|
398
|
+
readEvents(dir),
|
|
399
|
+
runDirectoryState(dir),
|
|
400
|
+
exists(path.join(dir, bankDir)),
|
|
401
|
+
exists(path.join(dir, runJournalDir, 'events.jsonl')),
|
|
402
|
+
]);
|
|
403
|
+
|
|
404
|
+
if (directoryState === 'new' && !hasBank && !hasJournal) {
|
|
405
|
+
return undefined;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const lock = await readWriterLock(dir);
|
|
409
|
+
const lastActivity = lastActivityOf(events);
|
|
410
|
+
const end = endOf(events);
|
|
411
|
+
const completedStages: string[] = [];
|
|
412
|
+
|
|
413
|
+
for (const stage of workflowStages) {
|
|
414
|
+
if (await exists(path.join(dir, 'OUT', `${stage}.json`))) {
|
|
415
|
+
completedStages.push(stage);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
const lastError = lastErrorOf(events);
|
|
420
|
+
let phase = lastActivity && phaseOf(lastActivity);
|
|
421
|
+
|
|
422
|
+
if (directoryState === 'completed') {
|
|
423
|
+
phase = 'completed';
|
|
424
|
+
} else if (end?.type === 'run_failed') {
|
|
425
|
+
phase = 'stopped';
|
|
426
|
+
} else if (end?.type === 'run_interrupted') {
|
|
427
|
+
phase = 'interrupted';
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
const status: RunStatus = {
|
|
431
|
+
dir,
|
|
432
|
+
// Answers already banked make the next run a resume, not a start.
|
|
433
|
+
state: directoryState === 'new' ? 'resumable' : directoryState,
|
|
434
|
+
writer: lock && {
|
|
435
|
+
purpose: lock.owner.purpose,
|
|
436
|
+
pid: lock.owner.pid,
|
|
437
|
+
host: lock.owner.host,
|
|
438
|
+
since: lock.owner.acquiredAt,
|
|
439
|
+
state: lock.state,
|
|
440
|
+
},
|
|
441
|
+
phase,
|
|
442
|
+
lastActivity,
|
|
443
|
+
completedStages,
|
|
444
|
+
answers: await readAnswers(dir),
|
|
445
|
+
spend: await readSpend(dir),
|
|
446
|
+
lastError,
|
|
447
|
+
stoppedAtBudget:
|
|
448
|
+
end?.type === 'run_failed' && end.payload.error === 'ModelBudgetError',
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
return status;
|
|
452
|
+
};
|
package/src/engine/templates.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { z } from 'zod';
|
|
2
|
+
import { recommendedModelId } from '../models/supported-models';
|
|
2
3
|
import { auditFileVersion, type auditFileSchema } from './audit-file';
|
|
3
4
|
|
|
4
5
|
// ============================================================================
|
|
@@ -9,6 +10,7 @@ import { auditFileVersion, type auditFileSchema } from './audit-file';
|
|
|
9
10
|
|
|
10
11
|
export const exampleAuditFile = {
|
|
11
12
|
version: auditFileVersion,
|
|
13
|
+
model: recommendedModelId,
|
|
12
14
|
brand: {
|
|
13
15
|
name: 'Northwind Data',
|
|
14
16
|
domain: 'northwind.example',
|
|
@@ -42,8 +44,9 @@ export const exampleAuditFile = {
|
|
|
42
44
|
grounding: 'full',
|
|
43
45
|
runPolicy: {
|
|
44
46
|
maxPlannedUnits: 100,
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
+
// No dollar cap here: approve one per run with `run --max-usd`, after
|
|
48
|
+
// `literally-aeo plan` shows the estimate. It caps every paid call.
|
|
49
|
+
budget: { maxHours: 12 },
|
|
47
50
|
},
|
|
48
51
|
} satisfies z.input<typeof auditFileSchema>;
|
|
49
52
|
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { AeoSurface } from '../surfaces';
|
|
2
|
+
import type { TokenUsage } from './pricing';
|
|
3
|
+
|
|
4
|
+
// ============================================================================
|
|
5
|
+
// The coefficients the cost estimate and the ledger's reservations are
|
|
6
|
+
// computed from (specs/aeo-claude-operator-spec.md §4.2): tokens per
|
|
7
|
+
// captured answer and per run for the Codex stages and the host's calls,
|
|
8
|
+
// and dollars per probe and per search. A versioned resource, recalibrated
|
|
9
|
+
// each release from recorded runs' journals, which hold every session's
|
|
10
|
+
// usage. The estimate is a range, never a quote.
|
|
11
|
+
//
|
|
12
|
+
// Calibration 1 (2026-11-04): four local runs of 16 and 32 answers and one
|
|
13
|
+
// author session (src/models/__fixtures__/calibration-runs.json). The
|
|
14
|
+
// per-answer stages (analyze, qualify, review) used 34,000 to 62,000 input
|
|
15
|
+
// and 4,500 to 11,000 output tokens per answer; the write stage 280,000 to
|
|
16
|
+
// 760,000 input and 11,000 to 27,000 output tokens per run; 71 to 94
|
|
17
|
+
// percent of stage input was served from cache. The host calls used 2,000
|
|
18
|
+
// to 4,500 input and 4,400 to 8,000 output tokens per answer under
|
|
19
|
+
// extraction-only grounding, and 7,700 to 13,500 input and 11,000 to 13,000
|
|
20
|
+
// output under full grounding: reasoning is billed as output. The high
|
|
21
|
+
// ends carry headroom for a stronger model's longer reasoning and for
|
|
22
|
+
// review rounds.
|
|
23
|
+
//
|
|
24
|
+
// The spike (2026-11-04) ran one analyze batch of ten answers on each
|
|
25
|
+
// supported model: about 7,000 input and 300 to 450 output tokens per
|
|
26
|
+
// answer, none of the input served from cache. The cached share therefore
|
|
27
|
+
// runs from none at the dear end to the measured share at the cheap end.
|
|
28
|
+
//
|
|
29
|
+
// The probe and search figures are not calibrated yet: they are rough
|
|
30
|
+
// per-request assumptions (a probe's model tokens and its provider's search
|
|
31
|
+
// fee), to be replaced by the costs the gateway reports.
|
|
32
|
+
// ============================================================================
|
|
33
|
+
|
|
34
|
+
export const costCoefficientsVersion = 1;
|
|
35
|
+
|
|
36
|
+
export type TokenRange = {
|
|
37
|
+
input: number;
|
|
38
|
+
output: number;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type Range<T> = { low: T; high: T };
|
|
42
|
+
|
|
43
|
+
/** Codex stage tokens. `perAnswer` covers every stage that reads answer
|
|
44
|
+
* files; `perRun` the write stage, which reads the whole report. */
|
|
45
|
+
export const stageTokens = {
|
|
46
|
+
perAnswer: {
|
|
47
|
+
low: { input: 30_000, output: 4000 },
|
|
48
|
+
high: { input: 90_000, output: 16_000 },
|
|
49
|
+
},
|
|
50
|
+
perRun: {
|
|
51
|
+
low: { input: 250_000, output: 10_000 },
|
|
52
|
+
high: { input: 900_000, output: 40_000 },
|
|
53
|
+
},
|
|
54
|
+
/** The share of stage input served from cache: high is cheap. The
|
|
55
|
+
* supported models reported none through the gateway in the spike. */
|
|
56
|
+
cachedShare: { low: 0, high: 0.8 },
|
|
57
|
+
} as const;
|
|
58
|
+
|
|
59
|
+
/** The one author session. */
|
|
60
|
+
export const authorTokens = {
|
|
61
|
+
session: {
|
|
62
|
+
low: { input: 250_000, output: 10_000 },
|
|
63
|
+
high: { input: 800_000, output: 45_000 },
|
|
64
|
+
},
|
|
65
|
+
} as const;
|
|
66
|
+
|
|
67
|
+
/** The author's research searches at the low end; the high end is the
|
|
68
|
+
* research tools' own spend cap (`authorToolCaps.searchSpendUsd`). */
|
|
69
|
+
export const authorSearchLowUsd = 0.05;
|
|
70
|
+
|
|
71
|
+
/** The host's own model calls per captured answer, by grounding:
|
|
72
|
+
* perception, source labels and the copy verifier always; claim research
|
|
73
|
+
* and adjudication under full grounding. */
|
|
74
|
+
export const hostTokensPerAnswer = {
|
|
75
|
+
extraction_only: {
|
|
76
|
+
low: { input: 1500, output: 3000 },
|
|
77
|
+
high: { input: 8000, output: 12_000 },
|
|
78
|
+
},
|
|
79
|
+
full: {
|
|
80
|
+
low: { input: 6000, output: 6000 },
|
|
81
|
+
high: { input: 24_000, output: 18_000 },
|
|
82
|
+
},
|
|
83
|
+
} as const;
|
|
84
|
+
|
|
85
|
+
/** Grounding search per captured answer under full grounding. */
|
|
86
|
+
export const searchUsdPerAnswer = { low: 0.001, high: 0.01 } as const;
|
|
87
|
+
|
|
88
|
+
/** One probe unit, by surface, in USD. The coding-agent surfaces run on
|
|
89
|
+
* the operator's own login and bill nothing to the run. */
|
|
90
|
+
export const probeUsd: Record<AeoSurface, Range<number>> = {
|
|
91
|
+
chatgpt: { low: 0.01, high: 0.05 },
|
|
92
|
+
gemini: { low: 0.02, high: 0.06 },
|
|
93
|
+
claude: { low: 0.02, high: 0.08 },
|
|
94
|
+
perplexity: { low: 0.01, high: 0.03 },
|
|
95
|
+
google_ai_overview: { low: 0.002, high: 0.006 },
|
|
96
|
+
claude_code: { low: 0, high: 0 },
|
|
97
|
+
codex: { low: 0, high: 0 },
|
|
98
|
+
cursor: { low: 0, high: 0 },
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/** The calibrated workload a Codex session is: a batch of answer files
|
|
102
|
+
* (analyze, qualify, review), the whole report (write) or a brief
|
|
103
|
+
* (author). Each stage's descriptor names its own. */
|
|
104
|
+
export type SessionCost = 'answers' | 'report' | 'brief';
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* sessionReservation is what one Codex session is reserved at before it
|
|
108
|
+
* starts: the same high figures, cache share included, that the estimate's
|
|
109
|
+
* high end assumes, so a run under the cap the estimate recommends is never
|
|
110
|
+
* refused for its reservations. The session settles at the tokens it
|
|
111
|
+
* reports; its reservation bounds how far one session can carry the run
|
|
112
|
+
* past its cap.
|
|
113
|
+
*/
|
|
114
|
+
export const sessionReservation = ({
|
|
115
|
+
cost,
|
|
116
|
+
answers,
|
|
117
|
+
}: {
|
|
118
|
+
cost: SessionCost;
|
|
119
|
+
answers: number;
|
|
120
|
+
}): TokenUsage => {
|
|
121
|
+
// One session is one stage over its batch; the per-answer high covers
|
|
122
|
+
// all three such stages, the heaviest two of which take about half each.
|
|
123
|
+
const batch = {
|
|
124
|
+
input: 50_000 + answers * (stageTokens.perAnswer.high.input / 2),
|
|
125
|
+
output: 8000 + answers * (stageTokens.perAnswer.high.output / 2),
|
|
126
|
+
};
|
|
127
|
+
const tokens = {
|
|
128
|
+
answers: batch,
|
|
129
|
+
report: stageTokens.perRun.high,
|
|
130
|
+
brief: authorTokens.session.high,
|
|
131
|
+
}[cost];
|
|
132
|
+
|
|
133
|
+
const reservation: TokenUsage = {
|
|
134
|
+
inputTokens: tokens.input,
|
|
135
|
+
cachedInputTokens: Math.round(tokens.input * stageTokens.cachedShare.low),
|
|
136
|
+
outputTokens: tokens.output,
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
return reservation;
|
|
140
|
+
};
|