opencode-acp 1.16.0-pr.376.121 → 1.16.0-pr.382.117

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/index.js CHANGED
@@ -2390,12 +2390,12 @@ function serializePruneMessagesState(messagesState) {
2390
2390
  markedForCleanup: Array.from(messagesState.markedForCleanup)
2391
2391
  };
2392
2392
  }
2393
- async function getForkParentId(client, sessionID) {
2393
+ async function isSubAgentSession(client, sessionID) {
2394
2394
  try {
2395
2395
  const result = await client.session.get({ path: { id: sessionID } });
2396
- return result.data?.parentID ?? null;
2396
+ return !!result.data?.parentID;
2397
2397
  } catch (error) {
2398
- return null;
2398
+ return false;
2399
2399
  }
2400
2400
  }
2401
2401
  function findLastCompactionTimestamp(messages) {
@@ -4456,205 +4456,6 @@ function rebuildCompressionState(state, messages, config, logger) {
4456
4456
  return rebuilt;
4457
4457
  }
4458
4458
 
4459
- // lib/state/fork-transfer.ts
4460
- function extractIdentity(message) {
4461
- const id = message?.info?.id;
4462
- if (typeof id !== "string" || id.length === 0) {
4463
- return null;
4464
- }
4465
- if (isSyntheticMessage(message)) {
4466
- return null;
4467
- }
4468
- const role = message.info.role;
4469
- const created = message.info.time?.created;
4470
- if (typeof created !== "number") {
4471
- return null;
4472
- }
4473
- return { id, role, created };
4474
- }
4475
- function buildSharedPrefixMapping(parentMessages, forkMessages) {
4476
- const parentIds = parentMessages.map(extractIdentity).filter((x) => x !== null);
4477
- const forkIds = forkMessages.map(extractIdentity).filter((x) => x !== null);
4478
- const mapping = /* @__PURE__ */ new Map();
4479
- const limit = Math.min(parentIds.length, forkIds.length);
4480
- for (let i = 0; i < limit; i++) {
4481
- const p = parentIds[i];
4482
- const f = forkIds[i];
4483
- if (p.created === f.created && p.role === f.role) {
4484
- mapping.set(p.id, f.id);
4485
- } else {
4486
- break;
4487
- }
4488
- }
4489
- return mapping;
4490
- }
4491
- function remapBoundaryRef(ref, mapping, forkByRawId, parentByRef) {
4492
- const parsed = parseBoundaryId(ref);
4493
- if (!parsed) {
4494
- return ref;
4495
- }
4496
- if (parsed.kind === "compressed-block") {
4497
- return parsed.ref;
4498
- }
4499
- const parentRawId = parentByRef.get(parsed.ref);
4500
- if (!parentRawId) {
4501
- return ref;
4502
- }
4503
- const forkRawId = mapping.get(parentRawId);
4504
- if (!forkRawId) {
4505
- return ref;
4506
- }
4507
- const forkRef = forkByRawId.get(forkRawId);
4508
- return forkRef ?? ref;
4509
- }
4510
- function translateBlock(block, mapping, forkByRawId, parentByRef) {
4511
- const anchorForkId = mapping.get(block.anchorMessageId);
4512
- if (!anchorForkId) {
4513
- return null;
4514
- }
4515
- const compressForkId = mapping.get(block.compressMessageId);
4516
- if (!compressForkId) {
4517
- return null;
4518
- }
4519
- const translateList = (ids) => ids.map((id) => mapping.get(id)).filter((id) => id !== void 0);
4520
- const preserveList = (ids) => [...new Set(ids)];
4521
- return {
4522
- ...block,
4523
- anchorMessageId: anchorForkId,
4524
- compressMessageId: compressForkId,
4525
- directMessageIds: translateList(block.directMessageIds),
4526
- effectiveMessageIds: translateList(block.effectiveMessageIds),
4527
- directToolIds: preserveList(block.directToolIds),
4528
- effectiveToolIds: preserveList(block.effectiveToolIds),
4529
- startId: remapBoundaryRef(block.startId, mapping, forkByRawId, parentByRef),
4530
- endId: remapBoundaryRef(block.endId, mapping, forkByRawId, parentByRef)
4531
- };
4532
- }
4533
- function translateByMessageId(parentByMessageId, mapping, translatedBlockIds) {
4534
- const result = /* @__PURE__ */ new Map();
4535
- for (const [parentMsgId, entry] of Object.entries(parentByMessageId)) {
4536
- if (!entry || typeof entry !== "object") {
4537
- continue;
4538
- }
4539
- const forkMsgId = mapping.get(parentMsgId);
4540
- if (!forkMsgId) {
4541
- continue;
4542
- }
4543
- const allBlockIds = (entry.allBlockIds ?? []).filter((id) => translatedBlockIds.has(id));
4544
- const activeBlockIds = (entry.activeBlockIds ?? []).filter(
4545
- (id) => translatedBlockIds.has(id)
4546
- );
4547
- result.set(forkMsgId, {
4548
- tokenCount: typeof entry.tokenCount === "number" ? entry.tokenCount : 0,
4549
- allBlockIds,
4550
- activeBlockIds
4551
- });
4552
- }
4553
- return result;
4554
- }
4555
- async function recoverFromParentState(client, state, forkMessages, parentId, logger) {
4556
- const parentState = await loadSessionState(parentId, logger);
4557
- if (!parentState) {
4558
- logger.info("fork-transfer: no parent state found, falling back to replay", {
4559
- parentId
4560
- });
4561
- return 0;
4562
- }
4563
- const parentMessagesState = parentState.prune?.messages;
4564
- const parentBlocks = parentMessagesState?.blocksById;
4565
- if (!parentBlocks) {
4566
- logger.info("fork-transfer: parent state has no blocks, falling back to replay", {
4567
- parentId
4568
- });
4569
- return 0;
4570
- }
4571
- const parentBlockEntries = Object.entries(parentBlocks).filter(
4572
- ([id, block]) => Number.isInteger(Number.parseInt(id, 10)) && Number.parseInt(id, 10) >= 1 && !!block
4573
- );
4574
- if (parentBlockEntries.length === 0) {
4575
- logger.info("fork-transfer: parent state has no blocks, falling back to replay", {
4576
- parentId
4577
- });
4578
- return 0;
4579
- }
4580
- let parentMessages;
4581
- try {
4582
- const response = await client.session.messages({ path: { id: parentId } });
4583
- parentMessages = filterMessages(response?.data || response);
4584
- } catch (error) {
4585
- logger.warn("fork-transfer: failed to fetch parent messages, falling back to replay", {
4586
- parentId,
4587
- error: error?.message || String(error)
4588
- });
4589
- return 0;
4590
- }
4591
- const mapping = buildSharedPrefixMapping(parentMessages, forkMessages);
4592
- if (mapping.size === 0) {
4593
- logger.info("fork-transfer: no shared prefix detected, falling back to replay", {
4594
- parentId
4595
- });
4596
- return 0;
4597
- }
4598
- assignMessageRefs(state, forkMessages);
4599
- const forkByRawId = state.messageIds.byRawId;
4600
- const parentByRef = new Map(Object.entries(parentState.messageIds?.byRef ?? {}));
4601
- const translatedBlocks = /* @__PURE__ */ new Map();
4602
- let skipped = 0;
4603
- for (const [blockIdStr, block] of parentBlockEntries) {
4604
- const blockId = Number.parseInt(blockIdStr, 10);
4605
- const translated = translateBlock(block, mapping, forkByRawId, parentByRef);
4606
- if (translated) {
4607
- translatedBlocks.set(blockId, translated);
4608
- } else {
4609
- skipped++;
4610
- }
4611
- }
4612
- if (translatedBlocks.size === 0) {
4613
- logger.info("fork-transfer: no blocks translatable, falling back to replay", {
4614
- parentId,
4615
- parentBlockCount: parentBlockEntries.length,
4616
- mappingSize: mapping.size
4617
- });
4618
- return 0;
4619
- }
4620
- const activeCount = Array.from(translatedBlocks.values()).filter((b) => b.active).length;
4621
- if (activeCount === 0) {
4622
- logger.info("fork-transfer: no active blocks translatable, falling back to replay", {
4623
- parentId,
4624
- recoveredBlocks: translatedBlocks.size,
4625
- skippedBlocks: skipped,
4626
- mappingSize: mapping.size
4627
- });
4628
- return 0;
4629
- }
4630
- const translatedByMessageId = translateByMessageId(
4631
- parentMessagesState.byMessageId ?? {},
4632
- mapping,
4633
- new Set(translatedBlocks.keys())
4634
- );
4635
- state.prune.messages = loadPruneMessagesState({
4636
- byMessageId: Object.fromEntries(translatedByMessageId),
4637
- blocksById: Object.fromEntries(
4638
- Array.from(translatedBlocks.entries()).map(
4639
- ([id, block]) => [String(id), block]
4640
- )
4641
- ),
4642
- activeBlockIds: [],
4643
- activeByAnchorMessageId: {},
4644
- nextBlockId: 1,
4645
- nextRunId: 1,
4646
- markedForCleanup: []
4647
- });
4648
- logger.info("fork-transfer: recovered compression state from parent", {
4649
- parentId,
4650
- recoveredBlocks: translatedBlocks.size,
4651
- activeBlocks: activeCount,
4652
- skippedBlocks: skipped,
4653
- mappingSize: mapping.size
4654
- });
4655
- return activeCount;
4656
- }
4657
-
4658
4459
  // lib/state/state.ts
4659
4460
  async function updatePerTurnState(state, logger, messages) {
4660
4461
  const lastCompactionTimestamp = findLastCompactionTimestamp(messages);
@@ -4849,8 +4650,8 @@ async function ensureSessionInitialized(client, state, sessionId, logger, messag
4849
4650
  resetSessionState(state);
4850
4651
  state.sessionId = sessionId;
4851
4652
  state.storageDir = config?.storagePath ? resolveStorageDir(config.storagePath, projectDir ?? cwd()) : void 0;
4852
- const parentId = await getForkParentId(client, sessionId);
4853
- state.isSubAgent = parentId !== null;
4653
+ const isSubAgent = await isSubAgentSession(client, sessionId);
4654
+ state.isSubAgent = isSubAgent;
4854
4655
  state.lastCompaction = findLastCompactionTimestamp(messages);
4855
4656
  state.currentTurn = countTurns(state, messages);
4856
4657
  state.nudges.turnNudgeAnchors = collectTurnNudgeAnchors(messages);
@@ -4864,14 +4665,8 @@ async function ensureSessionInitialized(client, state, sessionId, logger, messag
4864
4665
  );
4865
4666
  }
4866
4667
  if (config) {
4867
- let recovered = 0;
4868
- if (parentId) {
4869
- recovered = await recoverFromParentState(client, state, messages, parentId, logger);
4870
- }
4871
- if (recovered === 0) {
4872
- recovered = rebuildCompressionState(state, messages, config, logger);
4873
- }
4874
- if (recovered > 0) {
4668
+ const rebuilt = rebuildCompressionState(state, messages, config, logger);
4669
+ if (rebuilt > 0) {
4875
4670
  await saveSessionState(state, logger);
4876
4671
  }
4877
4672
  }
@@ -9735,7 +9530,7 @@ import { writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
9735
9530
  import { join as join4 } from "path";
9736
9531
  import { existsSync as existsSync4 } from "fs";
9737
9532
  import { homedir as homedir3 } from "os";
9738
- var LOG_VERSION = true ? "1.16.0-pr.376.121" : "dev";
9533
+ var LOG_VERSION = true ? "1.16.0-pr.382.117" : "dev";
9739
9534
  var LEVEL_RANK = {
9740
9535
  debug: 10,
9741
9536
  info: 20,
@@ -12226,7 +12021,7 @@ var server = (async (ctx) => {
12226
12021
  }
12227
12022
  const logger = new Logger(config.debug, config.debug ? "debug" : config.logLevel);
12228
12023
  logger.info("ACP plugin initialized", {
12229
- version: true ? "1.16.0-pr.376.121" : "dev",
12024
+ version: true ? "1.16.0-pr.382.117" : "dev",
12230
12025
  workspace: ctx.directory,
12231
12026
  logLevel: logger.level,
12232
12027
  debug: config.debug,