parallax-opencode 0.3.2 → 0.3.4

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 CHANGED
@@ -33,8 +33,12 @@ const modeStore = new Map();
33
33
  const protocolStore = new Map();
34
34
  let currentSessionId = null;
35
35
  let currentAgentName = null;
36
+ let stableSessionKey = null;
36
37
  function sessionId() {
37
- return currentSessionId || "default";
38
+ // Protocol state is keyed by a stable identifier, not OpenCode session ID.
39
+ // OpenCode creates multiple sessions per conversation (root, child, subagent).
40
+ // The first root session ID is locked in and never changes.
41
+ return stableSessionKey || "default";
38
42
  }
39
43
  function getFriction(s = sessionId()) {
40
44
  if (!frictionStore.has(s)) {
@@ -638,11 +642,16 @@ export default {
638
642
  // They have a parentID and would overwrite the main session's protocol state.
639
643
  if (info.parentID)
640
644
  return;
641
- currentSessionId =
645
+ // Lock in the first root session ID. Subsequent root session.created
646
+ // events must not change the key because protocol state is already
647
+ // attached to the first key via stableSessionKey.
648
+ if (stableSessionKey)
649
+ return;
650
+ stableSessionKey ??= (currentSessionId =
642
651
  info.id ||
643
652
  props.sessionID ||
644
653
  info.sessionID ||
645
- null;
654
+ null);
646
655
  // Agent name lives in Session.agent (v2 SDK types.gen.d.ts:590)
647
656
  currentAgentName =
648
657
  info.agent ||
@@ -651,6 +660,20 @@ export default {
651
660
  // Initialize trace with session info
652
661
  if (currentSessionId) {
653
662
  initTrace(currentSessionId, process.cwd(), detectProject());
663
+ // Carry over protocol state from default if checkins happened before
664
+ // the session.created event fired (common race on session start).
665
+ if (protocolStore.has("default")) {
666
+ protocolStore.set(currentSessionId, protocolStore.get("default"));
667
+ protocolStore.delete("default");
668
+ }
669
+ if (frictionStore.has("default")) {
670
+ frictionStore.set(currentSessionId, frictionStore.get("default"));
671
+ frictionStore.delete("default");
672
+ }
673
+ if (modeStore.has("default")) {
674
+ modeStore.set(currentSessionId, modeStore.get("default"));
675
+ modeStore.delete("default");
676
+ }
654
677
  writeState();
655
678
  }
656
679
  }
@@ -236,8 +236,9 @@ var modeStore = /* @__PURE__ */ new Map();
236
236
  var protocolStore = /* @__PURE__ */ new Map();
237
237
  var currentSessionId = null;
238
238
  var currentAgentName = null;
239
+ var stableSessionKey = null;
239
240
  function sessionId() {
240
- return currentSessionId || "default";
241
+ return stableSessionKey || "default";
241
242
  }
242
243
  function getFriction(s = sessionId()) {
243
244
  if (!frictionStore.has(s)) {
@@ -765,10 +766,23 @@ ${s.lastObservation}`
765
766
  const props = input.event.properties || {};
766
767
  const info = props.info || {};
767
768
  if (info.parentID) return;
768
- currentSessionId = info.id || props.sessionID || info.sessionID || null;
769
+ if (stableSessionKey) return;
770
+ stableSessionKey ??= currentSessionId = info.id || props.sessionID || info.sessionID || null;
769
771
  currentAgentName = info.agent || props.agent || null;
770
772
  if (currentSessionId) {
771
773
  initTrace(currentSessionId, process.cwd(), detectProject());
774
+ if (protocolStore.has("default")) {
775
+ protocolStore.set(currentSessionId, protocolStore.get("default"));
776
+ protocolStore.delete("default");
777
+ }
778
+ if (frictionStore.has("default")) {
779
+ frictionStore.set(currentSessionId, frictionStore.get("default"));
780
+ frictionStore.delete("default");
781
+ }
782
+ if (modeStore.has("default")) {
783
+ modeStore.set(currentSessionId, modeStore.get("default"));
784
+ modeStore.delete("default");
785
+ }
772
786
  writeState();
773
787
  }
774
788
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "parallax-opencode",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "PARALLAX ENGINE plugin for OpenCode -- protocol enforcement, friction-loop verification, mode switching (plan/build/debug), trace recording, coherence scoring, CI gate, and PR-ready trace artifacts",
5
5
  "type": "module",
6
6
  "main": "./dist/plugin.js",