@danceiny/gotry 0.2.0-rc.27 → 0.2.0-rc.28

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.
Files changed (64) hide show
  1. package/README.md +2 -2
  2. package/README.zh-CN.md +2 -2
  3. package/bin/gotry-bootstrap.js +47 -3
  4. package/dist/capabilities/anything.js +26 -0
  5. package/dist/capabilities/doctor.js +11 -4
  6. package/dist/capabilities/ground-transfer.js +168 -1
  7. package/dist/capabilities/provider-detail-sanitize.js +64 -0
  8. package/dist/capabilities/route-provider-conformance.js +341 -0
  9. package/dist/scripts/anything-path-measure-tests.js +133 -0
  10. package/dist/scripts/anything-path-measure.js +150 -0
  11. package/dist/scripts/anything-tests.js +136 -2
  12. package/dist/scripts/booking-copilot-dsh-warmer-proof.js +5 -2
  13. package/dist/scripts/bootstrap-tests.js +71 -1
  14. package/dist/scripts/city-scenario-tier-tests.js +234 -0
  15. package/dist/scripts/doctor-tests.js +37 -1
  16. package/dist/scripts/drill-multiuser-ledger-tests.js +1076 -0
  17. package/dist/scripts/drill-sdk-descendant-cleanup-tests.js +606 -0
  18. package/dist/scripts/drill-w2a-sensor-tests.js +788 -0
  19. package/dist/scripts/dsh-llm-tests.js +437 -0
  20. package/dist/scripts/g5-guard-tests.js +20 -1
  21. package/dist/scripts/g5-guard.js +5 -1
  22. package/dist/scripts/m3-cohort-tests.js +714 -0
  23. package/dist/scripts/m3-cohort.js +310 -0
  24. package/dist/scripts/nightly-evidence-tests.js +44 -2
  25. package/dist/scripts/nightly-evidence.js +21 -4
  26. package/dist/scripts/outcome-projection-tests.js +427 -0
  27. package/dist/scripts/persona-sim-tests.js +603 -0
  28. package/dist/scripts/persona-sim.js +1081 -0
  29. package/dist/scripts/replay-async.js +2 -0
  30. package/dist/scripts/replay.js +2 -0
  31. package/dist/scripts/route-provider-conformance-tests.js +391 -0
  32. package/dist/scripts/session-zone-crash.js +49 -0
  33. package/dist/scripts/session-zone-ledger-tests.js +432 -0
  34. package/dist/scripts/session-zone-observation-tests.js +492 -0
  35. package/dist/scripts/session-zone-observe.js +135 -0
  36. package/dist/scripts/session-zone-wiring-tests.js +566 -0
  37. package/dist/scripts/session-zones-tests.js +17 -1
  38. package/dist/scripts/spawn-bounded-abort-tests.js +3 -0
  39. package/dist/scripts/state-cli.js +16 -0
  40. package/dist/scripts/time-eval-tests.js +2 -0
  41. package/dist/scripts/unified-tests.js +37 -1
  42. package/dist/scripts/z3-race-tests.js +6 -1
  43. package/dist/src/city-scenario-tier.js +378 -0
  44. package/dist/src/dsh-llm.js +84 -14
  45. package/dist/src/index.js +160 -1
  46. package/dist/src/loop.js +16 -5
  47. package/dist/src/m3-cohort.js +1577 -0
  48. package/dist/src/outcome-projection.js +746 -0
  49. package/dist/src/session-zone-ledger.js +312 -0
  50. package/dist/src/session-zone-observation.js +354 -0
  51. package/dist/src/session-zone-wiring.js +658 -0
  52. package/dist/src/session-zones.js +7 -4
  53. package/dist/src/state-ledger.js +293 -40
  54. package/dist/src/unified.js +69 -5
  55. package/extension/manifest.json +2 -2
  56. package/package.json +1 -1
  57. package/ts/capabilities/anything.ts +27 -0
  58. package/ts/scripts/state-cli.ts +18 -0
  59. package/ts/src/contracts.ts +4 -0
  60. package/ts/src/dsh-llm.ts +111 -9
  61. package/ts/src/index.ts +175 -2
  62. package/ts/src/loop.ts +15 -5
  63. package/ts/src/state-ledger.ts +294 -40
  64. package/ts/src/unified.ts +91 -18
