@agimon-ai/doompi-loop 0.0.1-alpha.74 → 0.0.1-alpha.76
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 +6 -6
- package/dist/api-contracts.cjs +0 -7
- package/dist/api-contracts.d.cts +0 -2
- package/dist/api-contracts.d.mts +0 -2
- package/dist/api-contracts.mjs +0 -2
- package/dist/extensions/pi.cjs +0 -36
- package/dist/extensions/pi.cjs.map +0 -1
- package/dist/extensions/pi.d.cts +0 -5
- package/dist/extensions/pi.d.cts.map +0 -1
- package/dist/extensions/pi.d.mts +0 -5
- package/dist/extensions/pi.d.mts.map +0 -1
- package/dist/extensions/pi.mjs +0 -31
- package/dist/extensions/pi.mjs.map +0 -1
- package/dist/extensions/server.cjs +0 -51
- package/dist/extensions/server.cjs.map +0 -1
- package/dist/extensions/server.d.cts +0 -5
- package/dist/extensions/server.d.cts.map +0 -1
- package/dist/extensions/server.d.mts +0 -5
- package/dist/extensions/server.d.mts.map +0 -1
- package/dist/extensions/server.mjs +0 -46
- package/dist/extensions/server.mjs.map +0 -1
- package/dist/extensions/web.mjs +0 -228
- package/dist/extensions/web.mjs.map +0 -1
- package/dist/index.cjs +0 -0
- package/dist/index.d.cts +0 -2
- package/dist/index.d.mts +0 -2
- package/dist/index.mjs +0 -1
- package/dist/loopLaunchers.cjs +0 -5
- package/dist/loopLaunchers.d.cts +0 -2
- package/dist/loopLaunchers.d.mts +0 -2
- package/dist/loopLaunchers.mjs +0 -2
- package/dist/src/constants/loop.cjs +0 -12
- package/dist/src/constants/loop.cjs.map +0 -1
- package/dist/src/constants/loop.mjs +0 -9
- package/dist/src/constants/loop.mjs.map +0 -1
- package/dist/src/constants/piLoop.cjs +0 -16
- package/dist/src/constants/piLoop.cjs.map +0 -1
- package/dist/src/constants/piLoop.mjs +0 -11
- package/dist/src/constants/piLoop.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/_lib/runtime.cli.cjs +0 -26
- package/dist/src/extensions/workspaces/sessions/(backend)/_lib/runtime.cli.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/_lib/runtime.cli.mjs +0 -26
- package/dist/src/extensions/workspaces/sessions/(backend)/_lib/runtime.cli.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/_lib/runtime.server.cjs +0 -7
- package/dist/src/extensions/workspaces/sessions/(backend)/_lib/runtime.server.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/_lib/runtime.server.mjs +0 -7
- package/dist/src/extensions/workspaces/sessions/(backend)/_lib/runtime.server.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/command/loop.cli.cjs +0 -6
- package/dist/src/extensions/workspaces/sessions/(backend)/command/loop.cli.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/command/loop.cli.mjs +0 -7
- package/dist/src/extensions/workspaces/sessions/(backend)/command/loop.cli.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/command/loop.server.cjs +0 -6
- package/dist/src/extensions/workspaces/sessions/(backend)/command/loop.server.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/command/loop.server.mjs +0 -7
- package/dist/src/extensions/workspaces/sessions/(backend)/command/loop.server.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/command/loops.cli.cjs +0 -6
- package/dist/src/extensions/workspaces/sessions/(backend)/command/loops.cli.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/command/loops.cli.mjs +0 -7
- package/dist/src/extensions/workspaces/sessions/(backend)/command/loops.cli.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/command/loops.server.cjs +0 -6
- package/dist/src/extensions/workspaces/sessions/(backend)/command/loops.server.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/command/loops.server.mjs +0 -7
- package/dist/src/extensions/workspaces/sessions/(backend)/command/loops.server.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/hook/agent-settled.cli.cjs +0 -6
- package/dist/src/extensions/workspaces/sessions/(backend)/hook/agent-settled.cli.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/hook/agent-settled.cli.mjs +0 -7
- package/dist/src/extensions/workspaces/sessions/(backend)/hook/agent-settled.cli.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/hook/session-shutdown.server.cjs +0 -6
- package/dist/src/extensions/workspaces/sessions/(backend)/hook/session-shutdown.server.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/hook/session-shutdown.server.mjs +0 -7
- package/dist/src/extensions/workspaces/sessions/(backend)/hook/session-shutdown.server.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/hook/session-start.server.cjs +0 -6
- package/dist/src/extensions/workspaces/sessions/(backend)/hook/session-start.server.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/hook/session-start.server.mjs +0 -7
- package/dist/src/extensions/workspaces/sessions/(backend)/hook/session-start.server.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/doompi-use-loop.cli.cjs +0 -6
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/doompi-use-loop.cli.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/doompi-use-loop.cli.mjs +0 -7
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/doompi-use-loop.cli.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/doompi-use-loop.server.cjs +0 -6
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/doompi-use-loop.server.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/doompi-use-loop.server.mjs +0 -7
- package/dist/src/extensions/workspaces/sessions/(backend)/resource/doompi-use-loop.server.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/root.cli.cjs +0 -14
- package/dist/src/extensions/workspaces/sessions/(backend)/root.cli.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/root.cli.mjs +0 -15
- package/dist/src/extensions/workspaces/sessions/(backend)/root.cli.mjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/root.server.cjs +0 -17
- package/dist/src/extensions/workspaces/sessions/(backend)/root.server.cjs.map +0 -1
- package/dist/src/extensions/workspaces/sessions/(backend)/root.server.mjs +0 -18
- package/dist/src/extensions/workspaces/sessions/(backend)/root.server.mjs.map +0 -1
- package/dist/src/schemas/apiContracts.cjs +0 -13
- package/dist/src/schemas/apiContracts.cjs.map +0 -1
- package/dist/src/schemas/apiContracts.d.cts +0 -53
- package/dist/src/schemas/apiContracts.d.cts.map +0 -1
- package/dist/src/schemas/apiContracts.d.mts +0 -53
- package/dist/src/schemas/apiContracts.d.mts.map +0 -1
- package/dist/src/schemas/apiContracts.mjs +0 -13
- package/dist/src/schemas/apiContracts.mjs.map +0 -1
- package/dist/src/schemas/loopLaunchers.cjs +0 -17
- package/dist/src/schemas/loopLaunchers.cjs.map +0 -1
- package/dist/src/schemas/loopLaunchers.d.cts +0 -60
- package/dist/src/schemas/loopLaunchers.d.cts.map +0 -1
- package/dist/src/schemas/loopLaunchers.d.mts +0 -60
- package/dist/src/schemas/loopLaunchers.d.mts.map +0 -1
- package/dist/src/schemas/loopLaunchers.mjs +0 -15
- package/dist/src/schemas/loopLaunchers.mjs.map +0 -1
- package/dist/src/services/defaultLoopLauncher/index.cjs +0 -92
- package/dist/src/services/defaultLoopLauncher/index.cjs.map +0 -1
- package/dist/src/services/defaultLoopLauncher/index.mjs +0 -92
- package/dist/src/services/defaultLoopLauncher/index.mjs.map +0 -1
- package/dist/src/services/loopCommand/index.cjs +0 -15
- package/dist/src/services/loopCommand/index.cjs.map +0 -1
- package/dist/src/services/loopCommand/index.mjs +0 -15
- package/dist/src/services/loopCommand/index.mjs.map +0 -1
- package/dist/src/services/loopLaunchers/index.cjs +0 -180
- package/dist/src/services/loopLaunchers/index.cjs.map +0 -1
- package/dist/src/services/loopLaunchers/index.mjs +0 -180
- package/dist/src/services/loopLaunchers/index.mjs.map +0 -1
- package/dist/src/services/serverRuntime/index.cjs +0 -293
- package/dist/src/services/serverRuntime/index.cjs.map +0 -1
- package/dist/src/services/serverRuntime/index.mjs +0 -293
- package/dist/src/services/serverRuntime/index.mjs.map +0 -1
- package/dist/src/tui/leader.cjs +0 -36
- package/dist/src/tui/leader.cjs.map +0 -1
- package/dist/src/tui/leader.mjs +0 -36
- package/dist/src/tui/leader.mjs.map +0 -1
- package/dist/src/tui/loopListOverlay.cjs +0 -101
- package/dist/src/tui/loopListOverlay.cjs.map +0 -1
- package/dist/src/tui/loopListOverlay.mjs +0 -100
- package/dist/src/tui/loopListOverlay.mjs.map +0 -1
- package/dist/src/tui/loopRuntime.cjs +0 -256
- package/dist/src/tui/loopRuntime.cjs.map +0 -1
- package/dist/src/tui/loopRuntime.mjs +0 -256
- package/dist/src/tui/loopRuntime.mjs.map +0 -1
- package/dist/src/tui/startLoopOverlay.cjs +0 -71
- package/dist/src/tui/startLoopOverlay.cjs.map +0 -1
- package/dist/src/tui/startLoopOverlay.mjs +0 -70
- package/dist/src/tui/startLoopOverlay.mjs.map +0 -1
- package/dist/src/types/loopView.cjs +0 -19
- package/dist/src/types/loopView.cjs.map +0 -1
- package/dist/src/types/loopView.mjs +0 -18
- package/dist/src/types/loopView.mjs.map +0 -1
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
const require_loop = require("../../constants/loop.cjs");
|
|
2
|
-
const require_index = require("../loopLaunchers/index.cjs");
|
|
3
|
-
const require_loopView = require("../../types/loopView.cjs");
|
|
4
|
-
let _agimon_ai_doompi_minor_mode = require("@agimon-ai/doompi-minor-mode");
|
|
5
|
-
let _agimon_ai_doompi_core_server_facet = require("@agimon-ai/doompi-core/server-facet");
|
|
6
|
-
//#region src/services/serverRuntime/index.ts
|
|
7
|
-
const SOURCE = "@agimon-ai/doompi-loop";
|
|
8
|
-
const MODE_ID = "loop.active";
|
|
9
|
-
const DEFAULT_LAUNCHER_ID = "doompi.default";
|
|
10
|
-
const DEFAULT_INTERVAL_SECONDS = 300;
|
|
11
|
-
const MIN_INTERVAL_SECONDS = 30;
|
|
12
|
-
const MAX_INTERVAL_SECONDS = 3600;
|
|
13
|
-
function notify(context, body, level = "info") {
|
|
14
|
-
return Promise.resolve(context.client.notify({
|
|
15
|
-
body,
|
|
16
|
-
level
|
|
17
|
-
}));
|
|
18
|
-
}
|
|
19
|
-
function numberInput(value, fallback) {
|
|
20
|
-
if (typeof value !== "string" || value.trim() === "") return fallback;
|
|
21
|
-
const parsed = Number(value);
|
|
22
|
-
if (!Number.isInteger(parsed) || parsed < MIN_INTERVAL_SECONDS || parsed > MAX_INTERVAL_SECONDS) throw new Error(`Interval must be between ${MIN_INTERVAL_SECONDS} and ${MAX_INTERVAL_SECONDS} seconds.`);
|
|
23
|
-
return parsed;
|
|
24
|
-
}
|
|
25
|
-
function createSessionState(host) {
|
|
26
|
-
let launchers;
|
|
27
|
-
let defaultRegistration;
|
|
28
|
-
let unsubscribe;
|
|
29
|
-
let modeOwner;
|
|
30
|
-
const modeSelected = () => (host.context.selection.state?.["minor-mode"] ?? []).includes(MODE_ID);
|
|
31
|
-
const modeState = () => {
|
|
32
|
-
const launcherCount = launchers?.listLaunchers().length ?? 0;
|
|
33
|
-
const active = (launchers?.listInstances().length ?? 0) > 0;
|
|
34
|
-
const canStart = launcherCount > 0 || !modeSelected();
|
|
35
|
-
return {
|
|
36
|
-
activation: active ? "active" : "inactive",
|
|
37
|
-
condition: launchers?.listInstances().some(({ state }) => state !== "running") ? "queued" : "ready",
|
|
38
|
-
...active ? {
|
|
39
|
-
detail: `${launchers?.listInstances().length} active`,
|
|
40
|
-
color: "warning"
|
|
41
|
-
} : {},
|
|
42
|
-
actions: [{
|
|
43
|
-
id: "start",
|
|
44
|
-
enabled: canStart,
|
|
45
|
-
...canStart ? {} : { disabledReason: "No loop launchers are registered." }
|
|
46
|
-
}, {
|
|
47
|
-
id: "stop",
|
|
48
|
-
enabled: active,
|
|
49
|
-
...active ? {} : { disabledReason: "No loops are active." }
|
|
50
|
-
}]
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* The instances the activity dock lists.
|
|
55
|
-
*
|
|
56
|
-
* An empty list publishes an empty value rather than nothing, because the key
|
|
57
|
-
* being present is what keeps the group on screen as a launcher. The group
|
|
58
|
-
* declares no `hideWhenEmpty`, so an empty value is a header with no rows.
|
|
59
|
-
*/
|
|
60
|
-
const publishView = () => host.context.client.setStatus(require_loopView.LOOP_VIEW_STATUS_KEY, require_loopView.formatLoopStatusView(launchers?.listInstances() ?? []));
|
|
61
|
-
/** Both surfaces a loop shows up on: the minor-mode catalog and the activity dock. */
|
|
62
|
-
const publishMode = () => {
|
|
63
|
-
modeOwner?.publish();
|
|
64
|
-
publishView();
|
|
65
|
-
};
|
|
66
|
-
const startActivity = async (execution) => {
|
|
67
|
-
if (launchers !== void 0) return async () => void 0;
|
|
68
|
-
const dependencies = {
|
|
69
|
-
generation: `${execution.sessionId}:loop-launchers`,
|
|
70
|
-
createInstanceId: () => crypto.randomUUID(),
|
|
71
|
-
timestamp: () => (/* @__PURE__ */ new Date()).toISOString()
|
|
72
|
-
};
|
|
73
|
-
const service = require_index.createDoomLoopLaunchersService(dependencies);
|
|
74
|
-
const registration = service.register({
|
|
75
|
-
id: DEFAULT_LAUNCHER_ID,
|
|
76
|
-
source: SOURCE,
|
|
77
|
-
label: "Default loop",
|
|
78
|
-
description: "Run a prompt in this session on an interval.",
|
|
79
|
-
async launch({ instanceId, signal }) {
|
|
80
|
-
const promptValue = await execution.client.request({
|
|
81
|
-
kind: "input",
|
|
82
|
-
title: "Loop prompt",
|
|
83
|
-
multiline: true
|
|
84
|
-
}, signal);
|
|
85
|
-
const prompt = typeof promptValue === "string" ? promptValue.trim() : "";
|
|
86
|
-
if (!prompt || signal.aborted) return void 0;
|
|
87
|
-
const interval = numberInput(await execution.client.request({
|
|
88
|
-
kind: "input",
|
|
89
|
-
title: "Loop interval in seconds",
|
|
90
|
-
initialValue: String(DEFAULT_INTERVAL_SECONDS)
|
|
91
|
-
}, signal), DEFAULT_INTERVAL_SECONDS);
|
|
92
|
-
let stopped = false;
|
|
93
|
-
const tick = () => {
|
|
94
|
-
if (stopped || signal.aborted) return;
|
|
95
|
-
execution.session.prompt(prompt).catch((error) => {
|
|
96
|
-
notify(execution, `Loop pass failed: ${error instanceof Error ? error.message : String(error)}`, "warning");
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
|
-
const timer = setInterval(tick, interval * 1e3);
|
|
100
|
-
timer.unref?.();
|
|
101
|
-
tick();
|
|
102
|
-
return {
|
|
103
|
-
instanceId,
|
|
104
|
-
label: "Default loop",
|
|
105
|
-
detail: `every ${interval}s`,
|
|
106
|
-
stop() {
|
|
107
|
-
stopped = true;
|
|
108
|
-
clearInterval(timer);
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
launchers = service;
|
|
114
|
-
defaultRegistration = registration;
|
|
115
|
-
unsubscribe = service.subscribe(publishMode);
|
|
116
|
-
publishMode();
|
|
117
|
-
return async () => {
|
|
118
|
-
unsubscribe?.();
|
|
119
|
-
unsubscribe = void 0;
|
|
120
|
-
await registration.dispose("Headless loop activity stopped.");
|
|
121
|
-
await service.dispose("Headless loop activity stopped.");
|
|
122
|
-
if (launchers === service) launchers = void 0;
|
|
123
|
-
if (defaultRegistration === registration) defaultRegistration = void 0;
|
|
124
|
-
publishMode();
|
|
125
|
-
};
|
|
126
|
-
};
|
|
127
|
-
modeOwner = (0, _agimon_ai_doompi_minor_mode.defineMinorMode)({
|
|
128
|
-
descriptor: {
|
|
129
|
-
source: SOURCE,
|
|
130
|
-
id: MODE_ID,
|
|
131
|
-
label: "Loop",
|
|
132
|
-
description: "Session-scoped recurring prompt loops.",
|
|
133
|
-
order: 60,
|
|
134
|
-
actions: [{
|
|
135
|
-
id: "start",
|
|
136
|
-
label: "Start",
|
|
137
|
-
description: "Start a loop with a registered launcher.",
|
|
138
|
-
contexts: ["headless"],
|
|
139
|
-
parameters: [{
|
|
140
|
-
name: "launcherId",
|
|
141
|
-
label: "Launcher",
|
|
142
|
-
kind: "string",
|
|
143
|
-
required: true,
|
|
144
|
-
minLength: 1
|
|
145
|
-
}, {
|
|
146
|
-
name: "instanceId",
|
|
147
|
-
label: "Instance ID",
|
|
148
|
-
kind: "string",
|
|
149
|
-
required: false,
|
|
150
|
-
minLength: 1
|
|
151
|
-
}]
|
|
152
|
-
}, {
|
|
153
|
-
id: "stop",
|
|
154
|
-
label: "Stop",
|
|
155
|
-
description: "Stop one active loop instance.",
|
|
156
|
-
contexts: ["headless"],
|
|
157
|
-
parameters: [{
|
|
158
|
-
name: "instanceId",
|
|
159
|
-
label: "Instance ID",
|
|
160
|
-
kind: "string",
|
|
161
|
-
required: true,
|
|
162
|
-
minLength: 1
|
|
163
|
-
}, {
|
|
164
|
-
name: "reason",
|
|
165
|
-
label: "Reason",
|
|
166
|
-
kind: "string",
|
|
167
|
-
required: false,
|
|
168
|
-
minLength: 1
|
|
169
|
-
}]
|
|
170
|
-
}]
|
|
171
|
-
},
|
|
172
|
-
state: modeState,
|
|
173
|
-
async handleAction(_runtime, actionId, argumentsValue, { signal }) {
|
|
174
|
-
signal.throwIfAborted();
|
|
175
|
-
if (actionId === "start" && !launchers) {
|
|
176
|
-
const modes = (host.context.selection.state?.["minor-mode"] ?? []).filter((mode) => mode !== MODE_ID);
|
|
177
|
-
await host.changeSelection({
|
|
178
|
-
axis: "state",
|
|
179
|
-
key: "minor-mode",
|
|
180
|
-
values: [...modes, MODE_ID]
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
if (!launchers) throw new Error("Loop activity is not active.");
|
|
184
|
-
if (actionId === "start") {
|
|
185
|
-
const instance = await launchers.launch(String(argumentsValue.launcherId ?? ""), argumentsValue.instanceId ? { instanceId: String(argumentsValue.instanceId) } : {});
|
|
186
|
-
publishMode();
|
|
187
|
-
return { message: instance ? `Loop '${instance.instanceId}' started.` : "Loop launch was cancelled." };
|
|
188
|
-
}
|
|
189
|
-
if (actionId === "stop") {
|
|
190
|
-
const stopped = await launchers.stop(String(argumentsValue.instanceId ?? ""), String(argumentsValue.reason ?? "Stopped through minor_mode."));
|
|
191
|
-
if (stopped && launchers.listInstances().length === 0) {
|
|
192
|
-
const modes = (host.context.selection.state?.["minor-mode"] ?? []).filter((mode) => mode !== MODE_ID);
|
|
193
|
-
await host.changeSelection({
|
|
194
|
-
axis: "state",
|
|
195
|
-
key: "minor-mode",
|
|
196
|
-
values: modes
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
publishMode();
|
|
200
|
-
return { message: stopped ? "Loop stopped." : "Loop instance was not active." };
|
|
201
|
-
}
|
|
202
|
-
throw new Error(`Unknown loop mode action: ${actionId}`);
|
|
203
|
-
}
|
|
204
|
-
}).createOwner(void 0);
|
|
205
|
-
return {
|
|
206
|
-
services: [(0, _agimon_ai_doompi_minor_mode.serverMinorModes)([modeOwner])],
|
|
207
|
-
resources: [{
|
|
208
|
-
when: {
|
|
209
|
-
state: { "minor-mode": MODE_ID },
|
|
210
|
-
attribution: {
|
|
211
|
-
kind: "minor",
|
|
212
|
-
mode: MODE_ID
|
|
213
|
-
}
|
|
214
|
-
},
|
|
215
|
-
name: "doompi-use-loop",
|
|
216
|
-
kind: "skill",
|
|
217
|
-
read: () => (0, _agimon_ai_doompi_core_server_facet.readPackageResource)(require("url").pathToFileURL(__filename).href, "src/prompts/doompi-use-loop/SKILL.md")
|
|
218
|
-
}],
|
|
219
|
-
activities: [{
|
|
220
|
-
when: {
|
|
221
|
-
state: { "minor-mode": MODE_ID },
|
|
222
|
-
attribution: {
|
|
223
|
-
kind: "minor",
|
|
224
|
-
mode: MODE_ID
|
|
225
|
-
}
|
|
226
|
-
},
|
|
227
|
-
name: "doompi-loop",
|
|
228
|
-
start: startActivity
|
|
229
|
-
}],
|
|
230
|
-
commands: [{
|
|
231
|
-
name: require_loop.START_COMMAND_NAME,
|
|
232
|
-
description: "Start a registered loop.",
|
|
233
|
-
async execute(args, execution) {
|
|
234
|
-
if (!launchers) {
|
|
235
|
-
const modes = host.context.selection.state?.["minor-mode"] ?? [];
|
|
236
|
-
await host.changeSelection({
|
|
237
|
-
axis: "state",
|
|
238
|
-
key: "minor-mode",
|
|
239
|
-
values: [...modes, MODE_ID]
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
if (!launchers) throw new Error("Loop activity is not active.");
|
|
243
|
-
const available = launchers.listLaunchers();
|
|
244
|
-
const selected = args.trim() || await execution.client.request({
|
|
245
|
-
kind: "select",
|
|
246
|
-
title: "Choose a loop launcher",
|
|
247
|
-
options: available.map((entry) => ({
|
|
248
|
-
label: entry.label,
|
|
249
|
-
value: entry.id
|
|
250
|
-
}))
|
|
251
|
-
});
|
|
252
|
-
const launcherId = args.trim() || (typeof selected === "string" ? selected : "");
|
|
253
|
-
if (!launcherId) return;
|
|
254
|
-
const instance = await launchers.launch(launcherId);
|
|
255
|
-
publishMode();
|
|
256
|
-
await notify(execution, instance ? `Loop '${instance.instanceId}' started.` : "Loop launch was cancelled.");
|
|
257
|
-
}
|
|
258
|
-
}, {
|
|
259
|
-
name: require_loop.LIST_COMMAND_NAME,
|
|
260
|
-
description: "List and stop active loops.",
|
|
261
|
-
async execute(_args, execution) {
|
|
262
|
-
const instances = launchers?.listInstances() ?? [];
|
|
263
|
-
await notify(execution, instances.length === 0 ? "No loops are active." : JSON.stringify(instances, null, 2));
|
|
264
|
-
}
|
|
265
|
-
}],
|
|
266
|
-
hooks: [{
|
|
267
|
-
event: "session_start",
|
|
268
|
-
async handle() {
|
|
269
|
-
publishView();
|
|
270
|
-
}
|
|
271
|
-
}, {
|
|
272
|
-
when: {
|
|
273
|
-
state: { "minor-mode": MODE_ID },
|
|
274
|
-
attribution: {
|
|
275
|
-
kind: "minor",
|
|
276
|
-
mode: MODE_ID
|
|
277
|
-
}
|
|
278
|
-
},
|
|
279
|
-
event: "session_shutdown",
|
|
280
|
-
async handle() {
|
|
281
|
-
await launchers?.stopAll("Headless session shutdown.");
|
|
282
|
-
}
|
|
283
|
-
}],
|
|
284
|
-
async onDispose() {
|
|
285
|
-
await defaultRegistration?.dispose("Headless loop facet disposed.");
|
|
286
|
-
await launchers?.dispose("Headless loop facet disposed.");
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
//#endregion
|
|
291
|
-
exports.createSessionState = createSessionState;
|
|
292
|
-
|
|
293
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["LOOP_VIEW_STATUS_KEY","formatLoopStatusView","createDoomLoopLaunchersService","defineMinorMode","serverMinorModes","readPackageResource","START_COMMAND_NAME","LIST_COMMAND_NAME"],"sources":["../../../../src/services/serverRuntime/index.ts"],"sourcesContent":["import { serverMinorModes } from '@agimon-ai/doompi-minor-mode';\nimport { defineMinorMode, type MinorModeOwner, type MinorModeState } from '@agimon-ai/doompi-minor-mode';\n\nimport { LIST_COMMAND_NAME, START_COMMAND_NAME } from '../../constants/loop';\nimport type { DoomLoopLaunchersService, LoopLauncherRegistration, StoppableLoop } from '../../schemas/loopLaunchers';\nimport { createDoomLoopLaunchersService, type LoopLaunchersDependencies } from '../../services/loopLaunchers';\nimport { formatLoopStatusView, LOOP_VIEW_STATUS_KEY } from '../../types/loopView';\n\nconst SOURCE = '@agimon-ai/doompi-loop';\nconst MODE_ID = 'loop.active';\nconst DEFAULT_LAUNCHER_ID = 'doompi.default';\nconst DEFAULT_INTERVAL_SECONDS = 300;\nconst MIN_INTERVAL_SECONDS = 30;\nconst MAX_INTERVAL_SECONDS = 3600;\n\nfunction notify(\n context: {\n client: { notify(request: { body: string; level?: 'info' | 'warning' | 'error' }): void | Promise<void> };\n },\n body: string,\n level: 'info' | 'warning' | 'error' = 'info',\n): Promise<void> {\n return Promise.resolve(context.client.notify({ body, level }));\n}\n\nfunction numberInput(value: unknown, fallback: number): number {\n if (typeof value !== 'string' || value.trim() === '') return fallback;\n const parsed = Number(value);\n if (!Number.isInteger(parsed) || parsed < MIN_INTERVAL_SECONDS || parsed > MAX_INTERVAL_SECONDS) {\n throw new Error(`Interval must be between ${MIN_INTERVAL_SECONDS} and ${MAX_INTERVAL_SECONDS} seconds.`);\n }\n return parsed;\n}\n\nimport { type DoomHeadlessExecutionContext, type DoomHeadlessHostService } from '@agimon-ai/doompi-core/headless';\nimport { readPackageResource, type DoomServerSessionPlugin } from '@agimon-ai/doompi-core/server-facet';\nexport function createSessionState(host: DoomHeadlessHostService): DoomServerSessionPlugin {\n let launchers: DoomLoopLaunchersService | undefined;\n let defaultRegistration: LoopLauncherRegistration | undefined;\n let unsubscribe: (() => void) | undefined;\n let modeOwner: MinorModeOwner | undefined;\n const modeSelected = (): boolean => (host.context.selection.state?.['minor-mode'] ?? []).includes(MODE_ID);\n const modeState = (): MinorModeState => {\n const launcherCount = launchers?.listLaunchers().length ?? 0;\n const active = (launchers?.listInstances().length ?? 0) > 0;\n const canStart = launcherCount > 0 || !modeSelected();\n return {\n activation: active ? 'active' : 'inactive',\n condition: launchers?.listInstances().some(({ state }) => state !== 'running') ? 'queued' : 'ready',\n ...(active ? { detail: `${launchers?.listInstances().length} active`, color: 'warning' } : {}),\n actions: [\n {\n id: 'start',\n enabled: canStart,\n ...(canStart ? {} : { disabledReason: 'No loop launchers are registered.' }),\n },\n {\n id: 'stop',\n enabled: active,\n ...(active ? {} : { disabledReason: 'No loops are active.' }),\n },\n ],\n };\n };\n /**\n * The instances the activity dock lists.\n *\n * An empty list publishes an empty value rather than nothing, because the key\n * being present is what keeps the group on screen as a launcher. The group\n * declares no `hideWhenEmpty`, so an empty value is a header with no rows.\n */\n const publishView = (): void =>\n host.context.client.setStatus(LOOP_VIEW_STATUS_KEY, formatLoopStatusView(launchers?.listInstances() ?? []));\n /** Both surfaces a loop shows up on: the minor-mode catalog and the activity dock. */\n const publishMode = (): void => {\n modeOwner?.publish();\n publishView();\n };\n const startActivity = async (execution: typeof host.context): Promise<() => Promise<void>> => {\n if (launchers !== undefined) return async () => undefined;\n const dependencies: LoopLaunchersDependencies = {\n generation: `${execution.sessionId}:loop-launchers`,\n createInstanceId: () => crypto.randomUUID(),\n timestamp: () => new Date().toISOString(),\n };\n const service = createDoomLoopLaunchersService(dependencies);\n const registration = service.register({\n id: DEFAULT_LAUNCHER_ID,\n source: SOURCE,\n label: 'Default loop',\n description: 'Run a prompt in this session on an interval.',\n async launch({ instanceId, signal }): Promise<StoppableLoop | undefined> {\n const promptValue = await execution.client.request(\n { kind: 'input', title: 'Loop prompt', multiline: true },\n signal,\n );\n const prompt = typeof promptValue === 'string' ? promptValue.trim() : '';\n if (!prompt || signal.aborted) return undefined;\n const interval = numberInput(\n await execution.client.request(\n { kind: 'input', title: 'Loop interval in seconds', initialValue: String(DEFAULT_INTERVAL_SECONDS) },\n signal,\n ),\n DEFAULT_INTERVAL_SECONDS,\n );\n let stopped = false;\n const tick = (): void => {\n if (stopped || signal.aborted) return;\n void execution.session.prompt(prompt).catch((error) => {\n void notify(\n execution,\n `Loop pass failed: ${error instanceof Error ? error.message : String(error)}`,\n 'warning',\n );\n });\n };\n const timer = setInterval(tick, interval * 1000);\n timer.unref?.();\n tick();\n return {\n instanceId,\n label: 'Default loop',\n detail: `every ${interval}s`,\n stop() {\n stopped = true;\n clearInterval(timer);\n },\n };\n },\n });\n launchers = service;\n defaultRegistration = registration;\n unsubscribe = service.subscribe(publishMode);\n publishMode();\n return async () => {\n unsubscribe?.();\n unsubscribe = undefined;\n await registration.dispose('Headless loop activity stopped.');\n await service.dispose('Headless loop activity stopped.');\n if (launchers === service) launchers = undefined;\n if (defaultRegistration === registration) defaultRegistration = undefined;\n publishMode();\n };\n };\n modeOwner = defineMinorMode({\n descriptor: {\n source: SOURCE,\n id: MODE_ID,\n label: 'Loop',\n description: 'Session-scoped recurring prompt loops.',\n order: 60,\n actions: [\n {\n id: 'start',\n label: 'Start',\n description: 'Start a loop with a registered launcher.',\n contexts: ['headless'],\n parameters: [\n { name: 'launcherId', label: 'Launcher', kind: 'string', required: true, minLength: 1 },\n { name: 'instanceId', label: 'Instance ID', kind: 'string', required: false, minLength: 1 },\n ],\n },\n {\n id: 'stop',\n label: 'Stop',\n description: 'Stop one active loop instance.',\n contexts: ['headless'],\n parameters: [\n { name: 'instanceId', label: 'Instance ID', kind: 'string', required: true, minLength: 1 },\n { name: 'reason', label: 'Reason', kind: 'string', required: false, minLength: 1 },\n ],\n },\n ],\n },\n state: modeState,\n async handleAction(_runtime, actionId, argumentsValue, { signal }) {\n signal.throwIfAborted();\n if (actionId === 'start' && !launchers) {\n const modes = (host.context.selection.state?.['minor-mode'] ?? []).filter((mode) => mode !== MODE_ID);\n await host.changeSelection({ axis: 'state', key: 'minor-mode', values: [...modes, MODE_ID] });\n }\n if (!launchers) throw new Error('Loop activity is not active.');\n if (actionId === 'start') {\n const instance = await launchers.launch(\n String(argumentsValue.launcherId ?? ''),\n argumentsValue.instanceId ? { instanceId: String(argumentsValue.instanceId) } : {},\n );\n publishMode();\n return { message: instance ? `Loop '${instance.instanceId}' started.` : 'Loop launch was cancelled.' };\n }\n if (actionId === 'stop') {\n const stopped = await launchers.stop(\n String(argumentsValue.instanceId ?? ''),\n String(argumentsValue.reason ?? 'Stopped through minor_mode.'),\n );\n if (stopped && launchers.listInstances().length === 0) {\n const modes = (host.context.selection.state?.['minor-mode'] ?? []).filter((mode) => mode !== MODE_ID);\n await host.changeSelection({ axis: 'state', key: 'minor-mode', values: modes });\n }\n publishMode();\n return { message: stopped ? 'Loop stopped.' : 'Loop instance was not active.' };\n }\n throw new Error(`Unknown loop mode action: ${actionId}`);\n },\n }).createOwner(undefined);\n return {\n services: [serverMinorModes([modeOwner])],\n resources: [\n {\n when: { state: { 'minor-mode': MODE_ID }, attribution: { kind: 'minor', mode: MODE_ID } },\n name: 'doompi-use-loop',\n kind: 'skill',\n read: () => readPackageResource(import.meta.url, 'src/prompts/doompi-use-loop/SKILL.md'),\n },\n ],\n activities: [\n {\n when: { state: { 'minor-mode': MODE_ID }, attribution: { kind: 'minor', mode: MODE_ID } },\n name: 'doompi-loop',\n start: startActivity,\n },\n ],\n commands: [\n {\n name: START_COMMAND_NAME,\n description: 'Start a registered loop.',\n async execute(args: string, execution: DoomHeadlessExecutionContext) {\n if (!launchers) {\n const modes = host.context.selection.state?.['minor-mode'] ?? [];\n await host.changeSelection({ axis: 'state', key: 'minor-mode', values: [...modes, MODE_ID] });\n }\n if (!launchers) throw new Error('Loop activity is not active.');\n const available = launchers.listLaunchers();\n const selected =\n args.trim() ||\n (await execution.client.request({\n kind: 'select',\n title: 'Choose a loop launcher',\n options: available.map((entry) => ({ label: entry.label, value: entry.id })),\n }));\n const launcherId = args.trim() || (typeof selected === 'string' ? selected : '');\n if (!launcherId) return;\n const instance = await launchers.launch(launcherId);\n publishMode();\n await notify(execution, instance ? `Loop '${instance.instanceId}' started.` : 'Loop launch was cancelled.');\n },\n },\n {\n name: LIST_COMMAND_NAME,\n description: 'List and stop active loops.',\n async execute(_args: string, execution: DoomHeadlessExecutionContext) {\n const instances = launchers?.listInstances() ?? [];\n await notify(execution, instances.length === 0 ? 'No loops are active.' : JSON.stringify(instances, null, 2));\n },\n },\n ],\n hooks: [\n {\n // Ungated on purpose: the dock's loops group is a way in, so it has to\n // exist before anyone selects loop mode. The activity below is gated on\n // that selection and cannot do this job.\n event: 'session_start',\n async handle() {\n publishView();\n },\n },\n {\n when: { state: { 'minor-mode': MODE_ID }, attribution: { kind: 'minor', mode: MODE_ID } },\n event: 'session_shutdown',\n async handle() {\n await launchers?.stopAll('Headless session shutdown.');\n },\n },\n ],\n async onDispose() {\n await defaultRegistration?.dispose('Headless loop facet disposed.');\n await launchers?.dispose('Headless loop facet disposed.');\n },\n };\n}\n"],"mappings":";;;;;;AAQA,MAAM,SAAS;AAC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EACF,CACF;EACA,MAAM,YAAY;GAChB,MAAM,qBAAqB,QAAQ,+BAA+B;GAClE,MAAM,WAAW,QAAQ,+BAA+B;EAC1D;CACF;AACF"}
|
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
import { LIST_COMMAND_NAME, START_COMMAND_NAME } from "../../constants/loop.mjs";
|
|
2
|
-
import { createDoomLoopLaunchersService } from "../loopLaunchers/index.mjs";
|
|
3
|
-
import { LOOP_VIEW_STATUS_KEY, formatLoopStatusView } from "../../types/loopView.mjs";
|
|
4
|
-
import { defineMinorMode, serverMinorModes } from "@agimon-ai/doompi-minor-mode";
|
|
5
|
-
import { readPackageResource } from "@agimon-ai/doompi-core/server-facet";
|
|
6
|
-
//#region src/services/serverRuntime/index.ts
|
|
7
|
-
const SOURCE = "@agimon-ai/doompi-loop";
|
|
8
|
-
const MODE_ID = "loop.active";
|
|
9
|
-
const DEFAULT_LAUNCHER_ID = "doompi.default";
|
|
10
|
-
const DEFAULT_INTERVAL_SECONDS = 300;
|
|
11
|
-
const MIN_INTERVAL_SECONDS = 30;
|
|
12
|
-
const MAX_INTERVAL_SECONDS = 3600;
|
|
13
|
-
function notify(context, body, level = "info") {
|
|
14
|
-
return Promise.resolve(context.client.notify({
|
|
15
|
-
body,
|
|
16
|
-
level
|
|
17
|
-
}));
|
|
18
|
-
}
|
|
19
|
-
function numberInput(value, fallback) {
|
|
20
|
-
if (typeof value !== "string" || value.trim() === "") return fallback;
|
|
21
|
-
const parsed = Number(value);
|
|
22
|
-
if (!Number.isInteger(parsed) || parsed < MIN_INTERVAL_SECONDS || parsed > MAX_INTERVAL_SECONDS) throw new Error(`Interval must be between ${MIN_INTERVAL_SECONDS} and ${MAX_INTERVAL_SECONDS} seconds.`);
|
|
23
|
-
return parsed;
|
|
24
|
-
}
|
|
25
|
-
function createSessionState(host) {
|
|
26
|
-
let launchers;
|
|
27
|
-
let defaultRegistration;
|
|
28
|
-
let unsubscribe;
|
|
29
|
-
let modeOwner;
|
|
30
|
-
const modeSelected = () => (host.context.selection.state?.["minor-mode"] ?? []).includes(MODE_ID);
|
|
31
|
-
const modeState = () => {
|
|
32
|
-
const launcherCount = launchers?.listLaunchers().length ?? 0;
|
|
33
|
-
const active = (launchers?.listInstances().length ?? 0) > 0;
|
|
34
|
-
const canStart = launcherCount > 0 || !modeSelected();
|
|
35
|
-
return {
|
|
36
|
-
activation: active ? "active" : "inactive",
|
|
37
|
-
condition: launchers?.listInstances().some(({ state }) => state !== "running") ? "queued" : "ready",
|
|
38
|
-
...active ? {
|
|
39
|
-
detail: `${launchers?.listInstances().length} active`,
|
|
40
|
-
color: "warning"
|
|
41
|
-
} : {},
|
|
42
|
-
actions: [{
|
|
43
|
-
id: "start",
|
|
44
|
-
enabled: canStart,
|
|
45
|
-
...canStart ? {} : { disabledReason: "No loop launchers are registered." }
|
|
46
|
-
}, {
|
|
47
|
-
id: "stop",
|
|
48
|
-
enabled: active,
|
|
49
|
-
...active ? {} : { disabledReason: "No loops are active." }
|
|
50
|
-
}]
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* The instances the activity dock lists.
|
|
55
|
-
*
|
|
56
|
-
* An empty list publishes an empty value rather than nothing, because the key
|
|
57
|
-
* being present is what keeps the group on screen as a launcher. The group
|
|
58
|
-
* declares no `hideWhenEmpty`, so an empty value is a header with no rows.
|
|
59
|
-
*/
|
|
60
|
-
const publishView = () => host.context.client.setStatus(LOOP_VIEW_STATUS_KEY, formatLoopStatusView(launchers?.listInstances() ?? []));
|
|
61
|
-
/** Both surfaces a loop shows up on: the minor-mode catalog and the activity dock. */
|
|
62
|
-
const publishMode = () => {
|
|
63
|
-
modeOwner?.publish();
|
|
64
|
-
publishView();
|
|
65
|
-
};
|
|
66
|
-
const startActivity = async (execution) => {
|
|
67
|
-
if (launchers !== void 0) return async () => void 0;
|
|
68
|
-
const dependencies = {
|
|
69
|
-
generation: `${execution.sessionId}:loop-launchers`,
|
|
70
|
-
createInstanceId: () => crypto.randomUUID(),
|
|
71
|
-
timestamp: () => (/* @__PURE__ */ new Date()).toISOString()
|
|
72
|
-
};
|
|
73
|
-
const service = createDoomLoopLaunchersService(dependencies);
|
|
74
|
-
const registration = service.register({
|
|
75
|
-
id: DEFAULT_LAUNCHER_ID,
|
|
76
|
-
source: SOURCE,
|
|
77
|
-
label: "Default loop",
|
|
78
|
-
description: "Run a prompt in this session on an interval.",
|
|
79
|
-
async launch({ instanceId, signal }) {
|
|
80
|
-
const promptValue = await execution.client.request({
|
|
81
|
-
kind: "input",
|
|
82
|
-
title: "Loop prompt",
|
|
83
|
-
multiline: true
|
|
84
|
-
}, signal);
|
|
85
|
-
const prompt = typeof promptValue === "string" ? promptValue.trim() : "";
|
|
86
|
-
if (!prompt || signal.aborted) return void 0;
|
|
87
|
-
const interval = numberInput(await execution.client.request({
|
|
88
|
-
kind: "input",
|
|
89
|
-
title: "Loop interval in seconds",
|
|
90
|
-
initialValue: String(DEFAULT_INTERVAL_SECONDS)
|
|
91
|
-
}, signal), DEFAULT_INTERVAL_SECONDS);
|
|
92
|
-
let stopped = false;
|
|
93
|
-
const tick = () => {
|
|
94
|
-
if (stopped || signal.aborted) return;
|
|
95
|
-
execution.session.prompt(prompt).catch((error) => {
|
|
96
|
-
notify(execution, `Loop pass failed: ${error instanceof Error ? error.message : String(error)}`, "warning");
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
|
-
const timer = setInterval(tick, interval * 1e3);
|
|
100
|
-
timer.unref?.();
|
|
101
|
-
tick();
|
|
102
|
-
return {
|
|
103
|
-
instanceId,
|
|
104
|
-
label: "Default loop",
|
|
105
|
-
detail: `every ${interval}s`,
|
|
106
|
-
stop() {
|
|
107
|
-
stopped = true;
|
|
108
|
-
clearInterval(timer);
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
launchers = service;
|
|
114
|
-
defaultRegistration = registration;
|
|
115
|
-
unsubscribe = service.subscribe(publishMode);
|
|
116
|
-
publishMode();
|
|
117
|
-
return async () => {
|
|
118
|
-
unsubscribe?.();
|
|
119
|
-
unsubscribe = void 0;
|
|
120
|
-
await registration.dispose("Headless loop activity stopped.");
|
|
121
|
-
await service.dispose("Headless loop activity stopped.");
|
|
122
|
-
if (launchers === service) launchers = void 0;
|
|
123
|
-
if (defaultRegistration === registration) defaultRegistration = void 0;
|
|
124
|
-
publishMode();
|
|
125
|
-
};
|
|
126
|
-
};
|
|
127
|
-
modeOwner = defineMinorMode({
|
|
128
|
-
descriptor: {
|
|
129
|
-
source: SOURCE,
|
|
130
|
-
id: MODE_ID,
|
|
131
|
-
label: "Loop",
|
|
132
|
-
description: "Session-scoped recurring prompt loops.",
|
|
133
|
-
order: 60,
|
|
134
|
-
actions: [{
|
|
135
|
-
id: "start",
|
|
136
|
-
label: "Start",
|
|
137
|
-
description: "Start a loop with a registered launcher.",
|
|
138
|
-
contexts: ["headless"],
|
|
139
|
-
parameters: [{
|
|
140
|
-
name: "launcherId",
|
|
141
|
-
label: "Launcher",
|
|
142
|
-
kind: "string",
|
|
143
|
-
required: true,
|
|
144
|
-
minLength: 1
|
|
145
|
-
}, {
|
|
146
|
-
name: "instanceId",
|
|
147
|
-
label: "Instance ID",
|
|
148
|
-
kind: "string",
|
|
149
|
-
required: false,
|
|
150
|
-
minLength: 1
|
|
151
|
-
}]
|
|
152
|
-
}, {
|
|
153
|
-
id: "stop",
|
|
154
|
-
label: "Stop",
|
|
155
|
-
description: "Stop one active loop instance.",
|
|
156
|
-
contexts: ["headless"],
|
|
157
|
-
parameters: [{
|
|
158
|
-
name: "instanceId",
|
|
159
|
-
label: "Instance ID",
|
|
160
|
-
kind: "string",
|
|
161
|
-
required: true,
|
|
162
|
-
minLength: 1
|
|
163
|
-
}, {
|
|
164
|
-
name: "reason",
|
|
165
|
-
label: "Reason",
|
|
166
|
-
kind: "string",
|
|
167
|
-
required: false,
|
|
168
|
-
minLength: 1
|
|
169
|
-
}]
|
|
170
|
-
}]
|
|
171
|
-
},
|
|
172
|
-
state: modeState,
|
|
173
|
-
async handleAction(_runtime, actionId, argumentsValue, { signal }) {
|
|
174
|
-
signal.throwIfAborted();
|
|
175
|
-
if (actionId === "start" && !launchers) {
|
|
176
|
-
const modes = (host.context.selection.state?.["minor-mode"] ?? []).filter((mode) => mode !== MODE_ID);
|
|
177
|
-
await host.changeSelection({
|
|
178
|
-
axis: "state",
|
|
179
|
-
key: "minor-mode",
|
|
180
|
-
values: [...modes, MODE_ID]
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
if (!launchers) throw new Error("Loop activity is not active.");
|
|
184
|
-
if (actionId === "start") {
|
|
185
|
-
const instance = await launchers.launch(String(argumentsValue.launcherId ?? ""), argumentsValue.instanceId ? { instanceId: String(argumentsValue.instanceId) } : {});
|
|
186
|
-
publishMode();
|
|
187
|
-
return { message: instance ? `Loop '${instance.instanceId}' started.` : "Loop launch was cancelled." };
|
|
188
|
-
}
|
|
189
|
-
if (actionId === "stop") {
|
|
190
|
-
const stopped = await launchers.stop(String(argumentsValue.instanceId ?? ""), String(argumentsValue.reason ?? "Stopped through minor_mode."));
|
|
191
|
-
if (stopped && launchers.listInstances().length === 0) {
|
|
192
|
-
const modes = (host.context.selection.state?.["minor-mode"] ?? []).filter((mode) => mode !== MODE_ID);
|
|
193
|
-
await host.changeSelection({
|
|
194
|
-
axis: "state",
|
|
195
|
-
key: "minor-mode",
|
|
196
|
-
values: modes
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
publishMode();
|
|
200
|
-
return { message: stopped ? "Loop stopped." : "Loop instance was not active." };
|
|
201
|
-
}
|
|
202
|
-
throw new Error(`Unknown loop mode action: ${actionId}`);
|
|
203
|
-
}
|
|
204
|
-
}).createOwner(void 0);
|
|
205
|
-
return {
|
|
206
|
-
services: [serverMinorModes([modeOwner])],
|
|
207
|
-
resources: [{
|
|
208
|
-
when: {
|
|
209
|
-
state: { "minor-mode": MODE_ID },
|
|
210
|
-
attribution: {
|
|
211
|
-
kind: "minor",
|
|
212
|
-
mode: MODE_ID
|
|
213
|
-
}
|
|
214
|
-
},
|
|
215
|
-
name: "doompi-use-loop",
|
|
216
|
-
kind: "skill",
|
|
217
|
-
read: () => readPackageResource(import.meta.url, "src/prompts/doompi-use-loop/SKILL.md")
|
|
218
|
-
}],
|
|
219
|
-
activities: [{
|
|
220
|
-
when: {
|
|
221
|
-
state: { "minor-mode": MODE_ID },
|
|
222
|
-
attribution: {
|
|
223
|
-
kind: "minor",
|
|
224
|
-
mode: MODE_ID
|
|
225
|
-
}
|
|
226
|
-
},
|
|
227
|
-
name: "doompi-loop",
|
|
228
|
-
start: startActivity
|
|
229
|
-
}],
|
|
230
|
-
commands: [{
|
|
231
|
-
name: START_COMMAND_NAME,
|
|
232
|
-
description: "Start a registered loop.",
|
|
233
|
-
async execute(args, execution) {
|
|
234
|
-
if (!launchers) {
|
|
235
|
-
const modes = host.context.selection.state?.["minor-mode"] ?? [];
|
|
236
|
-
await host.changeSelection({
|
|
237
|
-
axis: "state",
|
|
238
|
-
key: "minor-mode",
|
|
239
|
-
values: [...modes, MODE_ID]
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
if (!launchers) throw new Error("Loop activity is not active.");
|
|
243
|
-
const available = launchers.listLaunchers();
|
|
244
|
-
const selected = args.trim() || await execution.client.request({
|
|
245
|
-
kind: "select",
|
|
246
|
-
title: "Choose a loop launcher",
|
|
247
|
-
options: available.map((entry) => ({
|
|
248
|
-
label: entry.label,
|
|
249
|
-
value: entry.id
|
|
250
|
-
}))
|
|
251
|
-
});
|
|
252
|
-
const launcherId = args.trim() || (typeof selected === "string" ? selected : "");
|
|
253
|
-
if (!launcherId) return;
|
|
254
|
-
const instance = await launchers.launch(launcherId);
|
|
255
|
-
publishMode();
|
|
256
|
-
await notify(execution, instance ? `Loop '${instance.instanceId}' started.` : "Loop launch was cancelled.");
|
|
257
|
-
}
|
|
258
|
-
}, {
|
|
259
|
-
name: LIST_COMMAND_NAME,
|
|
260
|
-
description: "List and stop active loops.",
|
|
261
|
-
async execute(_args, execution) {
|
|
262
|
-
const instances = launchers?.listInstances() ?? [];
|
|
263
|
-
await notify(execution, instances.length === 0 ? "No loops are active." : JSON.stringify(instances, null, 2));
|
|
264
|
-
}
|
|
265
|
-
}],
|
|
266
|
-
hooks: [{
|
|
267
|
-
event: "session_start",
|
|
268
|
-
async handle() {
|
|
269
|
-
publishView();
|
|
270
|
-
}
|
|
271
|
-
}, {
|
|
272
|
-
when: {
|
|
273
|
-
state: { "minor-mode": MODE_ID },
|
|
274
|
-
attribution: {
|
|
275
|
-
kind: "minor",
|
|
276
|
-
mode: MODE_ID
|
|
277
|
-
}
|
|
278
|
-
},
|
|
279
|
-
event: "session_shutdown",
|
|
280
|
-
async handle() {
|
|
281
|
-
await launchers?.stopAll("Headless session shutdown.");
|
|
282
|
-
}
|
|
283
|
-
}],
|
|
284
|
-
async onDispose() {
|
|
285
|
-
await defaultRegistration?.dispose("Headless loop facet disposed.");
|
|
286
|
-
await launchers?.dispose("Headless loop facet disposed.");
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
//#endregion
|
|
291
|
-
export { createSessionState };
|
|
292
|
-
|
|
293
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/services/serverRuntime/index.ts"],"sourcesContent":["import { serverMinorModes } from '@agimon-ai/doompi-minor-mode';\nimport { defineMinorMode, type MinorModeOwner, type MinorModeState } from '@agimon-ai/doompi-minor-mode';\n\nimport { LIST_COMMAND_NAME, START_COMMAND_NAME } from '../../constants/loop';\nimport type { DoomLoopLaunchersService, LoopLauncherRegistration, StoppableLoop } from '../../schemas/loopLaunchers';\nimport { createDoomLoopLaunchersService, type LoopLaunchersDependencies } from '../../services/loopLaunchers';\nimport { formatLoopStatusView, LOOP_VIEW_STATUS_KEY } from '../../types/loopView';\n\nconst SOURCE = '@agimon-ai/doompi-loop';\nconst MODE_ID = 'loop.active';\nconst DEFAULT_LAUNCHER_ID = 'doompi.default';\nconst DEFAULT_INTERVAL_SECONDS = 300;\nconst MIN_INTERVAL_SECONDS = 30;\nconst MAX_INTERVAL_SECONDS = 3600;\n\nfunction notify(\n context: {\n client: { notify(request: { body: string; level?: 'info' | 'warning' | 'error' }): void | Promise<void> };\n },\n body: string,\n level: 'info' | 'warning' | 'error' = 'info',\n): Promise<void> {\n return Promise.resolve(context.client.notify({ body, level }));\n}\n\nfunction numberInput(value: unknown, fallback: number): number {\n if (typeof value !== 'string' || value.trim() === '') return fallback;\n const parsed = Number(value);\n if (!Number.isInteger(parsed) || parsed < MIN_INTERVAL_SECONDS || parsed > MAX_INTERVAL_SECONDS) {\n throw new Error(`Interval must be between ${MIN_INTERVAL_SECONDS} and ${MAX_INTERVAL_SECONDS} seconds.`);\n }\n return parsed;\n}\n\nimport { type DoomHeadlessExecutionContext, type DoomHeadlessHostService } from '@agimon-ai/doompi-core/headless';\nimport { readPackageResource, type DoomServerSessionPlugin } from '@agimon-ai/doompi-core/server-facet';\nexport function createSessionState(host: DoomHeadlessHostService): DoomServerSessionPlugin {\n let launchers: DoomLoopLaunchersService | undefined;\n let defaultRegistration: LoopLauncherRegistration | undefined;\n let unsubscribe: (() => void) | undefined;\n let modeOwner: MinorModeOwner | undefined;\n const modeSelected = (): boolean => (host.context.selection.state?.['minor-mode'] ?? []).includes(MODE_ID);\n const modeState = (): MinorModeState => {\n const launcherCount = launchers?.listLaunchers().length ?? 0;\n const active = (launchers?.listInstances().length ?? 0) > 0;\n const canStart = launcherCount > 0 || !modeSelected();\n return {\n activation: active ? 'active' : 'inactive',\n condition: launchers?.listInstances().some(({ state }) => state !== 'running') ? 'queued' : 'ready',\n ...(active ? { detail: `${launchers?.listInstances().length} active`, color: 'warning' } : {}),\n actions: [\n {\n id: 'start',\n enabled: canStart,\n ...(canStart ? {} : { disabledReason: 'No loop launchers are registered.' }),\n },\n {\n id: 'stop',\n enabled: active,\n ...(active ? {} : { disabledReason: 'No loops are active.' }),\n },\n ],\n };\n };\n /**\n * The instances the activity dock lists.\n *\n * An empty list publishes an empty value rather than nothing, because the key\n * being present is what keeps the group on screen as a launcher. The group\n * declares no `hideWhenEmpty`, so an empty value is a header with no rows.\n */\n const publishView = (): void =>\n host.context.client.setStatus(LOOP_VIEW_STATUS_KEY, formatLoopStatusView(launchers?.listInstances() ?? []));\n /** Both surfaces a loop shows up on: the minor-mode catalog and the activity dock. */\n const publishMode = (): void => {\n modeOwner?.publish();\n publishView();\n };\n const startActivity = async (execution: typeof host.context): Promise<() => Promise<void>> => {\n if (launchers !== undefined) return async () => undefined;\n const dependencies: LoopLaunchersDependencies = {\n generation: `${execution.sessionId}:loop-launchers`,\n createInstanceId: () => crypto.randomUUID(),\n timestamp: () => new Date().toISOString(),\n };\n const service = createDoomLoopLaunchersService(dependencies);\n const registration = service.register({\n id: DEFAULT_LAUNCHER_ID,\n source: SOURCE,\n label: 'Default loop',\n description: 'Run a prompt in this session on an interval.',\n async launch({ instanceId, signal }): Promise<StoppableLoop | undefined> {\n const promptValue = await execution.client.request(\n { kind: 'input', title: 'Loop prompt', multiline: true },\n signal,\n );\n const prompt = typeof promptValue === 'string' ? promptValue.trim() : '';\n if (!prompt || signal.aborted) return undefined;\n const interval = numberInput(\n await execution.client.request(\n { kind: 'input', title: 'Loop interval in seconds', initialValue: String(DEFAULT_INTERVAL_SECONDS) },\n signal,\n ),\n DEFAULT_INTERVAL_SECONDS,\n );\n let stopped = false;\n const tick = (): void => {\n if (stopped || signal.aborted) return;\n void execution.session.prompt(prompt).catch((error) => {\n void notify(\n execution,\n `Loop pass failed: ${error instanceof Error ? error.message : String(error)}`,\n 'warning',\n );\n });\n };\n const timer = setInterval(tick, interval * 1000);\n timer.unref?.();\n tick();\n return {\n instanceId,\n label: 'Default loop',\n detail: `every ${interval}s`,\n stop() {\n stopped = true;\n clearInterval(timer);\n },\n };\n },\n });\n launchers = service;\n defaultRegistration = registration;\n unsubscribe = service.subscribe(publishMode);\n publishMode();\n return async () => {\n unsubscribe?.();\n unsubscribe = undefined;\n await registration.dispose('Headless loop activity stopped.');\n await service.dispose('Headless loop activity stopped.');\n if (launchers === service) launchers = undefined;\n if (defaultRegistration === registration) defaultRegistration = undefined;\n publishMode();\n };\n };\n modeOwner = defineMinorMode({\n descriptor: {\n source: SOURCE,\n id: MODE_ID,\n label: 'Loop',\n description: 'Session-scoped recurring prompt loops.',\n order: 60,\n actions: [\n {\n id: 'start',\n label: 'Start',\n description: 'Start a loop with a registered launcher.',\n contexts: ['headless'],\n parameters: [\n { name: 'launcherId', label: 'Launcher', kind: 'string', required: true, minLength: 1 },\n { name: 'instanceId', label: 'Instance ID', kind: 'string', required: false, minLength: 1 },\n ],\n },\n {\n id: 'stop',\n label: 'Stop',\n description: 'Stop one active loop instance.',\n contexts: ['headless'],\n parameters: [\n { name: 'instanceId', label: 'Instance ID', kind: 'string', required: true, minLength: 1 },\n { name: 'reason', label: 'Reason', kind: 'string', required: false, minLength: 1 },\n ],\n },\n ],\n },\n state: modeState,\n async handleAction(_runtime, actionId, argumentsValue, { signal }) {\n signal.throwIfAborted();\n if (actionId === 'start' && !launchers) {\n const modes = (host.context.selection.state?.['minor-mode'] ?? []).filter((mode) => mode !== MODE_ID);\n await host.changeSelection({ axis: 'state', key: 'minor-mode', values: [...modes, MODE_ID] });\n }\n if (!launchers) throw new Error('Loop activity is not active.');\n if (actionId === 'start') {\n const instance = await launchers.launch(\n String(argumentsValue.launcherId ?? ''),\n argumentsValue.instanceId ? { instanceId: String(argumentsValue.instanceId) } : {},\n );\n publishMode();\n return { message: instance ? `Loop '${instance.instanceId}' started.` : 'Loop launch was cancelled.' };\n }\n if (actionId === 'stop') {\n const stopped = await launchers.stop(\n String(argumentsValue.instanceId ?? ''),\n String(argumentsValue.reason ?? 'Stopped through minor_mode.'),\n );\n if (stopped && launchers.listInstances().length === 0) {\n const modes = (host.context.selection.state?.['minor-mode'] ?? []).filter((mode) => mode !== MODE_ID);\n await host.changeSelection({ axis: 'state', key: 'minor-mode', values: modes });\n }\n publishMode();\n return { message: stopped ? 'Loop stopped.' : 'Loop instance was not active.' };\n }\n throw new Error(`Unknown loop mode action: ${actionId}`);\n },\n }).createOwner(undefined);\n return {\n services: [serverMinorModes([modeOwner])],\n resources: [\n {\n when: { state: { 'minor-mode': MODE_ID }, attribution: { kind: 'minor', mode: MODE_ID } },\n name: 'doompi-use-loop',\n kind: 'skill',\n read: () => readPackageResource(import.meta.url, 'src/prompts/doompi-use-loop/SKILL.md'),\n },\n ],\n activities: [\n {\n when: { state: { 'minor-mode': MODE_ID }, attribution: { kind: 'minor', mode: MODE_ID } },\n name: 'doompi-loop',\n start: startActivity,\n },\n ],\n commands: [\n {\n name: START_COMMAND_NAME,\n description: 'Start a registered loop.',\n async execute(args: string, execution: DoomHeadlessExecutionContext) {\n if (!launchers) {\n const modes = host.context.selection.state?.['minor-mode'] ?? [];\n await host.changeSelection({ axis: 'state', key: 'minor-mode', values: [...modes, MODE_ID] });\n }\n if (!launchers) throw new Error('Loop activity is not active.');\n const available = launchers.listLaunchers();\n const selected =\n args.trim() ||\n (await execution.client.request({\n kind: 'select',\n title: 'Choose a loop launcher',\n options: available.map((entry) => ({ label: entry.label, value: entry.id })),\n }));\n const launcherId = args.trim() || (typeof selected === 'string' ? selected : '');\n if (!launcherId) return;\n const instance = await launchers.launch(launcherId);\n publishMode();\n await notify(execution, instance ? `Loop '${instance.instanceId}' started.` : 'Loop launch was cancelled.');\n },\n },\n {\n name: LIST_COMMAND_NAME,\n description: 'List and stop active loops.',\n async execute(_args: string, execution: DoomHeadlessExecutionContext) {\n const instances = launchers?.listInstances() ?? [];\n await notify(execution, instances.length === 0 ? 'No loops are active.' : JSON.stringify(instances, null, 2));\n },\n },\n ],\n hooks: [\n {\n // Ungated on purpose: the dock's loops group is a way in, so it has to\n // exist before anyone selects loop mode. The activity below is gated on\n // that selection and cannot do this job.\n event: 'session_start',\n async handle() {\n publishView();\n },\n },\n {\n when: { state: { 'minor-mode': MODE_ID }, attribution: { kind: 'minor', mode: MODE_ID } },\n event: 'session_shutdown',\n async handle() {\n await launchers?.stopAll('Headless session shutdown.');\n },\n },\n ],\n async onDispose() {\n await defaultRegistration?.dispose('Headless loop facet disposed.');\n await launchers?.dispose('Headless loop facet disposed.');\n },\n };\n}\n"],"mappings":";;;;;;AAQA,MAAM,SAAS;AACf,MAAM,UAAU;AAChB,MAAM,sBAAsB;AAC5B,MAAM,2BAA2B;AACjC,MAAM,uBAAuB;AAC7B,MAAM,uBAAuB;AAE7B,SAAS,OACP,SAGA,MACA,QAAsC,QACvB;CACf,OAAO,QAAQ,QAAQ,QAAQ,OAAO,OAAO;EAAE;EAAM;CAAM,CAAC,CAAC;AAC/D;AAEA,SAAS,YAAY,OAAgB,UAA0B;CAC7D,IAAI,OAAO,UAAU,YAAY,MAAM,KAAK,MAAM,IAAI,OAAO;CAC7D,MAAM,SAAS,OAAO,KAAK;CAC3B,IAAI,CAAC,OAAO,UAAU,MAAM,KAAK,SAAS,wBAAwB,SAAS,sBACzE,MAAM,IAAI,MAAM,4BAA4B,qBAAqB,OAAO,qBAAqB,UAAU;CAEzG,OAAO;AACT;AAIA,SAAgB,mBAAmB,MAAwD;CACzF,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,MAAM,sBAA+B,KAAK,QAAQ,UAAU,QAAQ,iBAAiB,CAAC,EAAA,CAAG,SAAS,OAAO;CACzG,MAAM,kBAAkC;EACtC,MAAM,gBAAgB,WAAW,cAAc,CAAC,CAAC,UAAU;EAC3D,MAAM,UAAU,WAAW,cAAc,CAAC,CAAC,UAAU,KAAK;EAC1D,MAAM,WAAW,gBAAgB,KAAK,CAAC,aAAa;EACpD,OAAO;GACL,YAAY,SAAS,WAAW;GAChC,WAAW,WAAW,cAAc,CAAC,CAAC,MAAM,EAAE,YAAY,UAAU,SAAS,IAAI,WAAW;GAC5F,GAAI,SAAS;IAA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