@w32191/just-loop 0.1.2 → 0.1.3
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.
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type LoopCore = {
|
|
2
|
+
startLoop: (sessionID: string, prompt: string, options: {
|
|
3
|
+
maxIterations?: number;
|
|
4
|
+
completionPromise?: string;
|
|
5
|
+
}) => Promise<unknown>;
|
|
6
|
+
cancelLoop: (sessionID: string) => Promise<unknown>;
|
|
7
|
+
};
|
|
8
|
+
type CommandExecuteBeforeInput = {
|
|
9
|
+
command?: unknown;
|
|
10
|
+
sessionID?: unknown;
|
|
11
|
+
arguments?: unknown;
|
|
12
|
+
};
|
|
13
|
+
type CommandExecuteBeforeOptions = {
|
|
14
|
+
defaultMaxIterations?: number;
|
|
15
|
+
};
|
|
16
|
+
export declare function handleCommandExecuteBefore(input: CommandExecuteBeforeInput, core: LoopCore, options?: CommandExecuteBeforeOptions): Promise<void>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { parseRalphLoopCommand } from "../commands/parse-ralph-loop-command.js";
|
|
2
|
+
function buildCommandLine(command, args) {
|
|
3
|
+
const normalized = command.startsWith("/") ? command : `/${command}`;
|
|
4
|
+
const trimmedArgs = args.trim();
|
|
5
|
+
return trimmedArgs.length > 0 ? `${normalized} ${trimmedArgs}` : normalized;
|
|
6
|
+
}
|
|
7
|
+
export async function handleCommandExecuteBefore(input, core, options = {}) {
|
|
8
|
+
if (typeof input.command !== "string")
|
|
9
|
+
return;
|
|
10
|
+
if (typeof input.sessionID !== "string")
|
|
11
|
+
return;
|
|
12
|
+
const args = typeof input.arguments === "string" ? input.arguments : "";
|
|
13
|
+
const command = parseRalphLoopCommand(buildCommandLine(input.command, args));
|
|
14
|
+
if (!command)
|
|
15
|
+
return;
|
|
16
|
+
if (command.kind === "cancel") {
|
|
17
|
+
await core.cancelLoop(input.sessionID);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
await core.startLoop(input.sessionID, command.prompt, {
|
|
21
|
+
maxIterations: command.maxIterations ?? options.defaultMaxIterations,
|
|
22
|
+
completionPromise: command.completionPromise,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -25,6 +25,14 @@ type ChatMessageOutput = {
|
|
|
25
25
|
type EventInput = {
|
|
26
26
|
event?: unknown;
|
|
27
27
|
};
|
|
28
|
+
type CommandExecuteBeforeInput = {
|
|
29
|
+
command?: unknown;
|
|
30
|
+
sessionID?: unknown;
|
|
31
|
+
arguments?: unknown;
|
|
32
|
+
};
|
|
33
|
+
type CommandExecuteBeforeOutput = {
|
|
34
|
+
parts?: unknown;
|
|
35
|
+
};
|
|
28
36
|
type ToolExecuteBeforeInput = {
|
|
29
37
|
tool?: unknown;
|
|
30
38
|
sessionID?: unknown;
|
|
@@ -39,6 +47,7 @@ export type PluginHooks = {
|
|
|
39
47
|
"chat.message": (input: ChatMessageInput, output: ChatMessageOutput) => Promise<void>;
|
|
40
48
|
event: (input: EventInput) => Promise<void>;
|
|
41
49
|
config: (input: Record<string, unknown>) => Promise<void>;
|
|
50
|
+
"command.execute.before": (input: CommandExecuteBeforeInput, output: CommandExecuteBeforeOutput) => Promise<void>;
|
|
42
51
|
"tool.execute.before": (input: ToolExecuteBeforeInput, output: ToolExecuteBeforeOutput) => Promise<void>;
|
|
43
52
|
};
|
|
44
53
|
export declare function createPlugin(ctx?: PluginInput, deps?: CreatePluginDeps): Promise<PluginHooks>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createOpenCodeHostAdapter } from "../host-adapter/opencode-host-adapter.js";
|
|
2
2
|
import { createLoopCore } from "../ralph-loop/loop-core.js";
|
|
3
|
+
import { handleCommandExecuteBefore } from "./command-execute-before-handler.js";
|
|
3
4
|
import { handleConfig } from "./config-handler.js";
|
|
4
5
|
import { handleEvent } from "./event-handler.js";
|
|
5
6
|
import { resolvePluginConfig } from "./plugin-config.js";
|
|
@@ -60,6 +61,13 @@ export async function createPlugin(ctx, deps = {}) {
|
|
|
60
61
|
return;
|
|
61
62
|
await handleEvent(input.event, core);
|
|
62
63
|
},
|
|
64
|
+
"command.execute.before": async (input) => {
|
|
65
|
+
if (!resolvedConfig.enabled)
|
|
66
|
+
return;
|
|
67
|
+
await handleCommandExecuteBefore(input, core, {
|
|
68
|
+
defaultMaxIterations: resolvedConfig.defaultMaxIterations,
|
|
69
|
+
});
|
|
70
|
+
},
|
|
63
71
|
"tool.execute.before": async (input, output) => {
|
|
64
72
|
if (!resolvedConfig.enabled)
|
|
65
73
|
return;
|