@agimon-ai/doompi-loop 0.0.1-alpha.40 → 0.0.1-alpha.43
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 +1 -1
- package/dist/adapters/pi/extension.cjs +1 -1
- package/dist/adapters/pi/extension.cjs.map +1 -1
- package/dist/adapters/pi/extension.d.cts.map +1 -1
- package/dist/adapters/pi/extension.d.mts.map +1 -1
- package/dist/adapters/pi/extension.mjs +1 -1
- package/dist/adapters/pi/extension.mjs.map +1 -1
- package/dist/types/loopView.cjs +2 -0
- package/dist/types/loopView.cjs.map +1 -0
- package/dist/types/loopView.mjs +2 -0
- package/dist/types/loopView.mjs.map +1 -0
- package/package.json +14 -8
- package/src/types/loopView.ts +73 -0
- package/web/LoopsActivitySection.tsx +60 -0
- package/web/index.ts +6 -2
- package/web/tsconfig.json +3 -2
package/README.md
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../../commands/loopCommand.cjs"),t=require("../../services/loopLaunchers.cjs"),n=require("../../tui/loopListOverlay.cjs"),r=require("../../tui/startLoopOverlay.cjs"),i=require("./loopConstants.cjs"),
|
|
1
|
+
const e=require("../../commands/loopCommand.cjs"),t=require("../../services/loopLaunchers.cjs"),n=require("../../tui/loopListOverlay.cjs"),r=require("../../tui/startLoopOverlay.cjs"),i=require("../../types/loopView.cjs"),a=require("./loopConstants.cjs"),o=require("./defaultLoopLauncher.cjs"),s=require("./leader.cjs");let c=require("@agimon-ai/doompi-extension-contracts/mode"),l=require("@agimon-ai/doompi-extension-contracts/cordis-host"),u=require("@agimon-ai/doompi-extension-contracts/help"),d=require("@agimon-ai/doompi-extension-contracts/loop-launchers"),f=require("@agimon-ai/doompi-extension-contracts/ui-hub");const p=`start`,m=`stop`,h=`Pi session replaced.`;function g(e,t){let n=t.length>0;return{activation:n?`active`:`inactive`,condition:t.some(({state:e})=>e===`starting`||e===`stopping`)?`queued`:`ready`,...n?{detail:`${t.length} active`,color:a.ACTIVE_MODE_COLOR}:{},actions:[...e.length>0?[{id:p,enabled:!0}]:[{id:p,enabled:!1,disabledReason:`No loop launchers are registered.`}],...n?[{id:m,enabled:!0}]:[{id:m,enabled:!1,disabledReason:`No loops are active.`}]]}}function _(u,_){let v=!0,y,b,x,S=e=>{let t=y;if(!(!v||!t||t.context.sessionManager!==e.sessionManager||t.hostSession.sessionId!==e.sessionManager.getSessionId()))return t},C=e=>{e.context.ui?.setStatus(a.STATUS_KEY,void 0),e.context.mode!==`tui`&&e.context.ui?.setStatus(i.LOOP_VIEW_STATUS_KEY,void 0)},w=e=>{if(!v||y!==e)return;let t=e.launchers.listLaunchers(),n=e.launchers.listInstances();e.context.ui?.setStatus(a.STATUS_KEY,n.length?`loops: ${n.length}`:void 0),e.context.mode!==`tui`&&e.context.ui?.setStatus(i.LOOP_VIEW_STATUS_KEY,i.formatLoopStatusView(n)),b?.publish(g(t,n))};u.effect(()=>()=>{v=!1;let e=y;y=void 0,e&&C(e),b?.publish(g([],[])),b?.dispose(),x?.(),x=void 0,b=void 0},`${a.PACKAGE_SOURCE}/runtime`);let T=o.createDefaultLoopLauncher(_);u.inject([c.DOOM_MINOR_MODE_CATALOG_SERVICE],e=>{let t=(0,c.registerMinorModeOwner)((0,c.requireMinorModeCatalog)(e),{descriptor:{source:a.PACKAGE_SOURCE,id:a.MODE_STATUS_ID,label:`Loop`,description:`Session-scoped recurring prompt loops.`,order:60,actions:[{id:p,label:`Start`,description:`Start a loop with a registered launcher.`,contexts:[`tui`,`headless`],parameters:[{name:`launcherId`,label:`Launcher`,kind:`string`,required:!0,minLength:1},{name:`instanceId`,label:`Instance ID`,kind:`string`,required:!1,minLength:1}]},{id:m,label:`Stop`,description:`Stop one active loop instance.`,contexts:[`tui`,`headless`],parameters:[{name:`instanceId`,label:`Instance ID`,kind:`string`,required:!0,minLength:1},{name:`reason`,label:`Reason`,kind:`string`,required:!1,minLength:1}]}]},initialState:g([],[]),async handleAction(e,t,n){let r=S(n.context);if(!r)throw Error(`Loop launchers are unavailable for the active session.`);if(e===p){let e=await r.launchers.launch(t.launcherId,t.instanceId?{instanceId:t.instanceId}:{});if(y!==r)throw Error(`Loop action became stale.`);return{message:e?`Loop '${e.instanceId}' started.`:`Loop launch was cancelled.`}}if(e===m){let e=await r.launchers.stop(t.instanceId,t.reason??`Stopped through minor_mode.`);if(y!==r)throw Error(`Loop action became stale.`);return{message:e?`Loop stopped.`:`Loop instance was not active.`}}throw Error(`Unknown loop mode action: ${e}`)}});b=t;let n=y;return n&&w(n),()=>{t.dispose(),b===t&&(b=void 0)}}),u.inject([f.DOOM_UI_HUB_SERVICE],e=>{let t=s.registerLeaderContribution((0,f.requireDoomUiHub)(e));return x=t,()=>{t(),x===t&&(x=void 0)}}),e.registerCommands(_,{async start(e){let t=S(e);if(!t)return;let n=t.launchers.listLaunchers();if(!n.length){e.ui.notify(`No loop launchers are registered for this session.`,a.NOTIFY_INFO_LEVEL);return}let i=await r.openStartLoopOverlay(e,n);if(!(y!==t||!i))try{let n=await t.launchers.launch(i);if(y!==t)return;n&&e.ui.notify(`${n.label??n.launcherLabel} started.`,a.NOTIFY_INFO_LEVEL)}catch(n){if(y!==t)return;e.ui.notify(`Loop could not start: ${n instanceof Error?n.message:String(n)}`,`error`)}},async list(e){let t=S(e);t&&await n.openLoopListOverlay(e,t.launchers)}}),u.inject([l.DOOM_CORDIS_SESSION_SERVICE],async e=>{let n=e.get(l.DOOM_CORDIS_SESSION_SERVICE),r=t.createDoomLoopLaunchersService({generation:`${n.generation}:loop-launchers`,createInstanceId:()=>crypto.randomUUID(),timestamp:()=>new Date().toISOString()}),i={context:n.context,hostSession:n,launchers:r};y=i,e.provide(d.DOOM_LOOP_LAUNCHERS_SERVICE,r);let a,o;try{a=T.register(n.context,r),o=r.subscribe(()=>w(i)),w(i)}catch(e){throw y===i&&(y=void 0),await r.dispose(h),e}return async()=>{y===i&&(y=void 0),o(),C(i),b?.publish(g([],[]));let e=[];try{await a.dispose(h)}catch(t){e.push(t)}try{await r.dispose(`Pi session shut down.`)}catch(t){e.push(t)}if(e.length>0)throw AggregateError(e,`Loop session cleanup failed.`)}})}async function v(e){let t=await(0,l.connectDoomCordisHost)(e,a.PACKAGE_SOURCE),n=t.root.plugin(y,{pi:e});try{await n}catch(e){try{await n.dispose()}finally{await t.dispose()}throw e}let r;e.on(`session_shutdown`,()=>r??=(async()=>{try{await n.dispose()}finally{await t.dispose()}})())}function y(e,t){e.inject([u.DOOM_HELP_SERVICE],e=>{let t=(0,u.requireDoomHelpService)(e).register({source:a.PACKAGE_SOURCE,moduleUrl:require("url").pathToFileURL(__filename).href,skills:[{name:`doompi-use-loop`,description:`Use Doom Pi Loop to start, inspect, and stop session-scoped recurring prompts safely.`}]});return()=>t.dispose()}),_(e,t.pi)}exports.default=v,exports.loopExtension=v,exports.installLoopRuntime=_;
|
|
2
2
|
//# sourceMappingURL=extension.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension.cjs","names":["ACTIVE_MODE_COLOR","STATUS_KEY","PACKAGE_SOURCE","createDefaultLoopLauncher","DOOM_MINOR_MODE_CATALOG_SERVICE","registerMinorModeOwner","requireMinorModeCatalog","MODE_STATUS_ID","DOOM_UI_HUB_SERVICE","registerLeaderContribution","requireDoomUiHub","NOTIFY_INFO_LEVEL","openStartLoopOverlay","openLoopListOverlay","DOOM_CORDIS_SESSION_SERVICE","createDoomLoopLaunchersService","DOOM_LOOP_LAUNCHERS_SERVICE","connectDoomCordisHost","DOOM_HELP_SERVICE","requireDoomHelpService"],"sources":["../../../src/adapters/pi/extension.ts"],"sourcesContent":["import {\n DOOM_MINOR_MODE_CATALOG_SERVICE,\n type MinorModeOwnerHandle,\n type MinorModeState,\n registerMinorModeOwner,\n requireMinorModeCatalog,\n} from '@agimon-ai/doompi-extension-contracts/mode';\nimport {\n connectDoomCordisHost,\n DOOM_CORDIS_SESSION_SERVICE,\n type DoomCordisSessionService,\n} from '@agimon-ai/doompi-extension-contracts/cordis-host';\nimport { DOOM_HELP_SERVICE, requireDoomHelpService } from '@agimon-ai/doompi-extension-contracts/help';\nimport {\n DOOM_LOOP_LAUNCHERS_SERVICE,\n type DoomLoopLaunchersService,\n type LoopInstanceSnapshot,\n type LoopLauncherRegistration,\n type LoopLauncherSummary,\n} from '@agimon-ai/doompi-extension-contracts/loop-launchers';\nimport { DOOM_UI_HUB_SERVICE, requireDoomUiHub } from '@agimon-ai/doompi-extension-contracts/ui-hub';\nimport type { Context } from '@deepseek-ai/cordis';\nimport type { ExtensionAPI, ExtensionContext } from '@earendil-works/pi-coding-agent';\nimport { registerCommands } from '../../commands/loopCommand.ts';\nimport { createDoomLoopLaunchersService } from '../../services/loopLaunchers.ts';\nimport { openLoopListOverlay } from '../../tui/loopListOverlay.ts';\nimport { openStartLoopOverlay } from '../../tui/startLoopOverlay.ts';\nimport { createDefaultLoopLauncher } from './defaultLoopLauncher.ts';\nimport { registerLeaderContribution } from './leader.ts';\nimport {\n ACTIVE_MODE_COLOR,\n LOOPS_GROUP_ORDER,\n MODE_STATUS_ID,\n NOTIFY_INFO_LEVEL,\n PACKAGE_SOURCE,\n STATUS_KEY,\n} from './loopConstants.ts';\n\nconst MODE_ACTION_START = 'start';\nconst MODE_ACTION_STOP = 'stop';\nconst SESSION_REPLACED_REASON = 'Pi session replaced.';\nconst SESSION_SHUTDOWN_REASON = 'Pi session shut down.';\n\ninterface ActiveLoopSession {\n readonly context: ExtensionContext;\n readonly hostSession: DoomCordisSessionService;\n readonly launchers: DoomLoopLaunchersService;\n}\n\nfunction loopModeState(\n launchers: readonly LoopLauncherSummary[],\n instances: readonly LoopInstanceSnapshot[],\n): MinorModeState {\n const active = instances.length > 0;\n return {\n activation: active ? 'active' : 'inactive',\n condition: instances.some(({ state }) => state === 'starting' || state === 'stopping') ? 'queued' : 'ready',\n ...(active ? { detail: `${instances.length} active`, color: ACTIVE_MODE_COLOR } : {}),\n actions: [\n ...(launchers.length > 0\n ? [{ id: MODE_ACTION_START, enabled: true } as const]\n : [{ id: MODE_ACTION_START, enabled: false, disabledReason: 'No loop launchers are registered.' } as const]),\n ...(active\n ? [{ id: MODE_ACTION_STOP, enabled: true } as const]\n : [{ id: MODE_ACTION_STOP, enabled: false, disabledReason: 'No loops are active.' } as const]),\n ],\n };\n}\n\n/** Install Loop state and external resources into its host-owned Cordis plugin fiber. */\nexport function installLoopRuntime(cordis: Context, pi: ExtensionAPI): void {\n let active = true;\n let activeSession: ActiveLoopSession | undefined;\n let mode: MinorModeOwnerHandle | undefined;\n let disposeLeader: (() => void) | undefined;\n\n const currentSession = (context: ExtensionContext): ActiveLoopSession | undefined => {\n const binding = activeSession;\n if (\n !active ||\n !binding ||\n binding.context.sessionManager !== context.sessionManager ||\n binding.hostSession.sessionId !== context.sessionManager.getSessionId()\n ) {\n return undefined;\n }\n return binding;\n };\n\n const publishStatus = (binding: ActiveLoopSession): void => {\n if (!active || activeSession !== binding) return;\n const launchers = binding.launchers.listLaunchers();\n const instances = binding.launchers.listInstances();\n binding.context.ui?.setStatus(STATUS_KEY, instances.length ? `loops: ${instances.length}` : undefined);\n mode?.publish(loopModeState(launchers, instances));\n };\n\n cordis.effect(\n () => () => {\n active = false;\n const binding = activeSession;\n activeSession = undefined;\n binding?.context.ui?.setStatus(STATUS_KEY, undefined);\n mode?.publish(loopModeState([], []));\n mode?.dispose();\n disposeLeader?.();\n disposeLeader = undefined;\n mode = undefined;\n },\n `${PACKAGE_SOURCE}/runtime`,\n );\n\n const defaultLauncher = createDefaultLoopLauncher(pi);\n cordis.inject([DOOM_MINOR_MODE_CATALOG_SERVICE], (modeContext) => {\n const owner = registerMinorModeOwner<ExtensionContext>(requireMinorModeCatalog(modeContext), {\n descriptor: {\n source: PACKAGE_SOURCE,\n id: MODE_STATUS_ID,\n label: 'Loop',\n description: 'Session-scoped recurring prompt loops.',\n order: LOOPS_GROUP_ORDER,\n actions: [\n {\n id: MODE_ACTION_START,\n label: 'Start',\n description: 'Start a loop with a registered launcher.',\n contexts: ['tui', 'headless'],\n parameters: [\n { name: 'launcherId', label: 'Launcher', kind: 'string', required: true, minLength: 1 },\n { name: 'instanceId', label: 'Instance ID', kind: 'string', required: false, minLength: 1 },\n ],\n },\n {\n id: MODE_ACTION_STOP,\n label: 'Stop',\n description: 'Stop one active loop instance.',\n contexts: ['tui', 'headless'],\n parameters: [\n { name: 'instanceId', label: 'Instance ID', kind: 'string', required: true, minLength: 1 },\n { name: 'reason', label: 'Reason', kind: 'string', required: false, minLength: 1 },\n ],\n },\n ],\n },\n initialState: loopModeState([], []),\n async handleAction(actionId, argumentsValue, execution) {\n const binding = currentSession(execution.context);\n if (!binding) throw new Error('Loop launchers are unavailable for the active session.');\n if (actionId === MODE_ACTION_START) {\n const instance = await binding.launchers.launch(\n argumentsValue.launcherId as string,\n argumentsValue.instanceId ? { instanceId: argumentsValue.instanceId as string } : {},\n );\n if (activeSession !== binding) throw new Error('Loop action became stale.');\n return { message: instance ? `Loop '${instance.instanceId}' started.` : 'Loop launch was cancelled.' };\n }\n if (actionId === MODE_ACTION_STOP) {\n const stopped = await binding.launchers.stop(\n argumentsValue.instanceId as string,\n (argumentsValue.reason as string | undefined) ?? 'Stopped through minor_mode.',\n );\n if (activeSession !== binding) throw new Error('Loop action became stale.');\n return { message: stopped ? 'Loop stopped.' : 'Loop instance was not active.' };\n }\n throw new Error(`Unknown loop mode action: ${actionId}`);\n },\n });\n mode = owner;\n const binding = activeSession;\n if (binding) publishStatus(binding);\n return () => {\n owner.dispose();\n if (mode === owner) mode = undefined;\n };\n });\n cordis.inject([DOOM_UI_HUB_SERVICE], (uiContext) => {\n const dispose = registerLeaderContribution(requireDoomUiHub(uiContext));\n disposeLeader = dispose;\n return () => {\n dispose();\n if (disposeLeader === dispose) disposeLeader = undefined;\n };\n });\n\n registerCommands(pi, {\n async start(ctx) {\n const binding = currentSession(ctx);\n if (!binding) return;\n const launchers = binding.launchers.listLaunchers();\n if (!launchers.length) {\n ctx.ui.notify('No loop launchers are registered for this session.', NOTIFY_INFO_LEVEL);\n return;\n }\n const launcherId = await openStartLoopOverlay(ctx, launchers);\n if (activeSession !== binding || !launcherId) return;\n try {\n const instance = await binding.launchers.launch(launcherId);\n if (activeSession !== binding) return;\n if (instance) ctx.ui.notify(`${instance.label ?? instance.launcherLabel} started.`, NOTIFY_INFO_LEVEL);\n } catch (error) {\n if (activeSession !== binding) return;\n ctx.ui.notify(`Loop could not start: ${error instanceof Error ? error.message : String(error)}`, 'error');\n }\n },\n async list(ctx) {\n const binding = currentSession(ctx);\n if (!binding) return;\n await openLoopListOverlay(ctx, binding.launchers);\n },\n });\n\n cordis.inject([DOOM_CORDIS_SESSION_SERVICE], async (sessionContext) => {\n const hostSession = sessionContext.get(DOOM_CORDIS_SESSION_SERVICE) as DoomCordisSessionService;\n const launchers = createDoomLoopLaunchersService({\n generation: `${hostSession.generation}:loop-launchers`,\n createInstanceId: () => crypto.randomUUID(),\n timestamp: () => new Date().toISOString(),\n });\n const binding: ActiveLoopSession = { context: hostSession.context, hostSession, launchers };\n activeSession = binding;\n sessionContext.provide(DOOM_LOOP_LAUNCHERS_SERVICE, launchers);\n\n let defaultRegistration: LoopLauncherRegistration;\n let unsubscribe: () => void;\n try {\n defaultRegistration = defaultLauncher.register(hostSession.context, launchers);\n unsubscribe = launchers.subscribe(() => publishStatus(binding));\n publishStatus(binding);\n } catch (error) {\n if (activeSession === binding) activeSession = undefined;\n await launchers.dispose(SESSION_REPLACED_REASON);\n throw error;\n }\n\n return async () => {\n if (activeSession === binding) activeSession = undefined;\n unsubscribe();\n binding.context.ui?.setStatus(STATUS_KEY, undefined);\n mode?.publish(loopModeState([], []));\n const cleanupErrors: unknown[] = [];\n try {\n await defaultRegistration.dispose(SESSION_REPLACED_REASON);\n } catch (error) {\n cleanupErrors.push(error);\n }\n try {\n await launchers.dispose(SESSION_SHUTDOWN_REASON);\n } catch (error) {\n cleanupErrors.push(error);\n }\n if (cleanupErrors.length > 0) throw new AggregateError(cleanupErrors, 'Loop session cleanup failed.');\n };\n });\n}\n\n/** The package's single standard Pi factory. */\nexport async function loopExtension(pi: ExtensionAPI): Promise<void> {\n const connection = await connectDoomCordisHost(pi, PACKAGE_SOURCE);\n const fiber = connection.root.plugin(loopPlugin, { pi });\n try {\n await fiber;\n } catch (error) {\n try {\n await fiber.dispose();\n } finally {\n await connection.dispose();\n }\n throw error;\n }\n let disposal: Promise<void> | undefined;\n pi.on(\n 'session_shutdown',\n () =>\n (disposal ??= (async () => {\n try {\n await fiber.dispose();\n } finally {\n await connection.dispose();\n }\n })()),\n );\n}\n\ninterface LoopPluginConfig {\n readonly pi: ExtensionAPI;\n}\n\nfunction loopPlugin(cordis: Context, config: LoopPluginConfig): void {\n cordis.inject([DOOM_HELP_SERVICE], (helpContext) => {\n const contribution = requireDoomHelpService(helpContext).register({\n source: PACKAGE_SOURCE,\n moduleUrl: import.meta.url,\n skills: [\n {\n name: 'doompi-use-loop',\n description: 'Use Doom Pi Loop to start, inspect, and stop session-scoped recurring prompts safely.',\n },\n ],\n });\n return () => contribution.dispose();\n });\n installLoopRuntime(cordis, config.pi);\n}\n\nexport default loopExtension;\n"],"mappings":"wkBAsCA,MAAM,EAAoB,QACpB,EAAmB,OACnB,EAA0B,uBAShC,SAAS,EACP,EACA,EACgB,CAChB,IAAM,EAAS,EAAU,OAAS,EAClC,MAAO,CACL,WAAY,EAAS,SAAW,WAChC,UAAW,EAAU,MAAM,CAAE,WAAY,IAAU,YAAc,IAAU,UAAU,EAAI,SAAW,QACpG,GAAI,EAAS,CAAE,OAAQ,GAAG,EAAU,OAAO,SAAU,MAAOA,EAAAA,iBAAkB,EAAI,CAAC,EACnF,QAAS,CACP,GAAI,EAAU,OAAS,EACnB,CAAC,CAAE,GAAI,EAAmB,QAAS,EAAK,CAAU,EAClD,CAAC,CAAE,GAAI,EAAmB,QAAS,GAAO,eAAgB,mCAAoC,CAAU,EAC5G,GAAI,EACA,CAAC,CAAE,GAAI,EAAkB,QAAS,EAAK,CAAU,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,iBAAiB,EAAI,GAAgB,CAClD,IAAM,GAAA,EAAeC,EAAAA,uBAAAA,CAAuB,CAAW,CAAC,CAAC,SAAS,CAChE,OAAQjB,EAAAA,eACR,UAAA,QAAA,KAAA,CAAA,CAAA,cAAA,UAAA,CAAA,CAAA,KACA,OAAQ,CACN,CACE,KAAM,kBACN,YAAa,uFACf,CACF,CACF,CAAC,EACD,UAAa,EAAa,QAAQ,CACpC,CAAC,EACD,EAAmB,EAAQ,EAAO,EAAE,CACtC"}
|
|
1
|
+
{"version":3,"file":"extension.cjs","names":["ACTIVE_MODE_COLOR","STATUS_KEY","LOOP_VIEW_STATUS_KEY","formatLoopStatusView","PACKAGE_SOURCE","createDefaultLoopLauncher","DOOM_MINOR_MODE_CATALOG_SERVICE","registerMinorModeOwner","requireMinorModeCatalog","MODE_STATUS_ID","DOOM_UI_HUB_SERVICE","registerLeaderContribution","requireDoomUiHub","NOTIFY_INFO_LEVEL","openStartLoopOverlay","openLoopListOverlay","DOOM_CORDIS_SESSION_SERVICE","createDoomLoopLaunchersService","DOOM_LOOP_LAUNCHERS_SERVICE","connectDoomCordisHost","DOOM_HELP_SERVICE","requireDoomHelpService"],"sources":["../../../src/adapters/pi/extension.ts"],"sourcesContent":["import {\n DOOM_MINOR_MODE_CATALOG_SERVICE,\n type MinorModeOwnerHandle,\n type MinorModeState,\n registerMinorModeOwner,\n requireMinorModeCatalog,\n} from '@agimon-ai/doompi-extension-contracts/mode';\nimport {\n connectDoomCordisHost,\n DOOM_CORDIS_SESSION_SERVICE,\n type DoomCordisSessionService,\n} from '@agimon-ai/doompi-extension-contracts/cordis-host';\nimport { DOOM_HELP_SERVICE, requireDoomHelpService } from '@agimon-ai/doompi-extension-contracts/help';\nimport {\n DOOM_LOOP_LAUNCHERS_SERVICE,\n type DoomLoopLaunchersService,\n type LoopInstanceSnapshot,\n type LoopLauncherRegistration,\n type LoopLauncherSummary,\n} from '@agimon-ai/doompi-extension-contracts/loop-launchers';\nimport { DOOM_UI_HUB_SERVICE, requireDoomUiHub } from '@agimon-ai/doompi-extension-contracts/ui-hub';\nimport type { Context } from '@deepseek-ai/cordis';\nimport type { ExtensionAPI, ExtensionContext } from '@earendil-works/pi-coding-agent';\nimport { registerCommands } from '../../commands/loopCommand.ts';\nimport { createDoomLoopLaunchersService } from '../../services/loopLaunchers.ts';\nimport { openLoopListOverlay } from '../../tui/loopListOverlay.ts';\nimport { openStartLoopOverlay } from '../../tui/startLoopOverlay.ts';\nimport { formatLoopStatusView, LOOP_VIEW_STATUS_KEY } from '../../types/loopView.ts';\nimport { createDefaultLoopLauncher } from './defaultLoopLauncher.ts';\nimport { registerLeaderContribution } from './leader.ts';\nimport {\n ACTIVE_MODE_COLOR,\n LOOPS_GROUP_ORDER,\n MODE_STATUS_ID,\n NOTIFY_INFO_LEVEL,\n PACKAGE_SOURCE,\n STATUS_KEY,\n} from './loopConstants.ts';\n\nconst MODE_ACTION_START = 'start';\nconst MODE_ACTION_STOP = 'stop';\nconst SESSION_REPLACED_REASON = 'Pi session replaced.';\nconst SESSION_SHUTDOWN_REASON = 'Pi session shut down.';\n\ninterface ActiveLoopSession {\n readonly context: ExtensionContext;\n readonly hostSession: DoomCordisSessionService;\n readonly launchers: DoomLoopLaunchersService;\n}\n\nfunction loopModeState(\n launchers: readonly LoopLauncherSummary[],\n instances: readonly LoopInstanceSnapshot[],\n): MinorModeState {\n const active = instances.length > 0;\n return {\n activation: active ? 'active' : 'inactive',\n condition: instances.some(({ state }) => state === 'starting' || state === 'stopping') ? 'queued' : 'ready',\n ...(active ? { detail: `${instances.length} active`, color: ACTIVE_MODE_COLOR } : {}),\n actions: [\n ...(launchers.length > 0\n ? [{ id: MODE_ACTION_START, enabled: true } as const]\n : [{ id: MODE_ACTION_START, enabled: false, disabledReason: 'No loop launchers are registered.' } as const]),\n ...(active\n ? [{ id: MODE_ACTION_STOP, enabled: true } as const]\n : [{ id: MODE_ACTION_STOP, enabled: false, disabledReason: 'No loops are active.' } as const]),\n ],\n };\n}\n\n/** Install Loop state and external resources into its host-owned Cordis plugin fiber. */\nexport function installLoopRuntime(cordis: Context, pi: ExtensionAPI): void {\n let active = true;\n let activeSession: ActiveLoopSession | undefined;\n let mode: MinorModeOwnerHandle | undefined;\n let disposeLeader: (() => void) | undefined;\n\n const currentSession = (context: ExtensionContext): ActiveLoopSession | undefined => {\n const binding = activeSession;\n if (\n !active ||\n !binding ||\n binding.context.sessionManager !== context.sessionManager ||\n binding.hostSession.sessionId !== context.sessionManager.getSessionId()\n ) {\n return undefined;\n }\n return binding;\n };\n\n const clearStatuses = (binding: ActiveLoopSession): void => {\n binding.context.ui?.setStatus(STATUS_KEY, undefined);\n if (binding.context.mode !== 'tui') binding.context.ui?.setStatus(LOOP_VIEW_STATUS_KEY, undefined);\n };\n const publishStatus = (binding: ActiveLoopSession): void => {\n if (!active || activeSession !== binding) return;\n const launchers = binding.launchers.listLaunchers();\n const instances = binding.launchers.listInstances();\n binding.context.ui?.setStatus(STATUS_KEY, instances.length ? `loops: ${instances.length}` : undefined);\n if (binding.context.mode !== 'tui') {\n binding.context.ui?.setStatus(LOOP_VIEW_STATUS_KEY, formatLoopStatusView(instances));\n }\n mode?.publish(loopModeState(launchers, instances));\n };\n\n cordis.effect(\n () => () => {\n active = false;\n const binding = activeSession;\n activeSession = undefined;\n if (binding) clearStatuses(binding);\n mode?.publish(loopModeState([], []));\n mode?.dispose();\n disposeLeader?.();\n disposeLeader = undefined;\n mode = undefined;\n },\n `${PACKAGE_SOURCE}/runtime`,\n );\n\n const defaultLauncher = createDefaultLoopLauncher(pi);\n cordis.inject([DOOM_MINOR_MODE_CATALOG_SERVICE], (modeContext) => {\n const owner = registerMinorModeOwner<ExtensionContext>(requireMinorModeCatalog(modeContext), {\n descriptor: {\n source: PACKAGE_SOURCE,\n id: MODE_STATUS_ID,\n label: 'Loop',\n description: 'Session-scoped recurring prompt loops.',\n order: LOOPS_GROUP_ORDER,\n actions: [\n {\n id: MODE_ACTION_START,\n label: 'Start',\n description: 'Start a loop with a registered launcher.',\n contexts: ['tui', 'headless'],\n parameters: [\n { name: 'launcherId', label: 'Launcher', kind: 'string', required: true, minLength: 1 },\n { name: 'instanceId', label: 'Instance ID', kind: 'string', required: false, minLength: 1 },\n ],\n },\n {\n id: MODE_ACTION_STOP,\n label: 'Stop',\n description: 'Stop one active loop instance.',\n contexts: ['tui', 'headless'],\n parameters: [\n { name: 'instanceId', label: 'Instance ID', kind: 'string', required: true, minLength: 1 },\n { name: 'reason', label: 'Reason', kind: 'string', required: false, minLength: 1 },\n ],\n },\n ],\n },\n initialState: loopModeState([], []),\n async handleAction(actionId, argumentsValue, execution) {\n const binding = currentSession(execution.context);\n if (!binding) throw new Error('Loop launchers are unavailable for the active session.');\n if (actionId === MODE_ACTION_START) {\n const instance = await binding.launchers.launch(\n argumentsValue.launcherId as string,\n argumentsValue.instanceId ? { instanceId: argumentsValue.instanceId as string } : {},\n );\n if (activeSession !== binding) throw new Error('Loop action became stale.');\n return { message: instance ? `Loop '${instance.instanceId}' started.` : 'Loop launch was cancelled.' };\n }\n if (actionId === MODE_ACTION_STOP) {\n const stopped = await binding.launchers.stop(\n argumentsValue.instanceId as string,\n (argumentsValue.reason as string | undefined) ?? 'Stopped through minor_mode.',\n );\n if (activeSession !== binding) throw new Error('Loop action became stale.');\n return { message: stopped ? 'Loop stopped.' : 'Loop instance was not active.' };\n }\n throw new Error(`Unknown loop mode action: ${actionId}`);\n },\n });\n mode = owner;\n const binding = activeSession;\n if (binding) publishStatus(binding);\n return () => {\n owner.dispose();\n if (mode === owner) mode = undefined;\n };\n });\n cordis.inject([DOOM_UI_HUB_SERVICE], (uiContext) => {\n const dispose = registerLeaderContribution(requireDoomUiHub(uiContext));\n disposeLeader = dispose;\n return () => {\n dispose();\n if (disposeLeader === dispose) disposeLeader = undefined;\n };\n });\n\n registerCommands(pi, {\n async start(ctx) {\n const binding = currentSession(ctx);\n if (!binding) return;\n const launchers = binding.launchers.listLaunchers();\n if (!launchers.length) {\n ctx.ui.notify('No loop launchers are registered for this session.', NOTIFY_INFO_LEVEL);\n return;\n }\n const launcherId = await openStartLoopOverlay(ctx, launchers);\n if (activeSession !== binding || !launcherId) return;\n try {\n const instance = await binding.launchers.launch(launcherId);\n if (activeSession !== binding) return;\n if (instance) ctx.ui.notify(`${instance.label ?? instance.launcherLabel} started.`, NOTIFY_INFO_LEVEL);\n } catch (error) {\n if (activeSession !== binding) return;\n ctx.ui.notify(`Loop could not start: ${error instanceof Error ? error.message : String(error)}`, 'error');\n }\n },\n async list(ctx) {\n const binding = currentSession(ctx);\n if (!binding) return;\n await openLoopListOverlay(ctx, binding.launchers);\n },\n });\n\n cordis.inject([DOOM_CORDIS_SESSION_SERVICE], async (sessionContext) => {\n const hostSession = sessionContext.get(DOOM_CORDIS_SESSION_SERVICE) as DoomCordisSessionService;\n const launchers = createDoomLoopLaunchersService({\n generation: `${hostSession.generation}:loop-launchers`,\n createInstanceId: () => crypto.randomUUID(),\n timestamp: () => new Date().toISOString(),\n });\n const binding: ActiveLoopSession = { context: hostSession.context, hostSession, launchers };\n activeSession = binding;\n sessionContext.provide(DOOM_LOOP_LAUNCHERS_SERVICE, launchers);\n\n let defaultRegistration: LoopLauncherRegistration;\n let unsubscribe: () => void;\n try {\n defaultRegistration = defaultLauncher.register(hostSession.context, launchers);\n unsubscribe = launchers.subscribe(() => publishStatus(binding));\n publishStatus(binding);\n } catch (error) {\n if (activeSession === binding) activeSession = undefined;\n await launchers.dispose(SESSION_REPLACED_REASON);\n throw error;\n }\n\n return async () => {\n if (activeSession === binding) activeSession = undefined;\n unsubscribe();\n clearStatuses(binding);\n mode?.publish(loopModeState([], []));\n const cleanupErrors: unknown[] = [];\n try {\n await defaultRegistration.dispose(SESSION_REPLACED_REASON);\n } catch (error) {\n cleanupErrors.push(error);\n }\n try {\n await launchers.dispose(SESSION_SHUTDOWN_REASON);\n } catch (error) {\n cleanupErrors.push(error);\n }\n if (cleanupErrors.length > 0) throw new AggregateError(cleanupErrors, 'Loop session cleanup failed.');\n };\n });\n}\n\n/** The package's single standard Pi factory. */\nexport async function loopExtension(pi: ExtensionAPI): Promise<void> {\n const connection = await connectDoomCordisHost(pi, PACKAGE_SOURCE);\n const fiber = connection.root.plugin(loopPlugin, { pi });\n try {\n await fiber;\n } catch (error) {\n try {\n await fiber.dispose();\n } finally {\n await connection.dispose();\n }\n throw error;\n }\n let disposal: Promise<void> | undefined;\n pi.on(\n 'session_shutdown',\n () =>\n (disposal ??= (async () => {\n try {\n await fiber.dispose();\n } finally {\n await connection.dispose();\n }\n })()),\n );\n}\n\ninterface LoopPluginConfig {\n readonly pi: ExtensionAPI;\n}\n\nfunction loopPlugin(cordis: Context, config: LoopPluginConfig): void {\n cordis.inject([DOOM_HELP_SERVICE], (helpContext) => {\n const contribution = requireDoomHelpService(helpContext).register({\n source: PACKAGE_SOURCE,\n moduleUrl: import.meta.url,\n skills: [\n {\n name: 'doompi-use-loop',\n description: 'Use Doom Pi Loop to start, inspect, and stop session-scoped recurring prompts safely.',\n },\n ],\n });\n return () => contribution.dispose();\n });\n installLoopRuntime(cordis, config.pi);\n}\n\nexport default loopExtension;\n"],"mappings":"8mBAuCA,MAAM,EAAoB,QACpB,EAAmB,OACnB,EAA0B,uBAShC,SAAS,EACP,EACA,EACgB,CAChB,IAAM,EAAS,EAAU,OAAS,EAClC,MAAO,CACL,WAAY,EAAS,SAAW,WAChC,UAAW,EAAU,MAAM,CAAE,WAAY,IAAU,YAAc,IAAU,UAAU,EAAI,SAAW,QACpG,GAAI,EAAS,CAAE,OAAQ,GAAG,EAAU,OAAO,SAAU,MAAOA,EAAAA,iBAAkB,EAAI,CAAC,EACnF,QAAS,CACP,GAAI,EAAU,OAAS,EACnB,CAAC,CAAE,GAAI,EAAmB,QAAS,EAAK,CAAU,EAClD,CAAC,CAAE,GAAI,EAAmB,QAAS,GAAO,eAAgB,mCAAoC,CAAU,EAC5G,GAAI,EACA,CAAC,CAAE,GAAI,EAAkB,QAAS,EAAK,CAAU,EAC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,EAAG,GACD,uBAEG,KAAc,SAAY,CACzB,GAAI,CACF,MAAM,EAAM,QAAQ,CACtB,QAAU,CACR,MAAM,EAAW,QAAQ,CAC3B,CACF,EAAA,CAAG,CACP,CACF,CAMA,SAAS,EAAW,EAAiB,EAAgC,CACnE,EAAO,OAAO,CAACgB,EAAAA,iBAAiB,EAAI,GAAgB,CAClD,IAAM,GAAA,EAAeC,EAAAA,uBAAAA,CAAuB,CAAW,CAAC,CAAC,SAAS,CAChE,OAAQjB,EAAAA,eACR,UAAA,QAAA,KAAA,CAAA,CAAA,cAAA,UAAA,CAAA,CAAA,KACA,OAAQ,CACN,CACE,KAAM,kBACN,YAAa,uFACf,CACF,CACF,CAAC,EACD,UAAa,EAAa,QAAQ,CACpC,CAAC,EACD,EAAmB,EAAQ,EAAO,EAAE,CACtC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension.d.cts","names":[],"sources":["../../../src/adapters/pi/extension.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"extension.d.cts","names":[],"sources":["../../../src/adapters/pi/extension.ts"],"mappings":";;;;iBAuEgB,mBAAmB,QAAQ,SAAS,IAAI;;iBAiMlC,cAAc,IAAI,eAAe"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension.d.mts","names":[],"sources":["../../../src/adapters/pi/extension.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"extension.d.mts","names":[],"sources":["../../../src/adapters/pi/extension.ts"],"mappings":";;;;iBAuEgB,mBAAmB,QAAQ,SAAS,IAAI;;iBAiMlC,cAAc,IAAI,eAAe"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{registerCommands as e}from"../../commands/loopCommand.mjs";import{createDoomLoopLaunchersService as t}from"../../services/loopLaunchers.mjs";import{openLoopListOverlay as n}from"../../tui/loopListOverlay.mjs";import{openStartLoopOverlay as r}from"../../tui/startLoopOverlay.mjs";import{
|
|
1
|
+
import{registerCommands as e}from"../../commands/loopCommand.mjs";import{createDoomLoopLaunchersService as t}from"../../services/loopLaunchers.mjs";import{openLoopListOverlay as n}from"../../tui/loopListOverlay.mjs";import{openStartLoopOverlay as r}from"../../tui/startLoopOverlay.mjs";import{LOOP_VIEW_STATUS_KEY as i,formatLoopStatusView as a}from"../../types/loopView.mjs";import{ACTIVE_MODE_COLOR as o,MODE_STATUS_ID as s,NOTIFY_INFO_LEVEL as c,PACKAGE_SOURCE as l,STATUS_KEY as u}from"./loopConstants.mjs";import{createDefaultLoopLauncher as d}from"./defaultLoopLauncher.mjs";import{registerLeaderContribution as f}from"./leader.mjs";import{DOOM_MINOR_MODE_CATALOG_SERVICE as p,registerMinorModeOwner as m,requireMinorModeCatalog as h}from"@agimon-ai/doompi-extension-contracts/mode";import{DOOM_CORDIS_SESSION_SERVICE as g,connectDoomCordisHost as _}from"@agimon-ai/doompi-extension-contracts/cordis-host";import{DOOM_HELP_SERVICE as v,requireDoomHelpService as y}from"@agimon-ai/doompi-extension-contracts/help";import{DOOM_LOOP_LAUNCHERS_SERVICE as b}from"@agimon-ai/doompi-extension-contracts/loop-launchers";import{DOOM_UI_HUB_SERVICE as x,requireDoomUiHub as S}from"@agimon-ai/doompi-extension-contracts/ui-hub";const C=`start`,w=`stop`,T=`Pi session replaced.`;function E(e,t){let n=t.length>0;return{activation:n?`active`:`inactive`,condition:t.some(({state:e})=>e===`starting`||e===`stopping`)?`queued`:`ready`,...n?{detail:`${t.length} active`,color:o}:{},actions:[...e.length>0?[{id:C,enabled:!0}]:[{id:C,enabled:!1,disabledReason:`No loop launchers are registered.`}],...n?[{id:w,enabled:!0}]:[{id:w,enabled:!1,disabledReason:`No loops are active.`}]]}}function D(o,_){let v=!0,y,D,O,k=e=>{let t=y;if(!(!v||!t||t.context.sessionManager!==e.sessionManager||t.hostSession.sessionId!==e.sessionManager.getSessionId()))return t},A=e=>{e.context.ui?.setStatus(u,void 0),e.context.mode!==`tui`&&e.context.ui?.setStatus(i,void 0)},j=e=>{if(!v||y!==e)return;let t=e.launchers.listLaunchers(),n=e.launchers.listInstances();e.context.ui?.setStatus(u,n.length?`loops: ${n.length}`:void 0),e.context.mode!==`tui`&&e.context.ui?.setStatus(i,a(n)),D?.publish(E(t,n))};o.effect(()=>()=>{v=!1;let e=y;y=void 0,e&&A(e),D?.publish(E([],[])),D?.dispose(),O?.(),O=void 0,D=void 0},`${l}/runtime`);let M=d(_);o.inject([p],e=>{let t=m(h(e),{descriptor:{source:l,id:s,label:`Loop`,description:`Session-scoped recurring prompt loops.`,order:60,actions:[{id:C,label:`Start`,description:`Start a loop with a registered launcher.`,contexts:[`tui`,`headless`],parameters:[{name:`launcherId`,label:`Launcher`,kind:`string`,required:!0,minLength:1},{name:`instanceId`,label:`Instance ID`,kind:`string`,required:!1,minLength:1}]},{id:w,label:`Stop`,description:`Stop one active loop instance.`,contexts:[`tui`,`headless`],parameters:[{name:`instanceId`,label:`Instance ID`,kind:`string`,required:!0,minLength:1},{name:`reason`,label:`Reason`,kind:`string`,required:!1,minLength:1}]}]},initialState:E([],[]),async handleAction(e,t,n){let r=k(n.context);if(!r)throw Error(`Loop launchers are unavailable for the active session.`);if(e===C){let e=await r.launchers.launch(t.launcherId,t.instanceId?{instanceId:t.instanceId}:{});if(y!==r)throw Error(`Loop action became stale.`);return{message:e?`Loop '${e.instanceId}' started.`:`Loop launch was cancelled.`}}if(e===w){let e=await r.launchers.stop(t.instanceId,t.reason??`Stopped through minor_mode.`);if(y!==r)throw Error(`Loop action became stale.`);return{message:e?`Loop stopped.`:`Loop instance was not active.`}}throw Error(`Unknown loop mode action: ${e}`)}});D=t;let n=y;return n&&j(n),()=>{t.dispose(),D===t&&(D=void 0)}}),o.inject([x],e=>{let t=f(S(e));return O=t,()=>{t(),O===t&&(O=void 0)}}),e(_,{async start(e){let t=k(e);if(!t)return;let n=t.launchers.listLaunchers();if(!n.length){e.ui.notify(`No loop launchers are registered for this session.`,c);return}let i=await r(e,n);if(!(y!==t||!i))try{let n=await t.launchers.launch(i);if(y!==t)return;n&&e.ui.notify(`${n.label??n.launcherLabel} started.`,c)}catch(n){if(y!==t)return;e.ui.notify(`Loop could not start: ${n instanceof Error?n.message:String(n)}`,`error`)}},async list(e){let t=k(e);t&&await n(e,t.launchers)}}),o.inject([g],async e=>{let n=e.get(g),r=t({generation:`${n.generation}:loop-launchers`,createInstanceId:()=>crypto.randomUUID(),timestamp:()=>new Date().toISOString()}),i={context:n.context,hostSession:n,launchers:r};y=i,e.provide(b,r);let a,o;try{a=M.register(n.context,r),o=r.subscribe(()=>j(i)),j(i)}catch(e){throw y===i&&(y=void 0),await r.dispose(T),e}return async()=>{y===i&&(y=void 0),o(),A(i),D?.publish(E([],[]));let e=[];try{await a.dispose(T)}catch(t){e.push(t)}try{await r.dispose(`Pi session shut down.`)}catch(t){e.push(t)}if(e.length>0)throw AggregateError(e,`Loop session cleanup failed.`)}})}async function O(e){let t=await _(e,l),n=t.root.plugin(k,{pi:e});try{await n}catch(e){try{await n.dispose()}finally{await t.dispose()}throw e}let r;e.on(`session_shutdown`,()=>r??=(async()=>{try{await n.dispose()}finally{await t.dispose()}})())}function k(e,t){e.inject([v],e=>{let t=y(e).register({source:l,moduleUrl:import.meta.url,skills:[{name:`doompi-use-loop`,description:`Use Doom Pi Loop to start, inspect, and stop session-scoped recurring prompts safely.`}]});return()=>t.dispose()}),D(e,t.pi)}export{O as default,O as loopExtension,D as installLoopRuntime};
|
|
2
2
|
//# sourceMappingURL=extension.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension.mjs","names":[],"sources":["../../../src/adapters/pi/extension.ts"],"sourcesContent":["import {\n DOOM_MINOR_MODE_CATALOG_SERVICE,\n type MinorModeOwnerHandle,\n type MinorModeState,\n registerMinorModeOwner,\n requireMinorModeCatalog,\n} from '@agimon-ai/doompi-extension-contracts/mode';\nimport {\n connectDoomCordisHost,\n DOOM_CORDIS_SESSION_SERVICE,\n type DoomCordisSessionService,\n} from '@agimon-ai/doompi-extension-contracts/cordis-host';\nimport { DOOM_HELP_SERVICE, requireDoomHelpService } from '@agimon-ai/doompi-extension-contracts/help';\nimport {\n DOOM_LOOP_LAUNCHERS_SERVICE,\n type DoomLoopLaunchersService,\n type LoopInstanceSnapshot,\n type LoopLauncherRegistration,\n type LoopLauncherSummary,\n} from '@agimon-ai/doompi-extension-contracts/loop-launchers';\nimport { DOOM_UI_HUB_SERVICE, requireDoomUiHub } from '@agimon-ai/doompi-extension-contracts/ui-hub';\nimport type { Context } from '@deepseek-ai/cordis';\nimport type { ExtensionAPI, ExtensionContext } from '@earendil-works/pi-coding-agent';\nimport { registerCommands } from '../../commands/loopCommand.ts';\nimport { createDoomLoopLaunchersService } from '../../services/loopLaunchers.ts';\nimport { openLoopListOverlay } from '../../tui/loopListOverlay.ts';\nimport { openStartLoopOverlay } from '../../tui/startLoopOverlay.ts';\nimport { createDefaultLoopLauncher } from './defaultLoopLauncher.ts';\nimport { registerLeaderContribution } from './leader.ts';\nimport {\n ACTIVE_MODE_COLOR,\n LOOPS_GROUP_ORDER,\n MODE_STATUS_ID,\n NOTIFY_INFO_LEVEL,\n PACKAGE_SOURCE,\n STATUS_KEY,\n} from './loopConstants.ts';\n\nconst MODE_ACTION_START = 'start';\nconst MODE_ACTION_STOP = 'stop';\nconst SESSION_REPLACED_REASON = 'Pi session replaced.';\nconst SESSION_SHUTDOWN_REASON = 'Pi session shut down.';\n\ninterface ActiveLoopSession {\n readonly context: ExtensionContext;\n readonly hostSession: DoomCordisSessionService;\n readonly launchers: DoomLoopLaunchersService;\n}\n\nfunction loopModeState(\n launchers: readonly LoopLauncherSummary[],\n instances: readonly LoopInstanceSnapshot[],\n): MinorModeState {\n const active = instances.length > 0;\n return {\n activation: active ? 'active' : 'inactive',\n condition: instances.some(({ state }) => state === 'starting' || state === 'stopping') ? 'queued' : 'ready',\n ...(active ? { detail: `${instances.length} active`, color: ACTIVE_MODE_COLOR } : {}),\n actions: [\n ...(launchers.length > 0\n ? [{ id: MODE_ACTION_START, enabled: true } as const]\n : [{ id: MODE_ACTION_START, enabled: false, disabledReason: 'No loop launchers are registered.' } as const]),\n ...(active\n ? [{ id: MODE_ACTION_STOP, enabled: true } as const]\n : [{ id: MODE_ACTION_STOP, enabled: false, disabledReason: 'No loops are active.' } as const]),\n ],\n };\n}\n\n/** Install Loop state and external resources into its host-owned Cordis plugin fiber. */\nexport function installLoopRuntime(cordis: Context, pi: ExtensionAPI): void {\n let active = true;\n let activeSession: ActiveLoopSession | undefined;\n let mode: MinorModeOwnerHandle | undefined;\n let disposeLeader: (() => void) | undefined;\n\n const currentSession = (context: ExtensionContext): ActiveLoopSession | undefined => {\n const binding = activeSession;\n if (\n !active ||\n !binding ||\n binding.context.sessionManager !== context.sessionManager ||\n binding.hostSession.sessionId !== context.sessionManager.getSessionId()\n ) {\n return undefined;\n }\n return binding;\n };\n\n const publishStatus = (binding: ActiveLoopSession): void => {\n if (!active || activeSession !== binding) return;\n const launchers = binding.launchers.listLaunchers();\n const instances = binding.launchers.listInstances();\n binding.context.ui?.setStatus(STATUS_KEY, instances.length ? `loops: ${instances.length}` : undefined);\n mode?.publish(loopModeState(launchers, instances));\n };\n\n cordis.effect(\n () => () => {\n active = false;\n const binding = activeSession;\n activeSession = undefined;\n binding?.context.ui?.setStatus(STATUS_KEY, undefined);\n mode?.publish(loopModeState([], []));\n mode?.dispose();\n disposeLeader?.();\n disposeLeader = undefined;\n mode = undefined;\n },\n `${PACKAGE_SOURCE}/runtime`,\n );\n\n const defaultLauncher = createDefaultLoopLauncher(pi);\n cordis.inject([DOOM_MINOR_MODE_CATALOG_SERVICE], (modeContext) => {\n const owner = registerMinorModeOwner<ExtensionContext>(requireMinorModeCatalog(modeContext), {\n descriptor: {\n source: PACKAGE_SOURCE,\n id: MODE_STATUS_ID,\n label: 'Loop',\n description: 'Session-scoped recurring prompt loops.',\n order: LOOPS_GROUP_ORDER,\n actions: [\n {\n id: MODE_ACTION_START,\n label: 'Start',\n description: 'Start a loop with a registered launcher.',\n contexts: ['tui', 'headless'],\n parameters: [\n { name: 'launcherId', label: 'Launcher', kind: 'string', required: true, minLength: 1 },\n { name: 'instanceId', label: 'Instance ID', kind: 'string', required: false, minLength: 1 },\n ],\n },\n {\n id: MODE_ACTION_STOP,\n label: 'Stop',\n description: 'Stop one active loop instance.',\n contexts: ['tui', 'headless'],\n parameters: [\n { name: 'instanceId', label: 'Instance ID', kind: 'string', required: true, minLength: 1 },\n { name: 'reason', label: 'Reason', kind: 'string', required: false, minLength: 1 },\n ],\n },\n ],\n },\n initialState: loopModeState([], []),\n async handleAction(actionId, argumentsValue, execution) {\n const binding = currentSession(execution.context);\n if (!binding) throw new Error('Loop launchers are unavailable for the active session.');\n if (actionId === MODE_ACTION_START) {\n const instance = await binding.launchers.launch(\n argumentsValue.launcherId as string,\n argumentsValue.instanceId ? { instanceId: argumentsValue.instanceId as string } : {},\n );\n if (activeSession !== binding) throw new Error('Loop action became stale.');\n return { message: instance ? `Loop '${instance.instanceId}' started.` : 'Loop launch was cancelled.' };\n }\n if (actionId === MODE_ACTION_STOP) {\n const stopped = await binding.launchers.stop(\n argumentsValue.instanceId as string,\n (argumentsValue.reason as string | undefined) ?? 'Stopped through minor_mode.',\n );\n if (activeSession !== binding) throw new Error('Loop action became stale.');\n return { message: stopped ? 'Loop stopped.' : 'Loop instance was not active.' };\n }\n throw new Error(`Unknown loop mode action: ${actionId}`);\n },\n });\n mode = owner;\n const binding = activeSession;\n if (binding) publishStatus(binding);\n return () => {\n owner.dispose();\n if (mode === owner) mode = undefined;\n };\n });\n cordis.inject([DOOM_UI_HUB_SERVICE], (uiContext) => {\n const dispose = registerLeaderContribution(requireDoomUiHub(uiContext));\n disposeLeader = dispose;\n return () => {\n dispose();\n if (disposeLeader === dispose) disposeLeader = undefined;\n };\n });\n\n registerCommands(pi, {\n async start(ctx) {\n const binding = currentSession(ctx);\n if (!binding) return;\n const launchers = binding.launchers.listLaunchers();\n if (!launchers.length) {\n ctx.ui.notify('No loop launchers are registered for this session.', NOTIFY_INFO_LEVEL);\n return;\n }\n const launcherId = await openStartLoopOverlay(ctx, launchers);\n if (activeSession !== binding || !launcherId) return;\n try {\n const instance = await binding.launchers.launch(launcherId);\n if (activeSession !== binding) return;\n if (instance) ctx.ui.notify(`${instance.label ?? instance.launcherLabel} started.`, NOTIFY_INFO_LEVEL);\n } catch (error) {\n if (activeSession !== binding) return;\n ctx.ui.notify(`Loop could not start: ${error instanceof Error ? error.message : String(error)}`, 'error');\n }\n },\n async list(ctx) {\n const binding = currentSession(ctx);\n if (!binding) return;\n await openLoopListOverlay(ctx, binding.launchers);\n },\n });\n\n cordis.inject([DOOM_CORDIS_SESSION_SERVICE], async (sessionContext) => {\n const hostSession = sessionContext.get(DOOM_CORDIS_SESSION_SERVICE) as DoomCordisSessionService;\n const launchers = createDoomLoopLaunchersService({\n generation: `${hostSession.generation}:loop-launchers`,\n createInstanceId: () => crypto.randomUUID(),\n timestamp: () => new Date().toISOString(),\n });\n const binding: ActiveLoopSession = { context: hostSession.context, hostSession, launchers };\n activeSession = binding;\n sessionContext.provide(DOOM_LOOP_LAUNCHERS_SERVICE, launchers);\n\n let defaultRegistration: LoopLauncherRegistration;\n let unsubscribe: () => void;\n try {\n defaultRegistration = defaultLauncher.register(hostSession.context, launchers);\n unsubscribe = launchers.subscribe(() => publishStatus(binding));\n publishStatus(binding);\n } catch (error) {\n if (activeSession === binding) activeSession = undefined;\n await launchers.dispose(SESSION_REPLACED_REASON);\n throw error;\n }\n\n return async () => {\n if (activeSession === binding) activeSession = undefined;\n unsubscribe();\n binding.context.ui?.setStatus(STATUS_KEY, undefined);\n mode?.publish(loopModeState([], []));\n const cleanupErrors: unknown[] = [];\n try {\n await defaultRegistration.dispose(SESSION_REPLACED_REASON);\n } catch (error) {\n cleanupErrors.push(error);\n }\n try {\n await launchers.dispose(SESSION_SHUTDOWN_REASON);\n } catch (error) {\n cleanupErrors.push(error);\n }\n if (cleanupErrors.length > 0) throw new AggregateError(cleanupErrors, 'Loop session cleanup failed.');\n };\n });\n}\n\n/** The package's single standard Pi factory. */\nexport async function loopExtension(pi: ExtensionAPI): Promise<void> {\n const connection = await connectDoomCordisHost(pi, PACKAGE_SOURCE);\n const fiber = connection.root.plugin(loopPlugin, { pi });\n try {\n await fiber;\n } catch (error) {\n try {\n await fiber.dispose();\n } finally {\n await connection.dispose();\n }\n throw error;\n }\n let disposal: Promise<void> | undefined;\n pi.on(\n 'session_shutdown',\n () =>\n (disposal ??= (async () => {\n try {\n await fiber.dispose();\n } finally {\n await connection.dispose();\n }\n })()),\n );\n}\n\ninterface LoopPluginConfig {\n readonly pi: ExtensionAPI;\n}\n\nfunction loopPlugin(cordis: Context, config: LoopPluginConfig): void {\n cordis.inject([DOOM_HELP_SERVICE], (helpContext) => {\n const contribution = requireDoomHelpService(helpContext).register({\n source: PACKAGE_SOURCE,\n moduleUrl: import.meta.url,\n skills: [\n {\n name: 'doompi-use-loop',\n description: 'Use Doom Pi Loop to start, inspect, and stop session-scoped recurring prompts safely.',\n },\n ],\n });\n return () => contribution.dispose();\n });\n installLoopRuntime(cordis, config.pi);\n}\n\nexport default loopExtension;\n"],"mappings":"6mCAsCA,MAAM,EAAoB,QACpB,EAAmB,OACnB,EAA0B,uBAShC,SAAS,EACP,EACA,EACgB,CAChB,IAAM,EAAS,EAAU,OAAS,EAClC,MAAO,CACL,WAAY,EAAS,SAAW,WAChC,UAAW,EAAU,MAAM,CAAE,WAAY,IAAU,YAAc,IAAU,UAAU,EAAI,SAAW,QACpG,GAAI,EAAS,CAAE,OAAQ,GAAG,EAAU,OAAO,SAAU,MAAO,CAAkB,EAAI,CAAC,EACnF,QAAS,CACP,GAAI,EAAU,OAAS,EACnB,CAAC,CAAE,GAAI,EAAmB,QAAS,EAAK,CAAU,EAClD,CAAC,CAAE,GAAI,EAAmB,QAAS,GAAO,eAAgB,mCAAoC,CAAU,EAC5G,GAAI,EACA,CAAC,CAAE,GAAI,EAAkB,QAAS,EAAK,CAAU,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sources":["../../../src/adapters/pi/extension.ts"],"sourcesContent":["import {\n DOOM_MINOR_MODE_CATALOG_SERVICE,\n type MinorModeOwnerHandle,\n type MinorModeState,\n registerMinorModeOwner,\n requireMinorModeCatalog,\n} from '@agimon-ai/doompi-extension-contracts/mode';\nimport {\n connectDoomCordisHost,\n DOOM_CORDIS_SESSION_SERVICE,\n type DoomCordisSessionService,\n} from '@agimon-ai/doompi-extension-contracts/cordis-host';\nimport { DOOM_HELP_SERVICE, requireDoomHelpService } from '@agimon-ai/doompi-extension-contracts/help';\nimport {\n DOOM_LOOP_LAUNCHERS_SERVICE,\n type DoomLoopLaunchersService,\n type LoopInstanceSnapshot,\n type LoopLauncherRegistration,\n type LoopLauncherSummary,\n} from '@agimon-ai/doompi-extension-contracts/loop-launchers';\nimport { DOOM_UI_HUB_SERVICE, requireDoomUiHub } from '@agimon-ai/doompi-extension-contracts/ui-hub';\nimport type { Context } from '@deepseek-ai/cordis';\nimport type { ExtensionAPI, ExtensionContext } from '@earendil-works/pi-coding-agent';\nimport { registerCommands } from '../../commands/loopCommand.ts';\nimport { createDoomLoopLaunchersService } from '../../services/loopLaunchers.ts';\nimport { openLoopListOverlay } from '../../tui/loopListOverlay.ts';\nimport { openStartLoopOverlay } from '../../tui/startLoopOverlay.ts';\nimport { formatLoopStatusView, LOOP_VIEW_STATUS_KEY } from '../../types/loopView.ts';\nimport { createDefaultLoopLauncher } from './defaultLoopLauncher.ts';\nimport { registerLeaderContribution } from './leader.ts';\nimport {\n ACTIVE_MODE_COLOR,\n LOOPS_GROUP_ORDER,\n MODE_STATUS_ID,\n NOTIFY_INFO_LEVEL,\n PACKAGE_SOURCE,\n STATUS_KEY,\n} from './loopConstants.ts';\n\nconst MODE_ACTION_START = 'start';\nconst MODE_ACTION_STOP = 'stop';\nconst SESSION_REPLACED_REASON = 'Pi session replaced.';\nconst SESSION_SHUTDOWN_REASON = 'Pi session shut down.';\n\ninterface ActiveLoopSession {\n readonly context: ExtensionContext;\n readonly hostSession: DoomCordisSessionService;\n readonly launchers: DoomLoopLaunchersService;\n}\n\nfunction loopModeState(\n launchers: readonly LoopLauncherSummary[],\n instances: readonly LoopInstanceSnapshot[],\n): MinorModeState {\n const active = instances.length > 0;\n return {\n activation: active ? 'active' : 'inactive',\n condition: instances.some(({ state }) => state === 'starting' || state === 'stopping') ? 'queued' : 'ready',\n ...(active ? { detail: `${instances.length} active`, color: ACTIVE_MODE_COLOR } : {}),\n actions: [\n ...(launchers.length > 0\n ? [{ id: MODE_ACTION_START, enabled: true } as const]\n : [{ id: MODE_ACTION_START, enabled: false, disabledReason: 'No loop launchers are registered.' } as const]),\n ...(active\n ? [{ id: MODE_ACTION_STOP, enabled: true } as const]\n : [{ id: MODE_ACTION_STOP, enabled: false, disabledReason: 'No loops are active.' } as const]),\n ],\n };\n}\n\n/** Install Loop state and external resources into its host-owned Cordis plugin fiber. */\nexport function installLoopRuntime(cordis: Context, pi: ExtensionAPI): void {\n let active = true;\n let activeSession: ActiveLoopSession | undefined;\n let mode: MinorModeOwnerHandle | undefined;\n let disposeLeader: (() => void) | undefined;\n\n const currentSession = (context: ExtensionContext): ActiveLoopSession | undefined => {\n const binding = activeSession;\n if (\n !active ||\n !binding ||\n binding.context.sessionManager !== context.sessionManager ||\n binding.hostSession.sessionId !== context.sessionManager.getSessionId()\n ) {\n return undefined;\n }\n return binding;\n };\n\n const clearStatuses = (binding: ActiveLoopSession): void => {\n binding.context.ui?.setStatus(STATUS_KEY, undefined);\n if (binding.context.mode !== 'tui') binding.context.ui?.setStatus(LOOP_VIEW_STATUS_KEY, undefined);\n };\n const publishStatus = (binding: ActiveLoopSession): void => {\n if (!active || activeSession !== binding) return;\n const launchers = binding.launchers.listLaunchers();\n const instances = binding.launchers.listInstances();\n binding.context.ui?.setStatus(STATUS_KEY, instances.length ? `loops: ${instances.length}` : undefined);\n if (binding.context.mode !== 'tui') {\n binding.context.ui?.setStatus(LOOP_VIEW_STATUS_KEY, formatLoopStatusView(instances));\n }\n mode?.publish(loopModeState(launchers, instances));\n };\n\n cordis.effect(\n () => () => {\n active = false;\n const binding = activeSession;\n activeSession = undefined;\n if (binding) clearStatuses(binding);\n mode?.publish(loopModeState([], []));\n mode?.dispose();\n disposeLeader?.();\n disposeLeader = undefined;\n mode = undefined;\n },\n `${PACKAGE_SOURCE}/runtime`,\n );\n\n const defaultLauncher = createDefaultLoopLauncher(pi);\n cordis.inject([DOOM_MINOR_MODE_CATALOG_SERVICE], (modeContext) => {\n const owner = registerMinorModeOwner<ExtensionContext>(requireMinorModeCatalog(modeContext), {\n descriptor: {\n source: PACKAGE_SOURCE,\n id: MODE_STATUS_ID,\n label: 'Loop',\n description: 'Session-scoped recurring prompt loops.',\n order: LOOPS_GROUP_ORDER,\n actions: [\n {\n id: MODE_ACTION_START,\n label: 'Start',\n description: 'Start a loop with a registered launcher.',\n contexts: ['tui', 'headless'],\n parameters: [\n { name: 'launcherId', label: 'Launcher', kind: 'string', required: true, minLength: 1 },\n { name: 'instanceId', label: 'Instance ID', kind: 'string', required: false, minLength: 1 },\n ],\n },\n {\n id: MODE_ACTION_STOP,\n label: 'Stop',\n description: 'Stop one active loop instance.',\n contexts: ['tui', 'headless'],\n parameters: [\n { name: 'instanceId', label: 'Instance ID', kind: 'string', required: true, minLength: 1 },\n { name: 'reason', label: 'Reason', kind: 'string', required: false, minLength: 1 },\n ],\n },\n ],\n },\n initialState: loopModeState([], []),\n async handleAction(actionId, argumentsValue, execution) {\n const binding = currentSession(execution.context);\n if (!binding) throw new Error('Loop launchers are unavailable for the active session.');\n if (actionId === MODE_ACTION_START) {\n const instance = await binding.launchers.launch(\n argumentsValue.launcherId as string,\n argumentsValue.instanceId ? { instanceId: argumentsValue.instanceId as string } : {},\n );\n if (activeSession !== binding) throw new Error('Loop action became stale.');\n return { message: instance ? `Loop '${instance.instanceId}' started.` : 'Loop launch was cancelled.' };\n }\n if (actionId === MODE_ACTION_STOP) {\n const stopped = await binding.launchers.stop(\n argumentsValue.instanceId as string,\n (argumentsValue.reason as string | undefined) ?? 'Stopped through minor_mode.',\n );\n if (activeSession !== binding) throw new Error('Loop action became stale.');\n return { message: stopped ? 'Loop stopped.' : 'Loop instance was not active.' };\n }\n throw new Error(`Unknown loop mode action: ${actionId}`);\n },\n });\n mode = owner;\n const binding = activeSession;\n if (binding) publishStatus(binding);\n return () => {\n owner.dispose();\n if (mode === owner) mode = undefined;\n };\n });\n cordis.inject([DOOM_UI_HUB_SERVICE], (uiContext) => {\n const dispose = registerLeaderContribution(requireDoomUiHub(uiContext));\n disposeLeader = dispose;\n return () => {\n dispose();\n if (disposeLeader === dispose) disposeLeader = undefined;\n };\n });\n\n registerCommands(pi, {\n async start(ctx) {\n const binding = currentSession(ctx);\n if (!binding) return;\n const launchers = binding.launchers.listLaunchers();\n if (!launchers.length) {\n ctx.ui.notify('No loop launchers are registered for this session.', NOTIFY_INFO_LEVEL);\n return;\n }\n const launcherId = await openStartLoopOverlay(ctx, launchers);\n if (activeSession !== binding || !launcherId) return;\n try {\n const instance = await binding.launchers.launch(launcherId);\n if (activeSession !== binding) return;\n if (instance) ctx.ui.notify(`${instance.label ?? instance.launcherLabel} started.`, NOTIFY_INFO_LEVEL);\n } catch (error) {\n if (activeSession !== binding) return;\n ctx.ui.notify(`Loop could not start: ${error instanceof Error ? error.message : String(error)}`, 'error');\n }\n },\n async list(ctx) {\n const binding = currentSession(ctx);\n if (!binding) return;\n await openLoopListOverlay(ctx, binding.launchers);\n },\n });\n\n cordis.inject([DOOM_CORDIS_SESSION_SERVICE], async (sessionContext) => {\n const hostSession = sessionContext.get(DOOM_CORDIS_SESSION_SERVICE) as DoomCordisSessionService;\n const launchers = createDoomLoopLaunchersService({\n generation: `${hostSession.generation}:loop-launchers`,\n createInstanceId: () => crypto.randomUUID(),\n timestamp: () => new Date().toISOString(),\n });\n const binding: ActiveLoopSession = { context: hostSession.context, hostSession, launchers };\n activeSession = binding;\n sessionContext.provide(DOOM_LOOP_LAUNCHERS_SERVICE, launchers);\n\n let defaultRegistration: LoopLauncherRegistration;\n let unsubscribe: () => void;\n try {\n defaultRegistration = defaultLauncher.register(hostSession.context, launchers);\n unsubscribe = launchers.subscribe(() => publishStatus(binding));\n publishStatus(binding);\n } catch (error) {\n if (activeSession === binding) activeSession = undefined;\n await launchers.dispose(SESSION_REPLACED_REASON);\n throw error;\n }\n\n return async () => {\n if (activeSession === binding) activeSession = undefined;\n unsubscribe();\n clearStatuses(binding);\n mode?.publish(loopModeState([], []));\n const cleanupErrors: unknown[] = [];\n try {\n await defaultRegistration.dispose(SESSION_REPLACED_REASON);\n } catch (error) {\n cleanupErrors.push(error);\n }\n try {\n await launchers.dispose(SESSION_SHUTDOWN_REASON);\n } catch (error) {\n cleanupErrors.push(error);\n }\n if (cleanupErrors.length > 0) throw new AggregateError(cleanupErrors, 'Loop session cleanup failed.');\n };\n });\n}\n\n/** The package's single standard Pi factory. */\nexport async function loopExtension(pi: ExtensionAPI): Promise<void> {\n const connection = await connectDoomCordisHost(pi, PACKAGE_SOURCE);\n const fiber = connection.root.plugin(loopPlugin, { pi });\n try {\n await fiber;\n } catch (error) {\n try {\n await fiber.dispose();\n } finally {\n await connection.dispose();\n }\n throw error;\n }\n let disposal: Promise<void> | undefined;\n pi.on(\n 'session_shutdown',\n () =>\n (disposal ??= (async () => {\n try {\n await fiber.dispose();\n } finally {\n await connection.dispose();\n }\n })()),\n );\n}\n\ninterface LoopPluginConfig {\n readonly pi: ExtensionAPI;\n}\n\nfunction loopPlugin(cordis: Context, config: LoopPluginConfig): void {\n cordis.inject([DOOM_HELP_SERVICE], (helpContext) => {\n const contribution = requireDoomHelpService(helpContext).register({\n source: PACKAGE_SOURCE,\n moduleUrl: import.meta.url,\n skills: [\n {\n name: 'doompi-use-loop',\n description: 'Use Doom Pi Loop to start, inspect, and stop session-scoped recurring prompts safely.',\n },\n ],\n });\n return () => contribution.dispose();\n });\n installLoopRuntime(cordis, config.pi);\n}\n\nexport default loopExtension;\n"],"mappings":"usCAuCA,MAAM,E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AC3D,EAAQ,EAAW,KAAK,OAAO,EAAY,CAAE,IAAG,CAAC,EACvD,GAAI,CACF,MAAM,CACR,OAAS,EAAO,CACd,GAAI,CACF,MAAM,EAAM,QAAQ,CACtB,QAAU,CACR,MAAM,EAAW,QAAQ,CAC3B,CACA,MAAM,CACR,CACA,IAAI,EACJ,EAAG,GACD,uBAEG,KAAc,SAAY,CACzB,GAAI,CACF,MAAM,EAAM,QAAQ,CACtB,QAAU,CACR,MAAM,EAAW,QAAQ,CAC3B,CACF,EAAA,CAAG,CACP,CACF,CAMA,SAAS,EAAW,EAAiB,EAAgC,CACnE,EAAO,OAAO,CAAC,CAAiB,EAAI,GAAgB,CAClD,IAAM,EAAe,EAAuB,CAAW,CAAC,CAAC,SAAS,CAChE,OAAQ,EACR,UAAW,YAAY,IACvB,OAAQ,CACN,CACE,KAAM,kBACN,YAAa,uFACf,CACF,CACF,CAAC,EACD,UAAa,EAAa,QAAQ,CACpC,CAAC,EACD,EAAmB,EAAQ,EAAO,EAAE,CACtC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
new RegExp(String.raw`\u001b\[[0-9;]*m`,`gu`);function e(e){if(e.length!==0)return JSON.stringify(e.map(e=>({instanceId:e.instanceId,label:e.label??e.launcherLabel,detail:e.detail??e.instanceId,state:e.state})))}exports.LOOP_VIEW_STATUS_KEY=`doom-loop-instances`,exports.formatLoopStatusView=e;
|
|
2
|
+
//# sourceMappingURL=loopView.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loopView.cjs","names":[],"sources":["../../src/types/loopView.ts"],"sourcesContent":["/** The browser-only status that carries active Loop instances into the activity dock. */\nexport const LOOP_VIEW_STATUS_KEY = 'doom-loop-instances';\n\nexport type LoopStatusState = 'starting' | 'running' | 'stopping';\n\n/** The small, serializable Loop view the cockpit needs for one activity row. */\nexport interface LoopStatusItem {\n readonly instanceId: string;\n readonly label: string;\n readonly detail: string;\n readonly state: LoopStatusState;\n}\n\ninterface LoopStatusSource {\n readonly instanceId: string;\n readonly launcherLabel: string;\n readonly label?: string;\n readonly detail?: string;\n readonly state: LoopStatusState;\n}\n\nconst ANSI = new RegExp(String.raw`\\u001b\\[[0-9;]*m`, 'gu');\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction isState(value: unknown): value is LoopStatusState {\n return value === 'starting' || value === 'running' || value === 'stopping';\n}\n\n/** Projects runtime snapshots into the JSON status consumed by the web plugin. */\nexport function formatLoopStatusView(instances: readonly LoopStatusSource[]): string | undefined {\n if (instances.length === 0) return undefined;\n return JSON.stringify(\n instances.map((instance) => ({\n instanceId: instance.instanceId,\n label: instance.label ?? instance.launcherLabel,\n detail: instance.detail ?? instance.instanceId,\n state: instance.state,\n })),\n );\n}\n\n/** Reads a Loop status without letting malformed session data crash the activity dock. */\nexport function parseLoopStatusView(raw: string | undefined): LoopStatusItem[] | undefined {\n if (raw === undefined) return undefined;\n const text = raw.replace(ANSI, '').trim();\n if (text === '') return undefined;\n\n try {\n const value: unknown = JSON.parse(text);\n if (!Array.isArray(value) || value.length === 0) return undefined;\n const items: LoopStatusItem[] = [];\n for (const item of value) {\n if (\n !isRecord(item) ||\n typeof item.instanceId !== 'string' ||\n item.instanceId.trim() === '' ||\n typeof item.label !== 'string' ||\n item.label.trim() === '' ||\n typeof item.detail !== 'string' ||\n !isState(item.state)\n ) {\n return undefined;\n }\n items.push({ instanceId: item.instanceId, label: item.label, detail: item.detail, state: item.state });\n }\n return items;\n } catch {\n return undefined;\n }\n}\n"],"mappings":"AAqBa,IAAI,OAAO,OAAO,GAAG,mBAAoB,IAAI,EAW1D,SAAgB,EAAqB,EAA4D,CAC3F,KAAU,SAAW,EACzB,OAAO,KAAK,UACV,EAAU,IAAK,IAAc,CAC3B,WAAY,EAAS,WACrB,MAAO,EAAS,OAAS,EAAS,cAClC,OAAQ,EAAS,QAAU,EAAS,WACpC,MAAO,EAAS,KAClB,EAAE,CACJ,CACF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=`doom-loop-instances`;new RegExp(String.raw`\u001b\[[0-9;]*m`,`gu`);function t(e){if(e.length!==0)return JSON.stringify(e.map(e=>({instanceId:e.instanceId,label:e.label??e.launcherLabel,detail:e.detail??e.instanceId,state:e.state})))}export{e as LOOP_VIEW_STATUS_KEY,t as formatLoopStatusView};
|
|
2
|
+
//# sourceMappingURL=loopView.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loopView.mjs","names":[],"sources":["../../src/types/loopView.ts"],"sourcesContent":["/** The browser-only status that carries active Loop instances into the activity dock. */\nexport const LOOP_VIEW_STATUS_KEY = 'doom-loop-instances';\n\nexport type LoopStatusState = 'starting' | 'running' | 'stopping';\n\n/** The small, serializable Loop view the cockpit needs for one activity row. */\nexport interface LoopStatusItem {\n readonly instanceId: string;\n readonly label: string;\n readonly detail: string;\n readonly state: LoopStatusState;\n}\n\ninterface LoopStatusSource {\n readonly instanceId: string;\n readonly launcherLabel: string;\n readonly label?: string;\n readonly detail?: string;\n readonly state: LoopStatusState;\n}\n\nconst ANSI = new RegExp(String.raw`\\u001b\\[[0-9;]*m`, 'gu');\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction isState(value: unknown): value is LoopStatusState {\n return value === 'starting' || value === 'running' || value === 'stopping';\n}\n\n/** Projects runtime snapshots into the JSON status consumed by the web plugin. */\nexport function formatLoopStatusView(instances: readonly LoopStatusSource[]): string | undefined {\n if (instances.length === 0) return undefined;\n return JSON.stringify(\n instances.map((instance) => ({\n instanceId: instance.instanceId,\n label: instance.label ?? instance.launcherLabel,\n detail: instance.detail ?? instance.instanceId,\n state: instance.state,\n })),\n );\n}\n\n/** Reads a Loop status without letting malformed session data crash the activity dock. */\nexport function parseLoopStatusView(raw: string | undefined): LoopStatusItem[] | undefined {\n if (raw === undefined) return undefined;\n const text = raw.replace(ANSI, '').trim();\n if (text === '') return undefined;\n\n try {\n const value: unknown = JSON.parse(text);\n if (!Array.isArray(value) || value.length === 0) return undefined;\n const items: LoopStatusItem[] = [];\n for (const item of value) {\n if (\n !isRecord(item) ||\n typeof item.instanceId !== 'string' ||\n item.instanceId.trim() === '' ||\n typeof item.label !== 'string' ||\n item.label.trim() === '' ||\n typeof item.detail !== 'string' ||\n !isState(item.state)\n ) {\n return undefined;\n }\n items.push({ instanceId: item.instanceId, label: item.label, detail: item.detail, state: item.state });\n }\n return items;\n } catch {\n return undefined;\n }\n}\n"],"mappings":"AACA,MAAa,EAAuB,sBAoBvB,IAAI,OAAO,OAAO,GAAG,mBAAoB,IAAI,EAW1D,SAAgB,EAAqB,EAA4D,CAC3F,KAAU,SAAW,EACzB,OAAO,KAAK,UACV,EAAU,IAAK,IAAc,CAC3B,WAAY,EAAS,WACrB,MAAO,EAAS,OAAS,EAAS,cAClC,OAAQ,EAAS,QAAU,EAAS,WACpC,MAAO,EAAS,KAClB,EAAE,CACJ,CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agimon-ai/doompi-loop",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.43",
|
|
4
4
|
"description": "Session-scoped recurring prompt scheduler and loop controls for Pi coding agents.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"web",
|
|
31
31
|
"llms.txt",
|
|
32
32
|
"src/prompts",
|
|
33
|
+
"src/types/loopView.ts",
|
|
33
34
|
"README.md",
|
|
34
35
|
"LICENSE",
|
|
35
36
|
"package.json"
|
|
@@ -56,22 +57,27 @@
|
|
|
56
57
|
},
|
|
57
58
|
"dependencies": {
|
|
58
59
|
"@deepseek-ai/cordis": "4.0.1",
|
|
59
|
-
"@agimon-ai/doompi-extension-contracts": "0.0.1-alpha.
|
|
60
|
-
"@agimon-ai/doompi-ui": "0.0.1-alpha.
|
|
61
|
-
"@agimon-ai/doompi-web-
|
|
60
|
+
"@agimon-ai/doompi-extension-contracts": "0.0.1-alpha.43",
|
|
61
|
+
"@agimon-ai/doompi-ui": "0.0.1-alpha.43",
|
|
62
|
+
"@agimon-ai/doompi-web-components": "0.0.1-alpha.4",
|
|
63
|
+
"@agimon-ai/doompi-web-contracts": "0.0.1-alpha.6"
|
|
62
64
|
},
|
|
63
65
|
"devDependencies": {
|
|
64
|
-
"@earendil-works/pi-coding-agent": "0.84.
|
|
65
|
-
"@earendil-works/pi-tui": "0.84.
|
|
66
|
+
"@earendil-works/pi-coding-agent": "0.84.4",
|
|
67
|
+
"@earendil-works/pi-tui": "0.84.4",
|
|
66
68
|
"@types/node": "26.2.0",
|
|
69
|
+
"@types/react": "19.2.7",
|
|
70
|
+
"@types/react-dom": "19.2.3",
|
|
67
71
|
"@vitest/coverage-v8": "4.1.11",
|
|
72
|
+
"react": "19.2.8",
|
|
73
|
+
"react-dom": "19.2.8",
|
|
68
74
|
"tsdown": "0.22.14",
|
|
69
75
|
"typescript": "7.0.2",
|
|
70
76
|
"vitest": "4.1.11"
|
|
71
77
|
},
|
|
72
78
|
"peerDependencies": {
|
|
73
|
-
"@earendil-works/pi-coding-agent": "0.84.
|
|
74
|
-
"@earendil-works/pi-tui": "0.84.
|
|
79
|
+
"@earendil-works/pi-coding-agent": "0.84.4",
|
|
80
|
+
"@earendil-works/pi-tui": "0.84.4"
|
|
75
81
|
},
|
|
76
82
|
"peerDependenciesMeta": {
|
|
77
83
|
"@earendil-works/pi-coding-agent": {
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/** The browser-only status that carries active Loop instances into the activity dock. */
|
|
2
|
+
export const LOOP_VIEW_STATUS_KEY = 'doom-loop-instances';
|
|
3
|
+
|
|
4
|
+
export type LoopStatusState = 'starting' | 'running' | 'stopping';
|
|
5
|
+
|
|
6
|
+
/** The small, serializable Loop view the cockpit needs for one activity row. */
|
|
7
|
+
export interface LoopStatusItem {
|
|
8
|
+
readonly instanceId: string;
|
|
9
|
+
readonly label: string;
|
|
10
|
+
readonly detail: string;
|
|
11
|
+
readonly state: LoopStatusState;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface LoopStatusSource {
|
|
15
|
+
readonly instanceId: string;
|
|
16
|
+
readonly launcherLabel: string;
|
|
17
|
+
readonly label?: string;
|
|
18
|
+
readonly detail?: string;
|
|
19
|
+
readonly state: LoopStatusState;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const ANSI = new RegExp(String.raw`\u001b\[[0-9;]*m`, 'gu');
|
|
23
|
+
|
|
24
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
25
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function isState(value: unknown): value is LoopStatusState {
|
|
29
|
+
return value === 'starting' || value === 'running' || value === 'stopping';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Projects runtime snapshots into the JSON status consumed by the web plugin. */
|
|
33
|
+
export function formatLoopStatusView(instances: readonly LoopStatusSource[]): string | undefined {
|
|
34
|
+
if (instances.length === 0) return undefined;
|
|
35
|
+
return JSON.stringify(
|
|
36
|
+
instances.map((instance) => ({
|
|
37
|
+
instanceId: instance.instanceId,
|
|
38
|
+
label: instance.label ?? instance.launcherLabel,
|
|
39
|
+
detail: instance.detail ?? instance.instanceId,
|
|
40
|
+
state: instance.state,
|
|
41
|
+
})),
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Reads a Loop status without letting malformed session data crash the activity dock. */
|
|
46
|
+
export function parseLoopStatusView(raw: string | undefined): LoopStatusItem[] | undefined {
|
|
47
|
+
if (raw === undefined) return undefined;
|
|
48
|
+
const text = raw.replace(ANSI, '').trim();
|
|
49
|
+
if (text === '') return undefined;
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
const value: unknown = JSON.parse(text);
|
|
53
|
+
if (!Array.isArray(value) || value.length === 0) return undefined;
|
|
54
|
+
const items: LoopStatusItem[] = [];
|
|
55
|
+
for (const item of value) {
|
|
56
|
+
if (
|
|
57
|
+
!isRecord(item) ||
|
|
58
|
+
typeof item.instanceId !== 'string' ||
|
|
59
|
+
item.instanceId.trim() === '' ||
|
|
60
|
+
typeof item.label !== 'string' ||
|
|
61
|
+
item.label.trim() === '' ||
|
|
62
|
+
typeof item.detail !== 'string' ||
|
|
63
|
+
!isState(item.state)
|
|
64
|
+
) {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
items.push({ instanceId: item.instanceId, label: item.label, detail: item.detail, state: item.state });
|
|
68
|
+
}
|
|
69
|
+
return items;
|
|
70
|
+
} catch {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Button, Dot, type DotTone } from '@agimon-ai/doompi-web-components';
|
|
2
|
+
import type { WebPluginSlotProps } from '@agimon-ai/doompi-web-contracts';
|
|
3
|
+
import { LOOP_VIEW_STATUS_KEY, parseLoopStatusView, type LoopStatusState } from '../src/types/loopView.ts';
|
|
4
|
+
|
|
5
|
+
const MANAGE_COMMAND = '/loops';
|
|
6
|
+
|
|
7
|
+
function toneOf(state: LoopStatusState): DotTone {
|
|
8
|
+
if (state === 'running') return 'green';
|
|
9
|
+
if (state === 'stopping') return 'orange';
|
|
10
|
+
return 'yellow';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Active recurring prompts owned by the focused session, plus the existing management flow. */
|
|
14
|
+
export function LoopsActivitySection({ sessionId, statuses, sendSessionFrame }: WebPluginSlotProps) {
|
|
15
|
+
const raw = statuses[LOOP_VIEW_STATUS_KEY];
|
|
16
|
+
const loops = parseLoopStatusView(raw);
|
|
17
|
+
const unavailable = raw !== undefined && raw.trim() !== '' && loops === undefined;
|
|
18
|
+
if (!loops && !unavailable) return null;
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<div data-testid="activity-loop-instances" className="flex flex-col gap-2">
|
|
22
|
+
{loops ? (
|
|
23
|
+
<ul aria-label="active loops" className="flex flex-col gap-1">
|
|
24
|
+
{loops.map((loop) => (
|
|
25
|
+
<li
|
|
26
|
+
key={loop.instanceId}
|
|
27
|
+
data-testid={`activity-loop-${loop.instanceId}`}
|
|
28
|
+
data-loop-state={loop.state}
|
|
29
|
+
title={`${loop.label}: ${loop.detail}`}
|
|
30
|
+
className="flex min-w-0 flex-col gap-0.5 px-1 py-0.5"
|
|
31
|
+
>
|
|
32
|
+
<span className="flex min-w-0 items-center gap-1.5">
|
|
33
|
+
<Dot tone={toneOf(loop.state)} pulse={loop.state !== 'running'} />
|
|
34
|
+
<span className="min-w-0 flex-1 truncate text-[10px] font-bold text-doom-hi">{loop.label}</span>
|
|
35
|
+
<span className="shrink-0 text-[9px] text-doom-faint">{loop.state}</span>
|
|
36
|
+
</span>
|
|
37
|
+
<span className="truncate pl-3 text-[9px] text-doom-faint">{loop.detail}</span>
|
|
38
|
+
</li>
|
|
39
|
+
))}
|
|
40
|
+
</ul>
|
|
41
|
+
) : (
|
|
42
|
+
<p className="px-1 text-[10px] text-doom-faint">loop status unavailable</p>
|
|
43
|
+
)}
|
|
44
|
+
<Button
|
|
45
|
+
variant="subtle"
|
|
46
|
+
size="xs"
|
|
47
|
+
data-testid="activity-loops-manage"
|
|
48
|
+
aria-label="manage loops"
|
|
49
|
+
disabled={sessionId === null}
|
|
50
|
+
onClick={() => {
|
|
51
|
+
if (sessionId === null) return;
|
|
52
|
+
sendSessionFrame(sessionId, { type: 'prompt', message: MANAGE_COMMAND });
|
|
53
|
+
}}
|
|
54
|
+
className="self-end text-[8px] font-bold"
|
|
55
|
+
>
|
|
56
|
+
manage
|
|
57
|
+
</Button>
|
|
58
|
+
</div>
|
|
59
|
+
);
|
|
60
|
+
}
|
package/web/index.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { defineWebPlugin } from '@agimon-ai/doompi-web-contracts';
|
|
2
|
+
import { LOOP_VIEW_STATUS_KEY } from '../src/types/loopView.ts';
|
|
3
|
+
import { LoopsActivitySection } from './LoopsActivitySection.tsx';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
|
-
* This package's cockpit presence
|
|
5
|
-
* the
|
|
6
|
+
* This package's cockpit presence. The selection bar carries the minor mode,
|
|
7
|
+
* while the activity dock shows each loop the active session is scheduling.
|
|
6
8
|
*/
|
|
7
9
|
const LOOPS_GROUP = { key: 'l', label: 'loops', detail: 'recurring prompt loops' };
|
|
8
10
|
|
|
9
11
|
export const webPlugin = defineWebPlugin({
|
|
10
12
|
id: 'loop',
|
|
11
13
|
minorModes: [{ name: 'loop', keys: 'l l', statusKey: 'doom-loop', order: 30 }],
|
|
14
|
+
activityGroups: [{ name: 'loops', keys: 'l l', statusKey: LOOP_VIEW_STATUS_KEY, hideWhenEmpty: true, order: 40 }],
|
|
15
|
+
activitySections: [{ id: 'loops', component: LoopsActivitySection }],
|
|
12
16
|
// The TUI's SPC l s and SPC l l: both are slash commands, so both carry over.
|
|
13
17
|
leaderBindings: [
|
|
14
18
|
{
|
package/web/tsconfig.json
CHANGED
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"esModuleInterop": true,
|
|
17
17
|
"skipLibCheck": true,
|
|
18
18
|
"allowImportingTsExtensions": true,
|
|
19
|
-
"forceConsistentCasingInFileNames": true
|
|
19
|
+
"forceConsistentCasingInFileNames": true,
|
|
20
|
+
"types": ["node"]
|
|
20
21
|
},
|
|
21
|
-
"include": [".", "../src/types"]
|
|
22
|
+
"include": [".", "../src/types", "../tests/web"]
|
|
22
23
|
}
|