opencode-immune 1.0.12 → 1.0.14
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 +65 -5
- 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
|
};
|
|
@@ -717,16 +718,38 @@ function createFallbackModels(state) {
|
|
|
717
718
|
await addManagedUltraworkSession(state, input.sessionID);
|
|
718
719
|
await writeUltraworkMarker(state);
|
|
719
720
|
// First contact with 0-ultrawork after plugin restart:
|
|
720
|
-
// if marker is active and tasks.md has incomplete work,
|
|
721
|
-
|
|
722
|
-
|
|
721
|
+
// if marker is active and tasks.md has incomplete work, send AUTO-RESUME prompt.
|
|
722
|
+
if (!wasAlreadyManaged && !state.autoResumeAttempted) {
|
|
723
|
+
state.autoResumeAttempted = true;
|
|
723
724
|
const markerActive = await isUltraworkMarkerActive(state);
|
|
724
725
|
if (markerActive) {
|
|
725
726
|
const recovery = await parseTasksFile(state.input.directory);
|
|
726
727
|
if (recovery && recovery.phase !== "ARCHIVE: DONE") {
|
|
727
728
|
state.recoveryContext = recovery;
|
|
728
729
|
console.log(`[opencode-immune] Auto-recovery on existing session: ` +
|
|
729
|
-
`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);
|
|
730
753
|
}
|
|
731
754
|
}
|
|
732
755
|
}
|
|
@@ -975,8 +998,45 @@ async function server(input) {
|
|
|
975
998
|
const recovery = await parseTasksFile(state.input.directory);
|
|
976
999
|
if (recovery && recovery.phase !== "ARCHIVE: DONE") {
|
|
977
1000
|
state.recoveryContext = recovery;
|
|
1001
|
+
state.autoResumeAttempted = true;
|
|
978
1002
|
console.log(`[opencode-immune] Plugin init: ultrawork marker active, recovery context loaded: ` +
|
|
979
|
-
`task="${recovery.task}", level=${recovery.level}, phase=${recovery.phase}`
|
|
1003
|
+
`task="${recovery.task}", level=${recovery.level}, phase=${recovery.phase}. ` +
|
|
1004
|
+
`Will create new session and send AUTO-RESUME.`);
|
|
1005
|
+
// Create a new session and send AUTO-RESUME prompt (same pattern as CYCLE_COMPLETE).
|
|
1006
|
+
// Delay to let opencode fully initialize.
|
|
1007
|
+
setTimeout(async () => {
|
|
1008
|
+
try {
|
|
1009
|
+
const createResult = await state.input.client.session.create({
|
|
1010
|
+
body: {
|
|
1011
|
+
title: `AUTO-RESUME: ${recovery.task}`,
|
|
1012
|
+
},
|
|
1013
|
+
});
|
|
1014
|
+
const newSessionData = createResult?.data;
|
|
1015
|
+
const newSessionID = newSessionData?.id;
|
|
1016
|
+
if (!newSessionID) {
|
|
1017
|
+
console.error("[opencode-immune] Auto-resume: Failed to create session — no session ID returned.");
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
console.log(`[opencode-immune] Auto-resume: New session created: ${newSessionID}`);
|
|
1021
|
+
await addManagedUltraworkSession(state, newSessionID);
|
|
1022
|
+
await state.input.client.session.promptAsync({
|
|
1023
|
+
body: {
|
|
1024
|
+
agent: ULTRAWORK_AGENT,
|
|
1025
|
+
parts: [
|
|
1026
|
+
{
|
|
1027
|
+
type: "text",
|
|
1028
|
+
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.`,
|
|
1029
|
+
},
|
|
1030
|
+
],
|
|
1031
|
+
},
|
|
1032
|
+
path: { id: newSessionID },
|
|
1033
|
+
});
|
|
1034
|
+
console.log(`[opencode-immune] Auto-resume prompt sent to new session ${newSessionID}`);
|
|
1035
|
+
}
|
|
1036
|
+
catch (err) {
|
|
1037
|
+
console.error("[opencode-immune] Auto-resume: Failed to create session or send prompt:", err);
|
|
1038
|
+
}
|
|
1039
|
+
}, 5_000);
|
|
980
1040
|
}
|
|
981
1041
|
}
|
|
982
1042
|
console.log(`[opencode-immune] Plugin initialized. Directory: ${input.directory}`);
|