opencode-immune 1.0.11 → 1.0.13
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 +46 -15
- package/package.json +1 -1
package/dist/plugin.js
CHANGED
|
@@ -19,6 +19,7 @@ function createState(input) {
|
|
|
19
19
|
todoWriteUsed: false,
|
|
20
20
|
approximateTokens: 0,
|
|
21
21
|
sessionActive: false,
|
|
22
|
+
autoResumeAttempted: false,
|
|
22
23
|
cycleCount: 0,
|
|
23
24
|
commitPending: false,
|
|
24
25
|
};
|
|
@@ -531,17 +532,25 @@ function createSessionRecoveryEvent(state) {
|
|
|
531
532
|
*/
|
|
532
533
|
function createSystemTransform(state) {
|
|
533
534
|
return async (input, output) => {
|
|
534
|
-
// Session Recovery injection
|
|
535
|
-
if
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
535
|
+
// Session Recovery injection:
|
|
536
|
+
// Inject if recoveryContext exists AND either:
|
|
537
|
+
// - session is already registered as managed root ultrawork, OR
|
|
538
|
+
// - session is not yet registered (plugin just restarted, map is empty)
|
|
539
|
+
// but agent field matches ultrawork (checked via input metadata if available)
|
|
540
|
+
if (state.recoveryContext) {
|
|
541
|
+
const isManaged = isManagedRootUltraworkSession(state, input.sessionID);
|
|
542
|
+
const mapIsEmpty = state.managedUltraworkSessions.size === 0;
|
|
543
|
+
if (isManaged || mapIsEmpty) {
|
|
544
|
+
const ctx = state.recoveryContext;
|
|
545
|
+
const intentInfo = ctx.intent ? `, Intent: ${ctx.intent}` : "";
|
|
546
|
+
const categoryInfo = ctx.category ? `, Category: ${ctx.category}` : "";
|
|
547
|
+
output.system.push(`[Session Recovery] Active Memory Bank task detected:\n` +
|
|
548
|
+
`- Task: ${ctx.task}\n` +
|
|
549
|
+
`- Level: ${ctx.level}${intentInfo}${categoryInfo}\n` +
|
|
550
|
+
`- Current Phase: ${ctx.phase}\n` +
|
|
551
|
+
`- Phase Status:\n${ctx.phaseStatus}\n` +
|
|
552
|
+
`Read memory-bank/tasks.md and memory-bank/activeContext.md to resume work.`);
|
|
553
|
+
}
|
|
545
554
|
}
|
|
546
555
|
// Ralph Loop injection
|
|
547
556
|
if (state.lastEditAttempt) {
|
|
@@ -709,16 +718,38 @@ function createFallbackModels(state) {
|
|
|
709
718
|
await addManagedUltraworkSession(state, input.sessionID);
|
|
710
719
|
await writeUltraworkMarker(state);
|
|
711
720
|
// First contact with 0-ultrawork after plugin restart:
|
|
712
|
-
// if marker is active and tasks.md has incomplete work,
|
|
713
|
-
|
|
714
|
-
|
|
721
|
+
// if marker is active and tasks.md has incomplete work, send AUTO-RESUME prompt.
|
|
722
|
+
if (!wasAlreadyManaged && !state.autoResumeAttempted) {
|
|
723
|
+
state.autoResumeAttempted = true;
|
|
715
724
|
const markerActive = await isUltraworkMarkerActive(state);
|
|
716
725
|
if (markerActive) {
|
|
717
726
|
const recovery = await parseTasksFile(state.input.directory);
|
|
718
727
|
if (recovery && recovery.phase !== "ARCHIVE: DONE") {
|
|
719
728
|
state.recoveryContext = recovery;
|
|
720
729
|
console.log(`[opencode-immune] Auto-recovery on existing session: ` +
|
|
721
|
-
`task="${recovery.task}", level=${recovery.level}, phase=${recovery.phase}`
|
|
730
|
+
`task="${recovery.task}", level=${recovery.level}, phase=${recovery.phase}. ` +
|
|
731
|
+
`Sending AUTO-RESUME prompt in 3s...`);
|
|
732
|
+
const sid = input.sessionID;
|
|
733
|
+
setTimeout(async () => {
|
|
734
|
+
try {
|
|
735
|
+
await state.input.client.session.promptAsync({
|
|
736
|
+
body: {
|
|
737
|
+
agent: ULTRAWORK_AGENT,
|
|
738
|
+
parts: [
|
|
739
|
+
{
|
|
740
|
+
type: "text",
|
|
741
|
+
text: `[AUTO-RESUME] Previous session was interrupted. Read memory-bank/tasks.md, check the Phase Status block, and continue the pipeline. Use ONLY the Phase Status block to determine the next phase. Do NOT analyze or evaluate the content of tasks.md. Call the appropriate router with the exact neutral prompt from your Step 5 table.`,
|
|
742
|
+
},
|
|
743
|
+
],
|
|
744
|
+
},
|
|
745
|
+
path: { id: sid },
|
|
746
|
+
});
|
|
747
|
+
console.log(`[opencode-immune] Auto-resume prompt sent to session ${sid}`);
|
|
748
|
+
}
|
|
749
|
+
catch (err) {
|
|
750
|
+
console.log(`[opencode-immune] Auto-resume prompt failed:`, err);
|
|
751
|
+
}
|
|
752
|
+
}, 3_000);
|
|
722
753
|
}
|
|
723
754
|
}
|
|
724
755
|
}
|