opencode-immune 1.0.16 → 1.0.18

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 +62 -5
  2. package/package.json +2 -2
package/dist/plugin.js CHANGED
@@ -931,6 +931,11 @@ function createMultiCycleHandler(state) {
931
931
  if (!messageContent)
932
932
  return;
933
933
  const messageRole = output.message?.role;
934
+ // ── ALL_CYCLES_COMPLETE: clear ultrawork marker (checked before managed session guard) ──
935
+ if (messageContent.includes(ALL_CYCLES_COMPLETE_MARKER)) {
936
+ await clearUltraworkMarker(state);
937
+ console.log("[opencode-immune] Multi-Cycle: ALL_CYCLES_COMPLETE detected, ultrawork marker cleared.");
938
+ }
934
939
  if (!isManagedRootUltraworkSession(state, sessionID))
935
940
  return;
936
941
  const managedSession = getManagedSession(state, sessionID);
@@ -951,11 +956,6 @@ function createMultiCycleHandler(state) {
951
956
  });
952
957
  }
953
958
  }
954
- // ── ALL_CYCLES_COMPLETE: clear ultrawork marker ──
955
- if (messageContent.includes(ALL_CYCLES_COMPLETE_MARKER)) {
956
- await clearUltraworkMarker(state);
957
- console.log("[opencode-immune] Multi-Cycle: ALL_CYCLES_COMPLETE detected, ultrawork marker cleared.");
958
- }
959
959
  // ── PRE_COMMIT: execute /commit ──
960
960
  if (messageContent.includes(PRE_COMMIT_MARKER) && !state.commitPending) {
961
961
  state.commitPending = true;
@@ -1044,6 +1044,7 @@ async function server(input) {
1044
1044
  if (markerActive) {
1045
1045
  const recovery = await parseTasksFile(state.input.directory);
1046
1046
  if (recovery && recovery.phase !== "ARCHIVE: DONE") {
1047
+ // Active task exists with incomplete phases — resume it
1047
1048
  state.recoveryContext = recovery;
1048
1049
  state.autoResumeAttempted = true;
1049
1050
  console.log(`[opencode-immune] Plugin init: ultrawork marker active, recovery context loaded: ` +
@@ -1085,6 +1086,62 @@ async function server(input) {
1085
1086
  }
1086
1087
  }, 5_000);
1087
1088
  }
1089
+ else {
1090
+ // No active task — check if backlog has pending work to start a new cycle
1091
+ try {
1092
+ const backlogPath = (0, path_1.join)(state.input.directory, "memory-bank", "backlog.md");
1093
+ const backlogContent = await (0, promises_1.readFile)(backlogPath, "utf-8");
1094
+ const hasPendingTasks = /- \[ \]/.test(backlogContent);
1095
+ if (hasPendingTasks) {
1096
+ state.autoResumeAttempted = true;
1097
+ console.log(`[opencode-immune] Plugin init: no active task but backlog has pending items. ` +
1098
+ `Will create new session to start next cycle.`);
1099
+ setTimeout(async () => {
1100
+ try {
1101
+ const createResult = await state.input.client.session.create({
1102
+ body: {
1103
+ title: `AUTO-CYCLE: next backlog task`,
1104
+ },
1105
+ });
1106
+ const newSessionData = createResult?.data;
1107
+ const newSessionID = newSessionData?.id;
1108
+ if (!newSessionID) {
1109
+ console.error("[opencode-immune] Auto-cycle: Failed to create session — no session ID returned.");
1110
+ return;
1111
+ }
1112
+ console.log(`[opencode-immune] Auto-cycle: New session created: ${newSessionID}`);
1113
+ await addManagedUltraworkSession(state, newSessionID);
1114
+ await state.input.client.session.promptAsync({
1115
+ body: {
1116
+ agent: ULTRAWORK_AGENT,
1117
+ parts: [
1118
+ {
1119
+ type: "text",
1120
+ text: `[AUTO-CYCLE] Continue processing task backlog. Read memory-bank/tasks.md and memory-bank/backlog.md, pick the next pending task, and run the full pipeline.`,
1121
+ },
1122
+ ],
1123
+ },
1124
+ path: { id: newSessionID },
1125
+ });
1126
+ console.log(`[opencode-immune] Auto-cycle prompt sent to new session ${newSessionID}`);
1127
+ }
1128
+ catch (err) {
1129
+ console.error("[opencode-immune] Auto-cycle: Failed to create session or send prompt:", err);
1130
+ }
1131
+ }, 5_000);
1132
+ }
1133
+ else {
1134
+ // No active task and no pending backlog — clear marker
1135
+ await clearUltraworkMarker(state);
1136
+ console.log(`[opencode-immune] Plugin init: no active task and no pending backlog. Marker cleared.`);
1137
+ }
1138
+ }
1139
+ catch {
1140
+ // backlog.md doesn't exist or can't be read — clear marker
1141
+ await clearUltraworkMarker(state);
1142
+ console.log(`[opencode-immune] Plugin init: no active task, backlog unreadable. Marker cleared.`);
1143
+ }
1144
+ }
1088
1145
  }
1089
1146
  console.log(`[opencode-immune] Plugin initialized. Directory: ${input.directory}`);
1090
1147
  // Compose tool.execute.after handlers:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-immune",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "description": "OpenCode plugin: session recovery, auto-retry, multi-cycle automation, context monitoring",
5
5
  "exports": {
6
6
  "./server": "./dist/plugin.js"
@@ -14,7 +14,7 @@
14
14
  "prepublishOnly": "npm run build"
15
15
  },
16
16
  "dependencies": {
17
- "@opencode-ai/plugin": "1.4.2"
17
+ "@opencode-ai/plugin": "1.4.3"
18
18
  },
19
19
  "devDependencies": {
20
20
  "@types/node": "^25.5.2",