(directory, client, input, fallbackName, fallbackArgs, output)
| 1586 | |
| 1587 | async function initLoop(directory, client, sessionID, args) { |
| 1588 | const target = String(args || "").trim() || "progress.md" |
| 1589 | const full = path.resolve(directory, target) |
| 1590 | if (await pathExists(full)) { await toast(client, `${target} already exists.`, "warning"); return } |
| 1591 | await fs.writeFile(full, DEFAULT_PROGRESS_MD, "utf8") |
| 1592 | await toast(client, `Created ${target}.`, "success") |
| 1593 | await appendLoopLog(directory, "init", { sessionID, file: target }) |
| 1594 | } |
| 1595 | |
| 1596 | async function exportLoop(directory, client, sessionID) { |
| 1597 | const state = await readState(directory, sessionID) |
| 1598 | await say(client, sessionID, "OpenCode loop state export:\n```json\n" + JSON.stringify(state, null, 2) + "\n```") |
| 1599 | } |
| 1600 | |
| 1601 | async function handleCommand(directory, client, input, fallbackName, fallbackArgs, output) { |
| 1602 | const name = commandName(input?.command ?? input?.name ?? fallbackName) |
| 1603 | const sessionID = input?.sessionID |
| 1604 | const args = commandArgsText(input?.arguments ?? fallbackArgs ?? "") |
| 1605 | if (!sessionID || !name) return false |
| 1606 | rememberSession(directory, client, sessionID) |
| 1607 | if (wasHandled(sessionID, name, args)) return true |
| 1608 | markHandled(sessionID, name, args) |
| 1609 | |
| 1610 | const handled = () => { |
| 1611 | if (output && Array.isArray(output.parts)) { |
| 1612 | output.parts.length = 0 |
| 1613 | output.parts.push({ type: "text", text: "OpenCode Loop command was handled by the local plugin. Do not explain this command; continue only when the loop injects its next task." }) |
| 1614 | } |
| 1615 | return true |
| 1616 | } |
| 1617 | |
| 1618 | if (name === "loop-goal") return await addGoal(directory, client, sessionID, args), handled() |
| 1619 | if (name === "loop-goal-status") return await statusGoal(directory, client, sessionID), handled() |
| 1620 | if (name === "loop-goal-pause") return await pauseGoal(directory, client, sessionID, args), handled() |
| 1621 | if (name === "loop-goal-resume") return await resumeGoal(directory, client, sessionID, args), handled() |
| 1622 | if (name === "loop-goal-clear") return await clearGoal(directory, client, sessionID, args), handled() |
| 1623 | if (name === "loop-goal-done" || name === "loop-goal-complete") return await completeGoalCommand(directory, client, sessionID, args), handled() |
| 1624 | if (name === "loop-goal-blocked") return await blockGoalCommand(directory, client, sessionID, args), handled() |
| 1625 | if (name === "loop") return await addLoop(directory, client, sessionID, args), handled() |
| 1626 | if (isPreset(name)) return await addLoop(directory, client, sessionID, args, presetDefaults(name, args)), handled() |
| 1627 | if (name === "loop-stop" || name === "loop-remove") return await stopLoop(directory, client, sessionID, args), handled() |
| 1628 | if (name === "loop-clear") return await stopLoop(directory, client, sessionID, "all"), handled() |
| 1629 | if (name === "loop-status") return await statusLoop(directory, client, sessionID), handled() |
| 1630 | if (name === "loop-logs") return await logsLoop(directory, client, sessionID), handled() |
no test coverage detected