From dcd16193e68ae991386008ffb214c95541239f63 Mon Sep 17 00:00:00 2001 From: sujalmandal <6429296+sujalmandal@users.noreply.github.com> Date: Mon, 5 Oct 2026 10:13:05 +0400 Subject: [PATCH] fix: resolve `planMode` from the agent's preset isolate `resolvePlanMode` only looked at `agent.ctx.get('planMode')` and the profile-root `ctx.get('planMode')`. On `dsh web` both miss: the model-facing plan-mode service is published per preset inside a group carrying `isolate: {planMode: true}`, while the host-plane row is disabled. The intercept therefore never fired and the native plan-review card always ran. The `agent.session?.events` fallback that used to carry the check is also gone: `@deepseek-ai/dsh-session` removed `get events()` in 0.1.2-rc.1 and replaced it with `snapshotEvents()`. Because the read was optional-chained, it degraded to `[]` and disabled the plugin silently instead of throwing. - read the preset-scoped service through `ctx.get('agentPresets').serviceFor(agent, 'planMode')`, the public registry accessor, ahead of the two context lookups - read the session log through `snapshotEvents()` and keep accepting the old `session.events` shape for pre-0.1.2-rc.1 hosts - update `tests/plan.test.js`, which still mocked the removed `session.events` property and so kept CI green over the regression --- lib/plan.js | 19 ++++++++++++++++++- tests/plan.test.js | 6 ++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/plan.js b/lib/plan.js index 67af96c..1ad47f6 100644 --- a/lib/plan.js +++ b/lib/plan.js @@ -16,11 +16,20 @@ const HEADING_RE = /^#\s+\S/ * @returns {import('./types.js').PlanModeService | undefined} */ export function resolvePlanMode(ctx, agent) { + const fromPreset = asPlanModeService(readPresetPlanMode(ctx, agent)) + if (fromPreset) return fromPreset const fromAgent = asPlanModeService(agent?.ctx?.get?.('planMode')) if (fromAgent) return fromAgent return asPlanModeService(ctx.get('planMode')) } +function readPresetPlanMode(ctx, agent) { + if (!agent) return undefined + const agentPresets = ctx.get?.('agentPresets') + if (!agentPresets || typeof agentPresets.serviceFor !== 'function') return undefined + return agentPresets.serviceFor(agent, 'planMode') +} + /** * @param {unknown} value * @returns {import('./types.js').PlanModeService | undefined} @@ -51,12 +60,20 @@ export function shouldInterceptExitPlanMode(exec, planMode) { export function isPlanModeActive(agent, planMode) { if (planMode) return planMode.get(agent).active let active = false - for (const event of agent.session?.events ?? []) { + for (const event of readSessionEvents(agent)) { if (event.type === 'plan/mode') active = event.data?.active === true } return active } +function readSessionEvents(agent) { + const session = agent?.session + if (!session) return [] + if (Array.isArray(session.events)) return session.events + if (typeof session.snapshotEvents !== 'function') return [] + return session.snapshotEvents() +} + /** * @param {unknown} args * @returns {string} diff --git a/tests/plan.test.js b/tests/plan.test.js index 82abfa8..3ef4183 100644 --- a/tests/plan.test.js +++ b/tests/plan.test.js @@ -34,10 +34,12 @@ test('shouldInterceptExitPlanMode ignores every other tool', () => { }, planMode(true)), false) }) -test('shouldInterceptExitPlanMode intercepts from session events when planMode is not on this context', () => { +test('shouldInterceptExitPlanMode intercepts from the session log when planMode is not on this context', () => { const agent = { inject() {}, - session: { events: [{ type: 'plan/mode', data: { active: true } }] }, + session: { + snapshotEvents: () => [{ type: 'plan/mode', data: { active: true } }], + }, } assert.equal(shouldInterceptExitPlanMode({ name: EXIT_PLAN_MODE,