@agimon-ai/doompi-workflow 0.0.1-alpha.32 → 0.0.1-alpha.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -65,7 +65,8 @@ Core tools are:
65
65
  Launch returns after the run is registered, not after all jobs complete. Use status and follow
66
66
  controls for progress, and wait for a terminal notification.
67
67
 
68
- In the TUI, `SPC w w` launches, `SPC w l` manages runs, `SPC w r` opens recovery, and `SPC w e`
68
+ In the TUI, `SPC w w` launches, `SPC w l` lists the repository's workflows, `SPC w r` inspects this
69
+ session's runs, `SPC w c` opens recovery, and `SPC w e`
69
70
  toggles model-visible tools. The root session can launch; child sessions can inspect the catalog but
70
71
  do not receive an unrestricted workflow factory.
71
72
 
@@ -1,2 +1,2 @@
1
- const e=require("../../types/index.cjs"),t=`doom-workflow`,n={key:`w`,label:e.LEADER_LABEL,order:50};function r(r){return[{id:`${t}.manage`,path:[n,{key:`l`,label:`manage`,detail:`running workflows`}],action:{name:e.LEADER_MANAGE_ACTION}},{id:`${t}.launch`,path:[n,{key:`w`,label:`launch`,detail:`start a workflow`}],action:{name:e.LEADER_LAUNCH_ACTION}},r?{id:`${t}.disable`,path:[n,{key:`e`,label:`exit`,detail:`take back workflow tools`}],action:{name:e.LEADER_DISABLE_ACTION}}:{id:`${t}.enable`,path:[n,{key:`e`,label:`enter`,detail:`give the agent workflow tools`}],action:{name:e.LEADER_ENABLE_ACTION}},{id:`${t}.recover`,path:[n,{key:`r`,label:`recover`,detail:`failed workflow`}],action:{name:e.LEADER_RECOVER_ACTION}}]}function i(t,n=!1){let i=t.registerLeader({source:e.PACKAGE_SOURCE,bindings:r(n)});return{setMode(e){i.update(r(e))},dispose(){i.dispose()}}}exports.registerLeaderContribution=i,exports.workflowLeaderBindings=r;
1
+ const e=require("../../types/index.cjs"),t=`doom-workflow`,n={key:`w`,label:e.LEADER_LABEL,detail:e.LEADER_DETAIL,order:50};function r(r){return[{id:`${t}.catalog`,path:[n,{key:`l`,label:`list`,detail:`workflows in this repo`}],action:{name:e.LEADER_CATALOG_ACTION}},{id:`${t}.manage`,path:[n,{key:`r`,label:`runs`,detail:`runs in this session`}],action:{name:e.LEADER_MANAGE_ACTION}},{id:`${t}.launch`,path:[n,{key:`w`,label:`launch`,detail:`start a workflow`}],action:{name:e.LEADER_LAUNCH_ACTION}},r?{id:`${t}.disable`,path:[n,{key:`e`,label:`exit`,detail:`take back workflow tools`,tone:`exit`}],action:{name:e.LEADER_DISABLE_ACTION}}:{id:`${t}.enable`,path:[n,{key:`e`,label:`enter`,detail:`give the agent workflow tools`}],action:{name:e.LEADER_ENABLE_ACTION}},{id:`${t}.recover`,path:[n,{key:`c`,label:`recover`,detail:`adopt a failed run`}],action:{name:e.LEADER_RECOVER_ACTION}}]}function i(t,n=!1){let i=t.registerLeader({source:e.PACKAGE_SOURCE,bindings:r(n)});return{setMode(e){i.update(r(e))},dispose(){i.dispose()}}}exports.registerLeaderContribution=i,exports.workflowLeaderBindings=r;
2
2
  //# sourceMappingURL=leader.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"leader.cjs","names":["LEADER_LABEL","LEADER_MANAGE_ACTION","LEADER_LAUNCH_ACTION","LEADER_DISABLE_ACTION","LEADER_ENABLE_ACTION","LEADER_RECOVER_ACTION","PACKAGE_SOURCE"],"sources":["../../../src/adapters/pi/leader.ts"],"sourcesContent":["import type { LeaderBinding } from '@agimon-ai/doompi-extension-contracts/leader';\nimport type { DoomUiHubService } from '@agimon-ai/doompi-extension-contracts/ui-hub';\nimport {\n LEADER_DISABLE_ACTION,\n LEADER_ENABLE_ACTION,\n LEADER_KEY,\n LEADER_LABEL,\n LEADER_LAUNCH_ACTION,\n LEADER_MANAGE_ACTION,\n LEADER_ORDER,\n LEADER_RECOVER_ACTION,\n PACKAGE_SOURCE,\n} from '../../types/index.ts';\n\nconst LEADER_BINDING_PREFIX = 'doom-workflow';\nconst GROUP_SEGMENT = { key: LEADER_KEY, label: LEADER_LABEL, order: LEADER_ORDER } as const;\n\nexport interface WorkflowLeaderHandle {\n /** Republish the menu for the mode's current state. */\n setMode(enabled: boolean): void;\n dispose(): void;\n}\n\n/**\n * The menu as it stands with the mode on or off.\n *\n * One entry on `e` rather than an enable row beside a disable row: only one of\n * the two ever does anything, and a menu that prints both makes the reader\n * check the mode line to find out which. The label says which way it flips.\n */\nexport function workflowLeaderBindings(mode: boolean): LeaderBinding[] {\n return [\n {\n id: `${LEADER_BINDING_PREFIX}.manage`,\n path: [GROUP_SEGMENT, { key: 'l', label: 'manage', detail: 'running workflows' }],\n action: { name: LEADER_MANAGE_ACTION },\n },\n {\n id: `${LEADER_BINDING_PREFIX}.launch`,\n path: [GROUP_SEGMENT, { key: 'w', label: 'launch', detail: 'start a workflow' }],\n action: { name: LEADER_LAUNCH_ACTION },\n },\n mode\n ? {\n id: `${LEADER_BINDING_PREFIX}.disable`,\n path: [GROUP_SEGMENT, { key: 'e', label: 'exit', detail: 'take back workflow tools' }],\n action: { name: LEADER_DISABLE_ACTION },\n }\n : {\n id: `${LEADER_BINDING_PREFIX}.enable`,\n path: [GROUP_SEGMENT, { key: 'e', label: 'enter', detail: 'give the agent workflow tools' }],\n action: { name: LEADER_ENABLE_ACTION },\n },\n {\n id: `${LEADER_BINDING_PREFIX}.recover`,\n path: [GROUP_SEGMENT, { key: 'r', label: 'recover', detail: 'failed workflow' }],\n action: { name: LEADER_RECOVER_ACTION },\n },\n ];\n}\n\nexport function registerLeaderContribution(hub: DoomUiHubService, enabled = false): WorkflowLeaderHandle {\n const contribution = hub.registerLeader({\n source: PACKAGE_SOURCE,\n bindings: workflowLeaderBindings(enabled),\n });\n return {\n setMode(enabled) {\n contribution.update(workflowLeaderBindings(enabled));\n },\n dispose() {\n contribution.dispose();\n },\n };\n}\n"],"mappings":"yCAcM,EAAwB,gBACxB,EAAgB,CAAE,IAAA,IAAiB,MAAOA,EAAAA,aAAc,MAAA,EAAoB,EAelF,SAAgB,EAAuB,EAAgC,CACrE,MAAO,CACL,CACE,GAAI,GAAG,EAAsB,SAC7B,KAAM,CAAC,EAAe,CAAE,IAAK,IAAK,MAAO,SAAU,OAAQ,mBAAoB,CAAC,EAChF,OAAQ,CAAE,KAAMC,EAAAA,oBAAqB,CACvC,EACA,CACE,GAAI,GAAG,EAAsB,SAC7B,KAAM,CAAC,EAAe,CAAE,IAAK,IAAK,MAAO,SAAU,OAAQ,kBAAmB,CAAC,EAC/E,OAAQ,CAAE,KAAMC,EAAAA,oBAAqB,CACvC,EACA,EACI,CACE,GAAI,GAAG,EAAsB,UAC7B,KAAM,CAAC,EAAe,CAAE,IAAK,IAAK,MAAO,OAAQ,OAAQ,0BAA2B,CAAC,EACrF,OAAQ,CAAE,KAAMC,EAAAA,qBAAsB,CACxC,EACA,CACE,GAAI,GAAG,EAAsB,SAC7B,KAAM,CAAC,EAAe,CAAE,IAAK,IAAK,MAAO,QAAS,OAAQ,+BAAgC,CAAC,EAC3F,OAAQ,CAAE,KAAMC,EAAAA,oBAAqB,CACvC,EACJ,CACE,GAAI,GAAG,EAAsB,UAC7B,KAAM,CAAC,EAAe,CAAE,IAAK,IAAK,MAAO,UAAW,OAAQ,iBAAkB,CAAC,EAC/E,OAAQ,CAAE,KAAMC,EAAAA,qBAAsB,CACxC,CACF,CACF,CAEA,SAAgB,EAA2B,EAAuB,EAAU,GAA6B,CACvG,IAAM,EAAe,EAAI,eAAe,CACtC,OAAQC,EAAAA,eACR,SAAU,EAAuB,CAAO,CAC1C,CAAC,EACD,MAAO,CACL,QAAQ,EAAS,CACf,EAAa,OAAO,EAAuB,CAAO,CAAC,CACrD,EACA,SAAU,CACR,EAAa,QAAQ,CACvB,CACF,CACF"}
