opencode-immune 1.0.28 → 1.0.30
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/dist/plugin.js +76 -11
- package/package.json +1 -1
package/dist/plugin.js
CHANGED
|
@@ -1277,8 +1277,65 @@ const PRE_COMMIT_MARKER = "0-ULTRAWORK: PRE_COMMIT";
|
|
|
1277
1277
|
const CYCLE_COMPLETE_MARKER = "0-ULTRAWORK: CYCLE_COMPLETE";
|
|
1278
1278
|
const NEXT_TASK_PATTERN = /Next task:\s*(.+)/;
|
|
1279
1279
|
const ALL_CYCLES_COMPLETE_MARKER = "0-ULTRAWORK: ALL_CYCLES_COMPLETE";
|
|
1280
|
+
// Default commit prompt — used when user's /commit command file is not found
|
|
1281
|
+
const DEFAULT_COMMIT_PROMPT = `Review the staged changes using \`git diff --cached\` and create a commit.
|
|
1282
|
+
|
|
1283
|
+
If there are no staged changes, check \`git status\` for unstaged changes and stage the relevant files first.
|
|
1284
|
+
|
|
1285
|
+
The commit message MUST follow this structure:
|
|
1286
|
+
1. First line: short description (<50 chars) prefixed with feat:/fix:/refactor:
|
|
1287
|
+
2. Second line: empty
|
|
1288
|
+
3. Body: concise bullet points describing significant changes
|
|
1289
|
+
|
|
1290
|
+
Create the commit using \`git commit -m\` with the properly formatted message.`;
|
|
1280
1291
|
/**
|
|
1281
|
-
*
|
|
1292
|
+
* Load the /commit command prompt from user's global config.
|
|
1293
|
+
* Falls back to DEFAULT_COMMIT_PROMPT if file doesn't exist.
|
|
1294
|
+
*/
|
|
1295
|
+
async function loadCommitPrompt() {
|
|
1296
|
+
try {
|
|
1297
|
+
const home = process.env.HOME ?? process.env.USERPROFILE ?? "";
|
|
1298
|
+
const commandPath = (0, path_1.join)(home, ".config", "opencode", "commands", "commit.md");
|
|
1299
|
+
const content = await (0, promises_1.readFile)(commandPath, "utf-8");
|
|
1300
|
+
// Strip YAML frontmatter (--- ... ---)
|
|
1301
|
+
const stripped = content.replace(/^---[\s\S]*?---\s*/, "").trim();
|
|
1302
|
+
return stripped || DEFAULT_COMMIT_PROMPT;
|
|
1303
|
+
}
|
|
1304
|
+
catch {
|
|
1305
|
+
return DEFAULT_COMMIT_PROMPT;
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
/**
|
|
1309
|
+
* Execute a commit by sending the /commit prompt to the current session.
|
|
1310
|
+
* The agent will analyze the diff and create a proper commit message.
|
|
1311
|
+
* Returns true if the prompt was sent successfully.
|
|
1312
|
+
*/
|
|
1313
|
+
async function runSmartCommit(state, sessionID) {
|
|
1314
|
+
try {
|
|
1315
|
+
const commitPrompt = await loadCommitPrompt();
|
|
1316
|
+
console.log(`[opencode-immune] Smart commit: sending commit prompt to session ${sessionID}...`);
|
|
1317
|
+
// Send commit prompt to the SAME session (ultrawork already finished, session is free)
|
|
1318
|
+
await state.input.client.session.prompt({
|
|
1319
|
+
body: {
|
|
1320
|
+
parts: [
|
|
1321
|
+
{
|
|
1322
|
+
type: "text",
|
|
1323
|
+
text: commitPrompt,
|
|
1324
|
+
},
|
|
1325
|
+
],
|
|
1326
|
+
},
|
|
1327
|
+
path: { id: sessionID },
|
|
1328
|
+
});
|
|
1329
|
+
console.log("[opencode-immune] Smart commit: completed.");
|
|
1330
|
+
return true;
|
|
1331
|
+
}
|
|
1332
|
+
catch (err) {
|
|
1333
|
+
console.error("[opencode-immune] Smart commit failed:", err);
|
|
1334
|
+
return false;
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
/**
|
|
1338
|
+
* Helper: run git commit in the project directory (fallback).
|
|
1282
1339
|
* Uses execFile for safety (no shell injection).
|
|
1283
1340
|
* Returns true if commit succeeded, false otherwise.
|
|
1284
1341
|
*/
|
|
@@ -1334,14 +1391,18 @@ function createTextCompleteHandler(state) {
|
|
|
1334
1391
|
}
|
|
1335
1392
|
// ── PRE_COMMIT only (without CYCLE_COMPLETE in same part): run commit ──
|
|
1336
1393
|
if (text.includes(PRE_COMMIT_MARKER) && !text.includes(CYCLE_COMPLETE_MARKER)) {
|
|
1337
|
-
if (!state.commitPending) {
|
|
1394
|
+
if (!state.commitPending && sessionID) {
|
|
1338
1395
|
state.commitPending = true;
|
|
1339
|
-
console.log("[opencode-immune] Multi-Cycle: PRE_COMMIT detected (standalone), running
|
|
1396
|
+
console.log("[opencode-immune] Multi-Cycle: PRE_COMMIT detected (standalone), running smart commit...");
|
|
1340
1397
|
try {
|
|
1341
|
-
await
|
|
1398
|
+
const ok = await runSmartCommit(state, sessionID);
|
|
1399
|
+
if (!ok) {
|
|
1400
|
+
console.log("[opencode-immune] Multi-Cycle: smart commit failed, falling back to git commit...");
|
|
1401
|
+
await runGitCommit(state.input.directory, "chore: ultrawork cycle auto-commit");
|
|
1402
|
+
}
|
|
1342
1403
|
}
|
|
1343
1404
|
catch (err) {
|
|
1344
|
-
console.error("[opencode-immune] Multi-Cycle:
|
|
1405
|
+
console.error("[opencode-immune] Multi-Cycle: commit failed (standalone):", err);
|
|
1345
1406
|
}
|
|
1346
1407
|
finally {
|
|
1347
1408
|
state.commitPending = false;
|
|
@@ -1351,16 +1412,20 @@ function createTextCompleteHandler(state) {
|
|
|
1351
1412
|
}
|
|
1352
1413
|
// ── CYCLE_COMPLETE: self-contained sequence: commit → new session ──
|
|
1353
1414
|
if (text.includes(CYCLE_COMPLETE_MARKER)) {
|
|
1354
|
-
// Step 1: Always commit first
|
|
1355
|
-
if (!state.commitPending) {
|
|
1415
|
+
// Step 1: Always commit first in the current session
|
|
1416
|
+
if (!state.commitPending && sessionID) {
|
|
1356
1417
|
state.commitPending = true;
|
|
1357
|
-
console.log("[opencode-immune] Multi-Cycle: CYCLE_COMPLETE detected, running
|
|
1418
|
+
console.log("[opencode-immune] Multi-Cycle: CYCLE_COMPLETE detected, running smart commit first...");
|
|
1358
1419
|
try {
|
|
1359
|
-
await
|
|
1360
|
-
|
|
1420
|
+
const ok = await runSmartCommit(state, sessionID);
|
|
1421
|
+
if (!ok) {
|
|
1422
|
+
console.log("[opencode-immune] Multi-Cycle: smart commit failed, falling back to git commit...");
|
|
1423
|
+
await runGitCommit(state.input.directory, "chore: ultrawork cycle auto-commit");
|
|
1424
|
+
}
|
|
1425
|
+
console.log("[opencode-immune] Multi-Cycle: commit completed before new cycle.");
|
|
1361
1426
|
}
|
|
1362
1427
|
catch (err) {
|
|
1363
|
-
console.error("[opencode-immune] Multi-Cycle:
|
|
1428
|
+
console.error("[opencode-immune] Multi-Cycle: commit failed (continuing anyway):", err);
|
|
1364
1429
|
}
|
|
1365
1430
|
finally {
|
|
1366
1431
|
state.commitPending = false;
|