@agimon-ai/doompi-loop 0.0.1-alpha.13 → 0.0.1-alpha.15
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 +21 -18
- package/dist/adapters/pi/defaultLoopLauncher.cjs +2 -0
- package/dist/adapters/pi/defaultLoopLauncher.cjs.map +1 -0
- package/dist/{services/loop/defaultLauncher.d.cts → adapters/pi/defaultLoopLauncher.d.cts} +3 -3
- package/dist/adapters/pi/defaultLoopLauncher.d.cts.map +1 -0
- package/dist/{services/loop/defaultLauncher.d.mts → adapters/pi/defaultLoopLauncher.d.mts} +3 -3
- package/dist/adapters/pi/defaultLoopLauncher.d.mts.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 +1 -1
- package/dist/adapters/pi/extension.cjs.map +1 -1
- package/dist/adapters/pi/extension.d.cts.map +1 -1
- package/dist/adapters/pi/extension.d.mts.map +1 -1
- package/dist/adapters/pi/extension.mjs +1 -1
- package/dist/adapters/pi/extension.mjs.map +1 -1
- package/dist/adapters/pi/leader.cjs +1 -1
- package/dist/adapters/pi/leader.cjs.map +1 -1
- package/dist/adapters/pi/leader.mjs +1 -1
- package/dist/adapters/pi/leader.mjs.map +1 -1
- package/dist/adapters/pi/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.mjs +1 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.mts +3 -2
- 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/loop/launcher.cjs +1 -1
- package/dist/services/loop/launcher.cjs.map +1 -1
- package/dist/services/loop/launcher.d.cts +2 -42
- package/dist/services/loop/launcher.d.cts.map +1 -1
- package/dist/services/loop/launcher.d.mts +2 -42
- package/dist/services/loop/launcher.d.mts.map +1 -1
- package/dist/services/loop/launcher.mjs +1 -1
- package/dist/services/loop/launcher.mjs.map +1 -1
- 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/dist/types/loop.d.cts +45 -0
- package/dist/types/loop.d.cts.map +1 -0
- package/dist/types/loop.d.mts +45 -0
- package/dist/types/loop.d.mts.map +1 -0
- package/package.json +3 -3
- package/dist/extensions/pi.cjs.map +0 -1
- package/dist/extensions/pi.mjs.map +0 -1
- package/dist/services/loop/defaultLauncher.cjs +0 -2
- package/dist/services/loop/defaultLauncher.cjs.map +0 -1
- package/dist/services/loop/defaultLauncher.d.cts.map +0 -1
- package/dist/services/loop/defaultLauncher.d.mts.map +0 -1
- package/dist/services/loop/defaultLauncher.mjs +0 -2
- package/dist/services/loop/defaultLauncher.mjs.map +0 -1
- package/dist/types/constants.cjs +0 -2
- package/dist/types/constants.cjs.map +0 -1
- package/dist/types/constants.mjs +0 -2
- package/dist/types/constants.mjs.map +0 -1
|
@@ -1,47 +1,7 @@
|
|
|
1
|
+
import { LoopLauncherClient, LoopLauncherRegistration, RegisterLoopLauncherOptions } from "../../types/loop.cjs";
|
|
1
2
|
//#region src/services/loop/launcher.d.ts
|
|
2
|
-
interface LoopLaunchRequest {
|
|
3
|
-
readonly instanceId: string;
|
|
4
|
-
readonly signal: AbortSignal;
|
|
5
|
-
}
|
|
6
|
-
interface StoppableLoop {
|
|
7
|
-
readonly instanceId: string;
|
|
8
|
-
readonly label?: string;
|
|
9
|
-
readonly detail?: string;
|
|
10
|
-
stop(reason?: string): void | Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
interface LoopLauncherSummary {
|
|
13
|
-
readonly id: string;
|
|
14
|
-
readonly source: string;
|
|
15
|
-
readonly label: string;
|
|
16
|
-
readonly description?: string;
|
|
17
|
-
}
|
|
18
|
-
interface LoopInstanceSnapshot {
|
|
19
|
-
readonly instanceId: string;
|
|
20
|
-
readonly launcherId: string;
|
|
21
|
-
readonly launcherLabel: string;
|
|
22
|
-
readonly label?: string;
|
|
23
|
-
readonly detail?: string;
|
|
24
|
-
readonly state: 'starting' | 'running' | 'stopping';
|
|
25
|
-
readonly startedAt?: string;
|
|
26
|
-
}
|
|
27
|
-
interface LoopLauncherRegistration {
|
|
28
|
-
dispose(reason?: string): Promise<void>;
|
|
29
|
-
}
|
|
30
|
-
interface LoopLauncherClient {
|
|
31
|
-
listLaunchers(): readonly LoopLauncherSummary[];
|
|
32
|
-
listInstances(): readonly LoopInstanceSnapshot[];
|
|
33
|
-
subscribe(listener: () => void): () => void;
|
|
34
|
-
launch(launcherId: string, options?: {
|
|
35
|
-
instanceId?: string;
|
|
36
|
-
}): Promise<LoopInstanceSnapshot | undefined>;
|
|
37
|
-
stop(instanceId: string, reason?: string): Promise<boolean>;
|
|
38
|
-
stopAll(reason?: string): Promise<void>;
|
|
39
|
-
}
|
|
40
|
-
interface RegisterLoopLauncherOptions extends LoopLauncherSummary {
|
|
41
|
-
launch(request: LoopLaunchRequest): Promise<StoppableLoop | undefined>;
|
|
42
|
-
}
|
|
43
3
|
declare function registerLoopLauncher(sessionId: string, options: RegisterLoopLauncherOptions): LoopLauncherRegistration;
|
|
44
4
|
declare function createLoopLauncherClient(sessionId: () => string | undefined): LoopLauncherClient;
|
|
45
5
|
//#endregion
|
|
46
|
-
export {
|
|
6
|
+
export { createLoopLauncherClient, registerLoopLauncher };
|
|
47
7
|
//# sourceMappingURL=launcher.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"launcher.d.cts","names":[],"sources":["../../../src/services/loop/launcher.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"launcher.d.cts","names":[],"sources":["../../../src/services/loop/launcher.ts"],"mappings":";;iBAuGgB,qBACd,mBACA,SAAS,8BACR;iBA0Ba,yBAAyB,sCAAsC"}
|
|
@@ -1,47 +1,7 @@
|
|
|
1
|
+
import { LoopLauncherClient, LoopLauncherRegistration, RegisterLoopLauncherOptions } from "../../types/loop.mjs";
|
|
1
2
|
//#region src/services/loop/launcher.d.ts
|
|
2
|
-
interface LoopLaunchRequest {
|
|
3
|
-
readonly instanceId: string;
|
|
4
|
-
readonly signal: AbortSignal;
|
|
5
|
-
}
|
|
6
|
-
interface StoppableLoop {
|
|
7
|
-
readonly instanceId: string;
|
|
8
|
-
readonly label?: string;
|
|
9
|
-
readonly detail?: string;
|
|
10
|
-
stop(reason?: string): void | Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
interface LoopLauncherSummary {
|
|
13
|
-
readonly id: string;
|
|
14
|
-
readonly source: string;
|
|
15
|
-
readonly label: string;
|
|
16
|
-
readonly description?: string;
|
|
17
|
-
}
|
|
18
|
-
interface LoopInstanceSnapshot {
|
|
19
|
-
readonly instanceId: string;
|
|
20
|
-
readonly launcherId: string;
|
|
21
|
-
readonly launcherLabel: string;
|
|
22
|
-
readonly label?: string;
|
|
23
|
-
readonly detail?: string;
|
|
24
|
-
readonly state: 'starting' | 'running' | 'stopping';
|
|
25
|
-
readonly startedAt?: string;
|
|
26
|
-
}
|
|
27
|
-
interface LoopLauncherRegistration {
|
|
28
|
-
dispose(reason?: string): Promise<void>;
|
|
29
|
-
}
|
|
30
|
-
interface LoopLauncherClient {
|
|
31
|
-
listLaunchers(): readonly LoopLauncherSummary[];
|
|
32
|
-
listInstances(): readonly LoopInstanceSnapshot[];
|
|
33
|
-
subscribe(listener: () => void): () => void;
|
|
34
|
-
launch(launcherId: string, options?: {
|
|
35
|
-
instanceId?: string;
|
|
36
|
-
}): Promise<LoopInstanceSnapshot | undefined>;
|
|
37
|
-
stop(instanceId: string, reason?: string): Promise<boolean>;
|
|
38
|
-
stopAll(reason?: string): Promise<void>;
|
|
39
|
-
}
|
|
40
|
-
interface RegisterLoopLauncherOptions extends LoopLauncherSummary {
|
|
41
|
-
launch(request: LoopLaunchRequest): Promise<StoppableLoop | undefined>;
|
|
42
|
-
}
|
|
43
3
|
declare function registerLoopLauncher(sessionId: string, options: RegisterLoopLauncherOptions): LoopLauncherRegistration;
|
|
44
4
|
declare function createLoopLauncherClient(sessionId: () => string | undefined): LoopLauncherClient;
|
|
45
5
|
//#endregion
|
|
46
|
-
export {
|
|
6
|
+
export { createLoopLauncherClient, registerLoopLauncher };
|
|
47
7
|
//# sourceMappingURL=launcher.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"launcher.d.mts","names":[],"sources":["../../../src/services/loop/launcher.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"launcher.d.mts","names":[],"sources":["../../../src/services/loop/launcher.ts"],"mappings":";;iBAuGgB,qBACd,mBACA,SAAS,8BACR;iBA0Ba,yBAAyB,sCAAsC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
const e=Symbol.for(`@agimon-ai/doompi-loop.launchers.v1`),t=`loop session id`,n=`loop launcher id`,r=`loop instance id`;function i(){let t=globalThis,n=t[e];if(n)return n;let r=new Map;return t[e]=r,r}function a(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 o(e,n){let r=a(e,t),o=i().get(r);if(o||!n)return o;let s={launchers:new Map,instances:new Map,listeners:new Set};return i().set(r,s),s}function s(e){for(let t of e.listeners)t()}function c(e){return{instanceId:e.instanceId,launcherId:e.launcher.options.id,launcherLabel:e.launcher.options.label,...e.handle?.label?{label:e.handle.label}:{},...e.handle?.detail?{detail:e.handle.detail}:{},state:e.state,...e.startedAt?{startedAt:e.startedAt}:{}}}async function l(e,t,n){if(e.instances.get(t.instanceId)===t){t.state=`stopping`,t.abortController.abort(n),s(e);try{await t.handle?.stop(n)}finally{e.instances.get(t.instanceId)===t&&e.instances.delete(t.instanceId),s(e)}}}function u(e,t){t.launchers.size||t.instances.size||t.listeners.size||i().get(e)===t&&i().delete(e)}function d(e,r){let i=a(e,t),c=a(r.id,n),d=o(i,!0);if(d.launchers.has(c))throw Error(`Loop launcher '${c}' is already registered for session '${i}'.`);let f={token:Symbol(c),options:{...r,id:c}};d.launchers.set(c,f),s(d);let p=!1;return{async dispose(e=`Loop launcher disposed.`){if(p)return;p=!0;let t=o(i,!1);if(!t||t.launchers.get(c)?.token!==f.token)return;t.launchers.delete(c);let n=[...t.instances.values()].filter(e=>e.launcher.token===f.token);await Promise.allSettled(n.map(n=>l(t,n,e))),s(t),u(i,t)}}}function f(e){let i=n=>{let r=e();if(!r)return;let i=a(r,t),s=o(i,n);return s?{key:i,session:s}:void 0};return{listLaunchers(){let e=i(!1)?.session;return e?[...e.launchers.values()].map(({options: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(){let e=i(!1)?.session;return e?[...e.instances.values()].map(c).sort((e,t)=>e.instanceId.localeCompare(t.instanceId)):[]},subscribe(e){let t=i(!0);if(!t)return()=>void 0;t.session.listeners.add(e);let n=!1;return()=>{n||(n=!0,t.session.listeners.delete(e),u(t.key,t.session))}},async launch(e,t){let o=i(!0);if(!o)throw Error(`The session-bound loop launcher registry is unavailable.`);let l=a(e,n),u=o.session.launchers.get(l);if(!u)throw Error(`Loop launcher '${l}' is unavailable.`);let d=a(t?.instanceId??globalThis.crypto.randomUUID(),r);if(o.session.instances.has(d))throw Error(`Loop instance '${d}' already exists.`);let f={instanceId:d,launcher:u,abortController:new AbortController,state:`starting`};o.session.instances.set(d,f),s(o.session);try{let e=await u.options.launch({instanceId:d,signal:f.abortController.signal}),t=o.session.instances.get(d)===f&&!f.abortController.signal.aborted;if(!e){o.session.instances.get(d)===f&&o.session.instances.delete(d),s(o.session);return}if(!t||e.instanceId!==d){if(await e.stop(t?`Loop launcher returned a mismatched instance id.`:`Loop launch was cancelled.`),o.session.instances.get(d)===f&&o.session.instances.delete(d),s(o.session),t)throw Error(`Loop launcher '${l}' returned a mismatched instance id.`);return}return f.handle=e,f.state=`running`,f.startedAt=new Date().toISOString(),s(o.session),c(f)}catch(e){let t=f.abortController.signal.aborted;if(o.session.instances.get(d)===f&&o.session.instances.delete(d),s(o.session),t)return;throw e}},async stop(e,t){let n=i(!1)?.session;if(!n)return!1;let o=n.instances.get(a(e,r));return o?(await l(n,o,t),!0):!1},async stopAll(e){let t=i(!1)?.session;t&&await Promise.allSettled([...t.instances.values()].map(n=>l(t,n,e)))}}}export{f as createLoopLauncherClient,d as registerLoopLauncher};
|
|
2
2
|
//# sourceMappingURL=launcher.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"launcher.mjs","names":[],"sources":["../../../src/services/loop/launcher.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\nconst REGISTRY_KEY = Symbol.for('@agimon-ai/doompi-loop.launchers.v1');\nconst MAX_ID_LENGTH = 256;\nconst SESSION_ID_LABEL = 'loop session id';\nconst LAUNCHER_ID_LABEL = 'loop launcher id';\nconst INSTANCE_ID_LABEL = 'loop instance id';\n\nexport interface LoopLaunchRequest {\n readonly instanceId: string;\n readonly signal: AbortSignal;\n}\n\nexport interface StoppableLoop {\n readonly instanceId: string;\n readonly label?: string;\n readonly detail?: string;\n stop(reason?: string): void | Promise<void>;\n}\n\nexport interface LoopLauncherSummary {\n readonly id: string;\n readonly source: string;\n readonly label: string;\n readonly description?: string;\n}\n\nexport interface LoopInstanceSnapshot {\n readonly instanceId: string;\n readonly launcherId: string;\n readonly launcherLabel: string;\n readonly label?: string;\n readonly detail?: string;\n readonly state: 'starting' | 'running' | 'stopping';\n readonly startedAt?: string;\n}\n\nexport interface LoopLauncherRegistration {\n dispose(reason?: string): Promise<void>;\n}\n\nexport interface LoopLauncherClient {\n listLaunchers(): readonly LoopLauncherSummary[];\n listInstances(): readonly LoopInstanceSnapshot[];\n subscribe(listener: () => void): () => void;\n launch(launcherId: string, options?: { instanceId?: string }): Promise<LoopInstanceSnapshot | undefined>;\n stop(instanceId: string, reason?: string): Promise<boolean>;\n stopAll(reason?: string): Promise<void>;\n}\n\nexport interface RegisterLoopLauncherOptions extends LoopLauncherSummary {\n launch(request: LoopLaunchRequest): Promise<StoppableLoop | undefined>;\n}\n\ninterface LauncherEntry {\n readonly token: symbol;\n readonly options: RegisterLoopLauncherOptions;\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\ninterface SessionRegistry {\n readonly launchers: Map<string, LauncherEntry>;\n readonly instances: Map<string, InstanceEntry>;\n readonly listeners: Set<() => void>;\n}\n\ntype LoopRegistry = Map<string, SessionRegistry>;\n\nfunction registry(): LoopRegistry {\n const root = globalThis as typeof globalThis & { [REGISTRY_KEY]?: LoopRegistry };\n return (root[REGISTRY_KEY] ??= new Map());\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 getSession(sessionId: string, create: boolean): SessionRegistry | undefined {\n const key = validId(sessionId, SESSION_ID_LABEL);\n const existing = registry().get(key);\n if (existing || !create) return existing;\n const created: SessionRegistry = { launchers: new Map(), instances: new Map(), listeners: new Set() };\n registry().set(key, created);\n return created;\n}\n\nfunction notify(session: SessionRegistry): void {\n for (const listener of session.listeners) listener();\n}\n\nfunction snapshot(entry: InstanceEntry): LoopInstanceSnapshot {\n return {\n instanceId: entry.instanceId,\n launcherId: entry.launcher.options.id,\n launcherLabel: entry.launcher.options.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\nasync function stopEntry(session: SessionRegistry, entry: InstanceEntry, reason?: string): Promise<void> {\n if (session.instances.get(entry.instanceId) !== entry) return;\n entry.state = 'stopping';\n entry.abortController.abort(reason);\n notify(session);\n try {\n await entry.handle?.stop(reason);\n } finally {\n if (session.instances.get(entry.instanceId) === entry) session.instances.delete(entry.instanceId);\n notify(session);\n }\n}\n\nfunction cleanSession(sessionId: string, session: SessionRegistry): void {\n if (session.launchers.size || session.instances.size || session.listeners.size) return;\n if (registry().get(sessionId) === session) registry().delete(sessionId);\n}\n\nexport function registerLoopLauncher(\n sessionId: string,\n options: RegisterLoopLauncherOptions,\n): LoopLauncherRegistration {\n const sessionKey = validId(sessionId, SESSION_ID_LABEL);\n const launcherId = validId(options.id, LAUNCHER_ID_LABEL);\n const session = getSession(sessionKey, true) as SessionRegistry;\n if (session.launchers.has(launcherId)) {\n throw new Error(`Loop launcher '${launcherId}' is already registered for session '${sessionKey}'.`);\n }\n const entry: LauncherEntry = { token: Symbol(launcherId), options: { ...options, id: launcherId } };\n session.launchers.set(launcherId, entry);\n notify(session);\n let disposed = false;\n return {\n async dispose(reason = 'Loop launcher disposed.'): Promise<void> {\n if (disposed) return;\n disposed = true;\n const current = getSession(sessionKey, false);\n if (!current || current.launchers.get(launcherId)?.token !== entry.token) return;\n current.launchers.delete(launcherId);\n const owned = [...current.instances.values()].filter((instance) => instance.launcher.token === entry.token);\n await Promise.allSettled(owned.map((instance) => stopEntry(current, instance, reason)));\n notify(current);\n cleanSession(sessionKey, current);\n },\n };\n}\n\nexport function createLoopLauncherClient(sessionId: () => string | undefined): LoopLauncherClient {\n const current = (create: boolean): { key: string; session: SessionRegistry } | undefined => {\n const value = sessionId();\n if (!value) return undefined;\n const key = validId(value, SESSION_ID_LABEL);\n const session = getSession(key, create);\n return session ? { key, session } : undefined;\n };\n return {\n listLaunchers() {\n const session = current(false)?.session;\n if (!session) return [];\n return [...session.launchers.values()]\n .map(({ options }) => ({\n id: options.id,\n source: options.source,\n label: options.label,\n ...(options.description ? { description: options.description } : {}),\n }))\n .sort((left, right) => left.label.localeCompare(right.label) || left.id.localeCompare(right.id));\n },\n listInstances() {\n const session = current(false)?.session;\n return session\n ? [...session.instances.values()]\n .map(snapshot)\n .sort((left, right) => left.instanceId.localeCompare(right.instanceId))\n : [];\n },\n subscribe(listener) {\n const target = current(true);\n if (!target) return () => undefined;\n target.session.listeners.add(listener);\n let disposed = false;\n return () => {\n if (disposed) return;\n disposed = true;\n target.session.listeners.delete(listener);\n cleanSession(target.key, target.session);\n };\n },\n async launch(launcherId, options) {\n const target = current(true);\n if (!target) throw new Error('The session-bound loop launcher registry is unavailable.');\n const normalizedLauncherId = validId(launcherId, LAUNCHER_ID_LABEL);\n const launcher = target.session.launchers.get(normalizedLauncherId);\n if (!launcher) throw new Error(`Loop launcher '${normalizedLauncherId}' is unavailable.`);\n const instanceId = validId(options?.instanceId ?? randomUUID(), INSTANCE_ID_LABEL);\n if (target.session.instances.has(instanceId)) throw new Error(`Loop instance '${instanceId}' already exists.`);\n const entry: InstanceEntry = { instanceId, launcher, abortController: new AbortController(), state: 'starting' };\n target.session.instances.set(instanceId, entry);\n notify(target.session);\n try {\n const handle = await launcher.options.launch({ instanceId, signal: entry.abortController.signal });\n const active = target.session.instances.get(instanceId) === entry && !entry.abortController.signal.aborted;\n if (!handle) {\n if (target.session.instances.get(instanceId) === entry) target.session.instances.delete(instanceId);\n notify(target.session);\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 (target.session.instances.get(instanceId) === entry) target.session.instances.delete(instanceId);\n notify(target.session);\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 = new Date().toISOString();\n notify(target.session);\n return snapshot(entry);\n } catch (error) {\n const cancelled = entry.abortController.signal.aborted;\n if (target.session.instances.get(instanceId) === entry) target.session.instances.delete(instanceId);\n notify(target.session);\n if (cancelled) return undefined;\n throw error;\n }\n },\n async stop(instanceId, reason) {\n const session = current(false)?.session;\n if (!session) return false;\n const entry = session.instances.get(validId(instanceId, INSTANCE_ID_LABEL));\n if (!entry) return false;\n await stopEntry(session, entry, reason);\n return true;\n },\n async stopAll(reason) {\n const session = current(false)?.session;\n if (!session) return;\n await Promise.allSettled([...session.instances.values()].map((entry) => stopEntry(session, entry, reason)));\n },\n };\n}\n"],"mappings":"yCAEA,MAAM,EAAe,OAAO,IAAI,qCAAqC,EAE/D,EAAmB,kBACnB,EAAoB,mBACpB,EAAoB,mBAsE1B,SAAS,GAAyB,CAChC,IAAM,EAAO,WACb,MAAQ,GAAK,KAAkB,IAAI,GACrC,CAEA,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,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,EAAS,EAAO,CAAM,EAC/B,IAFY,EAGrB,EACA,MAAM,QAAQ,EAAQ,CACpB,IAAM,EAAU,EAAQ,EAAK,CAAC,EAAE,QAC3B,GACL,MAAM,QAAQ,WAAW,CAAC,GAAG,EAAQ,UAAU,OAAO,CAAC,CAAC,CAAC,IAAK,GAAU,EAAU,EAAS,EAAO,CAAM,CAAC,CAAC,CAC5G,CACF,CACF"}
|
|
1
|
+
{"version":3,"file":"launcher.mjs","names":[],"sources":["../../../src/services/loop/launcher.ts"],"sourcesContent":["import type {\n LoopInstanceSnapshot,\n LoopLauncherClient,\n LoopLauncherRegistration,\n RegisterLoopLauncherOptions,\n StoppableLoop,\n} from '../../types/loop.ts';\n\nconst REGISTRY_KEY = Symbol.for('@agimon-ai/doompi-loop.launchers.v1');\nconst MAX_ID_LENGTH = 256;\nconst SESSION_ID_LABEL = 'loop session id';\nconst LAUNCHER_ID_LABEL = 'loop launcher id';\nconst INSTANCE_ID_LABEL = 'loop instance id';\n\ninterface LauncherEntry {\n readonly token: symbol;\n readonly options: RegisterLoopLauncherOptions;\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\ninterface SessionRegistry {\n readonly launchers: Map<string, LauncherEntry>;\n readonly instances: Map<string, InstanceEntry>;\n readonly listeners: Set<() => void>;\n}\n\ntype LoopRegistry = Map<string, SessionRegistry>;\n\nfunction registry(): LoopRegistry {\n const root = globalThis as typeof globalThis & { [REGISTRY_KEY]?: LoopRegistry };\n const existing = root[REGISTRY_KEY];\n if (existing) return existing;\n\n const created: LoopRegistry = new Map();\n root[REGISTRY_KEY] = created;\n return created;\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 getSession(sessionId: string, create: boolean): SessionRegistry | undefined {\n const key = validId(sessionId, SESSION_ID_LABEL);\n const existing = registry().get(key);\n if (existing || !create) return existing;\n const created: SessionRegistry = { launchers: new Map(), instances: new Map(), listeners: new Set() };\n registry().set(key, created);\n return created;\n}\n\nfunction notify(session: SessionRegistry): void {\n for (const listener of session.listeners) listener();\n}\n\nfunction snapshot(entry: InstanceEntry): LoopInstanceSnapshot {\n return {\n instanceId: entry.instanceId,\n launcherId: entry.launcher.options.id,\n launcherLabel: entry.launcher.options.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\nasync function stopEntry(session: SessionRegistry, entry: InstanceEntry, reason?: string): Promise<void> {\n if (session.instances.get(entry.instanceId) !== entry) return;\n entry.state = 'stopping';\n entry.abortController.abort(reason);\n notify(session);\n try {\n await entry.handle?.stop(reason);\n } finally {\n if (session.instances.get(entry.instanceId) === entry) session.instances.delete(entry.instanceId);\n notify(session);\n }\n}\n\nfunction cleanSession(sessionId: string, session: SessionRegistry): void {\n if (session.launchers.size || session.instances.size || session.listeners.size) return;\n if (registry().get(sessionId) === session) registry().delete(sessionId);\n}\n\nexport function registerLoopLauncher(\n sessionId: string,\n options: RegisterLoopLauncherOptions,\n): LoopLauncherRegistration {\n const sessionKey = validId(sessionId, SESSION_ID_LABEL);\n const launcherId = validId(options.id, LAUNCHER_ID_LABEL);\n const session = getSession(sessionKey, true) as SessionRegistry;\n if (session.launchers.has(launcherId)) {\n throw new Error(`Loop launcher '${launcherId}' is already registered for session '${sessionKey}'.`);\n }\n const entry: LauncherEntry = { token: Symbol(launcherId), options: { ...options, id: launcherId } };\n session.launchers.set(launcherId, entry);\n notify(session);\n let disposed = false;\n return {\n async dispose(reason = 'Loop launcher disposed.'): Promise<void> {\n if (disposed) return;\n disposed = true;\n const current = getSession(sessionKey, false);\n if (!current || current.launchers.get(launcherId)?.token !== entry.token) return;\n current.launchers.delete(launcherId);\n const owned = [...current.instances.values()].filter((instance) => instance.launcher.token === entry.token);\n await Promise.allSettled(owned.map((instance) => stopEntry(current, instance, reason)));\n notify(current);\n cleanSession(sessionKey, current);\n },\n };\n}\n\nexport function createLoopLauncherClient(sessionId: () => string | undefined): LoopLauncherClient {\n const current = (create: boolean): { key: string; session: SessionRegistry } | undefined => {\n const value = sessionId();\n if (!value) return undefined;\n const key = validId(value, SESSION_ID_LABEL);\n const session = getSession(key, create);\n return session ? { key, session } : undefined;\n };\n return {\n listLaunchers() {\n const session = current(false)?.session;\n if (!session) return [];\n return [...session.launchers.values()]\n .map(({ options }) => ({\n id: options.id,\n source: options.source,\n label: options.label,\n ...(options.description ? { description: options.description } : {}),\n }))\n .sort((left, right) => left.label.localeCompare(right.label) || left.id.localeCompare(right.id));\n },\n listInstances() {\n const session = current(false)?.session;\n return session\n ? [...session.instances.values()]\n .map(snapshot)\n .sort((left, right) => left.instanceId.localeCompare(right.instanceId))\n : [];\n },\n subscribe(listener) {\n const target = current(true);\n if (!target) return () => undefined;\n target.session.listeners.add(listener);\n let disposed = false;\n return () => {\n if (disposed) return;\n disposed = true;\n target.session.listeners.delete(listener);\n cleanSession(target.key, target.session);\n };\n },\n async launch(launcherId, options) {\n const target = current(true);\n if (!target) throw new Error('The session-bound loop launcher registry is unavailable.');\n const normalizedLauncherId = validId(launcherId, LAUNCHER_ID_LABEL);\n const launcher = target.session.launchers.get(normalizedLauncherId);\n if (!launcher) throw new Error(`Loop launcher '${normalizedLauncherId}' is unavailable.`);\n const instanceId = validId(options?.instanceId ?? globalThis.crypto.randomUUID(), INSTANCE_ID_LABEL);\n if (target.session.instances.has(instanceId)) throw new Error(`Loop instance '${instanceId}' already exists.`);\n const entry: InstanceEntry = { instanceId, launcher, abortController: new AbortController(), state: 'starting' };\n target.session.instances.set(instanceId, entry);\n notify(target.session);\n try {\n const handle = await launcher.options.launch({ instanceId, signal: entry.abortController.signal });\n const active = target.session.instances.get(instanceId) === entry && !entry.abortController.signal.aborted;\n if (!handle) {\n if (target.session.instances.get(instanceId) === entry) target.session.instances.delete(instanceId);\n notify(target.session);\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 (target.session.instances.get(instanceId) === entry) target.session.instances.delete(instanceId);\n notify(target.session);\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 = new Date().toISOString();\n notify(target.session);\n return snapshot(entry);\n } catch (error) {\n const cancelled = entry.abortController.signal.aborted;\n if (target.session.instances.get(instanceId) === entry) target.session.instances.delete(instanceId);\n notify(target.session);\n if (cancelled) return undefined;\n throw error;\n }\n },\n async stop(instanceId, reason) {\n const session = current(false)?.session;\n if (!session) return false;\n const entry = session.instances.get(validId(instanceId, INSTANCE_ID_LABEL));\n if (!entry) return false;\n await stopEntry(session, entry, reason);\n return true;\n },\n async stopAll(reason) {\n const session = current(false)?.session;\n if (!session) return;\n await Promise.allSettled([...session.instances.values()].map((entry) => stopEntry(session, entry, reason)));\n },\n };\n}\n"],"mappings":"AAQA,MAAM,EAAe,OAAO,IAAI,qCAAqC,EAE/D,EAAmB,kBACnB,EAAoB,mBACpB,EAAoB,mBAwB1B,SAAS,GAAyB,CAChC,IAAM,EAAO,WACP,EAAW,EAAK,GACtB,GAAI,EAAU,OAAO,EAErB,IAAM,EAAwB,IAAI,IAElC,MADA,GAAK,GAAgB,EACd,CACT,CAEA,SAAS,EAAQ,EAAe,EAAuB,CACrD,IAAM,EAAa,EAAM,KAAK,EAC1B,EAAa,GACjB,IAAK,IAAM,KAAa,EAAY,CAClC,IAAM,EAAO,EAAU,YAAY,CAAC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,CAAC,EAAS,MAAO,GACrB,IAAM,EAAQ,EAAQ,UAAU,IAAI,EAAQ,EAAY,CAAiB,CAAC,EAG1E,OAFK,GACL,MAAM,EAAU,EAAS,EAAO,CAAM,EAC/B,IAFY,EAGrB,EACA,MAAM,QAAQ,EAAQ,CACpB,IAAM,EAAU,EAAQ,EAAK,CAAC,EAAE,QAC3B,GACL,MAAM,QAAQ,WAAW,CAAC,GAAG,EAAQ,UAAU,OAAO,CAAC,CAAC,CAAC,IAAK,GAAU,EAAU,EAAS,EAAO,CAAM,CAAC,CAAC,CAC5G,CACF,CACF"}
|
|
@@ -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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loopListOverlay.cjs","names":["DoomOverlay","matchesKey","DOOM_OVERLAY_ACCENT","truncateToWidth","DOOM_FULLSCREEN_UI_OPTIONS"],"sources":["../../src/tui/loopListOverlay.ts"],"sourcesContent":["import {\n DOOM_FULLSCREEN_UI_OPTIONS,\n DOOM_OVERLAY_ACCENT,\n DoomOverlay,\n type DoomOverlayChrome,\n type DoomOverlayTui,\n} from '@agimon-ai/doompi-ui/components/doomOverlay';\nimport type { ExtensionContext, Theme } from '@earendil-works/pi-coding-agent';\nimport { matchesKey, truncateToWidth } from '@earendil-works/pi-tui';\nimport type { LoopInstanceSnapshot, LoopLauncherClient } from '../
|
|
1
|
+
{"version":3,"file":"loopListOverlay.cjs","names":["DoomOverlay","matchesKey","DOOM_NAVIGATION_KEYS","DOOM_OVERLAY_ACCENT","truncateToWidth","DOOM_FULLSCREEN_UI_OPTIONS"],"sources":["../../src/tui/loopListOverlay.ts"],"sourcesContent":["import {\n DOOM_FULLSCREEN_UI_OPTIONS,\n DOOM_NAVIGATION_KEYS,\n DOOM_OVERLAY_ACCENT,\n DoomOverlay,\n type DoomOverlayChrome,\n type DoomOverlayTui,\n} from '@agimon-ai/doompi-ui/components/doomOverlay';\nimport type { ExtensionContext, Theme } from '@earendil-works/pi-coding-agent';\nimport { matchesKey, truncateToWidth } from '@earendil-works/pi-tui';\nimport type { LoopInstanceSnapshot, LoopLauncherClient } from '../types/loop.ts';\n\nconst EMPTY_MESSAGE = 'No loop instances are active in this session.';\nconst STOP_SCOPE_MESSAGE = 'Stopping a loop does not cancel detached work already launched.';\nconst STOP_REASON = 'Stopped from the loop list.';\n\nexport class LoopListOverlay extends DoomOverlay {\n private readonly unsubscribe: () => void;\n private instances: readonly LoopInstanceSnapshot[];\n private selected = 0;\n\n constructor(\n tui: DoomOverlayTui,\n theme: Theme,\n private readonly client: LoopLauncherClient,\n private readonly done: (result: undefined) => void,\n ) {\n super(tui, theme);\n this.instances = client.listInstances();\n this.unsubscribe = client.subscribe(() => this.refresh());\n }\n\n dispose(): void {\n this.unsubscribe();\n }\n\n handleInput(data: string): void {\n if (matchesKey(data, 'escape') || matchesKey(data, 'ctrl+c') || data === 'q') {\n this.done(undefined);\n return;\n }\n if (matchesKey(data, 'up') || data === 'k') {\n this.move(-1);\n return;\n }\n if (matchesKey(data, 'down') || data === 'j') {\n this.move(1);\n return;\n }\n if (data === 'x') {\n const instance = this.instances[this.selected];\n if (instance) void this.client.stop(instance.instanceId, STOP_REASON);\n }\n }\n\n protected getChrome(): DoomOverlayChrome {\n return {\n title: 'LOOPS',\n breadcrumb: 'SPC › l / loops › l / list',\n headerRight: `${this.instances.length} active`,\n footer: `${DOOM_NAVIGATION_KEYS.list} move · x stop · esc close · launched detached work continues`,\n footerHints: [\n [DOOM_NAVIGATION_KEYS.list, 'move'],\n ['x', 'stop scheduling'],\n ['esc', 'close'],\n ],\n accent: DOOM_OVERLAY_ACCENT,\n };\n }\n\n protected renderBody(width: number): string[] {\n const stopScope = this.theme.fg('dim', truncateToWidth(STOP_SCOPE_MESSAGE, width));\n if (!this.instances.length) return [this.theme.fg('dim', EMPTY_MESSAGE), '', stopScope];\n return [\n stopScope,\n '',\n ...this.instances.flatMap((instance, index) => {\n const marker = index === this.selected ? this.theme.fg('accent', '▸') : ' ';\n const name = instance.label ?? instance.launcherLabel;\n const state = this.theme.fg(instance.state === 'running' ? 'success' : 'warning', instance.state);\n const line = truncateToWidth(`${marker} ${name} · ${state}`, width);\n const detail = instance.detail ?? instance.instanceId;\n return [line, ` ${this.theme.fg('dim', truncateToWidth(detail, Math.max(0, width - 4)))}`];\n }),\n ];\n }\n\n private refresh(): void {\n this.instances = this.client.listInstances();\n this.selected = Math.min(this.selected, Math.max(0, this.instances.length - 1));\n this.invalidate();\n }\n\n private move(delta: number): void {\n if (!this.instances.length) return;\n this.selected = Math.max(0, Math.min(this.selected + delta, this.instances.length - 1));\n this.invalidate();\n }\n}\n\nexport async function openLoopListOverlay(ctx: ExtensionContext, client: LoopLauncherClient): Promise<void> {\n if (ctx.mode !== 'tui') {\n const instances = client.listInstances();\n const labels = instances.map((instance) => `${instance.label ?? instance.launcherLabel} (${instance.instanceId})`);\n const selected = await ctx.ui.select('Stop loop scheduling', labels);\n const instance = instances[labels.indexOf(selected ?? '')];\n if (instance) await client.stop(instance.instanceId, STOP_REASON);\n return;\n }\n await ctx.ui.custom<undefined>(\n (tui, theme, _keybindings, done) => new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Q,GAAY,EAAE,GACpD,GAAU,MAAM,EAAO,KAAK,EAAS,WAAY,CAAW,EAChE,MACF,CACA,MAAM,EAAI,GAAG,QACV,EAAK,EAAO,EAAc,IAAS,IAAI,EAAgB,EAAK,EAAO,EAAQ,CAAI,EAChFC,EAAAA,0BACF,CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{DOOM_FULLSCREEN_UI_OPTIONS as e,
|
|
1
|
+
import{DOOM_FULLSCREEN_UI_OPTIONS as e,DOOM_NAVIGATION_KEYS as t,DOOM_OVERLAY_ACCENT as n,DoomOverlay as r}from"@agimon-ai/doompi-ui/components/doomOverlay";import{matchesKey as i,truncateToWidth as a}from"@earendil-works/pi-tui";const o=`Stopped from the loop list.`;var s=class extends r{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(i(e,`escape`)||i(e,`ctrl+c`)||e===`q`){this.done(void 0);return}if(i(e,`up`)||e===`k`){this.move(-1);return}if(i(e,`down`)||e===`j`){this.move(1);return}if(e===`x`){let e=this.instances[this.selected];e&&this.client.stop(e.instanceId,o)}}getChrome(){return{title:`LOOPS`,breadcrumb:`SPC › l / loops › l / list`,headerRight:`${this.instances.length} active`,footer:`${t.list} move · x stop · esc close · launched detached work continues`,footerHints:[[t.list,`move`],[`x`,`stop scheduling`],[`esc`,`close`]],accent:n}}renderBody(e){let t=this.theme.fg(`dim`,a(`Stopping a loop does not cancel detached work already launched.`,e));return this.instances.length?[t,``,...this.instances.flatMap((t,n)=>{let r=n===this.selected?this.theme.fg(`accent`,`▸`):` `,i=t.label??t.launcherLabel,o=this.theme.fg(t.state===`running`?`success`:`warning`,t.state),s=a(`${r} ${i} · ${o}`,e),c=t.detail??t.instanceId;return[s,` ${this.theme.fg(`dim`,a(c,Math.max(0,e-4)))}`]})]:[this.theme.fg(`dim`,`No loop instances are active in this session.`),``,t]}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 c(t,n){if(t.mode!==`tui`){let e=n.listInstances(),r=e.map(e=>`${e.label??e.launcherLabel} (${e.instanceId})`),i=await t.ui.select(`Stop loop scheduling`,r),a=e[r.indexOf(i??``)];a&&await n.stop(a.instanceId,o);return}await t.ui.custom((e,t,r,i)=>new s(e,t,n,i),e)}export{s as LoopListOverlay,c as openLoopListOverlay};
|
|
2
2
|
//# sourceMappingURL=loopListOverlay.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loopListOverlay.mjs","names":[],"sources":["../../src/tui/loopListOverlay.ts"],"sourcesContent":["import {\n DOOM_FULLSCREEN_UI_OPTIONS,\n DOOM_OVERLAY_ACCENT,\n DoomOverlay,\n type DoomOverlayChrome,\n type DoomOverlayTui,\n} from '@agimon-ai/doompi-ui/components/doomOverlay';\nimport type { ExtensionContext, Theme } from '@earendil-works/pi-coding-agent';\nimport { matchesKey, truncateToWidth } from '@earendil-works/pi-tui';\nimport type { LoopInstanceSnapshot, LoopLauncherClient } from '../
|
|
1
|
+
{"version":3,"file":"loopListOverlay.mjs","names":[],"sources":["../../src/tui/loopListOverlay.ts"],"sourcesContent":["import {\n DOOM_FULLSCREEN_UI_OPTIONS,\n DOOM_NAVIGATION_KEYS,\n DOOM_OVERLAY_ACCENT,\n DoomOverlay,\n type DoomOverlayChrome,\n type DoomOverlayTui,\n} from '@agimon-ai/doompi-ui/components/doomOverlay';\nimport type { ExtensionContext, Theme } from '@earendil-works/pi-coding-agent';\nimport { matchesKey, truncateToWidth } from '@earendil-works/pi-tui';\nimport type { LoopInstanceSnapshot, LoopLauncherClient } from '../types/loop.ts';\n\nconst EMPTY_MESSAGE = 'No loop instances are active in this session.';\nconst STOP_SCOPE_MESSAGE = 'Stopping a loop does not cancel detached work already launched.';\nconst STOP_REASON = 'Stopped from the loop list.';\n\nexport class LoopListOverlay extends DoomOverlay {\n private readonly unsubscribe: () => void;\n private instances: readonly LoopInstanceSnapshot[];\n private selected = 0;\n\n constructor(\n tui: DoomOverlayTui,\n theme: Theme,\n private readonly client: LoopLauncherClient,\n private readonly done: (result: undefined) => void,\n ) {\n super(tui, theme);\n this.instances = client.listInstances();\n this.unsubscribe = client.subscribe(() => this.refresh());\n }\n\n dispose(): void {\n this.unsubscribe();\n }\n\n handleInput(data: string): void {\n if (matchesKey(data, 'escape') || matchesKey(data, 'ctrl+c') || data === 'q') {\n this.done(undefined);\n return;\n }\n if (matchesKey(data, 'up') || data === 'k') {\n this.move(-1);\n return;\n }\n if (matchesKey(data, 'down') || data === 'j') {\n this.move(1);\n return;\n }\n if (data === 'x') {\n const instance = this.instances[this.selected];\n if (instance) void this.client.stop(instance.instanceId, STOP_REASON);\n }\n }\n\n protected getChrome(): DoomOverlayChrome {\n return {\n title: 'LOOPS',\n breadcrumb: 'SPC › l / loops › l / list',\n headerRight: `${this.instances.length} active`,\n footer: `${DOOM_NAVIGATION_KEYS.list} move · x stop · esc close · launched detached work continues`,\n footerHints: [\n [DOOM_NAVIGATION_KEYS.list, 'move'],\n ['x', 'stop scheduling'],\n ['esc', 'close'],\n ],\n accent: DOOM_OVERLAY_ACCENT,\n };\n }\n\n protected renderBody(width: number): string[] {\n const stopScope = this.theme.fg('dim', truncateToWidth(STOP_SCOPE_MESSAGE, width));\n if (!this.instances.length) return [this.theme.fg('dim', EMPTY_MESSAGE), '', stopScope];\n return [\n stopScope,\n '',\n ...this.instances.flatMap((instance, index) => {\n const marker = index === this.selected ? this.theme.fg('accent', '▸') : ' ';\n const name = instance.label ?? instance.launcherLabel;\n const state = this.theme.fg(instance.state === 'running' ? 'success' : 'warning', instance.state);\n const line = truncateToWidth(`${marker} ${name} · ${state}`, width);\n const detail = instance.detail ?? instance.instanceId;\n return [line, ` ${this.theme.fg('dim', truncateToWidth(detail, Math.max(0, width - 4)))}`];\n }),\n ];\n }\n\n private refresh(): void {\n this.instances = this.client.listInstances();\n this.selected = Math.min(this.selected, Math.max(0, this.instances.length - 1));\n this.invalidate();\n }\n\n private move(delta: number): void {\n if (!this.instances.length) return;\n this.selected = Math.max(0, Math.min(this.selected + delta, this.instances.length - 1));\n this.invalidate();\n }\n}\n\nexport async function openLoopListOverlay(ctx: ExtensionContext, client: LoopLauncherClient): Promise<void> {\n if (ctx.mode !== 'tui') {\n const instances = client.listInstances();\n const labels = instances.map((instance) => `${instance.label ?? instance.launcherLabel} (${instance.instanceId})`);\n const selected = await ctx.ui.select('Stop loop scheduling', labels);\n const instance = instances[labels.indexOf(selected ?? '')];\n if (instance) await client.stop(instance.instanceId, STOP_REASON);\n return;\n }\n await ctx.ui.custom<undefined>(\n (tui, theme, _keybindings, done) => new LoopListOverlay(tui, theme, client, done),\n DOOM_FULLSCREEN_UI_OPTIONS,\n );\n}\n"],"mappings":"sOAYA,MAEM,EAAc,8BAEpB,IAAa,EAAb,cAAqC,CAAY,CAQ5B,OACA,KARnB,YACA,UACA,SAAmB,EAEnB,YACE,EACA,EACA,EACA,EACA,CACA,MAAM,EAAK,CAAK,EAHC,KAAA,OAAA,EACA,KAAA,KAAA,EAGjB,KAAK,UAAY,EAAO,cAAc,EACtC,KAAK,YAAc,EAAO,cAAgB,KAAK,QAAQ,CAAC,CAC1D,CAEA,SAAgB,CACd,KAAK,YAAY,CACnB,CAEA,YAAY,EAAoB,CAC9B,GAAI,EAAW,EAAM,QAAQ,GAAK,EAAW,EAAM,QAAQ,GAAK,IAAS,IAAK,CAC5E,KAAK,KAAK,IAAA,EAAS,EACnB,MACF,CACA,GAAI,EAAW,EAAM,IAAI,GAAK,IAAS,IAAK,CAC1C,KAAK,KAAK,EAAE,EACZ,MACF,CACA,GAAI,EAAW,EAAM,MAAM,GAAK,IAAS,IAAK,CAC5C,KAAK,KAAK,CAAC,EACX,MACF,CACA,GAAI,IAA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AAK,IAAI,KAAK,SAAW,EAAO,KAAK,UAAU,OAAS,CAAC,CAAC,EACtF,KAAK,WAAW,EAClB,CACF,EAEA,eAAsB,EAAoB,EAAuB,EAA2C,CAC1G,GAAI,EAAI,OAAS,MAAO,CACtB,IAAM,EAAY,EAAO,cAAc,EACjC,EAAS,EAAU,IAAK,GAAa,GAAG,EAAS,OAAS,EAAS,cAAc,IAAI,EAAS,WAAW,EAAE,EAC3G,EAAW,MAAM,EAAI,GAAG,OAAO,uBAAwB,CAAM,EAC7D,EAAW,EAAU,EAAO,QAAQ,GAAY,EAAE,GACpD,GAAU,MAAM,EAAO,KAAK,EAAS,WAAY,CAAW,EAChE,MACF,CACA,MAAM,EAAI,GAAG,QACV,EAAK,EAAO,EAAc,IAAS,IAAI,EAAgB,EAAK,EAAO,EAAQ,CAAI,EAChF,CACF,CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
let e=require("@agimon-ai/doompi-ui/components/doomOverlay"),t=require("@earendil-works/pi-tui");var n=class extends e.DoomOverlay{launchers;done;selected=0;constructor(e,t,n,r){super(e,t),this.launchers=n,this.done=r}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");var n=class extends e.DoomOverlay{launchers;done;selected=0;constructor(e,t,n,r){super(e,t),this.launchers=n,this.done=r}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}(0,t.matchesKey)(e,`enter`)&&this.done(this.launchers[this.selected]?.id)}getChrome(){return{title:`START LOOP`,breadcrumb:`SPC › l / loops › s / start`,footer:`${e.DOOM_NAVIGATION_KEYS.list} move · enter launch · esc close`,footerHints:[[e.DOOM_NAVIGATION_KEYS.list,`move`],[`enter`,`launch`],[`esc`,`close`]],accent:e.DOOM_OVERLAY_ACCENT}}renderBody(e){return this.launchers.length?this.launchers.flatMap((n,r)=>{let i=r===this.selected,a=i?this.theme.fg(`accent`,`▸`):` `,o=i?this.theme.bold(n.label):n.label,s=[`${a} ${(0,t.truncateToWidth)(o,Math.max(0,e-2))}`];return n.description&&s.push(` ${this.theme.fg(`dim`,(0,t.truncateToWidth)(n.description,Math.max(0,e-4)))}`),s}):[this.theme.fg(`dim`,`No loop launchers are registered for this session.`)]}move(e){this.launchers.length&&(this.selected=Math.max(0,Math.min(this.selected+e,this.launchers.length-1)),this.invalidate())}};async function r(t,r){if(t.mode!==`tui`){let e=r.map(e=>e.label),n=await t.ui.select(`Start loop`,e);return r[e.indexOf(n??``)]?.id}return t.ui.custom((e,t,i,a)=>new n(e,t,r,a),e.DOOM_FULLSCREEN_UI_OPTIONS)}exports.StartLoopOverlay=n,exports.openStartLoopOverlay=r;
|
|
2
2
|
//# sourceMappingURL=startLoopOverlay.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"startLoopOverlay.cjs","names":["DoomOverlay","matchesKey","DOOM_OVERLAY_ACCENT","truncateToWidth","DOOM_FULLSCREEN_UI_OPTIONS"],"sources":["../../src/tui/startLoopOverlay.ts"],"sourcesContent":["import {\n DOOM_FULLSCREEN_UI_OPTIONS,\n DOOM_OVERLAY_ACCENT,\n DoomOverlay,\n type DoomOverlayChrome,\n type DoomOverlayTui,\n} from '@agimon-ai/doompi-ui/components/doomOverlay';\nimport type { ExtensionContext, Theme } from '@earendil-works/pi-coding-agent';\nimport { matchesKey, truncateToWidth } from '@earendil-works/pi-tui';\nimport type { LoopLauncherSummary } from '../
|
|
1
|
+
{"version":3,"file":"startLoopOverlay.cjs","names":["DoomOverlay","matchesKey","DOOM_NAVIGATION_KEYS","DOOM_OVERLAY_ACCENT","truncateToWidth","DOOM_FULLSCREEN_UI_OPTIONS"],"sources":["../../src/tui/startLoopOverlay.ts"],"sourcesContent":["import {\n DOOM_FULLSCREEN_UI_OPTIONS,\n DOOM_NAVIGATION_KEYS,\n DOOM_OVERLAY_ACCENT,\n DoomOverlay,\n type DoomOverlayChrome,\n type DoomOverlayTui,\n} from '@agimon-ai/doompi-ui/components/doomOverlay';\nimport type { ExtensionContext, Theme } from '@earendil-works/pi-coding-agent';\nimport { matchesKey, truncateToWidth } from '@earendil-works/pi-tui';\nimport type { LoopLauncherSummary } from '../types/loop.ts';\n\nconst EMPTY_MESSAGE = 'No loop launchers are registered for this session.';\n\nexport class StartLoopOverlay extends DoomOverlay {\n private selected = 0;\n\n constructor(\n tui: DoomOverlayTui,\n theme: Theme,\n private readonly launchers: readonly LoopLauncherSummary[],\n private readonly done: (result: string | undefined) => void,\n ) {\n super(tui, theme);\n }\n\n handleInput(data: string): void {\n if (matchesKey(data, 'escape') || matchesKey(data, 'ctrl+c') || data === 'q') {\n this.done(undefined);\n return;\n }\n if (matchesKey(data, 'up') || data === 'k') {\n this.move(-1);\n return;\n }\n if (matchesKey(data, 'down') || data === 'j') {\n this.move(1);\n return;\n }\n if (matchesKey(data, 'enter')) this.done(this.launchers[this.selected]?.id);\n }\n\n protected getChrome(): DoomOverlayChrome {\n return {\n title: 'START LOOP',\n breadcrumb: 'SPC › l / loops › s / start',\n footer: `${DOOM_NAVIGATION_KEYS.list} move · enter launch · esc close`,\n footerHints: [\n [DOOM_NAVIGATION_KEYS.list, 'move'],\n ['enter', 'launch'],\n ['esc', 'close'],\n ],\n accent: DOOM_OVERLAY_ACCENT,\n };\n }\n\n protected renderBody(width: number): string[] {\n if (!this.launchers.length) return [this.theme.fg('dim', EMPTY_MESSAGE)];\n return this.launchers.flatMap((launcher, index) => {\n const selected = index === this.selected;\n const marker = selected ? this.theme.fg('accent', '▸') : ' ';\n const label = selected ? this.theme.bold(launcher.label) : launcher.label;\n const lines = [`${marker} ${truncateToWidth(label, Math.max(0, width - 2))}`];\n if (launcher.description)\n lines.push(` ${this.theme.fg('dim', truncateToWidth(launcher.description, Math.max(0, width - 4)))}`);\n return lines;\n });\n }\n\n private move(delta: number): void {\n if (!this.launchers.length) return;\n this.selected = Math.max(0, Math.min(this.selected + delta, this.launchers.length - 1));\n this.invalidate();\n }\n}\n\nexport async function openStartLoopOverlay(\n ctx: ExtensionContext,\n launchers: readonly LoopLauncherSummary[],\n): Promise<string | undefined> {\n if (ctx.mode !== 'tui') {\n const labels = launchers.map((launcher) => launcher.label);\n const selected = await ctx.ui.select('Start loop', labels);\n return launchers[labels.indexOf(selected ?? '')]?.id;\n }\n return ctx.ui.custom<string | undefined>(\n (tui, theme, _keybindings, done) => new StartLoopOverlay(tui, theme, launchers, done),\n DOOM_FULLSCREEN_UI_OPTIONS,\n );\n}\n"],"mappings":"iGAcA,IAAa,EAAb,cAAsCA,EAAAA,WAAY,CAM7B,UACA,KANnB,SAAmB,EAEnB,YACE,EACA,EACA,EACA,EACA,CACA,MAAM,EAAK,CAAK,EAHC,KAAA,UAAA,EACA,KAAA,KAAA,CAGnB,CAEA,YAAY,EAAoB,CAC9B,IAAA,EAAIC,EAAAA,WAAAA,CAAW,EAAM,QAAQ,IAAA,EAAKA,EAAAA,WAAAA,CAAW,EAAM,QAAQ,GAAK,IAAS,IAAK,CAC5E,KAAK,KAAK,IAAA,EAAS,EACnB,MACF,CACA,IAAA,EAAIA,EAAAA,WAAAA,CAAW,EAAM,IAAI,GAAK,IAAS,IAAK,CAC1C,KAAK,KAAK,EAAE,EACZ,MACF,CACA,IAAA,EAAIA,EAAAA,WAAAA,CAAW,EAAM,MAAM,GAAK,IAAS,IAAK,CAC5C,KAAK,KAAK,CAAC,EACX,MACF,EACA,EAAIA,EAAAA,WAAAA,CAAW,EAAM,OAAO,GAAG,KAAK,KAAK,KAAK,UAAU,KAAK,SAAS,EAAE,EAAE,CAC5E,CAEA,WAAyC,CACvC,MAAO,CACL,MAAO,aACP,WAAY,8BACZ,OAAQ,GAAGC,EAAAA,qBAAqB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2 +1,2 @@
|
|
|
1
|
-
import{DOOM_FULLSCREEN_UI_OPTIONS as e,
|
|
1
|
+
import{DOOM_FULLSCREEN_UI_OPTIONS as e,DOOM_NAVIGATION_KEYS as t,DOOM_OVERLAY_ACCENT as n,DoomOverlay as r}from"@agimon-ai/doompi-ui/components/doomOverlay";import{matchesKey as i,truncateToWidth as a}from"@earendil-works/pi-tui";var o=class extends r{launchers;done;selected=0;constructor(e,t,n,r){super(e,t),this.launchers=n,this.done=r}handleInput(e){if(i(e,`escape`)||i(e,`ctrl+c`)||e===`q`){this.done(void 0);return}if(i(e,`up`)||e===`k`){this.move(-1);return}if(i(e,`down`)||e===`j`){this.move(1);return}i(e,`enter`)&&this.done(this.launchers[this.selected]?.id)}getChrome(){return{title:`START LOOP`,breadcrumb:`SPC › l / loops › s / start`,footer:`${t.list} move · enter launch · esc close`,footerHints:[[t.list,`move`],[`enter`,`launch`],[`esc`,`close`]],accent:n}}renderBody(e){return this.launchers.length?this.launchers.flatMap((t,n)=>{let r=n===this.selected,i=r?this.theme.fg(`accent`,`▸`):` `,o=r?this.theme.bold(t.label):t.label,s=[`${i} ${a(o,Math.max(0,e-2))}`];return t.description&&s.push(` ${this.theme.fg(`dim`,a(t.description,Math.max(0,e-4)))}`),s}):[this.theme.fg(`dim`,`No loop launchers are registered for this session.`)]}move(e){this.launchers.length&&(this.selected=Math.max(0,Math.min(this.selected+e,this.launchers.length-1)),this.invalidate())}};async function s(t,n){if(t.mode!==`tui`){let e=n.map(e=>e.label),r=await t.ui.select(`Start loop`,e);return n[e.indexOf(r??``)]?.id}return t.ui.custom((e,t,r,i)=>new o(e,t,n,i),e)}export{o as StartLoopOverlay,s as openStartLoopOverlay};
|
|
2
2
|
//# sourceMappingURL=startLoopOverlay.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"startLoopOverlay.mjs","names":[],"sources":["../../src/tui/startLoopOverlay.ts"],"sourcesContent":["import {\n DOOM_FULLSCREEN_UI_OPTIONS,\n DOOM_OVERLAY_ACCENT,\n DoomOverlay,\n type DoomOverlayChrome,\n type DoomOverlayTui,\n} from '@agimon-ai/doompi-ui/components/doomOverlay';\nimport type { ExtensionContext, Theme } from '@earendil-works/pi-coding-agent';\nimport { matchesKey, truncateToWidth } from '@earendil-works/pi-tui';\nimport type { LoopLauncherSummary } from '../
|
|
1
|
+
{"version":3,"file":"startLoopOverlay.mjs","names":[],"sources":["../../src/tui/startLoopOverlay.ts"],"sourcesContent":["import {\n DOOM_FULLSCREEN_UI_OPTIONS,\n DOOM_NAVIGATION_KEYS,\n DOOM_OVERLAY_ACCENT,\n DoomOverlay,\n type DoomOverlayChrome,\n type DoomOverlayTui,\n} from '@agimon-ai/doompi-ui/components/doomOverlay';\nimport type { ExtensionContext, Theme } from '@earendil-works/pi-coding-agent';\nimport { matchesKey, truncateToWidth } from '@earendil-works/pi-tui';\nimport type { LoopLauncherSummary } from '../types/loop.ts';\n\nconst EMPTY_MESSAGE = 'No loop launchers are registered for this session.';\n\nexport class StartLoopOverlay extends DoomOverlay {\n private selected = 0;\n\n constructor(\n tui: DoomOverlayTui,\n theme: Theme,\n private readonly launchers: readonly LoopLauncherSummary[],\n private readonly done: (result: string | undefined) => void,\n ) {\n super(tui, theme);\n }\n\n handleInput(data: string): void {\n if (matchesKey(data, 'escape') || matchesKey(data, 'ctrl+c') || data === 'q') {\n this.done(undefined);\n return;\n }\n if (matchesKey(data, 'up') || data === 'k') {\n this.move(-1);\n return;\n }\n if (matchesKey(data, 'down') || data === 'j') {\n this.move(1);\n return;\n }\n if (matchesKey(data, 'enter')) this.done(this.launchers[this.selected]?.id);\n }\n\n protected getChrome(): DoomOverlayChrome {\n return {\n title: 'START LOOP',\n breadcrumb: 'SPC › l / loops › s / start',\n footer: `${DOOM_NAVIGATION_KEYS.list} move · enter launch · esc close`,\n footerHints: [\n [DOOM_NAVIGATION_KEYS.list, 'move'],\n ['enter', 'launch'],\n ['esc', 'close'],\n ],\n accent: DOOM_OVERLAY_ACCENT,\n };\n }\n\n protected renderBody(width: number): string[] {\n if (!this.launchers.length) return [this.theme.fg('dim', EMPTY_MESSAGE)];\n return this.launchers.flatMap((launcher, index) => {\n const selected = index === this.selected;\n const marker = selected ? this.theme.fg('accent', '▸') : ' ';\n const label = selected ? this.theme.bold(launcher.label) : launcher.label;\n const lines = [`${marker} ${truncateToWidth(label, Math.max(0, width - 2))}`];\n if (launcher.description)\n lines.push(` ${this.theme.fg('dim', truncateToWidth(launcher.description, Math.max(0, width - 4)))}`);\n return lines;\n });\n }\n\n private move(delta: number): void {\n if (!this.launchers.length) return;\n this.selected = Math.max(0, Math.min(this.selected + delta, this.launchers.length - 1));\n this.invalidate();\n }\n}\n\nexport async function openStartLoopOverlay(\n ctx: ExtensionContext,\n launchers: readonly LoopLauncherSummary[],\n): Promise<string | undefined> {\n if (ctx.mode !== 'tui') {\n const labels = launchers.map((launcher) => launcher.label);\n const selected = await ctx.ui.select('Start loop', labels);\n return launchers[labels.indexOf(selected ?? '')]?.id;\n }\n return ctx.ui.custom<string | undefined>(\n (tui, theme, _keybindings, done) => new StartLoopOverlay(tui, theme, launchers, done),\n DOOM_FULLSCREEN_UI_OPTIONS,\n );\n}\n"],"mappings":"sOAcA,IAAa,EAAb,cAAsC,CAAY,CAM7B,UACA,KANnB,SAAmB,EAEnB,YACE,EACA,EACA,EACA,EACA,CACA,MAAM,EAAK,CAAK,EAHC,KAAA,UAAA,EACA,KAAA,KAAA,CAGnB,CAEA,YAAY,EAAoB,CAC9B,GAAI,EAAW,EAAM,QAAQ,GAAK,EAAW,EAAM,QAAQ,GAAK,IAAS,IAAK,CAC5E,KAAK,KAAK,IAAA,EAAS,EACnB,MACF,CACA,GAAI,EAAW,EAAM,IAAI,GAAK,IAAS,IAAK,CAC1C,KAAK,KAAK,EAAE,EACZ,MACF,CACA,GAAI,EAAW,EAAM,MAAM,GAAK,IAAS,IAAK,CAC5C,KAAK,KAAK,CAAC,EACX,MACF,CACI,EAAW,EAAM,O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IAAI,EAAiB,EAAK,EAAO,EAAW,CAAI,EACpF,CACF,CACF"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//#region src/types/loop.d.ts
|
|
2
|
+
interface LoopLaunchRequest {
|
|
3
|
+
readonly instanceId: string;
|
|
4
|
+
readonly signal: AbortSignal;
|
|
5
|
+
}
|
|
6
|
+
interface StoppableLoop {
|
|
7
|
+
readonly instanceId: string;
|
|
8
|
+
readonly label?: string;
|
|
9
|
+
readonly detail?: string;
|
|
10
|
+
stop(reason?: string): void | Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
interface LoopLauncherSummary {
|
|
13
|
+
readonly id: string;
|
|
14
|
+
readonly source: string;
|
|
15
|
+
readonly label: string;
|
|
16
|
+
readonly description?: string;
|
|
17
|
+
}
|
|
18
|
+
interface LoopInstanceSnapshot {
|
|
19
|
+
readonly instanceId: string;
|
|
20
|
+
readonly launcherId: string;
|
|
21
|
+
readonly launcherLabel: string;
|
|
22
|
+
readonly label?: string;
|
|
23
|
+
readonly detail?: string;
|
|
24
|
+
readonly state: 'starting' | 'running' | 'stopping';
|
|
25
|
+
readonly startedAt?: string;
|
|
26
|
+
}
|
|
27
|
+
interface LoopLauncherRegistration {
|
|
28
|
+
dispose(reason?: string): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
interface LoopLauncherClient {
|
|
31
|
+
listLaunchers(): readonly LoopLauncherSummary[];
|
|
32
|
+
listInstances(): readonly LoopInstanceSnapshot[];
|
|
33
|
+
subscribe(listener: () => void): () => void;
|
|
34
|
+
launch(launcherId: string, options?: {
|
|
35
|
+
instanceId?: string;
|
|
36
|
+
}): Promise<LoopInstanceSnapshot | undefined>;
|
|
37
|
+
stop(instanceId: string, reason?: string): Promise<boolean>;
|
|
38
|
+
stopAll(reason?: string): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
interface RegisterLoopLauncherOptions extends LoopLauncherSummary {
|
|
41
|
+
launch(request: LoopLaunchRequest): Promise<StoppableLoop | undefined>;
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { LoopInstanceSnapshot, LoopLaunchRequest, LoopLauncherClient, LoopLauncherRegistration, LoopLauncherSummary, RegisterLoopLauncherOptions, StoppableLoop };
|
|
45
|
+
//# sourceMappingURL=loop.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loop.d.cts","names":[],"sources":["../../src/types/loop.ts"],"mappings":";UAAiB;WACN;WACA,QAAQ;;UAGF;WACN;WACA;WACA;EACT,KAAK,yBAAyB;;UAGf;WACN;WACA;WACA;WACA;;UAGM;WACN;WACA;WACA;WACA;WACA;WACA;WACA;;UAGM;EACf,QAAQ,kBAAkB;;UAGX;EACf,0BAA0B;EAC1B,0BAA0B;EAC1B,UAAU;EACV,OAAO,oBAAoB;IAAY;MAAwB,QAAQ;EACvE,KAAK,oBAAoB,kBAAkB;EAC3C,QAAQ,kBAAkB;;UAGX,oCAAoC;EACnD,OAAO,SAAS,oBAAoB,QAAQ"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//#region src/types/loop.d.ts
|
|
2
|
+
interface LoopLaunchRequest {
|
|
3
|
+
readonly instanceId: string;
|
|
4
|
+
readonly signal: AbortSignal;
|
|
5
|
+
}
|
|
6
|
+
interface StoppableLoop {
|
|
7
|
+
readonly instanceId: string;
|
|
8
|
+
readonly label?: string;
|
|
9
|
+
readonly detail?: string;
|
|
10
|
+
stop(reason?: string): void | Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
interface LoopLauncherSummary {
|
|
13
|
+
readonly id: string;
|
|
14
|
+
readonly source: string;
|
|
15
|
+
readonly label: string;
|
|
16
|
+
readonly description?: string;
|
|
17
|
+
}
|
|
18
|
+
interface LoopInstanceSnapshot {
|
|
19
|
+
readonly instanceId: string;
|
|
20
|
+
readonly launcherId: string;
|
|
21
|
+
readonly launcherLabel: string;
|
|
22
|
+
readonly label?: string;
|
|
23
|
+
readonly detail?: string;
|
|
24
|
+
readonly state: 'starting' | 'running' | 'stopping';
|
|
25
|
+
readonly startedAt?: string;
|
|
26
|
+
}
|
|
27
|
+
interface LoopLauncherRegistration {
|
|
28
|
+
dispose(reason?: string): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
interface LoopLauncherClient {
|
|
31
|
+
listLaunchers(): readonly LoopLauncherSummary[];
|
|
32
|
+
listInstances(): readonly LoopInstanceSnapshot[];
|
|
33
|
+
subscribe(listener: () => void): () => void;
|
|
34
|
+
launch(launcherId: string, options?: {
|
|
35
|
+
instanceId?: string;
|
|
36
|
+
}): Promise<LoopInstanceSnapshot | undefined>;
|
|
37
|
+
stop(instanceId: string, reason?: string): Promise<boolean>;
|
|
38
|
+
stopAll(reason?: string): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
interface RegisterLoopLauncherOptions extends LoopLauncherSummary {
|
|
41
|
+
launch(request: LoopLaunchRequest): Promise<StoppableLoop | undefined>;
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { LoopInstanceSnapshot, LoopLaunchRequest, LoopLauncherClient, LoopLauncherRegistration, LoopLauncherSummary, RegisterLoopLauncherOptions, StoppableLoop };
|
|
45
|
+
//# sourceMappingURL=loop.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loop.d.mts","names":[],"sources":["../../src/types/loop.ts"],"mappings":";UAAiB;WACN;WACA,QAAQ;;UAGF;WACN;WACA;WACA;EACT,KAAK,yBAAyB;;UAGf;WACN;WACA;WACA;WACA;;UAGM;WACN;WACA;WACA;WACA;WACA;WACA;WACA;;UAGM;EACf,QAAQ,kBAAkB;;UAGX;EACf,0BAA0B;EAC1B,0BAA0B;EAC1B,UAAU;EACV,OAAO,oBAAoB;IAAY;MAAwB,QAAQ;EACvE,KAAK,oBAAoB,kBAAkB;EAC3C,QAAQ,kBAAkB;;UAGX,oCAAoC;EACnD,OAAO,SAAS,oBAAoB,QAAQ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agimon-ai/doompi-loop",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.15",
|
|
4
4
|
"description": "Generic multi-loop controller for Doompi",
|
|
5
5
|
"homepage": "https://agimon.ai",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@agimon-ai/doompi-extension-contracts": "0.0.1-alpha.
|
|
34
|
-
"@agimon-ai/doompi-ui": "0.0.1-alpha.
|
|
33
|
+
"@agimon-ai/doompi-extension-contracts": "0.0.1-alpha.15",
|
|
34
|
+
"@agimon-ai/doompi-ui": "0.0.1-alpha.15"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@earendil-works/pi-coding-agent": "0.84.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pi.cjs","names":["registerLoopExtension"],"sources":["../../src/extensions/pi.ts"],"sourcesContent":["import { registerLoopExtension } from '../adapters/pi/extension.ts';\n\nexport default registerLoopExtension;\n"],"mappings":"AAEA,IAAA,wCAAeA,CAAAA,CAAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pi.mjs","names":[],"sources":["../../src/extensions/pi.ts"],"sourcesContent":["import { registerLoopExtension } from '../adapters/pi/extension.ts';\n\nexport default registerLoopExtension;\n"],"mappings":"qEAEA,IAAA,EAAe"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=require("./launcher.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(e,t){let r=(await e.editor(`Loop prompt`,``))?.trim();if(!r||t.aborted)return;let i=await e.input(`Loop interval in seconds`,`Default: 300s`);if(i===void 0||t.aborted)return;let a=i.trim()||`300`,o=n(a);if(o){e.notify(o,`warning`);return}return{prompt:r,intervalSeconds:Number(a)}}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=e=>{if(!e.stopped){if(!e.context.isIdle()){n.add(e);return}n.delete(e);try{t.sendUserMessage(e.prompt)}catch(t){e.context.ui.notify(`Default loop pass could not start: ${t instanceof Error?t.message:String(t)}`,`warning`)}}};return t.on(`agent_settled`,()=>{let e=n.values().next().value;e&&a(e)}),{register(t){return e.registerLoopLauncher(t.sessionManager.getSessionId(),{id:`doompi.default`,source:`@agimon-ai/doompi-loop`,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=defaultLauncher.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defaultLauncher.cjs","names":["registerLoopLauncher"],"sources":["../../../src/services/loop/defaultLauncher.ts"],"sourcesContent":["import type { ExtensionAPI, ExtensionContext, ExtensionUIContext } from '@earendil-works/pi-coding-agent';\nimport { type LoopLauncherRegistration, registerLoopLauncher, type StoppableLoop } from './launcher.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): 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, 'warning');\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 'warning',\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) {\n return registerLoopLauncher(ctx.sessionManager.getSessionId(), {\n id: DEFAULT_LAUNCHER_ID,\n source: '@agimon-ai/doompi-loop',\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":"kCAMM,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,EAAO,SA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AK,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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defaultLauncher.d.cts","names":[],"sources":["../../../src/services/loop/defaultLauncher.ts"],"mappings":";;;UAqBiB;EACf,SAAS,KAAK,mBAAmB;;iBAoCnB,0BAA0B,IAAI,eAAe"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defaultLauncher.d.mts","names":[],"sources":["../../../src/services/loop/defaultLauncher.ts"],"mappings":";;;UAqBiB;EACf,SAAS,KAAK,mBAAmB;;iBAoCnB,0BAA0B,IAAI,eAAe"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{registerLoopLauncher as e}from"./launcher.mjs";const 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(e,t){let r=(await e.editor(`Loop prompt`,``))?.trim();if(!r||t.aborted)return;let i=await e.input(`Loop interval in seconds`,`Default: 300s`);if(i===void 0||t.aborted)return;let a=i.trim()||`300`,o=n(a);if(o){e.notify(o,`warning`);return}return{prompt:r,intervalSeconds:Number(a)}}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=e=>{if(!e.stopped){if(!e.context.isIdle()){n.add(e);return}n.delete(e);try{t.sendUserMessage(e.prompt)}catch(t){e.context.ui.notify(`Default loop pass could not start: ${t instanceof Error?t.message:String(t)}`,`warning`)}}};return t.on(`agent_settled`,()=>{let e=n.values().next().value;e&&a(e)}),{register(t){return e(t.sessionManager.getSessionId(),{id:`doompi.default`,source:`@agimon-ai/doompi-loop`,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))}}}})}}}export{a as createDefaultLoopLauncher};
|
|
2
|
-
//# sourceMappingURL=defaultLauncher.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defaultLauncher.mjs","names":[],"sources":["../../../src/services/loop/defaultLauncher.ts"],"sourcesContent":["import type { ExtensionAPI, ExtensionContext, ExtensionUIContext } from '@earendil-works/pi-coding-agent';\nimport { type LoopLauncherRegistration, registerLoopLauncher, type StoppableLoop } from './launcher.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): 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, 'warning');\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 'warning',\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) {\n return registerLoopLauncher(ctx.sessionManager.getSessionId(), {\n id: DEFAULT_LAUNCHER_ID,\n source: '@agimon-ai/doompi-loop',\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":"sDAGA,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,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,EAAO,SAAS,EAC1B,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,IAAI,IAEd,EAAe,GAAkC,CACjD,MAAK,QACT,IAAI,CAAC,EAAK,QAAQ,OAAO,EAAG,CAC1B,EAAQ,IAAI,CAAI,EAChB,MACF,CAEA,EAAQ,OAAO,CAAI,EACnB,GAAI,CACF,EAAG,gBAAgB,EAAK,MAAM,CAChC,OAAS,EAAO,CACd,EAAK,QAAQ,GAAG,OACd,sCAAsC,aAAiB,MAAQ,EAAM,QAAU,OAAO,CAAK,IAC3F,SACF,CACF,CAVA,CAWF,EAOA,OALA,EAAG,GAAG,oBAAuB,CAC3B,IAAM,EAAO,EAAQ,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,MACjC,GAAM,EAAY,CAAI,CAC5B,CAAC,EAEM,CACL,SAAS,EAAK,CACZ,OAAO,EAAqB,EAAI,eAAe,aAAa,EAAG,CAC7D,GAAI,iBACJ,OAAQ,yBACR,MAAO,eACP,YAAa,qDACb,MAAM,OAAO,CAAE,aAAY,UAAU,CACnC,IAAM,EAAW,MAAM,EAAmB,EAAI,GAAI,CAAM,EACxD,GAAI,CAAC,GAAY,EAAO,QAAS,OAEjC,IAAM,EAA0B,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"}
|
package/dist/types/constants.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
exports.ACTIVE_MODE_COLOR=`warning`,exports.LIST_COMMAND_DESCRIPTION=`List and stop active loops`,exports.LIST_COMMAND_NAME=`loops`,exports.MODE_STATUS_ID=`loop.active`,exports.NOTIFY_INFO_LEVEL=`info`,exports.PACKAGE_SOURCE=`@agimon-ai/doompi-loop`,exports.START_COMMAND_DESCRIPTION=`Start a registered loop`,exports.START_COMMAND_NAME=`loop`,exports.STATUS_KEY=`doom-loop`;
|
|
2
|
-
//# sourceMappingURL=constants.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.cjs","names":[],"sources":["../../src/types/constants.ts"],"sourcesContent":["export const PACKAGE_SOURCE = '@agimon-ai/doompi-loop';\nexport const START_COMMAND_NAME = 'loop';\nexport const LIST_COMMAND_NAME = 'loops';\nexport const START_COMMAND_DESCRIPTION = 'Start a registered loop';\nexport const LIST_COMMAND_DESCRIPTION = 'List and stop active loops';\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';\n"],"mappings":""}
|
package/dist/types/constants.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=`@agimon-ai/doompi-loop`,t=`loop`,n=`loops`,r=`Start a registered loop`,i=`List and stop active loops`,a=`doom-loop`,o=`loop.active`,s=`warning`,c=`info`;export{s as ACTIVE_MODE_COLOR,i as LIST_COMMAND_DESCRIPTION,n as LIST_COMMAND_NAME,o as MODE_STATUS_ID,c as NOTIFY_INFO_LEVEL,e as PACKAGE_SOURCE,r as START_COMMAND_DESCRIPTION,t as START_COMMAND_NAME,a as STATUS_KEY};
|
|
2
|
-
//# sourceMappingURL=constants.mjs.map
|