Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased — OpenTUI 0.8 compatibility source update

- Create `.opencode/opencode-loop/.gitignore` containing an explanatory comment and `*` whenever Loop first creates its state directory, so runtime state, checkpoints, and logs cannot be committed accidentally. An existing `.gitignore` is never overwritten.
- Extend optional `@opentui/core` and `@opentui/solid` peer support to 0.8.x while preserving 0.5.14–0.7.x; raise the Solid peer minimum to upstream 1.9.12 (recommend 1.9.16+ for the security update).
- Synchronize the npm lockfile's root manifest with package version 0.6.10 and new peer constraints. No bundled renderer, server entry, or scheduler authority changes.
- Keep the existing strict packaged-consumer peer assertion and provide manual Bun rendering validation for OpenTUI 0.8.1 before claiming runtime verification. CI/Actions and automatic npm releases remain disabled; npm 0.6.10 is unchanged.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ Patch checkpoints:
.opencode/opencode-loop/checkpoints/
```

Add `.opencode/opencode-loop/` to `.gitignore` if runtime state should not be committed.
Loop automatically creates `.opencode/opencode-loop/.gitignore` containing an explanatory comment and `*` when it first creates the state directory, so runtime state, checkpoints, and logs are not committed by accident. An existing `.gitignore` in that directory is left untouched.

## Permissions

Expand Down
2 changes: 2 additions & 0 deletions docs/SCHEDULING.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ Normal plugin Loop jobs are session-bound and persist under:
.opencode/opencode-loop/<session-id>.json
```

The state directory is created with a `.gitignore` containing an explanatory comment and `*`, so session state, logs, and checkpoints stay out of the repository automatically. An existing `.gitignore` is never overwritten.

Starting a new OpenCode session does not move old Loop jobs into the new session.

`/loop-doctor` reports:
Expand Down
4 changes: 2 additions & 2 deletions scripts/pulse-check.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { promises as fs } from "node:fs"
import path from "node:path"
import { dedicatedGoalOwnsContinuation } from "../src/source/runtime/companion-goal.js"
import { ensureStateDir } from "../src/source/core/state.js"

const LOCK_STALE_MS = 30_000
const LOCK_RETRY_MS = 25
Expand Down Expand Up @@ -96,9 +97,8 @@ async function writeJsonAtomic(file, value) {
}

