@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 +21 -0
- package/README.md +7 -2
- package/lib/index.js +425 -0
- package/lib/types/client.d.ts +10 -0
- package/lib/types/client.js +9 -0
- package/lib/types/index.d.ts +150 -0
- package/lib/types/index.js +424 -0
- package/lib/types/types.d.ts +45 -0
- package/lib/types/types.js +10 -0
- package/locale/de.json +6 -0
- package/locale/en.json +5 -0
- package/locale/es.json +6 -0
- package/locale/fr.json +6 -0
- package/locale/ja.json +6 -0
- package/locale/pt.json +6 -0
- package/locale/ru.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +57 -4
- package/src/client.ts +10 -0
- package/src/index.ts +483 -0
- package/src/types.ts +45 -0
|
@@ -0,0 +1,424 @@
|
|
|
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 { Service } from '@unieai/cordis';
|
|
25
|
+
import { brandString } from '@unieai/rabi-brand';
|
|
26
|
+
import { z as zod } from 'zod';
|
|
27
|
+
import { createUserMessage } from '@unieai/rabi-llm';
|
|
28
|
+
import { defineTool } from '@unieai/rabi-tools';
|
|
29
|
+
import { UserQuestionError } from '@unieai/rabi-user-questions';
|
|
30
|
+
/** The model-facing exit tool's name, admitted once the Session enters plan mode. */
|
|
31
|
+
export const EXIT_PLAN_MODE = 'exit_plan_mode';
|
|
32
|
+
/** The review question's id, echoed in the answer this tool reads. */
|
|
33
|
+
const REVIEW_ID = 'plan-review';
|
|
34
|
+
/** The review question's approve option label. */
|
|
35
|
+
const APPROVE_LABEL = 'Approve';
|
|
36
|
+
/** The review question's keep-planning option label. */
|
|
37
|
+
const KEEP_PLANNING_LABEL = 'Keep planning';
|
|
38
|
+
const EXIT_DESCRIPTION = 'Use only in plan mode. Present your plan for the user\'s review and, on approval, leave plan mode. '
|
|
39
|
+
+ 'The user may approve (carry out the plan from your next step) or keep '
|
|
40
|
+
+ 'planning — their feedback comes back in the tool result; revise and present again.';
|
|
41
|
+
/** The plan's first markdown heading (any level), or `undefined` when it has none. */
|
|
42
|
+
function firstHeading(plan) {
|
|
43
|
+
for (const line of plan.split('\n')) {
|
|
44
|
+
const match = /^#{1,6}\s+(.+?)\s*$/.exec(line);
|
|
45
|
+
if (match)
|
|
46
|
+
return match[1];
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Validate deployment-owned plan guidance. Missing, blank, non-string, or
|
|
52
|
+
* unknown fields fail at plugin load rather than being ignored.
|
|
53
|
+
*
|
|
54
|
+
* @param config Raw plugin config.
|
|
55
|
+
* @returns A detached validated config.
|
|
56
|
+
*/
|
|
57
|
+
export function resolveConfig(config) {
|
|
58
|
+
const section = config.section;
|
|
59
|
+
if (typeof section !== 'string') {
|
|
60
|
+
throw new Error('PlanModeConfig needs a string `section`');
|
|
61
|
+
}
|
|
62
|
+
if (section.trim() === '') {
|
|
63
|
+
throw new Error('PlanModeConfig needs a non-empty `section`');
|
|
64
|
+
}
|
|
65
|
+
const unknown = Object.keys(config).filter(key => key !== 'section');
|
|
66
|
+
if (unknown.length > 0) {
|
|
67
|
+
throw new Error(`PlanModeConfig has unknown key(s) ${unknown.join(', ')} — config is { section }`);
|
|
68
|
+
}
|
|
69
|
+
return { section };
|
|
70
|
+
}
|
|
71
|
+
const planUnitStateSchema = zod.object({
|
|
72
|
+
active: zod.boolean(),
|
|
73
|
+
wanted: zod.boolean().nullable(),
|
|
74
|
+
running: zod.object({
|
|
75
|
+
commandId: zod.string(),
|
|
76
|
+
wanted: zod.boolean(),
|
|
77
|
+
}).strict().nullable(),
|
|
78
|
+
activeAtLastHeader: zod.boolean().nullable(),
|
|
79
|
+
entered: zod.boolean(),
|
|
80
|
+
}).strict();
|
|
81
|
+
/** Wire payload schema of the `plan` projection. */
|
|
82
|
+
const planProjectionSchema = zod.object({
|
|
83
|
+
active: zod.boolean(),
|
|
84
|
+
pending: zod.boolean(),
|
|
85
|
+
});
|
|
86
|
+
/** Projection of logged plan selections and committed mode. */
|
|
87
|
+
export const planProjectionDefinition = {
|
|
88
|
+
key: 'plan',
|
|
89
|
+
stateVersion: 4,
|
|
90
|
+
stateSchema: planUnitStateSchema,
|
|
91
|
+
init: () => ({ active: false, wanted: null, running: null, activeAtLastHeader: null, entered: false }),
|
|
92
|
+
apply: (state, event) => {
|
|
93
|
+
if (event.type === 'command/run' && event.data.name === 'plan') {
|
|
94
|
+
if (event.data.args === undefined)
|
|
95
|
+
return state;
|
|
96
|
+
const wanted = event.data.args.trim() !== 'off';
|
|
97
|
+
return { ...state, running: { commandId: event.data.commandId, wanted } };
|
|
98
|
+
}
|
|
99
|
+
if (event.type === 'command/done' && event.data.commandId === state.running?.commandId) {
|
|
100
|
+
const wanted = event.data.kind === 'success' && state.running.wanted !== state.active
|
|
101
|
+
? state.running.wanted
|
|
102
|
+
: null;
|
|
103
|
+
return { ...state, wanted, running: null };
|
|
104
|
+
}
|
|
105
|
+
if (event.type === 'plan/mode') {
|
|
106
|
+
return { ...state, active: event.data.active, wanted: null, entered: state.entered || event.data.active };
|
|
107
|
+
}
|
|
108
|
+
if (event.type === 'request/header') {
|
|
109
|
+
return { ...state, activeAtLastHeader: state.active };
|
|
110
|
+
}
|
|
111
|
+
return state;
|
|
112
|
+
},
|
|
113
|
+
wire: {
|
|
114
|
+
viewSchema: planProjectionSchema,
|
|
115
|
+
view: (state) => {
|
|
116
|
+
const wanted = state.running?.wanted ?? state.wanted;
|
|
117
|
+
return { active: state.active, pending: wanted !== null && wanted !== state.active };
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* `ctx.planMode`: owns logged plan state, applies and narrates selected state at step start,
|
|
123
|
+
* the `plan:policy` section, the `/plan` command, and the conditional exit tool.
|
|
124
|
+
* Client carriers expose the projection's cropped `{ active, pending }` view.
|
|
125
|
+
* Agent prompt assembly fails while the projection reader is not ready;
|
|
126
|
+
* callers must await plugin activation before running an agent.
|
|
127
|
+
*/
|
|
128
|
+
export class PlanModeController extends Service {
|
|
129
|
+
static inject = ['tools', 'systemPrompt', 'sessionProjections', 'agents'];
|
|
130
|
+
/** Validated deployment-owned guidance. */
|
|
131
|
+
section;
|
|
132
|
+
planProjectionHandle;
|
|
133
|
+
/**
|
|
134
|
+
* Latest selection per session awaiting the next accepted in-turn pre-step.
|
|
135
|
+
* `narrate` is true for user selections and false for the exit tool, whose
|
|
136
|
+
* result already narrates the transition.
|
|
137
|
+
*/
|
|
138
|
+
pendingIntents = new WeakMap();
|
|
139
|
+
constructor(ctx, config = { section: '' }) {
|
|
140
|
+
super(ctx, 'planMode');
|
|
141
|
+
this.section = resolveConfig(config).section;
|
|
142
|
+
}
|
|
143
|
+
async [Service.init]() {
|
|
144
|
+
const ctx = this.ctx;
|
|
145
|
+
ctx.systemPrompt.section({
|
|
146
|
+
name: 'plan:policy',
|
|
147
|
+
order: ctx.systemPrompt.getSectionOrder('PLAN_POLICY'),
|
|
148
|
+
text: (context) => {
|
|
149
|
+
if (context.agent === undefined)
|
|
150
|
+
return '';
|
|
151
|
+
return this.selectedActive(context.agent.session) ? this.section : '';
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
this.planProjectionHandle = await ctx.sessionProjections.register(planProjectionDefinition);
|
|
155
|
+
let disposed = false;
|
|
156
|
+
// Pre-step is outside Session.append publication, so it can append the
|
|
157
|
+
// log-only mode event inside an open turn without re-entering the session.
|
|
158
|
+
// A failed append remains pending for a later accepted in-turn pre-step,
|
|
159
|
+
// and policy cannot block the step.
|
|
160
|
+
ctx.on('agent/pre-step', async ({ agent, signal }, next) => {
|
|
161
|
+
const decision = await next();
|
|
162
|
+
const pending = this.pendingIntents.get(agent.session);
|
|
163
|
+
if (decision.kind === 'reject' || signal.aborted || pending === undefined)
|
|
164
|
+
return decision;
|
|
165
|
+
const narration = this.narration(agent.session, pending.active);
|
|
166
|
+
try {
|
|
167
|
+
this.onBoundary(agent.session);
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
ctx.logger.warn('rabi-plan-mode: failed to append selected plan mode at step start: %o', error);
|
|
171
|
+
return decision;
|
|
172
|
+
}
|
|
173
|
+
return !pending.narrate || narration === undefined
|
|
174
|
+
? decision
|
|
175
|
+
: { ...decision, messages: [...decision.messages, narration] };
|
|
176
|
+
});
|
|
177
|
+
ctx.effect(() => () => { disposed = true; }, 'rabi-plan-mode: close service lifetime');
|
|
178
|
+
// The command child activates only when a command registry is composed.
|
|
179
|
+
ctx.inject(['commands'], (commandCtx) => {
|
|
180
|
+
commandCtx.commands.register({
|
|
181
|
+
definitionId: brandString('@unieai/rabi-plan-mode'),
|
|
182
|
+
name: 'plan',
|
|
183
|
+
description: 'Enter or leave plan mode',
|
|
184
|
+
input: { hint: '[off|message]', attachments: true },
|
|
185
|
+
handler: ({ agent, rawInput, attachments }) => {
|
|
186
|
+
const message = rawInput.trim();
|
|
187
|
+
if (message === 'off' && attachments.length > 0) {
|
|
188
|
+
return { kind: 'error', text: 'Attachments cannot accompany /plan off.' };
|
|
189
|
+
}
|
|
190
|
+
if (message === 'off') {
|
|
191
|
+
switch (this.set(agent, false)) {
|
|
192
|
+
case 'committed':
|
|
193
|
+
return { kind: 'success', text: 'Plan mode off.' };
|
|
194
|
+
case 'queued':
|
|
195
|
+
return { kind: 'success', text: 'Leaving plan mode (applies from the next step).' };
|
|
196
|
+
case 'cancelled':
|
|
197
|
+
return { kind: 'success', text: 'Plan mode entry cancelled.' };
|
|
198
|
+
case 'noop':
|
|
199
|
+
// Repeat the queued wording while an exit still awaits the
|
|
200
|
+
// next accepted pre-step; only a truly inactive session reads
|
|
201
|
+
// idempotent.
|
|
202
|
+
return this.loggedActive(agent.session)
|
|
203
|
+
? { kind: 'success', text: 'Leaving plan mode (applies from the next step).' }
|
|
204
|
+
: { kind: 'success', text: 'Plan mode is already inactive.' };
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const outcome = this.set(agent, true);
|
|
208
|
+
if (message !== '' || attachments.length > 0) {
|
|
209
|
+
agent.steer(createUserMessage({
|
|
210
|
+
content: [
|
|
211
|
+
...attachments,
|
|
212
|
+
...(message === '' ? [] : [{ type: 'text', text: message }]),
|
|
213
|
+
],
|
|
214
|
+
source: { kind: 'user' },
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
kind: 'success',
|
|
219
|
+
text: outcome === 'committed'
|
|
220
|
+
? 'Plan mode on. Use /plan off to leave.'
|
|
221
|
+
: 'Entering plan mode (applies from the next step). Use /plan off to leave.',
|
|
222
|
+
};
|
|
223
|
+
},
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
ctx.tools.register(defineTool({
|
|
227
|
+
name: EXIT_PLAN_MODE,
|
|
228
|
+
description: EXIT_DESCRIPTION,
|
|
229
|
+
parameters: {
|
|
230
|
+
plan: { type: 'string', required: true, description: 'The complete plan, as markdown, starting with a # heading that names it.' },
|
|
231
|
+
},
|
|
232
|
+
output: {
|
|
233
|
+
schema: {
|
|
234
|
+
type: 'object',
|
|
235
|
+
additionalProperties: false,
|
|
236
|
+
properties: {
|
|
237
|
+
approved: { type: 'boolean', required: true },
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
render: (_args, { approved }) => [{
|
|
241
|
+
type: 'text',
|
|
242
|
+
text: approved
|
|
243
|
+
? 'Plan approved — plan mode exited; carry out the plan starting with your next step.'
|
|
244
|
+
: 'The user dismissed the plan review to reply in their own words; plan mode remains active.',
|
|
245
|
+
}],
|
|
246
|
+
},
|
|
247
|
+
execute: async (args, exec) => {
|
|
248
|
+
const agent = exec.agent;
|
|
249
|
+
// Admission outlives plan mode and follows the selected state, so check the committed state.
|
|
250
|
+
if (agent === undefined || !this.loggedActive(agent.session)) {
|
|
251
|
+
throw new Error(`${EXIT_PLAN_MODE} is only available in plan mode`);
|
|
252
|
+
}
|
|
253
|
+
if (!/^#\s+\S/.test(args.plan.trim())) {
|
|
254
|
+
throw new Error(`${EXIT_PLAN_MODE} requires a non-empty markdown plan starting with a # heading`);
|
|
255
|
+
}
|
|
256
|
+
const interaction = ctx.get('userQuestions');
|
|
257
|
+
if (interaction === undefined) {
|
|
258
|
+
throw new Error('no user-questions channel is available to review the plan; ask the user to switch the session mode instead');
|
|
259
|
+
}
|
|
260
|
+
let answer;
|
|
261
|
+
try {
|
|
262
|
+
answer = await interaction.ask({
|
|
263
|
+
questions: [{
|
|
264
|
+
id: REVIEW_ID,
|
|
265
|
+
header: 'Plan review',
|
|
266
|
+
question: 'Approve this plan and leave plan mode?',
|
|
267
|
+
detail: args.plan,
|
|
268
|
+
options: [
|
|
269
|
+
{ label: APPROVE_LABEL, description: 'Leave plan mode; the plan is carried out from the next step.' },
|
|
270
|
+
{ label: KEEP_PLANNING_LABEL, description: 'Stay in plan mode; feedback goes back to the model.' },
|
|
271
|
+
],
|
|
272
|
+
// Presentation only: a capable UI renders the plan as a review
|
|
273
|
+
// decision instead of a generic question, and answers with one of
|
|
274
|
+
// the labels above either way.
|
|
275
|
+
intent: { kind: 'plan-review', approve: APPROVE_LABEL, callId: exec.callId },
|
|
276
|
+
}],
|
|
277
|
+
agent,
|
|
278
|
+
signal: exec.signal,
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
catch (cause) {
|
|
282
|
+
// A dismissed review is not a failed one: the user took the turn back
|
|
283
|
+
// to say something the two options do not cover, so the turn ends
|
|
284
|
+
// here instead of spending a model request on waiting. An abort (turn
|
|
285
|
+
// cancel, provider teardown) keeps its own failure.
|
|
286
|
+
if (cause instanceof UserQuestionError && cause.code === 'ASK_CANCELLED') {
|
|
287
|
+
exec.concludeTurn();
|
|
288
|
+
return { approved: false };
|
|
289
|
+
}
|
|
290
|
+
throw cause;
|
|
291
|
+
}
|
|
292
|
+
// A review may outlive this plugin fiber. Without its pre-step listener,
|
|
293
|
+
// an approved selection could never be appended, so fail and keep planning.
|
|
294
|
+
if (disposed) {
|
|
295
|
+
throw new Error('the plan-mode service was reloaded while the plan was under review; present the plan again');
|
|
296
|
+
}
|
|
297
|
+
const reviewItems = answer.answers.filter(entry => entry.id === REVIEW_ID);
|
|
298
|
+
const item = reviewItems.length === 1 ? reviewItems[0] : undefined;
|
|
299
|
+
if (item?.selected.length !== 1 || item.selected[0] !== APPROVE_LABEL || item.custom !== undefined) {
|
|
300
|
+
const feedback = item?.custom ?? '';
|
|
301
|
+
throw new Error(feedback === ''
|
|
302
|
+
? 'The user chose to keep planning; revise the plan and present it again.'
|
|
303
|
+
: `The user chose to keep planning; their feedback: ${feedback}`);
|
|
304
|
+
}
|
|
305
|
+
// Keep plan guidance for the rest of this assistant tool batch. The
|
|
306
|
+
// silent selection is appended at the next accepted in-turn pre-step,
|
|
307
|
+
// before its request assembly.
|
|
308
|
+
this.pendingIntents.set(agent.session, { active: false, narrate: false });
|
|
309
|
+
return { approved: true };
|
|
310
|
+
},
|
|
311
|
+
presentCall: args => ({
|
|
312
|
+
card: 'generic',
|
|
313
|
+
title: firstHeading(args.plan) ?? 'Plan',
|
|
314
|
+
kind: 'other',
|
|
315
|
+
content: [{ type: 'text', text: args.plan }],
|
|
316
|
+
}),
|
|
317
|
+
presentResult: (_args, result) => ({
|
|
318
|
+
card: 'generic',
|
|
319
|
+
title: 'Plan review',
|
|
320
|
+
content: result.content,
|
|
321
|
+
}),
|
|
322
|
+
}), { when: ({ agent }) => this.selectedActive(agent.session) || this.planState(agent.session).entered });
|
|
323
|
+
}
|
|
324
|
+
loggedActive(session) {
|
|
325
|
+
return this.planState(session).active;
|
|
326
|
+
}
|
|
327
|
+
/** The state a proposed step presents: a pending selection, else the logged state. */
|
|
328
|
+
selectedActive(session) {
|
|
329
|
+
return this.pendingIntents.get(session)?.active ?? this.loggedActive(session);
|
|
330
|
+
}
|
|
331
|
+
hasOpenTurn(session) {
|
|
332
|
+
return this.ctx.agents.turnBoundaryOf(session).openTurnStartSeq !== null;
|
|
333
|
+
}
|
|
334
|
+
loggedActiveAtLastHeader(session) {
|
|
335
|
+
return this.planState(session).activeAtLastHeader ?? undefined;
|
|
336
|
+
}
|
|
337
|
+
planState(session) {
|
|
338
|
+
if (this.planProjectionHandle === undefined) {
|
|
339
|
+
throw new Error('plan mode is not ready; await plugin activation before running an agent');
|
|
340
|
+
}
|
|
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 === undefined ? { active } : { active, pending: pending.active };
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Select whether plan mode should be active. Between turns the method
|
|
357
|
+
* appends the change immediately because no in-turn pre-step will run until
|
|
358
|
+
* another prompt starts a turn. The open-turn fold is the idle signal:
|
|
359
|
+
* agent status stays `running` through post-turn checkpointing, when no
|
|
360
|
+
* further in-turn pre-step runs. During an open turn the selection remains
|
|
361
|
+
* pending until the next accepted in-turn pre-step. Repeated selection of
|
|
362
|
+
* the current or already-pending state is a no-op.
|
|
363
|
+
*
|
|
364
|
+
* @param agent The agent to switch.
|
|
365
|
+
* @param active Whether plan mode should be active.
|
|
366
|
+
* @returns what happened: `committed` (logged now), `queued` (awaiting the
|
|
367
|
+
* next accepted in-turn pre-step), `cancelled` (an opposite pending selection
|
|
368
|
+
* was cleared; the logged state already matches), or `noop` (already in that
|
|
369
|
+
* state).
|
|
370
|
+
*/
|
|
371
|
+
set(agent, active) {
|
|
372
|
+
const session = agent.session;
|
|
373
|
+
const pending = this.pendingIntents.get(session);
|
|
374
|
+
const target = pending?.active ?? this.loggedActive(session);
|
|
375
|
+
if (active === target)
|
|
376
|
+
return 'noop';
|
|
377
|
+
if (this.hasOpenTurn(session)) {
|
|
378
|
+
this.pendingIntents.set(session, { active, narrate: true });
|
|
379
|
+
return this.loggedActive(session) === active ? 'cancelled' : 'queued';
|
|
380
|
+
}
|
|
381
|
+
// No open turn: commit now. Delete only after append succeeds so a
|
|
382
|
+
// failed durable write leaves the selection retryable, not dropped.
|
|
383
|
+
if (active === this.loggedActive(session)) {
|
|
384
|
+
this.pendingIntents.delete(session);
|
|
385
|
+
return 'cancelled';
|
|
386
|
+
}
|
|
387
|
+
session.append('plan/mode', { active });
|
|
388
|
+
this.pendingIntents.delete(session);
|
|
389
|
+
const narration = this.narration(session, active);
|
|
390
|
+
if (narration !== undefined)
|
|
391
|
+
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 === undefined)
|
|
398
|
+
return;
|
|
399
|
+
const target = pending.active;
|
|
400
|
+
if (target === this.loggedActive(session)) {
|
|
401
|
+
this.pendingIntents.delete(session);
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
session.append('plan/mode', { active: target });
|
|
405
|
+
// Delete only after append succeeds so a later accepted in-turn pre-step
|
|
406
|
+
// can retry a failed durable write.
|
|
407
|
+
this.pendingIntents.delete(session);
|
|
408
|
+
}
|
|
409
|
+
/** Build a user-switch notice when the last logged header described the other mode. */
|
|
410
|
+
narration(session, target) {
|
|
411
|
+
const told = this.loggedActiveAtLastHeader(session);
|
|
412
|
+
if (told === undefined || told === target)
|
|
413
|
+
return;
|
|
414
|
+
const text = target
|
|
415
|
+
? 'The user switched this session to plan mode.'
|
|
416
|
+
: 'The user switched this session back to the default mode.';
|
|
417
|
+
return createUserMessage({
|
|
418
|
+
content: [{ type: 'text', text }],
|
|
419
|
+
// The narration is already one sentence, so it is its own summary.
|
|
420
|
+
source: { kind: 'plan-mode', form: 'notice', summary: text },
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
export default PlanModeController;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure types of the plan domain: the ONE home of the `plan` projection-key
|
|
3
|
+
* declaration, free of this package's host-side value imports (cordis,
|
|
4
|
+
* rabi-tools, rabi-agent). Two namespace projections serve it — `./types` for
|
|
5
|
+
* host consumers and `./client` for client aggregates — with zero content
|
|
6
|
+
* duplication.
|
|
7
|
+
*
|
|
8
|
+
* @module @unieai/rabi-plan-mode/types
|
|
9
|
+
*/
|
|
10
|
+
import type { CommandId } from '@unieai/rabi-commands/brand';
|
|
11
|
+
/**
|
|
12
|
+
* The plan projection's wire value. `active` is the logged state in force
|
|
13
|
+
* (the last `plan/mode`, inactive before the first); `pending` is true while
|
|
14
|
+
* a logged `/plan` selection targets a state other than `active`, has not
|
|
15
|
+
* failed through its paired `command/done`, and no later `plan/mode` event has
|
|
16
|
+
* recorded that state. Capability absence (plan-mode not composed) is the
|
|
17
|
+
* key's absence, never a value.
|
|
18
|
+
*/
|
|
19
|
+
export interface PlanProjection {
|
|
20
|
+
active: boolean;
|
|
21
|
+
pending: boolean;
|
|
22
|
+
}
|
|
23
|
+
/** Host state used to derive {@link PlanProjection}. */
|
|
24
|
+
export interface PlanUnitState {
|
|
25
|
+
/** Logged plan mode. */
|
|
26
|
+
active: boolean;
|
|
27
|
+
/** The selection's target mode; null when no selection is outstanding. */
|
|
28
|
+
wanted: boolean | null;
|
|
29
|
+
/** The latest plan command awaiting its paired settlement. */
|
|
30
|
+
running: {
|
|
31
|
+
commandId: CommandId;
|
|
32
|
+
wanted: boolean;
|
|
33
|
+
} | null;
|
|
34
|
+
/** Active state recorded by the latest `request/header`, or null. */
|
|
35
|
+
activeAtLastHeader: boolean | null;
|
|
36
|
+
/** Whether a logged `plan/mode` has ever activated plan mode in this Session. */
|
|
37
|
+
entered: boolean;
|
|
38
|
+
}
|
|
39
|
+
declare module '@unieai/rabi-session-projection/types' {
|
|
40
|
+
interface SessionProjectionMap {
|
|
41
|
+
/** Plan collaboration state folded from the plan command lifecycle and `plan/mode` events. */
|
|
42
|
+
plan: PlanProjection;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure types of the plan domain: the ONE home of the `plan` projection-key
|
|
3
|
+
* declaration, free of this package's host-side value imports (cordis,
|
|
4
|
+
* rabi-tools, rabi-agent). Two namespace projections serve it — `./types` for
|
|
5
|
+
* host consumers and `./client` for client aggregates — with zero content
|
|
6
|
+
* duplication.
|
|
7
|
+
*
|
|
8
|
+
* @module @unieai/rabi-plan-mode/types
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
package/locale/de.json
ADDED
package/locale/en.json
ADDED
package/locale/es.json
ADDED
package/locale/fr.json
ADDED
package/locale/ja.json
ADDED
package/locale/pt.json
ADDED
package/locale/ru.json
ADDED
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unieai/rabi-plan-mode",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"description": "Logged per-agent plan mode with deployment guidance, a direct slash command, and a user-reviewed exit",
|
|
4
|
+
"version": "0.2.2-rc.5",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "lib/index.js",
|
|
10
|
+
"types": "lib/types/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./lib/types/index.d.ts",
|
|
14
|
+
"default": "./lib/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./types": {
|
|
17
|
+
"types": "./lib/types/types.d.ts",
|
|
18
|
+
"default": "./lib/types/types.js"
|
|
19
|
+
},
|
|
20
|
+
"./client": {
|
|
21
|
+
"types": "./lib/types/client.d.ts",
|
|
22
|
+
"default": "./lib/types/client.js"
|
|
23
|
+
},
|
|
24
|
+
"./src/*": "./src/*",
|
|
25
|
+
"./package.json": "./package.json",
|
|
26
|
+
"./locale/*.json": "./locale/*.json"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"locale/*.json",
|
|
30
|
+
"lib/index.js",
|
|
31
|
+
"lib/types/**/*.js",
|
|
32
|
+
"lib/types/**/*.d.ts",
|
|
33
|
+
"lib/types/**/*.d.ts.map",
|
|
34
|
+
"lib/**/*.js.map",
|
|
35
|
+
"src",
|
|
36
|
+
"README.md"
|
|
37
|
+
],
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@unieai/rabi-agent": "0.2.2-rc.5",
|
|
41
|
+
"@unieai/rabi-commands": "0.2.2-rc.5",
|
|
42
|
+
"@unieai/rabi-llm": "0.2.2-rc.5",
|
|
43
|
+
"@unieai/rabi-session": "0.2.2-rc.5",
|
|
44
|
+
"@unieai/rabi-session-projection": "0.2.2-rc.5",
|
|
45
|
+
"@unieai/rabi-system-prompt": "0.2.2-rc.5",
|
|
46
|
+
"@unieai/rabi-tools": "0.2.2-rc.5",
|
|
47
|
+
"@unieai/rabi-user-questions": "0.2.2-rc.5",
|
|
48
|
+
"@unieai/cordis": "4.1.0"
|
|
49
|
+
},
|
|
50
|
+
"peerDependenciesMeta": {
|
|
51
|
+
"@unieai/rabi-commands": {
|
|
52
|
+
"optional": true
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@unieai/rabi-brand": "0.2.2-rc.5",
|
|
57
|
+
"zod": "4.6.6"
|
|
58
|
+
}
|
|
59
|
+
}
|
package/src/client.ts
ADDED
|
@@ -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
|
+
|
|
10
|
+
export type * from './types.ts'
|