package/dist/src/index.js CHANGED
@@ -24,7 +24,8 @@ import { interpretArgs } from './tool-packet.js';
24
24
  import { projectUtility } from './memory-utility.js';
25
25
  import { pickNudgeWish } from './wish-pool.js';
26
26
  import { resolveTimelineDate } from './travel-timeline.js';
27
- import { ensureLedger, readCompanionsWithFallback, readMotivationWithFallback, readTripsWithFallback } from './state-ledger.js';
27
+ import { ensureLedger, openLedgerIfExists, readCompanionsWithFallback, readMotivationWithFallback, readTripsWithFallback } from './state-ledger.js';
28
+ import { applyZoneNote, bindZoneSession, boundZoneSession, isZoneObservableTool, observeToolResult, promoteWithRouting, renderSessionZoneBrief, resolveZoneSwitch, zoneScopeOfExec, zoneSessionRefFromExec, } from './session-zone-wiring.js';
28
29
  import { isValidHomeCityPreference, resolveDefaultOrigin } from './memory-capture.js';
29
30
  import { applyPlanningWindow } from './loop.js';
30
31
  import { buildTimeAnchor } from './time-anchor.js';
@@ -84,6 +85,7 @@ export const Config = z.object({
84
85
  timeoutMs: z.number().default(30_000),
85
86
  hbcliBin: z.string().default('hbcli'),
86
87
  sessionAccess: z.string().default('ask'),
88
+ sessionZones: z.string().default('off'),
87
89
  benchmarkEnvironmentConfigPath: z.string().default(''),
88
90
  lavishAxiPackageRoot: z.string().default(''),
89
91
  });
@@ -450,6 +452,9 @@ export function apply(ctx, config, seams = {}) {
450
452
  }
451
453
  // 时间感知:注册动态变量,persona 里用 {{current_date}} 引用。
452
454
  // 每次 assemble 时取系统时钟——LLM 始终知道「今天是几号」。
455
+ // provider 收到本次组装的 AssembleContext(dsh-system-prompt 契约:
456
+ // `variable(name, provider: (context: AssembleContext) => string | undefined)`);
457
+ // `scope` 是不透明、按身份比较的 ScopeKey —— 分区读回据此分辨会话。
453
458
  const sp = ctx['systemPrompt'];
