opencode-gitlab-duo-agentic 0.2.20 → 0.2.22

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/index.js +66 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -793,11 +793,18 @@ var WorkflowSession = class {
793
793
  #queue;
794
794
  #startRequestSent = false;
795
795
  #pendingApproval = false;
796
- constructor(client, modelId, cwd) {
796
+ #resumed = false;
797
+ #onWorkflowCreated;
798
+ constructor(client, modelId, cwd, options) {
797
799
  this.#client = client;
798
800
  this.#tokenService = new WorkflowTokenService(client);
799
801
  this.#modelId = modelId;
800
802
  this.#cwd = cwd;
803
+ if (options?.existingWorkflowId) {
804
+ this.#workflowId = options.existingWorkflowId;
805
+ this.#resumed = true;
806
+ }
807
+ this.#onWorkflowCreated = options?.onWorkflowCreated;
801
808
  }
802
809
  /**
803
810
  * Opt-in: override the server-side system prompt and/or register MCP tools.
@@ -817,6 +824,7 @@ var WorkflowSession = class {
817
824
  this.#tokenService.clear();
818
825
  this.#closeConnection();
819
826
  this.#pendingApproval = false;
827
+ this.#resumed = false;
820
828
  this.#startRequestSent = false;
821
829
  }
822
830
  // ---------------------------------------------------------------------------
@@ -948,11 +956,16 @@ var WorkflowSession = class {
948
956
  const status = action.newCheckpoint.status;
949
957
  dlog(`checkpoint: status=${status} ckptLen=${ckpt.length}`);
950
958
  const deltas = extractAgentTextDeltas(ckpt, this.#checkpoint);
951
- for (const delta of deltas) {
952
- queue.push({ type: "text-delta", value: delta });
953
- }
954
- if (deltas.length > 0) {
955
- dlog(`checkpoint: ${deltas.length} text deltas`);
959
+ if (this.#resumed) {
960
+ dlog(`checkpoint: RESUMED \u2014 discarding ${deltas.length} old deltas, fast-forwarding state`);
961
+ this.#resumed = false;
962
+ } else {
963
+ for (const delta of deltas) {
964
+ queue.push({ type: "text-delta", value: delta });
965
+ }
966
+ if (deltas.length > 0) {
967
+ dlog(`checkpoint: ${deltas.length} text deltas`);
968
+ }
956
969
  }
957
970
  if (isToolApproval(status)) {
958
971
  dlog(`checkpoint: TOOL_APPROVAL \u2192 pendingApproval=true (waiting for DWS close)`);
@@ -1088,7 +1101,9 @@ var WorkflowSession = class {
1088
1101
  const details = [created.message, created.error].filter(Boolean).join("; ");
1089
1102
  throw new Error(`failed to create workflow${details ? `: ${details}` : ""}`);
1090
1103
  }
1091
- return String(created.id);
1104
+ const workflowId = String(created.id);
1105
+ this.#onWorkflowCreated?.(workflowId);
1106
+ return workflowId;
1092
1107
  }
1093
1108
  async #loadProjectContext() {
1094
1109
  if (this.#projectPath !== void 0) return;
@@ -1466,6 +1481,39 @@ CODE QUALITY:
1466
1481
  </communication>
1467
1482
  </system-reminder>`;
1468
1483
 
1484
+ // src/workflow/session-store.ts
1485
+ import { readFileSync, writeFileSync, mkdirSync } from "fs";
1486
+ import { join } from "path";
1487
+ import { homedir } from "os";
1488
+ function getStorePath() {
1489
+ const dir = process.env.XDG_CACHE_HOME?.trim() ? join(process.env.XDG_CACHE_HOME, "opencode") : join(homedir(), ".cache", "opencode");
1490
+ return join(dir, "duo-workflow-sessions.json");
1491
+ }
1492
+ function readStore() {
1493
+ try {
1494
+ return JSON.parse(readFileSync(getStorePath(), "utf8"));
1495
+ } catch {
1496
+ return {};
1497
+ }
1498
+ }
1499
+ function writeStore(store) {
1500
+ try {
1501
+ const storePath = getStorePath();
1502
+ mkdirSync(join(storePath, ".."), { recursive: true });
1503
+ writeFileSync(storePath, JSON.stringify(store, null, 2), "utf8");
1504
+ } catch {
1505
+ }
1506
+ }
1507
+ function saveWorkflowId(key, workflowId) {
1508
+ const store = readStore();
1509
+ store[key] = workflowId;
1510
+ writeStore(store);
1511
+ }
1512
+ function loadWorkflowId(key) {
1513
+ const store = readStore();
1514
+ return store[key];
1515
+ }
1516
+
1469
1517
  // src/provider/duo-workflow-model.ts
1470
1518
  var sessions = /* @__PURE__ */ new Map();
1471
1519
  var UNKNOWN_USAGE = {
@@ -1743,7 +1791,17 @@ var DuoWorkflowModel = class {
1743
1791
  const key = sessionKey(this.#client.instanceUrl, this.modelId, sessionID);
1744
1792
  const existing = sessions.get(key);
1745
1793
  if (existing) return existing;
1746
- const created = new WorkflowSession(this.#client, this.modelId, this.#cwd);
1794
+ const existingWorkflowId = loadWorkflowId(key);
1795
+ if (existingWorkflowId) {
1796
+ dlog(`resolveSession: restored workflowId=${existingWorkflowId} from disk for ${sessionID}`);
1797
+ }
1798
+ const created = new WorkflowSession(this.#client, this.modelId, this.#cwd, {
1799
+ existingWorkflowId,
1800
+ onWorkflowCreated: (workflowId) => {
1801
+ dlog(`resolveSession: saving workflowId=${workflowId} for ${sessionID}`);
1802
+ saveWorkflowId(key, workflowId);
1803
+ }
1804
+ });
1747
1805
  if (this.#toolsConfig) created.setToolsConfig(this.#toolsConfig);
1748
1806
  sessions.set(key, created);
1749
1807
  return created;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-gitlab-duo-agentic",
3
- "version": "0.2.20",
3
+ "version": "0.2.22",
4
4
  "description": "OpenCode plugin and provider for GitLab Duo Agentic workflows",
5
5
  "license": "MIT",
6
6
  "type": "module",