@agimon-ai/doompi-loop 0.0.1-alpha.84 → 0.0.1-alpha.86

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agimon-ai/doompi-loop",
3
- "version": "0.0.1-alpha.84",
3
+ "version": "0.0.1-alpha.86",
4
4
  "description": "Session-scoped recurring prompt scheduler and loop controls for Pi coding agents.",
5
5
  "keywords": [
6
6
  "ai",
@@ -69,14 +69,16 @@
69
69
  "access": "public"
70
70
  },
71
71
  "dependencies": {
72
- "@agimon-ai/doompi-core": "0.0.1-alpha.83",
73
- "@agimon-ai/doompi-minor-mode": "0.0.1-alpha.83",
74
- "@agimon-ai/doompi-ui": "0.0.1-alpha.83",
75
- "@agimon-ai/doompi-web-components": "0.0.1-alpha.41",
76
- "@deepseek-ai/cordis": "4.0.2"
72
+ "@agimon-ai/doompi-core": "0.0.1-alpha.85",
73
+ "@agimon-ai/doompi-minor-mode": "0.0.1-alpha.85",
74
+ "@agimon-ai/doompi-ui": "0.0.1-alpha.85",
75
+ "@agimon-ai/doompi-web-components": "0.0.1-alpha.43",
76
+ "@deepseek-ai/cordis": "4.0.2",
77
+ "croner": "10.0.1",
78
+ "typebox": "1.3.34"
77
79
  },
