@robota-sdk/agent-command 3.0.0-beta.75 → 3.0.0-beta.77

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.
Files changed (55) hide show
  1. package/LICENSE +661 -21
  2. package/README.md +12 -6
  3. package/dist/node/index.cjs +40 -35
  4. package/dist/node/index.d.ts +69 -7
  5. package/dist/node/index.d.ts.map +1 -1
  6. package/dist/node/index.js +40 -35
  7. package/dist/node/index.js.map +1 -1
  8. package/package.json +7 -7
  9. package/src/agent/agent-command-parser.ts +1 -1
  10. package/src/agent/agent-command.ts +2 -1
  11. package/src/background/__tests__/background-command-module.test.ts +2 -5
  12. package/src/context/context-command.ts +4 -4
  13. package/src/default/__tests__/default-command-modules.test.ts +5 -2
  14. package/src/default/default-command-modules.ts +6 -0
  15. package/src/editor/__tests__/editor-command-functional.test.ts +91 -0
  16. package/src/editor/editor-command-module.ts +47 -0
  17. package/src/editor/editor-command.ts +53 -0
  18. package/src/editor/index.ts +7 -0
  19. package/src/editor/resolve-editor.ts +21 -0
  20. package/src/exit/__tests__/exit-command-module.test.ts +21 -2
  21. package/src/exit/exit-command-module.ts +1 -10
  22. package/src/exit/exit-command.ts +15 -1
  23. package/src/goal/__tests__/goal-command.test.ts +75 -0
  24. package/src/goal/goal-command-module.ts +48 -0
  25. package/src/goal/goal-command.ts +70 -0
  26. package/src/goal/index.ts +6 -0
  27. package/src/index.ts +3 -0
  28. package/src/language/__tests__/language-command-module.test.ts +16 -0
  29. package/src/language/language-command-module.ts +1 -18
  30. package/src/language/language-command.ts +35 -9
  31. package/src/mode/__tests__/mode-command-module.test.ts +34 -0
  32. package/src/mode/mode-command-module.ts +1 -18
  33. package/src/mode/mode-command.ts +31 -8
  34. package/src/preset/__tests__/preset-command-module.test.ts +43 -7
  35. package/src/preset/preset-command-module.ts +1 -18
  36. package/src/preset/preset-command.ts +42 -10
  37. package/src/provider/__tests__/org-policy.test.ts +19 -13
  38. package/src/provider/__tests__/provider-command-module.test.ts +151 -80
  39. package/src/provider/__tests__/scripted-interaction.ts +28 -0
  40. package/src/provider/provider-command-execution.ts +67 -50
  41. package/src/provider/provider-command-module.ts +3 -19
  42. package/src/provider/provider-command-profile-lifecycle.ts +52 -72
  43. package/src/provider/provider-command-profile-operations.ts +15 -51
  44. package/src/provider/provider-command-profile.ts +44 -49
  45. package/src/provider/provider-command-setup.ts +56 -51
  46. package/src/session/__tests__/session-command-module.test.ts +38 -0
  47. package/src/session/model-pricing.ts +7 -60
  48. package/src/session/session-command-module.ts +1 -10
  49. package/src/session/session-command.ts +14 -1
  50. package/src/shell/__tests__/shell-command-functional.test.ts +96 -0
  51. package/src/shell/index.ts +8 -0
  52. package/src/shell/resolve-shell.ts +25 -0
  53. package/src/shell/shell-command-module.ts +47 -0
  54. package/src/shell/shell-command.ts +44 -0
  55. package/src/shell/spawn-inherited.ts +32 -0
package/README.md CHANGED
@@ -16,12 +16,15 @@ import {
16
16
  createModeCommandModule,
17
17
  createProviderCommandModule,
18
18
  } from '@robota-sdk/agent-command';
19
+ import type { IProviderCommandModuleOptions } from '@robota-sdk/agent-command';
20
+
21
+ declare const providerOptions: IProviderCommandModuleOptions;
19
22
 
20
23
  // Register commands with a CommandRegistry (owned by agent-framework)
21
24
  const modules = [
22
- createAgentCommandModule(hostAdapters),
23
- createModeCommandModule(hostAdapters),
24
- createProviderCommandModule(hostAdapters),
25
+ createAgentCommandModule(),
26
+ createModeCommandModule(),
27
+ createProviderCommandModule(providerOptions),
25
28
  ];
26
29
  ```
27
30
 
@@ -40,9 +43,11 @@ const modules = [
40
43
  | `/mode` | Interaction mode switching |
41
44
  | `/permissions` | Permission management |
42
45
  | `/plugin` | Plugin enable/disable |
46
+ | `/preset` | Agent preset selection / switching |
43
47
  | `/provider` | AI provider configuration |
44
48
  | `/reset` | Session reset |
45
49
  | `/rewind` | Conversation history rewind |
50
+ | `/schedule` | Scheduled / deferred task management |
46
51
  | `/session` | Session lifecycle (rename, resume, fork, list) |
47
52
  | `/settings` | Settings management |
48
53
  | `/skills` | Skills management |
@@ -56,11 +61,12 @@ Each command is exposed via a factory function that returns an `ICommandModule`:
56
61
  ```typescript
57
62
  import { createExitCommandModule, createHelpCommandModule } from '@robota-sdk/agent-command';
58
63
 
59
- const exitCmd = createExitCommandModule(hostAdapters);
60
- const helpCmd = createHelpCommandModule(hostAdapters);
64
+ const exitCmd = createExitCommandModule();
65
+ const helpCmd = createHelpCommandModule();
61
66
  ```
62
67
 
63
- All 20 factory functions are re-exported from the root entry point.
68
+ All command factory functions are re-exported from the root entry point (21 command modules plus the
69
+ `createDefaultCommandModules` aggregator).
64
70
 
65
71
  ## Dependencies
66
72
 
@@ -1,29 +1,34 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@robota-sdk/agent-framework"),t=require("@robota-sdk/agent-preset"),n=require("@robota-sdk/agent-core"),r=require("node:path"),i=require("node:fs"),a=require("node:child_process"),o=require("node:os");const s=`general-purpose`;function c(e){let t=[],n=``,r,i=!1;for(let a of e){if(i){n+=a,i=!1;continue}if(r&&a===`\\`){i=!0;continue}if(r){a===r?r=void 0:n+=a;continue}if(a===`"`||a===`'`){r=a;continue}if(/\s/.test(a)){n.length>0&&(t.push(n),n=``);continue}n+=a}return n.length>0&&t.push(n),t}function l(e){let t=[],n,r,i;for(let a=0;a<e.length;a+=1){let o=e[a];if(o!==`--background`){if(o===`--agent`||o===`--type`||o===`-a`){n=e[a+1],a+=1;continue}if(o===`--model`){r=e[a+1],a+=1;continue}if(o===`--isolation`){let t=e[a+1];(t===`none`||t===`worktree`)&&(i=t),a+=1;continue}o!==void 0&&t.push(o)}}return{positional:t,...n?{agentType:n}:{},...r?{model:r}:{},...i?{isolation:i}:{}}}function u(e,t,n,r){return{agentType:t,label:n,mode:`background`,prompt:r,...e.model?{model:e.model}:{},...e.isolation?{isolation:e.isolation}:{}}}function ee(e,t){let n=l(e),[r,...i]=n.positional,a=n.agentType??s,o=n.positional;!n.agentType&&r&&t.has(r)&&(a=r,o=i);let c=o.join(` `).trim();if(c)return u(n,a,a,c)}function te(e,t){let n=l(e);return n.positional.map(e=>ne(e,n,t)).filter(e=>e!==void 0)}function ne(e,t,n){let r=e.indexOf(`=`);if(r>0)return d(e.slice(0,r),e.slice(r+1),t,n);let i=e.indexOf(`:`);if(i<=0||i===e.length-1)return;let a=e.slice(0,i),o=e.slice(i+1);return u(t,t.agentType??(n.has(a)?a:s),a,o)}function d(e,t,n,r){let i=t.indexOf(`:`);if(i===-1)return u(n,n.agentType??(r.has(e)?e:s),e,t);if(!(i===0||i===t.length-1))return u(n,t.slice(0,i),e,t.slice(i+1))}function f(e){return e instanceof Error?e.message:String(e)}function p(e){return new Set(e.listAgentDefinitions().map(e=>e.name))}function m(e,t){let n=e.listAgentDefinitions();if(!n.some(e=>e.name===t))return{message:`Unknown agent type: ${t}\nAvailable agents: ${n.map(e=>e.name).join(`, `)}`,success:!1}}async function h(e,t){let n=m(e,t.agentType);if(n)return n;try{return{state:await e.spawnAgentJob(t)}}catch(e){return{message:f(e),success:!1}}}function re(){return{message:``,effects:[{type:`agent-switcher-requested`}],success:!0}}async function ie(e){let t=e.listAgentDefinitions(),n=e.listAgentJobs();return{message:[`Available agents:`,...t.map(e=>` ${e.name} - ${e.description}`),``,n.length===0?`No active agent jobs.`:`Agent jobs:`,...n.map(e=>` ${ae(e)}`)].join(`
2
- `),success:!0,data:{agents:t.length,jobs:n.length}}}function ae(e){let t=[e.worktreePath?`worktree=${e.worktreePath}`:void 0,e.branchName?`branch=${e.branchName}`:void 0].filter(e=>e!==void 0),n=t.length>0?` ${t.join(` `)}`:``;return`${e.id} [${e.status}${n}] ${e.label} - ${e.promptPreview}`}async function oe(e,t){let n=ee(t,p(e));if(!n)return{message:`Usage: agent run [AGENT_NAME] [--agent AGENT_NAME] PROMPT`,success:!1};let r=await h(e,n);if(`success`in r)return r;let{state:i}=r;return{message:`Started agent job: ${i.id}`,success:!0,data:{agentId:i.id,status:i.status}}}async function se(t,n){let r=n.includes(`--wait`)||!n.includes(`--detach`),i=te(n.filter(e=>e!==`--wait`&&e!==`--detach`),p(t));if(i.length===0)return{message:`Usage: agent parallel [--wait|--detach] LABEL:"PROMPT" [LABEL=AGENT_NAME:"PROMPT"]`,success:!1};let a=i.map(e=>m(t,e.agentType)).find(e=>e!==void 0);if(a)return a;let o;try{o=await Promise.all(i.map(e=>t.spawnAgentJob(e)))}catch(e){return{message:f(e),success:!1}}let s=t.createBackgroundJobGroup({waitPolicy:`wait_all`,taskIds:o.map(e=>e.id),label:`agent parallel`});if(r){let n=(0,e.summarizeBackgroundJobGroup)(await t.waitBackgroundJobGroup(s.id));return{message:me(n),success:!0,data:{agentIds:o.map(e=>e.id),groupId:s.id,summary:n}}}return{message:[`Started agent jobs:`,...o.map(e=>`${e.label}: ${e.id}`)].join(`
3
- `),success:!0,data:{agentIds:o.map(e=>e.id),groupId:s.id}}}async function ce(t,n){let[r]=n;if(!r)return{message:`Usage: agent wait GROUP_ID`,success:!1};let i=(0,e.summarizeBackgroundJobGroup)(await t.waitBackgroundJobGroup(r));return{message:me(i),success:!0,data:{groupId:r,summary:i}}}async function le(e,t){let[n,r]=t;if(!n)return{message:`Usage: agent read AGENT_ID [OFFSET]`,success:!1};let i=r?{offset:Number.parseInt(r,10)}:void 0,a=await e.readBackgroundTaskLog(n,i),o=a.nextCursor?`\nNext offset: ${a.nextCursor.offset}`:``;return{message:a.lines.length>0?`${a.lines.join(`
4
- `)}${o}`:`No log lines: ${n}`,success:!0,data:{agentId:n,nextOffset:a.nextCursor?.offset}}}async function ue(e,t){let[n,...r]=t,i=r.join(` `).trim();return!n||!i?{message:`Usage: agent send AGENT_ID PROMPT`,success:!1}:(await e.sendAgentJob(n,i),{message:`Sent input to agent job: ${n}`,success:!0,data:{agentId:n}})}async function de(e,t){let[n,...r]=t;return n?(await e.cancelAgentJob(n,r.join(` `)||void 0),{message:`Agent job stopped: ${n}`,success:!0,data:{agentId:n}}):{message:`Usage: agent stop AGENT_ID [REASON]`,success:!1}}async function fe(e,t){let[n]=t;return n?(await e.closeAgentJob(n),{message:`Agent job closed: ${n}`,success:!0,data:{agentId:n}}):{message:`Usage: agent close AGENT_ID`,success:!1}}async function pe(e,t){try{if(t.trim()===``)return re();let[n=`list`,...r]=c(t);return n===`list`&&r.length===0?ie(e):n===`run`?oe(e,r):n===`parallel`?se(e,r):n===`wait`?ce(e,r):n===`read`||n===`open`?le(e,r):n===`send`?ue(e,r):n===`stop`||n===`cancel`?de(e,r):n===`close`?fe(e,r):oe(e,[n,...r])}catch(e){return{message:f(e),success:!1}}}function me(e){return[`Background job group ${e.groupId}: ${e.status} (${e.completed}/${e.total} completed, ${e.failed} failed, ${e.cancelled} cancelled, ${e.pending} pending)`,...e.lines].join(`
5
- `)}function he(e){let t=e.getAgentJobCapability?.();if(!t)throw Error(`Agent job capability is not available in this context.`);return t}function ge(){return[{name:`list`,description:`List available agents and active jobs`,source:`agent`},{name:`run`,description:`Start one background agent job`,source:`agent`},{name:`parallel`,description:`Run multiple agents in parallel`,source:`agent`},{name:`wait`,description:`Wait for a background agent group summary`,source:`agent`},{name:`read`,description:`Read an agent job log page`,source:`agent`},{name:`send`,description:`Send follow-up input to an agent job`,source:`agent`},{name:`stop`,description:`Cancel a running agent job`,source:`agent`},{name:`close`,description:`Dismiss a terminal agent job`,source:`agent`},{name:`open`,description:`Focus an agent job detail view when supported`,source:`agent`}]}function g(){return{name:`agent`,displayName:`Agent Jobs`,description:[`Subagent jobs command.`,`Natural-language arguments start one background agent job.`,`When the user explicitly asks to create, run, spawn, delegate to, or use agents/subagents, start the requested agent command immediately and do not ask a follow-up question unless execution is impossible or unsafe.`,`If the target item is unspecified, include target selection inside the agent prompt instead of delaying execution.`,`The parallel form starts multiple background agent jobs as a wait_all group and returns a consolidated group summary unless --detach is present.`,`list, wait, read, send, stop, close, and open manage existing agent jobs.`].join(` `),source:`agent`,modelInvocable:!0,argumentHint:`PROMPT | AGENT_NAME PROMPT | list | parallel [--wait|--detach] LABEL:"PROMPT" [LABEL=AGENT_NAME:"PROMPT"] | wait GROUP_ID | read AGENT_ID [OFFSET] | send AGENT_ID PROMPT | stop AGENT_ID | close AGENT_ID`,safety:`background-agent`,subcommands:ge()}}function _e(){let e=g();return{name:e.name,...e.displayName===void 0?{}:{displayName:e.displayName},description:e.description,requiresPermission:!1,execute:(e,t)=>pe(he(e),t),...e.modelInvocable===void 0?{}:{modelInvocable:e.modelInvocable},...e.userInvocable===void 0?{}:{userInvocable:e.userInvocable},...e.argumentHint===void 0?{}:{argumentHint:e.argumentHint},...e.safety===void 0?{}:{safety:e.safety}}}var ve=class{name=`agent`;getCommands(){return[g()]}};function ye(){return{name:`agent-command-agent`,commandSources:[new ve],systemCommands:[_e()],sessionRequirements:[`agent-runtime`]}}function be(e){return e.trim().split(/\s+/).filter(Boolean)}async function xe(t,n){let[r=`list`,i,...a]=be(n);if(r===`list`){let n=(0,e.listCommandBackgroundTasks)(t);return{message:(0,e.formatCommandBackgroundTaskList)(n),success:!0,data:{count:n.length}}}if(!i)return{message:e.BACKGROUND_COMMAND_USAGE,success:!1};if(r===`read`||r===`log`||r===`open`){let n=await(0,e.readCommandBackgroundTaskLog)(t,i,(0,e.parseCommandBackgroundLogCursor)(a[0])),r=n.nextCursor?`\nNext offset: ${n.nextCursor.offset}`:``;return{message:n.lines.length>0?`${n.lines.join(`
6
- `)}${r}`:`No log lines: ${i}`,success:!0,data:{taskId:i,nextOffset:n.nextCursor?.offset}}}return r===`cancel`||r===`stop`?(await(0,e.cancelCommandBackgroundTask)(t,i,a.join(` `)||void 0),{message:`Background task cancelled: ${i}`,success:!0,data:{taskId:i}}):r===`close`||r===`dismiss`?(await(0,e.closeCommandBackgroundTask)(t,i),{message:`Background task closed: ${i}`,success:!0,data:{taskId:i}}):{message:`Unknown background action: ${r}`,success:!1}}function Se(){return{name:`background`,displayName:`Background Tasks`,description:e.BACKGROUND_COMMAND_DESCRIPTION,source:`background`,modelInvocable:!1,subcommands:(0,e.buildBackgroundCommandSubcommands)()}}function Ce(){let e=Se();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,lifecycle:`inline`,subcommands:e.subcommands,execute:xe}}var we=class{name=`background`;getCommands(){return[Se()]}};function Te(){return{name:`agent-command-background`,commandSources:[new we],systemCommands:[Ce()]}}function Ee(e){let t=e.trim();return t.length>0?t:void 0}async function De(t,n){let{before:r,after:i,beforeMessageCount:a,afterMessageCount:o}=await(0,e.compactCommandContext)(t,Ee(n)),s=a-o;return{message:[`Context compacted.`,` Removed messages: ${s} (${a>0?Math.round(s/a*100):0}% of total)`,` Context: ${Math.round(r.usedPercentage)}% → ${Math.round(i.usedPercentage)}%`].join(`
7
- `),success:!0,data:{before:r,after:i,beforeMessageCount:a,afterMessageCount:o}}}function Oe(){return{name:`compact`,displayName:`Compact Context`,description:`Compress context window`,source:`compact`,modelInvocable:!0,argumentHint:`[instructions]`,safety:`write`,example:`/compact Summarize the current context`}}function ke(){let e=Oe();return{name:e.name,displayName:e.displayName,description:e.description,example:e.example,requiresPermission:!1,userInvocable:!0,modelInvocable:e.modelInvocable,argumentHint:e.argumentHint,safety:e.safety,lifecycle:`blocking`,execute:De}}var Ae=class{name=`compact`;getCommands(){return[Oe()]}};function je(){return{name:`agent-command-compact`,commandSources:[new Ae],systemCommands:[ke()]}}const _=[`Usage: /context [list] | add <path> | remove <path> | clear | auto on | off | <percent> | reset`,`Examples: /context list, /context add AGENTS.md, /context remove AGENTS.md, /context auto 85%`].join(`
8
- `);function v(e){return e===!1?`disabled`:`${Math.round(e*100)}%`}function y(e,t){return e===!1?`Auto compact: disabled (${t})`:`Auto compact: ${v(e)} (${t})`}function Me(e){return e?`settings`:`current session only`}async function Ne(t,n){let r=n.trim().split(/\s+/).filter(e=>e.length>0);if(r.length>0)return Pe(t,r);let i=(0,e.readCommandContextState)(t),a=(0,e.readAutoCompactThreshold)(t),o=(0,e.readAutoCompactThresholdSource)(t),s=We(t.getSession().getFullHistory()),c=(0,e.listCommandContextReferences)(t);return{message:[`Context: ${i.usedTokens.toLocaleString()} / ${i.maxTokens.toLocaleString()} tokens (${Math.round(i.usedPercentage)}%)`,y(a,o),Be(c),`History: ${s.turnCount} turn${s.turnCount===1?``:`s`}`].join(`
9
- `),success:!0,data:{usedTokens:i.usedTokens,maxTokens:i.maxTokens,percentage:i.usedPercentage,autoCompactThreshold:a,autoCompactThresholdSource:o,references:c}}}async function Pe(t,n){let[r,...i]=n;if(r===`list`)return i.length>0?{success:!1,message:_}:Ge(t);if(r===`add`)return Ie(t,i);if(r===`remove`)return Le(t,i);if(r===`clear`){if(i.length>0)return{success:!1,message:_};let n=(0,e.clearCommandContextReferences)(t);return{success:!0,message:`Context references cleared: ${n.removed.length} removed.`,data:{removed:n.removed}}}return r===`auto`?Fe(t,i):{success:!1,message:_}}function Fe(t,n){let[r,i]=n;if(i!==void 0)return{success:!1,message:_};if(r===void 0){let n=(0,e.readAutoCompactThreshold)(t),r=(0,e.readAutoCompactThresholdSource)(t);return{success:!0,message:[y(n,r),_].join(`
10
- `),data:{autoCompactThreshold:n,autoCompactThresholdSource:r}}}if(r===`on`)return b(t,e.DEFAULT_AUTO_COMPACT_THRESHOLD,`enabled`);if(r===`off`)return b(t,!1,`disabled`);if(r===`reset`){let n=(0,e.resetAutoCompactThresholdSetting)(t);return(0,e.setCommandAutoCompactThreshold)(t,e.DEFAULT_AUTO_COMPACT_THRESHOLD,`default`),{success:!0,message:`Auto compact reset to default: ${v(e.DEFAULT_AUTO_COMPACT_THRESHOLD)} (${Me(n)}).`,data:{autoCompactThreshold:e.DEFAULT_AUTO_COMPACT_THRESHOLD,autoCompactThresholdSource:`default`,persisted:n}}}let a=ze(r);return a.success?b(t,a.threshold,`threshold set`):{success:!1,message:`${a.message}\n${_}`}}async function Ie(t,n){let r=n.join(` `).trim();if(!r)return{success:!1,message:_};let i=await(0,e.addCommandContextReference)(t,r);return i.reference?{success:!0,message:[`Context reference added: ${S(i.reference)}.`,...i.evicted.length>0?[`Evicted ${i.evicted.length} older context reference(s).`]:[]].join(`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@robota-sdk/agent-framework"),t=require("@robota-sdk/agent-core"),n=require("node:fs"),r=require("node:os"),i=require("node:path"),a=require("node:child_process"),o=require("@robota-sdk/agent-preset");const s=`general-purpose`;function c(e){let t=[],n=``,r,i=!1;for(let a of e){if(i){n+=a,i=!1;continue}if(r&&a===`\\`){i=!0;continue}if(r){a===r?r=void 0:n+=a;continue}if(a===`"`||a===`'`){r=a;continue}if(/\s/.test(a)){n.length>0&&(t.push(n),n=``);continue}n+=a}return n.length>0&&t.push(n),t}function l(e){let t=[],n,r,i;for(let a=0;a<e.length;a+=1){let o=e[a];if(o!==`--background`){if(o===`--agent`||o===`--type`||o===`-a`){n=e[a+1],a+=1;continue}if(o===`--model`){r=e[a+1],a+=1;continue}if(o===`--isolation`){let t=e[a+1];(t===`none`||t===`worktree`)&&(i=t),a+=1;continue}o!==void 0&&t.push(o)}}return{positional:t,...n?{agentType:n}:{},...r?{model:r}:{},...i?{isolation:i}:{}}}function u(e,t,n,r){return{agentType:t,label:n,mode:`background`,prompt:r,...e.model?{model:e.model}:{},...e.isolation?{isolation:e.isolation}:{}}}function ee(e,t){let n=l(e),[r,...i]=n.positional,a=n.agentType??s,o=n.positional;!n.agentType&&r&&t.has(r)&&(a=r,o=i);let c=o.join(` `).trim();if(c)return u(n,a,a,c)}function te(e,t){let n=l(e);return n.positional.map(e=>ne(e,n,t)).filter(e=>e!==void 0)}function ne(e,t,n){let r=e.indexOf(`=`);if(r>0)return re(e.slice(0,r),e.slice(r+1),t,n);let i=e.indexOf(`:`);if(i<=0||i===e.length-1)return;let a=e.slice(0,i),o=e.slice(i+1);return u(t,t.agentType??(n.has(a)?a:s),a,o)}function re(e,t,n,r){let i=t.indexOf(`:`);if(i===-1)return u(n,n.agentType??(r.has(e)?e:s),e,t);if(!(i===0||i===t.length-1))return u(n,t.slice(0,i),e,t.slice(i+1))}function d(e){return e instanceof Error?e.message:String(e)}function f(e){return new Set(e.listAgentDefinitions().map(e=>e.name))}function p(e,t){let n=e.listAgentDefinitions();if(!n.some(e=>e.name===t))return{message:`Unknown agent type: ${t}\nAvailable agents: ${n.map(e=>e.name).join(`, `)}`,success:!1}}async function m(e,t){let n=p(e,t.agentType);if(n)return n;try{return{state:await e.spawnAgentJob(t)}}catch(e){return{message:d(e),success:!1}}}function ie(){return{message:``,effects:[{type:`agent-switcher-requested`}],success:!0}}async function ae(e){let t=e.listAgentDefinitions(),n=e.listAgentJobs();return{message:[`Available agents:`,...t.map(e=>` ${e.name} - ${e.description}`),``,n.length===0?`No active agent jobs.`:`Agent jobs:`,...n.map(e=>` ${oe(e)}`)].join(`
2
+ `),success:!0,data:{agents:t.length,jobs:n.length}}}function oe(e){let t=[e.worktreePath?`worktree=${e.worktreePath}`:void 0,e.branchName?`branch=${e.branchName}`:void 0].filter(e=>e!==void 0),n=t.length>0?` ${t.join(` `)}`:``;return`${e.id} [${e.status}${n}] ${e.label} - ${e.promptPreview}`}async function se(e,t){let n=ee(t,f(e));if(!n)return{message:`Usage: agent run [AGENT_NAME] [--agent AGENT_NAME] PROMPT`,success:!1};let r=await m(e,n);if(`success`in r)return r;let{state:i}=r;return{message:`Started agent job: ${i.id}`,success:!0,data:{agentId:i.id,status:i.status}}}async function ce(t,n){let r=n.includes(`--wait`)||!n.includes(`--detach`),i=te(n.filter(e=>e!==`--wait`&&e!==`--detach`),f(t));if(i.length===0)return{message:`Usage: agent parallel [--wait|--detach] LABEL:"PROMPT" [LABEL=AGENT_NAME:"PROMPT"]`,success:!1};let a=i.map(e=>p(t,e.agentType)).find(e=>e!==void 0);if(a)return a;let o;try{o=await Promise.all(i.map(e=>t.spawnAgentJob(e)))}catch(e){return{message:d(e),success:!1}}let s=t.createBackgroundJobGroup({waitPolicy:`wait_all`,taskIds:o.map(e=>e.id),label:`agent parallel`});if(r){let n=(0,e.summarizeBackgroundJobGroup)(await t.waitBackgroundJobGroup(s.id));return{message:he(n),success:!0,data:{agentIds:o.map(e=>e.id),groupId:s.id,summary:n}}}return{message:[`Started agent jobs:`,...o.map(e=>`${e.label}: ${e.id}`)].join(`
3
+ `),success:!0,data:{agentIds:o.map(e=>e.id),groupId:s.id}}}async function le(t,n){let[r]=n;if(!r)return{message:`Usage: agent wait GROUP_ID`,success:!1};let i=(0,e.summarizeBackgroundJobGroup)(await t.waitBackgroundJobGroup(r));return{message:he(i),success:!0,data:{groupId:r,summary:i}}}async function ue(e,t){let[n,r]=t;if(!n)return{message:`Usage: agent read AGENT_ID [OFFSET]`,success:!1};let i=r?{offset:Number.parseInt(r,10)}:void 0,a=await e.readBackgroundTaskLog(n,i),o=a.nextCursor?`\nNext offset: ${a.nextCursor.offset}`:``;return{message:a.lines.length>0?`${a.lines.join(`
4
+ `)}${o}`:`No log lines: ${n}`,success:!0,data:{agentId:n,nextOffset:a.nextCursor?.offset}}}async function de(e,t){let[n,...r]=t,i=r.join(` `).trim();return!n||!i?{message:`Usage: agent send AGENT_ID PROMPT`,success:!1}:(await e.sendAgentJob(n,i),{message:`Sent input to agent job: ${n}`,success:!0,data:{agentId:n}})}async function fe(e,t){let[n,...r]=t;return n?(await e.cancelAgentJob(n,r.join(` `)||void 0),{message:`Agent job stopped: ${n}`,success:!0,data:{agentId:n}}):{message:`Usage: agent stop AGENT_ID [REASON]`,success:!1}}async function pe(e,t){let[n]=t;return n?(await e.closeAgentJob(n),{message:`Agent job closed: ${n}`,success:!0,data:{agentId:n}}):{message:`Usage: agent close AGENT_ID`,success:!1}}async function me(e,t){try{if(t.trim()===``)return ie();let[n=`list`,...r]=c(t);return n===`list`&&r.length===0?ae(e):n===`run`?se(e,r):n===`parallel`?ce(e,r):n===`wait`?le(e,r):n===`read`||n===`open`?ue(e,r):n===`send`?de(e,r):n===`stop`||n===`cancel`?fe(e,r):n===`close`?pe(e,r):se(e,[n,...r])}catch(e){return{message:d(e),success:!1}}}function he(e){return[`Background job group ${e.groupId}: ${e.status} (${e.completed}/${e.total} completed, ${e.failed} failed, ${e.cancelled} cancelled, ${e.pending} pending)`,...e.lines].join(`
5
+ `)}function ge(e){let t=e.getAgentJobCapability?.();if(!t)throw Error(`Agent job capability is not available in this context.`);return t}function _e(){return[{name:`list`,description:`List available agents and active jobs`,source:`agent`},{name:`run`,description:`Start one background agent job`,source:`agent`},{name:`parallel`,description:`Run multiple agents in parallel`,source:`agent`},{name:`wait`,description:`Wait for a background agent group summary`,source:`agent`},{name:`read`,description:`Read an agent job log page`,source:`agent`},{name:`send`,description:`Send follow-up input to an agent job`,source:`agent`},{name:`stop`,description:`Cancel a running agent job`,source:`agent`},{name:`close`,description:`Dismiss a terminal agent job`,source:`agent`},{name:`open`,description:`Focus an agent job detail view when supported`,source:`agent`}]}function h(){return{name:`agent`,displayName:`Agent Jobs`,description:[`Subagent jobs command.`,`Natural-language arguments start one background agent job.`,`When the user explicitly asks to create, run, spawn, delegate to, or use agents/subagents, start the requested agent command immediately and do not ask a follow-up question unless execution is impossible or unsafe.`,`If the target item is unspecified, include target selection inside the agent prompt instead of delaying execution.`,`The parallel form starts multiple background agent jobs as a wait_all group and returns a consolidated group summary unless --detach is present.`,`list, wait, read, send, stop, close, and open manage existing agent jobs.`].join(` `),source:`agent`,modelInvocable:!0,argumentHint:`PROMPT | AGENT_NAME PROMPT | list | parallel [--wait|--detach] LABEL:"PROMPT" [LABEL=AGENT_NAME:"PROMPT"] | wait GROUP_ID | read AGENT_ID [OFFSET] | send AGENT_ID PROMPT | stop AGENT_ID | close AGENT_ID`,safety:`background-agent`,subcommands:_e()}}function ve(){let e=h();return{name:e.name,...e.displayName===void 0?{}:{displayName:e.displayName},description:e.description,requiresPermission:!1,execute:(e,t)=>me(ge(e),t),...e.modelInvocable===void 0?{}:{modelInvocable:e.modelInvocable},...e.userInvocable===void 0?{}:{userInvocable:e.userInvocable},...e.argumentHint===void 0?{}:{argumentHint:e.argumentHint},...e.safety===void 0?{}:{safety:e.safety}}}var ye=class{name=`agent`;getCommands(){return[h()]}};function be(){return{name:`agent-command-agent`,commandSources:[new ye],systemCommands:[ve()],sessionRequirements:[`agent-runtime`]}}function xe(e){return e.trim().split(/\s+/).filter(Boolean)}async function Se(t,n){let[r=`list`,i,...a]=xe(n);if(r===`list`){let n=(0,e.listCommandBackgroundTasks)(t);return{message:(0,e.formatCommandBackgroundTaskList)(n),success:!0,data:{count:n.length}}}if(!i)return{message:e.BACKGROUND_COMMAND_USAGE,success:!1};if(r===`read`||r===`log`||r===`open`){let n=await(0,e.readCommandBackgroundTaskLog)(t,i,(0,e.parseCommandBackgroundLogCursor)(a[0])),r=n.nextCursor?`\nNext offset: ${n.nextCursor.offset}`:``;return{message:n.lines.length>0?`${n.lines.join(`
6
+ `)}${r}`:`No log lines: ${i}`,success:!0,data:{taskId:i,nextOffset:n.nextCursor?.offset}}}return r===`cancel`||r===`stop`?(await(0,e.cancelCommandBackgroundTask)(t,i,a.join(` `)||void 0),{message:`Background task cancelled: ${i}`,success:!0,data:{taskId:i}}):r===`close`||r===`dismiss`?(await(0,e.closeCommandBackgroundTask)(t,i),{message:`Background task closed: ${i}`,success:!0,data:{taskId:i}}):{message:`Unknown background action: ${r}`,success:!1}}function g(){return{name:`background`,displayName:`Background Tasks`,description:e.BACKGROUND_COMMAND_DESCRIPTION,source:`background`,modelInvocable:!1,subcommands:(0,e.buildBackgroundCommandSubcommands)()}}function Ce(){let e=g();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,lifecycle:`inline`,subcommands:e.subcommands,execute:Se}}var we=class{name=`background`;getCommands(){return[g()]}};function Te(){return{name:`agent-command-background`,commandSources:[new we],systemCommands:[Ce()]}}function Ee(e){let t=e.trim();return t.length>0?t:void 0}async function De(t,n){let{before:r,after:i,beforeMessageCount:a,afterMessageCount:o}=await(0,e.compactCommandContext)(t,Ee(n)),s=a-o;return{message:[`Context compacted.`,` Removed messages: ${s} (${a>0?Math.round(s/a*100):0}% of total)`,` Context: ${Math.round(r.usedPercentage)}% → ${Math.round(i.usedPercentage)}%`].join(`
7
+ `),success:!0,data:{before:r,after:i,beforeMessageCount:a,afterMessageCount:o}}}function _(){return{name:`compact`,displayName:`Compact Context`,description:`Compress context window`,source:`compact`,modelInvocable:!0,argumentHint:`[instructions]`,safety:`write`,example:`/compact Summarize the current context`}}function Oe(){let e=_();return{name:e.name,displayName:e.displayName,description:e.description,example:e.example,requiresPermission:!1,userInvocable:!0,modelInvocable:e.modelInvocable,argumentHint:e.argumentHint,safety:e.safety,lifecycle:`blocking`,execute:De}}var ke=class{name=`compact`;getCommands(){return[_()]}};function Ae(){return{name:`agent-command-compact`,commandSources:[new ke],systemCommands:[Oe()]}}const v=[`Usage: /context [list] | add <path> | remove <path> | clear | auto on | off | <percent> | reset`,`Examples: /context list, /context add AGENTS.md, /context remove AGENTS.md, /context auto 85%`].join(`
8
+ `);function y(e){return e===!1?`disabled`:`${Math.round(e*100)}%`}function b(e,t){return e===!1?`Auto compact: disabled (${t})`:`Auto compact: ${y(e)} (${t})`}function je(e){return e?`settings`:`current session only`}async function Me(t,n){let r=n.trim().split(/\s+/).filter(e=>e.length>0);if(r.length>0)return Ne(t,r);let i=(0,e.readCommandContextState)(t),a=(0,e.readAutoCompactThreshold)(t),o=(0,e.readAutoCompactThresholdSource)(t),s=Ue(t.getSession().getFullHistory()),c=(0,e.listCommandContextReferences)(t);return{message:[`Context: ${i.usedTokens.toLocaleString()} / ${i.maxTokens.toLocaleString()} tokens (${Math.round(i.usedPercentage)}%)`,b(a,o),ze(c),`History: ${s.turnCount} turn${s.turnCount===1?``:`s`}`].join(`
9
+ `),success:!0,data:{usedTokens:i.usedTokens,maxTokens:i.maxTokens,percentage:i.usedPercentage,autoCompactThreshold:a,autoCompactThresholdSource:o,references:c}}}async function Ne(t,n){let[r,...i]=n;if(r===`list`)return i.length>0?{success:!1,message:v}:We(t);if(r===`add`)return Fe(t,i);if(r===`remove`)return Ie(t,i);if(r===`clear`){if(i.length>0)return{success:!1,message:v};let n=(0,e.clearCommandContextReferences)(t);return{success:!0,message:`Context references cleared: ${n.removed.length} removed.`,data:{removed:n.removed}}}return r===`auto`?Pe(t,i):{success:!1,message:v}}function Pe(t,n){let[r,i]=n;if(i!==void 0)return{success:!1,message:v};if(r===void 0){let n=(0,e.readAutoCompactThreshold)(t),r=(0,e.readAutoCompactThresholdSource)(t);return{success:!0,message:[b(n,r),v].join(`
10
+ `),data:{autoCompactThreshold:n,autoCompactThresholdSource:r}}}if(r===`on`)return x(t,e.DEFAULT_AUTO_COMPACT_THRESHOLD,`enabled`);if(r===`off`)return x(t,!1,`disabled`);if(r===`reset`){let n=(0,e.resetAutoCompactThresholdSetting)(t);return(0,e.setCommandAutoCompactThreshold)(t,e.DEFAULT_AUTO_COMPACT_THRESHOLD,`default`),{success:!0,message:`Auto compact reset to default: ${y(e.DEFAULT_AUTO_COMPACT_THRESHOLD)} (${je(n)}).`,data:{autoCompactThreshold:e.DEFAULT_AUTO_COMPACT_THRESHOLD,autoCompactThresholdSource:`default`,persisted:n}}}let a=Re(r);return a.success?x(t,a.threshold,`threshold set`):{success:!1,message:`${a.message}\n${v}`}}async function Fe(t,n){let r=n.join(` `).trim();if(!r)return{success:!1,message:v};let i=await(0,e.addCommandContextReference)(t,r);return i.reference?{success:!0,message:[`Context reference added: ${C(i.reference)}.`,...i.evicted.length>0?[`Evicted ${i.evicted.length} older context reference(s).`]:[]].join(`
11
11
  `),data:{reference:i.reference,evicted:i.evicted}}:{success:!1,message:i.diagnostics.join(`
