opencode-immune 1.0.74 → 1.0.75

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.
@@ -3777,7 +3777,7 @@ import { fileURLToPath } from "url";
3777
3777
  import { createHash } from "crypto";
3778
3778
  import { tmpdir } from "os";
3779
3779
  import { execFile } from "child_process";
3780
- var PLUGIN_VERSION = "1.0.74";
3780
+ var PLUGIN_VERSION = "1.0.75";
3781
3781
  var PLUGIN_PACKAGE_NAME = "opencode-immune";
3782
3782
  var PLUGIN_DIRNAME = dirname(fileURLToPath(import.meta.url));
3783
3783
  function getServerAuthHeaders() {
@@ -3948,6 +3948,42 @@ async function createManagedUltraworkSession(state, title) {
3948
3948
  await addManagedUltraworkSession(state, sessionID);
3949
3949
  return sessionID;
3950
3950
  }
3951
+ async function startAutoCycleInNewSession(state, options) {
3952
+ const nextTask = options.nextTask?.trim() || "Continue processing task backlog";
3953
+ const title = `AUTO-CYCLE: ${nextTask}`;
3954
+ state.autoResumeInFlight = true;
3955
+ try {
3956
+ const newSessionID = await createManagedUltraworkSession(state, title);
3957
+ if (!newSessionID) {
3958
+ throw new Error("session.create returned no session ID");
3959
+ }
3960
+ await refreshAutoCycleLock(state, newSessionID);
3961
+ await promptManagedSession(
3962
+ state,
3963
+ newSessionID,
3964
+ `[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.`
3965
+ );
3966
+ state.autoResumeAttempted = true;
3967
+ if (options.retireSourceSession && isManagedUltraworkSession(state, options.sourceSessionID)) {
3968
+ await removeManagedUltraworkSession(
3969
+ state,
3970
+ options.sourceSessionID,
3971
+ "auto-cycle moved to a new session"
3972
+ );
3973
+ }
3974
+ pluginLog.info(
3975
+ `[opencode-immune] ${options.logContext}: Bootstrap prompt sent to ${newSessionID}`
3976
+ );
3977
+ return newSessionID;
3978
+ } catch (err) {
3979
+ if (options.clearLockOnFailureReason) {
3980
+ await clearAutoCycleLock(state, options.clearLockOnFailureReason);
3981
+ }
3982
+ throw err;
3983
+ } finally {
3984
+ state.autoResumeInFlight = false;
3985
+ }
3986
+ }
3951
3987
  async function applyUltraworkSessionPermissions(state, sessionID) {
3952
3988
  if (state.ultraworkPermissionSessions.has(sessionID)) return;
3953
3989
  try {
@@ -5265,28 +5301,25 @@ function createSessionRecoveryEvent(state) {
5265
5301
  sessionID
5266
5302
  );
5267
5303
  if (!lockAcquired) return;
5268
- await addManagedUltraworkSession(state, sessionID);
5269
5304
  await refreshAutoCycleLock(state, sessionID);
5270
- state.autoResumeInFlight = true;
5271
5305
  setTimeout(async () => {
5272
5306
  try {
5273
- await promptManagedSession(
5307
+ const newSessionID = await startAutoCycleInNewSession(
5274
5308
  state,
5275
- sessionID,
5276
- `[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.`
5309
+ {
5310
+ sourceSessionID: sessionID,
5311
+ logContext: "Auto-cycle",
5312
+ clearLockOnFailureReason: "root session auto-cycle failed"
5313
+ }
5277
5314
  );
5278
- state.autoResumeAttempted = true;
5279
5315
  pluginLog.info(
5280
- `[opencode-immune] Auto-cycle prompt sent to root ultrawork session ${sessionID}`
5316
+ `[opencode-immune] Auto-cycle prompt sent to new session ${newSessionID}`
5281
5317
  );
5282
5318
  } catch (err) {
5283
- await clearAutoCycleLock(state, "root session auto-cycle failed");
5284
5319
  pluginLog.error(
5285
5320
  `[opencode-immune] Auto-cycle prompt failed for root session ${sessionID}:`,
5286
5321
  err
5287
5322
  );
5288
- } finally {
5289
- state.autoResumeInFlight = false;
5290
5323
  }
5291
5324
  }, 3e3);
5292
5325
  }
@@ -5836,15 +5869,18 @@ function createTextCompleteHandler(state) {
5836
5869
  const taskMatch = text.match(NEXT_TASK_PATTERN);
5837
5870
  const nextTask = taskMatch?.[1]?.trim() ?? "Continue processing task backlog";
5838
5871
  pluginLog.info(
5839
- `[opencode-immune] Multi-Cycle: Starting next cycle in current session (cycle ${state.cycleCount}/${MAX_CYCLES}) for: "${nextTask}"`
5872
+ `[opencode-immune] Multi-Cycle: Starting next cycle in a new session (cycle ${state.cycleCount}/${MAX_CYCLES}) for: "${nextTask}"`
5840
5873
  );
5841
5874
  try {
5842
- await promptManagedSession(
5875
+ await startAutoCycleInNewSession(
5843
5876
  state,
5844
- sessionID,
5845
- `[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.`
5877
+ {
5878
+ sourceSessionID: sessionID,
5879
+ nextTask,
5880
+ logContext: "Multi-Cycle",
5881
+ retireSourceSession: true
5882
+ }
5846
5883
  );
5847
- pluginLog.info(`[opencode-immune] Multi-Cycle: Bootstrap prompt sent to ${sessionID}`);
5848
5884
  } catch (err) {
5849
5885
  pluginLog.error("[opencode-immune] Multi-Cycle: Failed to send prompt:", err);
5850
5886
  }
@@ -5869,15 +5905,17 @@ function createTextCompleteHandler(state) {
5869
5905
  );
5870
5906
  try {
5871
5907
  await refreshAutoCycleLock(state, sessionID);
5872
- await promptManagedSession(
5908
+ await startAutoCycleInNewSession(
5873
5909
  state,
5874
- sessionID,
5875
- `[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.`
5910
+ {
5911
+ sourceSessionID: sessionID,
5912
+ logContext: "Multi-Cycle fallback",
5913
+ clearLockOnFailureReason: "fallback bootstrap failed",
5914
+ retireSourceSession: true
5915
+ }
5876
5916
  );
5877
- pluginLog.info(`[opencode-immune] Multi-Cycle fallback: Bootstrap prompt sent to ${sessionID}`);
5878
5917
  } catch (err) {
5879
5918
  state.autoCycleSourceSessions.delete(sessionID);
5880
- await clearAutoCycleLock(state, "fallback bootstrap failed");
5881
5919
  pluginLog.error("[opencode-immune] Multi-Cycle fallback: Failed to send prompt:", err);
5882
5920
  } finally {
5883
5921
  state.autoCycleInFlight = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-immune",
3
- "version": "1.0.74",
3
+ "version": "1.0.75",
4
4
  "type": "module",
5
5
  "description": "OpenCode plugin: session recovery, auto-retry, multi-cycle automation, context monitoring",
6
6
  "exports": {