fix(chat): every-turn method files ride in the cached system prompt; fact rewrite and missing-section writes keep the answer step's thinking mode (BUG-2424, #341)
- strict-workflow-router, interpretation status contract and working order §0.4 (same text every turn) move from the tool result to the end of the natal system prompt (<jyotish-method-every-turn>); the tool result names them in methodology.in_system_prompt; plan, delivery record and section count unchanged. About 7,300 fewer full-price input tokens per first answer. - The fact-guard rewrite and the missing-section continuation run with thinking on like the answer step: the provider keeps a separate prompt and cache per thinking mode, so the ~36k-token resend hit 384 tokens. Length continuation keeps thinking off. - Backtest manifests record each request's provider usage; launch chat cost estimate follows the new measurement. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXp2Vp62Ur3C7yRWQdSq
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
# 印度占星 Skill 更新日志
|
||||
|
||||
## 2026-11-27 · 问答首轮少付一部分输入费
|
||||
|
||||
- 占星师每轮都送的路由全文、解读状态合同和工作顺序改放在问答系统提示末尾(文字不变),工具结果里不再重复,供应商缓存按低价计;每题约少 7,300 个全价输入 token
|
||||
- 回答写完后的事实改写和补写「判断依据」改用写回答时的思考模式,重发的系统提示可以命中缓存
|
||||
- 后台上线配置里聊天的成本估算按新实测更新;Skill 版本不变
|
||||
|
||||
## 2026-11-26 · 只对上一部分条件的格局按对上的部分来解读
|
||||
|
||||
- 问答卡上,只对上一部分条件的格局列出对上了什么(参与的星管哪几宫、落在哪、强弱、功能吉凶)和缺了什么;这类格局不再写成「有某某格局」。后台状态不变。
|
||||
|
||||
@@ -33114,6 +33114,21 @@
|
||||
- **关联记录**:BUG-2421(发现处)、BUG-2406(主引擎九分盘上下文、Shadbala 之后重算)、BUG-1967(报告与问答读同一层)。
|
||||
- **修复版本**:下一版(staging)。
|
||||
|
||||
## BUG-2424 | 问答首轮输入成本高:每轮相同的方法文件排在用户问题之后按全价算;事实改写换了思考模式,整段系统提示不命中缓存(Gitea #341)
|
||||
|
||||
- 状态:fixed-pending-verify(本地分支 `claude/cost-2424`,未推送;待 staging 实测)。
|
||||
- 首次发现 / 最近更新:2026-11-23(#341)/ 2026-11-27。
|
||||
- 现象:一次首轮回答输入约 13–17 万 token,供应商缓存只命中约 45%;后台成本估算(BUG-2231)按旧样本。
|
||||
- 触发条件:每个本命首轮回答;事实核对拒收句子后的改写(约两成回答)和缺「判断依据」的补写。
|
||||
- 实测(公开 AA 盘、DeepSeek flash、改前 6 个首轮回答,按供应商逐次返回的 `prompt_cache_hit_tokens`):第 0 步(选工具)约 3.2 万 token 几乎全命中;写回答那一步约 10–11.4 万,命中约 3.37 万(系统提示 + 工具定义 + 用户轮),未命中约 6.7–8 万全是工具结果(证据卡约 12 万字 + methodology 约 4.5 万字)。事实改写那一次约 3.66 万 token 只命中 384。
|
||||
- 根因:(1)methodology 里路由全文、状态合同、工作顺序 §0.4(约 2.8 万字)每轮逐字相同,但放在工具结果里、排在用户问题之后,前缀缓存够不着,每轮按全价。(2)供应商按思考模式分开组 prompt 和缓存:同一段系统提示在关思考时 token 数都不同(探针 4,442 对 4,417,第二次 0 命中);事实改写和缺节补写用关思考的设置,重发的系统提示、工具定义和用户轮整段不命中。
|
||||
- 修复:(1)这三份放到本命系统提示末尾的 `<jyotish-method-every-turn>`(逐字、对所有用户相同、在原有规则之后,不改动前面的前缀);工具结果的 methodology 去掉这三节、用 `in_system_prompt` 点名;方法计划、delivery 记录和节数不变;输出合同不是每轮都送(通用骨架时跳过),留在工具结果。合同文件 P-08 补一句说明。(2)事实改写和缺节补写改用写回答那一步的思考模式(`consultationRepairGenerationSettings`);`length` 续写照旧关思考(BUG-345 / BUG-346)。(3)后台聊天成本估算按本次实测更新。回测脚本的模型请求记录加上每次调用的供应商用量。
|
||||
- 证据卡裁剪:本轮没有裁。卡已按领域取数(事业卡里没有子女、父母分盘的数据,#341 那句不成立);剩下的大块(预先算好的表、行运、运期、格局)都被写作规则、时间条、判断依据或事实核对用到;methodology 的按题部分是占星师的方法,不裁。只问西洋占星(`western_chart: only`)时印度卡的时间部分会被程序删掉,可以考虑只对这一类裁,留给负责人定。
|
||||
- 验证:改后 6 题(缓存热):写回答那一步未命中从 6.7–8.0 万降到 6.4–7.3 万(同题每题约少 7,300 token),命中从约 3.37 万升到约 4.06 万;系统提示多约 6,900 token,全部命中。按 flash 全价 2 元 / 百万、命中约 0.04 元 / 百万(供应商页面,未在仓库核实)、输出 8 元 / 百万算,每题输入成本约少 0.014 元(约 9%);触发事实改写的回答再少约 0.07 元。回答质量:事实核对、禁句、内部词、路由英文泄漏都没有变差,结论和要点一致;`mustAdded` 事业题 4 → 9/10,在此前基线的波动范围(7–18)内。「接下来一年事业」改后一次选了 career + annual(改前只选 career),卡变大;只有一次样本,第 0 步现在能读到路由全文,可能有关,待观察。`frontend/tests/consult-prompt-cache-2424.test.ts`(改前失败:没有这些导出;改后通过);`consult-condensed-checklist-20260927.test.ts` 的写作提示改为系统块 + 工具结果,P-08 长度 12,658 → 12,869(三栏说明)。
|
||||
- 防复发:系统提示必须对所有用户逐字相同,任何每轮不变的大段文字放在用户轮之前;同一请求内重发同一前缀的调用要用同一个思考模式。
|
||||
- 关联记录:BUG-2231(成本估算)、BUG-1973(重复整卡)、BUG-556(Anthropic 缓存断点)、BUG-1697 / BUG-1726(路由全文每轮送达)、BUG-1789(事实改写)。
|
||||
- 修复版本:`claude/cost-2424`(本地,待推送)。
|
||||
|
||||
## BUG-2425 | 生产只有数据库在备份:配置文件和证书没有异地副本,恢复没在新服务器演练;发版同步还会删掉告警渠道文件
|
||||
|
||||
- 状态:implemented, not installed(演练已做;配置备份脚本已写,需负责人提供公钥并以 root 安装;`.monitor.env` 删除问题的修复要随下一版发到生产)。
|
||||
|
||||
@@ -60,6 +60,7 @@ import { consultationInstructionReference, getJyotishAgent } from "../../src/mas
|
||||
import {
|
||||
AGENT_MAX_STEPS,
|
||||
consultationContinueGenerationSettings,
|
||||
consultationRepairGenerationSettings,
|
||||
consultationGenerationSettings,
|
||||
consultationNatalPrepareStep,
|
||||
consultationStepBudgetReceipt,
|
||||
@@ -484,7 +485,7 @@ async function runJobOnce(job: Job, resolved: ResolvedLanguageModel) {
|
||||
return (async () => {
|
||||
const continued = await agent.stream(messages, {
|
||||
...streamOptions,
|
||||
...consultationContinueGenerationSettings(resolved.model),
|
||||
...consultationRepairGenerationSettings(resolved.model),
|
||||
});
|
||||
usages.push(continued.totalUsage);
|
||||
return continued.fullStream as never;
|
||||
@@ -495,7 +496,7 @@ async function runJobOnce(job: Job, resolved: ResolvedLanguageModel) {
|
||||
preGuardOutput = text;
|
||||
const repaired = await agent.stream(consultationFactRepairMessages(baseMessages, text, units), {
|
||||
...streamOptions,
|
||||
...consultationContinueGenerationSettings(resolved.model),
|
||||
...consultationRepairGenerationSettings(resolved.model),
|
||||
});
|
||||
usages.push(repaired.totalUsage);
|
||||
return repaired.fullStream as never;
|
||||
|
||||
@@ -24,7 +24,7 @@ export type CapturedRequest = {
|
||||
url: string;
|
||||
body: unknown;
|
||||
/** From the streamed response: the tool calls the model made (the next request only references them by id). */
|
||||
response?: { function_calls: CapturedCall[]; output_text_chars: number };
|
||||
response?: { function_calls: CapturedCall[]; output_text_chars: number; usage?: Json | null };
|
||||
};
|
||||
type Sink = { requests: CapturedRequest[]; pending: Promise<void>[] };
|
||||
|
||||
@@ -34,6 +34,8 @@ const store = new AsyncLocalStorage<Sink>();
|
||||
function readStream(raw: string): NonNullable<CapturedRequest["response"]> {
|
||||
const calls: CapturedCall[] = [];
|
||||
let textChars = 0;
|
||||
// BUG-2424: the provider's own token count per request (prompt / cache hit / completion), from the last chunk that carries it.
|
||||
let usage: Json | null = null;
|
||||
for (const line of raw.split("\n")) {
|
||||
if (!line.startsWith("data:")) continue;
|
||||
let event: Json;
|
||||
@@ -42,13 +44,25 @@ function readStream(raw: string): NonNullable<CapturedRequest["response"]> {
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
if (event.usage && typeof event.usage === "object") usage = event.usage as Json;
|
||||
const response = (event.response ?? {}) as Json;
|
||||
if (response.usage && typeof response.usage === "object") usage = response.usage as Json;
|
||||
const item = (event.item ?? {}) as Json;
|
||||
if (event.type === "response.output_item.done" && item.type === "function_call") {
|
||||
calls.push({ name: String(item.name), call_id: String(item.call_id), arguments: String(item.arguments ?? "") });
|
||||
}
|
||||
if (event.type === "response.output_text.delta" && typeof event.delta === "string") textChars += event.delta.length;
|
||||
}
|
||||
return { function_calls: calls, output_text_chars: textChars };
|
||||
if (!calls.length && !textChars && !usage) {
|
||||
// Not a stream: a plain JSON body (generate calls).
|
||||
try {
|
||||
const body = JSON.parse(raw) as Json;
|
||||
if (body.usage && typeof body.usage === "object") usage = body.usage as Json;
|
||||
} catch {
|
||||
// not JSON either
|
||||
}
|
||||
}
|
||||
return { function_calls: calls, output_text_chars: textChars, usage };
|
||||
}
|
||||
let installed = false;
|
||||
|
||||
@@ -289,6 +303,7 @@ export function buildManifest(input: {
|
||||
tool_definitions: toolDefs(request.body).map((tool) => tool.name),
|
||||
response_tool_calls: (request.response?.function_calls ?? []).map((call) => ({ tool: call.name, arguments: call.arguments })),
|
||||
response_text_chars: request.response?.output_text_chars ?? null,
|
||||
usage: request.response?.usage ?? null,
|
||||
};
|
||||
});
|
||||
// The last request carries everything the model saw before its final answer.
|
||||
|
||||
@@ -100,6 +100,7 @@ import {
|
||||
CONSULTATION_ANSWER_TIMEOUT_MS,
|
||||
createConsultationRunClock,
|
||||
consultationContinueGenerationSettings,
|
||||
consultationRepairGenerationSettings,
|
||||
consultationGenerationSettings,
|
||||
consultationGeneralPrepareStep,
|
||||
consultAnswerEffortProviderOptions,
|
||||
@@ -1885,7 +1886,7 @@ async function handleConsultPost(request: Request) {
|
||||
const continued = await agent.stream(messages, {
|
||||
...streamOptions,
|
||||
abortSignal: answerPhaseSignal(),
|
||||
...consultationContinueGenerationSettings(selectedModel.model),
|
||||
...consultationRepairGenerationSettings(selectedModel.model),
|
||||
});
|
||||
usages.push(continued.totalUsage);
|
||||
return continued.fullStream;
|
||||
@@ -1915,7 +1916,7 @@ async function handleConsultPost(request: Request) {
|
||||
const repaired = await agent.stream(consultationFactRepairMessages(baseMessages, output, units), {
|
||||
...streamOptions,
|
||||
abortSignal: answerPhaseSignal(),
|
||||
...consultationContinueGenerationSettings(selectedModel.model),
|
||||
...consultationRepairGenerationSettings(selectedModel.model),
|
||||
});
|
||||
usages.push(repaired.totalUsage);
|
||||
return repaired.fullStream;
|
||||
|
||||
@@ -206,9 +206,13 @@ export function launchMargin(saleCny: number | null, costCny: number | null): nu
|
||||
* BUG-2231: chat.standard 原值 { input: 100_000, output: 13_000 };新值:2026-11-23 本地五个首轮回答的平均(含那一次补漏调用)
|
||||
* 输入 175,768、输出 22,650 token,取整为 176_000 / 22_700;原因:BUG-2229 的写法让首轮回答变长、卡上多了预先算好的表。
|
||||
* 追问(一份)约输入 185,000、输出 6,400 token:输入和首轮相近、输出少得多,按首轮估是上限。
|
||||
* BUG-2424 原值 { input: 176_000, output: 22_700 };新值:2026-11-27 本地六个首轮回答(事业、婚恋、财运、一年事业、
|
||||
* 印度和西洋对比、只按 KP)缓存改动之后、缓存已热的平均,按供应商逐次返回的用量相加(含补漏和改写调用):输入约
|
||||
* 151,000(其中约 79,600 命中缓存)、输出约 10,100;原因:BUG-2247 之后回答变短,每次调用的实测比旧样本小。
|
||||
* 这里仍按输入全价估,命中缓存的那部分实际约为全价的 1/50,所以是上限。
|
||||
*/
|
||||
export const LAUNCH_TYPICAL_TOKENS: Readonly<Record<LaunchFeatureKey, { input: number; output: number }>> = {
|
||||
"chat.standard": { input: 176_000, output: 22_700 },
|
||||
"chat.standard": { input: 151_000, output: 10_100 },
|
||||
"report.full": { input: 126_000, output: 33_000 },
|
||||
"annual.full": { input: 108_000, output: 86_000 },
|
||||
"synastry.full": { input: 360_000, output: 102_000 },
|
||||
|
||||
@@ -737,3 +737,50 @@ export function consultationMethodologyForDomains(
|
||||
planCache.set(key, methodology);
|
||||
return methodology;
|
||||
}
|
||||
|
||||
/**
|
||||
* BUG-2424: her layer-(a) files whose text is the same on every turn (the full router, the status contract and the
|
||||
* working order §0.4) travel once at the end of the natal system prompt instead of inside every tool result. The
|
||||
* system prompt is the same for every user, so the provider's prefix cache serves them at the cached-input price;
|
||||
* inside the tool result they came after the user's question and were paid at the full price every time. The
|
||||
* methodology plan, its delivery record and its section count are unchanged; only the model view drops these
|
||||
* sections and names them in `in_system_prompt`. The output contract stays in the tool result: it is skipped when
|
||||
* the generic skeleton travels, so it is not the same every turn.
|
||||
*/
|
||||
export const SYSTEM_PROMPT_METHOD_TAG = "jyotish-method-every-turn";
|
||||
|
||||
function systemPromptMethodSections(): z.infer<typeof consultationMethodologySectionSchema>[] {
|
||||
const workflow = packageFile(WORKFLOW_FILE);
|
||||
return [
|
||||
{ title: "占星师路由全文 · strict-workflow-router", source: ROUTER_FILE, text: packageFile(ROUTER_FILE) },
|
||||
{ title: "占星师解读状态合同 · interpretation_status_contract", source: STATUS_CONTRACT_FILE, text: packageFile(STATUS_CONTRACT_FILE) },
|
||||
{ title: "占星师工作顺序 · ai-reading-workflow-prompt §0.4 证据先行,结论最后", source: `${WORKFLOW_FILE}#0.4`, text: workflow ? headingSection(workflow, 3, "0.4 ") : null },
|
||||
].flatMap((section) => (section.text ? [{ ...section, text: clamp(section.text) }] : []));
|
||||
}
|
||||
|
||||
let systemPromptMethodText: string | null = null;
|
||||
|
||||
/** The block appended to the natal system prompt: byte-identical on every request. */
|
||||
export function systemPromptMethodBlock(): string {
|
||||
if (systemPromptMethodText !== null) return systemPromptMethodText;
|
||||
const sections = systemPromptMethodSections();
|
||||
systemPromptMethodText = sections.length === 0 ? "" : [
|
||||
`<${SYSTEM_PROMPT_METHOD_TAG}>`,
|
||||
"The astrologer's layer-(a) files, delivered every turn. The tool result's methodology lists them under in_system_prompt instead of repeating them; they rank exactly where its methodology order puts them.",
|
||||
...sections.map((section) => `## ${section.title} (${section.source})\n${section.text}`),
|
||||
`</${SYSTEM_PROMPT_METHOD_TAG}>`,
|
||||
].join("\n\n");
|
||||
return systemPromptMethodText;
|
||||
}
|
||||
|
||||
/** The model's view of one plan: the sections the system prompt already carries, word for word, are named, not repeated. */
|
||||
export function methodologyWithoutSystemPromptSections<T extends ConsultationMethodology>(methodology: T): Omit<T, "sections"> & { sections: T["sections"]; in_system_prompt?: string[] } {
|
||||
const inSystem = new Map(systemPromptMethodSections().map((section) => [section.source, section.text]));
|
||||
const moved = methodology.sections.filter((section) => inSystem.get(section.source) === section.text);
|
||||
if (moved.length === 0) return methodology;
|
||||
return {
|
||||
...methodology,
|
||||
sections: methodology.sections.filter((section) => !moved.includes(section)),
|
||||
in_system_prompt: moved.map((section) => section.title),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import {
|
||||
type ConsultationDomain,
|
||||
} from "../lib/consultation-domain-registry.ts";
|
||||
import { applyBirthTimeModeToWorkflowContext, type ConsultationBirthTimeMode } from "../lib/consultation-birth-time-mode.ts";
|
||||
import { consultationMethodologyForDomains } from "../lib/consultation-methodology.ts";
|
||||
import { consultationMethodologyForDomains, methodologyWithoutSystemPromptSections } from "../lib/consultation-methodology.ts";
|
||||
import type { DeclaredBirthWindowConsultation, ServerChartConsultation } from "../lib/consultation-route-service.ts";
|
||||
import { fetchDeclaredWindowChart } from "../lib/declared-window-chart.ts";
|
||||
import { runBirthWindowRangeReading } from "../lib/birth-window-range-reading.ts";
|
||||
@@ -353,6 +353,18 @@ export function consultationContinueGenerationSettings(model?: unknown) {
|
||||
return agentGenerationSettings(model, { thinking: "disabled" });
|
||||
}
|
||||
|
||||
/**
|
||||
* BUG-2424: the fact-guard rewrite and the missing-section continuation resend the answer step's system prompt, tools
|
||||
* and user turn, so they run in the answer step's thinking mode. The provider keeps a separate prompt (and prefix
|
||||
* cache) per thinking mode: in "disabled" mode those ~36k tokens were all uncached (measured 384 of 36,638 cached),
|
||||
* in the answer step's mode they hit the cache that step just warmed. A `length` continuation keeps thinking off
|
||||
* (BUG-345 / BUG-346: thinking must not eat the continued answer's budget).
|
||||
*/
|
||||
export function consultationRepairGenerationSettings(model?: unknown) {
|
||||
const effort = consultAnswerReasoningEffort();
|
||||
return agentGenerationSettings(model, { thinking: "enabled", ...(effort ? { providerReasoningEffort: effort } : {}) });
|
||||
}
|
||||
|
||||
export function consultationSliceGenerationSettings(model?: unknown) {
|
||||
return agentGenerationSettings(model, {
|
||||
thinking: "enabled",
|
||||
@@ -1208,7 +1220,8 @@ export function toModelEvidenceView(full: FullDomainPlanContext, card: EvidenceC
|
||||
success: full.success,
|
||||
domains: full.domains,
|
||||
omitted_domains: full.omitted_domains,
|
||||
...(full.methodology ? { methodology: full.methodology } : {}),
|
||||
// BUG-2424: her every-turn files are in the system prompt (cached); the view names them instead of repeating them.
|
||||
...(full.methodology ? { methodology: methodologyWithoutSystemPromptSections(full.methodology) } : {}),
|
||||
// Several domains: the top level is the most restrictive merge; each
|
||||
// domain's own contract is kept for per-domain detail. Its chart facts are
|
||||
// in the one card, not repeated here.
|
||||
|
||||
@@ -16,6 +16,8 @@ import {
|
||||
jyotishSkillMethodCoreBlock,
|
||||
} from "./skill-binding.ts";
|
||||
import { productContractBlock } from "../lib/product-runtime-contract.ts";
|
||||
// BUG-2424: her every-turn method files ride at the end of the natal system prompt, where the provider caches them.
|
||||
import { systemPromptMethodBlock } from "../lib/consultation-methodology.ts";
|
||||
// BUG-2161: typed plan-timing requests follow the astrologer's J §9 rules.
|
||||
import { PLAN_TIMING_RULE } from "../lib/plan-timing-clarify.ts";
|
||||
// BUG-2358: the product's own material (instructions, writing rules, tables, keys, card structure) is not handed out.
|
||||
@@ -45,6 +47,8 @@ const jyotishInstructions = productContractBlock("natal-instructions", {
|
||||
SPOKEN_HEADING_RULE: consultationSpokenHeadingRule("natal"),
|
||||
MEVG_BLOCKED_POLICY: productContractBlock("mevg-blocked-policy"),
|
||||
}) + "\n" + staleBirthHistoryRule + "\n" + PLAN_TIMING_RULE + "\n" + INSTRUCTION_PRIVACY_RULE;
|
||||
/** The natal agent's whole system prompt: the product instructions, then her every-turn files (last, so they never shift the rules' prefix). */
|
||||
const natalInstructions = `${jyotishInstructions}\n\n${systemPromptMethodBlock()}`.trimEnd();
|
||||
|
||||
/** How the natal instructions name this turn's answer mode. */
|
||||
function answerModeLabel(mode: ConsultationAnswerMode): string {
|
||||
@@ -60,7 +64,7 @@ export function getJyotishAgent(model: ResolvedLanguageModel, context: Consultat
|
||||
id: `jyotish-guide-${model.id}-${context.requestId}`,
|
||||
name: "Jyotish Guide",
|
||||
model: model.model,
|
||||
instructions: jyotishInstructions.replace(
|
||||
instructions: natalInstructions.replace(
|
||||
consultationSpokenHeadingRule("natal"),
|
||||
consultationSpokenHeadingRule(spokenKind),
|
||||
).replace(NATAL_VOICE_SLOT, consultationVoiceFor(answerMode)).replace(ANSWER_MODE_SLOT, answerModeLabel(answerMode)),
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
CONSULT_BRIEF_CHECKLIST_SOURCE,
|
||||
CONSULTATION_CONDENSED_CHECKLISTS,
|
||||
} from "../src/lib/consultation-condensed-checklist.ts";
|
||||
import { consultationMethodologyForDomains } from "../src/lib/consultation-methodology.ts";
|
||||
import { consultationMethodologyForDomains, SYSTEM_PROMPT_METHOD_TAG } from "../src/lib/consultation-methodology.ts";
|
||||
import { productContractBlockRaw } from "../src/lib/product-runtime-contract.ts";
|
||||
import { consultationDomainIds, type ConsultationDomain } from "../src/lib/consultation-domain-registry.ts";
|
||||
import { REPORT_HEADING } from "../src/lib/consultation-thinking-plan.ts";
|
||||
@@ -75,7 +75,17 @@ async function writerPrompt(domain: "career" | "marriage" | "wealth") {
|
||||
assert.deepEqual(result.terminal.map((event) => event.type), ["run.completed"]);
|
||||
const writer = firstPromptWithToolResult(result.prompts, "run-jyotish-consultation");
|
||||
assert.ok(writer > 0);
|
||||
return toolResultText(result.prompts[writer]);
|
||||
// 原值:只返回工具结果;新值:系统提示里的 <jyotish-method-every-turn> 块 + 工具结果;
|
||||
// 原因:BUG-2424 路由全文、状态合同、工作顺序每轮逐字相同,改放系统提示末尾(供应商缓存),写回答的模型照样每轮读到。
|
||||
const system = (result.prompts[writer] ?? [])
|
||||
.filter((message) => (message as { role?: string }).role === "system")
|
||||
.map((message) => String((message as { content?: unknown }).content ?? ""))
|
||||
.join("\n");
|
||||
const open = system.indexOf(`<${SYSTEM_PROMPT_METHOD_TAG}>`);
|
||||
const close = system.indexOf(`</${SYSTEM_PROMPT_METHOD_TAG}>`);
|
||||
const block = open >= 0 && close > open ? system.slice(open, close) : "";
|
||||
assert.ok(block.length > 0, "the every-turn method block is in the system prompt");
|
||||
return `${JSON.stringify(block)}\n${toolResultText(result.prompts[writer])}`;
|
||||
}
|
||||
|
||||
// 原值:测试名「career significators stay strength and affliction, and the system prompt is unchanged」,锁
|
||||
@@ -109,7 +119,8 @@ test("career directions are a checklist line with evidence, and the system promp
|
||||
// 原值(12): 12_391 新值(12): 12_323 原因(12): 产品 2026-11-16 合并两种解读方式:P-02、P-03 改成只有一种回答(白话正文 + 判断依据),短 68 个字符
|
||||
// 原值(13): 12_323 新值(13): 12_622 原因(13): BUG-1926(产品 2026-11-16 决定交付 Raman 原文):P-10 列卡上内容的那段加一句 classical_texts 的用法(原书的一般说法,帮助判断、在判断依据里按书名引用、正文不贴英文、不当判定),长 299 个字符,只说一次
|
||||
// 原值(14): 12_622 新值(14): 12_658 原因(14): BUG-2133(产品负责人 2026-11-21「问答也不引书名」):P-10 那句 classical_texts 的用法从「在判断依据里按书名引用」改为「在判断依据里写在「传统说法:」后面,不写书名、作者和页码」
|
||||
assert.equal(natal.length, 12_658);
|
||||
// 原值(15): 12_658 新值(15): 12_869 原因(15): BUG-2424 P-08 补一句:路由全文、状态合同、工作顺序放在系统提示末尾 <jyotish-method-every-turn>,methodology.in_system_prompt 点名(长 211 个字符)
|
||||
assert.equal(natal.length, 12_869);
|
||||
});
|
||||
|
||||
// 原值:测试名「career direction section only writes strength, resistance, timing and three events」,锁
|
||||
@@ -139,7 +150,8 @@ test("career directions keep the three events apart; the list is six lines", ()
|
||||
// 原值(12): 12_391 新值(12): 12_323 原因(12): 同上一测试(产品 2026-11-16 合并两种解读方式)
|
||||
// 原值(13): 12_323 新值(13): 12_622 原因(13): 同上一测试(BUG-1926,P-10 加一句 classical_texts 的用法)
|
||||
// 原值(14): 12_622 新值(14): 12_658 原因(14): 同上一测试(BUG-2133,问答也不引书名)
|
||||
assert.equal(natal.length, 12_658);
|
||||
// 原值(15): 12_658 新值(15): 12_869 原因(15): 同上一测试(BUG-2424,P-08 补一句方法块在系统提示末尾)
|
||||
assert.equal(natal.length, 12_869);
|
||||
});
|
||||
|
||||
test("each condensed list is 5–8 lines", () => {
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* BUG-2424: the unchanging parts of a chat request stay where the provider's prefix cache can serve them.
|
||||
* (1) Her every-turn method files (router, status contract, working order) travel once at the end of the natal
|
||||
* system prompt, not inside every tool result after the user's question.
|
||||
* (2) The fact-guard rewrite and the missing-section continuation run in the answer step's thinking mode, because
|
||||
* the provider keeps a separate prompt (and cache) per thinking mode; a `length` continuation keeps thinking off.
|
||||
*/
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import test from "node:test";
|
||||
|
||||
import {
|
||||
consultationMethodologyForDomains,
|
||||
methodologyWithoutSystemPromptSections,
|
||||
SYSTEM_PROMPT_METHOD_TAG,
|
||||
systemPromptMethodBlock,
|
||||
} from "../src/lib/consultation-methodology.ts";
|
||||
import {
|
||||
consultationContinueGenerationSettings,
|
||||
consultationGenerationSettings,
|
||||
consultationRepairGenerationSettings,
|
||||
} from "../src/mastra/consultation-tools.ts";
|
||||
|
||||
const MOVED = ["references/strict-workflow-router.md", "references/interpretation_status_contract.md", "references/ai-reading-workflow-prompt.md#0.4"];
|
||||
|
||||
test("the system-prompt method block is byte-identical every time and carries the three every-turn files in full", () => {
|
||||
const block = systemPromptMethodBlock();
|
||||
assert.equal(block, systemPromptMethodBlock());
|
||||
assert.ok(block.startsWith(`<${SYSTEM_PROMPT_METHOD_TAG}>`) && block.endsWith(`</${SYSTEM_PROMPT_METHOD_TAG}>`));
|
||||
const plan = consultationMethodologyForDomains(["career"], { question: "我适合做什么工作?" });
|
||||
assert.ok(plan);
|
||||
for (const source of MOVED) {
|
||||
const section = plan.sections.find((row) => row.source === source);
|
||||
assert.ok(section, source);
|
||||
assert.ok(block.includes(section.text), `${source} travels word for word`);
|
||||
}
|
||||
});
|
||||
|
||||
test("the model view names the moved sections instead of repeating them; the plan, its delivery and the rest are unchanged", () => {
|
||||
for (const domains of [["career"], ["marriage"], ["general"], ["wealth", "career"]] as const) {
|
||||
const plan = consultationMethodologyForDomains(domains, { question: "接下来一年会怎么样" });
|
||||
assert.ok(plan);
|
||||
const view = methodologyWithoutSystemPromptSections(plan);
|
||||
assert.deepEqual(view.sections.map((row) => row.source), plan.sections.map((row) => row.source).filter((source) => !MOVED.includes(source)));
|
||||
assert.equal(view.in_system_prompt?.length, 3);
|
||||
assert.deepEqual(view.delivery, plan.delivery);
|
||||
assert.ok(plan.sections.some((row) => row.source === MOVED[0]), "the plan itself still lists the router");
|
||||
// The output contract is not the same every turn (skipped with the generic skeleton), so it stays in the view.
|
||||
if (!domains.includes("general" as never)) assert.ok(view.sections.some((row) => row.source.endsWith("event_judgment_skeleton.md#5-6")));
|
||||
}
|
||||
});
|
||||
|
||||
test("the natal agent's instructions end with the block; the tool result view drops the moved sections", () => {
|
||||
const index = readFileSync(new URL("../src/mastra/index.ts", import.meta.url), "utf8");
|
||||
assert.match(index, /const natalInstructions = `\$\{jyotishInstructions\}\\n\\n\$\{systemPromptMethodBlock\(\)\}`/);
|
||||
assert.match(index, /instructions: natalInstructions\.replace\(/);
|
||||
const tools = readFileSync(new URL("../src/mastra/consultation-tools.ts", import.meta.url), "utf8");
|
||||
assert.match(tools, /methodology: methodologyWithoutSystemPromptSections\(full\.methodology\)/);
|
||||
});
|
||||
|
||||
test("fact rewrite and missing-section continuation use the answer step's thinking mode; a length continuation keeps it off", () => {
|
||||
const model = "deepseek";
|
||||
const repair = consultationRepairGenerationSettings(model);
|
||||
assert.deepEqual(repair.providerOptions.deepseek.thinking, consultationGenerationSettings(model).providerOptions.deepseek.thinking);
|
||||
assert.equal(repair.providerOptions.deepseek.thinking.type, "enabled");
|
||||
assert.equal(consultationContinueGenerationSettings(model).providerOptions.deepseek.thinking.type, "disabled");
|
||||
const route = readFileSync(new URL("../src/app/api/consult/route.ts", import.meta.url), "utf8");
|
||||
const body = (name: string) => route.slice(route.indexOf(`const ${name} = `), route.indexOf(`const ${name} = `) + 700);
|
||||
const factRepair = body("regenerateFactSentences");
|
||||
assert.match(factRepair, /consultationRepairGenerationSettings\(selectedModel\.model\)/);
|
||||
const missing = body("continueForMissingSection");
|
||||
assert.match(missing, /consultationRepairGenerationSettings\(selectedModel\.model\)/);
|
||||
const length = body("continueAfterLength");
|
||||
assert.match(length, /consultationContinueGenerationSettings\(selectedModel\.model\)/);
|
||||
});
|
||||
@@ -105,8 +105,8 @@ Period-first: {{PERIOD_FIRST_RULE}}
|
||||
Call run-jyotish-consultation before answering every turn, including short follow-ups; the calculation is request-scoped and is never carried over from an earlier turn.
|
||||
<!-- 产品规则,不是占星师的方法:P-07 领域只经 domains 数组选择;领域 id 与她的 strict route 名不是一回事。 -->
|
||||
Select consultation domains only through the single ordered domains array of run-jyotish-consultation, whether the question covers one domain or several; omit it to accept the domain the server already selected. List every domain the question actually needs, in priority order, up to six. Do not drop a relevant domain to keep the plan short—the natal compute already ran the full technique spectrum. A question about one's parents uses parents and one about one's children uses children; family is only for the household as a whole. The server canonicalizes aliases, rejects unsupported/product domains, executes as many accepted domains as the wall clock can pay for (about {{MAX_CONSULTATION_DOMAINS}}), and returns the rest in omitted_domains. The actual executed domains are in the tool context and receipt. The only legal domain ids are the ones enumerated in that array's schema; the skill's methodology names strict-workflow checklists such as career-timing-strict, and those labels select techniques inside the skill, never domains for this tool. A rejected domain plan is final for this run: correct the domains once, and never re-send the same call with extra parameters.
|
||||
<!-- 产品规则,不是占星师的方法:P-08 工具结果 methodology 的交付顺序与用法(本次更新:按占星师 2026-11-07 三层裁定列出送达的文件与按路由技法选择的子 skill)。 -->
|
||||
The tool result's methodology field is the checklist for the routes that actually ran: first 通用读法 · 先看受冲 (read afflictions before dignities, and count the signals it lists against the card's own fields), then, every turn, the astrologer's full router, her interpretation status contract, her output contract (event-judgment skeleton §5 Output Contract and §6 Hard Stops) and her working order (ai-reading-workflow-prompt §0.4); then, for this question, her event-judgment entry (ai-reading-workflow-prompt §2.3) and the matching event-judgment branch, her transit output guide when the question asks for a time, and the sub-skills the route's techniques need (specialized-jyotish only as the paragraphs for the needed technique plus its own boundaries; a relative link inside a sub-skill is read with skill_read as skills/<family>/<link>); then one list per domain. methodology.delivery says which of her files travelled, in which layer and why; delivering a file is not running its method. Use them to judge. The checklist is a list of things to check, not a list of paragraphs to write: run every item that bears on this question, never recite the checklists' wording to the user, and write the answer as VISIBLE VOICE says. Those sections are already delivered, so never spend a turn re-reading them; read a methodology.further_reading reference with skill_read only when the question needs something they do not cover. When methodology.domains_without_strict_checklist names a domain, it has no named checklist: follow the shared reading and the bound skill method, and do not imply a named strict route was followed.
|
||||
<!-- 产品规则,不是占星师的方法:P-08 工具结果 methodology 的交付顺序与用法(本次更新:按占星师 2026-11-07 三层裁定列出送达的文件与按路由技法选择的子 skill)。 BUG-2424(2026-11-27):原值「每轮四份第一层文件都在工具结果 methodology 里」;新值:路由全文、状态合同、工作顺序 §0.4 这三份每轮逐字相同的放在系统提示末尾 <jyotish-method-every-turn>,工具结果用 in_system_prompt 点名,输出合同仍在工具结果;原因:系统提示对所有用户相同,供应商前缀缓存按缓存价计,放在用户问题之后每轮按全价计;文字和送达层次不变。 -->
|
||||
The tool result's methodology field is the checklist for the routes that actually ran: first 通用读法 · 先看受冲 (read afflictions before dignities, and count the signals it lists against the card's own fields), then, every turn, the astrologer's full router, her interpretation status contract, her output contract (event-judgment skeleton §5 Output Contract and §6 Hard Stops) and her working order (ai-reading-workflow-prompt §0.4) — the router, the status contract and the working order are the same text every turn, so they sit once at the end of this system prompt in <jyotish-method-every-turn> and methodology.in_system_prompt names them; then, for this question, her event-judgment entry (ai-reading-workflow-prompt §2.3) and the matching event-judgment branch, her transit output guide when the question asks for a time, and the sub-skills the route's techniques need (specialized-jyotish only as the paragraphs for the needed technique plus its own boundaries; a relative link inside a sub-skill is read with skill_read as skills/<family>/<link>); then one list per domain. methodology.delivery says which of her files travelled, in which layer and why; delivering a file is not running its method. Use them to judge. The checklist is a list of things to check, not a list of paragraphs to write: run every item that bears on this question, never recite the checklists' wording to the user, and write the answer as VISIBLE VOICE says. Those sections are already delivered, so never spend a turn re-reading them; read a methodology.further_reading reference with skill_read only when the question needs something they do not cover. When methodology.domains_without_strict_checklist names a domain, it has no named checklist: follow the shared reading and the bound skill method, and do not imply a named strict route was followed.
|
||||
<!-- 产品规则,不是占星师的方法:P-09 多领域时顶层合同取最严格合并。 -->
|
||||
The tool result always carries one top-level answer contract—status, evidence_contract, claim_cards, rectification—even when several domains ran. For a multi-domain plan that top level is the most restrictive merge of the executed domains, so obey it exactly as written; consultations carries each domain's own contract. Never treat an absent top-level field as permission to answer without a contract.
|
||||
<!-- 产品公告 G-14(BUG-2133,产品负责人 2026-11-21「问答也不引书名」):原值为证据卡说明里 classical_texts「在「## 判断依据」里按书名引用」,系统提示 P-10 要求「写书名和它的大意」;新值为只写大意、前面写「传统说法:」,问答正文和判断依据都不写书名、作者、表号、章节和页码(与报告的 BUG-2130 同一口径;带作者名的方法名只留在报告的资料章节)。classical_texts 的 source 字段只供后台追溯。 -->
|
||||
|
||||
Reference in New Issue
Block a user