返回 CodeWhale
handler.rs
根目录 / crates / command-contract / src / handler.rs
1 //! Generic handler transport for staged command migration.
2 //!
3 //! The output type is generic so FEAT-014 does not move or duplicate the
4 //! TUI-owned `CommandResult`. During in-place adoption, the TUI instantiates
5 //! `CommandHandler<crate::commands::CommandResult>`.
6
7 use crate::facets::{
8 CommandBackgroundContext, CommandComposerContext, CommandConfigStatusContext,
9 CommandCostContext, CommandDebugChangeContext, CommandDebugDiagnosticsContext,
10 CommandDebugDiffContext, CommandDebugHistoryContext, CommandDebugReceiptsContext,
11 CommandDebugUndoContext, CommandMediaContext, CommandMemoryContext, CommandModePolicyContext,
12 CommandModelContext, CommandPermissionsContext, CommandPluginContext,
13 CommandPresentationContext, CommandProjectContext, CommandSessionContext,
14 CommandSessionControlContext, CommandSessionExportContext, CommandSessionLifecycleContext,
15 CommandSessionStructcopyContext, CommandSkillGroupContext, CommandSkillsContext,
16 CommandSystemPromptContext, CommandWorkspaceContext,
17 };
18
19 /// Exact host capabilities exposed to one contextual command handler.
20 ///
21 /// The set lives in the external contract crate so command registrations can
22 /// declare least authority without naming the TUI host. The dispatcher uses
23 /// the declaration to populate only those slots in [`CommandContexts`].
24 #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
25 pub struct CommandCapabilities(u64);
26
27 impl CommandCapabilities {
28 pub const NONE: Self = Self(0);
29 pub const SESSION: Self = Self(1 << 0);
30 pub const MODEL: Self = Self(1 << 1);
31 pub const COST: Self = Self(1 << 2);
32 pub const MODE_POLICY: Self = Self(1 << 3);
33 pub const SYSTEM_PROMPT: Self = Self(1 << 4);
34 pub const SKILLS: Self = Self(1 << 5);
35 pub const WORKSPACE: Self = Self(1 << 6);
36 pub const PRESENTATION: Self = Self(1 << 7);
37 pub const MEDIA: Self = Self(1 << 8);
38 /// Memory-group host data (FEAT-019 D1).
39 pub const MEMORY: Self = Self(1 << 9);
40 /// Project-group host data (FEAT-021 D1).
41 pub const PROJECT: Self = Self(1 << 10);
42 /// Skills-group host data (FEAT-022 D1).
43 pub const SKILL_GROUP: Self = Self(1 << 11);
44 /// Plugin-group host data (FEAT-020 D1), appended after current main capabilities.
45 pub const PLUGIN: Self = Self(1 << 12);
46 /// Session-lifecycle host data (FEAT-023 D3), the next non-conflicting bit
47 /// after `PLUGIN`. Required only by the seven host-dependent lifecycle
48 /// commands; `/compact` and `/purge` remain pure. Never widened by the
49 /// basic session capability.
50 pub const SESSION_LIFECYCLE: Self = Self(1 << 13);
51 /// Session-control host data (FEAT-024 D3), the next non-conflicting bit
52 /// after `SESSION_LIFECYCLE`. Required only by the seven host-dependent
53 /// control commands (`/relay`, `/rename`, `/resume`, `/rc`, `/remote-env`,
54 /// `/title`, `/color`); `/remote-env` and `/color` also declare
55 /// `PRESENTATION`. Bit 14 fit the
56 /// original `u16` backing without speculative widening in FEAT-023.
57 pub const SESSION_CONTROL: Self = Self(1 << 14);
58 /// Session-export host data (FEAT-025 D1), the next non-conflicting bit
59 /// after `SESSION_CONTROL`. Used by `/export`, `/copy`, and `/share`
60 /// for transcript or clipboard delivery; every concrete App, snapshot, clipboard,
61 /// filesystem, history, and turn-handoff access stays behind the TUI export
62 /// adapter.
63 ///
64 /// This filled the original 16-bit space. FEAT-029 widened the backing
65 /// storage before allocating the next independent diagnostics authority;
66 /// the published identity of this bit remains unchanged.
67 pub const SESSION_EXPORT: Self = Self(1 << 15);
68 /// Debug diagnostics host data (FEAT-029 D3/D4). This is the first bit in
69 /// the widened backing storage; other debug commands retain their own independent
70 /// authority and do not borrow this facet.
71 pub const DEBUG_DIAGNOSTICS: Self = Self(1 << 16);
72
73 /// Debug receipts authority; independent from diagnostics and other debug operations.
74 pub const DEBUG_RECEIPTS: Self = Self(1 << 17);
75 /// Debug change authority; independent from diagnostics and other debug operations.
76 pub const DEBUG_CHANGE: Self = Self(1 << 18);
77 /// Debug history authority; independent from diagnostics and other debug operations.
78 pub const DEBUG_HISTORY: Self = Self(1 << 19);
79 /// Debug diff authority; independent from diagnostics and other debug operations.
80 pub const DEBUG_DIFF: Self = Self(1 << 20);
81 /// Debug undo authority; independent from diagnostics and other debug operations.
82 pub const DEBUG_UNDO: Self = Self(1 << 21);
83
84 /// One human-selected structural copy; independent from export/recovery.
85 pub const SESSION_STRUCTCOPY: Self = Self(1 << 22);
86 /// Permission observations and token-checked removal, independent of status.
87 pub const PERMISSIONS: Self = Self(1 << 23);
88 /// Read-only status observations, with no permission mutation authority.
89 pub const CONFIG_STATUS: Self = Self(1 << 24);
90 /// Config-group host data (FEAT-028 D3), the next non-conflicting bit after
91 /// `CONFIG_STATUS`. Read/write settings, keys, presets, the editability
92 /// audit and login/logout observations for the config command group. It does
93 /// not grant pet, trust, mode, or workspace authority.
94 pub const CONFIG: Self = Self(1 << 25);
95 /// Whale view, stillness, name and colour host data (FEAT-028 D3), independent of
96 /// general configuration and system settings.
97 pub const PET: Self = Self(1 << 26);
98 /// Workspace trust and trusted-path allow-list host data (FEAT-028 D3),
99 /// independent of the general config facet and of `WORKSPACE` operations.
100 pub const TRUST: Self = Self(1 << 27);
101 /// Account/provider session state for `/login` and `/logout` (FEAT-028 D3).
102 pub const LOGIN: Self = Self(1 << 28);
103 /// Workbar placement/panel state for `/workbar` (FEAT-028 D3).
104 pub const WORK_SURFACE: Self = Self(1 << 29);
105 pub const NAVIGATION: Self = Self(1 << 30);
106 pub const VOICE_INPUT: Self = Self(1 << 31);
107 pub const BACKGROUND: Self = Self(1 << 32);
108 pub const COMPOSER: Self = Self(1 << 33);
109 pub const RESPONSE_COPY: Self = Self(1 << 34);
110 pub const PROVIDER_ROUTES: Self = Self(1 << 35);
111 pub const FEEDBACK: Self = Self(1 << 44);
112 pub const EFFORT: Self = Self(1 << 45);
113 pub const CLEAR: Self = Self(1 << 46);
114 pub const WORKFLOW_REVIEW: Self = Self(1 << 37);
115 pub const WORKFLOW_CONTROL: Self = Self(1 << 42);
116 pub const AUTO_REVIEW: Self = Self(1 << 43);
117 pub const MODEL_SELECTION: Self = Self(1 << 36);
118 pub const FLEET: Self = Self(1 << 38);
119 pub const LANE: Self = Self(1 << 39);
120 pub const CONSTITUTION: Self = Self(1 << 40);
121 pub const HOOKS: Self = Self(1 << 41);
122
123 /// Raw bit pattern, for tests that pin the capability-space capacity.
124 ///
125 /// Kept `#[cfg(test)]` so the `u64` backing stays an implementation detail
126 /// and nothing can widen it accidentally through a public accessor.
127 #[cfg(test)]
128 pub(crate) const fn bits_for_test(self) -> u64 {
129 self.0
130 }
131
132 pub const fn union(self, other: Self) -> Self {
133 Self(self.0 | other.0)
134 }
135
136 pub const fn contains(self, capability: Self) -> bool {
137 !capability.is_empty() && self.0 & capability.0 == capability.0
138 }
139
140 pub const fn is_empty(self) -> bool {
141 self.0 == 0
142 }
143 }
144
145 impl std::ops::BitOr for CommandCapabilities {
146 type Output = Self;
147
148 fn bitor(self, rhs: Self) -> Self::Output {
149 self.union(rhs)
150 }
151 }
152
153 /// A command handler that is either argument-only or capability-scoped.
154 #[derive(Clone, Copy)]
155 pub enum CommandHandler<R> {
156 Pure(fn(Option<&str>) -> R),
157 Contextual {
158 capabilities: CommandCapabilities,
159 handler: fn(CommandContexts<'_>, Option<&str>) -> R,
160 },
161 }
162
163 /// Transport envelope with one independently optional facet slot.
164 pub struct CommandContexts<'a> {
165 session: Option<&'a mut dyn CommandSessionContext>,
166 model: Option<&'a mut dyn CommandModelContext>,
167 cost: Option<&'a mut dyn CommandCostContext>,
168 mode_policy: Option<&'a mut dyn CommandModePolicyContext>,
169 system_prompt: Option<&'a mut dyn CommandSystemPromptContext>,
170 skills: Option<&'a mut dyn CommandSkillsContext>,
171 workspace: Option<&'a mut dyn CommandWorkspaceContext>,
172 presentation: Option<&'a mut dyn CommandPresentationContext>,
173 media: Option<&'a mut dyn CommandMediaContext>,
174 memory: Option<&'a mut dyn CommandMemoryContext>,
175 project: Option<&'a mut dyn CommandProjectContext>,
176 skill_group: Option<&'a mut dyn CommandSkillGroupContext>,
177 plugin: Option<&'a mut dyn CommandPluginContext>,
178 lifecycle: Option<&'a mut dyn CommandSessionLifecycleContext>,
179 control: Option<&'a mut dyn CommandSessionControlContext>,
180 export: Option<&'a mut dyn CommandSessionExportContext>,
181 structcopy: Option<&'a mut dyn CommandSessionStructcopyContext>,
182 debug_receipts: Option<&'a mut dyn CommandDebugReceiptsContext>,
183 debug_change: Option<&'a mut dyn CommandDebugChangeContext>,
184 debug_history: Option<&'a mut dyn CommandDebugHistoryContext>,
185 debug_diff: Option<&'a mut dyn CommandDebugDiffContext>,
186 debug_undo: Option<&'a mut dyn CommandDebugUndoContext>,
187 debug_diagnostics: Option<&'a mut dyn CommandDebugDiagnosticsContext>,
188 permissions: Option<&'a mut dyn CommandPermissionsContext>,
189 config_status: Option<&'a mut dyn CommandConfigStatusContext>,
190 config: Option<&'a mut dyn crate::config::CommandConfigContext>,
191 pet: Option<&'a mut dyn crate::config::CommandPetContext>,
192 trust: Option<&'a mut dyn crate::config::CommandTrustContext>,
193 login: Option<&'a mut dyn crate::config::CommandLoginContext>,
194 work_surface: Option<&'a mut dyn crate::config::CommandWorkSurfaceContext>,
195 navigation: Option<&'a mut dyn crate::navigation::CommandNavigationContext>,
196 voice_input: Option<&'a mut dyn crate::navigation::CommandVoiceInputContext>,
197 feedback: Option<&'a mut dyn crate::core_policy::FeedbackContext>,
198 effort: Option<&'a mut dyn crate::core_policy::EffortContext>,
199 clear: Option<&'a mut dyn crate::core_policy::ClearContext>,
200 provider_routes: Option<&'a mut dyn crate::model_setup::CommandProviderRoutesContext>,
201 workflow_review: Option<&'a dyn crate::workflow::CommandWorkflowReviewContext>,
202 workflow: Option<&'a mut dyn crate::workflow::CommandWorkflowContext>,
203 auto_review: Option<&'a mut dyn crate::workflow::CommandAutoReviewContext>,
204 model_selection: Option<&'a mut dyn crate::model_setup::CommandModelSelectionContext>,
205 response_copy: Option<&'a mut dyn crate::navigation::CommandResponseCopyContext>,
206 composer: Option<&'a mut dyn CommandComposerContext>,
207 background: Option<&'a mut dyn CommandBackgroundContext>,
208 fleet: Option<&'a mut dyn crate::fleet_lane::CommandFleetContext>,
209 lane: Option<&'a mut dyn crate::fleet_lane::CommandLaneContext>,
210 constitution: Option<&'a mut dyn crate::constitution::CommandConstitutionContext>,
211 hooks: Option<&'a mut dyn crate::hooks::CommandHooksContext>,
212 }
213
214 /// Consumed envelope used when one handler needs several independent facets.
215 pub struct ContextParts<'a> {
216 pub session: Option<&'a mut dyn CommandSessionContext>,
217 pub model: Option<&'a mut dyn CommandModelContext>,
218 pub cost: Option<&'a mut dyn CommandCostContext>,
219 pub mode_policy: Option<&'a mut dyn CommandModePolicyContext>,
220 pub system_prompt: Option<&'a mut dyn CommandSystemPromptContext>,
221 pub skills: Option<&'a mut dyn CommandSkillsContext>,
222 pub workspace: Option<&'a mut dyn CommandWorkspaceContext>,
223 pub presentation: Option<&'a mut dyn CommandPresentationContext>,
224 pub media: Option<&'a mut dyn CommandMediaContext>,
225 pub memory: Option<&'a mut dyn CommandMemoryContext>,
226 pub project: Option<&'a mut dyn CommandProjectContext>,
227 pub skill_group: Option<&'a mut dyn CommandSkillGroupContext>,
228 pub plugin: Option<&'a mut dyn CommandPluginContext>,
229 pub lifecycle: Option<&'a mut dyn CommandSessionLifecycleContext>,
230 pub control: Option<&'a mut dyn CommandSessionControlContext>,
231 pub export: Option<&'a mut dyn CommandSessionExportContext>,
232 pub structcopy: Option<&'a mut dyn CommandSessionStructcopyContext>,
233 pub debug_receipts: Option<&'a mut dyn CommandDebugReceiptsContext>,
234 pub debug_change: Option<&'a mut dyn CommandDebugChangeContext>,
235 pub debug_history: Option<&'a mut dyn CommandDebugHistoryContext>,
236 pub debug_diff: Option<&'a mut dyn CommandDebugDiffContext>,
237 pub debug_undo: Option<&'a mut dyn CommandDebugUndoContext>,
238 pub debug_diagnostics: Option<&'a mut dyn CommandDebugDiagnosticsContext>,
239 pub permissions: Option<&'a mut dyn CommandPermissionsContext>,
240 pub config_status: Option<&'a mut dyn CommandConfigStatusContext>,
241 pub config: Option<&'a mut dyn crate::config::CommandConfigContext>,
242 pub pet: Option<&'a mut dyn crate::config::CommandPetContext>,
243 pub trust: Option<&'a mut dyn crate::config::CommandTrustContext>,
244 pub login: Option<&'a mut dyn crate::config::CommandLoginContext>,
245 pub work_surface: Option<&'a mut dyn crate::config::CommandWorkSurfaceContext>,
246 pub navigation: Option<&'a mut dyn crate::navigation::CommandNavigationContext>,
247 pub voice_input: Option<&'a mut dyn crate::navigation::CommandVoiceInputContext>,
248 }
249
250 impl<'a> CommandContexts<'a> {
251 pub fn empty() -> Self {
252 Self {
253 session: None,
254 model: None,
255 cost: None,
256 mode_policy: None,
257 system_prompt: None,
258 skills: None,
259 workspace: None,
260 presentation: None,
261 media: None,
262 memory: None,
263 project: None,
264 skill_group: None,
265 plugin: None,
266 lifecycle: None,
267 control: None,
268 export: None,
269 structcopy: None,
270 debug_receipts: None,
271 debug_change: None,
272 debug_history: None,
273 debug_diff: None,
274 debug_undo: None,
275 debug_diagnostics: None,
276 permissions: None,
277 config_status: None,
278 config: None,
279 pet: None,
280 trust: None,
281 login: None,
282 work_surface: None,
283 navigation: None,
284 voice_input: None,
285 background: None,
286 feedback: None,
287 effort: None,
288 clear: None,
289 provider_routes: None,
290 workflow_review: None,
291 workflow: None,
292 auto_review: None,
293 model_selection: None,
294 response_copy: None,
295 composer: None,
296 fleet: None,
297 lane: None,
298 constitution: None,
299 hooks: None,
300 }
301 }
302
303 pub fn into_parts(self) -> ContextParts<'a> {
304 ContextParts {
305 session: self.session,
306 model: self.model,
307 cost: self.cost,
308 mode_policy: self.mode_policy,
309 system_prompt: self.system_prompt,
310 skills: self.skills,
311 workspace: self.workspace,
312 presentation: self.presentation,
313 media: self.media,
314 memory: self.memory,
315 project: self.project,
316 skill_group: self.skill_group,
317 plugin: self.plugin,
318 lifecycle: self.lifecycle,
319 control: self.control,
320 export: self.export,
321 structcopy: self.structcopy,
322 debug_receipts: self.debug_receipts,
323 debug_change: self.debug_change,
324 debug_history: self.debug_history,
325 debug_diff: self.debug_diff,
326 debug_undo: self.debug_undo,
327 debug_diagnostics: self.debug_diagnostics,
328 permissions: self.permissions,
329 config_status: self.config_status,
330 config: self.config,
331 pet: self.pet,
332 trust: self.trust,
333 login: self.login,
334 work_surface: self.work_surface,
335 navigation: self.navigation,
336 voice_input: self.voice_input,
337 }
338 }
339
340 pub fn with_config(mut self, value: &'a mut dyn crate::config::CommandConfigContext) -> Self {
341 assert!(
342 self.config.replace(value).is_none(),
343 "config facet already set"
344 );
345 self
346 }
347
348 pub fn with_pet(mut self, value: &'a mut dyn crate::config::CommandPetContext) -> Self {
349 assert!(self.pet.replace(value).is_none(), "pet facet already set");
350 self
351 }
352
353 pub fn with_trust(mut self, value: &'a mut dyn crate::config::CommandTrustContext) -> Self {
354 assert!(
355 self.trust.replace(value).is_none(),
356 "trust facet already set"
357 );
358 self
359 }
360
361 pub fn with_login(mut self, value: &'a mut dyn crate::config::CommandLoginContext) -> Self {
362 assert!(
363 self.login.replace(value).is_none(),
364 "login facet already set"
365 );
366 self
367 }
368
369 pub fn with_work_surface(
370 mut self,
371 value: &'a mut dyn crate::config::CommandWorkSurfaceContext,
372 ) -> Self {
373 assert!(
374 self.work_surface.replace(value).is_none(),
375 "work-surface facet already set"
376 );
377 self
378 }
379
380 pub fn with_navigation(
381 mut self,
382 value: &'a mut dyn crate::navigation::CommandNavigationContext,
383 ) -> Self {
384 assert!(
385 self.navigation.replace(value).is_none(),
386 "navigation facet already set"
387 );
388 self
389 }
390
391 pub fn with_voice_input(
392 mut self,
393 value: &'a mut dyn crate::navigation::CommandVoiceInputContext,
394 ) -> Self {
395 assert!(
396 self.voice_input.replace(value).is_none(),
397 "voice-input facet already set"
398 );
399 self
400 }
401
402 pub fn with_provider_routes(
403 mut self,
404 value: &'a mut dyn crate::model_setup::CommandProviderRoutesContext,
405 ) -> Self {
406 assert!(
407 self.provider_routes.replace(value).is_none(),
408 "provider-routes facet already set"
409 );
410 self
411 }
412
413 pub fn take_provider_routes(
414 &mut self,
415 ) -> Option<&'a mut dyn crate::model_setup::CommandProviderRoutesContext> {
416 self.provider_routes.take()
417 }
418
419 pub fn with_clear(mut self, value: &'a mut dyn crate::core_policy::ClearContext) -> Self {
420 assert!(
421 self.clear.replace(value).is_none(),
422 "clear facet already set"
423 );
424 self
425 }
426
427 pub fn take_clear(&mut self) -> Option<&'a mut dyn crate::core_policy::ClearContext> {
428 self.clear.take()
429 }
430
431 pub fn with_effort(mut self, value: &'a mut dyn crate::core_policy::EffortContext) -> Self {
432 assert!(
433 self.effort.replace(value).is_none(),
434 "effort facet already set"
435 );
436 self
437 }
438
439 pub fn take_effort(&mut self) -> Option<&'a mut dyn crate::core_policy::EffortContext> {
440 self.effort.take()
441 }
442
443 pub fn with_feedback(mut self, value: &'a mut dyn crate::core_policy::FeedbackContext) -> Self {
444 assert!(
445 self.feedback.replace(value).is_none(),
446 "feedback facet already set"
447 );
448 self
449 }
450
451 pub fn take_feedback(&mut self) -> Option<&'a mut dyn crate::core_policy::FeedbackContext> {
452 self.feedback.take()
453 }
454
455 pub fn with_workflow_review(
456 mut self,
457 value: &'a dyn crate::workflow::CommandWorkflowReviewContext,
458 ) -> Self {
459 assert!(
460 self.workflow_review.replace(value).is_none(),
461 "workflow review facet already set"
462 );
463 self
464 }
465 pub fn take_workflow_review(
466 &mut self,
467 ) -> Option<&'a dyn crate::workflow::CommandWorkflowReviewContext> {
468 self.workflow_review.take()
469 }
470
471 pub fn with_workflow(
472 mut self,
473 value: &'a mut dyn crate::workflow::CommandWorkflowContext,
474 ) -> Self {
475 assert!(
476 self.workflow.replace(value).is_none(),
477 "workflow facet already set"
478 );
479 self
480 }
481 pub fn take_workflow(&mut self) -> Option<&'a mut dyn crate::workflow::CommandWorkflowContext> {
482 self.workflow.take()
483 }
484
485 pub fn with_auto_review(
486 mut self,
487 value: &'a mut dyn crate::workflow::CommandAutoReviewContext,
488 ) -> Self {
489 assert!(
490 self.auto_review.replace(value).is_none(),
491 "auto_review facet already set"
492 );
493 self
494 }
495 pub fn take_auto_review(
496 &mut self,
497 ) -> Option<&'a mut dyn crate::workflow::CommandAutoReviewContext> {
498 self.auto_review.take()
499 }
500
501 pub fn with_model_selection(
502 mut self,
503 value: &'a mut dyn crate::model_setup::CommandModelSelectionContext,
504 ) -> Self {
505 assert!(
506 self.model_selection.replace(value).is_none(),
507 "model-selection facet already set"
508 );
509 self
510 }
511
512 pub fn take_model_selection(
513 &mut self,
514 ) -> Option<&'a mut dyn crate::model_setup::CommandModelSelectionContext> {
515 self.model_selection.take()
516 }
517
518 pub fn with_constitution(
519 mut self,
520 value: &'a mut dyn crate::constitution::CommandConstitutionContext,
521 ) -> Self {
522 assert!(
523 self.constitution.replace(value).is_none(),
524 "constitution facet already set"
525 );
526 self
527 }
528
529 pub fn take_constitution(
530 &mut self,
531 ) -> Option<&'a mut dyn crate::constitution::CommandConstitutionContext> {
532 self.constitution.take()
533 }
534
535 pub fn with_hooks(mut self, value: &'a mut dyn crate::hooks::CommandHooksContext) -> Self {
536 assert!(
537 self.hooks.replace(value).is_none(),
538 "hooks facet already set"
539 );
540 self
541 }
542
543 pub fn take_hooks(&mut self) -> Option<&'a mut dyn crate::hooks::CommandHooksContext> {
544 self.hooks.take()
545 }
546
547 pub fn with_fleet(mut self, value: &'a mut dyn crate::fleet_lane::CommandFleetContext) -> Self {
548 assert!(
549 self.fleet.replace(value).is_none(),
550 "fleet facet already set"
551 );
552 self
553 }
554
555 pub fn take_fleet(&mut self) -> Option<&'a mut dyn crate::fleet_lane::CommandFleetContext> {
556 self.fleet.take()
557 }
558
559 pub fn with_lane(mut self, value: &'a mut dyn crate::fleet_lane::CommandLaneContext) -> Self {
560 assert!(self.lane.replace(value).is_none(), "lane facet already set");
561 self
562 }
563
564 pub fn take_lane(&mut self) -> Option<&'a mut dyn crate::fleet_lane::CommandLaneContext> {
565 self.lane.take()
566 }
567
568 pub fn with_response_copy(
569 mut self,
570 value: &'a mut dyn crate::navigation::CommandResponseCopyContext,
571 ) -> Self {
572 assert!(
573 self.response_copy.replace(value).is_none(),
574 "response-copy facet already set"
575 );
576 self
577 }
578
579 pub fn take_response_copy(
580 &mut self,
581 ) -> Option<&'a mut dyn crate::navigation::CommandResponseCopyContext> {
582 self.response_copy.take()
583 }
584
585 pub fn with_composer(mut self, value: &'a mut dyn CommandComposerContext) -> Self {
586 assert!(
587 self.composer.replace(value).is_none(),
588 "composer facet already set"
589 );
590 self
591 }
592
593 pub fn take_composer(&mut self) -> Option<&'a mut dyn CommandComposerContext> {
594 self.composer.take()
595 }
596
597 pub fn with_background(mut self, value: &'a mut dyn CommandBackgroundContext) -> Self {
598 assert!(
599 self.background.replace(value).is_none(),
600 "background facet already set"
601 );
602 self
603 }
604
605 pub fn take_background(&mut self) -> Option<&'a mut dyn CommandBackgroundContext> {
606 self.background.take()
607 }
608
609 pub fn with_permissions(mut self, value: &'a mut dyn CommandPermissionsContext) -> Self {
610 assert!(
611 self.permissions.replace(value).is_none(),
612 "permissions facet already set"
613 );
614 self
615 }
616 pub fn with_config_status(mut self, value: &'a mut dyn CommandConfigStatusContext) -> Self {
617 assert!(
618 self.config_status.replace(value).is_none(),
619 "config status facet already set"
620 );
621 self
622 }
623
624 pub fn with_session(mut self, value: &'a mut dyn CommandSessionContext) -> Self {
625 assert!(
626 self.session.replace(value).is_none(),
627 "session facet already set"
628 );
629 self
630 }
631
632 pub fn with_model(mut self, value: &'a mut dyn CommandModelContext) -> Self {
633 assert!(
634 self.model.replace(value).is_none(),
635 "model facet already set"
636 );
637 self
638 }
639
640 pub fn with_cost(mut self, value: &'a mut dyn CommandCostContext) -> Self {
641 assert!(self.cost.replace(value).is_none(), "cost facet already set");
642 self
643 }
644
645 pub fn with_mode_policy(mut self, value: &'a mut dyn CommandModePolicyContext) -> Self {
646 assert!(
647 self.mode_policy.replace(value).is_none(),
648 "mode-policy facet already set"
649 );
650 self
651 }
652
653 pub fn with_system_prompt(mut self, value: &'a mut dyn CommandSystemPromptContext) -> Self {
654 assert!(
655 self.system_prompt.replace(value).is_none(),
656 "system-prompt facet already set"
657 );
658 self
659 }
660
661 pub fn with_skills(mut self, value: &'a mut dyn CommandSkillsContext) -> Self {
662 assert!(
663 self.skills.replace(value).is_none(),
664 "skills facet already set"
665 );
666 self
667 }
668
669 pub fn with_workspace(mut self, value: &'a mut dyn CommandWorkspaceContext) -> Self {
670 assert!(
671 self.workspace.replace(value).is_none(),
672 "workspace facet already set"
673 );
674 self
675 }
676
677 pub fn with_presentation(mut self, value: &'a mut dyn CommandPresentationContext) -> Self {
678 assert!(
679 self.presentation.replace(value).is_none(),
680 "presentation facet already set"
681 );
682 self
683 }
684
685 pub fn with_media(mut self, value: &'a mut dyn CommandMediaContext) -> Self {
686 assert!(
687 self.media.replace(value).is_none(),
688 "media facet already set"
689 );
690 self
691 }
692
693 pub fn with_memory(mut self, value: &'a mut dyn CommandMemoryContext) -> Self {
694 assert!(
695 self.memory.replace(value).is_none(),
696 "memory facet already set"
697 );
698 self
699 }
700
701 pub fn with_project(mut self, value: &'a mut dyn CommandProjectContext) -> Self {
702 assert!(
703 self.project.replace(value).is_none(),
704 "project facet already set"
705 );
706 self
707 }
708
709 pub fn with_skill_group(mut self, value: &'a mut dyn CommandSkillGroupContext) -> Self {
710 assert!(
711 self.skill_group.replace(value).is_none(),
712 "skill-group facet already set"
713 );
714 self
715 }
716
717 pub fn with_plugin(mut self, value: &'a mut dyn CommandPluginContext) -> Self {
718 assert!(
719 self.plugin.replace(value).is_none(),
720 "plugin facet already set"
721 );
722 self
723 }
724
725 pub fn with_lifecycle(mut self, value: &'a mut dyn CommandSessionLifecycleContext) -> Self {
726 assert!(
727 self.lifecycle.replace(value).is_none(),
728 "lifecycle facet already set"
729 );
730 self
731 }
732
733 pub fn with_control(mut self, value: &'a mut dyn CommandSessionControlContext) -> Self {
734 assert!(
735 self.control.replace(value).is_none(),
736 "control facet already set"
737 );
738 self
739 }
740
741 pub fn with_structcopy(mut self, value: &'a mut dyn CommandSessionStructcopyContext) -> Self {
742 assert!(
743 self.structcopy.replace(value).is_none(),
744 "structcopy facet already set"
745 );
746 self
747 }
748
749 pub fn with_export(mut self, value: &'a mut dyn CommandSessionExportContext) -> Self {
750 assert!(
751 self.export.replace(value).is_none(),
752 "export facet already set"
753 );
754 self
755 }
756
757 pub fn with_debug_receipts(mut self, value: &'a mut dyn CommandDebugReceiptsContext) -> Self {
758 assert!(
759 self.debug_receipts.replace(value).is_none(),
760 "debug_receipts facet already set"
761 );
762 self
763 }
764
765 pub fn with_debug_change(mut self, value: &'a mut dyn CommandDebugChangeContext) -> Self {
766 assert!(
767 self.debug_change.replace(value).is_none(),
768 "debug_change facet already set"
769 );
770 self
771 }
772
773 pub fn with_debug_history(mut self, value: &'a mut dyn CommandDebugHistoryContext) -> Self {
774 assert!(
775 self.debug_history.replace(value).is_none(),
776 "debug_history facet already set"
777 );
778 self
779 }
780
781 pub fn with_debug_diff(mut self, value: &'a mut dyn CommandDebugDiffContext) -> Self {
782 assert!(
783 self.debug_diff.replace(value).is_none(),
784 "debug_diff facet already set"
785 );
786 self
787 }
788
789 pub fn with_debug_undo(mut self, value: &'a mut dyn CommandDebugUndoContext) -> Self {
790 assert!(
791 self.debug_undo.replace(value).is_none(),
792 "debug_undo facet already set"
793 );
794 self
795 }
796
797 pub fn with_debug_diagnostics(
798 mut self,
799 value: &'a mut dyn CommandDebugDiagnosticsContext,
800 ) -> Self {
801 assert!(
802 self.debug_diagnostics.replace(value).is_none(),
803 "debug diagnostics facet already set"
804 );
805 self
806 }
807 }
808
809 impl Default for CommandContexts<'_> {
810 fn default() -> Self {
811 Self::empty()
812 }
813 }
814
814 lines RUST