@@ -284,7 +284,7 @@ QJsonObject sessionJson(AiAgentDock *dock, const QString &sessionId, bool detail
284284QVector<GrillMeForm::Answer> answersArg (const QJsonArray &array)
285285{
286286 QVector<GrillMeForm::Answer> answers;
287- for (const QJsonValue &v : array) {
287+ for (const auto &v : array) {
288288 const QJsonObject o = v.toObject ();
289289 GrillMeForm::Answer a;
290290 a.questionId = o.value (QStringLiteral (" id" )).toString ();
@@ -418,8 +418,11 @@ QJsonArray templatesJson(const GoalAgentSettings &s)
418418 return templates;
419419}
420420
421- const Arg kSession = Registrar::optional(QStringLiteral(" session" ), ArgType::String,
422- QStringLiteral (" session id from ai.sessions; default: the session in front" ));
421+ Arg sessionArgSpec ()
422+ {
423+ return Registrar::optional (QStringLiteral (" session" ), ArgType::String,
424+ QStringLiteral (" session id from ai.sessions; default: the session in front" ));
425+ }
423426
424427} // namespace
425428
@@ -574,7 +577,7 @@ void Registrar::ai()
574577 add (QStringLiteral (" ai.state" ),
575578 QStringLiteral (" Read a session's state: working, waiting for an answer (permission / form), models, modes, "
576579 " queue" ),
577- false , {kSession }, [sessionArg, idOf](const CommandContext &ctx) {
580+ false , {sessionArgSpec () }, [sessionArg, idOf](const CommandContext &ctx) {
578581 AiAgentDock *dock = nullptr ;
579582 AcpSessionView *view = sessionArg (ctx, &dock);
580583 if (!view)
@@ -586,7 +589,7 @@ void Registrar::ai()
586589 add (QStringLiteral (" ai.debugLog" ),
587590 QStringLiteral (" Read a session's debug log, as its Debug log window shows it (agent env values are hidden)" ),
588591 false ,
589- {kSession , optional (QStringLiteral (" last" ), ArgType::Int, QStringLiteral (" the last this many lines; default 200" )),
592+ {sessionArgSpec () , optional (QStringLiteral (" last" ), ArgType::Int, QStringLiteral (" the last this many lines; default 200" )),
590593 optional (QStringLiteral (" goalOnly" ), ArgType::Bool, QStringLiteral (" only the goal agent's lines" ))},
591594 [sessionArg](const CommandContext &ctx) {
592595 AiAgentDock *dock = nullptr ;
@@ -615,7 +618,7 @@ void Registrar::ai()
615618 });
616619
617620 add (QStringLiteral (" ai.read" ), QStringLiteral (" Read a session's transcript: prompts, replies and tool calls" ), false ,
618- {kSession , optional (QStringLiteral (" last" ), ArgType::Int, QStringLiteral (" the last this many entries; default 30" )),
621+ {sessionArgSpec () , optional (QStringLiteral (" last" ), ArgType::Int, QStringLiteral (" the last this many entries; default 30" )),
619622 optional (QStringLiteral (" from" ), ArgType::Int, QStringLiteral (" instead: entries from this index" )),
620623 optional (QStringLiteral (" count" ), ArgType::Int, QStringLiteral (" with `from`: how many; default 30" )),
621624 optional (QStringLiteral (" thoughts" ), ArgType::Bool, QStringLiteral (" include the agent's thinking; default false" ))},
@@ -684,7 +687,7 @@ void Registrar::ai()
684687 });
685688
686689 add (QStringLiteral (" ai.report" ), QStringLiteral (" Read the final answer of a session's last finished turn" ), false ,
687- {kSession }, [sessionArg, idOf](const CommandContext &ctx) {
690+ {sessionArgSpec () }, [sessionArg, idOf](const CommandContext &ctx) {
688691 AiAgentDock *dock = nullptr ;
689692 AcpSessionView *view = sessionArg (ctx, &dock);
690693 if (!view)
@@ -708,7 +711,7 @@ void Registrar::ai()
708711 add (QStringLiteral (" ai.send" ),
709712 QStringLiteral (" Send a prompt from a session's composer (queued behind a running turn; slash commands work)" ),
710713 true ,
711- {kSession , required (QStringLiteral (" text" ), ArgType::String, QStringLiteral (" the prompt" )),
714+ {sessionArgSpec () , required (QStringLiteral (" text" ), ArgType::String, QStringLiteral (" the prompt" )),
712715 optional (QStringLiteral (" images" ), ArgType::Array,
713716 QStringLiteral (" images to attach: [{path} (png/jpg/gif/webp; relative to the session folder) or "
714717 " {data: base64, mime: \" image/png\" }]" )),
@@ -758,7 +761,7 @@ void Registrar::ai()
758761
759762 add (QStringLiteral (" ai.draft" ),
760763 QStringLiteral (" Put text into a session's composer without sending it (what Send to AI does)" ), true ,
761- {kSession , required (QStringLiteral (" text" ), ArgType::String, QStringLiteral (" text to put in" )),
764+ {sessionArgSpec () , required (QStringLiteral (" text" ), ArgType::String, QStringLiteral (" text to put in" )),
762765 optional (QStringLiteral (" append" ), ArgType::Bool,
763766 QStringLiteral (" insert at the composer's caret (default true); false replaces the composer text" ))},
764767 [sessionArg, showSession, idOf](const CommandContext &ctx) {
@@ -778,7 +781,7 @@ void Registrar::ai()
778781 QStringLiteral (" Rewrite the composer's prompt with AI (the composer's Improve button) and leave the result "
779782 " there" ),
780783 true ,
781- {kSession , optional (QStringLiteral (" text" ), ArgType::String,
784+ {sessionArgSpec () , optional (QStringLiteral (" text" ), ArgType::String,
782785 QStringLiteral (" put this in the composer first; default: what it holds" ))},
783786 [sessionArg, showSession, idOf](const CommandContext &ctx) {
784787 AiAgentDock *dock = nullptr ;
@@ -817,7 +820,7 @@ void Registrar::ai()
817820 });
818821
819822 add (QStringLiteral (" ai.queue" ), QStringLiteral (" List the prompts queued behind a session's running turn" ), false ,
820- {kSession }, [sessionArg, idOf](const CommandContext &ctx) {
823+ {sessionArgSpec () }, [sessionArg, idOf](const CommandContext &ctx) {
821824 AiAgentDock *dock = nullptr ;
822825 AcpSessionView *view = sessionArg (ctx, &dock);
823826 if (!view)
@@ -831,7 +834,7 @@ void Registrar::ai()
831834
832835 add (QStringLiteral (" ai.unqueue" ),
833836 QStringLiteral (" Remove a queued prompt before it is sent (the queue strip's remove button)" ), true ,
834- {kSession , required (QStringLiteral (" index" ), ArgType::Int, QStringLiteral (" its index in ai.queue" ))},
837+ {sessionArgSpec () , required (QStringLiteral (" index" ), ArgType::Int, QStringLiteral (" its index in ai.queue" ))},
835838 [sessionArg, showSession, idOf](const CommandContext &ctx) {
836839 AiAgentDock *dock = nullptr ;
837840 AcpSessionView *view = sessionArg (ctx, &dock);
@@ -850,7 +853,7 @@ void Registrar::ai()
850853
851854 add (QStringLiteral (" ai.stopTask" ),
852855 QStringLiteral (" Stop one of a session's background tasks (ai.state lists them under tasks)" ), true ,
853- {kSession , required (QStringLiteral (" taskId" ), ArgType::String, QStringLiteral (" task id from ai.state" ))},
856+ {sessionArgSpec () , required (QStringLiteral (" taskId" ), ArgType::String, QStringLiteral (" task id from ai.state" ))},
854857 [sessionArg, showSession, idOf](const CommandContext &ctx) {
855858 AiAgentDock *dock = nullptr ;
856859 AcpSessionView *view = sessionArg (ctx, &dock);
@@ -878,7 +881,7 @@ void Registrar::ai()
878881
879882 add (QStringLiteral (" ai.retry" ),
880883 QStringLiteral (" Restart a session whose agent exited (the chat's Retry); a running agent has nothing to retry" ),
881- true , {kSession }, [w = w, sessionArg, showSession, idOf](const CommandContext &ctx) {
884+ true , {sessionArgSpec () }, [w = w, sessionArg, showSession, idOf](const CommandContext &ctx) {
882885 AiAgentDock *dock = nullptr ;
883886 AcpSessionView *view = sessionArg (ctx, &dock);
884887 if (!view)
@@ -899,7 +902,7 @@ void Registrar::ai()
899902 });
900903
901904 add (QStringLiteral (" ai.cancel" ), QStringLiteral (" Stop a session's running turn (and a goal running on it)" ), true ,
902- {kSession }, [sessionArg, showSession, idOf](const CommandContext &ctx) {
905+ {sessionArgSpec () }, [sessionArg, showSession, idOf](const CommandContext &ctx) {
903906 AiAgentDock *dock = nullptr ;
904907 AcpSessionView *view = sessionArg (ctx, &dock);
905908 if (!view)
@@ -912,7 +915,7 @@ void Registrar::ai()
912915
913916 add (QStringLiteral (" ai.set" ), QStringLiteral (" Pick a session's model, mode or reasoning effort (ai.state lists them)" ),
914917 true ,
915- {kSession , optional (QStringLiteral (" model" ), ArgType::String, QStringLiteral (" model id" )),
918+ {sessionArgSpec () , optional (QStringLiteral (" model" ), ArgType::String, QStringLiteral (" model id" )),
916919 optional (QStringLiteral (" mode" ), ArgType::String, QStringLiteral (" mode id" )),
917920 optional (QStringLiteral (" effort" ), ArgType::String, QStringLiteral (" effort id" )),
918921 optional (QStringLiteral (" prewalk" ), ArgType::String,
@@ -965,7 +968,7 @@ void Registrar::ai()
965968
966969 add (QStringLiteral (" ai.autoApprove" ),
967970 QStringLiteral (" Turn auto-approve of agent tool permissions on or off (applies to every session)" ), true ,
968- {required (QStringLiteral (" on" ), ArgType::Bool, QStringLiteral (" true: agents run tools without asking" )), kSession },
971+ {required (QStringLiteral (" on" ), ArgType::Bool, QStringLiteral (" true: agents run tools without asking" )), sessionArgSpec () },
969972 [sessionArg, showSession, idOf](const CommandContext &ctx) {
970973 AiAgentDock *dock = nullptr ;
971974 AcpSessionView *view = sessionArg (ctx, &dock);
@@ -978,7 +981,7 @@ void Registrar::ai()
978981
979982 add (QStringLiteral (" ai.permission" ),
980983 QStringLiteral (" Answer the permission request a session is waiting on (ai.state shows its options)" ), true ,
981- {kSession , required (QStringLiteral (" option" ), ArgType::String,
984+ {sessionArgSpec () , required (QStringLiteral (" option" ), ArgType::String,
982985 QStringLiteral (" option id or kind: allow_once, allow_always, reject_once, ..." ))},
983986 [sessionArg, showSession, idOf](const CommandContext &ctx) {
984987 AiAgentDock *dock = nullptr ;
@@ -1005,7 +1008,7 @@ void Registrar::ai()
10051008
10061009 add (QStringLiteral (" ai.answer" ),
10071010 QStringLiteral (" Answer the question form a session shows (ai.state has its questions) and submit it" ), true ,
1008- {kSession ,
1011+ {sessionArgSpec () ,
10091012 required (QStringLiteral (" answers" ), ArgType::Array,
10101013 QStringLiteral (" [{id, value, other?, note?, clarify?}]: value is an option value (single/select), an "
10111014 " array of them (multi), \" accept\" /\" change\" (proposal, a change in `other`), "
@@ -1034,7 +1037,7 @@ void Registrar::ai()
10341037 });
10351038
10361039 add (QStringLiteral (" ai.dismissForm" ), QStringLiteral (" Dismiss the question form a session shows" ), true ,
1037- {kSession , optional (QStringLiteral (" note" ), ArgType::String, QStringLiteral (" a note for the agent" ))},
1040+ {sessionArgSpec () , optional (QStringLiteral (" note" ), ArgType::String, QStringLiteral (" a note for the agent" ))},
10381041 [sessionArg, showSession, idOf](const CommandContext &ctx) {
10391042 AiAgentDock *dock = nullptr ;
10401043 AcpSessionView *view = sessionArg (ctx, &dock);
@@ -1049,7 +1052,7 @@ void Registrar::ai()
10491052 ctx.ok (sessionJson (dock, id, false ));
10501053 });
10511054
1052- add (QStringLiteral (" ai.focus" ), QStringLiteral (" Bring a session to the front" ), true , {kSession },
1055+ add (QStringLiteral (" ai.focus" ), QStringLiteral (" Bring a session to the front" ), true , {sessionArgSpec () },
10531056 [sessionArg, showSession, idOf](const CommandContext &ctx) {
10541057 AiAgentDock *dock = nullptr ;
10551058 AcpSessionView *view = sessionArg (ctx, &dock);
@@ -1061,7 +1064,7 @@ void Registrar::ai()
10611064 });
10621065
10631066 add (QStringLiteral (" ai.close" ), QStringLiteral (" Close a session (its agent stops; history is kept)" ), true ,
1064- {kSession , optional (QStringLiteral (" force" ), ArgType::Bool, QStringLiteral (" close even while it works" ))},
1067+ {sessionArgSpec () , optional (QStringLiteral (" force" ), ArgType::Bool, QStringLiteral (" close even while it works" ))},
10651068 [w = w, sessionArg, idOf](const CommandContext &ctx) {
10661069 AiAgentDock *dock = nullptr ;
10671070 AcpSessionView *view = sessionArg (ctx, &dock);
@@ -1080,7 +1083,7 @@ void Registrar::ai()
10801083
10811084 add (QStringLiteral (" ai.restart" ),
10821085 QStringLiteral (" Restart a session's agent with a fresh conversation in the same chat slot" ), true ,
1083- {kSession , optional (QStringLiteral (" force" ), ArgType::Bool, QStringLiteral (" restart even while it works" ))},
1086+ {sessionArgSpec () , optional (QStringLiteral (" force" ), ArgType::Bool, QStringLiteral (" restart even while it works" ))},
10841087 [w = w, sessionArg, idOf, showSession](const CommandContext &ctx) {
10851088 AiAgentDock *dock = nullptr ;
10861089 AcpSessionView *view = sessionArg (ctx, &dock);
@@ -1104,7 +1107,7 @@ void Registrar::ai()
11041107 add (QStringLiteral (" ai.switchAgent" ),
11051108 QStringLiteral (" Move an idle local Claude Code session to another Claude Code agent, keeping the conversation" ),
11061109 true ,
1107- {kSession , required (QStringLiteral (" agent" ), ArgType::String, QStringLiteral (" target agent id from ai.agents" ))},
1110+ {sessionArgSpec () , required (QStringLiteral (" agent" ), ArgType::String, QStringLiteral (" target agent id from ai.agents" ))},
11081111 [w = w, sessionArg, idOf, showSession](const CommandContext &ctx) {
11091112 AiAgentDock *dock = nullptr ;
11101113 AcpSessionView *view = sessionArg (ctx, &dock);
@@ -1623,7 +1626,7 @@ void Registrar::goal()
16231626 QStringLiteral (" Run a goal on a session: send a prompt (or keep going in the conversation) until each success "
16241627 " criterion is met" ),
16251628 true ,
1626- {kSession ,
1629+ {sessionArgSpec () ,
16271630 required (QStringLiteral (" criteria" ), ArgType::Array, QStringLiteral (" success criteria, checked in order" )),
16281631 optional (QStringLiteral (" prompt" ), ArgType::String,
16291632 QStringLiteral (" first prompt; default: the composer text, else the goal attaches to the conversation" )),
@@ -1677,7 +1680,7 @@ void Registrar::goal()
16771680 });
16781681
16791682 add (QStringLiteral (" goal.state" ), QStringLiteral (" Read the goal running on a session: criteria, iterations, verdicts" ),
1680- false , {kSession }, [sessionOf](const CommandContext &ctx) {
1683+ false , {sessionArgSpec () }, [sessionOf](const CommandContext &ctx) {
16811684 AiAgentDock *dock = nullptr ;
16821685 QString id;
16831686 if (!sessionOf (ctx, &dock, &id))
@@ -1707,7 +1710,7 @@ void Registrar::goal()
17071710 });
17081711
17091712 add (QStringLiteral (" goal.stop" ), QStringLiteral (" Stop the goal running on a session (the turn keeps going)" ), true ,
1710- {kSession }, [sessionOf](const CommandContext &ctx) {
1713+ {sessionArgSpec () }, [sessionOf](const CommandContext &ctx) {
17111714 AiAgentDock *dock = nullptr ;
17121715 QString id;
17131716 if (!sessionOf (ctx, &dock, &id))
@@ -1727,7 +1730,7 @@ void Registrar::goal()
17271730 QStringLiteral (" Write a prompt from success criteria with the judge agent (Improve on an empty composer) and "
17281731 " put it in the session's composer" ),
17291732 true ,
1730- {kSession , required (QStringLiteral (" criteria" ), ArgType::Array, QStringLiteral (" the success criteria" )),
1733+ {sessionArgSpec () , required (QStringLiteral (" criteria" ), ArgType::Array, QStringLiteral (" the success criteria" )),
17311734 optional (QStringLiteral (" judgeAgent" ), ArgType::String, QStringLiteral (" agent that writes it; default from goal.options" )),
17321735 optional (QStringLiteral (" template" ), ArgType::String, QStringLiteral (" prompt template id; default from goal.options" ))},
17331736 [w = w, sessionOf](const CommandContext &ctx) {
0 commit comments