@yuriai/web 0.2.27-beta.8 → 0.2.27

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 (196) hide show
  1. package/dist/assets/{AgentAvatar-BJ42lGZD.js → AgentAvatar-DNm_jMna.js} +1 -1
  2. package/dist/assets/AssistantContactStatus-BPRpgMFh.js +3 -0
  3. package/dist/assets/{AssistantUnreadBadge-QwhBfXpC.js → AssistantUnreadBadge-BssH-RvV.js} +1 -1
  4. package/dist/assets/{AssistantView-D7ryIKL0.js → AssistantView-CxQv-9Ms.js} +1 -1
  5. package/dist/assets/{DiagramView-ERrGEBDp.js → DiagramView-DPpG0fwx.js} +1 -1
  6. package/dist/assets/{FadeInOnReveal-Bu2GvaM9.js → FadeInOnReveal-S6UbimjB.js} +1 -1
  7. package/dist/assets/{GuiPluginSurface-MzQgEZNr.js → GuiPluginSurface-BOf0JA1T.js} +1 -1
  8. package/dist/assets/{GuiPluginWindow-DZMmlQzx.js → GuiPluginWindow-OrYkfQ4m.js} +1 -1
  9. package/dist/assets/{Icon-Dj4CCqCP.js → Icon-BE4mEwzV.js} +1 -1
  10. package/dist/assets/{ImageLoadingPlaceholder-BnFXgUuO.js → ImageLoadingPlaceholder-CBFJC_KD.js} +1 -1
  11. package/dist/assets/{LoadingImage-PBnivDKv.js → LoadingImage-NLq7_P-i.js} +1 -1
  12. package/dist/assets/MarkdownRenderer-BaMotAOQ.js +2 -0
  13. package/dist/assets/{MarkdownRendererImpl-CfyXL4rg.js → MarkdownRendererImpl-Cv6UnGG7.js} +1 -1
  14. package/dist/assets/{MarkstreamRendererImpl-BGadklK1.js → MarkstreamRendererImpl-Rb9O6wkW.js} +1 -1
  15. package/dist/assets/{MobileDetailNavigation-DqajQdB4.js → MobileDetailNavigation-CK4KbkeS.js} +1 -1
  16. package/dist/assets/{MobileResizableSheet-BvdUgwA3.js → MobileResizableSheet-Deidw1br.js} +1 -1
  17. package/dist/assets/{MobileShareBridge-3oPoYnry.js → MobileShareBridge-CO_OWEfq.js} +2 -2
  18. package/dist/assets/MobileTabPageHeader-DbC8L6A4.js +2 -0
  19. package/dist/assets/{MultiRunWindow-yhs0Ih5_.js → MultiRunWindow-DtVW9NTV.js} +1 -1
  20. package/dist/assets/{OnboardingScreen-Bi1VWFQC.js → OnboardingScreen-C8ld4wO7.js} +1 -1
  21. package/dist/assets/{OverlayScrollbar-BBDwGvGO.js → OverlayScrollbar-B3auC2WH.js} +1 -1
  22. package/dist/assets/{SettingsView-BSf-SJUA.js → SettingsView-Cm7woZWl.js} +14 -14
  23. package/dist/assets/{SettingsWindow-BvSXVMTm.js → SettingsWindow-CdL4PFxW.js} +1 -1
  24. package/dist/assets/{TerminalView-DhL01N7e.js → TerminalView-CwRB6Yyr.js} +1 -1
  25. package/dist/assets/{ToolOutputDialog-C8lnH4Ky.js → ToolOutputDialog-B4BfmoVH.js} +1 -1
  26. package/dist/assets/{YuriLogo-D8asj1CS.js → YuriLogo-BOx0s0Ue.js} +1 -1
  27. package/dist/assets/{appThemeRegistry-C-maYSdv.js → appThemeRegistry-B6woJIX5.js} +1 -1
  28. package/dist/assets/{button-vXOdzd8x.js → button-BXxwtxsG.js} +1 -1
  29. package/dist/assets/{capgoAdapter-DJ_h2x5D.js → capgoAdapter-C5HFS-rx.js} +1 -1
  30. package/dist/assets/{collapsible-DwDQs3Wa.js → collapsible-BEm0787p.js} +1 -1
  31. package/dist/assets/{context-menu-BabBujQ-.js → context-menu-DUwvVUDY.js} +1 -1
  32. package/dist/assets/device-BcRP6Tjd.js +2 -0
  33. package/dist/assets/{diagram-HwgrQxY5.js → diagram-DyY8dxjZ.js} +1 -1
  34. package/dist/assets/{dialog-Dnf626tb.js → dialog-CLca6ojn.js} +1 -1
  35. package/dist/assets/{dropdown-menu.styles-CBc_a-Nv.js → dropdown-menu.styles-DGaALKP0.js} +1 -1
  36. package/dist/assets/{es-BQkO-Odr.js → es-CrsHvgue.js} +2 -2
  37. package/dist/assets/fileMentionAutocompleteState-BZJqfgae.js +2 -0
  38. package/dist/assets/{fileMentionTouchSelection-CKPnEetl.js → fileMentionTouchSelection-C4dvP8GY.js} +2 -2
  39. package/dist/assets/{fileReferenceActions-g7KZLi_G.js → fileReferenceActions-CrIAce3K.js} +1 -1
  40. package/dist/assets/{fr-C852roK5.js → fr-CEgiRlfa.js} +2 -2
  41. package/dist/assets/{gitApi-CVq5oKCd.js → gitApi-D2G9ny2O.js} +1 -1
  42. package/dist/assets/{gitApiHttp-BYOIbYIh.js → gitApiHttp-B7vYwgBh.js} +4 -4
  43. package/dist/assets/{gui-M_Rbwkyu.js → gui-CJjEj3l4.js} +1 -1
  44. package/dist/assets/host-CnVx34Dh.js +1 -0
  45. package/dist/assets/{input-BtM712b1.js → input-D59Q2pm8.js} +1 -1
  46. package/dist/assets/insertionBoundaries-CedfTSM5.js +1 -0
  47. package/dist/assets/{ja-BqC39qK6.js → ja-CX-_p9jZ.js} +2 -2
  48. package/dist/assets/{ko-BMaChAWh.js → ko-D5xlLYJM.js} +2 -2
  49. package/dist/assets/main-CxpUooVS.js +2 -0
  50. package/dist/assets/{main-Mey7bCWf.js → main-Dpm4KxWX.js} +12 -12
  51. package/dist/assets/{markdownHeightCache-Bf8iisO4.js → markdownHeightCache-D2VWb_4E.js} +1 -1
  52. package/dist/assets/{mcpQueries-DpXqegX5.js → mcpQueries-DQ3KthDF.js} +1 -1
  53. package/dist/assets/miniChat-CTdj8Ug9.js +2 -0
  54. package/dist/assets/mobile-ChbA3Q8j.js +2 -0
  55. package/dist/assets/{mobileBackNavigation-DZcI7aZg.js → mobileBackNavigation-BJqt3oHk.js} +1 -1
  56. package/dist/assets/{multirun-hzspPepd.js → multirun-BILeETbd.js} +1 -1
  57. package/dist/assets/{native-H7K64Ulc.js → native-BYMhr-xH.js} +1 -1
  58. package/dist/assets/{native-config-CddZtLQ1.js → native-config-BIY0Cr-l.js} +1 -1
  59. package/dist/assets/{persistence-BT8045Ue.js → persistence-CWuLIq1J.js} +2 -2
  60. package/dist/assets/{pl-Ubs8p28T.js → pl-BjH81A_q.js} +2 -2
  61. package/dist/assets/{projectMeta-CEf0QPmD.js → projectMeta-B9_Uh8YH.js} +1 -1
  62. package/dist/assets/{pt-BR-8rAOjJrs.js → pt-BR-Dp5oK2x3.js} +2 -2
  63. package/dist/assets/queue-abort-optimistic-CS5jTJq-.js +1 -0
  64. package/dist/assets/{readiness-Dyr7314z.js → readiness-BNIgH81X.js} +1 -1
  65. package/dist/assets/renderElectronMiniChatApp-asOqV7FB.js +2 -0
  66. package/dist/assets/renderMobileApp-DAfque7-.js +28 -0
  67. package/dist/assets/{runtimeConfig-B8VHHNxj.js → runtimeConfig-BX8JirIc.js} +1 -1
  68. package/dist/assets/runtimeEndpointReset-CFQgUiUr.js +149 -0
  69. package/dist/assets/{scheduledTaskNavigation-Zm87Nydi.js → scheduledTaskNavigation-EomDNVu2.js} +1 -1
  70. package/dist/assets/sessionLookup-BxAaxPOw.js +1 -0
  71. package/dist/assets/{sortable-tabs-strip-D4pVoodN.js → sortable-tabs-strip-DpbW5MqX.js} +1 -1
  72. package/dist/assets/{speechSettingsQueries-RlCLMBtr.js → speechSettingsQueries-CC0fusUo.js} +2 -2
  73. package/dist/assets/src-BMKjN2ip.css +2 -0
  74. package/dist/assets/{store-ME7oHni1.js → store-CkIHVrmT.js} +4 -3
  75. package/dist/assets/{terminalApi-BSaclMDJ.js → terminalApi-rl9mZAlB.js} +1 -1
  76. package/dist/assets/{textarea-B98rsLs7.js → textarea-7eTptEtD.js} +1 -1
  77. package/dist/assets/{tooltip-B9810jbK.js → tooltip-BPwoSTzO.js} +1 -1
  78. package/dist/assets/types-CUtSV1V8.js +2 -0
  79. package/dist/assets/{uk-LzwzUApL.js → uk-BEfkaLtM.js} +2 -2
  80. package/dist/assets/{useAppFontEffects-D2C1sBYM.js → useAppFontEffects-Ck2PdQRx.js} +37 -37
  81. package/dist/assets/{useAssistantUIStore-TUN_ycy5.js → useAssistantUIStore-CfaQV3ID.js} +1 -1
  82. package/dist/assets/useDesktopWindowControlsLayout-DxxOUZj1.js +1 -0
  83. package/dist/assets/useEffectiveDirectory-CNCQfN_x.js +1 -0
  84. package/dist/assets/{useFontPreferences-BlhlCJCX.js → useFontPreferences-DeqW9nRx.js} +1 -1
  85. package/dist/assets/useMobileNavigationStore-BmVr5a5c.js +17 -0
  86. package/dist/assets/{useUIStore-DRx6OgCp.js → useUIStore-C6CE42oh.js} +1 -1
  87. package/dist/assets/{useWorkerHighlightedLines-D093jNsH.js → useWorkerHighlightedLines-CN_RGaSw.js} +1 -1
  88. package/dist/assets/{vendor-effect-DV9F8PTZ.js → vendor-effect-X1Hqc7ba.js} +13 -13
  89. package/dist/assets/vendor-opencode-client-cQ47ywrT.js +23 -0
  90. package/dist/assets/{vendor-opencode-plugin-BBOP6WNx.js → vendor-opencode-plugin-BmdTE4Te.js} +1 -1
  91. package/dist/assets/vendor-opencode-schema-DWT45VBX.js +1 -0
  92. package/dist/assets/vendor-solid-js-D98iXT7C.js +1 -0
  93. package/dist/assets/vendor-zod-DZzbCm1s.js +55 -0
  94. package/dist/assets/{zh-CN-D-FVCeks.js → zh-CN-DipfA56P.js} +2 -2
  95. package/dist/assets/{zh-TW-B9iH_NXL.js → zh-TW-B7pXMVjt.js} +2 -2
  96. package/dist/index.html +12 -12
  97. package/dist/mini-chat.html +12 -12
  98. package/dist/mobile.html +12 -12
  99. package/package.json +1 -1
  100. package/server/index.js +2 -145
  101. package/server/lib/assistants/DOCUMENTATION.md +56 -10
  102. package/server/lib/assistants/cards.js +1 -1
  103. package/server/lib/assistants/channel-image.js +92 -0
  104. package/server/lib/assistants/channel-image.test.js +76 -0
  105. package/server/lib/assistants/channel-output-store.test.js +41 -0
  106. package/server/lib/assistants/channel-output.integration.test.js +114 -0
  107. package/server/lib/assistants/channel-output.js +90 -0
  108. package/server/lib/assistants/channel-output.test.js +79 -0
  109. package/server/lib/assistants/channels/DOCUMENTATION.md +52 -14
  110. package/server/lib/assistants/channels/PROTOCOLS.md +23 -1
  111. package/server/lib/assistants/channels/dingtalk-chat-adapter.js +19 -7
  112. package/server/lib/assistants/channels/dingtalk-chat-adapter.test.js +8 -0
  113. package/server/lib/assistants/channels/routes.js +12 -0
  114. package/server/lib/assistants/channels/routes.test.js +34 -0
  115. package/server/lib/assistants/channels/runtime.js +117 -26
  116. package/server/lib/assistants/channels/runtime.test.js +179 -5
  117. package/server/lib/assistants/channels/sdk-adapters.js +15 -3
  118. package/server/lib/assistants/channels/sdk-adapters.test.js +17 -0
  119. package/server/lib/assistants/channels/store.js +9 -6
  120. package/server/lib/assistants/channels/store.test.js +21 -11
  121. package/server/lib/assistants/channels/transport.js +2 -1
  122. package/server/lib/assistants/channels/wecom-chat-adapter.js +16 -2
  123. package/server/lib/assistants/channels/wecom-chat-adapter.test.js +21 -0
  124. package/server/lib/assistants/contact-store.js +9 -3
  125. package/server/lib/assistants/contact-store.test.js +27 -0
  126. package/server/lib/assistants/contact-tools.js +65 -75
  127. package/server/lib/assistants/contact-tools.test.js +114 -22
  128. package/server/lib/assistants/harness.js +79 -34
  129. package/server/lib/assistants/harness.test.js +52 -20
  130. package/server/lib/assistants/resource-reference.integration.test.js +284 -0
  131. package/server/lib/assistants/routes.js +0 -3
  132. package/server/lib/assistants/service.js +116 -69
  133. package/server/lib/assistants/service.test.js +31 -17
  134. package/server/lib/assistants/weixin/DOCUMENTATION.md +34 -9
  135. package/server/lib/assistants/weixin/api.js +43 -1
  136. package/server/lib/assistants/weixin/api.test.js +28 -0
  137. package/server/lib/assistants/weixin/chat-adapter.js +8 -2
  138. package/server/lib/assistants/weixin/inbound.js +5 -3
  139. package/server/lib/assistants/weixin/inbound.test.js +20 -0
  140. package/server/lib/assistants/weixin/runtime.js +27 -18
  141. package/server/lib/assistants/weixin/runtime.test.js +36 -0
  142. package/server/lib/assistants/weixin/store.js +8 -4
  143. package/server/lib/assistants/weixin/store.test.js +21 -0
  144. package/server/lib/assistants/yuri-project.http.test.js +9 -3
  145. package/server/lib/notifications/DOCUMENTATION.md +6 -0
  146. package/server/lib/notifications/runtime.js +26 -15
  147. package/server/lib/notifications/runtime.test.js +14 -13
  148. package/server/lib/opencode/DOCUMENTATION.md +9 -0
  149. package/server/lib/opencode/auth.d.ts +6 -2
  150. package/server/lib/opencode/core-routes.js +0 -1
  151. package/server/lib/opencode/feature-routes-runtime.js +0 -24
  152. package/server/lib/opencode/location-release.d.ts +5 -1
  153. package/server/lib/opencode/managed-capabilities/scheduled-task.js +1 -1
  154. package/server/lib/opencode/managed-capabilities-runtime.test.js +1 -1
  155. package/server/lib/opencode/native-goal.js +15 -0
  156. package/server/lib/opencode/native-goal.test.js +17 -0
  157. package/server/lib/opencode/settings-helpers.js +0 -6
  158. package/server/lib/opencode/shutdown-runtime.js +0 -2
  159. package/server/lib/projects/project-config.js +3 -6
  160. package/server/lib/scheduled-tasks/DOCUMENTATION.md +10 -35
  161. package/server/lib/scheduled-tasks/managed-tool-route.js +1 -30
  162. package/server/lib/scheduled-tasks/routes.js +0 -26
  163. package/server/lib/scheduled-tasks/runtime.js +33 -257
  164. package/server/lib/scheduled-tasks/runtime.test.js +24 -65
  165. package/server/lib/session-metadata/DOCUMENTATION.md +9 -12
  166. package/server/lib/session-metadata/routes.js +4 -38
  167. package/server/lib/session-metadata/routes.test.js +2 -2
  168. package/dist/assets/AssistantContactStatus-dtkObamV.js +0 -3
  169. package/dist/assets/MarkdownRenderer-BajF4gUU.js +0 -2
  170. package/dist/assets/MobileTabPageHeader-B6cRyIRH.js +0 -2
  171. package/dist/assets/device-BjRYYXNT.js +0 -2
  172. package/dist/assets/host-BW3FEJdU.js +0 -1
  173. package/dist/assets/insertionBoundaries-Dx3WAY6i.js +0 -1
  174. package/dist/assets/main-9uP2z1qT.js +0 -2
  175. package/dist/assets/miniChat-DqZvVkme.js +0 -2
  176. package/dist/assets/mobile-DXAWjYcN.js +0 -2
  177. package/dist/assets/renderElectronMiniChatApp-DoOq8Cuo.js +0 -2
  178. package/dist/assets/renderMobileApp-TTxtOb8b.js +0 -28
  179. package/dist/assets/runtimeEndpointReset-BC6XWntz.js +0 -149
  180. package/dist/assets/sessionLookup-De53jDwM.js +0 -1
  181. package/dist/assets/src-lE4uqaHS.css +0 -2
  182. package/dist/assets/types-DFf9vd1b.js +0 -2
  183. package/dist/assets/useDesktopWindowControlsLayout-BjKaHN0x.js +0 -1
  184. package/dist/assets/useEffectiveDirectory-TEvyiQSC.js +0 -1
  185. package/dist/assets/useMobileNavigationStore-DTvJV9s-.js +0 -23
  186. package/dist/assets/vendor-opencode-client-ZeOZ4Efz.js +0 -23
  187. package/dist/assets/vendor-solid-js-9wmPZH9g.js +0 -1
  188. package/dist/assets/vendor-zod-Dzk5kdUU.js +0 -39
  189. package/server/lib/session-goal/DOCUMENTATION.md +0 -371
  190. package/server/lib/session-goal/capability.js +0 -57
  191. package/server/lib/session-goal/capability.test.js +0 -33
  192. package/server/lib/session-goal/objectives.js +0 -61
  193. package/server/lib/session-goal/routes.js +0 -274
  194. package/server/lib/session-goal/routes.test.js +0 -211
  195. package/server/lib/session-goal/runtime.js +0 -2452
  196. package/server/lib/session-goal/runtime.test.js +0 -2125
