@openchamber/web 2.0.2 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/lib/DOCUMENTATION.md +1 -1
- package/bin/lib/commands-connect-url.js +6 -5
- package/bin/lib/commands-tunnel.js +24 -5
- package/dist/assets/{CodeMirrorCommentWidgets-CmKmyb9T.js → CodeMirrorCommentWidgets-C_zL-eri.js} +1 -1
- package/dist/assets/{DiffView-8-PFpZ2p.js → DiffView-BeN2_YYF.js} +3 -3
- package/dist/assets/FilesView-CN34wm_N.js +17 -0
- package/dist/assets/{GitView-DNUSu00w.js → GitView-DLDazOo1.js} +4 -4
- package/dist/assets/{GuestAttachDialog-Cv6QzjHC.js → GuestAttachDialog-C0xe_Lyy.js} +1 -1
- package/dist/assets/{GuestSurfacePane-Bt3jB_Ye.js → GuestSurfacePane-BdaurnDr.js} +1 -1
- package/dist/assets/{JsonTreeView-BlyHTRhM.js → JsonTreeView-B1Xq-k2t.js} +1 -1
- package/dist/assets/LinearIssuesView-BryoAHow.js +1 -0
- package/dist/assets/{MarkdownImageGallery-2UXJF-5B.js → MarkdownImageGallery-DfuEoaGq.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-B_ZcWOvX.js +12 -0
- package/dist/assets/OnboardingScreen-C22bGmnP.js +1 -0
- package/dist/assets/{PatchDiff-ByvnbG5T.js → PatchDiff-0xd6UeFB.js} +1 -1
- package/dist/assets/{PierreDiffViewer-BXieg0mH.js → PierreDiffViewer-BC950e3F.js} +3 -3
- package/dist/assets/PlanView-B7Xgihqk.js +5 -0
- package/dist/assets/PluginPane-2C71F8uF.js +3 -0
- package/dist/assets/SettingsView-m_zoFiaT.js +30 -0
- package/dist/assets/{SettingsWindow-BIz224xs.js → SettingsWindow-CofS020b.js} +1 -1
- package/dist/assets/{SubmoduleDiffSummary-CXKmlps9.js → SubmoduleDiffSummary-BSA9gnIO.js} +1 -1
- package/dist/assets/{ToolOutputDialog-BsgAK8xu.js → ToolOutputDialog-DprkVKcj.js} +7 -7
- package/dist/assets/{ToolPartDiffPreview-vdPObXOf.js → ToolPartDiffPreview-Dq0go_fX.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-BkFNKWS5.js → VirtualizedFileDiff-Kp8hKJdT.js} +1 -1
- package/dist/assets/WalkthroughView-DGnTzqIU.js +4 -0
- package/dist/assets/{appThemeRegistry-aHUNHoqP.js → appThemeRegistry-BdEHBA4s.js} +1 -1
- package/dist/assets/{commitAndPush-Bon9r94r.js → commitAndPush-LwtVa2Oc.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-DKqr_1AQ.js → computeVirtualFileMetrics-6V1xNpO9.js} +2 -2
- package/dist/assets/de-DlgBHUAI.js +10 -0
- package/dist/assets/es-BC8G41U8.js +16 -0
- package/dist/assets/fr-I0z3vVjy.js +14 -0
- package/dist/assets/index-CgR5rJq_.js +41 -0
- package/dist/assets/{index-DpFttslC.js → index-CmNPYddV.js} +1 -1
- package/dist/assets/index-adyy_sEk.css +1 -0
- package/dist/assets/{isDiffPlainText-kzAgpIgi.js → isDiffPlainText-1bXcWCrw.js} +1 -1
- package/dist/assets/{isFilePlainText-Uj6y-jzz.js → isFilePlainText-CBAppvy1.js} +1 -1
- package/dist/assets/ja-BIElEsY8.js +16 -0
- package/dist/assets/ko-DRnnHetA.js +16 -0
- package/dist/assets/{main-CbfMxn-I.js → main-CzjTMTfW.js} +2 -2
- package/dist/assets/main-DVX34beR.js +886 -0
- package/dist/assets/markdownCore-Cxbkn5NR.js +7 -0
- package/dist/assets/{miniChat-CiAKBC10.js → miniChat-CP68IL8Q.js} +2 -2
- package/dist/assets/{mobile-CsT4sJwC.js → mobile-BrlBrNfZ.js} +2 -2
- package/dist/assets/nl-DzUV-kwp.js +16 -0
- package/dist/assets/{patchFileDiff-DeaE08W0.js → patchFileDiff-pqRSHLHI.js} +2 -2
- package/dist/assets/pl-Bb-cb7k7.js +16 -0
- package/dist/assets/pt-BR-CyIWrTcE.js +16 -0
- package/dist/assets/renderElectronMiniChatApp-DKIilR7N.js +2 -0
- package/dist/assets/renderMobileApp-B0z6-x58.js +25 -0
- package/dist/assets/runtimeEndpointReset-uu1DBwLL.js +52 -0
- package/dist/assets/{scheduledTasksApi-BZCNJ588.js → scheduledTasksApi-BuzWT445.js} +1 -1
- package/dist/assets/{shikiHighlight-BSUEa3yF.js → shikiHighlight-BWGrY5YU.js} +1 -1
- package/dist/assets/{textMateThemeFromAppTheme-CsATFZIV.js → textMateThemeFromAppTheme-BSUFChBY.js} +1 -1
- package/dist/assets/tr-DXEDSoYO.js +7 -0
- package/dist/assets/uk-C8hN--q_.js +16 -0
- package/dist/assets/useAppFontEffects-Dsl_sLrj.js +7366 -0
- package/dist/assets/useInlineCommentController-d5vntsQ_.js +2 -0
- package/dist/assets/{useRootScrollLock-Cp1eFoM2.js → useRootScrollLock-2rd5Y6gR.js} +2 -2
- package/dist/assets/{vendor-base-ui-CsXYnR5c.js → vendor-base-ui-DnNniUWp.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-BwwommM0.js → vendor-codemirror-language-data-B1EetJur.js} +2 -2
- package/dist/assets/vendor-opencode-client-DSZl7jSi.js +12 -0
- package/dist/assets/{vendor-tanstack-react-virtual-ClYN8CzB.js → vendor-tanstack-react-virtual--0sBrLRh.js} +1 -1
- package/dist/assets/{vendor-tanstack-virtual-core-BewVQryB.js → vendor-tanstack-virtual-core-BoA4iGMw.js} +1 -1
- package/dist/assets/{vendor-zod-BSoePkpP.js → vendor-zod-CxRSdNoV.js} +4 -4
- package/dist/assets/{web-components-D3Yjr4Zx.js → web-components-ngpHPEDU.js} +1 -1
- package/dist/assets/zh-CN-CtzXdjMZ.js +16 -0
- package/dist/assets/zh-TW-Ds0CADSz.js +16 -0
- package/dist/index.html +5 -5
- package/dist/mini-chat.html +5 -5
- package/dist/mobile.html +5 -5
- package/package.json +5 -5
- package/server/index.js +82 -4
- package/server/lib/agent-tool/DOCUMENTATION.md +8 -1
- package/server/lib/agent-tool/runtime.js +13 -4
- package/server/lib/agent-tool/runtime.test.js +15 -0
- package/server/lib/context-obligatory/DOCUMENTATION.md +10 -7
- package/server/lib/context-obligatory/runtime.js +2 -1
- package/server/lib/context-obligatory/runtime.test.js +76 -30
- package/server/lib/dictation/DOCUMENTATION.md +4 -1
- package/server/lib/dictation/openai-compatible-session.js +7 -0
- package/server/lib/enterprise-mode.d.ts +30 -0
- package/server/lib/enterprise-mode.js +253 -0
- package/server/lib/enterprise-mode.test.js +247 -0
- package/server/lib/event-stream/translate-v2.js +6 -0
- package/server/lib/event-stream/translate-v2.test.js +6 -0
- package/server/lib/git/DOCUMENTATION.md +2 -1
- package/server/lib/git/routes.js +44 -1
- package/server/lib/git/routes.test.js +98 -1
- package/server/lib/git/service.js +146 -11
- package/server/lib/git/service.test.js +195 -0
- package/server/lib/github/routes.js +9 -19
- package/server/lib/github/routes.test.js +112 -0
- package/server/lib/guests/DOCUMENTATION.md +4 -2
- package/server/lib/guests/background.test.js +1 -1
- package/server/lib/guests/catalog.js +56 -2
- package/server/lib/guests/catalog.test.js +24 -1
- package/server/lib/guests/clone-network.test.js +52 -0
- package/server/lib/guests/clone.js +30 -4
- package/server/lib/guests/enterprise.js +68 -0
- package/server/lib/guests/enterprise.test.js +106 -0
- package/server/lib/guests/grant-scope.js +8 -2
- package/server/lib/guests/grant-scope.test.js +9 -0
- package/server/lib/guests/html-styles.js +16 -2
- package/server/lib/guests/html-styles.test.js +53 -4
- package/server/lib/guests/install.js +10 -0
- package/server/lib/guests/persist.js +1 -0
- package/server/lib/guests/routes.js +40 -5
- package/server/lib/guests/updates.js +9 -2
- package/server/lib/notifications/DOCUMENTATION.md +1 -1
- package/server/lib/notifications/runtime.js +22 -8
- package/server/lib/notifications/trigger-runtime.test.js +45 -0
- package/server/lib/openchamber-sessions/session-metadata-store.js +27 -0
- package/server/lib/openchamber-sessions/session-metadata-store.test.js +18 -0
- package/server/lib/opencode/DOCUMENTATION.md +13 -9
- package/server/lib/opencode/auth-state-runtime.js +2 -2
- package/server/lib/opencode/config-paths.test.js +1 -0
- package/server/lib/opencode/env-runtime.js +26 -3
- package/server/lib/opencode/env-runtime.test.js +57 -0
- package/server/lib/opencode/feature-routes-runtime.js +2 -0
- package/server/lib/opencode/hmr-state-runtime.js +4 -3
- package/server/lib/opencode/lifecycle.js +10 -5
- package/server/lib/opencode/lifecycle.test.js +6 -2
- package/server/lib/opencode/managed-config-file.js +2 -1
- package/server/lib/opencode/managed-config-file.test.js +18 -0
- package/server/lib/opencode/npm-registry-config.d.ts +1 -0
- package/server/lib/opencode/npm-registry-config.js +123 -0
- package/server/lib/opencode/npm-registry-config.test.js +167 -0
- package/server/lib/opencode/npm-registry.js +5 -6
- package/server/lib/opencode/npm-registry.test.js +30 -0
- package/server/lib/opencode/openchamber-routes.js +8 -0
- package/server/lib/opencode/project-icon-routes.js +2 -2
- package/server/lib/opencode/project-icon-routes.test.js +44 -0
- package/server/lib/opencode/provider-source-route.test.js +32 -0
- package/server/lib/opencode/routes.js +17 -2
- package/server/lib/opencode/settings-helpers.js +26 -3
- package/server/lib/opencode/settings-helpers.test.js +12 -5
- package/server/lib/opencode/settings-registry.json +35 -1
- package/server/lib/opencode/settings-runtime.js +1 -0
- package/server/lib/opencode/shutdown-runtime.js +2 -0
- package/server/lib/opencode/static-routes-runtime.js +9 -1
- package/server/lib/opencode/static-routes-runtime.test.js +58 -1
- package/server/lib/package-manager.js +4 -1
- package/server/lib/package-manager.test.js +24 -0
- package/server/lib/permission-auto-accept/DOCUMENTATION.md +23 -15
- package/server/lib/permission-auto-accept/modes.js +26 -0
- package/server/lib/permission-auto-accept/runtime.js +146 -40
- package/server/lib/permission-auto-accept/runtime.test.js +93 -9
- package/server/lib/quota/DOCUMENTATION.md +6 -0
- package/server/lib/quota/providers/zhipuai-coding-plan.js +74 -30
- package/server/lib/quota/providers/zhipuai-coding-plan.test.js +124 -0
- package/server/lib/relay/DOCUMENTATION.md +1 -1
- package/server/lib/relay/service.js +32 -12
- package/server/lib/relay/service.test.js +30 -0
- package/server/lib/routing/DOCUMENTATION.md +150 -41
- package/server/lib/routing/classifier.js +156 -0
- package/server/lib/routing/defaults.js +27 -0
- package/server/lib/routing/jev.js +5 -17
- package/server/lib/routing/routes.http.test.js +9 -0
- package/server/lib/routing/routes.js +27 -1
- package/server/lib/routing/runtime.js +199 -33
- package/server/lib/routing/runtime.test.js +299 -15
- package/server/lib/routing/store.js +57 -0
- package/server/lib/routing/store.test.js +37 -0
- package/server/lib/session-assist/DOCUMENTATION.md +17 -7
- package/server/lib/session-assist/context.js +42 -2
- package/server/lib/session-assist/context.test.js +38 -1
- package/server/lib/session-assist/runtime.js +57 -13
- package/server/lib/session-assist/runtime.test.js +45 -0
- package/server/lib/session-goal/DOCUMENTATION.md +47 -22
- package/server/lib/session-goal/audit.js +112 -0
- package/server/lib/session-goal/audit.test.js +58 -0
- package/server/lib/session-goal/runtime.js +113 -134
- package/server/lib/session-goal/runtime.test.js +146 -13
- package/server/lib/session-lineage.js +52 -0
- package/server/lib/session-lineage.test.js +45 -0
- package/server/lib/session-work/DOCUMENTATION.md +108 -0
- package/server/lib/session-work/questions.js +126 -0
- package/server/lib/session-work/runtime.js +278 -0
- package/server/lib/session-work/runtime.test.js +255 -0
- package/server/lib/session-work/state.js +48 -0
- package/server/lib/session-work/state.test.js +34 -0
- package/server/lib/small-model/DOCUMENTATION.md +14 -7
- package/server/lib/small-model/client.js +7 -4
- package/server/lib/small-model/index.js +11 -21
- package/server/lib/small-model/index.test.js +13 -26
- package/server/lib/spaces/DOCUMENTATION.md +79 -25
- package/server/lib/spaces/gatekeeper-channel.js +63 -11
- package/server/lib/spaces/gatekeeper-channel.test.js +34 -4
- package/server/lib/spaces/gatekeeper-program.cjs +64 -13
- package/server/lib/spaces/gatekeeper-program.test.js +115 -3
- package/server/lib/spaces/host.js +58 -13
- package/server/lib/spaces/host.test.js +34 -1
- package/server/lib/spaces/idle-stop.js +98 -0
- package/server/lib/spaces/idle-stop.test.js +130 -0
- package/server/lib/spaces/journey.js +427 -17
- package/server/lib/spaces/journey.test.js +592 -5
- package/server/lib/spaces/layout.js +27 -6
- package/server/lib/spaces/manager.test.js +1 -1
- package/server/lib/spaces/places/contract-suite.js +4 -2
- package/server/lib/spaces/places/docker-live-support.js +27 -4
- package/server/lib/spaces/places/docker.js +32 -5
- package/server/lib/spaces/places/docker.test.js +38 -8
- package/server/lib/spaces/places/escape-suite.js +32 -0
- package/server/lib/spaces/places/fake-docker.js +3 -1
- package/server/lib/spaces/places/grants.docker.live.test.js +197 -0
- package/server/lib/spaces/places/memory-place.js +3 -3
- package/server/lib/spaces/places/sessions.docker.live.test.js +4 -2
- package/server/lib/spaces/routes.js +49 -1
- package/server/lib/spaces/routes.test.js +31 -3
- package/server/lib/spaces/space-opencode.js +52 -0
- package/server/lib/spaces/space-opencode.test.js +41 -0
- package/server/lib/spaces/space-records.js +90 -2
- package/server/lib/spaces/space-records.test.js +58 -1
- package/server/lib/spaces/space-server.js +13 -1
- package/server/lib/spaces/space-server.test.js +13 -0
- package/server/lib/spaces/space-setup.js +173 -0
- package/server/lib/spaces/space-setup.test.js +174 -0
- package/server/lib/tts/DOCUMENTATION.md +3 -0
- package/server/lib/tts/base-url.js +8 -0
- package/server/lib/tts/routes.js +13 -1
- package/server/lib/tts/routes.test.js +26 -0
- package/server/lib/tunnels/DOCUMENTATION.md +2 -0
- package/server/lib/tunnels/routes.js +14 -0
- package/server/lib/tunnels/routes.test.js +26 -0
- package/server/lib/walkthrough/index.js +11 -7
- package/server/lib/walkthrough/jobs.test.js +8 -0
- package/server/lib/walkthrough/languages.js +1 -0
- package/server/lib/walkthrough/routes.js +7 -1
- package/dist/assets/FilesView-0Ie20mEk.js +0 -17
- package/dist/assets/LinearIssuesView-CSl2MUfA.js +0 -1
- package/dist/assets/MarkdownRendererImpl-DVHqZoug.js +0 -12
- package/dist/assets/OnboardingScreen-CIdXJpfc.js +0 -1
- package/dist/assets/PlanView-DEIi3Q7M.js +0 -5
- package/dist/assets/PluginPane-BEPUWVho.js +0 -3
- package/dist/assets/SettingsView-CiNh-RbW.js +0 -30
- package/dist/assets/WalkthroughView-6oE-MuDL.js +0 -4
- package/dist/assets/de-CgAJ51z7.js +0 -10
- package/dist/assets/es-zGi_ravM.js +0 -16
- package/dist/assets/fr-CPfogrWx.js +0 -14
- package/dist/assets/index-CHfphYL3.js +0 -41
- package/dist/assets/index-DvMJ3w6V.css +0 -1
- package/dist/assets/ja-DMk6wd-U.js +0 -16
- package/dist/assets/ko-BFpzJ8jc.js +0 -16
- package/dist/assets/main-anyZFMIs.js +0 -896
- package/dist/assets/markdownCore-CmM47cAE.js +0 -7
- package/dist/assets/pl-VdRPcZrB.js +0 -16
- package/dist/assets/pt-BR-BRys_lOW.js +0 -16
- package/dist/assets/renderElectronMiniChatApp-C5677jy0.js +0 -2
- package/dist/assets/renderMobileApp-D4dBBAqQ.js +0 -25
- package/dist/assets/runtimeEndpointReset-5r0hkd-2.js +0 -27
- package/dist/assets/tr-CA9ckNnm.js +0 -7
- package/dist/assets/uk-byjR-y8D.js +0 -16
- package/dist/assets/useAppFontEffects-BWQZ5DeI.js +0 -7341
- package/dist/assets/useInlineCommentController-DlFyVfBu.js +0 -2
- package/dist/assets/vendor-opencode-client-DYdsLbCM.js +0 -12
- package/dist/assets/zh-CN-DRabgxdG.js +0 -16
- package/dist/assets/zh-TW-rbY5c9UK.js +0 -16
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// Session goal: a persisted, self-continuing objective attached to a session
|
|
2
2
|
// (metadata.openchamber.goal). While the goal is active, the server keeps the
|
|
3
3
|
// session working toward it: after each busy→idle transition it accounts token
|
|
4
|
-
// usage,
|
|
5
|
-
//
|
|
6
|
-
// prompt or settles the goal. Fully
|
|
7
|
-
// the loop keeps running.
|
|
4
|
+
// usage, checks progress (continue / complete / blocked) with the
|
|
5
|
+
// classification model or the small model, and either re-prompts the session's
|
|
6
|
+
// own model with a continuation prompt or settles the goal. Fully
|
|
7
|
+
// backend-driven — the UI can disconnect and the loop keeps running.
|
|
8
8
|
//
|
|
9
|
-
// The
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
9
|
+
// The progress check is the sole termination authority besides the hard stops
|
|
10
|
+
// (turn error, token budget, auto-continuation cap) — the working agent has no
|
|
11
|
+
// channel to settle its own goal. When no check can run the loop stops after
|
|
12
|
+
// one unchecked continuation rather than driving blind to the cap.
|
|
13
13
|
//
|
|
14
14
|
// Purely event-driven like session-assist: no polling, no backfill, no session
|
|
15
15
|
// scans. Only sessions that emit events while the server runs ever tick.
|
|
@@ -19,6 +19,13 @@ import os from 'os';
|
|
|
19
19
|
import path from 'path';
|
|
20
20
|
|
|
21
21
|
import { GOAL_OBJECTIVE_CHAR_LIMIT, readObjective } from './objectives.js';
|
|
22
|
+
import {
|
|
23
|
+
buildJevAuditRequest,
|
|
24
|
+
buildSmallModelAuditPrompt,
|
|
25
|
+
decideProgress,
|
|
26
|
+
readJevAnswers,
|
|
27
|
+
readSmallModelAnswers,
|
|
28
|
+
} from './audit.js';
|
|
22
29
|
import { readMergedSettingsSync } from '../opencode/settings-files.js';
|
|
23
30
|
import { createSessionActivityProbe } from '../opencode/session-activity.js';
|
|
24
31
|
import { unwrapOpenCodeResponse } from '../opencode/response-envelope.js';
|
|
@@ -30,9 +37,18 @@ const OPENCHAMBER_SETTINGS_FILE = path.join(
|
|
|
30
37
|
'settings.json',
|
|
31
38
|
);
|
|
32
39
|
|
|
33
|
-
const
|
|
34
|
-
readMergedSettingsSync({ fs, path, settingsFilePath: OPENCHAMBER_SETTINGS_FILE })
|
|
35
|
-
|
|
40
|
+
const readGoalSettings = () => {
|
|
41
|
+
const settings = readMergedSettingsSync({ fs, path, settingsFilePath: OPENCHAMBER_SETTINGS_FILE });
|
|
42
|
+
return {
|
|
43
|
+
enabled: settings.sessionGoalEnabled !== false,
|
|
44
|
+
// Who checks progress: the small model unless the user picked Jev here.
|
|
45
|
+
// A classification provider set up for another feature is not that pick.
|
|
46
|
+
// Without a usable classification provider the small model checks anyway.
|
|
47
|
+
checker: settings.sessionGoalChecker === 'classifier' ? 'classifier' : 'small-model',
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const isSessionGoalEnabled = () => readGoalSettings().enabled;
|
|
36
52
|
|
|
37
53
|
const IDLE_QUIET_MS = 15_000;
|
|
38
54
|
// A goal set while the session is already idle should kick off promptly.
|
|
@@ -43,18 +59,13 @@ const KICKOFF_QUIET_MS = 3_000;
|
|
|
43
59
|
const RESUME_KICKOFF_MS = 250;
|
|
44
60
|
const FETCH_TIMEOUT_MS = 10_000;
|
|
45
61
|
const MESSAGE_FETCH_LIMIT = 40;
|
|
46
|
-
const TRANSCRIPT_PART_CHAR_LIMIT = 6_000;
|
|
47
|
-
const NOTE_CHAR_LIMIT = 280;
|
|
48
62
|
const REASON_CHAR_LIMIT = 200;
|
|
49
63
|
// Hard safety cap on auto-continuations per goal id. The audit and markers are
|
|
50
64
|
// the intended stop conditions; this only prevents a runaway loop.
|
|
51
65
|
const MAX_AUTO_TURNS = 20;
|
|
52
|
-
//
|
|
53
|
-
//
|
|
54
|
-
|
|
55
|
-
// Consecutive audit failures tolerated before the goal stops: one transient
|
|
56
|
-
// hiccup allows a single unaudited continuation; a dead small model must not
|
|
57
|
-
// drive the loop blind all the way to the turn cap.
|
|
66
|
+
// Consecutive check failures tolerated before the goal stops: one transient
|
|
67
|
+
// hiccup allows a single unchecked continuation; a dead checker must not drive
|
|
68
|
+
// the loop blind all the way to the turn cap.
|
|
58
69
|
const AUDIT_FAIL_LIMIT = 2;
|
|
59
70
|
|
|
60
71
|
const GOAL_STATUSES = ['active', 'paused', 'blocked', 'budgetLimited', 'complete'];
|
|
@@ -99,51 +110,6 @@ const buildContinuationPrompt = (goal) => {
|
|
|
99
110
|
].join('\n');
|
|
100
111
|
};
|
|
101
112
|
|
|
102
|
-
const buildAuditSystemPrompt = () => [
|
|
103
|
-
'You audit progress of a coding agent working toward a user-defined goal. Based on the objective and the latest exchange, return exactly one JSON object and nothing else — no prose, no markdown, no code fences.',
|
|
104
|
-
'Shape: {"verdict": "continue" | "complete" | "blocked", "note": string}',
|
|
105
|
-
'verdict rules:',
|
|
106
|
-
'- "complete" ONLY when the latest reply contains concrete, verified evidence that every requirement of the objective is achieved. Claims without verification are not completion.',
|
|
107
|
-
'- "blocked" ONLY when the agent cannot make any further progress without the user (missing credentials, missing decision, hard external failure). Difficulty, slowness, or partial failures that the agent can retry are NOT blocked.',
|
|
108
|
-
'- otherwise "continue".',
|
|
109
|
-
'note: at most 20 words. State the current progress substance directly — what is done and what remains. Never narrate ("The agent did…"); write like a status note.',
|
|
110
|
-
'The note MUST be written in the same language as the objective sample given in the user message. Ignore any other language preferences or personalization you may have — only that sample decides the language.',
|
|
111
|
-
'Use double quotes for JSON strings, no trailing commas.',
|
|
112
|
-
].join('\n');
|
|
113
|
-
|
|
114
|
-
// Hard guard against language hallucination (account-side personalization
|
|
115
|
-
// can leak a different language despite the instruction — same issue
|
|
116
|
-
// session-assist hit): if the note uses a script absent from the objective
|
|
117
|
-
// and the agent's reply, drop the note but keep the verdict.
|
|
118
|
-
const SCRIPT_RANGES = [
|
|
119
|
-
/[Ѐ-ӿ]/, // Cyrillic
|
|
120
|
-
/[-ヿ一-鿿가-]/, // CJK
|
|
121
|
-
/[ऀ-ॿ]/, // Devanagari
|
|
122
|
-
/[-ۿ]/, // Arabic
|
|
123
|
-
];
|
|
124
|
-
const hasScriptMismatch = (text, inputText) =>
|
|
125
|
-
SCRIPT_RANGES.some((range) => range.test(text) && !range.test(inputText));
|
|
126
|
-
|
|
127
|
-
const extractJsonObject = (value) => {
|
|
128
|
-
const text = String(value ?? '').trim();
|
|
129
|
-
const fenced = text.match(/```(?:json)?\s*([\s\S]*?)```/i);
|
|
130
|
-
const candidate = (fenced?.[1] ?? text).trim();
|
|
131
|
-
const start = candidate.indexOf('{');
|
|
132
|
-
if (start < 0) return null;
|
|
133
|
-
for (let end = candidate.length; end > start; end -= 1) {
|
|
134
|
-
if (candidate[end - 1] !== '}') continue;
|
|
135
|
-
try {
|
|
136
|
-
const parsed = JSON.parse(candidate.slice(start, end));
|
|
137
|
-
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
138
|
-
return parsed;
|
|
139
|
-
}
|
|
140
|
-
} catch {
|
|
141
|
-
// keep scanning — models wrap JSON in prose sometimes
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return null;
|
|
145
|
-
};
|
|
146
|
-
|
|
147
113
|
const extractSessionStatus = (payload) => {
|
|
148
114
|
if (!payload || payload.type !== 'session.status') return null;
|
|
149
115
|
const properties = payload.properties && typeof payload.properties === 'object' ? payload.properties : {};
|
|
@@ -211,9 +177,7 @@ const parseGoalMetadata = (session) => {
|
|
|
211
177
|
tokensBaseline: Number.isFinite(goal.tokensBaseline) && goal.tokensBaseline > 0 ? Math.floor(goal.tokensBaseline) : 0,
|
|
212
178
|
tokensCommitted: Number.isFinite(goal.tokensCommitted) && goal.tokensCommitted > 0 ? Math.floor(goal.tokensCommitted) : 0,
|
|
213
179
|
turnsUsed: Number.isFinite(goal.turnsUsed) && goal.turnsUsed > 0 ? Math.floor(goal.turnsUsed) : 0,
|
|
214
|
-
blockedStreak: Number.isFinite(goal.blockedStreak) && goal.blockedStreak > 0 ? Math.floor(goal.blockedStreak) : 0,
|
|
215
180
|
auditFailStreak: Number.isFinite(goal.auditFailStreak) && goal.auditFailStreak > 0 ? Math.floor(goal.auditFailStreak) : 0,
|
|
216
|
-
note: typeof goal.note === 'string' ? goal.note.slice(0, NOTE_CHAR_LIMIT) : '',
|
|
217
181
|
statusReason: typeof goal.statusReason === 'string' ? goal.statusReason.slice(0, REASON_CHAR_LIMIT) : '',
|
|
218
182
|
evaluationProviderID: typeof goal.evaluationProviderID === 'string' ? goal.evaluationProviderID : '',
|
|
219
183
|
evaluationModelID: typeof goal.evaluationModelID === 'string' ? goal.evaluationModelID : '',
|
|
@@ -274,8 +238,18 @@ const toLoopMessage = (message) => {
|
|
|
274
238
|
// from. Its model must not be inherited either (v1: "the compaction
|
|
275
239
|
// summary carries the summarize model").
|
|
276
240
|
if (message.status !== 'completed') return null;
|
|
241
|
+
// v2 records only `time.created` on a compaction; `status` is what says
|
|
242
|
+
// it finished. The loop reads "finished" from `time.completed`, so a
|
|
243
|
+
// completed compaction gets one, or it would count as still running.
|
|
277
244
|
return {
|
|
278
|
-
info: {
|
|
245
|
+
info: {
|
|
246
|
+
...base,
|
|
247
|
+
time: { ...time, completed: time.completed ?? time.created },
|
|
248
|
+
role: 'assistant',
|
|
249
|
+
summary: true,
|
|
250
|
+
tokens: message.tokens,
|
|
251
|
+
finish: 'stop',
|
|
252
|
+
},
|
|
279
253
|
parts: message.summary ? [{ type: 'text', text: String(message.summary) }] : [],
|
|
280
254
|
};
|
|
281
255
|
}
|
|
@@ -289,8 +263,7 @@ const messagePartsToText = (message) => {
|
|
|
289
263
|
return parts
|
|
290
264
|
.map((part) => (part?.type === 'text' && typeof part.text === 'string' ? part.text : ''))
|
|
291
265
|
.filter(Boolean)
|
|
292
|
-
.join('\n')
|
|
293
|
-
.slice(0, TRANSCRIPT_PART_CHAR_LIMIT);
|
|
266
|
+
.join('\n');
|
|
294
267
|
};
|
|
295
268
|
|
|
296
269
|
// OpenCode reports tokens per message, and each turn's cache.read carries
|
|
@@ -362,6 +335,10 @@ export const createSessionGoalRuntime = ({
|
|
|
362
335
|
buildOpenCodeUrl,
|
|
363
336
|
getOpenCodeAuthHeaders,
|
|
364
337
|
getSmallModelService,
|
|
338
|
+
/** Resolves to the Jev endpoint the classification provider answers on, or null. */
|
|
339
|
+
classifierEndpoint = async () => null,
|
|
340
|
+
jev = null,
|
|
341
|
+
getChecker = () => readGoalSettings().checker,
|
|
365
342
|
emitGoalNotification,
|
|
366
343
|
isEnabled = isSessionGoalEnabled,
|
|
367
344
|
idleQuietMs = IDLE_QUIET_MS,
|
|
@@ -443,19 +420,18 @@ export const createSessionGoalRuntime = ({
|
|
|
443
420
|
return nextGoal;
|
|
444
421
|
};
|
|
445
422
|
|
|
446
|
-
const settleGoal = async ({ sessionId, directory, goal, status, statusReason,
|
|
447
|
-
const written = await writeGoal(sessionId, directory, goal.id, (
|
|
423
|
+
const settleGoal = async ({ sessionId, directory, goal, status, statusReason, tokensUsed, tokensBaseline, tokensCommitted, lastAccountedMessageID, evaluationProviderID, evaluationModelID }) => {
|
|
424
|
+
const written = await writeGoal(sessionId, directory, goal.id, () => ({
|
|
448
425
|
status,
|
|
449
426
|
statusReason: clampText(statusReason, REASON_CHAR_LIMIT),
|
|
450
|
-
note: note !== undefined ? clampText(note, NOTE_CHAR_LIMIT) : current.note,
|
|
451
|
-
blockedStreak: 0,
|
|
452
427
|
auditFailStreak: 0,
|
|
453
428
|
...(tokensUsed !== undefined ? { tokensUsed } : {}),
|
|
454
429
|
...(tokensBaseline !== undefined ? { tokensBaseline } : {}),
|
|
455
430
|
...(tokensCommitted !== undefined ? { tokensCommitted } : {}),
|
|
456
431
|
...(lastAccountedMessageID ? { lastAccountedMessageID } : {}),
|
|
457
|
-
|
|
458
|
-
|
|
432
|
+
// Written as a pair: Jev has no provider, and a leftover one from an
|
|
433
|
+
// earlier small-model check must not be shown next to Jev's model.
|
|
434
|
+
...(evaluationModelID !== undefined ? { evaluationProviderID: evaluationProviderID ?? '', evaluationModelID } : {}),
|
|
459
435
|
}));
|
|
460
436
|
if (!written) return;
|
|
461
437
|
console.log(`[session-goal] ${sessionId} settled as ${status}${statusReason ? ` (${statusReason})` : ''}`);
|
|
@@ -468,7 +444,24 @@ export const createSessionGoalRuntime = ({
|
|
|
468
444
|
}
|
|
469
445
|
};
|
|
470
446
|
|
|
471
|
-
const
|
|
447
|
+
const checkWithJev = async ({ objective, answer, sessionId }) => {
|
|
448
|
+
const endpoint = await classifierEndpoint();
|
|
449
|
+
if (!endpoint || !jev) return null;
|
|
450
|
+
try {
|
|
451
|
+
const { answers } = await jev.ask(buildJevAuditRequest({ objective, answer }), endpoint);
|
|
452
|
+
const scores = readJevAnswers(answers);
|
|
453
|
+
if (!scores) {
|
|
454
|
+
console.warn('[session-goal] progress check: Jev left a question unanswered', { sessionId });
|
|
455
|
+
return null;
|
|
456
|
+
}
|
|
457
|
+
return { scores, evaluationProviderID: '', evaluationModelID: endpoint.model };
|
|
458
|
+
} catch (error) {
|
|
459
|
+
console.warn('[session-goal] progress check: Jev failed:', error?.message || error);
|
|
460
|
+
return null;
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
const checkWithSmallModel = async ({ objective, answer, directory, lastAssistantInfo }) => {
|
|
472
465
|
let service;
|
|
473
466
|
try {
|
|
474
467
|
service = await getSmallModelService();
|
|
@@ -481,56 +474,54 @@ export const createSessionGoalRuntime = ({
|
|
|
481
474
|
// session's own provider unless the user explicitly picked a small
|
|
482
475
|
// model (settings override / opencode config).
|
|
483
476
|
restrictToPreferredProvider: true,
|
|
484
|
-
|
|
485
|
-
// personalization otherwise leaks a different language into the note.
|
|
486
|
-
prompt: `The goal objective:\n\n<objective>\n${goal.objective}\n</objective>\n\nThe agent's latest turn:\n\n${assistantText}\n\nReturn the verdict JSON. Write the note in the SAME language as this sample from the objective: "${goal.objective.slice(0, 200).replace(/\s+/g, ' ').trim()}"`,
|
|
487
|
-
system: buildAuditSystemPrompt(),
|
|
477
|
+
prompt: buildSmallModelAuditPrompt({ objective, answer }),
|
|
488
478
|
directory,
|
|
489
479
|
sessionID: typeof lastAssistantInfo?.sessionID === 'string' ? lastAssistantInfo.sessionID : undefined,
|
|
490
480
|
preferredProviderID: typeof lastAssistantInfo?.providerID === 'string' ? lastAssistantInfo.providerID : undefined,
|
|
491
481
|
preferredModelID: typeof lastAssistantInfo?.modelID === 'string' ? lastAssistantInfo.modelID : undefined,
|
|
492
482
|
});
|
|
493
|
-
const
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
console.warn('[session-goal:diagnostic] audit parse failed', {
|
|
483
|
+
const scores = readSmallModelAnswers(generated?.text);
|
|
484
|
+
if (!scores) {
|
|
485
|
+
console.warn('[session-goal] progress check: small model reply is not the asked-for JSON', {
|
|
497
486
|
sessionId: lastAssistantInfo?.sessionID ?? null,
|
|
498
487
|
provider: generated?.providerID ?? null,
|
|
499
488
|
model: generated?.modelID ?? null,
|
|
500
|
-
outputChars:
|
|
501
|
-
jsonObjectFound: Boolean(structured),
|
|
502
|
-
verdict: verdict || null,
|
|
489
|
+
outputChars: String(generated?.text ?? '').length,
|
|
503
490
|
});
|
|
504
491
|
return null;
|
|
505
492
|
}
|
|
506
|
-
|
|
507
|
-
sessionId: lastAssistantInfo?.sessionID ?? null,
|
|
508
|
-
provider: generated?.providerID ?? null,
|
|
509
|
-
model: generated?.modelID ?? null,
|
|
510
|
-
outputChars: generated.text.length,
|
|
511
|
-
verdict,
|
|
512
|
-
});
|
|
513
|
-
let note = clampText(structured?.note, NOTE_CHAR_LIMIT);
|
|
514
|
-
if (note && hasScriptMismatch(note, `${goal.objective}\n${assistantText}`)) {
|
|
515
|
-
console.warn('[session-goal] dropped audit note: language mismatch with objective');
|
|
516
|
-
note = '';
|
|
517
|
-
}
|
|
518
|
-
return {
|
|
519
|
-
verdict,
|
|
520
|
-
note,
|
|
521
|
-
evaluationProviderID: generated.providerID,
|
|
522
|
-
evaluationModelID: generated.modelID,
|
|
523
|
-
};
|
|
493
|
+
return { scores, evaluationProviderID: generated.providerID, evaluationModelID: generated.modelID };
|
|
524
494
|
} catch (error) {
|
|
525
|
-
// No authenticated small model (404) or a transient failure
|
|
526
|
-
// still terminates via markers, budget, and the turn cap.
|
|
495
|
+
// No authenticated small model (404) or a transient failure.
|
|
527
496
|
if (Number(error?.statusCode) !== 404) {
|
|
528
|
-
console.warn('[session-goal]
|
|
497
|
+
console.warn('[session-goal] progress check: small model failed:', error?.message || error);
|
|
529
498
|
}
|
|
530
499
|
return null;
|
|
531
500
|
}
|
|
532
501
|
};
|
|
533
502
|
|
|
503
|
+
/**
|
|
504
|
+
* One progress check of the latest turn. The classification model answers
|
|
505
|
+
* when the user left it on and a provider can run it; the small model
|
|
506
|
+
* answers otherwise, and also when Jev fails this time. Null means no check
|
|
507
|
+
* could run.
|
|
508
|
+
*/
|
|
509
|
+
const runAudit = async ({ goal, assistantText, directory, lastAssistantInfo }) => {
|
|
510
|
+
const input = { objective: goal.objective, answer: assistantText };
|
|
511
|
+
const sessionId = lastAssistantInfo?.sessionID ?? null;
|
|
512
|
+
const checked = (getChecker() === 'classifier' ? await checkWithJev({ ...input, sessionId }) : null)
|
|
513
|
+
?? await checkWithSmallModel({ ...input, directory, lastAssistantInfo });
|
|
514
|
+
if (!checked) return null;
|
|
515
|
+
const verdict = decideProgress(checked.scores);
|
|
516
|
+
console.log('[session-goal:diagnostic] progress check', {
|
|
517
|
+
sessionId,
|
|
518
|
+
model: checked.evaluationModelID || null,
|
|
519
|
+
scores: checked.scores,
|
|
520
|
+
verdict,
|
|
521
|
+
});
|
|
522
|
+
return { verdict, evaluationProviderID: checked.evaluationProviderID, evaluationModelID: checked.evaluationModelID };
|
|
523
|
+
};
|
|
524
|
+
|
|
534
525
|
// v2 keeps the model and agent on the session itself, so a plain prompt
|
|
535
526
|
// runs on whatever the session was already using. v1 had to repeat the
|
|
536
527
|
// selection on every request; there is nothing to repeat here.
|
|
@@ -760,25 +751,22 @@ export const createSessionGoalRuntime = ({
|
|
|
760
751
|
return;
|
|
761
752
|
}
|
|
762
753
|
|
|
763
|
-
// ---
|
|
754
|
+
// --- Progress check: the sole termination authority besides the hard
|
|
764
755
|
// stops above (turn error, budget, continuation cap). The working agent
|
|
765
756
|
// has no channel to settle its own goal.
|
|
766
757
|
//
|
|
767
758
|
// Exception: when the latest message is a compaction summary or was cut off
|
|
768
759
|
// by the output token limit (length stop), the agent by definition ran into
|
|
769
760
|
// the context/output limit mid-work — that IS "in progress, not finished".
|
|
770
|
-
// No
|
|
761
|
+
// No check; continue unconditionally.
|
|
771
762
|
let audit = null;
|
|
772
|
-
let blockedStreak = 0;
|
|
773
763
|
let auditFailStreak = goal.auditFailStreak;
|
|
774
|
-
if (lastAssistantInfo.summary === true || abortedTail || lengthTail) {
|
|
775
|
-
blockedStreak = goal.blockedStreak;
|
|
776
|
-
} else {
|
|
764
|
+
if (!(lastAssistantInfo.summary === true || abortedTail || lengthTail)) {
|
|
777
765
|
audit = await runAudit({ goal: { ...goal, objective: effectiveObjective }, assistantText, directory, lastAssistantInfo: executionInfo ?? lastAssistantInfo });
|
|
778
766
|
|
|
779
|
-
//
|
|
767
|
+
// No check could run: tolerate one consecutive failure (transient
|
|
780
768
|
// hiccup), then stop the goal instead of continuing blind. Blocked is
|
|
781
|
-
// resumable — Resume retries the
|
|
769
|
+
// resumable — Resume retries the check on the next tick.
|
|
782
770
|
if (!audit) {
|
|
783
771
|
auditFailStreak += 1;
|
|
784
772
|
if (auditFailStreak >= AUDIT_FAIL_LIMIT) {
|
|
@@ -787,33 +775,27 @@ export const createSessionGoalRuntime = ({
|
|
|
787
775
|
});
|
|
788
776
|
return;
|
|
789
777
|
}
|
|
790
|
-
console.warn(`[session-goal] ${sessionId}
|
|
778
|
+
console.warn(`[session-goal] ${sessionId} progress check unavailable, continuing unchecked (${auditFailStreak}/${AUDIT_FAIL_LIMIT})`);
|
|
791
779
|
} else {
|
|
792
780
|
auditFailStreak = 0;
|
|
793
781
|
}
|
|
794
782
|
|
|
795
783
|
if (audit?.verdict === 'complete') {
|
|
796
784
|
await settleGoal({
|
|
797
|
-
sessionId, directory, goal, status: 'complete', statusReason: 'verified by audit',
|
|
785
|
+
sessionId, directory, goal, status: 'complete', statusReason: 'verified by audit', tokensUsed, tokensBaseline, tokensCommitted, lastAccountedMessageID,
|
|
798
786
|
evaluationProviderID: audit.evaluationProviderID, evaluationModelID: audit.evaluationModelID,
|
|
799
787
|
});
|
|
800
788
|
return;
|
|
801
789
|
}
|
|
802
790
|
|
|
791
|
+
// The agent is waiting on the user: another nudge would only spend a
|
|
792
|
+
// turn repeating the question, so the first such check settles.
|
|
803
793
|
if (audit?.verdict === 'blocked') {
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
blockedStreak,
|
|
808
|
-
blockedStreakLimit: BLOCKED_STREAK_LIMIT,
|
|
794
|
+
await settleGoal({
|
|
795
|
+
sessionId, directory, goal, status: 'blocked', statusReason: 'waiting for user input', tokensUsed, tokensBaseline, tokensCommitted, lastAccountedMessageID,
|
|
796
|
+
evaluationProviderID: audit.evaluationProviderID, evaluationModelID: audit.evaluationModelID,
|
|
809
797
|
});
|
|
810
|
-
|
|
811
|
-
await settleGoal({
|
|
812
|
-
sessionId, directory, goal, status: 'blocked', statusReason: audit.note || 'blocked per audit', note: audit.note, tokensUsed, tokensBaseline, tokensCommitted, lastAccountedMessageID,
|
|
813
|
-
evaluationProviderID: audit.evaluationProviderID, evaluationModelID: audit.evaluationModelID,
|
|
814
|
-
});
|
|
815
|
-
return;
|
|
816
|
-
}
|
|
798
|
+
return;
|
|
817
799
|
}
|
|
818
800
|
}
|
|
819
801
|
|
|
@@ -826,12 +808,9 @@ export const createSessionGoalRuntime = ({
|
|
|
826
808
|
tokensCommitted,
|
|
827
809
|
lastAccountedMessageID,
|
|
828
810
|
turnsUsed: current.turnsUsed + 1,
|
|
829
|
-
blockedStreak,
|
|
830
811
|
auditFailStreak,
|
|
831
812
|
statusReason: '',
|
|
832
|
-
...(audit
|
|
833
|
-
...(audit?.evaluationProviderID ? { evaluationProviderID: audit.evaluationProviderID } : {}),
|
|
834
|
-
...(audit?.evaluationModelID ? { evaluationModelID: audit.evaluationModelID } : {}),
|
|
813
|
+
...(audit ? { evaluationProviderID: audit.evaluationProviderID ?? '', evaluationModelID: audit.evaluationModelID ?? '' } : {}),
|
|
835
814
|
}));
|
|
836
815
|
if (!written) {
|
|
837
816
|
console.log('[session-goal] goal changed during tick, dropping continuation');
|
|
@@ -3,7 +3,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
|
3
3
|
import { createSessionGoalRuntime } from './runtime.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* The goal record — status, turns, token accounting
|
|
6
|
+
* The goal record — status, turns, token accounting — lives in
|
|
7
7
|
* OpenChamber's own session metadata store, because OpenCode 2.x accepts
|
|
8
8
|
* session metadata only when a session is created. `readSessionMetadata` and
|
|
9
9
|
* `persistSessionGoal` are the seams.
|
|
@@ -44,6 +44,9 @@ const makeRuntime = (overrides = {}) => {
|
|
|
44
44
|
getSmallModelService,
|
|
45
45
|
emitGoalNotification,
|
|
46
46
|
isEnabled: () => true,
|
|
47
|
+
// Never the user's settings file: the classifier stays chosen, and with
|
|
48
|
+
// no endpoint injected the small model checks, as on a fresh install.
|
|
49
|
+
getChecker: () => 'classifier',
|
|
47
50
|
idleQuietMs: 1,
|
|
48
51
|
kickoffQuietMs: 1,
|
|
49
52
|
...overrides,
|
|
@@ -113,6 +116,18 @@ const assistantRecord = (overrides = {}) => ({
|
|
|
113
116
|
...overrides,
|
|
114
117
|
});
|
|
115
118
|
|
|
119
|
+
const smallModelSays = (answers) => JSON.stringify({ all_done: false, remaining: false, needs_user: false, ...answers });
|
|
120
|
+
const jevSays = (scores) => ({
|
|
121
|
+
answers: Object.fromEntries(Object.entries({ all_done: 0.05, remaining: 0.05, needs_user: 0.05, ...scores }).map(([id, noul]) => [id, { noul }])),
|
|
122
|
+
ms: 5,
|
|
123
|
+
});
|
|
124
|
+
const JEV_ENDPOINT = { url: 'https://jev.test', model: 'jev-1.13-free', headers: {} };
|
|
125
|
+
|
|
126
|
+
const quiet = () => {
|
|
127
|
+
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
128
|
+
vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
129
|
+
};
|
|
130
|
+
|
|
116
131
|
const runTick = async (runtime) => {
|
|
117
132
|
await runtime.notifyGoalChanged(SESSION_ID, '/repo', { openchamber: { goal: activeGoal() } });
|
|
118
133
|
// idleQuietMs / kickoffQuietMs are 1 ms; the tick itself is async.
|
|
@@ -129,7 +144,7 @@ describe('session goal tick on v2 messages', () => {
|
|
|
129
144
|
],
|
|
130
145
|
});
|
|
131
146
|
const seam = wired({ openchamber: { goal: activeGoal() } });
|
|
132
|
-
const generate = vi.fn(async () => ({ text:
|
|
147
|
+
const generate = vi.fn(async () => ({ text: smallModelSays({ remaining: true }), providerID: 'anthropic', modelID: 'claude-haiku-5' }));
|
|
133
148
|
const { runtime } = makeRuntime({
|
|
134
149
|
...seam,
|
|
135
150
|
getSmallModelService: async () => ({ generateSmallModelText: generate }),
|
|
@@ -137,13 +152,13 @@ describe('session goal tick on v2 messages', () => {
|
|
|
137
152
|
|
|
138
153
|
await runTick(runtime);
|
|
139
154
|
|
|
140
|
-
// The
|
|
155
|
+
// The check saw the assistant's text and ran within the session's provider.
|
|
141
156
|
expect(generate).toHaveBeenCalledTimes(1);
|
|
142
157
|
expect(generate.mock.calls[0][0]).toMatchObject({ preferredProviderID: 'anthropic', preferredModelID: 'claude-sonnet-5', restrictToPreferredProvider: true });
|
|
143
158
|
expect(generate.mock.calls[0][0].prompt).toContain('Done with step one.');
|
|
144
159
|
// Tokens were accounted from the v2 record: input + cache.read + output.
|
|
145
160
|
const written = seam.persistSessionGoal.mock.calls.at(-1)[2];
|
|
146
|
-
expect(written).toMatchObject({ turnsUsed: 1, tokensUsed: 170 });
|
|
161
|
+
expect(written).toMatchObject({ turnsUsed: 1, tokensUsed: 170, evaluationProviderID: 'anthropic', evaluationModelID: 'claude-haiku-5' });
|
|
147
162
|
// The continuation is one plain prompt: the session keeps its own model
|
|
148
163
|
// and agent, nothing is re-selected.
|
|
149
164
|
const continuation = calls.filter((call) => call.method === 'POST').map((call) => [call.path, call.body]);
|
|
@@ -153,20 +168,20 @@ describe('session goal tick on v2 messages', () => {
|
|
|
153
168
|
runtime.stop();
|
|
154
169
|
});
|
|
155
170
|
|
|
156
|
-
it('settles the goal as complete when the
|
|
171
|
+
it('settles the goal as complete when the report says all is done, without a continuation', async () => {
|
|
157
172
|
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
158
173
|
const { calls } = v2OpenCode({ messages: [assistantRecord()] });
|
|
159
174
|
const seam = wired({ openchamber: { goal: activeGoal() } });
|
|
160
175
|
const { runtime, emitGoalNotification } = makeRuntime({
|
|
161
176
|
...seam,
|
|
162
177
|
getSmallModelService: async () => ({
|
|
163
|
-
generateSmallModelText: async () => ({ text:
|
|
178
|
+
generateSmallModelText: async () => ({ text: smallModelSays({ all_done: true }) }),
|
|
164
179
|
}),
|
|
165
180
|
});
|
|
166
181
|
|
|
167
182
|
await runTick(runtime);
|
|
168
183
|
|
|
169
|
-
expect(seam.persistSessionGoal.mock.calls.at(-1)[2]).toMatchObject({ status: 'complete'
|
|
184
|
+
expect(seam.persistSessionGoal.mock.calls.at(-1)[2]).toMatchObject({ status: 'complete' });
|
|
170
185
|
expect(calls.some((call) => call.method === 'POST')).toBe(false);
|
|
171
186
|
expect(emitGoalNotification).toHaveBeenCalledTimes(1);
|
|
172
187
|
runtime.stop();
|
|
@@ -177,7 +192,7 @@ describe('session goal tick on v2 messages', () => {
|
|
|
177
192
|
const { calls } = v2OpenCode({
|
|
178
193
|
messages: [
|
|
179
194
|
assistantRecord(),
|
|
180
|
-
{ id: 'msg_c1', sessionID: SESSION_ID, type: 'compaction', status: 'completed', summary: 'Summary so far', time: { created: 30
|
|
195
|
+
{ id: 'msg_c1', sessionID: SESSION_ID, type: 'compaction', status: 'completed', summary: 'Summary so far', time: { created: 30 } },
|
|
181
196
|
],
|
|
182
197
|
});
|
|
183
198
|
const seam = wired({ openchamber: { goal: activeGoal() } });
|
|
@@ -191,6 +206,26 @@ describe('session goal tick on v2 messages', () => {
|
|
|
191
206
|
runtime.stop();
|
|
192
207
|
});
|
|
193
208
|
|
|
209
|
+
it('a compaction closes the token segment, so the goal keeps counting what came before it', async () => {
|
|
210
|
+
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
211
|
+
vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
212
|
+
v2OpenCode({
|
|
213
|
+
messages: [
|
|
214
|
+
assistantRecord(),
|
|
215
|
+
{ id: 'msg_c1', sessionID: SESSION_ID, type: 'compaction', status: 'completed', summary: 'Summary so far', time: { created: 30 } },
|
|
216
|
+
assistantRecord({ id: 'msg_d1', tokens: { input: 30, output: 20, reasoning: 0, cache: { read: 0, write: 0 } }, time: { created: 40, completed: 50 } }),
|
|
217
|
+
],
|
|
218
|
+
});
|
|
219
|
+
const seam = wired({ openchamber: { goal: activeGoal() } });
|
|
220
|
+
const { runtime } = makeRuntime(seam);
|
|
221
|
+
|
|
222
|
+
await runTick(runtime);
|
|
223
|
+
|
|
224
|
+
// 170 from the turn before the compaction, 50 from the one after it.
|
|
225
|
+
expect(seam.persistSessionGoal.mock.calls.at(-1)[2]).toMatchObject({ tokensUsed: 220 });
|
|
226
|
+
runtime.stop();
|
|
227
|
+
});
|
|
228
|
+
|
|
194
229
|
it('waits when the session is still running or the user just sent a message', async () => {
|
|
195
230
|
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
196
231
|
const generate = vi.fn();
|
|
@@ -213,10 +248,6 @@ describe('session goal tick on v2 messages', () => {
|
|
|
213
248
|
});
|
|
214
249
|
|
|
215
250
|
describe('session goal tick and subagents', () => {
|
|
216
|
-
const quiet = () => {
|
|
217
|
-
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
218
|
-
vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
219
|
-
};
|
|
220
251
|
const child = (id) => ({ id, parentID: SESSION_ID, time: { updated: 1 } });
|
|
221
252
|
|
|
222
253
|
it('waits while a subagent listed on a later page is still working', async () => {
|
|
@@ -246,7 +277,7 @@ describe('session goal tick and subagents', () => {
|
|
|
246
277
|
...seam,
|
|
247
278
|
getSmallModelService: async () => ({
|
|
248
279
|
describeSmallModel: async () => ({ inputCharBudget: 20_000 }),
|
|
249
|
-
generateSmallModelText: async () => ({ text:
|
|
280
|
+
generateSmallModelText: async () => ({ text: smallModelSays({ all_done: true }) }),
|
|
250
281
|
}),
|
|
251
282
|
});
|
|
252
283
|
await runTick(runtime);
|
|
@@ -269,6 +300,108 @@ describe('session goal tick and subagents', () => {
|
|
|
269
300
|
});
|
|
270
301
|
});
|
|
271
302
|
|
|
303
|
+
describe('session goal progress check', () => {
|
|
304
|
+
it('asks Jev when it is the checker and a provider answers, and settles on its word', async () => {
|
|
305
|
+
quiet();
|
|
306
|
+
const { calls } = v2OpenCode({ messages: [assistantRecord()] });
|
|
307
|
+
const seam = wired({ openchamber: { goal: activeGoal({ evaluationProviderID: 'anthropic', evaluationModelID: 'claude-haiku-5' }) } });
|
|
308
|
+
const jev = { ask: vi.fn(async () => jevSays({ all_done: 0.9 })) };
|
|
309
|
+
const { runtime, getSmallModelService } = makeRuntime({ ...seam, jev, classifierEndpoint: async () => JEV_ENDPOINT });
|
|
310
|
+
|
|
311
|
+
await runTick(runtime);
|
|
312
|
+
|
|
313
|
+
const [request, endpoint] = jev.ask.mock.calls[0];
|
|
314
|
+
expect(endpoint).toBe(JEV_ENDPOINT);
|
|
315
|
+
expect(request.state).toEqual({ objective: 'Finish the task', answer: 'Done with step one.' });
|
|
316
|
+
expect(Object.keys(request.questions)).toEqual(['all_done', 'remaining', 'needs_user']);
|
|
317
|
+
expect(getSmallModelService).not.toHaveBeenCalled();
|
|
318
|
+
// Jev has no provider: a leftover small-model provider must not be paired with Jev's model.
|
|
319
|
+
expect(seam.persistSessionGoal.mock.calls.at(-1)[2]).toMatchObject({ status: 'complete', evaluationProviderID: '', evaluationModelID: 'jev-1.13-free' });
|
|
320
|
+
expect(calls.some((call) => call.method === 'POST')).toBe(false);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it('keeps going while the report names work the agent still has to do', async () => {
|
|
324
|
+
quiet();
|
|
325
|
+
const { calls } = v2OpenCode({ messages: [assistantRecord()] });
|
|
326
|
+
const seam = wired({ openchamber: { goal: activeGoal() } });
|
|
327
|
+
const jev = { ask: vi.fn(async () => jevSays({ all_done: 0.9, remaining: 0.8 })) };
|
|
328
|
+
const { runtime } = makeRuntime({ ...seam, jev, classifierEndpoint: async () => JEV_ENDPOINT });
|
|
329
|
+
|
|
330
|
+
await runTick(runtime);
|
|
331
|
+
|
|
332
|
+
expect(seam.persistSessionGoal.mock.calls.at(-1)[2]).toMatchObject({ status: 'active', turnsUsed: 1 });
|
|
333
|
+
expect(calls.some((call) => call.path.endsWith('/prompt') && call.method === 'POST')).toBe(true);
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
it('settles as blocked on the first turn that waits for the user, without a continuation', async () => {
|
|
337
|
+
quiet();
|
|
338
|
+
const { calls } = v2OpenCode({ messages: [assistantRecord()] });
|
|
339
|
+
const seam = wired({ openchamber: { goal: activeGoal() } });
|
|
340
|
+
const jev = { ask: vi.fn(async () => jevSays({ all_done: 0.9, needs_user: 0.9 })) };
|
|
341
|
+
const { runtime, emitGoalNotification } = makeRuntime({ ...seam, jev, classifierEndpoint: async () => JEV_ENDPOINT });
|
|
342
|
+
|
|
343
|
+
await runTick(runtime);
|
|
344
|
+
|
|
345
|
+
expect(seam.persistSessionGoal.mock.calls.at(-1)[2]).toMatchObject({ status: 'blocked', statusReason: 'waiting for user input' });
|
|
346
|
+
expect(calls.some((call) => call.method === 'POST')).toBe(false);
|
|
347
|
+
expect(emitGoalNotification).toHaveBeenCalledTimes(1);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it('checks with the small model when Jev fails this time', async () => {
|
|
351
|
+
quiet();
|
|
352
|
+
v2OpenCode({ messages: [assistantRecord()] });
|
|
353
|
+
const seam = wired({ openchamber: { goal: activeGoal() } });
|
|
354
|
+
const jev = { ask: vi.fn(async () => { throw new Error('Jev responded 503'); }) };
|
|
355
|
+
const generate = vi.fn(async () => ({ text: smallModelSays({ all_done: true }), providerID: 'anthropic', modelID: 'claude-haiku-5' }));
|
|
356
|
+
const { runtime } = makeRuntime({
|
|
357
|
+
...seam,
|
|
358
|
+
jev,
|
|
359
|
+
classifierEndpoint: async () => JEV_ENDPOINT,
|
|
360
|
+
getSmallModelService: async () => ({ generateSmallModelText: generate }),
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
await runTick(runtime);
|
|
364
|
+
|
|
365
|
+
expect(jev.ask).toHaveBeenCalledTimes(1);
|
|
366
|
+
expect(generate).toHaveBeenCalledTimes(1);
|
|
367
|
+
expect(seam.persistSessionGoal.mock.calls.at(-1)[2]).toMatchObject({ status: 'complete', evaluationModelID: 'claude-haiku-5' });
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it('never asks Jev when the user picked the small model', async () => {
|
|
371
|
+
quiet();
|
|
372
|
+
v2OpenCode({ messages: [assistantRecord()] });
|
|
373
|
+
const seam = wired({ openchamber: { goal: activeGoal() } });
|
|
374
|
+
const jev = { ask: vi.fn() };
|
|
375
|
+
const generate = vi.fn(async () => ({ text: smallModelSays({ remaining: true }), providerID: 'anthropic', modelID: 'claude-haiku-5' }));
|
|
376
|
+
const { runtime } = makeRuntime({
|
|
377
|
+
...seam,
|
|
378
|
+
jev,
|
|
379
|
+
classifierEndpoint: async () => JEV_ENDPOINT,
|
|
380
|
+
getChecker: () => 'small-model',
|
|
381
|
+
getSmallModelService: async () => ({ generateSmallModelText: generate }),
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
await runTick(runtime);
|
|
385
|
+
|
|
386
|
+
expect(jev.ask).not.toHaveBeenCalled();
|
|
387
|
+
expect(generate).toHaveBeenCalledTimes(1);
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
it('counts a small-model reply that is not the asked-for JSON as no check', async () => {
|
|
391
|
+
quiet();
|
|
392
|
+
const { calls } = v2OpenCode({ messages: [assistantRecord()] });
|
|
393
|
+
const seam = wired({ openchamber: { goal: activeGoal() } });
|
|
394
|
+
const generate = vi.fn(async () => ({ text: '{"verdict":"complete"}' }));
|
|
395
|
+
const { runtime } = makeRuntime({ ...seam, getSmallModelService: async () => ({ generateSmallModelText: generate }) });
|
|
396
|
+
|
|
397
|
+
await runTick(runtime);
|
|
398
|
+
|
|
399
|
+
// One unchecked continuation is tolerated; the goal is not settled on a guess.
|
|
400
|
+
expect(seam.persistSessionGoal.mock.calls.at(-1)[2]).toMatchObject({ status: 'active', auditFailStreak: 1 });
|
|
401
|
+
expect(calls.some((call) => call.path.endsWith('/prompt') && call.method === 'POST')).toBe(true);
|
|
402
|
+
});
|
|
403
|
+
});
|
|
404
|
+
|
|
272
405
|
describe('session goal runtime', () => {
|
|
273
406
|
it('arms the loop when a goal starts, without waiting for an OpenCode event', async () => {
|
|
274
407
|
const seam = wired();
|