1
+ {"version":3,"file":"leader.cjs","names":["LEADER_LABEL","LEADER_DETAIL","LEADER_CATALOG_ACTION","LEADER_MANAGE_ACTION","LEADER_LAUNCH_ACTION","LEADER_DISABLE_ACTION","LEADER_ENABLE_ACTION","LEADER_RECOVER_ACTION","PACKAGE_SOURCE"],"sources":["../../../src/adapters/pi/leader.ts"],"sourcesContent":["import type { LeaderBinding } from '@agimon-ai/doompi-extension-contracts/leader';\nimport type { DoomUiHubService } from '@agimon-ai/doompi-extension-contracts/ui-hub';\nimport {\n LEADER_CATALOG_ACTION,\n LEADER_DETAIL,\n LEADER_DISABLE_ACTION,\n LEADER_ENABLE_ACTION,\n LEADER_KEY,\n LEADER_LABEL,\n LEADER_LAUNCH_ACTION,\n LEADER_MANAGE_ACTION,\n LEADER_ORDER,\n LEADER_RECOVER_ACTION,\n PACKAGE_SOURCE,\n} from '../../types/index.ts';\n\nconst LEADER_BINDING_PREFIX = 'doom-workflow';\nconst GROUP_SEGMENT = {\n key: LEADER_KEY,\n label: LEADER_LABEL,\n detail: LEADER_DETAIL,\n order: LEADER_ORDER,\n} as const;\n\nexport interface WorkflowLeaderHandle {\n /** Republish the menu for the mode's current state. */\n setMode(enabled: boolean): void;\n dispose(): void;\n}\n\n/**\n * The menu as it stands with the mode on or off.\n *\n * One entry on `e` rather than an enable row beside a disable row: only one of\n * the two ever does anything, and a menu that prints both makes the reader\n * check the mode line to find out which. The label says which way it flips.\n */\nexport function workflowLeaderBindings(mode: boolean): LeaderBinding[] {\n return [\n {\n id: `${LEADER_BINDING_PREFIX}.catalog`,\n path: [GROUP_SEGMENT, { key: 'l', label: 'list', detail: 'workflows in this repo' }],\n action: { name: LEADER_CATALOG_ACTION },\n },\n {\n id: `${LEADER_BINDING_PREFIX}.manage`,\n path: [GROUP_SEGMENT, { key: 'r', label: 'runs', detail: 'runs in this session' }],\n action: { name: LEADER_MANAGE_ACTION },\n },\n {\n id: `${LEADER_BINDING_PREFIX}.launch`,\n path: [GROUP_SEGMENT, { key: 'w', label: 'launch', detail: 'start a workflow' }],\n action: { name: LEADER_LAUNCH_ACTION },\n },\n mode\n ? {\n id: `${LEADER_BINDING_PREFIX}.disable`,\n path: [GROUP_SEGMENT, { key: 'e', label: 'exit', detail: 'take back workflow tools', tone: 'exit' }],\n action: { name: LEADER_DISABLE_ACTION },\n }\n : {\n id: `${LEADER_BINDING_PREFIX}.enable`,\n path: [GROUP_SEGMENT, { key: 'e', label: 'enter', detail: 'give the agent workflow tools' }],\n action: { name: LEADER_ENABLE_ACTION },\n },\n // `r` is runs everywhere, so recovery moves off it rather than reading as a\n // third flavour of list in the one space that has both.\n {\n id: `${LEADER_BINDING_PREFIX}.recover`,\n path: [GROUP_SEGMENT, { key: 'c', label: 'recover', detail: 'adopt a failed run' }],\n action: { name: LEADER_RECOVER_ACTION },\n },\n ];\n}\n\nexport function registerLeaderContribution(hub: DoomUiHubService, enabled = false): WorkflowLeaderHandle {\n const contribution = hub.registerLeader({\n source: PACKAGE_SOURCE,\n bindings: workflowLeaderBindings(enabled),\n });\n return {\n setMode(enabled) {\n contribution.update(workflowLeaderBindings(enabled));\n },\n dispose() {\n contribution.dispose();\n },\n };\n}\n"],"mappings":"yCAgBM,EAAwB,gBACxB,EAAgB,CACpB,IAAA,IACA,MAAOA,EAAAA,aACP,OAAQC,EAAAA,cACR,MAAA,EACF,EAeA,SAAgB,EAAuB,EAAgC,CACrE,MAAO,CACL,CACE,GAAI,GAAG,EAAsB,UAC7B,KAAM,CAAC,EAAe,CAAE,IAAK,IAAK,MAAO,OAAQ,OAAQ,wBAAyB,CAAC,EACnF,OAAQ,CAAE,KAAMC,EAAAA,qBAAsB,CACxC,EACA,CACE,GAAI,GAAG,EAAsB,SAC7B,KAAM,CAAC,EAAe,CAAE,IAAK,IAAK,MAAO,OAAQ,OAAQ,sBAAuB,CAAC,EACjF,OAAQ,CAAE,KAAMC,EAAAA,oBAAqB,CACvC,EACA,CACE,GAAI,GAAG,EAAsB,SAC7B,KAAM,CAAC,EAAe,CAAE,IAAK,IAAK,MAAO,SAAU,OAAQ,kBAAmB,CAAC,EAC/E,OAAQ,CAAE,KAAMC,EAAAA,oBAAqB,CACvC,EACA,EACI,CACE,GAAI,GAAG,EAAsB,UAC7B,KAAM,CAAC,EAAe,CAAE,IAAK,IAAK,MAAO,OAAQ,OAAQ,2BAA4B,KAAM,MAAO,CAAC,EACnG,OAAQ,CAAE,KAAMC,EAAAA,qBAAsB,CACxC,EACA,CACE,GAAI,GAAG,EAAsB,SAC7B,KAAM,CAAC,EAAe,CAAE,IAAK,IAAK,MAAO,QAAS,OAAQ,+BAAgC,CAAC,EAC3F,OAAQ,CAAE,KAAMC,EAAAA,oBAAqB,CACvC,EAGJ,CACE,GAAI,GAAG,EAAsB,UAC7B,KAAM,CAAC,EAAe,CAAE,IAAK,IAAK,MAAO,UAAW,OAAQ,oBAAqB,CAAC,EAClF,OAAQ,CAAE,KAAMC,EAAAA,qBAAsB,CACxC,CACF,CACF,CAEA,SAAgB,EAA2B,EAAuB,EAAU,GAA6B,CACvG,IAAM,EAAe,EAAI,eAAe,CACtC,OAAQC,EAAAA,eACR,SAAU,EAAuB,CAAO,CAC1C,CAAC,EACD,MAAO,CACL,QAAQ,EAAS,CACf,EAAa,OAAO,EAAuB,CAAO,CAAC,CACrD,EACA,SAAU,CACR,EAAa,QAAQ,CACvB,CACF,CACF"}
@@ -1,2 +1,2 @@
1
- import{LEADER_DISABLE_ACTION as e,LEADER_ENABLE_ACTION as t,LEADER_LABEL as n,LEADER_LAUNCH_ACTION as r,LEADER_MANAGE_ACTION as i,LEADER_RECOVER_ACTION as a,PACKAGE_SOURCE as o}from"../../types/index.mjs";const s=`doom-workflow`,c={key:`w`,label:n,order:50};function l(n){return[{id:`${s}.manage`,path:[c,{key:`l`,label:`manage`,detail:`running workflows`}],action:{name:i}},{id:`${s}.launch`,path:[c,{key:`w`,label:`launch`,detail:`start a workflow`}],action:{name:r}},n?{id:`${s}.disable`,path:[c,{key:`e`,label:`exit`,detail:`take back workflow tools`}],action:{name:e}}:{id:`${s}.enable`,path:[c,{key:`e`,label:`enter`,detail:`give the agent workflow tools`}],action:{name:t}},{id:`${s}.recover`,path:[c,{key:`r`,label:`recover`,detail:`failed workflow`}],action:{name:a}}]}function u(e,t=!1){let n=e.registerLeader({source:o,bindings:l(t)});return{setMode(e){n.update(l(e))},dispose(){n.dispose()}}}export{u as registerLeaderContribution,l as workflowLeaderBindings};
1
+ import{LEADER_CATALOG_ACTION as e,LEADER_DETAIL as t,LEADER_DISABLE_ACTION as n,LEADER_ENABLE_ACTION as r,LEADER_LABEL as i,LEADER_LAUNCH_ACTION as a,LEADER_MANAGE_ACTION as o,LEADER_RECOVER_ACTION as s,PACKAGE_SOURCE as c}from"../../types/index.mjs";const l=`doom-workflow`,u={key:`w`,label:i,detail:t,order:50};function d(t){return[{id:`${l}.catalog`,path:[u,{key:`l`,label:`list`,detail:`workflows in this repo`}],action:{name:e}},{id:`${l}.manage`,path:[u,{key:`r`,label:`runs`,detail:`runs in this session`}],action:{name:o}},{id:`${l}.launch`,path:[u,{key:`w`,label:`launch`,detail:`start a workflow`}],action:{name:a}},t?{id:`${l}.disable`,path:[u,{key:`e`,label:`exit`,detail:`take back workflow tools`,tone:`exit`}],action:{name:n}}:{id:`${l}.enable`,path:[u,{key:`e`,label:`enter`,detail:`give the agent workflow tools`}],action:{name:r}},{id:`${l}.recover`,path:[u,{key:`c`,label:`recover`,detail:`adopt a failed run`}],action:{name:s}}]}function f(e,t=!1){let n=e.registerLeader({source:c,bindings:d(t)});return{setMode(e){n.update(d(e))},dispose(){n.dispose()}}}export{f as registerLeaderContribution,d as workflowLeaderBindings};
2
2
  //# sourceMappingURL=leader.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"leader.mjs","names":[],"sources":["../../../src/adapters/pi/leader.ts"],"sourcesContent":["import type { LeaderBinding } from '@agimon-ai/doompi-extension-contracts/leader';\nimport type { DoomUiHubService } from '@agimon-ai/doompi-extension-contracts/ui-hub';\nimport {\n LEADER_DISABLE_ACTION,\n LEADER_ENABLE_ACTION,\n LEADER_KEY,\n LEADER_LABEL,\n LEADER_LAUNCH_ACTION,\n LEADER_MANAGE_ACTION,\n LEADER_ORDER,\n LEADER_RECOVER_ACTION,\n PACKAGE_SOURCE,\n} from '../../types/index.ts';\n\nconst LEADER_BINDING_PREFIX = 'doom-workflow';\nconst GROUP_SEGMENT = { key: LEADER_KEY, label: LEADER_LABEL, order: LEADER_ORDER } as const;\n\nexport interface WorkflowLeaderHandle {\n /** Republish the menu for the mode's current state. */\n setMode(enabled: boolean): void;\n dispose(): void;\n}\n\n/**\n * The menu as it stands with the mode on or off.\n *\n * One entry on `e` rather than an enable row beside a disable row: only one of\n * the two ever does anything, and a menu that prints both makes the reader\n * check the mode line to find out which. The label says which way it flips.\n */\nexport function workflowLeaderBindings(mode: boolean): LeaderBinding[] {\n return [\n {\n id: `${LEADER_BINDING_PREFIX}.manage`,\n path: [GROUP_SEGMENT, { key: 'l', label: 'manage', detail: 'running workflows' }],\n action: { name: LEADER_MANAGE_ACTION },\n },\n {\n id: `${LEADER_BINDING_PREFIX}.launch`,\n path: [GROUP_SEGMENT, { key: 'w', label: 'launch', detail: 'start a workflow' }],\n action: { name: LEADER_LAUNCH_ACTION },\n },\n mode\n ? {\n id: `${LEADER_BINDING_PREFIX}.disable`,\n path: [GROUP_SEGMENT, { key: 'e', label: 'exit', detail: 'take back workflow tools' }],\n action: { name: LEADER_DISABLE_ACTION },\n }\n : {\n id: `${LEADER_BINDING_PREFIX}.enable`,\n path: [GROUP_SEGMENT, { key: 'e', label: 'enter', detail: 'give the agent workflow tools' }],\n action: { name: LEADER_ENABLE_ACTION },\n },\n {\n id: `${LEADER_BINDING_PREFIX}.recover`,\n path: [GROUP_SEGMENT, { key: 'r', label: 'recover', detail: 'failed workflow' }],\n action: { name: LEADER_RECOVER_ACTION },\n },\n ];\n}\n\nexport function registerLeaderContribution(hub: DoomUiHubService, enabled = false): WorkflowLeaderHandle {\n const contribution = hub.registerLeader({\n source: PACKAGE_SOURCE,\n bindings: workflowLeaderBindings(enabled),\n });\n return {\n setMode(enabled) {\n contribution.update(workflowLeaderBindings(enabled));\n },\n dispose() {\n contribution.dispose();\n },\n };\n}\n"],"mappings":"6MAcA,MAAM,EAAwB,gBACxB,EAAgB,CAAE,IAAA,IAAiB,MAAO,EAAc,MAAA,EAAoB,EAelF,SAAgB,EAAuB,EAAgC,CACrE,MAAO,CACL,CACE,GAAI,GAAG,EAAsB,SAC7B,KAAM,CAAC,EAAe,CAAE,IAAK,IAAK,MAAO,SAAU,OAAQ,mBAAoB,CAAC,EAChF,OAAQ,CAAE,KAAM,CAAqB,CACvC,EACA,CACE,GAAI,GAAG,EAAsB,SAC7B,KAAM,CAAC,EAAe,CAAE,IAAK,IAAK,MAAO,SAAU,OAAQ,kBAAmB,CAAC,EAC/E,OAAQ,CAAE,KAAM,CAAqB,CACvC,EACA,EACI,CACE,GAAI,GAAG,EAAsB,UAC7B,KAAM,CAAC,EAAe,CAAE,IAAK,IAAK,MAAO,OAAQ,OAAQ,0BAA2B,CAAC,EACrF,OAAQ,CAAE,KAAM,CAAsB,CACxC,EACA,CACE,GAAI,GAAG,EAAsB,SAC7B,KAAM,CAAC,EAAe,CAAE,IAAK,IAAK,MAAO,QAAS,OAAQ,+BAAgC,CAAC,EAC3F,OAAQ,CAAE,KAAM,CAAqB,CACvC,EACJ,CACE,GAAI,GAAG,EAAsB,UAC7B,KAAM,CAAC,EAAe,CAAE,IAAK,IAAK,MAAO,UAAW,OAAQ,iBAAkB,CAAC,EAC/E,OAAQ,CAAE,KAAM,CAAsB,CACxC,CACF,CACF,CAEA,SAAgB,EAA2B,EAAuB,EAAU,GAA6B,CACvG,IAAM,EAAe,EAAI,eAAe,CACtC,OAAQ,EACR,SAAU,EAAuB,CAAO,CAC1C,CAAC,EACD,MAAO,CACL,QAAQ,EAAS,CACf,EAAa,OAAO,EAAuB,CAAO,CAAC,CACrD,EACA,SAAU,CACR,EAAa,QAAQ,CACvB,CACF,CACF"}