454
459
  sp?.variable?.('current_date', () => {
455
460
  const d = new Date();
@@ -464,6 +469,32 @@ export function apply(ctx, config, seams = {}) {
464
469
  // 模型都是盲的、重新访谈——「回访规划时长降 ≥50%」不可能成立。这里把画像
465
470
  // 渲染成紧凑 brief 注入 persona;为空 = 首访。与当轮说法冲突时以用户为准。
466
471
  sp?.variable?.('motivation_brief', () => renderMotivationBrief(config.stateRoot ?? '.'));
472
+ // 会话双区记忆读回(issue #255 P4-3,design/session-dual-zone-memory-design.md §5):
473
+ // 变量恒注册(persona 侧可随时引用),但总闸 off(默认)时恒返回空串 —— 接线惰性,
474
+ // 不建库、不读库、零事件;persona 模板本身不在本 PR 改动,因此开关 off 时注入面
475
+ // 输出逐字节不变。空串 = 首访/无活笔记(与 motivation_brief 同纪律)。
476
+ // 会话双区读回(issue #255 P4-3):**只在总闸 on 时注册**。
477
+ // - 为什么是条件注册:默认关必须与 main **不可区分**——注入面多出一个变量名
478
+ // 就已经是可观测差异(§48 benchmark-environment-bridge-tests 的
479
+ // 「normal product mode keeps its prompt variables」逐项断言会红)。
480
+ // 出厂 persona(cordis.gotry-patch.yml)今天不引用本变量,所以条件注册安全。
481
+ // - **后续约束**:创始人一旦把 `{{session_zone_brief}}` 写进出厂 persona,
482
+ // 本变量必须改为**无条件注册**(关闸时返回空串)——strict 插值下未注册的
483
+ // 引用会让整段 persona 渲染失败。那一步同时要改 §48 的变量清单断言、
484
+ // persona-surface-guard-tests 的注入面清单与 benchmark-environment-bridge-e2e
485
+ // 的 CANONICAL_RAW_VARIABLES。
486
+ // - 读回按**组装 scope** 取会话身份(dsh agent-loop 以 agent 对象为 ScopeKey,
487
+ // 与工具侧 exec.agent 同一身份):同一宿主进程里的两个会话因此读不到对方的
488
+ // resource 层笔记(设计 §1.1);取不到 scope → 不出 resource 段(fail-closed)。
489
+ const zoneSwitch = resolveZoneSwitch(config.sessionZones);
490
+ if (zoneSwitch === 'on') {
491
+ sp?.variable?.('session_zone_brief', assembleContext => renderSessionZoneBrief({
492
+ ledger: openLedgerIfExists(config.stateRoot ?? '.'),
493
+ now: new Date().toISOString(),
494
+ sessionRef: boundZoneSession(assembleContext?.scope),
495
+ zoneSwitch,
496
+ }));
497
+ }
467
498
  // 通道路由卡(通道注册表生成,docs/design/tool-orchestration-design.md §2.1/D-8):
468
499
  // persona 检索条款只留行为契约,机/火/酒通道顺位与额度口径查卡——prose 教义
469
500
  // 变查表教义,注册表加通道卡片自动一致。
@@ -537,6 +568,30 @@ export function apply(ctx, config, seams = {}) {
537
568
  if (typeof t.execute === 'function') {
538
569
  t.execute = guardToolExecute(String(t.name), config.stateRoot ?? '.', t.execute);
539
570
  }
571
+ // 工具观察捕获缝(issue #255 P4-3):总闸 on 且工具在闭集白名单内才包裹——
572
+ // off(默认)时 execute 一层不多包,行为逐字节不变。捕获只投影形状字段
573
+ // (verdict/条数/价格带),证据只走指针;捕获失败永不影响工具返回值。
574
+ if (zoneSwitch === 'on' && typeof t.execute === 'function' && isZoneObservableTool(t.name)) {
575
+ const inner = t.execute;
576
+ const toolName = String(t.name);
577
+ t.execute = async (args, exec) => {
578
+ const result = await inner(args, exec);
579
+ try {
580
+ const sessionRef = zoneSessionRefFromExec(exec);
581
+ if (sessionRef) {
582
+ bindZoneSession(zoneScopeOfExec(exec), sessionRef);
583
+ observeToolResult(openLedgerIfExists(config.stateRoot ?? '.') ?? ensureLedger(config.stateRoot ?? '.'), {
584
+ tool: toolName,
585
+ result,
586
+ session_ref: sessionRef,
587
+ ts: new Date().toISOString(),
588
+ });
589
+ }
590
+ }
591
+ catch { /* 记忆面永不把产品主路径带红 */ }
592
+ return result;
593
+ };
594
+ }
540
595
  ctx.tools.register(t);
541
596
  };
542
597
  // Issue #443: register the five local editor tools only from trusted host
@@ -1055,6 +1110,110 @@ export function apply(ctx, config, seams = {}) {
1055
1110
  },
1056
1111
  presentCall: args => ({ card: 'generic', title: '记录旅行', kind: 'edit', rawInput: args }),
1057
1112
  }));