12
- `)||`Context reference not found: ${r}`,data:{diagnostics:i.diagnostics}}}function Le(t,n){let r=n.join(` `).trim();if(!r)return{success:!1,message:_};let i=(0,e.removeCommandContextReference)(t,r);return i.removed?{success:!0,message:`Context reference removed: ${S(i.removed)}.`,data:{removed:i.removed}}:{success:!1,message:`Context reference not found: ${r}`}}function b(t,n,r){let i=(0,e.writeAutoCompactThresholdSetting)(t,n),a=i?`settings`:`session`;return(0,e.setCommandAutoCompactThreshold)(t,n,a),{success:!0,message:Re(r,n,i),data:{autoCompactThreshold:n,autoCompactThresholdSource:a,persisted:i}}}function Re(e,t,n){let r=Me(n);return e===`disabled`?`Auto compact disabled (${r}).`:e===`enabled`?`Auto compact enabled at ${v(t)} (${r}).`:`Auto compact threshold set to ${v(t)} (${r}).`}function ze(e){if(e.endsWith(`%`)){let t=Number(e.slice(0,-1));return!Number.isFinite(t)||t<=0||t>100?{success:!1,message:`Auto compact percentage must be greater than 0% and at most 100%.`}:{success:!0,threshold:t/100}}if(e.includes(`.`)){let t=Number(e);return!Number.isFinite(t)||t<=0||t>1?{success:!1,message:`Auto compact fraction must be greater than 0 and at most 1.`}:{success:!0,threshold:t}}return{success:!1,message:`Use a percentage such as 85% or a fraction such as 0.85.`}}function Be(e){return`References: ${e.filter(e=>e.status===`active`).length} active, ${e.filter(e=>e.status===`observed`).length} observed`}function x(e){return Math.ceil(e/4)}function S(e){return[e.relativePath,`[${e.loadType}, ${e.status}]`,`~${x(e.byteLength).toLocaleString()} tokens`].join(` `)}function Ve(e){try{return JSON.parse(e)}catch{return null}}function He(e){let t=Ve(e);if(t===null)return``;let n=Object.values(t)[0],r=typeof n==`string`?n:JSON.stringify(n);return r.length>60?`${r.slice(0,60)}…`:r}function Ue(e){let t=0,n=0,r=0,i=0,a=0,o=0,s=0;for(let c of e){let e=Math.ceil(JSON.stringify(c).length/4);c.role===`system`?t+=e:c.role===`user`?(n+=e,r++):c.role===`assistant`?(i+=e,a++):c.role===`tool`&&(o+=e,s++)}return{systemTokens:t,userTokens:n,userCount:r,assistantTokens:i,assistantCount:a,toolTokens:o,toolCallCount:s,totalTokens:t+n+i+o}}function We(e){let t=new Map;for(let n of e){if(n.category!==`chat`||n.type!==`assistant`)continue;let e=n.data;for(let n of e.toolCalls??[])t.set(n.id,{name:n.function.name,firstArg:He(n.function.arguments)})}let n=0,r=0,i=new Map;for(let a of e)if(a.category===`chat`){if(a.type===`user`)n++;else if(a.type===`tool`){let e=a.data,n=t.get(e.toolCallId??``),o=n?.name??`tool`,s=n?.firstArg??``;r++,i.set(`${o}:${s}`,{toolName:o,displayArg:s})}}return{turnCount:n,toolResults:[...i.values()],totalToolCallCount:r}}function C(e,t,n){let r=`${e}${t>0?` — ~${t.toLocaleString()} tokens`:``}:`;return n.length===0?`${r}\n (none)`:[r,...n.map(e=>` ${e}`)].join(`
13
- `)}function Ge(t){let n=(0,e.readCommandContextState)(t),r=(0,e.readAutoCompactThreshold)(t),i=(0,e.readAutoCompactThresholdSource)(t),a=Ue(t.getSession().getHistory()),o=We(t.getSession().getFullHistory()),s=(0,e.listCommandContextReferences)(t),c=s.filter(e=>e.loadType===`system`),l=s.filter(e=>e.loadType===`manual`),u=s.filter(e=>e.loadType===`prompt-reference`),ee=c.reduce((e,t)=>e+x(t.byteLength),0),te=l.reduce((e,t)=>e+x(t.byteLength),0),ne=u.reduce((e,t)=>e+x(t.byteLength),0),d=o.turnCount===0?`Conversation history — 0 turns`:`Conversation history — ${o.turnCount} turn${o.turnCount===1?``:`s`} | ~${a.totalTokens.toLocaleString()} tokens`,f=o.toolResults.map(e=>`${e.toolName}${e.displayArg?`: ${e.displayArg}`:``}`),p=o.toolResults.length,m=o.totalToolCallCount,h=m===0?`Tool results (0): (none)`:p<m?`Tool results (${p} unique / ${m} calls, ~${a.toolTokens.toLocaleString()} tokens):`:`Tool results (${p}, ~${a.toolTokens.toLocaleString()} tokens):`,re=o.turnCount===0?[]:[`User (${a.userCount}): ~${a.userTokens.toLocaleString()} tokens`,`Assistant (${a.assistantCount}): ~${a.assistantTokens.toLocaleString()} tokens`,...a.systemTokens>0?[`System messages: ~${a.systemTokens.toLocaleString()} tokens`]:[],m>0?[h,...f.map(e=>` ${e}`)].join(`
14
- `):h],ie=o.turnCount===0?`${d}:\n (none)`:[`${d}:`,...re.map(e=>` ${e}`)].join(`
15
- `);return{success:!0,message:[`Context: ${n.usedTokens.toLocaleString()} / ${n.maxTokens.toLocaleString()} tokens (${Math.round(n.usedPercentage)}%)`,y(r,i),``,C(`System prompt (active every turn)`,ee,c.map(S)),``,ie,``,C(`Manually added`,te,l.map(S)),``,C(`Prompt references (@-syntax)`,ne,u.map(S))].join(`
16
- `),data:{references:s,history:{turnCount:o.turnCount,toolResults:o.toolResults}}}}function w(){return{name:`context`,displayName:`Context References`,description:`Context window info, reference inventory, and auto-compact controls`,source:`context`,modelInvocable:!1,argumentHint:`list | add <path> | remove <path> | clear | auto ...`,subcommands:[{name:`list`,description:`List loaded context references`,source:`context`},{name:`add`,description:`Add a file to active context references`,source:`context`},{name:`remove`,description:`Remove a context reference`,source:`context`},{name:`clear`,description:`Clear context references`,source:`context`},{name:`auto`,description:`Inspect or change auto-compact policy`,source:`context`}]}}function Ke(){let e=w();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,execute:Ne}}var qe=class{name=`context`;getCommands(){return[w()]}};function Je(){return{name:`agent-command-context`,commandSources:[new qe],systemCommands:[Ke()]}}function Ye(t,n){return{success:!0,message:`Exit requested.`,effects:[(0,e.createSessionExitRequestedEffect)()]}}function Xe(){return{name:`exit`,displayName:`Exit Session`,description:e.EXIT_COMMAND_DESCRIPTION,source:`exit`,modelInvocable:!1}}function Ze(){let e=Xe();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!0,userInvocable:!0,modelInvocable:!1,lifecycle:`inline`,execute:Ye}}var Qe=class{name=`exit`;getCommands(){return[Xe()]}};const $e={exit:{type:`confirm`,message:`Exit the session?`}};function et(){return{name:`agent-command-exit`,commandSources:[new Qe],systemCommands:[Ze()],interactionHints:$e}}function tt(t,n){return{success:!0,message:(0,e.formatCommandHelpMessage)(t)}}function nt(){return{name:`help`,displayName:`Help`,description:e.HELP_COMMAND_DESCRIPTION,source:`help`,modelInvocable:!1}}function rt(){let e=nt();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,lifecycle:`inline`,execute:tt}}var it=class{name=`help`;getCommands(){return[nt()]}};function at(){return{name:`agent-command-help`,commandSources:[new it],systemCommands:[rt()]}}function ot(t,n){let r=(0,e.parseLanguageArgument)(n);return r===void 0?{message:(0,e.formatLanguageUsageMessage)(),success:!1}:{message:`Language set to "${r}".`,success:!0,data:{language:r},effects:[{type:`language-change-requested`,language:r}]}}function st(){return{name:`language`,displayName:`Language`,description:e.LANGUAGE_COMMAND_DESCRIPTION,source:`language`,argumentHint:e.LANGUAGE_COMMAND_ARGUMENT_HINT,subcommands:(0,e.buildLanguageCommandSubcommands)(`language`),modelInvocable:!1}}function ct(){let e=st();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,argumentHint:e.argumentHint,subcommands:e.subcommands,lifecycle:`inline`,execute:ot}}var lt=class{name=`language`;getCommands(){return[st()]}};const ut={language:{type:`pick`,getItems:()=>(0,e.buildLanguageCommandSubcommands)().map(e=>({label:`${e.name} ${e.description??``}`.trimEnd(),value:e.name,description:e.description}))}};function dt(){return{name:`agent-command-language`,commandSources:[new lt],systemCommands:[ct()],interactionHints:ut}}function T(){return{message:e.MEMORY_COMMAND_USAGE,success:!1}}function ft(e){return{message:e instanceof Error?e.message:String(e),success:!1}}function pt(e){let t=e.list(),n=t.topics.length>0?t.topics.map(e=>`- ${e.name}: ${e.path}`).join(`
12
+ `)||`Context reference not found: ${r}`,data:{diagnostics:i.diagnostics}}}function Ie(t,n){let r=n.join(` `).trim();if(!r)return{success:!1,message:v};let i=(0,e.removeCommandContextReference)(t,r);return i.removed?{success:!0,message:`Context reference removed: ${C(i.removed)}.`,data:{removed:i.removed}}:{success:!1,message:`Context reference not found: ${r}`}}function x(t,n,r){let i=(0,e.writeAutoCompactThresholdSetting)(t,n),a=i?`settings`:`session`;return(0,e.setCommandAutoCompactThreshold)(t,n,a),{success:!0,message:Le(r,n,i),data:{autoCompactThreshold:n,autoCompactThresholdSource:a,persisted:i}}}function Le(e,t,n){let r=je(n);return e===`disabled`?`Auto compact disabled (${r}).`:e===`enabled`?`Auto compact enabled at ${y(t)} (${r}).`:`Auto compact threshold set to ${y(t)} (${r}).`}function Re(e){if(e.endsWith(`%`)){let t=Number(e.slice(0,-1));return!Number.isFinite(t)||t<=0||t>100?{success:!1,message:`Auto compact percentage must be greater than 0% and at most 100%.`}:{success:!0,threshold:t/100}}if(e.includes(`.`)){let t=Number(e);return!Number.isFinite(t)||t<=0||t>1?{success:!1,message:`Auto compact fraction must be greater than 0 and at most 1.`}:{success:!0,threshold:t}}return{success:!1,message:`Use a percentage such as 85% or a fraction such as 0.85.`}}function ze(e){return`References: ${e.filter(e=>e.status===`active`).length} active, ${e.filter(e=>e.status===`observed`).length} observed`}function S(e){return Math.ceil(e/t.CONTEXT_ESTIMATE_CHARS_PER_TOKEN)}function C(e){return[e.relativePath,`[${e.loadType}, ${e.status}]`,`~${S(e.byteLength).toLocaleString()} tokens`].join(` `)}function Be(e){try{return JSON.parse(e)}catch{return null}}function Ve(e){let t=Be(e);if(t===null)return``;let n=Object.values(t)[0],r=typeof n==`string`?n:JSON.stringify(n);return r.length>60?`${r.slice(0,60)}…`:r}function He(e){let n=0,r=0,i=0,a=0,o=0,s=0,c=0;for(let l of e){let e=Math.ceil(JSON.stringify(l).length/t.CONTEXT_ESTIMATE_CHARS_PER_TOKEN);l.role===`system`?n+=e:l.role===`user`?(r+=e,i++):l.role===`assistant`?(a+=e,o++):l.role===`tool`&&(s+=e,c++)}return{systemTokens:n,userTokens:r,userCount:i,assistantTokens:a,assistantCount:o,toolTokens:s,toolCallCount:c,totalTokens:n+r+a+s}}function Ue(e){let t=new Map;for(let n of e){if(n.category!==`chat`||n.type!==`assistant`)continue;let e=n.data;for(let n of e.toolCalls??[])t.set(n.id,{name:n.function.name,firstArg:Ve(n.function.arguments)})}let n=0,r=0,i=new Map;for(let a of e)if(a.category===`chat`){if(a.type===`user`)n++;else if(a.type===`tool`){let e=a.data,n=t.get(e.toolCallId??``),o=n?.name??`tool`,s=n?.firstArg??``;r++,i.set(`${o}:${s}`,{toolName:o,displayArg:s})}}return{turnCount:n,toolResults:[...i.values()],totalToolCallCount:r}}function w(e,t,n){let r=`${e}${t>0?` — ~${t.toLocaleString()} tokens`:``}:`;return n.length===0?`${r}\n (none)`:[r,...n.map(e=>` ${e}`)].join(`
13
+ `)}function We(t){let n=(0,e.readCommandContextState)(t),r=(0,e.readAutoCompactThreshold)(t),i=(0,e.readAutoCompactThresholdSource)(t),a=He(t.getSession().getHistory()),o=Ue(t.getSession().getFullHistory()),s=(0,e.listCommandContextReferences)(t),c=s.filter(e=>e.loadType===`system`),l=s.filter(e=>e.loadType===`manual`),u=s.filter(e=>e.loadType===`prompt-reference`),ee=c.reduce((e,t)=>e+S(t.byteLength),0),te=l.reduce((e,t)=>e+S(t.byteLength),0),ne=u.reduce((e,t)=>e+S(t.byteLength),0),re=o.turnCount===0?`Conversation history — 0 turns`:`Conversation history — ${o.turnCount} turn${o.turnCount===1?``:`s`} | ~${a.totalTokens.toLocaleString()} tokens`,d=o.toolResults.map(e=>`${e.toolName}${e.displayArg?`: ${e.displayArg}`:``}`),f=o.toolResults.length,p=o.totalToolCallCount,m=p===0?`Tool results (0): (none)`:f<p?`Tool results (${f} unique / ${p} calls, ~${a.toolTokens.toLocaleString()} tokens):`:`Tool results (${f}, ~${a.toolTokens.toLocaleString()} tokens):`,ie=o.turnCount===0?[]:[`User (${a.userCount}): ~${a.userTokens.toLocaleString()} tokens`,`Assistant (${a.assistantCount}): ~${a.assistantTokens.toLocaleString()} tokens`,...a.systemTokens>0?[`System messages: ~${a.systemTokens.toLocaleString()} tokens`]:[],p>0?[m,...d.map(e=>` ${e}`)].join(`
14
+ `):m],ae=o.turnCount===0?`${re}:\n (none)`:[`${re}:`,...ie.map(e=>` ${e}`)].join(`
15
+ `);return{success:!0,message:[`Context: ${n.usedTokens.toLocaleString()} / ${n.maxTokens.toLocaleString()} tokens (${Math.round(n.usedPercentage)}%)`,b(r,i),``,w(`System prompt (active every turn)`,ee,c.map(C)),``,ae,``,w(`Manually added`,te,l.map(C)),``,w(`Prompt references (@-syntax)`,ne,u.map(C))].join(`
16
+ `),data:{references:s,history:{turnCount:o.turnCount,toolResults:o.toolResults}}}}function T(){return{name:`context`,displayName:`Context References`,description:`Context window info, reference inventory, and auto-compact controls`,source:`context`,modelInvocable:!1,argumentHint:`list | add <path> | remove <path> | clear | auto ...`,subcommands:[{name:`list`,description:`List loaded context references`,source:`context`},{name:`add`,description:`Add a file to active context references`,source:`context`},{name:`remove`,description:`Remove a context reference`,source:`context`},{name:`clear`,description:`Clear context references`,source:`context`},{name:`auto`,description:`Inspect or change auto-compact policy`,source:`context`}]}}function Ge(){let e=T();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,execute:Me}}var Ke=class{name=`context`;getCommands(){return[T()]}};function qe(){return{name:`agent-command-context`,commandSources:[new Ke],systemCommands:[Ge()]}}function Je(){let e=process.env.VISUAL?.trim(),t=process.env.EDITOR?.trim(),n=(e!==void 0&&e.length>0?e:t!==void 0&&t.length>0?t:`vi`).split(/\s+/).filter(e=>e.length>0);return{command:n[0]??`vi`,args:n.slice(1)}}function E(e,t,n){return new Promise((i,o)=>{let s=(0,a.spawn)(e,[...t],{cwd:n,stdio:`inherit`,env:process.env});s.on(`error`,o),s.on(`exit`,(e,t)=>{if(e!==null){i(e);return}if(t){let e=r.constants.signals[t];i(128+(e??0));return}i(0)})})}const Ye="Compose a message in $EDITOR (optionally pre-filled with `/editor <text>`), then return it.";async function Xe(e,t){if(e.canHandoffTerminal?.()!==!0||e.runWithTerminal===void 0)return{message:`An editor is unavailable here (no interactive terminal).`,success:!1};let a=Je(),o=(0,n.mkdtempSync)((0,i.join)((0,r.tmpdir)(),`robota-editor-`)),s=(0,i.join)(o,`message.md`);(0,n.writeFileSync)(s,t??``,`utf8`);try{let t=await e.runWithTerminal(async()=>E(a.command,[...a.args,s],e.getCwd()));if(t!==0)return{message:`Editor exited without saving (code ${t}).`,success:!1,data:{exitCode:t}};let r=(0,n.readFileSync)(s,`utf8`).replace(/\s+$/u,``);return r.length===0?{message:`Editor closed with empty content; nothing composed.`,success:!1}:{message:r,success:!0,data:{content:r}}}finally{(0,n.rmSync)(o,{recursive:!0,force:!0,maxRetries:3,retryDelay:20})}}function D(){return{name:`editor`,displayName:`Editor`,description:Ye,source:`editor`,modelInvocable:!1}}function Ze(){let e=D();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,lifecycle:`inline`,execute:Xe}}var Qe=class{name=`editor`;getCommands(){return[D()]}};function $e(){return{name:`agent-command-editor`,commandSources:[new Qe],systemCommands:[Ze()]}}async function et(n,r){let i=n.getUserInteraction?.();return i&&!(0,t.isConfirmed)(await i.ask((0,t.confirmAction)(`exit`,`Exit the session?`)))?{success:!0,message:`Exit cancelled.`}:{success:!0,message:`Exit requested.`,effects:[(0,e.createSessionExitRequestedEffect)()]}}function tt(){return{name:`exit`,displayName:`Exit Session`,description:e.EXIT_COMMAND_DESCRIPTION,source:`exit`,modelInvocable:!1}}function nt(){let e=tt();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!0,userInvocable:!0,modelInvocable:!1,lifecycle:`inline`,execute:et}}var rt=class{name=`exit`;getCommands(){return[tt()]}};function it(){return{name:`agent-command-exit`,commandSources:[new rt],systemCommands:[nt()]}}const at=`Assign an autonomous goal the agent pursues across turns until satisfied.`;function ot(e){let t=[`Goal: ${e.objective}`,`Status: ${e.status}${e.stopReason?` (${e.stopReason})`:``}`,`Iterations: ${e.iterations} / ${e.maxIterations}`],n=e.progress[e.progress.length-1];return n?.reason&&t.push(`Latest: ${n.reason}`),t.join(`
17
+ `)}async function st(e,t){let n=t.trim(),r=n.split(/\s+/)[0]?.toLowerCase()??``;if(n.length===0||r===`help`)return{message:`Usage:
18
+ /goal <objective> assign a goal and pursue it autonomously
19
+ /goal status show the current goal and progress
20
+ /goal cancel stop the current goal`,success:!0};if(r===`status`){let t=e.getGoalState?.()??null;return t?{message:ot(t),success:!0,data:{status:t.status}}:{message:`No goal is set.`,success:!0}}if(r===`cancel`||r===`stop`){let t=e.cancelGoal?.()??null;return t?{message:`Goal cancelled: ${t.objective}`,success:!0}:{message:`No active goal to cancel.`,success:!1}}if(!e.setGoal)return{message:`Goal pursuit is not available in this session.`,success:!1};let i;try{i=await e.setGoal(n)}catch(e){return{message:e instanceof Error?e.message:String(e),success:!1}}return{message:`Goal set — pursuing autonomously (up to ${i.maxIterations} iterations):\n${i.objective}`,success:!0,data:{goalId:i.id}}}function ct(){return{name:`goal`,displayName:`Autonomous Goal`,description:at,source:`goal`,modelInvocable:!1}}function lt(){let e=ct();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,lifecycle:`inline`,execute:st}}var ut=class{name=`goal`;getCommands(){return[ct()]}};function dt(){return{name:`agent-command-goal`,commandSources:[new ut],systemCommands:[lt()]}}function ft(t,n){return{success:!0,message:(0,e.formatCommandHelpMessage)(t)}}function O(){return{name:`help`,displayName:`Help`,description:e.HELP_COMMAND_DESCRIPTION,source:`help`,modelInvocable:!1}}function pt(){let e=O();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,lifecycle:`inline`,execute:ft}}var mt=class{name=`help`;getCommands(){return[O()]}};function ht(){return{name:`agent-command-help`,commandSources:[new mt],systemCommands:[pt()]}}async function gt(n){let r=n.getUserInteraction?.();if(!r)return;let i=(0,e.buildLanguageCommandSubcommands)().map(e=>({value:e.name,label:e.name,description:e.description})),a=await r.ask((0,t.selectAction)(`language`,`Select language`,i)),o=a.type===`answer`?a.values[0]:void 0;return o===void 0?void 0:(0,e.parseLanguageArgument)(o)}async function _t(t,n){let r=(0,e.parseLanguageArgument)(n);return r===void 0&&(r=await gt(t),r===void 0)?{message:(0,e.formatLanguageUsageMessage)(),success:!1}:{message:`Language set to "${r}".`,success:!0,data:{language:r},effects:[{type:`language-change-requested`,language:r}]}}function k(){return{name:`language`,displayName:`Language`,description:e.LANGUAGE_COMMAND_DESCRIPTION,source:`language`,argumentHint:e.LANGUAGE_COMMAND_ARGUMENT_HINT,subcommands:(0,e.buildLanguageCommandSubcommands)(`language`),modelInvocable:!1}}function vt(){let e=k();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,argumentHint:e.argumentHint,subcommands:e.subcommands,lifecycle:`inline`,execute:_t}}var yt=class{name=`language`;getCommands(){return[k()]}};function bt(){return{name:`agent-command-language`,commandSources:[new yt],systemCommands:[vt()]}}function A(){return{message:e.MEMORY_COMMAND_USAGE,success:!1}}function xt(e){return{message:e instanceof Error?e.message:String(e),success:!1}}function St(e){let t=e.list(),n=t.topics.length>0?t.topics.map(e=>`- ${e.name}: ${e.path}`).join(`
17
21
  `):`(none)`;return{message:[`Memory index: ${t.indexPath}`,`Topics directory: ${t.topicsPath}`,`Topics:`,n].join(`
