@agimon-ai/doompi-workflow 0.0.1-alpha.34 → 0.0.1-alpha.36
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 +2 -2
- package/dist/adapters/pi/leader.cjs +1 -1
- package/dist/adapters/pi/leader.cjs.map +1 -1
- package/dist/adapters/pi/leader.mjs +1 -1
- package/dist/adapters/pi/leader.mjs.map +1 -1
- package/dist/adapters/pi/workflow/piExtension.cjs +8 -8
- package/dist/adapters/pi/workflow/piExtension.cjs.map +1 -1
- package/dist/adapters/pi/workflow/piExtension.mjs +8 -8
- package/dist/adapters/pi/workflow/piExtension.mjs.map +1 -1
- package/dist/adapters/pi/workflow/piTools.cjs +3 -3
- package/dist/adapters/pi/workflow/piTools.mjs +3 -3
- package/dist/adapters/pi/workflow/workflowLauncher.cjs +1 -1
- package/dist/adapters/pi/workflow/workflowLauncher.cjs.map +1 -1
- package/dist/adapters/pi/workflow/workflowLauncher.mjs +1 -1
- package/dist/adapters/pi/workflow/workflowLauncher.mjs.map +1 -1
- package/dist/schemas/workflowPi.cjs +1 -1
- package/dist/schemas/workflowPi.cjs.map +1 -1
- package/dist/schemas/workflowPi.mjs +1 -1
- package/dist/schemas/workflowPi.mjs.map +1 -1
- package/dist/tui/workflow/overlayText.cjs +1 -1
- package/dist/tui/workflow/overlayText.cjs.map +1 -1
- package/dist/tui/workflow/overlayText.mjs +1 -1
- package/dist/tui/workflow/overlayText.mjs.map +1 -1
- package/dist/tui/workflow/terminalGrid.cjs +2 -0
- package/dist/tui/workflow/terminalGrid.cjs.map +1 -0
- package/dist/tui/workflow/terminalGrid.mjs +2 -0
- package/dist/tui/workflow/terminalGrid.mjs.map +1 -0
- package/dist/tui/workflow/workflowCatalog.cjs +2 -0
- package/dist/tui/workflow/workflowCatalog.cjs.map +1 -0
- package/dist/tui/workflow/workflowCatalog.mjs +2 -0
- package/dist/tui/workflow/workflowCatalog.mjs.map +1 -0
- package/dist/tui/workflow/workflowFinishedMessage.cjs +3 -0
- package/dist/tui/workflow/workflowFinishedMessage.cjs.map +1 -0
- package/dist/tui/workflow/workflowFinishedMessage.mjs +3 -0
- package/dist/tui/workflow/workflowFinishedMessage.mjs.map +1 -0
- package/dist/tui/workflow/workflowInspector.cjs +1 -1
- package/dist/tui/workflow/workflowInspector.cjs.map +1 -1
- package/dist/tui/workflow/workflowInspector.mjs +1 -1
- package/dist/tui/workflow/workflowInspector.mjs.map +1 -1
- package/dist/tui/workflow/workflowPicker.cjs.map +1 -1
- package/dist/tui/workflow/workflowPicker.mjs.map +1 -1
- package/dist/tui/workflow/workflowRunPanel.cjs +1 -1
- package/dist/tui/workflow/workflowRunPanel.cjs.map +1 -1
- package/dist/tui/workflow/workflowRunPanel.mjs +1 -1
- package/dist/tui/workflow/workflowRunPanel.mjs.map +1 -1
- package/dist/types/index.cjs +1 -1
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.mjs +1 -1
- package/dist/types/index.mjs.map +1 -1
- package/package.json +12 -4
- package/src/prompts/doompi-use-workflow/SKILL.md +1 -1
package/README.md
CHANGED
|
@@ -65,8 +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
|
|
69
|
-
session's runs, `SPC w c` opens recovery, and `SPC w e`
|
|
68
|
+
In the TUI, `SPC w l` lists the repository's workflows and launches the one under the cursor with
|
|
69
|
+
`r`, `SPC w r` inspects this session's runs, `SPC w c` opens recovery, and `SPC w e`
|
|
70
70
|
toggles model-visible tools. The root session can launch; child sessions can inspect the catalog but
|
|
71
71
|
do not receive an unrestricted workflow factory.
|
|
72
72
|
|
|
@@ -1,2 +1,2 @@
|
|
|
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:`
|
|
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:`browse and launch workflows`}],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}},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_DETAIL","LEADER_CATALOG_ACTION","LEADER_MANAGE_ACTION","
|
|
1
|
+
{"version":3,"file":"leader.cjs","names":["LEADER_LABEL","LEADER_DETAIL","LEADER_CATALOG_ACTION","LEADER_MANAGE_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_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 // Launching lives on this board's own `r` key rather than a second menu\n // entry: picking which workflow to run is the same act as reading what\n // one does.\n path: [GROUP_SEGMENT, { key: 'l', label: 'list', detail: 'browse and launch workflows' }],\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 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":"yCAeM,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,UAI7B,KAAM,CAAC,EAAe,CAAE,IAAK,IAAK,MAAO,OAAQ,OAAQ,6BAA8B,CAAC,EACxF,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,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_CATALOG_ACTION as e,LEADER_DETAIL as t,LEADER_DISABLE_ACTION as n,LEADER_ENABLE_ACTION as r,LEADER_LABEL as i,
|
|
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_MANAGE_ACTION as a,LEADER_RECOVER_ACTION as o,PACKAGE_SOURCE as s}from"../../types/index.mjs";const c=`doom-workflow`,l={key:`w`,label:i,detail:t,order:50};function u(t){return[{id:`${c}.catalog`,path:[l,{key:`l`,label:`list`,detail:`browse and launch workflows`}],action:{name:e}},{id:`${c}.manage`,path:[l,{key:`r`,label:`runs`,detail:`runs in this session`}],action:{name:a}},t?{id:`${c}.disable`,path:[l,{key:`e`,label:`exit`,detail:`take back workflow tools`,tone:`exit`}],action:{name:n}}:{id:`${c}.enable`,path:[l,{key:`e`,label:`enter`,detail:`give the agent workflow tools`}],action:{name:r}},{id:`${c}.recover`,path:[l,{key:`c`,label:`recover`,detail:`adopt a failed run`}],action:{name:o}}]}function d(e,t=!1){let n=e.registerLeader({source:s,bindings:u(t)});return{setMode(e){n.update(u(e))},dispose(){n.dispose()}}}export{d as registerLeaderContribution,u 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_CATALOG_ACTION,\n LEADER_DETAIL,\n LEADER_DISABLE_ACTION,\n LEADER_ENABLE_ACTION,\n LEADER_KEY,\n LEADER_LABEL,\n
|
|
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_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 // Launching lives on this board's own `r` key rather than a second menu\n // entry: picking which workflow to run is the same act as reading what\n // one does.\n path: [GROUP_SEGMENT, { key: 'l', label: 'list', detail: 'browse and launch workflows' }],\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 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":"iOAeA,MAAM,EAAwB,gBACxB,EAAgB,CACpB,IAAA,IACA,MAAO,EACP,OAAQ,EACR,MAAA,EACF,EAeA,SAAgB,EAAuB,EAAgC,CACrE,MAAO,CACL,CACE,GAAI,GAAG,EAAsB,UAI7B,KAAM,CAAC,EAAe,CAAE,IAAK,IAAK,MAAO,OAAQ,OAAQ,6BAA8B,CAAC,EACxF,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,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`,_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(`
|
|
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("../../../schemas/workflowPi.cjs"),o=require("../../../tui/workflow/terminalGrid.cjs"),s=require("../../../tui/workflow/workflowFinishedMessage.cjs"),c=require("../../../tui/workflow/workflowCatalog.cjs"),l=require("../../../tui/workflow/workflowPicker.cjs"),u=require("../../../tui/workflow/workflowProgressOverlay.cjs"),d=require("../../../tui/workflow/workflowPrompt.cjs"),ee=require("../../../tui/workflow/workflowRunPanel.cjs"),te=require("../../../tui/workflow/workflowStepMessage.cjs"),f=require("./piToolBridge.cjs"),ne=require("./piTools.cjs"),re=require("./workflowLauncher.cjs");let ie=require("node:fs"),p=require("node:path"),ae=require("node:url"),m=require("@agimon-ai/doompi-extension-contracts/child-process"),oe=require("@agimon-ai/doompi-extension-contracts/ui-hub"),h=require("node:child_process"),se=require("node:crypto"),ce=require("node:fs/promises"),g=require("node:module"),le=require("@agimon-ai/doompi-extension-contracts/mode"),ue=require("@agimon-ai/doompi-extension-contracts/narration"),de=require("@agimon-ai/doompi-extension-contracts/readiness"),fe=require("@agimon-ai/doompi-telemetry"),_=require("@agimon-ai/workflow-mcp"),v=require("@earendil-works/pi-tui");const pe={overlay:!0,overlayOptions:{anchor:`top-left`,width:`100%`,maxHeight:`100%`,margin:0}},me=`workflow-mcp-follow`,he=`activate`,ge=`deactivate`;function _e(e,t){return{activation:e?`active`:`inactive`,condition:`ready`,...e?{detail:t>0?`${t} active runs`:`tools enabled`,color:`accent`}:{},actions:[...e?[{id:he,enabled:!1,disabledReason:`Workflow mode is active.`}]:[{id:he,enabled:!0}],...e?[{id:ge,enabled:!0}]:[{id:ge,enabled:!1,disabledReason:`Workflow mode is inactive.`}]]}}const y=`ctrl+alt+w`,b=`ctrl+alt+q`,ve={alt:`⌥`,cmd:`⌘`,ctrl:`⌃`,meta:`⌘`,shift:`⇧`};function x(e,t=process.platform){let n=e.split(`+`);return t===`darwin`?n.map(e=>ve[e]??e.toUpperCase()).join(``):n.map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(`+`)}const S=1e4,C=`running`,ye=`completed`,w=`failed`,T=`error`,be=`error`,xe=`doom_workflow.launch_requested`,Se=`../../../../skills`,E={running:`▸`,repair:`⚠`,completed:`✔`,failed:`✖`,separator:`·`};function Ce(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 we(e,t=process.platform){let n=[x(b,t),`close`];return e?[[`Esc Esc`,`close`],[x(y,t),`switch typing`],n]:[n]}function Te(e,t,n,r){let i=`${E.running} ${e.runKey}`,a=[e.workspace,Oe(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 Ee(e,t,n){let r=[];for(let i of e){let e=i.status===ye?E.completed:i.status===w?E.failed:E.running,a=i.status===ye?`success`:i.status===w?be:`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===ye?E.completed:e.status===w?E.failed:E.running,a=e.status===C?`muted`:e.status===w?be:`dim`;r.push((0,v.truncateToWidth)(t.fg(a,` ${i} ${e.name}`),n))}}return r}function De(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 Oe(e){return e.stale?`stale`:e.stage===T?w:e.stage}const ke=`CMUX_WORKSPACE_ID`,D=`TMUX_PANE`,O=`WORKFLOW_TMUX_SESSION_NAME`,Ae=[`CMUX_SURFACE_ID`,m.SUBAGENT_ROOT_SESSION_ENV,ke,D,`WORKFLOW_LAUNCHER_TYPE`,O,`WORKFLOW_STATUS_FILE`],k=`tmux`,A=`cmux`,je=`native`,Me=`This run points at Pi's own terminal, so its launcher screen is hidden. Use workflow status instead.`;function Ne(e){let t=e.launcher;if(t?.type===A){let e=process.env[ke];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 Pe=`No durable launcher identity is recorded for this run.`;function Fe(e){return(0,p.basename)(e,(0,p.extname)(e))}function Ie(){let e={...process.env};for(let t of Ae)delete e[t];return e}function Le(){let e=process.env.WORKFLOW_LAUNCHER;return e===k||e===A?e:void 0}function Re(e){return e.map(e=>`'${e.replaceAll(`'`,`'\\''`)}'`).join(` `)}function ze(){try{return(0,g.createRequire)(require("url").pathToFileURL(__filename).href).resolve(`@agimon-ai/workflow-mcp/cli`)}catch{return}}const Be=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 Ve(e){let t=[];if(j(e,t),t.length!==0)return t[0].filter(e=>t.every(t=>t.includes(e))).sort()}async function He(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 Ue(e){return[e.runKey,e.workspace,Oe(e),e.runner].filter(Boolean).join(` ${E.separator} `)}function We(h={}){return g=>{let v=h.featureFactory?.()??(0,_.createEmbeddedWorkflowFeature)(),ve=(0,se.randomUUID)(),w=!0,be=0,ke,D,O,Ae=h.isActive??(()=>!0),j=()=>w&&Ae(),We=e=>{let t=e.diagnostics.join(`; `),n=(e.error?.message??t)||`Initialization did not complete.`,r=`${e.packageId} initialization ${e.state}: ${n}`;V?.hasUI?V.ui.notify(r,`warning`):process.emitWarning(r)},Ge=e=>(h.cordis?(0,de.readDoomReadinessCoordinator)(h.cordis):void 0)||(O??=(0,de.createDoomReadinessCoordinator)({notify:We}),O),M=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.`)},Ke=(e,t)=>{let n=Reflect.get(e,t,e);return typeof n==`function`?n.bind(e):n},qe=new Proxy(g,{get(e,t){return t===`registerTool`?t=>{e.registerTool({...t,execute:async(e,n,r,i,a)=>(await M(r),t.execute(e,n,r,i,a))})}:Ke(e,t)}}),{parser:Je,recoverService:Ye,registry:N,runService:Xe,runTool:Ze}=v,Qe=h.spawnDetached??Be,$e=h.monitorIntervalMs??3e4,et=h.followIntervalMs??2e3,P,tt=!1,F,nt=!1,I,rt=new Map,L=new Map,it=new Set,at=0,ot=h.cordis?t.registerRunProvider(h.cordis):void 0,st=!1,R=0,z=!1,ct,B;h.cordis?.inject([le.DOOM_MINOR_MODE_CATALOG_SERVICE],t=>{let n=_e(z,R),r=(0,le.registerMinorModeOwner)((0,le.requireMinorModeCatalog)(t),{descriptor:{source:e.PACKAGE_SOURCE,id:`workflow`,label:`Workflow`,description:`Workflow discovery, launch, inspection, control, and recovery tools.`,order:20,actions:[{id:he,label:`Activate`,description:`Enable workflow tools for this session.`,contexts:[`tui`,`headless`],parameters:[]},{id:ge,label:`Deactivate`,description:`Disable workflow tools without stopping active runs.`,contexts:[`tui`,`headless`],parameters:[]}]},initialState:n,async handleAction(e,t,n){if(await M(),e===he)return await ln(!0,n.context),{message:`Workflow mode activated.`};if(e===ge)return await ln(!1,n.context),{message:`Workflow mode deactivated.`};throw Error(`Unknown workflow mode action: ${e}`)}});return B=r,ct=JSON.stringify(n),()=>{r.dispose(),B===r&&(B=void 0,ct=void 0)}});let V,H,U,lt=!1,ut=new Map,W,dt=new Set,G=new Map,ft=[],K=new Map,pt=0,mt=new u.WorkflowProgressOverlay,ht,gt,q=e=>(gt??=(0,fe.createDoomTelemetry)({serviceName:`doom-workflow`,packageName:`@agimon-ai/doompi-workflow`,cwd:e?.cwd,env:process.env,enableLogs:!0,enableTraces:!0}),gt),_t,vt=e=>{q(V).recordWarning(`doom_workflow.narration_failed`,e).catch(e=>{process.emitWarning(`Doom-workflow could not record a narration failure: ${String(e)}`)})},yt={narrate(e){let t=_t,n=(0,ue.createNarrationRequest)(e);if(!(!t||!n))try{Promise.resolve(t.request(n)).catch(vt)}catch(e){vt(e)}}};h.cordis?.inject([ue.DOOM_NARRATION_SERVICE],e=>{let t=(0,ue.requireDoomNarrationService)(e);return _t=t,()=>{_t===t&&(_t=void 0)}});let bt=e=>{e&&j()&&(ht=(0,m.resolveRootSessionId)(e))},xt=()=>{let e=ht??V?.sessionManager.getSessionId();return e?(0,m.resolveRootSessionId)(e):void 0},St=(e,t)=>e.sessionManager.getSessionId().trim()===t,Ct=v.createRecoverTool({ownerSessionId:xt}),wt=v.createControlTool(),J=new Set,Tt=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},Et=(e,t)=>{let n=Ve(Je.parseWorkflowFile(e));if(!(!n||n.includes(t)))return`Runner ${JSON.stringify(t)} is not available across this workflow. Compatible runners: ${n.join(`, `)||`none`}.`},Dt=ne.createWorkflowLaunchExecutor({activeRunCount:async()=>R,observeSession:bt,rejectRunner:Et,runTool:Ze,trackPendingRun:Tt,...h.launchAckPollMs===void 0?{}:{launchAckPollMs:h.launchAckPollMs},...h.launchAckTimeoutMs===void 0?{}:{launchAckTimeoutMs:h.launchAckTimeoutMs},findLaunchedRun:async({sessionId:e,since:t,workflowPath:n})=>{let r=Fe(n),i=n=>{if(!f.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 W?(await W.refresh(),ft.find(i)):(await He(N)).find(i)},onLateFailure:(e,t)=>{let n=e instanceof Error?e.message:String(e);t.ui.notify(f.launchNotice(`Workflow launch failed after it was reported started.\n${n}`),`warning`)},onLaunch:async e=>(await q(e).recordEvent(xe,{outcome:`requested`}),Z(e,!1))}),Ot=()=>{let e=[...K.values()].sort((e,t)=>Date.parse(e.startedAt)-Date.parse(t.startedAt)||X(e).localeCompare(X(t)));mt.update(e.map(e=>u.workflowProgressRow(e,G.get(X(e))??[])))},kt=e=>{pt+=1;let t=X(e);e.stage===C&&!e.stale?K.set(t,e):K.delete(t),Ot()},At=e=>{K.clear();for(let t of e)K.set(X(t),t);Ot()},jt=(e,t)=>{let n=G.get(e)??[];n.push(t),G.set(e,n)},Y,Mt=e=>{!j()||e!==V||Y||(Y=setTimeout(()=>{Y=void 0,j()&&e===V&&Z(e,!0)},120),Y.unref?.())},Nt=e=>{G.delete(e)},Pt=async e=>{let t=(0,m.resolveRootSessionId)(e.sessionManager.getSessionId()),n=v.createRunControl({recordFilter:e=>f.isSessionRun(e,t)});W=n;let r=()=>j()&&e===V&&W===n,i=[n.on(`step`,t=>{if(!r())return;let n=X(t.record);jt(n,{at:t.at,job:t.job,status:t.status,step:t.step,type:`step`,...t.reason===void 0?{}:{reason:t.reason}}),kt(t.record),Mt(e)}),n.on(`job`,t=>{if(!r())return;let n=X(t.record);jt(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}}),kt(t.record),Mt(e)}),n.on(`runStarted`,t=>{r()&&(ft.unshift(t.record),ft.length>32&&(ft.length=32),kt(t.record),Mt(e))}),n.on(`runUpdated`,t=>{r()&&(kt(t.record),Z(e,!0))}),n.on(`runFinished`,t=>{r()&&(kt(t.record),Z(e,!0))})];for(let e of i)dt.add(e);try{await n.start()}catch(e){for(let e of i)dt.delete(e),e();throw n.dispose(),W===n&&(W=void 0),e}if(!j()||e!==V||W!==n){for(let e of i)dt.delete(e),e();n.dispose(),W===n&&(W=void 0)}},Ft=()=>{Y&&clearTimeout(Y),Y=void 0;for(let e of dt)e();dt.clear(),W?.dispose(),W=void 0,G.clear(),pt+=1,K.clear(),Ot()},It=()=>{H?.teardown(),H?.handle?.hide(),H=void 0},X=e=>e.runId??`${e.workspace}/${e.runKey}`,Lt=()=>{let e=B;if(!e)return;let t=_e(z,R),n=JSON.stringify(t);n!==ct&&(ct=n,e.publish(t))},Z=async(e,t)=>{if(!j()||e!==V)return;let r=q(e);if(tt){r.recordEvent(`doom_workflow.monitor_skipped`,{outcome:`already_running`});return}let i=Date.now(),a=pt;tt=!0;try{let o=await He(N);if(!j()||e!==V)return;let c=(0,m.resolveRootSessionId)(e.sessionManager.getSessionId()),l=St(e,c),u=o.filter(e=>f.isSessionRun(e,c)),d=u.filter(e=>e.stage===C&&!e.stale),ee=u.filter(e=>e.stage===T);a===pt&&At(d),r.recordEvent(`doom_workflow.monitor_counts`,{"workflow.run_count":u.length,"workflow.running_count":d.length,"workflow.failed_count":ee.length,mode:z?`on`:`off`});let te=f.runsForSession(o,c).filter(e=>!e.stale);R=te.length,Lt(),ot?.update(te.map(e=>({id:e.runId??e.runKey,sessionId:c}))),Gt(new Set(u.map(e=>X(e))));let ne=new Map(u.map(e=>[X(e),e.stage]));for(let e of u){let r=X(e),i=rt.get(r),a=Date.parse(e.startedAt),o=i===void 0&&(at===0||!Number.isFinite(a)||a>=at);st&&n.narrateWorkflowTransition(yt,e,i===C||i===ye||i===T?i:void 0,o),!(!t||!l||e.stage===C)&&!it.has(r)&&(i===C||o)&&L.set(r,e)}let re=new Set([...u.filter(e=>e.stage===C&&!e.stale).map(e=>X(e)),...L.keys()]);for(let e of G.keys())re.has(e)||Nt(e);if(t)for(let t of u){if(rt.get(X(t))!==C||t.stage===C)continue;let n=t.stage===ye,i=t.failedJob?` at ${t.failedJob}`:``;e.ui.notify(n?`${E.completed} ${t.runKey} completed`:`${E.failed} ${t.runKey} ${Oe(t)}${i}`,n?`info`:`warning`),r.recordEvent(`doom_workflow.run_transition`,{outcome:n?`completed`:Oe(t)})}if(l&&L.size>0)try{let e=[...L.values()],t=await Promise.all(e.map(async e=>{if(e.stage===ye)return f.finishedRunSummary(e,[]);let t=X(e),n=G.get(t)??De(e,await(0,_.readWorkflowProgress)(N.runDirectoryFor(e)));return f.finishedRunSummary(e,(0,_.summarizeWorkflowProgress)(n))}));g.sendMessage({customType:s.WORKFLOW_FINISHED_MESSAGE,content:t.join(`
|
|
2
2
|
|
|
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);
|
|
4
|
-
`).slice(-24):[`Unable to read ${e.runKey}: ${r.stderr.trim()||`tmux exited ${r.code}`}`]}if(t.type===
|
|
5
|
-
`).slice(-24):[`Unable to read ${e.runKey}: ${
|
|
6
|
-
`)},
|
|
7
|
-
`),{deliverAs:`followUp`})},
|
|
3
|
+
`),display:!0,details:{runIds:e.map(e=>e.runId??X(e)),runs:e.map(e=>({runKey:e.runKey,workspace:e.workspace,stage:e.stage,...e.workflowId?{workflowId:e.workflowId}:{},...e.failedJob?{failedJob:e.failedJob}:{},...e.errorMessage?{error:e.errorMessage}:{}}))}},{triggerTurn:!0,deliverAs:`steer`});for(let t of e){let e=X(t);it.add(e),L.delete(e),Nt(e)}}catch(e){await r.recordError(`doom_workflow.terminal_delivery_failed`,e,{"workflow.pending_terminal_count":L.size})}rt=ne,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{tt=!1}},Rt=e=>{F&&clearInterval(F),F=void 0,I=void 0,e.ui.setWidget(me,void 0)},zt=new Map,Bt=(e,t,n)=>{let r=e.launcher;if(!r||r.type!==k||Ne(e)||t<40||n<10)return;let i=X(e),a=`${t}x${n}`;if(zt.get(i)===a)return;zt.set(i,a);let o=r.windowId??r.paneId??r.sessionId??r.sessionName;g.exec(k,[`resize-window`,`-t`,o,`-x`,String(t),`-y`,String(n)],{timeout:S})},Vt=async e=>{let t=await g.exec(A,[`rpc`,`terminal.replay`,JSON.stringify({workspace_id:e})],{timeout:S});if(t.code!==0)return;let n;try{n=JSON.parse(t.stdout)}catch{return}let r=a.terminalReplaySchema.safeParse(n);if(!r.success)return;let i=o.renderGridLines(r.data.render_grid,24);return i.length>0?i:void 0},Ht=async e=>{let t=e.launcher;if(!t)return[Pe];if(Ne(e))return[Me];if(t.type===k){let n=t.paneId??t.sessionId??t.sessionName,r=await g.exec(k,[`capture-pane`,`-p`,`-e`,`-t`,n,`-S`,`-24`],{timeout:S});return r.code===0?r.stdout.trimEnd().split(`
|
|
4
|
+
`).slice(-24):[`Unable to read ${e.runKey}: ${r.stderr.trim()||`tmux exited ${r.code}`}`]}if(t.type===je)return[`This run is hosted natively and has no launcher screen to read.`];let n=await Vt(t.workspaceId);if(n)return n;let r=await g.exec(A,[`read-screen`,`--workspace`,t.workspaceId,`--scrollback`,`--lines`,`24`],{timeout:S});return r.code===0?r.stdout.trimEnd().split(`
|
|
5
|
+
`).slice(-24):[`Unable to read ${e.runKey}: ${r.stderr.trim()||`cmux exited ${r.code}`}`]},Ut=new Map,Wt=async e=>{let t=X(e),n=Ut.get(t)??{at:0,lines:[]};if(Ut.set(t,n),n.inFlight||Date.now()-n.at<750)return n.lines;n.inFlight=Ht(e);try{n.lines=await n.inFlight}finally{n.at=Date.now(),n.inFlight=void 0}return n.lines},Gt=e=>{for(let t of Ut.keys())e.has(t)||Ut.delete(t);for(let t of zt.keys())e.has(t)||zt.delete(t)},Kt=async e=>{let t=e.launcher;if(!t)return Pe;if(Ne(e))return Me;if(t.type===je)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}.`},qt=async(e,t)=>{if(!nt){nt=!0;try{let n=(0,_.summarizeWorkflowProgress)(De(e,await(0,_.readWorkflowProgress)(N.runDirectoryFor(e)))),r=n.length>0?void 0:await Wt(e);t.ui.setWidget(me,(t,i)=>({render:t=>Te(e,r??Ee(n,i,t),i,t),invalidate:()=>{}}),{placement:`aboveEditor`})}finally{nt=!1}}},Jt=async(e,t)=>{Rt(t),I=e,await qt(e,t),F=setInterval(()=>{I&&qt(I,t)},et),F.unref?.()},Yt=async(e,t)=>{let n=e.launcher;if(!(!n||n.type===je||Ne(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})}},Xt=async(e,t)=>{It();let n=!Ne(e)&&(e.launcher?.type===k||e.launcher?.type===A),r=new i.TerminalInputBatcher(t=>Yt(e,t)),a=[],o=[],s,c=!1,l=async()=>{a=(0,_.summarizeWorkflowProgress)(De(e,await(0,_.readWorkflowProgress)(N.runDirectoryFor(e)))),o=await Wt(e)};await l();let u=()=>{s&&clearInterval(s),s=void 0,r.dispose()},d={interactive:n,runKey:e.runKey,teardown:u};H=d;let te=()=>{It(),t.ui.notify(`Closed the ${e.runKey} view. The run keeps going.`,`info`)};return t.ui.custom((i,f,ne,re)=>(s=setInterval(()=>{c||(c=!0,l().finally(()=>{c=!1,i.requestRender()}))},200),s.unref?.(),new ee.WorkflowRunPanelComponent(i,f,{runKey:e.runKey,label:`${E.running} ${Ue(e)}`,breadcrumb:`SPC › w / workflows › run`,interactive:n,footer:Ce(n),hints:we(n),snapshot:e=>({progress:Ee(a,f,e),output:o}),onViewport:(t,n)=>Bt(e,t,n),onUnfollow:()=>{d.handle?.unfocus(),t.ui.notify(`Typing goes to this session. The run keeps going.`,`info`)},onClose:te,sendInput:e=>r.write(e),flushInput:()=>void r.flush(),unfollowShortcut:y,closeShortcut:b,onDispose:()=>{u(),H===d&&(H=void 0),re()}})),{...ee.runPanelUiOptions(n),onHandle:e=>{d.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(` `)},Zt=async(e,t=!1)=>{if(!(lt||H||I)){lt=!0;try{let n=await e.ui.custom((e,t,n,i)=>new r.WorkflowInspectorComponent(e,t,{list:async()=>{let e=xt(),t=(await He(N)).filter(t=>t.stage===C&&!t.stale&&f.isSessionRun(t,e));return ut=new Map(t.map(e=>[X(e),e])),Promise.all(t.map(async e=>({displayName:e.displayName,executionState:e.executionState,jobs:(0,_.summarizeWorkflowProgress)(De(e,await(0,_.readWorkflowProgress)(N.runDirectoryFor(e)))),key:X(e),output:[],runKey:e.runKey,startedAt:e.startedAt,workspace:e.workspace})))},output:async e=>{let t=ut.get(e.key);return t?Wt(t):[`Workflow is no longer active.`]}},i),{...pe,onHandle:e=>{U=e}});if(n){let r=await Q(n);t?await nn(r,e):await Xt(r,e)}}finally{U=void 0,lt=!1,ut.clear()}}},Q=async(e,t=xt())=>{bt(t);let n=(await He(N,e.workspace)).filter(n=>n.runKey===e.runKey&&f.isSessionRun(n,t));if(n.length>1)throw Error(f.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(f.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},Qt=async e=>{let t=(await He(N,e.workspace)).filter(t=>t.runKey===e.runKey&&t.stage===T);if(t.length>1)throw Error(f.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(f.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},$t=async e=>{let t=N.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,ce.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.`]},en=async(e,t)=>{let n=await Qt(e);return await q(t).recordEvent(`doom_workflow.recovery_evidence_requested`,{outcome:`requested`}),[`Workflow: ${Ue(n)}`,`--- run.json ---`,JSON.stringify(n,null,2),...await $t(n)].join(`
|
|
6
|
+
`)},tn=async(e,t)=>{let n=ze();if(!n)return;let r=await Qt(e),i;try{i=Je.parseWorkflowFile(r.workflowPath)}catch{return}if(!i[`launch-command`])return;let a=(0,m.resolveRootSessionId)(t.sessionManager.getSessionId()),o=await N.claimRunRecovery(r.workspace,r.runKey,a),s=r.originalRepoPath??t.cwd,c=Re([process.execPath,n,`recover-workflow`,r.runKey,`--workspace`,r.workspace,`--recovery-claim`,o.claimId,...e.runner?[`--runner`,e.runner]:[]]),l=Le();try{await Qe(process.execPath,[n,`launch-process`,...l?[`--launcher`,l]:[],`--name`,`${r.displayName} recover`,`--cwd`,s,`--command`,c],{cwd:s,env:Ie()})}catch(e){throw await N.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.`},nn=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 d.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 Xt(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 wt.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(f.toolResultText(a)||`Unable to ${i.toLowerCase()} workflow.`);t.ui.notify(f.toolResultText(a)||`${i} requested for ${n.runKey}.`,`info`),await Z(t,!1),n=await Q(n)}},rn=(e,t)=>({editor:(t,n)=>e.ui.editor(t,n),input:(n,r)=>d.openWorkflowInput(e,{title:n,breadcrumb:t,...r?{fallback:r}:{}}),notify:(t,n)=>e.ui.notify(t,n),select:(n,r)=>d.openWorkflowChoice(e,{title:n,breadcrumb:t,choices:r})}),an=async e=>{if(!e.hasUI){e.ui.notify(`The workflow list needs an interactive Pi session.`,`warning`);return}let t=await re.loadWorkflowCatalog(v.listWorkflowsTool,e.cwd),n=new Map(t.map(e=>[e.path,e])),r={compatibleRunners:Ve,launch:(e,t)=>Dt.execute(e,t),parseWorkflow:e=>Je.parseWorkflowFile(e),ui:rn(e,`SPC › w / workflows › l / list`)};await c.openWorkflowCatalogOverlay(e,t.map(e=>({key:e.path,name:e.name,relativePath:e.relativePath,description:e.description,tags:e.tags})),{loadDetail:e=>re.summarizeWorkflowFile(e.key,r),launchWorkflow:t=>{let i=n.get(t.key);i&&re.launchWorkflowEntry(r,i,e).then(t=>{t&&e.ui.notify(f.launchNotice(f.toolResultText(t)),`info`)},t=>{e.ui.notify(t instanceof Error?t.message:String(t),`error`)})}})},on=async e=>{let t=(await He(N)).filter(e=>e.stage===T);if(t.length===0){e.ui.notify(`No failed workflows are available to recover.`,`info`);return}let n=await l.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 Qt(n);if(r.stage!==T)throw Error(`${r.runKey} is no longer failed.`);let i=(0,p.resolve)((0,p.dirname)((0,ae.fileURLToPath)(require("url").pathToFileURL(__filename).href)),Se,`workflow-recovery`,`SKILL.md`);if(!(0,ie.existsSync)(i))throw Error(`Workflow recovery skill is unavailable at ${i}.`);sn(!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`})},sn=e=>{if(!j())return;let t=new Set(g.getActiveTools());for(let n of ne.WORKFLOW_PI_TOOL_NAMES)e?t.add(n):t.delete(n);g.setActiveTools([...t]),z=e,Lt(),h.onModeChange?.(e)},cn=()=>z?[`${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(`
|
|
8
8
|
`):[`Workflow mode off`,`Press SPC w e to give the agent its workflow tools. Runs already going are unaffected.`].join(`
|
|
9
|
-
`),
|
|
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?
|
|
9
|
+
`),ln=async(e,t)=>{sn(e),z||Rt(t),t.ui.notify(cn(),`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 M();let t=H?.handle;if(t){if(!H?.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 ${H?.runKey}.`,`info`));return}if(I){Rt(e),e.ui.notify(`Workflow continues in the background.`,`info`);return}await Zt(e)}}),g.registerShortcut(b,{description:`Close the workflow run view`,handler:async e=>{if(await M(),!H)return;let t=H.runKey;It(),e.ui.notify(`Closed the ${t} view. The run keeps going.`,`info`)}}),g.on(`resources_discover`,()=>{if(!z)return{skillPaths:[]};let e=(0,p.resolve)((0,p.dirname)((0,ae.fileURLToPath)(require("url").pathToFileURL(__filename).href)),Se);return{skillPaths:(0,ie.existsSync)(e)?[e]:[]}}),s.registerWorkflowFinishedRenderer(g),g.registerMessageRenderer(`workflow-step`,(e,{outputPad:t},n)=>{let r=te.isWorkflowStepMessageDetails(e.details)?e.details:void 0,i=typeof e.content==`string`?e.content:JSON.stringify(e.content);return te.renderWorkflowStepMessage(r,i,t,n)}),ne.registerWorkflowPiTools(qe,{runTool:Ze,recoverTool:Ct,launchExecutor:Dt,controlTool:wt,requireSessionRun:Q,requireRecoverableRun:Qt,readRecoveryEvidence:en,delegateRecovery:tn,trackPendingRun:Tt,observeSession:bt,activeRunCount:async()=>R,onLaunch:async e=>(await q(e).recordEvent(xe,{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 Jt(n,t),`Following ${Ue(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: ${Ue(n)}`,`Stage: ${Oe(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?Xt(n,t):Kt(n)},rejectRunner:Et});let un;h.cordis?.inject([oe.DOOM_UI_HUB_SERVICE],t=>{let n=(0,oe.requireDoomUiHub)(t).registerLeaderActions({source:e.PACKAGE_SOURCE,handlers:{[e.LEADER_ENABLE_ACTION]:async e=>(await M(),ln(!0,e)),[e.LEADER_DISABLE_ACTION]:async e=>(await M(),ln(!1,e)),[e.LEADER_MANAGE_ACTION]:async e=>(await M(),Zt(e,!0)),[e.LEADER_CATALOG_ACTION]:async e=>(await M(),an(e)),[e.LEADER_RECOVER_ACTION]:async e=>(await M(),on(e))},onError:(e,t,n)=>{n.ui.notify(e instanceof Error?e.message:String(e),`error`)}});return un=n,()=>{n(),un===n&&(un=void 0)}}),g.on(`session_start`,(t,n)=>{if(!w||!Ae())return;let r=++be,i=D;ke?.abort();let a=new AbortController;ke=a,V=n;let o=()=>w&&r===be&&V===n&&Ae();Ft(),P&&clearInterval(P),P=void 0,ot?.update([]),Rt(n),U?.hide(),U=void 0,lt=!1,ut.clear(),It(),Ut.clear(),mt.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);bt(c),at=Date.now(),st=!1,rt=new Map,L.clear(),it.clear(),sn(h.initialMode??process.env.WORKFLOW_MCP_MODE===`on`);let l=Ge(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,`${ve}:${r}`,async e=>{let t=()=>a.signal.aborted||!o();return e.throwIfAborted(),t()||(await Pt(n),e.throwIfAborted(),t())||(await Z(n,!1),e.throwIfAborted(),t())?{value:void 0}:(st=!0,P=setInterval(()=>{o()&&Z(n,!0)},$e),P.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)}`)}},dn;return{dispose:(e=V)=>(dn??=(async()=>{if(!w)return;w=!1,be+=1;let t=D;D=void 0,ke?.abort(),ke=void 0,await $(`stop the workflow observer`,Ft);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[Xe,Ye])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?.())])}P&&clearInterval(P),P=void 0,Y&&clearTimeout(Y),Y=void 0;let r=ot;ot=void 0,r&&await $(`unregister the background-work provider`,()=>r.dispose()),st=!1,U?.hide(),U=void 0,lt=!1,ut.clear(),Ut.clear(),It(),R=0,e?Rt(e):F&&clearInterval(F),F=void 0,I=void 0,mt.dispose(),z=!1,ct=void 0;let i=B;B=void 0,i&&(await $(`publish the inactive workflow mode`,()=>i.publish(_e(!1,0))),await $(`dispose the workflow mode owner`,()=>i.dispose()));let a=un;un=void 0,a&&await $(`dispose workflow leader actions`,a);let o=J.size,s=gt;gt=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(),L.clear(),it.clear(),ft.length=0,ht=void 0,V=void 0})(),dn)}}}exports.compatibleRunners=Ve,exports.installWorkflowPiRuntime=We,exports.panelHint=Ce,exports.panelHints=we,exports.shortcutLabel=x;
|
|
11
11
|
//# sourceMappingURL=piExtension.cjs.map
|