1113
+ // 会话双区记忆工具面(issue #255 P4-3):**只在总闸 on 时注册**——off(默认)时
1114
+ // 工具清单逐项不变,模型看不到任何分区入口(接线惰性的第一道)。
1115
+ if (zoneSwitch === 'on') {
1116
+ registerGuarded(defineTool({
1117
+ name: 'gotry_session_zone_note',
1118
+ description: 'Session working-zone memory (hot context, issue #255): capture a STRUCTURED fragment of what is still in play this session '
1119
+ + '(destination / date window / party size / budget stance = intent tier, 24h; search shapes = resource tier, 30min), '
1120
+ + 'revise it with optimistic CAS when the user corrects a detail, or drop it when it stops being true. '
1121
+ + 'Payload must be typed slot-spec-family fields — NEVER raw conversation text, IDs, phone numbers, URLs or credentials '
1122
+ + '(the write gate rejects those shapes). Evidence is a pointer (session + observation index), never content. '
1123
+ + 'action="propose" only PROPOSES moving a note into the durable notebook: it writes NOTHING; the owner must confirm in their own words, '
1124
+ + 'after which you call gotry_session_zone_promote with that quote. The model may never self-promote. '
1125
+ + 'action="deny" records that the owner declined to remember it long-term (writes nothing; stop re-proposing it this session).',
1126
+ parameters: {
1127
+ action: { type: 'string', required: true, enum: ['capture', 'revise', 'drop', 'propose', 'deny'], description: 'capture=新片段入工作区;revise=CAS 修订(需 noteId+expectedRev);drop=更正即弃;propose=提议晋升(零写入);deny=owner 否决提议(零写入)' },
1128
+ tier: { type: 'string', enum: ['resource', 'intent'], description: 'capture 必填:intent(目的地/日期/人数/预算立场,24h)或 resource(检索形态,30min)' },
1129
+ kind: { type: 'string', enum: ['availability', 'price_band', 'destination', 'date_window', 'party_size', 'budget_stance'], description: 'capture 必填;revise 可选(改 kind)' },
1130
+ payload: { type: 'object', additionalProperties: true, description: '结构化片段,如 { city: "大理" } / { start: "2026-11-01", end: "2026-11-05" };禁放原文/证件/电话/URL/凭证' },
1131
+ noteId: { type: 'string', description: 'revise/drop/propose 的目标笔记 id' },
1132
+ expectedRev: { type: 'integer', description: 'revise 的父 rev(必须等于当前 rev,否则 stale_rev 拒绝)' },
1133
+ promoteKind: { type: 'string', enum: ['trip_fact', 'preference', 'constraint', 'lesson'], description: 'propose 时提议的持久条目类别' },
1134
+ },
1135
+ output: {
1136
+ schema: { type: 'json' },
1137
+ render: (_args, value) => [{ type: 'text', text: String(value.summary ?? '') }],
1138
+ },
1139
+ async execute(args, exec) {
1140
+ const sessionRef = zoneSessionRefFromExec(exec);
1141
+ if (!sessionRef) {
1142
+ return { ok: false, code: 'bad_session', summary: '无会话身份(exec.agent.session.id 缺失):分区不记忆无主体的片段' };
1143
+ }
1144
+ bindZoneSession(zoneScopeOfExec(exec), sessionRef);
1145
+ const r = applyZoneNote(ensureLedger(config.stateRoot), {
1146
+ action: args.action,
1147
+ ...(args.tier !== undefined ? { tier: args.tier } : {}),
1148
+ ...(args.kind !== undefined ? { kind: args.kind } : {}),
1149
+ ...(args.payload !== undefined ? { payload: args.payload } : {}),
1150
+ ...(args.noteId !== undefined ? { noteId: args.noteId } : {}),
1151
+ ...(args.expectedRev !== undefined ? { expectedRev: args.expectedRev } : {}),
1152
+ ...(args.promoteKind !== undefined ? { promoteKind: args.promoteKind } : {}),
1153
+ session_ref: sessionRef,
1154
+ ts: new Date().toISOString(),
1155
+ });
1156
+ if (!r.ok)
1157
+ return { ok: false, code: r.code, summary: r.detail };
1158
+ const summary = r.proposed
1159
+ ? `已提议(未写入):${r.ask ?? ''}`
1160
+ : `${r.action}${r.appended ? ' 已落账' : ' 幂等跳过'}${r.noteId ? `:${r.noteId.slice(0, 60)}` : ''}`;
1161
+ return { ok: true, action: r.action, appended: r.appended, note_id: r.noteId, requires_owner_confirm: r.requiresOwnerConfirm === true, summary };
1162
+ },
1163
+ presentCall: args => ({ card: 'generic', title: `会话记忆:${String(args.action ?? '')}`, kind: 'edit', rawInput: args }),
1164
+ }));
1165
+ registerGuarded(defineTool({
1166
+ name: 'gotry_session_zone_promote',
1167
+ description: 'Owner-confirmed promotion into the durable trip notebook (issue #255) — the ONLY write path into durable memory. '
1168
+ + 'Requires ownerQuote: the user\'s OWN words confirming they want this remembered long-term; your own summary is not a confirmation. '
1169
+ + 'Routing rule: a preference ALSO goes through the motivation-profile gate (pass motivation.{weights|hard|homeCity}), '
1170
+ + 'a trip fact through the timeline gate (pass trip.{destination,start}), a companion constraint through the companion gate (pass companion.{label,constraints}). '
1171
+ + 'Without the required routed payload the promotion is REJECTED — the notebook never becomes a parallel store for a fact that already has an owner. '
1172
+ + 'Generic constraints and lessons live in the notebook itself. The notebook write and the routed gate write are one transaction: they cannot diverge.',
1173
+ parameters: {
1174
+ noteId: { type: 'string', required: true, description: '源工作区笔记 id(必须未过期)' },
1175
+ kind: { type: 'string', required: true, enum: ['trip_fact', 'preference', 'constraint', 'lesson'], description: '持久条目类别' },
1176
+ ownerQuote: { type: 'string', required: true, description: '用户本人确认要长期记住的原话(≤200 字;模型自述不算确认)' },
1177
+ surface: { type: 'string', required: true, enum: ['user_reply', 'approval_card'], description: '确认表面:用户回复 或 审批卡' },
1178
+ payload: { type: 'object', additionalProperties: true, description: '可选:覆盖源笔记载荷的结构化断言' },
1179
+ motivation: { type: 'object', additionalProperties: true, description: 'preference 必填:{ weights?, hard?, homeCity? } 至少一项(经动机画像闸)' },
1180
+ trip: { type: 'object', additionalProperties: true, description: 'trip_fact 必填:{ destination, start(YYYY-MM-DD), end?, companions? }(经时间线闸)' },
1181
+ companion: { type: 'object', additionalProperties: true, description: '同行人约束必填:{ label, constraints:{ mobility?, health?, prefs? } }(经同行人闸)' },
1182
+ },
1183
+ output: {
1184
+ schema: { type: 'json' },
1185
+ render: (_args, value) => [{ type: 'text', text: String(value.summary ?? '') }],
1186
+ },
1187
+ async execute(args, exec) {
1188
+ const sessionRef = zoneSessionRefFromExec(exec);
1189
+ if (sessionRef)
1190
+ bindZoneSession(zoneScopeOfExec(exec), sessionRef);
1191
+ const r = promoteWithRouting(ensureLedger(config.stateRoot), {
1192
+ noteId: String(args.noteId ?? ''),
1193
+ kind: String(args.kind ?? ''),
1194
+ ownerQuote: String(args.ownerQuote ?? ''),
1195
+ surface: String(args.surface ?? ''),
1196
+ ...(args.payload !== undefined ? { payload: args.payload } : {}),
1197
+ ...(args.motivation !== undefined ? { motivation: args.motivation } : {}),
1198
+ ...(args.trip !== undefined ? { trip: args.trip } : {}),
1199
+ ...(args.companion !== undefined ? { companion: args.companion } : {}),
1200
+ ts: new Date().toISOString(),
1201
+ });
1202
+ if (!r.ok)
1203
+ return { ok: false, code: r.code, summary: r.detail };
1204
+ const routed = r.routed ? `;并经 ${r.routed.authority} 闸${r.routed.applied ? '落地' : '幂等跳过'}` : '';
1205
+ return {
1206
+ ok: true,
1207
+ appended: r.appended,
1208
+ entry_id: r.entryId,
1209
+ authority: r.authority,
1210
+ routed: r.routed ? JSON.parse(JSON.stringify(r.routed)) : null,
1211
+ summary: `${r.appended ? '已写入笔记本' : '笔记本幂等跳过'}${routed}`,
1212
+ };
1213
+ },
1214
+ presentCall: args => ({ card: 'generic', title: '笔记本晋升(owner 确认)', kind: 'edit', rawInput: args }),
1215
+ }));
1216
+ }
1058
1217
  registerGuarded(defineTool({
1059
1218
  name: 'gotry_hotel_search',
1060
1219
  description: routed('gotry_hotel_search', 'Search hotels via hotelbyte-cli (real-time when hbcli credentials exist, falls back to the static pack with explicit evidence tagging). '
package/dist/src/loop.js CHANGED
@@ -161,13 +161,18 @@ function terminalOutcomeFromState(ticketId, state) {
161
161
  '4_做不到的诚实说': false,
162
162
  });
163
163
  }
164
+ // issue #620:求解器自身失败时既没有产物也没有判定——2 条不成立;但「做不到诚实说」
165
+ // 恰恰成立(我们明说了是引擎故障而非不可行),不靠 unsat_core 冒充自检通过。
166
+ const solverFailed = Boolean(state.solve.solver_error);
164
167
  return asyncTerminalOutcome(ticketId, {
165
168
  '1_承诺时间后必有明确产物': Boolean(state.solve.legs?.length || state.solve.verdicts?.length),
166
- '2_产物通过自检清单': state.solve.feasible
167
- ? (state.solve.legs?.every(l => l['energy_pct'] !== undefined) ?? false)
168
- : Boolean(state.solve.unsat_core?.length),
169
+ '2_产物通过自检清单': solverFailed
170
+ ? false
171
+ : state.solve.feasible
172
+ ? (state.solve.legs?.every(l => l['energy_pct'] !== undefined) ?? false)
173
+ : Boolean(state.solve.unsat_core?.length),
169
174
  '3_待决问题全部是简单选择题': state.gates.every(g => g.id === 'budget' || g.options.length >= 2),
170
- '4_做不到的诚实说': state.solve.feasible || Boolean(state.solve.suggestions?.length),
175
+ '4_做不到的诚实说': solverFailed || state.solve.feasible || Boolean(state.solve.suggestions?.length),
171
176
  });
172
177
  }
173
178
  export function isComplex(state) {
@@ -207,7 +212,13 @@ export function renderSolve(state) {
207
212
  if (!s)
208
213
  return '(无求解结果)';
209
214
  const lines = [];
210
- if (s.feasible) {
215
+ if (s.solver_error) {
216
+ // issue #620:求解器自己失败 ≠ 行程不可行。这里**不**说「不可行」、不列「冲突」,
217
+ // 也不把机器 token(solver_error.code)渲染给用户——它只在日志/证据里。
218
+ lines.push('**这轮没算出结论——求解器自身出错了,不是你的行程不可行**');
219
+ lines.push('- 我不把引擎故障说成「不可行」:这条已记录,修好或换候选形态(枚举)后重算');
220
+ }
221
+ else if (s.feasible) {
211
222
  lines.push(`**方案可行,机票合计 ¥${s.money_cny}**`);
212
223
  // §7-1 issue #559 卡点 4:从 s.skeleton_notes 字符串编码里推断 unscaffolded 的 seg.id,
213
224
  // 不动 unified.ts/journey.ts(内核冻结面 #234),用户面给 ⚠ 前缀与「枢纽对未在骨架覆盖」补充。