18
- `),success:!0,data:{indexPath:t.indexPath,topicsPath:t.topicsPath,topicCount:t.topics.length}}}function mt(e,t){if(!t||t===`index`){let t=e.loadStartupMemory();return{message:t.content||`(empty memory index)`,success:!0,data:{path:t.path,lineCount:t.lineCount,truncated:t.truncated}}}return{message:e.readTopic(t)||`(empty memory topic: ${t})`,success:!0,data:{topic:t}}}function ht(t){let n=t[1],r=t[2],i=t.slice(3).join(` `).trim();if(!(!n||!(0,e.isCommandMemoryType)(n)||!r||i.length===0))return{type:n,topic:r,text:i}}function gt(e){let t=e.list(`pending`);return{message:[`Pending memory candidates:`,...t.length>0?t.map(e=>`- ${e.id} ${e.type}/${e.topic} confidence=${e.confidence}: ${e.text}`):[`(no pending memory candidates)`]].join(`
19
- `),success:!0,data:{count:t.length}}}function E(t,n){(0,e.recordCommandMemoryEvent)(t,n)}function _t(e,t,n,r){if(!r)return T();try{let i=t.mark(r,`approved`,`approved-by-user`),a=n.append(i),o=t.mark(r,`saved`,`approved-and-saved`);return E(e,{type:`memory_candidate_approved`,candidateId:o.id,topic:o.topic,reason:`approved-by-user`}),E(e,{type:`memory_candidate_saved`,candidateId:o.id,topic:o.topic,reason:a.deduplicated?`deduplicated`:`approved-and-saved`}),{message:a.deduplicated?`Saved memory candidate ${r} was already present in ${a.topicPath}`:`Saved memory candidate ${r} to ${a.topicPath}`,success:!0,data:{id:r,status:o.status,topic:a.topic,topicPath:a.topicPath,deduplicated:a.deduplicated}}}catch(e){return ft(e instanceof Error?e:String(e))}}function vt(e,t,n){if(!n)return T();try{let r=t.mark(n,`rejected`,`rejected-by-user`);return E(e,{type:`memory_candidate_rejected`,candidateId:r.id,topic:r.topic,reason:`rejected-by-user`}),{message:`Rejected memory candidate ${n}`,success:!0,data:{id:n,status:r.status}}}catch(e){return ft(e instanceof Error?e:String(e))}}function yt(t){let n=(0,e.listCommandUsedMemoryReferences)(t);return{message:[`Used memory references:`,...n.length>0?n.map(e=>{let t=e.truncated?` truncated=true`:``;return`- ${e.topic} score=${e.score}${t}: ${e.path}`}):[`(no memory used in current turn)`]].join(`
20
- `),success:!0,data:{count:n.length,references:[...n]}}}function bt(t,n){let r=n.trim().split(/\s+/).filter(Boolean),i=r[0]??`list`,a=(0,e.createCommandMemoryStores)(t);if(i===`list`)return pt(a.project);if(i===`show`)return mt(a.project,r[1]);if(i===`pending`)return gt(a.pending);if(i===`approve`)return _t(t,a.pending,a.project,r[1]);if(i===`reject`)return vt(t,a.pending,r[1]);if(i===`used`)return yt(t);if(i===`add`){let t=ht(r);if(!t)return T();if((0,e.hasSensitiveCommandMemoryContent)(t.text))return{message:`Refusing to save sensitive memory content.`,success:!1};let n=a.project.append(t);return{message:n.deduplicated?`${t.type} memory already exists in ${n.topicPath}`:`Saved ${t.type} memory to ${n.topicPath}`,success:!0,data:{indexPath:n.indexPath,topicPath:n.topicPath,topic:n.topic,deduplicated:n.deduplicated}}}return T()}function D(){return{name:`memory`,displayName:`Memory`,description:e.MEMORY_COMMAND_DESCRIPTION,source:`memory`,argumentHint:e.MEMORY_COMMAND_ARGUMENT_HINT,modelInvocable:!0,safety:`write`,subcommands:(0,e.buildMemoryCommandSubcommands)()}}function xt(){let e=D();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!0,argumentHint:e.argumentHint,safety:e.safety,subcommands:e.subcommands,execute:bt}}var St=class{name=`memory`;getCommands(){return[D()]}};function Ct(){return{name:`agent-command-memory`,commandSources:[new St],systemCommands:[xt()]}}function wt(t,n){let r=(0,e.parsePermissionModeArgument)(n);if(r===void 0){let n=(0,e.readCommandPermissionMode)(t);return{message:`Current mode: ${n}`,success:!0,data:{mode:n}}}return(0,e.isPermissionMode)(r)?((0,e.writeCommandPermissionMode)(t,r),{message:`Permission mode set to: ${r}`,success:!0,data:{mode:r}}):{message:(0,e.formatInvalidPermissionModeMessage)(),success:!1}}function O(){return{name:`mode`,displayName:`Interaction Mode`,description:e.PERMISSION_MODE_COMMAND_DESCRIPTION,source:`mode`,argumentHint:e.PERMISSION_MODE_ARGUMENT_HINT,subcommands:(0,e.buildPermissionModeSubcommands)(`mode`),modelInvocable:!1}}function Tt(){let e=O();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,argumentHint:e.argumentHint,subcommands:e.subcommands,lifecycle:`inline`,execute:wt}}var Et=class{name=`mode`;getCommands(){return[O()]}};const Dt={mode:{type:`pick`,getItems:()=>(0,e.buildPermissionModeSubcommands)().map(e=>({label:e.name,value:e.name,description:e.description}))}};function Ot(){return{name:`agent-command-mode`,commandSources:[new Et],systemCommands:[Tt()],interactionHints:Dt}}function kt(t,n){let r=(0,e.parsePermissionModeArgument)(n);if(r!==void 0){if(!(0,e.isPermissionMode)(r))return{message:(0,e.formatInvalidPermissionModeMessage)(),success:!1};(0,e.writeCommandPermissionMode)(t,r);let n=(0,e.readCommandPermissionsState)(t);return{message:`Permission mode set to: ${r}\n${(0,e.formatCommandPermissionsMessage)(n)}`,success:!0,data:{mode:n.mode,sessionAllowed:n.sessionAllowed}}}let i=(0,e.readCommandPermissionsState)(t);return{message:(0,e.formatCommandPermissionsMessage)(i),success:!0,data:{mode:i.mode,sessionAllowed:i.sessionAllowed}}}function k(){return{name:`permissions`,displayName:`Permissions`,description:e.PERMISSIONS_COMMAND_DESCRIPTION,source:`permissions`,argumentHint:e.PERMISSION_MODE_ARGUMENT_HINT,subcommands:(0,e.buildPermissionModeSubcommands)(`permissions`),modelInvocable:!1}}function At(){let e=k();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!0,userInvocable:!0,modelInvocable:!1,argumentHint:e.argumentHint,subcommands:e.subcommands,lifecycle:`inline`,execute:kt}}var jt=class{name=`permissions`;getCommands(){return[k()]}};function Mt(){return{name:`agent-command-permissions`,commandSources:[new jt],systemCommands:[At()]}}function Nt(e){let t=e.trim().split(/\s+/).filter(e=>e.length>0);return{subcommand:t[0]??``,subArgs:t.slice(1).join(` `).trim()}}function A(e){return{success:!1,message:e}}function Pt(t){return(0,e.resolvePluginCommandAdapter)(t)}async function j(e,t){let n=Pt(e);if(n===void 0)return{success:!1,message:`Plugin management is not available.`};try{return{success:!0,message:await t(n)}}catch(e){return{success:!1,message:`Plugin error: ${e instanceof Error?e.message:String(e)}`}}}async function Ft(e,t){let{subcommand:n,subArgs:r}=Nt(t);return n===`add`&&r.length>0?j(e,async e=>{let t=await e.marketplaceAdd(r);return`Added marketplace: "${t}" (from ${r})\nInstall plugins with: /plugin install <name>@${t}`}):n===`remove`&&r.length>0?j(e,async e=>(await e.marketplaceRemove(r),`Removed marketplace "${r}" and uninstalled its plugins.`)):n===`update`&&r.length>0?j(e,async e=>(await e.marketplaceUpdate(r),`Updated marketplace "${r}".`)):n===`list`?j(e,async e=>{let t=await e.marketplaceList();return t.length===0?`No marketplace sources configured.`:`Marketplace sources:\n${t.map(e=>` ${e.name} (${e.type})`).join(`
21
- `)}`}):A(`Usage: /plugin marketplace add <source> | remove <name> | update <name> | list`)}function M(e,t,n,r){return t.length===0?Promise.resolve(A(n)):j(e,e=>Promise.resolve(r(e,t)))}function It(){return{success:!0,message:`Opening plugin manager...`,effects:[(0,e.createPluginTuiRequestedEffect)()]}}function Lt(e,t){return M(e,t,`Usage: /plugin install <name>@<marketplace>`,async(e,t)=>(await e.install(t),`Installed plugin: ${t}`))}function Rt(e,t){return M(e,t,`Usage: /plugin uninstall <name>@<marketplace>`,async(e,t)=>(await e.uninstall(t),`Uninstalled plugin: ${t}`))}function zt(e,t){return M(e,t,`Usage: /plugin enable <name>@<marketplace>`,async(e,t)=>(await e.enable(t),`Enabled plugin: ${t}`))}function Bt(e,t){return M(e,t,`Usage: /plugin disable <name>@<marketplace>`,async(e,t)=>(await e.disable(t),`Disabled plugin: ${t}`))}async function Vt(e,t){let{subcommand:n,subArgs:r}=Nt(t);switch(n){case``:case`manage`:return It();case`install`:return Lt(e,r);case`uninstall`:return Rt(e,r);case`enable`:return zt(e,r);case`disable`:return Bt(e,r);case`marketplace`:return Ft(e,r);default:return A(`Unknown plugin subcommand: ${n}`)}}async function Ht(t,n){return j(t,async e=>{let t=await e.reloadPlugins();return`Reloaded ${t.loadedPluginCount===1?`1 plugin resource`:`${t.loadedPluginCount} plugin resources`}.`}).then(t=>t.success?{...t,effects:[(0,e.createPluginRegistryReloadRequestedEffect)()]}:t)}function N(){return{name:`plugin`,displayName:`Plugins`,description:e.PLUGIN_COMMAND_DESCRIPTION,source:`plugin-manager`,modelInvocable:!1,argumentHint:e.PLUGIN_COMMAND_ARGUMENT_HINT,subcommands:(0,e.buildPluginCommandSubcommands)()}}function P(){return{name:`reload-plugins`,displayName:`Reload Plugins`,description:e.RELOAD_PLUGINS_COMMAND_DESCRIPTION,source:`plugin-manager`,modelInvocable:!1}}function Ut(){let e=N();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,argumentHint:e.argumentHint,lifecycle:`inline`,subcommands:e.subcommands,execute:Vt}}function Wt(){let e=P();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,lifecycle:`inline`,execute:Ht}}var Gt=class{name=`plugin-manager`;getCommands(){return[N(),P()]}};function Kt(){return{name:`agent-command-plugin`,commandSources:[new Gt],systemCommands:[Ut(),Wt()]}}function qt(e){return e.getSession().getActivePresetId?.()??`default`}function Jt(e){return[`Available presets:`,...(0,t.listPresets)().map(t=>`${t.id===e?`* `:` `}${t.id} — ${t.title}: ${t.description}`)].join(`
22
- `)}function Yt(e){return`Unknown preset: ${e}. Available: ${(0,t.listPresets)().map(e=>e.id).join(`, `)}`}function Xt(n,r){let i=r.trim().split(/\s+/)[0];if(i===void 0||i.length===0||i===`list`){let e=qt(n);return{message:Jt(e),success:!0,data:{presets:(0,t.listPresets)(),active:e}}}return(0,t.getPreset)(i)===void 0?{message:Yt(i),success:!1}:((0,e.applyPresetToSession)(n,i,(0,t.resolvePreset)(i)),{message:`Switched to preset: ${i}`,success:!0,data:{preset:i}})}function Zt(e=`preset`){return(0,t.listPresets)().map(t=>({name:t.id,description:t.description,source:e}))}function F(){return{name:`preset`,displayName:`Agent Preset`,description:`List presets or switch the active preset`,source:`preset`,argumentHint:`list | <preset-id>`,subcommands:Zt(`preset`),modelInvocable:!1}}function Qt(){let e=F();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,argumentHint:e.argumentHint,subcommands:e.subcommands,lifecycle:`inline`,execute:Xt}}var $t=class{name=`preset`;getCommands(){return[F()]}};const en={preset:{type:`pick`,getItems:()=>Zt().map(e=>({label:e.name,value:e.name,description:e.description}))}};function tn(){return{name:`agent-command-preset`,commandSources:[new $t],systemCommands:[Qt()],interactionHints:en}}function I(e,t,n={}){let r=ln(e,t);return{type:e,steps:fn(un(r),n.initialValues),setupHelpLinks:r.setupHelpLinks??[],stepIndex:0,values:{},existingProfileNames:n.existingProfileNames??[],...n.profileName===void 0?{}:{profileName:n.profileName},...n.setCurrent===void 0?{}:{setCurrent:n.setCurrent}}}function nn(e){return e.length===0?` No providers are available.`:[` Select provider:`,...e.map((e,t)=>` ${t+1}. ${z(e)}`),` Provider [1-${e.length}] (default: 1): `].join(`
23
- `)}function rn(e,t){let r=e.trim(),i=r.length>0?r:`1`,a=cn(i);if(a!==void 0){let e=t[a];if(e!==void 0)return e.type;throw Error(`Provider selection ${i} is out of range. Currently supported: ${(0,n.formatSupportedProviderTypes)(t)}`)}let o=(0,n.findProviderDefinition)(t,i);if(o===void 0)throw Error(`Unknown provider: ${i}. Currently supported: ${(0,n.formatSupportedProviderTypes)(t)}`);return o.type}function L(e){let t=e.steps[e.stepIndex];if(t===void 0)throw Error(`Provider setup step ${e.stepIndex} is out of range`);return t}function R(e,t){let n=L(e),r=t.trim()||n.defaultValue||``,i=V(n,r);if(i!==void 0)return{status:`error`,state:e,message:i};let a={...e,stepIndex:e.stepIndex+1,values:{...e.values,[n.key]:r}};return a.stepIndex<e.steps.length?{status:`next`,state:a}:{status:`complete`,input:pn(a)}}async function an(e,t,n,r={}){let i=I(e,n,r),a=i.steps.length;for(;i.stepIndex<a;){let e=L(i),n=await t(on(e,i.setupHelpLinks),e.masked===!0),r=R(i,n);if(r.status===`complete`)return r.input;if(r.status===`error`)throw Error(r.message);i=r.state}throw Error(`Provider setup flow ended without completion`)}function on(e,t=[]){let n=e.defaultValue===void 0?``:` (default: ${e.defaultValue})`,r=B(t);return`${r.length>0?`${r}\n`:``} ${e.title}${n}: `}const sn={"cloud-paid":`[Cloud/Paid]`,"cloud-free":`[Cloud/Free]`,"local-free":`[Local/Free]`};function z(e){let t=`${e.category===void 0?``:`${sn[e.category]??``} `}${e.displayName===void 0?e.type:`${e.displayName} (${e.type})`}`;return e.description===void 0?t:`${t} — ${e.description}`}function B(e=[]){return e.length===0?``:e.map(e=>` Setup help: ${dn(e.kind)}: ${e.label} - ${e.url}`).join(`
24
- `)}function cn(e){if(/^\d+$/.test(e))return Number(e)-1}function V(e,t){if(e.required===!0&&t.length===0)return`Required`}function ln(e,t){let r=(0,n.findProviderDefinition)(t,e);if(r===void 0)throw Error(`Unknown provider: ${e}. Currently supported: ${(0,n.formatSupportedProviderTypes)(t)}`);return r}function un(e){if(e.setupSteps!==void 0)return[...e.setupSteps];let t=[{key:`model`,title:`${e.type} model`,defaultValue:e.defaults?.model,required:e.defaults?.model===void 0}];return e.defaults?.baseURL!==void 0&&t.unshift({key:`baseURL`,title:`${e.type} base URL`,defaultValue:e.defaults.baseURL}),e.requiresApiKey===!0&&t.push({key:`apiKey`,title:`${e.type} API key`,defaultValue:e.defaults?.apiKey,required:e.defaults?.apiKey===void 0,masked:!0}),t}function dn(e){return e===`api-key`?`API key`:e===`console`?`Console`:`Official`}function fn(e,t){return t===void 0?[...e]:e.map(e=>{let n=t[e.key];return n===void 0?e:{...e,defaultValue:n,required:!1}})}function pn(t){let n=t.profileName??(0,e.suggestProviderProfileName)({type:t.type},{existingProfileNames:t.existingProfileNames}),r=t.values.apiKey;return{profile:n,type:t.type,model:t.values.model,...r!==void 0&&r.length>0&&{apiKey:r},...t.values.baseURL!==void 0&&{baseURL:t.values.baseURL},setCurrent:t.setCurrent??!0}}const mn={type:`session-restart-requested`,reason:`other`};function hn(e,t){return I(e,t.providerDefinitions,{existingProfileNames:Object.keys(t.settings.readMergedSettings().providers??{})})}function H(e,t){return{prompt:gn(e),submit:n=>vn(e,n,t),cancel:()=>({message:`Provider setup cancelled.`,success:!0})}}function gn(e){let t=L(e),n=t.masked===!0&&t.defaultValue!==void 0?`(unchanged)`:t.defaultValue;return{kind:`text`,title:t.title,..._n(e),...n===void 0?{}:{placeholder:n},...t.defaultValue===void 0?{}:{allowEmpty:!0},...t.masked===void 0?{}:{masked:t.masked},validate:e=>V(t,e)}}function _n(e){let t=B(e.setupHelpLinks);return t.length>0?{description:t}:{}}function vn(e,t,n){let r=R(e,t);return r.status===`error`?{message:r.message,success:!1,interaction:H(e,n)}:r.status===`complete`?yn(r.input,n):{message:``,success:!0,interaction:H(r.state,n)}}function yn(t,n){let r=n.settings.readTargetSettings(),i=(0,e.buildProviderSetupPatch)(t,{providerDefinitions:n.providerDefinitions});return n.settings.writeTargetSettings((0,e.mergeProviderPatch)(r,i)),{message:`Provider ${t.profile} configured. Restarting...`,success:!0,effects:[{...mn,message:`Provider setup restart`}]}}function bn(e,t,n){return`${e===n?`* `:``}${e}: ${t.type??`unknown`} ${t.model??`(no model)`}`}function xn(t,n,r){if(!n)return{message:`Usage: /provider switch <profile>`,success:!1};if(!t?.[n])return{message:`Provider profile "${n}" was not found.`,success:!1};let{orgPolicy:i}=r;if(i?.allowedProviders&&!i.allowedProviders.includes(n))return{message:(0,e.formatOrgPolicyViolationMessage)(`Provider "${n}" is not allowed by your organization policy. Allowed: ${i.allowedProviders.join(`, `)}.`,i.adminContact),success:!1};if(r.settings.readMergedSettings().currentProvider===n)return{message:`Already using provider "${n}".`,success:!0};let a=t[n],o=r.settings.readTargetSettings(),s=r.settings.readMergedSettings(),c=o.providers?.[n]!==void 0||s.providers?.[n]!==void 0?{...o,currentProvider:n}:(0,e.setCurrentProvider)(o,n);return r.settings.writeTargetSettings(c),{message:`Switched to ${n} (${a.model??`unknown model`}). History preserved.`,success:!0,effects:[{type:`provider-hot-swap-requested`,profileName:n}]}}function Sn(e,t){let n=t.settings.readMergedSettings().providers?.[e];if(!n)return{message:`Provider profile "${e}" was not found.`,success:!1};if(!n.type)return{message:`Provider profile "${e}" is missing type.`,success:!1};try{let r=I(n.type,t.providerDefinitions,{profileName:e,setCurrent:!1,initialValues:Cn(n)});return{message:`Provider edit requested: ${e}`,success:!0,interaction:U(r,e,t)}}catch(e){return{message:e instanceof Error?e.message:String(e),success:!1}}}function Cn(e){return{...typeof e.model==`string`?{model:e.model}:{},...typeof e.apiKey==`string`?{apiKey:e.apiKey}:{},...typeof e.baseURL==`string`?{baseURL:e.baseURL}:{}}}function U(e,t,n){return{prompt:gn(e),submit:r=>wn(e,t,r,n),cancel:()=>({message:`Provider edit cancelled.`,success:!0})}}function wn(e,t,n,r){let i=R(e,n);return i.status===`error`?{message:i.message,success:!1,interaction:U(e,t,r)}:i.status===`complete`?Tn(i.input,t,r):{message:``,success:!0,interaction:U(i.state,t,r)}}function Tn(t,n,r){let i=r.settings.readMergedSettings(),a=i.providers?.[n];if(!a)return{message:`Provider profile "${n}" was not found.`,success:!1};let{orgPolicy:o}=r;if(o?.requireApiKeyFromEnv&&(0,e.isApiKeyPlaintext)(t.apiKey))return{message:(0,e.formatOrgPolicyViolationMessage)(`Your organization policy requires API keys to be stored as environment variable references ($ENV:VAR_NAME), not as plaintext.`,o.adminContact),success:!1};let s=r.settings.readTargetSettings(),c=(0,e.buildProviderSetupPatch)(t,{providerDefinitions:r.providerDefinitions}).providers[n];if(!c)return{message:`Provider profile "${n}" was not updated.`,success:!1};r.settings.writeTargetSettings((0,e.upsertProviderProfile)(s,n,{...a,...c}));let l=i.currentProvider===n;return{message:l?`Provider ${n} updated. Switching...`:`Provider ${n} updated.`,success:!0,...l?{effects:[{type:`provider-hot-swap-requested`,profileName:n}]}:{}}}const En={type:`session-restart-requested`,reason:`other`};function Dn(e,t){let n=t.settings.readMergedSettings();if(!n.providers?.[e])return{message:`Provider profile "${e}" was not found.`,success:!1};let r=Fn(e,Object.keys(n.providers));return{message:`Provider duplicate requested: ${e}`,success:!0,interaction:On(e,r,t)}}function On(e,t,n){return{prompt:{kind:`text`,title:`Duplicate ${e} as`,placeholder:t,allowEmpty:!0,validate:e=>kn(e,t,n)},submit:r=>An(e,r,t,n),cancel:()=>({message:`Provider duplicate cancelled.`,success:!0})}}function kn(e,t,n){let r=In(e,t);if(r.length===0)return`Required`;if(n.settings.readMergedSettings().providers?.[r]!==void 0)return`Provider profile "${r}" already exists`}function An(t,n,r,i){let a=i.settings.readMergedSettings().providers?.[t];if(!a)return{message:`Provider profile "${t}" was not found.`,success:!1};let o=In(n,r),s=kn(o,r,i);return s===void 0?(i.settings.writeTargetSettings((0,e.upsertProviderProfile)(i.settings.readTargetSettings(),o,{...a})),{message:`Provider profile duplicated: ${t} -> ${o}.`,success:!0}):{message:s,success:!1}}function jn(e,t){let n=t.settings.readMergedSettings().providers??{};return n[e]?Object.keys(n).length<=1?{message:`Cannot delete the only provider profile.`,success:!1}:t.settings.readTargetSettings().providers?.[e]===void 0?{message:`Provider profile "${e}" is not stored in the active write target; edit its source settings file or override it before deleting.`,success:!1}:{message:`Provider delete requested: ${e}`,success:!0,interaction:Mn(e,t)}:{message:`Provider profile "${e}" was not found.`,success:!1}}function Mn(e,t){return{prompt:{kind:`choice`,title:`Delete provider profile ${e}?`,options:[{value:`yes`,label:`Yes`},{value:`no`,label:`No`}]},submit:n=>n===`yes`?Nn(e,t):{message:`Provider delete cancelled.`,success:!0},cancel:()=>({message:`Provider delete cancelled.`,success:!0})}}function Nn(t,n){let r=n.settings.readMergedSettings();if(r.currentProvider!==t)return n.settings.writeTargetSettings((0,e.deleteProviderProfile)(n.settings.readTargetSettings(),t)),{message:`Provider profile deleted: ${t}.`,success:!0};let i=Object.entries(r.providers??{}).filter(([e])=>e!==t).map(([e,t])=>({value:e,label:bn(e,t,r.currentProvider)}));return{message:`Select a replacement provider before deleting ${t}.`,success:!0,interaction:{prompt:{kind:`choice`,title:`Replacement provider for ${t}`,options:i,maxVisible:8},submit:e=>Pn(t,e,n),cancel:()=>({message:`Provider delete cancelled.`,success:!0})}}}function Pn(t,n,r){if(r.settings.readMergedSettings().providers?.[n]===void 0||n===t)return{message:`Provider profile "${n}" was not found.`,success:!1};let i=(0,e.deleteProviderProfile)(r.settings.readTargetSettings(),t);return r.settings.writeTargetSettings({...i,currentProvider:n}),{message:`Provider profile deleted: ${t}. Restarting with ${n}...`,success:!0,effects:[{...En,message:`Provider delete restart`}]}}function Fn(t,n){let r=(0,e.sanitizeProviderProfileName)(`${t}-copy`)??`provider-copy`;if(!n.includes(r))return r;for(let e=2;e<1e3;e+=1){let t=`${r}-${e}`;if(!n.includes(t))return t}return`${r}-${Date.now()}`}function In(t,n){return(0,e.sanitizeProviderProfileName)(t.trim()||n)??``}const Ln=`switch`,Rn=`edit`,zn=`test`,Bn=`duplicate`,Vn=`delete`,Hn=`cancel`;function Un(e,t,n){return{prompt:{kind:`choice`,title:`Select provider profile`,options:Object.entries(t??{}).map(([t,n])=>({value:t,label:bn(t,n,e)})),maxVisible:8},submit:e=>Wn(e,n),cancel:()=>({message:`Provider profile selection cancelled.`,success:!0})}}function Wn(e,t){return t.settings.readMergedSettings().providers?.[e]?{message:`Provider profile selected: ${e}`,success:!0,interaction:Gn(e,t)}:{message:`Provider profile "${e}" was not found.`,success:!1}}function Gn(e,t){return{prompt:{kind:`choice`,title:`Provider profile: ${e}`,options:[{value:Ln,label:`Switch`},{value:Rn,label:`Edit`},{value:zn,label:`Test`},{value:Bn,label:`Duplicate`},{value:Vn,label:`Delete`},{value:Hn,label:`Cancel`}]},submit:n=>Kn(e,n,t),cancel:()=>({message:`Provider profile action cancelled.`,success:!0})}}async function Kn(t,n,r){let i=r.settings.readMergedSettings();switch(n){case Ln:return xn(i.providers,t,r);case Rn:return Sn(t,r);case zn:return await(0,e.testProviderProfileCommand)(i.currentProvider,i.providers,t,r);case Bn:return Dn(t,r);case Vn:return jn(t,r);case Hn:return{message:`Provider profile action cancelled.`,success:!0};default:return{message:`Unknown provider profile action "${n}".`,success:!1}}}async function qn(t,n){let r=n.settings.readMergedSettings(),i=t.trim();if(i.length===0)return Jn(r.currentProvider,r.providers,n);let[a=`current`,o]=i.split(/\s+/);return a===`list`?Jn(r.currentProvider,r.providers,n):a===`current`||a===``?{message:Xn(r.currentProvider,r.providers),success:!0}:a===`switch`?xn(r.providers,o,n):a===`test`?await(0,e.testProviderProfileCommand)(r.currentProvider,r.providers,o,n):a===`add`?Zn(o,n):{message:`Usage: provider [current|list|switch <profile>|add <type>|test [profile]]`,success:!1}}function Jn(e,t,n){let r=Yn(e,t);return Object.keys(t??{}).length===0?{message:r,success:!0}:{message:r,success:!0,interaction:Un(e,t,n)}}function Yn(e,t){let n=Object.entries(t??{});return n.length===0?`No provider profiles configured.`:n.map(([t,n])=>`${t===e?`*`:`-`} ${t}: ${n.type??`unknown`} ${n.model??`(no model)`}`).join(`
25
- `)}function Xn(e,t){if(!e)return`No current provider configured.`;let n=t?.[e];return n?[`Current provider: ${e}`,`Type: ${n.type??`unknown`}`,`Model: ${n.model??`(no model)`}`,...n.baseURL?[`Base URL: ${n.baseURL}`]:[]].join(`
26
- `):`Current provider "${e}" was not found in providers.`}function Zn(e,t){return e===void 0||e.length===0?{message:`Provider setup requested. Select a provider to continue.`,success:!0,interaction:Qn(t)}:(0,n.findProviderDefinition)(t.providerDefinitions,e)===void 0?{message:`Usage: provider add <type>. Supported: ${(0,n.formatSupportedProviderTypes)(t.providerDefinitions)}`,success:!1}:{message:`Provider setup requested: ${e}`,success:!0,interaction:H(hn(e,t),t)}}function Qn(e){return{prompt:{kind:`choice`,title:`Select provider`,options:e.providerDefinitions.map(e=>({value:e.type,label:z(e)})),maxVisible:6},submit:t=>{let n=hn(t,e);return{message:`Provider setup requested: ${t}`,success:!0,interaction:H(n,e)}},cancel:()=>({message:`Provider setup cancelled.`,success:!0})}}function $n(){return[{name:`current`,description:`Show current provider`,source:`provider`},{name:`list`,description:`List provider profiles`,source:`provider`},{name:`switch`,description:`Hot-swap to another provider profile`,source:`provider`},{name:`add`,description:`Configure a provider profile`,source:`provider`},{name:`test`,description:`Test provider profile`,source:`provider`}]}function W(){return{name:`provider`,displayName:`Provider Setup`,description:`Manage provider profiles`,source:`provider`,modelInvocable:!1,argumentHint:`current | list | switch <profile> | add [type] | test [profile]`,subcommands:$n(),example:`/provider switch production`}}var er=class{name=`provider`;getCommands(){return[W()]}};function tr(e){let t=W();return{name:t.name,displayName:t.displayName,description:t.description,example:t.example,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,argumentHint:t.argumentHint,subcommands:t.subcommands,execute:async(t,n)=>qn(n,e)}}const nr={provider:{type:`pick`,getItems:()=>$n().map(e=>({label:e.name,value:e.name,description:e.description}))}};function rr(e){return{name:`agent-command-provider`,commandSources:[new er],systemCommands:[tr(e)],interactionHints:nr}}async function ir(e,t){let n=(await e(`
22
+ `),success:!0,data:{indexPath:t.indexPath,topicsPath:t.topicsPath,topicCount:t.topics.length}}}function Ct(e,t){if(!t||t===`index`){let t=e.loadStartupMemory();return{message:t.content||`(empty memory index)`,success:!0,data:{path:t.path,lineCount:t.lineCount,truncated:t.truncated}}}return{message:e.readTopic(t)||`(empty memory topic: ${t})`,success:!0,data:{topic:t}}}function wt(t){let n=t[1],r=t[2],i=t.slice(3).join(` `).trim();if(!(!n||!(0,e.isCommandMemoryType)(n)||!r||i.length===0))return{type:n,topic:r,text:i}}function Tt(e){let t=e.list(`pending`);return{message:[`Pending memory candidates:`,...t.length>0?t.map(e=>`- ${e.id} ${e.type}/${e.topic} confidence=${e.confidence}: ${e.text}`):[`(no pending memory candidates)`]].join(`
23
+ `),success:!0,data:{count:t.length}}}function j(t,n){(0,e.recordCommandMemoryEvent)(t,n)}function Et(e,t,n,r){if(!r)return A();try{let i=t.mark(r,`approved`,`approved-by-user`),a=n.append(i),o=t.mark(r,`saved`,`approved-and-saved`);return j(e,{type:`memory_candidate_approved`,candidateId:o.id,topic:o.topic,reason:`approved-by-user`}),j(e,{type:`memory_candidate_saved`,candidateId:o.id,topic:o.topic,reason:a.deduplicated?`deduplicated`:`approved-and-saved`}),{message:a.deduplicated?`Saved memory candidate ${r} was already present in ${a.topicPath}`:`Saved memory candidate ${r} to ${a.topicPath}`,success:!0,data:{id:r,status:o.status,topic:a.topic,topicPath:a.topicPath,deduplicated:a.deduplicated}}}catch(e){return xt(e instanceof Error?e:String(e))}}function Dt(e,t,n){if(!n)return A();try{let r=t.mark(n,`rejected`,`rejected-by-user`);return j(e,{type:`memory_candidate_rejected`,candidateId:r.id,topic:r.topic,reason:`rejected-by-user`}),{message:`Rejected memory candidate ${n}`,success:!0,data:{id:n,status:r.status}}}catch(e){return xt(e instanceof Error?e:String(e))}}function Ot(t){let n=(0,e.listCommandUsedMemoryReferences)(t);return{message:[`Used memory references:`,...n.length>0?n.map(e=>{let t=e.truncated?` truncated=true`:``;return`- ${e.topic} score=${e.score}${t}: ${e.path}`}):[`(no memory used in current turn)`]].join(`
24
+ `),success:!0,data:{count:n.length,references:[...n]}}}function kt(t,n){let r=n.trim().split(/\s+/).filter(Boolean),i=r[0]??`list`,a=(0,e.createCommandMemoryStores)(t);if(i===`list`)return St(a.project);if(i===`show`)return Ct(a.project,r[1]);if(i===`pending`)return Tt(a.pending);if(i===`approve`)return Et(t,a.pending,a.project,r[1]);if(i===`reject`)return Dt(t,a.pending,r[1]);if(i===`used`)return Ot(t);if(i===`add`){let t=wt(r);if(!t)return A();if((0,e.hasSensitiveCommandMemoryContent)(t.text))return{message:`Refusing to save sensitive memory content.`,success:!1};let n=a.project.append(t);return{message:n.deduplicated?`${t.type} memory already exists in ${n.topicPath}`:`Saved ${t.type} memory to ${n.topicPath}`,success:!0,data:{indexPath:n.indexPath,topicPath:n.topicPath,topic:n.topic,deduplicated:n.deduplicated}}}return A()}function M(){return{name:`memory`,displayName:`Memory`,description:e.MEMORY_COMMAND_DESCRIPTION,source:`memory`,argumentHint:e.MEMORY_COMMAND_ARGUMENT_HINT,modelInvocable:!0,safety:`write`,subcommands:(0,e.buildMemoryCommandSubcommands)()}}function At(){let e=M();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!0,argumentHint:e.argumentHint,safety:e.safety,subcommands:e.subcommands,execute:kt}}var jt=class{name=`memory`;getCommands(){return[M()]}};function Mt(){return{name:`agent-command-memory`,commandSources:[new jt],systemCommands:[At()]}}async function Nt(n){let r=n.getUserInteraction?.();if(!r)return;let i=(0,e.buildPermissionModeSubcommands)().map(e=>({value:e.name,label:e.name,description:e.description})),a=await r.ask((0,t.selectAction)(`mode`,`Select interaction mode`,i));return a.type===`answer`?a.values[0]:void 0}async function Pt(t,n){let r=(0,e.parsePermissionModeArgument)(n);if(r===void 0&&(r=await Nt(t),r===void 0)){let n=(0,e.readCommandPermissionMode)(t);return{message:`Current mode: ${n}`,success:!0,data:{mode:n}}}return(0,e.isPermissionMode)(r)?((0,e.writeCommandPermissionMode)(t,r),{message:`Permission mode set to: ${r}`,success:!0,data:{mode:r}}):{message:(0,e.formatInvalidPermissionModeMessage)(),success:!1}}function N(){return{name:`mode`,displayName:`Interaction Mode`,description:e.PERMISSION_MODE_COMMAND_DESCRIPTION,source:`mode`,argumentHint:e.PERMISSION_MODE_ARGUMENT_HINT,subcommands:(0,e.buildPermissionModeSubcommands)(`mode`),modelInvocable:!1}}function Ft(){let e=N();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,argumentHint:e.argumentHint,subcommands:e.subcommands,lifecycle:`inline`,execute:Pt}}var It=class{name=`mode`;getCommands(){return[N()]}};function Lt(){return{name:`agent-command-mode`,commandSources:[new It],systemCommands:[Ft()]}}function Rt(t,n){let r=(0,e.parsePermissionModeArgument)(n);if(r!==void 0){if(!(0,e.isPermissionMode)(r))return{message:(0,e.formatInvalidPermissionModeMessage)(),success:!1};(0,e.writeCommandPermissionMode)(t,r);let n=(0,e.readCommandPermissionsState)(t);return{message:`Permission mode set to: ${r}\n${(0,e.formatCommandPermissionsMessage)(n)}`,success:!0,data:{mode:n.mode,sessionAllowed:n.sessionAllowed}}}let i=(0,e.readCommandPermissionsState)(t);return{message:(0,e.formatCommandPermissionsMessage)(i),success:!0,data:{mode:i.mode,sessionAllowed:i.sessionAllowed}}}function P(){return{name:`permissions`,displayName:`Permissions`,description:e.PERMISSIONS_COMMAND_DESCRIPTION,source:`permissions`,argumentHint:e.PERMISSION_MODE_ARGUMENT_HINT,subcommands:(0,e.buildPermissionModeSubcommands)(`permissions`),modelInvocable:!1}}function zt(){let e=P();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!0,userInvocable:!0,modelInvocable:!1,argumentHint:e.argumentHint,subcommands:e.subcommands,lifecycle:`inline`,execute:Rt}}var Bt=class{name=`permissions`;getCommands(){return[P()]}};function Vt(){return{name:`agent-command-permissions`,commandSources:[new Bt],systemCommands:[zt()]}}function Ht(e){let t=e.trim().split(/\s+/).filter(e=>e.length>0);return{subcommand:t[0]??``,subArgs:t.slice(1).join(` `).trim()}}function F(e){return{success:!1,message:e}}function Ut(t){return(0,e.resolvePluginCommandAdapter)(t)}async function I(e,t){let n=Ut(e);if(n===void 0)return{success:!1,message:`Plugin management is not available.`};try{return{success:!0,message:await t(n)}}catch(e){return{success:!1,message:`Plugin error: ${e instanceof Error?e.message:String(e)}`}}}async function Wt(e,t){let{subcommand:n,subArgs:r}=Ht(t);return n===`add`&&r.length>0?I(e,async e=>{let t=await e.marketplaceAdd(r);return`Added marketplace: "${t}" (from ${r})\nInstall plugins with: /plugin install <name>@${t}`}):n===`remove`&&r.length>0?I(e,async e=>(await e.marketplaceRemove(r),`Removed marketplace "${r}" and uninstalled its plugins.`)):n===`update`&&r.length>0?I(e,async e=>(await e.marketplaceUpdate(r),`Updated marketplace "${r}".`)):n===`list`?I(e,async e=>{let t=await e.marketplaceList();return t.length===0?`No marketplace sources configured.`:`Marketplace sources:\n${t.map(e=>` ${e.name} (${e.type})`).join(`
25
+ `)}`}):F(`Usage: /plugin marketplace add <source> | remove <name> | update <name> | list`)}function L(e,t,n,r){return t.length===0?Promise.resolve(F(n)):I(e,e=>Promise.resolve(r(e,t)))}function Gt(){return{success:!0,message:`Opening plugin manager...`,effects:[(0,e.createPluginTuiRequestedEffect)()]}}function Kt(e,t){return L(e,t,`Usage: /plugin install <name>@<marketplace>`,async(e,t)=>(await e.install(t),`Installed plugin: ${t}`))}function qt(e,t){return L(e,t,`Usage: /plugin uninstall <name>@<marketplace>`,async(e,t)=>(await e.uninstall(t),`Uninstalled plugin: ${t}`))}function Jt(e,t){return L(e,t,`Usage: /plugin enable <name>@<marketplace>`,async(e,t)=>(await e.enable(t),`Enabled plugin: ${t}`))}function Yt(e,t){return L(e,t,`Usage: /plugin disable <name>@<marketplace>`,async(e,t)=>(await e.disable(t),`Disabled plugin: ${t}`))}async function Xt(e,t){let{subcommand:n,subArgs:r}=Ht(t);switch(n){case``:case`manage`:return Gt();case`install`:return Kt(e,r);case`uninstall`:return qt(e,r);case`enable`:return Jt(e,r);case`disable`:return Yt(e,r);case`marketplace`:return Wt(e,r);default:return F(`Unknown plugin subcommand: ${n}`)}}async function Zt(t,n){return I(t,async e=>{let t=await e.reloadPlugins();return`Reloaded ${t.loadedPluginCount===1?`1 plugin resource`:`${t.loadedPluginCount} plugin resources`}.`}).then(t=>t.success?{...t,effects:[(0,e.createPluginRegistryReloadRequestedEffect)()]}:t)}function R(){return{name:`plugin`,displayName:`Plugins`,description:e.PLUGIN_COMMAND_DESCRIPTION,source:`plugin-manager`,modelInvocable:!1,argumentHint:e.PLUGIN_COMMAND_ARGUMENT_HINT,subcommands:(0,e.buildPluginCommandSubcommands)()}}function z(){return{name:`reload-plugins`,displayName:`Reload Plugins`,description:e.RELOAD_PLUGINS_COMMAND_DESCRIPTION,source:`plugin-manager`,modelInvocable:!1}}function Qt(){let e=R();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,argumentHint:e.argumentHint,lifecycle:`inline`,subcommands:e.subcommands,execute:Xt}}function $t(){let e=z();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,lifecycle:`inline`,execute:Zt}}var en=class{name=`plugin-manager`;getCommands(){return[R(),z()]}};function tn(){return{name:`agent-command-plugin`,commandSources:[new en],systemCommands:[Qt(),$t()]}}function nn(e){return e.getSession().getActivePresetId?.()??`default`}function rn(e){return[`Available presets:`,...(0,o.listPresets)().map(t=>`${t.id===e?`* `:` `}${t.id} — ${t.title}: ${t.description}`)].join(`
26
+ `)}function an(e){return`Unknown preset: ${e}. Available: ${(0,o.listPresets)().map(e=>e.id).join(`, `)}`}function on(e){let t=nn(e);return{message:rn(t),success:!0,data:{presets:(0,o.listPresets)(),active:t}}}async function sn(e){let n=e.getUserInteraction?.();if(!n)return;let r=(0,o.listPresets)().map(e=>({value:e.id,label:e.id,description:e.description})),i=await n.ask((0,t.selectAction)(`preset`,`Select a preset`,r));return i.type===`answer`?i.values[0]:void 0}async function cn(t,n){let r=n.trim().split(/\s+/)[0];if(r===`list`||(r===void 0||r.length===0)&&(r=await sn(t),r===void 0))return on(t);if((0,o.getPreset)(r)===void 0)return{message:an(r),success:!1};let i=(0,o.resolvePreset)(r);return await(0,e.applyPresetToSession)(t,r,i),{message:`Switched to preset: ${r}`,success:!0,data:{preset:r}}}function ln(e=`preset`){return(0,o.listPresets)().map(t=>({name:t.id,description:t.description,source:e}))}function B(){return{name:`preset`,displayName:`Agent Preset`,description:`List presets or switch the active preset`,source:`preset`,argumentHint:`list | <preset-id>`,subcommands:ln(`preset`),modelInvocable:!1}}function un(){let e=B();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,argumentHint:e.argumentHint,subcommands:e.subcommands,lifecycle:`inline`,execute:cn}}var dn=class{name=`preset`;getCommands(){return[B()]}};function fn(){return{name:`agent-command-preset`,commandSources:[new dn],systemCommands:[un()]}}function V(e,t,n={}){let r=bn(e,t);return{type:e,steps:Cn(xn(r),n.initialValues),setupHelpLinks:r.setupHelpLinks??[],stepIndex:0,values:{},existingProfileNames:n.existingProfileNames??[],...n.profileName===void 0?{}:{profileName:n.profileName},...n.setCurrent===void 0?{}:{setCurrent:n.setCurrent}}}function pn(e){return e.length===0?` No providers are available.`:[` Select provider:`,...e.map((e,t)=>` ${t+1}. ${W(e)}`),` Provider [1-${e.length}] (default: 1): `].join(`
27
+ `)}function mn(e,n){let r=e.trim(),i=r.length>0?r:`1`,a=vn(i);if(a!==void 0){let e=n[a];if(e!==void 0)return e.type;throw Error(`Provider selection ${i} is out of range. Currently supported: ${(0,t.formatSupportedProviderTypes)(n)}`)}let o=(0,t.findProviderDefinition)(n,i);if(o===void 0)throw Error(`Unknown provider: ${i}. Currently supported: ${(0,t.formatSupportedProviderTypes)(n)}`);return o.type}function H(e){let t=e.steps[e.stepIndex];if(t===void 0)throw Error(`Provider setup step ${e.stepIndex} is out of range`);return t}function U(e,t){let n=H(e),r=t.trim()||n.defaultValue||``,i=yn(n,r);if(i!==void 0)return{status:`error`,state:e,message:i};let a={...e,stepIndex:e.stepIndex+1,values:{...e.values,[n.key]:r}};return a.stepIndex<e.steps.length?{status:`next`,state:a}:{status:`complete`,input:wn(a)}}async function hn(e,t,n,r={}){let i=V(e,n,r),a=i.steps.length;for(;i.stepIndex<a;){let e=H(i),n=await t(gn(e,i.setupHelpLinks),e.masked===!0),r=U(i,n);if(r.status===`complete`)return r.input;if(r.status===`error`)throw Error(r.message);i=r.state}throw Error(`Provider setup flow ended without completion`)}function gn(e,t=[]){let n=e.defaultValue===void 0?``:` (default: ${e.defaultValue})`,r=G(t);return`${r.length>0?`${r}\n`:``} ${e.title}${n}: `}const _n={"cloud-paid":`[Cloud/Paid]`,"cloud-free":`[Cloud/Free]`,"local-free":`[Local/Free]`};function W(e){let t=`${e.category===void 0?``:`${_n[e.category]??``} `}${e.displayName===void 0?e.type:`${e.displayName} (${e.type})`}`;return e.description===void 0?t:`${t} — ${e.description}`}function G(e=[]){return e.length===0?``:e.map(e=>` Setup help: ${Sn(e.kind)}: ${e.label} - ${e.url}`).join(`
28
+ `)}function vn(e){if(/^\d+$/.test(e))return Number(e)-1}function yn(e,t){if(e.required===!0&&t.length===0)return`Required`}function bn(e,n){let r=(0,t.findProviderDefinition)(n,e);if(r===void 0)throw Error(`Unknown provider: ${e}. Currently supported: ${(0,t.formatSupportedProviderTypes)(n)}`);return r}function xn(e){if(e.setupSteps!==void 0)return[...e.setupSteps];let t=[{key:`model`,title:`${e.type} model`,defaultValue:e.defaults?.model,required:e.defaults?.model===void 0}];return e.defaults?.baseURL!==void 0&&t.unshift({key:`baseURL`,title:`${e.type} base URL`,defaultValue:e.defaults.baseURL}),e.requiresApiKey===!0&&t.push({key:`apiKey`,title:`${e.type} API key`,defaultValue:e.defaults?.apiKey,required:e.defaults?.apiKey===void 0,masked:!0}),t}function Sn(e){return e===`api-key`?`API key`:e===`console`?`Console`:`Official`}function Cn(e,t){return t===void 0?[...e]:e.map(e=>{let n=t[e.key];return n===void 0?e:{...e,defaultValue:n,required:!1}})}function wn(t){let n=t.profileName??(0,e.suggestProviderProfileName)({type:t.type},{existingProfileNames:t.existingProfileNames}),r=t.values.apiKey;return{profile:n,type:t.type,model:t.values.model,...r!==void 0&&r.length>0&&{apiKey:r},...t.values.baseURL!==void 0&&{baseURL:t.values.baseURL},setCurrent:t.setCurrent??!0}}const Tn={type:`session-restart-requested`,reason:`other`};function En(e,t){return V(e,t.providerDefinitions,{existingProfileNames:Object.keys(t.settings.readMergedSettings().providers??{})})}function Dn(e,n){let r=H(e),i=r.masked===!0&&r.defaultValue!==void 0?`(unchanged)`:r.defaultValue,a=G(e.setupHelpLinks),o=[n,a.length>0?a:void 0].filter(e=>e!==void 0&&e.length>0).join(`
29
+ `)||void 0;return(0,t.textAction)(`provider-setup-${r.key}`,r.title,{description:o,placeholder:i,allowEmpty:r.defaultValue!==void 0,masked:r.masked})}async function On(e,t,n,r){let i=t,a;for(;;){let t=await e.ask(Dn(i,a));if(t.type===`cancelled`)return{message:r,success:!0};let o=U(i,t.text??``);if(o.status===`error`){a=o.message;continue}if(o.status===`complete`)return n(o.input);i=o.state,a=void 0}}function kn(e,t,n){return On(e,t,e=>An(e,n),`Provider setup cancelled.`)}function An(t,n){let r=n.settings.readTargetSettings(),i=(0,e.buildProviderSetupPatch)(t,{providerDefinitions:n.providerDefinitions});return n.settings.writeTargetSettings((0,e.mergeProviderPatch)(r,i)),{message:`Provider ${t.profile} configured. Restarting...`,success:!0,effects:[{...Tn,message:`Provider setup restart`}]}}function jn(e,t,n){return`${e===n?`* `:``}${e}: ${t.type??`unknown`} ${t.model??`(no model)`}`}function Mn(t,n,r){if(!n)return{message:`Usage: /provider switch <profile>`,success:!1};if(!t?.[n])return{message:`Provider profile "${n}" was not found.`,success:!1};let{orgPolicy:i}=r;if(i?.allowedProviders&&!i.allowedProviders.includes(n))return{message:(0,e.formatOrgPolicyViolationMessage)(`Provider "${n}" is not allowed by your organization policy. Allowed: ${i.allowedProviders.join(`, `)}.`,i.adminContact),success:!1};if(r.settings.readMergedSettings().currentProvider===n)return{message:`Already using provider "${n}".`,success:!0};let a=t[n],o=r.settings.readTargetSettings(),s=r.settings.readMergedSettings(),c=o.providers?.[n]!==void 0||s.providers?.[n]!==void 0?{...o,currentProvider:n}:(0,e.setCurrentProvider)(o,n);return r.settings.writeTargetSettings(c),{message:`Switched to ${n} (${a.model??`unknown model`}). History preserved.`,success:!0,effects:[{type:`provider-hot-swap-requested`,profileName:n}]}}async function Nn(e,t,n){let r=n.settings.readMergedSettings().providers?.[t];if(!r)return{message:`Provider profile "${t}" was not found.`,success:!1};if(!r.type)return{message:`Provider profile "${t}" is missing type.`,success:!1};let i;try{i=V(r.type,n.providerDefinitions,{profileName:t,setCurrent:!1,initialValues:Pn(r)})}catch(e){return{message:e instanceof Error?e.message:String(e),success:!1}}return On(e,i,e=>Fn(e,t,n),`Provider edit cancelled.`)}function Pn(e){return{...typeof e.model==`string`?{model:e.model}:{},...typeof e.apiKey==`string`?{apiKey:e.apiKey}:{},...typeof e.baseURL==`string`?{baseURL:e.baseURL}:{}}}function Fn(t,n,r){let i=r.settings.readMergedSettings(),a=i.providers?.[n];if(!a)return{message:`Provider profile "${n}" was not found.`,success:!1};let{orgPolicy:o}=r;if(o?.requireApiKeyFromEnv&&(0,e.isApiKeyPlaintext)(t.apiKey))return{message:(0,e.formatOrgPolicyViolationMessage)(`Your organization policy requires API keys to be stored as environment variable references ($ENV:VAR_NAME), not as plaintext.`,o.adminContact),success:!1};let s=r.settings.readTargetSettings(),c=(0,e.buildProviderSetupPatch)(t,{providerDefinitions:r.providerDefinitions}).providers[n];if(!c)return{message:`Provider profile "${n}" was not updated.`,success:!1};r.settings.writeTargetSettings((0,e.upsertProviderProfile)(s,n,{...a,...c}));let l=i.currentProvider===n;return{message:l?`Provider ${n} updated. Switching...`:`Provider ${n} updated.`,success:!0,...l?{effects:[{type:`provider-hot-swap-requested`,profileName:n}]}:{}}}const In={type:`session-restart-requested`,reason:`other`};async function Ln(e,n,r){let i=r.settings.readMergedSettings();if(!i.providers?.[n])return{message:`Provider profile "${n}" was not found.`,success:!1};let a=Un(n,Object.keys(i.providers)),o;for(;;){let i=await e.ask((0,t.textAction)(`provider-duplicate`,`Duplicate ${n} as`,{description:o,placeholder:a,allowEmpty:!0}));if(i.type===`cancelled`)return{message:`Provider duplicate cancelled.`,success:!0};let s=i.text??``,c=Rn(s,a,r);if(c!==void 0){o=c;continue}return zn(n,s,a,r)}}function Rn(e,t,n){let r=Wn(e,t);if(r.length===0)return`Required`;if(n.settings.readMergedSettings().providers?.[r]!==void 0)return`Provider profile "${r}" already exists`}function zn(t,n,r,i){let a=i.settings.readMergedSettings().providers?.[t];if(!a)return{message:`Provider profile "${t}" was not found.`,success:!1};let o=Wn(n,r),s=Rn(o,r,i);return s===void 0?(i.settings.writeTargetSettings((0,e.upsertProviderProfile)(i.settings.readTargetSettings(),o,{...a})),{message:`Provider profile duplicated: ${t} -> ${o}.`,success:!0}):{message:s,success:!1}}async function Bn(e,n,r){let i=r.settings.readMergedSettings().providers??{};return i[n]?Object.keys(i).length<=1?{message:`Cannot delete the only provider profile.`,success:!1}:r.settings.readTargetSettings().providers?.[n]===void 0?{message:`Provider profile "${n}" is not stored in the active write target; edit its source settings file or override it before deleting.`,success:!1}:(0,t.isConfirmed)(await e.ask((0,t.confirmAction)(`provider-delete`,`Delete provider profile ${n}?`)))?Vn(e,n,r):{message:`Provider delete cancelled.`,success:!0}:{message:`Provider profile "${n}" was not found.`,success:!1}}async function Vn(n,r,i){let a=i.settings.readMergedSettings();if(a.currentProvider!==r)return i.settings.writeTargetSettings((0,e.deleteProviderProfile)(i.settings.readTargetSettings(),r)),{message:`Provider profile deleted: ${r}.`,success:!0};let o=Object.entries(a.providers??{}).filter(([e])=>e!==r).map(([e,t])=>({value:e,label:jn(e,t,a.currentProvider)})),s=await n.ask((0,t.selectAction)(`provider-delete-replacement`,`Replacement provider for ${r}`,o,{maxVisible:8}));return s.type!==`answer`||s.values[0]===void 0?{message:`Provider delete cancelled.`,success:!0}:Hn(r,s.values[0],i)}function Hn(t,n,r){if(r.settings.readMergedSettings().providers?.[n]===void 0||n===t)return{message:`Provider profile "${n}" was not found.`,success:!1};let i=(0,e.deleteProviderProfile)(r.settings.readTargetSettings(),t);return r.settings.writeTargetSettings({...i,currentProvider:n}),{message:`Provider profile deleted: ${t}. Restarting with ${n}...`,success:!0,effects:[{...In,message:`Provider delete restart`}]}}function Un(t,n){let r=(0,e.sanitizeProviderProfileName)(`${t}-copy`)??`provider-copy`;if(!n.includes(r))return r;for(let e=2;e<1e3;e+=1){let t=`${r}-${e}`;if(!n.includes(t))return t}return`${r}-${Date.now()}`}function Wn(t,n){return(0,e.sanitizeProviderProfileName)(t.trim()||n)??``}const Gn=`switch`,Kn=`edit`,qn=`test`,Jn=`duplicate`,Yn=`delete`,Xn=`cancel`;async function Zn(e,n,r,i){let a=Object.entries(r??{}).map(([e,t])=>({value:e,label:jn(e,t,n)})),o=await e.ask((0,t.selectAction)(`provider-profile`,`Select provider profile`,a,{maxVisible:8}));return o.type!==`answer`||o.values[0]===void 0?{message:`Provider profile selection cancelled.`,success:!0}:Qn(e,o.values[0],i)}async function Qn(e,n,r){if(!r.settings.readMergedSettings().providers?.[n])return{message:`Provider profile "${n}" was not found.`,success:!1};let i=await e.ask((0,t.selectAction)(`provider-profile-action`,`Provider profile: ${n}`,[{value:Gn,label:`Switch`},{value:Kn,label:`Edit`},{value:qn,label:`Test`},{value:Jn,label:`Duplicate`},{value:Yn,label:`Delete`},{value:Xn,label:`Cancel`}]));return i.type!==`answer`||i.values[0]===void 0?{message:`Provider profile action cancelled.`,success:!0}:$n(e,n,i.values[0],r)}async function $n(t,n,r,i){let a=i.settings.readMergedSettings();switch(r){case Gn:return Mn(a.providers,n,i);case Kn:return Nn(t,n,i);case qn:return(0,e.testProviderProfileCommand)(a.currentProvider,a.providers,n,i);case Jn:return Ln(t,n,i);case Yn:return Bn(t,n,i);case Xn:return{message:`Provider profile action cancelled.`,success:!0};default:return{message:`Unknown provider profile action "${r}".`,success:!1}}}async function er(t,n,r){let i=t.getUserInteraction?.(),a=r.settings.readMergedSettings(),o=n.trim();if(o.length===0)return tr(i,a.currentProvider,a.providers,r);let[s=`current`,c]=o.split(/\s+/);return s===`list`?tr(i,a.currentProvider,a.providers,r):s===`current`||s===``?{message:rr(a.currentProvider,a.providers),success:!0}:s===`switch`?Mn(a.providers,c,r):s===`test`?(0,e.testProviderProfileCommand)(a.currentProvider,a.providers,c,r):s===`add`?ir(i,c,r):{message:`Usage: provider [current|list|switch <profile>|add <type>|test [profile]]`,success:!1}}function tr(e,t,n,r){return!e||Object.keys(n??{}).length===0?{message:nr(t,n),success:!0}:Zn(e,t,n,r)}function nr(e,t){let n=Object.entries(t??{});return n.length===0?`No provider profiles configured.`:n.map(([t,n])=>`${t===e?`*`:`-`} ${t}: ${n.type??`unknown`} ${n.model??`(no model)`}`).join(`
30
+ `)}function rr(e,t){if(!e)return`No current provider configured.`;let n=t?.[e];return n?[`Current provider: ${e}`,`Type: ${n.type??`unknown`}`,`Model: ${n.model??`(no model)`}`,...n.baseURL?[`Base URL: ${n.baseURL}`]:[]].join(`
31
+ `):`Current provider "${e}" was not found in providers.`}function ir(e,n,r){return n===void 0||n.length===0?e?ar(e,r):{message:`Usage: provider add <type>. Supported: ${(0,t.formatSupportedProviderTypes)(r.providerDefinitions)}`,success:!1}:(0,t.findProviderDefinition)(r.providerDefinitions,n)===void 0?{message:`Usage: provider add <type>. Supported: ${(0,t.formatSupportedProviderTypes)(r.providerDefinitions)}`,success:!1}:e?kn(e,En(n,r),r):{message:`Provider setup for "${n}" requires an interactive session.`,success:!1}}async function ar(e,n){let r=n.providerDefinitions.map(e=>({value:e.type,label:W(e)})),i=await e.ask((0,t.selectAction)(`provider-type`,`Select provider`,r,{maxVisible:6}));if(i.type!==`answer`||i.values[0]===void 0)return{message:`Provider setup cancelled.`,success:!0};let a=i.values[0];return(0,t.findProviderDefinition)(n.providerDefinitions,a)===void 0?{message:`Usage: provider add <type>. Supported: ${(0,t.formatSupportedProviderTypes)(n.providerDefinitions)}`,success:!1}:kn(e,En(a,n),n)}function or(){return[{name:`current`,description:`Show current provider`,source:`provider`},{name:`list`,description:`List provider profiles`,source:`provider`},{name:`switch`,description:`Hot-swap to another provider profile`,source:`provider`},{name:`add`,description:`Configure a provider profile`,source:`provider`},{name:`test`,description:`Test provider profile`,source:`provider`}]}function K(){return{name:`provider`,displayName:`Provider Setup`,description:`Manage provider profiles`,source:`provider`,modelInvocable:!1,argumentHint:`current | list | switch <profile> | add [type] | test [profile]`,subcommands:or(),example:`/provider switch production`}}var sr=class{name=`provider`;getCommands(){return[K()]}};function cr(e){let t=K();return{name:t.name,displayName:t.displayName,description:t.description,example:t.example,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,argumentHint:t.argumentHint,subcommands:t.subcommands,lifecycle:`inline`,execute:(t,n)=>er(t,n,e)}}function lr(e){return{name:`agent-command-provider`,commandSources:[new sr],systemCommands:[cr(e)]}}async function ur(e,t){let n=(await e(`
27
32
  Do you have an API key for an AI provider?