@@ -2,11 +2,7 @@ import crypto from 'node:crypto';
2
2
  import { DateTime } from 'luxon';
3
3
  import parser from 'cron-parser';
4
4
  import { makeOpenCodeV2Client } from '../opencode/v2-client.js';
5
- import {
6
- getSessionGoalCapability,
7
- isSessionGoalSupported,
8
- sessionGoalUnavailableMessage,
9
- } from '../session-goal/capability.js';
5
+ import { getNativeSessionGoal } from '../opencode/native-goal.js';
10
6
  import { buildScheduledTaskMetadata } from '../session-metadata/system-session.js';
11
7
  import { SCHEDULED_SLOT_CLAIMED_CODE } from './run-history-store.js';
12
8
  import {
@@ -34,7 +30,7 @@ const SESSION_SETTLEMENT_POLL_MS = 1_000;
34
30
  */
35
31
  const SESSION_SETTLEMENT_MESSAGE_LIMIT = 50;
36
32
  /** Goal terminal statuses — active/paused mean the run is still open. */
37
- const GOAL_TERMINAL_STATUSES = new Set(['complete', 'blocked', 'budgetLimited']);
33
+ const GOAL_TERMINAL_STATUSES = new Set(['complete', 'paused']);
38
34
  /** Assistant finish values that are real terminal success (not tool-calls mid-loop). */
39
35
  const ASSISTANT_SUCCESS_FINISH = new Set(['stop']);
40
36
  /** Assistant finish values that are terminal failure without an error object. */
@@ -375,27 +371,11 @@ const listLatestMessages = async (client, sessionID, requestOptions) => {
375
371
  return Array.isArray(messagesResult?.data) ? messagesResult.data : null;
376
372
  };
377
373
 
378
- const extractGoalFromSession = (session) => {
379
- const metadata = session?.metadata;
380
- if (!metadata || typeof metadata !== 'object') return null;
381
- const namespace = metadata.yuri;
382
- if (!namespace || typeof namespace !== 'object') return null;
383
- const goal = namespace.goal;
384
- if (!goal || typeof goal !== 'object') return null;
385
- const status = typeof goal.status === 'string' ? goal.status.trim() : '';
386
- if (!status) return null;
387
- return {
388
- status,
389
- note: typeof goal.note === 'string' ? goal.note.trim() : '',
390
- };
391
- };
392
374
 
393
375
  /**
394
376
  * Single-shot session outcome for post-run continuation (no polling).
395
- * Goal-enabled + supported: terminal complete → success; blocked/budgetLimited
396
- * → error; otherwise not-yet-success. Goal unsupported: never invent success.
397
- * Prefer Host `readSessionMetadata` over OpenCode `session.get` (direct clients
398
- * do not see the Host store). Store read failure is never empty-goal success.
377
+ * Native Goal: complete → success; paused → error; all other or failed reads
378
+ * stay unknown. Never infer Goal completion from first-turn assistant history.
399
379
  * Non-goal: session.active failure stays unknown; latest-side assistant tail
400
380
  * must be a real terminal (finish tool-calls / incomplete / model-switch ≠
401
381
  * success). History rows are never rewritten here.
@@ -415,7 +395,6 @@ const snapshotSessionOutcome = async ({
415
395
  projectPath,
416
396
  goalEnabled,
417
397
  signal,
418
- readSessionMetadata = null,
419
398
  }) => {
420
399
  const requestOptions = signal ? { signal } : undefined;
421
400
 
@@ -437,11 +416,6 @@ const snapshotSessionOutcome = async ({
437
416
  }
438
417
 
439
418
  if (goalEnabled) {
440
- if (!isSessionGoalSupported()) {
441
- // Host goal state unavailable — do not promote assistant-tail idle to success.
442
- return { outcome: 'busy' };
443
- }
444
-
445
419
  const classifyGoal = (goal) => {
446
420
  if (goal && GOAL_TERMINAL_STATUSES.has(goal.status)) {
447
421
  if (goal.status === 'complete') {
@@ -449,44 +423,18 @@ const snapshotSessionOutcome = async ({
449
423
  }
450
424
  return {
451
425
  outcome: 'error',
452
- error: goal.note || `goal ${goal.status}`,
426
+ error: goal.reason || `goal ${goal.status}`,
453
427
  };
454
428
  }
455
429
  return null;
456
430
  };
457
431
 
458
- // Prefer Host store: OpenCode session.get cannot see yuri.goal.
459
- if (typeof readSessionMetadata === 'function') {
460
- try {
461
- const metadata = await readSessionMetadata(sessionID);
462
- const classified = classifyGoal(extractGoalFromSession({ metadata }));
463
- if (classified) return classified;
464
- } catch (error) {
465
- if (signal?.aborted) throw error;
466
- // Store read failure must not masquerade as empty goal / success.
467
- return { outcome: 'busy' };
468
- }
469
- return { outcome: 'busy' };
470
- }
471
-
472
- if (typeof client?.session?.get === 'function') {
473
- try {
474
- const sessionResult = await client.session.get({
475
- sessionID,
476
- directory: projectPath,
477
- }, requestOptions);
478
- if (!sessionResult?.error) {
479
- const classified = classifyGoal(
480
- extractGoalFromSession(sessionResult?.data ?? sessionResult),
481
- );
482
- if (classified) return classified;
483
- }
484
- } catch (error) {
485
- if (signal?.aborted) throw error;
486
- if (isSessionNotFoundError(error)) {
487
- return { outcome: 'error', error: SESSION_NOT_FOUND_ERROR };
488
- }
489
- }
432
+ try {
433
+ const classified = classifyGoal(await getNativeSessionGoal(client, sessionID, projectPath, signal));
434
+ if (classified) return classified;
435
+ } catch (error) {
436
+ if (signal?.aborted) throw error;
437
+ if (isSessionNotFoundError(error)) return { outcome: 'error', error: SESSION_NOT_FOUND_ERROR };
490
438
  }
491
439
  return { outcome: 'busy' };
492
440
  }
@@ -553,7 +501,6 @@ export const createScheduledTasksRuntime = (deps) => {
553
501
  listProjects,
554
502
  buildOpenCodeUrl,
555
503
  getOpenCodeAuthHeaders,
556
- getSmallModelService,
557
504
  waitForOpenCodeReady,
558
505
  emitTaskRunEvent,
559
506
  notifyTaskRun,
@@ -564,8 +511,6 @@ export const createScheduledTasksRuntime = (deps) => {
564
511
  maxRunDurationMs = DEFAULT_MAX_RUN_MS,
565
512
  /** Create-phase cap. Clamped below 60s. Watchdog abort still wins. */
566
513
  createPhaseDeadlineMs = CREATE_PHASE_DEADLINE_MS,
567
- /** Host store write: (sessionId, directory, goal) => Promise */
568
- persistSessionGoal = null,
569
514
  /** Host store write: (sessionId, patch) => Promise — required for sidebar isolation */
570
515
  persistSessionMetadata = null,
571
516
  /**
@@ -574,15 +519,6 @@ export const createScheduledTasksRuntime = (deps) => {
574
519
  * @type {null | ((event: { sessionID: string, directory?: string, metadata: object }) => void)}
575
520
  */
576
521
  onSystemSessionPersisted = null,
577
- /** Host store read: (sessionId) => Promise<metadata|null> */
578
- readSessionMetadata = null,
579
- /**
580
- * After a scheduled goal is first persisted, arm the session-goal loop.
581
- * (session-goal runtime's own progress writes only broadcast — do not
582
- * feed those back here.)
583
- * @type {null | ((event: { sessionID: string, directory: string, metadata: object }) => void)}
584
- */
585
- onGoalPersisted = null,
586
522
  } = deps;
