@unieai/rabi-plan-mode 0.0.0-stage → 0.2.2-rc.5

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DeepSeek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,8 @@
1
- # Temporary Holding Version
1
+ # @unieai/rabi-plan-mode
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Logged per-agent plan mode with deployment guidance, a direct slash command, and a user-reviewed exit
4
+
5
+ Part of Rabi, the agent harness UnieAI Code runs on. Installed as a dependency of `@unieai/rabi`;
6
+ not meant to be used on its own.
7
+
8
+ See LICENSE for the license and copyright of this package.
package/lib/index.js ADDED
@@ -0,0 +1,425 @@
1
+ import { Service } from "@unieai/cordis";
2
+ import { brandString } from "@unieai/rabi-brand";
3
+ import { z } from "zod";
4
+ import { createUserMessage } from "@unieai/rabi-llm";
5
+ import { defineTool } from "@unieai/rabi-tools";
6
+ import { UserQuestionError } from "@unieai/rabi-user-questions";
7
+ //#region lib/types/index.js
8
+ /**
9
+ * Plan mode is logged per-agent collaboration state: while active, a
10
+ * deployment-owned guidance section is included in each model request, and
11
+ * `exit_plan_mode` presents the completed plan for user review, while the
12
+ * `/plan off` command lets a user leave directly. Sandbox mode and approval
13
+ * policy enforce restrictions independently and do not read or write plan
14
+ * state.
15
+ *
16
+ * The `plan` projection folds the session log, so resume and fork restore the
17
+ * state. User selections remain pending until the next accepted in-turn
18
+ * pre-step. The service includes the selected state in the proposed step
19
+ * assembly, then appends `plan/mode` from `agent/pre-step` only when the step
20
+ * is accepted. Same-step request retries reuse their assembly.
21
+ *
22
+ * The exit tool is disclosed progressively: it is admitted from the first step
23
+ * whose selected state is active and stays admitted for the rest of the
24
+ * Session, so leaving plan mode changes only the guidance section. Native
25
+ * declarations, PTC bindings, and execution share that admission.
26
+ *
27
+ * See packages/plan/plan-mode/README.md.
28
+ *
29
+ * @module @unieai/rabi-plan-mode
30
+ */
31
+ /** The model-facing exit tool's name, admitted once the Session enters plan mode. */
32
+ const EXIT_PLAN_MODE = "exit_plan_mode";
33
+ /** The review question's id, echoed in the answer this tool reads. */
34
+ const REVIEW_ID = "plan-review";
35
+ /** The review question's approve option label. */
36
+ const APPROVE_LABEL = "Approve";
37
+ /** The review question's keep-planning option label. */
38
+ const KEEP_PLANNING_LABEL = "Keep planning";
39
+ const EXIT_DESCRIPTION = "Use only in plan mode. Present your plan for the user's review and, on approval, leave plan mode. The user may approve (carry out the plan from your next step) or keep planning — their feedback comes back in the tool result; revise and present again.";
40
+ /** The plan's first markdown heading (any level), or `undefined` when it has none. */
41
+ function firstHeading(plan) {
42
+ for (const line of plan.split("\n")) {
43
+ const match = /^#{1,6}\s+(.+?)\s*$/.exec(line);
44
+ if (match) return match[1];
45
+ }
46
+ }
47
+ /**
48
+ * Validate deployment-owned plan guidance. Missing, blank, non-string, or
49
+ * unknown fields fail at plugin load rather than being ignored.
50
+ *
51
+ * @param config Raw plugin config.
52
+ * @returns A detached validated config.
53
+ */
54
+ function resolveConfig(config) {
55
+ const section = config.section;
56
+ if (typeof section !== "string") throw new Error("PlanModeConfig needs a string `section`");
57
+ if (section.trim() === "") throw new Error("PlanModeConfig needs a non-empty `section`");
58
+ const unknown = Object.keys(config).filter((key) => key !== "section");
59
+ if (unknown.length > 0) throw new Error(`PlanModeConfig has unknown key(s) ${unknown.join(", ")} — config is { section }`);
60
+ return { section };
61
+ }
62
+ /** Projection of logged plan selections and committed mode. */
63
+ const planProjectionDefinition = {
64
+ key: "plan",
65
+ stateVersion: 4,
66
+ stateSchema: z.object({
67
+ active: z.boolean(),
68
+ wanted: z.boolean().nullable(),
69
+ running: z.object({
70
+ commandId: z.string(),
71
+ wanted: z.boolean()
72
+ }).strict().nullable(),
73
+ activeAtLastHeader: z.boolean().nullable(),
74
+ entered: z.boolean()
75
+ }).strict(),
76
+ init: () => ({
77
+ active: false,
78
+ wanted: null,
79
+ running: null,
80
+ activeAtLastHeader: null,
81
+ entered: false
82
+ }),
83
+ apply: (state, event) => {
84
+ if (event.type === "command/run" && event.data.name === "plan") {
85
+ if (event.data.args === void 0) return state;
86
+ const wanted = event.data.args.trim() !== "off";
87
+ return {
88
+ ...state,
89
+ running: {
90
+ commandId: event.data.commandId,
91
+ wanted
92
+ }
93
+ };
94
+ }
95
+ if (event.type === "command/done" && event.data.commandId === state.running?.commandId) {
96
+ const wanted = event.data.kind === "success" && state.running.wanted !== state.active ? state.running.wanted : null;
97
+ return {
98
+ ...state,
99
+ wanted,
100
+ running: null
101
+ };
102
+ }
103
+ if (event.type === "plan/mode") return {
104
+ ...state,
105
+ active: event.data.active,
106
+ wanted: null,
107
+ entered: state.entered || event.data.active
108
+ };
109
+ if (event.type === "request/header") return {
110
+ ...state,
111
+ activeAtLastHeader: state.active
112
+ };
113
+ return state;
114
+ },
115
+ wire: {
116
+ viewSchema: z.object({
117
+ active: z.boolean(),
118
+ pending: z.boolean()
119
+ }),
120
+ view: (state) => {
121
+ const wanted = state.running?.wanted ?? state.wanted;
122
+ return {
123
+ active: state.active,
124
+ pending: wanted !== null && wanted !== state.active
125
+ };
126
+ }
127
+ }
128
+ };
129
+ /**
130
+ * `ctx.planMode`: owns logged plan state, applies and narrates selected state at step start,
131
+ * the `plan:policy` section, the `/plan` command, and the conditional exit tool.
132
+ * Client carriers expose the projection's cropped `{ active, pending }` view.
133
+ * Agent prompt assembly fails while the projection reader is not ready;
134
+ * callers must await plugin activation before running an agent.
135
+ */
136
+ var PlanModeController = class extends Service {
137
+ static inject = [
138
+ "tools",
139
+ "systemPrompt",
140
+ "sessionProjections",
141
+ "agents"
142
+ ];
143
+ /** Validated deployment-owned guidance. */
144
+ section;
145
+ planProjectionHandle;
146
+ /**
147
+ * Latest selection per session awaiting the next accepted in-turn pre-step.
148
+ * `narrate` is true for user selections and false for the exit tool, whose
149
+ * result already narrates the transition.
150
+ */
151
+ pendingIntents = /* @__PURE__ */ new WeakMap();
152
+ constructor(ctx, config = { section: "" }) {
153
+ super(ctx, "planMode");
154
+ this.section = resolveConfig(config).section;
155
+ }
156
+ async [Service.init]() {
157
+ const ctx = this.ctx;
158
+ ctx.systemPrompt.section({
159
+ name: "plan:policy",
160
+ order: ctx.systemPrompt.getSectionOrder("PLAN_POLICY"),
161
+ text: (context) => {
162
+ if (context.agent === void 0) return "";
163
+ return this.selectedActive(context.agent.session) ? this.section : "";
164
+ }
165
+ });
166
+ this.planProjectionHandle = await ctx.sessionProjections.register(planProjectionDefinition);
167
+ let disposed = false;
168
+ ctx.on("agent/pre-step", async ({ agent, signal }, next) => {
169
+ const decision = await next();
170
+ const pending = this.pendingIntents.get(agent.session);
171
+ if (decision.kind === "reject" || signal.aborted || pending === void 0) return decision;
172
+ const narration = this.narration(agent.session, pending.active);
173
+ try {
174
+ this.onBoundary(agent.session);
175
+ } catch (error) {
176
+ ctx.logger.warn("rabi-plan-mode: failed to append selected plan mode at step start: %o", error);
177
+ return decision;
178
+ }
179
+ return !pending.narrate || narration === void 0 ? decision : {
180
+ ...decision,
181
+ messages: [...decision.messages, narration]
182
+ };
183
+ });
184
+ ctx.effect(() => () => {
185
+ disposed = true;
186
+ }, "rabi-plan-mode: close service lifetime");
187
+ ctx.inject(["commands"], (commandCtx) => {
188
+ commandCtx.commands.register({
189
+ definitionId: brandString("@unieai/rabi-plan-mode"),
190
+ name: "plan",
191
+ description: "Enter or leave plan mode",
192
+ input: {
193
+ hint: "[off|message]",
194
+ attachments: true
195
+ },
196
+ handler: ({ agent, rawInput, attachments }) => {
197
+ const message = rawInput.trim();
198
+ if (message === "off" && attachments.length > 0) return {
199
+ kind: "error",
200
+ text: "Attachments cannot accompany /plan off."
201
+ };
202
+ if (message === "off") switch (this.set(agent, false)) {
203
+ case "committed": return {
204
+ kind: "success",
205
+ text: "Plan mode off."
206
+ };
207
+ case "queued": return {
208
+ kind: "success",
209
+ text: "Leaving plan mode (applies from the next step)."
210
+ };
211
+ case "cancelled": return {
212
+ kind: "success",
213
+ text: "Plan mode entry cancelled."
214
+ };
215
+ case "noop": return this.loggedActive(agent.session) ? {
216
+ kind: "success",
217
+ text: "Leaving plan mode (applies from the next step)."
218
+ } : {
219
+ kind: "success",
220
+ text: "Plan mode is already inactive."
221
+ };
222
+ }
223
+ const outcome = this.set(agent, true);
224
+ if (message !== "" || attachments.length > 0) agent.steer(createUserMessage({
225
+ content: [...attachments, ...message === "" ? [] : [{
226
+ type: "text",
227
+ text: message
228
+ }]],
229
+ source: { kind: "user" }
230
+ }));
231
+ return {
232
+ kind: "success",
233
+ text: outcome === "committed" ? "Plan mode on. Use /plan off to leave." : "Entering plan mode (applies from the next step). Use /plan off to leave."
234
+ };
235
+ }
236
+ });
237
+ });
238
+ ctx.tools.register(defineTool({
239
+ name: EXIT_PLAN_MODE,
240
+ description: EXIT_DESCRIPTION,
241
+ parameters: { plan: {
242
+ type: "string",
243
+ required: true,
244
+ description: "The complete plan, as markdown, starting with a # heading that names it."
245
+ } },
246
+ output: {
247
+ schema: {
248
+ type: "object",
249
+ additionalProperties: false,
250
+ properties: { approved: {
251
+ type: "boolean",
252
+ required: true
253
+ } }
254
+ },
255
+ render: (_args, { approved }) => [{
256
+ type: "text",
257
+ text: approved ? "Plan approved — plan mode exited; carry out the plan starting with your next step." : "The user dismissed the plan review to reply in their own words; plan mode remains active."
258
+ }]
259
+ },
260
+ execute: async (args, exec) => {
261
+ const agent = exec.agent;
262
+ if (agent === void 0 || !this.loggedActive(agent.session)) throw new Error(`${EXIT_PLAN_MODE} is only available in plan mode`);
263
+ if (!/^#\s+\S/.test(args.plan.trim())) throw new Error(`${EXIT_PLAN_MODE} requires a non-empty markdown plan starting with a # heading`);
264
+ const interaction = ctx.get("userQuestions");
265
+ if (interaction === void 0) throw new Error("no user-questions channel is available to review the plan; ask the user to switch the session mode instead");
266
+ let answer;
267
+ try {
268
+ answer = await interaction.ask({
269
+ questions: [{
270
+ id: REVIEW_ID,
271
+ header: "Plan review",
272
+ question: "Approve this plan and leave plan mode?",
273
+ detail: args.plan,
274
+ options: [{
275
+ label: APPROVE_LABEL,
276
+ description: "Leave plan mode; the plan is carried out from the next step."
277
+ }, {
278
+ label: KEEP_PLANNING_LABEL,
279
+ description: "Stay in plan mode; feedback goes back to the model."
280
+ }],
281
+ intent: {
282
+ kind: "plan-review",
283
+ approve: APPROVE_LABEL,
284
+ callId: exec.callId
285
+ }
286
+ }],
287
+ agent,
288
+ signal: exec.signal
289
+ });
290
+ } catch (cause) {
291
+ if (cause instanceof UserQuestionError && cause.code === "ASK_CANCELLED") {
292
+ exec.concludeTurn();
293
+ return { approved: false };
294
+ }
295
+ throw cause;
296
+ }
297
+ if (disposed) throw new Error("the plan-mode service was reloaded while the plan was under review; present the plan again");
298
+ const reviewItems = answer.answers.filter((entry) => entry.id === REVIEW_ID);
299
+ const item = reviewItems.length === 1 ? reviewItems[0] : void 0;
300
+ if (item?.selected.length !== 1 || item.selected[0] !== APPROVE_LABEL || item.custom !== void 0) {
301
+ const feedback = item?.custom ?? "";
302
+ throw new Error(feedback === "" ? "The user chose to keep planning; revise the plan and present it again." : `The user chose to keep planning; their feedback: ${feedback}`);
303
+ }
304
+ this.pendingIntents.set(agent.session, {
305
+ active: false,
306
+ narrate: false
307
+ });
308
+ return { approved: true };
309
+ },
310
+ presentCall: (args) => ({
311
+ card: "generic",
312
+ title: firstHeading(args.plan) ?? "Plan",
313
+ kind: "other",
314
+ content: [{
315
+ type: "text",
316
+ text: args.plan
317
+ }]
318
+ }),
319
+ presentResult: (_args, result) => ({
320
+ card: "generic",
321
+ title: "Plan review",
322
+ content: result.content
323
+ })
324
+ }), { when: ({ agent }) => this.selectedActive(agent.session) || this.planState(agent.session).entered });
325
+ }
326
+ loggedActive(session) {
327
+ return this.planState(session).active;
328
+ }
329
+ /** The state a proposed step presents: a pending selection, else the logged state. */
330
+ selectedActive(session) {
331
+ return this.pendingIntents.get(session)?.active ?? this.loggedActive(session);
332
+ }
333
+ hasOpenTurn(session) {
334
+ return this.ctx.agents.turnBoundaryOf(session).openTurnStartSeq !== null;
335
+ }
336
+ loggedActiveAtLastHeader(session) {
337
+ return this.planState(session).activeAtLastHeader ?? void 0;
338
+ }
339
+ planState(session) {
340
+ if (this.planProjectionHandle === void 0) throw new Error("plan mode is not ready; await plugin activation before running an agent");
341
+ return this.planProjectionHandle.stateOf(session);
342
+ }
343
+ /**
344
+ * Read the logged plan state and any selected state awaiting the next
345
+ * accepted in-turn pre-step.
346
+ *
347
+ * @param agent The agent to read.
348
+ * @returns Current logged state plus a pending selection, when present.
349
+ */
350
+ get(agent) {
351
+ const active = this.loggedActive(agent.session);
352
+ const pending = this.pendingIntents.get(agent.session);
353
+ return pending === void 0 ? { active } : {
354
+ active,
355
+ pending: pending.active
356
+ };
357
+ }
358
+ /**
359
+ * Select whether plan mode should be active. Between turns the method
360
+ * appends the change immediately because no in-turn pre-step will run until
361
+ * another prompt starts a turn. The open-turn fold is the idle signal:
362
+ * agent status stays `running` through post-turn checkpointing, when no
363
+ * further in-turn pre-step runs. During an open turn the selection remains
364
+ * pending until the next accepted in-turn pre-step. Repeated selection of
365
+ * the current or already-pending state is a no-op.
366
+ *
367
+ * @param agent The agent to switch.
368
+ * @param active Whether plan mode should be active.
369
+ * @returns what happened: `committed` (logged now), `queued` (awaiting the
370
+ * next accepted in-turn pre-step), `cancelled` (an opposite pending selection
371
+ * was cleared; the logged state already matches), or `noop` (already in that
372
+ * state).
373
+ */
374
+ set(agent, active) {
375
+ const session = agent.session;
376
+ if (active === (this.pendingIntents.get(session)?.active ?? this.loggedActive(session))) return "noop";
377
+ if (this.hasOpenTurn(session)) {
378
+ this.pendingIntents.set(session, {
379
+ active,
380
+ narrate: true
381
+ });
382
+ return this.loggedActive(session) === active ? "cancelled" : "queued";
383
+ }
384
+ if (active === this.loggedActive(session)) {
385
+ this.pendingIntents.delete(session);
386
+ return "cancelled";
387
+ }
388
+ session.append("plan/mode", { active });
389
+ this.pendingIntents.delete(session);
390
+ const narration = this.narration(session, active);
391
+ if (narration !== void 0) agent.inject(narration);
392
+ return "committed";
393
+ }
394
+ /** Append one pending selection before the next request assembly. */
395
+ onBoundary(session) {
396
+ const pending = this.pendingIntents.get(session);
397
+ if (pending === void 0) return;
398
+ const target = pending.active;
399
+ if (target === this.loggedActive(session)) {
400
+ this.pendingIntents.delete(session);
401
+ return;
402
+ }
403
+ session.append("plan/mode", { active: target });
404
+ this.pendingIntents.delete(session);
405
+ }
406
+ /** Build a user-switch notice when the last logged header described the other mode. */
407
+ narration(session, target) {
408
+ const told = this.loggedActiveAtLastHeader(session);
409
+ if (told === void 0 || told === target) return;
410
+ const text = target ? "The user switched this session to plan mode." : "The user switched this session back to the default mode.";
411
+ return createUserMessage({
412
+ content: [{
413
+ type: "text",
414
+ text
415
+ }],
416
+ source: {
417
+ kind: "plan-mode",
418
+ form: "notice",
419
+ summary: text
420
+ }
421
+ });
422
+ }
423
+ };
424
+ //#endregion
425
+ export { EXIT_PLAN_MODE, PlanModeController, PlanModeController as default, planProjectionDefinition, resolveConfig };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Client-namespace projection of the plan domain: a pure re-export of the package's
3
+ * types outlet. Client code imports ONLY the client namespace (repo
4
+ * discipline), so `./client` projects the same single-source content
5
+ * `./types` serves to host consumers — zero duplication.
6
+ *
7
+ * @module @unieai/rabi-plan-mode/client
8
+ */
9
+ export type * from './types.ts';
10
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Client-namespace projection of the plan domain: a pure re-export of the package's
3
+ * types outlet. Client code imports ONLY the client namespace (repo
4
+ * discipline), so `./client` projects the same single-source content
5
+ * `./types` serves to host consumers — zero duplication.
6
+ *
7
+ * @module @unieai/rabi-plan-mode/client
8
+ */
9
+ export {};
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Plan mode is logged per-agent collaboration state: while active, a
3
+ * deployment-owned guidance section is included in each model request, and
4
+ * `exit_plan_mode` presents the completed plan for user review, while the
5
+ * `/plan off` command lets a user leave directly. Sandbox mode and approval
6
+ * policy enforce restrictions independently and do not read or write plan
7
+ * state.
8
+ *
9
+ * The `plan` projection folds the session log, so resume and fork restore the
10
+ * state. User selections remain pending until the next accepted in-turn
11
+ * pre-step. The service includes the selected state in the proposed step
12
+ * assembly, then appends `plan/mode` from `agent/pre-step` only when the step
13
+ * is accepted. Same-step request retries reuse their assembly.
14
+ *
15
+ * The exit tool is disclosed progressively: it is admitted from the first step
16
+ * whose selected state is active and stays admitted for the rest of the
17
+ * Session, so leaving plan mode changes only the guidance section. Native
18
+ * declarations, PTC bindings, and execution share that admission.
19
+ *
20
+ * See packages/plan/plan-mode/README.md.
21
+ *
22
+ * @module @unieai/rabi-plan-mode
23
+ */
24
+ import { Context, Service } from '@unieai/cordis';
25
+ import { z as zod } from 'zod';
26
+ import type { Agent } from '@unieai/rabi-agent';
27
+ import type { ContextFormed } from '@unieai/rabi-llm';
28
+ import type { PlanProjection, PlanUnitState } from './types.ts';
29
+ declare module '@unieai/rabi-llm' {
30
+ interface MessageSourceMap {
31
+ 'plan-mode': {
32
+ kind: 'plan-mode';
33
+ } & ContextFormed;
34
+ }
35
+ }
36
+ export type * from './types.ts';
37
+ declare module '@unieai/rabi-session/types' {
38
+ interface SessionEventMap {
39
+ /**
40
+ * Whether plan mode is in force from this point on: log-only, non-surface,
41
+ * whole-value replace. The last `plan/mode` wins; a log with none folds to
42
+ * inactive through the projection unit's fold.
43
+ */
44
+ 'plan/mode': {
45
+ active: boolean;
46
+ };
47
+ }
48
+ }
49
+ declare module '@unieai/cordis' {
50
+ interface Context {
51
+ planMode: PlanModeController;
52
+ }
53
+ }
54
+ /** The model-facing exit tool's name, admitted once the Session enters plan mode. */
55
+ export declare const EXIT_PLAN_MODE = "exit_plan_mode";
56
+ /** Deployment-owned plan guidance. */
57
+ export interface PlanModeConfig {
58
+ /** Guidance rendered as the `plan:policy` prompt section while plan mode is active. */
59
+ section: string;
60
+ }
61
+ /**
62
+ * Validate deployment-owned plan guidance. Missing, blank, non-string, or
63
+ * unknown fields fail at plugin load rather than being ignored.
64
+ *
65
+ * @param config Raw plugin config.
66
+ * @returns A detached validated config.
67
+ */
68
+ export declare function resolveConfig(config: PlanModeConfig): PlanModeConfig;
69
+ /** Projection of logged plan selections and committed mode. */
70
+ export declare const planProjectionDefinition: {
71
+ key: "plan";
72
+ stateVersion: number;
73
+ stateSchema: zod.ZodType<PlanUnitState, unknown, zod.core.$ZodTypeInternals<PlanUnitState, unknown>>;
74
+ init: () => {
75
+ active: false;
76
+ wanted: null;
77
+ running: null;
78
+ activeAtLastHeader: null;
79
+ entered: false;
80
+ };
81
+ apply: (state: NoInfer<PlanUnitState>, event: import("@unieai/rabi-session").SessionEvent) => PlanUnitState;
82
+ wire: {
83
+ viewSchema: zod.ZodType<PlanProjection, unknown, zod.core.$ZodTypeInternals<PlanProjection, unknown>>;
84
+ view: (state: NoInfer<PlanUnitState>) => {
85
+ active: boolean;
86
+ pending: boolean;
87
+ };
88
+ };
89
+ };
90
+ /**
91
+ * `ctx.planMode`: owns logged plan state, applies and narrates selected state at step start,
92
+ * the `plan:policy` section, the `/plan` command, and the conditional exit tool.
93
+ * Client carriers expose the projection's cropped `{ active, pending }` view.
94
+ * Agent prompt assembly fails while the projection reader is not ready;
95
+ * callers must await plugin activation before running an agent.
96
+ */
97
+ export declare class PlanModeController extends Service {
98
+ static inject: string[];
99
+ /** Validated deployment-owned guidance. */
100
+ private readonly section;
101
+ private planProjectionHandle;
102
+ /**
103
+ * Latest selection per session awaiting the next accepted in-turn pre-step.
104
+ * `narrate` is true for user selections and false for the exit tool, whose
105
+ * result already narrates the transition.
106
+ */
107
+ private readonly pendingIntents;
108
+ constructor(ctx: Context, config?: PlanModeConfig);
109
+ protected [Service.init](): Promise<void>;
110
+ private loggedActive;
111
+ /** The state a proposed step presents: a pending selection, else the logged state. */
112
+ private selectedActive;
113
+ private hasOpenTurn;
114
+ private loggedActiveAtLastHeader;
115
+ private planState;
116
+ /**
117
+ * Read the logged plan state and any selected state awaiting the next
118
+ * accepted in-turn pre-step.
119
+ *
120
+ * @param agent The agent to read.
121
+ * @returns Current logged state plus a pending selection, when present.
122
+ */
123
+ get(agent: Agent): {
124
+ active: boolean;
125
+ pending?: boolean;
126
+ };
127
+ /**
128
+ * Select whether plan mode should be active. Between turns the method
129
+ * appends the change immediately because no in-turn pre-step will run until
130
+ * another prompt starts a turn. The open-turn fold is the idle signal:
131
+ * agent status stays `running` through post-turn checkpointing, when no
132
+ * further in-turn pre-step runs. During an open turn the selection remains
133
+ * pending until the next accepted in-turn pre-step. Repeated selection of
134
+ * the current or already-pending state is a no-op.
135
+ *
136
+ * @param agent The agent to switch.
137
+ * @param active Whether plan mode should be active.
138
+ * @returns what happened: `committed` (logged now), `queued` (awaiting the
139
+ * next accepted in-turn pre-step), `cancelled` (an opposite pending selection
140
+ * was cleared; the logged state already matches), or `noop` (already in that
141
+ * state).
142
+ */
143
+ set(agent: Agent, active: boolean): 'committed' | 'queued' | 'cancelled' | 'noop';
144
+ /** Append one pending selection before the next request assembly. */
145
+ private onBoundary;
146
+ /** Build a user-switch notice when the last logged header described the other mode. */
147
+ private narration;
148
+ }
149
+ export default PlanModeController;
150
+ //# sourceMappingURL=index.d.ts.map