@agimon-ai/doompi-loop 0.0.1-alpha.3 → 0.0.1-alpha.31
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 +79 -18
- package/dist/adapters/pi/defaultLoopLauncher.cjs +2 -0
- package/dist/adapters/pi/defaultLoopLauncher.cjs.map +1 -0
- package/dist/adapters/pi/defaultLoopLauncher.mjs +2 -0
- package/dist/adapters/pi/defaultLoopLauncher.mjs.map +1 -0
- package/dist/adapters/pi/extension.cjs +2 -0
- package/dist/adapters/pi/extension.cjs.map +1 -0
- package/dist/adapters/pi/extension.d.cts +10 -0
- package/dist/adapters/pi/extension.d.cts.map +1 -0
- package/dist/adapters/pi/extension.d.mts +10 -0
- package/dist/adapters/pi/extension.d.mts.map +1 -0
- package/dist/adapters/pi/extension.mjs +2 -0
- package/dist/adapters/pi/extension.mjs.map +1 -0
- package/dist/adapters/pi/leader.cjs +2 -0
- package/dist/adapters/pi/leader.cjs.map +1 -0
- package/dist/adapters/pi/leader.mjs +2 -0
- package/dist/adapters/pi/leader.mjs.map +1 -0
- package/dist/adapters/pi/loopConstants.cjs +2 -0
- package/dist/adapters/pi/loopConstants.cjs.map +1 -0
- package/dist/adapters/pi/loopConstants.mjs +2 -0
- package/dist/adapters/pi/loopConstants.mjs.map +1 -0
- package/dist/commands/loopCommand.cjs +1 -1
- package/dist/commands/loopCommand.cjs.map +1 -1
- package/dist/commands/loopCommand.mjs +1 -1
- package/dist/commands/loopCommand.mjs.map +1 -1
- package/dist/extensions/pi.cjs +1 -2
- package/dist/extensions/pi.d.cts +2 -2
- package/dist/extensions/pi.d.mts +2 -2
- package/dist/extensions/pi.mjs +1 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +1 -1
- package/dist/schemas/loopCommands.cjs +2 -0
- package/dist/schemas/loopCommands.cjs.map +1 -0
- package/dist/schemas/loopCommands.mjs +2 -0
- package/dist/schemas/loopCommands.mjs.map +1 -0
- package/dist/services/loopLaunchers.cjs +2 -0
- package/dist/services/loopLaunchers.cjs.map +1 -0
- package/dist/services/loopLaunchers.mjs +2 -0
- package/dist/services/loopLaunchers.mjs.map +1 -0
- package/dist/tui/loopListOverlay.cjs +1 -1
- package/dist/tui/loopListOverlay.cjs.map +1 -1
- package/dist/tui/loopListOverlay.mjs +1 -1
- package/dist/tui/loopListOverlay.mjs.map +1 -1
- package/dist/tui/startLoopOverlay.cjs +1 -1
- package/dist/tui/startLoopOverlay.cjs.map +1 -1
- package/dist/tui/startLoopOverlay.mjs +1 -1
- package/dist/tui/startLoopOverlay.mjs.map +1 -1
- package/llms.txt +9 -0
- package/package.json +29 -12
- package/src/prompts/doompi-use-loop/SKILL.md +24 -0
- package/dist/constants.cjs +0 -2
- package/dist/constants.cjs.map +0 -1
- package/dist/constants.mjs +0 -2
- package/dist/constants.mjs.map +0 -1
- package/dist/extension.cjs +0 -2
- package/dist/extension.cjs.map +0 -1
- package/dist/extension.d.cts +0 -6
- package/dist/extension.d.cts.map +0 -1
- package/dist/extension.d.mts +0 -6
- package/dist/extension.d.mts.map +0 -1
- package/dist/extension.mjs +0 -2
- package/dist/extension.mjs.map +0 -1
- package/dist/extensions/pi.cjs.map +0 -1
- package/dist/extensions/pi.mjs.map +0 -1
- package/dist/launcher.cjs +0 -2
- package/dist/launcher.cjs.map +0 -1
- package/dist/launcher.d.cts +0 -47
- package/dist/launcher.d.cts.map +0 -1
- package/dist/launcher.d.mts +0 -47
- package/dist/launcher.d.mts.map +0 -1
- package/dist/launcher.mjs +0 -2
- package/dist/launcher.mjs.map +0 -1
- package/dist/leader.cjs +0 -2
- package/dist/leader.cjs.map +0 -1
- package/dist/leader.mjs +0 -2
- package/dist/leader.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -1,37 +1,98 @@
|
|
|
1
1
|
# @agimon-ai/doompi-loop
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A session-scoped scheduler that sends a prompt immediately and repeats it at a bounded interval.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
mid-session, stacks with the others, and reports itself on the shared `MODES` line.
|
|
5
|
+
Part of the [DoomPi distribution](https://www.npmjs.com/package/@agimon-ai/doompi).
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
Several loops can coexist. Loop is a minor mode and remains active while at least one scheduled
|
|
8
|
+
prompt belongs to the current session.
|
|
9
|
+
|
|
10
|
+
> **Alpha:** launcher and scheduling contracts may change between releases.
|
|
11
|
+
|
|
12
|
+
## Requirements
|
|
13
|
+
|
|
14
|
+
- Node.js 22.19.0 or newer
|
|
15
|
+
- Pi 0.84.2 and Pi TUI 0.84.2
|
|
11
16
|
|
|
12
17
|
## Install
|
|
13
18
|
|
|
19
|
+
DoomPi includes Loop in every composition. Pi loads it through package extension metadata. For
|
|
20
|
+
standalone Pi:
|
|
21
|
+
|
|
14
22
|
```bash
|
|
15
|
-
|
|
23
|
+
pi install npm:@agimon-ai/doompi-loop
|
|
16
24
|
```
|
|
17
25
|
|
|
18
|
-
##
|
|
26
|
+
## Start and manage loops
|
|
27
|
+
|
|
28
|
+
Use `/loop` to start a loop and `/loops` to inspect or stop active loops. In DoomPi, `SPC l s` opens
|
|
29
|
+
the start flow and `SPC l l` opens the list.
|
|
30
|
+
|
|
31
|
+
The default interval is 300 seconds. Accepted intervals range from 30 to 3600 seconds. A loop runs
|
|
32
|
+
its prompt once immediately, then schedules later passes.
|
|
33
|
+
|
|
34
|
+
If Pi is busy, a due pass waits for the shared agent to become idle. Multiple due signals can
|
|
35
|
+
coalesce rather than creating overlapping model turns. Stopping a loop prevents future passes but
|
|
36
|
+
does not rewind side effects from a pass already sent.
|
|
37
|
+
|
|
38
|
+
## Lifecycle and cost
|
|
19
39
|
|
|
20
|
-
|
|
21
|
-
|
|
40
|
+
Loop state belongs to the session's `doom/loop-launchers` service; it is not a durable queue.
|
|
41
|
+
Replacing or shutting down the session aborts pending launches and stops active timers. Resuming a
|
|
42
|
+
transcript does not restart old loops.
|
|
22
43
|
|
|
23
|
-
|
|
44
|
+
Every pass can start another model turn and repeat tool or external side effects. Choose
|
|
45
|
+
conservative intervals, make prompts idempotent where possible, and stop loops when the recurring
|
|
46
|
+
work is complete.
|
|
24
47
|
|
|
25
|
-
##
|
|
48
|
+
## Extension authors: cross-extension launchers
|
|
26
49
|
|
|
27
|
-
|
|
50
|
+
Launcher definitions use the shared Cordis service. A consumer registers a launcher and returns its
|
|
51
|
+
cleanup callback. Cordis removes that launcher when either package or the session unloads, then
|
|
52
|
+
registers it again when the provider returns.
|
|
28
53
|
|
|
29
|
-
|
|
54
|
+
```ts
|
|
55
|
+
import {
|
|
56
|
+
DOOM_LOOP_LAUNCHERS_SERVICE,
|
|
57
|
+
requireDoomLoopLaunchers,
|
|
58
|
+
} from '@agimon-ai/doompi-extension-contracts/loop-launchers';
|
|
59
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
60
|
+
|
|
61
|
+
export function myLoopPlugin(ctx: Context): void {
|
|
62
|
+
ctx.inject([DOOM_LOOP_LAUNCHERS_SERVICE], (sessionContext) => {
|
|
63
|
+
const registration = requireDoomLoopLaunchers(sessionContext).register({
|
|
64
|
+
id: 'example.recurring-check',
|
|
65
|
+
source: '@example/doompi-recurring-check',
|
|
66
|
+
label: 'Recurring check',
|
|
67
|
+
async launch({ instanceId, signal }) {
|
|
68
|
+
signal.throwIfAborted();
|
|
69
|
+
// Start session work. The returned stop callback owns cleanup.
|
|
70
|
+
return { instanceId, stop: () => undefined };
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
return () => registration.dispose('Contributor unloaded.');
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Mount that plugin on the runner's shared Doom Cordis root. Loop owns the registry and default
|
|
79
|
+
launcher. Consumers depend only on
|
|
80
|
+
`@agimon-ai/doompi-extension-contracts/loop-launchers`; there is no process-global registry or
|
|
81
|
+
session-ID lookup API.
|
|
82
|
+
|
|
83
|
+
The package root exports `installLoopRuntime` for composition tests, plus the service contract
|
|
84
|
+
types. Normal Pi activation uses the discovered `extensions/pi` entry.
|
|
85
|
+
|
|
86
|
+
## Development
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
pnpm build
|
|
90
|
+
pnpm typecheck
|
|
91
|
+
pnpm test
|
|
92
|
+
pnpm lint
|
|
93
|
+
```
|
|
30
94
|
|
|
31
|
-
|
|
32
|
-
| -------------------------------------- |
|
|
33
|
-
| `@agimon-ai/doompi-loop` |
|
|
34
|
-
| `@agimon-ai/doompi-loop/extensions/pi` |
|
|
95
|
+
Maintained by [Agimon](https://agimon.ai/about).
|
|
35
96
|
|
|
36
97
|
## License
|
|
37
98
|
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./loopConstants.cjs"),t=3600;function n(e){let n=Number(e);if(!Number.isInteger(n))return`Interval must be a whole number of seconds, got ${e}.`;if(n<30||n>t)return`Interval must be between 30 and ${t} seconds.`}async function r(t,r){let i=(await t.editor(`Loop prompt`,``))?.trim();if(!i||r.aborted)return;let a=await t.input(`Loop interval in seconds`,`Default: 300s`);if(a===void 0||r.aborted)return;let o=a.trim()||`300`,s=n(o);if(s){t.notify(s,e.NOTIFY_WARNING_LEVEL);return}return{prompt:i,intervalSeconds:Number(o)}}function i(e){let t=e.replaceAll(/\s+/gu,` `).trim();return t.length>80?`${t.slice(0,79)}…`:t}function a(t){let n=new Set,a=r=>{if(!r.stopped){if(!r.context.isIdle()){n.add(r);return}n.delete(r);try{t.sendUserMessage(r.prompt)}catch(t){r.context.ui.notify(`Default loop pass could not start: ${t instanceof Error?t.message:String(t)}`,e.NOTIFY_WARNING_LEVEL)}}};return t.on(`agent_settled`,()=>{let e=n.values().next().value;e&&a(e)}),{register(t,o){return o.register({id:`doompi.default`,source:e.PACKAGE_SOURCE,label:`Default loop`,description:`Run your own prompt in this session on an interval`,async launch({instanceId:e,signal:o}){let s=await r(t.ui,o);if(!s||o.aborted)return;let c={...s,context:t,stopped:!1};return c.timer=setInterval(()=>a(c),c.intervalSeconds*1e3),c.timer.unref?.(),a(c),{instanceId:e,label:`Default loop`,detail:`every ${c.intervalSeconds}s · ${i(c.prompt)}`,stop(){c.stopped||(c.stopped=!0,c.timer&&clearInterval(c.timer),c.timer=void 0,n.delete(c))}}}})}}}exports.createDefaultLoopLauncher=a;
|
|
2
|
+
//# sourceMappingURL=defaultLoopLauncher.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultLoopLauncher.cjs","names":["NOTIFY_WARNING_LEVEL","PACKAGE_SOURCE"],"sources":["../../../src/adapters/pi/defaultLoopLauncher.ts"],"sourcesContent":["import type {\n DoomLoopLaunchersService,\n LoopLauncherRegistration,\n StoppableLoop,\n} from '@agimon-ai/doompi-extension-contracts/loop-launchers';\nimport type { ExtensionAPI, ExtensionContext, ExtensionUIContext } from '@earendil-works/pi-coding-agent';\nimport { NOTIFY_WARNING_LEVEL, PACKAGE_SOURCE } from './loopConstants.ts';\n\nconst DEFAULT_LAUNCHER_ID = 'doompi.default';\nconst DEFAULT_INTERVAL_SECONDS = 300;\nconst MIN_INTERVAL_SECONDS = 30;\nconst MAX_INTERVAL_SECONDS = 3600;\nconst MILLISECONDS_PER_SECOND = 1000;\nconst PROMPT_PREVIEW_LENGTH = 80;\n\ninterface PreparedDefaultLoop {\n readonly prompt: string;\n readonly intervalSeconds: number;\n}\n\ninterface ActiveDefaultLoop extends PreparedDefaultLoop {\n readonly context: ExtensionContext;\n timer?: ReturnType<typeof setInterval>;\n stopped: boolean;\n}\n\nexport interface DefaultLoopLauncher {\n register(ctx: ExtensionContext, launchers: DoomLoopLaunchersService): LoopLauncherRegistration;\n}\n\nfunction intervalError(raw: string): string | undefined {\n const seconds = Number(raw);\n if (!Number.isInteger(seconds)) return `Interval must be a whole number of seconds, got ${raw}.`;\n if (seconds < MIN_INTERVAL_SECONDS || seconds > MAX_INTERVAL_SECONDS) {\n return `Interval must be between ${MIN_INTERVAL_SECONDS} and ${MAX_INTERVAL_SECONDS} seconds.`;\n }\n return undefined;\n}\n\nasync function prepareDefaultLoop(\n ui: ExtensionUIContext,\n signal: AbortSignal,\n): Promise<PreparedDefaultLoop | undefined> {\n const prompt = (await ui.editor('Loop prompt', ''))?.trim();\n if (!prompt || signal.aborted) return undefined;\n\n const rawInterval = await ui.input('Loop interval in seconds', `Default: ${DEFAULT_INTERVAL_SECONDS}s`);\n if (rawInterval === undefined || signal.aborted) return undefined;\n const normalizedInterval = rawInterval.trim() || String(DEFAULT_INTERVAL_SECONDS);\n const error = intervalError(normalizedInterval);\n if (error) {\n ui.notify(error, NOTIFY_WARNING_LEVEL);\n return undefined;\n }\n\n return { prompt, intervalSeconds: Number(normalizedInterval) };\n}\n\nfunction promptPreview(prompt: string): string {\n const oneLine = prompt.replaceAll(/\\s+/gu, ' ').trim();\n return oneLine.length > PROMPT_PREVIEW_LENGTH ? `${oneLine.slice(0, PROMPT_PREVIEW_LENGTH - 1)}…` : oneLine;\n}\n\nexport function createDefaultLoopLauncher(pi: ExtensionAPI): DefaultLoopLauncher {\n const pending = new Set<ActiveDefaultLoop>();\n\n const requestPass = (loop: ActiveDefaultLoop): void => {\n if (loop.stopped) return;\n if (!loop.context.isIdle()) {\n pending.add(loop);\n return;\n }\n\n pending.delete(loop);\n try {\n pi.sendUserMessage(loop.prompt);\n } catch (error) {\n loop.context.ui.notify(\n `Default loop pass could not start: ${error instanceof Error ? error.message : String(error)}`,\n NOTIFY_WARNING_LEVEL,\n );\n }\n };\n\n pi.on('agent_settled', () => {\n const next = pending.values().next().value;\n if (next) requestPass(next);\n });\n\n return {\n register(ctx, launchers) {\n return launchers.register({\n id: DEFAULT_LAUNCHER_ID,\n source: PACKAGE_SOURCE,\n label: 'Default loop',\n description: 'Run your own prompt in this session on an interval',\n async launch({ instanceId, signal }) {\n const prepared = await prepareDefaultLoop(ctx.ui, signal);\n if (!prepared || signal.aborted) return undefined;\n\n const loop: ActiveDefaultLoop = { ...prepared, context: ctx, stopped: false };\n loop.timer = setInterval(() => requestPass(loop), loop.intervalSeconds * MILLISECONDS_PER_SECOND);\n loop.timer.unref?.();\n requestPass(loop);\n\n const handle: StoppableLoop = {\n instanceId,\n label: 'Default loop',\n detail: `every ${loop.intervalSeconds}s · ${promptPreview(loop.prompt)}`,\n stop() {\n if (loop.stopped) return;\n loop.stopped = true;\n if (loop.timer) clearInterval(loop.timer);\n loop.timer = undefined;\n pending.delete(loop);\n },\n };\n return handle;\n },\n });\n },\n };\n}\n"],"mappings":"uCAWM,EAAuB,KAmB7B,SAAS,EAAc,EAAiC,CACtD,IAAM,EAAU,OAAO,CAAG,EAC1B,GAAI,CAAC,OAAO,UAAU,CAAO,EAAG,MAAO,mDAAmD,EAAI,GAC9F,GAAI,EAAU,IAAwB,EAAU,EAC9C,MAAO,mCAAwD,EAAqB,UAGxF,CAEA,eAAe,EACb,EACA,EAC0C,CAC1C,IAAM,GAAU,MAAM,EAAG,OAAO,cAAe,EAAE,EAAA,EAAI,KAAK,EAC1D,GAAI,CAAC,GAAU,EAAO,QAAS,OAE/B,IAAM,EAAc,MAAM,EAAG,MAAM,2BAA4B,eAAuC,EACtG,GAAI,IAAgB,IAAA,IAAa,EAAO,QAAS,OACjD,IAAM,EAAqB,EAAY,KAAK,GAAK,MAC3C,EAAQ,EAAc,CAAkB,EAC9C,GAAI,EAAO,CACT,EAAG,OAAO,EAAOA,EAAAA,oBAAoB,EACrC,MACF,CAEA,MAAO,CAAE,SAAQ,gBAAiB,OAAO,CAAkB,CAAE,CAC/D,CAEA,SAAS,EAAc,EAAwB,CAC7C,IAAM,EAAU,EAAO,WAAW,QAAS,GAAG,CAAC,CAAC,KAAK,EACrD,OAAO,EAAQ,OAAS,GAAwB,GAAG,EAAQ,MAAM,EAAG,EAAyB,EAAE,GAAK,CACtG,CAEA,SAAgB,EAA0B,EAAuC,CAC/E,IAAM,EAAU,I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!Number.isInteger(t))return`Interval must be a whole number of seconds, got ${e}.`;if(t<30||t>n)return`Interval must be between 30 and ${n} seconds.`}async function i(t,n){let i=(await t.editor(`Loop prompt`,``))?.trim();if(!i||n.aborted)return;let a=await t.input(`Loop interval in seconds`,`Default: 300s`);if(a===void 0||n.aborted)return;let o=a.trim()||`300`,s=r(o);if(s){t.notify(s,e);return}return{prompt:i,intervalSeconds:Number(o)}}function a(e){let t=e.replaceAll(/\s+/gu,` `).trim();return t.length>80?`${t.slice(0,79)}…`:t}function o(n){let r=new Set,o=t=>{if(!t.stopped){if(!t.context.isIdle()){r.add(t);return}r.delete(t);try{n.sendUserMessage(t.prompt)}catch(n){t.context.ui.notify(`Default loop pass could not start: ${n instanceof Error?n.message:String(n)}`,e)}}};return n.on(`agent_settled`,()=>{let e=r.values().next().value;e&&o(e)}),{register(e,n){return n.register({id:`doompi.default`,source:t,label:`Default loop`,description:`Run your own prompt in this session on an interval`,async launch({instanceId:t,signal:n}){let s=await i(e.ui,n);if(!s||n.aborted)return;let c={...s,context:e,stopped:!1};return c.timer=setInterval(()=>o(c),c.intervalSeconds*1e3),c.timer.unref?.(),o(c),{instanceId:t,label:`Default loop`,detail:`every ${c.intervalSeconds}s · ${a(c.prompt)}`,stop(){c.stopped||(c.stopped=!0,c.timer&&clearInterval(c.timer),c.timer=void 0,r.delete(c))}}}})}}}export{o as createDefaultLoopLauncher};
|
|
2
|
+
//# sourceMappingURL=defaultLoopLauncher.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultLoopLauncher.mjs","names":[],"sources":["../../../src/adapters/pi/defaultLoopLauncher.ts"],"sourcesContent":["import type {\n DoomLoopLaunchersService,\n LoopLauncherRegistration,\n StoppableLoop,\n} from '@agimon-ai/doompi-extension-contracts/loop-launchers';\nimport type { ExtensionAPI, ExtensionContext, ExtensionUIContext } from '@earendil-works/pi-coding-agent';\nimport { NOTIFY_WARNING_LEVEL, PACKAGE_SOURCE } from './loopConstants.ts';\n\nconst DEFAULT_LAUNCHER_ID = 'doompi.default';\nconst DEFAULT_INTERVAL_SECONDS = 300;\nconst MIN_INTERVAL_SECONDS = 30;\nconst MAX_INTERVAL_SECONDS = 3600;\nconst MILLISECONDS_PER_SECOND = 1000;\nconst PROMPT_PREVIEW_LENGTH = 80;\n\ninterface PreparedDefaultLoop {\n readonly prompt: string;\n readonly intervalSeconds: number;\n}\n\ninterface ActiveDefaultLoop extends PreparedDefaultLoop {\n readonly context: ExtensionContext;\n timer?: ReturnType<typeof setInterval>;\n stopped: boolean;\n}\n\nexport interface DefaultLoopLauncher {\n register(ctx: ExtensionContext, launchers: DoomLoopLaunchersService): LoopLauncherRegistration;\n}\n\nfunction intervalError(raw: string): string | undefined {\n const seconds = Number(raw);\n if (!Number.isInteger(seconds)) return `Interval must be a whole number of seconds, got ${raw}.`;\n if (seconds < MIN_INTERVAL_SECONDS || seconds > MAX_INTERVAL_SECONDS) {\n return `Interval must be between ${MIN_INTERVAL_SECONDS} and ${MAX_INTERVAL_SECONDS} seconds.`;\n }\n return undefined;\n}\n\nasync function prepareDefaultLoop(\n ui: ExtensionUIContext,\n signal: AbortSignal,\n): Promise<PreparedDefaultLoop | undefined> {\n const prompt = (await ui.editor('Loop prompt', ''))?.trim();\n if (!prompt || signal.aborted) return undefined;\n\n const rawInterval = await ui.input('Loop interval in seconds', `Default: ${DEFAULT_INTERVAL_SECONDS}s`);\n if (rawInterval === undefined || signal.aborted) return undefined;\n const normalizedInterval = rawInterval.trim() || String(DEFAULT_INTERVAL_SECONDS);\n const error = intervalError(normalizedInterval);\n if (error) {\n ui.notify(error, NOTIFY_WARNING_LEVEL);\n return undefined;\n }\n\n return { prompt, intervalSeconds: Number(normalizedInterval) };\n}\n\nfunction promptPreview(prompt: string): string {\n const oneLine = prompt.replaceAll(/\\s+/gu, ' ').trim();\n return oneLine.length > PROMPT_PREVIEW_LENGTH ? `${oneLine.slice(0, PROMPT_PREVIEW_LENGTH - 1)}…` : oneLine;\n}\n\nexport function createDefaultLoopLauncher(pi: ExtensionAPI): DefaultLoopLauncher {\n const pending = new Set<ActiveDefaultLoop>();\n\n const requestPass = (loop: ActiveDefaultLoop): void => {\n if (loop.stopped) return;\n if (!loop.context.isIdle()) {\n pending.add(loop);\n return;\n }\n\n pending.delete(loop);\n try {\n pi.sendUserMessage(loop.prompt);\n } catch (error) {\n loop.context.ui.notify(\n `Default loop pass could not start: ${error instanceof Error ? error.message : String(error)}`,\n NOTIFY_WARNING_LEVEL,\n );\n }\n };\n\n pi.on('agent_settled', () => {\n const next = pending.values().next().value;\n if (next) requestPass(next);\n });\n\n return {\n register(ctx, launchers) {\n return launchers.register({\n id: DEFAULT_LAUNCHER_ID,\n source: PACKAGE_SOURCE,\n label: 'Default loop',\n description: 'Run your own prompt in this session on an interval',\n async launch({ instanceId, signal }) {\n const prepared = await prepareDefaultLoop(ctx.ui, signal);\n if (!prepared || signal.aborted) return undefined;\n\n const loop: ActiveDefaultLoop = { ...prepared, context: ctx, stopped: false };\n loop.timer = setInterval(() => requestPass(loop), loop.intervalSeconds * MILLISECONDS_PER_SECOND);\n loop.timer.unref?.();\n requestPass(loop);\n\n const handle: StoppableLoop = {\n instanceId,\n label: 'Default loop',\n detail: `every ${loop.intervalSeconds}s · ${promptPreview(loop.prompt)}`,\n stop() {\n if (loop.stopped) return;\n loop.stopped = true;\n if (loop.timer) clearInterval(loop.timer);\n loop.timer = undefined;\n pending.delete(loop);\n },\n };\n return handle;\n },\n });\n },\n };\n}\n"],"mappings":"+EAQA,MAGM,EAAuB,KAmB7B,SAAS,EAAc,EAAiC,CACtD,IAAM,EAAU,OAAO,CAAG,EAC1B,GAAI,CAAC,OAAO,UAAU,CAAO,EAAG,MAAO,mDAAmD,EAAI,GAC9F,GAAI,EAAU,IAAwB,EAAU,EAC9C,MAAO,mCAAwD,EAAqB,UAGxF,CAEA,eAAe,EACb,EACA,EAC0C,CAC1C,IAAM,GAAU,MAAM,EAAG,OAAO,cAAe,EAAE,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0B,CAAE,GAAG,EAAU,QAAS,EAAK,QAAS,EAAM,EAiB5E,MAhBA,GAAK,MAAQ,gBAAkB,EAAY,CAAI,EAAG,EAAK,gBAAkB,GAAuB,EAChG,EAAK,MAAM,QAAQ,EACnB,EAAY,CAAI,EAcT,CAXL,aACA,MAAO,eACP,OAAQ,SAAS,EAAK,gBAAgB,MAAM,EAAc,EAAK,MAAM,IACrE,MAAO,CACD,EAAK,UACT,EAAK,QAAU,GACX,EAAK,OAAO,cAAc,EAAK,KAAK,EACxC,EAAK,MAAQ,IAAA,GACb,EAAQ,OAAO,CAAI,EACrB,CAEU,CACd,CACF,CAAC,CACH,CACF,CACF"}
|
|
@@ -0,0 +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"),a=require("./defaultLoopLauncher.cjs"),o=require("./leader.cjs");let s=require("@agimon-ai/doompi-extension-contracts/mode"),c=require("@agimon-ai/doompi-extension-contracts/cordis-host"),l=require("@agimon-ai/doompi-extension-contracts/help"),u=require("@agimon-ai/doompi-extension-contracts/loop-launchers"),d=require("@agimon-ai/doompi-extension-contracts/ui-hub");const f=`start`,p=`stop`,m=`Pi session replaced.`;function h(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:i.ACTIVE_MODE_COLOR}:{},actions:[...e.length>0?[{id:f,enabled:!0}]:[{id:f,enabled:!1,disabledReason:`No loop launchers are registered.`}],...n?[{id:p,enabled:!0}]:[{id:p,enabled:!1,disabledReason:`No loops are active.`}]]}}function g(l,g){let _=!0,v,y,b,x=e=>{let t=v;if(!(!_||!t||t.context.sessionManager!==e.sessionManager||t.hostSession.sessionId!==e.sessionManager.getSessionId()))return t},S=e=>{if(!_||v!==e)return;let t=e.launchers.listLaunchers(),n=e.launchers.listInstances();e.context.ui?.setStatus(i.STATUS_KEY,n.length?`loops: ${n.length}`:void 0),y?.publish(h(t,n))};l.effect(()=>()=>{_=!1;let e=v;v=void 0,e?.context.ui?.setStatus(i.STATUS_KEY,void 0),y?.publish(h([],[])),y?.dispose(),b?.(),b=void 0,y=void 0},`${i.PACKAGE_SOURCE}/runtime`);let C=a.createDefaultLoopLauncher(g);l.inject([s.DOOM_MINOR_MODE_CATALOG_SERVICE],e=>{let t=(0,s.registerMinorModeOwner)((0,s.requireMinorModeCatalog)(e),{descriptor:{source:i.PACKAGE_SOURCE,id:i.MODE_STATUS_ID,label:`Loop`,description:`Session-scoped recurring prompt loops.`,order:60,actions:[{id:f,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:p,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:h([],[]),async handleAction(e,t,n){let r=x(n.context);if(!r)throw Error(`Loop launchers are unavailable for the active session.`);if(e===f){let e=await r.launchers.launch(t.launcherId,t.instanceId?{instanceId:t.instanceId}:{});if(v!==r)throw Error(`Loop action became stale.`);return{message:e?`Loop '${e.instanceId}' started.`:`Loop launch was cancelled.`}}if(e===p){let e=await r.launchers.stop(t.instanceId,t.reason??`Stopped through minor_mode.`);if(v!==r)throw Error(`Loop action became stale.`);return{message:e?`Loop stopped.`:`Loop instance was not active.`}}throw Error(`Unknown loop mode action: ${e}`)}});y=t;let n=v;return n&&S(n),()=>{t.dispose(),y===t&&(y=void 0)}}),l.inject([d.DOOM_UI_HUB_SERVICE],e=>{let t=o.registerLeaderContribution((0,d.requireDoomUiHub)(e));return b=t,()=>{t(),b===t&&(b=void 0)}}),e.registerCommands(g,{async start(e){let t=x(e);if(!t)return;let n=t.launchers.listLaunchers();if(!n.length){e.ui.notify(`No loop launchers are registered for this session.`,i.NOTIFY_INFO_LEVEL);return}let a=await r.openStartLoopOverlay(e,n);if(!(v!==t||!a))try{let n=await t.launchers.launch(a);if(v!==t)return;n&&e.ui.notify(`${n.label??n.launcherLabel} started.`,i.NOTIFY_INFO_LEVEL)}catch(n){if(v!==t)return;e.ui.notify(`Loop could not start: ${n instanceof Error?n.message:String(n)}`,`error`)}},async list(e){let t=x(e);t&&await n.openLoopListOverlay(e,t.launchers)}}),l.inject([c.DOOM_CORDIS_SESSION_SERVICE],async e=>{let n=e.get(c.DOOM_CORDIS_SESSION_SERVICE),r=t.createDoomLoopLaunchersService({generation:`${n.generation}:loop-launchers`,createInstanceId:()=>crypto.randomUUID(),timestamp:()=>new Date().toISOString()}),a={context:n.context,hostSession:n,launchers:r};v=a,e.provide(u.DOOM_LOOP_LAUNCHERS_SERVICE,r);let o,s;try{o=C.register(n.context,r),s=r.subscribe(()=>S(a)),S(a)}catch(e){throw v===a&&(v=void 0),await r.dispose(m),e}return async()=>{v===a&&(v=void 0),s(),a.context.ui?.setStatus(i.STATUS_KEY,void 0),y?.publish(h([],[]));let e=[];try{await o.dispose(m)}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 _(e){let t=await(0,c.connectDoomCordisHost)(e,i.PACKAGE_SOURCE),n=t.root.plugin(v,{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 v(e,t){e.inject([l.DOOM_HELP_SERVICE],e=>{let t=(0,l.requireDoomHelpService)(e).register({source:i.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()}),g(e,t.pi)}exports.default=_,exports.loopExtension=_,exports.installLoopRuntime=g;
|
|
2
|
+
//# sourceMappingURL=extension.cjs.map
|
|
@@ -0,0 +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,EACjD,CAAC,CAAE,GAAI,EAAkB,QAAS,GAAO,eAAgB,sBAAuB,CAAU,CAChG,CACF,CACF,CAGA,SAAgB,EAAmB,EAAiB,EAAwB,CAC1E,IAAI,EAAS,GACT,EACA,EACA,EAEE,EAAkB,GAA6D,CACnF,IAAM,EAAU,EAEd,MAAC,GACD,CAAC,GACD,EAAQ,QAAQ,iBAAmB,EAAQ,gBAC3C,EAAQ,YAAY,YAAc,EAAQ,eAAe,aAAa,GAIxE,OAAO,CACT,EAEM,EAAiB,GAAqC,CAC1D,GAAI,CAAC,GAAU,IAAkB,EAAS,OAC1C,IAAM,EAAY,EAAQ,UAAU,cAAc,EAC5C,EAAY,EAAQ,U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3
|
+
//#region src/adapters/pi/extension.d.ts
|
|
4
|
+
/** Install Loop state and external resources into its host-owned Cordis plugin fiber. */
|
|
5
|
+
declare function installLoopRuntime(cordis: Context, pi: ExtensionAPI): void;
|
|
6
|
+
/** The package's single standard Pi factory. */
|
|
7
|
+
declare function loopExtension(pi: ExtensionAPI): Promise<void>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { loopExtension as default, loopExtension, installLoopRuntime };
|
|
10
|
+
//# sourceMappingURL=extension.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension.d.cts","names":[],"sources":["../../../src/adapters/pi/extension.ts"],"mappings":";;;;iBAsEgB,mBAAmB,QAAQ,SAAS,IAAI;;iBA0LlC,cAAc,IAAI,eAAe"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
//#region src/adapters/pi/extension.d.ts
|
|
4
|
+
/** Install Loop state and external resources into its host-owned Cordis plugin fiber. */
|
|
5
|
+
declare function installLoopRuntime(cordis: Context, pi: ExtensionAPI): void;
|
|
6
|
+
/** The package's single standard Pi factory. */
|
|
7
|
+
declare function loopExtension(pi: ExtensionAPI): Promise<void>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { loopExtension as default, loopExtension, installLoopRuntime };
|
|
10
|
+
//# sourceMappingURL=extension.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension.d.mts","names":[],"sources":["../../../src/adapters/pi/extension.ts"],"mappings":";;;;iBAsEgB,mBAAmB,QAAQ,SAAS,IAAI;;iBA0LlC,cAAc,IAAI,eAAe"}
|
|
@@ -0,0 +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{ACTIVE_MODE_COLOR as i,MODE_STATUS_ID as a,NOTIFY_INFO_LEVEL as o,PACKAGE_SOURCE as s,STATUS_KEY as c}from"./loopConstants.mjs";import{createDefaultLoopLauncher as l}from"./defaultLoopLauncher.mjs";import{registerLeaderContribution as u}from"./leader.mjs";import{DOOM_MINOR_MODE_CATALOG_SERVICE as d,registerMinorModeOwner as f,requireMinorModeCatalog as p}from"@agimon-ai/doompi-extension-contracts/mode";import{DOOM_CORDIS_SESSION_SERVICE as m,connectDoomCordisHost as h}from"@agimon-ai/doompi-extension-contracts/cordis-host";import{DOOM_HELP_SERVICE as g,requireDoomHelpService as _}from"@agimon-ai/doompi-extension-contracts/help";import{DOOM_LOOP_LAUNCHERS_SERVICE as v}from"@agimon-ai/doompi-extension-contracts/loop-launchers";import{DOOM_UI_HUB_SERVICE as y,requireDoomUiHub as b}from"@agimon-ai/doompi-extension-contracts/ui-hub";const x=`start`,S=`stop`,C=`Pi session replaced.`;function w(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:i}:{},actions:[...e.length>0?[{id:x,enabled:!0}]:[{id:x,enabled:!1,disabledReason:`No loop launchers are registered.`}],...n?[{id:S,enabled:!0}]:[{id:S,enabled:!1,disabledReason:`No loops are active.`}]]}}function T(i,h){let g=!0,_,T,E,D=e=>{let t=_;if(!(!g||!t||t.context.sessionManager!==e.sessionManager||t.hostSession.sessionId!==e.sessionManager.getSessionId()))return t},O=e=>{if(!g||_!==e)return;let t=e.launchers.listLaunchers(),n=e.launchers.listInstances();e.context.ui?.setStatus(c,n.length?`loops: ${n.length}`:void 0),T?.publish(w(t,n))};i.effect(()=>()=>{g=!1;let e=_;_=void 0,e?.context.ui?.setStatus(c,void 0),T?.publish(w([],[])),T?.dispose(),E?.(),E=void 0,T=void 0},`${s}/runtime`);let k=l(h);i.inject([d],e=>{let t=f(p(e),{descriptor:{source:s,id:a,label:`Loop`,description:`Session-scoped recurring prompt loops.`,order:60,actions:[{id:x,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:S,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:w([],[]),async handleAction(e,t,n){let r=D(n.context);if(!r)throw Error(`Loop launchers are unavailable for the active session.`);if(e===x){let e=await r.launchers.launch(t.launcherId,t.instanceId?{instanceId:t.instanceId}:{});if(_!==r)throw Error(`Loop action became stale.`);return{message:e?`Loop '${e.instanceId}' started.`:`Loop launch was cancelled.`}}if(e===S){let e=await r.launchers.stop(t.instanceId,t.reason??`Stopped through minor_mode.`);if(_!==r)throw Error(`Loop action became stale.`);return{message:e?`Loop stopped.`:`Loop instance was not active.`}}throw Error(`Unknown loop mode action: ${e}`)}});T=t;let n=_;return n&&O(n),()=>{t.dispose(),T===t&&(T=void 0)}}),i.inject([y],e=>{let t=u(b(e));return E=t,()=>{t(),E===t&&(E=void 0)}}),e(h,{async start(e){let t=D(e);if(!t)return;let n=t.launchers.listLaunchers();if(!n.length){e.ui.notify(`No loop launchers are registered for this session.`,o);return}let i=await r(e,n);if(!(_!==t||!i))try{let n=await t.launchers.launch(i);if(_!==t)return;n&&e.ui.notify(`${n.label??n.launcherLabel} started.`,o)}catch(n){if(_!==t)return;e.ui.notify(`Loop could not start: ${n instanceof Error?n.message:String(n)}`,`error`)}},async list(e){let t=D(e);t&&await n(e,t.launchers)}}),i.inject([m],async e=>{let n=e.get(m),r=t({generation:`${n.generation}:loop-launchers`,createInstanceId:()=>crypto.randomUUID(),timestamp:()=>new Date().toISOString()}),i={context:n.context,hostSession:n,launchers:r};_=i,e.provide(v,r);let a,o;try{a=k.register(n.context,r),o=r.subscribe(()=>O(i)),O(i)}catch(e){throw _===i&&(_=void 0),await r.dispose(C),e}return async()=>{_===i&&(_=void 0),o(),i.context.ui?.setStatus(c,void 0),T?.publish(w([],[]));let e=[];try{await a.dispose(C)}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 E(e){let t=await h(e,s),n=t.root.plugin(D,{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 D(e,t){e.inject([g],e=>{let t=_(e).register({source:s,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()}),T(e,t.pi)}export{E as default,E as loopExtension,T as installLoopRuntime};
|
|
2
|
+
//# sourceMappingURL=extension.mjs.map
|
|
@@ -0,0 +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,EACjD,CAAC,CAAE,GAAI,EAAkB,QAAS,GAAO,eAAgB,sBAAuB,CAAU,CAChG,CACF,CACF,CAGA,SAAgB,EAAmB,EAAiB,EAAwB,CAC1E,IAAI,EAAS,GACT,EACA,EACA,EAEE,EAAkB,GAA6D,CACnF,IAAM,EAAU,EAEd,MAAC,GACD,CAAC,GACD,EAAQ,QAAQ,iBAAmB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ACF,MAAM,EAAoB,QAAQ,CAAuB,CAC3D,OAAS,EAAO,CACd,EAAc,KAAK,CAAK,CAC1B,CACA,GAAI,CACF,MAAM,EAAU,QAAQ,uBAAuB,CACjD,OAAS,EAAO,CACd,EAAc,KAAK,CAAK,CAC1B,CACA,GAAI,EAAc,OAAS,EAAG,MAAU,eAAe,EAAe,8BAA8B,CACtG,CACF,CAAC,CACH,CAGA,eAAsB,EAAc,EAAiC,CACnE,IAAM,EAAa,MAAM,EAAsB,EAAI,CAAc,EAC3D,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
|
+
const e=require("../../schemas/loopCommands.cjs"),t=require("./loopConstants.cjs");function n(n){let r=n.registerLeader({source:t.PACKAGE_SOURCE,bindings:[{id:`loop.start`,path:[{key:`l`,label:`loops`,order:60},{key:`s`,label:`start`}],command:{name:e.START_COMMAND_NAME}},{id:`loop.list`,path:[{key:`l`,label:`loops`,order:60},{key:`l`,label:`list`,detail:`stop`}],command:{name:e.LIST_COMMAND_NAME}}]});return()=>r.dispose()}exports.registerLeaderContribution=n;
|
|
2
|
+
//# sourceMappingURL=leader.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"leader.cjs","names":["PACKAGE_SOURCE","START_COMMAND_NAME","LIST_COMMAND_NAME"],"sources":["../../../src/adapters/pi/leader.ts"],"sourcesContent":["import type { DoomUiHubService } from '@agimon-ai/doompi-extension-contracts/ui-hub';\nimport { LIST_COMMAND_NAME, START_COMMAND_NAME } from '../../schemas/loopCommands.ts';\nimport { LOOPS_GROUP_ORDER, PACKAGE_SOURCE } from './loopConstants.ts';\n\nexport function registerLeaderContribution(hub: DoomUiHubService): () => void {\n const contribution = hub.registerLeader({\n source: PACKAGE_SOURCE,\n bindings: [\n {\n id: 'loop.start',\n path: [\n { key: 'l', label: 'loops', order: LOOPS_GROUP_ORDER },\n { key: 's', label: 'start' },\n ],\n command: { name: START_COMMAND_NAME },\n },\n {\n id: 'loop.list',\n path: [\n { key: 'l', label: 'loops', order: LOOPS_GROUP_ORDER },\n { key: 'l', label: 'list', detail: 'stop' },\n ],\n command: { name: LIST_COMMAND_NAME },\n },\n ],\n });\n return () => contribution.dispose();\n}\n"],"mappings":"mFAIA,SAAgB,EAA2B,EAAmC,CAC5E,IAAM,EAAe,EAAI,eAAe,CACtC,OAAQA,EAAAA,eACR,SAAU,CACR,CACE,GAAI,aACJ,KAAM,CACJ,CAAE,IAAK,IAAK,MAAO,QAAS,MAAA,EAAyB,EACrD,CAAE,IAAK,IAAK,MAAO,OAAQ,CAC7B,EACA,QAAS,CAAE,KAAMC,EAAAA,kBAAmB,CACtC,EACA,CACE,GAAI,YACJ,KAAM,CACJ,CAAE,IAAK,IAAK,MAAO,QAAS,MAAA,EAAyB,EACrD,CAAE,IAAK,IAAK,MAAO,OAAQ,OAAQ,MAAO,CAC5C,EACA,QAAS,CAAE,KAAMC,EAAAA,iBAAkB,CACrC,CACF,CACF,CAAC,EACD,UAAa,EAAa,QAAQ,CACpC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{LIST_COMMAND_NAME as e,START_COMMAND_NAME as t}from"../../schemas/loopCommands.mjs";import{PACKAGE_SOURCE as n}from"./loopConstants.mjs";function r(r){let i=r.registerLeader({source:n,bindings:[{id:`loop.start`,path:[{key:`l`,label:`loops`,order:60},{key:`s`,label:`start`}],command:{name:t}},{id:`loop.list`,path:[{key:`l`,label:`loops`,order:60},{key:`l`,label:`list`,detail:`stop`}],command:{name:e}}]});return()=>i.dispose()}export{r as registerLeaderContribution};
|
|
2
|
+
//# sourceMappingURL=leader.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"leader.mjs","names":[],"sources":["../../../src/adapters/pi/leader.ts"],"sourcesContent":["import type { DoomUiHubService } from '@agimon-ai/doompi-extension-contracts/ui-hub';\nimport { LIST_COMMAND_NAME, START_COMMAND_NAME } from '../../schemas/loopCommands.ts';\nimport { LOOPS_GROUP_ORDER, PACKAGE_SOURCE } from './loopConstants.ts';\n\nexport function registerLeaderContribution(hub: DoomUiHubService): () => void {\n const contribution = hub.registerLeader({\n source: PACKAGE_SOURCE,\n bindings: [\n {\n id: 'loop.start',\n path: [\n { key: 'l', label: 'loops', order: LOOPS_GROUP_ORDER },\n { key: 's', label: 'start' },\n ],\n command: { name: START_COMMAND_NAME },\n },\n {\n id: 'loop.list',\n path: [\n { key: 'l', label: 'loops', order: LOOPS_GROUP_ORDER },\n { key: 'l', label: 'list', detail: 'stop' },\n ],\n command: { name: LIST_COMMAND_NAME },\n },\n ],\n });\n return () => contribution.dispose();\n}\n"],"mappings":"gJAIA,SAAgB,EAA2B,EAAmC,CAC5E,IAAM,EAAe,EAAI,eAAe,CACtC,OAAQ,EACR,SAAU,CACR,CACE,GAAI,aACJ,KAAM,CACJ,CAAE,IAAK,IAAK,MAAO,QAAS,MAAA,EAAyB,EACrD,CAAE,IAAK,IAAK,MAAO,OAAQ,CAC7B,EACA,QAAS,CAAE,KAAM,CAAmB,CACtC,EACA,CACE,GAAI,YACJ,KAAM,CACJ,CAAE,IAAK,IAAK,MAAO,QAAS,MAAA,EAAyB,EACrD,CAAE,IAAK,IAAK,MAAO,OAAQ,OAAQ,MAAO,CAC5C,EACA,QAAS,CAAE,KAAM,CAAkB,CACrC,CACF,CACF,CAAC,EACD,UAAa,EAAa,QAAQ,CACpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loopConstants.cjs","names":[],"sources":["../../../src/adapters/pi/loopConstants.ts"],"sourcesContent":["export const PACKAGE_SOURCE = '@agimon-ai/doompi-loop';\nexport const LOOPS_GROUP_ORDER = 60;\nexport const STATUS_KEY = 'doom-loop';\nexport const MODE_STATUS_ID = 'loop.active';\nexport const ACTIVE_MODE_COLOR = 'warning';\nexport const NOTIFY_INFO_LEVEL = 'info';\nexport const NOTIFY_WARNING_LEVEL = 'warning';\n"],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loopConstants.mjs","names":[],"sources":["../../../src/adapters/pi/loopConstants.ts"],"sourcesContent":["export const PACKAGE_SOURCE = '@agimon-ai/doompi-loop';\nexport const LOOPS_GROUP_ORDER = 60;\nexport const STATUS_KEY = 'doom-loop';\nexport const MODE_STATUS_ID = 'loop.active';\nexport const ACTIVE_MODE_COLOR = 'warning';\nexport const NOTIFY_INFO_LEVEL = 'info';\nexport const NOTIFY_WARNING_LEVEL = 'warning';\n"],"mappings":"AAAA,MAAa,EAAiB,yBAEjB,EAAa,YACb,EAAiB,cACjB,EAAoB,UACpB,EAAoB,OACpB,EAAuB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../
|
|
1
|
+
const e=require("../schemas/loopCommands.cjs");function t(t,n){t.registerCommand(e.START_COMMAND_NAME,{description:`Start a registered loop`,handler:async(e,t)=>n.start(t)}),t.registerCommand(e.LIST_COMMAND_NAME,{description:`List and stop active loops`,handler:async(e,t)=>n.list(t)})}exports.registerCommands=t;
|
|
2
2
|
//# sourceMappingURL=loopCommand.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loopCommand.cjs","names":["START_COMMAND_NAME","
|
|
1
|
+
{"version":3,"file":"loopCommand.cjs","names":["START_COMMAND_NAME","LIST_COMMAND_NAME"],"sources":["../../src/commands/loopCommand.ts"],"sourcesContent":["import type { ExtensionAPI, ExtensionContext } from '@earendil-works/pi-coding-agent';\nimport { LIST_COMMAND_NAME, START_COMMAND_NAME } from '../schemas/loopCommands.ts';\n\nconst START_COMMAND_DESCRIPTION = 'Start a registered loop';\nconst LIST_COMMAND_DESCRIPTION = 'List and stop active loops';\n\nexport interface LoopCommandHandlers {\n start(ctx: ExtensionContext): Promise<void>;\n list(ctx: ExtensionContext): Promise<void>;\n}\n\nexport function registerCommands(pi: ExtensionAPI, handlers: LoopCommandHandlers): void {\n pi.registerCommand(START_COMMAND_NAME, {\n description: START_COMMAND_DESCRIPTION,\n handler: async (_args, ctx) => handlers.start(ctx),\n });\n pi.registerCommand(LIST_COMMAND_NAME, {\n description: LIST_COMMAND_DESCRIPTION,\n handler: async (_args, ctx) => handlers.list(ctx),\n });\n}\n"],"mappings":"+CAWA,SAAgB,EAAiB,EAAkB,EAAqC,CACtF,EAAG,gBAAgBA,EAAAA,mBAAoB,CACrC,YAAa,0BACb,QAAS,MAAO,EAAO,IAAQ,EAAS,MAAM,CAAG,CACnD,CAAC,EACD,EAAG,gBAAgBC,EAAAA,kBAAmB,CACpC,YAAa,6BACb,QAAS,MAAO,EAAO,IAAQ,EAAS,KAAK,CAAG,CAClD,CAAC,CACH"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{LIST_COMMAND_NAME as e,START_COMMAND_NAME as t}from"../schemas/loopCommands.mjs";function n(n,r){n.registerCommand(t,{description:`Start a registered loop`,handler:async(e,t)=>r.start(t)}),n.registerCommand(e,{description:`List and stop active loops`,handler:async(e,t)=>r.list(t)})}export{n as registerCommands};
|
|
2
2
|
//# sourceMappingURL=loopCommand.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loopCommand.mjs","names":[],"sources":["../../src/commands/loopCommand.ts"],"sourcesContent":["import type { ExtensionAPI, ExtensionContext } from '@earendil-works/pi-coding-agent';\nimport {
|
|
1
|
+
{"version":3,"file":"loopCommand.mjs","names":[],"sources":["../../src/commands/loopCommand.ts"],"sourcesContent":["import type { ExtensionAPI, ExtensionContext } from '@earendil-works/pi-coding-agent';\nimport { LIST_COMMAND_NAME, START_COMMAND_NAME } from '../schemas/loopCommands.ts';\n\nconst START_COMMAND_DESCRIPTION = 'Start a registered loop';\nconst LIST_COMMAND_DESCRIPTION = 'List and stop active loops';\n\nexport interface LoopCommandHandlers {\n start(ctx: ExtensionContext): Promise<void>;\n list(ctx: ExtensionContext): Promise<void>;\n}\n\nexport function registerCommands(pi: ExtensionAPI, handlers: LoopCommandHandlers): void {\n pi.registerCommand(START_COMMAND_NAME, {\n description: START_COMMAND_DESCRIPTION,\n handler: async (_args, ctx) => handlers.start(ctx),\n });\n pi.registerCommand(LIST_COMMAND_NAME, {\n description: LIST_COMMAND_DESCRIPTION,\n handler: async (_args, ctx) => handlers.list(ctx),\n });\n}\n"],"mappings":"wFAWA,SAAgB,EAAiB,EAAkB,EAAqC,CACtF,EAAG,gBAAgB,EAAoB,CACrC,YAAa,0BACb,QAAS,MAAO,EAAO,IAAQ,EAAS,MAAM,CAAG,CACnD,CAAC,EACD,EAAG,gBAAgB,EAAmB,CACpC,YAAa,6BACb,QAAS,MAAO,EAAO,IAAQ,EAAS,KAAK,CAAG,CAClD,CAAC,CACH"}
|
package/dist/extensions/pi.cjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=pi.cjs.map
|
|
1
|
+
const e=require("../adapters/pi/extension.cjs");module.exports=e.default;
|
package/dist/extensions/pi.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
export =
|
|
1
|
+
import loopExtension from "../adapters/pi/extension.cjs";
|
|
2
|
+
export = loopExtension;
|
package/dist/extensions/pi.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
export {
|
|
1
|
+
import loopExtension from "../adapters/pi/extension.mjs";
|
|
2
|
+
export { loopExtension as default };
|
package/dist/extensions/pi.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
//# sourceMappingURL=pi.mjs.map
|
|
1
|
+
import e from"../adapters/pi/extension.mjs";export{e as default};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./adapters/pi/extension.cjs");exports.installLoopRuntime=e.installLoopRuntime;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { LoopInstanceSnapshot, LoopLaunchRequest,
|
|
3
|
-
export { type LoopInstanceSnapshot, type LoopLaunchRequest, type
|
|
1
|
+
import { installLoopRuntime } from "./adapters/pi/extension.cjs";
|
|
2
|
+
import { DoomLoopLaunchersService, LoopInstanceSnapshot, LoopLaunchRequest, LoopLauncherDefinition, LoopLauncherRegistration, LoopLauncherSummary, StoppableLoop } from "@agimon-ai/doompi-extension-contracts/loop-launchers";
|
|
3
|
+
export { type DoomLoopLaunchersService, type LoopInstanceSnapshot, type LoopLaunchRequest, type LoopLauncherDefinition, type LoopLauncherRegistration, type LoopLauncherSummary, type StoppableLoop, installLoopRuntime };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { LoopInstanceSnapshot, LoopLaunchRequest,
|
|
3
|
-
export { type LoopInstanceSnapshot, type LoopLaunchRequest, type
|
|
1
|
+
import { installLoopRuntime } from "./adapters/pi/extension.mjs";
|
|
2
|
+
import { DoomLoopLaunchersService, LoopInstanceSnapshot, LoopLaunchRequest, LoopLauncherDefinition, LoopLauncherRegistration, LoopLauncherSummary, StoppableLoop } from "@agimon-ai/doompi-extension-contracts/loop-launchers";
|
|
3
|
+
export { type DoomLoopLaunchersService, type LoopInstanceSnapshot, type LoopLaunchRequest, type LoopLauncherDefinition, type LoopLauncherRegistration, type LoopLauncherSummary, type StoppableLoop, installLoopRuntime };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{installLoopRuntime as e}from"./adapters/pi/extension.mjs";export{e as installLoopRuntime};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loopCommands.cjs","names":[],"sources":["../../src/schemas/loopCommands.ts"],"sourcesContent":["export const START_COMMAND_NAME = 'loop';\nexport const LIST_COMMAND_NAME = 'loops';\n"],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loopCommands.mjs","names":[],"sources":["../../src/schemas/loopCommands.ts"],"sourcesContent":["export const START_COMMAND_NAME = 'loop';\nexport const LIST_COMMAND_NAME = 'loops';\n"],"mappings":"AAAA,MAAa,EAAqB,OACrB,EAAoB"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=`loop launcher id`,t=`loop instance id`;function n(e,t){let n=e.trim(),r=!1;for(let e of n){let t=e.codePointAt(0);if(t!==void 0&&(t<=31||t===127)){r=!0;break}}if(!n||n.length>256||r)throw Error(`Invalid ${t}.`);return n}function r(e){return{instanceId:e.instanceId,launcherId:e.launcher.definition.id,launcherLabel:e.launcher.definition.label,...e.handle?.label?{label:e.handle.label}:{},...e.handle?.detail?{detail:e.handle.detail}:{},state:e.state,...e.startedAt?{startedAt:e.startedAt}:{}}}function i({generation:i,createInstanceId:a,timestamp:o}){if(!i||i.length>256)throw TypeError(`Doom loop launchers require a valid generation.`);let s=new Map,c=new Map,l=new Set,u=0,d=!1,f=()=>{if(d)throw Error(`The Doom loop-launchers service is disposed.`)},p=()=>{for(let e of l)e()},m=async(e,t)=>{if(c.get(e.instanceId)===e){e.state=`stopping`,e.abortController.abort(t),p();try{await e.handle?.stop(t)}finally{c.get(e.instanceId)===e&&c.delete(e.instanceId),p()}}};return Object.freeze({generation:i,register(t){f();let r=n(t.id,e);if(s.has(r))throw Error(`Loop launcher '${r}' is already registered.`);let a=Symbol(r),o={token:a,definition:{...t,id:r}};s.set(r,o),u+=1,p();let l=!1;return Object.freeze({id:r,generation:`${i}:launcher:${u}`,async dispose(e=`Loop launcher disposed.`){if(l||(l=!0,s.get(r)?.token!==a))return;s.delete(r);let t=[...c.values()].filter(e=>e.launcher.token===a);await Promise.allSettled(t.map(t=>m(t,e))),p()}})},listLaunchers(){return f(),[...s.values()].map(({definition:e})=>({id:e.id,source:e.source,label:e.label,...e.description?{description:e.description}:{}})).sort((e,t)=>e.label.localeCompare(t.label)||e.id.localeCompare(t.id))},listInstances(){return f(),[...c.values()].map(r).sort((e,t)=>e.instanceId.localeCompare(t.instanceId))},subscribe(e){f(),l.add(e);let t=!0;return()=>{t&&(t=!1,l.delete(e))}},async launch(i,l){f();let u=n(i,e),m=s.get(u);if(!m)throw Error(`Loop launcher '${u}' is unavailable.`);let h=n(l?.instanceId??a(),t);if(c.has(h))throw Error(`Loop instance '${h}' already exists.`);let g={instanceId:h,launcher:m,abortController:new AbortController,state:`starting`};c.set(h,g),p();try{let e=await m.definition.launch({instanceId:h,signal:g.abortController.signal}),t=!d&&c.get(h)===g&&!g.abortController.signal.aborted;if(!e){c.get(h)===g&&c.delete(h),p();return}if(!t||e.instanceId!==h){if(await e.stop(t?`Loop launcher returned a mismatched instance id.`:`Loop launch was cancelled.`),c.get(h)===g&&c.delete(h),p(),t)throw Error(`Loop launcher '${u}' returned a mismatched instance id.`);return}return g.handle=e,g.state=`running`,g.startedAt=o(),p(),r(g)}catch(e){let t=g.abortController.signal.aborted||d;if(c.get(h)===g&&c.delete(h),p(),t)return;throw e}},async stop(e,r){f();let i=c.get(n(e,t));return i?(await m(i,r),!0):!1},async stopAll(e){d&&c.size===0||await Promise.allSettled([...c.values()].map(t=>m(t,e)))},async dispose(e=`Doom loop-launchers service disposed.`){d||(d=!0,s.clear(),await Promise.allSettled([...c.values()].map(t=>m(t,e))),l.clear())}})}exports.createDoomLoopLaunchersService=i;
|
|
2
|
+
//# sourceMappingURL=loopLaunchers.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loopLaunchers.cjs","names":[],"sources":["../../src/services/loopLaunchers.ts"],"sourcesContent":["import type {\n DoomLoopLaunchersService,\n LoopInstanceSnapshot,\n LoopLauncherDefinition,\n LoopLauncherRegistration,\n StoppableLoop,\n} from '@agimon-ai/doompi-extension-contracts/loop-launchers';\n\nconst MAX_ID_LENGTH = 256;\nconst MAX_GENERATION_LENGTH = 256;\nconst LAUNCHER_ID_LABEL = 'loop launcher id';\nconst INSTANCE_ID_LABEL = 'loop instance id';\n\ninterface LauncherEntry {\n readonly token: symbol;\n readonly definition: LoopLauncherDefinition;\n}\n\ninterface InstanceEntry {\n readonly instanceId: string;\n readonly launcher: LauncherEntry;\n readonly abortController: AbortController;\n state: LoopInstanceSnapshot['state'];\n handle?: StoppableLoop;\n startedAt?: string;\n}\n\nexport interface LoopLaunchersDependencies {\n readonly generation: string;\n readonly createInstanceId: () => string;\n readonly timestamp: () => string;\n}\n\nfunction validId(value: string, label: string): string {\n const normalized = value.trim();\n let hasControl = false;\n for (const character of normalized) {\n const code = character.codePointAt(0);\n if (code !== undefined && (code <= 0x1f || code === 0x7f)) {\n hasControl = true;\n break;\n }\n }\n if (!normalized || normalized.length > MAX_ID_LENGTH || hasControl) throw new Error(`Invalid ${label}.`);\n return normalized;\n}\n\nfunction snapshot(entry: InstanceEntry): LoopInstanceSnapshot {\n return {\n instanceId: entry.instanceId,\n launcherId: entry.launcher.definition.id,\n launcherLabel: entry.launcher.definition.label,\n ...(entry.handle?.label ? { label: entry.handle.label } : {}),\n ...(entry.handle?.detail ? { detail: entry.handle.detail } : {}),\n state: entry.state,\n ...(entry.startedAt ? { startedAt: entry.startedAt } : {}),\n };\n}\n\n/** Creates the provider-owned launcher registry for one active Doom session. */\nexport function createDoomLoopLaunchersService({\n generation,\n createInstanceId,\n timestamp,\n}: LoopLaunchersDependencies): DoomLoopLaunchersService {\n if (!generation || generation.length > MAX_GENERATION_LENGTH) {\n throw new TypeError('Doom loop launchers require a valid generation.');\n }\n\n const launchers = new Map<string, LauncherEntry>();\n const instances = new Map<string, InstanceEntry>();\n const listeners = new Set<() => void>();\n let registrationSequence = 0;\n let disposed = false;\n\n const ensureActive = (): void => {\n if (disposed) throw new Error('The Doom loop-launchers service is disposed.');\n };\n const notify = (): void => {\n for (const listener of listeners) listener();\n };\n const stopEntry = async (entry: InstanceEntry, reason?: string): Promise<void> => {\n if (instances.get(entry.instanceId) !== entry) return;\n entry.state = 'stopping';\n entry.abortController.abort(reason);\n notify();\n try {\n await entry.handle?.stop(reason);\n } finally {\n if (instances.get(entry.instanceId) === entry) instances.delete(entry.instanceId);\n notify();\n }\n };\n\n const service: DoomLoopLaunchersService = {\n generation,\n register(definition): LoopLauncherRegistration {\n ensureActive();\n const id = validId(definition.id, LAUNCHER_ID_LABEL);\n if (launchers.has(id)) throw new Error(`Loop launcher '${id}' is already registered.`);\n const token = Symbol(id);\n const entry: LauncherEntry = { token, definition: { ...definition, id } };\n launchers.set(id, entry);\n registrationSequence += 1;\n notify();\n let registrationDisposed = false;\n return Object.freeze({\n id,\n generation: `${generation}:launcher:${registrationSequence}`,\n async dispose(reason = 'Loop launcher disposed.'): Promise<void> {\n if (registrationDisposed) return;\n registrationDisposed = true;\n if (launchers.get(id)?.token !== token) return;\n launchers.delete(id);\n const owned = [...instances.values()].filter((instance) => instance.launcher.token === token);\n await Promise.allSettled(owned.map((instance) => stopEntry(instance, reason)));\n notify();\n },\n });\n },\n listLaunchers() {\n ensureActive();\n return [...launchers.values()]\n .map(({ definition }) => ({\n id: definition.id,\n source: definition.source,\n label: definition.label,\n ...(definition.description ? { description: definition.description } : {}),\n }))\n .sort((left, right) => left.label.localeCompare(right.label) || left.id.localeCompare(right.id));\n },\n listInstances() {\n ensureActive();\n return [...instances.values()]\n .map(snapshot)\n .sort((left, right) => left.instanceId.localeCompare(right.instanceId));\n },\n subscribe(listener) {\n ensureActive();\n listeners.add(listener);\n let subscribed = true;\n return () => {\n if (!subscribed) return;\n subscribed = false;\n listeners.delete(listener);\n };\n },\n async launch(launcherId, options) {\n ensureActive();\n const normalizedLauncherId = validId(launcherId, LAUNCHER_ID_LABEL);\n const launcher = launchers.get(normalizedLauncherId);\n if (!launcher) throw new Error(`Loop launcher '${normalizedLauncherId}' is unavailable.`);\n const instanceId = validId(options?.instanceId ?? createInstanceId(), INSTANCE_ID_LABEL);\n if (instances.has(instanceId)) throw new Error(`Loop instance '${instanceId}' already exists.`);\n const entry: InstanceEntry = { instanceId, launcher, abortController: new AbortController(), state: 'starting' };\n instances.set(instanceId, entry);\n notify();\n try {\n const handle = await launcher.definition.launch({ instanceId, signal: entry.abortController.signal });\n const active = !disposed && instances.get(instanceId) === entry && !entry.abortController.signal.aborted;\n if (!handle) {\n if (instances.get(instanceId) === entry) instances.delete(instanceId);\n notify();\n return undefined;\n }\n if (!active || handle.instanceId !== instanceId) {\n await handle.stop(active ? 'Loop launcher returned a mismatched instance id.' : 'Loop launch was cancelled.');\n if (instances.get(instanceId) === entry) instances.delete(instanceId);\n notify();\n if (active) throw new Error(`Loop launcher '${normalizedLauncherId}' returned a mismatched instance id.`);\n return undefined;\n }\n entry.handle = handle;\n entry.state = 'running';\n entry.startedAt = timestamp();\n notify();\n return snapshot(entry);\n } catch (error) {\n const cancelled = entry.abortController.signal.aborted || disposed;\n if (instances.get(instanceId) === entry) instances.delete(instanceId);\n notify();\n if (cancelled) return undefined;\n throw error;\n }\n },\n async stop(instanceId, reason) {\n ensureActive();\n const entry = instances.get(validId(instanceId, INSTANCE_ID_LABEL));\n if (!entry) return false;\n await stopEntry(entry, reason);\n return true;\n },\n async stopAll(reason) {\n if (disposed && instances.size === 0) return;\n await Promise.allSettled([...instances.values()].map((entry) => stopEntry(entry, reason)));\n },\n async dispose(reason = 'Doom loop-launchers service disposed.') {\n if (disposed) return;\n disposed = true;\n launchers.clear();\n await Promise.allSettled([...instances.values()].map((entry) => stopEntry(entry, reason)));\n listeners.clear();\n },\n };\n\n return Object.freeze(service);\n}\n"],"mappings":"AAQA,MAEM,EAAoB,mBACpB,EAAoB,mBAsB1B,SAAS,EAAQ,EAAe,EAAuB,CACrD,IAAM,EAAa,EAAM,KAAK,EAC1B,EAAa,GACjB,IAAK,IAAM,KAAa,EAAY,CAClC,IAAM,EAAO,EAAU,YAAY,CAAC,EACpC,GAAI,IAAS,IAAA,KAAc,GAAQ,IAAQ,IAAS,KAAO,CACzD,EAAa,GACb,KACF,CACF,CACA,GAAI,CAAC,GAAc,EAAW,OAAS,KAAiB,EAAY,MAAU,MAAM,WAAW,EAAM,EAAE,EACvG,OAAO,CACT,CAEA,SAAS,EAAS,EAA4C,CAC5D,MAAO,CACL,WAAY,EAAM,WAClB,WAAY,EAAM,SAAS,WAAW,GACtC,cAAe,EAAM,SAAS,WAAW,MACzC,GAAI,EAAM,QAAQ,MAAQ,CAAE,MAAO,EAAM,OAAO,KAAM,EAAI,CAAC,EAC3D,GAAI,EAAM,QAAQ,OAAS,CAAE,OAAQ,EAAM,OAAO,MAAO,EAAI,CAAC,EAC9D,MAAO,EAAM,MACb,GAAI,EAAM,UAAY,CAAE,UAAW,EAAM,SAAU,EAAI,CAAC,CAC1D,CACF,CAGA,SAAgB,EAA+B,CAC7C,aACA,mBACA,aACsD,CACtD,GAAI,CAAC,GAAc,EAAW,OAAS,IACrC,MAAU,UAAU,iDAAiD,EAGvE,IAAM,EAAY,IAAI,IAChB,EAAY,IAAI,IAChB,EAA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!n||n.length>256||r)throw Error(`Invalid ${t}.`);return n}function r(e){return{instanceId:e.instanceId,launcherId:e.launcher.definition.id,launcherLabel:e.launcher.definition.label,...e.handle?.label?{label:e.handle.label}:{},...e.handle?.detail?{detail:e.handle.detail}:{},state:e.state,...e.startedAt?{startedAt:e.startedAt}:{}}}function i({generation:i,createInstanceId:a,timestamp:o}){if(!i||i.length>256)throw TypeError(`Doom loop launchers require a valid generation.`);let s=new Map,c=new Map,l=new Set,u=0,d=!1,f=()=>{if(d)throw Error(`The Doom loop-launchers service is disposed.`)},p=()=>{for(let e of l)e()},m=async(e,t)=>{if(c.get(e.instanceId)===e){e.state=`stopping`,e.abortController.abort(t),p();try{await e.handle?.stop(t)}finally{c.get(e.instanceId)===e&&c.delete(e.instanceId),p()}}};return Object.freeze({generation:i,register(t){f();let r=n(t.id,e);if(s.has(r))throw Error(`Loop launcher '${r}' is already registered.`);let a=Symbol(r),o={token:a,definition:{...t,id:r}};s.set(r,o),u+=1,p();let l=!1;return Object.freeze({id:r,generation:`${i}:launcher:${u}`,async dispose(e=`Loop launcher disposed.`){if(l||(l=!0,s.get(r)?.token!==a))return;s.delete(r);let t=[...c.values()].filter(e=>e.launcher.token===a);await Promise.allSettled(t.map(t=>m(t,e))),p()}})},listLaunchers(){return f(),[...s.values()].map(({definition:e})=>({id:e.id,source:e.source,label:e.label,...e.description?{description:e.description}:{}})).sort((e,t)=>e.label.localeCompare(t.label)||e.id.localeCompare(t.id))},listInstances(){return f(),[...c.values()].map(r).sort((e,t)=>e.instanceId.localeCompare(t.instanceId))},subscribe(e){f(),l.add(e);let t=!0;return()=>{t&&(t=!1,l.delete(e))}},async launch(i,l){f();let u=n(i,e),m=s.get(u);if(!m)throw Error(`Loop launcher '${u}' is unavailable.`);let h=n(l?.instanceId??a(),t);if(c.has(h))throw Error(`Loop instance '${h}' already exists.`);let g={instanceId:h,launcher:m,abortController:new AbortController,state:`starting`};c.set(h,g),p();try{let e=await m.definition.launch({instanceId:h,signal:g.abortController.signal}),t=!d&&c.get(h)===g&&!g.abortController.signal.aborted;if(!e){c.get(h)===g&&c.delete(h),p();return}if(!t||e.instanceId!==h){if(await e.stop(t?`Loop launcher returned a mismatched instance id.`:`Loop launch was cancelled.`),c.get(h)===g&&c.delete(h),p(),t)throw Error(`Loop launcher '${u}' returned a mismatched instance id.`);return}return g.handle=e,g.state=`running`,g.startedAt=o(),p(),r(g)}catch(e){let t=g.abortController.signal.aborted||d;if(c.get(h)===g&&c.delete(h),p(),t)return;throw e}},async stop(e,r){f();let i=c.get(n(e,t));return i?(await m(i,r),!0):!1},async stopAll(e){d&&c.size===0||await Promise.allSettled([...c.values()].map(t=>m(t,e)))},async dispose(e=`Doom loop-launchers service disposed.`){d||(d=!0,s.clear(),await Promise.allSettled([...c.values()].map(t=>m(t,e))),l.clear())}})}export{i as createDoomLoopLaunchersService};
|
|
2
|
+
//# sourceMappingURL=loopLaunchers.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loopLaunchers.mjs","names":[],"sources":["../../src/services/loopLaunchers.ts"],"sourcesContent":["import type {\n DoomLoopLaunchersService,\n LoopInstanceSnapshot,\n LoopLauncherDefinition,\n LoopLauncherRegistration,\n StoppableLoop,\n} from '@agimon-ai/doompi-extension-contracts/loop-launchers';\n\nconst MAX_ID_LENGTH = 256;\nconst MAX_GENERATION_LENGTH = 256;\nconst LAUNCHER_ID_LABEL = 'loop launcher id';\nconst INSTANCE_ID_LABEL = 'loop instance id';\n\ninterface LauncherEntry {\n readonly token: symbol;\n readonly definition: LoopLauncherDefinition;\n}\n\ninterface InstanceEntry {\n readonly instanceId: string;\n readonly launcher: LauncherEntry;\n readonly abortController: AbortController;\n state: LoopInstanceSnapshot['state'];\n handle?: StoppableLoop;\n startedAt?: string;\n}\n\nexport interface LoopLaunchersDependencies {\n readonly generation: string;\n readonly createInstanceId: () => string;\n readonly timestamp: () => string;\n}\n\nfunction validId(value: string, label: string): string {\n const normalized = value.trim();\n let hasControl = false;\n for (const character of normalized) {\n const code = character.codePointAt(0);\n if (code !== undefined && (code <= 0x1f || code === 0x7f)) {\n hasControl = true;\n break;\n }\n }\n if (!normalized || normalized.length > MAX_ID_LENGTH || hasControl) throw new Error(`Invalid ${label}.`);\n return normalized;\n}\n\nfunction snapshot(entry: InstanceEntry): LoopInstanceSnapshot {\n return {\n instanceId: entry.instanceId,\n launcherId: entry.launcher.definition.id,\n launcherLabel: entry.launcher.definition.label,\n ...(entry.handle?.label ? { label: entry.handle.label } : {}),\n ...(entry.handle?.detail ? { detail: entry.handle.detail } : {}),\n state: entry.state,\n ...(entry.startedAt ? { startedAt: entry.startedAt } : {}),\n };\n}\n\n/** Creates the provider-owned launcher registry for one active Doom session. */\nexport function createDoomLoopLaunchersService({\n generation,\n createInstanceId,\n timestamp,\n}: LoopLaunchersDependencies): DoomLoopLaunchersService {\n if (!generation || generation.length > MAX_GENERATION_LENGTH) {\n throw new TypeError('Doom loop launchers require a valid generation.');\n }\n\n const launchers = new Map<string, LauncherEntry>();\n const instances = new Map<string, InstanceEntry>();\n const listeners = new Set<() => void>();\n let registrationSequence = 0;\n let disposed = false;\n\n const ensureActive = (): void => {\n if (disposed) throw new Error('The Doom loop-launchers service is disposed.');\n };\n const notify = (): void => {\n for (const listener of listeners) listener();\n };\n const stopEntry = async (entry: InstanceEntry, reason?: string): Promise<void> => {\n if (instances.get(entry.instanceId) !== entry) return;\n entry.state = 'stopping';\n entry.abortController.abort(reason);\n notify();\n try {\n await entry.handle?.stop(reason);\n } finally {\n if (instances.get(entry.instanceId) === entry) instances.delete(entry.instanceId);\n notify();\n }\n };\n\n const service: DoomLoopLaunchersService = {\n generation,\n register(definition): LoopLauncherRegistration {\n ensureActive();\n const id = validId(definition.id, LAUNCHER_ID_LABEL);\n if (launchers.has(id)) throw new Error(`Loop launcher '${id}' is already registered.`);\n const token = Symbol(id);\n const entry: LauncherEntry = { token, definition: { ...definition, id } };\n launchers.set(id, entry);\n registrationSequence += 1;\n notify();\n let registrationDisposed = false;\n return Object.freeze({\n id,\n generation: `${generation}:launcher:${registrationSequence}`,\n async dispose(reason = 'Loop launcher disposed.'): Promise<void> {\n if (registrationDisposed) return;\n registrationDisposed = true;\n if (launchers.get(id)?.token !== token) return;\n launchers.delete(id);\n const owned = [...instances.values()].filter((instance) => instance.launcher.token === token);\n await Promise.allSettled(owned.map((instance) => stopEntry(instance, reason)));\n notify();\n },\n });\n },\n listLaunchers() {\n ensureActive();\n return [...launchers.values()]\n .map(({ definition }) => ({\n id: definition.id,\n source: definition.source,\n label: definition.label,\n ...(definition.description ? { description: definition.description } : {}),\n }))\n .sort((left, right) => left.label.localeCompare(right.label) || left.id.localeCompare(right.id));\n },\n listInstances() {\n ensureActive();\n return [...instances.values()]\n .map(snapshot)\n .sort((left, right) => left.instanceId.localeCompare(right.instanceId));\n },\n subscribe(listener) {\n ensureActive();\n listeners.add(listener);\n let subscribed = true;\n return () => {\n if (!subscribed) return;\n subscribed = false;\n listeners.delete(listener);\n };\n },\n async launch(launcherId, options) {\n ensureActive();\n const normalizedLauncherId = validId(launcherId, LAUNCHER_ID_LABEL);\n const launcher = launchers.get(normalizedLauncherId);\n if (!launcher) throw new Error(`Loop launcher '${normalizedLauncherId}' is unavailable.`);\n const instanceId = validId(options?.instanceId ?? createInstanceId(), INSTANCE_ID_LABEL);\n if (instances.has(instanceId)) throw new Error(`Loop instance '${instanceId}' already exists.`);\n const entry: InstanceEntry = { instanceId, launcher, abortController: new AbortController(), state: 'starting' };\n instances.set(instanceId, entry);\n notify();\n try {\n const handle = await launcher.definition.launch({ instanceId, signal: entry.abortController.signal });\n const active = !disposed && instances.get(instanceId) === entry && !entry.abortController.signal.aborted;\n if (!handle) {\n if (instances.get(instanceId) === entry) instances.delete(instanceId);\n notify();\n return undefined;\n }\n if (!active || handle.instanceId !== instanceId) {\n await handle.stop(active ? 'Loop launcher returned a mismatched instance id.' : 'Loop launch was cancelled.');\n if (instances.get(instanceId) === entry) instances.delete(instanceId);\n notify();\n if (active) throw new Error(`Loop launcher '${normalizedLauncherId}' returned a mismatched instance id.`);\n return undefined;\n }\n entry.handle = handle;\n entry.state = 'running';\n entry.startedAt = timestamp();\n notify();\n return snapshot(entry);\n } catch (error) {\n const cancelled = entry.abortController.signal.aborted || disposed;\n if (instances.get(instanceId) === entry) instances.delete(instanceId);\n notify();\n if (cancelled) return undefined;\n throw error;\n }\n },\n async stop(instanceId, reason) {\n ensureActive();\n const entry = instances.get(validId(instanceId, INSTANCE_ID_LABEL));\n if (!entry) return false;\n await stopEntry(entry, reason);\n return true;\n },\n async stopAll(reason) {\n if (disposed && instances.size === 0) return;\n await Promise.allSettled([...instances.values()].map((entry) => stopEntry(entry, reason)));\n },\n async dispose(reason = 'Doom loop-launchers service disposed.') {\n if (disposed) return;\n disposed = true;\n launchers.clear();\n await Promise.allSettled([...instances.values()].map((entry) => stopEntry(entry, reason)));\n listeners.clear();\n },\n };\n\n return Object.freeze(service);\n}\n"],"mappings":"AAQA,MAEM,EAAoB,mBACpB,EAAoB,mBAsB1B,SAAS,EAAQ,EAAe,EAAuB,CACrD,IAAM,EAAa,EAAM,KAAK,EAC1B,EAAa,GACjB,IAAK,IAAM,KAAa,EAAY,CAClC,IAAM,EAAO,EAAU,YAAY,CAAC,EACpC,GAAI,IAAS,IAAA,KAAc,GAAQ,IAAQ,IAAS,KAAO,CACzD,EAAa,GACb,KACF,CACF,CACA,GAAI,CAAC,GAAc,EAAW,OAAS,KAAiB,EAAY,MAAU,MAAM,WAAW,EAAM,EAAE,EACvG,OAAO,CACT,CAEA,SAAS,EAAS,EAA4C,CAC5D,MAAO,CACL,WAAY,EAAM,WAClB,WAAY,EAAM,SAAS,WAAW,GACtC,cAAe,EAAM,SAAS,WAAW,MACzC,GAAI,EAAM,QAAQ,MAAQ,CAAE,MAAO,EAAM,OAAO,KAAM,EAAI,CAAC,EAC3D,GAAI,EAAM,QAAQ,OAAS,CAAE,OAAQ,EAAM,OAAO,MAAO,EAAI,CAAC,EAC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CAAC,IAAK,GAAU,EAAU,EAAO,CAAM,CAAC,CAAC,EACzF,EAAU,MAAM,EAClB,CAGyB,CAAC,CAC9B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
let e=require("@agimon-ai/doompi-ui/components/doomOverlay"),t=require("@earendil-works/pi-tui");const n=`Stopped from the loop list.`;var r=class extends e.DoomOverlay{client;done;unsubscribe;instances;selected=0;constructor(e,t,n,r){super(e,t),this.client=n,this.done=r,this.instances=n.listInstances(),this.unsubscribe=n.subscribe(()=>this.refresh())}dispose(){this.unsubscribe()}handleInput(e){if((0,t.matchesKey)(e,`escape`)||(0,t.matchesKey)(e,`ctrl+c`)||e===`q`)
|
|
1
|
+
let e=require("@agimon-ai/doompi-ui/components/doomOverlay"),t=require("@earendil-works/pi-tui");const n=`Stopped from the loop list.`;var r=class extends e.DoomOverlay{client;done;unsubscribe;instances;selected=0;constructor(e,t,n,r){super(e,t),this.client=n,this.done=r,this.instances=n.listInstances(),this.unsubscribe=n.subscribe(()=>this.refresh())}dispose(){this.unsubscribe()}handleInput(e){if((0,t.matchesKey)(e,`escape`)||(0,t.matchesKey)(e,`ctrl+c`)||e===`q`){this.done(void 0);return}if((0,t.matchesKey)(e,`up`)||e===`k`){this.move(-1);return}if((0,t.matchesKey)(e,`down`)||e===`j`){this.move(1);return}if(e===`x`){let e=this.instances[this.selected];e&&this.client.stop(e.instanceId,n)}}getChrome(){return{title:`LOOPS`,breadcrumb:`SPC › l / loops › l / list`,headerRight:`${this.instances.length} active`,footer:`${e.DOOM_NAVIGATION_KEYS.list} move · x stop · esc close · launched detached work continues`,footerHints:[[e.DOOM_NAVIGATION_KEYS.list,`move`],[`x`,`stop scheduling`],[`esc`,`close`]],accent:e.DOOM_OVERLAY_ACCENT}}renderBody(e){let n=this.theme.fg(`dim`,(0,t.truncateToWidth)(`Stopping a loop does not cancel detached work already launched.`,e));return this.instances.length?[n,``,...this.instances.flatMap((n,r)=>{let i=r===this.selected?this.theme.fg(`accent`,`▸`):` `,a=n.label??n.launcherLabel,o=this.theme.fg(n.state===`running`?`success`:`warning`,n.state),s=(0,t.truncateToWidth)(`${i} ${a} · ${o}`,e),c=n.detail??n.instanceId;return[s,` ${this.theme.fg(`dim`,(0,t.truncateToWidth)(c,Math.max(0,e-4)))}`]})]:[this.theme.fg(`dim`,`No loop instances are active in this session.`),``,n]}refresh(){this.instances=this.client.listInstances(),this.selected=Math.min(this.selected,Math.max(0,this.instances.length-1)),this.invalidate()}move(e){this.instances.length&&(this.selected=Math.max(0,Math.min(this.selected+e,this.instances.length-1)),this.invalidate())}};async function i(t,i){if(t.mode!==`tui`){let e=i.listInstances(),r=e.map(e=>`${e.label??e.launcherLabel} (${e.instanceId})`),a=await t.ui.select(`Stop loop scheduling`,r),o=e[r.indexOf(a??``)];o&&await i.stop(o.instanceId,n);return}await t.ui.custom((e,t,n,a)=>new r(e,t,i,a),e.DOOM_FULLSCREEN_UI_OPTIONS)}exports.LoopListOverlay=r,exports.openLoopListOverlay=i;
|
|
2
2
|
//# sourceMappingURL=loopListOverlay.cjs.map
|