1
+ {"version":3,"file":"leader.mjs","names":[],"sources":["../../../src/adapters/pi/leader.ts"],"sourcesContent":["import type { LeaderBinding } from '@agimon-ai/doompi-extension-contracts/leader';\nimport type { DoomUiHubService } from '@agimon-ai/doompi-extension-contracts/ui-hub';\nimport {\n LEADER_CATALOG_ACTION,\n LEADER_DETAIL,\n LEADER_DISABLE_ACTION,\n LEADER_ENABLE_ACTION,\n LEADER_KEY,\n LEADER_LABEL,\n LEADER_LAUNCH_ACTION,\n LEADER_MANAGE_ACTION,\n LEADER_ORDER,\n LEADER_RECOVER_ACTION,\n PACKAGE_SOURCE,\n} from '../../types/index.ts';\n\nconst LEADER_BINDING_PREFIX = 'doom-workflow';\nconst GROUP_SEGMENT = {\n key: LEADER_KEY,\n label: LEADER_LABEL,\n detail: LEADER_DETAIL,\n order: LEADER_ORDER,\n} as const;\n\nexport interface WorkflowLeaderHandle {\n /** Republish the menu for the mode's current state. */\n setMode(enabled: boolean): void;\n dispose(): void;\n}\n\n/**\n * The menu as it stands with the mode on or off.\n *\n * One entry on `e` rather than an enable row beside a disable row: only one of\n * the two ever does anything, and a menu that prints both makes the reader\n * check the mode line to find out which. The label says which way it flips.\n */\nexport function workflowLeaderBindings(mode: boolean): LeaderBinding[] {\n return [\n {\n id: `${LEADER_BINDING_PREFIX}.catalog`,\n path: [GROUP_SEGMENT, { key: 'l', label: 'list', detail: 'workflows in this repo' }],\n action: { name: LEADER_CATALOG_ACTION },\n },\n {\n id: `${LEADER_BINDING_PREFIX}.manage`,\n path: [GROUP_SEGMENT, { key: 'r', label: 'runs', detail: 'runs in this session' }],\n action: { name: LEADER_MANAGE_ACTION },\n },\n {\n id: `${LEADER_BINDING_PREFIX}.launch`,\n path: [GROUP_SEGMENT, { key: 'w', label: 'launch', detail: 'start a workflow' }],\n action: { name: LEADER_LAUNCH_ACTION },\n },\n mode\n ? {\n id: `${LEADER_BINDING_PREFIX}.disable`,\n path: [GROUP_SEGMENT, { key: 'e', label: 'exit', detail: 'take back workflow tools', tone: 'exit' }],\n action: { name: LEADER_DISABLE_ACTION },\n }\n : {\n id: `${LEADER_BINDING_PREFIX}.enable`,\n path: [GROUP_SEGMENT, { key: 'e', label: 'enter', detail: 'give the agent workflow tools' }],\n action: { name: LEADER_ENABLE_ACTION },\n },\n // `r` is runs everywhere, so recovery moves off it rather than reading as a\n // third flavour of list in the one space that has both.\n {\n id: `${LEADER_BINDING_PREFIX}.recover`,\n path: [GROUP_SEGMENT, { key: 'c', label: 'recover', detail: 'adopt a failed run' }],\n action: { name: LEADER_RECOVER_ACTION },\n },\n ];\n}\n\nexport function registerLeaderContribution(hub: DoomUiHubService, enabled = false): WorkflowLeaderHandle {\n const contribution = hub.registerLeader({\n source: PACKAGE_SOURCE,\n bindings: workflowLeaderBindings(enabled),\n });\n return {\n setMode(enabled) {\n contribution.update(workflowLeaderBindings(enabled));\n },\n dispose() {\n contribution.dispose();\n },\n };\n}\n"],"mappings":"2PAgBA,MAAM,EAAwB,gBACxB,EAAgB,CACpB,IAAA,IACA,MAAO,EACP,OAAQ,EACR,MAAA,EACF,EAeA,SAAgB,EAAuB,EAAgC,CACrE,MAAO,CACL,CACE,GAAI,GAAG,EAAsB,UAC7B,KAAM,CAAC,EAAe,CAAE,IAAK,IAAK,MAAO,OAAQ,OAAQ,wBAAyB,CAAC,EACnF,OAAQ,CAAE,KAAM,CAAsB,CACxC,EACA,CACE,GAAI,GAAG,EAAsB,SAC7B,KAAM,CAAC,EAAe,CAAE,IAAK,IAAK,MAAO,OAAQ,OAAQ,sBAAuB,CAAC,EACjF,OAAQ,CAAE,KAAM,CAAqB,CACvC,EACA,CACE,GAAI,GAAG,EAAsB,SAC7B,KAAM,CAAC,EAAe,CAAE,IAAK,IAAK,MAAO,SAAU,OAAQ,kBAAmB,CAAC,EAC/E,OAAQ,CAAE,KAAM,CAAqB,CACvC,EACA,EACI,CACE,GAAI,GAAG,EAAsB,UAC7B,KAAM,CAAC,EAAe,CAAE,IAAK,IAAK,MAAO,OAAQ,OAAQ,2BAA4B,KAAM,MAAO,CAAC,EACnG,OAAQ,CAAE,KAAM,CAAsB,CACxC,EACA,CACE,GAAI,GAAG,EAAsB,SAC7B,KAAM,CAAC,EAAe,CAAE,IAAK,IAAK,MAAO,QAAS,OAAQ,+BAAgC,CAAC,EAC3F,OAAQ,CAAE,KAAM,CAAqB,CACvC,EAGJ,CACE,GAAI,GAAG,EAAsB,UAC7B,KAAM,CAAC,EAAe,CAAE,IAAK,IAAK,MAAO,UAAW,OAAQ,oBAAqB,CAAC,EAClF,OAAQ,CAAE,KAAM,CAAsB,CACxC,CACF,CACF,CAEA,SAAgB,EAA2B,EAAuB,EAAU,GAA6B,CACvG,IAAM,EAAe,EAAI,eAAe,CACtC,OAAQ,EACR,SAAU,EAAuB,CAAO,CAC1C,CAAC,EACD,MAAO,CACL,QAAQ,EAAS,CACf,EAAa,OAAO,EAAuB,CAAO,CAAC,CACrD,EACA,SAAU,CACR,EAAa,QAAQ,CACvB,CACF,CACF"}
@@ -1,11 +1,11 @@
1
- const e=require("../../../types/index.cjs"),t=require("../../../services/backgroundWork.cjs"),n=require("../../../services/workflowNarration.cjs"),r=require("../../../tui/workflow/workflowInspector.cjs"),i=require("../../../tui/workflow/workflowOverlay.cjs"),a=require("../../../tui/workflow/workflowPicker.cjs"),o=require("../../../tui/workflow/workflowProgressOverlay.cjs"),s=require("../../../tui/workflow/workflowPrompt.cjs"),c=require("../../../tui/workflow/workflowRunPanel.cjs"),l=require("../../../tui/workflow/workflowStepMessage.cjs"),u=require("./piToolBridge.cjs"),d=require("./piTools.cjs"),f=require("./workflowLauncher.cjs");let ee=require("node:fs"),p=require("node:path"),te=require("node:url"),m=require("@agimon-ai/doompi-extension-contracts/child-process"),ne=require("@agimon-ai/doompi-extension-contracts/ui-hub"),h=require("node:child_process"),re=require("node:crypto"),ie=require("node:fs/promises"),g=require("node:module"),ae=require("@agimon-ai/doompi-extension-contracts/mode"),oe=require("@agimon-ai/doompi-extension-contracts/narration"),se=require("@agimon-ai/doompi-extension-contracts/readiness"),ce=require("@agimon-ai/doompi-telemetry"),_=require("@agimon-ai/workflow-mcp"),v=require("@earendil-works/pi-tui");const le={overlay:!0,overlayOptions:{anchor:`top-left`,width:`100%`,maxHeight:`100%`,margin:0}},ue=`workflow-mcp-follow`,de=`activate`,fe=`deactivate`;function pe(e,t){return{activation:e?`active`:`inactive`,condition:`ready`,...e?{detail:t>0?`${t} active runs`:`tools enabled`,color:`accent`}:{},actions:[...e?[{id:de,enabled:!1,disabledReason:`Workflow mode is active.`}]:[{id:de,enabled:!0}],...e?[{id:fe,enabled:!0}]:[{id:fe,enabled:!1,disabledReason:`Workflow mode is inactive.`}]]}}const me=`SPC › w / workflows › w / launch`,y=`ctrl+alt+w`,b=`ctrl+alt+q`,he={alt:`⌥`,cmd:`⌘`,ctrl:`⌃`,meta:`⌘`,shift:`⇧`};function x(e,t=process.platform){let n=e.split(`+`);return t===`darwin`?n.map(e=>he[e]??e.toUpperCase()).join(``):n.map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(`+`)}const S=1e4,C=`running`,ge=`completed`,w=`failed`,T=`error`,_e=`error`,ve=`doom_workflow.launch_requested`,ye=`../../../../skills`,E={running:`▸`,repair:`⚠`,completed:`✔`,failed:`✖`,separator:`·`};function be(e,t=process.platform){let n=x(b,t);return e?[`Esc Esc closes this view`,`${x(y,t)} switches typing`,`${n} closes`].join(` ${E.separator} `):`view only ${E.separator} ${n} closes this view`}function xe(e,t=process.platform){let n=[x(b,t),`close`];return e?[[`Esc Esc`,`close`],[x(y,t),`switch typing`],n]:[n]}function Se(e,t,n,r){let i=`${E.running} ${e.runKey}`,a=[e.workspace,Te(e),e.runner].filter(Boolean).join(` ${E.separator} `),o=`${x(y)} to background`,s=n.fg(`accent`,(0,v.truncateToWidth)(i,r));return(0,v.visibleWidth)(i)+3+(0,v.visibleWidth)(a)<=r&&(s+=` `+n.fg(`muted`,a),(0,v.visibleWidth)(i)+3+(0,v.visibleWidth)(a)+3+(0,v.visibleWidth)(o)<=r&&(s+=` `+n.fg(`dim`,o))),[s,...t.map(e=>(0,v.truncateToWidth)(e,r))]}function Ce(e,t,n){let r=[];for(let i of e){let e=i.status===ge?E.completed:i.status===w?E.failed:E.running,a=i.status===ge?`success`:i.status===w?_e:`accent`,o=i.total?` ${E.separator} ${(i.index??0)+1}/${i.total}`:``;if(r.push((0,v.truncateToWidth)(t.fg(a,`${e} ${i.name}`)+t.fg(`dim`,o),n)),i.status===C)for(let e of i.steps){let i=e.status===ge?E.completed:e.status===w?E.failed:E.running,a=e.status===C?`muted`:e.status===w?_e:`dim`;r.push((0,v.truncateToWidth)(t.fg(a,` ${i} ${e.name}`),n))}}return r}function we(e,t){let n=Date.parse(e.startedAt);return Number.isFinite(n)?t.filter(e=>{let t=Date.parse(e.at);return!Number.isFinite(t)||t>=n}):t}function Te(e){return e.stale?`stale`:e.stage===T?w:e.stage}const D=`CMUX_WORKSPACE_ID`,O=`TMUX_PANE`,Ee=`WORKFLOW_TMUX_SESSION_NAME`,De=[`CMUX_SURFACE_ID`,m.SUBAGENT_ROOT_SESSION_ENV,D,O,`WORKFLOW_LAUNCHER_TYPE`,Ee,`WORKFLOW_STATUS_FILE`],k=`tmux`,A=`cmux`,Oe=`native`,ke=`This run points at Pi's own terminal, so its launcher screen is hidden. Use workflow status instead.`;function Ae(e){let t=e.launcher;if(t?.type===A){let e=process.env[D];return!!e&&t.workspaceId===e}if(t?.type!==k)return!1;let n=process.env[O],r=process.env[Ee];return!!n&&t.paneId===n||!!r&&t.sessionName===r}const je=`No durable launcher identity is recorded for this run.`;function Me(e){return(0,p.basename)(e,(0,p.extname)(e))}function Ne(){let e={...process.env};for(let t of De)delete e[t];return e}function Pe(){let e=process.env.WORKFLOW_LAUNCHER;return e===k||e===A?e:void 0}function Fe(e){return e.map(e=>`'${e.replaceAll(`'`,`'\\''`)}'`).join(` `)}function Ie(){try{return(0,g.createRequire)(require("url").pathToFileURL(__filename).href).resolve(`@agimon-ai/workflow-mcp/cli`)}catch{return}}const Le=async(e,t,n)=>{await new Promise((r,i)=>{let a=(0,h.spawn)(e,[...t],{...n,detached:!0,stdio:`ignore`});a.once(`error`,i),a.once(`spawn`,()=>{a.off(`error`,i),a.unref(),r()})})};function j(e,t){if(Array.isArray(e)){for(let n of e)j(n,t);return}if(!(!e||typeof e!=`object`))for(let[n,r]of Object.entries(e))(n===`interactiveRun`||n===`run`)&&r&&typeof r==`object`&&!Array.isArray(r)?t.push(Object.keys(r)):j(r,t)}function Re(e){let t=[];if(j(e,t),t.length!==0)return t[0].filter(e=>t.every(t=>t.includes(e))).sort()}async function M(e,t){let n=[],r=1,i=!0;for(;i;){let a=await e.listRunsPage({page:r,pageSize:100,workspace:t});n.push(...a.items),i=a.hasNextPage,r+=1}return n}function ze(e){return[e.runKey,e.workspace,Te(e),e.runner].filter(Boolean).join(` ${E.separator} `)}function Be(h={}){return g=>{let v=h.featureFactory?.()??(0,_.createEmbeddedWorkflowFeature)(),he=(0,re.randomUUID)(),w=!0,_e=0,D,O,Ee,De=h.isActive??(()=>!0),j=()=>w&&De(),Be=e=>{let t=e.diagnostics.join(`; `),n=(e.error?.message??t)||`Initialization did not complete.`,r=`${e.packageId} initialization ${e.state}: ${n}`;H?.hasUI?H.ui.notify(r,`warning`):process.emitWarning(r)},Ve=e=>(h.cordis?(0,se.readDoomReadinessCoordinator)(h.cordis):void 0)||(Ee??=(0,se.createDoomReadinessCoordinator)({notify:Be}),Ee),N=async e=>{e?.throwIfAborted();let t=O;if(!t)throw Error(`Workflow session initialization has not started.`);let n=await t;if(e?.throwIfAborted(),await n.wait(e?{signal:e}:void 0),!j()||t!==O)throw Error(`Workflow readiness belongs to a stale extension generation.`)},He=(e,t)=>{let n=Reflect.get(e,t,e);return typeof n==`function`?n.bind(e):n},Ue=new Proxy(g,{get(e,t){return t===`registerTool`?t=>{e.registerTool({...t,execute:async(e,n,r,i,a)=>(await N(r),t.execute(e,n,r,i,a))})}:He(e,t)}}),{parser:We,recoverService:Ge,registry:P,runService:Ke,runTool:qe}=v,Je=h.spawnDetached??Le,Ye=h.monitorIntervalMs??3e4,Xe=h.followIntervalMs??2e3,F,Ze=!1,I,Qe=!1,L,$e=new Map,R=new Map,et=new Set,tt=0,nt=h.cordis?t.registerRunProvider(h.cordis):void 0,rt=!1,z=0,B=!1,it,V;h.cordis?.inject([ae.DOOM_MINOR_MODE_CATALOG_SERVICE],t=>{let n=pe(B,z),r=(0,ae.registerMinorModeOwner)((0,ae.requireMinorModeCatalog)(t),{descriptor:{source:e.PACKAGE_SOURCE,id:`workflow`,label:`Workflow`,description:`Workflow discovery, launch, inspection, control, and recovery tools.`,order:20,actions:[{id:de,label:`Activate`,description:`Enable workflow tools for this session.`,contexts:[`tui`,`headless`],parameters:[]},{id:fe,label:`Deactivate`,description:`Disable workflow tools without stopping active runs.`,contexts:[`tui`,`headless`],parameters:[]}]},initialState:n,async handleAction(e,t,n){if(await N(),e===de)return await nn(!0,n.context),{message:`Workflow mode activated.`};if(e===fe)return await nn(!1,n.context),{message:`Workflow mode deactivated.`};throw Error(`Unknown workflow mode action: ${e}`)}});return V=r,it=JSON.stringify(n),()=>{r.dispose(),V===r&&(V=void 0,it=void 0)}});let H,U,W,at=!1,ot=new Map,G,st=new Set,K=new Map,ct=[],lt=new Map,ut=0,dt=new o.WorkflowProgressOverlay,ft,pt,q=e=>(pt??=(0,ce.createDoomTelemetry)({serviceName:`doom-workflow`,packageName:`@agimon-ai/doompi-workflow`,cwd:e?.cwd,env:process.env,enableLogs:!0,enableTraces:!0}),pt),mt,ht=e=>{q(H).recordWarning(`doom_workflow.narration_failed`,e).catch(e=>{process.emitWarning(`Doom-workflow could not record a narration failure: ${String(e)}`)})},gt={narrate(e){let t=mt,n=(0,oe.createNarrationRequest)(e);if(!(!t||!n))try{Promise.resolve(t.request(n)).catch(ht)}catch(e){ht(e)}}};h.cordis?.inject([oe.DOOM_NARRATION_SERVICE],e=>{let t=(0,oe.requireDoomNarrationService)(e);return mt=t,()=>{mt===t&&(mt=void 0)}});let _t=e=>{e&&j()&&(ft=(0,m.resolveRootSessionId)(e))},vt=()=>{let e=ft??H?.sessionManager.getSessionId();return e?(0,m.resolveRootSessionId)(e):void 0},yt=(e,t)=>e.sessionManager.getSessionId().trim()===t,bt=v.createRecoverTool({ownerSessionId:vt}),xt=v.createControlTool(),J=new Set,St=e=>{let t=Date.now(),n=q();return J.add(e),n.recordEvent(`doom_workflow.run_started`,{outcome:`started`}),e.then(()=>(J.delete(e),n.recordEvent(`doom_workflow.run_finished`,{duration_ms:Date.now()-t,outcome:`completed`})),r=>(J.delete(e),n.recordError(`doom_workflow.run_failed`,r,{duration_ms:Date.now()-t}))),e},Ct=(e,t)=>{let n=Re(We.parseWorkflowFile(e));if(!(!n||n.includes(t)))return`Runner ${JSON.stringify(t)} is not available across this workflow. Compatible runners: ${n.join(`, `)||`none`}.`},wt=d.createWorkflowLaunchExecutor({activeRunCount:async()=>z,observeSession:_t,rejectRunner:Ct,runTool:qe,trackPendingRun:St,...h.launchAckPollMs===void 0?{}:{launchAckPollMs:h.launchAckPollMs},...h.launchAckTimeoutMs===void 0?{}:{launchAckTimeoutMs:h.launchAckTimeoutMs},findLaunchedRun:async({sessionId:e,since:t,workflowPath:n})=>{let r=Me(n),i=n=>{if(!u.isSessionRun(n,e)||n.stale||n.workflowId&&n.workflowId!==r)return!1;let i=Date.parse(n.startedAt);return Number.isFinite(i)&&i>=t-2e3};return G?(await G.refresh(),ct.find(i)):(await M(P)).find(i)},onLateFailure:(e,t)=>{let n=e instanceof Error?e.message:String(e);t.ui.notify(u.launchNotice(`Workflow launch failed after it was reported started.\n${n}`),`warning`)},onLaunch:async e=>(await q(e).recordEvent(ve,{outcome:`requested`}),Z(e,!1))}),Tt=()=>{let e=[...lt.values()].sort((e,t)=>Date.parse(e.startedAt)-Date.parse(t.startedAt)||X(e).localeCompare(X(t)));dt.update(e.map(e=>o.workflowProgressRow(e,K.get(X(e))??[])))},Et=e=>{ut+=1;let t=X(e);e.stage===C&&!e.stale?lt.set(t,e):lt.delete(t),Tt()},Dt=e=>{lt.clear();for(let t of e)lt.set(X(t),t);Tt()},Ot=(e,t)=>{let n=K.get(e)??[];n.push(t),K.set(e,n)},Y,kt=e=>{!j()||e!==H||Y||(Y=setTimeout(()=>{Y=void 0,j()&&e===H&&Z(e,!0)},120),Y.unref?.())},At=e=>{K.delete(e)},jt=async e=>{let t=(0,m.resolveRootSessionId)(e.sessionManager.getSessionId()),n=v.createRunControl({recordFilter:e=>u.isSessionRun(e,t)});G=n;let r=()=>j()&&e===H&&G===n,i=[n.on(`step`,t=>{if(!r())return;let n=X(t.record);Ot(n,{at:t.at,job:t.job,status:t.status,step:t.step,type:`step`,...t.reason===void 0?{}:{reason:t.reason}}),Et(t.record),kt(e)}),n.on(`job`,t=>{if(!r())return;let n=X(t.record);Ot(n,{at:t.at,job:t.job,status:t.status,type:`job`,...t.index===void 0?{}:{index:t.index},...t.reason===void 0?{}:{reason:t.reason},...t.total===void 0?{}:{total:t.total}}),Et(t.record),kt(e)}),n.on(`runStarted`,t=>{r()&&(ct.unshift(t.record),ct.length>32&&(ct.length=32),Et(t.record),kt(e))}),n.on(`runUpdated`,t=>{r()&&(Et(t.record),Z(e,!0))}),n.on(`runFinished`,t=>{r()&&(Et(t.record),Z(e,!0))})];for(let e of i)st.add(e);try{await n.start()}catch(e){for(let e of i)st.delete(e),e();throw n.dispose(),G===n&&(G=void 0),e}if(!j()||e!==H||G!==n){for(let e of i)st.delete(e),e();n.dispose(),G===n&&(G=void 0)}},Mt=()=>{Y&&clearTimeout(Y),Y=void 0;for(let e of st)e();st.clear(),G?.dispose(),G=void 0,K.clear(),ut+=1,lt.clear(),Tt()},Nt=()=>{U?.teardown(),U?.handle?.hide(),U=void 0},X=e=>e.runId??`${e.workspace}/${e.runKey}`,Pt=()=>{let e=V;if(!e)return;let t=pe(B,z),n=JSON.stringify(t);n!==it&&(it=n,e.publish(t))},Z=async(e,t)=>{if(!j()||e!==H)return;let r=q(e);if(Ze){r.recordEvent(`doom_workflow.monitor_skipped`,{outcome:`already_running`});return}let i=Date.now(),a=ut;Ze=!0;try{let o=await M(P);if(!j()||e!==H)return;let s=(0,m.resolveRootSessionId)(e.sessionManager.getSessionId()),c=yt(e,s),l=o.filter(e=>u.isSessionRun(e,s)),d=l.filter(e=>e.stage===C&&!e.stale),f=l.filter(e=>e.stage===T);a===ut&&Dt(d),r.recordEvent(`doom_workflow.monitor_counts`,{"workflow.run_count":l.length,"workflow.running_count":d.length,"workflow.failed_count":f.length,mode:B?`on`:`off`});let ee=u.runsForSession(o,s).filter(e=>!e.stale);z=ee.length,Pt(),nt?.update(ee.map(e=>({id:e.runId??e.runKey,sessionId:s}))),zt(new Set(l.map(e=>X(e))));let p=new Map(l.map(e=>[X(e),e.stage]));for(let e of l){let r=X(e),i=$e.get(r),a=Date.parse(e.startedAt),o=i===void 0&&(tt===0||!Number.isFinite(a)||a>=tt);rt&&n.narrateWorkflowTransition(gt,e,i===C||i===ge||i===T?i:void 0,o),!(!t||!c||e.stage===C)&&!et.has(r)&&(i===C||o)&&R.set(r,e)}let te=new Set([...l.filter(e=>e.stage===C&&!e.stale).map(e=>X(e)),...R.keys()]);for(let e of K.keys())te.has(e)||At(e);if(t)for(let t of l){if($e.get(X(t))!==C||t.stage===C)continue;let n=t.stage===ge,i=t.failedJob?` at ${t.failedJob}`:``;e.ui.notify(n?`${E.completed} ${t.runKey} completed`:`${E.failed} ${t.runKey} ${Te(t)}${i}`,n?`info`:`warning`),r.recordEvent(`doom_workflow.run_transition`,{outcome:n?`completed`:Te(t)})}if(c&&R.size>0)try{let e=[...R.values()],t=await Promise.all(e.map(async e=>{if(e.stage===ge)return u.finishedRunSummary(e,[]);let t=X(e),n=K.get(t)??we(e,await(0,_.readWorkflowProgress)(P.runDirectoryFor(e)));return u.finishedRunSummary(e,(0,_.summarizeWorkflowProgress)(n))}));g.sendMessage({customType:`workflow-run-finished`,content:t.join(`
1
+ const e=require("../../../types/index.cjs"),t=require("../../../services/backgroundWork.cjs"),n=require("../../../services/workflowNarration.cjs"),r=require("../../../tui/workflow/workflowInspector.cjs"),i=require("../../../tui/workflow/workflowOverlay.cjs"),a=require("../../../tui/workflow/workflowPicker.cjs"),o=require("../../../tui/workflow/workflowProgressOverlay.cjs"),s=require("../../../tui/workflow/workflowPrompt.cjs"),c=require("../../../tui/workflow/workflowRunPanel.cjs"),l=require("../../../tui/workflow/workflowStepMessage.cjs"),u=require("./piToolBridge.cjs"),d=require("./piTools.cjs"),f=require("./workflowLauncher.cjs");let ee=require("node:fs"),p=require("node:path"),te=require("node:url"),m=require("@agimon-ai/doompi-extension-contracts/child-process"),ne=require("@agimon-ai/doompi-extension-contracts/ui-hub"),h=require("node:child_process"),re=require("node:crypto"),ie=require("node:fs/promises"),g=require("node:module"),ae=require("@agimon-ai/doompi-extension-contracts/mode"),oe=require("@agimon-ai/doompi-extension-contracts/narration"),se=require("@agimon-ai/doompi-extension-contracts/readiness"),ce=require("@agimon-ai/doompi-telemetry"),_=require("@agimon-ai/workflow-mcp"),v=require("@earendil-works/pi-tui");const le={overlay:!0,overlayOptions:{anchor:`top-left`,width:`100%`,maxHeight:`100%`,margin:0}},ue=`workflow-mcp-follow`,de=`activate`,fe=`deactivate`;function pe(e,t){return{activation:e?`active`:`inactive`,condition:`ready`,...e?{detail:t>0?`${t} active runs`:`tools enabled`,color:`accent`}:{},actions:[...e?[{id:de,enabled:!1,disabledReason:`Workflow mode is active.`}]:[{id:de,enabled:!0}],...e?[{id:fe,enabled:!0}]:[{id:fe,enabled:!1,disabledReason:`Workflow mode is inactive.`}]]}}const me=`SPC › w / workflows › w / launch`,y=`ctrl+alt+w`,b=`ctrl+alt+q`,he={alt:`⌥`,cmd:`⌘`,ctrl:`⌃`,meta:`⌘`,shift:`⇧`};function x(e,t=process.platform){let n=e.split(`+`);return t===`darwin`?n.map(e=>he[e]??e.toUpperCase()).join(``):n.map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(`+`)}const S=1e4,C=`running`,ge=`completed`,w=`failed`,_e=`error`,ve=`error`,ye=`doom_workflow.launch_requested`,be=`../../../../skills`,T={running:`▸`,repair:`⚠`,completed:`✔`,failed:`✖`,separator:`·`};function xe(e,t=process.platform){let n=x(b,t);return e?[`Esc Esc closes this view`,`${x(y,t)} switches typing`,`${n} closes`].join(` ${T.separator} `):`view only ${T.separator} ${n} closes this view`}function Se(e,t=process.platform){let n=[x(b,t),`close`];return e?[[`Esc Esc`,`close`],[x(y,t),`switch typing`],n]:[n]}function Ce(e,t,n,r){let i=`${T.running} ${e.runKey}`,a=[e.workspace,Ee(e),e.runner].filter(Boolean).join(` ${T.separator} `),o=`${x(y)} to background`,s=n.fg(`accent`,(0,v.truncateToWidth)(i,r));return(0,v.visibleWidth)(i)+3+(0,v.visibleWidth)(a)<=r&&(s+=` `+n.fg(`muted`,a),(0,v.visibleWidth)(i)+3+(0,v.visibleWidth)(a)+3+(0,v.visibleWidth)(o)<=r&&(s+=` `+n.fg(`dim`,o))),[s,...t.map(e=>(0,v.truncateToWidth)(e,r))]}function we(e,t,n){let r=[];for(let i of e){let e=i.status===ge?T.completed:i.status===w?T.failed:T.running,a=i.status===ge?`success`:i.status===w?ve:`accent`,o=i.total?` ${T.separator} ${(i.index??0)+1}/${i.total}`:``;if(r.push((0,v.truncateToWidth)(t.fg(a,`${e} ${i.name}`)+t.fg(`dim`,o),n)),i.status===C)for(let e of i.steps){let i=e.status===ge?T.completed:e.status===w?T.failed:T.running,a=e.status===C?`muted`:e.status===w?ve:`dim`;r.push((0,v.truncateToWidth)(t.fg(a,` ${i} ${e.name}`),n))}}return r}function Te(e,t){let n=Date.parse(e.startedAt);return Number.isFinite(n)?t.filter(e=>{let t=Date.parse(e.at);return!Number.isFinite(t)||t>=n}):t}function Ee(e){return e.stale?`stale`:e.stage===_e?w:e.stage}const E=`CMUX_WORKSPACE_ID`,D=`TMUX_PANE`,O=`WORKFLOW_TMUX_SESSION_NAME`,De=[`CMUX_SURFACE_ID`,m.SUBAGENT_ROOT_SESSION_ENV,E,D,`WORKFLOW_LAUNCHER_TYPE`,O,`WORKFLOW_STATUS_FILE`],k=`tmux`,A=`cmux`,Oe=`native`,ke=`This run points at Pi's own terminal, so its launcher screen is hidden. Use workflow status instead.`;function Ae(e){let t=e.launcher;if(t?.type===A){let e=process.env[E];return!!e&&t.workspaceId===e}if(t?.type!==k)return!1;let n=process.env[D],r=process.env[O];return!!n&&t.paneId===n||!!r&&t.sessionName===r}const je=`No durable launcher identity is recorded for this run.`;function Me(e){return(0,p.basename)(e,(0,p.extname)(e))}function Ne(){let e={...process.env};for(let t of De)delete e[t];return e}function Pe(){let e=process.env.WORKFLOW_LAUNCHER;return e===k||e===A?e:void 0}function Fe(e){return e.map(e=>`'${e.replaceAll(`'`,`'\\''`)}'`).join(` `)}function Ie(){try{return(0,g.createRequire)(require("url").pathToFileURL(__filename).href).resolve(`@agimon-ai/workflow-mcp/cli`)}catch{return}}const Le=async(e,t,n)=>{await new Promise((r,i)=>{let a=(0,h.spawn)(e,[...t],{...n,detached:!0,stdio:`ignore`});a.once(`error`,i),a.once(`spawn`,()=>{a.off(`error`,i),a.unref(),r()})})};function j(e,t){if(Array.isArray(e)){for(let n of e)j(n,t);return}if(!(!e||typeof e!=`object`))for(let[n,r]of Object.entries(e))(n===`interactiveRun`||n===`run`)&&r&&typeof r==`object`&&!Array.isArray(r)?t.push(Object.keys(r)):j(r,t)}function Re(e){let t=[];if(j(e,t),t.length!==0)return t[0].filter(e=>t.every(t=>t.includes(e))).sort()}async function M(e,t){let n=[],r=1,i=!0;for(;i;){let a=await e.listRunsPage({page:r,pageSize:100,workspace:t});n.push(...a.items),i=a.hasNextPage,r+=1}return n}function ze(e){return[e.runKey,e.workspace,Ee(e),e.runner].filter(Boolean).join(` ${T.separator} `)}function Be(h={}){return g=>{let v=h.featureFactory?.()??(0,_.createEmbeddedWorkflowFeature)(),he=(0,re.randomUUID)(),w=!0,ve=0,E,D,O,De=h.isActive??(()=>!0),j=()=>w&&De(),Be=e=>{let t=e.diagnostics.join(`; `),n=(e.error?.message??t)||`Initialization did not complete.`,r=`${e.packageId} initialization ${e.state}: ${n}`;H?.hasUI?H.ui.notify(r,`warning`):process.emitWarning(r)},Ve=e=>(h.cordis?(0,se.readDoomReadinessCoordinator)(h.cordis):void 0)||(O??=(0,se.createDoomReadinessCoordinator)({notify:Be}),O),N=async e=>{e?.throwIfAborted();let t=D;if(!t)throw Error(`Workflow session initialization has not started.`);let n=await t;if(e?.throwIfAborted(),await n.wait(e?{signal:e}:void 0),!j()||t!==D)throw Error(`Workflow readiness belongs to a stale extension generation.`)},He=(e,t)=>{let n=Reflect.get(e,t,e);return typeof n==`function`?n.bind(e):n},Ue=new Proxy(g,{get(e,t){return t===`registerTool`?t=>{e.registerTool({...t,execute:async(e,n,r,i,a)=>(await N(r),t.execute(e,n,r,i,a))})}:He(e,t)}}),{parser:We,recoverService:Ge,registry:P,runService:Ke,runTool:qe}=v,Je=h.spawnDetached??Le,Ye=h.monitorIntervalMs??3e4,Xe=h.followIntervalMs??2e3,F,Ze=!1,I,Qe=!1,L,$e=new Map,R=new Map,et=new Set,tt=0,nt=h.cordis?t.registerRunProvider(h.cordis):void 0,rt=!1,z=0,B=!1,it,V;h.cordis?.inject([ae.DOOM_MINOR_MODE_CATALOG_SERVICE],t=>{let n=pe(B,z),r=(0,ae.registerMinorModeOwner)((0,ae.requireMinorModeCatalog)(t),{descriptor:{source:e.PACKAGE_SOURCE,id:`workflow`,label:`Workflow`,description:`Workflow discovery, launch, inspection, control, and recovery tools.`,order:20,actions:[{id:de,label:`Activate`,description:`Enable workflow tools for this session.`,contexts:[`tui`,`headless`],parameters:[]},{id:fe,label:`Deactivate`,description:`Disable workflow tools without stopping active runs.`,contexts:[`tui`,`headless`],parameters:[]}]},initialState:n,async handleAction(e,t,n){if(await N(),e===de)return await rn(!0,n.context),{message:`Workflow mode activated.`};if(e===fe)return await rn(!1,n.context),{message:`Workflow mode deactivated.`};throw Error(`Unknown workflow mode action: ${e}`)}});return V=r,it=JSON.stringify(n),()=>{r.dispose(),V===r&&(V=void 0,it=void 0)}});let H,U,W,at=!1,ot=new Map,G,st=new Set,K=new Map,ct=[],lt=new Map,ut=0,dt=new o.WorkflowProgressOverlay,ft,pt,q=e=>(pt??=(0,ce.createDoomTelemetry)({serviceName:`doom-workflow`,packageName:`@agimon-ai/doompi-workflow`,cwd:e?.cwd,env:process.env,enableLogs:!0,enableTraces:!0}),pt),mt,ht=e=>{q(H).recordWarning(`doom_workflow.narration_failed`,e).catch(e=>{process.emitWarning(`Doom-workflow could not record a narration failure: ${String(e)}`)})},gt={narrate(e){let t=mt,n=(0,oe.createNarrationRequest)(e);if(!(!t||!n))try{Promise.resolve(t.request(n)).catch(ht)}catch(e){ht(e)}}};h.cordis?.inject([oe.DOOM_NARRATION_SERVICE],e=>{let t=(0,oe.requireDoomNarrationService)(e);return mt=t,()=>{mt===t&&(mt=void 0)}});let _t=e=>{e&&j()&&(ft=(0,m.resolveRootSessionId)(e))},vt=()=>{let e=ft??H?.sessionManager.getSessionId();return e?(0,m.resolveRootSessionId)(e):void 0},yt=(e,t)=>e.sessionManager.getSessionId().trim()===t,bt=v.createRecoverTool({ownerSessionId:vt}),xt=v.createControlTool(),J=new Set,St=e=>{let t=Date.now(),n=q();return J.add(e),n.recordEvent(`doom_workflow.run_started`,{outcome:`started`}),e.then(()=>(J.delete(e),n.recordEvent(`doom_workflow.run_finished`,{duration_ms:Date.now()-t,outcome:`completed`})),r=>(J.delete(e),n.recordError(`doom_workflow.run_failed`,r,{duration_ms:Date.now()-t}))),e},Ct=(e,t)=>{let n=Re(We.parseWorkflowFile(e));if(!(!n||n.includes(t)))return`Runner ${JSON.stringify(t)} is not available across this workflow. Compatible runners: ${n.join(`, `)||`none`}.`},wt=d.createWorkflowLaunchExecutor({activeRunCount:async()=>z,observeSession:_t,rejectRunner:Ct,runTool:qe,trackPendingRun:St,...h.launchAckPollMs===void 0?{}:{launchAckPollMs:h.launchAckPollMs},...h.launchAckTimeoutMs===void 0?{}:{launchAckTimeoutMs:h.launchAckTimeoutMs},findLaunchedRun:async({sessionId:e,since:t,workflowPath:n})=>{let r=Me(n),i=n=>{if(!u.isSessionRun(n,e)||n.stale||n.workflowId&&n.workflowId!==r)return!1;let i=Date.parse(n.startedAt);return Number.isFinite(i)&&i>=t-2e3};return G?(await G.refresh(),ct.find(i)):(await M(P)).find(i)},onLateFailure:(e,t)=>{let n=e instanceof Error?e.message:String(e);t.ui.notify(u.launchNotice(`Workflow launch failed after it was reported started.\n${n}`),`warning`)},onLaunch:async e=>(await q(e).recordEvent(ye,{outcome:`requested`}),Z(e,!1))}),Tt=()=>{let e=[...lt.values()].sort((e,t)=>Date.parse(e.startedAt)-Date.parse(t.startedAt)||X(e).localeCompare(X(t)));dt.update(e.map(e=>o.workflowProgressRow(e,K.get(X(e))??[])))},Et=e=>{ut+=1;let t=X(e);e.stage===C&&!e.stale?lt.set(t,e):lt.delete(t),Tt()},Dt=e=>{lt.clear();for(let t of e)lt.set(X(t),t);Tt()},Ot=(e,t)=>{let n=K.get(e)??[];n.push(t),K.set(e,n)},Y,kt=e=>{!j()||e!==H||Y||(Y=setTimeout(()=>{Y=void 0,j()&&e===H&&Z(e,!0)},120),Y.unref?.())},At=e=>{K.delete(e)},jt=async e=>{let t=(0,m.resolveRootSessionId)(e.sessionManager.getSessionId()),n=v.createRunControl({recordFilter:e=>u.isSessionRun(e,t)});G=n;let r=()=>j()&&e===H&&G===n,i=[n.on(`step`,t=>{if(!r())return;let n=X(t.record);Ot(n,{at:t.at,job:t.job,status:t.status,step:t.step,type:`step`,...t.reason===void 0?{}:{reason:t.reason}}),Et(t.record),kt(e)}),n.on(`job`,t=>{if(!r())return;let n=X(t.record);Ot(n,{at:t.at,job:t.job,status:t.status,type:`job`,...t.index===void 0?{}:{index:t.index},...t.reason===void 0?{}:{reason:t.reason},...t.total===void 0?{}:{total:t.total}}),Et(t.record),kt(e)}),n.on(`runStarted`,t=>{r()&&(ct.unshift(t.record),ct.length>32&&(ct.length=32),Et(t.record),kt(e))}),n.on(`runUpdated`,t=>{r()&&(Et(t.record),Z(e,!0))}),n.on(`runFinished`,t=>{r()&&(Et(t.record),Z(e,!0))})];for(let e of i)st.add(e);try{await n.start()}catch(e){for(let e of i)st.delete(e),e();throw n.dispose(),G===n&&(G=void 0),e}if(!j()||e!==H||G!==n){for(let e of i)st.delete(e),e();n.dispose(),G===n&&(G=void 0)}},Mt=()=>{Y&&clearTimeout(Y),Y=void 0;for(let e of st)e();st.clear(),G?.dispose(),G=void 0,K.clear(),ut+=1,lt.clear(),Tt()},Nt=()=>{U?.teardown(),U?.handle?.hide(),U=void 0},X=e=>e.runId??`${e.workspace}/${e.runKey}`,Pt=()=>{let e=V;if(!e)return;let t=pe(B,z),n=JSON.stringify(t);n!==it&&(it=n,e.publish(t))},Z=async(e,t)=>{if(!j()||e!==H)return;let r=q(e);if(Ze){r.recordEvent(`doom_workflow.monitor_skipped`,{outcome:`already_running`});return}let i=Date.now(),a=ut;Ze=!0;try{let o=await M(P);if(!j()||e!==H)return;let s=(0,m.resolveRootSessionId)(e.sessionManager.getSessionId()),c=yt(e,s),l=o.filter(e=>u.isSessionRun(e,s)),d=l.filter(e=>e.stage===C&&!e.stale),f=l.filter(e=>e.stage===_e);a===ut&&Dt(d),r.recordEvent(`doom_workflow.monitor_counts`,{"workflow.run_count":l.length,"workflow.running_count":d.length,"workflow.failed_count":f.length,mode:B?`on`:`off`});let ee=u.runsForSession(o,s).filter(e=>!e.stale);z=ee.length,Pt(),nt?.update(ee.map(e=>({id:e.runId??e.runKey,sessionId:s}))),zt(new Set(l.map(e=>X(e))));let p=new Map(l.map(e=>[X(e),e.stage]));for(let e of l){let r=X(e),i=$e.get(r),a=Date.parse(e.startedAt),o=i===void 0&&(tt===0||!Number.isFinite(a)||a>=tt);rt&&n.narrateWorkflowTransition(gt,e,i===C||i===ge||i===_e?i:void 0,o),!(!t||!c||e.stage===C)&&!et.has(r)&&(i===C||o)&&R.set(r,e)}let te=new Set([...l.filter(e=>e.stage===C&&!e.stale).map(e=>X(e)),...R.keys()]);for(let e of K.keys())te.has(e)||At(e);if(t)for(let t of l){if($e.get(X(t))!==C||t.stage===C)continue;let n=t.stage===ge,i=t.failedJob?` at ${t.failedJob}`:``;e.ui.notify(n?`${T.completed} ${t.runKey} completed`:`${T.failed} ${t.runKey} ${Ee(t)}${i}`,n?`info`:`warning`),r.recordEvent(`doom_workflow.run_transition`,{outcome:n?`completed`:Ee(t)})}if(c&&R.size>0)try{let e=[...R.values()],t=await Promise.all(e.map(async e=>{if(e.stage===ge)return u.finishedRunSummary(e,[]);let t=X(e),n=K.get(t)??Te(e,await(0,_.readWorkflowProgress)(P.runDirectoryFor(e)));return u.finishedRunSummary(e,(0,_.summarizeWorkflowProgress)(n))}));g.sendMessage({customType:`workflow-run-finished`,content:t.join(`
2
2
 
3
3
  `),display:!0,details:{runIds:e.map(e=>e.runId??X(e))}},{triggerTurn:!0,deliverAs:`steer`});for(let t of e){let e=X(t);et.add(e),R.delete(e),At(e)}}catch(e){await r.recordError(`doom_workflow.terminal_delivery_failed`,e,{"workflow.pending_terminal_count":R.size})}$e=p,r.recordEvent(`doom_workflow.monitor_finished`,{duration_ms:Date.now()-i,outcome:`completed`})}catch(t){await r.recordError(`doom_workflow.monitor_failed`,t,{duration_ms:Date.now()-i}),e.ui.notify(`Workflow status refresh failed: ${t instanceof Error?t.message:String(t)}`,`warning`)}finally{Ze=!1}},Ft=e=>{I&&clearInterval(I),I=void 0,L=void 0,e.ui.setWidget(ue,void 0)},It=async e=>{let t=e.launcher;if(!t)return[je];if(Ae(e))return[ke];if(t.type===k){let n=t.paneId??t.sessionId??t.sessionName,r=await g.exec(k,[`capture-pane`,`-p`,`-t`,n,`-S`,`-24`],{timeout:S});return r.code===0?r.stdout.trimEnd().split(`
4
4
  `).slice(-24):[`Unable to read ${e.runKey}: ${r.stderr.trim()||`tmux exited ${r.code}`}`]}if(t.type===Oe)return[`This run is hosted natively and has no launcher screen to read.`];let n=await g.exec(A,[`read-screen`,`--workspace`,t.workspaceId,`--scrollback`,`--lines`,`24`],{timeout:S});return n.code===0?n.stdout.trimEnd().split(`
5
- `).slice(-24):[`Unable to read ${e.runKey}: ${n.stderr.trim()||`cmux exited ${n.code}`}`]},Lt=new Map,Rt=async e=>{let t=X(e),n=Lt.get(t)??{at:0,lines:[]};if(Lt.set(t,n),n.inFlight||Date.now()-n.at<750)return n.lines;n.inFlight=It(e);try{n.lines=await n.inFlight}finally{n.at=Date.now(),n.inFlight=void 0}return n.lines},zt=e=>{for(let t of Lt.keys())e.has(t)||Lt.delete(t)},Bt=async e=>{let t=e.launcher;if(!t)return je;if(Ae(e))return ke;if(t.type===Oe)return`This run is hosted natively rather than in a multiplexer, so there is no separate window to bring forward.`;if(t.type===A)return await g.exec(A,[`select-workspace`,`--workspace`,t.workspaceId],{timeout:S}),`Opened ${e.runKey} in cmux.`;if(!process.env.TMUX)return`Pi is not attached to tmux. Follow the output instead, or attach to the recorded tmux session manually.`;let n=t.sessionId??t.sessionName,r=await g.exec(k,[`switch-client`,`-t`,n],{timeout:S});return r.code===0?(t.paneId&&await g.exec(k,[`select-pane`,`-t`,t.paneId],{timeout:S}),`Opened ${e.runKey} in tmux.`):r.stderr.trim()||`Unable to open tmux session ${n}.`},Vt=async(e,t)=>{if(!Qe){Qe=!0;try{let n=(0,_.summarizeWorkflowProgress)(we(e,await(0,_.readWorkflowProgress)(P.runDirectoryFor(e)))),r=n.length>0?void 0:await Rt(e);t.ui.setWidget(ue,(t,i)=>({render:t=>Se(e,r??Ce(n,i,t),i,t),invalidate:()=>{}}),{placement:`aboveEditor`})}finally{Qe=!1}}},Ht=async(e,t)=>{Ft(t),L=e,await Vt(e,t),I=setInterval(()=>{L&&Vt(L,t)},Xe),I.unref?.()},Ut=async(e,t)=>{let n=e.launcher;if(!(!n||n.type===Oe||Ae(e))){if(n.type===k){let e=n.paneId??n.sessionId??n.sessionName;await g.exec(k,[`send-keys`,`-t`,e,`-l`,t],{timeout:S});return}await g.exec(A,[`send`,`--workspace`,n.workspaceId,t],{timeout:S})}},Wt=async(e,t)=>{Nt();let n=!Ae(e)&&(e.launcher?.type===k||e.launcher?.type===A),r=new i.TerminalInputBatcher(t=>Ut(e,t)),a=[],o=[],s,l=!1,u=async()=>{a=(0,_.summarizeWorkflowProgress)(we(e,await(0,_.readWorkflowProgress)(P.runDirectoryFor(e)))),o=await Rt(e)};await u();let d=()=>{s&&clearInterval(s),s=void 0,r.dispose()},f={interactive:n,runKey:e.runKey,teardown:d};U=f;let ee=()=>{Nt(),t.ui.notify(`Closed the ${e.runKey} view. The run keeps going.`,`info`)};return t.ui.custom((i,p,te,m)=>(s=setInterval(()=>{l||(l=!0,u().finally(()=>{l=!1,i.requestRender()}))},200),s.unref?.(),new c.WorkflowRunPanelComponent(i,p,{runKey:e.runKey,label:`${E.running} ${ze(e)}`,breadcrumb:`SPC › w / workflows › run`,interactive:n,footer:be(n),hints:xe(n),snapshot:e=>({progress:Ce(a,p,e),output:o}),onUnfollow:()=>{f.handle?.unfocus(),t.ui.notify(`Typing goes to this session. The run keeps going.`,`info`)},onClose:ee,sendInput:e=>r.write(e),flushInput:()=>void r.flush(),unfollowShortcut:y,closeShortcut:b,onDispose:()=>{d(),U===f&&(U=void 0),m()}})),{...c.runPanelUiOptions(n),onHandle:e=>{f.handle=e}}),t.ui.notify(n?`${e.runKey}: typing goes to the run. Press Esc twice to close, ${x(y)} to type here instead.`:`${e.runKey}: view only, because this run is hosted natively. ${x(b)} closes it.`,`info`),n?[`Showing ${e.runKey} over Pi. Typing goes to the run.`,`Pressing Escape twice quickly closes the view, and a single Escape still reaches the run.`,`${x(y)} moves typing between the run and this session,`,`and ${x(b)} closes the view. The run keeps going either way.`].join(` `):[`Showing ${e.runKey} over Pi, as a view only:`,`the run is hosted natively rather than in a multiplexer, so there is no terminal to type into.`,`Typing stays with this session, and ${x(b)} closes the view.`].join(` `)},Gt=async(e,t=!1)=>{if(!(at||U||L)){at=!0;try{let n=await e.ui.custom((e,t,n,i)=>new r.WorkflowInspectorComponent(e,t,{list:async()=>{let e=vt(),t=(await M(P)).filter(t=>t.stage===C&&!t.stale&&u.isSessionRun(t,e));return ot=new Map(t.map(e=>[X(e),e])),Promise.all(t.map(async e=>({displayName:e.displayName,executionState:e.executionState,jobs:(0,_.summarizeWorkflowProgress)(we(e,await(0,_.readWorkflowProgress)(P.runDirectoryFor(e)))),key:X(e),output:[],runKey:e.runKey,startedAt:e.startedAt,workspace:e.workspace})))},output:async e=>{let t=ot.get(e.key);return t?Rt(t):[`Workflow is no longer active.`]}},i),{...le,onHandle:e=>{W=e}});if(n){let r=await Q(n);t?await Xt(r,e):await Wt(r,e)}}finally{W=void 0,at=!1,ot.clear()}}},Q=async(e,t=vt())=>{_t(t);let n=(await M(P,e.workspace)).filter(n=>n.runKey===e.runKey&&u.isSessionRun(n,t));if(n.length>1)throw Error(u.withOptions(`Workflow run key ${JSON.stringify(e.runKey)} exists in more than one workspace in this session.`,[`Retry with the workspace from the run identity.`]));let r=n[0];if(!r)throw Error(u.withOptions(`No workflow run matches ${JSON.stringify(e.runKey)} in this session.`,[`workflow_run with action status: use a run key from this session before retrying.`,`Tell the user this session did not launch that run rather than guessing a similar key. A run launched by another Pi session, or from the command line, is managed there or with the workflow-mcp CLI.`]));return r},Kt=async e=>{let t=(await M(P,e.workspace)).filter(t=>t.runKey===e.runKey&&t.stage===T);if(t.length>1)throw Error(u.withOptions(`Failed workflow run key ${JSON.stringify(e.runKey)} exists in more than one workspace.`,[`Retry with the workspace from the recovery picker or run identity.`]));let n=t[0];if(!n)throw Error(u.withOptions(`No failed workflow run matches ${JSON.stringify(e.runKey)}.`,[`Use the recovery picker to select an interrupted or failed run, or retry with its workspace.`,`Do not recover a running or completed workflow.`]));return n},qt=async e=>{let t=P.runDirectoryFor(e),n=[(0,p.resolve)(t,`changelog.md`),(0,p.resolve)(t,`context.md`),(0,p.resolve)(t,`progress.ndjson`)],r=[];for(let e of n)try{let t=await(0,ie.readFile)(e,`utf-8`);r.push(`--- ${(0,p.basename)(e)} ---`,t.slice(-65536).trimEnd())}catch(e){if(e.code!==`ENOENT`)throw e}return r.length>0?r:[`No durable recovery evidence files are recorded for this run.`]},Jt=async(e,t)=>{let n=await Kt(e);return await q(t).recordEvent(`doom_workflow.recovery_evidence_requested`,{outcome:`requested`}),[`Workflow: ${ze(n)}`,`--- run.json ---`,JSON.stringify(n,null,2),...await qt(n)].join(`
6
- `)},Yt=async(e,t)=>{let n=Ie();if(!n)return;let r=await Kt(e),i;try{i=We.parseWorkflowFile(r.workflowPath)}catch{return}if(!i[`launch-command`])return;let a=(0,m.resolveRootSessionId)(t.sessionManager.getSessionId()),o=await P.claimRunRecovery(r.workspace,r.runKey,a),s=r.originalRepoPath??t.cwd,c=Fe([process.execPath,n,`recover-workflow`,r.runKey,`--workspace`,r.workspace,`--recovery-claim`,o.claimId,...e.runner?[`--runner`,e.runner]:[]]),l=Pe();try{await Je(process.execPath,[n,`launch-process`,...l?[`--launcher`,l]:[],`--name`,`${r.displayName} recover`,`--cwd`,s,`--command`,c],{cwd:s,env:Ne()})}catch(e){throw await P.releaseRunRecoveryClaim(r.workspace,r.runKey,o.claimId),e}return await q(t).recordEvent(`doom_workflow.recover_delegated`,{launcher:l??`auto`,outcome:`delegated`}),`Recovering ${r.runKey} in a launcher of its own, so this session keeps its terminal. It reports back here when it ends.`},Xt=async(e,t)=>{let n=e;for(;;){let e=[`Open output`],r=n.executionState??C;r===C&&e.push(`Pause`),r===`paused`&&e.push(`Resume`),n.stage===C&&e.push(`Stop`),e.push(`Back`);let i=await s.openWorkflowChoice(t,{title:`Manage ${n.runKey}`,breadcrumb:`SPC › w / workflows › l / manage`,choices:e});if(!i||i===`Back`)return;if(n=await Q(n),n.stage!==C){t.ui.notify(`${n.runKey} is no longer running.`,`warning`);return}if(i===`Open output`){await Wt(n,t);return}if(i===`Stop`){if(!await t.ui.confirm(`Stop ${n.runKey}?`,`The workflow will be interrupted and will not be restarted automatically.`))continue;if(n=await Q(n),n.stage!==C){t.ui.notify(`${n.runKey} is no longer running.`,`warning`);return}}if(i!==`Pause`&&i!==`Resume`&&i!==`Stop`)continue;if(!n.runId)throw Error(`${n.runKey} has no controllable run generation.`);let a=await xt.execute({action:i.toLowerCase(),expectedRunId:n.runId,...i===`Stop`?{reason:`Stopped from the workflow manager.`}:{},runKey:n.runKey,workspace:n.workspace});if(a.isError)throw Error(u.toolResultText(a)||`Unable to ${i.toLowerCase()} workflow.`);t.ui.notify(u.toolResultText(a)||`${i} requested for ${n.runKey}.`,`info`),await Z(t,!1),n=await Q(n)}},Zt=(e,t)=>({editor:(t,n)=>e.ui.editor(t,n),input:(n,r)=>s.openWorkflowInput(e,{title:n,breadcrumb:t,...r?{fallback:r}:{}}),notify:(t,n)=>e.ui.notify(t,n),select:(n,r)=>s.openWorkflowChoice(e,{title:n,breadcrumb:t,choices:r})}),Qt=async e=>{if(!e.hasUI){e.ui.notify(`Workflow launch needs an interactive Pi session.`,`warning`);return}let t=await f.openWorkflowLaunchWizard({compatibleRunners:Re,cwd:e.cwd,launch:(e,t)=>wt.execute(e,t),listWorkflowsTool:v.listWorkflowsTool,parseWorkflow:e=>We.parseWorkflowFile(e),pickWorkflow:t=>a.openWorkflowPickerOverlay(e,{title:`WORKFLOW LAUNCHER`,breadcrumb:me,unit:`workflows`,action:`launch`,filterPlaceholder:`type to filter by name, path or tag`,emptyMessage:`No workflow definitions were found in this repository.`},t.map(e=>({key:e.path,name:e.name,detail:e.relativePath,search:[e.description,...e.tags].join(` `),value:e}))),ui:Zt(e,me)},e);t&&e.ui.notify(u.launchNotice(u.toolResultText(t)),`info`)},$t=async e=>{let t=(await M(P)).filter(e=>e.stage===T);if(t.length===0){e.ui.notify(`No failed workflows are available to recover.`,`info`);return}let n=await a.openWorkflowPickerOverlay(e,{title:`WORKFLOW RECOVERY`,breadcrumb:`SPC › w / workflows › r / recover`,unit:`failed runs`,action:`recover`,filterPlaceholder:`type to filter by name, run key or failed job`,emptyMessage:`No failed workflows are available to recover.`},t.map(e=>({key:`${e.workspace}/${e.runKey}`,name:e.displayName,detail:`${e.workspace}/${e.runKey}${e.failedJob?` · ${e.failedJob}`:``}`,...e.failedJob?{search:e.failedJob}:{},value:e})));if(!n)return;let r=await Kt(n);if(r.stage!==T)throw Error(`${r.runKey} is no longer failed.`);let i=(0,p.resolve)((0,p.dirname)((0,te.fileURLToPath)(require("url").pathToFileURL(__filename).href)),ye,`workflow-recovery`,`SKILL.md`);if(!(0,ee.existsSync)(i))throw Error(`Workflow recovery skill is unavailable at ${i}.`);en(!0),e.ui.notify(`Workflow tools enabled. The agent will investigate this failure and choose the safe next step.`,`info`),g.sendUserMessage([`Investigate recovery for this failed workflow run. This selection is permission to investigate, not permission to recover blindly.`,`Run identity: ${JSON.stringify({runKey:r.runKey,workspace:r.workspace})}`,`Read the package-owned recovery skill with the read tool at ${JSON.stringify(i)} before acting.`,`Inspect status, every relevant log source, process state, the staged run.json, and only the repair referenced by activeRepairId.`,`Choose exactly one outcome: recover, launch fresh, or defer. Never edit issue.md or repair.json, never scan historical repairs, and never pass recovery dryRun or a job override.`,`Do not recover terminal, approval-pending, blocked, or otherwise unsafe work. If evidence is incomplete, defer and explain what is missing.`,`If recovery is justified, preserve the recorded worktree and repair metadata, then verify real process and registry progress before reporting success.`].join(`
7
- `),{deliverAs:`followUp`})},en=e=>{if(!j())return;let t=new Set(g.getActiveTools());for(let n of d.WORKFLOW_PI_TOOL_NAMES)e?t.add(n):t.delete(n);g.setActiveTools([...t]),B=e,Pt(),h.onModeChange?.(e)},tn=()=>B?[`${E.completed} Workflow mode on`,`Ask for workflows in plain language: the agent can list, launch, inspect, pause, resume, stop, and recover runs.`,`${x(y)} stops following a run without stopping it.`].join(`
5
+ `).slice(-24):[`Unable to read ${e.runKey}: ${n.stderr.trim()||`cmux exited ${n.code}`}`]},Lt=new Map,Rt=async e=>{let t=X(e),n=Lt.get(t)??{at:0,lines:[]};if(Lt.set(t,n),n.inFlight||Date.now()-n.at<750)return n.lines;n.inFlight=It(e);try{n.lines=await n.inFlight}finally{n.at=Date.now(),n.inFlight=void 0}return n.lines},zt=e=>{for(let t of Lt.keys())e.has(t)||Lt.delete(t)},Bt=async e=>{let t=e.launcher;if(!t)return je;if(Ae(e))return ke;if(t.type===Oe)return`This run is hosted natively rather than in a multiplexer, so there is no separate window to bring forward.`;if(t.type===A)return await g.exec(A,[`select-workspace`,`--workspace`,t.workspaceId],{timeout:S}),`Opened ${e.runKey} in cmux.`;if(!process.env.TMUX)return`Pi is not attached to tmux. Follow the output instead, or attach to the recorded tmux session manually.`;let n=t.sessionId??t.sessionName,r=await g.exec(k,[`switch-client`,`-t`,n],{timeout:S});return r.code===0?(t.paneId&&await g.exec(k,[`select-pane`,`-t`,t.paneId],{timeout:S}),`Opened ${e.runKey} in tmux.`):r.stderr.trim()||`Unable to open tmux session ${n}.`},Vt=async(e,t)=>{if(!Qe){Qe=!0;try{let n=(0,_.summarizeWorkflowProgress)(Te(e,await(0,_.readWorkflowProgress)(P.runDirectoryFor(e)))),r=n.length>0?void 0:await Rt(e);t.ui.setWidget(ue,(t,i)=>({render:t=>Ce(e,r??we(n,i,t),i,t),invalidate:()=>{}}),{placement:`aboveEditor`})}finally{Qe=!1}}},Ht=async(e,t)=>{Ft(t),L=e,await Vt(e,t),I=setInterval(()=>{L&&Vt(L,t)},Xe),I.unref?.()},Ut=async(e,t)=>{let n=e.launcher;if(!(!n||n.type===Oe||Ae(e))){if(n.type===k){let e=n.paneId??n.sessionId??n.sessionName;await g.exec(k,[`send-keys`,`-t`,e,`-l`,t],{timeout:S});return}await g.exec(A,[`send`,`--workspace`,n.workspaceId,t],{timeout:S})}},Wt=async(e,t)=>{Nt();let n=!Ae(e)&&(e.launcher?.type===k||e.launcher?.type===A),r=new i.TerminalInputBatcher(t=>Ut(e,t)),a=[],o=[],s,l=!1,u=async()=>{a=(0,_.summarizeWorkflowProgress)(Te(e,await(0,_.readWorkflowProgress)(P.runDirectoryFor(e)))),o=await Rt(e)};await u();let d=()=>{s&&clearInterval(s),s=void 0,r.dispose()},f={interactive:n,runKey:e.runKey,teardown:d};U=f;let ee=()=>{Nt(),t.ui.notify(`Closed the ${e.runKey} view. The run keeps going.`,`info`)};return t.ui.custom((i,p,te,m)=>(s=setInterval(()=>{l||(l=!0,u().finally(()=>{l=!1,i.requestRender()}))},200),s.unref?.(),new c.WorkflowRunPanelComponent(i,p,{runKey:e.runKey,label:`${T.running} ${ze(e)}`,breadcrumb:`SPC › w / workflows › run`,interactive:n,footer:xe(n),hints:Se(n),snapshot:e=>({progress:we(a,p,e),output:o}),onUnfollow:()=>{f.handle?.unfocus(),t.ui.notify(`Typing goes to this session. The run keeps going.`,`info`)},onClose:ee,sendInput:e=>r.write(e),flushInput:()=>void r.flush(),unfollowShortcut:y,closeShortcut:b,onDispose:()=>{d(),U===f&&(U=void 0),m()}})),{...c.runPanelUiOptions(n),onHandle:e=>{f.handle=e}}),t.ui.notify(n?`${e.runKey}: typing goes to the run. Press Esc twice to close, ${x(y)} to type here instead.`:`${e.runKey}: view only, because this run is hosted natively. ${x(b)} closes it.`,`info`),n?[`Showing ${e.runKey} over Pi. Typing goes to the run.`,`Pressing Escape twice quickly closes the view, and a single Escape still reaches the run.`,`${x(y)} moves typing between the run and this session,`,`and ${x(b)} closes the view. The run keeps going either way.`].join(` `):[`Showing ${e.runKey} over Pi, as a view only:`,`the run is hosted natively rather than in a multiplexer, so there is no terminal to type into.`,`Typing stays with this session, and ${x(b)} closes the view.`].join(` `)},Gt=async(e,t=!1)=>{if(!(at||U||L)){at=!0;try{let n=await e.ui.custom((e,t,n,i)=>new r.WorkflowInspectorComponent(e,t,{list:async()=>{let e=vt(),t=(await M(P)).filter(t=>t.stage===C&&!t.stale&&u.isSessionRun(t,e));return ot=new Map(t.map(e=>[X(e),e])),Promise.all(t.map(async e=>({displayName:e.displayName,executionState:e.executionState,jobs:(0,_.summarizeWorkflowProgress)(Te(e,await(0,_.readWorkflowProgress)(P.runDirectoryFor(e)))),key:X(e),output:[],runKey:e.runKey,startedAt:e.startedAt,workspace:e.workspace})))},output:async e=>{let t=ot.get(e.key);return t?Rt(t):[`Workflow is no longer active.`]}},i),{...le,onHandle:e=>{W=e}});if(n){let r=await Q(n);t?await Xt(r,e):await Wt(r,e)}}finally{W=void 0,at=!1,ot.clear()}}},Q=async(e,t=vt())=>{_t(t);let n=(await M(P,e.workspace)).filter(n=>n.runKey===e.runKey&&u.isSessionRun(n,t));if(n.length>1)throw Error(u.withOptions(`Workflow run key ${JSON.stringify(e.runKey)} exists in more than one workspace in this session.`,[`Retry with the workspace from the run identity.`]));let r=n[0];if(!r)throw Error(u.withOptions(`No workflow run matches ${JSON.stringify(e.runKey)} in this session.`,[`workflow_run with action status: use a run key from this session before retrying.`,`Tell the user this session did not launch that run rather than guessing a similar key. A run launched by another Pi session, or from the command line, is managed there or with the workflow-mcp CLI.`]));return r},Kt=async e=>{let t=(await M(P,e.workspace)).filter(t=>t.runKey===e.runKey&&t.stage===_e);if(t.length>1)throw Error(u.withOptions(`Failed workflow run key ${JSON.stringify(e.runKey)} exists in more than one workspace.`,[`Retry with the workspace from the recovery picker or run identity.`]));let n=t[0];if(!n)throw Error(u.withOptions(`No failed workflow run matches ${JSON.stringify(e.runKey)}.`,[`Use the recovery picker to select an interrupted or failed run, or retry with its workspace.`,`Do not recover a running or completed workflow.`]));return n},qt=async e=>{let t=P.runDirectoryFor(e),n=[(0,p.resolve)(t,`changelog.md`),(0,p.resolve)(t,`context.md`),(0,p.resolve)(t,`progress.ndjson`)],r=[];for(let e of n)try{let t=await(0,ie.readFile)(e,`utf-8`);r.push(`--- ${(0,p.basename)(e)} ---`,t.slice(-65536).trimEnd())}catch(e){if(e.code!==`ENOENT`)throw e}return r.length>0?r:[`No durable recovery evidence files are recorded for this run.`]},Jt=async(e,t)=>{let n=await Kt(e);return await q(t).recordEvent(`doom_workflow.recovery_evidence_requested`,{outcome:`requested`}),[`Workflow: ${ze(n)}`,`--- run.json ---`,JSON.stringify(n,null,2),...await qt(n)].join(`
6
+ `)},Yt=async(e,t)=>{let n=Ie();if(!n)return;let r=await Kt(e),i;try{i=We.parseWorkflowFile(r.workflowPath)}catch{return}if(!i[`launch-command`])return;let a=(0,m.resolveRootSessionId)(t.sessionManager.getSessionId()),o=await P.claimRunRecovery(r.workspace,r.runKey,a),s=r.originalRepoPath??t.cwd,c=Fe([process.execPath,n,`recover-workflow`,r.runKey,`--workspace`,r.workspace,`--recovery-claim`,o.claimId,...e.runner?[`--runner`,e.runner]:[]]),l=Pe();try{await Je(process.execPath,[n,`launch-process`,...l?[`--launcher`,l]:[],`--name`,`${r.displayName} recover`,`--cwd`,s,`--command`,c],{cwd:s,env:Ne()})}catch(e){throw await P.releaseRunRecoveryClaim(r.workspace,r.runKey,o.claimId),e}return await q(t).recordEvent(`doom_workflow.recover_delegated`,{launcher:l??`auto`,outcome:`delegated`}),`Recovering ${r.runKey} in a launcher of its own, so this session keeps its terminal. It reports back here when it ends.`},Xt=async(e,t)=>{let n=e;for(;;){let e=[`Open output`],r=n.executionState??C;r===C&&e.push(`Pause`),r===`paused`&&e.push(`Resume`),n.stage===C&&e.push(`Stop`),e.push(`Back`);let i=await s.openWorkflowChoice(t,{title:`Manage ${n.runKey}`,breadcrumb:`SPC › w / workflows › r / runs`,choices:e});if(!i||i===`Back`)return;if(n=await Q(n),n.stage!==C){t.ui.notify(`${n.runKey} is no longer running.`,`warning`);return}if(i===`Open output`){await Wt(n,t);return}if(i===`Stop`){if(!await t.ui.confirm(`Stop ${n.runKey}?`,`The workflow will be interrupted and will not be restarted automatically.`))continue;if(n=await Q(n),n.stage!==C){t.ui.notify(`${n.runKey} is no longer running.`,`warning`);return}}if(i!==`Pause`&&i!==`Resume`&&i!==`Stop`)continue;if(!n.runId)throw Error(`${n.runKey} has no controllable run generation.`);let a=await xt.execute({action:i.toLowerCase(),expectedRunId:n.runId,...i===`Stop`?{reason:`Stopped from the workflow manager.`}:{},runKey:n.runKey,workspace:n.workspace});if(a.isError)throw Error(u.toolResultText(a)||`Unable to ${i.toLowerCase()} workflow.`);t.ui.notify(u.toolResultText(a)||`${i} requested for ${n.runKey}.`,`info`),await Z(t,!1),n=await Q(n)}},Zt=(e,t)=>({editor:(t,n)=>e.ui.editor(t,n),input:(n,r)=>s.openWorkflowInput(e,{title:n,breadcrumb:t,...r?{fallback:r}:{}}),notify:(t,n)=>e.ui.notify(t,n),select:(n,r)=>s.openWorkflowChoice(e,{title:n,breadcrumb:t,choices:r})}),Qt=async e=>{if(!e.hasUI){e.ui.notify(`Workflow launch needs an interactive Pi session.`,`warning`);return}let t=await f.openWorkflowLaunchWizard({compatibleRunners:Re,cwd:e.cwd,launch:(e,t)=>wt.execute(e,t),listWorkflowsTool:v.listWorkflowsTool,parseWorkflow:e=>We.parseWorkflowFile(e),pickWorkflow:t=>a.openWorkflowPickerOverlay(e,{title:`WORKFLOW LAUNCHER`,breadcrumb:me,unit:`workflows`,action:`launch`,filterPlaceholder:`type to filter by name, path or tag`,emptyMessage:`No workflow definitions were found in this repository.`},t.map(e=>({key:e.path,name:e.name,detail:e.relativePath,search:[e.description,...e.tags].join(` `),value:e}))),ui:Zt(e,me)},e);t&&e.ui.notify(u.launchNotice(u.toolResultText(t)),`info`)},$t=async e=>{if(!e.hasUI){e.ui.notify(`The workflow list needs an interactive Pi session.`,`warning`);return}let t=await f.loadWorkflowCatalog(v.listWorkflowsTool,e.cwd);await a.openWorkflowPickerOverlay(e,{title:`WORKFLOWS`,breadcrumb:`SPC › w / workflows › l / list`,unit:`workflows`,action:`close`,filterPlaceholder:`type to filter by name, path or tag`,emptyMessage:`No workflow definitions were found in this repository.`},t.map(e=>({key:e.path,name:e.name,detail:e.relativePath,search:[e.description,...e.tags].join(` `),value:e})))},en=async e=>{let t=(await M(P)).filter(e=>e.stage===_e);if(t.length===0){e.ui.notify(`No failed workflows are available to recover.`,`info`);return}let n=await a.openWorkflowPickerOverlay(e,{title:`WORKFLOW RECOVERY`,breadcrumb:`SPC › w / workflows › c / recover`,unit:`failed runs`,action:`recover`,filterPlaceholder:`type to filter by name, run key or failed job`,emptyMessage:`No failed workflows are available to recover.`},t.map(e=>({key:`${e.workspace}/${e.runKey}`,name:e.displayName,detail:`${e.workspace}/${e.runKey}${e.failedJob?` · ${e.failedJob}`:``}`,...e.failedJob?{search:e.failedJob}:{},value:e})));if(!n)return;let r=await Kt(n);if(r.stage!==_e)throw Error(`${r.runKey} is no longer failed.`);let i=(0,p.resolve)((0,p.dirname)((0,te.fileURLToPath)(require("url").pathToFileURL(__filename).href)),be,`workflow-recovery`,`SKILL.md`);if(!(0,ee.existsSync)(i))throw Error(`Workflow recovery skill is unavailable at ${i}.`);tn(!0),e.ui.notify(`Workflow tools enabled. The agent will investigate this failure and choose the safe next step.`,`info`),g.sendUserMessage([`Investigate recovery for this failed workflow run. This selection is permission to investigate, not permission to recover blindly.`,`Run identity: ${JSON.stringify({runKey:r.runKey,workspace:r.workspace})}`,`Read the package-owned recovery skill with the read tool at ${JSON.stringify(i)} before acting.`,`Inspect status, every relevant log source, process state, the staged run.json, and only the repair referenced by activeRepairId.`,`Choose exactly one outcome: recover, launch fresh, or defer. Never edit issue.md or repair.json, never scan historical repairs, and never pass recovery dryRun or a job override.`,`Do not recover terminal, approval-pending, blocked, or otherwise unsafe work. If evidence is incomplete, defer and explain what is missing.`,`If recovery is justified, preserve the recorded worktree and repair metadata, then verify real process and registry progress before reporting success.`].join(`
7
+ `),{deliverAs:`followUp`})},tn=e=>{if(!j())return;let t=new Set(g.getActiveTools());for(let n of d.WORKFLOW_PI_TOOL_NAMES)e?t.add(n):t.delete(n);g.setActiveTools([...t]),B=e,Pt(),h.onModeChange?.(e)},nn=()=>B?[`${T.completed} Workflow mode on`,`Ask for workflows in plain language: the agent can list, launch, inspect, pause, resume, stop, and recover runs.`,`${x(y)} stops following a run without stopping it.`].join(`
8
8
  `):[`Workflow mode off`,`Press SPC w e to give the agent its workflow tools. Runs already going are unaffected.`].join(`
9
- `),nn=async(e,t)=>{en(e),B||Ft(t),t.ui.notify(tn(),`info`),await Z(t,!1)};g.registerShortcut(y,{description:`Open workflows or move typing between a workflow run and this session`,handler:async e=>{await N();let t=U?.handle;if(t){if(!U?.interactive){e.ui.notify(`This run is hosted natively, so the view takes no typing. Your keys stay here.`,`info`);return}t.isFocused()?(t.unfocus(),e.ui.notify(`Typing goes to this session. The run keeps going.`,`info`)):(t.focus(),e.ui.notify(`Typing goes to ${U?.runKey}.`,`info`));return}if(L){Ft(e),e.ui.notify(`Workflow continues in the background.`,`info`);return}await Gt(e)}}),g.registerShortcut(b,{description:`Close the workflow run view`,handler:async e=>{if(await N(),!U)return;let t=U.runKey;Nt(),e.ui.notify(`Closed the ${t} view. The run keeps going.`,`info`)}}),g.on(`resources_discover`,()=>{if(!B)return{skillPaths:[]};let e=(0,p.resolve)((0,p.dirname)((0,te.fileURLToPath)(require("url").pathToFileURL(__filename).href)),ye);return{skillPaths:(0,ee.existsSync)(e)?[e]:[]}}),g.registerMessageRenderer(`workflow-step`,(e,{outputPad:t},n)=>{let r=l.isWorkflowStepMessageDetails(e.details)?e.details:void 0,i=typeof e.content==`string`?e.content:JSON.stringify(e.content);return l.renderWorkflowStepMessage(r,i,t,n)}),d.registerWorkflowPiTools(Ue,{runTool:qe,recoverTool:bt,launchExecutor:wt,controlTool:xt,requireSessionRun:Q,requireRecoverableRun:Kt,readRecoveryEvidence:Jt,delegateRecovery:Yt,trackPendingRun:St,observeSession:_t,activeRunCount:async()=>z,onLaunch:async e=>(await q(e).recordEvent(ve,{outcome:`requested`}),Z(e,!1)),followRun:async(e,t)=>{let n=await Q(e,t.sessionManager.getSessionId());return await q(t).recordEvent(`doom_workflow.follow_started`,{outcome:`started`}),await Ht(n,t),`Following ${ze(n)}. Press ${x(y)} to stop following; the run keeps going.`},tailRun:async(e,t)=>{let n=await Q(e,t.sessionManager.getSessionId());return await q(t).recordEvent(`doom_workflow.tail_requested`,{outcome:`requested`}),[`Workflow: ${ze(n)}`,`Stage: ${Te(n)}`,`Raw launcher output is hidden from chat. Use action follow or open to view it.`].join(`
10
- `)},openRun:async(e,t)=>{let n=await Q(e,t.sessionManager.getSessionId());return await q(t).recordEvent(`doom_workflow.open_requested`,{outcome:`requested`}),t.hasUI?Wt(n,t):Bt(n)},rejectRunner:Ct});let rn;h.cordis?.inject([ne.DOOM_UI_HUB_SERVICE],t=>{let n=(0,ne.requireDoomUiHub)(t).registerLeaderActions({source:e.PACKAGE_SOURCE,handlers:{[e.LEADER_ENABLE_ACTION]:async e=>(await N(),nn(!0,e)),[e.LEADER_DISABLE_ACTION]:async e=>(await N(),nn(!1,e)),[e.LEADER_MANAGE_ACTION]:async e=>(await N(),Gt(e,!0)),[e.LEADER_LAUNCH_ACTION]:async e=>(await N(),Qt(e)),[e.LEADER_RECOVER_ACTION]:async e=>(await N(),$t(e))},onError:(e,t,n)=>{n.ui.notify(e instanceof Error?e.message:String(e),`error`)}});return rn=n,()=>{n(),rn===n&&(rn=void 0)}}),g.on(`session_start`,(t,n)=>{if(!w||!De())return;let r=++_e,i=O;D?.abort();let a=new AbortController;D=a,H=n;let o=()=>w&&r===_e&&H===n&&De();Mt(),F&&clearInterval(F),F=void 0,nt?.update([]),Ft(n),W?.hide(),W=void 0,at=!1,ot.clear(),Nt(),Lt.clear(),dt.setUICtx(n.ui),q(n).recordEvent(`doom_workflow.session_started`,{mode:process.env.WORKFLOW_MCP_MODE===`on`?`on`:`off`,outcome:`started`});let s=n.sessionManager.getSessionId(),c=(0,m.resolveRootSessionId)(s);_t(c),tt=Date.now(),rt=!1,$e=new Map,R.clear(),et.clear(),en(h.initialMode??process.env.WORKFLOW_MCP_MODE===`on`);let l=Ve(n);O=(async()=>{if(i&&await Promise.allSettled([i.then(e=>e.wait())]),!o())throw Error(`Workflow session initialization was superseded.`);return l.start(e.PACKAGE_SOURCE,`${he}:${r}`,async e=>{let t=()=>a.signal.aborted||!o();return e.throwIfAborted(),t()||(await jt(n),e.throwIfAborted(),t())||(await Z(n,!1),e.throwIfAborted(),t())?{value:void 0}:(rt=!0,F=setInterval(()=>{o()&&Z(n,!0)},Ye),F.unref?.(),{value:void 0})})})(),Promise.allSettled([O.then(e=>e.wait())])});let $=async(e,t)=>{try{await t()}catch(t){process.emitWarning(`Doom-workflow cleanup could not ${e}: ${String(t)}`)}},an;return{dispose:(e=H)=>(an??=(async()=>{if(!w)return;w=!1,_e+=1;let t=O;O=void 0,D?.abort(),D=void 0,await $(`stop the workflow observer`,Mt);let n=Ee;if(Ee=void 0,n?await $(`dispose standalone workflow readiness`,()=>n.dispose()):t&&await Promise.allSettled([t.then(e=>e.wait())]),J.size>0){for(let e of[Ke,Ge])await $(`interrupt an inline workflow`,()=>e.interrupt(`SIGTERM`,{phase:`workflow`,source:`pi-session-shutdown`}));await Promise.race([Promise.allSettled(J),new Promise(e=>setTimeout(e,1e4).unref?.())])}F&&clearInterval(F),F=void 0,Y&&clearTimeout(Y),Y=void 0;let r=nt;nt=void 0,r&&await $(`unregister the background-work provider`,()=>r.dispose()),rt=!1,W?.hide(),W=void 0,at=!1,ot.clear(),Lt.clear(),Nt(),z=0,e?Ft(e):I&&clearInterval(I),I=void 0,L=void 0,dt.dispose(),B=!1,it=void 0;let i=V;V=void 0,i&&(await $(`publish the inactive workflow mode`,()=>i.publish(pe(!1,0))),await $(`dispose the workflow mode owner`,()=>i.dispose()));let a=rn;rn=void 0,a&&await $(`dispose workflow leader actions`,a);let o=J.size,s=pt;pt=void 0,s&&(await $(`record the workflow session finish`,()=>s.recordEvent(`doom_workflow.session_finished`,{"workflow.pending_count":o,outcome:o===0?`completed`:`interrupted`})),await $(`stop workflow telemetry`,()=>s.shutdown())),J.clear(),R.clear(),et.clear(),ct.length=0,ft=void 0,H=void 0})(),an)}}}exports.compatibleRunners=Re,exports.installWorkflowPiRuntime=Be,exports.panelHint=be,exports.panelHints=xe,exports.shortcutLabel=x;
9
+ `),rn=async(e,t)=>{tn(e),B||Ft(t),t.ui.notify(nn(),`info`),await Z(t,!1)};g.registerShortcut(y,{description:`Open workflows or move typing between a workflow run and this session`,handler:async e=>{await N();let t=U?.handle;if(t){if(!U?.interactive){e.ui.notify(`This run is hosted natively, so the view takes no typing. Your keys stay here.`,`info`);return}t.isFocused()?(t.unfocus(),e.ui.notify(`Typing goes to this session. The run keeps going.`,`info`)):(t.focus(),e.ui.notify(`Typing goes to ${U?.runKey}.`,`info`));return}if(L){Ft(e),e.ui.notify(`Workflow continues in the background.`,`info`);return}await Gt(e)}}),g.registerShortcut(b,{description:`Close the workflow run view`,handler:async e=>{if(await N(),!U)return;let t=U.runKey;Nt(),e.ui.notify(`Closed the ${t} view. The run keeps going.`,`info`)}}),g.on(`resources_discover`,()=>{if(!B)return{skillPaths:[]};let e=(0,p.resolve)((0,p.dirname)((0,te.fileURLToPath)(require("url").pathToFileURL(__filename).href)),be);return{skillPaths:(0,ee.existsSync)(e)?[e]:[]}}),g.registerMessageRenderer(`workflow-step`,(e,{outputPad:t},n)=>{let r=l.isWorkflowStepMessageDetails(e.details)?e.details:void 0,i=typeof e.content==`string`?e.content:JSON.stringify(e.content);return l.renderWorkflowStepMessage(r,i,t,n)}),d.registerWorkflowPiTools(Ue,{runTool:qe,recoverTool:bt,launchExecutor:wt,controlTool:xt,requireSessionRun:Q,requireRecoverableRun:Kt,readRecoveryEvidence:Jt,delegateRecovery:Yt,trackPendingRun:St,observeSession:_t,activeRunCount:async()=>z,onLaunch:async e=>(await q(e).recordEvent(ye,{outcome:`requested`}),Z(e,!1)),followRun:async(e,t)=>{let n=await Q(e,t.sessionManager.getSessionId());return await q(t).recordEvent(`doom_workflow.follow_started`,{outcome:`started`}),await Ht(n,t),`Following ${ze(n)}. Press ${x(y)} to stop following; the run keeps going.`},tailRun:async(e,t)=>{let n=await Q(e,t.sessionManager.getSessionId());return await q(t).recordEvent(`doom_workflow.tail_requested`,{outcome:`requested`}),[`Workflow: ${ze(n)}`,`Stage: ${Ee(n)}`,`Raw launcher output is hidden from chat. Use action follow or open to view it.`].join(`
10
+ `)},openRun:async(e,t)=>{let n=await Q(e,t.sessionManager.getSessionId());return await q(t).recordEvent(`doom_workflow.open_requested`,{outcome:`requested`}),t.hasUI?Wt(n,t):Bt(n)},rejectRunner:Ct});let an;h.cordis?.inject([ne.DOOM_UI_HUB_SERVICE],t=>{let n=(0,ne.requireDoomUiHub)(t).registerLeaderActions({source:e.PACKAGE_SOURCE,handlers:{[e.LEADER_ENABLE_ACTION]:async e=>(await N(),rn(!0,e)),[e.LEADER_DISABLE_ACTION]:async e=>(await N(),rn(!1,e)),[e.LEADER_MANAGE_ACTION]:async e=>(await N(),Gt(e,!0)),[e.LEADER_CATALOG_ACTION]:async e=>(await N(),$t(e)),[e.LEADER_LAUNCH_ACTION]:async e=>(await N(),Qt(e)),[e.LEADER_RECOVER_ACTION]:async e=>(await N(),en(e))},onError:(e,t,n)=>{n.ui.notify(e instanceof Error?e.message:String(e),`error`)}});return an=n,()=>{n(),an===n&&(an=void 0)}}),g.on(`session_start`,(t,n)=>{if(!w||!De())return;let r=++ve,i=D;E?.abort();let a=new AbortController;E=a,H=n;let o=()=>w&&r===ve&&H===n&&De();Mt(),F&&clearInterval(F),F=void 0,nt?.update([]),Ft(n),W?.hide(),W=void 0,at=!1,ot.clear(),Nt(),Lt.clear(),dt.setUICtx(n.ui),q(n).recordEvent(`doom_workflow.session_started`,{mode:process.env.WORKFLOW_MCP_MODE===`on`?`on`:`off`,outcome:`started`});let s=n.sessionManager.getSessionId(),c=(0,m.resolveRootSessionId)(s);_t(c),tt=Date.now(),rt=!1,$e=new Map,R.clear(),et.clear(),tn(h.initialMode??process.env.WORKFLOW_MCP_MODE===`on`);let l=Ve(n);D=(async()=>{if(i&&await Promise.allSettled([i.then(e=>e.wait())]),!o())throw Error(`Workflow session initialization was superseded.`);return l.start(e.PACKAGE_SOURCE,`${he}:${r}`,async e=>{let t=()=>a.signal.aborted||!o();return e.throwIfAborted(),t()||(await jt(n),e.throwIfAborted(),t())||(await Z(n,!1),e.throwIfAborted(),t())?{value:void 0}:(rt=!0,F=setInterval(()=>{o()&&Z(n,!0)},Ye),F.unref?.(),{value:void 0})})})(),Promise.allSettled([D.then(e=>e.wait())])});let $=async(e,t)=>{try{await t()}catch(t){process.emitWarning(`Doom-workflow cleanup could not ${e}: ${String(t)}`)}},on;return{dispose:(e=H)=>(on??=(async()=>{if(!w)return;w=!1,ve+=1;let t=D;D=void 0,E?.abort(),E=void 0,await $(`stop the workflow observer`,Mt);let n=O;if(O=void 0,n?await $(`dispose standalone workflow readiness`,()=>n.dispose()):t&&await Promise.allSettled([t.then(e=>e.wait())]),J.size>0){for(let e of[Ke,Ge])await $(`interrupt an inline workflow`,()=>e.interrupt(`SIGTERM`,{phase:`workflow`,source:`pi-session-shutdown`}));await Promise.race([Promise.allSettled(J),new Promise(e=>setTimeout(e,1e4).unref?.())])}F&&clearInterval(F),F=void 0,Y&&clearTimeout(Y),Y=void 0;let r=nt;nt=void 0,r&&await $(`unregister the background-work provider`,()=>r.dispose()),rt=!1,W?.hide(),W=void 0,at=!1,ot.clear(),Lt.clear(),Nt(),z=0,e?Ft(e):I&&clearInterval(I),I=void 0,L=void 0,dt.dispose(),B=!1,it=void 0;let i=V;V=void 0,i&&(await $(`publish the inactive workflow mode`,()=>i.publish(pe(!1,0))),await $(`dispose the workflow mode owner`,()=>i.dispose()));let a=an;an=void 0,a&&await $(`dispose workflow leader actions`,a);let o=J.size,s=pt;pt=void 0,s&&(await $(`record the workflow session finish`,()=>s.recordEvent(`doom_workflow.session_finished`,{"workflow.pending_count":o,outcome:o===0?`completed`:`interrupted`})),await $(`stop workflow telemetry`,()=>s.shutdown())),J.clear(),R.clear(),et.clear(),ct.length=0,ft=void 0,H=void 0})(),on)}}}exports.compatibleRunners=Re,exports.installWorkflowPiRuntime=Be,exports.panelHint=xe,exports.panelHints=Se,exports.shortcutLabel=x;
11
11
  //# sourceMappingURL=piExtension.cjs.map