587
523
 
588
524
  let started = false;
@@ -847,21 +783,6 @@ export const createScheduledTasksRuntime = (deps) => {
847
783
  return projectRunning < maxProjectConcurrency;
848
784
  };
849
785
 
850
- // Same instruction the composer attaches on an armed goal send: the agent
851
- // must know goal mode is on from turn one, and each turn has to end with a
852
- // factual report for the independent audit.
853
- const buildGoalIntroText = (tokenBudget) => {
854
- const budgetLine = tokenBudget
855
- ? ` A token budget of ${tokenBudget} tokens applies to this goal.`
856
- : '';
857
- return '<system-reminder>\n'
858
- + 'Goal mode is active for this session. The user message above defines the goal objective. '
859
- + 'Work toward it across turns; whenever you stop before the objective is verifiably complete, the system will automatically prompt you to continue. '
860
- + 'Progress is evaluated independently after each turn, so end every turn with a clear, factual statement of what is done, what was verified, and what remains.'
861
- + budgetLine
862
- + '\n</system-reminder>';
863
- };
864
-
865
786
  const buildSessionCreateInput = (task, projectPath, title, metadata) => ({
866
787
  title,
867
788
  location: { directory: projectPath },
@@ -886,146 +807,14 @@ export const createScheduledTasksRuntime = (deps) => {
886
807
  }
887
808
  };
888
809
 
889
- const buildPromptText = (task, projectPath) => {
890
- const promptText = task.execution.prompt;
891
- if (!task.execution.goalEnabled) {
892
- return promptText;
893
- }
894
- return `${promptText}\n${buildGoalIntroText(task.execution.goalTokenBudget)}`;
895
- };
896
-
897
- // Scheduled goal runs: write the file-backed objective, then persist a
898
- // trackable goal record into the Host session-metadata store (same seam as
899
- // manual UI goals). OpenCode SessionInfo has no yuri.goal channel.
900
- const createTaskGoal = async ({
901
- sessionID,
902
- projectPath,
903
- task,
904
- signal,
905
- }) => {
906
- signal?.throwIfAborted?.();
907
- if (typeof persistSessionGoal !== 'function') {
908
- throw new Error('session goal persist is not configured');
909
- }
910
- // File-backed objective keyed by session id: the full expanded prompt
911
- // lives under the Yuri data dir. If the file write fails, fall
912
- // back to an inline objective so parseGoalMetadata still accepts the
913
- // record. Oversized prompts are distilled into audit criteria by the
914
- // small model; on distill failure a head+tail excerpt keeps intent.
915
- let objectiveText = task.execution.prompt;
916
- if (objectiveText.length > 5000) {
917
- let distilled = null;
918
- try {
919
- signal?.throwIfAborted?.();
920
- const service = typeof getSmallModelService === 'function'
921
- ? await getSmallModelService()
922
- : null;
923
- signal?.throwIfAborted?.();
924
- if (!service?.generateSmallModelText) {
925
- throw new Error('Small model service is not configured');
926
- }
927
- const generated = await service.generateSmallModelText({
928
- restrictToPreferredProvider: true,
929
- prompt: objectiveText,
930
- system: [
931
- 'You distill a large task description into the COMPLETION CRITERIA a progress auditor will judge against.',
932
- 'Return ONLY the criteria text — no preamble, no headers, no markdown fences.',
933
- 'Capture: the end goals, what must exist and work when the task is fully done, and how each major part is verified. Omit implementation steps.',
934
- 'Preserve verbatim any file paths, commands, and identifiers that define the task.',
935
- 'Stay under 4000 characters.',
936
- 'Write in the same language as the task text.',
937
- ].join('\n'),
938
- directory: projectPath,
939
- preferredProviderID: task.execution.providerID,
940
- preferredModelID: task.execution.modelID,
941
- });
942
- signal?.throwIfAborted?.();
943
- distilled = typeof generated?.text === 'string' ? generated.text.trim() : null;
944
- } catch (error) {
945
- if (signal?.aborted) {
946
- throw error;
947
- }
948
- console.warn('[scheduled-tasks] goal objective distillation failed:', error?.message || error);
949
- }
950
- if (distilled) {
951
- objectiveText = distilled;
952
- } else {
953
- const marker = '\n\n[… objective trimmed for the auditor — the full prompt was delivered in the chat message …]\n\n';
954
- const half = Math.max(0, Math.floor((5000 - marker.length) / 2));
955
- objectiveText = `${objectiveText.slice(0, half)}${marker}${objectiveText.slice(-half)}`;
956
- }
957
- }
958
- signal?.throwIfAborted?.();
959
- let objectiveFile = false;
960
- try {
961
- const { writeObjective } = await import('../session-goal/objectives.js');
962
- await writeObjective(sessionID, objectiveText);
963
- objectiveFile = true;
964
- signal?.throwIfAborted?.();
965
- } catch (error) {
966
- if (signal?.aborted) {
967
- throw error;
968
- }
969
- console.warn('[scheduled-tasks] goal objective file write failed, continuing with inline objective:', error?.message || error);
970
- }
971
- signal?.throwIfAborted?.();
972
-
973
- const budgetRaw = task.execution?.goalTokenBudget;
974
- const tokenBudget = Number.isFinite(budgetRaw) && budgetRaw > 0
975
- ? Math.floor(budgetRaw)
976
- : null;
977
- const now = Date.now();
978
- const goal = {
979
- id: crypto.randomUUID(),
980
- status: 'active',
981
- // File-backed: flag only (text lives under goals/<sessionId>.md).
982
- // Inline fallback: full objective text when the file write failed.
983
- objective: objectiveFile ? '' : objectiveText,
984
- objectiveFile,
985
- tokenBudget,
986
- tokensUsed: 0,
987
- turnsUsed: 0,
988
- blockedStreak: 0,
989
- note: '',
990
- statusReason: '',
991
- lastAccountedMessageID: '',
992
- executionGeneration: 0,
993
- createdAt: now,
994
- updatedAt: now,
995
- };
996
-
997
- // Persist failure must throw — never prompt as if the goal was registered.
998
- const persisted = await persistSessionGoal(sessionID, projectPath, goal);
999
- signal?.throwIfAborted?.();
1000
-
1001
- if (typeof onGoalPersisted === 'function') {
1002
- try {
1003
- // Prefer full metadata when the seam returns the store object; otherwise
1004
- // synthesize the yuri.goal shape the session-goal loop expects.
1005
- const metadata = persisted
1006
- && typeof persisted === 'object'
1007
- && !Array.isArray(persisted)
1008
- && persisted.yuri
1009
- ? persisted
1010
- : { yuri: { goal } };
1011
- onGoalPersisted({
1012
- sessionID,
1013
- directory: projectPath,
1014
- metadata,
1015
- });
1016
- } catch (error) {
1017
- console.warn('[scheduled-tasks] onGoalPersisted failed:', error?.message || error);
1018
- }
1019
- }
1020
- };
1021
-
1022
810
  const runSessionPrompt = async ({ client, sessionID, projectPath, task, signal }) => {
1023
811
  signal?.throwIfAborted?.();
1024
812
  const requestOptions = signal ? { signal } : undefined;
1025
- await client.session.prompt({
1026
- sessionID,
1027
- text: buildPromptText(task, projectPath),
1028
- }, requestOptions);
813
+ if (task.execution.goalEnabled) {
814
+ await client.session.command({ sessionID, name: 'goal', text: task.execution.prompt }, requestOptions);
815
+ } else {
816
+ await client.session.prompt({ sessionID, text: task.execution.prompt }, requestOptions);
817
+ }
1029
818
  };
1030
819
 
1031
820
  /**
@@ -1042,6 +831,8 @@ export const createScheduledTasksRuntime = (deps) => {
1042
831
  client,
1043
832
  sessionID,
1044
833
  signal,
834
+ projectPath,
835
+ goalEnabled,
1045
836
  }) => {
1046
837
  const requestOptions = signal ? { signal } : undefined;
1047
838
  let emptyIdleProbes = 0;
@@ -1070,6 +861,13 @@ export const createScheduledTasksRuntime = (deps) => {
1070
861
  continue;
1071
862
  }
1072
863
 
864
+ if (goalEnabled) {
865
+ const outcome = await snapshotSessionOutcome({ client, sessionID, projectPath, goalEnabled: true, signal });
866
+ if (outcome.outcome !== 'busy') return outcome;
867
+ await sleep(SESSION_SETTLEMENT_POLL_MS, signal);
868
+ continue;
869
+ }
870
+
1073
871
  try {
1074
872
  const messages = await listLatestMessages(client, sessionID, requestOptions);
1075
873
  if (messages) {
@@ -1104,7 +902,7 @@ export const createScheduledTasksRuntime = (deps) => {
1104
902
 
1105
903
  const runScheduledCommandIfApplicable = async ({ client, projectPath, sessionID, task, signal }) => {
1106
904
  signal?.throwIfAborted?.();
1107
- const parsed = parseScheduledCommandPrompt(task?.execution?.prompt);
905
+ const parsed = task.execution.goalEnabled ? null : parseScheduledCommandPrompt(task?.execution?.prompt);
1108
906
  if (!parsed) {
1109
907
  return false;
1110
908
  }
@@ -1168,18 +966,8 @@ export const createScheduledTasksRuntime = (deps) => {
1168
966
 
1169
967
  signal?.throwIfAborted?.();
1170
968
 
1171
- // Goal-enabled tasks: refuse before session create / objective write /
1172
- // prompt when Host goal state is unavailable OR persist is not wired.
1173
- // Config + run-history stay; only this run is recorded as error (no
1174
- // false first-turn success / no create·distill·prompt side effects).
1175
- if (task.execution?.goalEnabled) {
1176
- const capability = getSessionGoalCapability();
1177
- if (!capability.supported) {
1178
- throw new Error(sessionGoalUnavailableMessage(capability));
1179
- }
1180
- if (typeof persistSessionGoal !== 'function') {
1181
- throw new Error('session goal persist is not configured');
1182
- }
969
+ if (task.execution?.goalEnabled && (task.execution.prompt.length > 4000 || ['pause', 'resume', 'clear'].includes(task.execution.prompt.trim().toLowerCase()))) {
970
+ throw new Error('Invalid native goal objective: use 1–4000 characters, not a goal control word');
1183
971
  }
1184
972
 
1185
973
  if (typeof persistSessionMetadata !== 'function') {
@@ -1279,15 +1067,6 @@ export const createScheduledTasksRuntime = (deps) => {
1279
1067
  } catch {
1280
1068
  }
1281
1069
 
1282
- if (task.execution.goalEnabled) {
1283
- await createTaskGoal({
1284
- sessionID,
1285
- projectPath,
1286
- task,
1287
- signal,
1288
- });
1289
- }
1290
-
1291
1070
  signal?.throwIfAborted?.();
1292
1071
 
1293
1072
  executionErrorsBySession.set(sessionID, null);
@@ -1314,6 +1093,8 @@ export const createScheduledTasksRuntime = (deps) => {
1314
1093
  client,
1315
1094
  sessionID,
1316
1095
  signal,
1096
+ projectPath,
1097
+ goalEnabled: task.execution.goalEnabled || /^\/goal\b/i.test(task.execution.prompt.trim()),
1317
1098
  });
1318
1099
 
1319
1100
  const finishedAt = Date.now();
@@ -1530,7 +1311,7 @@ export const createScheduledTasksRuntime = (deps) => {
1530
1311
  ]);
1531
1312
 
1532
1313
  if (raced.timedOut) {
1533
- // Bound: do not await uncancellable steps (distill / writeObjective).
1314
+ // Bound: do not await uncancellable steps after the deadline.
1534
1315
  // session.interrupt is started by the signal listener on create;
1535
1316
  // later throwIfAborted gates stop goal write / command / prompt.
1536
1317
  throw timeoutError;
@@ -1806,7 +1587,6 @@ export const createScheduledTasksRuntime = (deps) => {
1806
1587
  sessionID,
1807
1588
  projectPath: projectPathByID.get(projectID),
1808
1589
  goalEnabled: Boolean(task.execution?.goalEnabled),
1809
- readSessionMetadata,
1810
1590
  signal,
1811
1591
  });
1812
1592
  if (signal.aborted || runningTaskKeys.has(taskKey) || tasksByProject.get(projectID)?.get(taskID) !== task) continue;
@@ -1849,15 +1629,12 @@ export const createScheduledTasksRuntime = (deps) => {
1849
1629
  if (!run.sessionId || runningTaskKeys.has(buildTaskKey(run.projectId, run.taskId))) continue;
1850
1630
  try {
1851
1631
  if (typeof client?.session?.active !== 'function') continue;
1852
- const metadata = typeof readSessionMetadata === 'function'
1853
- ? await readSessionMetadata(run.sessionId)
1854
- : null;
1632
+ const goal = await getNativeSessionGoal(client, run.sessionId, run.directory, signal);
1855
1633
  const snapshot = await snapshotSessionOutcome({
1856
1634
  client,
1857
1635
  sessionID: run.sessionId,
1858
1636
  projectPath: run.directory,
1859
- goalEnabled: Boolean(extractGoalFromSession({ metadata })),
1860
- readSessionMetadata: typeof readSessionMetadata === 'function' ? async () => metadata : null,
1637
+ goalEnabled: Boolean(goal),
1861
1638
  signal,
1862
1639
  });
1863
1640
  if (signal.aborted || runningTaskKeys.has(buildTaskKey(run.projectId, run.taskId))) continue;
@@ -2019,7 +1796,6 @@ export const createScheduledTasksRuntime = (deps) => {
2019
1796
  sessionID,
2020
1797
  projectPath,
2021
1798
  goalEnabled: Boolean(task.execution?.goalEnabled),
2022
- readSessionMetadata,
2023
1799
  });
2024
1800
  if (snapshot.outcome !== 'success' && snapshot.outcome !== 'error') {
2025
1801
  return;
@@ -12,12 +12,13 @@ vi.mock('../opencode/v2-client.js', () => ({
12
12
  makeOpenCodeV2Client: vi.fn(),
13
13
  }));
14
14
 
15
- vi.mock('../session-goal/objectives.js', () => ({
16
- writeObjective: vi.fn(async () => ({ content: 'ok' })),
15
+ vi.mock('../opencode/native-goal.js', () => ({
16
+ getNativeSessionGoal: vi.fn(async () => null),
17
17
  }));
18
18
 
19
19
  const { makeOpenCodeV2Client } = await import('../opencode/v2-client.js');
20
- const { writeObjective } = await import('../session-goal/objectives.js');
20
+ const { getNativeSessionGoal } = await import('../opencode/native-goal.js');
21
+ beforeEach(() => { getNativeSessionGoal.mockReset().mockResolvedValue(null); });
21
22
  const { createScheduledTaskRunHistoryStore } = await import('./run-history-store.js');
22
23
  const {
23
24
  computeNextRunAt,
@@ -332,8 +333,8 @@ describe('scheduled-tasks history recovery', () => {
332
333
  };
333
334
  const runtime = createRuntime(vi.fn(async () => ({ task: null })), {
334
335
  runHistoryStore: store,
335
- readSessionMetadata: vi.fn(async () => ({ yuri: { goal: { status: goalStatus } } })),
336
336
  });
337
+ getNativeSessionGoal.mockImplementation(async () => ({ status: goalStatus }));
337
338
  try {
338
339
  await runtime.start();
339
340
  await vi.advanceTimersByTimeAsync(0);
@@ -770,7 +771,6 @@ describe('scheduled-tasks run history and session lifecycle', () => {
770
771
  beforeEach(() => {
771
772
  vi.restoreAllMocks();
772
773
  makeOpenCodeV2Client.mockReset();
773
- writeObjective.mockClear();
774
774
  });
775
775
 
776
776
  const createHistoryStore = () => {
@@ -1308,7 +1308,7 @@ describe('scheduled-tasks run history and session lifecycle', () => {
1308
1308
  vi.useRealTimers();
1309
1309
  });
1310
1310
 
1311
- it('goalEnabled without persist refuses before OpenCode ready / distill / session create (no side effects)', async () => {
1311
+ it('oversized native goals refuse before OpenCode ready or session create, without distillation', async () => {
1312
1312
  const history = createHistoryStore();
1313
1313
  const create = vi.fn(async () => ({ id: 'ses_distill' }));
1314
1314
  const interrupt = vi.fn(async () => undefined);
@@ -1332,7 +1332,6 @@ describe('scheduled-tasks run history and session lifecycle', () => {
1332
1332
  ...scheduledTask.execution,
1333
1333
  prompt: largePrompt,
1334
1334
  goalEnabled: true,
1335
- goalTokenBudget: 12_000,
1336
1335
  },
1337
1336
  };
1338
1337
  const updateScheduledTaskState = vi.fn(async (_projectID, _taskID, state) => ({
@@ -1351,32 +1350,31 @@ describe('scheduled-tasks run history and session lifecycle', () => {
1351
1350
  waitForOpenCodeReady,
1352
1351
  logger: { info: vi.fn(), warn: vi.fn() },
1353
1352
  runHistoryStore: history,
1354
- // intentionally no persistSessionGoal
1355
1353
  });
1356
1354
  await runtime.syncProject('project-1');
1357
1355
  const result = await runtime.runNow('project-1', 'task-1');
1358
1356
 
1359
1357
  expect(result.ok).toBe(false);
1360
- expect(result.error).toMatch(/session goal persist is not configured/);
1358
+ expect(result.error).toMatch(/4000/);
1361
1359
  expect(waitForOpenCodeReady).not.toHaveBeenCalled();
1362
1360
  expect(getSmallModelService).not.toHaveBeenCalled();
1363
1361
  expect(generateSmallModelText).not.toHaveBeenCalled();
1364
1362
  expect(create).not.toHaveBeenCalled();
1365
1363
  expect(prompt).not.toHaveBeenCalled();
1366
- expect(writeObjective).not.toHaveBeenCalled();
1367
1364
  expect(history.attachSession).not.toHaveBeenCalled();
1368
1365
  expect(history.finishRun).toHaveBeenCalledWith(
1369
1366
  expect.any(String),
1370
1367
  expect.objectContaining({
1371
1368
  status: 'error',
1372
- error: expect.stringMatching(/session goal persist is not configured/),
1369
+ error: expect.stringMatching(/4000/),
1373
1370
  }),
1374
1371
  );
1375
1372
  });
1376
1373
 
1377
- it('goalEnabled without persist refuses before session create / objective write', async () => {
1374
+ it('native goal command failure does not send a normal prompt or report success', async () => {
1378
1375
  const history = createHistoryStore();
1379
1376
  const client = createSuccessfulClient({ sessionID: 'ses_goal' });
1377
+ client.command.mockRejectedValue(new Error('Native goal unavailable'));
1380
1378
 
1381
1379
  const goalTask = {
1382
1380
  ...scheduledTask,
@@ -1384,7 +1382,6 @@ describe('scheduled-tasks run history and session lifecycle', () => {
1384
1382
  ...scheduledTask.execution,
1385
1383
  prompt: 'finish the migration',
1386
1384
  goalEnabled: true,
1387
- goalTokenBudget: 12_000,
1388
1385
  },
1389
1386
  };
1390
1387
  const updateScheduledTaskState = vi.fn(async (_projectID, _taskID, state) => ({
@@ -1400,40 +1397,35 @@ describe('scheduled-tasks run history and session lifecycle', () => {
1400
1397
  buildOpenCodeUrl: vi.fn(() => 'http://127.0.0.1:4096'),
1401
1398
  getOpenCodeAuthHeaders: vi.fn(() => ({})),
1402
1399
  waitForOpenCodeReady: vi.fn(async () => {}),
1400
+ persistSessionMetadata: vi.fn(async () => ({})),
1403
1401
  logger: { info: vi.fn(), warn: vi.fn() },
1404
1402
  runHistoryStore: history,
1405
- // intentionally no persistSessionGoal
1406
1403
  });
1407
1404
  await runtime.syncProject('project-1');
1408
1405
  const result = await runtime.runNow('project-1', 'task-1');
1409
1406
 
1410
- // Missing persist is an explicit run failure before any side effects.
1411
1407
  expect(result.ok).toBe(false);
1412
1408
  expect(result.status).toBe('error');
1413
- expect(result.error).toMatch(/session goal persist is not configured/);
1414
- expect(client.create).not.toHaveBeenCalled();
1409
+ expect(result.error).toMatch(/Native goal unavailable/);
1410
+ expect(client.create).toHaveBeenCalled();
1415
1411
  expect(client.prompt).not.toHaveBeenCalled();
1416
- expect(writeObjective).not.toHaveBeenCalled();
1417
1412
  expect(history.finishRun).toHaveBeenCalledWith(
1418
1413
  expect.any(String),
1419
1414
  expect.objectContaining({
1420
1415
  status: 'error',
1421
- error: expect.stringMatching(/session goal persist is not configured/),
1416
+ error: expect.stringMatching(/Native goal unavailable/),
1422
1417
  }),
1423
1418
  );
1424
1419
  // Task config is preserved (goalEnabled stays on the task); only this run fails.
1425
1420
  const finalPatch = updateScheduledTaskState.mock.calls.at(-1)[2];
1426
1421
  expect(finalPatch.lastStatus).toBe('error');
1427
- expect(Object.hasOwn(finalPatch, 'lastSessionId')).toBe(false);
1422
+ expect(history.attachSession).toHaveBeenCalledWith(expect.any(String), 'ses_goal');
1428
1423
  });
1429
1424
 
1430
- it('goalEnabled with persist writes objective + active goal then prompts', async () => {
1425
+ it('goalEnabled executes the native command and settles only from native goal state', async () => {
1431
1426
  const history = createHistoryStore();
1432
1427
  const client = createSuccessfulClient({ sessionID: 'ses_goal_ok' });
1433
- const persistSessionGoal = vi.fn(async (_sessionId, _directory, goal) => ({
1434
- yuri: { goal },
1435
- }));
1436
- const onGoalPersisted = vi.fn();
1428
+ getNativeSessionGoal.mockResolvedValue({ status: 'complete' });
1437
1429
 
1438
1430
  const goalTask = {
1439
1431
  ...scheduledTask,
@@ -1441,7 +1433,6 @@ describe('scheduled-tasks run history and session lifecycle', () => {
1441
1433
  ...scheduledTask.execution,
1442
1434
  prompt: 'finish the migration',
1443
1435
  goalEnabled: true,
1444
- goalTokenBudget: 12_000,
1445
1436
  },
1446
1437
  };
1447
1438
  const updateScheduledTaskState = vi.fn(async (_projectID, _taskID, state) => ({
@@ -1460,50 +1451,22 @@ describe('scheduled-tasks run history and session lifecycle', () => {
1460
1451
  persistSessionMetadata: vi.fn(async () => ({})),
1461
1452
  logger: { info: vi.fn(), warn: vi.fn() },
1462
1453
  runHistoryStore: history,
1463
- persistSessionGoal,
1464
- onGoalPersisted,
1465
1454
  });
1466
1455
  await runtime.syncProject('project-1');
1467
1456
  const result = await runtime.runNow('project-1', 'task-1');
1468
1457
 
1469
1458
  expect(result.ok).toBe(true);
1470
1459
  expect(client.create).toHaveBeenCalled();
1471
- expect(writeObjective).toHaveBeenCalledWith('ses_goal_ok', 'finish the migration');
1472
- expect(persistSessionGoal).toHaveBeenCalledTimes(1);
1473
- expect(persistSessionGoal.mock.calls[0][0]).toBe('ses_goal_ok');
1474
- expect(persistSessionGoal.mock.calls[0][1]).toBe('/tmp/project-1');
1475
- expect(persistSessionGoal.mock.calls[0][2]).toMatchObject({
1476
- status: 'active',
1477
- objectiveFile: true,
1478
- objective: '',
1479
- tokenBudget: 12_000,
1480
- tokensUsed: 0,
1481
- turnsUsed: 0,
1482
- blockedStreak: 0,
1483
- note: '',
1484
- statusReason: '',
1485
- lastAccountedMessageID: '',
1486
- });
1487
- expect(typeof persistSessionGoal.mock.calls[0][2].id).toBe('string');
1488
- expect(persistSessionGoal.mock.calls[0][2].id.length).toBeGreaterThan(0);
1489
- expect(onGoalPersisted).toHaveBeenCalledWith(expect.objectContaining({
1490
- sessionID: 'ses_goal_ok',
1491
- directory: '/tmp/project-1',
1492
- metadata: expect.objectContaining({
1493
- yuri: expect.objectContaining({
1494
- goal: expect.objectContaining({ status: 'active' }),
1495
- }),
1496
- }),
1497
- }));
1498
- expect(client.prompt).toHaveBeenCalled();
1460
+ expect(client.command).toHaveBeenCalledWith({ sessionID: 'ses_goal_ok', name: 'goal', text: 'finish the migration' }, expect.objectContaining({ signal: expect.any(AbortSignal) }));
1461
+ expect(getNativeSessionGoal).toHaveBeenCalled();
1462
+ expect(client.prompt).not.toHaveBeenCalled();
1463
+ expect(client.messageList).not.toHaveBeenCalled();
1499
1464
  });
1500
1465
 
1501
- it('goalEnabled persist failure aborts before prompt', async () => {
1466
+ it('native paused goal is a failed run, never first-turn success', async () => {
1502
1467
  const history = createHistoryStore();
1503
1468
  const client = createSuccessfulClient({ sessionID: 'ses_goal_fail' });
1504
- const persistSessionGoal = vi.fn(async () => {
1505
- throw new Error('store unavailable');
1506
- });
1469
+ getNativeSessionGoal.mockResolvedValue({ status: 'paused', reason: 'Not making progress' });
1507
1470
 
1508
1471
  const goalTask = {
1509
1472
  ...scheduledTask,
@@ -1529,15 +1492,12 @@ describe('scheduled-tasks run history and session lifecycle', () => {
1529
1492
  persistSessionMetadata: vi.fn(async () => ({})),
1530
1493
  logger: { info: vi.fn(), warn: vi.fn() },
1531
1494
  runHistoryStore: history,
1532
- persistSessionGoal,
1533
1495
  });
1534
1496
  await runtime.syncProject('project-1');
1535
1497
  const result = await runtime.runNow('project-1', 'task-1');
1536
1498
 
1537
1499
  expect(result.ok).toBe(false);
1538
- expect(result.error).toMatch(/store unavailable/);
1539
- expect(writeObjective).toHaveBeenCalled();
1540
- expect(persistSessionGoal).toHaveBeenCalled();
1500
+ expect(result.error).toMatch(/Not making progress/);
1541
1501
  expect(client.prompt).not.toHaveBeenCalled();
1542
1502
  });
1543
1503
 
@@ -1720,7 +1680,6 @@ describe('scheduled-tasks run history and session lifecycle', () => {
1720
1680
  expect(result.ok).toBe(true);
1721
1681
  expect(client.create).toHaveBeenCalled();
1722
1682
  expect(client.prompt).toHaveBeenCalled();
1723
- expect(writeObjective).not.toHaveBeenCalled();
1724
1683
  });
1725
1684
 
1726
1685
  it('settles from the latest-side page: >50 older completed + newest error → error', async () => {