diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a6dcce074..b0da8622d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,7 +29,8 @@ jobs: with: node-version: 22 cache: npm - - run: npm ci + # Installed as the release installs. + - run: npm run ci:install - run: npm run typecheck - run: npm run lint - run: npm run compile diff --git a/.github/workflows/npm.yml b/.github/workflows/npm.yml index 919550adb..74ec0d77a 100644 --- a/.github/workflows/npm.yml +++ b/.github/workflows/npm.yml @@ -42,8 +42,8 @@ jobs: cache: npm - name: The tag names this version run: test "$TAG" = "v$(node -p 'require("./package.json").version')" - # No dependency's install script runs in this job, but Bun's own: it puts the bun executable in place. - - run: npm ci --ignore-scripts && node node_modules/bun/install.js + # No dependency's install script runs, but Bun's own: it puts the bun executable in place. + - run: npm run ci:install - name: The release's executables, as checked against its SHA256SUMS env: GH_TOKEN: ${{ github.token }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1c0907946..042463b8d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -31,7 +31,8 @@ jobs: env: TAG: ${{ github.ref_name }} run: test "$TAG" = "v$(node -p 'require("./package.json").version')" - - run: npm ci + # Installed as npm.yml installs, so the packages are checked as they will be published. + - run: npm run ci:install - name: CHANGELOG.md has this version's notes env: TAG: ${{ github.ref_name }} diff --git a/CHANGELOG.md b/CHANGELOG.md index e7bf7bb80..404b7ff36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## 1.0.1 (2026-11-25) + +- A plan's report asks the question the planning started from; replies added while planning follow it in the PDF. +- A report opens with the answer, without the progress notes written along the way. +- Price history reads two, three and five years. +- A year of price history that spans February 29 is no longer refused. +- Storing a key names the provider's API key (for example, "Stored the Tauric API key"). +- A correlation of returns needs at least three returns (four shared dates); over three dates it reported a perfect +1 or -1. + ## 1.0.0 (2026-11-24) - TradingAgents: Towards Agentic Finance Research. diff --git a/package-lock.json b/package-lock.json index 7933fcc37..17418e278 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "tradingagents", - "version": "1.0.0", + "version": "1.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "tradingagents", - "version": "1.0.0", + "version": "1.0.1", "license": "Apache-2.0", "dependencies": { "@ai-sdk/anthropic": "4.0.106", @@ -36,12 +36,12 @@ }, "devDependencies": { "@biomejs/biome": "2.6.8", - "@types/bun": "1.4.4", + "@types/bun": "1.4.5", "@types/node": "22.20.5", "@types/pdfkit": "0.17.7", "@types/react": "19.3.0", "@types/semver": "7.8.0", - "bun": "1.4.4", + "bun": "1.4.5", "typescript": "7.0.2" }, "engines": { @@ -505,9 +505,9 @@ } }, "node_modules/@oven/bun-darwin-aarch64": { - "version": "1.4.4", - "resolved": "https://registry.npmjs.org/@oven/bun-darwin-aarch64/-/bun-darwin-aarch64-1.4.4.tgz", - "integrity": "sha512-zW/hxwc8sJAILGwB5eTC4i48ouGXf0V4lrxmEOk3JIE6JkYVW1TZh1E2pIempqsezgW1sckTIIDudFON8bJ2Mw==", + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/@oven/bun-darwin-aarch64/-/bun-darwin-aarch64-1.4.5.tgz", + "integrity": "sha512-4MIFXHmctH2EhAxLXm2/qxNtv17dFtLJylvaOCsrgq6KSqHTs6eW5YSrJjRbJxYUJaR901fsN8JfZOa+CsWpWQ==", "cpu": [ "arm64" ], @@ -519,9 +519,9 @@ ] }, "node_modules/@oven/bun-darwin-x64": { - "version": "1.4.4", - "resolved": "https://registry.npmjs.org/@oven/bun-darwin-x64/-/bun-darwin-x64-1.4.4.tgz", - "integrity": "sha512-oKGcxLsvh4oHjAo28nPm8c/xN0o/OmGyj1IHYc94vprkWsW2hNg2keEZt5f40cI5Hvu4jDlSRTR0UNpv1UIAxw==", + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/@oven/bun-darwin-x64/-/bun-darwin-x64-1.4.5.tgz", + "integrity": "sha512-qkLPMGHZM9NI6CeHTWwVezzmlo6cC4Ta7yUAjYIWXS366qQcOlcp75t2uZyiuVRBMPS0h9qE0tCcvCHGaFqjJg==", "cpu": [ "x64" ], @@ -533,9 +533,9 @@ ] }, "node_modules/@oven/bun-freebsd-aarch64": { - "version": "1.4.4", - "resolved": "https://registry.npmjs.org/@oven/bun-freebsd-aarch64/-/bun-freebsd-aarch64-1.4.4.tgz", - "integrity": "sha512-klvA9FlwLxZj3JYIOPQA4bbnHIC3uas8kBE4GaGGkeVgAQP/k8hAzYkOqkSaqHBDbxLrTyFEQArEAevJq6NJzg==", + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/@oven/bun-freebsd-aarch64/-/bun-freebsd-aarch64-1.4.5.tgz", + "integrity": "sha512-limWGUkd7wNKh9X/KJa4RyPMTdZsI+sqs7KmAWc/zFllRe5BSlN71ZfAVSYDDJMUJUQUvDdAMywH5zYkYrfUzQ==", "cpu": [ "arm64" ], @@ -547,9 +547,9 @@ ] }, "node_modules/@oven/bun-freebsd-x64": { - "version": "1.4.4", - "resolved": "https://registry.npmjs.org/@oven/bun-freebsd-x64/-/bun-freebsd-x64-1.4.4.tgz", - "integrity": "sha512-sF1xS/scbyN94P2d0eTiarO6JHxrIvhZNT9hnWjQXW5nwKRtfuP+UYnIMNyvW1BQPcZFP/cvfLBNUIe1ea4zPA==", + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/@oven/bun-freebsd-x64/-/bun-freebsd-x64-1.4.5.tgz", + "integrity": "sha512-LahCo0mJJzscE0PUKO8FXdFiOc2vqt9zhf35gSFAVemeCn88idDWpp/rhNcnEsHWMhf5GMXxGJA5D9deTmzW1g==", "cpu": [ "x64" ], @@ -561,9 +561,9 @@ ] }, "node_modules/@oven/bun-linux-aarch64": { - "version": "1.4.4", - "resolved": "https://registry.npmjs.org/@oven/bun-linux-aarch64/-/bun-linux-aarch64-1.4.4.tgz", - "integrity": "sha512-ZTVtpf9zmHSBVPX1sBwe5agGb/rN34yPGg/Hby8e2Ax2uCUA2URZKlZH7qLntK7qaFJCMXh9v0GWNYN2zINz1w==", + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/@oven/bun-linux-aarch64/-/bun-linux-aarch64-1.4.5.tgz", + "integrity": "sha512-4BXmsSKnjOrlGWqZV4x/oWa7AVoR+B6lCXddMzOAXBIm3t50eslg9wb66gmtW1AamEQ1l1CDvmmruysEhqOWMg==", "cpu": [ "arm64" ], @@ -575,9 +575,9 @@ ] }, "node_modules/@oven/bun-linux-aarch64-android": { - "version": "1.4.4", - "resolved": "https://registry.npmjs.org/@oven/bun-linux-aarch64-android/-/bun-linux-aarch64-android-1.4.4.tgz", - "integrity": "sha512-5lvn3at5vRC0GxvmiqEiV2/e23tnRi0q5pzR40yfDvDA3OW7PSkt4chF1nA9vnAJhro4/l+ol1FmNP6D3cf/oA==", + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/@oven/bun-linux-aarch64-android/-/bun-linux-aarch64-android-1.4.5.tgz", + "integrity": "sha512-SI502JpXyu6em6y8E3F48GO3LwjYXSG3DWEOPhf9LXJWjjnPG9OwrWajtM91saa2vAixZ0ErlZa8UzNORcgcyQ==", "cpu": [ "arm64" ], @@ -589,9 +589,9 @@ ] }, "node_modules/@oven/bun-linux-aarch64-musl": { - "version": "1.4.4", - "resolved": "https://registry.npmjs.org/@oven/bun-linux-aarch64-musl/-/bun-linux-aarch64-musl-1.4.4.tgz", - "integrity": "sha512-QFd0P+mHJxbZFbUla4MgiE5OwxysHaUIYxL2pPNkpWtaI7v4ShOpr8OhBmsuyB0xn5rv/ZJnPsj2y8+bB9+g/A==", + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/@oven/bun-linux-aarch64-musl/-/bun-linux-aarch64-musl-1.4.5.tgz", + "integrity": "sha512-XCNc+WvvMAdNNb+OWTogpy+N9wm62fkVeEVLb6how0RZhW5LPi6c7BlkeVCuWps7XjEl2saFpHFa20/1E+PAHg==", "cpu": [ "arm64" ], @@ -603,9 +603,9 @@ ] }, "node_modules/@oven/bun-linux-x64": { - "version": "1.4.4", - "resolved": "https://registry.npmjs.org/@oven/bun-linux-x64/-/bun-linux-x64-1.4.4.tgz", - "integrity": "sha512-CHbbkmHVM28T1GFq+6GL4Ao4ujwwYwj1CxFFwEFzLanPfNsId9AhbIP0Q4reWuWBkGimUkoQygrK7Rgjtj3vog==", + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/@oven/bun-linux-x64/-/bun-linux-x64-1.4.5.tgz", + "integrity": "sha512-IWX9BELoGHAUtMonkeSaNaZwXzRk+oDw6Mk+HBFXd3KHYIBNBsIGRupMZPcgNoDbJpLu6gAJjIoIVPZtt1aJ1g==", "cpu": [ "x64" ], @@ -617,9 +617,9 @@ ] }, "node_modules/@oven/bun-linux-x64-android": { - "version": "1.4.4", - "resolved": "https://registry.npmjs.org/@oven/bun-linux-x64-android/-/bun-linux-x64-android-1.4.4.tgz", - "integrity": "sha512-3dMicj9C1DhaIfDkwt/9GtpU0W+q+GazbG9OIlEyL3Q1BBEz2e6ZRz/JiO8D/ECC0caXAqvnpFudehcLlgIwWQ==", + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/@oven/bun-linux-x64-android/-/bun-linux-x64-android-1.4.5.tgz", + "integrity": "sha512-81X3/qn9v18bHHIHfkGikQ/KztJTJpo6GMuqtwKm/jHMQy+Z8JpjIfxdaYocxeiRwgQhBXlby2HTKPvMyEjsOg==", "cpu": [ "x64" ], @@ -631,9 +631,9 @@ ] }, "node_modules/@oven/bun-linux-x64-musl": { - "version": "1.4.4", - "resolved": "https://registry.npmjs.org/@oven/bun-linux-x64-musl/-/bun-linux-x64-musl-1.4.4.tgz", - "integrity": "sha512-lEEjNOJJrbGZu2NVcPI4uXdILcpspezWkA8R/Jr0RCGhM6zQd0Y7JBIIKNAmbX59EeWpeEz7Q78iLbpcAUypUA==", + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/@oven/bun-linux-x64-musl/-/bun-linux-x64-musl-1.4.5.tgz", + "integrity": "sha512-10QoW/YfTgnURaGEaHpJCiXjLI2e5iTtfVDaA5JKcyUzaa1cq6cVUY9/Uq5XkYzvtRjHLRe9Oj/lTDIQcxy8HQ==", "cpu": [ "x64" ], @@ -645,9 +645,9 @@ ] }, "node_modules/@oven/bun-windows-aarch64": { - "version": "1.4.4", - "resolved": "https://registry.npmjs.org/@oven/bun-windows-aarch64/-/bun-windows-aarch64-1.4.4.tgz", - "integrity": "sha512-n0ep5ZRPCZY1+dqFJpnnRUZB1wy4GYU6At8RF+pyzySCLjkN9R4rFh2PtBHAgF/lg1vOl3/CeER3pDM+p40ATA==", + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/@oven/bun-windows-aarch64/-/bun-windows-aarch64-1.4.5.tgz", + "integrity": "sha512-MiPFZnBNDnBXgr1oONc5pizC4fOLjnIOfNkYdFEnWzLmoFTg86naZIG3SvS7d/GglpQSAnCKMAzSjI/TAckiRw==", "cpu": [ "arm64" ], @@ -659,9 +659,9 @@ ] }, "node_modules/@oven/bun-windows-x64": { - "version": "1.4.4", - "resolved": "https://registry.npmjs.org/@oven/bun-windows-x64/-/bun-windows-x64-1.4.4.tgz", - "integrity": "sha512-a3LNctBVO8PjePsFZfwDleF2JXYf2BfQ1u/PLRnBDLnC2Riml+4+LgJpKj4xRGhB92KweGyQI5PXaTkP9qypMQ==", + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/@oven/bun-windows-x64/-/bun-windows-x64-1.4.5.tgz", + "integrity": "sha512-FNvply651vcE/GHgNWz6mZvhmkwBuu8Hw54oNzA+CQog+HW+542rXQmZqNHRkFxazD9L3xi+iTtvO3engAgJfw==", "cpu": [ "x64" ], @@ -685,13 +685,13 @@ "license": "Apache-2.0" }, "node_modules/@types/bun": { - "version": "1.4.4", - "resolved": "https://registry.npmjs.org/@types/bun/-/bun-1.4.4.tgz", - "integrity": "sha512-9wkRDXUXK124pEnAutE6n/l18j+i9GC5IAHK8TmX/2nlySETmky0OU6yL5U8pW1AoKh++AN9auDCr647BfurjQ==", + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/@types/bun/-/bun-1.4.5.tgz", + "integrity": "sha512-DpgwNI9z0L1S0gtb45QLCWgwCUcMLnsHYMJHQvpNj7erGiCGBvpggltAIeARrtobNMKMuy0UP7i56tKKgwFs/Q==", "dev": true, "license": "MIT", "dependencies": { - "bun-types": "1.4.4" + "bun-types": "1.4.5" } }, "node_modules/@types/node": { @@ -1267,9 +1267,9 @@ } }, "node_modules/bun": { - "version": "1.4.4", - "resolved": "https://registry.npmjs.org/bun/-/bun-1.4.4.tgz", - "integrity": "sha512-hj0ASdG6PNjLZGFAXktWb3Uaj/dcv/1wCsIttoEXADNIQBsGjTr+5uLKYbrDkuc7NT0Tkj4yPIqJI2jDxXdvVg==", + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/bun/-/bun-1.4.5.tgz", + "integrity": "sha512-SWOAncfhwiqIyaZ3uyuUD/6o8aWbG8QtU6SChlz4u6U/C89gTZafLDCmbUvyNjx+ccxLLHV+lSsWqE1OBN8bBw==", "cpu": [ "arm64", "x64" @@ -1289,24 +1289,24 @@ "bunx": "bin/bunx.exe" }, "optionalDependencies": { - "@oven/bun-darwin-aarch64": "1.4.4", - "@oven/bun-darwin-x64": "1.4.4", - "@oven/bun-freebsd-aarch64": "1.4.4", - "@oven/bun-freebsd-x64": "1.4.4", - "@oven/bun-linux-aarch64": "1.4.4", - "@oven/bun-linux-aarch64-android": "1.4.4", - "@oven/bun-linux-aarch64-musl": "1.4.4", - "@oven/bun-linux-x64": "1.4.4", - "@oven/bun-linux-x64-android": "1.4.4", - "@oven/bun-linux-x64-musl": "1.4.4", - "@oven/bun-windows-aarch64": "1.4.4", - "@oven/bun-windows-x64": "1.4.4" + "@oven/bun-darwin-aarch64": "1.4.5", + "@oven/bun-darwin-x64": "1.4.5", + "@oven/bun-freebsd-aarch64": "1.4.5", + "@oven/bun-freebsd-x64": "1.4.5", + "@oven/bun-linux-aarch64": "1.4.5", + "@oven/bun-linux-aarch64-android": "1.4.5", + "@oven/bun-linux-aarch64-musl": "1.4.5", + "@oven/bun-linux-x64": "1.4.5", + "@oven/bun-linux-x64-android": "1.4.5", + "@oven/bun-linux-x64-musl": "1.4.5", + "@oven/bun-windows-aarch64": "1.4.5", + "@oven/bun-windows-x64": "1.4.5" } }, "node_modules/bun-types": { - "version": "1.4.4", - "resolved": "https://registry.npmjs.org/bun-types/-/bun-types-1.4.4.tgz", - "integrity": "sha512-yjrJh5oGX7mMPKGd19YXyIjmEuj4G4zNC30bs7PM9Az7NQ3ndF3j6hbeRdvJTRQEhJ/FYQwW0a2moweEi2hMxQ==", + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/bun-types/-/bun-types-1.4.5.tgz", + "integrity": "sha512-ECHn+9dhL3wv0G6u0+7dQvrnaimXiRDxxerYBmhTaLyJEEuvTPWk2Fye3XIf5Y++JIIiHKfQw4Z7V5D8KuiXbg==", "dev": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 78fd5b825..652c3485e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tradingagents", - "version": "1.0.0", + "version": "1.0.1", "private": true, "description": "TradingAgents: Towards Agentic Finance Research", "license": "Apache-2.0", @@ -15,6 +15,7 @@ "dist" ], "scripts": { + "ci:install": "npm ci --ignore-scripts && node node_modules/bun/install.js", "build": "tsc -p tsconfig.build.json", "compile": "npm run build && bun scripts/compile.ts", "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p scripts/tsconfig.json", @@ -23,12 +24,12 @@ }, "devDependencies": { "@biomejs/biome": "2.6.8", - "@types/bun": "1.4.4", + "@types/bun": "1.4.5", "@types/node": "22.20.5", "@types/pdfkit": "0.17.7", "@types/react": "19.3.0", "@types/semver": "7.8.0", - "bun": "1.4.4", + "bun": "1.4.5", "typescript": "7.0.2" }, "dependencies": { diff --git a/src/agents/loop.ts b/src/agents/loop.ts index ee0984024..f838ba76c 100644 --- a/src/agents/loop.ts +++ b/src/agents/loop.ts @@ -347,20 +347,23 @@ export async function runAgent( } /** - * The run's answer: what it wrote after its last research call (data, compute or an agent), in order. Text - * written beside bookkeeping calls only (a decision recorded, the plan updated) after that call belongs to - * the answer; text beside a research call was written before the results it waited for, so it does not. + * The run's answer: what it wrote after its last tool call, as the prompt says; text beside a call is + * progress. A run that wrote nothing after it (its report beside a bookkeeping call, such as a decision + * recorded) answers with what it wrote after its last research call (data, compute or an agent), in order. */ function answerOf(messages: readonly Message[], registry: Pick): string { - const researched = (message: Message) => + const calls = (research: boolean) => (message: Message) => message.role === "assistant" && - message.parts.some((part) => part.type === "tool-call" && registry.kindOf(part.name) !== "control"); - const last = messages.findLastIndex(researched); - return messages - .slice(last + 1) - .flatMap((message) => (message.role === "assistant" ? message.parts : [])) - .flatMap((part) => (part.type === "text" && part.text.trim() ? [part.text.trim()] : [])) - .join("\n\n"); + message.parts.some( + (part) => part.type === "tool-call" && (!research || registry.kindOf(part.name) !== "control"), + ); + const textAfter = (index: number) => + messages + .slice(index + 1) + .flatMap((message) => (message.role === "assistant" ? message.parts : [])) + .flatMap((part) => (part.type === "text" && part.text.trim() ? [part.text.trim()] : [])) + .join("\n\n"); + return textAfter(messages.findLastIndex(calls(false))) || textAfter(messages.findLastIndex(calls(true))); } /** diff --git a/src/cli/changelog.generated.ts b/src/cli/changelog.generated.ts index 25200d83f..c4ff1d9d1 100644 --- a/src/cli/changelog.generated.ts +++ b/src/cli/changelog.generated.ts @@ -4,6 +4,21 @@ import type { VersionNotes } from "./whats-new.js"; export const CHANGELOG: readonly VersionNotes[] = [ + { + "version": "1.0.1", + "sections": [ + { + "items": [ + "A plan's report asks the question the planning started from; replies added while planning follow it in the PDF.", + "A report opens with the answer, without the progress notes written along the way.", + "Price history reads two, three and five years.", + "A year of price history that spans February 29 is no longer refused.", + "Storing a key names the provider's API key (for example, \"Stored the Tauric API key\").", + "A correlation of returns needs at least three returns (four shared dates); over three dates it reported a perfect +1 or -1." + ] + } + ] + }, { "version": "1.0.0", "sections": [ diff --git a/src/cli/report/pdf.ts b/src/cli/report/pdf.ts index ce4371ac7..bbbe40705 100644 --- a/src/cli/report/pdf.ts +++ b/src/cli/report/pdf.ts @@ -81,7 +81,7 @@ export function uncovered(report: Report): number { const texts = [ report.title, report.question, - report.earlier ?? "", + ...report.added, ...report.sources, ...partTexts(report.parts), ]; @@ -336,17 +336,19 @@ export async function reportPdf(report: Report): Promise { ); doc.y += 14; - // The question (after the one before it, when that one's plan may be what it carries out), set off in a - // panel; a question too long for a page runs on without the panel. + // The question (then what was added to it while planning, under one label), set off in a panel; a + // question too long for a page runs on without the panel. const asked = [ - ...(report.earlier ? [{ label: message("report.earlier"), text: report.earlier }] : []), { label: message("report.question"), text: report.question }, + ...report.added.map((text, i) => ({ label: i ? "" : message("report.added"), text })), ].filter((entry) => entry.text); if (asked.length) { const inner = width - 28; - const heights = asked.map(({ text }) => { + const heights = asked.map(({ label, text }) => { doc.font("regular").fontSize(BODY); - return doc.heightOfString(text, { width: inner, lineGap: LINE_GAP, features: FEATURES }) + 11; + return ( + doc.heightOfString(text, { width: inner, lineGap: LINE_GAP, features: FEATURES }) + (label ? 11 : 0) + ); }); const height = heights.reduce((sum, each) => sum + each, 0) + 6 * (asked.length - 1) + 19; const panel = height <= bottom() - MARGIN; @@ -355,16 +357,18 @@ export async function reportPdf(report: Report): Promise { if (panel) doc.save().rect(left, top, width, height).fill(PANEL).restore(); doc.y = top + 9; for (const { label, text } of asked) { - doc - .font("bold") - .fontSize(6.5) - .fillColor(MUTED) - .text(label.toUpperCase(), left + 14, doc.y, { - characterSpacing: 1, - lineBreak: false, - features: FEATURES, - }); - doc.y += 11; + if (label) { + doc + .font("bold") + .fontSize(6.5) + .fillColor(MUTED) + .text(label.toUpperCase(), left + 14, doc.y, { + characterSpacing: 1, + lineBreak: false, + features: FEATURES, + }); + doc.y += 11; + } paragraph([{ text }], left + 14, inner, BODY, INK); doc.y += 6; } diff --git a/src/cli/report/report.ts b/src/cli/report/report.ts index 62d326cb1..5fffc1f30 100644 --- a/src/cli/report/report.ts +++ b/src/cli/report/report.ts @@ -11,12 +11,10 @@ import { type Part, type Run, reportParts } from "./layout.js"; export type Report = { title: string; + /** For an answer to a plan, or one that ran it as proposed: the question the planning started from. */ question: string; - /** - * The question asked just before in plan mode, when this one was asked in plan mode too or ran its plan - * as proposed: the answer may carry out the plan that one got, so the reader sees what it was. - */ - earlier?: string; + /** What the person added while planning, in the order said: the replies in plan mode after the question. */ + added: string[]; /** When the answer was written, as an ISO time. */ at: string; model: string; @@ -28,7 +26,7 @@ export type Report = { /** * The last completed turn of `session` in `done` as a report, or undefined when it has none with an answer. - * The title is the answer's opening heading when it has one. `model` stands in when the turn did not say. + * The question of a plan is the one the planning started from, not the reply that ran it. The title is the answer's opening heading when it has one. `model` stands in when the turn did not say. */ export function lastReport( done: readonly Block[], @@ -39,16 +37,14 @@ export function lastReport( ); const last = turns.at(-1); if (!last?.answer.trim()) return undefined; - const before = turns.at(-2); + const [asked, ...added] = planning(turns); const parts = reportParts(last.answer); const [first, ...rest] = parts; const titled = first?.kind === "heading"; return { title: titled ? textOf(first.runs) : message("report.title"), - question: printable(last.question).trim(), - ...(before?.plan && (last.plan || last.question === message("app.runPlan")) - ? { earlier: printable(before.question).trim() } - : {}), + question: printable((asked ?? last).question).trim(), + added: added.map((turn) => printable(turn.question).trim()).filter(Boolean), at: last.at, model: printable(last.model ?? model), version: printable(version), @@ -57,6 +53,20 @@ export function lastReport( }; } +/** + * The turns a plan was made in, when the last of `turns` answered in plan mode or ran the plan as proposed: + * the plan-mode turns up to it (the run itself left out), in order. Otherwise none. + */ +function planning(turns: readonly Answered[]): Answered[] { + const last = turns.at(-1); + const ran = !last?.plan && last?.question === message("app.runPlan"); + if (!last?.plan && !ran) return []; + const end = ran ? turns.length - 1 : turns.length; + let start = end; + while (start > 0 && turns[start - 1]?.plan) start--; + return turns.slice(start, end); +} + function textOf(runs: readonly Run[]): string { return runs .map((run) => run.text) diff --git a/src/cli/transcript-state.ts b/src/cli/transcript-state.ts index a30a21f17..ee02d9d1c 100644 --- a/src/cli/transcript-state.ts +++ b/src/cli/transcript-state.ts @@ -195,6 +195,8 @@ const BOOKKEEPING = new Set(["update_plan", "use_skill", ASK_TOOL]); const MEMORY = new Set(["recall_memory", "save_note", "record_decision"]); /** A call that researches (data, compute, an agent), as against keeping the books: what an answer follows. */ const researches = (name: string) => !BOOKKEEPING.has(name) && !MEMORY.has(name) && name !== "evidence"; +/** Steps' text joined as the engine joins an answer's: the ones with text, a blank line between. */ +const joined = (...texts: string[]) => texts.filter((text) => text.trim()).join("\n\n"); /** The state once `run` has gone on after a retry: what said it was being asked for again is gone. */ function resumed(state: TranscriptState, isMain: boolean, run: string): TranscriptState { @@ -282,8 +284,9 @@ export type TranscriptState = { * text of its steps. */ /** - * `stepText`: the step under way; `sinceResearch`: what the finished steps wrote since the main agent's - * last research call, which the turn's answer is made of. + * `stepText`: the step under way; `sinceCall` and `sinceResearch`: what the finished steps wrote since the + * main agent's last call and its last research call. The turn's answer is the first, or the second when + * the first is empty, as the engine makes it. */ /** `worked`: the main agent carried research out (computed, or ran an agent) in this turn. */ turn: { @@ -292,6 +295,7 @@ export type TranscriptState = { asked?: true; worked?: true; stepText: string; + sinceCall: string; sinceResearch: string; }; /** The app wrote the question it just sent: the next `turn.started` does not write it again. */ @@ -346,7 +350,7 @@ export const emptyTranscript: TranscriptState = { delegated: [], titles: {}, }, - turn: { question: "", stepText: "", sinceResearch: "" }, + turn: { question: "", stepText: "", sinceCall: "", sinceResearch: "" }, citations: { recorded: [], cited: [] }, status: { turnActive: false }, }; @@ -726,6 +730,7 @@ export function reduceTranscript( question: event.question, ...(event.mode === "plan" ? { plan: true as const } : {}), stepText: "", + sinceCall: "", sinceResearch: "", }, citations: { recorded: written.citations.recorded, cited: [] }, @@ -775,16 +780,18 @@ export function reduceTranscript( turn: { ...state.turn, stepText: "", - sinceResearch: [state.turn.sinceResearch, state.turn.stepText] - .filter((t) => t.trim()) - .join("\n\n"), + sinceCall: joined(state.turn.sinceCall, state.turn.stepText), + sinceResearch: joined(state.turn.sinceResearch, state.turn.stepText), }, } : state; case "tool.called": { - // The main agent acting ends its thinking; its data calls join the step's batch. A research call - // follows the step that made it: what that step and those before wrote is not the answer. - if (isMain && researches(event.name)) state = { ...state, turn: { ...state.turn, sinceResearch: "" } }; + // The main agent acting ends its thinking; its data calls join the step's batch. A call follows the + // step that made it: what that step and those before wrote is not the answer. + if (isMain) { + const sinceResearch = researches(event.name) ? "" : state.turn.sinceResearch; + state = { ...state, turn: { ...state.turn, sinceCall: "", sinceResearch } }; + } if (isMain && carriesOut(event)) state = { ...state, turn: { ...state.turn, worked: true } }; if (isMain) { state = closeThought(state, id, envelope.ts); @@ -1046,10 +1053,13 @@ export function reduceTranscript( case "usage.updated": return { ...state, status: { ...state.status, usage: event.usage } }; case "turn.completed": { - // The answer is what was written since the last research call, the step under way included when a - // turn ends without a closing step event; shown already when it was all streamed. A turn that asked - // ends with its questions, which the question step shows: only what the model wrote is shown here. - const written = [state.turn.sinceResearch, state.turn.stepText].filter((t) => t.trim()).join("\n\n"); + // The answer is what was written since the last call, or since the last research call when nothing + // was, the step under way included when a turn ends without a closing step event; shown already when + // it was all streamed. A turn that asked ends with its questions, which the question step shows: only + // what the model wrote is shown here. + const written = + joined(state.turn.sinceCall, state.turn.stepText) || + joined(state.turn.sinceResearch, state.turn.stepText); const streamed = event.answer.replace(/\s+/g, "") === written.replace(/\s+/g, ""); const flushed = flushText(closeThought(state, id, envelope.ts), id); // The engine's numbering, for an answer not streamed and for the list of what it cited. diff --git a/src/compute/correlation.ts b/src/compute/correlation.ts index bb2cff4a3..f5c80f3a7 100644 --- a/src/compute/correlation.ts +++ b/src/compute/correlation.ts @@ -29,11 +29,12 @@ export function correlate( if ("error" in aligned) return aligned; const { columns, dates } = aligned; const observations = columns[0]?.length ?? 0; - if (observations < LEAST) { + // The minimum counts what is correlated: returns are one fewer than the shared dates. + const points = of === "returns" ? Math.max(0, observations - 1) : observations; + if (points < LEAST) { const who = series.length === 2 ? `${series[0]?.label} and ${series[1]?.label}` : "the series"; - return { - error: `${who} share ${observations} ${dates ? "dates" : "values"}; ${of} need at least ${LEAST}`, - }; + const shared = `${observations} ${dates ? "dates" : "values"}${of === "returns" ? `, so ${points} returns` : ""}`; + return { error: `${who} share ${shared}; a correlation needs at least ${LEAST}` }; } if (of === "returns") { const index = columns.findIndex((column) => column.some((value) => value <= 0)); diff --git a/src/contracts/limits.ts b/src/contracts/limits.ts index 695511634..9cfc6055c 100644 --- a/src/contracts/limits.ts +++ b/src/contracts/limits.ts @@ -60,6 +60,8 @@ export const CALLS = { resultChars: 12_000, /** Intraday bars one price_history page asks for: the most the source serves at once. */ intradayBars: 100, + /** Days of daily bars, both ends counted, one Tauric request serves at most; a longer window is read in pieces. */ + dailyWindowDays: 366, /** Pages of 25 companies a sector screen reads at most: 500 companies, the largest sector. */ screenPages: 20, textChars: 10_000, diff --git a/src/contracts/messages.ts b/src/contracts/messages.ts index 3097f0337..4dd5c6beb 100644 --- a/src/contracts/messages.ts +++ b/src/contracts/messages.ts @@ -100,7 +100,8 @@ const catalog = { "cli.nothingStoredBecause": ({ reason }: { reason: string }) => `Nothing stored: ${reason}`, "cli.envKeyWins": ({ variable }: { variable: string }) => `${variable} is set and is used; the stored key is used once it is unset.`, - "cli.keyStored": ({ name, path }: { name: string; path: string }) => `Stored the ${name} key in ${path}.`, + "cli.keyStored": ({ name, path }: { name: string; path: string }) => + `Stored the ${name === "model" ? "model server" : keyLabel(name)} API key in ${path}.`, "cli.setup": ({ app, baseUrlVar, @@ -199,7 +200,7 @@ event odds from Polymarket; the rest is not available. ["/help for commands", "esc to stop"].join(separator), "report.title": () => "Research report", "report.question": () => "Question", - "report.earlier": () => "Earlier question", + "report.added": () => "Added while planning", "report.sources": () => "Sources", "report.written": ({ at }: { at: string }) => `${at.slice(0, 10)} ${at.slice(11, 16)} UTC`, "report.page": ({ page, count }: { page: number; count: number }) => `Page ${page} of ${count}`, @@ -644,7 +645,7 @@ event odds from Polymarket; the rest is not available. "session.signedOut": ({ app }: { app: string }) => `not signed in to ChatGPT: ${app} login chatgpt`, "session.changedWhileOpening": () => "the session changed while it was being opened; open it again", "config.noKey": ({ provider, vars, app }: { provider: string; vars: string; app: string }) => - `the ${provider} model needs a key: set ${vars}, or store one with ${app} key ${provider}`, + `the ${keyLabel(provider)} model needs an API key: set ${vars}, or store one with ${app} key ${provider}`, "config.badReasoning": ({ where, levels }: { where: string; levels: string }) => `${where}: reasoning must be one of ${levels}`, "config.keyForOtherServer": ({ endpoint, app }: { endpoint: string; app: string }) => diff --git a/src/contracts/product.ts b/src/contracts/product.ts index 38ceb04f3..4e7f81624 100644 --- a/src/contracts/product.ts +++ b/src/contracts/product.ts @@ -10,7 +10,7 @@ export const APP_TITLE = "TradingAgents"; export const MAKER = "Tauric Research"; /** This build's version; a test keeps it equal to package.json's. */ -export const VERSION = "1.0.0"; +export const VERSION = "1.0.1"; /** How this build names itself to the services it calls. */ export const USER_AGENT = `${APP_NAME}/${VERSION}`; diff --git a/src/data/tauric/provider.ts b/src/data/tauric/provider.ts index 9cfc08499..2a15c199c 100644 --- a/src/data/tauric/provider.ts +++ b/src/data/tauric/provider.ts @@ -6,7 +6,7 @@ * translated into the capability contracts. */ -import { errorText } from "../../contracts/index.js"; +import { addDays, errorText } from "../../contracts/index.js"; import { CALLS } from "../../contracts/limits.js"; import type { Capability, @@ -47,7 +47,19 @@ type Answer = TauricClient[M] extends (...args: ne : never; export function tauricProvider(client: TauricClient) { + // A window longer than Tauric serves at once is read in pieces, newest first, until it is covered or the + // source's history starts within a piece (an older piece would have nothing). const daily = async (key: string, window: { from: string; to: string }, signal?: AbortSignal) => { + const pieces: DailyBars[] = []; + for (const piece of piecesOf(window)) { + const answer = await dailyPiece(key, piece, signal); + pieces.push(answer); + const since = answer.coverage.history_from; + if (since && since >= piece.from) break; + } + return joined(pieces); + }; + const dailyPiece = async (key: string, window: { from: string; to: string }, signal?: AbortSignal) => { const { kind, id } = parseInstrument(key); const call = signal ? { signal } : {}; const query = { interval: "1d" as const, start: window.from, end: window.to }; @@ -140,13 +152,9 @@ export function tauricProvider(client: TauricClient) { revision: REVISION[bar.status], ...(Object.keys(bar.field_states).length ? { field_states: bar.field_states } : {}), })), - history_from: answer.coverage.history_from ?? null, - // A full page may have left earlier bars out; the next page ends just before its oldest bar. The - // source's continue_end is not followed here: on intraday pages it can skip a session's first bars. - earlier_end: - sorted.length >= limit && sorted[0]?.start - ? new Date(Date.parse(sorted[0].start) - 1_000).toISOString() - : null, + history_from: coverage.history_from ?? null, + // The bar just before the oldest one served; none at the start of the source's history. + earlier_end: coverage.continue_end ?? null, }; }, // Both listings from this one source, or neither. @@ -674,6 +682,45 @@ const REVISION = { settled: "final", unsettled: "provisional" } as const satisfi DailyBar["revision"] >; +/** `window` as windows Tauric serves, newest first, each ending the day before the one after it starts. */ +function piecesOf({ from, to }: { from: string; to: string }): { from: string; to: string }[] { + const pieces: { from: string; to: string }[] = []; + for (let end = to; end >= from; ) { + const earliest = addDays(end, 1 - CALLS.dailyWindowDays); + const start = earliest > from ? earliest : from; + pieces.push({ from: start, to: end }); + end = addDays(start, -1); + } + // A window that ends before it starts is asked as it is, for the source to answer. + return pieces.length ? pieces : [{ from, to }]; +} + +/** + * Pieces of one window, newest first, as one: their bars oldest first, the newest piece's instrument and + * basis, complete only when every piece is, and older bars continuing where the oldest piece says. + */ +function joined(pieces: readonly DailyBars[]): DailyBars { + const newest = pieces[0] as DailyBars; + if (pieces.length === 1) return newest; + const all = [...pieces].reverse(); + const oldest = all[0] as DailyBars; + const dated = all.flatMap((piece) => piece.bars); + const completes = all.map((piece) => piece.coverage.complete); + return { + ...newest, + bars: dated, + coverage: { + from: dated[0]?.date ?? null, + through: dated.at(-1)?.date ?? null, + complete: completes.includes(false) ? false : completes.includes(null) ? null : true, + complete_reason: all.find((piece) => piece.coverage.complete_reason)?.coverage.complete_reason ?? null, + history_from: all.find((piece) => piece.coverage.history_from)?.coverage.history_from ?? null, + missing_sessions: all.reduce((sum, piece) => sum + piece.coverage.missing_sessions, 0), + }, + earlier_end: oldest.earlier_end, + }; +} + /** Tauric's answer for the window asked: the bars in it and whether every session there is accounted for. */ function bars(answer: Bars, { from, to }: { from: string; to: string }): DailyBars { const within = (date: string) => date >= from && date <= to; diff --git a/src/tools/price-history.ts b/src/tools/price-history.ts index 0e22dafd0..d73060c2e 100644 --- a/src/tools/price-history.ts +++ b/src/tools/price-history.ts @@ -11,7 +11,7 @@ import { referenceTo } from "./references.js"; import { defineTool, type ToolAnswer, ToolRefusalError } from "./tool.js"; import { fieldNotes, instrument, instrumentLine, provenanceOf } from "./tool-text.js"; -const PERIODS = ["5d", "1mo", "3mo", "6mo", "ytd", "1y"] as const; +const PERIODS = ["5d", "1mo", "3mo", "6mo", "ytd", "1y", "2y", "3y", "5y"] as const; /** Instrument types whose values are rates or yields. */ const RATES = new Set(["rate"]); type Period = (typeof PERIODS)[number]; @@ -275,7 +275,8 @@ async function referenceRates( /** * The dates a period covers, ending at `to` (both inclusive), so every provider answers the same - * window: 5d is the 7 calendar days ending at `to`, months and a year count back by calendar, ytd + * window: 5d is the 7 calendar days ending at `to`, months and years count back by calendar and start + * the day after the date they count back to (a year is 365 or 366 days, as Tauric serves at most), ytd * starts on January 1 of `to`'s year. */ export function windowOf(period: Period, to: string): { from: string; to: string } { @@ -284,10 +285,11 @@ export function windowOf(period: Period, to: string): { from: string; to: string if (period === "5d") { return { from: new Date(Date.UTC(year, month - 1, date - 6)).toISOString().slice(0, 10), to }; } - // The same day of an earlier month, or that month's last day when it is shorter (March 31 -> February 28). - const back = { "1mo": 1, "3mo": 3, "6mo": 6, "1y": 12 }[period]; + // The day after the same day of an earlier month, or after that month's last day when it is shorter + // (March 31 -> March 1). + const back = { "1mo": 1, "3mo": 3, "6mo": 6, "1y": 12, "2y": 24, "3y": 36, "5y": 60 }[period]; const lastDay = new Date(Date.UTC(year, month - 1 - back + 1, 0)).getUTCDate(); - const from = new Date(Date.UTC(year, month - 1 - back, Math.min(date, lastDay))); + const from = new Date(Date.UTC(year, month - 1 - back, Math.min(date, lastDay) + 1)); return { from: from.toISOString().slice(0, 10), to }; }