@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,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { excerpt, loadAssistContext, newestContentId } from './context.js';
|
|
2
|
+
import { excerpt, loadAssistContext, loadSettledTurns, newestContentId } from './context.js';
|
|
3
3
|
import { buildAssistPrompt } from './prompt.js';
|
|
4
4
|
|
|
5
5
|
// v2 message records are flat and a page lists them newest first.
|
|
@@ -197,4 +197,41 @@ describe('session assist context', () => {
|
|
|
197
197
|
expect(trimmed).toMatch(/^START/);
|
|
198
198
|
expect(trimmed).toMatch(/END$/);
|
|
199
199
|
});
|
|
200
|
+
|
|
201
|
+
it('reads the settled turns before a message that was just sent', async () => {
|
|
202
|
+
const signal = new AbortController().signal;
|
|
203
|
+
// The new request is already stored and has no answer yet.
|
|
204
|
+
const sent = await loadSettledTurns({
|
|
205
|
+
signal,
|
|
206
|
+
readPage: async () => page([...pair(1), ...pair(2), ...pair(3), ...pair(4), user('new', 'fresh request')]),
|
|
207
|
+
});
|
|
208
|
+
expect(sent.map((turn) => turn.user.id)).toEqual(['u2', 'u3', 'u4']);
|
|
209
|
+
|
|
210
|
+
// It may not be stored yet: the newest record is the previous answer.
|
|
211
|
+
const notStored = await loadSettledTurns({ signal, readPage: async () => page([...pair(1)]) });
|
|
212
|
+
expect(notStored.map((turn) => turn.user.id)).toEqual(['u1']);
|
|
213
|
+
|
|
214
|
+
// A session without a settled turn is an empty history, not a failure.
|
|
215
|
+
expect(await loadSettledTurns({ signal, readPage: async () => page([user('only', 'first message')]) })).toEqual([]);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it('keeps paging past an unanswered tail until three settled turns are found', async () => {
|
|
219
|
+
let calls = 0;
|
|
220
|
+
const turns = await loadSettledTurns({
|
|
221
|
+
signal: new AbortController().signal,
|
|
222
|
+
readPage: async ({ cursor }) => {
|
|
223
|
+
calls++;
|
|
224
|
+
return cursor ? page([...pair(1), ...pair(2)]) : page([...pair(3), user('new', 'fresh request')], 'older');
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
expect(calls).toBe(2);
|
|
228
|
+
expect(turns.map((turn) => turn.user.id)).toEqual(['u1', 'u2', 'u3']);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('treats a failed page as failure, not as an empty history', async () => {
|
|
232
|
+
await expect(loadSettledTurns({
|
|
233
|
+
signal: new AbortController().signal,
|
|
234
|
+
readPage: async () => ({}),
|
|
235
|
+
})).rejects.toThrow('Session message page is unavailable');
|
|
236
|
+
});
|
|
200
237
|
});
|
|
@@ -96,8 +96,17 @@ export const createSessionAssistRuntime = ({
|
|
|
96
96
|
// Archive state is OpenChamber's own in v2 (no OpenCode route sets it), so
|
|
97
97
|
// the runtime asks rather than reading `time.archived` off the record.
|
|
98
98
|
isSessionArchived = async () => false,
|
|
99
|
+
// Asked once when a turn ends, before the quiet window is armed: which of
|
|
100
|
+
// the enabled fields are worth the Small Model (`{ recap, suggestion }`), or
|
|
101
|
+
// null for "unknown", which keeps every enabled field. See session-work.
|
|
102
|
+
evaluateTurn = null,
|
|
103
|
+
// `../session-lineage.js`: a known subsession never gets an assist, so its
|
|
104
|
+
// turn end arms nothing and reads nothing.
|
|
105
|
+
lineage = null,
|
|
99
106
|
}) => {
|
|
100
107
|
const timers = new Map();
|
|
108
|
+
// Turn ends waiting for `evaluateTurn`; a newer event replaces or drops the entry.
|
|
109
|
+
const gates = new Map();
|
|
101
110
|
const inflight = new Map();
|
|
102
111
|
const ready = new Map();
|
|
103
112
|
// Sessions holding an assist this process wrote, keyed to their directory.
|
|
@@ -114,6 +123,7 @@ export const createSessionAssistRuntime = ({
|
|
|
114
123
|
|
|
115
124
|
const invalidate = (sessionId) => {
|
|
116
125
|
clearTimer(sessionId);
|
|
126
|
+
gates.delete(sessionId);
|
|
117
127
|
ready.delete(sessionId);
|
|
118
128
|
inflight.get(sessionId)?.controller.abort();
|
|
119
129
|
};
|
|
@@ -128,8 +138,12 @@ export const createSessionAssistRuntime = ({
|
|
|
128
138
|
.catch(() => console.warn('[session-assist] failed to retire a stale assist'));
|
|
129
139
|
};
|
|
130
140
|
|
|
131
|
-
const generateAssist = async (sessionId, directory, signal) => {
|
|
132
|
-
const
|
|
141
|
+
const generateAssist = async (sessionId, directory, signal, allowed) => {
|
|
142
|
+
const enabledTargets = getTargets();
|
|
143
|
+
const targets = {
|
|
144
|
+
recap: enabledTargets.recap && allowed.recap,
|
|
145
|
+
suggestion: enabledTargets.suggestion && allowed.suggestion,
|
|
146
|
+
};
|
|
133
147
|
if (!targets.recap && !targets.suggestion) return;
|
|
134
148
|
const baseUrl = buildOpenCodeUrl('/', '').replace(/\/$/, '');
|
|
135
149
|
const client = OpenCode.make({
|
|
@@ -149,6 +163,7 @@ export const createSessionAssistRuntime = ({
|
|
|
149
163
|
checkCurrent();
|
|
150
164
|
// Reverted history is not the active conversation. A new prompt clears
|
|
151
165
|
// the revert boundary before its next idle event.
|
|
166
|
+
if (session?.id === sessionId) lineage?.remember(sessionId, session.parentID ?? null);
|
|
152
167
|
if (session?.id !== sessionId || session.parentID || session.revert?.messageID) return;
|
|
153
168
|
// An archived session is put away: no recap or suggestion is generated for it.
|
|
154
169
|
if (await isSessionArchived(sessionId)) return;
|
|
@@ -210,8 +225,8 @@ export const createSessionAssistRuntime = ({
|
|
|
210
225
|
if (freshSession?.id !== sessionId || freshSession.revert?.messageID || freshSession.location?.directory !== session.location?.directory) return;
|
|
211
226
|
if (await isSessionArchived(sessionId)) return;
|
|
212
227
|
const enabled = getTargets();
|
|
213
|
-
if (!enabled.recap) recap = '';
|
|
214
|
-
if (!enabled.suggestion) suggestion = '';
|
|
228
|
+
if (!enabled.recap || !allowed.recap) recap = '';
|
|
229
|
+
if (!enabled.suggestion || !allowed.suggestion) suggestion = '';
|
|
215
230
|
if (!recap && !suggestion) return;
|
|
216
231
|
await persistSessionAssist(sessionId, directory, {
|
|
217
232
|
recap,
|
|
@@ -222,15 +237,15 @@ export const createSessionAssistRuntime = ({
|
|
|
222
237
|
persisted.set(sessionId, directory);
|
|
223
238
|
};
|
|
224
239
|
|
|
225
|
-
const startGeneration = (sessionId, directory, armedAt) => {
|
|
240
|
+
const startGeneration = (sessionId, directory, armedAt, allowed) => {
|
|
226
241
|
if (stopped) return;
|
|
227
242
|
if (inflight.has(sessionId)) {
|
|
228
|
-
ready.set(sessionId, { directory, armedAt });
|
|
243
|
+
ready.set(sessionId, { directory, armedAt, allowed });
|
|
229
244
|
return;
|
|
230
245
|
}
|
|
231
246
|
const controller = new AbortController();
|
|
232
247
|
inflight.set(sessionId, { controller, armedAt });
|
|
233
|
-
generateAssist(sessionId, directory, controller.signal)
|
|
248
|
+
generateAssist(sessionId, directory, controller.signal, allowed)
|
|
234
249
|
.catch(() => {
|
|
235
250
|
if (!controller.signal.aborted) console.warn('[session-assist] failed to read or save assistance');
|
|
236
251
|
})
|
|
@@ -239,22 +254,46 @@ export const createSessionAssistRuntime = ({
|
|
|
239
254
|
if (ready.has(sessionId)) {
|
|
240
255
|
const next = ready.get(sessionId);
|
|
241
256
|
ready.delete(sessionId);
|
|
242
|
-
startGeneration(sessionId, next.directory, next.armedAt);
|
|
257
|
+
startGeneration(sessionId, next.directory, next.armedAt, next.allowed);
|
|
243
258
|
}
|
|
244
259
|
});
|
|
245
260
|
};
|
|
246
261
|
|
|
247
|
-
const armTimer = (sessionId, directory) => {
|
|
262
|
+
const armTimer = (sessionId, directory, armedAt, allowed) => {
|
|
248
263
|
clearTimer(sessionId);
|
|
249
|
-
const armedAt = Date.now();
|
|
250
264
|
const timer = setTimeout(() => {
|
|
251
265
|
timers.delete(sessionId);
|
|
252
|
-
startGeneration(sessionId, directory, armedAt);
|
|
266
|
+
startGeneration(sessionId, directory, armedAt, allowed);
|
|
253
267
|
}, quietMs);
|
|
254
268
|
timer.unref?.();
|
|
255
269
|
timers.set(sessionId, { timer, armedAt });
|
|
256
270
|
};
|
|
257
271
|
|
|
272
|
+
const ALL_FIELDS = { recap: true, suggestion: true };
|
|
273
|
+
|
|
274
|
+
// The quiet window is armed only for fields Jev did not rule out; with
|
|
275
|
+
// nothing left there is no timer and no Small Model call at all.
|
|
276
|
+
const onTurnEnd = (sessionId, directory) => {
|
|
277
|
+
clearTimer(sessionId);
|
|
278
|
+
const armedAt = Date.now();
|
|
279
|
+
if (typeof evaluateTurn !== 'function') {
|
|
280
|
+
armTimer(sessionId, directory, armedAt, ALL_FIELDS);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
const gate = { armedAt };
|
|
284
|
+
gates.set(sessionId, gate);
|
|
285
|
+
Promise.resolve()
|
|
286
|
+
.then(() => evaluateTurn({ sessionId, directory, assist: getTargets() }))
|
|
287
|
+
.catch(() => null)
|
|
288
|
+
.then((allowed) => {
|
|
289
|
+
if (stopped || gates.get(sessionId) !== gate) return;
|
|
290
|
+
gates.delete(sessionId);
|
|
291
|
+
const fields = allowed ?? ALL_FIELDS;
|
|
292
|
+
if (!fields.recap && !fields.suggestion) return;
|
|
293
|
+
armTimer(sessionId, directory, armedAt, fields);
|
|
294
|
+
});
|
|
295
|
+
};
|
|
296
|
+
|
|
258
297
|
let parkedNoticeLogged = false;
|
|
259
298
|
const processPayload = (payload, directoryHint = '') => {
|
|
260
299
|
if (stopped) return;
|
|
@@ -267,7 +306,9 @@ export const createSessionAssistRuntime = ({
|
|
|
267
306
|
}
|
|
268
307
|
const status = extractSessionStatus(payload);
|
|
269
308
|
if (status) {
|
|
270
|
-
if (status.type === 'idle')
|
|
309
|
+
if (status.type === 'idle') {
|
|
310
|
+
if (lineage?.isChild(status.sessionId) !== true) onTurnEnd(status.sessionId, status.directory || directoryHint);
|
|
311
|
+
}
|
|
271
312
|
else {
|
|
272
313
|
invalidate(status.sessionId);
|
|
273
314
|
retireStored(status.sessionId, status.directory || directoryHint);
|
|
@@ -277,7 +318,9 @@ export const createSessionAssistRuntime = ({
|
|
|
277
318
|
const userMessage = extractUserMessage(payload);
|
|
278
319
|
if (userMessage) {
|
|
279
320
|
// Ignore old message.updated events re-emitted after completion.
|
|
280
|
-
const since = timers.get(userMessage.sessionId)?.armedAt
|
|
321
|
+
const since = timers.get(userMessage.sessionId)?.armedAt
|
|
322
|
+
?? gates.get(userMessage.sessionId)?.armedAt
|
|
323
|
+
?? inflight.get(userMessage.sessionId)?.armedAt;
|
|
281
324
|
if (since !== undefined && userMessage.createdAt >= since) invalidate(userMessage.sessionId);
|
|
282
325
|
}
|
|
283
326
|
};
|
|
@@ -285,6 +328,7 @@ export const createSessionAssistRuntime = ({
|
|
|
285
328
|
const stop = () => {
|
|
286
329
|
stopped = true;
|
|
287
330
|
for (const sessionId of timers.keys()) clearTimer(sessionId);
|
|
331
|
+
gates.clear();
|
|
288
332
|
ready.clear();
|
|
289
333
|
for (const { controller } of inflight.values()) controller.abort();
|
|
290
334
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
2
|
import { createSessionAssistRuntime } from './runtime.js';
|
|
3
|
+
import { createSessionLineage } from '../session-lineage.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* The recap and the suggestion live in OpenChamber's own session metadata
|
|
@@ -164,6 +165,50 @@ describe('session assist runtime', () => {
|
|
|
164
165
|
vi.unstubAllGlobals();
|
|
165
166
|
});
|
|
166
167
|
|
|
168
|
+
it('asks the turn-end gate first and arms nothing when it rules both fields out', async () => {
|
|
169
|
+
const persistSessionAssist = vi.fn(async () => undefined);
|
|
170
|
+
const getSmallModelService = vi.fn(async () => {
|
|
171
|
+
throw new Error('the small model must not be woken');
|
|
172
|
+
});
|
|
173
|
+
const evaluateTurn = vi.fn(async () => ({ recap: false, suggestion: false }));
|
|
174
|
+
const { runtime, buildOpenCodeUrl } = makeRuntime({ persistSessionAssist, getSmallModelService, evaluateTurn });
|
|
175
|
+
|
|
176
|
+
runtime.processPayload(idle());
|
|
177
|
+
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
178
|
+
|
|
179
|
+
expect(evaluateTurn).toHaveBeenCalledWith({ sessionId: 'ses_1', directory: '', assist: { recap: true, suggestion: true } });
|
|
180
|
+
expect(buildOpenCodeUrl).not.toHaveBeenCalled();
|
|
181
|
+
expect(getSmallModelService).not.toHaveBeenCalled();
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('arms nothing for a known subsession: no gate, no timer, no read', async () => {
|
|
185
|
+
const lineage = createSessionLineage();
|
|
186
|
+
lineage.remember('ses_1', 'ses_parent');
|
|
187
|
+
const evaluateTurn = vi.fn(async () => null);
|
|
188
|
+
const { runtime, buildOpenCodeUrl } = makeRuntime({ persistSessionAssist: vi.fn(async () => undefined), evaluateTurn, lineage });
|
|
189
|
+
|
|
190
|
+
runtime.processPayload(idle());
|
|
191
|
+
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
192
|
+
|
|
193
|
+
expect(evaluateTurn).not.toHaveBeenCalled();
|
|
194
|
+
expect(buildOpenCodeUrl).not.toHaveBeenCalled();
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('drops a gate answer that arrives after the next turn started', async () => {
|
|
198
|
+
const persistSessionAssist = vi.fn(async () => undefined);
|
|
199
|
+
let answer;
|
|
200
|
+
const evaluateTurn = vi.fn(() => new Promise((resolve) => { answer = resolve; }));
|
|
201
|
+
const { runtime, buildOpenCodeUrl } = makeRuntime({ persistSessionAssist, evaluateTurn });
|
|
202
|
+
|
|
203
|
+
runtime.processPayload(idle());
|
|
204
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
205
|
+
runtime.processPayload({ type: 'session.status', properties: { sessionID: 'ses_1', status: { type: 'busy' } } });
|
|
206
|
+
answer({ recap: true, suggestion: true });
|
|
207
|
+
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
208
|
+
|
|
209
|
+
expect(buildOpenCodeUrl).not.toHaveBeenCalled();
|
|
210
|
+
});
|
|
211
|
+
|
|
167
212
|
it('arms generation again as soon as a store is injected', async () => {
|
|
168
213
|
const persistSessionAssist = vi.fn(async () => undefined);
|
|
169
214
|
const getSmallModelService = vi.fn(async () => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Session Goal
|
|
2
2
|
|
|
3
3
|
Server-side control loop that keeps a session working toward a user-defined
|
|
4
|
-
objective stored under `metadata.openchamber.goal`, with the
|
|
5
|
-
an independent progress
|
|
4
|
+
objective stored under `metadata.openchamber.goal`, with Jev (the
|
|
5
|
+
classification model) or the small model as an independent progress check. Built on OpenChamber's backend-driven
|
|
6
6
|
architecture (session-assist is the structural template): the loop lives in
|
|
7
7
|
the web server and survives UI disconnects.
|
|
8
8
|
|
|
@@ -19,12 +19,10 @@ the web server and survives UI disconnects.
|
|
|
19
19
|
tokensBaseline, // segment start snapshot (pre-goal turn; 0 after compaction)
|
|
20
20
|
tokensCommitted, // closed segments' total (one segment per compaction)
|
|
21
21
|
turnsUsed, // auto-continuations sent (capped at MAX_AUTO_TURNS)
|
|
22
|
-
|
|
23
|
-
auditFailStreak, // consecutive failed/unavailable audit calls
|
|
24
|
-
note, // latest audit progress note, <= 280 chars
|
|
22
|
+
auditFailStreak, // consecutive progress checks that could not run
|
|
25
23
|
statusReason, // why settled; 'resumed' is a kickoff signal from UI
|
|
26
|
-
evaluationProviderID, // provider
|
|
27
|
-
evaluationModelID, // model
|
|
24
|
+
evaluationProviderID, // provider of the latest check; '' when Jev answered
|
|
25
|
+
evaluationModelID, // model of the latest check (Jev's model id for Jev)
|
|
28
26
|
lastAccountedMessageID, // incremental accounting cursor
|
|
29
27
|
createdAt, updatedAt
|
|
30
28
|
}
|
|
@@ -65,7 +63,7 @@ before touching the filesystem). Rationale: metadata rides every
|
|
|
65
63
|
the file is unreadable — a goal never dies because a file went away.
|
|
66
64
|
- UI display fetches content via the GET route
|
|
67
65
|
(`useGoalObjectiveContent`); in VS Code the route is unavailable, so the
|
|
68
|
-
strip
|
|
66
|
+
strip shows a generic goal title (display-only fallback by design).
|
|
69
67
|
- Server-created goals write the file through `create.js`, which also owns
|
|
70
68
|
objective fitting, inline fallback, metadata creation, and the synthetic
|
|
71
69
|
first-turn reminder shared by scheduled tasks and CLI-created sessions.
|
|
@@ -104,7 +102,10 @@ before touching the filesystem). Rationale: metadata rides every
|
|
|
104
102
|
(`type`, `content[]`, `model`, `finish`, `tokens`); `toLoopMessage`
|
|
105
103
|
projects them into the `{ info, parts }` view the rest of the tick reads,
|
|
106
104
|
and a completed `compaction` record plays v1's `summary: true` assistant
|
|
107
|
-
turn.
|
|
105
|
+
turn. v2 gives a compaction only `time.created`, so the projection
|
|
106
|
+
stamps `time.completed` from it: every "finished" check in the tick reads
|
|
107
|
+
`time.completed`, and without it a compaction looks still running. Other
|
|
108
|
+
plumbing roles are dropped from the view;
|
|
108
109
|
- quiescence check via the message tail (trailing user message or
|
|
109
110
|
unfinished assistant reply → bail; the next idle transition re-arms);
|
|
110
111
|
- token accounting as a SNAPSHOT of the latest completed assistant turn:
|
|
@@ -145,19 +146,37 @@ before touching the filesystem). Rationale: metadata rides every
|
|
|
145
146
|
one new recovery attempt over the same transcript; the continuation
|
|
146
147
|
consumes that permission, so another truncation blocks again. Resume
|
|
147
148
|
does not bypass assistant errors or the token budget;
|
|
148
|
-
- otherwise,
|
|
149
|
-
only — no conversation history and no continuation prompts
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
149
|
+
- otherwise, a progress check of the objective + the last assistant turn
|
|
150
|
+
only — no conversation history and no continuation prompts (`audit.js`).
|
|
151
|
+
Three yes/no questions: does the report say all requested work is done
|
|
152
|
+
(`all_done`), does it name requested work the agent still has to do
|
|
153
|
+
(`remaining`), and is the agent stopped by something only the user can
|
|
154
|
+
provide (`needs_user`). `decideProgress` combines them in code:
|
|
155
|
+
`needs_user >= 0.5` → blocked, `all_done >= 0.5 && remaining < 0.5` →
|
|
156
|
+
complete, anything else → continue. Jev answers with probabilities; the
|
|
157
|
+
small model answers the same questions as JSON booleans read as 1/0, so
|
|
158
|
+
there is one format and one decision. The long turn is cut to its head
|
|
159
|
+
and, mostly, its tail, where the report sits.
|
|
160
|
+
Who answers: Jev when `sessionGoalChecker` is `classifier` (an explicit
|
|
161
|
+
pick; the default is `small-model`, since a classification provider set
|
|
162
|
+
up for another feature is not consent to audit goals with Jev) and a
|
|
163
|
+
classification provider can run it (`classifierEndpoint`, owned by
|
|
164
|
+
`../routing`); the small model otherwise, and also when Jev fails this
|
|
165
|
+
time (`restrictToPreferredProvider`, session's own provider/model
|
|
166
|
+
preferred). The check is the SOLE termination authority besides the hard
|
|
167
|
+
stops above — the working agent has no channel to settle its own goal.
|
|
168
|
+
`complete` and `blocked` settle on the first such answer: a blocked turn
|
|
169
|
+
waits on the user, and another nudge would only spend a turn repeating the
|
|
170
|
+
question (`statusReason: 'waiting for user input'`). There is no note: the
|
|
171
|
+
strip shows the objective. A check that cannot run tolerates ONE
|
|
172
|
+
consecutive unchecked continuation (`auditFailStreak`); a second
|
|
173
|
+
consecutive failure settles the goal as `blocked` ("progress audit
|
|
174
|
+
unavailable") — resumable, and settling resets the streak so Resume gets
|
|
175
|
+
fresh tolerance. A dead checker can never drive the loop blind to the turn
|
|
176
|
+
cap. Measured on 144 hand-written goal-report turns plus 8 real ones (lab:
|
|
177
|
+
`~/projects/openchamber-extensions/jev-goal-lab`): Jev 142/144 with both
|
|
178
|
+
misses on the safe side, gpt-6-luna 141/144. Change the questions or the
|
|
179
|
+
threshold only with a new run of that lab;
|
|
161
180
|
- continue: persist accounting + `turnsUsed` first (a crash after the
|
|
162
181
|
write just waits for the next idle tick; the reverse could double-send),
|
|
163
182
|
re-check the tail, then `POST /api/session/:id/prompt` with the
|
|
@@ -203,6 +222,12 @@ sees only that final turn, so the report is its evidence.
|
|
|
203
222
|
above the composer; `SessionGoalDialog.tsx` — manage dialog
|
|
204
223
|
(edit/pause/resume/complete/clear).
|
|
205
224
|
- Sidebar glyph next to the date in `SessionNodeItem`.
|
|
225
|
+
- `components/sections/openchamber/SessionGoalCheckerField.tsx` — Settings →
|
|
226
|
+
Chat → Goal: Jev or the small model checks progress
|
|
227
|
+
(`sessionGoalChecker`). Without a classification provider the Jev chip is
|
|
228
|
+
disabled and the small model shows as chosen, matching the server.
|
|
229
|
+
`useGoalCheckAvailable` (`hooks/useSessionGoal.ts`) gates arming a new goal
|
|
230
|
+
on either checker being able to run.
|
|
206
231
|
|
|
207
232
|
## Scheduled goals
|
|
208
233
|
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The goal progress check: three yes/no questions about the agent's latest
|
|
3
|
+
* turn, asked either of Jev (the classification model) or of the small model,
|
|
4
|
+
* and one decision taken from the answers in code.
|
|
5
|
+
*
|
|
6
|
+
* Jev answers each question with a probability; the small model answers the
|
|
7
|
+
* same questions as JSON booleans, read as 1 or 0, so both go through the same
|
|
8
|
+
* decision. Measured on 144 goal-report turns (hand-written, labelled before
|
|
9
|
+
* any answer was seen) plus 8 real goal turns: Jev 142/144 with both misses
|
|
10
|
+
* on the safe side (a finished turn read as "continue"), gpt-6-luna 141/144.
|
|
11
|
+
* Lab: ~/projects/openchamber-extensions/jev-goal-lab. Change the wording or
|
|
12
|
+
* the thresholds only with a new run of it.
|
|
13
|
+
*/
|
|
14
|
+
import { z } from 'zod';
|
|
15
|
+
|
|
16
|
+
const CONTEXT = 'A user gave an AI coding agent the goal in `objective`. `answer` is the agent\'s latest message, which ends with a report of what is done and what remains.';
|
|
17
|
+
|
|
18
|
+
const QUESTIONS = {
|
|
19
|
+
all_done: {
|
|
20
|
+
question: 'Does `answer` report that all the work requested in `objective` is done?',
|
|
21
|
+
criteria: {
|
|
22
|
+
true: 'Every part the objective asks for is reported done. Steps left only for the user, such as testing in the app, reviewing, or committing, and optional ideas the objective did not ask for, do not count against it.',
|
|
23
|
+
false: 'Some requested part is reported unfinished, skipped, postponed, not started, or only partly done, or the agent narrowed the goal to a subset, even if the message says "done".',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
remaining: {
|
|
27
|
+
question: 'Does `answer` name requested work that the agent itself still has to do?',
|
|
28
|
+
criteria: {
|
|
29
|
+
true: 'The message lists or mentions remaining steps of the objective the agent can still carry out, or says it will continue, fix, retry, or finish something.',
|
|
30
|
+
false: 'Nothing of the objective is left for the agent: either everything is done, or what is left needs the user, or it is only user-side checking or an optional unrequested idea.',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
needs_user: {
|
|
34
|
+
question: 'Does `answer` say the agent cannot go on with the objective without something only the user can provide?',
|
|
35
|
+
criteria: {
|
|
36
|
+
true: 'The agent is stopped by missing credentials, login, keys or access; a decision between options only the user can make; a device or machine it cannot reach; or an external failure it cannot work around.',
|
|
37
|
+
false: 'The agent can keep going on its own: it picked a sensible default, the problem is one it can fix or retry, it only asks an optional question, or all that is left for the user is testing or review of finished work.',
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const QUESTION_IDS = Object.keys(QUESTIONS);
|
|
43
|
+
const THRESHOLD = 0.5;
|
|
44
|
+
|
|
45
|
+
// The report sits at the end of a turn, so a long turn keeps its opening and,
|
|
46
|
+
// mostly, its close.
|
|
47
|
+
const ANSWER_HEAD_CHARS = 2_000;
|
|
48
|
+
const ANSWER_TAIL_CHARS = 8_000;
|
|
49
|
+
|
|
50
|
+
const excerptAnswer = (text) => (text.length <= ANSWER_HEAD_CHARS + ANSWER_TAIL_CHARS
|
|
51
|
+
? text
|
|
52
|
+
: `${text.slice(0, ANSWER_HEAD_CHARS).trimEnd()}\n[…]\n${text.slice(-ANSWER_TAIL_CHARS).trimStart()}`);
|
|
53
|
+
|
|
54
|
+
/** The Jev request for one check. */
|
|
55
|
+
export const buildJevAuditRequest = ({ objective, answer }) => ({
|
|
56
|
+
state: { objective, answer: excerptAnswer(answer) },
|
|
57
|
+
questions: Object.fromEntries(Object.entries(QUESTIONS).map(([id, { question, criteria }]) => [
|
|
58
|
+
id,
|
|
59
|
+
{ type: 'noul', instructions: [CONTEXT, question], criteria },
|
|
60
|
+
])),
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const noulAnswer = z.object({ noul: z.number() });
|
|
64
|
+
|
|
65
|
+
/** Jev's answers as scores, or null when any question went unanswered. */
|
|
66
|
+
export const readJevAnswers = (answers) => {
|
|
67
|
+
const scores = {};
|
|
68
|
+
for (const id of QUESTION_IDS) {
|
|
69
|
+
const parsed = noulAnswer.safeParse(answers?.[id]);
|
|
70
|
+
if (!parsed.success) return null;
|
|
71
|
+
scores[id] = parsed.data.noul;
|
|
72
|
+
}
|
|
73
|
+
return scores;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/** The same questions for the small model, as one prompt asking for JSON booleans. */
|
|
77
|
+
export const buildSmallModelAuditPrompt = ({ objective, answer }) => [
|
|
78
|
+
'You check the progress of an AI coding agent. Answer three yes/no questions and return exactly one JSON object and nothing else — no prose, no markdown, no code fences: {"all_done": boolean, "remaining": boolean, "needs_user": boolean}.',
|
|
79
|
+
CONTEXT,
|
|
80
|
+
...Object.entries(QUESTIONS).map(([id, { question, criteria }]) => `${id}: ${question}\n true: ${criteria.true}\n false: ${criteria.false}`),
|
|
81
|
+
`<objective>\n${objective}\n</objective>`,
|
|
82
|
+
`<answer>\n${excerptAnswer(answer)}\n</answer>`,
|
|
83
|
+
'Return the JSON.',
|
|
84
|
+
].join('\n\n');
|
|
85
|
+
|
|
86
|
+
const smallModelAnswers = z.object({ all_done: z.boolean(), remaining: z.boolean(), needs_user: z.boolean() });
|
|
87
|
+
|
|
88
|
+
/** The small model's reply as scores, or null when it is not the asked-for JSON. */
|
|
89
|
+
export const readSmallModelAnswers = (text) => {
|
|
90
|
+
const match = String(text ?? '').match(/\{[\s\S]*\}/);
|
|
91
|
+
if (!match) return null;
|
|
92
|
+
let json;
|
|
93
|
+
try {
|
|
94
|
+
json = JSON.parse(match[0]);
|
|
95
|
+
} catch {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
const parsed = smallModelAnswers.safeParse(json);
|
|
99
|
+
if (!parsed.success) return null;
|
|
100
|
+
return Object.fromEntries(QUESTION_IDS.map((id) => [id, parsed.data[id] ? 1 : 0]));
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* `blocked` first: a turn that waits on the user is not finished even when
|
|
105
|
+
* everything else is. `complete` needs the report to say all is done and name
|
|
106
|
+
* nothing left for the agent; anything else keeps the goal going.
|
|
107
|
+
*/
|
|
108
|
+
export const decideProgress = (scores) => {
|
|
109
|
+
if (scores.needs_user >= THRESHOLD) return 'blocked';
|
|
110
|
+
if (scores.all_done >= THRESHOLD && scores.remaining < THRESHOLD) return 'complete';
|
|
111
|
+
return 'continue';
|
|
112
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
buildJevAuditRequest,
|
|
5
|
+
buildSmallModelAuditPrompt,
|
|
6
|
+
decideProgress,
|
|
7
|
+
readJevAnswers,
|
|
8
|
+
readSmallModelAnswers,
|
|
9
|
+
} from './audit.js';
|
|
10
|
+
|
|
11
|
+
describe('goal progress decision', () => {
|
|
12
|
+
it('blocks whenever the turn waits on the user, even with all work reported done', () => {
|
|
13
|
+
expect(decideProgress({ all_done: 0.9, remaining: 0.1, needs_user: 0.7 })).toBe('blocked');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('completes only when all is done and nothing is left for the agent', () => {
|
|
17
|
+
expect(decideProgress({ all_done: 0.9, remaining: 0.1, needs_user: 0.1 })).toBe('complete');
|
|
18
|
+
expect(decideProgress({ all_done: 0.9, remaining: 0.6, needs_user: 0.1 })).toBe('continue');
|
|
19
|
+
expect(decideProgress({ all_done: 0.3, remaining: 0.1, needs_user: 0.1 })).toBe('continue');
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('Jev answers', () => {
|
|
24
|
+
it('reads the three scores', () => {
|
|
25
|
+
expect(readJevAnswers({ all_done: { noul: 0.8 }, remaining: { noul: 0.1 }, needs_user: { noul: 0.05 } }))
|
|
26
|
+
.toEqual({ all_done: 0.8, remaining: 0.1, needs_user: 0.05 });
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('refuses an answer set with a question missing rather than guessing it', () => {
|
|
30
|
+
expect(readJevAnswers({ all_done: { noul: 0.8 }, remaining: { noul: 0.1 } })).toBeNull();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('keeps the closing report of a long turn', () => {
|
|
34
|
+
const answer = `${'narrative '.repeat(3_000)}Remaining: wire the VS Code bridge.`;
|
|
35
|
+
const request = buildJevAuditRequest({ objective: 'Ship it', answer });
|
|
36
|
+
expect(request.state.answer.length).toBeLessThan(answer.length);
|
|
37
|
+
expect(request.state.answer.endsWith('Remaining: wire the VS Code bridge.')).toBe(true);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe('small model answers', () => {
|
|
42
|
+
it('reads the booleans as scores, also inside a code fence', () => {
|
|
43
|
+
expect(readSmallModelAnswers('```json\n{"all_done": true, "remaining": false, "needs_user": false}\n```'))
|
|
44
|
+
.toEqual({ all_done: 1, remaining: 0, needs_user: 0 });
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('refuses anything that is not the asked-for shape', () => {
|
|
48
|
+
expect(readSmallModelAnswers('{"verdict": "complete"}')).toBeNull();
|
|
49
|
+
expect(readSmallModelAnswers('{"all_done": "yes", "remaining": false, "needs_user": false}')).toBeNull();
|
|
50
|
+
expect(readSmallModelAnswers('no json here')).toBeNull();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('asks the same three questions Jev gets', () => {
|
|
54
|
+
const prompt = buildSmallModelAuditPrompt({ objective: 'Ship it', answer: 'Done.' });
|
|
55
|
+
for (const id of ['all_done', 'remaining', 'needs_user']) expect(prompt).toContain(`${id}:`);
|
|
56
|
+
expect(prompt).toContain('<objective>\nShip it\n</objective>');
|
|
57
|
+
});
|
|
58
|
+
});
|