opencode-immune 1.0.31 → 1.0.32

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.
Files changed (2) hide show
  1. package/dist/plugin.js +33 -93
  2. package/package.json +1 -1
package/dist/plugin.js CHANGED
@@ -1284,92 +1284,40 @@ const PRE_COMMIT_MARKER = "0-ULTRAWORK: PRE_COMMIT";
1284
1284
  const CYCLE_COMPLETE_MARKER = "0-ULTRAWORK: CYCLE_COMPLETE";
1285
1285
  const NEXT_TASK_PATTERN = /Next task:\s*(.+)/;
1286
1286
  const ALL_CYCLES_COMPLETE_MARKER = "0-ULTRAWORK: ALL_CYCLES_COMPLETE";
1287
- // Default commit prompt — used when user's /commit command file is not found
1288
- const DEFAULT_COMMIT_PROMPT = `Review the staged changes using \`git diff --cached\` and create a commit.
1289
-
1290
- If there are no staged changes, check \`git status\` for unstaged changes and stage the relevant files first.
1291
-
1292
- The commit message MUST follow this structure:
1293
- 1. First line: short description (<50 chars) prefixed with feat:/fix:/refactor:
1294
- 2. Second line: empty
1295
- 3. Body: concise bullet points describing significant changes
1296
-
1297
- Create the commit using \`git commit -m\` with the properly formatted message.`;
1298
1287
  /**
1299
- * Load the /commit command prompt from user's global config.
1300
- * Falls back to DEFAULT_COMMIT_PROMPT if file doesn't exist.
1288
+ * Helper: run git add + diff-stat + commit with descriptive message.
1289
+ * Builds commit body from `git diff --cached --stat` so the commit
1290
+ * is not an opaque "auto-commit" but shows what changed.
1291
+ * Returns true if commit succeeded (or nothing to commit), false on error.
1301
1292
  */