async function acquireLock(project) {
const directory = pulseDirectory(project)
const lock = pulseLockDirectory(project)
await fs.mkdir(directory, { recursive: true })
await ensureStateDir(project)

for (let attempt = 0; attempt < LOCK_RETRIES; attempt += 1) {
try {
Expand Down
10 changes: 10 additions & 0 deletions scripts/state-integrity-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ try {
assert.equal(oldSnapshot.jobs.length, 1)
assert.equal(oldSnapshot.jobs[0].runCount, 7)

const ignoreFile = path.join(stateDir(root), ".gitignore")
assert.equal(
await readFile(ignoreFile, "utf8"),
"# OpenCode Loop runtime state and logs; do not commit this directory.\n*\n",
"state dir must ignore its runtime files automatically with an explanatory comment",
)
await writeFile(ignoreFile, "custom-ignore\n")
await writeState(root, sessionID, oldSnapshot)
assert.equal(await readFile(ignoreFile, "utf8"), "custom-ignore\n", "an existing .gitignore must never be overwritten")

const corrupt = '{"version":4,"jobs":['
await mkdir(stateDir(root), { recursive: true })
await writeFile(file, corrupt)
Expand Down
24 changes: 21 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ import { randomUUID as stateLockRandomUUID } from "crypto";
import os from "os";
import path from "path";
var STATE_DIR = ".opencode/opencode-loop";
var STATE_IGNORE_FILE = ".gitignore";
var STATE_IGNORE_CONTENT = `# OpenCode Loop runtime state and logs; do not commit this directory.
*
`;
var STATE_BASELINE = Symbol("opencode-loop-state-baseline");
var stateWriteLocks = new Map;
function stateDir(directory) {
Expand All @@ -402,6 +406,17 @@ function statePath(directory, sessionID) {
async function ensureDir(directory) {
await fs.mkdir(directory, { recursive: true });
}
async function ensureStateDir(directory) {
const target = stateDir(directory);
await ensureDir(target);
try {
await fs.writeFile(path.join(target, STATE_IGNORE_FILE), STATE_IGNORE_CONTENT, { flag: "wx" });
} catch (error) {
if (error?.code !== "EEXIST")
throw error;
}
return target;
}
async function pathExists(filePath) {
try {
await fs.access(filePath);
Expand Down Expand Up @@ -588,7 +603,7 @@ async function recoverDeadStateProcessLock(directory, canonical, stale, depth =
async function acquireStateProcessLock(directory, sessionID) {
const targetDirectory = stateDir(directory);
await assertStatePathSafe(directory, targetDirectory);
await ensureDir(targetDirectory);
await ensureStateDir(directory);
await assertStatePathSafe(directory, targetDirectory);
const target = statePath(directory, sessionID);
const canonical = `${target}.lock`;
Expand Down Expand Up @@ -680,7 +695,7 @@ async function readStateFile(directory, sessionID, { backupCorrupt = true } = {}
}
if (backupCorrupt) {
try {
await ensureDir(stateDir(directory));
await ensureStateDir(directory);
await fs.copyFile(target, `${target}.corrupt-${Date.now()}`);
} catch {}
}
Expand Down Expand Up @@ -845,7 +860,7 @@ async function removeState(directory, sessionID) {
// src/source/core/process.js
async function appendLoopLog(directory, line, extra = {}) {
try {
await ensureDir(stateDir(directory));
await ensureStateDir(directory);
await fs2.appendFile(path2.join(stateDir(directory), "loop.log"), JSON.stringify({ time: new Date().toISOString(), line, ...extra }) + `
`);
} catch {}
Expand Down Expand Up @@ -1672,6 +1687,8 @@ async function writeGoalReport(directory, sessionID, job) {
if (!isGoalJob(job))
return;
const target = job.goalEvidenceFile ? path3.resolve(directory, job.goalEvidenceFile) : goalReportPath(directory, sessionID, job);
if (!job.goalEvidenceFile)
await ensureStateDir(directory);
await ensureDir(path3.dirname(target));
await fs3.writeFile(target, goalReportText(job), "utf8");
}
Expand Down Expand Up @@ -3133,6 +3150,7 @@ ${text.trim().slice(0, 20000)}`);
return;
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
const checkpointDir = path8.join(stateDir(directory), "checkpoints", safeID(sessionID));
await ensureStateDir(directory);
await ensureDir(checkpointDir);
const diff = await runProcess2("git", ["diff", "--binary"], directory, 120000);
const staged = await runProcess2("git", ["diff", "--cached", "--binary"], directory, 120000);
Expand Down
22 changes: 18 additions & 4 deletions src/native.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,17 @@ function statePath(directory, sessionID) {
async function ensureDir(directory) {
await fs.mkdir(directory, { recursive: true });
}
async function ensureStateDir(directory) {
const target = stateDir(directory);
await ensureDir(target);
try {
await fs.writeFile(path3.join(target, STATE_IGNORE_FILE), STATE_IGNORE_CONTENT, { flag: "wx" });
} catch (error) {
if (error?.code !== "EEXIST")
throw error;
}
return target;
}
function stateLockError(kind, detail) {
const error = new Error(`OpenCode Loop state lock ${kind}: ${detail}`);
error.code = "OPENCODE_LOOP_STATE_LOCK";
Expand Down Expand Up @@ -743,7 +754,7 @@ async function recoverDeadStateProcessLock(directory, canonical, stale, depth =
async function acquireStateProcessLock(directory, sessionID) {
const targetDirectory = stateDir(directory);
await assertStatePathSafe(directory, targetDirectory);
await ensureDir(targetDirectory);
await ensureStateDir(directory);
await assertStatePathSafe(directory, targetDirectory);
const target = statePath(directory, sessionID);
const canonical = `${target}.lock`;
Expand Down Expand Up @@ -835,7 +846,7 @@ async function readStateFile(directory, sessionID, { backupCorrupt = true } = {}
}
if (backupCorrupt) {
try {
await ensureDir(stateDir(directory));
await ensureStateDir(directory);
await fs.copyFile(target, `${target}.corrupt-${Date.now()}`);
} catch {}
}
Expand Down Expand Up @@ -999,7 +1010,9 @@ async function removeState(directory, sessionID) {
}
});
}
var STATE_DIR = ".opencode/opencode-loop", STATE_BASELINE, stateWriteLocks, STATE_PROCESS_LOCK_TIMEOUT_MS = 5000, STATE_PROCESS_LOCK_POLL_MS = 20;
var STATE_DIR = ".opencode/opencode-loop", STATE_IGNORE_FILE = ".gitignore", STATE_IGNORE_CONTENT = `# OpenCode Loop runtime state and logs; do not commit this directory.
*
`, STATE_BASELINE, stateWriteLocks, STATE_PROCESS_LOCK_TIMEOUT_MS = 5000, STATE_PROCESS_LOCK_POLL_MS = 20;
var init_state = __esm(() => {
STATE_BASELINE = Symbol("opencode-loop-state-baseline");
stateWriteLocks = new Map;
Expand All @@ -1011,7 +1024,7 @@ import path4 from "path";
import { spawn as spawn2 } from "child_process";
async function appendLoopLog(directory, line, extra = {}) {
try {
await ensureDir(stateDir(directory));
await ensureStateDir(directory);
await fs2.appendFile(path4.join(stateDir(directory), "loop.log"), JSON.stringify({ time: new Date().toISOString(), line, ...extra }) + `
`);
} catch {}
Expand Down Expand Up @@ -1339,6 +1352,7 @@ ${text.trim().slice(0, 20000)}`);
return;
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
const checkpointDir = path6.join(stateDir(directory), "checkpoints", safeID(sessionID));
await ensureStateDir(directory);
await ensureDir(checkpointDir);
const diff = await runProcess2("git", ["diff", "--binary"], directory, 120000);
const staged = await runProcess2("git", ["diff", "--cached", "--binary"], directory, 120000);
Expand Down
22 changes: 18 additions & 4 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,17 @@ function statePath(directory, sessionID) {
async function ensureDir(directory) {
await fs.mkdir(directory, { recursive: true });
}
async function ensureStateDir(directory) {
const target = stateDir(directory);
await ensureDir(target);
try {
await fs.writeFile(path3.join(target, STATE_IGNORE_FILE), STATE_IGNORE_CONTENT, { flag: "wx" });
} catch (error) {
if (error?.code !== "EEXIST")
throw error;
}
return target;
}
function stateLockError(kind, detail) {
const error = new Error(`OpenCode Loop state lock ${kind}: ${detail}`);
error.code = "OPENCODE_LOOP_STATE_LOCK";
Expand Down Expand Up @@ -743,7 +754,7 @@ async function recoverDeadStateProcessLock(directory, canonical, stale, depth =
async function acquireStateProcessLock(directory, sessionID) {
const targetDirectory = stateDir(directory);
await assertStatePathSafe(directory, targetDirectory);
await ensureDir(targetDirectory);
await ensureStateDir(directory);
await assertStatePathSafe(directory, targetDirectory);
const target = statePath(directory, sessionID);
const canonical = `${target}.lock`;
Expand Down Expand Up @@ -835,7 +846,7 @@ async function readStateFile(directory, sessionID, { backupCorrupt = true } = {}
}
if (backupCorrupt) {
try {
await ensureDir(stateDir(directory));
await ensureStateDir(directory);
await fs.copyFile(target, `${target}.corrupt-${Date.now()}`);
} catch {}
}
Expand Down Expand Up @@ -999,7 +1010,9 @@ async function removeState(directory, sessionID) {
}
});
}
var STATE_DIR = ".opencode/opencode-loop", STATE_BASELINE, stateWriteLocks, STATE_PROCESS_LOCK_TIMEOUT_MS = 5000, STATE_PROCESS_LOCK_POLL_MS = 20;
var STATE_DIR = ".opencode/opencode-loop", STATE_IGNORE_FILE = ".gitignore", STATE_IGNORE_CONTENT = `# OpenCode Loop runtime state and logs; do not commit this directory.
*
`, STATE_BASELINE, stateWriteLocks, STATE_PROCESS_LOCK_TIMEOUT_MS = 5000, STATE_PROCESS_LOCK_POLL_MS = 20;
var init_state = __esm(() => {
STATE_BASELINE = Symbol("opencode-loop-state-baseline");
stateWriteLocks = new Map;
Expand All @@ -1011,7 +1024,7 @@ import path4 from "path";
import { spawn as spawn2 } from "child_process";
async function appendLoopLog(directory, line, extra = {}) {
try {
await ensureDir(stateDir(directory));
await ensureStateDir(directory);
await fs2.appendFile(path4.join(stateDir(directory), "loop.log"), JSON.stringify({ time: new Date().toISOString(), line, ...extra }) + `
`);
} catch {}
Expand Down Expand Up @@ -1339,6 +1352,7 @@ ${text.trim().slice(0, 20000)}`);
return;
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
const checkpointDir = path6.join(stateDir(directory), "checkpoints", safeID(sessionID));
await ensureStateDir(directory);
await ensureDir(checkpointDir);
const diff = await runProcess2("git", ["diff", "--binary"], directory, 120000);
const staged = await runProcess2("git", ["diff", "--cached", "--binary"], directory, 120000);
Expand Down
4 changes: 2 additions & 2 deletions src/source/core/process.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { promises as fs } from "node:fs"
import path from "node:path"
import { spawn } from "node:child_process"
import { stateDir, ensureDir } from "./state.js"
import { stateDir, ensureStateDir } from "./state.js"

export async function appendLoopLog(directory, line, extra = {}) {
try {
await ensureDir(stateDir(directory))
await ensureStateDir(directory)
await fs.appendFile(path.join(stateDir(directory), "loop.log"), JSON.stringify({ time: new Date().toISOString(), line, ...extra }) + "\n")
} catch {}
}
Expand Down
18 changes: 16 additions & 2 deletions src/source/core/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,26 @@ import path from "node:path"
import { safeID } from "./args.js"

const STATE_DIR = ".opencode/opencode-loop"
const STATE_IGNORE_FILE = ".gitignore"
const STATE_IGNORE_CONTENT = "# OpenCode Loop runtime state and logs; do not commit this directory.\n*\n"
const STATE_BASELINE = Symbol("opencode-loop-state-baseline")
const stateWriteLocks = new Map()

export function stateDir(directory) { return path.join(directory, STATE_DIR) }
function statePath(directory, sessionID) { return path.join(stateDir(directory), `${safeID(sessionID)}.json`) }
export async function ensureDir(directory) { await fs.mkdir(directory, { recursive: true }) }

// Keep runtime state and logs out of the project repository. The ignore file is
// created only when it is missing and is never overwritten, so a user-owned or
// customized .gitignore survives updates.
export async function ensureStateDir(directory) {
const target = stateDir(directory)
await ensureDir(target)
try { await fs.writeFile(path.join(target, STATE_IGNORE_FILE), STATE_IGNORE_CONTENT, { flag: "wx" }) }
catch (error) { if (error?.code !== "EEXIST") throw error }
return target
}

export async function pathExists(filePath) { try { await fs.access(filePath); return true } catch { return false } }

const STATE_PROCESS_LOCK_TIMEOUT_MS = 5_000
Expand Down Expand Up @@ -183,7 +197,7 @@ async function recoverDeadStateProcessLock(directory, canonical, stale, depth =
async function acquireStateProcessLock(directory, sessionID) {
const targetDirectory = stateDir(directory)
await assertStatePathSafe(directory, targetDirectory)
await ensureDir(targetDirectory)
await ensureStateDir(directory)
await assertStatePathSafe(directory, targetDirectory)
const target = statePath(directory, sessionID)
const canonical = `${target}.lock`
Expand Down Expand Up @@ -273,7 +287,7 @@ async function readStateFile(directory, sessionID, { backupCorrupt = true } = {}
// repeatedly creates an unbounded number of .corrupt-* backups.
if (backupCorrupt) {
try {
await ensureDir(stateDir(directory))
await ensureStateDir(directory)
await fs.copyFile(target, `${target}.corrupt-${Date.now()}`)
} catch {}
}
Expand Down
3 changes: 2 additions & 1 deletion src/source/runtime/goal-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { promises as fs } from "node:fs"
import path from "node:path"
import { DEFAULT_GOAL_MAX_NO_PROGRESS, safeID } from "../core/args.js"
import { isGoalJob, goalStatusText } from "../core/jobs.js"
import { stateDir, ensureDir } from "../core/state.js"
import { stateDir, ensureDir, ensureStateDir } from "../core/state.js"

const GOAL_REPORT_DIR = "goals"

Expand Down Expand Up @@ -47,6 +47,7 @@ export function goalReportText(job) {
export async function writeGoalReport(directory, sessionID, job) {
if (!isGoalJob(job)) return
const target = job.goalEvidenceFile ? path.resolve(directory, job.goalEvidenceFile) : goalReportPath(directory, sessionID, job)
if (!job.goalEvidenceFile) await ensureStateDir(directory)
await ensureDir(path.dirname(target))
await fs.writeFile(target, goalReportText(job), "utf8")
}
3 changes: 2 additions & 1 deletion src/source/runtime/job-workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { promises as fs } from "node:fs"
import path from "node:path"
import { safeID } from "../core/args.js"
import { decoratePrompt, isGoalJob } from "../core/jobs.js"
import { stateDir, ensureDir } from "../core/state.js"
import { stateDir, ensureDir, ensureStateDir } from "../core/state.js"
import { appendLoopLog as defaultAppendLoopLog, readSmallTextFile as defaultReadSmallTextFile, runProcess as defaultRunProcess } from "../core/process.js"
import { buildGoalPrompt as defaultBuildGoalPrompt } from "./goal-runtime.js"

Expand Down Expand Up @@ -133,6 +133,7 @@ export function createJobWorkspaceRuntime(options = {}) {
if (!status.stdout.trim()) return
const timestamp = new Date().toISOString().replace(/[:.]/g, "-")
const checkpointDir = path.join(stateDir(directory), "checkpoints", safeID(sessionID))
await ensureStateDir(directory)
await ensureDir(checkpointDir)
const diff = await runProcess("git", ["diff", "--binary"], directory, 120_000)
const staged = await runProcess("git", ["diff", "--cached", "--binary"], directory, 120_000)
Expand Down