78
80
  "devDependencies": {
79
- "@agimon-ai/doompi-build": "0.0.1-alpha.11",
81
+ "@agimon-ai/doompi-build": "0.0.1-alpha.12",
80
82
  "@earendil-works/pi-coding-agent": "0.87.1",
81
83
  "@earendil-works/pi-tui": "0.87.1",
82
84
  "@types/node": "26.6.1",
@@ -1,24 +1,44 @@
1
1
  ---
2
2
  name: doompi-use-loop
3
- description: Use Doom Pi Loop to start, inspect, and stop session-scoped recurring prompts safely.
3
+ description: Create, inspect, and stop session-scoped interval, cron, and extension-contributed loops.
4
4
  ---
5
5
 
6
6
  # Use Doom Pi Loop
7
7
 
8
- Use Loop when the same prompt should run immediately and then recur while the current Pi session remains active.
8
+ Enable the Loop minor mode to expose `loop_list`, `loop_start`, and `loop_stop` to the agent. Enabling the mode does not create a loop. Disabling it hides agent tools but leaves existing loops and manual Activity controls available.
9
9
 
10
- ## Start and control loops
10
+ ## Agent configuration
11
11
 
12
- 1. Use `/loop` or `SPC l s` to start a loop.
13
- 2. Choose a prompt that is safe to repeat and an interval from 30 to 3600 seconds. The default is 300 seconds.
14
- 3. Use `/loops` or `SPC l l` to inspect active loops and stop individual instances.
15
- 4. Stop a loop as soon as its recurring work is complete.
12
+ Call `loop_list` first. It returns the available launcher IDs, their input schemas, and active instance IDs. Providers without an input schema require manual setup and cannot be started by an agent tool.
16
13
 
17
- Several loops can coexist. When Pi is busy, a due pass waits for the shared agent to become idle, and repeated due signals may coalesce instead of overlapping.
14
+ An interval loop runs immediately when the session can accept a prompt, then every 30 to 3600 seconds:
18
15
 
19
- ## Control cost and side effects
16
+ ```json
17
+ {
18
+ "launcherId": "doompi.default",
19
+ "input": { "prompt": "Check the current build status and report changes.", "intervalSeconds": 300 }
20
+ }
21
+ ```
20
22
 
21
- - Every pass can start another model turn and repeat tool calls or external side effects.
22
- - Prefer idempotent checks and conservative intervals.
23
- - Do not use Loop as a durable job queue. Replacing or shutting down the session stops timers, and resuming a transcript does not restart old loops.
24
- - Stopping a loop prevents future passes, but it cannot undo effects from a prompt that was already sent.
23
+ A cron loop runs at its next scheduled minute, not immediately. Supply a five-field cron expression and an optional IANA timezone. The default timezone is UTC:
24
+
25
+ ```json
26
+ {
27
+ "launcherId": "doompi.cron",
28
+ "input": { "prompt": "Summarize the work remaining today.", "cron": "0 9 * * 1-5", "timezone": "Australia/Brisbane" }
29
+ }
30
+ ```
31
+
32
+ Pass either configuration to `loop_start`. Stop one instance with `loop_stop` and its exact `instanceId`. Extension launchers, such as Agiflow project dispatch, use their own schemas from `loop_list`; do not guess their configuration fields.
33
+
34
+ ## Manual controls
35
+
36
+ Activity's Loops group is available whenever the Loop package is loaded, even with the minor mode off. It offers interval and cron setup, a chooser for extension types, and per-instance stop controls. `/loop [launcherId]` starts manual setup. `/loops` lists instances, and `/loops stop <instanceId>` stops one. The TUI also provides `SPC l s` and `SPC l l`.
37
+
38
+ ## Cost and lifecycle
39
+
40
+ Several loops can coexist, but built-in loops do not deliberately overlap prompts on the same agent. The CLI coalesces due passes while busy and retries after the agent settles. The server skips busy ticks and checks again at the next scheduled tick.
41
+
42
+ Every pass can start a model turn and repeat tool calls or external side effects. Prefer idempotent checks and conservative schedules. Stop loops when the recurring work is complete.
43
+
44
+ Loops are session-scoped, not a durable job queue. Replacing or shutting down the session stops timers; reopening a transcript does not restart them or replay missed ticks. Stopping prevents future submissions but does not undo or cancel a prompt already submitted.
@@ -30,8 +30,8 @@ function isState(value: unknown): value is LoopStatusState {
30
30
  }
31
31
 
32
32
  /** Projects runtime snapshots into the JSON status consumed by the web plugin. */
33
- export function formatLoopStatusView(instances: readonly LoopStatusSource[]): string | undefined {
34
- if (instances.length === 0) return undefined;
33
+ export function formatLoopStatusView(instances: readonly LoopStatusSource[]): string {
34
+ if (instances.length === 0) return '';
35
35
  return JSON.stringify(
36
36
  instances.map((instance) => ({
37
37
  instanceId: instance.instanceId,
@@ -1 +0,0 @@
1
- {"version":3,"file":"loopLaunchers-CPUUrDzQ.d.mts","names":[],"sources":["../src/schemas/loopLaunchers.ts"],"mappings":";;;cAGa;UAEI;WACN;WACA,QAAQ;;UAGF;WACN;WACA;WACA;EACT,KAAK,yBAAyB;;UAGf;WACN;WACA;WACA;WACA;;UAGM;WACN;WACA;WACA;WACA;WACA;WACA;WACA;;UAGM,+BAA+B;EAC9C,OAAO,SAAS,oBAAoB,QAAQ;;UAG7B;WACN;WACA;EACT,QAAQ,kBAAkB;;;UAIX;WACN;EACT,SAAS,YAAY,yBAAyB;EAC9C,0BAA0B;EAC1B,0BAA0B;EAC1B,UAAU;EACV,OAAO,oBAAoB;IAAY;MAAwB,QAAQ;EACvE,KAAK,oBAAoB,kBAAkB;EAC3C,QAAQ,kBAAkB;EAC1B,QAAQ,kBAAkB;;;YAIhB;IACR,uBAAuB;;;iBAIX,sBAAsB,SAAS,UAAU;iBAIzC,yBAAyB,SAAS,UAAU"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"loopView-CLIBhqYC.cjs","names":[],"sources":["../src/constants/loop.ts","../src/services/loopLaunchers/index.ts","../src/types/loopView.ts"],"sourcesContent":["export const START_COMMAND_DESCRIPTION = 'Start a registered loop';\nexport const LIST_COMMAND_DESCRIPTION = 'List and stop active loops';\nexport const START_COMMAND_NAME = 'loop';\nexport const LIST_COMMAND_NAME = 'loops';\n","import type {\n DoomLoopLaunchersService,\n LoopInstanceSnapshot,\n LoopLauncherDefinition,\n LoopLauncherRegistration,\n StoppableLoop,\n} from '../../schemas/loopLaunchers';\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","/** The browser-only status that carries active Loop instances into the activity dock. */\nexport const LOOP_VIEW_STATUS_KEY = 'doom-loop-instances';\n\nexport type LoopStatusState = 'starting' | 'running' | 'stopping';\n\n/** The small, serializable Loop view the cockpit needs for one activity row. */\nexport interface LoopStatusItem {\n readonly instanceId: string;\n readonly label: string;\n readonly detail: string;\n readonly state: LoopStatusState;\n}\n\ninterface LoopStatusSource {\n readonly instanceId: string;\n readonly launcherLabel: string;\n readonly label?: string;\n readonly detail?: string;\n readonly state: LoopStatusState;\n}\n\nconst ANSI = new RegExp(String.raw`\\u001b\\[[0-9;]*m`, 'gu');\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction isState(value: unknown): value is LoopStatusState {\n return value === 'starting' || value === 'running' || value === 'stopping';\n}\n\n/** Projects runtime snapshots into the JSON status consumed by the web plugin. */\nexport function formatLoopStatusView(instances: readonly LoopStatusSource[]): string | undefined {\n if (instances.length === 0) return undefined;\n return JSON.stringify(\n instances.map((instance) => ({\n instanceId: instance.instanceId,\n label: instance.label ?? instance.launcherLabel,\n detail: instance.detail ?? instance.instanceId,\n state: instance.state,\n })),\n );\n}\n\n/** Reads a Loop status without letting malformed session data crash the activity dock. */\nexport function parseLoopStatusView(raw: string | undefined): LoopStatusItem[] | undefined {\n if (raw === undefined) return undefined;\n const text = raw.replace(ANSI, '').trim();\n if (text === '') return undefined;\n\n try {\n const value: unknown = JSON.parse(text);\n if (!Array.isArray(value) || value.length === 0) return undefined;\n const items: LoopStatusItem[] = [];\n for (const item of value) {\n if (\n !isRecord(item) ||\n typeof item.instanceId !== 'string' ||\n item.instanceId.trim() === '' ||\n typeof item.label !== 'string' ||\n item.label.trim() === '' ||\n typeof item.detail !== 'string' ||\n !isState(item.state)\n ) {\n return undefined;\n }\n items.push({ instanceId: item.instanceId, label: item.label, detail: item.detail, state: item.state });\n }\n return items;\n } catch {\n return undefined;\n }\n}\n"],"mappings":";AAAA,MAAa,4BAA4B;AACzC,MAAa,2BAA2B;AACxC,MAAa,qBAAqB;AAClC,MAAa,oBAAoB;;;ACKjC,MAAM,gBAAgB;AACtB,MAAM,wBAAwB;AAC9B,MAAM,oBAAoB;AAC1B,MAAM,oBAAoB;AAsB1B,SAAS,QAAQ,OAAe,OAAuB;CACrD,MAAM,aAAa,MAAM,KAAK;CAC9B,IAAI,aAAa;CACjB,KAAK,MAAM,aAAa,YAAY;EAClC,MAAM,OAAO,UAAU,YAAY,CAAC;EACpC,IAAI,SAAS,KAAA,MAAc,QAAQ,MAAQ,SAAS,MAAO;GACzD,aAAa;GACb;EACF;CACF;CACA,IAAI,CAAC,cAAc,WAAW,SAAS,iBAAiB,YAAY,MAAM,IAAI,MAAM,WAAW,MAAM,EAAE;CACvG,OAAO;AACT;AAEA,SAAS,SAAS,OAA4C;CAC5D,OAAO;EACL,YAAY,MAAM;EAClB,YAAY,MAAM,SAAS,WAAW;EACtC,eAAe,MAAM,SAAS,WAAW;EACzC,GAAI,MAAM,QAAQ,QAAQ,EAAE,OAAO,MAAM,OAAO,MAAM,IAAI,CAAC;EAC3D,GAAI,MAAM,QAAQ,SAAS,EAAE,QAAQ,MAAM,OAAO,OAAO,IAAI,CAAC;EAC9D,OAAO,MAAM;EACb,GAAI,MAAM,YAAY,EAAE,WAAW,MAAM,UAAU,IAAI,CAAC;CAC1D;AACF;;AAGA,SAAgB,+BAA+B,EAC7C,YACA,kBACA,aACsD;CACtD,IAAI,CAAC,cAAc,WAAW,SAAS,uBACrC,MAAM,IAAI,UAA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MAAM;GAChB,MAAM,QAAQ,WAAW,CAAC,GAAG,UAAU,OAAO,CAAC,CAAC,CAAC,KAAK,UAAU,UAAU,OAAO,MAAM,CAAC,CAAC;GACzF,UAAU,MAAM;EAClB;CAGyB,CAAC;AAC9B;;;;AC7MA,MAAa,uBAAuB;AAoBvB,IAAI,OAAO,OAAO,GAAG,oBAAoB,IAAI;;AAW1D,SAAgB,qBAAqB,WAA4D;CAC/F,IAAI,UAAU,WAAW,GAAG,OAAO,KAAA;CACnC,OAAO,KAAK,UACV,UAAU,KAAK,cAAc;EAC3B,YAAY,SAAS;EACrB,OAAO,SAAS,SAAS,SAAS;EAClC,QAAQ,SAAS,UAAU,SAAS;EACpC,OAAO,SAAS;CAClB,EAAE,CACJ;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"loopView-CmuIEbUa.mjs","names":[],"sources":["../src/constants/loop.ts","../src/services/loopLaunchers/index.ts","../src/types/loopView.ts"],"sourcesContent":["export const START_COMMAND_DESCRIPTION = 'Start a registered loop';\nexport const LIST_COMMAND_DESCRIPTION = 'List and stop active loops';\nexport const START_COMMAND_NAME = 'loop';\nexport const LIST_COMMAND_NAME = 'loops';\n","import type {\n DoomLoopLaunchersService,\n LoopInstanceSnapshot,\n LoopLauncherDefinition,\n LoopLauncherRegistration,\n StoppableLoop,\n} from '../../schemas/loopLaunchers';\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","/** The browser-only status that carries active Loop instances into the activity dock. */\nexport const LOOP_VIEW_STATUS_KEY = 'doom-loop-instances';\n\nexport type LoopStatusState = 'starting' | 'running' | 'stopping';\n\n/** The small, serializable Loop view the cockpit needs for one activity row. */\nexport interface LoopStatusItem {\n readonly instanceId: string;\n readonly label: string;\n readonly detail: string;\n readonly state: LoopStatusState;\n}\n\ninterface LoopStatusSource {\n readonly instanceId: string;\n readonly launcherLabel: string;\n readonly label?: string;\n readonly detail?: string;\n readonly state: LoopStatusState;\n}\n\nconst ANSI = new RegExp(String.raw`\\u001b\\[[0-9;]*m`, 'gu');\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction isState(value: unknown): value is LoopStatusState {\n return value === 'starting' || value === 'running' || value === 'stopping';\n}\n\n/** Projects runtime snapshots into the JSON status consumed by the web plugin. */\nexport function formatLoopStatusView(instances: readonly LoopStatusSource[]): string | undefined {\n if (instances.length === 0) return undefined;\n return JSON.stringify(\n instances.map((instance) => ({\n instanceId: instance.instanceId,\n label: instance.label ?? instance.launcherLabel,\n detail: instance.detail ?? instance.instanceId,\n state: instance.state,\n })),\n );\n}\n\n/** Reads a Loop status without letting malformed session data crash the activity dock. */\nexport function parseLoopStatusView(raw: string | undefined): LoopStatusItem[] | undefined {\n if (raw === undefined) return undefined;\n const text = raw.replace(ANSI, '').trim();\n if (text === '') return undefined;\n\n try {\n const value: unknown = JSON.parse(text);\n if (!Array.isArray(value) || value.length === 0) return undefined;\n const items: LoopStatusItem[] = [];\n for (const item of value) {\n if (\n !isRecord(item) ||\n typeof item.instanceId !== 'string' ||\n item.instanceId.trim() === '' ||\n typeof item.label !== 'string' ||\n item.label.trim() === '' ||\n typeof item.detail !== 'string' ||\n !isState(item.state)\n ) {\n return undefined;\n }\n items.push({ instanceId: item.instanceId, label: item.label, detail: item.detail, state: item.state });\n }\n return items;\n } catch {\n return undefined;\n }\n}\n"],"mappings":";AAAA,MAAa,4BAA4B;AACzC,MAAa,2BAA2B;AACxC,MAAa,qBAAqB;AAClC,MAAa,oBAAoB;;;ACKjC,MAAM,gBAAgB;AACtB,MAAM,wBAAwB;AAC9B,MAAM,oBAAoB;AAC1B,MAAM,oBAAoB;AAsB1B,SAAS,QAAQ,OAAe,OAAuB;CACrD,MAAM,aAAa,MAAM,KAAK;CAC9B,IAAI,aAAa;CACjB,KAAK,MAAM,aAAa,YAAY;EAClC,MAAM,OAAO,UAAU,YAAY,CAAC;EACpC,IAAI,SAAS,KAAA,MAAc,QAAQ,MAAQ,SAAS,MAAO;GACzD,aAAa;GACb;EACF;CACF;CACA,IAAI,CAAC,cAAc,WAAW,SAAS,iBAAiB,YAAY,MAAM,IAAI,MAAM,WAAW,MAAM,EAAE;CACvG,OAAO;AACT;AAEA,SAAS,SAAS,OAA4C;CAC5D,OAAO;EACL,YAAY,MAAM;EAClB,YAAY,MAAM,SAAS,WAAW;EACtC,eAAe,MAAM,S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