28
33
 
29
34
  1. Yes, I have an API key
@@ -50,14 +55,14 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
50
55
  When the server is running, come back here and press Enter to continue.
51
56
 
52
57
  ─────────────────────────────────────────────────────────────────────────────
53
- `),await e(` Press Enter when LM Studio server is running: `),{path:`local`,preselectedType:`gemma`}):{path:`has-key`}}async function ar(t,n,r,i,a){let o=await ir(r,i),s=Object.keys((0,e.readMergedProviderSettings)(t).providers??{}),c=(0,e.resolveSettingsPathForScope)(t,n.settingsScope),l;l=o.preselectedType===void 0?rn(await r(nn(a)),a):o.preselectedType,(0,e.applyProviderConfiguration)(c,await an(l,r,a,{existingProfileNames:s}),{providerDefinitions:a});let u=await r(` Response language (ko/en/ja/zh, default: en): `);if(u){let t=(0,e.readSettings)(c);t.language=u,(0,e.writeSettings)(c,t)}i.writeLine(`\n Config saved to ${c}\n`)}async function or(t,n,r,i,a,o){let s=(0,e.readMergedProviderSettings)(t);if((0,e.checkSettingsDocument)(n.provider===void 0?s:{...s,currentProvider:n.provider},a)===`valid`||n.provider===void 0&&(0,e.resolveEnvDefaultProvider)(a,o.env)!==void 0)return;if(!(o.isInteractive??(()=>!1))())throw new e.ProviderConfigError(o.formatError(a));await ar(t,sr(t,n),r,i,a);let c=(0,e.readMergedProviderSettings)(t);if((0,e.checkSettingsDocument)(n.provider===void 0?c:{...c,currentProvider:n.provider},a)!==`valid`)throw new e.ProviderConfigError(o.formatError(a))}function sr(t,n){if(n.settingsScope!==void 0||n.provider!==void 0)return n;let i=cr((0,e.getProviderSettingsPaths)(t));if(i===void 0)return n;let a=(0,r.join)(t,`.robota`,`settings.json`),o=(0,r.join)(t,`.robota`,`settings.local.json`);return i===a||i===o?{...n,settingsScope:`project-local`}:n}function cr(t){for(let n=t.length-1;n>=0;--n){let r=t[n];if(r!==void 0&&typeof(0,e.readSettings)(r).currentProvider==`string`)return r}}function lr(e,t){return{success:!0,message:`Reset requested.`,data:{resetRequested:!0},effects:[{type:`settings-reset-requested`}]}}function G(){return{name:`reset`,displayName:`Reset Settings`,description:`Delete settings`,source:`reset`,modelInvocable:!1}}function ur(){let e=G();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!0,userInvocable:!0,modelInvocable:!1,lifecycle:`inline`,execute:lr}}var dr=class{name=`reset`;getCommands(){return[G()]}};function fr(){return{name:`agent-command-reset`,commandSources:[new dr],systemCommands:[ur()]}}function K(){return{message:`Usage: rewind [list] | rewind inspect <checkpoint-id> | rewind restore <checkpoint-id> | rewind code <checkpoint-id> | rewind rollback <checkpoint-id>`,success:!1}}function pr(e){let t=e.replace(/\s+/g,` `).trim();return t.length<=120?t:`${t.slice(0,117)}...`}function mr(e){return{message:[`Edit checkpoints:`,...e.length>0?e.map(e=>`- ${e.id} files=${e.fileCount} ${e.createdAt} ${pr(e.prompt)}`):[`(no edit checkpoints)`]].join(`
54
- `),success:!0,data:{count:e.length,checkpoints:[...e]}}}function hr(e){return e.length>0?e.join(`, `):`(none)`}function gr(e){let t=e.capturedFiles.length>0?e.capturedFiles.map(e=>{let t=e.snapshotSizeBytes===void 0?``:` size=${e.snapshotSizeBytes}B`;return`- ${e.relativePath} action=${e.restoreAction} snapshot=${String(e.snapshotAvailable)}${t}`}):[`(no files captured)`];return{message:[`Checkpoint ${e.target.id}`,`Prompt: ${pr(e.target.prompt)}`,`Captured files:`,...t,`Restore later checkpoints: files=${e.restoreToCheckpoint.fileCount} checkpoints=${hr(e.restoreToCheckpoint.checkpointIds)}`,`Rollback through checkpoint: files=${e.rollbackThroughCheckpoint.fileCount} checkpoints=${hr(e.rollbackThroughCheckpoint.checkpointIds)}`].join(`
55
- `),success:!0,data:{inspection:e}}}function _r(e){return{message:[`Restored code to ${e.target.id}.`,`Restored files: ${e.restoredFileCount}`,`Rolled back checkpoints: ${e.restoredCheckpointCount}`].join(`
56
- `),success:!0,data:{target:e.target,restoredCheckpointCount:e.restoredCheckpointCount,restoredFileCount:e.restoredFileCount,removedCheckpointCount:e.removedCheckpointCount}}}function vr(e){return{message:[`Rolled back code through ${e.target.id}.`,`Restored files: ${e.restoredFileCount}`,`Removed checkpoints: ${e.removedCheckpointCount}`].join(`
57
- `),success:!0,data:{target:e.target,restoredCheckpointCount:e.restoredCheckpointCount,restoredFileCount:e.restoredFileCount,removedCheckpointCount:e.removedCheckpointCount}}}function q(e){return{message:e instanceof Error?e.message:String(e),success:!1}}function yr(t,n){if(!n)return K();try{return gr((0,e.inspectCommandEditCheckpoint)(t,n))}catch(e){return q(e instanceof Error?e:String(e))}}async function br(t,n){if(!n)return K();try{return _r(await(0,e.restoreCommandEditCheckpoint)(t,n))}catch(e){return q(e instanceof Error?e:String(e))}}async function xr(t,n){if(!n)return K();try{return vr(await(0,e.rollbackCommandEditCheckpoint)(t,n))}catch(e){return q(e instanceof Error?e:String(e))}}async function Sr(t,n){let r=n.trim().split(/\s+/).filter(Boolean),i=r[0]??`list`;return i===`list`?mr((0,e.listCommandEditCheckpoints)(t)):i===`inspect`?yr(t,r[1]):i===`restore`||i===`code`?br(t,r[1]):i===`rollback`?xr(t,r[1]):K()}function Cr(){return{name:`rewind`,displayName:`Rewind History`,description:e.REWIND_COMMAND_DESCRIPTION,source:`rewind`,argumentHint:e.REWIND_COMMAND_ARGUMENT_HINT,modelInvocable:!1,safety:`write`,subcommands:(0,e.buildRewindCommandSubcommands)()}}function wr(){let e=Cr();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,argumentHint:e.argumentHint,userInvocable:!0,modelInvocable:!1,safety:`write`,subcommands:e.subcommands,execute:Sr}}var Tr=class{name=`rewind`;getCommands(){return[Cr()]}};function Er(){return{name:`agent-command-rewind`,commandSources:[new Tr],systemCommands:[wr()]}}const Dr={s:1e3,m:6e4,h:36e5,d:864e5},J=`Usage: /schedule in <N><s|m|h|d> <instruction> | /schedule cron "<expr>" <instruction>`;function Or(e,t){let n=e.trim();if(n.length===0)return{ok:!1,error:J};if(n.startsWith(`in `)){let e=n.slice(3).trim(),r=e.indexOf(` `);if(r===-1)return{ok:!1,error:`Missing instruction. ${J}`};let i=e.slice(0,r),a=e.slice(r+1).trim(),o=/^(\d+)(s|m|h|d)$/.exec(i);if(!o)return{ok:!1,error:`Invalid duration "${i}". ${J}`};if(a.length===0)return{ok:!1,error:`Missing instruction. ${J}`};let s=parseInt(o[1],10)*Dr[o[2]];return{ok:!0,spec:{cronExpression:new Date(t+s).toISOString(),instruction:a,recurring:!1}}}if(n.startsWith(`cron `)){let e=n.slice(5).trim(),t=/^["']([^"']+)["']\s+(.+)$/.exec(e);if(!t)return{ok:!1,error:`cron form needs a quoted expression. ${J}`};let r=t[2].trim();return r.length===0?{ok:!1,error:`Missing instruction. ${J}`}:{ok:!0,spec:{cronExpression:t[1].trim(),instruction:r,recurring:!0}}}return{ok:!1,error:J}}function kr(e,t){return`${e}: ${t.slice(0,48)}${t.length>48?`…`:``}`}async function Ar(e,t,n=Date.now()){let r=Or(t,n);if(!r.ok)return{message:r.error,success:!1};let{cronExpression:i,instruction:a,recurring:o}=r.spec,s=await e.spawnScheduledWake({label:kr(`Scheduled`,a),cronExpression:i,agentInstruction:a});return{message:`Scheduled wake (${o?`cron \`${i}\``:`once at ${i}`}): "${a}" — task ${s.id}.`,success:!0,data:{taskId:s.id,cronExpression:i,recurring:o}}}function jr(e){let t=/^["']([^"']+)["']\s+["']([^"']+)["']\s+(.+)$/.exec(e.trim());if(!t)return null;let n=t[3].trim();return n.length===0?null:{command:t[1],matchPattern:t[2],instruction:n}}async function Mr(e,t){let n=jr(t);if(!n)return{message:`Usage: /monitor "<command>" "<pattern>" <instruction>`,success:!1};let r=await e.spawnMonitorWake({label:kr(`Monitor`,n.instruction),command:n.command,matchPattern:n.matchPattern,agentInstruction:n.instruction});return{message:`Monitoring \`${n.command}\` for /${n.matchPattern}/ — task ${r.id}.`,success:!0,data:{taskId:r.id,matchPattern:n.matchPattern}}}function Nr(e){let t=e.getAgentJobCapability?.();if(!t)throw Error(`Scheduling requires an active agent runtime.`);return t}function Y(){return{name:`schedule`,displayName:`Schedule Wake`,description:`Schedule the agent to wake and run an instruction on a timer (one-shot or cron).`,source:`schedule`,argumentHint:`in <N><s|m|h|d> <instruction> | cron "<expr>" <instruction>`,modelInvocable:!0}}function Pr(){return{name:`monitor`,displayName:`Monitor Process`,description:`Watch a process’s output and wake the agent when a line matches a pattern.`,source:`schedule`,argumentHint:`"<command>" "<pattern>" <instruction>`,modelInvocable:!0}}function Fr(){let e=Y();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!0,argumentHint:e.argumentHint,lifecycle:`inline`,execute:(e,t)=>Ar(Nr(e),t)}}function Ir(){let e=Pr();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!0,argumentHint:e.argumentHint,lifecycle:`inline`,execute:(e,t)=>Mr(Nr(e),t)}}var Lr=class{name=`schedule`;getCommands(){return[Y(),Pr()]}};function Rr(){return{name:`agent-command-schedule`,commandSources:[new Lr],systemCommands:[Fr(),Ir()],sessionRequirements:[`agent-runtime`]}}const zr={"claude-opus-4-7":{inputPerMillion:15,outputPerMillion:75},"claude-opus-4-5":{inputPerMillion:15,outputPerMillion:75},"claude-sonnet-4-6":{inputPerMillion:3,outputPerMillion:15},"claude-sonnet-4-5":{inputPerMillion:3,outputPerMillion:15},"claude-haiku-4-5":{inputPerMillion:.8,outputPerMillion:4},"claude-3-5-sonnet-20241022":{inputPerMillion:3,outputPerMillion:15},"claude-3-5-haiku-20241022":{inputPerMillion:.8,outputPerMillion:4},"claude-3-opus-20240229":{inputPerMillion:15,outputPerMillion:75},"gpt-4o":{inputPerMillion:2.5,outputPerMillion:10},"gpt-4o-mini":{inputPerMillion:.15,outputPerMillion:.6},o1:{inputPerMillion:15,outputPerMillion:60},"o1-mini":{inputPerMillion:3,outputPerMillion:12},o3:{inputPerMillion:10,outputPerMillion:40},"o3-mini":{inputPerMillion:1.1,outputPerMillion:4.4},"deepseek-chat":{inputPerMillion:.14,outputPerMillion:.28},"deepseek-reasoner":{inputPerMillion:.55,outputPerMillion:2.19},"gemini-2.0-flash":{inputPerMillion:.1,outputPerMillion:.4},"gemini-2.0-flash-thinking":{inputPerMillion:.35,outputPerMillion:3.5},"gemini-1.5-pro":{inputPerMillion:1.25,outputPerMillion:5},"gemini-1.5-flash":{inputPerMillion:.075,outputPerMillion:.3}},Br=[{pattern:/claude-opus/i,price:{inputPerMillion:15,outputPerMillion:75}},{pattern:/claude-sonnet/i,price:{inputPerMillion:3,outputPerMillion:15}},{pattern:/claude-haiku/i,price:{inputPerMillion:.8,outputPerMillion:4}},{pattern:/gpt-4o-mini/i,price:{inputPerMillion:.15,outputPerMillion:.6}},{pattern:/gpt-4/i,price:{inputPerMillion:2.5,outputPerMillion:10}},{pattern:/deepseek/i,price:{inputPerMillion:.14,outputPerMillion:.28}},{pattern:/gemini-2/i,price:{inputPerMillion:.1,outputPerMillion:.4}},{pattern:/gemini-1/i,price:{inputPerMillion:1.25,outputPerMillion:5}}];function Vr(e){let t=zr[e];if(t)return t;for(let{pattern:t,price:n}of Br)if(t.test(e))return n}function Hr(e,t,n){let r=Vr(e);if(r)return t/1e6*r.inputPerMillion+n/1e6*r.outputPerMillion}function X(e){return e<.01?`$${e.toFixed(4)}`:e<1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function Ur(e){return e.toLocaleString(`en-US`)}const Wr=`Conversation cleared.`;function Gr(t,n){return(0,e.clearConversationHistory)(t),{success:!0,message:Wr,effects:[{type:`conversation-history-cleared`}]}}function Kr(t,n){let r=(0,e.parseSessionNameArgument)(n);return r===void 0?{success:!1,message:e.RENAME_COMMAND_USAGE}:{success:!0,message:`Session renamed to "${r}".`,data:{name:r},effects:[(0,e.createSessionRenamedEffect)(r)]}}function qr(t,n){return{success:!0,message:`Opening session picker...`,data:{triggerResumePicker:!0},effects:[(0,e.createSessionPickerRequestedEffect)()]}}const Jr=`.robota/budget.json`;function Yr(e){let t=(0,r.join)(e,Jr);if(!(0,i.existsSync)(t))return;let n;try{n=(0,i.readFileSync)(t,`utf-8`)}catch{return}try{return JSON.parse(n)}catch{return}}function Xr(e,t){(0,i.mkdirSync)((0,r.join)(e,`.robota`),{recursive:!0}),(0,i.writeFileSync)((0,r.join)(e,Jr),JSON.stringify(t,null,2))}function Zr(e){let t=(0,r.join)(e,Jr);(0,i.existsSync)(t)&&(0,i.writeFileSync)(t,`{}`)}function Qr(t){let n=t.getSession(),r=(0,e.readCommandSessionInfo)(t),i=n.getSessionTokenUsage?.(),a=n.getModelId?.(),o=[`Session: ${r.sessionId}`,`Messages: ${r.messageCount}`],s={sessionId:r.sessionId,messageCount:r.messageCount};if(i){if(o.push(`Tokens: ${Ur(i.inputTokens)} input / ${Ur(i.outputTokens)} output`),s.inputTokens=i.inputTokens,s.outputTokens=i.outputTokens,a){let e=Hr(a,i.inputTokens,i.outputTokens);if(e!==void 0){o.push(`Cost: ${X(e)} (${a})`),s.estimatedCostUsd=e;let n=Yr(t.getCwd());if(n?.monthly){let t=n.monthly-e,r=Math.min(100,Math.round(e/n.monthly*100));o.push(`Budget: ${X(t)} remaining of ${X(n.monthly)}/mo (${r}% used)`),s.budgetMonthly=n.monthly,s.budgetRemainingUsd=t}}}}else o.push(`Tokens: not yet available (no turns completed)`);return{lines:o,data:s}}function $r(e,t){let n=t.trim();if(n.startsWith(`budget`)){let t=n.slice(6).trim();if(t===`clear`)return Zr(e.getCwd()),{success:!0,message:`Monthly budget cleared.`};if(t===``){let t=Yr(e.getCwd());return t?.monthly?{success:!0,message:`Monthly budget: ${X(t.monthly)}`}:{success:!0,message:`No budget set. Use: /cost budget <amount>`}}let r=parseFloat(t);return!Number.isFinite(r)||r<=0?{success:!1,message:`Usage: /cost budget <amount> (e.g. /cost budget 5.00)`}:(Xr(e.getCwd(),{monthly:r}),{success:!0,message:`Monthly budget set to ${X(r)}.`})}let{lines:r,data:i}=Qr(e);return{success:!0,message:r.join(`
58
- `),data:i}}function ei(t,n){let r=(0,e.validateCommandSessionReplayLog)(t);return{success:r.validation.ok,message:(0,e.formatCommandSessionReplayValidationReport)(r),data:{logFile:r.logFile,entryCount:r.entryCount,issueCount:r.validation.issues.length,ok:r.validation.ok}}}function ti(){return{name:`clear`,displayName:`Clear History`,description:e.CLEAR_COMMAND_DESCRIPTION,source:`session`,modelInvocable:!1}}function ni(){return{name:`rename`,displayName:`Rename Session`,description:e.RENAME_COMMAND_DESCRIPTION,source:`session`,modelInvocable:!1}}function ri(){return{name:`resume`,displayName:`Resume Session`,description:e.RESUME_COMMAND_DESCRIPTION,source:`session`,modelInvocable:!1}}function ii(){return{name:`cost`,displayName:`Session Cost`,description:e.COST_COMMAND_DESCRIPTION,source:`session`,modelInvocable:!1}}function ai(){return{name:`validate-session`,displayName:`Validate Session`,description:e.VALIDATE_SESSION_COMMAND_DESCRIPTION,source:`session`,modelInvocable:!1}}function oi(){let e=ti();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,lifecycle:`inline`,execute:Gr}}function si(){let e=ni();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,lifecycle:`inline`,execute:Kr}}function ci(){let e=ri();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,lifecycle:`inline`,execute:qr}}function li(){let e=ii();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,lifecycle:`inline`,execute:$r}}function ui(){let e=ai();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,lifecycle:`inline`,execute:ei}}var di=class{name=`session`;getCommands(){return[ti(),ni(),ri(),ii(),ai()]}};const fi={clear:{type:`confirm`,message:`Clear conversation history?`}};function pi(){return{name:`agent-command-session`,commandSources:[new di],systemCommands:[oi(),si(),ci(),li(),ui()],interactionHints:fi}}function Z(){return{name:`settings`,displayName:`Settings`,description:`Open transport settings — enable/disable transports and configure options`,source:`settings`,modelInvocable:!1}}function mi(){let e=Z();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,lifecycle:`inline`,execute:async()=>({success:!0,message:`Opening settings...`,effects:[{type:`settings-tui-requested`}]})}}var hi=class{name=`settings`;getCommands(){return[Z()]}};function gi(){return{name:`agent-command-settings`,commandSources:[new hi],systemCommands:[mi()]}}const _i=`Skill command. Before following a matching registered skill from the system prompt Skills section, invoke the projected skills command tool with args "<skill-name> [args]". Without arguments, list registered skills. With a skill name, activate that skill. Slash syntax is a UI input/display concern; the SDK command identity is "skills".`;function vi(e){let t=[];return e.modelInvocable||t.push(`model-disabled`),e.userInvocable||t.push(`model-only`),e.context&&t.push(`context:${e.context}`),e.agent&&t.push(`agent:${e.agent}`),t.length>0?` [${t.join(`, `)}]`:``}function yi(e){let t=e.argumentHint?` ${e.argumentHint}`:``;return`- ${e.name}${t}: ${e.description}${vi(e)}`}function bi(e){return e.length===0?[`No skills are registered for this session.`,``,`Skills are metadata until activated. Do not invent or imitate a skill workflow when no matching registered skill exists.`].join(`
59
- `):[`Registered skills:`,...e.map(yi),``,`Activation contract:`,`- Use /skills <skill-name> [args] to activate a matching skill.`,`- Treat /<skill-name> as a virtual alias for /skills <skill-name>.`,`- The system prompt Skills section is skill selection metadata.`,`- Treat descriptions as selection metadata only, not as loaded SKILL.md content.`,`- Do not answer by merely naming, recommending, or imitating a matching skill.`,`- If no listed skill matches the task, continue without claiming a skill was activated.`].join(`
60
- `)}function xi(e){let t=e.trim();if(t.length===0||t===`list`)return{action:`list`,skillArgs:``};let[n=``,...r]=t.split(/\s+/);return n.length===0?{action:`list`,skillArgs:``}:{action:`activate`,skillName:n,skillArgs:r.join(` `)}}async function Si(e,t=``){let n=xi(t);if(n.action===`activate`&&n.skillName!==void 0){if(!e.executeSkillCommandByName)return{success:!1,message:`Skill activation is not available in this session.`};let t=`/${n.skillName}${n.skillArgs?` ${n.skillArgs}`:``}`;return await e.executeSkillCommandByName(n.skillName,n.skillArgs,{invocationSource:e.getCommandInvocationSource?.()??`user`,displayInput:t,rawInput:t})??{success:!1,message:`Unknown skill: ${n.skillName}`}}let r=e.listSkills?.()??[];return{success:!0,message:bi(r),data:{skills:r,activationContract:{activateWith:`/skills <skill-name> [args]`,activationRequiredBeforeWorkflow:!0,metadataIsNotSkillContent:!0}}}}function Ci(){return{name:`skills`,displayName:`Skills`,description:_i,source:`skills`,modelInvocable:!0,userInvocable:!0,argumentHint:`[list | <skill-name> [args]]`,safety:`read-only`}}function wi(){let e=Ci();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!0,argumentHint:e.argumentHint,safety:e.safety,lifecycle:`inline`,execute:Si}}var Ti=class{name=`skills`;getCommands(){return[Ci()]}};function Ei(t){let n=[new Ti];return n.push(new e.SkillCommandSource(t.cwd)),{name:`agent-command-skills`,commandSources:n,systemCommands:[wi()]}}const Di=[`Usage: /statusline on | off | reset | git on | git off`,`Fields: model, context, permission mode, message count, session name, thinking state, git branch.`].join(`
61
- `);function Oi(t){let n=t.trim().toLowerCase().split(/\s+/).filter(e=>e.length>0),[r,i]=n;return r===`on`&&i===void 0?{success:!0,message:`Status line enabled.`,patch:{enabled:!0}}:r===`off`&&i===void 0?{success:!0,message:`Status line disabled.`,patch:{enabled:!1}}:r===`reset`&&i===void 0?{success:!0,message:`Status line settings reset.`,patch:{...e.DEFAULT_STATUS_LINE_COMMAND_SETTINGS}}:r===`git`&&i===`on`&&n.length===2?{success:!0,message:`Status line git branch shown.`,patch:{gitBranch:!0}}:r===`git`&&i===`off`&&n.length===2?{success:!0,message:`Status line git branch hidden.`,patch:{gitBranch:!1}}:{success:!1,message:Di}}function ki(e,t){let n=Oi(t);return n.success?{success:!0,message:n.message,effects:[{type:`statusline-settings-patch`,patch:n.patch}]}:{success:!1,message:n.message}}function Ai(){return{name:`statusline`,displayName:`Status Line`,description:e.STATUSLINE_COMMAND_DESCRIPTION,source:`statusline`,argumentHint:e.STATUSLINE_COMMAND_ARGUMENT_HINT,subcommands:(0,e.buildStatusLineCommandSubcommands)(`statusline`),modelInvocable:!1}}function ji(){let e=Ai();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,argumentHint:e.argumentHint,subcommands:e.subcommands,lifecycle:`inline`,execute:ki}}var Mi=class{name=`statusline`;getCommands(){return[Ai()]}};function Ni(){return{name:`agent-command-statusline`,commandSources:[new Mi],systemCommands:[ji()]}}const Pi=`Inspect Robota user-local storage and memory state.`,Fi=`storage list [--format json] | memory set/list/inspect/disable/delete`,Q=`Usage: user-local storage list [--format json] | user-local memory set <category> <key> <value> --summary <summary> --source <source> | user-local memory list [--format json] | user-local memory inspect <category> <key> [--format json] | user-local memory disable <category> <key> | user-local memory delete <category> <key>`;function Ii(e){return e.length===0?`No user-local memory items.`:e.map(e=>`- ${e.category}/${e.key} (${e.enabled?`enabled`:`disabled`})`).join(`
62
- `)}function $(e){if(e===void 0)throw Error(`User-local memory category is required.`);return e}async function Li(t,n){let r=await(0,e.listUserLocalMemoryItems)({activeRepositoryRoot:t});return{message:n.format===`json`?JSON.stringify(r,null,2):Ii(r.items),success:!0,data:{list:r}}}async function Ri(t,n){let[r,i,a]=n.positional,o=await(0,e.setUserLocalMemoryItem)({activeRepositoryRoot:t,category:$(r),key:i??``,value:a??``,summary:n.summary??``,source:n.source??``});return{message:`Stored user-local memory item ${o.category}/${o.key} at ${o.storageLocation}`,success:!0,data:{item:o}}}async function zi(t,n){let[r,i]=n.positional,a=await(0,e.inspectUserLocalMemoryItem)({activeRepositoryRoot:t,category:$(r),key:i??``});return{message:n.format===`json`?JSON.stringify(a,null,2):`${a.category}/${a.key}: ${a.summary}`,success:!0,data:{item:a}}}async function Bi(t,n){let[r,i]=n.positional,a=await(0,e.disableUserLocalMemoryItem)({activeRepositoryRoot:t,category:$(r),key:i??``});return{message:`Disabled user-local memory item ${a.category}/${a.key}`,success:!0,data:{item:a}}}async function Vi(t,n){let[r,i]=n.positional,a=await(0,e.deleteUserLocalMemoryItem)({activeRepositoryRoot:t,category:$(r),key:i??``});return{message:`Deleted user-local memory item ${a.category}/${a.key}`,success:!0,data:{result:a}}}async function Hi(e,t){return(t.action??`list`)===`list`?Li(e,t):t.action===`set`?Ri(e,t):t.action===`inspect`?zi(e,t):t.action===`disable`?Bi(e,t):t.action===`delete`?Vi(e,t):{message:Q,success:!1}}function Ui(e){if(e===void 0||e===`text`)return`text`;if(e===`json`)return`json`;throw Error(`Unsupported user-local output format: ${e}`)}function Wi(e,t,n){return e===`--format`?{format:t[n+1],nextIndex:n+1}:e.startsWith(`--format=`)?{format:e.slice(9),nextIndex:n}:e===`--summary`?{summary:t[n+1],nextIndex:n+1}:e.startsWith(`--summary=`)?{summary:e.slice(10),nextIndex:n}:e===`--source`?{source:t[n+1],nextIndex:n+1}:e.startsWith(`--source=`)?{source:e.slice(9),nextIndex:n}:null}function Gi(e,t={}){let n=t.format,r=t.summary,i=t.source,a=[];for(let t=0;t<e.length;t+=1){let o=e[t],s=Wi(o,e,t);if(s!==null){n=s.format??n,r=s.summary??r,i=s.source??i,t=s.nextIndex;continue}a.push(o)}return{target:a[0],action:a[1],positional:a.slice(2),format:Ui(n),summary:r,source:i}}function Ki(e){return e.trim().split(/\s+/).filter(Boolean)}function qi(e,t){let n=t.map(e=>`- ${e.category}`);return[`User-local storage root: ${e}`,`Categories:`,...n].join(`
63
- `)}async function Ji(t,n){if((n.action??`list`)!==`list`)return{message:Q,success:!1};let r=await(0,e.inspectUserLocalStorage)({activeRepositoryRoot:t});return{message:n.format===`json`?JSON.stringify(r,null,2):qi(r.root,r.categories),success:!0,data:{root:r.root,categories:r.categories,inspection:r}}}async function Yi(e,t){return t.target===`storage`?Ji(e,t):t.target===`memory`?Hi(e,t):{message:Q,success:!1}}function Xi(e){return e.includes(`ENOENT`)?`User-local memory item not found.`:e}async function Zi(e){try{return await Yi(e.cwd,Gi(e.argv,{format:e.format,summary:e.summary,source:e.source}))}catch(e){return{message:Xi(e instanceof Error?e.message:String(e)),success:!1}}}async function Qi(e,t){try{return await Yi(e.getCwd(),Gi(Ki(t)))}catch(e){return{message:Xi(e instanceof Error?e.message:String(e)),success:!1}}}function $i(){return{name:`user-local`,displayName:`User Config`,description:Pi,source:`user-local`,argumentHint:Fi,modelInvocable:!1,safety:`read-only`,subcommands:[{name:`storage`,description:`Inspect user-local storage categories`,source:`user-local`},{name:`memory`,description:`Inspect and manage user-local memory items`,source:`user-local`}]}}function ea(){let e=$i();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,argumentHint:e.argumentHint,safety:e.safety,subcommands:e.subcommands,execute:Qi}}var ta=class{name=`user-local`;getCommands(){return[$i()]}};function na(){return{name:`agent-command-user-local`,commandSources:[new ta],systemCommands:[ea()]}}function ra(e,t,n){let r=e;if(t!==void 0){let e=new Set(t);r=r.filter(t=>e.has(t.name))}if(n!==void 0){let e=new Set(n);r=r.filter(t=>!e.has(t.name))}return r}function ia({cwd:e,providerDefinitions:t,providerSettingsAdapter:n,enabledCommandModules:r,disabledCommandModules:i}){return ra([Ei({cwd:e}),at(),ye(),Mt(),Ot(),tn(),dt(),Te(),Ct(),na(),je(),Je(),et(),pi(),fr(),Er(),Rr(),Ni(),Kt(),gi(),rr({providerDefinitions:t,settings:n})],r,i)}function aa(t){let n=(0,o.homedir)(),i=(0,r.join)(n,`.robota`,`plugins`),s=(0,r.join)(n,`.robota`,`settings.json`),c=(e,t)=>(0,a.execSync)(e,{timeout:t.timeout,stdio:t.stdio??`pipe`}),l=new e.PluginSettingsStore(s),u=new e.MarketplaceClient({pluginsDir:i,exec:c});return{cwd:t,marketplace:u,installer:new e.BundlePluginInstaller({pluginsDir:i,settingsStore:l,marketplaceClient:u,exec:c}),loader:new e.BundlePluginLoader(i),settingsStore:l}}async function oa(e){let t=await e.loader.loadAll(),n=e.settingsStore.getEnabledPlugins();return t.map(e=>{let t=e.pluginDir.split(`/`),r=t.indexOf(`cache`),i=r>=0?t[r+1]??``:``,a=i?`${e.manifest.name}@${i}`:e.manifest.name;return{name:a,description:e.manifest.description,enabled:n[a]!==!1&&n[e.manifest.name]!==!1}})}async function sa(e,t){let n;try{n=e.marketplace.fetchManifest(t)}catch{return[]}let r=e.installer.getInstalledPlugins(),i=new Set(Object.values(r).map(e=>e.pluginName));return n.plugins.map(e=>({name:e.name,description:e.description,installed:i.has(e.name)}))}async function ca(t,n,i){let[o,s]=n.split(`@`);if(!o||!s)throw Error(`Plugin ID must be in format: name@marketplace`);if(i===`project`){let n=(0,r.join)(t.cwd,`.robota`,`plugins`);await new e.BundlePluginInstaller({pluginsDir:n,settingsStore:t.settingsStore,marketplaceClient:t.marketplace,exec:(e,t)=>(0,a.execSync)(e,{timeout:t.timeout,stdio:t.stdio??`pipe`})}).install(o,s);return}await t.installer.install(o,s)}async function la(e,t){let n=e.installer.getPluginsByMarketplace(t);for(let t of n)await e.installer.uninstall(`${t.pluginName}@${t.marketplace}`);e.marketplace.removeMarketplace(t)}function ua(e){return e.marketplace.listMarketplaces().map(e=>({name:e.name,type:e.source.type}))}function da(e){let t=aa(e);return{listInstalled:()=>oa(t),listAvailablePlugins:e=>sa(t,e),install:(e,n)=>ca(t,e,n),uninstall:async e=>t.installer.uninstall(e),enable:async e=>t.installer.enable(e),disable:async e=>t.installer.disable(e),marketplaceAdd:async e=>e.includes(`/`)&&!e.includes(`:`)?t.marketplace.addMarketplace({type:`github`,repo:e}):t.marketplace.addMarketplace({type:`git`,url:e}),marketplaceRemove:e=>la(t,e),marketplaceUpdate:async e=>t.marketplace.updateMarketplace(e),marketplaceList:async()=>ua(t),reloadPlugins:async()=>({loadedPluginCount:(await t.loader.loadAll()).length})}}const fa=`plugin`;function pa(){return process.env.HOME??(0,o.homedir)()}function ma(t){let n=new e.BundlePluginLoader((0,r.join)(pa(),`.robota`,`plugins`));try{let r=n.loadPluginsSync();return r.length===0?(t.replaceSource(fa),0):(t.replaceSource(fa,new e.PluginCommandSource(r)),r.length)}catch{return t.replaceSource(fa),0}}exports.AgentCommandSource=ve,exports.BackgroundCommandSource=we,exports.CLEAR_COMMAND_MESSAGE=Wr,exports.CompactCommandSource=Ae,exports.ContextCommandSource=qe,exports.ExitCommandSource=Qe,exports.HelpCommandSource=it,exports.LanguageCommandSource=lt,exports.MemoryCommandSource=St,exports.ModeCommandSource=Et,exports.PermissionsCommandSource=jt,exports.PluginManagerCommandSource=Gt,exports.PresetCommandSource=$t,exports.ProviderCommandSource=er,exports.RewindCommandSource=Tr,exports.SKILLS_COMMAND_DESCRIPTION=_i,exports.STATUSLINE_USAGE=Di,exports.ScheduleCommandSource=Lr,exports.SessionCommandSource=di,exports.SettingsCommandSource=hi,exports.SkillsCommandSource=Ti,exports.StatusLineCommandSource=Mi,exports.USER_LOCAL_COMMAND_ARGUMENT_HINT=Fi,exports.USER_LOCAL_COMMAND_DESCRIPTION=Pi,exports.USER_LOCAL_COMMAND_USAGE=Q,exports.UserLocalCommandSource=ta,exports.createAgentCommandEntry=g,exports.createAgentCommandModule=ye,exports.createAgentSystemCommand=_e,exports.createBackgroundCommandEntry=Se,exports.createBackgroundCommandModule=Te,exports.createClearCommandEntry=ti,exports.createCompactCommandEntry=Oe,exports.createCompactCommandModule=je,exports.createContextCommandEntry=w,exports.createContextCommandModule=Je,exports.createCostCommandEntry=ii,exports.createDefaultCommandModules=ia,exports.createDefaultPluginCommandAdapter=da,exports.createExitCommandEntry=Xe,exports.createExitCommandModule=et,exports.createHelpCommandEntry=nt,exports.createHelpCommandModule=at,exports.createLanguageCommandEntry=st,exports.createLanguageCommandModule=dt,exports.createMemoryCommandEntry=D,exports.createMemoryCommandModule=Ct,exports.createModeCommandEntry=O,exports.createModeCommandModule=Ot,exports.createMonitorCommandEntry=Pr,exports.createPermissionsCommandEntry=k,exports.createPermissionsCommandModule=Mt,exports.createPluginCommandEntry=N,exports.createPluginCommandModule=Kt,exports.createPresetCommandEntry=F,exports.createPresetCommandModule=tn,exports.createProviderCommandEntry=W,exports.createProviderCommandModule=rr,exports.createProviderSetupFlow=I,exports.createReloadPluginsCommandEntry=P,exports.createRenameCommandEntry=ni,exports.createResetCommandEntry=G,exports.createResetCommandModule=fr,exports.createResumeCommandEntry=ri,exports.createRewindCommandModule=Er,exports.createScheduleCommandEntry=Y,exports.createScheduleCommandModule=Rr,exports.createSessionCommandModule=pi,exports.createSettingsCommandEntry=Z,exports.createSettingsCommandModule=gi,exports.createSkillsCommandEntry=Ci,exports.createSkillsCommandModule=Ei,exports.createStatusLineCommandEntry=Ai,exports.createStatusLineCommandModule=Ni,exports.createUserLocalCommandEntry=$i,exports.createUserLocalCommandModule=na,exports.createValidateSessionCommandEntry=ai,exports.ensureProviderConfig=or,exports.executeAgentCommand=pe,exports.executeBackgroundCommand=xe,exports.executeClearCommand=Gr,exports.executeCompactCommand=De,exports.executeContextCommand=Ne,exports.executeCostCommand=$r,exports.executeExitCommand=Ye,exports.executeHelpCommand=tt,exports.executeLanguageCommand=ot,exports.executeMemoryCommand=bt,exports.executeModeCommand=wt,exports.executeMonitorCommand=Mr,exports.executePermissionsCommand=kt,exports.executePluginCommand=Vt,exports.executePresetCommand=Xt,exports.executeProviderCommand=qn,exports.executeReloadPluginsCommand=Ht,exports.executeRenameCommand=Kr,exports.executeResetCommand=lr,exports.executeResumeCommand=qr,exports.executeRewindCommand=Sr,exports.executeScheduleCommand=Ar,exports.executeSkillsCommand=Si,exports.executeStatusLineCommand=ki,exports.executeUserLocalCommand=Qi,exports.executeUserLocalDirectCommand=Zi,exports.executeValidateSessionCommand=ei,exports.formatProviderSetupChoiceLabel=z,exports.formatProviderSetupHelpLinks=B,exports.formatProviderSetupPromptLabel=on,exports.formatProviderSetupSelectionPrompt=nn,exports.getProviderSetupStep=L,exports.parseScheduleSpec=Or,exports.reloadPluginCommandSource=ma,exports.resolveProviderSetupSelection=rn,exports.runProviderSetupPromptFlow=an,exports.runProviderStartupSetup=ar,exports.submitProviderSetupValue=R,exports.validateProviderSetupValue=V;
58
+ `),await e(` Press Enter when LM Studio server is running: `),{path:`local`,preselectedType:`gemma`}):{path:`has-key`}}async function dr(t,n,r,i,a){let o=await ur(r,i),s=Object.keys((0,e.readMergedProviderSettings)(t).providers??{}),c=(0,e.resolveSettingsPathForScope)(t,n.settingsScope),l;l=o.preselectedType===void 0?mn(await r(pn(a)),a):o.preselectedType,(0,e.applyProviderConfiguration)(c,await hn(l,r,a,{existingProfileNames:s}),{providerDefinitions:a});let u=await r(` Response language (ko/en/ja/zh, default: en): `);if(u){let t=(0,e.readSettings)(c);t.language=u,(0,e.writeSettings)(c,t)}i.writeLine(`\n Config saved to ${c}\n`)}async function fr(t,n,r,i,a,o){let s=(0,e.readMergedProviderSettings)(t);if((0,e.checkSettingsDocument)(n.provider===void 0?s:{...s,currentProvider:n.provider},a)===`valid`||n.provider===void 0&&(0,e.resolveEnvDefaultProvider)(a,o.env)!==void 0)return;if(!(o.isInteractive??(()=>!1))())throw new e.ProviderConfigError(o.formatError(a));await dr(t,pr(t,n),r,i,a);let c=(0,e.readMergedProviderSettings)(t);if((0,e.checkSettingsDocument)(n.provider===void 0?c:{...c,currentProvider:n.provider},a)!==`valid`)throw new e.ProviderConfigError(o.formatError(a))}function pr(t,n){if(n.settingsScope!==void 0||n.provider!==void 0)return n;let r=mr((0,e.getProviderSettingsPaths)(t));if(r===void 0)return n;let a=(0,i.join)(t,`.robota`,`settings.json`),o=(0,i.join)(t,`.robota`,`settings.local.json`);return r===a||r===o?{...n,settingsScope:`project-local`}:n}function mr(t){for(let n=t.length-1;n>=0;--n){let r=t[n];if(r!==void 0&&typeof(0,e.readSettings)(r).currentProvider==`string`)return r}}function hr(e,t){return{success:!0,message:`Reset requested.`,data:{resetRequested:!0},effects:[{type:`settings-reset-requested`}]}}function gr(){return{name:`reset`,displayName:`Reset Settings`,description:`Delete settings`,source:`reset`,modelInvocable:!1}}function _r(){let e=gr();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!0,userInvocable:!0,modelInvocable:!1,lifecycle:`inline`,execute:hr}}var vr=class{name=`reset`;getCommands(){return[gr()]}};function yr(){return{name:`agent-command-reset`,commandSources:[new vr],systemCommands:[_r()]}}function q(){return{message:`Usage: rewind [list] | rewind inspect <checkpoint-id> | rewind restore <checkpoint-id> | rewind code <checkpoint-id> | rewind rollback <checkpoint-id>`,success:!1}}function br(e){let t=e.replace(/\s+/g,` `).trim();return t.length<=120?t:`${t.slice(0,117)}...`}function xr(e){return{message:[`Edit checkpoints:`,...e.length>0?e.map(e=>`- ${e.id} files=${e.fileCount} ${e.createdAt} ${br(e.prompt)}`):[`(no edit checkpoints)`]].join(`
59
+ `),success:!0,data:{count:e.length,checkpoints:[...e]}}}function Sr(e){return e.length>0?e.join(`, `):`(none)`}function Cr(e){let t=e.capturedFiles.length>0?e.capturedFiles.map(e=>{let t=e.snapshotSizeBytes===void 0?``:` size=${e.snapshotSizeBytes}B`;return`- ${e.relativePath} action=${e.restoreAction} snapshot=${String(e.snapshotAvailable)}${t}`}):[`(no files captured)`];return{message:[`Checkpoint ${e.target.id}`,`Prompt: ${br(e.target.prompt)}`,`Captured files:`,...t,`Restore later checkpoints: files=${e.restoreToCheckpoint.fileCount} checkpoints=${Sr(e.restoreToCheckpoint.checkpointIds)}`,`Rollback through checkpoint: files=${e.rollbackThroughCheckpoint.fileCount} checkpoints=${Sr(e.rollbackThroughCheckpoint.checkpointIds)}`].join(`
60
+ `),success:!0,data:{inspection:e}}}function wr(e){return{message:[`Restored code to ${e.target.id}.`,`Restored files: ${e.restoredFileCount}`,`Rolled back checkpoints: ${e.restoredCheckpointCount}`].join(`
61
+ `),success:!0,data:{target:e.target,restoredCheckpointCount:e.restoredCheckpointCount,restoredFileCount:e.restoredFileCount,removedCheckpointCount:e.removedCheckpointCount}}}function Tr(e){return{message:[`Rolled back code through ${e.target.id}.`,`Restored files: ${e.restoredFileCount}`,`Removed checkpoints: ${e.removedCheckpointCount}`].join(`
62
+ `),success:!0,data:{target:e.target,restoredCheckpointCount:e.restoredCheckpointCount,restoredFileCount:e.restoredFileCount,removedCheckpointCount:e.removedCheckpointCount}}}function J(e){return{message:e instanceof Error?e.message:String(e),success:!1}}function Er(t,n){if(!n)return q();try{return Cr((0,e.inspectCommandEditCheckpoint)(t,n))}catch(e){return J(e instanceof Error?e:String(e))}}async function Dr(t,n){if(!n)return q();try{return wr(await(0,e.restoreCommandEditCheckpoint)(t,n))}catch(e){return J(e instanceof Error?e:String(e))}}async function Or(t,n){if(!n)return q();try{return Tr(await(0,e.rollbackCommandEditCheckpoint)(t,n))}catch(e){return J(e instanceof Error?e:String(e))}}async function kr(t,n){let r=n.trim().split(/\s+/).filter(Boolean),i=r[0]??`list`;return i===`list`?xr((0,e.listCommandEditCheckpoints)(t)):i===`inspect`?Er(t,r[1]):i===`restore`||i===`code`?Dr(t,r[1]):i===`rollback`?Or(t,r[1]):q()}function Ar(){return{name:`rewind`,displayName:`Rewind History`,description:e.REWIND_COMMAND_DESCRIPTION,source:`rewind`,argumentHint:e.REWIND_COMMAND_ARGUMENT_HINT,modelInvocable:!1,safety:`write`,subcommands:(0,e.buildRewindCommandSubcommands)()}}function jr(){let e=Ar();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,argumentHint:e.argumentHint,userInvocable:!0,modelInvocable:!1,safety:`write`,subcommands:e.subcommands,execute:kr}}var Mr=class{name=`rewind`;getCommands(){return[Ar()]}};function Nr(){return{name:`agent-command-rewind`,commandSources:[new Mr],systemCommands:[jr()]}}const Pr={s:1e3,m:6e4,h:36e5,d:864e5},Y=`Usage: /schedule in <N><s|m|h|d> <instruction> | /schedule cron "<expr>" <instruction>`;function Fr(e,t){let n=e.trim();if(n.length===0)return{ok:!1,error:Y};if(n.startsWith(`in `)){let e=n.slice(3).trim(),r=e.indexOf(` `);if(r===-1)return{ok:!1,error:`Missing instruction. ${Y}`};let i=e.slice(0,r),a=e.slice(r+1).trim(),o=/^(\d+)(s|m|h|d)$/.exec(i);if(!o)return{ok:!1,error:`Invalid duration "${i}". ${Y}`};if(a.length===0)return{ok:!1,error:`Missing instruction. ${Y}`};let s=parseInt(o[1],10)*Pr[o[2]];return{ok:!0,spec:{cronExpression:new Date(t+s).toISOString(),instruction:a,recurring:!1}}}if(n.startsWith(`cron `)){let e=n.slice(5).trim(),t=/^["']([^"']+)["']\s+(.+)$/.exec(e);if(!t)return{ok:!1,error:`cron form needs a quoted expression. ${Y}`};let r=t[2].trim();return r.length===0?{ok:!1,error:`Missing instruction. ${Y}`}:{ok:!0,spec:{cronExpression:t[1].trim(),instruction:r,recurring:!0}}}return{ok:!1,error:Y}}function Ir(e,t){return`${e}: ${t.slice(0,48)}${t.length>48?`…`:``}`}async function Lr(e,t,n=Date.now()){let r=Fr(t,n);if(!r.ok)return{message:r.error,success:!1};let{cronExpression:i,instruction:a,recurring:o}=r.spec,s=await e.spawnScheduledWake({label:Ir(`Scheduled`,a),cronExpression:i,agentInstruction:a});return{message:`Scheduled wake (${o?`cron \`${i}\``:`once at ${i}`}): "${a}" — task ${s.id}.`,success:!0,data:{taskId:s.id,cronExpression:i,recurring:o}}}function Rr(e){let t=/^["']([^"']+)["']\s+["']([^"']+)["']\s+(.+)$/.exec(e.trim());if(!t)return null;let n=t[3].trim();return n.length===0?null:{command:t[1],matchPattern:t[2],instruction:n}}async function zr(e,t){let n=Rr(t);if(!n)return{message:`Usage: /monitor "<command>" "<pattern>" <instruction>`,success:!1};let r=await e.spawnMonitorWake({label:Ir(`Monitor`,n.instruction),command:n.command,matchPattern:n.matchPattern,agentInstruction:n.instruction});return{message:`Monitoring \`${n.command}\` for /${n.matchPattern}/ — task ${r.id}.`,success:!0,data:{taskId:r.id,matchPattern:n.matchPattern}}}function Br(e){let t=e.getAgentJobCapability?.();if(!t)throw Error(`Scheduling requires an active agent runtime.`);return t}function X(){return{name:`schedule`,displayName:`Schedule Wake`,description:`Schedule the agent to wake and run an instruction on a timer (one-shot or cron).`,source:`schedule`,argumentHint:`in <N><s|m|h|d> <instruction> | cron "<expr>" <instruction>`,modelInvocable:!0}}function Vr(){return{name:`monitor`,displayName:`Monitor Process`,description:`Watch a process’s output and wake the agent when a line matches a pattern.`,source:`schedule`,argumentHint:`"<command>" "<pattern>" <instruction>`,modelInvocable:!0}}function Hr(){let e=X();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!0,argumentHint:e.argumentHint,lifecycle:`inline`,execute:(e,t)=>Lr(Br(e),t)}}function Ur(){let e=Vr();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!0,argumentHint:e.argumentHint,lifecycle:`inline`,execute:(e,t)=>zr(Br(e),t)}}var Wr=class{name=`schedule`;getCommands(){return[X(),Vr()]}};function Gr(){return{name:`agent-command-schedule`,commandSources:[new Wr],systemCommands:[Hr(),Ur()],sessionRequirements:[`agent-runtime`]}}function Kr(e,n,r){return(0,t.calculateModelCost)(e,n,r)}function Z(e){return e<.01?`$${e.toFixed(4)}`:e<1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function qr(e){return e.toLocaleString(`en-US`)}const Jr=`Conversation cleared.`;async function Yr(n,r){let i=n.getUserInteraction?.();return i&&!(0,t.isConfirmed)(await i.ask((0,t.confirmAction)(`clear`,`Clear conversation history?`)))?{success:!0,message:`Clear cancelled.`}:((0,e.clearConversationHistory)(n),{success:!0,message:Jr,effects:[{type:`conversation-history-cleared`}]})}function Xr(t,n){let r=(0,e.parseSessionNameArgument)(n);return r===void 0?{success:!1,message:e.RENAME_COMMAND_USAGE}:{success:!0,message:`Session renamed to "${r}".`,data:{name:r},effects:[(0,e.createSessionRenamedEffect)(r)]}}function Zr(t,n){return{success:!0,message:`Opening session picker...`,data:{triggerResumePicker:!0},effects:[(0,e.createSessionPickerRequestedEffect)()]}}const Qr=`.robota/budget.json`;function $r(e){let t=(0,i.join)(e,Qr);if(!(0,n.existsSync)(t))return;let r;try{r=(0,n.readFileSync)(t,`utf-8`)}catch{return}try{return JSON.parse(r)}catch{return}}function ei(e,t){(0,n.mkdirSync)((0,i.join)(e,`.robota`),{recursive:!0}),(0,n.writeFileSync)((0,i.join)(e,Qr),JSON.stringify(t,null,2))}function ti(e){let t=(0,i.join)(e,Qr);(0,n.existsSync)(t)&&(0,n.writeFileSync)(t,`{}`)}function ni(t){let n=t.getSession(),r=(0,e.readCommandSessionInfo)(t),i=n.getSessionTokenUsage?.(),a=n.getModelId?.(),o=[`Session: ${r.sessionId}`,`Messages: ${r.messageCount}`],s={sessionId:r.sessionId,messageCount:r.messageCount};if(i){if(o.push(`Tokens: ${qr(i.inputTokens)} input / ${qr(i.outputTokens)} output`),s.inputTokens=i.inputTokens,s.outputTokens=i.outputTokens,a){let e=Kr(a,i.inputTokens,i.outputTokens);if(e!==void 0){o.push(`Cost: ${Z(e)} (${a})`),s.estimatedCostUsd=e;let n=$r(t.getCwd());if(n?.monthly){let t=n.monthly-e,r=Math.min(100,Math.round(e/n.monthly*100));o.push(`Budget: ${Z(t)} remaining of ${Z(n.monthly)}/mo (${r}% used)`),s.budgetMonthly=n.monthly,s.budgetRemainingUsd=t}}}}else o.push(`Tokens: not yet available (no turns completed)`);return{lines:o,data:s}}function ri(e,t){let n=t.trim();if(n.startsWith(`budget`)){let t=n.slice(6).trim();if(t===`clear`)return ti(e.getCwd()),{success:!0,message:`Monthly budget cleared.`};if(t===``){let t=$r(e.getCwd());return t?.monthly?{success:!0,message:`Monthly budget: ${Z(t.monthly)}`}:{success:!0,message:`No budget set. Use: /cost budget <amount>`}}let r=parseFloat(t);return!Number.isFinite(r)||r<=0?{success:!1,message:`Usage: /cost budget <amount> (e.g. /cost budget 5.00)`}:(ei(e.getCwd(),{monthly:r}),{success:!0,message:`Monthly budget set to ${Z(r)}.`})}let{lines:r,data:i}=ni(e);return{success:!0,message:r.join(`
63
+ `),data:i}}function ii(t,n){let r=(0,e.validateCommandSessionReplayLog)(t);return{success:r.validation.ok,message:(0,e.formatCommandSessionReplayValidationReport)(r),data:{logFile:r.logFile,entryCount:r.entryCount,issueCount:r.validation.issues.length,ok:r.validation.ok}}}function ai(){return{name:`clear`,displayName:`Clear History`,description:e.CLEAR_COMMAND_DESCRIPTION,source:`session`,modelInvocable:!1}}function oi(){return{name:`rename`,displayName:`Rename Session`,description:e.RENAME_COMMAND_DESCRIPTION,source:`session`,modelInvocable:!1}}function si(){return{name:`resume`,displayName:`Resume Session`,description:e.RESUME_COMMAND_DESCRIPTION,source:`session`,modelInvocable:!1}}function ci(){return{name:`cost`,displayName:`Session Cost`,description:e.COST_COMMAND_DESCRIPTION,source:`session`,modelInvocable:!1}}function li(){return{name:`validate-session`,displayName:`Validate Session`,description:e.VALIDATE_SESSION_COMMAND_DESCRIPTION,source:`session`,modelInvocable:!1}}function ui(){let e=ai();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,lifecycle:`inline`,execute:Yr}}function di(){let e=oi();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,lifecycle:`inline`,execute:Xr}}function fi(){let e=si();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,lifecycle:`inline`,execute:Zr}}function pi(){let e=ci();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,lifecycle:`inline`,execute:ri}}function mi(){let e=li();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,lifecycle:`inline`,execute:ii}}var hi=class{name=`session`;getCommands(){return[ai(),oi(),si(),ci(),li()]}};function gi(){return{name:`agent-command-session`,commandSources:[new hi],systemCommands:[ui(),di(),fi(),pi(),mi()]}}function _i(){return{name:`settings`,displayName:`Settings`,description:`Open transport settings — enable/disable transports and configure options`,source:`settings`,modelInvocable:!1}}function vi(){let e=_i();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,lifecycle:`inline`,execute:async()=>({success:!0,message:`Opening settings...`,effects:[{type:`settings-tui-requested`}]})}}var yi=class{name=`settings`;getCommands(){return[_i()]}};function bi(){return{name:`agent-command-settings`,commandSources:[new yi],systemCommands:[vi()]}}function xi(){let e=(0,t.resolvePlatformShell)();return{command:e.command,interactiveArgs:e.interactiveArgs,commandArgs:t=>e.commandArgs(t)}}const Si="Drop to an interactive shell (or run `/shell <command>` interactively), then return to the agent.";async function Ci(e,t){if(e.canHandoffTerminal?.()!==!0||e.runWithTerminal===void 0)return{message:`An interactive shell is unavailable here (no interactive terminal).`,success:!1};let n=xi(),r=e.getCwd(),i=t.trim(),a=await e.runWithTerminal(async()=>i.length>0?E(n.command,n.commandArgs(i),r):E(n.command,n.interactiveArgs,r));return{message:i.length>0?`Command exited (code ${a}).`:`Shell session ended (code ${a}).`,success:a===0,data:{exitCode:a}}}function wi(){return{name:`shell`,displayName:`Shell`,description:Si,source:`shell`,modelInvocable:!1}}function Ti(){let e=wi();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!0,userInvocable:!0,modelInvocable:!1,lifecycle:`inline`,execute:Ci}}var Ei=class{name=`shell`;getCommands(){return[wi()]}};function Di(){return{name:`agent-command-shell`,commandSources:[new Ei],systemCommands:[Ti()]}}const Oi=`Skill command. Before following a matching registered skill from the system prompt Skills section, invoke the projected skills command tool with args "<skill-name> [args]". Without arguments, list registered skills. With a skill name, activate that skill. Slash syntax is a UI input/display concern; the SDK command identity is "skills".`;function ki(e){let t=[];return e.modelInvocable||t.push(`model-disabled`),e.userInvocable||t.push(`model-only`),e.context&&t.push(`context:${e.context}`),e.agent&&t.push(`agent:${e.agent}`),t.length>0?` [${t.join(`, `)}]`:``}function Ai(e){let t=e.argumentHint?` ${e.argumentHint}`:``;return`- ${e.name}${t}: ${e.description}${ki(e)}`}function ji(e){return e.length===0?[`No skills are registered for this session.`,``,`Skills are metadata until activated. Do not invent or imitate a skill workflow when no matching registered skill exists.`].join(`
64
+ `):[`Registered skills:`,...e.map(Ai),``,`Activation contract:`,`- Use /skills <skill-name> [args] to activate a matching skill.`,`- Treat /<skill-name> as a virtual alias for /skills <skill-name>.`,`- The system prompt Skills section is skill selection metadata.`,`- Treat descriptions as selection metadata only, not as loaded SKILL.md content.`,`- Do not answer by merely naming, recommending, or imitating a matching skill.`,`- If no listed skill matches the task, continue without claiming a skill was activated.`].join(`
65
+ `)}function Mi(e){let t=e.trim();if(t.length===0||t===`list`)return{action:`list`,skillArgs:``};let[n=``,...r]=t.split(/\s+/);return n.length===0?{action:`list`,skillArgs:``}:{action:`activate`,skillName:n,skillArgs:r.join(` `)}}async function Ni(e,t=``){let n=Mi(t);if(n.action===`activate`&&n.skillName!==void 0){if(!e.executeSkillCommandByName)return{success:!1,message:`Skill activation is not available in this session.`};let t=`/${n.skillName}${n.skillArgs?` ${n.skillArgs}`:``}`;return await e.executeSkillCommandByName(n.skillName,n.skillArgs,{invocationSource:e.getCommandInvocationSource?.()??`user`,displayInput:t,rawInput:t})??{success:!1,message:`Unknown skill: ${n.skillName}`}}let r=e.listSkills?.()??[];return{success:!0,message:ji(r),data:{skills:r,activationContract:{activateWith:`/skills <skill-name> [args]`,activationRequiredBeforeWorkflow:!0,metadataIsNotSkillContent:!0}}}}function Pi(){return{name:`skills`,displayName:`Skills`,description:Oi,source:`skills`,modelInvocable:!0,userInvocable:!0,argumentHint:`[list | <skill-name> [args]]`,safety:`read-only`}}function Fi(){let e=Pi();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!0,argumentHint:e.argumentHint,safety:e.safety,lifecycle:`inline`,execute:Ni}}var Ii=class{name=`skills`;getCommands(){return[Pi()]}};function Li(t){let n=[new Ii];return n.push(new e.SkillCommandSource(t.cwd)),{name:`agent-command-skills`,commandSources:n,systemCommands:[Fi()]}}const Ri=[`Usage: /statusline on | off | reset | git on | git off`,`Fields: model, context, permission mode, message count, session name, thinking state, git branch.`].join(`
66
+ `);function zi(t){let n=t.trim().toLowerCase().split(/\s+/).filter(e=>e.length>0),[r,i]=n;return r===`on`&&i===void 0?{success:!0,message:`Status line enabled.`,patch:{enabled:!0}}:r===`off`&&i===void 0?{success:!0,message:`Status line disabled.`,patch:{enabled:!1}}:r===`reset`&&i===void 0?{success:!0,message:`Status line settings reset.`,patch:{...e.DEFAULT_STATUS_LINE_COMMAND_SETTINGS}}:r===`git`&&i===`on`&&n.length===2?{success:!0,message:`Status line git branch shown.`,patch:{gitBranch:!0}}:r===`git`&&i===`off`&&n.length===2?{success:!0,message:`Status line git branch hidden.`,patch:{gitBranch:!1}}:{success:!1,message:Ri}}function Bi(e,t){let n=zi(t);return n.success?{success:!0,message:n.message,effects:[{type:`statusline-settings-patch`,patch:n.patch}]}:{success:!1,message:n.message}}function Vi(){return{name:`statusline`,displayName:`Status Line`,description:e.STATUSLINE_COMMAND_DESCRIPTION,source:`statusline`,argumentHint:e.STATUSLINE_COMMAND_ARGUMENT_HINT,subcommands:(0,e.buildStatusLineCommandSubcommands)(`statusline`),modelInvocable:!1}}function Hi(){let e=Vi();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,argumentHint:e.argumentHint,subcommands:e.subcommands,lifecycle:`inline`,execute:Bi}}var Ui=class{name=`statusline`;getCommands(){return[Vi()]}};function Wi(){return{name:`agent-command-statusline`,commandSources:[new Ui],systemCommands:[Hi()]}}const Gi=`Inspect Robota user-local storage and memory state.`,Ki=`storage list [--format json] | memory set/list/inspect/disable/delete`,Q=`Usage: user-local storage list [--format json] | user-local memory set <category> <key> <value> --summary <summary> --source <source> | user-local memory list [--format json] | user-local memory inspect <category> <key> [--format json] | user-local memory disable <category> <key> | user-local memory delete <category> <key>`;function qi(e){return e.length===0?`No user-local memory items.`:e.map(e=>`- ${e.category}/${e.key} (${e.enabled?`enabled`:`disabled`})`).join(`
67
+ `)}function $(e){if(e===void 0)throw Error(`User-local memory category is required.`);return e}async function Ji(t,n){let r=await(0,e.listUserLocalMemoryItems)({activeRepositoryRoot:t});return{message:n.format===`json`?JSON.stringify(r,null,2):qi(r.items),success:!0,data:{list:r}}}async function Yi(t,n){let[r,i,a]=n.positional,o=await(0,e.setUserLocalMemoryItem)({activeRepositoryRoot:t,category:$(r),key:i??``,value:a??``,summary:n.summary??``,source:n.source??``});return{message:`Stored user-local memory item ${o.category}/${o.key} at ${o.storageLocation}`,success:!0,data:{item:o}}}async function Xi(t,n){let[r,i]=n.positional,a=await(0,e.inspectUserLocalMemoryItem)({activeRepositoryRoot:t,category:$(r),key:i??``});return{message:n.format===`json`?JSON.stringify(a,null,2):`${a.category}/${a.key}: ${a.summary}`,success:!0,data:{item:a}}}async function Zi(t,n){let[r,i]=n.positional,a=await(0,e.disableUserLocalMemoryItem)({activeRepositoryRoot:t,category:$(r),key:i??``});return{message:`Disabled user-local memory item ${a.category}/${a.key}`,success:!0,data:{item:a}}}async function Qi(t,n){let[r,i]=n.positional,a=await(0,e.deleteUserLocalMemoryItem)({activeRepositoryRoot:t,category:$(r),key:i??``});return{message:`Deleted user-local memory item ${a.category}/${a.key}`,success:!0,data:{result:a}}}async function $i(e,t){return(t.action??`list`)===`list`?Ji(e,t):t.action===`set`?Yi(e,t):t.action===`inspect`?Xi(e,t):t.action===`disable`?Zi(e,t):t.action===`delete`?Qi(e,t):{message:Q,success:!1}}function ea(e){if(e===void 0||e===`text`)return`text`;if(e===`json`)return`json`;throw Error(`Unsupported user-local output format: ${e}`)}function ta(e,t,n){return e===`--format`?{format:t[n+1],nextIndex:n+1}:e.startsWith(`--format=`)?{format:e.slice(9),nextIndex:n}:e===`--summary`?{summary:t[n+1],nextIndex:n+1}:e.startsWith(`--summary=`)?{summary:e.slice(10),nextIndex:n}:e===`--source`?{source:t[n+1],nextIndex:n+1}:e.startsWith(`--source=`)?{source:e.slice(9),nextIndex:n}:null}function na(e,t={}){let n=t.format,r=t.summary,i=t.source,a=[];for(let t=0;t<e.length;t+=1){let o=e[t],s=ta(o,e,t);if(s!==null){n=s.format??n,r=s.summary??r,i=s.source??i,t=s.nextIndex;continue}a.push(o)}return{target:a[0],action:a[1],positional:a.slice(2),format:ea(n),summary:r,source:i}}function ra(e){return e.trim().split(/\s+/).filter(Boolean)}function ia(e,t){let n=t.map(e=>`- ${e.category}`);return[`User-local storage root: ${e}`,`Categories:`,...n].join(`
68
+ `)}async function aa(t,n){if((n.action??`list`)!==`list`)return{message:Q,success:!1};let r=await(0,e.inspectUserLocalStorage)({activeRepositoryRoot:t});return{message:n.format===`json`?JSON.stringify(r,null,2):ia(r.root,r.categories),success:!0,data:{root:r.root,categories:r.categories,inspection:r}}}async function oa(e,t){return t.target===`storage`?aa(e,t):t.target===`memory`?$i(e,t):{message:Q,success:!1}}function sa(e){return e.includes(`ENOENT`)?`User-local memory item not found.`:e}async function ca(e){try{return await oa(e.cwd,na(e.argv,{format:e.format,summary:e.summary,source:e.source}))}catch(e){return{message:sa(e instanceof Error?e.message:String(e)),success:!1}}}async function la(e,t){try{return await oa(e.getCwd(),na(ra(t)))}catch(e){return{message:sa(e instanceof Error?e.message:String(e)),success:!1}}}function ua(){return{name:`user-local`,displayName:`User Config`,description:Gi,source:`user-local`,argumentHint:Ki,modelInvocable:!1,safety:`read-only`,subcommands:[{name:`storage`,description:`Inspect user-local storage categories`,source:`user-local`},{name:`memory`,description:`Inspect and manage user-local memory items`,source:`user-local`}]}}function da(){let e=ua();return{name:e.name,displayName:e.displayName,description:e.description,requiresPermission:!1,userInvocable:!0,modelInvocable:!1,argumentHint:e.argumentHint,safety:e.safety,subcommands:e.subcommands,execute:la}}var fa=class{name=`user-local`;getCommands(){return[ua()]}};function pa(){return{name:`agent-command-user-local`,commandSources:[new fa],systemCommands:[da()]}}function ma(e,t,n){let r=e;if(t!==void 0){let e=new Set(t);r=r.filter(t=>e.has(t.name))}if(n!==void 0){let e=new Set(n);r=r.filter(t=>!e.has(t.name))}return r}function ha({cwd:e,providerDefinitions:t,providerSettingsAdapter:n,enabledCommandModules:r,disabledCommandModules:i}){return ma([Li({cwd:e}),ht(),be(),Vt(),Lt(),fn(),bt(),Te(),dt(),Di(),$e(),Mt(),pa(),Ae(),qe(),it(),gi(),yr(),Nr(),Gr(),Wi(),tn(),bi(),lr({providerDefinitions:t,settings:n})],r,i)}function ga(t){let n=(0,r.homedir)(),o=(0,i.join)(n,`.robota`,`plugins`),s=(0,i.join)(n,`.robota`,`settings.json`),c=(e,t)=>(0,a.execSync)(e,{timeout:t.timeout,stdio:t.stdio??`pipe`}),l=new e.PluginSettingsStore(s),u=new e.MarketplaceClient({pluginsDir:o,exec:c});return{cwd:t,marketplace:u,installer:new e.BundlePluginInstaller({pluginsDir:o,settingsStore:l,marketplaceClient:u,exec:c}),loader:new e.BundlePluginLoader(o),settingsStore:l}}async function _a(e){let t=await e.loader.loadAll(),n=e.settingsStore.getEnabledPlugins();return t.map(e=>{let t=e.pluginDir.split(`/`),r=t.indexOf(`cache`),i=r>=0?t[r+1]??``:``,a=i?`${e.manifest.name}@${i}`:e.manifest.name;return{name:a,description:e.manifest.description,enabled:n[a]!==!1&&n[e.manifest.name]!==!1}})}async function va(e,t){let n;try{n=e.marketplace.fetchManifest(t)}catch{return[]}let r=e.installer.getInstalledPlugins(),i=new Set(Object.values(r).map(e=>e.pluginName));return n.plugins.map(e=>({name:e.name,description:e.description,installed:i.has(e.name)}))}async function ya(t,n,r){let[o,s]=n.split(`@`);if(!o||!s)throw Error(`Plugin ID must be in format: name@marketplace`);if(r===`project`){let n=(0,i.join)(t.cwd,`.robota`,`plugins`);await new e.BundlePluginInstaller({pluginsDir:n,settingsStore:t.settingsStore,marketplaceClient:t.marketplace,exec:(e,t)=>(0,a.execSync)(e,{timeout:t.timeout,stdio:t.stdio??`pipe`})}).install(o,s);return}await t.installer.install(o,s)}async function ba(e,t){let n=e.installer.getPluginsByMarketplace(t);for(let t of n)await e.installer.uninstall(`${t.pluginName}@${t.marketplace}`);e.marketplace.removeMarketplace(t)}function xa(e){return e.marketplace.listMarketplaces().map(e=>({name:e.name,type:e.source.type}))}function Sa(e){let t=ga(e);return{listInstalled:()=>_a(t),listAvailablePlugins:e=>va(t,e),install:(e,n)=>ya(t,e,n),uninstall:async e=>t.installer.uninstall(e),enable:async e=>t.installer.enable(e),disable:async e=>t.installer.disable(e),marketplaceAdd:async e=>e.includes(`/`)&&!e.includes(`:`)?t.marketplace.addMarketplace({type:`github`,repo:e}):t.marketplace.addMarketplace({type:`git`,url:e}),marketplaceRemove:e=>ba(t,e),marketplaceUpdate:async e=>t.marketplace.updateMarketplace(e),marketplaceList:async()=>xa(t),reloadPlugins:async()=>({loadedPluginCount:(await t.loader.loadAll()).length})}}const Ca=`plugin`;function wa(){return process.env.HOME??(0,r.homedir)()}function Ta(t){let n=new e.BundlePluginLoader((0,i.join)(wa(),`.robota`,`plugins`));try{let r=n.loadPluginsSync();return r.length===0?(t.replaceSource(Ca),0):(t.replaceSource(Ca,new e.PluginCommandSource(r)),r.length)}catch{return t.replaceSource(Ca),0}}exports.AgentCommandSource=ye,exports.BackgroundCommandSource=we,exports.CLEAR_COMMAND_MESSAGE=Jr,exports.CompactCommandSource=ke,exports.ContextCommandSource=Ke,exports.EDITOR_COMMAND_DESCRIPTION=Ye,exports.EditorCommandSource=Qe,exports.ExitCommandSource=rt,exports.GOAL_COMMAND_DESCRIPTION=at,exports.GoalCommandSource=ut,exports.HelpCommandSource=mt,exports.LanguageCommandSource=yt,exports.MemoryCommandSource=jt,exports.ModeCommandSource=It,exports.PermissionsCommandSource=Bt,exports.PluginManagerCommandSource=en,exports.PresetCommandSource=dn,exports.ProviderCommandSource=sr,exports.RewindCommandSource=Mr,exports.SHELL_COMMAND_DESCRIPTION=Si,exports.SKILLS_COMMAND_DESCRIPTION=Oi,exports.STATUSLINE_USAGE=Ri,exports.ScheduleCommandSource=Wr,exports.SessionCommandSource=hi,exports.SettingsCommandSource=yi,exports.ShellCommandSource=Ei,exports.SkillsCommandSource=Ii,exports.StatusLineCommandSource=Ui,exports.USER_LOCAL_COMMAND_ARGUMENT_HINT=Ki,exports.USER_LOCAL_COMMAND_DESCRIPTION=Gi,exports.USER_LOCAL_COMMAND_USAGE=Q,exports.UserLocalCommandSource=fa,exports.createAgentCommandEntry=h,exports.createAgentCommandModule=be,exports.createAgentSystemCommand=ve,exports.createBackgroundCommandEntry=g,exports.createBackgroundCommandModule=Te,exports.createClearCommandEntry=ai,exports.createCompactCommandEntry=_,exports.createCompactCommandModule=Ae,exports.createContextCommandEntry=T,exports.createContextCommandModule=qe,exports.createCostCommandEntry=ci,exports.createDefaultCommandModules=ha,exports.createDefaultPluginCommandAdapter=Sa,exports.createEditorCommandEntry=D,exports.createEditorCommandModule=$e,exports.createExitCommandEntry=tt,exports.createExitCommandModule=it,exports.createGoalCommandEntry=ct,exports.createGoalCommandModule=dt,exports.createHelpCommandEntry=O,exports.createHelpCommandModule=ht,exports.createLanguageCommandEntry=k,exports.createLanguageCommandModule=bt,exports.createMemoryCommandEntry=M,exports.createMemoryCommandModule=Mt,exports.createModeCommandEntry=N,exports.createModeCommandModule=Lt,exports.createMonitorCommandEntry=Vr,exports.createPermissionsCommandEntry=P,exports.createPermissionsCommandModule=Vt,exports.createPluginCommandEntry=R,exports.createPluginCommandModule=tn,exports.createPresetCommandEntry=B,exports.createPresetCommandModule=fn,exports.createProviderCommandEntry=K,exports.createProviderCommandModule=lr,exports.createProviderSetupFlow=V,exports.createReloadPluginsCommandEntry=z,exports.createRenameCommandEntry=oi,exports.createResetCommandEntry=gr,exports.createResetCommandModule=yr,exports.createResumeCommandEntry=si,exports.createRewindCommandModule=Nr,exports.createScheduleCommandEntry=X,exports.createScheduleCommandModule=Gr,exports.createSessionCommandModule=gi,exports.createSettingsCommandEntry=_i,exports.createSettingsCommandModule=bi,exports.createShellCommandEntry=wi,exports.createShellCommandModule=Di,exports.createSkillsCommandEntry=Pi,exports.createSkillsCommandModule=Li,exports.createStatusLineCommandEntry=Vi,exports.createStatusLineCommandModule=Wi,exports.createUserLocalCommandEntry=ua,exports.createUserLocalCommandModule=pa,exports.createValidateSessionCommandEntry=li,exports.ensureProviderConfig=fr,exports.executeAgentCommand=me,exports.executeBackgroundCommand=Se,exports.executeClearCommand=Yr,exports.executeCompactCommand=De,exports.executeContextCommand=Me,exports.executeCostCommand=ri,exports.executeEditorCommand=Xe,exports.executeExitCommand=et,exports.executeGoalCommand=st,exports.executeHelpCommand=ft,exports.executeLanguageCommand=_t,exports.executeMemoryCommand=kt,exports.executeModeCommand=Pt,exports.executeMonitorCommand=zr,exports.executePermissionsCommand=Rt,exports.executePluginCommand=Xt,exports.executePresetCommand=cn,exports.executeProviderCommand=er,exports.executeReloadPluginsCommand=Zt,exports.executeRenameCommand=Xr,exports.executeResetCommand=hr,exports.executeResumeCommand=Zr,exports.executeRewindCommand=kr,exports.executeScheduleCommand=Lr,exports.executeShellCommand=Ci,exports.executeSkillsCommand=Ni,exports.executeStatusLineCommand=Bi,exports.executeUserLocalCommand=la,exports.executeUserLocalDirectCommand=ca,exports.executeValidateSessionCommand=ii,exports.formatProviderSetupChoiceLabel=W,exports.formatProviderSetupHelpLinks=G,exports.formatProviderSetupPromptLabel=gn,exports.formatProviderSetupSelectionPrompt=pn,exports.getProviderSetupStep=H,exports.parseScheduleSpec=Fr,exports.reloadPluginCommandSource=Ta,exports.resolveEditor=Je,exports.resolveProviderSetupSelection=mn,exports.resolveShell=xi,exports.runProviderSetupPromptFlow=hn,exports.runProviderStartupSetup=dr,exports.spawnInherited=E,exports.submitProviderSetupValue=U,exports.validateProviderSetupValue=yn;