1302
- async function loadCommitPrompt() {
1303
- try {
1304
- const home = process.env.HOME ?? process.env.USERPROFILE ?? "";
1305
- const commandPath = (0, path_1.join)(home, ".config", "opencode", "commands", "commit.md");
1306
- const content = await (0, promises_1.readFile)(commandPath, "utf-8");
1307
- // Strip YAML frontmatter (--- ... ---)
1308
- const stripped = content.replace(/^---[\s\S]*?---\s*/, "").trim();
1309
- return stripped || DEFAULT_COMMIT_PROMPT;
1310
- }
1311
- catch {
1312
- return DEFAULT_COMMIT_PROMPT;
1313
- }
1314
- }
1315
- /**
1316
- * Execute a commit by sending the /commit prompt to the current session.
1317
- * The agent will analyze the diff and create a proper commit message.
1318
- * Returns true if the prompt was sent successfully.
1319
- */
1320
- async function runSmartCommit(state, sessionID) {
1321
- try {
1322
- const commitPrompt = await loadCommitPrompt();
1323
- console.log(`[opencode-immune] Smart commit: sending commit prompt to session ${sessionID}...`);
1324
- // Send commit prompt to the SAME session (ultrawork already finished, session is free)
1325
- await state.input.client.session.prompt({
1326
- body: {
1327
- parts: [
1328
- {
1329
- type: "text",
1330
- text: commitPrompt,
1331
- },
1332
- ],
1333
- },
1334
- path: { id: sessionID },
1335
- });
1336
- console.log("[opencode-immune] Smart commit: completed.");
1337
- return true;
1338
- }
1339
- catch (err) {
1340
- console.error("[opencode-immune] Smart commit failed:", err);
1341
- return false;
1342
- }
1343
- }
1344
- /**
1345
- * Helper: run git commit in the project directory (fallback).
1346
- * Uses execFile for safety (no shell injection).
1347
- * Returns true if commit succeeded, false otherwise.
1348
- */
1349
- function runGitCommit(directory, message) {
1293
+ function runGitCommit(directory) {
1350
1294
  return new Promise((resolve) => {
1351
- // Stage all changes first
1295
+ // Stage all changes
1352
1296
  (0, child_process_1.execFile)("git", ["add", "-A"], { cwd: directory }, (addErr) => {
1353
1297
  if (addErr) {
1354
1298
  console.error("[opencode-immune] git add failed:", addErr.message);
1355
1299
  resolve(false);
1356
1300
  return;
1357
1301
  }
1358
- // Then commit
1359
- (0, child_process_1.execFile)("git", ["commit", "-m", message], { cwd: directory }, (commitErr, stdout, stderr) => {
1360
- if (commitErr) {
1361
- // "nothing to commit" is not a real error
1362
- if (stderr?.includes("nothing to commit") || stdout?.includes("nothing to commit")) {
1363
- console.log("[opencode-immune] git commit: nothing to commit (clean tree).");
1364
- resolve(true);
1302
+ // Get diff stat for commit body
1303
+ (0, child_process_1.execFile)("git", ["diff", "--cached", "--stat"], { cwd: directory }, (_diffErr, diffOut) => {
1304
+ const stat = (diffOut ?? "").trim();
1305
+ const body = stat ? `\n\n${stat}` : "";
1306
+ const message = `chore: ultrawork cycle auto-commit${body}`;
1307
+ (0, child_process_1.execFile)("git", ["commit", "-m", message], { cwd: directory }, (commitErr, stdout, stderr) => {
1308
+ if (commitErr) {
1309
+ if (stderr?.includes("nothing to commit") || stdout?.includes("nothing to commit")) {
1310
+ console.log("[opencode-immune] git commit: nothing to commit (clean tree).");
1311
+ resolve(true);
1312
+ return;
1313
+ }
1314
+ console.error("[opencode-immune] git commit failed:", commitErr.message, stderr);
1315
+ resolve(false);
1365
1316
  return;
1366
1317
  }
1367
- console.error("[opencode-immune] git commit failed:", commitErr.message, stderr);
1368
- resolve(false);
1369
- return;
1370
- }
1371
- console.log("[opencode-immune] git commit succeeded:", stdout?.trim());
1372
- resolve(true);
1318
+ console.log("[opencode-immune] git commit succeeded:", stdout?.trim());
1319
+ resolve(true);
1320
+ });
1373
1321
  });
1374
1322
  });
1375
1323
  });
@@ -1398,18 +1346,14 @@ function createTextCompleteHandler(state) {
1398
1346
  }
1399
1347
  // ── PRE_COMMIT only (without CYCLE_COMPLETE in same part): run commit ──
1400
1348
  if (text.includes(PRE_COMMIT_MARKER) && !text.includes(CYCLE_COMPLETE_MARKER)) {
1401
- if (!state.commitPending && sessionID) {
1349
+ if (!state.commitPending) {
1402
1350
  state.commitPending = true;
1403
- console.log("[opencode-immune] Multi-Cycle: PRE_COMMIT detected (standalone), running smart commit...");
1351
+ console.log("[opencode-immune] Multi-Cycle: PRE_COMMIT detected (standalone), running git commit...");
1404
1352
  try {
1405
- const ok = await runSmartCommit(state, sessionID);
1406
- if (!ok) {
1407
- console.log("[opencode-immune] Multi-Cycle: smart commit failed, falling back to git commit...");
1408
- await runGitCommit(state.input.directory, "chore: ultrawork cycle auto-commit");
1409
- }
1353
+ await runGitCommit(state.input.directory);
1410
1354
  }
1411
1355
  catch (err) {
1412
- console.error("[opencode-immune] Multi-Cycle: commit failed (standalone):", err);
1356
+ console.error("[opencode-immune] Multi-Cycle: git commit failed (standalone):", err);
1413
1357
  }
1414
1358
  finally {
1415
1359
  state.commitPending = false;
@@ -1419,20 +1363,16 @@ function createTextCompleteHandler(state) {
1419
1363
  }
1420
1364
  // ── CYCLE_COMPLETE: self-contained sequence: commit → new session ──
1421
1365
  if (text.includes(CYCLE_COMPLETE_MARKER)) {
1422
- // Step 1: Always commit first in the current session
1423
- if (!state.commitPending && sessionID) {
1366
+ // Step 1: Always commit first
1367
+ if (!state.commitPending) {
1424
1368
  state.commitPending = true;
1425
- console.log("[opencode-immune] Multi-Cycle: CYCLE_COMPLETE detected, running smart commit first...");
1369
+ console.log("[opencode-immune] Multi-Cycle: CYCLE_COMPLETE detected, running git commit first...");
1426
1370
  try {
1427
- const ok = await runSmartCommit(state, sessionID);
1428
- if (!ok) {
1429
- console.log("[opencode-immune] Multi-Cycle: smart commit failed, falling back to git commit...");
1430
- await runGitCommit(state.input.directory, "chore: ultrawork cycle auto-commit");
1431
- }
1432
- console.log("[opencode-immune] Multi-Cycle: commit completed before new cycle.");
1371
+ await runGitCommit(state.input.directory);
1372
+ console.log("[opencode-immune] Multi-Cycle: git commit completed before new cycle.");
1433
1373
  }
1434
1374
  catch (err) {
1435
- console.error("[opencode-immune] Multi-Cycle: commit failed (continuing anyway):", err);
1375
+ console.error("[opencode-immune] Multi-Cycle: git commit failed (continuing anyway):", err);
1436
1376
  }
1437
1377
  finally {
1438
1378
  state.commitPending = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-immune",
3
- "version": "1.0.31",
3
+ "version": "1.0.32",
4
4
  "description": "OpenCode plugin: session recovery, auto-retry, multi-cycle automation, context monitoring",
5
5
  "exports": {
6
6
  "./server": "./dist/plugin.js"